3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Support functions for managing debug image info table when loading and unloading
26 static EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader
= {
27 0, // volatile UINT32 UpdateStatus;
28 0, // UINT32 TableSize;
29 NULL
// EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;
32 static EFI_SYSTEM_TABLE_POINTER
*mDebugTable
= NULL
;
36 CoreInitializeDebugImageInfoTable (
43 Creates and initializes the DebugImageInfo Table. Also creates the configuration
44 table and registers it into the system table.
53 This function allocates memory, frees it, and then allocates memory at an
54 address within the initial allocation. Since this function is called early
55 in DXE core initialization (before drivers are dispatched), this should not
61 EFI_PHYSICAL_ADDRESS Mem
;
65 // Allocate boot services memory for the structure. It's required to be aligned on
66 // a 4M boundary, so allocate a 4M block (plus what we require), free it up, calculate
67 // a 4M aligned address within the memory we just freed, and then allocate memory at that
68 // address for our initial structure.
70 NumberOfPages
= FOUR_MEG_PAGES
+ EFI_SIZE_TO_PAGES(sizeof (EFI_SYSTEM_TABLE_POINTER
));
72 Status
= CoreAllocatePages (AllocateAnyPages
, EfiBootServicesData
, NumberOfPages
, &Mem
);
73 ASSERT_EFI_ERROR (Status
);
74 if (EFI_ERROR(Status
)) {
77 Status
= CoreFreePages (Mem
, NumberOfPages
);
78 ASSERT_EFI_ERROR (Status
);
79 if (EFI_ERROR(Status
)) {
83 // Now get a 4M aligned address within the memory range we were given.
84 // Then allocate memory at that address
86 Mem
= (Mem
+ FOUR_MEG_MASK
) & (~FOUR_MEG_MASK
);
88 Status
= CoreAllocatePages (AllocateAddress
, EfiBootServicesData
, NumberOfPages
- FOUR_MEG_PAGES
, &Mem
);
89 ASSERT_EFI_ERROR (Status
);
90 if (EFI_ERROR(Status
)) {
94 // We now have a 4M aligned page allocated, so fill in the data structure.
95 // Ideally we would update the CRC now as well, but the service may not yet be available.
96 // See comments in the CoreUpdateDebugTableCrc32() function below for details.
98 mDebugTable
= (EFI_SYSTEM_TABLE_POINTER
*)(UINTN
)Mem
;
99 mDebugTable
->Signature
= EFI_SYSTEM_TABLE_SIGNATURE
;
100 mDebugTable
->EfiSystemTableBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) gST
;
101 mDebugTable
->Crc32
= 0;
102 Status
= CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid
, &mDebugInfoTableHeader
);
103 ASSERT_EFI_ERROR (Status
);
107 CoreUpdateDebugTableCrc32 (
114 Update the CRC32 in the Debug Table.
115 Since the CRC32 service is made available by the Runtime driver, we have to
116 wait for the Runtime Driver to be installed before the CRC32 can be computed.
117 This function is called elsewhere by the core when the runtime architectural
118 protocol is produced.
128 ASSERT(mDebugTable
!= NULL
);
129 mDebugTable
->Crc32
= 0;
130 gBS
->CalculateCrc32 ((VOID
*)mDebugTable
, sizeof (EFI_SYSTEM_TABLE_POINTER
), &mDebugTable
->Crc32
);
134 CoreNewDebugImageInfoEntry (
135 IN UINTN ImageInfoType
,
136 IN EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
,
137 IN EFI_HANDLE ImageHandle
143 Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
144 the table if it's not large enough to accomidate another entry.
148 ImageInfoType - type of debug image information
149 LoadedImage - pointer to the loaded image protocol for the image being loaded
150 ImageHandle - image handle for the image being loaded
157 EFI_DEBUG_IMAGE_INFO
*Table
;
158 EFI_DEBUG_IMAGE_INFO
*NewTable
;
164 // Set the flag indicating that we're in the process of updating the table.
166 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
168 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
169 MaxTableIndex
= mDebugInfoTableHeader
.TableSize
;
171 for (Index
= 0; Index
< MaxTableIndex
; Index
++) {
172 if (Table
[Index
].NormalImage
== NULL
) {
174 // We have found a free entry so exit the loop
179 if (Index
== MaxTableIndex
) {
181 // Table is full, so re-allocate another page for a larger table...
183 TableSize
= MaxTableIndex
* EFI_DEBUG_TABLE_ENTRY_SIZE
;
184 NewTable
= CoreAllocateZeroBootServicesPool (TableSize
+ EFI_PAGE_SIZE
);
185 if (NewTable
== NULL
) {
186 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
190 // Copy the old table into the new one
192 CopyMem (NewTable
, Table
, TableSize
);
194 // Free the old table
196 CoreFreePool (Table
);
198 // Update the table header
201 mDebugInfoTableHeader
.EfiDebugImageInfoTable
= NewTable
;
202 mDebugInfoTableHeader
.TableSize
+= EFI_PAGE_SIZE
/ EFI_DEBUG_TABLE_ENTRY_SIZE
;
205 // Allocate data for new entry
207 Table
[Index
].NormalImage
= CoreAllocateZeroBootServicesPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL
));
208 if (Table
[Index
].NormalImage
!= NULL
) {
212 Table
[Index
].NormalImage
->ImageInfoType
= (UINT32
) ImageInfoType
;
213 Table
[Index
].NormalImage
->LoadedImageProtocolInstance
= LoadedImage
;
214 Table
[Index
].NormalImage
->ImageHandle
= ImageHandle
;
216 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
221 CoreRemoveDebugImageInfoEntry (
222 EFI_HANDLE ImageHandle
228 Removes and frees an entry from the DebugImageInfo Table.
232 ImageHandle - image handle for the image being unloaded
240 EFI_DEBUG_IMAGE_INFO
*Table
;
243 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
245 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
247 for (Index
= 0; Index
< mDebugInfoTableHeader
.TableSize
; Index
++) {
248 if (Table
[Index
].NormalImage
!= NULL
&& Table
[Index
].NormalImage
->ImageHandle
== ImageHandle
) {
250 // Found a match. Free up the record, then NULL the pointer to indicate the slot
253 CoreFreePool (Table
[Index
].NormalImage
);
254 Table
[Index
].NormalImage
= NULL
;
258 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;