From a9a8edeaf49b43ed8fe5f758ae80a19757b63ba8 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Tue, 23 May 2017 16:11:39 +0200 Subject: [PATCH] Handle arguments in a better way --- patches/reboot.s | 4 ++-- source/main.c | 49 +++++++++++++++++++++++------------------------- source/start.s | 6 ++---- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/patches/reboot.s b/patches/reboot.s index c805572..5efa419 100644 --- a/patches/reboot.s +++ b/patches/reboot.s @@ -17,7 +17,7 @@ arm11_entrypoint_addr equ 0x1FFFFFFC ; - r1: FIRM path in exefs. ; - r7 (or r8): pointer to file object ; - *r7: vtable - ; - *(vtable + 0x28): fread function + ; - *(vtable + 0x28): fread function ; - *(r7 + 8): file handle sub r7, r0, #8 @@ -160,7 +160,7 @@ fname: .ascii "FILE" mov r0, #2 ; argc ldr r1, =argv_addr ; argv - ldr r2, =0xBEEF ; magic word + ldr r2, =0xBABE ; magic word ldr r5, =arm11_entrypoint_addr ldr r6, [r4, #0x08] diff --git a/source/main.c b/source/main.c index 3dc33b4..38ef998 100644 --- a/source/main.c +++ b/source/main.c @@ -43,7 +43,7 @@ bool isFirmlaunch = false, isSdMode; u16 launchedPath[41]; -void main(int argc, char **argv) +void main(int argc, char **argv, u32 magicWord) { bool isSafeMode = false, isNoForceFlagSet = false; @@ -52,33 +52,30 @@ void main(int argc, char **argv) FirmwareType firmType; FirmwareSource nandType; - switch(argc) + if(magicWord == 0xBEEF && argc >= 1) //Normal boot { - case 1: //Normal boot - { - u32 i; - for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16 - launchedPath[i] = argv[0][i]; - launchedPath[i] = 0; - break; - } + u32 i; + for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16 + launchedPath[i] = argv[0][i]; + launchedPath[i] = 0; + break; + } + else if(magicWord == 0xBABE && argc == 2) //Firmlaunch + { + u32 i; + u16 *p = (u16 *)argv[0]; + for(i = 0; i < 40 && p[i] != 0; i++) + launchedPath[i] = p[i]; + launchedPath[i] = 0; - case 2: //Firmlaunch - { - u32 i; - u16 *p = (u16 *)argv[0]; - for(i = 0; i < 40 && p[i] != 0; i++) - launchedPath[i] = p[i]; - launchedPath[i] = 0; - - isFirmlaunch = true; - break; - } - - default: - sprintf(errbuf, "Unsupported launcher (argc = %d).", argc); - error(errbuf); - break; + isFirmlaunch = true; + break; + } + else + { + sprintf(errbuf, "Unsupported launcher or entrypoint (magic = 0x%08x, argc = %d).", magicWord, argc); + error(errbuf); + break; } if(memcmp(launchedPath, u"sdmc", 8) == 0) diff --git a/source/start.s b/source/start.s index 89a88fe..17dba3c 100644 --- a/source/start.s +++ b/source/start.s @@ -29,12 +29,9 @@ _start: orr r4, #0x1C0 msr cpsr_cx, r4 - ldr r4, =0xBEEF - cmp r2, r4 - movne r0, #0 @ check magic word - mov r9, r0 mov r10, r1 + mov r11, r2 @ Change the stack pointer mov sp, #0x08100000 @@ -95,4 +92,5 @@ _start: mov r0, r9 mov r1, r10 + mov r2, r11 b main