]> git.proxmox.com Git - mirror_edk2.git/blob - SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/Ia32/IntHandlerFuncs.c
This revision can only work with Intel(c) UDK Debugger Tool version 1.3 or greater...
[mirror_edk2.git] / SourceLevelDebugPkg / Library / PeCoffExtraActionLibDebug / Ia32 / IntHandlerFuncs.c
1 /** @file
2 Ia32 arch functions to access IDT vector.
3
4 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PeCoffExtraActionLib.h>
16
17 /**
18 Read IDT entry to check if IDT entries are setup by Debug Agent.
19
20 @param[in] IdtDescriptor Pointer to IDT Descriptor.
21
22 @retval TRUE IDT entries were setup by Debug Agent.
23 @retval FALSE IDT entries were not setuo by Debug Agent.
24
25 **/
26 BOOLEAN
27 CheckDebugAgentHandler (
28 IN IA32_DESCRIPTOR *IdtDescriptor
29 )
30 {
31 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
32 UINTN InterruptHandler;
33
34 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base;
35 if (IdtEntry == NULL) {
36 return FALSE;
37 }
38
39 InterruptHandler = IdtEntry[0].Bits.OffsetLow + (IdtEntry[0].Bits.OffsetHigh << 16);
40 if (InterruptHandler >= 4 && *(UINT32 *)(InterruptHandler - 4) == AGENT_HANDLER_SIGNATURE) {
41 return TRUE;
42 } else {
43 return FALSE;
44 }
45 }
46
47 /**
48 Save IDT entry for INT1 and update it.
49
50 @param[in] IdtDescriptor Pointer to IDT Descriptor.
51 @param[out] SavedIdtEntry Original IDT entry returned.
52
53 **/
54 VOID
55 SaveAndUpdateIdtEntry1 (
56 IN IA32_DESCRIPTOR *IdtDescriptor,
57 OUT IA32_IDT_GATE_DESCRIPTOR *SavedIdtEntry
58 )
59 {
60 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
61 UINT16 CodeSegment;
62 UINTN InterruptHandler;
63
64 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base;
65 CopyMem (SavedIdtEntry, &IdtEntry[1], sizeof (IA32_IDT_GATE_DESCRIPTOR));
66
67 //
68 // Use current CS as the segment selector of interrupt gate in IDT
69 //
70 CodeSegment = AsmReadCs ();
71
72 InterruptHandler = (UINTN) &AsmInterruptHandle;
73 IdtEntry[1].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
74 IdtEntry[1].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
75 IdtEntry[1].Bits.Selector = CodeSegment;
76 IdtEntry[1].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
77 }
78
79 /**
80 Restore IDT entry for INT1.
81
82 @param[in] IdtDescriptor Pointer to IDT Descriptor.
83 @param[in] RestoredIdtEntry IDT entry to be restored.
84
85 **/
86 VOID
87 RestoreIdtEntry1 (
88 IN IA32_DESCRIPTOR *IdtDescriptor,
89 IN IA32_IDT_GATE_DESCRIPTOR *RestoredIdtEntry
90 )
91 {
92 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
93
94 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base;
95 CopyMem (&IdtEntry[1], RestoredIdtEntry, sizeof (IA32_IDT_GATE_DESCRIPTOR));
96 }