]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Drivers/CpuDxe/Exception.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmPkg / Drivers / CpuDxe / Exception.c
1 /** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Portions Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "CpuDxe.h"
11 #include <Library/CpuExceptionHandlerLib.h>
12 #include <Guid/VectorHandoffTable.h>
13
14 EFI_STATUS
15 InitializeExceptions (
16 IN EFI_CPU_ARCH_PROTOCOL *Cpu
17 )
18 {
19 EFI_STATUS Status;
20 EFI_VECTOR_HANDOFF_INFO *VectorInfoList;
21 EFI_VECTOR_HANDOFF_INFO *VectorInfo;
22 BOOLEAN IrqEnabled;
23 BOOLEAN FiqEnabled;
24
25 VectorInfo = (EFI_VECTOR_HANDOFF_INFO *)NULL;
26 Status = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID **)&VectorInfoList);
27 if ((Status == EFI_SUCCESS) && (VectorInfoList != NULL)) {
28 VectorInfo = VectorInfoList;
29 }
30
31 // initialize the CpuExceptionHandlerLib so we take over the exception vector table from the DXE Core
32 InitializeCpuExceptionHandlers (VectorInfo);
33
34 Status = EFI_SUCCESS;
35
36 //
37 // Disable interrupts
38 //
39 Cpu->GetInterruptState (Cpu, &IrqEnabled);
40 Cpu->DisableInterrupt (Cpu);
41
42 //
43 // EFI does not use the FIQ, but a debugger might so we must disable
44 // as we take over the exception vectors.
45 //
46 FiqEnabled = ArmGetFiqState ();
47 ArmDisableFiq ();
48
49 if (FiqEnabled) {
50 ArmEnableFiq ();
51 }
52
53 if (IrqEnabled) {
54 //
55 // Restore interrupt state
56 //
57 Status = Cpu->EnableInterrupt (Cpu);
58 }
59
60 //
61 // On a DEBUG build, unmask SErrors so they are delivered right away rather
62 // than when the OS unmasks them. This gives us a better chance of figuring
63 // out the cause.
64 //
65 DEBUG_CODE (
66 ArmEnableAsynchronousAbort ();
67 );
68
69 return Status;
70 }
71
72 /**
73 This function registers and enables the handler specified by InterruptHandler for a processor
74 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
75 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
76 The installed handler is called once for each processor interrupt or exception.
77
78 @param InterruptType A pointer to the processor's current interrupt state. Set to TRUE if interrupts
79 are enabled and FALSE if interrupts are disabled.
80 @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
81 when a processor interrupt occurs. If this parameter is NULL, then the handler
82 will be uninstalled.
83
84 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
85 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
86 previously installed.
87 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
88 previously installed.
89 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported.
90
91 **/
92 EFI_STATUS
93 RegisterInterruptHandler (
94 IN EFI_EXCEPTION_TYPE InterruptType,
95 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
96 )
97 {
98 // pass down to CpuExceptionHandlerLib
99 return (EFI_STATUS)RegisterCpuInterruptHandler (InterruptType, InterruptHandler);
100 }