mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-04 00:28:51 -04:00
kern: retrieve target firmware from exosphere instead of hardcoding
This commit is contained in:
parent
2ca6772475
commit
9beb05da50
4 changed files with 35 additions and 24 deletions
|
@ -94,6 +94,18 @@ core0_el2:
|
|||
core0_el1:
|
||||
bl _ZN3ams4kern4init19DisableMmuAndCachesEv
|
||||
|
||||
/* Get the target firmware from exosphere. */
|
||||
LOAD_IMMEDIATE_32(w0, 0xC3000004)
|
||||
mov w1, #65000
|
||||
smc #1
|
||||
cmp x0, #0
|
||||
0:
|
||||
b.ne 0b
|
||||
|
||||
/* Store the target firmware. */
|
||||
adr x0, __metadata_target_firmware
|
||||
str w1, [x0]
|
||||
|
||||
/* We want to invoke kernel loader. */
|
||||
adr x0, _start
|
||||
adr x1, __metadata_kernel_layout
|
||||
|
@ -102,14 +114,7 @@ core0_el1:
|
|||
LOAD_FROM_LABEL(x3, __metadata_kernelldr_offset)
|
||||
add x3, x0, x3
|
||||
|
||||
/* If kernelldr is ours, set its target firmware. */
|
||||
ldr w4, [x3, #4]
|
||||
LOAD_IMMEDIATE_32(w5, 0x30444C4D)
|
||||
cmp w4, w5
|
||||
b.ne 1f
|
||||
LOAD_FROM_LABEL(x4, __metadata_target_firmware)
|
||||
str w4, [x3, #8]
|
||||
1:
|
||||
/* Invoke kernel loader. */
|
||||
blr x3
|
||||
|
||||
/* At this point kernelldr has been invoked, and we are relocated at a random virtual address. */
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
#define cpuactlr_el1 s3_1_c15_c2_0
|
||||
#define cpuectlr_el1 s3_1_c15_c2_1
|
||||
|
||||
#define LOAD_IMMEDIATE_32(reg, val) \
|
||||
mov reg, #(((val) >> 0x00) & 0xFFFF); \
|
||||
movk reg, #(((val) >> 0x10) & 0xFFFF), lsl#16
|
||||
|
||||
.section .crt0.text.start, "ax", %progbits
|
||||
.global _start
|
||||
_start:
|
||||
|
@ -46,12 +50,25 @@ _main:
|
|||
ldr x17, [x17, #0x10] /* stack top */
|
||||
add sp, x17, x18
|
||||
|
||||
/* Stack is now set up. */
|
||||
/* Apply relocations and call init array for KernelLdr. */
|
||||
/* Stack is now set up, so save important state. */
|
||||
sub sp, sp, #0x30
|
||||
stp x0, x1, [sp, #0x00]
|
||||
stp x2, x30, [sp, #0x10]
|
||||
stp xzr, xzr, [sp, #0x20]
|
||||
|
||||
/* Get the target firmware from exosphere. */
|
||||
LOAD_IMMEDIATE_32(w0, 0xC3000004)
|
||||
mov w1, #65000
|
||||
smc #1
|
||||
cmp x0, #0
|
||||
0:
|
||||
b.ne 0b
|
||||
|
||||
/* Store the target firmware. */
|
||||
adr x0, __metadata_target_firmware
|
||||
str w1, [x0]
|
||||
|
||||
/* Apply relocations and call init array for KernelLdr. */
|
||||
adr x0, _start
|
||||
adr x1, __external_references
|
||||
ldr x1, [x1, #0x18] /* .dynamic. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue