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