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