]>
Commit | Line | Data |
---|---|---|
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 |
2a09527e | 5 | Copyright (c) 2012 - 2022, 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 |
1436aea4 | 16 | #define CPU_EXCEPTION_INIT_DATA_REV 1\r |
408b8330 JW |
17 | \r |
18 | typedef union {\r | |
19 | struct {\r | |
20 | //\r | |
21 | // Revision number of this structure.\r | |
22 | //\r | |
1436aea4 | 23 | UINT32 Revision;\r |
408b8330 JW |
24 | //\r |
25 | // The address of top of known good stack reserved for *ALL* exceptions\r | |
26 | // listed in field StackSwitchExceptions.\r | |
27 | //\r | |
1436aea4 | 28 | UINTN KnownGoodStackTop;\r |
408b8330 JW |
29 | //\r |
30 | // The size of known good stack for *ONE* exception only.\r | |
31 | //\r | |
1436aea4 | 32 | UINTN KnownGoodStackSize;\r |
408b8330 JW |
33 | //\r |
34 | // Buffer of exception vector list for stack switch.\r | |
35 | //\r | |
1436aea4 | 36 | UINT8 *StackSwitchExceptions;\r |
408b8330 JW |
37 | //\r |
38 | // Number of exception vectors in StackSwitchExceptions.\r | |
39 | //\r | |
1436aea4 | 40 | UINTN StackSwitchExceptionNumber;\r |
408b8330 JW |
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 | |
1436aea4 | 45 | VOID *IdtTable;\r |
408b8330 JW |
46 | //\r |
47 | // Size of buffer for IdtTable.\r | |
48 | //\r | |
1436aea4 | 49 | UINTN IdtTableSize;\r |
408b8330 JW |
50 | //\r |
51 | // Buffer of GDT table. It must be type of IA32_SEGMENT_DESCRIPTOR.\r | |
52 | //\r | |
1436aea4 | 53 | VOID *GdtTable;\r |
408b8330 JW |
54 | //\r |
55 | // Size of buffer for GdtTable.\r | |
56 | //\r | |
1436aea4 | 57 | UINTN GdtTableSize;\r |
408b8330 JW |
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 | |
1436aea4 | 62 | VOID *ExceptionTssDesc;\r |
408b8330 JW |
63 | //\r |
64 | // Size of buffer for ExceptionTssDesc.\r | |
65 | //\r | |
1436aea4 | 66 | UINTN ExceptionTssDescSize;\r |
408b8330 JW |
67 | //\r |
68 | // Buffer of task-state segment for exceptions. It must be type of\r | |
69 | // IA32_TASK_STATE_SEGMENT.\r | |
70 | //\r | |
1436aea4 | 71 | VOID *ExceptionTss;\r |
408b8330 JW |
72 | //\r |
73 | // Size of buffer for ExceptionTss.\r | |
74 | //\r | |
1436aea4 | 75 | UINTN ExceptionTssSize;\r |
408b8330 JW |
76 | //\r |
77 | // Flag to indicate if default handlers should be initialized or not.\r | |
78 | //\r | |
1436aea4 | 79 | BOOLEAN InitDefaultHandlers;\r |
408b8330 JW |
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 |
99 | EFI_STATUS\r |
100 | EFIAPI\r | |
101 | InitializeCpuExceptionHandlers (\r | |
1436aea4 | 102 | IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r |
57f360f2 JF |
103 | );\r |
104 | \r | |
408b8330 | 105 | /**\r |
e7abb94d | 106 | Setup separate stacks for certain exception handlers.\r |
408b8330 | 107 | \r |
e7abb94d | 108 | InitData is optional and processor arch dependent.\r |
408b8330 | 109 | \r |
e7abb94d RN |
110 | @param[in] InitData Pointer to data optional for information about how\r |
111 | to assign stacks for certain exception handlers.\r | |
408b8330 | 112 | \r |
e7abb94d | 113 | @retval EFI_SUCCESS The stacks are assigned successfully.\r |
408b8330 JW |
114 | @retval EFI_UNSUPPORTED This function is not supported.\r |
115 | \r | |
116 | **/\r | |
117 | EFI_STATUS\r | |
118 | EFIAPI\r | |
e7abb94d | 119 | InitializeSeparateExceptionStacks (\r |
1436aea4 | 120 | IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL\r |
408b8330 JW |
121 | );\r |
122 | \r | |
57f360f2 JF |
123 | /**\r |
124 | Registers a function to be called from the processor interrupt handler.\r | |
125 | \r | |
d1102dba LG |
126 | This function registers and enables the handler specified by InterruptHandler for a processor\r |
127 | interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the\r | |
128 | handler for the processor interrupt or exception type specified by InterruptType is uninstalled.\r | |
57f360f2 | 129 | The installed handler is called once for each processor interrupt or exception.\r |
2a09527e RN |
130 | NOTE: This function should be invoked after InitializeCpuExceptionHandlers() is invoked,\r |
131 | otherwise EFI_UNSUPPORTED returned.\r | |
57f360f2 JF |
132 | \r |
133 | @param[in] InterruptType Defines which interrupt or exception to hook.\r | |
134 | @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r | |
135 | when a processor interrupt occurs. If this parameter is NULL, then the handler\r | |
136 | will be uninstalled.\r | |
137 | \r | |
138 | @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r | |
139 | @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r | |
140 | previously installed.\r | |
141 | @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r | |
142 | previously installed.\r | |
143 | @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r | |
144 | or this function is not supported.\r | |
3f25e6ea | 145 | **/\r |
57f360f2 | 146 | EFI_STATUS\r |
1e172d6b | 147 | EFIAPI\r |
57f360f2 | 148 | RegisterCpuInterruptHandler (\r |
1436aea4 MK |
149 | IN EFI_EXCEPTION_TYPE InterruptType,\r |
150 | IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r | |
1e172d6b | 151 | );\r |
152 | \r | |
e2884d2c JF |
153 | /**\r |
154 | Display processor context.\r | |
155 | \r | |
156 | @param[in] ExceptionType Exception type.\r | |
157 | @param[in] SystemContext Processor context to be display.\r | |
158 | **/\r | |
159 | VOID\r | |
160 | EFIAPI\r | |
161 | DumpCpuContext (\r | |
1436aea4 MK |
162 | IN EFI_EXCEPTION_TYPE ExceptionType,\r |
163 | IN EFI_SYSTEM_CONTEXT SystemContext\r | |
e2884d2c | 164 | );\r |
d1102dba | 165 | \r |
1e172d6b | 166 | #endif\r |