ArmPkg: update CpuDxe to use CpuExceptionHandlerLib
Use the new ARM/AArch64 implementation of the base CpuExceptionHandlerLib library from CpuDxe to centralize exception handling. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eugene Cohen <eugene@hp.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
This commit is contained in:
committed by
Ard Biesheuvel
parent
8a47a6cb9e
commit
5811eea0fd
@@ -1,234 +0,0 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
||||
Copyright (c) 2014, ARM Limited. All rights reserved.<BR>
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "CpuDxe.h"
|
||||
|
||||
//FIXME: Will not compile on non-ARMv7 builds
|
||||
#include <Chipset/ArmV7.h>
|
||||
|
||||
VOID
|
||||
ExceptionHandlersStart (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
ExceptionHandlersEnd (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
CommonExceptionEntry (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
AsmCommonExceptionEntry (
|
||||
VOID
|
||||
);
|
||||
|
||||
|
||||
EFI_EXCEPTION_CALLBACK gExceptionHandlers[MAX_ARM_EXCEPTION + 1];
|
||||
EFI_EXCEPTION_CALLBACK gDebuggerExceptionHandlers[MAX_ARM_EXCEPTION + 1];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
This function registers and enables the handler specified by InterruptHandler for a processor
|
||||
interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
|
||||
handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
|
||||
The installed handler is called once for each processor interrupt or exception.
|
||||
|
||||
@param InterruptType A pointer to the processor's current interrupt state. Set to TRUE if interrupts
|
||||
are enabled and FALSE if interrupts are disabled.
|
||||
@param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
|
||||
when a processor interrupt occurs. If this parameter is NULL, then the handler
|
||||
will be uninstalled.
|
||||
|
||||
@retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
|
||||
@retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
|
||||
previously installed.
|
||||
@retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
|
||||
previously installed.
|
||||
@retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
RegisterInterruptHandler (
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
|
||||
)
|
||||
{
|
||||
if (InterruptType > MAX_ARM_EXCEPTION) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if ((InterruptHandler != NULL) && (gExceptionHandlers[InterruptType] != NULL)) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
gExceptionHandlers[InterruptType] = InterruptHandler;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
CommonCExceptionHandler (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN OUT EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
if (ExceptionType <= MAX_ARM_EXCEPTION) {
|
||||
if (gExceptionHandlers[ExceptionType]) {
|
||||
gExceptionHandlers[ExceptionType] (ExceptionType, SystemContext);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
DEBUG ((EFI_D_ERROR, "Unknown exception type %d from %08x\n", ExceptionType, SystemContext.SystemContextArm->PC));
|
||||
ASSERT (FALSE);
|
||||
}
|
||||
|
||||
if (ExceptionType == EXCEPT_ARM_SOFTWARE_INTERRUPT) {
|
||||
//
|
||||
// ARM JTAG debuggers some times use this vector, so it is not an error to get one
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
DefaultExceptionHandler (ExceptionType, SystemContext);
|
||||
}
|
||||
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
InitializeExceptions (
|
||||
IN EFI_CPU_ARCH_PROTOCOL *Cpu
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Offset;
|
||||
UINTN Length;
|
||||
UINTN Index;
|
||||
BOOLEAN IrqEnabled;
|
||||
BOOLEAN FiqEnabled;
|
||||
EFI_PHYSICAL_ADDRESS Base;
|
||||
UINT32 *VectorBase;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
ZeroMem (gExceptionHandlers,sizeof(*gExceptionHandlers));
|
||||
|
||||
//
|
||||
// Disable interrupts
|
||||
//
|
||||
Cpu->GetInterruptState (Cpu, &IrqEnabled);
|
||||
Cpu->DisableInterrupt (Cpu);
|
||||
|
||||
//
|
||||
// EFI does not use the FIQ, but a debugger might so we must disable
|
||||
// as we take over the exception vectors.
|
||||
//
|
||||
FiqEnabled = ArmGetFiqState ();
|
||||
ArmDisableFiq ();
|
||||
|
||||
if (FeaturePcdGet(PcdRelocateVectorTable) == TRUE) {
|
||||
//
|
||||
// Copy an implementation of the ARM exception vectors to PcdCpuVectorBaseAddress.
|
||||
//
|
||||
Length = (UINTN)ExceptionHandlersEnd - (UINTN)ExceptionHandlersStart;
|
||||
|
||||
// Check if the exception vector is in the low address
|
||||
if (PcdGet32 (PcdCpuVectorBaseAddress) == 0x0) {
|
||||
// Set SCTLR.V to 0 to enable VBAR to be used
|
||||
ArmSetLowVectors ();
|
||||
} else {
|
||||
ArmSetHighVectors ();
|
||||
}
|
||||
|
||||
//
|
||||
// Reserve space for the exception handlers
|
||||
//
|
||||
Base = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdCpuVectorBaseAddress);
|
||||
VectorBase = (UINT32 *)(UINTN)Base;
|
||||
Status = gBS->AllocatePages (AllocateAddress, EfiBootServicesCode, EFI_SIZE_TO_PAGES (Length), &Base);
|
||||
// If the request was for memory that's not in the memory map (which is often the case for 0x00000000
|
||||
// on embedded systems, for example, we don't want to hang up. So we'll check here for a status of
|
||||
// EFI_NOT_FOUND, and continue in that case.
|
||||
if (EFI_ERROR(Status) && (Status != EFI_NOT_FOUND)) {
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
|
||||
if (FeaturePcdGet(PcdDebuggerExceptionSupport) == TRUE) {
|
||||
// Save existing vector table, in case debugger is already hooked in
|
||||
CopyMem ((VOID *)gDebuggerExceptionHandlers, (VOID *)VectorBase, sizeof (gDebuggerExceptionHandlers));
|
||||
}
|
||||
|
||||
// Copy our assembly code into the page that contains the exception vectors.
|
||||
CopyMem ((VOID *)VectorBase, (VOID *)ExceptionHandlersStart, Length);
|
||||
|
||||
//
|
||||
// Patch in the common Assembly exception handler
|
||||
//
|
||||
Offset = (UINTN)CommonExceptionEntry - (UINTN)ExceptionHandlersStart;
|
||||
*(UINTN *) ((UINT8 *)(UINTN)PcdGet32 (PcdCpuVectorBaseAddress) + Offset) = (UINTN)AsmCommonExceptionEntry;
|
||||
|
||||
//
|
||||
// Initialize the C entry points for interrupts
|
||||
//
|
||||
for (Index = 0; Index <= MAX_ARM_EXCEPTION; Index++) {
|
||||
if (!FeaturePcdGet(PcdDebuggerExceptionSupport) ||
|
||||
(gDebuggerExceptionHandlers[Index] == 0) || (gDebuggerExceptionHandlers[Index] == (VOID *)(UINTN)0xEAFFFFFE)) {
|
||||
// Exception handler contains branch to vector location (jmp $) so no handler
|
||||
// NOTE: This code assumes vectors are ARM and not Thumb code
|
||||
Status = RegisterInterruptHandler (Index, NULL);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
} else {
|
||||
// If the debugger has already hooked put its vector back
|
||||
VectorBase[Index] = (UINT32)(UINTN)gDebuggerExceptionHandlers[Index];
|
||||
}
|
||||
}
|
||||
|
||||
// Flush Caches since we updated executable stuff
|
||||
InvalidateInstructionCacheRange ((VOID *)PcdGet32(PcdCpuVectorBaseAddress), Length);
|
||||
|
||||
//Note: On ARM processor with the Security Extension, the Vector Table can be located anywhere in the memory.
|
||||
// The Vector Base Address Register defines the location
|
||||
ArmWriteVBar (PcdGet32(PcdCpuVectorBaseAddress));
|
||||
} else {
|
||||
// The Vector table must be 32-byte aligned
|
||||
if (((UINT32)ExceptionHandlersStart & ARM_VECTOR_TABLE_ALIGNMENT) != 0) {
|
||||
ASSERT (0);
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
// We do not copy the Exception Table at PcdGet32(PcdCpuVectorBaseAddress). We just set Vector Base Address to point into CpuDxe code.
|
||||
ArmWriteVBar ((UINT32)ExceptionHandlersStart);
|
||||
}
|
||||
|
||||
if (FiqEnabled) {
|
||||
ArmEnableFiq ();
|
||||
}
|
||||
|
||||
if (IrqEnabled) {
|
||||
//
|
||||
// Restore interrupt state
|
||||
//
|
||||
Status = Cpu->EnableInterrupt (Cpu);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
@@ -1,304 +0,0 @@
|
||||
#------------------------------------------------------------------------------
|
||||
#
|
||||
# Use ARMv6 instruction to operate on a single stack
|
||||
#
|
||||
# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
|
||||
# Copyright (c) 2014, ARM Limited. All rights reserved.<BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
#include <Library/PcdLib.h>
|
||||
|
||||
/*
|
||||
|
||||
This is the stack constructed by the exception handler (low address to high address)
|
||||
# R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM
|
||||
Reg Offset
|
||||
=== ======
|
||||
R0 0x00 # stmfd SP!,{R0-R12}
|
||||
R1 0x04
|
||||
R2 0x08
|
||||
R3 0x0c
|
||||
R4 0x10
|
||||
R5 0x14
|
||||
R6 0x18
|
||||
R7 0x1c
|
||||
R8 0x20
|
||||
R9 0x24
|
||||
R10 0x28
|
||||
R11 0x2c
|
||||
R12 0x30
|
||||
SP 0x34 # reserved via subtraction 0x20 (32) from SP
|
||||
LR 0x38
|
||||
PC 0x3c
|
||||
CPSR 0x40
|
||||
DFSR 0x44
|
||||
DFAR 0x48
|
||||
IFSR 0x4c
|
||||
IFAR 0x50
|
||||
|
||||
LR 0x54 # SVC Link register (we need to restore it)
|
||||
|
||||
LR 0x58 # pushed by srsfd
|
||||
CPSR 0x5c
|
||||
|
||||
*/
|
||||
|
||||
|
||||
GCC_ASM_EXPORT(ExceptionHandlersStart)
|
||||
GCC_ASM_EXPORT(ExceptionHandlersEnd)
|
||||
GCC_ASM_EXPORT(CommonExceptionEntry)
|
||||
GCC_ASM_EXPORT(AsmCommonExceptionEntry)
|
||||
GCC_ASM_EXPORT(CommonCExceptionHandler)
|
||||
|
||||
.text
|
||||
.syntax unified
|
||||
#if !defined(__APPLE__)
|
||||
.fpu neon @ makes vpush/vpop assemble
|
||||
#endif
|
||||
.align 5
|
||||
|
||||
|
||||
//
|
||||
// This code gets copied to the ARM vector table
|
||||
// ExceptionHandlersStart - ExceptionHandlersEnd gets copied
|
||||
//
|
||||
ASM_PFX(ExceptionHandlersStart):
|
||||
|
||||
ASM_PFX(Reset):
|
||||
b ASM_PFX(ResetEntry)
|
||||
|
||||
ASM_PFX(UndefinedInstruction):
|
||||
b ASM_PFX(UndefinedInstructionEntry)
|
||||
|
||||
ASM_PFX(SoftwareInterrupt):
|
||||
b ASM_PFX(SoftwareInterruptEntry)
|
||||
|
||||
ASM_PFX(PrefetchAbort):
|
||||
b ASM_PFX(PrefetchAbortEntry)
|
||||
|
||||
ASM_PFX(DataAbort):
|
||||
b ASM_PFX(DataAbortEntry)
|
||||
|
||||
ASM_PFX(ReservedException):
|
||||
b ASM_PFX(ReservedExceptionEntry)
|
||||
|
||||
ASM_PFX(Irq):
|
||||
b ASM_PFX(IrqEntry)
|
||||
|
||||
ASM_PFX(Fiq):
|
||||
b ASM_PFX(FiqEntry)
|
||||
|
||||
ASM_PFX(ResetEntry):
|
||||
srsdb #0x13! @ Store return state on SVC stack
|
||||
@ We are already in SVC mode
|
||||
|
||||
stmfd SP!,{LR} @ Store the link register for the current mode
|
||||
sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} @ Store the register state
|
||||
|
||||
mov R0,#0 @ ExceptionType
|
||||
ldr R1,ASM_PFX(CommonExceptionEntry)
|
||||
bx R1
|
||||
|
||||
ASM_PFX(UndefinedInstructionEntry):
|
||||
sub LR, LR, #4 @ Only -2 for Thumb, adjust in CommonExceptionEntry
|
||||
srsdb #0x13! @ Store return state on SVC stack
|
||||
cps #0x13 @ Switch to SVC for common stack
|
||||
stmfd SP!,{LR} @ Store the link register for the current mode
|
||||
sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} @ Store the register state
|
||||
|
||||
mov R0,#1 @ ExceptionType
|
||||
ldr R1,ASM_PFX(CommonExceptionEntry)
|
||||
bx R1
|
||||
|
||||
ASM_PFX(SoftwareInterruptEntry):
|
||||
srsdb #0x13! @ Store return state on SVC stack
|
||||
@ We are already in SVC mode
|
||||
stmfd SP!,{LR} @ Store the link register for the current mode
|
||||
sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} @ Store the register state
|
||||
|
||||
mov R0,#2 @ ExceptionType
|
||||
ldr R1,ASM_PFX(CommonExceptionEntry)
|
||||
bx R1
|
||||
|
||||
ASM_PFX(PrefetchAbortEntry):
|
||||
sub LR,LR,#4
|
||||
srsdb #0x13! @ Store return state on SVC stack
|
||||
cps #0x13 @ Switch to SVC for common stack
|
||||
stmfd SP!,{LR} @ Store the link register for the current mode
|
||||
sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} @ Store the register state
|
||||
|
||||
mov R0,#3 @ ExceptionType
|
||||
ldr R1,ASM_PFX(CommonExceptionEntry)
|
||||
bx R1
|
||||
|
||||
ASM_PFX(DataAbortEntry):
|
||||
sub LR,LR,#8
|
||||
srsdb #0x13! @ Store return state on SVC stack
|
||||
cps #0x13 @ Switch to SVC for common stack
|
||||
stmfd SP!,{LR} @ Store the link register for the current mode
|
||||
sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} @ Store the register state
|
||||
|
||||
mov R0,#4
|
||||
ldr R1,ASM_PFX(CommonExceptionEntry)
|
||||
bx R1
|
||||
|
||||
ASM_PFX(ReservedExceptionEntry):
|
||||
srsdb #0x13! @ Store return state on SVC stack
|
||||
cps #0x13 @ Switch to SVC for common stack
|
||||
stmfd SP!,{LR} @ Store the link register for the current mode
|
||||
sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} @ Store the register state
|
||||
|
||||
mov R0,#5
|
||||
ldr R1,ASM_PFX(CommonExceptionEntry)
|
||||
bx R1
|
||||
|
||||
ASM_PFX(IrqEntry):
|
||||
sub LR,LR,#4
|
||||
srsdb #0x13! @ Store return state on SVC stack
|
||||
cps #0x13 @ Switch to SVC for common stack
|
||||
stmfd SP!,{LR} @ Store the link register for the current mode
|
||||
sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} @ Store the register state
|
||||
|
||||
mov R0,#6 @ ExceptionType
|
||||
ldr R1,ASM_PFX(CommonExceptionEntry)
|
||||
bx R1
|
||||
|
||||
ASM_PFX(FiqEntry):
|
||||
sub LR,LR,#4
|
||||
srsdb #0x13! @ Store return state on SVC stack
|
||||
cps #0x13 @ Switch to SVC for common stack
|
||||
stmfd SP!,{LR} @ Store the link register for the current mode
|
||||
sub SP,SP,#0x20 @ Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} @ Store the register state
|
||||
@ Since we have already switch to SVC R8_fiq - R12_fiq
|
||||
@ never get used or saved
|
||||
mov R0,#7 @ ExceptionType
|
||||
ldr R1,ASM_PFX(CommonExceptionEntry)
|
||||
bx R1
|
||||
|
||||
//
|
||||
// This gets patched by the C code that patches in the vector table
|
||||
//
|
||||
ASM_PFX(CommonExceptionEntry):
|
||||
.word ASM_PFX(AsmCommonExceptionEntry)
|
||||
|
||||
ASM_PFX(ExceptionHandlersEnd):
|
||||
|
||||
//
|
||||
// This code runs from CpuDxe driver loaded address. It is patched into
|
||||
// CommonExceptionEntry.
|
||||
//
|
||||
ASM_PFX(AsmCommonExceptionEntry):
|
||||
mrc p15, 0, R1, c6, c0, 2 @ Read IFAR
|
||||
str R1, [SP, #0x50] @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR
|
||||
|
||||
mrc p15, 0, R1, c5, c0, 1 @ Read IFSR
|
||||
str R1, [SP, #0x4c] @ Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR
|
||||
|
||||
mrc p15, 0, R1, c6, c0, 0 @ Read DFAR
|
||||
str R1, [SP, #0x48] @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR
|
||||
|
||||
mrc p15, 0, R1, c5, c0, 0 @ Read DFSR
|
||||
str R1, [SP, #0x44] @ Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR
|
||||
|
||||
ldr R1, [SP, #0x5c] @ srsdb saved pre-exception CPSR on the stack
|
||||
str R1, [SP, #0x40] @ Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR
|
||||
|
||||
add R2, SP, #0x38 @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
|
||||
and R3, R1, #0x1f @ Check CPSR to see if User or System Mode
|
||||
cmp R3, #0x1f @ if ((CPSR == 0x10) || (CPSR == 0x1f))
|
||||
cmpne R3, #0x10 @
|
||||
stmdaeq R2, {lr}^ @ save unbanked lr
|
||||
@ else
|
||||
stmdane R2, {lr} @ save SVC lr
|
||||
|
||||
|
||||
ldr R5, [SP, #0x58] @ PC is the LR pushed by srsfd
|
||||
@ Check to see if we have to adjust for Thumb entry
|
||||
sub r4, r0, #1 @ if (ExceptionType == 1 || ExceptionType == 2)) {
|
||||
cmp r4, #1 @ // UND & SVC have differnt LR adjust for Thumb
|
||||
bhi NoAdjustNeeded
|
||||
|
||||
tst r1, #0x20 @ if ((CPSR & T)) == T) { // Thumb Mode on entry
|
||||
addne R5, R5, #2 @ PC += 2;
|
||||
strne R5,[SP,#0x58] @ Update LR value pushed by srsfd
|
||||
|
||||
NoAdjustNeeded:
|
||||
|
||||
str R5, [SP, #0x3c] @ Store it in EFI_SYSTEM_CONTEXT_ARM.PC
|
||||
|
||||
add R1, SP, #0x60 @ We pushed 0x60 bytes on the stack
|
||||
str R1, [SP, #0x34] @ Store it in EFI_SYSTEM_CONTEXT_ARM.SP
|
||||
|
||||
@ R0 is ExceptionType
|
||||
mov R1,SP @ R1 is SystemContext
|
||||
|
||||
#if (FixedPcdGet32(PcdVFPEnabled))
|
||||
vpush {d0-d15} @ save vstm registers in case they are used in optimizations
|
||||
#endif
|
||||
|
||||
mov R4, SP @ Save current SP
|
||||
tst R4, #4
|
||||
subne SP, SP, #4 @ Adjust SP if not 8-byte aligned
|
||||
|
||||
/*
|
||||
VOID
|
||||
EFIAPI
|
||||
CommonCExceptionHandler (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType, R0
|
||||
IN OUT EFI_SYSTEM_CONTEXT SystemContext R1
|
||||
)
|
||||
|
||||
*/
|
||||
blx ASM_PFX(CommonCExceptionHandler) @ Call exception handler
|
||||
|
||||
mov SP, R4 @ Restore SP
|
||||
|
||||
#if (FixedPcdGet32(PcdVFPEnabled))
|
||||
vpop {d0-d15}
|
||||
#endif
|
||||
|
||||
ldr R1, [SP, #0x4c] @ Restore EFI_SYSTEM_CONTEXT_ARM.IFSR
|
||||
mcr p15, 0, R1, c5, c0, 1 @ Write IFSR
|
||||
|
||||
ldr R1, [SP, #0x44] @ Restore EFI_SYSTEM_CONTEXT_ARM.DFSR
|
||||
mcr p15, 0, R1, c5, c0, 0 @ Write DFSR
|
||||
|
||||
ldr R1,[SP,#0x3c] @ EFI_SYSTEM_CONTEXT_ARM.PC
|
||||
str R1,[SP,#0x58] @ Store it back to srsfd stack slot so it can be restored
|
||||
|
||||
ldr R1,[SP,#0x40] @ EFI_SYSTEM_CONTEXT_ARM.CPSR
|
||||
str R1,[SP,#0x5c] @ Store it back to srsfd stack slot so it can be restored
|
||||
|
||||
add R3, SP, #0x54 @ Make R3 point to SVC LR saved on entry
|
||||
add R2, SP, #0x38 @ Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
|
||||
and R1, R1, #0x1f @ Check to see if User or System Mode
|
||||
cmp R1, #0x1f @ if ((CPSR == 0x10) || (CPSR == 0x1f))
|
||||
cmpne R1, #0x10 @
|
||||
ldmibeq R2, {lr}^ @ restore unbanked lr
|
||||
@ else
|
||||
ldmibne R3, {lr} @ restore SVC lr, via ldmfd SP!, {LR}
|
||||
|
||||
ldmfd SP!,{R0-R12} @ Restore general purpose registers
|
||||
@ Exception handler can not change SP
|
||||
|
||||
add SP,SP,#0x20 @ Clear out the remaining stack space
|
||||
ldmfd SP!,{LR} @ restore the link register for this context
|
||||
rfefd SP! @ return from exception via srsfd stack slot
|
||||
|
@@ -1,301 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//
|
||||
// Use ARMv6 instruction to operate on a single stack
|
||||
//
|
||||
// Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
|
||||
// Copyright (c) 2014, ARM Limited. All rights reserved.<BR>
|
||||
//
|
||||
// This program and the accompanying materials
|
||||
// are licensed and made available under the terms and conditions of the BSD License
|
||||
// which accompanies this distribution. The full text of the license may be found at
|
||||
// http://opensource.org/licenses/bsd-license.php
|
||||
//
|
||||
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <Library/PcdLib.h>
|
||||
|
||||
/*
|
||||
|
||||
This is the stack constructed by the exception handler (low address to high address)
|
||||
# R0 - IFAR is EFI_SYSTEM_CONTEXT for ARM
|
||||
Reg Offset
|
||||
=== ======
|
||||
R0 0x00 # stmfd SP!,{R0-R12}
|
||||
R1 0x04
|
||||
R2 0x08
|
||||
R3 0x0c
|
||||
R4 0x10
|
||||
R5 0x14
|
||||
R6 0x18
|
||||
R7 0x1c
|
||||
R8 0x20
|
||||
R9 0x24
|
||||
R10 0x28
|
||||
R11 0x2c
|
||||
R12 0x30
|
||||
SP 0x34 # reserved via subtraction 0x20 (32) from SP
|
||||
LR 0x38
|
||||
PC 0x3c
|
||||
CPSR 0x40
|
||||
DFSR 0x44
|
||||
DFAR 0x48
|
||||
IFSR 0x4c
|
||||
IFAR 0x50
|
||||
|
||||
LR 0x54 # SVC Link register (we need to restore it)
|
||||
|
||||
LR 0x58 # pushed by srsfd
|
||||
CPSR 0x5c
|
||||
|
||||
*/
|
||||
|
||||
|
||||
EXPORT ExceptionHandlersStart
|
||||
EXPORT ExceptionHandlersEnd
|
||||
EXPORT CommonExceptionEntry
|
||||
EXPORT AsmCommonExceptionEntry
|
||||
IMPORT CommonCExceptionHandler
|
||||
|
||||
PRESERVE8
|
||||
AREA DxeExceptionHandlers, CODE, READONLY, CODEALIGN, ALIGN=5
|
||||
|
||||
//
|
||||
// This code gets copied to the ARM vector table
|
||||
// ExceptionHandlersStart - ExceptionHandlersEnd gets copied
|
||||
//
|
||||
ExceptionHandlersStart
|
||||
|
||||
Reset
|
||||
b ResetEntry
|
||||
|
||||
UndefinedInstruction
|
||||
b UndefinedInstructionEntry
|
||||
|
||||
SoftwareInterrupt
|
||||
b SoftwareInterruptEntry
|
||||
|
||||
PrefetchAbort
|
||||
b PrefetchAbortEntry
|
||||
|
||||
DataAbort
|
||||
b DataAbortEntry
|
||||
|
||||
ReservedException
|
||||
b ReservedExceptionEntry
|
||||
|
||||
Irq
|
||||
b IrqEntry
|
||||
|
||||
Fiq
|
||||
b FiqEntry
|
||||
|
||||
ResetEntry
|
||||
srsfd #0x13! ; Store return state on SVC stack
|
||||
; We are already in SVC mode
|
||||
stmfd SP!,{LR} ; Store the link register for the current mode
|
||||
sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} ; Store the register state
|
||||
|
||||
mov R0,#0 ; ExceptionType
|
||||
ldr R1,CommonExceptionEntry
|
||||
bx R1
|
||||
|
||||
UndefinedInstructionEntry
|
||||
sub LR, LR, #4 ; Only -2 for Thumb, adjust in CommonExceptionEntry
|
||||
srsfd #0x13! ; Store return state on SVC stack
|
||||
cps #0x13 ; Switch to SVC for common stack
|
||||
stmfd SP!,{LR} ; Store the link register for the current mode
|
||||
sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} ; Store the register state
|
||||
|
||||
mov R0,#1 ; ExceptionType
|
||||
ldr R1,CommonExceptionEntry;
|
||||
bx R1
|
||||
|
||||
SoftwareInterruptEntry
|
||||
srsfd #0x13! ; Store return state on SVC stack
|
||||
; We are already in SVC mode
|
||||
stmfd SP!,{LR} ; Store the link register for the current mode
|
||||
sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} ; Store the register state
|
||||
|
||||
mov R0,#2 ; ExceptionType
|
||||
ldr R1,CommonExceptionEntry
|
||||
bx R1
|
||||
|
||||
PrefetchAbortEntry
|
||||
sub LR,LR,#4
|
||||
srsfd #0x13! ; Store return state on SVC stack
|
||||
cps #0x13 ; Switch to SVC for common stack
|
||||
stmfd SP!,{LR} ; Store the link register for the current mode
|
||||
sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} ; Store the register state
|
||||
|
||||
mov R0,#3 ; ExceptionType
|
||||
ldr R1,CommonExceptionEntry
|
||||
bx R1
|
||||
|
||||
DataAbortEntry
|
||||
sub LR,LR,#8
|
||||
srsfd #0x13! ; Store return state on SVC stack
|
||||
cps #0x13 ; Switch to SVC for common stack
|
||||
stmfd SP!,{LR} ; Store the link register for the current mode
|
||||
sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} ; Store the register state
|
||||
|
||||
mov R0,#4 ; ExceptionType
|
||||
ldr R1,CommonExceptionEntry
|
||||
bx R1
|
||||
|
||||
ReservedExceptionEntry
|
||||
srsfd #0x13! ; Store return state on SVC stack
|
||||
cps #0x13 ; Switch to SVC for common stack
|
||||
stmfd SP!,{LR} ; Store the link register for the current mode
|
||||
sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} ; Store the register state
|
||||
|
||||
mov R0,#5 ; ExceptionType
|
||||
ldr R1,CommonExceptionEntry
|
||||
bx R1
|
||||
|
||||
IrqEntry
|
||||
sub LR,LR,#4
|
||||
srsfd #0x13! ; Store return state on SVC stack
|
||||
cps #0x13 ; Switch to SVC for common stack
|
||||
stmfd SP!,{LR} ; Store the link register for the current mode
|
||||
sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} ; Store the register state
|
||||
|
||||
mov R0,#6 ; ExceptionType
|
||||
ldr R1,CommonExceptionEntry
|
||||
bx R1
|
||||
|
||||
FiqEntry
|
||||
sub LR,LR,#4
|
||||
srsfd #0x13! ; Store return state on SVC stack
|
||||
cps #0x13 ; Switch to SVC for common stack
|
||||
stmfd SP!,{LR} ; Store the link register for the current mode
|
||||
sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
|
||||
stmfd SP!,{R0-R12} ; Store the register state
|
||||
; Since we have already switch to SVC R8_fiq - R12_fiq
|
||||
; never get used or saved
|
||||
mov R0,#7 ; ExceptionType
|
||||
ldr R1,CommonExceptionEntry
|
||||
bx R1
|
||||
|
||||
//
|
||||
// This gets patched by the C code that patches in the vector table
|
||||
//
|
||||
CommonExceptionEntry
|
||||
dcd AsmCommonExceptionEntry
|
||||
|
||||
ExceptionHandlersEnd
|
||||
|
||||
//
|
||||
// This code runs from CpuDxe driver loaded address. It is patched into
|
||||
// CommonExceptionEntry.
|
||||
//
|
||||
AsmCommonExceptionEntry
|
||||
mrc p15, 0, R1, c6, c0, 2 ; Read IFAR
|
||||
str R1, [SP, #0x50] ; Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR
|
||||
|
||||
mrc p15, 0, R1, c5, c0, 1 ; Read IFSR
|
||||
str R1, [SP, #0x4c] ; Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR
|
||||
|
||||
mrc p15, 0, R1, c6, c0, 0 ; Read DFAR
|
||||
str R1, [SP, #0x48] ; Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR
|
||||
|
||||
mrc p15, 0, R1, c5, c0, 0 ; Read DFSR
|
||||
str R1, [SP, #0x44] ; Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR
|
||||
|
||||
ldr R1, [SP, #0x5c] ; srsfd saved pre-exception CPSR on the stack
|
||||
str R1, [SP, #0x40] ; Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR
|
||||
|
||||
add R2, SP, #0x38 ; Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
|
||||
and R3, R1, #0x1f ; Check CPSR to see if User or System Mode
|
||||
cmp R3, #0x1f ; if ((CPSR == 0x10) || (CPSR == 0x1f))
|
||||
cmpne R3, #0x10 ;
|
||||
stmeqed R2, {lr}^ ; save unbanked lr
|
||||
; else
|
||||
stmneed R2, {lr} ; save SVC lr
|
||||
|
||||
|
||||
ldr R5, [SP, #0x58] ; PC is the LR pushed by srsfd
|
||||
; Check to see if we have to adjust for Thumb entry
|
||||
sub r4, r0, #1 ; if (ExceptionType == 1 || ExceptionType == 2)) {
|
||||
cmp r4, #1 ; // UND & SVC have differnt LR adjust for Thumb
|
||||
bhi NoAdjustNeeded
|
||||
|
||||
tst r1, #0x20 ; if ((CPSR & T)) == T) { // Thumb Mode on entry
|
||||
addne R5, R5, #2 ; PC += 2;
|
||||
strne R5,[SP,#0x58] ; Update LR value pushed by srsfd
|
||||
|
||||
NoAdjustNeeded
|
||||
|
||||
str R5, [SP, #0x3c] ; Store it in EFI_SYSTEM_CONTEXT_ARM.PC
|
||||
|
||||
add R1, SP, #0x60 ; We pushed 0x60 bytes on the stack
|
||||
str R1, [SP, #0x34] ; Store it in EFI_SYSTEM_CONTEXT_ARM.SP
|
||||
|
||||
; R0 is ExceptionType
|
||||
mov R1,SP ; R1 is SystemContext
|
||||
|
||||
#if (FixedPcdGet32(PcdVFPEnabled))
|
||||
vpush {d0-d15} ; save vstm registers in case they are used in optimizations
|
||||
#endif
|
||||
|
||||
mov R4, SP ; Save current SP
|
||||
tst R4, #4
|
||||
subne SP, SP, #4 ; Adjust SP if not 8-byte aligned
|
||||
|
||||
/*
|
||||
VOID
|
||||
EFIAPI
|
||||
CommonCExceptionHandler (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType, R0
|
||||
IN OUT EFI_SYSTEM_CONTEXT SystemContext R1
|
||||
)
|
||||
|
||||
*/
|
||||
blx CommonCExceptionHandler ; Call exception handler
|
||||
|
||||
mov SP, R4 ; Restore SP
|
||||
|
||||
#if (FixedPcdGet32(PcdVFPEnabled))
|
||||
vpop {d0-d15}
|
||||
#endif
|
||||
|
||||
ldr R1, [SP, #0x4c] ; Restore EFI_SYSTEM_CONTEXT_ARM.IFSR
|
||||
mcr p15, 0, R1, c5, c0, 1 ; Write IFSR
|
||||
|
||||
ldr R1, [SP, #0x44] ; Restore EFI_SYSTEM_CONTEXT_ARM.DFSR
|
||||
mcr p15, 0, R1, c5, c0, 0 ; Write DFSR
|
||||
|
||||
ldr R1,[SP,#0x3c] ; EFI_SYSTEM_CONTEXT_ARM.PC
|
||||
str R1,[SP,#0x58] ; Store it back to srsfd stack slot so it can be restored
|
||||
|
||||
ldr R1,[SP,#0x40] ; EFI_SYSTEM_CONTEXT_ARM.CPSR
|
||||
str R1,[SP,#0x5c] ; Store it back to srsfd stack slot so it can be restored
|
||||
|
||||
add R3, SP, #0x54 ; Make R3 point to SVC LR saved on entry
|
||||
add R2, SP, #0x38 ; Make R2 point to EFI_SYSTEM_CONTEXT_ARM.LR
|
||||
and R1, R1, #0x1f ; Check to see if User or System Mode
|
||||
cmp R1, #0x1f ; if ((CPSR == 0x10) || (CPSR == 0x1f))
|
||||
cmpne R1, #0x10 ;
|
||||
ldmeqed R2, {lr}^ ; restore unbanked lr
|
||||
; else
|
||||
ldmneed R3, {lr} ; restore SVC lr, via ldmfd SP!, {LR}
|
||||
|
||||
ldmfd SP!,{R0-R12} ; Restore general purpose registers
|
||||
; Exception handler can not change SP
|
||||
|
||||
add SP,SP,#0x20 ; Clear out the remaining stack space
|
||||
ldmfd SP!,{LR} ; restore the link register for this context
|
||||
rfefd SP! ; return from exception via srsfd stack slot
|
||||
|
||||
END
|
||||
|
||||
|
Reference in New Issue
Block a user