]>
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 |
9c4ac31c | 16 | #include "DxeMain.h"\r |
28a00297 | 17 | \r |
18 | \r | |
e94a9ff7 | 19 | 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 | |
2f2a277d | 25 | UINTN mMaxTableEntries = 0;\r |
26 | \r | |
e94a9ff7 | 27 | EFI_SYSTEM_TABLE_POINTER *mDebugTable = NULL;\r |
28a00297 | 28 | \r |
ec90508b | 29 | #define FOUR_MEG_ALIGNMENT 0x400000\r |
022c6d45 | 30 | \r |
ec90508b | 31 | #define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof (VOID *))\r |
28a00297 | 32 | \r |
162ed594 | 33 | /**\r |
28a00297 | 34 | Creates and initializes the DebugImageInfo Table. Also creates the configuration\r |
35 | table and registers it into the system table.\r | |
36 | \r | |
162ed594 | 37 | **/\r |
38 | VOID\r | |
39 | CoreInitializeDebugImageInfoTable (\r | |
40 | VOID\r | |
41 | )\r | |
022c6d45 | 42 | {\r |
28a00297 | 43 | EFI_STATUS Status;\r |
022c6d45 | 44 | \r |
28a00297 | 45 | //\r |
19e14fc9 | 46 | // Allocate 4M aligned page for the structure and fill in the data.\r |
28a00297 | 47 | // Ideally we would update the CRC now as well, but the service may not yet be available.\r |
48 | // See comments in the CoreUpdateDebugTableCrc32() function below for details.\r | |
49 | //\r | |
19e14fc9 | 50 | mDebugTable = AllocateAlignedPages (EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER)), FOUR_MEG_ALIGNMENT); \r |
28a00297 | 51 | mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE;\r |
52 | mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gDxeCoreST;\r | |
53 | mDebugTable->Crc32 = 0;\r | |
54 | Status = CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid, &mDebugInfoTableHeader);\r | |
55 | ASSERT_EFI_ERROR (Status);\r | |
56 | }\r | |
57 | \r | |
28a00297 | 58 | \r |
162ed594 | 59 | /**\r |
28a00297 | 60 | Update the CRC32 in the Debug Table.\r |
61 | Since the CRC32 service is made available by the Runtime driver, we have to\r | |
62 | wait for the Runtime Driver to be installed before the CRC32 can be computed.\r | |
63 | This function is called elsewhere by the core when the runtime architectural\r | |
64 | protocol is produced.\r | |
65 | \r | |
162ed594 | 66 | **/\r |
67 | VOID\r | |
68 | CoreUpdateDebugTableCrc32 (\r | |
69 | VOID\r | |
70 | )\r | |
28a00297 | 71 | {\r |
72 | ASSERT(mDebugTable != NULL);\r | |
73 | mDebugTable->Crc32 = 0;\r | |
0e9b156d | 74 | gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);\r |
28a00297 | 75 | }\r |
76 | \r | |
162ed594 | 77 | \r |
78 | /**\r | |
79 | Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates\r | |
80 | the table if it's not large enough to accomidate another entry.\r | |
81 | \r | |
022c6d45 | 82 | @param ImageInfoType type of debug image information\r |
83 | @param LoadedImage pointer to the loaded image protocol for the image being\r | |
84 | loaded\r | |
162ed594 | 85 | @param ImageHandle image handle for the image being loaded\r |
86 | \r | |
87 | **/\r | |
28a00297 | 88 | VOID\r |
89 | CoreNewDebugImageInfoEntry (\r | |
90 | IN UINT32 ImageInfoType,\r | |
91 | IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,\r | |
92 | IN EFI_HANDLE ImageHandle\r | |
93 | )\r | |
022c6d45 | 94 | {\r |
28a00297 | 95 | EFI_DEBUG_IMAGE_INFO *Table;\r |
96 | EFI_DEBUG_IMAGE_INFO *NewTable;\r | |
97 | UINTN Index;\r | |
28a00297 | 98 | UINTN TableSize;\r |
99 | \r | |
100 | //\r | |
101 | // Set the flag indicating that we're in the process of updating the table.\r | |
102 | //\r | |
103 | mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r | |
104 | \r | |
105 | Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;\r | |
2f2a277d | 106 | \r |
107 | if (mDebugInfoTableHeader.TableSize < mMaxTableEntries) {\r | |
108 | //\r | |
109 | // We still have empty entires in the Table, find the first empty entry.\r | |
110 | //\r | |
111 | Index = 0;\r | |
112 | while (Table[Index].NormalImage != NULL) {\r | |
113 | Index++;\r | |
28a00297 | 114 | }\r |
2f2a277d | 115 | //\r |
116 | // There must be an empty entry in the in the table.\r | |
117 | //\r | |
118 | ASSERT (Index < mMaxTableEntries);\r | |
119 | } else {\r | |
28a00297 | 120 | //\r |
121 | // Table is full, so re-allocate another page for a larger table...\r | |
122 | //\r | |
2f2a277d | 123 | TableSize = mMaxTableEntries * EFI_DEBUG_TABLE_ENTRY_SIZE;\r |
9c4ac31c | 124 | NewTable = AllocateZeroPool (TableSize + EFI_PAGE_SIZE);\r |
28a00297 | 125 | if (NewTable == NULL) {\r |
126 | mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r | |
127 | return;\r | |
128 | }\r | |
129 | //\r | |
130 | // Copy the old table into the new one\r | |
131 | //\r | |
132 | CopyMem (NewTable, Table, TableSize);\r | |
133 | //\r | |
134 | // Free the old table\r | |
135 | //\r | |
136 | CoreFreePool (Table);\r | |
137 | //\r | |
138 | // Update the table header\r | |
139 | //\r | |
140 | Table = NewTable;\r | |
141 | mDebugInfoTableHeader.EfiDebugImageInfoTable = NewTable;\r | |
2f2a277d | 142 | //\r |
143 | // Enlarge the max table entries and set the first empty entry index to\r | |
144 | // be the original max table entries.\r | |
145 | //\r | |
146 | Index = mMaxTableEntries;\r | |
147 | mMaxTableEntries += EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;\r | |
28a00297 | 148 | }\r |
2f2a277d | 149 | \r |
28a00297 | 150 | //\r |
151 | // Allocate data for new entry\r | |
152 | //\r | |
9c4ac31c | 153 | Table[Index].NormalImage = AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));\r |
28a00297 | 154 | if (Table[Index].NormalImage != NULL) {\r |
155 | //\r | |
156 | // Update the entry\r | |
157 | //\r | |
158 | Table[Index].NormalImage->ImageInfoType = (UINT32) ImageInfoType;\r | |
159 | Table[Index].NormalImage->LoadedImageProtocolInstance = LoadedImage;\r | |
160 | Table[Index].NormalImage->ImageHandle = ImageHandle;\r | |
2f2a277d | 161 | //\r |
162 | // Increase the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.\r | |
163 | //\r | |
164 | mDebugInfoTableHeader.TableSize++;\r | |
165 | mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;\r | |
28a00297 | 166 | }\r |
167 | mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r | |
168 | }\r | |
169 | \r | |
170 | \r | |
28a00297 | 171 | \r |
162ed594 | 172 | /**\r |
28a00297 | 173 | Removes and frees an entry from the DebugImageInfo Table.\r |
174 | \r | |
162ed594 | 175 | @param ImageHandle image handle for the image being unloaded\r |
28a00297 | 176 | \r |
162ed594 | 177 | **/\r |
178 | VOID\r | |
179 | CoreRemoveDebugImageInfoEntry (\r | |
180 | EFI_HANDLE ImageHandle\r | |
181 | )\r | |
022c6d45 | 182 | {\r |
28a00297 | 183 | EFI_DEBUG_IMAGE_INFO *Table;\r |
184 | UINTN Index;\r | |
185 | \r | |
186 | mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r | |
187 | \r | |
188 | Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;\r | |
189 | \r | |
2f2a277d | 190 | for (Index = 0; Index < mMaxTableEntries; Index++) {\r |
28a00297 | 191 | if (Table[Index].NormalImage != NULL && Table[Index].NormalImage->ImageHandle == ImageHandle) {\r |
192 | //\r | |
193 | // Found a match. Free up the record, then NULL the pointer to indicate the slot\r | |
194 | // is free.\r | |
195 | //\r | |
196 | CoreFreePool (Table[Index].NormalImage);\r | |
197 | Table[Index].NormalImage = NULL;\r | |
2f2a277d | 198 | //\r |
199 | // Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.\r | |
200 | //\r | |
201 | mDebugInfoTableHeader.TableSize--;\r | |
202 | mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;\r | |
28a00297 | 203 | break;\r |
204 | }\r | |
205 | }\r | |
206 | mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r | |
207 | }\r | |
208 | \r | |
162ed594 | 209 | \r |