TianoCore EDK2 master
Loading...
Searching...
No Matches
PlDebugSupportX64.c
Go to the documentation of this file.
1
9#include "PlDebugSupport.h"
10
11IA32_IDT_GATE_DESCRIPTOR NullDesc = {
12 { 0, 0 }
13};
14
25 IN IA32_IDT_GATE_DESCRIPTOR *IdtGateDecriptor
26 )
27{
28 UINTN InterruptHandle;
29
30 //
31 // InterruptHandle 0-15 : OffsetLow
32 // InterruptHandle 16-31 : OffsetHigh
33 // InterruptHandle 32-63 : OffsetUpper
34 //
35 InterruptHandle = ((UINTN)IdtGateDecriptor->Bits.OffsetLow) |
36 (((UINTN)IdtGateDecriptor->Bits.OffsetHigh) << 16) |
37 (((UINTN)IdtGateDecriptor->Bits.OffsetUpper) << 32);
38
39 return InterruptHandle;
40}
41
53VOID
55 IN EFI_EXCEPTION_TYPE ExceptionType,
56 OUT VOID **Stub
57 )
58{
59 UINT8 *StubCopy;
60
61 StubCopy = *Stub;
62
63 //
64 // Fixup the stub code for this vector
65 //
66
67 // The stub code looks like this:
68 //
69 // 00000000 6A 00 push 0 ; push vector number - will be modified before installed
70 // 00000002 E9 db 0e9h ; jump rel32
71 // 00000003 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[0x1] = (UINT8)ExceptionType;
78
79 //
80 // fixup the jump target to point to the common entry
81 //
82 *(UINT32 *)&StubCopy[0x3] = (UINT32)((UINTN)CommonIdtEntry - (UINTN)&StubCopy[StubSize]);
83
84 return;
85}
86
107 CALLBACK_FUNC NewCallback,
108 EFI_EXCEPTION_TYPE ExceptionType
109 )
110{
111 EFI_STATUS Status;
112
113 Status = EFI_SUCCESS;
114
115 if (CompareMem (&IdtEntryTable[ExceptionType].NewDesc, &NullDesc, sizeof (IA32_IDT_GATE_DESCRIPTOR)) != 0) {
116 //
117 // we've already installed to this vector
118 //
119 if (NewCallback != NULL) {
120 //
121 // if the input handler is non-null, error
122 //
123 Status = EFI_ALREADY_STARTED;
124 } else {
125 UnhookEntry (ExceptionType);
126 }
127 } else {
128 //
129 // no user handler installed on this vector
130 //
131 if (NewCallback == NULL) {
132 //
133 // if the input handler is null, error
134 //
135 Status = EFI_INVALID_PARAMETER;
136 } else {
137 HookEntry (ExceptionType, NewCallback);
138 }
139 }
140
141 return Status;
142}
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 *IdtGateDecriptor)
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