summaryrefslogtreecommitdiffstats
path: root/newlib/libc/sys/sh
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/sys/sh')
-rw-r--r--newlib/libc/sys/sh/sys/syscall.h4
-rw-r--r--newlib/libc/sys/sh/syscalls.c28
2 files changed, 32 insertions, 0 deletions
diff --git a/newlib/libc/sys/sh/sys/syscall.h b/newlib/libc/sys/sh/sys/syscall.h
index f141df764..fd9ee7c51 100644
--- a/newlib/libc/sys/sh/sys/syscall.h
+++ b/newlib/libc/sys/sh/sys/syscall.h
@@ -27,5 +27,9 @@
#define SYS_pipe 42
#define SYS_execve 59
+#define SYS_argc 172 /* == 0xAC, for Argument Count :-) */
+#define SYS_argnlen 173
+#define SYS_argn 174
+
#define SYS_utime 201 /* not really a system call */
#define SYS_wait 202 /* nor is this */
diff --git a/newlib/libc/sys/sh/syscalls.c b/newlib/libc/sys/sh/syscalls.c
index 8380c7017..f0e924297 100644
--- a/newlib/libc/sys/sh/syscalls.c
+++ b/newlib/libc/sys/sh/syscalls.c
@@ -191,3 +191,31 @@ _gettimeofday (struct timeval *tv, struct timezone *tz)
tv->tv_sec = __trap34 (SYS_time);
return 0;
}
+
+static inline int
+__setup_argv_for_main (int argc)
+{
+ char **argv;
+ int i = argc;
+
+ argv = __builtin_alloca ((1 + argc) * sizeof (*argv));
+
+ argv[i] = NULL;
+ while (i--) {
+ argv[i] = __builtin_alloca (1 + __trap34 (SYS_argnlen, i));
+ __trap34 (SYS_argn, i, argv[i]);
+ }
+
+ return main (argc, argv);
+}
+
+int
+__setup_argv_and_call_main ()
+{
+ int argc = __trap34 (SYS_argc);
+
+ if (argc <= 0)
+ return main (argc, NULL);
+ else
+ return __setup_argv_for_main (argc);
+}