]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/Dxe/Misc/DebugImageInfo.c
The ALIGNMENT definition has been moved to common header file.
[mirror_edk2.git] / EdkModulePkg / Core / Dxe / Misc / DebugImageInfo.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 DebugImageInfo.c\r
15 \r
16Abstract:\r
17\r
18 Support functions for managing debug image info table when loading and unloading\r
19 images.\r
20\r
21--*/\r
22\r
23#include <DxeMain.h>\r
24\r
25\r
26static EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader = {\r
27 0, // volatile UINT32 UpdateStatus;\r
28 0, // UINT32 TableSize;\r
29 NULL // EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;\r
30};\r
31\r
32static EFI_SYSTEM_TABLE_POINTER *mDebugTable = NULL;\r
33\r
34 \r
35VOID\r
36CoreInitializeDebugImageInfoTable (\r
37 VOID\r
38 )\r
39/*++\r
40\r
41Routine Description:\r
42\r
43 Creates and initializes the DebugImageInfo Table. Also creates the configuration\r
44 table and registers it into the system table.\r
45\r
46Arguments:\r
47 None\r
48\r
49Returns:\r
50 NA\r
51\r
52Notes:\r
53 This function allocates memory, frees it, and then allocates memory at an\r
54 address within the initial allocation. Since this function is called early\r
55 in DXE core initialization (before drivers are dispatched), this should not\r
56 be a problem.\r
57\r
58--*/\r
59{ \r
60 EFI_STATUS Status;\r
61 EFI_PHYSICAL_ADDRESS Mem;\r
62 UINTN NumberOfPages; \r
63\r
64 //\r
65 // Allocate boot services memory for the structure. It's required to be aligned on\r
66 // a 4M boundary, so allocate a 4M block (plus what we require), free it up, calculate\r
67 // a 4M aligned address within the memory we just freed, and then allocate memory at that\r
68 // address for our initial structure.\r
69 //\r
70 NumberOfPages = FOUR_MEG_PAGES + EFI_SIZE_TO_PAGES(sizeof (EFI_SYSTEM_TABLE_POINTER)); \r
71\r
72 Status = CoreAllocatePages (AllocateAnyPages, EfiBootServicesData, NumberOfPages , &Mem); \r
73 ASSERT_EFI_ERROR (Status);\r
74 if (EFI_ERROR(Status)) {\r
75 return;\r
76 }\r
77 Status = CoreFreePages (Mem, NumberOfPages); \r
78 ASSERT_EFI_ERROR (Status);\r
79 if (EFI_ERROR(Status)) {\r
80 return;\r
81 }\r
82 //\r
83 // Now get a 4M aligned address within the memory range we were given.\r
84 // Then allocate memory at that address\r
85 //\r
86 Mem = (Mem + FOUR_MEG_MASK) & (~FOUR_MEG_MASK);\r
87 \r
88 Status = CoreAllocatePages (AllocateAddress, EfiBootServicesData, NumberOfPages - FOUR_MEG_PAGES, &Mem); \r
89 ASSERT_EFI_ERROR (Status);\r
90 if (EFI_ERROR(Status)) {\r
91 return;\r
92 }\r
93 //\r
94 // We now have a 4M aligned page allocated, so fill in the data structure.\r
95 // Ideally we would update the CRC now as well, but the service may not yet be available.\r
96 // See comments in the CoreUpdateDebugTableCrc32() function below for details.\r
97 //\r
98 mDebugTable = (EFI_SYSTEM_TABLE_POINTER *)(UINTN)Mem;\r
99 mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE;\r
100 mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gST;\r
101 mDebugTable->Crc32 = 0;\r
102 Status = CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid, &mDebugInfoTableHeader);\r
103 ASSERT_EFI_ERROR (Status);\r
104}\r
105\r
106VOID\r
107CoreUpdateDebugTableCrc32 (\r
108 VOID\r
109 )\r
110/*++\r
111\r
112Routine Description:\r
113\r
114 Update the CRC32 in the Debug Table.\r
115 Since the CRC32 service is made available by the Runtime driver, we have to\r
116 wait for the Runtime Driver to be installed before the CRC32 can be computed.\r
117 This function is called elsewhere by the core when the runtime architectural\r
118 protocol is produced.\r
119\r
120Arguments:\r
121 None\r
122\r
123Returns:\r
124 NA\r
125\r
126--*/\r
127{\r
128 ASSERT(mDebugTable != NULL);\r
129 mDebugTable->Crc32 = 0;\r
130 gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);\r
131}\r
132\r
133VOID\r
134CoreNewDebugImageInfoEntry (\r
df557cca 135 IN UINT32 ImageInfoType,\r
878ddf1f 136 IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,\r
137 IN EFI_HANDLE ImageHandle\r
138 )\r
139/*++\r
140\r
141Routine Description:\r
142\r
143 Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates\r
144 the table if it's not large enough to accomidate another entry.\r
145\r
146Arguments:\r
147\r
148 ImageInfoType - type of debug image information\r
149 LoadedImage - pointer to the loaded image protocol for the image being loaded\r
150 ImageHandle - image handle for the image being loaded\r
151\r
152Returns:\r
153 NA\r
154\r
155--*/\r
156{ \r
157 EFI_DEBUG_IMAGE_INFO *Table;\r
158 EFI_DEBUG_IMAGE_INFO *NewTable;\r
159 UINTN Index;\r
160 UINTN MaxTableIndex;\r
161 UINTN TableSize;\r
162\r
163 //\r
164 // Set the flag indicating that we're in the process of updating the table.\r
165 //\r
166 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
167\r
168 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;\r
169 MaxTableIndex = mDebugInfoTableHeader.TableSize;\r
170\r
171 for (Index = 0; Index < MaxTableIndex; Index++) {\r
172 if (Table[Index].NormalImage == NULL) {\r
173 //\r
174 // We have found a free entry so exit the loop\r
175 //\r
176 break;\r
177 }\r
178 }\r
179 if (Index == MaxTableIndex) {\r
180 //\r
181 // Table is full, so re-allocate another page for a larger table...\r
182 //\r
183 TableSize = MaxTableIndex * EFI_DEBUG_TABLE_ENTRY_SIZE;\r
184 NewTable = CoreAllocateZeroBootServicesPool (TableSize + EFI_PAGE_SIZE);\r
185 if (NewTable == NULL) {\r
186 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
187 return;\r
188 }\r
189 //\r
190 // Copy the old table into the new one\r
191 //\r
192 CopyMem (NewTable, Table, TableSize);\r
193 //\r
194 // Free the old table\r
195 //\r
196 CoreFreePool (Table);\r
197 //\r
198 // Update the table header\r
199 //\r
200 Table = NewTable;\r
201 mDebugInfoTableHeader.EfiDebugImageInfoTable = NewTable;\r
202 mDebugInfoTableHeader.TableSize += EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;\r
203 }\r
204 //\r
205 // Allocate data for new entry\r
206 //\r
207 Table[Index].NormalImage = CoreAllocateZeroBootServicesPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));\r
208 if (Table[Index].NormalImage != NULL) {\r
209 //\r
210 // Update the entry\r
211 //\r
212 Table[Index].NormalImage->ImageInfoType = (UINT32) ImageInfoType;\r
213 Table[Index].NormalImage->LoadedImageProtocolInstance = LoadedImage;\r
214 Table[Index].NormalImage->ImageHandle = ImageHandle;\r
215 }\r
216 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
217}\r
218\r
219\r
220VOID\r
221CoreRemoveDebugImageInfoEntry (\r
222 EFI_HANDLE ImageHandle\r
223 )\r
224/*++\r
225\r
226Routine Description:\r
227\r
228 Removes and frees an entry from the DebugImageInfo Table.\r
229\r
230Arguments:\r
231\r
232 ImageHandle - image handle for the image being unloaded\r
233\r
234Returns:\r
235\r
236 NA\r
237\r
238--*/\r
239{ \r
240 EFI_DEBUG_IMAGE_INFO *Table;\r
241 UINTN Index;\r
242\r
243 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
244\r
245 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;\r
246\r
247 for (Index = 0; Index < mDebugInfoTableHeader.TableSize; Index++) {\r
248 if (Table[Index].NormalImage != NULL && Table[Index].NormalImage->ImageHandle == ImageHandle) {\r
249 //\r
250 // Found a match. Free up the record, then NULL the pointer to indicate the slot\r
251 // is free.\r
252 //\r
253 CoreFreePool (Table[Index].NormalImage);\r
254 Table[Index].NormalImage = NULL;\r
255 break;\r
256 }\r
257 }\r
258 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
259}\r
260\r