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