public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch, sim, mips] Implement unlink, lseek, and stat for MIPS
@ 2013-07-10 14:49 Steve Ellcey 
  2013-07-24 23:19 ` Steve Ellcey
  2013-09-03  6:14 ` Mike Frysinger
  0 siblings, 2 replies; 5+ messages in thread
From: Steve Ellcey  @ 2013-07-10 14:49 UTC (permalink / raw)
  To: gdb-patches

A while back I submitted a GCC patch that allowed me to build the Fortran
compiler on a newlib based cross compiler.  While using the GNU simulator
to test that, I found that a number of tests failed due to unimplemented
system calls on the MIPS GNU simulator.  This patch implements unlink,
lseek, and stat in the GNU simulator for MIPS.  There is a second small
patch that I sent to newlib that generates the necessary functions for
the simulator to see and intercept these functions like it does others
that are already implemented such as open and close.

OK to checkin?

Steve Ellcey
sellcey@mips.com


Steve Ellcey  <sellcey@mips.com>

	* interp.c (sim_monitor): Add switch entries for unlink (13),
	lseek (14), and stat (15).


diff --git a/sim/mips/interp.c b/sim/mips/interp.c
index 032570a..766a113 100644
--- a/sim/mips/interp.c
+++ b/sim/mips/interp.c
@@ -47,6 +47,7 @@ code on the hardware.
 #include <ansidecl.h>
 #include <ctype.h>
 #include <limits.h>
+#include <byteswap.h>
 #include <math.h>
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
@@ -1342,6 +1343,60 @@ sim_monitor (SIM_DESC sd,
 	break;
       }
 
+    case 13: /* int unlink(const char *path) */
+      {
+	char *path = fetch_str (sd, A0);
+	V0 = sim_io_unlink (sd, path);
+	free (path);
+	break;
+      }
+
+    case 14: /* int lseek(int fd, int offset, int whence) */
+      {
+	V0 = sim_io_lseek (sd, A0, A1, A2);
+	break;
+      }
+
+/* We may need to swap stat data around before passing it on to the
+   program being run.  */
+#define copy16(x) (BigEndianMem ? bswap_16(x) : (x))
+#define copy32(x) (BigEndianMem ? bswap_32(x) : (x))
+
+    case 15: /* int stat(const char *path, struct stat *buf); */
+      {
+	/* We need to put the data into the type of stat structure
+	   that MIPS uses and make sure it has the correct endianness.
+	   We are assuming that the host and MIPS agree on what the bits
+	   in st_mode mean.  That appears to be true for x86 linux and
+	   MIPS.  */
+        struct stat host_stat;
+	struct __attribute__ ((__packed__)) mips_stat {
+		short st_dev;
+		unsigned short st_ino;
+		unsigned int st_mode;
+		unsigned short st_nlink;
+		unsigned short st_uid;
+		unsigned short st_gid;
+		short st_rdev;
+		int st_size;
+	} mips_stat;
+	char *buf;
+        char *path = fetch_str (sd, A0);
+	buf = (char *) A1;
+	V0 = sim_io_stat (sd, path, &host_stat);
+	free (path);
+	mips_stat.st_dev = copy16((short) host_stat.st_dev);
+	mips_stat.st_ino = copy16((unsigned short) host_stat.st_ino);
+	mips_stat.st_mode = copy32((int) host_stat.st_mode);
+	mips_stat.st_nlink = copy16((unsigned short) host_stat.st_nlink);
+	mips_stat.st_uid = copy16((unsigned short) host_stat.st_uid);
+	mips_stat.st_gid = copy16((unsigned short) host_stat.st_gid);
+	mips_stat.st_rdev = copy16((short) host_stat.st_rdev);
+	mips_stat.st_size = copy32((int) host_stat.st_size);
+	sim_write (sd, A1, (char *) &mips_stat, 20);
+	break;
+      }
+
     case 17: /* void _exit() */
       {
 	sim_io_eprintf (sd, "sim_monitor(17): _exit(int reason) to be coded\n");

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch, sim, mips] Implement unlink, lseek, and stat for MIPS
  2013-07-10 14:49 [patch, sim, mips] Implement unlink, lseek, and stat for MIPS Steve Ellcey 
@ 2013-07-24 23:19 ` Steve Ellcey
  2013-08-07 21:48   ` Steve Ellcey
  2013-09-03  6:14 ` Mike Frysinger
  1 sibling, 1 reply; 5+ messages in thread
From: Steve Ellcey @ 2013-07-24 23:19 UTC (permalink / raw)
  To: gdb-patches

Ping.  The newlib/libgloss patch that this needs has been approved and
checked in.  OK to checkin this MIPS specific GNU simulator change?

Steve Ellcey
sellcey@mips.com


On Wed, 2013-07-10 at 07:48 -0700, Steve Ellcey wrote:
> A while back I submitted a GCC patch that allowed me to build the Fortran
> compiler on a newlib based cross compiler.  While using the GNU simulator
> to test that, I found that a number of tests failed due to unimplemented
> system calls on the MIPS GNU simulator.  This patch implements unlink,
> lseek, and stat in the GNU simulator for MIPS.  There is a second small
> patch that I sent to newlib that generates the necessary functions for
> the simulator to see and intercept these functions like it does others
> that are already implemented such as open and close.
> 
> OK to checkin?
> 
> Steve Ellcey
> sellcey@mips.com
> 
> 
> Steve Ellcey  <sellcey@mips.com>
> 
> 	* interp.c (sim_monitor): Add switch entries for unlink (13),
> 	lseek (14), and stat (15).
> 
> 
> diff --git a/sim/mips/interp.c b/sim/mips/interp.c
> index 032570a..766a113 100644
> --- a/sim/mips/interp.c
> +++ b/sim/mips/interp.c
> @@ -47,6 +47,7 @@ code on the hardware.
>  #include <ansidecl.h>
>  #include <ctype.h>
>  #include <limits.h>
> +#include <byteswap.h>
>  #include <math.h>
>  #ifdef HAVE_STDLIB_H
>  #include <stdlib.h>
> @@ -1342,6 +1343,60 @@ sim_monitor (SIM_DESC sd,
>  	break;
>        }
>  
> +    case 13: /* int unlink(const char *path) */
> +      {
> +	char *path = fetch_str (sd, A0);
> +	V0 = sim_io_unlink (sd, path);
> +	free (path);
> +	break;
> +      }
> +
> +    case 14: /* int lseek(int fd, int offset, int whence) */
> +      {
> +	V0 = sim_io_lseek (sd, A0, A1, A2);
> +	break;
> +      }
> +
> +/* We may need to swap stat data around before passing it on to the
> +   program being run.  */
> +#define copy16(x) (BigEndianMem ? bswap_16(x) : (x))
> +#define copy32(x) (BigEndianMem ? bswap_32(x) : (x))
> +
> +    case 15: /* int stat(const char *path, struct stat *buf); */
> +      {
> +	/* We need to put the data into the type of stat structure
> +	   that MIPS uses and make sure it has the correct endianness.
> +	   We are assuming that the host and MIPS agree on what the bits
> +	   in st_mode mean.  That appears to be true for x86 linux and
> +	   MIPS.  */
> +        struct stat host_stat;
> +	struct __attribute__ ((__packed__)) mips_stat {
> +		short st_dev;
> +		unsigned short st_ino;
> +		unsigned int st_mode;
> +		unsigned short st_nlink;
> +		unsigned short st_uid;
> +		unsigned short st_gid;
> +		short st_rdev;
> +		int st_size;
> +	} mips_stat;
> +	char *buf;
> +        char *path = fetch_str (sd, A0);
> +	buf = (char *) A1;
> +	V0 = sim_io_stat (sd, path, &host_stat);
> +	free (path);
> +	mips_stat.st_dev = copy16((short) host_stat.st_dev);
> +	mips_stat.st_ino = copy16((unsigned short) host_stat.st_ino);
> +	mips_stat.st_mode = copy32((int) host_stat.st_mode);
> +	mips_stat.st_nlink = copy16((unsigned short) host_stat.st_nlink);
> +	mips_stat.st_uid = copy16((unsigned short) host_stat.st_uid);
> +	mips_stat.st_gid = copy16((unsigned short) host_stat.st_gid);
> +	mips_stat.st_rdev = copy16((short) host_stat.st_rdev);
> +	mips_stat.st_size = copy32((int) host_stat.st_size);
> +	sim_write (sd, A1, (char *) &mips_stat, 20);
> +	break;
> +      }
> +
>      case 17: /* void _exit() */
>        {
>  	sim_io_eprintf (sd, "sim_monitor(17): _exit(int reason) to be coded\n");
> 




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch, sim, mips] Implement unlink, lseek, and stat for MIPS
  2013-07-24 23:19 ` Steve Ellcey
@ 2013-08-07 21:48   ` Steve Ellcey
  2013-09-03  6:14     ` Mike Frysinger
  0 siblings, 1 reply; 5+ messages in thread
From: Steve Ellcey @ 2013-08-07 21:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: vapier

Another ping with a cc to Mike Frysinger as the global sim maintainer
since there doesn't seem to be a mips specific maintainer for sim.

Steve Ellcey
sellcey@mips.com

On Wed, 2013-07-24 at 16:19 -0700, Steve Ellcey wrote:
> Ping.  The newlib/libgloss patch that this needs has been approved and
> checked in.  OK to checkin this MIPS specific GNU simulator change?
> 
> Steve Ellcey
> sellcey@mips.com
> 
> 
> On Wed, 2013-07-10 at 07:48 -0700, Steve Ellcey wrote:
> > A while back I submitted a GCC patch that allowed me to build the Fortran
> > compiler on a newlib based cross compiler.  While using the GNU simulator
> > to test that, I found that a number of tests failed due to unimplemented
> > system calls on the MIPS GNU simulator.  This patch implements unlink,
> > lseek, and stat in the GNU simulator for MIPS.  There is a second small
> > patch that I sent to newlib that generates the necessary functions for
> > the simulator to see and intercept these functions like it does others
> > that are already implemented such as open and close.
> > 
> > OK to checkin?
> > 
> > Steve Ellcey
> > sellcey@mips.com
> > 
> > 
> > Steve Ellcey  <sellcey@mips.com>
> > 
> > 	* interp.c (sim_monitor): Add switch entries for unlink (13),
> > 	lseek (14), and stat (15).
> > 
> > 
> > diff --git a/sim/mips/interp.c b/sim/mips/interp.c
> > index 032570a..766a113 100644
> > --- a/sim/mips/interp.c
> > +++ b/sim/mips/interp.c
> > @@ -47,6 +47,7 @@ code on the hardware.
> >  #include <ansidecl.h>
> >  #include <ctype.h>
> >  #include <limits.h>
> > +#include <byteswap.h>
> >  #include <math.h>
> >  #ifdef HAVE_STDLIB_H
> >  #include <stdlib.h>
> > @@ -1342,6 +1343,60 @@ sim_monitor (SIM_DESC sd,
> >  	break;
> >        }
> >  
> > +    case 13: /* int unlink(const char *path) */
> > +      {
> > +	char *path = fetch_str (sd, A0);
> > +	V0 = sim_io_unlink (sd, path);
> > +	free (path);
> > +	break;
> > +      }
> > +
> > +    case 14: /* int lseek(int fd, int offset, int whence) */
> > +      {
> > +	V0 = sim_io_lseek (sd, A0, A1, A2);
> > +	break;
> > +      }
> > +
> > +/* We may need to swap stat data around before passing it on to the
> > +   program being run.  */
> > +#define copy16(x) (BigEndianMem ? bswap_16(x) : (x))
> > +#define copy32(x) (BigEndianMem ? bswap_32(x) : (x))
> > +
> > +    case 15: /* int stat(const char *path, struct stat *buf); */
> > +      {
> > +	/* We need to put the data into the type of stat structure
> > +	   that MIPS uses and make sure it has the correct endianness.
> > +	   We are assuming that the host and MIPS agree on what the bits
> > +	   in st_mode mean.  That appears to be true for x86 linux and
> > +	   MIPS.  */
> > +        struct stat host_stat;
> > +	struct __attribute__ ((__packed__)) mips_stat {
> > +		short st_dev;
> > +		unsigned short st_ino;
> > +		unsigned int st_mode;
> > +		unsigned short st_nlink;
> > +		unsigned short st_uid;
> > +		unsigned short st_gid;
> > +		short st_rdev;
> > +		int st_size;
> > +	} mips_stat;
> > +	char *buf;
> > +        char *path = fetch_str (sd, A0);
> > +	buf = (char *) A1;
> > +	V0 = sim_io_stat (sd, path, &host_stat);
> > +	free (path);
> > +	mips_stat.st_dev = copy16((short) host_stat.st_dev);
> > +	mips_stat.st_ino = copy16((unsigned short) host_stat.st_ino);
> > +	mips_stat.st_mode = copy32((int) host_stat.st_mode);
> > +	mips_stat.st_nlink = copy16((unsigned short) host_stat.st_nlink);
> > +	mips_stat.st_uid = copy16((unsigned short) host_stat.st_uid);
> > +	mips_stat.st_gid = copy16((unsigned short) host_stat.st_gid);
> > +	mips_stat.st_rdev = copy16((short) host_stat.st_rdev);
> > +	mips_stat.st_size = copy32((int) host_stat.st_size);
> > +	sim_write (sd, A1, (char *) &mips_stat, 20);
> > +	break;
> > +      }
> > +
> >      case 17: /* void _exit() */
> >        {
> >  	sim_io_eprintf (sd, "sim_monitor(17): _exit(int reason) to be coded\n");
> > 
> 
> 




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch, sim, mips] Implement unlink, lseek, and stat for MIPS
  2013-07-10 14:49 [patch, sim, mips] Implement unlink, lseek, and stat for MIPS Steve Ellcey 
  2013-07-24 23:19 ` Steve Ellcey
@ 2013-09-03  6:14 ` Mike Frysinger
  1 sibling, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2013-09-03  6:14 UTC (permalink / raw)
  To: gdb-patches; +Cc: Steve Ellcey 

[-- Attachment #1: Type: Text/Plain, Size: 1813 bytes --]

On Wednesday 10 July 2013 10:48:28 Steve Ellcey wrote:
> A while back I submitted a GCC patch that allowed me to build the Fortran
> compiler on a newlib based cross compiler.  While using the GNU simulator
> to test that, I found that a number of tests failed due to unimplemented
> system calls on the MIPS GNU simulator.  This patch implements unlink,
> lseek, and stat in the GNU simulator for MIPS.  There is a second small
> patch that I sent to newlib that generates the necessary functions for
> the simulator to see and intercept these functions like it does others
> that are already implemented such as open and close.

yeah, it'd be nice if mips could just use the already existing 
common/syscall.c and common/callback.c files where a bunch of funcs are already 
implemented ...

> --- a/sim/mips/interp.c
> +++ b/sim/mips/interp.c
>
> +/* We may need to swap stat data around before passing it on to the
> +   program being run.  */
> +#define copy16(x) (BigEndianMem ? bswap_16(x) : (x))
> +#define copy32(x) (BigEndianMem ? bswap_32(x) : (x))
> +
> +    case 15: /* int stat(const char *path, struct stat *buf); */
> +      {
> +	/* We need to put the data into the type of stat structure
> +	   that MIPS uses and make sure it has the correct endianness.
> +	   We are assuming that the host and MIPS agree on what the bits
> +	   in st_mode mean.  That appears to be true for x86 linux and
> +	   MIPS.  */

instead of doing this, can you use the existing stat cb handler instead ?

	host_callback *cb = STATE_CALLBACK (sd);
	struct stat statbuf;
	int result;

	result = (*cb->stat) (cb, path, &statbuf);

you'll need to initialize cb->stat_map to a string (probably in 
sim_create_inferior).  see bfin/interp.c:cb_linux_stat_map_32 as an example.
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch, sim, mips] Implement unlink, lseek, and stat for MIPS
  2013-08-07 21:48   ` Steve Ellcey
@ 2013-09-03  6:14     ` Mike Frysinger
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2013-09-03  6:14 UTC (permalink / raw)
  To: gdb-patches; +Cc: Steve Ellcey

[-- Attachment #1: Type: Text/Plain, Size: 312 bytes --]

On Wednesday 07 August 2013 17:47:37 Steve Ellcey wrote:
> Another ping with a cc to Mike Frysinger as the global sim maintainer
> since there doesn't seem to be a mips specific maintainer for sim.

sorry, i was on vacation for a month and then didn't catch up on e-mail for a 
few weeks after that
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-09-03  6:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-10 14:49 [patch, sim, mips] Implement unlink, lseek, and stat for MIPS Steve Ellcey 
2013-07-24 23:19 ` Steve Ellcey
2013-08-07 21:48   ` Steve Ellcey
2013-09-03  6:14     ` Mike Frysinger
2013-09-03  6:14 ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).