]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/DebugSupportDxe/Ia32/DebugSupport.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / DebugSupportDxe / Ia32 / DebugSupport.h
CommitLineData
6e8a984e 1/** @file\r
2 Generic debug support macros, typedefs and prototypes for IA32/x64.\r
3\r
d1102dba 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
6e8a984e 6\r
7**/\r
8\r
9#ifndef _DEBUG_SUPPORT_H_\r
10#define _DEBUG_SUPPORT_H_\r
11\r
6e8a984e 12#include <Uefi.h>\r
13\r
14#include <Protocol/DebugSupport.h>\r
15#include <Protocol/LoadedImage.h>\r
16\r
17#include <Library/DebugLib.h>\r
18#include <Library/UefiDriverEntryPoint.h>\r
19#include <Library/BaseMemoryLib.h>\r
20#include <Library/MemoryAllocationLib.h>\r
21#include <Library/UefiBootServicesTableLib.h>\r
22#include <Library/BaseLib.h>\r
6e8a984e 23\r
24#define NUM_IDT_ENTRIES 0x78\r
25#define SYSTEM_TIMER_VECTOR 0x68\r
6e8a984e 26\r
27typedef\r
28VOID\r
29(*DEBUG_PROC) (\r
30 VOID\r
31 );\r
32\r
1ccdbf2a 33typedef\r
34VOID\r
35(EFIAPI *CALLBACK_FUNC) (\r
36 );\r
37\r
6e8a984e 38typedef struct {\r
39 IA32_IDT_GATE_DESCRIPTOR OrigDesc;\r
40 DEBUG_PROC OrigVector;\r
41 IA32_IDT_GATE_DESCRIPTOR NewDesc;\r
42 DEBUG_PROC StubEntry;\r
1ccdbf2a 43 CALLBACK_FUNC RegisteredCallback;\r
6e8a984e 44} IDT_ENTRY;\r
45\r
c84507ab 46extern UINT8 InterruptEntryStub[];\r
47extern UINT32 StubSize;\r
48extern VOID (*OrigVector) (VOID);\r
49extern IDT_ENTRY *IdtEntryTable;\r
6e8a984e 50extern IA32_IDT_GATE_DESCRIPTOR NullDesc;\r
51\r
52/**\r
53 Generic IDT entry.\r
54\r
55**/\r
56VOID\r
57CommonIdtEntry (\r
58 VOID\r
59 );\r
60\r
61/**\r
62 Check whether FXSTOR is supported\r
63\r
64 @retval TRUE FXSTOR is supported.\r
65 @retval FALSE FXSTOR is not supported.\r
66\r
67**/\r
68BOOLEAN\r
69FxStorSupport (\r
70 VOID\r
71 );\r
72\r
73/**\r
74 Encodes an IDT descriptor with the given physical address.\r
75\r
76 @param DestDesc The IDT descriptor address.\r
77 @param Vecotr The interrupt vector entry.\r
78\r
79**/\r
80VOID\r
81Vect2Desc (\r
82 IA32_IDT_GATE_DESCRIPTOR * DestDesc,\r
83 VOID (*Vector) (VOID)\r
84 );\r
85\r
6e8a984e 86/**\r
d1102dba
LG
87 Initializes driver's handler registration database.\r
88\r
6e8a984e 89 This code executes in boot services context\r
90 Must be public because it's referenced from DebugSupport.c\r
91\r
92 @retval EFI_UNSUPPORTED If IA32 processor does not support FXSTOR/FXRSTOR instructions,\r
93 the context save will fail, so these processor's are not supported.\r
94 @retval EFI_OUT_OF_RESOURCES Fails to allocate memory.\r
95 @retval EFI_SUCCESS Initializes successfully.\r
96\r
97**/\r
98EFI_STATUS\r
99PlInitializeDebugSupportDriver (\r
100 VOID\r
101 );\r
102\r
103/**\r
104 This is the callback that is written to the LoadedImage protocol instance\r
105 on the image handle. It uninstalls all registered handlers and frees all entry\r
106 stub memory.\r
107\r
108 @param ImageHandle The firmware allocated handle for the EFI image.\r
109\r
110 @retval EFI_SUCCESS Always.\r
111\r
112**/\r
113EFI_STATUS\r
114EFIAPI\r
115PlUnloadDebugSupportDriver (\r
116 IN EFI_HANDLE ImageHandle\r
117 );\r
118\r
119/**\r
c84507ab 120 Returns the maximum value that may be used for the ProcessorIndex parameter in\r
d1102dba
LG
121 RegisterPeriodicCallback() and RegisterExceptionCallback().\r
122\r
c84507ab 123 Hard coded to support only 1 processor for now.\r
6e8a984e 124\r
c84507ab 125 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
126 @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the maximum supported\r
d1102dba
LG
127 processor index is returned. Always 0 returned.\r
128\r
c84507ab 129 @retval EFI_SUCCESS Always returned with **MaxProcessorIndex set to 0.\r
6e8a984e 130\r
131**/\r
132EFI_STATUS\r
133EFIAPI\r
134GetMaximumProcessorIndex (\r
135 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
136 OUT UINTN *MaxProcessorIndex\r
137 );\r
138\r
139/**\r
c84507ab 140 Registers a function to be called back periodically in interrupt context.\r
d1102dba 141\r
c84507ab 142 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
143 @param ProcessorIndex Specifies which processor the callback function applies to.\r
144 @param PeriodicCallback A pointer to a function of type PERIODIC_CALLBACK that is the main\r
145 periodic entry point of the debug agent.\r
d1102dba
LG
146\r
147 @retval EFI_SUCCESS The function completed successfully.\r
c84507ab 148 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback\r
d1102dba
LG
149 function was previously registered.\r
150 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback\r
151 function.\r
6e8a984e 152**/\r
153EFI_STATUS\r
154EFIAPI\r
155RegisterPeriodicCallback (\r
156 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
157 IN UINTN ProcessorIndex,\r
158 IN EFI_PERIODIC_CALLBACK PeriodicCallback\r
159 );\r
160\r
161/**\r
c84507ab 162 Registers a function to be called when a given processor exception occurs.\r
6e8a984e 163\r
164 This code executes in boot services context.\r
d1102dba 165\r
c84507ab 166 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
167 @param ProcessorIndex Specifies which processor the callback function applies to.\r
168 @param ExceptionCallback A pointer to a function of type EXCEPTION_CALLBACK that is called\r
d1102dba
LG
169 when the processor exception specified by ExceptionType occurs.\r
170 @param ExceptionType Specifies which processor exception to hook.\r
171\r
172 @retval EFI_SUCCESS The function completed successfully.\r
c84507ab 173 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback\r
d1102dba
LG
174 function was previously registered.\r
175 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback\r
c84507ab 176 function.\r
6e8a984e 177**/\r
178EFI_STATUS\r
179EFIAPI\r
180RegisterExceptionCallback (\r
181 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
182 IN UINTN ProcessorIndex,\r
c84507ab 183 IN EFI_EXCEPTION_CALLBACK ExceptionCallback,\r
6e8a984e 184 IN EFI_EXCEPTION_TYPE ExceptionType\r
185 );\r
186\r
187/**\r
c84507ab 188 Invalidates processor instruction cache for a memory range. Subsequent execution in this range\r
d1102dba
LG
189 causes a fresh memory fetch to retrieve code to be executed.\r
190\r
c84507ab 191 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
192 @param ProcessorIndex Specifies which processor's instruction cache is to be invalidated.\r
d1102dba 193 @param Start Specifies the physical base of the memory range to be invalidated.\r
c84507ab 194 @param Length Specifies the minimum number of bytes in the processor's instruction\r
d1102dba
LG
195 cache to invalidate.\r
196\r
c84507ab 197 @retval EFI_SUCCESS Always returned.\r
6e8a984e 198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202InvalidateInstructionCache (\r
203 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
204 IN UINTN ProcessorIndex,\r
205 IN VOID *Start,\r
206 IN UINT64 Length\r
207 );\r
208\r
209/**\r
210 Allocate pool for a new IDT entry stub.\r
211\r
212 Copy the generic stub into the new buffer and fixup the vector number\r
213 and jump target address.\r
214\r
215 @param ExceptionType This is the exception type that the new stub will be created\r
216 for.\r
217 @param Stub On successful exit, *Stub contains the newly allocated entry stub.\r
218\r
6e8a984e 219**/\r
c84507ab 220VOID\r
6e8a984e 221CreateEntryStub (\r
222 IN EFI_EXCEPTION_TYPE ExceptionType,\r
223 OUT VOID **Stub\r
224 );\r
225\r
226/**\r
c84507ab 227 Get Interrupt Handle from IDT Gate Descriptor.\r
6e8a984e 228\r
229 @param IdtGateDecriptor IDT Gate Descriptor.\r
230\r
c84507ab 231 @return Interrupt Handle stored in IDT Gate Descriptor.\r
6e8a984e 232\r
233**/\r
c84507ab 234UINTN\r
235GetInterruptHandleFromIdt (\r
6e8a984e 236 IN IA32_IDT_GATE_DESCRIPTOR *IdtGateDecriptor\r
237 );\r
238\r
239/**\r
240 This is the main worker function that manages the state of the interrupt\r
241 handlers. It both installs and uninstalls interrupt handlers based on the\r
242 value of NewCallback. If NewCallback is NULL, then uninstall is indicated.\r
243 If NewCallback is non-NULL, then install is indicated.\r
244\r
245 @param NewCallback If non-NULL, NewCallback specifies the new handler to register.\r
246 If NULL, specifies that the previously registered handler should\r
247 be uninstalled.\r
248 @param ExceptionType Indicates which entry to manage.\r
249\r
250 @retval EFI_SUCCESS Process is ok.\r
251 @retval EFI_INVALID_PARAMETER Requested uninstalling a handler from a vector that has\r
252 no handler registered for it\r
253 @retval EFI_ALREADY_STARTED Requested install to a vector that already has a handler registered.\r
254 @retval others Possible return values are passed through from UnHookEntry and HookEntry.\r
255\r
256**/\r
257EFI_STATUS\r
258ManageIdtEntryTable (\r
1ccdbf2a 259 CALLBACK_FUNC NewCallback,\r
6e8a984e 260 EFI_EXCEPTION_TYPE ExceptionType\r
261 );\r
262\r
263/**\r
264 Creates a nes entry stub. Then saves the current IDT entry and replaces it\r
265 with an interrupt gate for the new entry point. The IdtEntryTable is updated\r
266 with the new registered function.\r
267\r
268 This code executes in boot services context. The stub entry executes in interrupt\r
269 context.\r
270\r
271 @param ExceptionType Specifies which vector to hook.\r
272 @param NewCallback A pointer to the new function to be registered.\r
273\r
6e8a984e 274**/\r
c84507ab 275VOID\r
6e8a984e 276HookEntry (\r
277 IN EFI_EXCEPTION_TYPE ExceptionType,\r
1ccdbf2a 278 IN CALLBACK_FUNC NewCallback\r
6e8a984e 279 );\r
280\r
281/**\r
282 Undoes HookEntry. This code executes in boot services context.\r
283\r
284 @param ExceptionType Specifies which entry to unhook\r
285\r
6e8a984e 286**/\r
c84507ab 287VOID\r
6e8a984e 288UnhookEntry (\r
289 IN EFI_EXCEPTION_TYPE ExceptionType\r
290 );\r
291\r
292#endif\r