2 Support functions for managing debug image info table when loading and unloading
5 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader
= {
20 0, // volatile UINT32 UpdateStatus;
21 0, // UINT32 TableSize;
22 NULL
// EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;
25 EFI_SYSTEM_TABLE_POINTER
*mDebugTable
= NULL
;
27 #define FOUR_MEG_ALIGNMENT 0x400000
29 #define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof (VOID *))
32 Creates and initializes the DebugImageInfo Table. Also creates the configuration
33 table and registers it into the system table.
37 CoreInitializeDebugImageInfoTable (
44 // Allocate 4M aligned page for the structure and fill in the data.
45 // Ideally we would update the CRC now as well, but the service may not yet be available.
46 // See comments in the CoreUpdateDebugTableCrc32() function below for details.
48 mDebugTable
= AllocateAlignedPages (EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER
)), FOUR_MEG_ALIGNMENT
);
49 mDebugTable
->Signature
= EFI_SYSTEM_TABLE_SIGNATURE
;
50 mDebugTable
->EfiSystemTableBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) gDxeCoreST
;
51 mDebugTable
->Crc32
= 0;
52 Status
= CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid
, &mDebugInfoTableHeader
);
53 ASSERT_EFI_ERROR (Status
);
58 Update the CRC32 in the Debug Table.
59 Since the CRC32 service is made available by the Runtime driver, we have to
60 wait for the Runtime Driver to be installed before the CRC32 can be computed.
61 This function is called elsewhere by the core when the runtime architectural
66 CoreUpdateDebugTableCrc32 (
70 ASSERT(mDebugTable
!= NULL
);
71 mDebugTable
->Crc32
= 0;
72 gBS
->CalculateCrc32 ((VOID
*)mDebugTable
, sizeof (EFI_SYSTEM_TABLE_POINTER
), &mDebugTable
->Crc32
);
77 Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
78 the table if it's not large enough to accomidate another entry.
80 @param ImageInfoType type of debug image information
81 @param LoadedImage pointer to the loaded image protocol for the image being
83 @param ImageHandle image handle for the image being loaded
87 CoreNewDebugImageInfoEntry (
88 IN UINT32 ImageInfoType
,
89 IN EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
,
90 IN EFI_HANDLE ImageHandle
93 EFI_DEBUG_IMAGE_INFO
*Table
;
94 EFI_DEBUG_IMAGE_INFO
*NewTable
;
100 // Set the flag indicating that we're in the process of updating the table.
102 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
104 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
105 MaxTableIndex
= mDebugInfoTableHeader
.TableSize
;
107 for (Index
= 0; Index
< MaxTableIndex
; Index
++) {
108 if (Table
[Index
].NormalImage
== NULL
) {
110 // We have found a free entry so exit the loop
115 if (Index
== MaxTableIndex
) {
117 // Table is full, so re-allocate another page for a larger table...
119 TableSize
= MaxTableIndex
* EFI_DEBUG_TABLE_ENTRY_SIZE
;
120 NewTable
= AllocateZeroPool (TableSize
+ EFI_PAGE_SIZE
);
121 if (NewTable
== NULL
) {
122 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
126 // Copy the old table into the new one
128 CopyMem (NewTable
, Table
, TableSize
);
130 // Free the old table
132 CoreFreePool (Table
);
134 // Update the table header
137 mDebugInfoTableHeader
.EfiDebugImageInfoTable
= NewTable
;
138 mDebugInfoTableHeader
.TableSize
+= EFI_PAGE_SIZE
/ EFI_DEBUG_TABLE_ENTRY_SIZE
;
141 // Allocate data for new entry
143 Table
[Index
].NormalImage
= AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL
));
144 if (Table
[Index
].NormalImage
!= NULL
) {
148 Table
[Index
].NormalImage
->ImageInfoType
= (UINT32
) ImageInfoType
;
149 Table
[Index
].NormalImage
->LoadedImageProtocolInstance
= LoadedImage
;
150 Table
[Index
].NormalImage
->ImageHandle
= ImageHandle
;
152 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
158 Removes and frees an entry from the DebugImageInfo Table.
160 @param ImageHandle image handle for the image being unloaded
164 CoreRemoveDebugImageInfoEntry (
165 EFI_HANDLE ImageHandle
168 EFI_DEBUG_IMAGE_INFO
*Table
;
171 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
173 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
175 for (Index
= 0; Index
< mDebugInfoTableHeader
.TableSize
; Index
++) {
176 if (Table
[Index
].NormalImage
!= NULL
&& Table
[Index
].NormalImage
->ImageHandle
== ImageHandle
) {
178 // Found a match. Free up the record, then NULL the pointer to indicate the slot
181 CoreFreePool (Table
[Index
].NormalImage
);
182 Table
[Index
].NormalImage
= NULL
;
186 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;