]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / DebugImageInfo.c
1 /** @file
2 Support functions for managing debug image info table when loading and unloading
3 images.
4
5 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
6 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
10
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.
13
14 **/
15
16 #include "DxeMain.h"
17
18
19 EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader = {
20 0, // volatile UINT32 UpdateStatus;
21 0, // UINT32 TableSize;
22 NULL // EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;
23 };
24
25 UINTN mMaxTableEntries = 0;
26
27 EFI_SYSTEM_TABLE_POINTER *mDebugTable = NULL;
28
29 #define FOUR_MEG_ALIGNMENT 0x400000
30
31 #define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof (VOID *))
32
33 /**
34 Creates and initializes the DebugImageInfo Table. Also creates the configuration
35 table and registers it into the system table.
36
37 **/
38 VOID
39 CoreInitializeDebugImageInfoTable (
40 VOID
41 )
42 {
43 EFI_STATUS Status;
44
45 //
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.
49 //
50 mDebugTable = AllocateAlignedPages (EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER)), FOUR_MEG_ALIGNMENT);
51 ASSERT (mDebugTable != NULL);
52 mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE;
53 mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gDxeCoreST;
54 mDebugTable->Crc32 = 0;
55 Status = CoreInstallConfigurationTable (&gEfiDebugImageInfoTableGuid, &mDebugInfoTableHeader);
56 ASSERT_EFI_ERROR (Status);
57 }
58
59
60 /**
61 Update the CRC32 in the Debug Table.
62 Since the CRC32 service is made available by the Runtime driver, we have to
63 wait for the Runtime Driver to be installed before the CRC32 can be computed.
64 This function is called elsewhere by the core when the runtime architectural
65 protocol is produced.
66
67 **/
68 VOID
69 CoreUpdateDebugTableCrc32 (
70 VOID
71 )
72 {
73 ASSERT(mDebugTable != NULL);
74 mDebugTable->Crc32 = 0;
75 gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);
76 }
77
78
79 /**
80 Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
81 the table if it's not large enough to accomidate another entry.
82
83 @param ImageInfoType type of debug image information
84 @param LoadedImage pointer to the loaded image protocol for the image being
85 loaded
86 @param ImageHandle image handle for the image being loaded
87
88 **/
89 VOID
90 CoreNewDebugImageInfoEntry (
91 IN UINT32 ImageInfoType,
92 IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
93 IN EFI_HANDLE ImageHandle
94 )
95 {
96 EFI_DEBUG_IMAGE_INFO *Table;
97 EFI_DEBUG_IMAGE_INFO *NewTable;
98 UINTN Index;
99 UINTN TableSize;
100
101 //
102 // Set the flag indicating that we're in the process of updating the table.
103 //
104 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
105
106 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
107
108 if (mDebugInfoTableHeader.TableSize < mMaxTableEntries) {
109 //
110 // We still have empty entires in the Table, find the first empty entry.
111 //
112 Index = 0;
113 while (Table[Index].NormalImage != NULL) {
114 Index++;
115 }
116 //
117 // There must be an empty entry in the in the table.
118 //
119 ASSERT (Index < mMaxTableEntries);
120 } else {
121 //
122 // Table is full, so re-allocate another page for a larger table...
123 //
124 TableSize = mMaxTableEntries * EFI_DEBUG_TABLE_ENTRY_SIZE;
125 NewTable = AllocateZeroPool (TableSize + EFI_PAGE_SIZE);
126 if (NewTable == NULL) {
127 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
128 return;
129 }
130 //
131 // Copy the old table into the new one
132 //
133 CopyMem (NewTable, Table, TableSize);
134 //
135 // Free the old table
136 //
137 CoreFreePool (Table);
138 //
139 // Update the table header
140 //
141 Table = NewTable;
142 mDebugInfoTableHeader.EfiDebugImageInfoTable = NewTable;
143 //
144 // Enlarge the max table entries and set the first empty entry index to
145 // be the original max table entries.
146 //
147 Index = mMaxTableEntries;
148 mMaxTableEntries += EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;
149 }
150
151 //
152 // Allocate data for new entry
153 //
154 Table[Index].NormalImage = AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));
155 if (Table[Index].NormalImage != NULL) {
156 //
157 // Update the entry
158 //
159 Table[Index].NormalImage->ImageInfoType = (UINT32) ImageInfoType;
160 Table[Index].NormalImage->LoadedImageProtocolInstance = LoadedImage;
161 Table[Index].NormalImage->ImageHandle = ImageHandle;
162 //
163 // Increase the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
164 //
165 mDebugInfoTableHeader.TableSize++;
166 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
167 }
168 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
169 }
170
171
172
173 /**
174 Removes and frees an entry from the DebugImageInfo Table.
175
176 @param ImageHandle image handle for the image being unloaded
177
178 **/
179 VOID
180 CoreRemoveDebugImageInfoEntry (
181 EFI_HANDLE ImageHandle
182 )
183 {
184 EFI_DEBUG_IMAGE_INFO *Table;
185 UINTN Index;
186
187 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
188
189 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
190
191 for (Index = 0; Index < mMaxTableEntries; Index++) {
192 if (Table[Index].NormalImage != NULL && Table[Index].NormalImage->ImageHandle == ImageHandle) {
193 //
194 // Found a match. Free up the record, then NULL the pointer to indicate the slot
195 // is free.
196 //
197 CoreFreePool (Table[Index].NormalImage);
198 Table[Index].NormalImage = NULL;
199 //
200 // Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the mDebugInfoTable in modified status.
201 //
202 mDebugInfoTableHeader.TableSize--;
203 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
204 break;
205 }
206 }
207 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
208 }
209
210