]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmExceptionLib/AArch64/AArch64Exception.c
bd307628af87a1531071a3feaa2009a060974d5f
[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 * This program and the accompanying materials
7 * are licensed and made available under the terms and conditions of the BSD License
8 * which accompanies this distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
10 *
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 *
14 **/
15
16 #include <Uefi.h>
17
18 #include <Chipset/AArch64.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Protocol/DebugSupport.h> // for MAX_AARCH64_EXCEPTION
21
22 UINTN gMaxExceptionNumber = MAX_AARCH64_EXCEPTION;
23 EFI_EXCEPTION_CALLBACK gExceptionHandlers[MAX_AARCH64_EXCEPTION + 1] = { 0 };
24 EFI_EXCEPTION_CALLBACK gDebuggerExceptionHandlers[MAX_AARCH64_EXCEPTION + 1] = { 0 };
25 PHYSICAL_ADDRESS gExceptionVectorAlignmentMask = ARM_VECTOR_TABLE_ALIGNMENT;
26 UINTN gDebuggerNoHandlerValue = 0; // todo: define for AArch64
27
28 #define EL0_STACK_PAGES 2
29
30 VOID
31 RegisterEl0Stack (
32 IN VOID *Stack
33 );
34
35 RETURN_STATUS ArchVectorConfig(
36 IN UINTN VectorBaseAddress
37 )
38 {
39 UINTN HcrReg;
40 UINT8 *Stack;
41
42 Stack = AllocatePages (EL0_STACK_PAGES);
43 if (Stack == NULL) {
44 return RETURN_OUT_OF_RESOURCES;
45 }
46
47 RegisterEl0Stack ((UINT8 *)Stack + EFI_PAGES_TO_SIZE (EL0_STACK_PAGES));
48
49 if (ArmReadCurrentEL() == AARCH64_EL2) {
50 HcrReg = ArmReadHcr();
51
52 // Trap General Exceptions. All exceptions that would be routed to EL1 are routed to EL2
53 HcrReg |= ARM_HCR_TGE;
54
55 ArmWriteHcr(HcrReg);
56 }
57
58 return RETURN_SUCCESS;
59 }