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