]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
1. Set the EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED bit on insertion/deletion of entries...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / DebugImageInfo.c
1 /** @file
2 Support functions for managing debug image info table when loading and unloading
3 images.
4
5 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "DxeMain.h"
17
18
19 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader = {
20 0, // volatile UINT32 UpdateStatus;
21 0, // UINT32 TableSize;
22 NULL // EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;
23 };
24
25 UINTN mMaxTableEntries = 0;
26
27 EFI_SYSTEM_TABLE_POINTER *mDebugTable = NULL;
28
29 #define FOUR_MEG_ALIGNMENT 0x400000
30
31 #define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof (VOID *))
32
33 /**
34 Creates and initializes the DebugImageInfo Table. Also creates the configuration
35 table and registers it into the system table.
36
37 **/
38 VOID
39 CoreInitializeDebugImageInfoTable (
40 VOID
41 )
42 {
43 EFI_STATUS Status;
44
45 //
46 // Allocate 4M aligned page for the structure and fill in the data.
47 // Ideally we would update the CRC now as well, but the service may not yet be available.
48 // See comments in the CoreUpdateDebugTableCrc32() function below for details.
49 //
50 mDebugTable = AllocateAlignedPages (EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER)), FOUR_MEG_ALIGNMENT);
51 mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE;
52 mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gDxeCoreST;
53 mDebugTable->Crc32 = 0;
54 Status = CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid, &mDebugInfoTableHeader);
55 ASSERT_EFI_ERROR (Status);
56 }
57
58
59 /**
60 Update the CRC32 in the Debug Table.
61 Since the CRC32 service is made available by the Runtime driver, we have to
62 wait for the Runtime Driver to be installed before the CRC32 can be computed.
63 This function is called elsewhere by the core when the runtime architectural
64 protocol is produced.
65
66 **/
67 VOID
68 CoreUpdateDebugTableCrc32 (
69 VOID
70 )
71 {
72 ASSERT(mDebugTable != NULL);
73 mDebugTable->Crc32 = 0;
74 gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);
75 }
76
77
78 /**
79 Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
80 the table if it's not large enough to accomidate another entry.
81
82 @param ImageInfoType type of debug image information
83 @param LoadedImage pointer to the loaded image protocol for the image being
84 loaded
85 @param ImageHandle image handle for the image being loaded
86
87 **/
88 VOID
89 CoreNewDebugImageInfoEntry (
90 IN UINT32 ImageInfoType,
91 IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
92 IN EFI_HANDLE ImageHandle
93 )
94 {
95 EFI_DEBUG_IMAGE_INFO *Table;
96 EFI_DEBUG_IMAGE_INFO *NewTable;
97 UINTN Index;
98 UINTN TableSize;
99
100 //
101 // Set the flag indicating that we're in the process of updating the table.
102 //
103 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
104
105 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
106
107 if (mDebugInfoTableHeader.TableSize < mMaxTableEntries) {
108 //
109 // We still have empty entires in the Table, find the first empty entry.
110 //
111 Index = 0;
112 while (Table[Index].NormalImage != NULL) {
113 Index++;
114 }
115 //
116 // There must be an empty entry in the in the table.
117 //
118 ASSERT (Index < mMaxTableEntries);
119 } else {
120 //
121 // Table is full, so re-allocate another page for a larger table...
122 //
123 TableSize = mMaxTableEntries * EFI_DEBUG_TABLE_ENTRY_SIZE;
124 NewTable = AllocateZeroPool (TableSize + EFI_PAGE_SIZE);
125 if (NewTable == NULL) {
126 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
127 return;
128 }
129 //
130 // Copy the old table into the new one
131 //
132 CopyMem (NewTable, Table, TableSize);
133 //
134 // Free the old table
135 //
136 CoreFreePool (Table);
137 //
138 // Update the table header
139 //
140 Table = NewTable;
141 mDebugInfoTableHeader.EfiDebugImageInfoTable = NewTable;
142 //
143 // Enlarge the max table entries and set the first empty entry index to
144 // be the original max table entries.
145 //
146 Index = mMaxTableEntries;
147 mMaxTableEntries += EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;
148 }
149
150 //
151 // Allocate data for new entry
152 //
153 Table[Index].NormalImage = AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));
154 if (Table[Index].NormalImage != NULL) {
155 //
156 // Update the entry
157 //
158 Table[Index].NormalImage->ImageInfoType = (UINT32) ImageInfoType;
159 Table[Index].NormalImage->LoadedImageProtocolInstance = LoadedImage;
160 Table[Index].NormalImage->ImageHandle = ImageHandle;
161 //
162 // Increase the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
163 //
164 mDebugInfoTableHeader.TableSize++;
165 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
166 }
167 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
168 }
169
170
171
172 /**
173 Removes and frees an entry from the DebugImageInfo Table.
174
175 @param ImageHandle image handle for the image being unloaded
176
177 **/
178 VOID
179 CoreRemoveDebugImageInfoEntry (
180 EFI_HANDLE ImageHandle
181 )
182 {
183 EFI_DEBUG_IMAGE_INFO *Table;
184 UINTN Index;
185
186 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
187
188 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
189
190 for (Index = 0; Index < mMaxTableEntries; Index++) {
191 if (Table[Index].NormalImage != NULL && Table[Index].NormalImage->ImageHandle == ImageHandle) {
192 //
193 // Found a match. Free up the record, then NULL the pointer to indicate the slot
194 // is free.
195 //
196 CoreFreePool (Table[Index].NormalImage);
197 Table[Index].NormalImage = NULL;
198 //
199 // Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
200 //
201 mDebugInfoTableHeader.TableSize--;
202 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
203 break;
204 }
205 }
206 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
207 }
208
209