]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
Add comments and DoxyGen format for these files.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / DebugImageInfo.c
1 /** @file
2
3 Support functions for managing debug image info table when loading and unloading
4 images.
5
6 Copyright (c) 2006 - 2008, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include <DxeMain.h>
18
19
20 static EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader = {
21 0, // volatile UINT32 UpdateStatus;
22 0, // UINT32 TableSize;
23 NULL // EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;
24 };
25
26 static EFI_SYSTEM_TABLE_POINTER *mDebugTable = NULL;
27
28
29 VOID
30 CoreInitializeDebugImageInfoTable (
31 VOID
32 )
33 /*++
34
35 Routine Description:
36
37 Creates and initializes the DebugImageInfo Table. Also creates the configuration
38 table and registers it into the system table.
39
40 Arguments:
41 None
42
43 Returns:
44 NA
45
46 Notes:
47 This function allocates memory, frees it, and then allocates memory at an
48 address within the initial allocation. Since this function is called early
49 in DXE core initialization (before drivers are dispatched), this should not
50 be a problem.
51
52 --*/
53 {
54 EFI_STATUS Status;
55 EFI_PHYSICAL_ADDRESS Mem;
56 UINTN NumberOfPages;
57
58 //
59 // Allocate boot services memory for the structure. It's required to be aligned on
60 // a 4M boundary, so allocate a 4M block (plus what we require), free it up, calculate
61 // a 4M aligned address within the memory we just freed, and then allocate memory at that
62 // address for our initial structure.
63 //
64 NumberOfPages = FOUR_MEG_PAGES + EFI_SIZE_TO_PAGES(sizeof (EFI_SYSTEM_TABLE_POINTER));
65
66 Status = CoreAllocatePages (AllocateAnyPages, EfiBootServicesData, NumberOfPages , &Mem);
67 ASSERT_EFI_ERROR (Status);
68 if (EFI_ERROR(Status)) {
69 return;
70 }
71 Status = CoreFreePages (Mem, NumberOfPages);
72 ASSERT_EFI_ERROR (Status);
73 if (EFI_ERROR(Status)) {
74 return;
75 }
76 //
77 // Now get a 4M aligned address within the memory range we were given.
78 // Then allocate memory at that address
79 //
80 Mem = (Mem + FOUR_MEG_MASK) & (~FOUR_MEG_MASK);
81
82 Status = CoreAllocatePages (AllocateAddress, EfiBootServicesData, NumberOfPages - FOUR_MEG_PAGES, &Mem);
83 ASSERT_EFI_ERROR (Status);
84 if (EFI_ERROR(Status)) {
85 return;
86 }
87 //
88 // We now have a 4M aligned page allocated, so fill in the data structure.
89 // Ideally we would update the CRC now as well, but the service may not yet be available.
90 // See comments in the CoreUpdateDebugTableCrc32() function below for details.
91 //
92 mDebugTable = (EFI_SYSTEM_TABLE_POINTER *)(UINTN)Mem;
93 mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE;
94 mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gDxeCoreST;
95 mDebugTable->Crc32 = 0;
96 Status = CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid, &mDebugInfoTableHeader);
97 ASSERT_EFI_ERROR (Status);
98 }
99
100 VOID
101 CoreUpdateDebugTableCrc32 (
102 VOID
103 )
104 /*++
105
106 Routine Description:
107
108 Update the CRC32 in the Debug Table.
109 Since the CRC32 service is made available by the Runtime driver, we have to
110 wait for the Runtime Driver to be installed before the CRC32 can be computed.
111 This function is called elsewhere by the core when the runtime architectural
112 protocol is produced.
113
114 Arguments:
115 None
116
117 Returns:
118 NA
119
120 --*/
121 {
122 ASSERT(mDebugTable != NULL);
123 mDebugTable->Crc32 = 0;
124 gDxeCoreBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);
125 }
126
127 VOID
128 CoreNewDebugImageInfoEntry (
129 IN UINT32 ImageInfoType,
130 IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
131 IN EFI_HANDLE ImageHandle
132 )
133 /*++
134
135 Routine Description:
136
137 Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
138 the table if it's not large enough to accomidate another entry.
139
140 Arguments:
141
142 ImageInfoType - type of debug image information
143 LoadedImage - pointer to the loaded image protocol for the image being loaded
144 ImageHandle - image handle for the image being loaded
145
146 Returns:
147 NA
148
149 --*/
150 {
151 EFI_DEBUG_IMAGE_INFO *Table;
152 EFI_DEBUG_IMAGE_INFO *NewTable;
153 UINTN Index;
154 UINTN MaxTableIndex;
155 UINTN TableSize;
156
157 //
158 // Set the flag indicating that we're in the process of updating the table.
159 //
160 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
161
162 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
163 MaxTableIndex = mDebugInfoTableHeader.TableSize;
164
165 for (Index = 0; Index < MaxTableIndex; Index++) {
166 if (Table[Index].NormalImage == NULL) {
167 //
168 // We have found a free entry so exit the loop
169 //
170 break;
171 }
172 }
173 if (Index == MaxTableIndex) {
174 //
175 // Table is full, so re-allocate another page for a larger table...
176 //
177 TableSize = MaxTableIndex * EFI_DEBUG_TABLE_ENTRY_SIZE;
178 NewTable = CoreAllocateZeroBootServicesPool (TableSize + EFI_PAGE_SIZE);
179 if (NewTable == NULL) {
180 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
181 return;
182 }
183 //
184 // Copy the old table into the new one
185 //
186 CopyMem (NewTable, Table, TableSize);
187 //
188 // Free the old table
189 //
190 CoreFreePool (Table);
191 //
192 // Update the table header
193 //
194 Table = NewTable;
195 mDebugInfoTableHeader.EfiDebugImageInfoTable = NewTable;
196 mDebugInfoTableHeader.TableSize += EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;
197 }
198 //
199 // Allocate data for new entry
200 //
201 Table[Index].NormalImage = CoreAllocateZeroBootServicesPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));
202 if (Table[Index].NormalImage != NULL) {
203 //
204 // Update the entry
205 //
206 Table[Index].NormalImage->ImageInfoType = (UINT32) ImageInfoType;
207 Table[Index].NormalImage->LoadedImageProtocolInstance = LoadedImage;
208 Table[Index].NormalImage->ImageHandle = ImageHandle;
209 }
210 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
211 }
212
213
214 VOID
215 CoreRemoveDebugImageInfoEntry (
216 EFI_HANDLE ImageHandle
217 )
218 /*++
219
220 Routine Description:
221
222 Removes and frees an entry from the DebugImageInfo Table.
223
224 Arguments:
225
226 ImageHandle - image handle for the image being unloaded
227
228 Returns:
229
230 NA
231
232 --*/
233 {
234 EFI_DEBUG_IMAGE_INFO *Table;
235 UINTN Index;
236
237 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
238
239 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
240
241 for (Index = 0; Index < mDebugInfoTableHeader.TableSize; Index++) {
242 if (Table[Index].NormalImage != NULL && Table[Index].NormalImage->ImageHandle == ImageHandle) {
243 //
244 // Found a match. Free up the record, then NULL the pointer to indicate the slot
245 // is free.
246 //
247 CoreFreePool (Table[Index].NormalImage);
248 Table[Index].NormalImage = NULL;
249 break;
250 }
251 }
252 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
253 }
254