TianoCore EDK2 master
Loading...
Searching...
No Matches
PlDebugSupportIa32.c
Go to the documentation of this file.
1
9#include "PlDebugSupport.h"
10
11IA32_IDT_GATE_DESCRIPTOR NullDesc = {
12 { 0 }
13};
14
25 IN IA32_IDT_GATE_DESCRIPTOR *IdtGateDescriptor
26 )
27{
28 UINTN InterruptHandle;
29
30 //
31 // InterruptHandle 0-15 : OffsetLow
32 // InterruptHandle 16-31 : OffsetHigh
33 //
34 ((UINT16 *)&InterruptHandle)[0] = (UINT16)IdtGateDescriptor->Bits.OffsetLow;
35 ((UINT16 *)&InterruptHandle)[1] = (UINT16)IdtGateDescriptor->Bits.OffsetHigh;
36
37 return InterruptHandle;
38}
39
51VOID
53 IN EFI_EXCEPTION_TYPE ExceptionType,
54 OUT VOID **Stub
55 )
56{
57 UINT8 *StubCopy;
58
59 StubCopy = *Stub;
60
61 //
62 // Fixup the stub code for this vector
63 //
64
65 // The stub code looks like this:
66 //
67 // 00000000 89 25 00000004 R mov AppEsp, esp ; save stack top
68 // 00000006 BC 00008014 R mov esp, offset DbgStkBot ; switch to debugger stack
69 // 0000000B 6A 00 push 0 ; push vector number - will be modified before installed
70 // 0000000D E9 db 0e9h ; jump rel32
71 // 0000000E 00000000 dd 0 ; fixed up to relative address of CommonIdtEntry
72 //
73
74 //
75 // poke in the exception type so the second push pushes the exception type
76 //
77 StubCopy[0x0c] = (UINT8)ExceptionType;
78
79 //
80 // fixup the jump target to point to the common entry
81 //
82 *(UINT32 *)&StubCopy[0x0e] = (UINT32)CommonIdtEntry - (UINT32)&StubCopy[StubSize];
83
84 return;
85}
86
106 CALLBACK_FUNC NewCallback,
107 EFI_EXCEPTION_TYPE ExceptionType
108 )
109{
110 EFI_STATUS Status;
111
112 Status = EFI_SUCCESS;
113
114 if (CompareMem (&IdtEntryTable[ExceptionType].NewDesc, &NullDesc, sizeof (IA32_IDT_GATE_DESCRIPTOR)) != 0) {
115 //
116 // we've already installed to this vector
117 //
118 if (NewCallback != NULL) {
119 //
120 // if the input handler is non-null, error
121 //
122 Status = EFI_ALREADY_STARTED;
123 } else {
124 UnhookEntry (ExceptionType);
125 }
126 } else {
127 //
128 // no user handler installed on this vector
129 //
130 if (NewCallback == NULL) {
131 //
132 // if the input handler is null, error
133 //
134 Status = EFI_INVALID_PARAMETER;
135 } else {
136 HookEntry (ExceptionType, NewCallback);
137 }
138 }
139
140 return Status;
141}
UINT64 UINTN
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID HookEntry(IN EFI_EXCEPTION_TYPE ExceptionType, IN CALLBACK_FUNC NewCallback)
VOID CommonIdtEntry(VOID)
VOID UnhookEntry(IN EFI_EXCEPTION_TYPE ExceptionType)
#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
EFI_STATUS ManageIdtEntryTable(CALLBACK_FUNC NewCallback, EFI_EXCEPTION_TYPE ExceptionType)
UINTN GetInterruptHandleFromIdt(IN IA32_IDT_GATE_DESCRIPTOR *IdtGateDescriptor)
VOID CreateEntryStub(IN EFI_EXCEPTION_TYPE ExceptionType, OUT VOID **Stub)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112