]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / DebugImageInfo.c
CommitLineData
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
cd5ebaa0
HT
5Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
23c98c94 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
28a00297 13\r
504214c4 14**/\r
28a00297 15\r
9c4ac31c 16#include "DxeMain.h"\r
28a00297 17\r
18\r
e94a9ff7 19EFI_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 25UINTN mMaxTableEntries = 0;\r
26\r
e94a9ff7 27EFI_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
38VOID\r
39CoreInitializeDebugImageInfoTable (\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
b364eeb0 51 ASSERT (mDebugTable != NULL);\r
28a00297 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
28a00297 59\r
162ed594 60/**\r
28a00297 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
162ed594 67**/\r
68VOID\r
69CoreUpdateDebugTableCrc32 (\r
70 VOID\r
71 )\r
28a00297 72{\r
73 ASSERT(mDebugTable != NULL);\r
74 mDebugTable->Crc32 = 0;\r
0e9b156d 75 gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);\r
28a00297 76}\r
77\r
162ed594 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
022c6d45 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
162ed594 86 @param ImageHandle image handle for the image being loaded\r
87\r
88**/\r
28a00297 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
022c6d45 95{\r
28a00297 96 EFI_DEBUG_IMAGE_INFO *Table;\r
97 EFI_DEBUG_IMAGE_INFO *NewTable;\r
98 UINTN Index;\r
28a00297 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
2f2a277d 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
28a00297 115 }\r
2f2a277d 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
28a00297 121 //\r
122 // Table is full, so re-allocate another page for a larger table...\r
123 //\r
2f2a277d 124 TableSize = mMaxTableEntries * EFI_DEBUG_TABLE_ENTRY_SIZE;\r
9c4ac31c 125 NewTable = AllocateZeroPool (TableSize + EFI_PAGE_SIZE);\r
28a00297 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
2f2a277d 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
28a00297 149 }\r
2f2a277d 150\r
28a00297 151 //\r
152 // Allocate data for new entry\r
153 //\r
9c4ac31c 154 Table[Index].NormalImage = AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));\r
28a00297 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
2f2a277d 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
28a00297 167 }\r
168 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
169}\r
170\r
171\r
28a00297 172\r
162ed594 173/**\r
28a00297 174 Removes and frees an entry from the DebugImageInfo Table.\r
175\r
162ed594 176 @param ImageHandle image handle for the image being unloaded\r
28a00297 177\r
162ed594 178**/\r
179VOID\r
180CoreRemoveDebugImageInfoEntry (\r
181 EFI_HANDLE ImageHandle\r
182 )\r
022c6d45 183{\r
28a00297 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
2f2a277d 191 for (Index = 0; Index < mMaxTableEntries; Index++) {\r
28a00297 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
2f2a277d 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
28a00297 204 break;\r
205 }\r
206 }\r
207 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;\r
208}\r
209\r
162ed594 210\r