]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
UefiCpuPkg/CpuExceptionHandlerLib: Add stack switch support
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / SmmException.c
CommitLineData
e41aad15
JF
1/** @file\r
2 CPU exception handler library implemenation for SMM modules.\r
3\r
1b2f7b3e 4 Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>\r
e41aad15
JF
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 <PiSmm.h>\r
16#include "CpuExceptionCommon.h"\r
17\r
dd563742 18CONST UINTN mDoFarReturnFlag = 1;\r
e41aad15 19\r
d91225cf
JF
20//\r
21// Spin lock for CPU information display\r
22//\r
23SPIN_LOCK mDisplayMessageSpinLock;\r
24\r
d91225cf
JF
25RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];\r
26EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];\r
2c5873fe 27EXCEPTION_HANDLER_DATA mExceptionHandlerData;\r
44ecbc28
JF
28/**\r
29 Common exception handler.\r
30\r
31 @param ExceptionType Exception type.\r
32 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
33**/\r
34VOID\r
35EFIAPI\r
36CommonExceptionHandler (\r
dd563742 37 IN EFI_EXCEPTION_TYPE ExceptionType,\r
44ecbc28
JF
38 IN EFI_SYSTEM_CONTEXT SystemContext\r
39 )\r
40{\r
41 CommonExceptionHandlerWorker (ExceptionType, SystemContext, &mExceptionHandlerData);\r
42}\r
43\r
e41aad15
JF
44/**\r
45 Initializes all CPU exceptions entries and provides the default exception handlers.\r
dd563742 46\r
e41aad15
JF
47 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
48 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
dd563742 49 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.\r
e41aad15
JF
50 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
51\r
52 @param[in] VectorInfo Pointer to reserved vector list.\r
dd563742
JF
53\r
54 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized\r
e41aad15
JF
55 with default exception handlers.\r
56 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
57 @retval EFI_UNSUPPORTED This function is not supported.\r
58\r
59**/\r
60EFI_STATUS\r
61EFIAPI\r
62InitializeCpuExceptionHandlers (\r
63 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
64 )\r
65{\r
ab95e54d
JF
66 mExceptionHandlerData.ReservedVectors = mReservedVectorsData;\r
67 mExceptionHandlerData.ExternalInterruptHandler = mExternalInterruptHandlerTable;\r
68 InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock);\r
69 return InitializeCpuExceptionHandlersWorker (VectorInfo, &mExceptionHandlerData);\r
e41aad15
JF
70}\r
71\r
72/**\r
73 Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.\r
dd563742 74\r
e41aad15
JF
75 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
76 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
dd563742 77 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.\r
e41aad15
JF
78 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
79\r
80 @param[in] VectorInfo Pointer to reserved vector list.\r
dd563742
JF
81\r
82 @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized\r
e41aad15
JF
83 with default interrupt/exception handlers.\r
84 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
85 @retval EFI_UNSUPPORTED This function is not supported.\r
86\r
87**/\r
88EFI_STATUS\r
89EFIAPI\r
90InitializeCpuInterruptHandlers (\r
91 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
92 )\r
93{\r
94 return EFI_UNSUPPORTED;\r
95}\r
96\r
97/**\r
98 Registers a function to be called from the processor interrupt handler.\r
99\r
dd563742
JF
100 This function registers and enables the handler specified by InterruptHandler for a processor\r
101 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the\r
102 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.\r
e41aad15
JF
103 The installed handler is called once for each processor interrupt or exception.\r
104 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or\r
105 InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.\r
106\r
107 @param[in] InterruptType Defines which interrupt or exception to hook.\r
108 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
109 when a processor interrupt occurs. If this parameter is NULL, then the handler\r
110 will be uninstalled.\r
111\r
112 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
113 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
114 previously installed.\r
115 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
116 previously installed.\r
117 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r
118 or this function is not supported.\r
3f25e6ea 119**/\r
e41aad15
JF
120EFI_STATUS\r
121EFIAPI\r
122RegisterCpuInterruptHandler (\r
123 IN EFI_EXCEPTION_TYPE InterruptType,\r
124 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
125 )\r
126{\r
670f13af 127 return RegisterCpuInterruptHandlerWorker (InterruptType, InterruptHandler, &mExceptionHandlerData);\r
0ff5aa9c
JW
128}\r
129\r
130/**\r
131 Initializes all CPU exceptions entries with optional extra initializations.\r
132\r
133 By default, this method should include all functionalities implemented by\r
134 InitializeCpuExceptionHandlers(), plus extra initialization works, if any.\r
135 This could be done by calling InitializeCpuExceptionHandlers() directly\r
136 in this method besides the extra works.\r
137\r
138 InitData is optional and its use and content are processor arch dependent.\r
139 The typical usage of it is to convey resources which have to be reserved\r
140 elsewhere and are necessary for the extra initializations of exception.\r
141\r
142 @param[in] VectorInfo Pointer to reserved vector list.\r
143 @param[in] InitData Pointer to data optional for extra initializations\r
144 of exception.\r
145\r
146 @retval EFI_SUCCESS The exceptions have been successfully\r
147 initialized.\r
148 @retval EFI_INVALID_PARAMETER VectorInfo or InitData contains invalid\r
149 content.\r
150\r
151**/\r
152EFI_STATUS\r
153EFIAPI\r
154InitializeCpuExceptionHandlersEx (\r
155 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,\r
156 IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL\r
157 )\r
158{\r
159 return InitializeCpuExceptionHandlers (VectorInfo);\r
160}\r