From: Mike Frysinger Date: Tue, 16 Nov 2021 06:26:47 +0000 (-0500) Subject: sim: syscall: hoist argc/argn/argnlen to common code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=85588c9ab947a4edfeedc7c14bd202d15ccfbbff;p=binutils-gdb.git sim: syscall: hoist argc/argn/argnlen to common code Now that the callback framework supports argv & envp, we can move the Blackfin implementation of these syscalls to the common code. --- diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c index 88ddbd071b3..f41e9b1bd7b 100644 --- a/sim/bfin/interp.c +++ b/sim/bfin/interp.c @@ -144,39 +144,6 @@ bfin_syscall (SIM_CPU *cpu) tbuf += sprintf (tbuf, "exit(%i)", args[0]); sim_engine_halt (sd, cpu, NULL, PCREG, sim_exited, sc.arg1); -#ifdef CB_SYS_argc - case CB_SYS_argc: - tbuf += sprintf (tbuf, "argc()"); - sc.result = countargv ((char **)argv); - break; - case CB_SYS_argnlen: - { - tbuf += sprintf (tbuf, "argnlen(%u)", args[0]); - if (sc.arg1 < countargv ((char **)argv)) - sc.result = strlen (argv[sc.arg1]); - else - sc.result = -1; - } - break; - case CB_SYS_argn: - { - tbuf += sprintf (tbuf, "argn(%u)", args[0]); - if (sc.arg1 < countargv ((char **)argv)) - { - const char *argn = argv[sc.arg1]; - int len = strlen (argn); - int written = sc.write_mem (cb, &sc, sc.arg2, argn, len + 1); - if (written == len + 1) - sc.result = sc.arg2; - else - sc.result = -1; - } - else - sc.result = -1; - } - break; -#endif - case CB_SYS_gettimeofday: { struct timeval _tv, *tv = &_tv; diff --git a/sim/common/syscall.c b/sim/common/syscall.c index bad3b3b6214..df9dd92e6da 100644 --- a/sim/common/syscall.c +++ b/sim/common/syscall.c @@ -141,6 +141,46 @@ cb_syscall (host_callback *cb, CB_SYSCALL *sc) switch (cb_target_to_host_syscall (cb, sc->func)) { + case CB_SYS_argc: + result = countargv (cb->argv); + break; + + case CB_SYS_argnlen: + { + if (sc->arg1 >= 0 && sc->arg1 < countargv (cb->argv)) + result = strlen (cb->argv[sc->arg1]); + else + { + result = -1; + errcode = EINVAL; + } + } + break; + + case CB_SYS_argn: + { + if (sc->arg1 >= 0 && sc->arg1 < countargv (cb->argv)) + { + const char *argn = cb->argv[sc->arg1]; + int len = strlen (argn); + int written = sc->write_mem (cb, sc, sc->arg2, argn, len + 1); + + if (written == len + 1) + result = sc->arg2; + else + { + result = -1; + errcode = EINVAL; + } + } + else + { + result = -1; + errcode = EINVAL; + } + } + break; + case CB_SYS_argvlen : { /* Compute how much space is required to store the argv,envp