From 457b4cec1317b06d5bd536d2be776615f4ead525 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sat, 13 Aug 2016 20:49:40 +0200 Subject: [PATCH] Disable interrupts and do some refactoring. --- patches/reboot.s | 33 ++++++++++++++++++--------------- source/firm.c | 6 ++++-- source/firm.h | 2 +- source/start.s | 9 ++++++++- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/patches/reboot.s b/patches/reboot.s index 1a7a91c..799d156 100644 --- a/patches/reboot.s +++ b/patches/reboot.s @@ -41,26 +41,29 @@ payload_maxsize equ 0x10000 ; Maximum size for the payload (maximum that CakeB read_payload: ; Read file - mov r0, r7 + mov r0, r7 adr r1, bytes_read ldr r2, =payload_addr cmp r4, #0 movne r3, #0x12000 ; Skip the first 0x12000 bytes. moveq r3, payload_maxsize - ldr r6, [sp, #0x3A8-0x198] - ldr r6, [r6, #0x28] - blx r6 + ldr r6, [sp, #0x3A8-0x198] + ldr r6, [r6, #0x28] + blx r6 cmp r4, #0 movne r4, #0 bne read_payload ; Go read the real payload. - ; Copy the last digits of the wanted firm to the 5th byte of the payload - add r2, sp, #0x3A8 - 0x70 - ldr r0, [r2, #0x27] - ldr r1, =payload_addr + 4 - str r0, [r1] - ldr r0, [r2, #0x2B] - str r0, [r1, #4] + ; Copy the low TID (in UTF-16) of the wanted firm to the 5th byte of the payload + add r0, sp, #0x3A8 - 0x70 + add r0, 0x1A + add r1, r0, #0x10 + ldr r2, =payload_addr + 4 + copy_TID_low: + ldrh r3, [r0], #2 + strh r3, [r2], #2 + cmp r0, r1 + blo copy_TID_low ; Set kernel state mov r0, #0 @@ -81,10 +84,10 @@ payload_maxsize equ 0x10000 ; Maximum size for the payload (maximum that CakeB bytes_read: .word 0 fopen: .ascii "OPEN" .pool -bin_fname: .dcw "sdmc:/arm9loaderhax.bin" - .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -dat_fname: .dcw "sdmc:/Luma3DS.dat" - .word 0 +bin_fname: .dcw "sdmc:/arm9loaderhax.bin" + .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +dat_fname: .dcw "sdmc:/Luma3DS.dat" + .word 0 .align 4 kernelcode_start: diff --git a/source/firm.c b/source/firm.c index e9ffc57..3e84180 100755 --- a/source/firm.c +++ b/source/firm.c @@ -36,6 +36,8 @@ #include "i2c.h" #include "../build/injector.h" +extern u16 launchedFirmTIDLow[8]; //defined in start.s + static firmHeader *const firm = (firmHeader *)0x24000000; static const firmSectionHeader *section; @@ -76,14 +78,14 @@ void main(void) needConfig = fileRead(&config, configPath) ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION; //Determine if this is a firmlaunch boot - if(*(vu8 *)0x23F00005) + if(launchedFirmTIDLow[5] != 0) { if(needConfig == CREATE_CONFIGURATION) mcuReboot(); isFirmlaunch = true; //'0' = NATIVE_FIRM, '1' = TWL_FIRM, '2' = AGB_FIRM - firmType = *(vu8 *)0x23F00009 == '3' ? SAFE_FIRM : (FirmwareType)(*(vu8 *)0x23F00005 - '0'); + firmType = launchedFirmTIDLow[7] == u'3' ? SAFE_FIRM : (FirmwareType)(launchedFirmTIDLow[5] - u'0'); nandType = (FirmwareSource)BOOTCONFIG(0, 3); firmSource = (FirmwareSource)BOOTCONFIG(2, 1); diff --git a/source/firm.h b/source/firm.h index e4200a4..9e7bf61 100644 --- a/source/firm.h +++ b/source/firm.h @@ -53,7 +53,7 @@ typedef enum ConfigurationStatus MODIFY_CONFIGURATION = 1, CREATE_CONFIGURATION = 2 } ConfigurationStatus; - + static inline u32 loadFirm(FirmwareType firmType); static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lh); static inline void patchLegacyFirm(FirmwareType firmType); diff --git a/source/start.s b/source/start.s index 4d40922..a43cfae 100644 --- a/source/start.s +++ b/source/start.s @@ -26,12 +26,19 @@ _start: b start - .word 0, 0 +.global launchedFirmTIDLow +launchedFirmTIDLow: + .hword 0, 0, 0, 0, 0, 0, 0, 0 start: @ Change the stack pointer mov sp, #0x27000000 + @ Disable interrupts + mrs r0, cpsr + orr r0, #0x1C0 + msr cpsr_cx, r0 + @ Disable caches / MPU mrc p15, 0, r0, c1, c0, 0 @ read control register bic r0, #(1<<12) @ - instruction cache disable