2 Generic debug support macros, typedefs and prototypes for IA32/x64.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef _DEBUG_SUPPORT_H_
10 #define _DEBUG_SUPPORT_H_
14 #include <Protocol/DebugSupport.h>
15 #include <Protocol/LoadedImage.h>
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>
24 #define NUM_IDT_ENTRIES 0x78
25 #define SYSTEM_TIMER_VECTOR 0x68
35 (EFIAPI
*CALLBACK_FUNC
) (
39 IA32_IDT_GATE_DESCRIPTOR OrigDesc
;
40 DEBUG_PROC OrigVector
;
41 IA32_IDT_GATE_DESCRIPTOR NewDesc
;
43 CALLBACK_FUNC RegisteredCallback
;
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
;
62 Check whether FXSTOR is supported
64 @retval TRUE FXSTOR is supported.
65 @retval FALSE FXSTOR is not supported.
74 Encodes an IDT descriptor with the given physical address.
76 @param DestDesc The IDT descriptor address.
77 @param Vecotr The interrupt vector entry.
82 IA32_IDT_GATE_DESCRIPTOR
* DestDesc
,
87 Initializes driver's handler registration database.
89 This code executes in boot services context
90 Must be public because it's referenced from DebugSupport.c
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.
99 PlInitializeDebugSupportDriver (
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
108 @param ImageHandle The firmware allocated handle for the EFI image.
110 @retval EFI_SUCCESS Always.
115 PlUnloadDebugSupportDriver (
116 IN EFI_HANDLE ImageHandle
120 Returns the maximum value that may be used for the ProcessorIndex parameter in
121 RegisterPeriodicCallback() and RegisterExceptionCallback().
123 Hard coded to support only 1 processor for now.
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.
129 @retval EFI_SUCCESS Always returned with **MaxProcessorIndex set to 0.
134 GetMaximumProcessorIndex (
135 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
136 OUT UINTN
*MaxProcessorIndex
140 Registers a function to be called back periodically in interrupt context.
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.
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
155 RegisterPeriodicCallback (
156 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
157 IN UINTN ProcessorIndex
,
158 IN EFI_PERIODIC_CALLBACK PeriodicCallback
162 Registers a function to be called when a given processor exception occurs.
164 This code executes in boot services context.
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.
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
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
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.
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
197 @retval EFI_SUCCESS Always returned.
202 InvalidateInstructionCache (
203 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
204 IN UINTN ProcessorIndex
,
210 Allocate pool for a new IDT entry stub.
212 Copy the generic stub into the new buffer and fixup the vector number
213 and jump target address.
215 @param ExceptionType This is the exception type that the new stub will be created
217 @param Stub On successful exit, *Stub contains the newly allocated entry stub.
222 IN EFI_EXCEPTION_TYPE ExceptionType
,
227 Get Interrupt Handle from IDT Gate Descriptor.
229 @param IdtGateDecriptor IDT Gate Descriptor.
231 @return Interrupt Handle stored in IDT Gate Descriptor.
235 GetInterruptHandleFromIdt (
236 IN IA32_IDT_GATE_DESCRIPTOR
*IdtGateDecriptor
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.
245 @param NewCallback If non-NULL, NewCallback specifies the new handler to register.
246 If NULL, specifies that the previously registered handler should
248 @param ExceptionType Indicates which entry to manage.
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.
258 ManageIdtEntryTable (
259 CALLBACK_FUNC NewCallback
,
260 EFI_EXCEPTION_TYPE ExceptionType
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.
268 This code executes in boot services context. The stub entry executes in interrupt
271 @param ExceptionType Specifies which vector to hook.
272 @param NewCallback A pointer to the new function to be registered.
277 IN EFI_EXCEPTION_TYPE ExceptionType
,
278 IN CALLBACK_FUNC NewCallback
282 Undoes HookEntry. This code executes in boot services context.
284 @param ExceptionType Specifies which entry to unhook
289 IN EFI_EXCEPTION_TYPE ExceptionType