TianoCore EDK2 master
Loading...
Searching...
No Matches
IntHandlerFuncs.c
Go to the documentation of this file.
1
9#include <PeCoffExtraActionLib.h>
10
21BOOLEAN
23 IN IA32_DESCRIPTOR *IdtDescriptor,
24 IN UINTN InterruptType
25 )
26{
27 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
28 UINTN InterruptHandler;
29
30 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
31 if (IdtEntry == NULL) {
32 return FALSE;
33 }
34
35 InterruptHandler = IdtEntry[InterruptType].Bits.OffsetLow +
36 (IdtEntry[InterruptType].Bits.OffsetHigh << 16);
37 if ((InterruptHandler >= sizeof (UINT32)) && (*(UINT32 *)(InterruptHandler - sizeof (UINT32)) == AGENT_HANDLER_SIGNATURE)) {
38 return TRUE;
39 } else {
40 return FALSE;
41 }
42}
43
51VOID
53 IN IA32_DESCRIPTOR *IdtDescriptor,
54 OUT IA32_IDT_GATE_DESCRIPTOR *SavedIdtEntry
55 )
56{
57 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
58 UINT16 CodeSegment;
59 UINTN InterruptHandler;
60
61 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
62 CopyMem (SavedIdtEntry, &IdtEntry[1], sizeof (IA32_IDT_GATE_DESCRIPTOR));
63
64 //
65 // Use current CS as the segment selector of interrupt gate in IDT
66 //
67 CodeSegment = AsmReadCs ();
68
69 InterruptHandler = (UINTN)&AsmInterruptHandle;
70 IdtEntry[1].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
71 IdtEntry[1].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
72 IdtEntry[1].Bits.Selector = CodeSegment;
73 IdtEntry[1].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
74}
75
83VOID
85 IN IA32_DESCRIPTOR *IdtDescriptor,
86 IN IA32_IDT_GATE_DESCRIPTOR *RestoredIdtEntry
87 )
88{
89 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
90
91 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
92 CopyMem (&IdtEntry[1], RestoredIdtEntry, sizeof (IA32_IDT_GATE_DESCRIPTOR));
93}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
UINT16 EFIAPI AsmReadCs(VOID)
VOID SaveAndUpdateIdtEntry1(IN IA32_DESCRIPTOR *IdtDescriptor, OUT IA32_IDT_GATE_DESCRIPTOR *SavedIdtEntry)
VOID RestoreIdtEntry1(IN IA32_DESCRIPTOR *IdtDescriptor, IN IA32_IDT_GATE_DESCRIPTOR *RestoredIdtEntry)
BOOLEAN CheckDebugAgentHandler(IN IA32_DESCRIPTOR *IdtDescriptor, IN UINTN InterruptType)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284