]>
Commit | Line | Data |
---|---|---|
8f07f895 | 1 | /** @file\r |
e41aad15 | 2 | CPU exception handler library implemenation for SEC/PEIM modules.\r |
8f07f895 | 3 | \r |
e41aad15 | 4 | Copyright (c) 2012 - 2013, Intel Corporation. All rights reserved.<BR>\r |
8f07f895 | 5 | This program and the accompanying materials are licensed and made available under\r |
6 | the terms and conditions of the BSD License that accompanies this distribution.\r | |
7 | 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 <PiPei.h>\r | |
16 | #include "CpuExceptionCommon.h"\r | |
17 | \r | |
18 | //\r | |
19 | // Image Aglinment size for SEC/PEI phase\r | |
20 | //\r | |
e41aad15 JF |
21 | CONST UINTN mImageAlignSize = 4;\r |
22 | CONST UINTN mDoFarReturnFlag = 0;\r | |
8f07f895 | 23 | \r |
24 | /**\r | |
25 | Common exception handler.\r | |
26 | \r | |
27 | @param ExceptionType Exception type.\r | |
28 | @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r | |
29 | **/\r | |
30 | VOID\r | |
31 | EFIAPI\r | |
32 | CommonExceptionHandler (\r | |
33 | IN EFI_EXCEPTION_TYPE ExceptionType, \r | |
34 | IN EFI_SYSTEM_CONTEXT SystemContext\r | |
35 | )\r | |
36 | {\r | |
37 | //\r | |
38 | // Display ExceptionType, CPU information and Image information\r | |
39 | // \r | |
40 | DumpCpuContent (ExceptionType, SystemContext);\r | |
41 | \r | |
42 | //\r | |
43 | // Enter a dead loop.\r | |
44 | //\r | |
45 | CpuDeadLoop ();\r | |
46 | }\r | |
47 | \r | |
48 | /**\r | |
e41aad15 JF |
49 | Initializes all CPU exceptions entries and provides the default exception handlers.\r |
50 | \r | |
51 | Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r | |
52 | persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r | |
53 | If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r | |
54 | If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r | |
a9c7ab95 | 55 | Note: Before invoking this API, caller must allocate memory for IDT table and load \r |
56 | IDTR by AsmWriteIdtr().\r | |
e41aad15 JF |
57 | \r |
58 | @param[in] VectorInfo Pointer to reserved vector list.\r | |
8f07f895 | 59 | \r |
e41aad15 JF |
60 | @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized \r |
61 | with default exception handlers.\r | |
62 | @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r | |
63 | @retval EFI_UNSUPPORTED This function is not supported.\r | |
64 | \r | |
8f07f895 | 65 | **/\r |
e41aad15 JF |
66 | EFI_STATUS\r |
67 | EFIAPI\r | |
68 | InitializeCpuExceptionHandlers (\r | |
69 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r | |
70 | )\r | |
71 | {\r | |
72 | EFI_STATUS Status; \r | |
73 | RESERVED_VECTORS_DATA ReservedVectorData[CPU_EXCEPTION_NUM];\r | |
74 | IA32_DESCRIPTOR IdtDescriptor;\r | |
75 | UINTN IdtEntryCount;\r | |
76 | UINT16 CodeSegment;\r | |
77 | EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;\r | |
78 | IA32_IDT_GATE_DESCRIPTOR *IdtTable;\r | |
79 | UINTN Index;\r | |
80 | UINTN InterruptHandler;\r | |
81 | \r | |
82 | if (VectorInfo != NULL) {\r | |
83 | SetMem ((VOID *) ReservedVectorData, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);\r | |
84 | Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectorData, CPU_EXCEPTION_NUM);\r | |
85 | if (EFI_ERROR (Status)) {\r | |
86 | return EFI_INVALID_PARAMETER;\r | |
87 | }\r | |
88 | }\r | |
89 | //\r | |
90 | // Read IDT descriptor and calculate IDT size\r | |
91 | //\r | |
92 | AsmReadIdtr (&IdtDescriptor);\r | |
93 | IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR);\r | |
94 | if (IdtEntryCount > CPU_EXCEPTION_NUM) {\r | |
95 | //\r | |
96 | // CPU exeption library only setup CPU_EXCEPTION_NUM exception handler at most\r | |
97 | //\r | |
98 | IdtEntryCount = CPU_EXCEPTION_NUM;\r | |
99 | }\r | |
100 | //\r | |
101 | // Use current CS as the segment selector of interrupt gate in IDT\r | |
102 | //\r | |
103 | CodeSegment = AsmReadCs ();\r | |
104 | \r | |
105 | AsmGetTemplateAddressMap (&TemplateMap);\r | |
106 | IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;\r | |
107 | for (Index = 0; Index < IdtEntryCount; Index ++) {\r | |
108 | IdtTable[Index].Bits.Selector = CodeSegment;\r | |
109 | //\r | |
110 | // Check reserved vectors attributes if has, only EFI_VECTOR_HANDOFF_DO_NOT_HOOK\r | |
111 | // supported in this instance\r | |
112 | //\r | |
113 | if (VectorInfo != NULL) {\r | |
114 | if (ReservedVectorData[Index].Attribute == EFI_VECTOR_HANDOFF_DO_NOT_HOOK) {\r | |
115 | continue;\r | |
116 | }\r | |
117 | }\r | |
118 | //\r | |
119 | // Update IDT entry\r | |
120 | //\r | |
121 | InterruptHandler = TemplateMap.ExceptionStart + Index * TemplateMap.ExceptionStubHeaderSize;\r | |
122 | ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);\r | |
123 | }\r | |
124 | return EFI_SUCCESS;\r | |
125 | }\r | |
126 | \r | |
127 | /**\r | |
128 | Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r | |
129 | \r | |
130 | Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r | |
131 | persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r | |
132 | If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r | |
133 | If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r | |
134 | \r | |
135 | @param[in] VectorInfo Pointer to reserved vector list.\r | |
136 | \r | |
137 | @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized \r | |
138 | with default interrupt/exception handlers.\r | |
139 | @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r | |
140 | @retval EFI_UNSUPPORTED This function is not supported.\r | |
141 | \r | |
142 | **/\r | |
143 | EFI_STATUS\r | |
8f07f895 | 144 | EFIAPI\r |
e41aad15 JF |
145 | InitializeCpuInterruptHandlers (\r |
146 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r | |
8f07f895 | 147 | )\r |
148 | {\r | |
e41aad15 | 149 | return EFI_UNSUPPORTED;\r |
8f07f895 | 150 | }\r |
e41aad15 JF |
151 | \r |
152 | /**\r | |
153 | Registers a function to be called from the processor interrupt handler.\r | |
154 | \r | |
155 | This function registers and enables the handler specified by InterruptHandler for a processor \r | |
156 | interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the \r | |
157 | handler for the processor interrupt or exception type specified by InterruptType is uninstalled. \r | |
158 | The installed handler is called once for each processor interrupt or exception.\r | |
159 | NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r | |
160 | InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r | |
161 | \r | |
162 | @param[in] InterruptType Defines which interrupt or exception to hook.\r | |
163 | @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r | |
164 | when a processor interrupt occurs. If this parameter is NULL, then the handler\r | |
165 | will be uninstalled.\r | |
166 | \r | |
167 | @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r | |
168 | @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r | |
169 | previously installed.\r | |
170 | @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r | |
171 | previously installed.\r | |
172 | @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r | |
173 | or this function is not supported.\r | |
3f25e6ea | 174 | **/\r |
e41aad15 JF |
175 | EFI_STATUS\r |
176 | EFIAPI\r | |
177 | RegisterCpuInterruptHandler (\r | |
178 | IN EFI_EXCEPTION_TYPE InterruptType,\r | |
179 | IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r | |
180 | )\r | |
181 | {\r | |
182 | return EFI_UNSUPPORTED;\r | |
183 | } |