Handle arguments in a better way

This commit is contained in:
TuxSH 2017-05-23 16:11:39 +02:00
parent dd21a3930d
commit a9a8edeaf4
3 changed files with 27 additions and 32 deletions

View File

@ -17,7 +17,7 @@ arm11_entrypoint_addr equ 0x1FFFFFFC
; - r1: FIRM path in exefs. ; - r1: FIRM path in exefs.
; - r7 (or r8): pointer to file object ; - r7 (or r8): pointer to file object
; - *r7: vtable ; - *r7: vtable
; - *(vtable + 0x28): fread function ; - *(vtable + 0x28): fread function
; - *(r7 + 8): file handle ; - *(r7 + 8): file handle
sub r7, r0, #8 sub r7, r0, #8
@ -160,7 +160,7 @@ fname: .ascii "FILE"
mov r0, #2 ; argc mov r0, #2 ; argc
ldr r1, =argv_addr ; argv ldr r1, =argv_addr ; argv
ldr r2, =0xBEEF ; magic word ldr r2, =0xBABE ; magic word
ldr r5, =arm11_entrypoint_addr ldr r5, =arm11_entrypoint_addr
ldr r6, [r4, #0x08] ldr r6, [r4, #0x08]

View File

@ -43,7 +43,7 @@ bool isFirmlaunch = false,
isSdMode; isSdMode;
u16 launchedPath[41]; u16 launchedPath[41];
void main(int argc, char **argv) void main(int argc, char **argv, u32 magicWord)
{ {
bool isSafeMode = false, bool isSafeMode = false,
isNoForceFlagSet = false; isNoForceFlagSet = false;
@ -52,33 +52,30 @@ void main(int argc, char **argv)
FirmwareType firmType; FirmwareType firmType;
FirmwareSource nandType; 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
u32 i; launchedPath[i] = argv[0][i];
for(i = 0; i < 40 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16 launchedPath[i] = 0;
launchedPath[i] = argv[0][i]; break;
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 isFirmlaunch = true;
{ break;
u32 i; }
u16 *p = (u16 *)argv[0]; else
for(i = 0; i < 40 && p[i] != 0; i++) {
launchedPath[i] = p[i]; sprintf(errbuf, "Unsupported launcher or entrypoint (magic = 0x%08x, argc = %d).", magicWord, argc);
launchedPath[i] = 0; error(errbuf);
break;
isFirmlaunch = true;
break;
}
default:
sprintf(errbuf, "Unsupported launcher (argc = %d).", argc);
error(errbuf);
break;
} }
if(memcmp(launchedPath, u"sdmc", 8) == 0) if(memcmp(launchedPath, u"sdmc", 8) == 0)

View File

@ -29,12 +29,9 @@ _start:
orr r4, #0x1C0 orr r4, #0x1C0
msr cpsr_cx, r4 msr cpsr_cx, r4
ldr r4, =0xBEEF
cmp r2, r4
movne r0, #0 @ check magic word
mov r9, r0 mov r9, r0
mov r10, r1 mov r10, r1
mov r11, r2
@ Change the stack pointer @ Change the stack pointer
mov sp, #0x08100000 mov sp, #0x08100000
@ -95,4 +92,5 @@ _start:
mov r0, r9 mov r0, r9
mov r1, r10 mov r1, r10
mov r2, r11
b main b main