mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-23 21:54:27 +02:00
Ring3: Added support for AARCH64 EL2&0 translation regime.
This commit is contained in:
parent
d12742da3d
commit
a071d15784
@ -133,6 +133,15 @@ ASM_FUNC(ArmInvalidateTlb)
|
|||||||
isb
|
isb
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
ASM_FUNC(ArmWriteCptr)
|
||||||
|
EL1_OR_EL2_OR_EL3(x1)
|
||||||
|
1:ret
|
||||||
|
2:msr cptr_el2, x0
|
||||||
|
b 4f
|
||||||
|
3:msr cptr_el3, x0 // EL3 Coprocessor Trap Reg (CPTR)
|
||||||
|
4:isb
|
||||||
|
ret
|
||||||
|
|
||||||
ASM_FUNC(ArmCallWFE)
|
ASM_FUNC(ArmCallWFE)
|
||||||
wfe
|
wfe
|
||||||
ret
|
ret
|
||||||
|
@ -63,6 +63,7 @@ ArmMemoryAttributeToPageAttribute (
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Permissions = 0;
|
Permissions = 0;
|
||||||
break;
|
break;
|
||||||
@ -479,29 +480,24 @@ GcdAttributeToPageAttribute (
|
|||||||
PageAttributes |= TT_AF;
|
PageAttributes |= TT_AF;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((GcdAttributes & EFI_MEMORY_USER) != 0) {
|
if ((GcdAttributes & EFI_MEMORY_USER) != 0) {
|
||||||
PageAttributes |= TT_PXN_MASK;
|
PageAttributes |= TT_PXN_MASK;
|
||||||
|
|
||||||
if ((GcdAttributes & EFI_MEMORY_RO) != 0) {
|
if ((GcdAttributes & EFI_MEMORY_RO) != 0) {
|
||||||
PageAttributes |= TT_AP_RO_RO;
|
PageAttributes |= TT_AP_RO_RO;
|
||||||
} else {
|
} else {
|
||||||
PageAttributes |= TT_AP_RW_RW;
|
PageAttributes |= TT_AP_RW_RW;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ArmReadCurrentEL () == AARCH64_EL1) {
|
PageAttributes |= TT_UXN_MASK;
|
||||||
//
|
|
||||||
// TODO: Add EL2&0 support.
|
if ((GcdAttributes & EFI_MEMORY_RO) != 0) {
|
||||||
//
|
PageAttributes |= TT_AP_NO_RO;
|
||||||
PageAttributes |= TT_UXN_MASK;
|
} else {
|
||||||
}
|
PageAttributes |= TT_AP_NO_RW;
|
||||||
|
}
|
||||||
if ((GcdAttributes & EFI_MEMORY_RO) != 0) {
|
}
|
||||||
PageAttributes |= TT_AP_NO_RO;
|
|
||||||
} else {
|
|
||||||
PageAttributes |= TT_AP_NO_RW;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return PageAttributes;
|
return PageAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,6 +599,7 @@ ArmConfigureMmu (
|
|||||||
UINTN RootTableEntryCount;
|
UINTN RootTableEntryCount;
|
||||||
UINT64 TCR;
|
UINT64 TCR;
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
UINTN Hcr;
|
||||||
|
|
||||||
ASSERT (ArmReadCurrentEL () < AARCH64_EL3);
|
ASSERT (ArmReadCurrentEL () < AARCH64_EL3);
|
||||||
if (ArmReadCurrentEL () == AARCH64_EL3) {
|
if (ArmReadCurrentEL () == AARCH64_EL3) {
|
||||||
@ -627,6 +624,19 @@ ArmConfigureMmu (
|
|||||||
T0SZ = 64 - MaxAddressBits;
|
T0SZ = 64 - MaxAddressBits;
|
||||||
RootTableEntryCount = GetRootTableEntryCount (T0SZ);
|
RootTableEntryCount = GetRootTableEntryCount (T0SZ);
|
||||||
|
|
||||||
|
if (ArmReadCurrentEL () == AARCH64_EL2) {
|
||||||
|
//
|
||||||
|
// Switch to EL2&0 translation regime.
|
||||||
|
//
|
||||||
|
Hcr = ArmReadHcr ();
|
||||||
|
Hcr |= ARM_HCR_E2H | ARM_HCR_TGE;
|
||||||
|
ArmWriteHcr (Hcr);
|
||||||
|
//
|
||||||
|
// Allow access to the Advanced SIMD and floating-point registers.
|
||||||
|
//
|
||||||
|
ArmWriteCptr (AARCH64_CPTR_FPEN);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set TCR that allows us to retrieve T0SZ in the subsequent functions
|
// Set TCR that allows us to retrieve T0SZ in the subsequent functions
|
||||||
//
|
//
|
||||||
|
@ -107,7 +107,7 @@
|
|||||||
CpuExceptionHandlerLib|ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.inf
|
CpuExceptionHandlerLib|ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.inf
|
||||||
ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
|
ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
|
||||||
ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf
|
ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf
|
||||||
ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf
|
ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf
|
||||||
|
|
||||||
PlatformPeiLib|ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
|
PlatformPeiLib|ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
|
||||||
MemoryInitPeiLib|ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
|
MemoryInitPeiLib|ArmVirtPkg/Library/ArmVirtMemoryInitPeiLib/ArmVirtMemoryInitPeiLib.inf
|
||||||
|
@ -88,24 +88,23 @@ ASM_FUNC(ArmCallRing3)
|
|||||||
// Disable interrupts.
|
// Disable interrupts.
|
||||||
msr daifset, #0xf
|
msr daifset, #0xf
|
||||||
isb
|
isb
|
||||||
|
// Copy PSTATE to SPSR.
|
||||||
|
mrs x6, nzcv
|
||||||
|
mrs x7, pan
|
||||||
|
orr x6, x6, x7
|
||||||
// Prepare Ring3 SP and EntryPoint.
|
// Prepare Ring3 SP and EntryPoint.
|
||||||
msr sp_el0, x1
|
msr sp_el0, x1
|
||||||
msr elr_el1, x2
|
EL1_OR_EL2(x1)
|
||||||
|
1:msr elr_el1, x2
|
||||||
|
msr spsr_el1, x6
|
||||||
|
b 3f
|
||||||
|
2:msr elr_el2, x2
|
||||||
|
msr spsr_el2, x6
|
||||||
// Save Core SP and switch to CoreSysCall Stack.
|
// Save Core SP and switch to CoreSysCall Stack.
|
||||||
mov x5, sp
|
3:mov x5, sp
|
||||||
str x5, [x4]
|
str x5, [x4]
|
||||||
mov sp, x3
|
mov sp, x3
|
||||||
// Copy PSTATE to SPSR.
|
|
||||||
mrs x1, nzcv
|
|
||||||
mrs x2, pan
|
|
||||||
orr x1, x1, x2
|
|
||||||
//
|
|
||||||
// M[3:0], bits [3:0] AArch64 Exception level and selected Stack Pointer.
|
|
||||||
// 0b0000 - EL0.
|
|
||||||
// 0b0100 - EL1 with SP_EL0 (ELt).
|
|
||||||
// 0b0101 - EL1 with SP_EL1 (EL1h).
|
|
||||||
//
|
|
||||||
msr spsr_el1, x1
|
|
||||||
isb
|
isb
|
||||||
eret
|
eret
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ InitializeMsr (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Tcr;
|
UINTN Tcr;
|
||||||
|
UINTN Sctlr;
|
||||||
//
|
//
|
||||||
// If HCR_EL2.NV is 1 and the current Exception level is EL1,
|
// If HCR_EL2.NV is 1 and the current Exception level is EL1,
|
||||||
// then EL1 read accesses to the CurrentEL register return a value of 0x2 in bits[3:2].
|
// then EL1 read accesses to the CurrentEL register return a value of 0x2 in bits[3:2].
|
||||||
@ -115,6 +116,10 @@ InitializeMsr (
|
|||||||
//
|
//
|
||||||
// Enable Privileged Access Never feature.
|
// Enable Privileged Access Never feature.
|
||||||
//
|
//
|
||||||
|
Sctlr = ArmReadSctlr ();
|
||||||
|
Sctlr |= SCTLR_EPAN;
|
||||||
|
ArmWriteSctlr (Sctlr);
|
||||||
|
|
||||||
ArmSetPan ();
|
ArmSetPan ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#define AARCH64_CPTR_TFP (1 << 10)
|
#define AARCH64_CPTR_TFP (1 << 10)
|
||||||
#define AARCH64_CPTR_RES1 0x33ff
|
#define AARCH64_CPTR_RES1 0x33ff
|
||||||
#define AARCH64_CPTR_DEFAULT AARCH64_CPTR_RES1
|
#define AARCH64_CPTR_DEFAULT AARCH64_CPTR_RES1
|
||||||
|
#define AARCH64_CPTR_FPEN (3 << 20)
|
||||||
|
|
||||||
// ID_AA64MMFR1 - AArch64 Memory Model Feature Register 0 definitions
|
// ID_AA64MMFR1 - AArch64 Memory Model Feature Register 0 definitions
|
||||||
#define AARCH64_MMFR1_VH (0xF << 8)
|
#define AARCH64_MMFR1_VH (0xF << 8)
|
||||||
@ -46,6 +47,9 @@
|
|||||||
#define SCR_FW (1 << 4)
|
#define SCR_FW (1 << 4)
|
||||||
#define SCR_AW (1 << 5)
|
#define SCR_AW (1 << 5)
|
||||||
|
|
||||||
|
// SCTLR - System Control Register definitions
|
||||||
|
#define SCTLR_EPAN BIT57
|
||||||
|
|
||||||
// MIDR - Main ID Register definitions
|
// MIDR - Main ID Register definitions
|
||||||
#define ARM_CPU_TYPE_SHIFT 4
|
#define ARM_CPU_TYPE_SHIFT 4
|
||||||
#define ARM_CPU_TYPE_MASK 0xFFF
|
#define ARM_CPU_TYPE_MASK 0xFFF
|
||||||
|
@ -497,7 +497,7 @@ ArmEnableVFP (
|
|||||||
VOID
|
VOID
|
||||||
);
|
);
|
||||||
|
|
||||||
UINT32
|
UINTN
|
||||||
EFIAPI
|
EFIAPI
|
||||||
ArmReadSctlr (
|
ArmReadSctlr (
|
||||||
VOID
|
VOID
|
||||||
@ -506,7 +506,7 @@ ArmReadSctlr (
|
|||||||
VOID
|
VOID
|
||||||
EFIAPI
|
EFIAPI
|
||||||
ArmWriteSctlr (
|
ArmWriteSctlr (
|
||||||
IN UINT32 Value
|
IN UINTN Value
|
||||||
);
|
);
|
||||||
|
|
||||||
UINTN
|
UINTN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user