From cdbaed8a8ebaf8567fd3fc50c2373d8fd6cf8e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Jos=C3=A9=20Garc=C3=ADa=20Garc=C3=ADa?= Date: Thu, 29 Sep 2016 18:42:34 +0200 Subject: [PATCH 1/4] Add arguments support --- newlib/libc/sys/vita/crt0.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/newlib/libc/sys/vita/crt0.c b/newlib/libc/sys/vita/crt0.c index 8edf156c4d..d00582d3a4 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,27 @@ void _free_vita_newlib(void) { _free_vita_heap(); } -void _start() { +void _start(unsigned int args, void *argp) +{ + char *argv[ARG_MAX + 1]; + int argc = 0; + 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] = NULL; _init_vita_newlib(); __libc_init_array(); - exit(main(1, (const char*[]){"", 0})); + exit(main(argc, argv)); } From a63af0a476b4aeb03ab8d3208d833cf3c46ba183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Jos=C3=A9=20Garc=C3=ADa=20Garc=C3=ADa?= Date: Fri, 30 Sep 2016 08:39:08 +0200 Subject: [PATCH 2/4] Fix errors --- newlib/libc/sys/vita/crt0.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/newlib/libc/sys/vita/crt0.c b/newlib/libc/sys/vita/crt0.c index d00582d3a4..bc78376f67 100755 --- a/newlib/libc/sys/vita/crt0.c +++ b/newlib/libc/sys/vita/crt0.c @@ -19,7 +19,7 @@ void _free_vita_newlib(void) { void _start(unsigned int args, void *argp) { - char *argv[ARG_MAX + 1]; + char *argv[ARGC_MAX + 1]; int argc = 0; int loc = 0; char *ptr = argp; @@ -36,7 +36,7 @@ void _start(unsigned int args, void *argp) } } - argv[argc] = NULL; + argv[argc] = 0; _init_vita_newlib(); __libc_init_array(); exit(main(argc, argv)); From a53590e357edb152d7e623b6e0f734f4f386e8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Jos=C3=A9=20Garc=C3=ADa=20Garc=C3=ADa?= Date: Sun, 2 Oct 2016 10:09:40 +0200 Subject: [PATCH 3/4] Update crt0.c --- newlib/libc/sys/vita/crt0.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/newlib/libc/sys/vita/crt0.c b/newlib/libc/sys/vita/crt0.c index bc78376f67..71ee3ea025 100755 --- a/newlib/libc/sys/vita/crt0.c +++ b/newlib/libc/sys/vita/crt0.c @@ -17,6 +17,11 @@ void _free_vita_newlib(void) { _free_vita_heap(); } +/* + * 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]; From f4dbac046808922b8490ec6c9b44c883387d0c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Jos=C3=A9=20Garc=C3=ADa=20Garc=C3=ADa?= Date: Sun, 2 Oct 2016 12:12:43 +0200 Subject: [PATCH 4/4] Add argv[0] as program name --- newlib/libc/sys/vita/crt0.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/newlib/libc/sys/vita/crt0.c b/newlib/libc/sys/vita/crt0.c index 71ee3ea025..384924abdd 100755 --- a/newlib/libc/sys/vita/crt0.c +++ b/newlib/libc/sys/vita/crt0.c @@ -24,8 +24,8 @@ void _free_vita_newlib(void) { void _start(unsigned int args, void *argp) { - char *argv[ARGC_MAX + 1]; - int argc = 0; + char *argv[ARGC_MAX + 1] = {""}; // Program name + int argc = 1; int loc = 0; char *ptr = argp;