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 UINTN mMaxTableEntries
= 0;
27 EFI_SYSTEM_TABLE_POINTER
*mDebugTable
= NULL
;
29 #define FOUR_MEG_ALIGNMENT 0x400000
31 #define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof (VOID *))
34 Creates and initializes the DebugImageInfo Table. Also creates the configuration
35 table and registers it into the system table.
39 CoreInitializeDebugImageInfoTable (
46 // Allocate 4M aligned page for the structure and fill in the data.
47 // Ideally we would update the CRC now as well, but the service may not yet be available.
48 // See comments in the CoreUpdateDebugTableCrc32() function below for details.
50 mDebugTable
= AllocateAlignedPages (EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER
)), FOUR_MEG_ALIGNMENT
);
51 mDebugTable
->Signature
= EFI_SYSTEM_TABLE_SIGNATURE
;
52 mDebugTable
->EfiSystemTableBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) gDxeCoreST
;
53 mDebugTable
->Crc32
= 0;
54 Status
= CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid
, &mDebugInfoTableHeader
);
55 ASSERT_EFI_ERROR (Status
);
60 Update the CRC32 in the Debug Table.
61 Since the CRC32 service is made available by the Runtime driver, we have to
62 wait for the Runtime Driver to be installed before the CRC32 can be computed.
63 This function is called elsewhere by the core when the runtime architectural
68 CoreUpdateDebugTableCrc32 (
72 ASSERT(mDebugTable
!= NULL
);
73 mDebugTable
->Crc32
= 0;
74 gBS
->CalculateCrc32 ((VOID
*)mDebugTable
, sizeof (EFI_SYSTEM_TABLE_POINTER
), &mDebugTable
->Crc32
);
79 Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
80 the table if it's not large enough to accomidate another entry.
82 @param ImageInfoType type of debug image information
83 @param LoadedImage pointer to the loaded image protocol for the image being
85 @param ImageHandle image handle for the image being loaded
89 CoreNewDebugImageInfoEntry (
90 IN UINT32 ImageInfoType
,
91 IN EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
,
92 IN EFI_HANDLE ImageHandle
95 EFI_DEBUG_IMAGE_INFO
*Table
;
96 EFI_DEBUG_IMAGE_INFO
*NewTable
;
101 // Set the flag indicating that we're in the process of updating the table.
103 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
105 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
107 if (mDebugInfoTableHeader
.TableSize
< mMaxTableEntries
) {
109 // We still have empty entires in the Table, find the first empty entry.
112 while (Table
[Index
].NormalImage
!= NULL
) {
116 // There must be an empty entry in the in the table.
118 ASSERT (Index
< mMaxTableEntries
);
121 // Table is full, so re-allocate another page for a larger table...
123 TableSize
= mMaxTableEntries
* EFI_DEBUG_TABLE_ENTRY_SIZE
;
124 NewTable
= AllocateZeroPool (TableSize
+ EFI_PAGE_SIZE
);
125 if (NewTable
== NULL
) {
126 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
130 // Copy the old table into the new one
132 CopyMem (NewTable
, Table
, TableSize
);
134 // Free the old table
136 CoreFreePool (Table
);
138 // Update the table header
141 mDebugInfoTableHeader
.EfiDebugImageInfoTable
= NewTable
;
143 // Enlarge the max table entries and set the first empty entry index to
144 // be the original max table entries.
146 Index
= mMaxTableEntries
;
147 mMaxTableEntries
+= EFI_PAGE_SIZE
/ EFI_DEBUG_TABLE_ENTRY_SIZE
;
151 // Allocate data for new entry
153 Table
[Index
].NormalImage
= AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL
));
154 if (Table
[Index
].NormalImage
!= NULL
) {
158 Table
[Index
].NormalImage
->ImageInfoType
= (UINT32
) ImageInfoType
;
159 Table
[Index
].NormalImage
->LoadedImageProtocolInstance
= LoadedImage
;
160 Table
[Index
].NormalImage
->ImageHandle
= ImageHandle
;
162 // Increase the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
164 mDebugInfoTableHeader
.TableSize
++;
165 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED
;
167 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
173 Removes and frees an entry from the DebugImageInfo Table.
175 @param ImageHandle image handle for the image being unloaded
179 CoreRemoveDebugImageInfoEntry (
180 EFI_HANDLE ImageHandle
183 EFI_DEBUG_IMAGE_INFO
*Table
;
186 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;
188 Table
= mDebugInfoTableHeader
.EfiDebugImageInfoTable
;
190 for (Index
= 0; Index
< mMaxTableEntries
; Index
++) {
191 if (Table
[Index
].NormalImage
!= NULL
&& Table
[Index
].NormalImage
->ImageHandle
== ImageHandle
) {
193 // Found a match. Free up the record, then NULL the pointer to indicate the slot
196 CoreFreePool (Table
[Index
].NormalImage
);
197 Table
[Index
].NormalImage
= NULL
;
199 // Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
201 mDebugInfoTableHeader
.TableSize
--;
202 mDebugInfoTableHeader
.UpdateStatus
|= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED
;
206 mDebugInfoTableHeader
.UpdateStatus
&= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS
;