TianoCore EDK2 master
Loading...
Searching...
No Matches
PlDebugSupport.c
Go to the documentation of this file.
1
9#include "DebugSupport.h"
10
11//
12// This the global main table to keep track of the interrupts
13//
14IDT_ENTRY *IdtEntryTable = NULL;
15
23VOID
26 OUT IA32_IDT_GATE_DESCRIPTOR *IdtGateDescriptor
27 )
28{
29 IA32_DESCRIPTOR IdtrValue;
30 IA32_IDT_GATE_DESCRIPTOR *IdtTable;
31
32 AsmReadIdtr (&IdtrValue);
33 IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtrValue.Base;
34
35 CopyMem ((VOID *)IdtGateDescriptor, (VOID *)&(IdtTable)[Vector], sizeof (IA32_IDT_GATE_DESCRIPTOR));
36}
37
45VOID
47 EFI_EXCEPTION_TYPE Vector,
48 IA32_IDT_GATE_DESCRIPTOR *IdtGateDescriptor
49 )
50{
51 IA32_DESCRIPTOR IdtrValue;
52 IA32_IDT_GATE_DESCRIPTOR *IdtTable;
53
54 AsmReadIdtr (&IdtrValue);
55 IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtrValue.Base;
56
57 CopyMem ((VOID *)&(IdtTable)[Vector], (VOID *)IdtGateDescriptor, sizeof (IA32_IDT_GATE_DESCRIPTOR));
58}
59
72VOID
74 IN EFI_EXCEPTION_TYPE ExceptionType,
75 IN CALLBACK_FUNC NewCallback
76 )
77{
78 BOOLEAN OldIntFlagState;
79
80 CreateEntryStub (ExceptionType, (VOID **)&IdtEntryTable[ExceptionType].StubEntry);
81
82 //
83 // Disables CPU interrupts and returns the previous interrupt state
84 //
85 OldIntFlagState = SaveAndDisableInterrupts ();
86
87 //
88 // gets IDT Gate descriptor by index
89 //
90 ReadIdtGateDescriptor (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));
91 //
92 // stores orignal interrupt handle
93 //
94 IdtEntryTable[ExceptionType].OrigVector = (DEBUG_PROC)GetInterruptHandleFromIdt (&(IdtEntryTable[ExceptionType].OrigDesc));
95
96 //
97 // encodes new IDT Gate descriptor by stub entry
98 //
99 Vect2Desc (&IdtEntryTable[ExceptionType].NewDesc, IdtEntryTable[ExceptionType].StubEntry);
100 //
101 // stores NewCallback
102 //
103 IdtEntryTable[ExceptionType].RegisteredCallback = NewCallback;
104
105 //
106 // writes back new IDT Gate descriptor
107 //
108 WriteIdtGateDescriptor (ExceptionType, &(IdtEntryTable[ExceptionType].NewDesc));
109
110 //
111 // restore interrupt state
112 //
113 SetInterruptState (OldIntFlagState);
114
115 return;
116}
117
124VOID
126 IN EFI_EXCEPTION_TYPE ExceptionType
127 )
128{
129 BOOLEAN OldIntFlagState;
130
131 //
132 // Disables CPU interrupts and returns the previous interrupt state
133 //
134 OldIntFlagState = SaveAndDisableInterrupts ();
135
136 //
137 // restore the default IDT Date Descriptor
138 //
139 WriteIdtGateDescriptor (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));
140
141 //
142 // restore interrupt state
143 //
144 SetInterruptState (OldIntFlagState);
145
146 return;
147}
148
163EFIAPI
166 OUT UINTN *MaxProcessorIndex
167 )
168{
169 *MaxProcessorIndex = 0;
170 return EFI_SUCCESS;
171}
172
188EFIAPI
191 IN UINTN ProcessorIndex,
192 IN EFI_PERIODIC_CALLBACK PeriodicCallback
193 )
194{
195 return ManageIdtEntryTable (PeriodicCallback, SYSTEM_TIMER_VECTOR);
196}
197
216EFIAPI
219 IN UINTN ProcessorIndex,
220 IN EFI_EXCEPTION_CALLBACK ExceptionCallback,
221 IN EFI_EXCEPTION_TYPE ExceptionType
222 )
223{
224 return ManageIdtEntryTable (ExceptionCallback, ExceptionType);
225}
226
241EFIAPI
244 IN UINTN ProcessorIndex,
245 IN VOID *Start,
246 IN UINT64 Length
247 )
248{
249 AsmWbinvd ();
250 return EFI_SUCCESS;
251}
252
263VOID
265 EFI_EXCEPTION_TYPE ExceptionType,
266 EFI_SYSTEM_CONTEXT_IA32 *ContextRecord
267 )
268{
269 if (IdtEntryTable[ExceptionType].RegisteredCallback != NULL) {
270 if (ExceptionType != SYSTEM_TIMER_VECTOR) {
271 IdtEntryTable[ExceptionType].RegisteredCallback (ExceptionType, ContextRecord);
272 } else {
273 OrigVector = IdtEntryTable[ExceptionType].OrigVector;
274 IdtEntryTable[ExceptionType].RegisteredCallback (ContextRecord);
275 }
276 }
277}
278
290EFIAPI
292 IN EFI_HANDLE ImageHandle
293 )
294{
295 EFI_EXCEPTION_TYPE ExceptionType;
296
297 for (ExceptionType = 0; ExceptionType < NUM_IDT_ENTRIES; ExceptionType++) {
298 ManageIdtEntryTable (NULL, ExceptionType);
299 //
300 // Free space for each Interrupt Stub precedure.
301 //
302 if (IdtEntryTable[ExceptionType].StubEntry != NULL) {
303 FreePool ((VOID *)(UINTN)IdtEntryTable[ExceptionType].StubEntry);
304 }
305 }
306
307 FreePool (IdtEntryTable);
308
309 return EFI_SUCCESS;
310}
311
326 VOID
327 )
328{
329 EFI_EXCEPTION_TYPE ExceptionType;
330
331 //
332 // Check whether FxStor instructions are supported.
333 //
334 if (!FxStorSupport ()) {
335 return EFI_UNSUPPORTED;
336 }
337
338 IdtEntryTable = AllocateZeroPool (sizeof (IDT_ENTRY) * NUM_IDT_ENTRIES);
339 if (IdtEntryTable == NULL) {
340 return EFI_OUT_OF_RESOURCES;
341 }
342
343 for (ExceptionType = 0; ExceptionType < NUM_IDT_ENTRIES; ExceptionType++) {
344 IdtEntryTable[ExceptionType].StubEntry = (DEBUG_PROC)(UINTN)AllocatePool (StubSize);
345 if (IdtEntryTable[ExceptionType].StubEntry == NULL) {
346 goto ErrorCleanup;
347 }
348
349 //
350 // Copy Interrupt stub code.
351 //
352 CopyMem ((VOID *)(UINTN)IdtEntryTable[ExceptionType].StubEntry, InterruptEntryStub, StubSize);
353 }
354
355 return EFI_SUCCESS;
356
357ErrorCleanup:
358
359 for (ExceptionType = 0; ExceptionType < NUM_IDT_ENTRIES; ExceptionType++) {
360 if (IdtEntryTable[ExceptionType].StubEntry != NULL) {
361 FreePool ((VOID *)(UINTN)IdtEntryTable[ExceptionType].StubEntry);
362 }
363 }
364
365 FreePool (IdtEntryTable);
366
367 return EFI_OUT_OF_RESOURCES;
368}
UINT64 UINTN
BOOLEAN EFIAPI SetInterruptState(IN BOOLEAN InterruptState)
Definition: Cpu.c:48
BOOLEAN EFIAPI SaveAndDisableInterrupts(VOID)
Definition: Cpu.c:21
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID EFIAPI AsmWbinvd(VOID)
EFI_STATUS ManageIdtEntryTable(CALLBACK_FUNC NewCallback, EFI_EXCEPTION_TYPE ExceptionType)
UINTN GetInterruptHandleFromIdt(IN IA32_IDT_GATE_DESCRIPTOR *IdtGateDecriptor)
VOID Vect2Desc(IA32_IDT_GATE_DESCRIPTOR *DestDesc, VOID(*Vector)(VOID))
BOOLEAN FxStorSupport(VOID)
VOID CreateEntryStub(IN EFI_EXCEPTION_TYPE ExceptionType, OUT VOID **Stub)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
INTN EFI_EXCEPTION_TYPE
Definition: DebugSupport.h:35
VOID(EFIAPI * EFI_EXCEPTION_CALLBACK)(IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
Definition: DebugSupport.h:816
VOID(EFIAPI * EFI_PERIODIC_CALLBACK)(IN OUT EFI_SYSTEM_CONTEXT SystemContext)
Definition: DebugSupport.h:829
VOID HookEntry(IN EFI_EXCEPTION_TYPE ExceptionType, IN CALLBACK_FUNC NewCallback)
VOID WriteIdtGateDescriptor(EFI_EXCEPTION_TYPE Vector, IA32_IDT_GATE_DESCRIPTOR *IdtGateDescriptor)
VOID ReadIdtGateDescriptor(IN EFI_EXCEPTION_TYPE Vector, OUT IA32_IDT_GATE_DESCRIPTOR *IdtGateDescriptor)
EFI_STATUS EFIAPI RegisterExceptionCallback(IN EFI_DEBUG_SUPPORT_PROTOCOL *This, IN UINTN ProcessorIndex, IN EFI_EXCEPTION_CALLBACK ExceptionCallback, IN EFI_EXCEPTION_TYPE ExceptionType)
VOID UnhookEntry(IN EFI_EXCEPTION_TYPE ExceptionType)
EFI_STATUS PlInitializeDebugSupportDriver(VOID)
EFI_STATUS EFIAPI InvalidateInstructionCache(IN EFI_DEBUG_SUPPORT_PROTOCOL *This, IN UINTN ProcessorIndex, IN VOID *Start, IN UINT64 Length)
EFI_STATUS EFIAPI GetMaximumProcessorIndex(IN EFI_DEBUG_SUPPORT_PROTOCOL *This, OUT UINTN *MaxProcessorIndex)
VOID InterruptDistrubutionHub(EFI_EXCEPTION_TYPE ExceptionType, EFI_SYSTEM_CONTEXT_IA32 *ContextRecord)
EFI_STATUS EFIAPI PlUnloadDebugSupportDriver(IN EFI_HANDLE ImageHandle)
EFI_STATUS EFIAPI RegisterPeriodicCallback(IN EFI_DEBUG_SUPPORT_PROTOCOL *This, IN UINTN ProcessorIndex, IN EFI_PERIODIC_CALLBACK PeriodicCallback)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
VOID EFIAPI AsmReadIdtr(OUT IA32_DESCRIPTOR *Idtr)
Definition: X86ReadIdtr.c:24