]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: syscall: hoist argc/argn/argnlen to common code
authorMike Frysinger <vapier@gentoo.org>
Tue, 16 Nov 2021 06:26:47 +0000 (01:26 -0500)
committerMike Frysinger <vapier@gentoo.org>
Tue, 16 Nov 2021 07:13:42 +0000 (02:13 -0500)
Now that the callback framework supports argv & envp, we can move
the Blackfin implementation of these syscalls to the common code.

sim/bfin/interp.c
sim/common/syscall.c

index 88ddbd071b3d42c295bbbdbb5c7fdb56e79c097f..f41e9b1bd7bb6c3ff2346c383115787716d2c5a9 100644 (file)
@@ -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;
index bad3b3b6214d494788198e77fe9369e420aaa673..df9dd92e6dac43eb2f21f881cd5d94b2a02a2603 100644 (file)
@@ -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