]>
Commit | Line | Data |
---|---|---|
e41aad15 JF |
1 | /** @file\r |
2 | CPU exception handler library implemenation for DXE modules.\r | |
3 | \r | |
4 | Copyright (c) 2013, 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 <PiDxe.h>\r | |
16 | #include "CpuExceptionCommon.h"\r | |
17 | #include <Library/DebugLib.h>\r | |
18 | #include <Library/MemoryAllocationLib.h>\r | |
19 | \r | |
20 | CONST UINTN mDoFarReturnFlag = 0;\r | |
21 | \r | |
22 | extern SPIN_LOCK mDisplayMessageSpinLock;\r | |
23 | extern EFI_CPU_INTERRUPT_HANDLER *mExternalInterruptHandler;\r | |
24 | \r | |
25 | /**\r | |
26 | Initializes all CPU exceptions entries and provides the default exception handlers.\r | |
27 | \r | |
28 | Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r | |
29 | persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r | |
30 | If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r | |
31 | If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r | |
32 | \r | |
33 | @param[in] VectorInfo Pointer to reserved vector list.\r | |
34 | \r | |
35 | @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized \r | |
36 | with default exception handlers.\r | |
37 | @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r | |
38 | @retval EFI_UNSUPPORTED This function is not supported.\r | |
39 | \r | |
40 | **/\r | |
41 | EFI_STATUS\r | |
42 | EFIAPI\r | |
43 | InitializeCpuExceptionHandlers (\r | |
44 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r | |
45 | )\r | |
46 | {\r | |
47 | return InitializeCpuExceptionHandlersWorker (VectorInfo);\r | |
48 | }\r | |
49 | \r | |
50 | /**\r | |
51 | Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r | |
52 | \r | |
53 | Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r | |
54 | persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r | |
55 | If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r | |
56 | If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r | |
57 | \r | |
58 | @param[in] VectorInfo Pointer to reserved vector list.\r | |
59 | \r | |
60 | @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized \r | |
61 | with default interrupt/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 | |
65 | **/\r | |
66 | EFI_STATUS\r | |
67 | EFIAPI\r | |
68 | InitializeCpuInterruptHandlers (\r | |
69 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r | |
70 | )\r | |
71 | {\r | |
72 | EFI_STATUS Status;\r | |
73 | IA32_IDT_GATE_DESCRIPTOR *IdtTable;\r | |
74 | IA32_DESCRIPTOR IdtDescriptor;\r | |
75 | UINTN IdtEntryCount;\r | |
76 | EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;\r | |
77 | UINTN Index;\r | |
78 | UINTN InterruptEntry;\r | |
79 | UINT8 *InterruptEntryCode;\r | |
80 | \r | |
81 | mReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM);\r | |
82 | ASSERT (mReservedVectors != NULL);\r | |
83 | SetMem ((VOID *) mReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM, 0xff);\r | |
84 | if (VectorInfo != NULL) {\r | |
85 | Status = ReadAndVerifyVectorInfo (VectorInfo, mReservedVectors, CPU_INTERRUPT_NUM);\r | |
86 | if (EFI_ERROR (Status)) {\r | |
87 | FreePool (mReservedVectors);\r | |
88 | return EFI_INVALID_PARAMETER;\r | |
89 | }\r | |
90 | }\r | |
91 | InitializeSpinLock (&mDisplayMessageSpinLock);\r | |
92 | mExternalInterruptHandler = AllocateZeroPool (sizeof (EFI_CPU_INTERRUPT_HANDLER) * CPU_INTERRUPT_NUM);\r | |
93 | ASSERT (mExternalInterruptHandler != NULL);\r | |
94 | \r | |
95 | //\r | |
96 | // Read IDT descriptor and calculate IDT size\r | |
97 | //\r | |
98 | AsmReadIdtr (&IdtDescriptor);\r | |
99 | IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR);\r | |
100 | if (IdtEntryCount > CPU_INTERRUPT_NUM) {\r | |
101 | IdtEntryCount = CPU_INTERRUPT_NUM;\r | |
102 | }\r | |
103 | //\r | |
104 | // Create Interrupt Descriptor Table and Copy the old IDT table in\r | |
105 | //\r | |
106 | IdtTable = AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM);\r | |
107 | ASSERT (IdtTable != NULL);\r | |
108 | CopyMem (IdtTable, (VOID *)IdtDescriptor.Base, sizeof (IA32_IDT_GATE_DESCRIPTOR) * IdtEntryCount);\r | |
109 | \r | |
110 | AsmGetTemplateAddressMap (&TemplateMap);\r | |
111 | ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);\r | |
112 | InterruptEntryCode = AllocatePool (TemplateMap.ExceptionStubHeaderSize * CPU_INTERRUPT_NUM);\r | |
113 | ASSERT (InterruptEntryCode != NULL);\r | |
114 | \r | |
115 | InterruptEntry = (UINTN) InterruptEntryCode;\r | |
116 | for (Index = 0; Index < CPU_INTERRUPT_NUM; Index ++) {\r | |
117 | CopyMem (\r | |
118 | (VOID *) InterruptEntry,\r | |
119 | (VOID *) TemplateMap.ExceptionStart,\r | |
120 | TemplateMap.ExceptionStubHeaderSize\r | |
121 | );\r | |
07da1ac8 | 122 | AsmVectorNumFixup ((VOID *) InterruptEntry, (UINT8) Index, (VOID *) TemplateMap.ExceptionStart);\r |
e41aad15 JF |
123 | InterruptEntry += TemplateMap.ExceptionStubHeaderSize;\r |
124 | }\r | |
125 | \r | |
126 | TemplateMap.ExceptionStart = (UINTN) InterruptEntryCode;\r | |
127 | UpdateIdtTable (IdtTable, &TemplateMap, CPU_INTERRUPT_NUM);\r | |
128 | \r | |
129 | //\r | |
130 | // Load Interrupt Descriptor Table\r | |
131 | //\r | |
132 | IdtDescriptor.Base = (UINTN) IdtTable;\r | |
133 | IdtDescriptor.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM - 1);\r | |
134 | AsmWriteIdtr ((IA32_DESCRIPTOR *) &IdtDescriptor);\r | |
135 | \r | |
136 | return EFI_SUCCESS;\r | |
137 | }\r | |
138 | \r | |
139 | /**\r | |
140 | Registers a function to be called from the processor interrupt handler.\r | |
141 | \r | |
142 | This function registers and enables the handler specified by InterruptHandler for a processor \r | |
143 | interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the \r | |
144 | handler for the processor interrupt or exception type specified by InterruptType is uninstalled. \r | |
145 | The installed handler is called once for each processor interrupt or exception.\r | |
146 | NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r | |
147 | InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r | |
148 | \r | |
149 | @param[in] InterruptType Defines which interrupt or exception to hook.\r | |
150 | @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r | |
151 | when a processor interrupt occurs. If this parameter is NULL, then the handler\r | |
152 | will be uninstalled.\r | |
153 | \r | |
154 | @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r | |
155 | @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r | |
156 | previously installed.\r | |
157 | @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r | |
158 | previously installed.\r | |
159 | @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r | |
160 | or this function is not supported.\r | |
3f25e6ea | 161 | **/\r |
e41aad15 JF |
162 | EFI_STATUS\r |
163 | EFIAPI\r | |
164 | RegisterCpuInterruptHandler (\r | |
165 | IN EFI_EXCEPTION_TYPE InterruptType,\r | |
166 | IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r | |
167 | )\r | |
168 | {\r | |
169 | return RegisterCpuInterruptHandlerWorker (InterruptType, InterruptHandler);\r | |
170 | }\r |