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 STATIC EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader
= {
20 0, // volatile UINT32 UpdateStatus;
21 0, // UINT32 TableSize;
22 NULL
// EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;
25 STATIC EFI_SYSTEM_TABLE_POINTER
*mDebugTable
= NULL
;
30 Creates and initializes the DebugImageInfo Table. Also creates the configuration
31 table and registers it into the system table.
34 This function allocates memory, frees it, and then allocates memory at an
35 address within the initial allocation. Since this function is called early
36 in DXE core initialization (before drivers are dispatched), this should not
41 CoreInitializeDebugImageInfoTable (
46 EFI_PHYSICAL_ADDRESS Mem
;
50 // Allocate boot services memory for the structure. It's required to be aligned on
51 // a 4M boundary, so allocate a 4M block (plus what we require), free it up, calculate
52 // a 4M aligned address within the memory we just freed, and then allocate memory at that
53 // address for our initial structure.
55 NumberOfPages
= FOUR_MEG_PAGES
+ EFI_SIZE_TO_PAGES(sizeof (EFI_SYSTEM_TABLE_POINTER
));
57 Status
= CoreAllocatePages (AllocateAnyPages
, EfiBootServicesData
, NumberOfPages
, &Mem
);
58 ASSERT_EFI_ERROR (Status
);
59 if (EFI_ERROR(Status
)) {
62 Status
= CoreFreePages (Mem
, NumberOfPages
);
63 ASSERT_EFI_ERROR (Status
);
64 if (EFI_ERROR(Status
)) {
68 // Now get a 4M aligned address within the memory range we were given.
69 // Then allocate memory at that address
71 Mem
= (Mem
+ FOUR_MEG_MASK
) & (~FOUR_MEG_MASK
);
73 Status
= CoreAllocatePages (AllocateAddress
, EfiBootServicesData
, NumberOfPages
- FOUR_MEG_PAGES
, &Mem
);
74 ASSERT_EFI_ERROR (Status
);
75 if (EFI_ERROR(Status
)) {
79 // We now have a 4M aligned page allocated, so fill in the data structure.
80 // Ideally we would update the CRC now as well, but the service may not yet be available.
81 // See comments in the CoreUpdateDebugTableCrc32() function below for details.
83 mDebugTable
= (EFI_SYSTEM_TABLE_POINTER
*)(UINTN
)Mem
;
84 mDebugTable
->Signature
= EFI_SYSTEM_TABLE_SIGNATURE
;
85 mDebugTable
->EfiSystemTableBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) gDxeCoreST
;
86 mDebugTable
->Crc32
= 0;
87 Status
= CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid
, &mDebugInfoTableHeader
);
88 ASSERT_EFI_ERROR (Status
);
93 Update the CRC32 in the Debug Table.
94 Since the CRC32 service is made available by the Runtime driver, we have to
95 wait for the Runtime Driver to be installed before the CRC32 can be computed.
96 This function is called elsewhere by the core when the runtime architectural
101 CoreUpdateDebugTableCrc32 (
105 ASSERT(mDebugTable
!= NULL
);
106 mDebugTable
->Crc32
= 0;
107 gDxeCoreBS
->CalculateCrc32 ((VOID
*)mDebugTable
, sizeof (EFI_SYSTEM_TABLE_POINTER
), &mDebugTable
->Crc32
);
112 Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
113 the table if it's not large enough to accomidate another entry.
115 @param ImageInfoType type of debug image information
116 @param LoadedImage pointer to the loaded image protocol for the image being
118 @param ImageHandle image handle for the image being loaded
122 CoreNewDebugImageInfoEntry (
123 IN UINT32 ImageInfoType
,
124 IN EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
,
125 IN EFI_HANDLE ImageHandle
128 EFI_DEBUG_IMAGE_INFO
*Table
;
129 EFI_DEBUG_IMAGE_INFO
*NewTable
;
135 // Set the flag indicating that we're in the process of updating the table.
137 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
139 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
140 MaxTableIndex
= mDebugInfoTableHeader
.TableSize
;
142 for (Index
= 0; Index
< MaxTableIndex
; Index
++) {
143 if (Table
[Index
].NormalImage
== NULL
) {
145 // We have found a free entry so exit the loop
150 if (Index
== MaxTableIndex
) {
152 // Table is full, so re-allocate another page for a larger table...
154 TableSize
= MaxTableIndex
* EFI_DEBUG_TABLE_ENTRY_SIZE
;
155 NewTable
= CoreAllocateZeroBootServicesPool (TableSize
+ EFI_PAGE_SIZE
);
156 if (NewTable
== NULL
) {
157 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
161 // Copy the old table into the new one
163 CopyMem (NewTable
, Table
, TableSize
);
165 // Free the old table
167 CoreFreePool (Table
);
169 // Update the table header
172 mDebugInfoTableHeader
.EfiDebugImageInfoTable
= NewTable
;
173 mDebugInfoTableHeader
.TableSize
+= EFI_PAGE_SIZE
/ EFI_DEBUG_TABLE_ENTRY_SIZE
;
176 // Allocate data for new entry
178 Table
[Index
].NormalImage
= CoreAllocateZeroBootServicesPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL
));
179 if (Table
[Index
].NormalImage
!= NULL
) {
183 Table
[Index
].NormalImage
->ImageInfoType
= (UINT32
) ImageInfoType
;
184 Table
[Index
].NormalImage
->LoadedImageProtocolInstance
= LoadedImage
;
185 Table
[Index
].NormalImage
->ImageHandle
= ImageHandle
;
187 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
193 Removes and frees an entry from the DebugImageInfo Table.
195 @param ImageHandle image handle for the image being unloaded
199 CoreRemoveDebugImageInfoEntry (
200 EFI_HANDLE ImageHandle
203 EFI_DEBUG_IMAGE_INFO
*Table
;
206 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
208 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
210 for (Index
= 0; Index
< mDebugInfoTableHeader
.TableSize
; Index
++) {
211 if (Table
[Index
].NormalImage
!= NULL
&& Table
[Index
].NormalImage
->ImageHandle
== ImageHandle
) {
213 // Found a match. Free up the record, then NULL the pointer to indicate the slot
216 CoreFreePool (Table
[Index
].NormalImage
);
217 Table
[Index
].NormalImage
= NULL
;
221 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;