]>
Commit | Line | Data |
---|---|---|
8f07f895 | 1 | /** @file\r |
2 | x64 CPU Exception Hanlder.\r | |
3 | \r | |
4 | Copyright (c) 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 "CpuExceptionCommon.h"\r | |
16 | \r | |
17 | /**\r | |
18 | Internal function to setup CPU exception handlers.\r | |
19 | \r | |
20 | **/\r | |
21 | VOID\r | |
22 | InternalSetupCpuExceptionHandlers (\r | |
23 | VOID\r | |
24 | )\r | |
25 | {\r | |
26 | IA32_DESCRIPTOR IdtDescriptor;\r | |
27 | UINTN IdtSize;\r | |
28 | EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;\r | |
29 | UINT16 CodeSegment;\r | |
30 | IA32_IDT_GATE_DESCRIPTOR *IdtEntry;\r | |
31 | UINTN Index;\r | |
32 | UINTN InterruptHandler;\r | |
33 | \r | |
34 | //\r | |
35 | // Read IDT descriptor and calculate IDT size\r | |
36 | //\r | |
37 | AsmReadIdtr (&IdtDescriptor);\r | |
38 | IdtSize = (IdtDescriptor.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR);\r | |
39 | if (IdtSize > CPU_EXCEPTION_NUM) {\r | |
40 | //\r | |
41 | // CPU exeption library only setup CPU_EXCEPTION_NUM exception handler at most\r | |
42 | //\r | |
43 | IdtSize = CPU_EXCEPTION_NUM;\r | |
44 | }\r | |
45 | \r | |
46 | //\r | |
47 | // Use current CS as the segment selector of interrupt gate in IDT\r | |
48 | //\r | |
49 | CodeSegment = AsmReadCs ();\r | |
50 | IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;\r | |
51 | \r | |
52 | GetTemplateAddressMap (&TemplateMap);\r | |
53 | \r | |
54 | for (Index = 0; Index < IdtSize; Index ++) {\r | |
55 | InterruptHandler = TemplateMap.ExceptionStart + Index * TemplateMap.ExceptionStubHeaderSize;\r | |
56 | IdtEntry[Index].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;\r | |
57 | IdtEntry[Index].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);\r | |
58 | IdtEntry[Index].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);\r | |
59 | IdtEntry[Index].Bits.Selector = CodeSegment;\r | |
60 | IdtEntry[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r | |
61 | }\r | |
62 | }\r | |
63 | \r | |
64 | /**\r | |
65 | Common exception handler.\r | |
66 | \r | |
67 | @param ExceptionType Exception type.\r | |
68 | @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r | |
69 | **/\r | |
70 | VOID\r | |
71 | DumpCpuContent (\r | |
72 | IN UINTN ExceptionType,\r | |
73 | IN EFI_SYSTEM_CONTEXT SystemContext\r | |
74 | )\r | |
75 | {\r | |
76 | UINTN ImageBase;\r | |
77 | UINTN EntryPoint;\r | |
78 | \r | |
79 | InternalPrintMessage (\r | |
80 | "!!!! X64 Exception Type - %016lx CPU Apic ID - %08x !!!!\n",\r | |
81 | ExceptionType,\r | |
82 | GetApicId ()\r | |
83 | );\r | |
84 | InternalPrintMessage (\r | |
85 | "RIP - %016lx, CS - %016lx, RFLAGS - %016lx\n",\r | |
86 | SystemContext.SystemContextX64->Rip,\r | |
87 | SystemContext.SystemContextX64->Cs,\r | |
88 | SystemContext.SystemContextX64->Rflags\r | |
89 | );\r | |
90 | if (mErrorCodeFlag & (1 << ExceptionType)) {\r | |
91 | InternalPrintMessage (\r | |
92 | "ExceptionData - %016lx\n",\r | |
93 | SystemContext.SystemContextX64->ExceptionData\r | |
94 | );\r | |
95 | }\r | |
96 | InternalPrintMessage (\r | |
97 | "RAX - %016lx, RCX - %016lx, RDX - %016lx\n",\r | |
98 | SystemContext.SystemContextX64->Rax,\r | |
99 | SystemContext.SystemContextX64->Rcx,\r | |
100 | SystemContext.SystemContextX64->Rdx\r | |
101 | );\r | |
102 | InternalPrintMessage (\r | |
103 | "RBX - %016lx, RSP - %016lx, RBP - %016lx\n",\r | |
104 | SystemContext.SystemContextX64->Rbx,\r | |
105 | SystemContext.SystemContextX64->Rsp,\r | |
106 | SystemContext.SystemContextX64->Rbp\r | |
107 | );\r | |
108 | InternalPrintMessage (\r | |
109 | "RSI - %016lx, RDI - %016lx\n",\r | |
110 | SystemContext.SystemContextX64->Rsi,\r | |
111 | SystemContext.SystemContextX64->Rdi\r | |
112 | );\r | |
113 | InternalPrintMessage (\r | |
114 | "R8 - %016lx, R9 - %016lx, R10 - %016lx\n",\r | |
115 | SystemContext.SystemContextX64->R8,\r | |
116 | SystemContext.SystemContextX64->R9,\r | |
117 | SystemContext.SystemContextX64->R10\r | |
118 | );\r | |
119 | InternalPrintMessage (\r | |
120 | "R11 - %016lx, R12 - %016lx, R13 - %016lx\n",\r | |
121 | SystemContext.SystemContextX64->R11,\r | |
122 | SystemContext.SystemContextX64->R12,\r | |
123 | SystemContext.SystemContextX64->R13\r | |
124 | );\r | |
125 | InternalPrintMessage (\r | |
126 | "R14 - %016lx, R15 - %016lx\n",\r | |
127 | SystemContext.SystemContextX64->R14,\r | |
128 | SystemContext.SystemContextX64->R15\r | |
129 | );\r | |
130 | InternalPrintMessage (\r | |
131 | "DS - %016lx, ES - %016lx, FS - %016lx\n",\r | |
132 | SystemContext.SystemContextX64->Ds,\r | |
133 | SystemContext.SystemContextX64->Es,\r | |
134 | SystemContext.SystemContextX64->Fs\r | |
135 | );\r | |
136 | InternalPrintMessage (\r | |
137 | "GS - %016lx, SS - %016lx\n",\r | |
138 | SystemContext.SystemContextX64->Gs,\r | |
139 | SystemContext.SystemContextX64->Ss\r | |
140 | );\r | |
141 | InternalPrintMessage (\r | |
142 | "CR0 - %016lx, CR2 - %016lx, CR3 - %016lx\n",\r | |
143 | SystemContext.SystemContextX64->Cr0,\r | |
144 | SystemContext.SystemContextX64->Cr2,\r | |
145 | SystemContext.SystemContextX64->Cr3\r | |
146 | );\r | |
147 | InternalPrintMessage (\r | |
148 | "CR4 - %016lx, CR8 - %016lx\n",\r | |
149 | SystemContext.SystemContextX64->Cr4,\r | |
150 | SystemContext.SystemContextX64->Cr8\r | |
151 | );\r | |
152 | InternalPrintMessage (\r | |
153 | "DR0 - %016lx, DR1 - %016lx, DR2 - %016lx\n",\r | |
154 | SystemContext.SystemContextX64->Dr0,\r | |
155 | SystemContext.SystemContextX64->Dr1,\r | |
156 | SystemContext.SystemContextX64->Dr2\r | |
157 | );\r | |
158 | InternalPrintMessage (\r | |
159 | "DR3 - %016lx, DR6 - %016lx, DR7 - %016lx\n",\r | |
160 | SystemContext.SystemContextX64->Dr3,\r | |
161 | SystemContext.SystemContextX64->Dr6,\r | |
162 | SystemContext.SystemContextX64->Dr7\r | |
163 | );\r | |
164 | InternalPrintMessage (\r | |
165 | "GDTR - %016lx %016lx, LDTR - %016lx\n",\r | |
166 | SystemContext.SystemContextX64->Gdtr[0],\r | |
167 | SystemContext.SystemContextX64->Gdtr[1],\r | |
168 | SystemContext.SystemContextX64->Ldtr\r | |
169 | );\r | |
170 | InternalPrintMessage (\r | |
171 | "IDTR - %016lx %016lx, TR - %016lx\n",\r | |
172 | SystemContext.SystemContextX64->Idtr[0],\r | |
173 | SystemContext.SystemContextX64->Idtr[1],\r | |
174 | SystemContext.SystemContextX64->Tr\r | |
175 | );\r | |
176 | InternalPrintMessage (\r | |
177 | "FXSAVE_STATE - %016lx\n",\r | |
178 | &SystemContext.SystemContextX64->FxSaveState\r | |
179 | );\r | |
180 | \r | |
181 | //\r | |
182 | // Find module image base and module entry point by RIP\r | |
183 | //\r | |
184 | ImageBase = FindModuleImageBase (SystemContext.SystemContextX64->Rip, &EntryPoint);\r | |
185 | if (ImageBase != 0) {\r | |
186 | InternalPrintMessage (\r | |
187 | " (ImageBase=%016lx, EntryPoint=%016lx) !!!!\n",\r | |
188 | ImageBase,\r | |
189 | EntryPoint\r | |
190 | );\r | |
191 | }\r | |
192 | }\r |