]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Include/Library/CpuExceptionHandlerLib.h
MdeModulePkg/CpuExceptionHandlerLib.h: Add a new API InitializeCpuExceptionHandlersEx
[mirror_edk2.git] / MdeModulePkg / Include / Library / CpuExceptionHandlerLib.h
CommitLineData
1e172d6b 1/** @file\r
57f360f2
JF
2 CPU Exception library provides the default CPU interrupt/exception handler.\r
3 It also provides capability to register user interrupt/exception handler.\r
1e172d6b 4\r
e2884d2c 5 Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>\r
1e172d6b 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
57f360f2
JF
16#ifndef __CPU_EXCEPTION_HANDLER_LIB_H__\r
17#define __CPU_EXCEPTION_HANDLER_LIB_H__\r
18\r
19#include <Ppi/VectorHandoffInfo.h>\r
20#include <Protocol/Cpu.h>\r
1e172d6b 21\r
408b8330
JW
22#define CPU_EXCEPTION_INIT_DATA_REV 1\r
23\r
24typedef union {\r
25 struct {\r
26 //\r
27 // Revision number of this structure.\r
28 //\r
29 UINT32 Revision;\r
30 //\r
31 // The address of top of known good stack reserved for *ALL* exceptions\r
32 // listed in field StackSwitchExceptions.\r
33 //\r
34 UINTN KnownGoodStackTop;\r
35 //\r
36 // The size of known good stack for *ONE* exception only.\r
37 //\r
38 UINTN KnownGoodStackSize;\r
39 //\r
40 // Buffer of exception vector list for stack switch.\r
41 //\r
42 UINT8 *StackSwitchExceptions;\r
43 //\r
44 // Number of exception vectors in StackSwitchExceptions.\r
45 //\r
46 UINTN StackSwitchExceptionNumber;\r
47 //\r
48 // Buffer of IDT table. It must be type of IA32_IDT_GATE_DESCRIPTOR.\r
49 // Normally there's no need to change IDT table size.\r
50 //\r
51 VOID *IdtTable;\r
52 //\r
53 // Size of buffer for IdtTable.\r
54 //\r
55 UINTN IdtTableSize;\r
56 //\r
57 // Buffer of GDT table. It must be type of IA32_SEGMENT_DESCRIPTOR.\r
58 //\r
59 VOID *GdtTable;\r
60 //\r
61 // Size of buffer for GdtTable.\r
62 //\r
63 UINTN GdtTableSize;\r
64 //\r
65 // Pointer to start address of descriptor of exception task gate in the\r
66 // GDT table. It must be type of IA32_TSS_DESCRIPTOR.\r
67 //\r
68 VOID *ExceptionTssDesc;\r
69 //\r
70 // Size of buffer for ExceptionTssDesc.\r
71 //\r
72 UINTN ExceptionTssDescSize;\r
73 //\r
74 // Buffer of task-state segment for exceptions. It must be type of\r
75 // IA32_TASK_STATE_SEGMENT.\r
76 //\r
77 VOID *ExceptionTss;\r
78 //\r
79 // Size of buffer for ExceptionTss.\r
80 //\r
81 UINTN ExceptionTssSize;\r
82 //\r
83 // Flag to indicate if default handlers should be initialized or not.\r
84 //\r
85 BOOLEAN InitDefaultHandlers;\r
86 } Ia32, X64;\r
87} CPU_EXCEPTION_INIT_DATA;\r
88\r
1e172d6b 89/**\r
57f360f2
JF
90 Initializes all CPU exceptions entries and provides the default exception handlers.\r
91 \r
92 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
93 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
94 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r
95 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
96\r
97 @param[in] VectorInfo Pointer to reserved vector list.\r
98 \r
99 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized \r
100 with default exception handlers.\r
101 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
102 @retval EFI_UNSUPPORTED This function is not supported.\r
103\r
1e172d6b 104**/\r
57f360f2
JF
105EFI_STATUS\r
106EFIAPI\r
107InitializeCpuExceptionHandlers (\r
108 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
109 );\r
110\r
408b8330
JW
111/**\r
112 Initializes all CPU exceptions entries with optional extra initializations.\r
113\r
114 By default, this method should include all functionalities implemented by\r
115 InitializeCpuExceptionHandlers(), plus extra initialization works, if any.\r
116 This could be done by calling InitializeCpuExceptionHandlers() directly\r
117 in this method besides the extra works.\r
118\r
119 InitData is optional and its use and content are processor arch dependent.\r
120 The typical usage of it is to convey resources which have to be reserved\r
121 elsewhere and are necessary for the extra initializations of exception.\r
122\r
123 @param[in] VectorInfo Pointer to reserved vector list.\r
124 @param[in] InitData Pointer to data optional for extra initializations\r
125 of exception.\r
126\r
127 @retval EFI_SUCCESS The exceptions have been successfully\r
128 initialized.\r
129 @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid\r
130 content.\r
131 @retval EFI_UNSUPPORTED This function is not supported.\r
132\r
133**/\r
134EFI_STATUS\r
135EFIAPI\r
136InitializeCpuExceptionHandlersEx (\r
137 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,\r
138 IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL\r
139 );\r
140\r
57f360f2
JF
141/**\r
142 Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r
143 \r
144 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
145 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
146 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. \r
147 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
148\r
149 @param[in] VectorInfo Pointer to reserved vector list.\r
150 \r
151 @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized \r
152 with default interrupt/exception handlers.\r
153 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
154 @retval EFI_UNSUPPORTED This function is not supported.\r
155\r
156**/\r
157EFI_STATUS\r
158EFIAPI\r
159InitializeCpuInterruptHandlers (\r
160 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
161 );\r
162\r
163/**\r
164 Registers a function to be called from the processor interrupt handler.\r
165\r
166 This function registers and enables the handler specified by InterruptHandler for a processor \r
167 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the \r
168 handler for the processor interrupt or exception type specified by InterruptType is uninstalled. \r
169 The installed handler is called once for each processor interrupt or exception.\r
170 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r
171 InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r
172\r
173 @param[in] InterruptType Defines which interrupt or exception to hook.\r
174 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
175 when a processor interrupt occurs. If this parameter is NULL, then the handler\r
176 will be uninstalled.\r
177\r
178 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
179 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
180 previously installed.\r
181 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
182 previously installed.\r
183 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r
184 or this function is not supported.\r
3f25e6ea 185**/\r
57f360f2 186EFI_STATUS\r
1e172d6b 187EFIAPI\r
57f360f2
JF
188RegisterCpuInterruptHandler (\r
189 IN EFI_EXCEPTION_TYPE InterruptType,\r
190 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
1e172d6b 191 );\r
192\r
e2884d2c
JF
193/**\r
194 Display processor context.\r
195\r
196 @param[in] ExceptionType Exception type.\r
197 @param[in] SystemContext Processor context to be display.\r
198**/\r
199VOID\r
200EFIAPI\r
201DumpCpuContext (\r
202 IN EFI_EXCEPTION_TYPE ExceptionType,\r
203 IN EFI_SYSTEM_CONTEXT SystemContext\r
204 );\r
205 \r
1e172d6b 206#endif\r