]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
Change PeiMain/DxeMain's base name to PeiCore/DxeCore.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / DebugImageInfo.c
... / ...
CommitLineData
1/** @file\r
2 Support functions for managing debug image info table when loading and unloading\r
3 images.\r
4\r
5Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "DxeMain.h"\r
17\r
18\r
19EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader = {\r
20 0, // volatile UINT32 UpdateStatus;\r
21 0, // UINT32 TableSize;\r
22 NULL // EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;\r
23};\r
24\r
25UINTN mMaxTableEntries = 0;\r
26\r
27EFI_SYSTEM_TABLE_POINTER *mDebugTable = NULL;\r
28\r
29#define FOUR_MEG_ALIGNMENT 0x400000\r
30\r
31#define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof (VOID *))\r
32\r
33/**\r
34 Creates and initializes the DebugImageInfo Table. Also creates the configuration\r
35 table and registers it into the system table.\r
36\r
37**/\r
38VOID\r
39CoreInitializeDebugImageInfoTable (\r
40 VOID\r
41 )\r
42{\r
43 EFI_STATUS Status;\r
44\r
45 //\r
46 // Allocate 4M aligned page for the structure and fill in the data.\r
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
50 mDebugTable = AllocateAlignedPages (EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER)), FOUR_MEG_ALIGNMENT); \r
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
58\r
59/**\r
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
66**/\r
67VOID\r
68CoreUpdateDebugTableCrc32 (\r
69 VOID\r
70 )\r
71{\r
72 ASSERT(mDebugTable != NULL);\r
73 mDebugTable->Crc32 = 0;\r
74 gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);\r
75}\r
76\r
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
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
85 @param ImageHandle image handle for the image being loaded\r
86\r
87**/\r
88VOID\r
89CoreNewDebugImageInfoEntry (\r
90 IN UINT32 ImageInfoType,\r
91 IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,\r
92 IN EFI_HANDLE ImageHandle\r
93 )\r
94{\r
95 EFI_DEBUG_IMAGE_INFO *Table;\r
96 EFI_DEBUG_IMAGE_INFO *NewTable;\r
97 UINTN Index;\r
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
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
114 }\r
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
120 //\r
121 // Table is full, so re-allocate another page for a larger table...\r
122 //\r
123 TableSize = mMaxTableEntries * EFI_DEBUG_TABLE_ENTRY_SIZE;\r
124 NewTable = AllocateZeroPool (TableSize + EFI_PAGE_SIZE);\r
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
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
148 }\r
149\r
150 //\r
151 // Allocate data for new entry\r
152 //\r
153 Table[Index].NormalImage = AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));\r
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
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
166 }\r
167 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
168}\r
169\r
170\r
171\r
172/**\r
173 Removes and frees an entry from the DebugImageInfo Table.\r
174\r
175 @param ImageHandle image handle for the image being unloaded\r
176\r
177**/\r
178VOID\r
179CoreRemoveDebugImageInfoEntry (\r
180 EFI_HANDLE ImageHandle\r
181 )\r
182{\r
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
190 for (Index = 0; Index < mMaxTableEntries; Index++) {\r
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
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
203 break;\r
204 }\r
205 }\r
206 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
207}\r
208\r
209\r