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