]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Drivers/CpuDxe/Exception.c
ArmPkg: Replace BSD License with BSD+Patent License
[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 - 2014, ARM Ltd. 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 EFI_STATUS Status;
19 EFI_VECTOR_HANDOFF_INFO *VectorInfoList;
20 EFI_VECTOR_HANDOFF_INFO *VectorInfo;
21 BOOLEAN IrqEnabled;
22 BOOLEAN FiqEnabled;
23
24 VectorInfo = (EFI_VECTOR_HANDOFF_INFO *)NULL;
25 Status = EfiGetSystemConfigurationTable(&gEfiVectorHandoffTableGuid, (VOID **)&VectorInfoList);
26 if (Status == EFI_SUCCESS && VectorInfoList != NULL) {
27 VectorInfo = VectorInfoList;
28 }
29
30 // intialize the CpuExceptionHandlerLib so we take over the exception vector table from the DXE Core
31 InitializeCpuExceptionHandlers(VectorInfo);
32
33 Status = EFI_SUCCESS;
34
35 //
36 // Disable interrupts
37 //
38 Cpu->GetInterruptState (Cpu, &IrqEnabled);
39 Cpu->DisableInterrupt (Cpu);
40
41 //
42 // EFI does not use the FIQ, but a debugger might so we must disable
43 // as we take over the exception vectors.
44 //
45 FiqEnabled = ArmGetFiqState ();
46 ArmDisableFiq ();
47
48 if (FiqEnabled) {
49 ArmEnableFiq ();
50 }
51
52 if (IrqEnabled) {
53 //
54 // Restore interrupt state
55 //
56 Status = Cpu->EnableInterrupt (Cpu);
57 }
58
59 //
60 // On a DEBUG build, unmask SErrors so they are delivered right away rather
61 // than when the OS unmasks them. This gives us a better chance of figuring
62 // out the cause.
63 //
64 DEBUG_CODE (
65 ArmEnableAsynchronousAbort ();
66 );
67
68 return Status;
69 }
70
71 /**
72 This function registers and enables the handler specified by InterruptHandler for a processor
73 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
74 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
75 The installed handler is called once for each processor interrupt or exception.
76
77 @param InterruptType A pointer to the processor's current interrupt state. Set to TRUE if interrupts
78 are enabled and FALSE if interrupts are disabled.
79 @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
80 when a processor interrupt occurs. If this parameter is NULL, then the handler
81 will be uninstalled.
82
83 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
84 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
85 previously installed.
86 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
87 previously installed.
88 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported.
89
90 **/
91 EFI_STATUS
92 RegisterInterruptHandler(
93 IN EFI_EXCEPTION_TYPE InterruptType,
94 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
95 ) {
96 // pass down to CpuExceptionHandlerLib
97 return (EFI_STATUS)RegisterCpuInterruptHandler(InterruptType, InterruptHandler);
98 }