]> git.proxmox.com Git - mirror_edk2.git/blame - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.c
This revision can only work with Intel(c) UDK Debugger Tool version 1.3 or greater...
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / X64 / ArchDebugSupport.c
CommitLineData
18b144ea 1/** @file\r
93c0bdec 2 Supporting functions for X64 architecture.\r
18b144ea 3\r
b422b62c 4 Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
18b144ea 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 "DebugAgent.h"\r
16\r
18b144ea 17/**\r
18 Initialize IDT entries to support source level debug.\r
19\r
20**/\r
21VOID\r
22InitializeDebugIdt (\r
23 VOID\r
24 )\r
25{\r
26 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;\r
27 UINTN InterruptHandler;\r
28 IA32_DESCRIPTOR IdtDescriptor;\r
29 UINTN Index;\r
30 UINT16 CodeSegment;\r
31\r
32 AsmReadIdtr (&IdtDescriptor);\r
33\r
34 //\r
35 // Use current CS as the segment selector of interrupt gate in IDT\r
36 //\r
37 CodeSegment = AsmReadCs ();\r
38\r
39 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;\r
40\r
41 for (Index = 0; Index < 20; Index ++) {\r
b422b62c 42 if (((PcdGet32 (PcdExceptionsIgnoredByDebugger) & ~(BIT1 | BIT3)) & (1 << Index)) != 0) {\r
18b144ea 43 //\r
b422b62c 44 // If the exception is masked to be reserved except for INT1 and INT3, skip it\r
18b144ea 45 //\r
46 continue;\r
47 }\r
48 InterruptHandler = (UINTN)&Exception0Handle + Index * ExceptionStubHeaderSize;\r
49 IdtEntry[Index].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;\r
50 IdtEntry[Index].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);\r
51 IdtEntry[Index].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);\r
52 IdtEntry[Index].Bits.Selector = CodeSegment;\r
53 IdtEntry[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r
54 }\r
55\r
56 InterruptHandler = (UINTN) &TimerInterruptHandle;\r
57 IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;\r
58 IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);\r
59 IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);\r
60 IdtEntry[DEBUG_TIMER_VECTOR].Bits.Selector = CodeSegment;\r
61 IdtEntry[DEBUG_TIMER_VECTOR].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r
93c0bdec 62\r
63 //\r
64 // Set DE flag in CR4 to enable IO breakpoint\r
65 //\r
66 AsmWriteCr4 (AsmReadCr4 () | BIT3);\r
18b144ea 67}\r
b422b62c 68\r
69/**\r
70 Retrieve exception handler from IDT table by ExceptionNum.\r
71\r
72 @param[in] ExceptionNum Exception number\r
73 \r
74 @return Exception handler\r
75\r
76**/\r
77VOID *\r
78GetExceptionHandlerInIdtEntry (\r
79 IN UINTN ExceptionNum\r
80 )\r
81{\r
82 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;\r
83 IA32_DESCRIPTOR IdtDescriptor;\r
84\r
85 AsmReadIdtr (&IdtDescriptor);\r
86 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;\r
87\r
88 return (VOID *) (IdtEntry[ExceptionNum].Bits.OffsetLow |\r
89 (((UINTN)IdtEntry[ExceptionNum].Bits.OffsetHigh) << 16) |\r
90 (((UINTN)IdtEntry[ExceptionNum].Bits.OffsetUpper) << 32));\r
91} \r
92\r
93/**\r
94 Set exception handler in IDT table by ExceptionNum.\r
95\r
96 @param[in] ExceptionNum Exception number\r
97 @param[in] ExceptionHandler Exception Handler to be set \r
98\r
99**/\r
100VOID\r
101SetExceptionHandlerInIdtEntry (\r
102 IN UINTN ExceptionNum,\r
103 IN VOID *ExceptionHandler\r
104 )\r
105{\r
106 IA32_IDT_GATE_DESCRIPTOR *IdtEntry;\r
107 IA32_DESCRIPTOR IdtDescriptor;\r
108\r
109 AsmReadIdtr (&IdtDescriptor);\r
110 IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;\r
111\r
112 IdtEntry[ExceptionNum].Bits.OffsetLow = (UINT16)(UINTN)ExceptionHandler;\r
113 IdtEntry[ExceptionNum].Bits.OffsetHigh = (UINT16)((UINTN)ExceptionHandler >> 16);\r
114 IdtEntry[ExceptionNum].Bits.OffsetUpper = (UINT32)((UINTN)ExceptionHandler >> 32);\r
115}\r