[gnu.bash.bug] Bash 1.03 on Cray hardware

hrp@boring.cray.com (Hal Peterson) (10/03/89)

The following patches will get bash 1.03 to compile and run on a
Cray-2 system running UNICOS 5.0.  I compiled with scc, as you can see
from the Makefile.  The changes should be good for 5.1 as well.  Some
of the things I did apply to everybody:  for example, I don't have "."
in my PATH, so in the Makefile I invoke "./newversion.aux" instead of
"newversion.aux".  And the changes to nojobs.c are probably necessary
for anybody who tries to use it.

alloca.c and malloc.c are taken from our port of GNU Emacs.  Thanks to
Rita Wu for providing them.

These changes are almost good enough for Cray X-MP systems as well,
but I haven't yet figured out how to initialize the alloca code.  Stay
tuned.

On the Cray-2 platform there are still some bugs, but the interactive
stuff is usable.

				Hal
========================================================================
*** Makefile	Thu Aug 31 12:48:47 1989
--- ../bash-1.03-CRAY/Makefile	Thu Sep 14 15:25:00 1989
***************
*** 45,56 ****
  # Use i386 for PC type 386 boxes. (Compaq, etc.)
  # SUN3, SUN4, SUN386i, VAX, SONY, CONVEX, HP, HP9KS300, i386, NeXT, AIX,
  # ATT3B, ATT386
! TARGET = SUN3
  
  # The name of the target operating system.  There isn't such a big
  # difference between SUNOS3 and Bsd.  But there might be in the future.
  # SUNOS3, SUNOS4, SYSV, Bsd, HPUX, UNIXPC
! OS = SUNOS4
  
  # You only need this if you are hacking the shell in a location
  # that doesn't do enough backups, or does a poor job.  In that
--- 45,56 ----
  # Use i386 for PC type 386 boxes. (Compaq, etc.)
  # SUN3, SUN4, SUN386i, VAX, SONY, CONVEX, HP, HP9KS300, i386, NeXT, AIX,
  # ATT3B, ATT386
! TARGET = CRAY
  
  # The name of the target operating system.  There isn't such a big
  # difference between SUNOS3 and Bsd.  But there might be in the future.
  # SUNOS3, SUNOS4, SYSV, Bsd, HPUX, UNIXPC
! OS = SYSV
  
  # You only need this if you are hacking the shell in a location
  # that doesn't do enough backups, or does a poor job.  In that
***************
*** 75,91 ****
  # Xenix requires -lx -ldir.  It is also required in the readline Makefile.
  #LOCAL_LIBS = -lx -ldir
  
! GCC_SUNOS4_FLAG = -Bstatic
! DEBUG_FLAGS = $(PROFILE_FLAGS) -g $(GCC_SUNOS4_FLAG)
  LDFLAGS	= $(DEBUG_FLAGS)
  CFLAGS	= $(DEBUG_FLAGS) -D${TARGET} -DTARGET=${TARGET} -D${OS}
  CPPFLAGS= -I$(LIBSRC)
  
  # If you don't have Bison use "yacc".  Otherwise use "bison -y".
! BISON = bison -y
  
  # If you don't have Gcc use cc.
! CC = gcc -traditional
  
  ####################################################################
  
--- 75,94 ----
  # Xenix requires -lx -ldir.  It is also required in the readline Makefile.
  #LOCAL_LIBS = -lx -ldir
  
! 
! GCC_SUNOS4_FLAG =
! PCCDEBUG = -g -h olevel_0
! SCCDEBUG = -g -h noopt
! DEBUG_FLAGS = $(PROFILE_FLAGS) $(SCCDEBUG) $(GCC_SUNOS4_FLAG)
  LDFLAGS	= $(DEBUG_FLAGS)
  CFLAGS	= $(DEBUG_FLAGS) -D${TARGET} -DTARGET=${TARGET} -D${OS}
  CPPFLAGS= -I$(LIBSRC)
  
  # If you don't have Bison use "yacc".  Otherwise use "bison -y".
! BISON = yacc
  
  # If you don't have Gcc use cc.
! CC = scc
  
  ####################################################################
  
***************
*** 110,119 ****
  ALLOC_SOURCE = ./alloc-files/
  
  # Our malloc.
! MALLOC = $(ALLOC_SOURCE)malloc.o
  MALLOC_FLAGS = -Drcheck -Dbotch=programming_error
  #MALLOC= $(ALLOC_SOURCE)malloc.o
! #ALLOCA= $(ALLOC_SOURCE)alloca.o
  
  ALLOC_HEADERS = $(ALLOC_SOURCE)getpagesize.h
  ALLOC_FILES = $(ALLOC_SOURCE)malloc.c $(ALLOC_SOURCE)alloca.c\
--- 113,122 ----
  ALLOC_SOURCE = ./alloc-files/
  
  # Our malloc.
! MALLOC = malloc.o
  MALLOC_FLAGS = -Drcheck -Dbotch=programming_error
  #MALLOC= $(ALLOC_SOURCE)malloc.o
! ALLOCA= alloca.o
  
  ALLOC_HEADERS = $(ALLOC_SOURCE)getpagesize.h
  ALLOC_FILES = $(ALLOC_SOURCE)malloc.c $(ALLOC_SOURCE)alloca.c\
***************
*** 128,143 ****
  
  # If your system doesn't have a sys_siglist, then define SIGLIST
  # as siglist.o
! #SIGLIST = siglist.o
  
  RM = rm
  AR = ar
! RANLIB = ranlib
  
  # Support libraries required.  Termcap and Readline.
  # We would like to use GNU's termcap library.  Where is it?
  # If you don't have -ltermcap, you might try -lcurses.
! TERMCAP = /usr/lib/libtermcap.a
  READLINE= ./readline/libreadline.a
  
  # The source code for the support libraries.
--- 131,146 ----
  
  # If your system doesn't have a sys_siglist, then define SIGLIST
  # as siglist.o
! SIGLIST = siglist.o
  
  RM = rm
  AR = ar
! RANLIB = true
  
  # Support libraries required.  Termcap and Readline.
  # We would like to use GNU's termcap library.  Where is it?
  # If you don't have -ltermcap, you might try -lcurses.
! TERMCAP = /usr/lib/libcurses.a
  READLINE= ./readline/libreadline.a
  
  # The source code for the support libraries.
***************
*** 180,186 ****
  OBJECTS  = shell.o y.tab.o general.o make_cmd.o print_cmd.o\
  	   dispose_cmd.o execute_cmd.o variables.o builtins.o copy_cmd.o\
  	   flags.o jobs.o subst.o glob.o hash.o mailcheck.o test.o\
! 	   trap.o alias.o $(MALLOC) $(ALLOCA) braces.o unwind_prot.o\
  	   $(SIGLIST) bashline.o version.o
  
  # Documentation for the shell.
--- 183,189 ----
  OBJECTS  = shell.o y.tab.o general.o make_cmd.o print_cmd.o\
  	   dispose_cmd.o execute_cmd.o variables.o builtins.o copy_cmd.o\
  	   flags.o jobs.o subst.o glob.o hash.o mailcheck.o test.o\
! 	   trap.o alias.o $(ALLOCA) $(MALLOC) braces.o unwind_prot.o\
  	   $(SIGLIST) bashline.o version.o
  
  # Documentation for the shell.
***************
*** 208,220 ****
  	$(RM) .make
  
  .build:		newversion.aux  .make $(SOURCES)
! 	if newversion.aux -build; then mv -f newversion.h version.h; fi
  
  .make:
  	touch .make
  
  version.h:	newversion.aux
! 	if newversion.aux -build; then mv -f newversion.h version.h; fi
  
  shell.h:	general.h variables.h config.h
  		touch shell.h
--- 211,223 ----
  	$(RM) .make
  
  .build:		newversion.aux  .make $(SOURCES)
! 	if ./newversion.aux -build; then mv -f newversion.h version.h; fi
  
  .make:
  	touch .make
  
  version.h:	newversion.aux
! 	if ./newversion.aux -build; then mv -f newversion.h version.h; fi
  
  shell.h:	general.h variables.h config.h
  		touch shell.h
***************
*** 228,236 ****
  		(cd $(RLIBSRC); $(MAKE) $(MFLAGS) CC='$(CC)'\
  			CFLAGS='$(CFLAGS) -DSHELL')
  
! $(TERMCAP):	$(TERMCAP_SOURCE)
! 		(cd $(LIBSRC); $(MAKE) $(MFLAGS) CC='$(CC)'\
! 			CFLAGS='$(CFLAGS) -I.')
  
  shell.o:	shell.h flags.h shell.c
  		$(CC) $(CFG_FLAGS) $(CFLAGS) $(CPPFLAGS) -c shell.c
--- 231,239 ----
  		(cd $(RLIBSRC); $(MAKE) $(MFLAGS) CC='$(CC)'\
  			CFLAGS='$(CFLAGS) -DSHELL')
  
! #$(TERMCAP):	$(TERMCAP_SOURCE)
! #		(cd $(LIBSRC); $(MAKE) $(MFLAGS) CC='$(CC)'\
! #			CFLAGS='$(CFLAGS) -I.')
  
  shell.o:	shell.h flags.h shell.c
  		$(CC) $(CFG_FLAGS) $(CFLAGS) $(CPPFLAGS) -c shell.c
***************
*** 242,252 ****
  		touch keymaps.c
  
  $(MALLOC):	$(ALLOC_FILES)
! 		$(CC) -I$(ALLOC_SOURCE) $(CFLAGS) $(MALLOC_FLAGS) -c $*.c &&\
! 		mv `basename $*`.o $(MALLOC)
  
! #$(ALLOCA):	$(ALLOC_FILES)
! #		$(CC) -I$(ALLOC_SOURCE) $(CFLAGS) -o $(ALLOCA) -c $*.c
  
  bashline.o:	bashline.c config.h $(RLIBSRC)readline.h
  		$(CC) -I../ $(CFLAGS) $(CPPFLAGS) -c bashline.c
--- 245,254 ----
  		touch keymaps.c
  
  $(MALLOC):	$(ALLOC_FILES)
! 		$(CC) -I$(ALLOC_SOURCE) $(CFLAGS) $(MALLOC_FLAGS) -c $(ALLOC_SOURCE)malloc.c
  
! $(ALLOCA):	$(ALLOC_FILES)
! 		$(CC) -I$(ALLOC_SOURCE) $(CFLAGS) -c $(ALLOC_SOURCE)alloca.c
  
  bashline.o:	bashline.c config.h $(RLIBSRC)readline.h
  		$(CC) -I../ $(CFLAGS) $(CPPFLAGS) -c bashline.c
***************
*** 309,315 ****
  		$(SHELL) -c 'f=$(PROGRAM)-`cat .distribution`.tar.Z;uuencode $$f $$f | split -800 - uuencoded/$$f.uu.'
  
  .distribution:	newversion.aux
! 		newversion.aux -dist `$(PROGRAM) -c 'echo $$BASH_VERSION'`
  
  distribution:	$(PROGRAM).tar.Z .distribution
  		cp $(PROGRAM).tar.Z $(PROGRAM)-`cat .distribution`.tar.Z
--- 311,317 ----
  		$(SHELL) -c 'f=$(PROGRAM)-`cat .distribution`.tar.Z;uuencode $$f $$f | split -800 - uuencoded/$$f.uu.'
  
  .distribution:	newversion.aux
! 		./newversion.aux -dist `$(PROGRAM) -c 'echo $$BASH_VERSION'`
  
  distribution:	$(PROGRAM).tar.Z .distribution
  		cp $(PROGRAM).tar.Z $(PROGRAM)-`cat .distribution`.tar.Z
***************
*** 319,325 ****
  
  newversion:	newversion.aux
  		rm -f .build
! 		newversion.aux -dist
  		mv -f newversion.h version.h
  		make $(PROGRAM)
  
--- 321,327 ----
  
  newversion:	newversion.aux
  		rm -f .build
! 		./newversion.aux -dist
  		mv -f newversion.h version.h
  		make $(PROGRAM)
  
***************
*** 334,336 ****
--- 336,341 ----
  dist-clean:
  		rm -f $(OBJECTS) $(PROGRAM) y.tab.c newversion.aux
  		rm -rf uuencoded
+ 
+ alloca.o:	$(ALLOC_SOURCE)alloca.c
+ malloc.o:	$(ALLOC_SOURCE)malloc.c
*** alloc-files/malloc.c	Thu May 25 10:44:25 1989
--- ../bash-1.03-CRAY/alloc-files/malloc.c	Tue Sep 12 11:56:43 1989
***************
*** 127,132 ****
--- 127,151 ----
   * Call malloc_stats to get info on memory stats if MSTATS turned on.
   * realloc knows how to return same block given, just changing its size,
   * if the power of 2 is correct.
+  *
+  * Aug 87, MJM: for Cray UNICOS
+  *    If USE_LIBC-MALLOC is #defined, then just provide dummy interfaces
+  *    for externals needed by emacs source code.  This includes:
+  *            int malloc_sbrk_used, int malloc_sbrk_unused;
+  *            malloc_init (start, warnfun)
+  *            malloc_stats ()  #ifdef MSTATS
+  *    Cannot use GNU malloc.c with current Cray xmp C compiler because the
+  *    calling sequence uses malloc (and mshrink) when passing large structures
+  *    and cannot have a user program calling sbrk() or sbreak ().
+  *    Only lose warning messages about running out of space and mstat stuff.
+  *
+  * Note: in src/alloc.c it says for example --
+  *    Each cons_block is just under 1020 bytes long,
+  *    since malloc really allocates in units of powers of two
+  *    and uses 4 bytes for its own overhead.
+  *    #define CONS_BLOCK_SIZE  \
+  *      ((1020 - sizeof (struct cons_block *)) / sizeof (struct Lisp_Cons))
+  *    -- I think this is only for efficiency ???
   */
  
  /*
***************
*** 144,153 ****
  #include "config.h"
  #endif /* emacs */
  
- #ifdef HPUX
- #define USG
- #endif
- 
  /* Determine which kind of system this is.  */
  #include <signal.h>
  #ifndef SIGTSTP
--- 163,168 ----
***************
*** 182,191 ****
  #endif
  #endif
  
- #ifndef emacs
- #define start_of_data() &etext
- #endif
- 
  #define ISALLOC ((char) 0xf7)	/* magic byte that implies allocation */
  #define ISFREE ((char) 0x54)	/* magic byte that implies free block */
  				/* this is for error checking only */
--- 197,202 ----
***************
*** 238,247 ****
    (*(struct mhead **) (sizeof (char *) + (char *) (a)))
  
  #ifdef rcheck
- #include <stdio.h>
- #ifndef botch
- #define botch(x) abort ()
- #endif
  
  /* To implement range checking, we write magic values in at the beginning and
     end of each allocated block, and make sure they are undisturbed whenever a
--- 249,254 ----
***************
*** 313,318 ****
--- 320,369 ----
    return blocksize - sizeof (struct mhead) - EXTRA;
  }
  
+ #ifdef USE_LIBC_MALLOC
+ malloc_check ()       /* called in alloc.c  xmalloc(), xrealloc()  */
+ {
+ char	*sbrk ();
+ register char	*cp;
+ register int	siz;
+ extern char	*start_of_data ();     /* start of initialized data  */
+ 
+ 	if (!data_space_start)
+ 		data_space_start = start_of_data ();
+   	if (lim_data == 0)
+     		get_lim_data ();
+ 
+   /* Find current end of memory and issue warning if getting near max */
+ 
+ 	cp = sbrk (0);
+ 	siz = cp - data_space_start;
+ 	malloc_sbrk_used = siz;
+ 	malloc_sbrk_unused = lim_data - siz;
+ 
+   	if (warnfunction)     /* malloc_init sets */
+     		switch (warnlevel) {
+ 		case 0:
+ 			if (siz > (lim_data /4) * 3) {
+ 				warnlevel++;
+ 				(*warnfunction) ("Warning: past 75% of memory limit");
+ 				}
+ 			break;
+       		case 1:
+         		if (siz > (lim_data /20) * 17) {
+             			warnlevel++;
+             			(*warnfunction) ("Warning: past 85% of memory limit");
+           			}
+         		break;
+       		case 2:
+         		if (siz > (lim_data /20) * 19) {
+             			warnlevel++;
+             			(*warnfunction) ("Warning: past 95% of memory limit");
+           			}
+       			break;
+       		}
+ 
+ }
+ #else	USE_LIBC_MALLOC
  static void
  morecore (nu)			/* ask system for more memory */
       register int nu;		/* size index to get more of  */
***************
*** 323,328 ****
--- 374,383 ----
    register unsigned int siz;
    int oldmask;
  
+ #ifdef CRAY2
+   int bytes;
+ #endif
+ 
  #ifdef BSD
  #ifndef BSD4_1
    oldmask = sigsetmask (-1);
***************
*** 380,387 ****
--- 435,448 ----
  	break;
        }
  
+ #ifdef CRAY2
+   bytes = getbytes (cp);
+   if (bytes & 0x3ff) /* land on 1k boundaries */
+     sbrk (1024 - (bytes & 0xff));
+ #else
    if ((int) cp & 0x3ff)	/* land on 1K boundaries */
      sbrk (1024 - ((int) cp & 0x3ff));
+ #endif /* CRAY2 */
  #endif /* not VMS */
  
   /* Take at least 2k, and figure out how many blocks of the desired size
***************
*** 393,403 ****
--- 454,466 ----
    if ((cp = sbrk (1 << (siz + 3))) == (char *) -1)
      return;			/* no more room! */
  #ifndef VMS
+ #ifndef CRAY
    if ((int) cp & 7)
      {		/* shouldn't happen, but just in case */
        cp = (char *) (((int) cp + 8) & ~7);
        nblks--;
      }
+ #endif /* CRAY */
  #endif /* not VMS */
  
   /* save new header and link the nblks blocks together */
***************
*** 427,434 ****
    char * sbrk ();
    register char *cp = sbrk (0);
  
!   if ((int) cp & 0x3ff)	/* land on 1K boundaries */
!     sbrk (1024 - ((int) cp & 0x3ff));
  
    /* Record address of start of space allocated by malloc.  */
    if (_malloc_base == 0)
--- 490,504 ----
    char * sbrk ();
    register char *cp = sbrk (0);
  
! #ifdef CRAY2
!    int bytes;
!    bytes = getbytes (cp);
!    if (bytes & 0x3ff) /* land on 1k boundaries */
!      sbrk (1024 - (bytes & 0x3ff));
! #else
!    if ((int) cp & 0x3ff)	/* land on 1K boundaries */
!      sbrk (1024 - ((int) cp & 0x3ff));
! #endif
  
    /* Record address of start of space allocated by malloc.  */
    if (_malloc_base == 0)
***************
*** 545,563 ****
  	p = (struct mhead *) ap - 1;
        }
  
- #ifndef rcheck
      if (p -> mh_alloc != ISALLOC)
        abort ();
  
! #else rcheck
!     if (p -> mh_alloc != ISALLOC)
!       {
! 	if (p -> mh_alloc == ISFREE)
! 	  botch ("free: Called with already freed block argument\n");
! 	else
! 	  botch ("free: Called with bad argument\n");
!       }
! 
      ASSERT (p -> mh_magic4 == MAGIC4);
      ap += p -> mh_nbytes;
      ASSERT (*ap++ == MAGIC1); ASSERT (*ap++ == MAGIC1);
--- 615,624 ----
  	p = (struct mhead *) ap - 1;
        }
  
      if (p -> mh_alloc != ISALLOC)
        abort ();
  
! #ifdef rcheck
      ASSERT (p -> mh_magic4 == MAGIC4);
      ap += p -> mh_nbytes;
      ASSERT (*ap++ == MAGIC1); ASSERT (*ap++ == MAGIC1);
***************
*** 657,663 ****
--- 718,730 ----
    if (ptr == 0)
      return 0;
    /* If entire block has the desired alignment, just accept it.  */
+ 
+ #ifdef CRAY2
+   if (((long) ptr & (alignment - 1)) == 0)
+ #else
    if (((int) ptr & (alignment - 1)) == 0)
+ #endif
+ 
      return ptr;
    /* Otherwise, get address of byte in the block that has that alignment.  */
    aligned = (char *) (((int) ptr + alignment - 1) & -alignment);
***************
*** 679,684 ****
--- 746,752 ----
    return memalign (getpagesize (), size);
  }
  #endif /* not HPUX */
+ #endif	USE_LIBC_MALLOC
  #endif /* not VMS */
  
  #ifdef MSTATS
***************
*** 731,738 ****
--- 799,815 ----
  {
    extern long ulimit ();
      
+ #ifdef CRAY
+   lim_data = (ulimit (3,0)) >> 3;  /* convert to words */
+ #else
    lim_data = ulimit (3, 0);
+ #endif
+ 
    lim_data -= (long) data_space_start;
+ 
+ #ifdef CRAY
+   lim_data <<= 3;  /* convert to bytes */
+ #endif
  }
  
  #else /* not USG */
***************
*** 759,764 ****
--- 836,856 ----
  
  #endif /* BSD42 */
  #endif /* not USG */
+ 
+ #ifdef CRAY
+ int getbytes (cp)
+      char *cp;
+ {
+   long tp;
+   int bytes, word;
+ 
+   tp = (long) cp;
+   bytes = tp >> 61;
+   word = tp & 037777777777;
+   bytes += (word <<3);  /* multiply by 8 */
+   return (bytes);
+ }
+ #endif
  
  #ifdef VMS
  /* There is a problem when dumping and restoring things on VMS. Calls
***************
*** 831,833 ****
--- 923,972 ----
    return temp;
  }
  #endif /* VMS */
+ 
+ /*
+  *	Return the address of the start of the data segment prior to
+  *	doing an unexec().  After unexec() the return value is undefined.
+  *	See crt0.c for further information and definition of data_start.
+  *
+  *	Apparently, on BSD systems this is etext at startup.  On
+  *	USG systems (swapping) this is highly mmu dependent and
+  *	is also dependent on whether or not the program is running
+  *	with shared text.  Generally there is a (possibly large)
+  *	gap between end of text and start of data with shared text.
+  *
+  *	On Uniplus+ systems with shared text, data starts at a
+  *	fixed address.  Each port (from a given oem) is generally
+  *	different, and the specific value of the start of data can
+  *	be obtained via the UniPlus+ specific "uvar(2)" system call,
+  *	however the method outlined in crt0.c seems to be more portable.
+  *
+  *	Probably what will have to happen when a USG unexec is available,
+  *	at least on UniPlus, is temacs will have to be made unshared so
+  *	that text and data are contiguous.  Then once loadup is complete,
+  *	unexec will produce a shared executable where the data can be
+  *	at the normal shared text boundry and the startofdata variable
+  *	will be patched by unexec to the correct value.
+  *
+  */
+  
+ char *
+ start_of_data ()
+ {
+ #ifdef DATA_START
+   return ((char *) DATA_START);
+ #else
+ #ifdef CRAY2
+   extern int zzzzzztx;
+   return ((char *) &zzzzzztx);
+ #else 
+ #ifdef CRAY1
+   extern struct exec exec_hdr;
+   return ((char *) (exec_hdr.a_text));
+ #else
+   extern int data_start;
+   return ((char *) &data_start);
+ #endif
+ #endif
+ #endif
+ }
*** alloc-files/alloca.c	Mon Nov  7 09:35:19 1988
--- ../bash-1.03-CRAY/alloc-files/alloca.c	Tue Sep 12 11:45:37 1989
***************
*** 55,60 ****
--- 55,66 ----
  
  extern void	free();
  extern pointer	xmalloc();
+ #ifdef CRAY
+ extern int depth_on_entry;
+ static int call_depth;
+ #define INCR_CALL_DEPTH \
+         call_depth += (depth_on_entry == call_depth) ? 1 : 0
+ #endif
  
  /*
  	Define STACK_DIRECTION if you know the direction of stack
***************
*** 93,99 ****
--- 99,109 ----
        find_stack_direction ();	/* recurse once */
      }
    else				/* second entry */
+ #ifdef CRAY
+     if (getbytes (&dummy) > getbytes (addr))
+ #else  
      if (&dummy > addr)
+ #endif
        stack_dir = 1;		/* stack grew upward */
      else
        stack_dir = -1;		/* stack grew downward */
***************
*** 140,146 ****
--- 150,164 ----
       unsigned	size;		/* # bytes to allocate */
  {
    auto char	probe;		/* probes stack depth: */
+ #ifdef CRAY
+   register char *depth;
+ #else
    register char	*depth = &probe;
+ #endif
+ 
+ #ifdef CRAY
+   depth = (char *) call_depth;
+ #endif
  
  #if STACK_DIRECTION == 0
    if (STACK_DIR == 0)		/* unknown growth direction */
***************
*** 179,186 ****
      /* address of header */
  
      ((header *)new)->h.next = last_alloca_header;
      ((header *)new)->h.deep = depth;
! 
      last_alloca_header = (header *)new;
  
      /* User storage begins just after header. */
--- 197,207 ----
      /* address of header */
  
      ((header *)new)->h.next = last_alloca_header;
+ #ifdef CRAY
+     ((header *)new)->h.deep = (char *) call_depth;
+ #else
      ((header *)new)->h.deep = depth;
! #endif
      last_alloca_header = (header *)new;
  
      /* User storage begins just after header. */
*** alloc-files/i386-alloca.s	Mon Nov  7 09:35:20 1988
--- ../bash-1.03-CRAY/alloc-files/i386-alloca.s	Tue Sep 12 11:43:32 1989
***************
*** 1,16 ****
- 	.file "alloca.s"
- 	.text
- 	.align 4
- 	.def alloca; .val alloca; .scl 2; .type 044; .endef
- 	.globl alloca
- alloca:
- 	popl %edx
- 	popl %eax
- 	addl $3,%eax
- 	andl $0xfffffffc,%eax
- 	subl %eax,%esp
- 	movl %esp,%eax
- 	pushl %eax
- 	pushl %edx
- 	ret
- 	.def alloca; .val .; .scl -1; .endef
--- 0 ----
*** config.h	Sat Aug 26 14:00:05 1989
--- ../bash-1.03-CRAY/config.h	Mon Sep 11 17:47:05 1989
***************
*** 57,64 ****
  
  /* Define NO_WAIT_H if your system doesn't seem to have sys/wait.h.
     This is true for HPUX and ALTOS. */
! #if defined (HPUX) || defined (ALTOS)
  #define NO_WAIT_H
  #endif
  
  #endif  /* _CONFIG_ */
--- 57,69 ----
  
  /* Define NO_WAIT_H if your system doesn't seem to have sys/wait.h.
     This is true for HPUX and ALTOS. */
! #if defined (HPUX) || defined (ALTOS) || defined (CRAY)
  #define NO_WAIT_H
+ #ifdef CRAY
+ #define FILL_BITS 48
+ #else
+ #define FILL_BITS 16
+ #endif /* CRAY */
  #endif
  
  #endif  /* _CONFIG_ */
*** flags.c	Sat Aug 12 06:20:03 1989
--- ../bash-1.03-CRAY/flags.c	Mon Sep 11 17:43:33 1989
***************
*** 22,27 ****
--- 22,28 ----
  /* Flags hacking. */
  
  #include <stdio.h>		/* For `NULL'.  Can you believe this? */
+ #include "general.h"
  #include "quit.h"
  #include "flags.h"
  #include "config.h"
*** general.h	Thu Jun 29 12:43:24 1989
--- ../bash-1.03-CRAY/general.h	Mon Sep 11 17:01:21 1989
***************
*** 39,49 ****
  #endif
  
  /* The output of `signal' is different on different systems.  Yechh. */
! #if defined(SUNOS4) || defined (NeXT)
  #define sighandler void
  #else
  #define sighandler int
  #endif
  
  typedef sighandler SigHandler ();
  
--- 39,54 ----
  #endif
  
  /* The output of `signal' is different on different systems.  Yechh. */
! #if defined(SUNOS4) || defined (NeXT) || defined (CRAY)
  #define sighandler void
  #else
  #define sighandler int
  #endif
+ 
+ #ifdef CRAY
+ /* "word" is a type defined in <sys/types.h> on UNICOS. */
+ #define word bash_word
+ #endif CRAY
  
  typedef sighandler SigHandler ();
  
*** jobs.h	Sun Aug 20 21:29:49 1989
--- ../bash-1.03-CRAY/jobs.h	Mon Sep 11 17:48:29 1989
***************
*** 38,44 ****
      struct
        {
  	unsigned short
! 	  w_Fill1    : 16,	/* high 16 bits unused */
  	  w_Retcode  : 8,	/* exit code if w_termsig==0 */
  	  w_Coredump : 1,	/* core dump indicator */
  	  w_Termsig  : 7;	/* termination signal */
--- 38,44 ----
      struct
        {
  	unsigned short
! 	  w_Fill1    : FILL_BITS,	/* high FILL_BITS bits unused */
  	  w_Retcode  : 8,	/* exit code if w_termsig==0 */
  	  w_Coredump : 1,	/* core dump indicator */
  	  w_Termsig  : 7;	/* termination signal */
***************
*** 50,56 ****
      struct
        {
  	unsigned short
! 	  w_Fill2   : 16,	/* high 16 bits unused */
  	  w_Stopsig : 8,	/* signal that stopped us */
  	  w_Stopval : 8;	/* == W_STOPPED if stopped */
        } w_S;
--- 50,56 ----
      struct
        {
  	unsigned short
! 	  w_Fill2   : FILL_BITS,	/* high FILL_BITS bits unused */
  	  w_Stopsig : 8,	/* signal that stopped us */
  	  w_Stopval : 8;	/* == W_STOPPED if stopped */
        } w_S;
*** nojobs.c	Thu Aug 24 20:39:25 1989
--- ../bash-1.03-CRAY/nojobs.c	Tue Sep 12 11:41:07 1989
***************
*** 23,28 ****
--- 23,31 ----
  #include <signal.h>
  #include <setjmp.h>
  #include <errno.h>
+ #ifdef SYSV
+ #include <sys/termio.h>
+ #endif
  #include "config.h"
  #include "general.h"
  #include "jobs.h"
***************
*** 31,37 ****
  #define SIGABRT SIGIOT
  #endif
  
! #ifndef SYSV
  #include <sys/time.h>
  #include <sys/resource.h>
  /* The total amount of system time spent running processes for me. */
--- 34,42 ----
  #define SIGABRT SIGIOT
  #endif
  
! #ifdef SYSV
! #include <sys/fcntl.h>
! #else
  #include <sys/time.h>
  #include <sys/resource.h>
  /* The total amount of system time spent running processes for me. */
***************
*** 43,49 ****
  struct timeval total_usertime = {0, 0};
  long user_minutes_used = 0;
  int user_seconds_used = 0;
! #endif
  
  int last_made_pid;
  int last_asynchronous_pid;
--- 48,54 ----
  struct timeval total_usertime = {0, 0};
  long user_minutes_used = 0;
  int user_seconds_used = 0;
! #endif /* SYSV */
  
  int last_made_pid;
  int last_asynchronous_pid;
***************
*** 61,67 ****
  initialize_job_signals ()
  {
    extern int login_shell;
!   int throw_to_top_level ();
  
    signal (SIGINT, throw_to_top_level);
    signal (SIGQUIT, SIG_IGN);
--- 66,72 ----
  initialize_job_signals ()
  {
    extern int login_shell;
!   sighandler throw_to_top_level ();
  
    signal (SIGINT, throw_to_top_level);
    signal (SIGQUIT, SIG_IGN);
***************
*** 129,135 ****
         * In the parent.
         */
        last_made_pid = pid;
!       remember_pid (pid);
  
        if (async_p)
  	last_asynchronous_pid = pid;
--- 134,140 ----
         * In the parent.
         */
        last_made_pid = pid;
!       /* remember_pid (pid); */ /* What's this? */
  
        if (async_p)
  	last_asynchronous_pid = pid;
***************
*** 137,142 ****
--- 142,175 ----
    return (pid);
  }
  
+ wait_for_single_pid (pid)
+      int pid;
+ {
+   int got_pid, return_val;
+   union wait status;
+ 
+   while ((got_pid = wait (&status)) != pid)
+     {
+       if (got_pid < 0)
+ 	{
+ 	  if (errno != EINTR && errno != ECHILD)
+ 	    file_error ("wait");
+ 	  break;
+ 	}
+       QUIT;
+     }
+   QUIT;
+ }
+ 
+ wait_for_background_pids ()
+ {
+   while ((wait (0) >= 0))
+     /* empty body */;
+   if ((errno != ECHILD) && (errno != EINTR))
+     file_error ("wait");
+   QUIT;
+ }
+ 
  /*
   * Wait for pid (one of our children) to terminate.
   */
***************
*** 186,192 ****
--- 219,231 ----
  /* When we end a job abnormally, or if we stop a job, we set the tty to the
     state kept in here.  When a job ends normally, we set the state in here
     to the state of the tty. */
+ #ifdef SYSV
+ static struct termio shell_tty_info;
+ #define TIOCGETP TCGETA
+ #define TIOCSETN TCSETAW
+ #else
  static struct sgttyb shell_tty_info;
+ #endif
  
  /* Fill the contents of shell_tty_info with the current tty info. */
  get_tty_state ()
*** quit.h	Sat Aug 12 06:25:31 1989
--- ../bash-1.03-CRAY/quit.h	Mon Sep 11 16:59:16 1989
***************
*** 2,7 ****
--- 2,10 ----
  
  #ifndef __QUIT__
  #define __QUIT__
+ /* We need to declare throw_top_level */
+ extern sighandler throw_to_top_level ();
+ 
  /* Non-zero means SIGINT has already ocurred. */
  extern int interrupt_state;
  
*** readline/readline.c	Fri Sep  1 10:58:33 1989
--- ../bash-1.03-CRAY/readline/readline.c	Tue Sep 12 09:23:02 1989
***************
*** 35,40 ****
--- 35,41 ----
  #include <fcntl.h>
  #include <sys/file.h>
  #include <signal.h>
+ #include <errno.h>
  
  #ifdef __GNUC__
  #define alloca __builtin_alloca
***************
*** 59,67 ****
  #include <sys/stat.h>
  
  #include <pwd.h>
! #ifdef SYSV
  struct pwd *getpwuid (), *getpwent ();
  #endif
  
  #define HACK_TERMCAP_MOTION
  
--- 60,70 ----
  #include <sys/stat.h>
  
  #include <pwd.h>
! #if defined (SYSV) && !defined (CRAY)
  struct pwd *getpwuid (), *getpwent ();
  #endif
+ 
+ extern int errno;         /* Not always in <errno.h>.  Bogusness. */
  
  #define HACK_TERMCAP_MOTION
  
*** siglist.c	Wed Jul 26 08:02:05 1989
--- ../bash-1.03-CRAY/siglist.c	Tue Sep 12 11:38:54 1989
***************
*** 1,47 ****
  /* siglist.c -- signal list for those machines that don't have one. */
  
- /* Copyright (C) 1989 Free Software Foundation, Inc.
- 
- This file is part of GNU Bash, the Bourne Again SHell.
- 
- Bash is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 1, or (at your option) any later
- version.
- 
- Bash is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- for more details.
- 
- You should have received a copy of the GNU General Public License along
- with Bash; see the file COPYING.  If not, write to the Free Software
- Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
- 
  char *sys_siglist[] = {
!   "bogus signal",			/* 0 */
!   "hangup",				/* 1  SIGHUP */
!   "interrupt",				/* 2  SIGINT */
!   "quit",				/* 3  SIGQUIT */
!   "illegal instruction",		/* 4  SIGILL */
!   "trace trap",				/* 5  SIGTRAP */
!   "IOT instruction",			/* 6  SIGIOT */
!   "EMT instruction",			/* 7  SIGEMT */
!   "floating point exception",		/* 8  SIGFPE */
!   "kill",				/* 9  SIGKILL */
!   "bus error",				/* 10 SIGBUS */
!   "segmentation violation",		/* 11 SIGSEGV */
!   "bad argument to system call",	/* 12 SIGSYS */
!   "write on a pipe with no one to read it", /* 13 SIGPIPE */
!   "alarm clock",			/* 14 SIGALRM */
!   "software termination signum",	/* 15 SIGTERM */
!   "user defined signal 1",		/* 16 SIGUSR1 */
!   "user defined signal 2",		/* 17 SIGUSR2 */
!   "death of a child",			/* 18 SIGCLD */
!   "power-fail restart",			/* 19 SIGPWR */
!   "virtual timer alarm",		/* 20 SIGVTALRM */
!   "profiling timer alarm",		/* 21 SIGPROF */
!   "asynchronous I/O",			/* 22 SIGIO */
!   "window change or mouse signal",	/* 23 SIGWINDOW */
    (char *)0x0
  };
--- 1,39 ----
  /* siglist.c -- signal list for those machines that don't have one. */
+ /*	this version is specific to Cray Research UNICOS. */
  
  char *sys_siglist[] = {
!   "bogus signal",                       	/* 0 */
!   "hangup",					/* 1 SIGHUP */
!   "interrupt",					/* 2 SIGINT */
!   "quit",					/* 3 SIGQUIT */
!   "illegal instruction",			/* 4 SIGILL */
!   "trace trap",					/* 5 SIGTRAP */
!   "user abort",					/* 6 SIGABRT */
!   "error exit",					/* 7 SIGERR */
!   "floating point exception",			/* 8 SIGFPE */
!   "kill (no REG or IGN)",			/* 9 SIGKILL */
!   "program range error",			/* 10 SIGPRE */
!   "operand range error",			/* 11 SIGORE */
!   "bad argument to system call",		/* 12 SIGSYS */
!   "write on a pipe with no one to read it",	/* 13 SIGPIPE */
!   "alarm clock",				/* 14 SIGALRM */
!   "software termination signal from kill",	/* 15 SIGTERM */
!   "user defined signal 1",			/* 16 SIGUSR1 */
!   "user defined signal 2",			/* 17 SIGUSR2 */
!   "death of a child",				/* 18 SIGCLD */
!   "power failure",				/* 19 SIGPWR */
!   "multitasking wakeup signal",			/* 20 SIGMT */
!   "multitasking kill signal",			/* 21 SIGMTKILL */
!   "FORTRAN asynchronous I/O completion",	/* 22 SIGBUFIO */
!   "recovery signal (advisory)",			/* 23 SIGRECOVERY */
!   "uncorrectable memory err (CMDB, LMP, FPT)",	/* 24 SIGUME */
!   "reserved for Cray Research, Inc.",		/* 25 SIGCRAY7 */
!   "cpu limit exceeded",				/* 26 SIGCPULIM */
!   "system shutdown imminent (advisory)",	/* 27 SIGSHUTDN */
!   "SuperLink IPC library I/O completion.",	/* 28 SIGSL */
!   "reserved for Cray Research, Inc.",		/* 29 SIGCRAY3 */
!   "reserved for Cray Research, Inc.",		/* 30 SIGCRAY2 */
!   "reserved for Cray Research, Inc.",		/* 31 SIGCRAY1 */
!   "reserved for Cray Research, Inc.",		/* 32 SIGCRAY0 */
    (char *)0x0
  };