]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
Update the copyright notice format
[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. All rights reserved.<BR>\r
6This 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 ASSERT (mDebugTable != NULL);\r
52 mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE;\r
53 mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gDxeCoreST;\r
54 mDebugTable->Crc32 = 0;\r
55 Status = CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid, &mDebugInfoTableHeader);\r
56 ASSERT_EFI_ERROR (Status);\r
57}\r
58\r
59\r
60/**\r
61 Update the CRC32 in the Debug Table.\r
62 Since the CRC32 service is made available by the Runtime driver, we have to\r
63 wait for the Runtime Driver to be installed before the CRC32 can be computed.\r
64 This function is called elsewhere by the core when the runtime architectural\r
65 protocol is produced.\r
66\r
67**/\r
68VOID\r
69CoreUpdateDebugTableCrc32 (\r
70 VOID\r
71 )\r
72{\r
73 ASSERT(mDebugTable != NULL);\r
74 mDebugTable->Crc32 = 0;\r
75 gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);\r
76}\r
77\r
78\r
79/**\r
80 Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates\r
81 the table if it's not large enough to accomidate another entry.\r
82\r
83 @param ImageInfoType type of debug image information\r
84 @param LoadedImage pointer to the loaded image protocol for the image being\r
85 loaded\r
86 @param ImageHandle image handle for the image being loaded\r
87\r
88**/\r
89VOID\r
90CoreNewDebugImageInfoEntry (\r
91 IN UINT32 ImageInfoType,\r
92 IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,\r
93 IN EFI_HANDLE ImageHandle\r
94 )\r
95{\r
96 EFI_DEBUG_IMAGE_INFO *Table;\r
97 EFI_DEBUG_IMAGE_INFO *NewTable;\r
98 UINTN Index;\r
99 UINTN TableSize;\r
100\r
101 //\r
102 // Set the flag indicating that we're in the process of updating the table.\r
103 //\r
104 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
105\r
106 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;\r
107 \r
108 if (mDebugInfoTableHeader.TableSize < mMaxTableEntries) {\r
109 //\r
110 // We still have empty entires in the Table, find the first empty entry.\r
111 //\r
112 Index = 0;\r
113 while (Table[Index].NormalImage != NULL) {\r
114 Index++;\r
115 }\r
116 //\r
117 // There must be an empty entry in the in the table.\r
118 //\r
119 ASSERT (Index < mMaxTableEntries);\r
120 } else {\r
121 //\r
122 // Table is full, so re-allocate another page for a larger table...\r
123 //\r
124 TableSize = mMaxTableEntries * EFI_DEBUG_TABLE_ENTRY_SIZE;\r
125 NewTable = AllocateZeroPool (TableSize + EFI_PAGE_SIZE);\r
126 if (NewTable == NULL) {\r
127 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
128 return;\r
129 }\r
130 //\r
131 // Copy the old table into the new one\r
132 //\r
133 CopyMem (NewTable, Table, TableSize);\r
134 //\r
135 // Free the old table\r
136 //\r
137 CoreFreePool (Table);\r
138 //\r
139 // Update the table header\r
140 //\r
141 Table = NewTable;\r
142 mDebugInfoTableHeader.EfiDebugImageInfoTable = NewTable;\r
143 //\r
144 // Enlarge the max table entries and set the first empty entry index to\r
145 // be the original max table entries.\r
146 //\r
147 Index = mMaxTableEntries;\r
148 mMaxTableEntries += EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;\r
149 }\r
150\r
151 //\r
152 // Allocate data for new entry\r
153 //\r
154 Table[Index].NormalImage = AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));\r
155 if (Table[Index].NormalImage != NULL) {\r
156 //\r
157 // Update the entry\r
158 //\r
159 Table[Index].NormalImage->ImageInfoType = (UINT32) ImageInfoType;\r
160 Table[Index].NormalImage->LoadedImageProtocolInstance = LoadedImage;\r
161 Table[Index].NormalImage->ImageHandle = ImageHandle;\r
162 //\r
163 // Increase the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.\r
164 //\r
165 mDebugInfoTableHeader.TableSize++;\r
166 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;\r
167 }\r
168 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
169}\r
170\r
171\r
172\r
173/**\r
174 Removes and frees an entry from the DebugImageInfo Table.\r
175\r
176 @param ImageHandle image handle for the image being unloaded\r
177\r
178**/\r
179VOID\r
180CoreRemoveDebugImageInfoEntry (\r
181 EFI_HANDLE ImageHandle\r
182 )\r
183{\r
184 EFI_DEBUG_IMAGE_INFO *Table;\r
185 UINTN Index;\r
186\r
187 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
188\r
189 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;\r
190\r
191 for (Index = 0; Index < mMaxTableEntries; Index++) {\r
192 if (Table[Index].NormalImage != NULL && Table[Index].NormalImage->ImageHandle == ImageHandle) {\r
193 //\r
194 // Found a match. Free up the record, then NULL the pointer to indicate the slot\r
195 // is free.\r
196 //\r
197 CoreFreePool (Table[Index].NormalImage);\r
198 Table[Index].NormalImage = NULL;\r
199 //\r
200 // Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.\r
201 //\r
202 mDebugInfoTableHeader.TableSize--;\r
203 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;\r
204 break;\r
205 }\r
206 }\r
207 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
208}\r
209\r
210\r