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