]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmExceptionLib/AArch64/AArch64Exception.c
ArmPkg: Fix Ecc error 5003 in ArmExceptionLib
[mirror_edk2.git] / ArmPkg / Library / ArmExceptionLib / AArch64 / AArch64Exception.c
1 /** @file
2 * Exception Handling support specific for AArch64
3 *
4 * Copyright (c) 2016 HP Development Company, L.P.
5 * Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
6 *
7 * SPDX-License-Identifier: BSD-2-Clause-Patent
8 *
9 **/
10
11 #include <Uefi.h>
12
13 #include <Chipset/AArch64.h>
14 #include <Library/MemoryAllocationLib.h>
15 #include <Protocol/DebugSupport.h> // for MAX_AARCH64_EXCEPTION
16
17 UINTN gMaxExceptionNumber = MAX_AARCH64_EXCEPTION;
18 EFI_EXCEPTION_CALLBACK gExceptionHandlers[MAX_AARCH64_EXCEPTION + 1] = { 0 };
19 EFI_EXCEPTION_CALLBACK gDebuggerExceptionHandlers[MAX_AARCH64_EXCEPTION + 1] = { 0 };
20 PHYSICAL_ADDRESS gExceptionVectorAlignmentMask = ARM_VECTOR_TABLE_ALIGNMENT;
21 UINTN gDebuggerNoHandlerValue = 0; // todo: define for AArch64
22
23 #define EL0_STACK_SIZE EFI_PAGES_TO_SIZE(2)
24 STATIC UINTN mNewStackBase[EL0_STACK_SIZE / sizeof (UINTN)];
25
26 VOID
27 RegisterEl0Stack (
28 IN VOID *Stack
29 );
30
31 RETURN_STATUS
32 ArchVectorConfig (
33 IN UINTN VectorBaseAddress
34 )
35 {
36 UINTN HcrReg;
37
38 // Round down sp by 16 bytes alignment
39 RegisterEl0Stack (
40 (VOID *)(((UINTN)mNewStackBase + EL0_STACK_SIZE) & ~0xFUL)
41 );
42
43 if (ArmReadCurrentEL() == AARCH64_EL2) {
44 HcrReg = ArmReadHcr();
45
46 // Trap General Exceptions. All exceptions that would be routed to EL1 are routed to EL2
47 HcrReg |= ARM_HCR_TGE;
48
49 ArmWriteHcr(HcrReg);
50 }
51
52 return RETURN_SUCCESS;
53 }