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