]>
Commit | Line | Data |
---|---|---|
18b144ea | 1 | /** @file\r |
93c0bdec | 2 | Supporting functions for IA32 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 | |
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 | |
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 | |
b422b62c | 51 | IdtEntry[Index].Bits.Selector = CodeSegment;\r |
52 | IdtEntry[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r | |
18b144ea | 53 | }\r |
54 | \r | |
55 | InterruptHandler = (UINTN) &TimerInterruptHandle;\r | |
56 | IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;\r | |
57 | IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);\r | |
93c0bdec | 58 | IdtEntry[DEBUG_TIMER_VECTOR].Bits.Selector = CodeSegment;\r |
59 | IdtEntry[DEBUG_TIMER_VECTOR].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r | |
60 | \r | |
61 | //\r | |
62 | // Set DE flag in CR4 to enable IO breakpoint\r | |
63 | //\r | |
64 | AsmWriteCr4 (AsmReadCr4 () | BIT3);\r | |
18b144ea | 65 | }\r |
b422b62c | 66 | \r |
67 | /**\r | |
68 | Retrieve exception handler from IDT table by ExceptionNum.\r | |
69 | \r | |
70 | @param[in] ExceptionNum Exception number\r | |
71 | \r | |
72 | @return Exception handler\r | |
73 | \r | |
74 | **/\r | |
75 | VOID *\r | |
76 | GetExceptionHandlerInIdtEntry (\r | |
77 | IN UINTN ExceptionNum\r | |
78 | )\r | |
79 | {\r | |
80 | IA32_IDT_GATE_DESCRIPTOR *IdtEntry;\r | |
81 | IA32_DESCRIPTOR IdtDescriptor;\r | |
82 | \r | |
83 | AsmReadIdtr (&IdtDescriptor);\r | |
84 | IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;\r | |
85 | \r | |
86 | return (VOID *) (((UINTN)IdtEntry[ExceptionNum].Bits.OffsetLow) |\r | |
87 | (((UINTN)IdtEntry[ExceptionNum].Bits.OffsetHigh) << 16));\r | |
88 | } \r | |
89 | \r | |
90 | /**\r | |
91 | Set exception handler in IDT table by ExceptionNum.\r | |
92 | \r | |
93 | @param[in] ExceptionNum Exception number\r | |
94 | @param[in] ExceptionHandler Exception Handler to be set \r | |
95 | \r | |
96 | **/\r | |
97 | VOID\r | |
98 | SetExceptionHandlerInIdtEntry (\r | |
99 | IN UINTN ExceptionNum,\r | |
100 | IN VOID *ExceptionHandler\r | |
101 | )\r | |
102 | {\r | |
103 | IA32_IDT_GATE_DESCRIPTOR *IdtEntry;\r | |
104 | IA32_DESCRIPTOR IdtDescriptor;\r | |
105 | \r | |
106 | AsmReadIdtr (&IdtDescriptor);\r | |
107 | IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;\r | |
108 | \r | |
109 | IdtEntry[ExceptionNum].Bits.OffsetLow = (UINT16)(UINTN)ExceptionHandler;\r | |
110 | IdtEntry[ExceptionNum].Bits.OffsetHigh = (UINT16)((UINTN)ExceptionHandler >> 16);\r | |
111 | }\r |