]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmExceptionLib/AArch64/AArch64Exception.c
be1cdcf5ebc70310b1d81186d26e4625e7b1350d
[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_PAGES 2
23
24 VOID
25 RegisterEl0Stack (
26 IN VOID *Stack
27 );
28
29 RETURN_STATUS ArchVectorConfig(
30 IN UINTN VectorBaseAddress
31 )
32 {
33 UINTN HcrReg;
34 UINT8 *Stack;
35
36 Stack = AllocatePages (EL0_STACK_PAGES);
37 if (Stack == NULL) {
38 return RETURN_OUT_OF_RESOURCES;
39 }
40
41 RegisterEl0Stack ((UINT8 *)Stack + EFI_PAGES_TO_SIZE (EL0_STACK_PAGES));
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 }