2 Supporting functions for X64 architecture.
4 Copyright (c) 2010 - 2012, 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.
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.
15 #include "DebugAgent.h"
18 Initialize IDT entries to support source level debug.
26 IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
;
27 UINTN InterruptHandler
;
28 IA32_DESCRIPTOR IdtDescriptor
;
32 AsmReadIdtr (&IdtDescriptor
);
35 // Use current CS as the segment selector of interrupt gate in IDT
37 CodeSegment
= AsmReadCs ();
39 IdtEntry
= (IA32_IDT_GATE_DESCRIPTOR
*) IdtDescriptor
.Base
;
41 for (Index
= 0; Index
< 20; Index
++) {
42 if ((PcdGet32 (PcdExceptionsIgnoredByDebugger
) & (1 << Index
)) != 0) {
44 // If the exception is masked to be reserved, skip it
48 InterruptHandler
= (UINTN
)&Exception0Handle
+ Index
* ExceptionStubHeaderSize
;
49 IdtEntry
[Index
].Bits
.OffsetLow
= (UINT16
)(UINTN
)InterruptHandler
;
50 IdtEntry
[Index
].Bits
.OffsetHigh
= (UINT16
)((UINTN
)InterruptHandler
>> 16);
51 IdtEntry
[Index
].Bits
.OffsetUpper
= (UINT32
)((UINTN
)InterruptHandler
>> 32);
52 IdtEntry
[Index
].Bits
.Selector
= CodeSegment
;
53 IdtEntry
[Index
].Bits
.GateType
= IA32_IDT_GATE_TYPE_INTERRUPT_32
;
56 InterruptHandler
= (UINTN
) &TimerInterruptHandle
;
57 IdtEntry
[DEBUG_TIMER_VECTOR
].Bits
.OffsetLow
= (UINT16
)(UINTN
)InterruptHandler
;
58 IdtEntry
[DEBUG_TIMER_VECTOR
].Bits
.OffsetHigh
= (UINT16
)((UINTN
)InterruptHandler
>> 16);
59 IdtEntry
[DEBUG_TIMER_VECTOR
].Bits
.OffsetUpper
= (UINT32
)((UINTN
)InterruptHandler
>> 32);
60 IdtEntry
[DEBUG_TIMER_VECTOR
].Bits
.Selector
= CodeSegment
;
61 IdtEntry
[DEBUG_TIMER_VECTOR
].Bits
.GateType
= IA32_IDT_GATE_TYPE_INTERRUPT_32
;
64 // Set DE flag in CR4 to enable IO breakpoint
66 AsmWriteCr4 (AsmReadCr4 () | BIT3
);