Received: from cs.wisc.edu by primost.cs.wisc.edu; Sat, 3 Apr 93 14:49:34 -0600
Received: from ursa.calvin.edu by cs.wisc.edu; Sat, 3 Apr 93 14:49:27 -0600
Received: by Calvin.EDU (4.1/SMI-4.1)
	id AA09340; Sat, 3 Apr 93 15:49:18 EST
From: mjr@Calvin.EDU (Matt Ranney)
Message-Id: <9304032049.AA09340@Calvin.EDU>
Subject: Re: spim under linux
To: larus
Date: Sat, 3 Apr 93 15:49:18 EST
In-Reply-To: <9304032011.AA04577@primost.cs.wisc.edu> from "James Larus" at Apr 3, 93 02:11:32 pm
X-Mailer: ELM [version 2.4beta PL3]
Content-Type: text
Content-Length: 11600     

James Larus Writes...
) 
) Sure, I'd like to see them.  I'm not sure they are generally useful,
) but with permission, I'd like include them with the distributed copy
) of SPIM.

No problem.  They weren't that hard to do, and you can feel free to
include them or mangle them in any way you see fit.

The ioctl() stuff in spim.c I am a bit unsure of.  Linux doesn't have
TIOCGETP, and it also doesn't have man pages for the corresponding
ioctl() calls, so I had to kinda guess, based on my SunOS manual
pages.  However, I think it does almost the same thing.

The other changes are very simple.  I'd be happy to explain any of
them if you want.  A diff -C 5 follows...

diff -r -C 5 spim.orig/Imakefile spim/Imakefile
*** spim.orig/Imakefile	Fri Sep 18 13:43:00 1992
--- spim/Imakefile	Sat Apr  3 15:42:44 1993
***************
*** 56,74 ****
  # on the VAX).
  #
  
  # Full path for directory that will hold the trap handler file (default:
  # SPIM source directory):
! TRAP_DIR = /var/scratch/lib
  
  
  # Full path for the directory that will hold the executable files:
! BIN_DIR = /var/scratch/bin.MIPS
  
  
  # Full path for the directory that will hold the man files:
! MAN_DIR = /var/scratch/man
  
  
  # If host computer is big-endian (e.g. 68000's (i.e. Sun 3, HP Bobcats), RT/PC,
  # SPARC, HP 700's (snakes), and some MIPS boxes), define this:
  #ENDIAN=-DBIGENDIAN
--- 56,74 ----
  # on the VAX).
  #
  
  # Full path for directory that will hold the trap handler file (default:
  # SPIM source directory):
! TRAP_DIR = /usr/local/spim
  
  
  # Full path for the directory that will hold the executable files:
! BIN_DIR = /usr/local/bin
  
  
  # Full path for the directory that will hold the man files:
! MAN_DIR = /usr/local/man
  
  
  # If host computer is big-endian (e.g. 68000's (i.e. Sun 3, HP Bobcats), RT/PC,
  # SPARC, HP 700's (snakes), and some MIPS boxes), define this:
  #ENDIAN=-DBIGENDIAN
***************
*** 99,117 ****
  
  # Size of the segments when spim starts up (data segment must be >= 64K).
  MEM_SIZES = -DTEXT_SIZE=65536 -DDATA_SIZE=131072 -DK_TEXT_SIZE=65536
  
  
! # Define these flags if your operating system libraries are missing these:
! #
! # -DNEED_VSPRINTF   If your system doesn't have vsprintf
! # -DNEED_STRTOL     If your system doesn't have strtol
! #
! # Note: Ultrix and SunOS do not need any flags.
! #       Sequent requires both flags.
! #	PC/RTs requires -DNEED_VSPRINTF
! #	Older versions of 4.3BSD requires -DNEED_STRTOL
  
  SYS_FLAGS =
  
  #
  # END OF PARAMETERS
--- 99,117 ----
  
  # Size of the segments when spim starts up (data segment must be >= 64K).
  MEM_SIZES = -DTEXT_SIZE=65536 -DDATA_SIZE=131072 -DK_TEXT_SIZE=65536
  
  
! /* Define these flags if your operating system libraries are missing these:
! 
!  -DNEED_VSPRINTF   If your system doesn't have vsprintf
!  -DNEED_STRTOL     If your system doesn't have strtol
! 
!  Note: Ultrix and SunOS do not need any flags.
!        Sequent requires both flags.
! 	PC/RTs requires -DNEED_VSPRINTF
! 	Older versions of 4.3BSD requires -DNEED_STRTOL */
  
  SYS_FLAGS =
  
  #
  # END OF PARAMETERS
***************
*** 139,149 ****
  LEXCFLAGS = -O
  YFLAGS = -d
  
  DEPLIBS = XawClientDepLibs
  LOCALLIBS = XawClientLibs
! CDEBUGFLAGS = -g
  EXTRA_DEFINES = $(ENDIAN) $(MEM_SIZES) $(SYS_FLAGS) $(CL_FLAG)
  
  #
  
  #
--- 139,150 ----
  LEXCFLAGS = -O
  YFLAGS = -d
  
  DEPLIBS = XawClientDepLibs
  LOCALLIBS = XawClientLibs
! CDEBUGFLAGS = -O
! DEPXTOOLLIB =
  EXTRA_DEFINES = $(ENDIAN) $(MEM_SIZES) $(SYS_FLAGS) $(CL_FLAG)
  
  #
  
  #
diff -r -C 5 spim.orig/inst.c spim/inst.c
*** spim.orig/inst.c	Thu Sep 10 21:37:33 1992
--- spim/inst.c	Sat Apr  3 11:25:15 1993
***************
*** 35,45 ****
  #include "parser.h"
  #include "scanner.h"
  #include "data.h"
  
  
! #ifdef __STDC__
  int bcmp (const void *, const void *, size_t);
  #else
  int bcmp ();
  #endif
  
--- 35,45 ----
  #include "parser.h"
  #include "scanner.h"
  #include "data.h"
  
  
! #if defined(__STDC__) && !defined(linux)
  int bcmp (const void *, const void *, size_t);
  #else
  int bcmp ();
  #endif
  
diff -r -C 5 spim.orig/mips-syscall.c spim/mips-syscall.c
*** spim.orig/mips-syscall.c	Fri Sep 18 02:56:47 1992
--- spim/mips-syscall.c	Sat Apr  3 11:32:41 1993
***************
*** 92,102 ****
  static int prog_sigmask = 0;	/* Copy of sigmask passed to system */
  
  static mem_addr exception_address[NSIG]; /* trampoline addresses for */
  					 /* each signal handler */
  
! static struct sigvec sighandler[NSIG]; /* Map to program handlers */
  
  static int prog_fds[OPEN_MAX];	/* Map from program fds to simulator fds */
  
  static int fds_initialized = 0;	/* FD map initialized? */
  
--- 92,106 ----
  static int prog_sigmask = 0;	/* Copy of sigmask passed to system */
  
  static mem_addr exception_address[NSIG]; /* trampoline addresses for */
  					 /* each signal handler */
  
! #if defined(linux)
! #  define SIGBUS SIGSEGV
! #else
!    static struct sigvec sighandler[NSIG]; /* Map to program handlers */
! #endif /* linux */
  
  static int prog_fds[OPEN_MAX];	/* Map from program fds to simulator fds */
  
  static int fds_initialized = 0;	/* FD map initialized? */
  
diff -r -C 5 spim.orig/run.c spim/run.c
*** spim.orig/run.c	Wed Sep  2 17:12:03 1992
--- spim/run.c	Sat Apr  3 13:17:33 1993
***************
*** 45,59 ****
  #include "run.h"
  
  
  extern int errno;
  
! #ifdef __STDC__
  long atol (const char *);
! #else
  long atol ();
! #endif
  
  
  /* Local functions: */
  
  #ifdef __STDC__
--- 45,61 ----
  #include "run.h"
  
  
  extern int errno;
  
! #if !defined (linux)
! #  if defined(__STDC__)
  long atol (const char *);
! #  else
  long atol ();
! #  endif /* STDC */
! #endif /* linux */
  
  
  /* Local functions: */
  
  #ifdef __STDC__
Only in spim: run.c~
diff -r -C 5 spim.orig/spim-utils.c spim/spim-utils.c
*** spim.orig/spim-utils.c	Wed Sep  2 21:51:10 1992
--- spim/spim-utils.c	Sat Apr  3 11:45:11 1993
***************
*** 521,531 ****
  
    va_start (args);
  #endif
    fmt = va_arg (args, char *);
  
! #ifdef mips
    vfprintf (stderr, fmt, args);
  #else
    _doprnt (fmt, args, stderr);
  #endif
    exit (-1);
--- 521,531 ----
  
    va_start (args);
  #endif
    fmt = va_arg (args, char *);
  
! #if defined(mips) || defined(linux)
    vfprintf (stderr, fmt, args);
  #else
    _doprnt (fmt, args, stderr);
  #endif
    exit (-1);
diff -r -C 5 spim.orig/spim.c spim/spim.c
*** spim.orig/spim.c	Wed Sep 16 20:09:03 1992
--- spim/spim.c	Sat Apr  3 12:54:30 1993
***************
*** 1105,1115 ****
  #else
    va_start (args);
    fmt = va_arg (args, char *);
  #endif
  
! #ifdef mips
    vfprintf (stderr, fmt, args);
  #else
    _doprnt (fmt, args, stderr);
  #endif
    va_end (args);
--- 1105,1115 ----
  #else
    va_start (args);
    fmt = va_arg (args, char *);
  #endif
  
! #if defined(mips) || defined(linux)
    vfprintf (stderr, fmt, args);
  #else
    _doprnt (fmt, args, stderr);
  #endif
    va_end (args);
***************
*** 1138,1148 ****
  #else
    va_start (args);
    fmt = va_arg (args, char *);
  #endif
  
! #ifdef mips
    vfprintf (stderr, fmt, args);
  #else
    _doprnt (fmt, args, stderr);
  #endif
    va_end (args);
--- 1138,1148 ----
  #else
    va_start (args);
    fmt = va_arg (args, char *);
  #endif
  
! #if defined(mips) || defined(linux)
    vfprintf (stderr, fmt, args);
  #else
    _doprnt (fmt, args, stderr);
  #endif
    va_end (args);
***************
*** 1179,1189 ****
    fp = va_arg (args, long);
    f = (FILE *) fp;		/* Not too portable... */
    fmt = va_arg (args, char *);
  #endif
  
! #ifdef mips
    if (f != 0)
      vfprintf (f, fmt, args);
    else
      vfprintf (stdout, fmt, args);
  #else
--- 1179,1189 ----
    fp = va_arg (args, long);
    f = (FILE *) fp;		/* Not too portable... */
    fmt = va_arg (args, char *);
  #endif
  
! #if defined(mips) || defined(linux)
    if (f != 0)
      vfprintf (f, fmt, args);
    else
      vfprintf (stdout, fmt, args);
  #else
***************
*** 1207,1218 ****
    read (console_in, str, n);
  }
  
  
  static int console_state_saved;
  static struct sgttyb saved_console_state;
! 
  
  /* Give the console to the program for IO. */
  
  #ifdef __STDC__
  static void
--- 1207,1221 ----
    read (console_in, str, n);
  }
  
  
  static int console_state_saved;
+ #ifdef linux
+ static struct termios saved_console_state;
+ #else
  static struct sgttyb saved_console_state;
! #endif
  
  /* Give the console to the program for IO. */
  
  #ifdef __STDC__
  static void
***************
*** 1220,1236 ****
  #else
  static void
  console_to_program ()
  #endif
  {
    int flags;
!   
    ioctl (console_in, TIOCGETP, (char *) &saved_console_state);
    flags = saved_console_state.sg_flags;
    saved_console_state.sg_flags = (flags | CBREAK) & ~(CRMOD|ECHO);
    ioctl (console_in, TIOCSETP, (char *) &saved_console_state);
    saved_console_state.sg_flags = flags;
    console_state_saved = 1;
  }
  
  
  /* Return the console to SPIM. */
--- 1223,1250 ----
  #else
  static void
  console_to_program ()
  #endif
  {
+ #ifdef linux
+   struct termios state;
+ 
+   ioctl(console_in, TCGETS, &saved_console_state);
+   ioctl(console_in, TCGETS, &state);
+   state.c_lflag &= ICANON | ~(ECHO);
+   state.c_cc[VTIME] = 0;
+   state.c_cc[VMIN] = 0;
+   ioctl(console_in, TCSETS, &state);
+ #else
    int flags;
! 
    ioctl (console_in, TIOCGETP, (char *) &saved_console_state);
    flags = saved_console_state.sg_flags;
    saved_console_state.sg_flags = (flags | CBREAK) & ~(CRMOD|ECHO);
    ioctl (console_in, TIOCSETP, (char *) &saved_console_state);
    saved_console_state.sg_flags = flags;
+ #endif
    console_state_saved = 1;
  }
  
  
  /* Return the console to SPIM. */
***************
*** 1241,1252 ****
--- 1255,1271 ----
  #else
  static void
  console_to_spim ()
  #endif
  {
+ #ifdef linux
+   if (console_state_saved)
+     ioctl(console_in, TCSETS, &saved_console_state);
+ #else
    if (console_state_saved)
      ioctl (console_in, TIOCSETP, (char *) &saved_console_state);
+ #endif
  }
  
       
  #ifdef __STDC__
  int
diff -r -C 5 spim.orig/spim.h spim/spim.h
*** spim.orig/spim.h	Thu Sep 10 21:36:25 1992
--- spim/spim.h	Sat Apr  3 11:52:06 1993
***************
*** 20,32 ****
  
  
  /* $Header: /home/primost/larus/UW/Funding/WWT.NSF/RCS/spim.h,v 3.13 1992/09/10 21:36:21 larus Exp larus $
  */
  
  #define NULL 0
  
- 
  #define streq(s1, s2) !strcmp(s1, s2)
  
  
  /* Round V to next greatest B boundary */
  
--- 20,33 ----
  
  
  /* $Header: /home/primost/larus/UW/Funding/WWT.NSF/RCS/spim.h,v 3.13 1992/09/10 21:36:21 larus Exp larus $
  */
  
+ #ifndef NULL
  #define NULL 0
+ #endif
  
  #define streq(s1, s2) !strcmp(s1, s2)
  
  
  /* Round V to next greatest B boundary */
  
***************
*** 49,60 ****
  /* Useful and pervasive declarations: */
  
  #ifdef __STDC__
  #include <stdlib.h>
  #include <string.h>
! void bzero (void *, size_t);
! void bcopy (const void *, void *, size_t);
  #else
  double atof ();
  int atoi ();
  void bzero ();
  void bcopy ();
--- 50,65 ----
  /* Useful and pervasive declarations: */
  
  #ifdef __STDC__
  #include <stdlib.h>
  #include <string.h>
! #if defined(linux)
! # include <termios.h>
! #else
!   void bzero (void *, size_t);
!   void bcopy (const void *, void *, size_t);
! #endif /* linux */
  #else
  double atof ();
  int atoi ();
  void bzero ();
  void bcopy ();



-- 
Matt Ranney -  mjr@calvin.edu
  "You know, I don't think theres a man, woman, or child alive today
   who doesn't enjoy a lovely beverage."  -DL
