]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / SmmException.c
CommitLineData
e41aad15 1/** @file\r
418aded9 2 CPU exception handler library implementation for SMM modules.\r
e41aad15 3\r
2a09527e 4 Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR>\r
0acd8697 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
e41aad15
JF
6\r
7**/\r
8\r
9#include <PiSmm.h>\r
10#include "CpuExceptionCommon.h"\r
11\r
053e878b 12CONST UINTN mDoFarReturnFlag = 1;\r
e41aad15 13\r
053e878b
MK
14RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];\r
15EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];\r
34d50512 16EXCEPTION_HANDLER_DATA mExceptionHandlerData = {\r
2a09527e
RN
17 CPU_EXCEPTION_NUM,\r
18 0, // To be fixed\r
34d50512
RN
19 mReservedVectorsData,\r
20 mExternalInterruptHandlerTable\r
21};\r
d91225cf 22\r
44ecbc28
JF
23/**\r
24 Common exception handler.\r
25\r
26 @param ExceptionType Exception type.\r
27 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
28**/\r
29VOID\r
30EFIAPI\r
31CommonExceptionHandler (\r
053e878b
MK
32 IN EFI_EXCEPTION_TYPE ExceptionType,\r
33 IN EFI_SYSTEM_CONTEXT SystemContext\r
44ecbc28
JF
34 )\r
35{\r
36 CommonExceptionHandlerWorker (ExceptionType, SystemContext, &mExceptionHandlerData);\r
37}\r
38\r
e41aad15
JF
39/**\r
40 Initializes all CPU exceptions entries and provides the default exception handlers.\r
dd563742 41\r
e41aad15
JF
42 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to\r
43 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.\r
dd563742 44 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.\r
e41aad15
JF
45 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.\r
46\r
47 @param[in] VectorInfo Pointer to reserved vector list.\r
dd563742
JF
48\r
49 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized\r
e41aad15
JF
50 with default exception handlers.\r
51 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
52 @retval EFI_UNSUPPORTED This function is not supported.\r
53\r
54**/\r
55EFI_STATUS\r
56EFIAPI\r
57InitializeCpuExceptionHandlers (\r
053e878b 58 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL\r
e41aad15
JF
59 )\r
60{\r
ab95e54d
JF
61 InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock);\r
62 return InitializeCpuExceptionHandlersWorker (VectorInfo, &mExceptionHandlerData);\r
e41aad15
JF
63}\r
64\r
e41aad15
JF
65/**\r
66 Registers a function to be called from the processor interrupt handler.\r
67\r
dd563742
JF
68 This function registers and enables the handler specified by InterruptHandler for a processor\r
69 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the\r
70 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.\r
e41aad15 71 The installed handler is called once for each processor interrupt or exception.\r
2a09527e
RN
72 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() is invoked,\r
73 otherwise EFI_UNSUPPORTED returned.\r
e41aad15
JF
74\r
75 @param[in] InterruptType Defines which interrupt or exception to hook.\r
76 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
77 when a processor interrupt occurs. If this parameter is NULL, then the handler\r
78 will be uninstalled.\r
79\r
80 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
81 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
82 previously installed.\r
83 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
84 previously installed.\r
85 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,\r
86 or this function is not supported.\r
3f25e6ea 87**/\r
e41aad15
JF
88EFI_STATUS\r
89EFIAPI\r
90RegisterCpuInterruptHandler (\r
053e878b
MK
91 IN EFI_EXCEPTION_TYPE InterruptType,\r
92 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
e41aad15
JF
93 )\r
94{\r
670f13af 95 return RegisterCpuInterruptHandlerWorker (InterruptType, InterruptHandler, &mExceptionHandlerData);\r
0ff5aa9c
JW
96}\r
97\r
98/**\r
e7abb94d 99 Setup separate stacks for certain exception handlers.\r
0f7bccf5 100 If the input Buffer and BufferSize are both NULL, use global variable if possible.\r
0ff5aa9c 101\r
0f7bccf5
ZL
102 @param[in] Buffer Point to buffer used to separate exception stack.\r
103 @param[in, out] BufferSize On input, it indicates the byte size of Buffer.\r
104 If the size is not enough, the return status will\r
105 be EFI_BUFFER_TOO_SMALL, and output BufferSize\r
106 will be the size it needs.\r
0ff5aa9c 107\r
e7abb94d
RN
108 @retval EFI_SUCCESS The stacks are assigned successfully.\r
109 @retval EFI_UNSUPPORTED This function is not supported.\r
0f7bccf5 110 @retval EFI_BUFFER_TOO_SMALL This BufferSize is too small.\r
0ff5aa9c
JW
111**/\r
112EFI_STATUS\r
113EFIAPI\r
e7abb94d 114InitializeSeparateExceptionStacks (\r
0f7bccf5
ZL
115 IN VOID *Buffer,\r
116 IN OUT UINTN *BufferSize\r
0ff5aa9c
JW
117 )\r
118{\r
e7abb94d 119 return EFI_UNSUPPORTED;\r
0ff5aa9c 120}\r