3 Support functions for managing debug image info table when loading and unloading
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
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.
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;
26 static EFI_SYSTEM_TABLE_POINTER
*mDebugTable
= NULL
;
30 CoreInitializeDebugImageInfoTable (
37 Creates and initializes the DebugImageInfo Table. Also creates the configuration
38 table and registers it into the system table.
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
55 EFI_PHYSICAL_ADDRESS Mem
;
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.
64 NumberOfPages
= FOUR_MEG_PAGES
+ EFI_SIZE_TO_PAGES(sizeof (EFI_SYSTEM_TABLE_POINTER
));
66 Status
= CoreAllocatePages (AllocateAnyPages
, EfiBootServicesData
, NumberOfPages
, &Mem
);
67 ASSERT_EFI_ERROR (Status
);
68 if (EFI_ERROR(Status
)) {
71 Status
= CoreFreePages (Mem
, NumberOfPages
);
72 ASSERT_EFI_ERROR (Status
);
73 if (EFI_ERROR(Status
)) {
77 // Now get a 4M aligned address within the memory range we were given.
78 // Then allocate memory at that address
80 Mem
= (Mem
+ FOUR_MEG_MASK
) & (~FOUR_MEG_MASK
);
82 Status
= CoreAllocatePages (AllocateAddress
, EfiBootServicesData
, NumberOfPages
- FOUR_MEG_PAGES
, &Mem
);
83 ASSERT_EFI_ERROR (Status
);
84 if (EFI_ERROR(Status
)) {
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.
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
);
101 CoreUpdateDebugTableCrc32 (
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.
122 ASSERT(mDebugTable
!= NULL
);
123 mDebugTable
->Crc32
= 0;
124 gDxeCoreBS
->CalculateCrc32 ((VOID
*)mDebugTable
, sizeof (EFI_SYSTEM_TABLE_POINTER
), &mDebugTable
->Crc32
);
128 CoreNewDebugImageInfoEntry (
129 IN UINT32 ImageInfoType
,
130 IN EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
,
131 IN EFI_HANDLE ImageHandle
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.
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
151 EFI_DEBUG_IMAGE_INFO
*Table
;
152 EFI_DEBUG_IMAGE_INFO
*NewTable
;
158 // Set the flag indicating that we're in the process of updating the table.
160 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
162 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
163 MaxTableIndex
= mDebugInfoTableHeader
.TableSize
;
165 for (Index
= 0; Index
< MaxTableIndex
; Index
++) {
166 if (Table
[Index
].NormalImage
== NULL
) {
168 // We have found a free entry so exit the loop
173 if (Index
== MaxTableIndex
) {
175 // Table is full, so re-allocate another page for a larger table...
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
;
184 // Copy the old table into the new one
186 CopyMem (NewTable
, Table
, TableSize
);
188 // Free the old table
190 CoreFreePool (Table
);
192 // Update the table header
195 mDebugInfoTableHeader
.EfiDebugImageInfoTable
= NewTable
;
196 mDebugInfoTableHeader
.TableSize
+= EFI_PAGE_SIZE
/ EFI_DEBUG_TABLE_ENTRY_SIZE
;
199 // Allocate data for new entry
201 Table
[Index
].NormalImage
= CoreAllocateZeroBootServicesPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL
));
202 if (Table
[Index
].NormalImage
!= NULL
) {
206 Table
[Index
].NormalImage
->ImageInfoType
= (UINT32
) ImageInfoType
;
207 Table
[Index
].NormalImage
->LoadedImageProtocolInstance
= LoadedImage
;
208 Table
[Index
].NormalImage
->ImageHandle
= ImageHandle
;
210 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
215 CoreRemoveDebugImageInfoEntry (
216 EFI_HANDLE ImageHandle
222 Removes and frees an entry from the DebugImageInfo Table.
226 ImageHandle - image handle for the image being unloaded
234 EFI_DEBUG_IMAGE_INFO
*Table
;
237 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
239 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
241 for (Index
= 0; Index
< mDebugInfoTableHeader
.TableSize
; Index
++) {
242 if (Table
[Index
].NormalImage
!= NULL
&& Table
[Index
].NormalImage
->ImageHandle
== ImageHandle
) {
244 // Found a match. Free up the record, then NULL the pointer to indicate the slot
247 CoreFreePool (Table
[Index
].NormalImage
);
248 Table
[Index
].NormalImage
= NULL
;
252 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;