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