]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Supporting functions for X64 architecture.\r | |
3 | \r | |
4 | Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r | |
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 | |
17 | /**\r | |
18 | Initialize IDT entries to support source level debug.\r | |
19 | \r | |
20 | **/\r | |
21 | VOID\r | |
22 | InitializeDebugIdt (\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 | |
62 | \r | |
63 | //\r | |
64 | // Set DE flag in CR4 to enable IO breakpoint\r | |
65 | //\r | |
66 | AsmWriteCr4 (AsmReadCr4 () | BIT3);\r | |
67 | }\r |