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
;
31 Creates and initializes the DebugImageInfo Table. Also creates the configuration
32 table and registers it into the system table.
35 This function allocates memory, frees it, and then allocates memory at an
36 address within the initial allocation. Since this function is called early
37 in DXE core initialization (before drivers are dispatched), this should not
42 CoreInitializeDebugImageInfoTable (
47 EFI_PHYSICAL_ADDRESS Mem
;
51 // Allocate boot services memory for the structure. It's required to be aligned on
52 // a 4M boundary, so allocate a 4M block (plus what we require), free it up, calculate
53 // a 4M aligned address within the memory we just freed, and then allocate memory at that
54 // address for our initial structure.
56 NumberOfPages
= FOUR_MEG_PAGES
+ EFI_SIZE_TO_PAGES(sizeof (EFI_SYSTEM_TABLE_POINTER
));
58 Status
= CoreAllocatePages (AllocateAnyPages
, EfiBootServicesData
, NumberOfPages
, &Mem
);
59 ASSERT_EFI_ERROR (Status
);
60 if (EFI_ERROR(Status
)) {
63 Status
= CoreFreePages (Mem
, NumberOfPages
);
64 ASSERT_EFI_ERROR (Status
);
65 if (EFI_ERROR(Status
)) {
69 // Now get a 4M aligned address within the memory range we were given.
70 // Then allocate memory at that address
72 Mem
= (Mem
+ FOUR_MEG_MASK
) & (~FOUR_MEG_MASK
);
74 Status
= CoreAllocatePages (AllocateAddress
, EfiBootServicesData
, NumberOfPages
- FOUR_MEG_PAGES
, &Mem
);
75 ASSERT_EFI_ERROR (Status
);
76 if (EFI_ERROR(Status
)) {
80 // We now have a 4M aligned page allocated, so fill in the data structure.
81 // Ideally we would update the CRC now as well, but the service may not yet be available.
82 // See comments in the CoreUpdateDebugTableCrc32() function below for details.
84 mDebugTable
= (EFI_SYSTEM_TABLE_POINTER
*)(UINTN
)Mem
;
85 mDebugTable
->Signature
= EFI_SYSTEM_TABLE_SIGNATURE
;
86 mDebugTable
->EfiSystemTableBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) gDxeCoreST
;
87 mDebugTable
->Crc32
= 0;
88 Status
= CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid
, &mDebugInfoTableHeader
);
89 ASSERT_EFI_ERROR (Status
);
94 Update the CRC32 in the Debug Table.
95 Since the CRC32 service is made available by the Runtime driver, we have to
96 wait for the Runtime Driver to be installed before the CRC32 can be computed.
97 This function is called elsewhere by the core when the runtime architectural
102 CoreUpdateDebugTableCrc32 (
106 ASSERT(mDebugTable
!= NULL
);
107 mDebugTable
->Crc32
= 0;
108 gDxeCoreBS
->CalculateCrc32 ((VOID
*)mDebugTable
, sizeof (EFI_SYSTEM_TABLE_POINTER
), &mDebugTable
->Crc32
);
113 Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
114 the table if it's not large enough to accomidate another entry.
116 @param ImageInfoType type of debug image information
117 @param LoadedImage pointer to the loaded image protocol for the image being
119 @param ImageHandle image handle for the image being loaded
123 CoreNewDebugImageInfoEntry (
124 IN UINT32 ImageInfoType
,
125 IN EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
,
126 IN EFI_HANDLE ImageHandle
129 EFI_DEBUG_IMAGE_INFO
*Table
;
130 EFI_DEBUG_IMAGE_INFO
*NewTable
;
136 // Set the flag indicating that we're in the process of updating the table.
138 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
140 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
141 MaxTableIndex
= mDebugInfoTableHeader
.TableSize
;
143 for (Index
= 0; Index
< MaxTableIndex
; Index
++) {
144 if (Table
[Index
].NormalImage
== NULL
) {
146 // We have found a free entry so exit the loop
151 if (Index
== MaxTableIndex
) {
153 // Table is full, so re-allocate another page for a larger table...
155 TableSize
= MaxTableIndex
* EFI_DEBUG_TABLE_ENTRY_SIZE
;
156 NewTable
= CoreAllocateZeroBootServicesPool (TableSize
+ EFI_PAGE_SIZE
);
157 if (NewTable
== NULL
) {
158 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
162 // Copy the old table into the new one
164 CopyMem (NewTable
, Table
, TableSize
);
166 // Free the old table
168 CoreFreePool (Table
);
170 // Update the table header
173 mDebugInfoTableHeader
.EfiDebugImageInfoTable
= NewTable
;
174 mDebugInfoTableHeader
.TableSize
+= EFI_PAGE_SIZE
/ EFI_DEBUG_TABLE_ENTRY_SIZE
;
177 // Allocate data for new entry
179 Table
[Index
].NormalImage
= CoreAllocateZeroBootServicesPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL
));
180 if (Table
[Index
].NormalImage
!= NULL
) {
184 Table
[Index
].NormalImage
->ImageInfoType
= (UINT32
) ImageInfoType
;
185 Table
[Index
].NormalImage
->LoadedImageProtocolInstance
= LoadedImage
;
186 Table
[Index
].NormalImage
->ImageHandle
= ImageHandle
;
188 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
194 Removes and frees an entry from the DebugImageInfo Table.
196 @param ImageHandle image handle for the image being unloaded
200 CoreRemoveDebugImageInfoEntry (
201 EFI_HANDLE ImageHandle
204 EFI_DEBUG_IMAGE_INFO
*Table
;
207 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
209 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
211 for (Index
= 0; Index
< mDebugInfoTableHeader
.TableSize
; Index
++) {
212 if (Table
[Index
].NormalImage
!= NULL
&& Table
[Index
].NormalImage
->ImageHandle
== ImageHandle
) {
214 // Found a match. Free up the record, then NULL the pointer to indicate the slot
217 CoreFreePool (Table
[Index
].NormalImage
);
218 Table
[Index
].NormalImage
= NULL
;
222 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;