diff --git a/newlib/libc/sys/vita/crt0.c b/newlib/libc/sys/vita/crt0.c index 8edf156c4d..384924abdd 100755 --- a/newlib/libc/sys/vita/crt0.c +++ b/newlib/libc/sys/vita/crt0.c @@ -1,3 +1,6 @@ +/* The maximum number of arguments that can be passed to main(). */ +#define ARGC_MAX 19 + int main(int argc, const char* argv[]); void _init_vita_newlib(void) { @@ -14,8 +17,32 @@ void _free_vita_newlib(void) { _free_vita_heap(); } -void _start() { +/* + * Code below is based on the PSPSDK implementation + * Copyright (c) 2005 Marcus R. Brown + */ + +void _start(unsigned int args, void *argp) +{ + char *argv[ARGC_MAX + 1] = {""}; // Program name + int argc = 1; + int loc = 0; + char *ptr = argp; + + /* Turn our thread arguments into main()'s argc and argv[]. */ + while(loc < args) + { + argv[argc] = &ptr[loc]; + loc += strlen(&ptr[loc]) + 1; + argc++; + if(argc == ARGC_MAX) + { + break; + } + } + + argv[argc] = 0; _init_vita_newlib(); __libc_init_array(); - exit(main(1, (const char*[]){"", 0})); + exit(main(argc, argv)); }