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