]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmException.c
UefiCpuPkg/ExceptionLib: Move global variable location
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / SmmException.c
1 /** @file
2 CPU exception handler library implemenation for SMM modules.
3
4 Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiSmm.h>
16 #include "CpuExceptionCommon.h"
17
18 CONST UINTN mDoFarReturnFlag = 1;
19
20 //
21 // Spin lock for CPU information display
22 //
23 SPIN_LOCK mDisplayMessageSpinLock;
24
25 //
26 // Image align size for DXE/SMM
27 //
28 CONST UINTN mImageAlignSize = SIZE_4KB;
29
30 RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
31 EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
32 EXCEPTION_HANDLER_DATA mExceptionHandlerData;
33 /**
34 Common exception handler.
35
36 @param ExceptionType Exception type.
37 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
38 **/
39 VOID
40 EFIAPI
41 CommonExceptionHandler (
42 IN EFI_EXCEPTION_TYPE ExceptionType,
43 IN EFI_SYSTEM_CONTEXT SystemContext
44 )
45 {
46 CommonExceptionHandlerWorker (ExceptionType, SystemContext, &mExceptionHandlerData);
47 }
48
49 /**
50 Initializes all CPU exceptions entries and provides the default exception handlers.
51
52 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
53 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
54 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
55 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
56
57 @param[in] VectorInfo Pointer to reserved vector list.
58
59 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
60 with default exception handlers.
61 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
62 @retval EFI_UNSUPPORTED This function is not supported.
63
64 **/
65 EFI_STATUS
66 EFIAPI
67 InitializeCpuExceptionHandlers (
68 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
69 )
70 {
71 mExceptionHandlerData.ReservedVectors = mReservedVectorsData;
72 mExceptionHandlerData.ExternalInterruptHandler = mExternalInterruptHandlerTable;
73 InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock);
74 return InitializeCpuExceptionHandlersWorker (VectorInfo, &mExceptionHandlerData);
75 }
76
77 /**
78 Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.
79
80 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
81 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
82 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
83 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
84
85 @param[in] VectorInfo Pointer to reserved vector list.
86
87 @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized
88 with default interrupt/exception handlers.
89 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
90 @retval EFI_UNSUPPORTED This function is not supported.
91
92 **/
93 EFI_STATUS
94 EFIAPI
95 InitializeCpuInterruptHandlers (
96 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
97 )
98 {
99 return EFI_UNSUPPORTED;
100 }
101
102 /**
103 Registers a function to be called from the processor interrupt handler.
104
105 This function registers and enables the handler specified by InterruptHandler for a processor
106 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
107 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
108 The installed handler is called once for each processor interrupt or exception.
109 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or
110 InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.
111
112 @param[in] InterruptType Defines which interrupt or exception to hook.
113 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
114 when a processor interrupt occurs. If this parameter is NULL, then the handler
115 will be uninstalled.
116
117 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
118 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
119 previously installed.
120 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
121 previously installed.
122 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
123 or this function is not supported.
124 **/
125 EFI_STATUS
126 EFIAPI
127 RegisterCpuInterruptHandler (
128 IN EFI_EXCEPTION_TYPE InterruptType,
129 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
130 )
131 {
132 return RegisterCpuInterruptHandlerWorker (InterruptType, InterruptHandler, &mExceptionHandlerData);
133 }