2 Generic debug support macros, typedefs and prototypes for IA32/x64.
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef _DEBUG_SUPPORT_H_
16 #define _DEBUG_SUPPORT_H_
21 #include <Protocol/DebugSupport.h>
22 #include <Protocol/LoadedImage.h>
24 #include <Library/DebugLib.h>
25 #include <Library/UefiDriverEntryPoint.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/BaseLib.h>
30 #include <Library/PcdLib.h>
32 #define NUM_IDT_ENTRIES 0x78
33 #define SYSTEM_TIMER_VECTOR 0x68
34 #define VECTOR_ENTRY_PAGES 1
36 #define FF_FXSR (1 << 24)
45 IA32_IDT_GATE_DESCRIPTOR OrigDesc
;
46 DEBUG_PROC OrigVector
;
47 IA32_IDT_GATE_DESCRIPTOR NewDesc
;
49 VOID (*RegisteredCallback
) ();
52 extern EFI_SYSTEM_CONTEXT SystemContext
;
53 extern UINT8 InterruptEntryStub
[];
54 extern UINT32 StubSize
;
55 extern VOID (*OrigVector
) (VOID
);
56 extern IDT_ENTRY
*IdtEntryTable
;
57 extern IA32_IDT_GATE_DESCRIPTOR NullDesc
;
69 Check whether FXSTOR is supported
71 @retval TRUE FXSTOR is supported.
72 @retval FALSE FXSTOR is not supported.
81 Encodes an IDT descriptor with the given physical address.
83 @param DestDesc The IDT descriptor address.
84 @param Vecotr The interrupt vector entry.
89 IA32_IDT_GATE_DESCRIPTOR
* DestDesc
,
94 Programs interrupt flag to the requested state and returns previous
97 @param NewState New interrupt status.
99 @retval TRUE Old interrupt status is TRUE.
100 @retval FALSE Old interrupt status is FALSE
109 Initializes driver's handler registration databas.
111 This code executes in boot services context
112 Must be public because it's referenced from DebugSupport.c
114 @retval EFI_UNSUPPORTED If IA32 processor does not support FXSTOR/FXRSTOR instructions,
115 the context save will fail, so these processor's are not supported.
116 @retval EFI_OUT_OF_RESOURCES Fails to allocate memory.
117 @retval EFI_SUCCESS Initializes successfully.
121 PlInitializeDebugSupportDriver (
126 This is the callback that is written to the LoadedImage protocol instance
127 on the image handle. It uninstalls all registered handlers and frees all entry
130 @param ImageHandle The firmware allocated handle for the EFI image.
132 @retval EFI_SUCCESS Always.
137 PlUnloadDebugSupportDriver (
138 IN EFI_HANDLE ImageHandle
142 This is a DebugSupport protocol member function, hard
143 coded to support only 1 processor for now.
145 @param This The DebugSupport instance
146 @param MaxProcessorIndex The maximuim supported processor index
148 @retval EFI_SUCCESS Always returned with **MaxProcessorIndex set to 0.
153 GetMaximumProcessorIndex (
154 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
155 OUT UINTN
*MaxProcessorIndex
159 DebugSupport protocol member function.
161 @param This The DebugSupport instance
162 @param ProcessorIndex Which processor the callback applies to.
163 @param PeriodicCallback Callback function
165 @retval EFI_SUCCESS Indicates the callback was registered.
166 @retval others Callback was not registered.
171 RegisterPeriodicCallback (
172 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
173 IN UINTN ProcessorIndex
,
174 IN EFI_PERIODIC_CALLBACK PeriodicCallback
178 DebugSupport protocol member function.
180 This code executes in boot services context.
182 @param This The DebugSupport instance
183 @param ProcessorIndex Which processor the callback applies to.
184 @param NewCallback Callback function
185 @param ExceptionType Which exception to hook
187 @retval EFI_SUCCESS Indicates the callback was registered.
188 @retval others Callback was not registered.
193 RegisterExceptionCallback (
194 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
195 IN UINTN ProcessorIndex
,
196 IN EFI_EXCEPTION_CALLBACK NewCallback
,
197 IN EFI_EXCEPTION_TYPE ExceptionType
201 DebugSupport protocol member function. Calls assembly routine to flush cache.
203 @param This The DebugSupport instance
204 @param ProcessorIndex Which processor the callback applies to.
205 @param Start Physical base of the memory range to be invalidated
206 @param Length mininum number of bytes in instruction cache to invalidate
208 @retval EFI_SUCCESS Always returned.
213 InvalidateInstructionCache (
214 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
215 IN UINTN ProcessorIndex
,
221 Allocate pool for a new IDT entry stub.
223 Copy the generic stub into the new buffer and fixup the vector number
224 and jump target address.
226 @param ExceptionType This is the exception type that the new stub will be created
228 @param Stub On successful exit, *Stub contains the newly allocated entry stub.
230 @retval EFI_SUCCESS Always.
235 IN EFI_EXCEPTION_TYPE ExceptionType
,
240 Get Procedure Entry Point from IDT Gate Descriptor.
242 @param IdtGateDecriptor IDT Gate Descriptor.
244 @return Procedure Entry Point located in IDT Gate Descriptor.
247 UINTN
GetProcedureEntryPoint (
248 IN IA32_IDT_GATE_DESCRIPTOR
*IdtGateDecriptor
252 This is the main worker function that manages the state of the interrupt
253 handlers. It both installs and uninstalls interrupt handlers based on the
254 value of NewCallback. If NewCallback is NULL, then uninstall is indicated.
255 If NewCallback is non-NULL, then install is indicated.
257 @param NewCallback If non-NULL, NewCallback specifies the new handler to register.
258 If NULL, specifies that the previously registered handler should
260 @param ExceptionType Indicates which entry to manage.
262 @retval EFI_SUCCESS Process is ok.
263 @retval EFI_INVALID_PARAMETER Requested uninstalling a handler from a vector that has
264 no handler registered for it
265 @retval EFI_ALREADY_STARTED Requested install to a vector that already has a handler registered.
266 @retval others Possible return values are passed through from UnHookEntry and HookEntry.
270 ManageIdtEntryTable (
271 VOID (*NewCallback
)(),
272 EFI_EXCEPTION_TYPE ExceptionType
276 Creates a nes entry stub. Then saves the current IDT entry and replaces it
277 with an interrupt gate for the new entry point. The IdtEntryTable is updated
278 with the new registered function.
280 This code executes in boot services context. The stub entry executes in interrupt
283 @param ExceptionType Specifies which vector to hook.
284 @param NewCallback A pointer to the new function to be registered.
286 @retval EFI_SUCCESS Always.
291 IN EFI_EXCEPTION_TYPE ExceptionType
,
292 IN
VOID (*NewCallback
) ()
296 Undoes HookEntry. This code executes in boot services context.
298 @param ExceptionType Specifies which entry to unhook
300 @retval EFI_SUCCESS Always.
305 IN EFI_EXCEPTION_TYPE ExceptionType