]> 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.2 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
93c0bdec 4 Copyright (c) 2010 - 2012, 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
42 if ((PcdGet32 (PcdExceptionsIgnoredByDebugger) & (1 << Index)) != 0) {\r
43 //\r
44 // If the exception is masked to be reserved, skip it\r
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