]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
Add doxygen style comments for functions in DxeMain.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / DebugImageInfo.c
1 /** @file
2
3 Support functions for managing debug image info table when loading and unloading
4 images.
5
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
11
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.
14
15 **/
16
17 #include <DxeMain.h>
18
19
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;
24 };
25
26 static EFI_SYSTEM_TABLE_POINTER *mDebugTable = NULL;
27
28
29
30 /**
31 Creates and initializes the DebugImageInfo Table. Also creates the configuration
32 table and registers it into the system table.
33
34 Note:
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
38 be a problem.
39
40 **/
41 VOID
42 CoreInitializeDebugImageInfoTable (
43 VOID
44 )
45 {
46 EFI_STATUS Status;
47 EFI_PHYSICAL_ADDRESS Mem;
48 UINTN NumberOfPages;
49
50 //
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.
55 //
56 NumberOfPages = FOUR_MEG_PAGES + EFI_SIZE_TO_PAGES(sizeof (EFI_SYSTEM_TABLE_POINTER));
57
58 Status = CoreAllocatePages (AllocateAnyPages, EfiBootServicesData, NumberOfPages , &Mem);
59 ASSERT_EFI_ERROR (Status);
60 if (EFI_ERROR(Status)) {
61 return;
62 }
63 Status = CoreFreePages (Mem, NumberOfPages);
64 ASSERT_EFI_ERROR (Status);
65 if (EFI_ERROR(Status)) {
66 return;
67 }
68 //
69 // Now get a 4M aligned address within the memory range we were given.
70 // Then allocate memory at that address
71 //
72 Mem = (Mem + FOUR_MEG_MASK) & (~FOUR_MEG_MASK);
73
74 Status = CoreAllocatePages (AllocateAddress, EfiBootServicesData, NumberOfPages - FOUR_MEG_PAGES, &Mem);
75 ASSERT_EFI_ERROR (Status);
76 if (EFI_ERROR(Status)) {
77 return;
78 }
79 //
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.
83 //
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);
90 }
91
92
93 /**
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
98 protocol is produced.
99
100 **/
101 VOID
102 CoreUpdateDebugTableCrc32 (
103 VOID
104 )
105 {
106 ASSERT(mDebugTable != NULL);
107 mDebugTable->Crc32 = 0;
108 gDxeCoreBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);
109 }
110
111
112 /**
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.
115
116 @param ImageInfoType type of debug image information
117 @param LoadedImage pointer to the loaded image protocol for the image being
118 loaded
119 @param ImageHandle image handle for the image being loaded
120
121 **/
122 VOID
123 CoreNewDebugImageInfoEntry (
124 IN UINT32 ImageInfoType,
125 IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
126 IN EFI_HANDLE ImageHandle
127 )
128 {
129 EFI_DEBUG_IMAGE_INFO *Table;
130 EFI_DEBUG_IMAGE_INFO *NewTable;
131 UINTN Index;
132 UINTN MaxTableIndex;
133 UINTN TableSize;
134
135 //
136 // Set the flag indicating that we're in the process of updating the table.
137 //
138 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
139
140 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
141 MaxTableIndex = mDebugInfoTableHeader.TableSize;
142
143 for (Index = 0; Index < MaxTableIndex; Index++) {
144 if (Table[Index].NormalImage == NULL) {
145 //
146 // We have found a free entry so exit the loop
147 //
148 break;
149 }
150 }
151 if (Index == MaxTableIndex) {
152 //
153 // Table is full, so re-allocate another page for a larger table...
154 //
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;
159 return;
160 }
161 //
162 // Copy the old table into the new one
163 //
164 CopyMem (NewTable, Table, TableSize);
165 //
166 // Free the old table
167 //
168 CoreFreePool (Table);
169 //
170 // Update the table header
171 //
172 Table = NewTable;
173 mDebugInfoTableHeader.EfiDebugImageInfoTable = NewTable;
174 mDebugInfoTableHeader.TableSize += EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE;
175 }
176 //
177 // Allocate data for new entry
178 //
179 Table[Index].NormalImage = CoreAllocateZeroBootServicesPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL));
180 if (Table[Index].NormalImage != NULL) {
181 //
182 // Update the entry
183 //
184 Table[Index].NormalImage->ImageInfoType = (UINT32) ImageInfoType;
185 Table[Index].NormalImage->LoadedImageProtocolInstance = LoadedImage;
186 Table[Index].NormalImage->ImageHandle = ImageHandle;
187 }
188 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
189 }
190
191
192
193 /**
194 Removes and frees an entry from the DebugImageInfo Table.
195
196 @param ImageHandle image handle for the image being unloaded
197
198 **/
199 VOID
200 CoreRemoveDebugImageInfoEntry (
201 EFI_HANDLE ImageHandle
202 )
203 {
204 EFI_DEBUG_IMAGE_INFO *Table;
205 UINTN Index;
206
207 mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
208
209 Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
210
211 for (Index = 0; Index < mDebugInfoTableHeader.TableSize; Index++) {
212 if (Table[Index].NormalImage != NULL && Table[Index].NormalImage->ImageHandle == ImageHandle) {
213 //
214 // Found a match. Free up the record, then NULL the pointer to indicate the slot
215 // is free.
216 //
217 CoreFreePool (Table[Index].NormalImage);
218 Table[Index].NormalImage = NULL;
219 break;
220 }
221 }
222 mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
223 }
224
225