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