Add unlink support to moxie simulator
authorAnthony Green <green@moxielogic.com>
Sat, 14 Dec 2019 10:23:20 +0000 (05:23 -0500)
committerAnthony Green <green@moxielogic.com>
Sat, 14 Dec 2019 10:33:39 +0000 (05:33 -0500)
This change adds support for the unlink system call, which is
required by the GCC testsuite.  It also switches read/write/open
system calls to use the sim_io_* functions.

2019-12-14  Anthony Green  <green@moxielogic.com>

* interp.c (sim_engine_run): Make use of sim_io_* functions for
read/write/open system calls.  Implement the unlink system call.

sim/moxie/ChangeLog
sim/moxie/interp.c

index 86fb33410811982a4d83fb4bac3d91cebaf6b85d..9f21b3c90ed6a4ca41bb8abe1ba9a1db5d207651 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-14  Anthony Green  <green@moxielogic.com>
+
+       * interp.c (sim_engine_run): Make use of sim_io_* functions for
+       read/write/open system calls.  Implement the unlink system call.
+
 2017-09-06  John Baldwin  <jhb@FreeBSD.org>
 
        * configure: Regenerate.
index ecea5b42f38f629ee98ce62a8ad574e8e431f2b5..fe770093e533d3ede553191c91584f2e8abab602 100644 (file)
@@ -32,6 +32,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "sim-main.h"
 #include "sim-base.h"
 #include "sim-options.h"
+#include "sim-io.h"
 
 typedef int word;
 typedef unsigned int uword;
@@ -942,9 +943,10 @@ sim_engine_run (SIM_DESC sd,
                      char fname[1024];
                      int mode = (int) convert_target_flags ((unsigned) cpu.asregs.regs[3]);
                      int perm = (int) cpu.asregs.regs[4];
-                     int fd = open (fname, mode, perm);
+                     int fd;
                      sim_core_read_buffer (sd, scpu, read_map, fname,
                                            cpu.asregs.regs[2], 1024);
+                     fd = sim_io_open (sd, fname, mode);
                      /* FIXME - set errno */
                      cpu.asregs.regs[2] = fd;
                      break;
@@ -954,7 +956,7 @@ sim_engine_run (SIM_DESC sd,
                      int fd = cpu.asregs.regs[2];
                      unsigned len = (unsigned) cpu.asregs.regs[4];
                      char *buf = malloc (len);
-                     cpu.asregs.regs[2] = read (fd, buf, len);
+                     cpu.asregs.regs[2] = sim_io_read (sd, fd, buf, len);
                      sim_core_write_buffer (sd, scpu, write_map, buf,
                                             cpu.asregs.regs[3], len);
                      free (buf);
@@ -968,11 +970,22 @@ sim_engine_run (SIM_DESC sd,
                      str = malloc (len);
                      sim_core_read_buffer (sd, scpu, read_map, str,
                                            cpu.asregs.regs[3], len);
-                     count = write (cpu.asregs.regs[2], str, len);
+                     count = sim_io_write (sd, cpu.asregs.regs[2], str, len);
                      free (str);
                      cpu.asregs.regs[2] = count;
                      break;
                    }
+                 case 0x7: /* SYS_unlink */
+                   {
+                     char fname[1024];
+                     int fd;
+                     sim_core_read_buffer (sd, scpu, read_map, fname,
+                                           cpu.asregs.regs[2], 1024);
+                     fd = sim_io_unlink (sd, fname);
+                     /* FIXME - set errno */
+                     cpu.asregs.regs[2] = fd;
+                     break;
+                   }
                  case 0xffffffff: /* Linux System Call */
                    {
                      unsigned int handler = cpu.asregs.sregs[1];