mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-24 03:06:17 +00:00
kern: make GetTargetFirmware a compile-time constant when not building for Switch
This commit is contained in:
parent
3c85e37667
commit
b917ea283e
4 changed files with 32 additions and 3 deletions
|
@ -22,6 +22,12 @@ namespace ams::kern {
|
|||
|
||||
constexpr size_t PageSize = 4_KB;
|
||||
|
||||
#ifdef ATMOSPHERE_BOARD_NINTENDO_NX
|
||||
ams::TargetFirmware GetTargetFirmware();
|
||||
#else
|
||||
consteval ALWAYS_INLINE ams::TargetFirmware GetTargetFirmware() {
|
||||
return ams::TargetFirmware_Current;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -61,12 +61,14 @@ __metadata_kernel_layout:
|
|||
.error "Incorrect Mesosphere Metadata"
|
||||
.endif
|
||||
|
||||
#ifdef ATMOSPHERE_BOARD_NINTENDO_NX
|
||||
.global _ZN3ams4kern17GetTargetFirmwareEv
|
||||
.type _ZN3ams4kern17GetTargetFirmwareEv, %function
|
||||
_ZN3ams4kern17GetTargetFirmwareEv:
|
||||
adr x0, __metadata_target_firmware
|
||||
ldr w0, [x0]
|
||||
ret
|
||||
#endif
|
||||
|
||||
/* ams::kern::init::StartCore0(uintptr_t, uintptr_t) */
|
||||
.section .crt0.text._ZN3ams4kern4init10StartCore0Emm, "ax", %progbits
|
||||
|
@ -94,6 +96,7 @@ core0_el2:
|
|||
core0_el1:
|
||||
bl _ZN3ams4kern4init19DisableMmuAndCachesEv
|
||||
|
||||
#ifdef ATMOSPHERE_BOARD_NINTENDO_NX
|
||||
/* Get the target firmware from exosphere. */
|
||||
LOAD_IMMEDIATE_32(w0, 0xC3000004)
|
||||
mov w1, #65000
|
||||
|
@ -105,6 +108,7 @@ core0_el1:
|
|||
/* Store the target firmware. */
|
||||
adr x0, __metadata_target_firmware
|
||||
str w1, [x0]
|
||||
#endif
|
||||
|
||||
/* We want to invoke kernel loader. */
|
||||
adr x0, _start
|
||||
|
|
|
@ -56,6 +56,7 @@ _main:
|
|||
stp x2, x30, [sp, #0x10]
|
||||
stp xzr, xzr, [sp, #0x20]
|
||||
|
||||
#ifdef ATMOSPHERE_BOARD_NINTENDO_NX
|
||||
/* Get the target firmware from exosphere. */
|
||||
LOAD_IMMEDIATE_32(w0, 0xC3000004)
|
||||
mov w1, #65000
|
||||
|
@ -67,6 +68,7 @@ _main:
|
|||
/* Store the target firmware. */
|
||||
adr x0, __metadata_target_firmware
|
||||
str w1, [x0]
|
||||
#endif
|
||||
|
||||
/* Apply relocations and call init array for KernelLdr. */
|
||||
adr x0, _start
|
||||
|
@ -121,13 +123,14 @@ _main:
|
|||
mov sp, x2
|
||||
br x1
|
||||
|
||||
|
||||
#ifdef ATMOSPHERE_BOARD_NINTENDO_NX
|
||||
.global _ZN3ams4kern17GetTargetFirmwareEv
|
||||
.type _ZN3ams4kern17GetTargetFirmwareEv, %function
|
||||
_ZN3ams4kern17GetTargetFirmwareEv:
|
||||
adr x0, __metadata_target_firmware
|
||||
ldr w0, [x0]
|
||||
ret
|
||||
#endif
|
||||
|
||||
.balign 8
|
||||
__external_references:
|
||||
|
|
|
@ -87,6 +87,22 @@ namespace ams::kern::init::loader {
|
|||
cpu::InvalidateEntireTlb();
|
||||
}
|
||||
|
||||
#ifdef ATMOSPHERE_BOARD_NINTENDO_NX
|
||||
|
||||
ALWAYS_INLINE bool ShouldPerformCpuSpecificSetup() {
|
||||
/* Perform cpu-specific setup only on < 10.0.0. */
|
||||
return kern::GetTargetFirmware() < ams::TargetFirmware_10_0_0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
consteval ALWAYS_INLINE bool ShouldPerformCpuSpecificSetup() {
|
||||
/* Always perform cpu-specific setup. */
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void SetupInitialIdentityMapping(KInitialPageTable &ttbr1_table, uintptr_t base_address, uintptr_t kernel_size, uintptr_t page_table_region, size_t page_table_region_size, KInitialPageTable::IPageAllocator &allocator) {
|
||||
/* Make a new page table for TTBR0_EL1. */
|
||||
KInitialPageTable ttbr0_table(allocator.Allocate());
|
||||
|
@ -116,8 +132,8 @@ namespace ams::kern::init::loader {
|
|||
cpu::MemoryAccessIndirectionRegisterAccessor(MairValue).Store();
|
||||
cpu::TranslationControlRegisterAccessor(TcrValue).Store();
|
||||
|
||||
/* Perform cpu-specific setup on < 10.0.0. */
|
||||
if (kern::GetTargetFirmware() < ams::TargetFirmware_10_0_0) {
|
||||
/* Perform cpu-specific setup if needed. */
|
||||
if (ShouldPerformCpuSpecificSetup()) {
|
||||
SavedRegisterState saved_registers;
|
||||
SaveRegistersToTpidrEl1(&saved_registers);
|
||||
ON_SCOPE_EXIT { VerifyAndClearTpidrEl1(&saved_registers); };
|
||||
|
|
Loading…
Reference in a new issue