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