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 (((UINTN)IdtEntry[InterruptType].Bits.OffsetHigh) << 16) +
37 (((UINTN)IdtEntry[InterruptType].Bits.OffsetUpper) << 32);
38 if ((InterruptHandler >= sizeof (UINT32)) && (*(UINT32 *)(InterruptHandler - sizeof (UINT32)) == AGENT_HANDLER_SIGNATURE)) {
39 return TRUE;
40 } else {
41 return FALSE;
42 }
43}
44
52VOID
54 IN IA32_DESCRIPTOR *IdtDescriptor,
55 OUT IA32_IDT_GATE_DESCRIPTOR *SavedIdtEntry
56 )
57{
58 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
59 UINT16 CodeSegment;
60 UINTN InterruptHandler;
61
62 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
63 CopyMem (SavedIdtEntry, &IdtEntry[1], sizeof (IA32_IDT_GATE_DESCRIPTOR));
64
65 //
66 // Use current CS as the segment selector of interrupt gate in IDT
67 //
68 CodeSegment = AsmReadCs ();
69
70 InterruptHandler = (UINTN)&AsmInterruptHandle;
71 IdtEntry[1].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
72 IdtEntry[1].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
73 IdtEntry[1].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);
74 IdtEntry[1].Bits.Selector = CodeSegment;
75 IdtEntry[1].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
76}
77
85VOID
87 IN IA32_DESCRIPTOR *IdtDescriptor,
88 IN IA32_IDT_GATE_DESCRIPTOR *RestoredIdtEntry
89 )
90{
91 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
92
93 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
94 CopyMem (&IdtEntry[1], RestoredIdtEntry, sizeof (IA32_IDT_GATE_DESCRIPTOR));
95}
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