[gnu.emacs] Getting 18.52 up and running on an IRIS-4d under OS version 3.0

barry@confusion.ads.com (Barry Lustig) (10/25/88)

It seems that Silicon Graphics made some changes between 3.0 and
previous versions of the OS.  /usr/lib/crt0.o is now /usr/lib/crt1.o,
the symbol "start" is now "__start" (actually, back to normal).  But,
there must be other problems, because when I try and do the unexec I
get: 

	unexec: 7 sections instead of 6.
	unexec: .init section where .rdata expected.

Is there anyone from Silicon Graphics, or any place else for that
matter, who has worked on this?

Barry Lustig
Advanced Decision Systems

raible@EW09.NAS.NASA.GOV (Eric L. Raible) (10/26/88)

   Date: 25 Oct 88 00:03:58 GMT
   From: daitc!ida.org!potomac!zodiac!confusion!barry@uunet.uu.net  (Barry Lustig)
   Organization: Advanced Decision Systems, Mt. View, CA (415) 960-7300

   It seems that Silicon Graphics made some changes between 3.0 and
   previous versions of the OS.  /usr/lib/crt0.o is now /usr/lib/crt1.o,
   the symbol "start" is now "__start" (actually, back to normal).  But,
   there must be other problems, because when I try and do the unexec I
   get: 

	   unexec: 7 sections instead of 6.
	   unexec: .init section where .rdata expected.

   Is there anyone from Silicon Graphics, or any place else for that
   matter, who has worked on this?

   Barry Lustig
   Advanced Decision Systems


The solution to this involves a change to m-iris4d.h, an addition to
s-iris3-6.h, and a new unexmips.c from Earl Killian
(mips!wright.mips.com!earl).

All of these changes should work in pre-3.0 systems (rms?).

(Sorry that these changes are not in diff format, but I don't have the
originals handy.)

etc/loadst still doesn't work on the 4d's.  Jon Hahn
(hahn@orville.nas.nasa.gov)  has the relevant code.

------------------ Changes for m-iris4d.h -----------------

/* Define STACK_DIRECTION for alloca.c */

#define STACK_DIRECTION -1

/* Define this is you have the files /usr/lib/crt{1,n}.o */

#define HAVE_CRTN

#ifdef HAVE_CRTN
# define START_FILES /usr/lib/crt1.o
# define LIB_STANDARD -lc /usr/lib/crtn.o
#else
# define START_FILES /usr/lib/crt0.o
# define DEFAULT_ENTRY_ADDRESS start
#endif


/* The standard definitions of these macros would work ok,
   but these are faster because the constants are short.  */

------------------ Addition for s-iris3-6.h -----------------

#define sigsetmask(mask)	/* Null expansion */
#define sigblock(x) x  <==== NEW

/* The IRIS defines SIGIO in signal.h, but doesn't implement it. */
#undef SIGIO

------------------ New unexmips.c -----------------

/* Unexec for MIPS (including IRIS4D).
   Note that the GNU project considers support for MIPS operation
   a peripheral activity which should not be allowed to divert effort
   from development of the GNU system.  Changes in this code will be
   installed when users send them in, but aside from that
   we don't plan to think about it, or about whether other Emacs
   maintenance might break it.

   Copyright (C) 1988 Free Software Foundation, Inc.

		       NO WARRANTY

  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
CORRECTION.

 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.

		GENERAL PUBLIC LICENSE TO COPY

  1. You may copy and distribute verbatim copies of this source file
as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy a valid copyright notice "Copyright
(C) 1987 Free Software Foundation, Inc."; and include following the
copyright notice a verbatim copy of the above disclaimer of warranty
and of this License.  You may charge a distribution fee for the
physical act of transferring a copy.

  2. You may modify your copy or copies of this source file or
any portion of it, and copy and distribute such modifications under
the terms of Paragraph 1 above, provided that you also do the following:

    a) cause the modified files to carry prominent notices stating
    that you changed the files and the date of any change; and

    b) cause the whole of any work that you distribute or publish,
    that in whole or in part contains or is a derivative of this
    program or any part thereof, to be licensed at no charge to all
    third parties on terms identical to those contained in this
    License Agreement (except that you may choose to grant more extensive
    warranty protection to some or all third parties, at your option).

    c) You may charge a distribution fee for the physical act of
    transferring a copy, and you may at your option offer warranty
    protection in exchange for a fee.

Mere aggregation of another unrelated program with this program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other program under the scope of these terms.

  3. You may copy and distribute this program (or a portion or derivative
of it, under Paragraph 2) in object code or executable form under the terms
of Paragraphs 1 and 2 above provided that you also do one of the following:

    a) accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of
    Paragraphs 1 and 2 above; or,

    b) accompany it with a written offer, valid for at least three
    years, to give any third party free (except for a nominal
    shipping charge) a complete machine-readable copy of the
    corresponding source code, to be distributed under the terms of
    Paragraphs 1 and 2 above; or,

    c) accompany it with the information you received as to where the
    corresponding source code may be obtained.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form alone.)

For an executable file, complete source code means all the source code for
all modules it contains; but, as a special exception, it need not include
source code for modules which are standard libraries that accompany the
operating system on which the executable file runs.

  4. You may not copy, sublicense, distribute or transfer this program
except as expressly provided under this License Agreement.  Any attempt
otherwise to copy, sublicense, distribute or transfer this program is void and
your rights to use the program under this License agreement shall be
automatically terminated.  However, parties who have received computer
software programs from you with this License Agreement will not have
their licenses terminated so long as such parties remain in full compliance.

  5. If you wish to incorporate parts of this program into other free
programs whose distribution conditions are different, write to the Free
Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
worked out a simple rule that can be stated here, but we will often permit
this.  We will be guided by the two goals of preserving the free status of
all derivatives of our free software and of promoting the sharing and reuse of
software.


In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them.   Help stamp out software-hoarding!  */


#include "config.h"
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <stdio.h>
#include <varargs.h>
#include <filehdr.h>
#include <aouthdr.h>
#include <scnhdr.h>
#include <sym.h>

#ifdef IRIS_4D
#include "getpagesize.h"
#endif

extern int errno;
extern int sys_nerr;
extern char *sys_errlist[];
#define EEOF -1

static void
fatal_unexec(s, va_alist)
    va_dcl
{
    va_list ap;
    if (errno == EEOF) {
	fputs("unexec: unexpected end of file, ", stderr);
    }
    else if (errno < sys_nerr) {
	fprintf(stderr, "unexec: %s, ", sys_errlist[errno]);
    }
    else {
	fprintf(stderr, "unexec: error code %d, ", errno);
    }
    va_start(ap);
    _doprnt(s, ap, stderr);
    fputs(".\n", stderr);
    exit(1);
}

#define READ(_fd, _buffer, _size, _error_message, _error_arg) \
	errno = EEOF; \
	if (read(_fd, _buffer, _size) != _size) \
	  fatal_unexec(_error_message, _error_arg);

#define WRITE(_fd, _buffer, _size, _error_message, _error_arg) \
	if (write(_fd, _buffer, _size) != _size) \
	  fatal_unexec(_error_message, _error_arg);

#define SEEK(_fd, _position, _error_message, _error_arg) \
	errno = EEOF; \
	if (lseek(_fd, _position, L_SET) != _position) \
	  fatal_unexec(_error_message, _error_arg);

/* Define name of label for entry point for the dumped executable.  */

#ifndef DEFAULT_ENTRY_ADDRESS
#define DEFAULT_ENTRY_ADDRESS __start
#endif

static struct scnhdr *text_section;
static struct scnhdr *init_section;
static struct scnhdr *finit_section;
static struct scnhdr *rdata_section;
static struct scnhdr *data_section;
static struct scnhdr *lit8_section;
static struct scnhdr *lit4_section;
static struct scnhdr *sdata_section;
static struct scnhdr *sbss_section;
static struct scnhdr *bss_section;

struct headers {
    struct filehdr fhdr;
    struct aouthdr aout;
    struct scnhdr section[10];
};

unexec (new_name, a_name, data_start, bss_start, entry_address)
     char *new_name, *a_name;
     unsigned data_start, bss_start, entry_address;
{
  int new, old;
  int pagesize, brk;
  int newsyms, symrel;
  int nread;
  struct headers hdr;
  int i;
  int vaddr, scnptr;
#define BUFSIZE 8192
  char buffer[BUFSIZE];

  old = open (a_name, O_RDONLY, 0);
  if (old < 0) fatal_unexec("opening %s", a_name);

  new = creat (new_name, 0666);
  if (new < 0) fatal_unexec("creating %s", new_name);

  hdr = *((struct headers *)TEXT_START);
  if (hdr.fhdr.f_magic != MIPSELMAGIC
      && hdr.fhdr.f_magic != MIPSEBMAGIC) {
      fprintf(stderr, "unexec: input file magic number is %x, not %x or %x.\n",
	      hdr.fhdr.f_magic, MIPSELMAGIC, MIPSEBMAGIC);
      exit(1);
  }
  if (hdr.fhdr.f_opthdr != sizeof(hdr.aout)) {
      fprintf(stderr, "unexec: input a.out header is %d bytes, not %d.\n",
	      hdr.fhdr.f_opthdr, sizeof(hdr.aout));
      exit(1);
  }
#if 0
  if (hdr.aout.magic != ZMAGIC
      && hdr.aout.magic != NMAGIC
      && hdr.aout.magic != OMAGIC) {
      fprintf(stderr, "unexec: input file a.out magic number is %o, not %o, %o, or %o.\n",
	      hdr.aout.magic, ZMAGIC, NMAGIC, OMAGIC);
      exit(1);
  }
#else
  if (hdr.aout.magic != ZMAGIC) {
      fprintf(stderr, "unexec: input file a.out magic number is %o, not %o.\n",
	      hdr.aout.magic, ZMAGIC);
      exit(1);
  }
#endif

#define CHECK_SCNHDR(ptr, name, flags) \
  if (strcmp(hdr.section[i].s_name, name) == 0) { \
    if (hdr.section[i].s_flags != flags) { \
      fprintf(stderr, "unexec: %x flags where %x expected in %s section.\n", \
	      hdr.section[i].s_flags, flags, name); \
    } \
    ptr = hdr.section + i; \
    i += 1; \
  } \
  else { \
    ptr = NULL; \
  }

  i = 0;
  CHECK_SCNHDR(text_section,  _TEXT,  STYP_TEXT);
  CHECK_SCNHDR(init_section,  _INIT,  STYP_INIT);
  CHECK_SCNHDR(rdata_section, _RDATA, STYP_RDATA);
  CHECK_SCNHDR(data_section,  _DATA,  STYP_DATA);
#ifdef _LIT8
  CHECK_SCNHDR(lit8_section,  _LIT8,  STYP_LIT8);
  CHECK_SCNHDR(lit4_section,  _LIT4,  STYP_LIT4);
#endif
  CHECK_SCNHDR(sdata_section, _SDATA, STYP_SDATA);
  CHECK_SCNHDR(sbss_section,  _SBSS,  STYP_SBSS);
  CHECK_SCNHDR(bss_section,   _BSS,   STYP_BSS);
  if (i != hdr.fhdr.f_nscns) {
      fprintf(stderr, "unexec: %d sections found instead of %d.\n",
	      i, hdr.fhdr.f_nscns);
  }

  pagesize = getpagesize();
  brk = (sbrk(0) + pagesize - 1) & (-pagesize);
  hdr.aout.dsize = brk - DATA_START;
  hdr.aout.bsize = 0;
  if (entry_address == 0) {
    extern DEFAULT_ENTRY_ADDRESS();
    hdr.aout.entry = (unsigned)DEFAULT_ENTRY_ADDRESS;
  }
  else {
    hdr.aout.entry = entry_address;
  }
  hdr.aout.bss_start = hdr.aout.data_start + hdr.aout.dsize;
  rdata_section->s_size = data_start - DATA_START;
  data_section->s_vaddr = data_start;
  data_section->s_paddr = data_start;
  data_section->s_size = brk - DATA_START;
  data_section->s_scnptr = rdata_section->s_scnptr
				+ rdata_section->s_size;
  vaddr = data_section->s_vaddr + data_section->s_size;
  scnptr = data_section->s_scnptr + data_section->s_size;
  if (lit8_section != NULL) {
    lit8_section->s_vaddr = vaddr;
    lit8_section->s_paddr = vaddr;
    lit8_section->s_size = 0;
    lit8_section->s_scnptr = scnptr;
  }
  if (lit4_section != NULL) {
    lit4_section->s_vaddr = vaddr;
    lit4_section->s_paddr = vaddr;
    lit4_section->s_size = 0;
    lit4_section->s_scnptr = scnptr;
  }
  if (sdata_section != NULL) {
    sdata_section->s_vaddr = vaddr;
    sdata_section->s_paddr = vaddr;
    sdata_section->s_size = 0;
    sdata_section->s_scnptr = scnptr;
  }
  if (sbss_section != NULL) {
    sbss_section->s_vaddr = vaddr;
    sbss_section->s_paddr = vaddr;
    sbss_section->s_size = 0;
    sbss_section->s_scnptr = scnptr;
  }
  if (bss_section != NULL) {
    bss_section->s_vaddr = vaddr;
    bss_section->s_paddr = vaddr;
    bss_section->s_size = 0;
    bss_section->s_scnptr = scnptr;
  }

  WRITE(new, TEXT_START, hdr.aout.tsize,
	"writing text section to %s", new_name);
  WRITE(new, DATA_START, hdr.aout.dsize,
	"writing text section to %s", new_name);

  SEEK(old, hdr.fhdr.f_symptr, "seeking to start of symbols in %s", a_name);
  errno = EEOF;
  nread = read(old, buffer, BUFSIZE);
  if (nread < sizeof(HDRR)) fatal_unexec("reading symbols from %s", a_name);
#define symhdr ((pHDRR)buffer)
  newsyms = hdr.aout.tsize + hdr.aout.dsize;
  symrel = newsyms - hdr.fhdr.f_symptr;
  hdr.fhdr.f_symptr = newsyms;
  symhdr->cbLineOffset += symrel;
  symhdr->cbDnOffset += symrel;
  symhdr->cbPdOffset += symrel;
  symhdr->cbSymOffset += symrel;
  symhdr->cbOptOffset += symrel;
  symhdr->cbAuxOffset += symrel;
  symhdr->cbSsOffset += symrel;
  symhdr->cbSsExtOffset += symrel;
  symhdr->cbFdOffset += symrel;
  symhdr->cbRfdOffset += symrel;
  symhdr->cbExtOffset += symrel;
#undef symhdr
  do {
      if (write(new, buffer, nread) != nread)
	fatal_unexec("writing symbols to %s", new_name);
      nread = read(old, buffer, BUFSIZE);
      if (nread < 0) fatal_unexec("reading symbols from %s", a_name);
#undef BUFSIZE
  } while (nread != 0);

  SEEK(new, 0, "seeking to start of header in %s", new_name);
  WRITE(new, &hdr, sizeof(hdr),
	"writing header of %s", new_name);

  close(old);
  close(new);
  mark_x(new_name);
}

/*
 * mark_x
 *
 * After succesfully building the new a.out, mark it executable
 */
static
mark_x (name)
     char *name;
{
  struct stat sbuf;
  int um = umask (777);
  umask (um);
  if (stat(name, &sbuf) < 0)
    fatal_unexec("getting protection on %s", name);
  sbuf.st_mode |= 0111 & ~um;
  if (chmod(name, sbuf.st_mode) < 0)
    fatal_unexec("setting protection on %s", name);
}

earl@wright (Earl Killian) (10/27/88)

Here are the changes to the 18.52 distribution necessary for getting
gnu emacs up on a MIPS system V.  SGI's Unix is similar, but not
identical.  The unexmips.c here will work fine.  You may find the rest
of the code useful too; I don't really know.

### Cut Here ###
echo x - README-mips
sed 's/^X//' >README-mips <<'*-*-END-of-README-mips-*-*'
XHere are 3 diff files (feed to patch), 2 include files and a spec.
XRISC/os 3.0 has select() but cannot select on pipes (and certain character
Xdevices -- like /dev/tty when you're really on a pty). Rather than throw
Xout subprocesses I've patched emacs to use AF_INET sockets to talk to
Xchild processes (so now you can use M-X compile, shell and emacsclient).
XUnforunately I borrowed source from BSD to do some of the work.
XSo you must implement the following function which I call "getunresport()"
XIt should take one argument of type pointer to int and return an int.
XThe arg will be a suggested port # to which a AF_INET SOCK_STREAM
Xsocket bound to INADDR_ANY should be returned or -1 if error occurs. 
XAny port number between IPPORT_RESERVED and IPPORT_USERRESERVED will do so
Xlong as the argument is updated to reflect the bound port number.
X
X Len Lattanzi (len@Synthesis.com){wyse,ames,pyramid,decwrl}!mips!synthesis!len
X Synthesis Software Solutions, Inc.				1 408 991 0367
X 292 Commercial Avenue, Sunnyvale, California 94086
*-*-END-of-README-mips-*-*
echo x - config.diff
sed 's/^X//' >config.diff <<'*-*-END-of-config.diff-*-*'
X*** config.h	Thu Oct 20 00:44:32 1988
X--- config.h-dist	Wed Oct  5 00:26:02 1988
X***************
X*** 24,30 ****
X     See the file ../etc/MACHINES for a list of systems and
X     the names of the s- files to use for them.
X     See s-template.h for documentation on writing s- files.  */
X! #include "s-riscos3-0.h"
X  
X  /* Include here a m- file that describes the machine and system you use.
X     See the file ../etc/MACHINES for a list of machines and
X--- 24,30 ----
X     See the file ../etc/MACHINES for a list of systems and
X     the names of the s- files to use for them.
X     See s-template.h for documentation on writing s- files.  */
X! #include "s-bsd4-2.h"
X  
X  /* Include here a m- file that describes the machine and system you use.
X     See the file ../etc/MACHINES for a list of machines and
X***************
X*** 31,37 ****
X     the names of the m- files to use for them.
X     See m-template.h for info on what m- files should define.
X     */
X! #include "m-mips.h"
X  
X  /* Load in the conversion definitions if this system
X     needs them and the source file being compiled has not
X--- 31,37 ----
X     the names of the m- files to use for them.
X     See m-template.h for info on what m- files should define.
X     */
X! #include "m-vax.h"
X  
X  /* Load in the conversion definitions if this system
X     needs them and the source file being compiled has not
X***************
X*** 101,107 ****
X  
X  #ifndef PURESIZE
X  #ifdef HAVE_X_WINDOWS
X! #define PURESIZE 160000
X  #else
X  #define PURESIZE 118000
X  #endif
X--- 101,107 ----
X  
X  #ifndef PURESIZE
X  #ifdef HAVE_X_WINDOWS
X! #define PURESIZE 122000
X  #else
X  #define PURESIZE 118000
X  #endif
*-*-END-of-config.diff-*-*
echo x - emacsclient.diff
sed 's/^X//' >emacsclient.diff <<'*-*-END-of-emacsclient.diff-*-*'
X*** /tmp/,RCSt1a16735	Wed Oct 19 22:54:51 1988
X--- emacsclient.c	Wed Oct 19 22:53:32 1988
X***************
X*** 193,201 ****
X  	      fprintf (stderr, cwd);
X  	      *cwd = '\0';
X  	    }
X  	}
X  	
X-       strcat (msgp->mtext, cwd);
X        strcat (msgp->mtext, argv[0]);
X        strcat (msgp->mtext, " ");
X        argv++; argc--;
X--- 193,201 ----
X  	      fprintf (stderr, cwd);
X  	      *cwd = '\0';
X  	    }
X+ 	  strcat (msgp->mtext, cwd);
X  	}
X  	
X        strcat (msgp->mtext, argv[0]);
X        strcat (msgp->mtext, " ");
X        argv++; argc--;
*-*-END-of-emacsclient.diff-*-*
echo x - m-mips.h
sed 's/^X//' >m-mips.h <<'*-*-END-of-m-mips.h-*-*'
X/* m- file for Mips machines.
X   Copyright (C) 1987 Free Software Foundation, Inc.
X
XThis file is part of GNU Emacs.
X
XGNU Emacs is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY.  No author or distributor
Xaccepts responsibility to anyone for the consequences of using it
Xor for whether it serves any particular purpose or works at all,
Xunless he says so in writing.  Refer to the GNU Emacs General Public
XLicense for full details.
X
XEveryone is granted permission to copy, modify and redistribute
XGNU Emacs, but only under the conditions described in the
XGNU Emacs General Public License.   A copy of this license is
Xsupposed to have been given to you along with GNU Emacs so you
Xcan know your rights and responsibilities.  It should be in a
Xfile named COPYING.  Among other things, the copyright notice
Xand this notice must be preserved on all copies.  */
X
X
X/* The following three symbols give information on
X the size of various data types.  */
X
X#define SHORTBITS 16		/* Number of bits in a short */
X
X#define INTBITS 32		/* Number of bits in an int */
X
X#define LONGBITS 32		/* Number of bits in a long */
X
X/* Define BIG_ENDIAN iff lowest-numbered byte in a word
X   is the most significant byte.  */
X
X#define BIG_ENDIAN
X
X/* Define NO_ARG_ARRAY if you cannot take the address of the first of a
X * group of arguments and treat it as an array of the arguments.  */
X
X#define NO_ARG_ARRAY
X
X/* Define WORD_MACHINE if addresses and such have
X * to be corrected before they can be used as byte counts.  */
X
X#undef WORD_MACHINE
X
X/* Define how to take a char and sign-extend into an int.
X   On machines where char is signed, this is a no-op.  */
X
X#define SIGN_EXTEND_CHAR(c) ((signed char)(c))
X
X/* Now define a symbol for the cpu type, if your compiler
X   does not define it automatically:
X   Ones defined so far include vax, m68000, ns16000, pyramid,
X   orion, tahoe, APOLLO and many others */
X#ifndef mips
X#	define mips
X#endif
X
X/* Use type int rather than a union, to represent Lisp_Object */
X/* This is desirable for most machines.  */
X
X#define NO_UNION_TYPE
X
X/* Define EXPLICIT_SIGN_EXTEND if XINT must explicitly sign-extend
X   the 24-bit bit field into an int.  In other words, if bit fields
X   are always unsigned.
X
X   If you use NO_UNION_TYPE, this flag does not matter.  */
X
X#define EXPLICIT_SIGN_EXTEND
X
X/* Data type of load average, as read out of kmem.  */
X
X#define LOAD_AVE_TYPE long
X
X/* Convert that into an integer that is 100 for a load average of 1.0  */
X
X#define LOAD_AVE_CVT(x) (int) (((double) (x)) * 100.0 / 256.0)
X
X/* Define CANNOT_DUMP on machines where unexec does not work.
X   Then the function dump-emacs will not be defined
X   and temacs will do (load "loadup") automatically unless told otherwise.  */
X
X#undef CANNOT_DUMP
X
X/* Define VIRT_ADDR_VARIES if the virtual addresses of
X   pure and impure space as loaded can vary, and even their
X   relative order cannot be relied on.
X
X   Otherwise Emacs assumes that text space precedes data space,
X   numerically.  */
X
X/* #define VIRT_ADDR_VARIES */
X
X/* Define C_ALLOCA if this machine does not support a true alloca
X   and the one written in C should be used instead.
X   Define HAVE_ALLOCA to say that the system provides a properly
X   working alloca function and it should be used.
X   Define neither one if an assembler-language alloca
X   in the file alloca.s should be used.  */
X
X#define C_ALLOCA
X/* #define HAVE_ALLOCA */
X
X/* Define NO_REMAP if memory segmentation makes it not work well
X   to change the boundary between the text section and data section
X   when Emacs is dumped.  If you define this, the preloaded Lisp
X   code will not be sharable; but that's better than failing completely.  */
X
X#define NO_REMAP
X
X/* This machine requires completely different unexec code
X   which lives in a separate file.  Specify the file name.  */
X
X#define UNEXEC unexmips.o
X
X/* Describe layout of the address space in an executing process.  */
X
X#define TEXT_START 0x400000
X#define DATA_START 0x800000
X
X/* Alter some of the options used when linking.  */
X
X#define LIBS_MACHINE -lmld
X#define LD_SWITCH_MACHINE -D 800000 -g3
X#define COFF
X#define LIBS_DEBUG
X
X/* The standard definitions of these macros would work ok,
X   but these are faster because the constants are short.  */
X
X#define XUINT(a) (((unsigned)(a) << INTBITS-VALBITS) >> INTBITS-VALBITS)
X
X#define XSET(var, type, ptr) \
X   ((var) = ((int)(type) << VALBITS) + (((unsigned) (ptr) << INTBITS-VALBITS) >> INTBITS-VALBITS))
X
X#define XSETINT(a, b)  XSET(a, XTYPE(a), b)
X#define XSETUINT(a, b) XSET(a, XTYPE(a), b)
X#define XSETPNTR(a, b) XSET(a, XTYPE(a), b)
X
X#define XUNMARK(a) ((a) = (((unsigned)(a) << INTBITS-GCTYPEBITS-VALBITS) >> INTBITS-GCTYPEBITS-VALBITS))
*-*-END-of-m-mips.h-*-*
echo x - process.diff
sed 's/^X//' >process.diff <<'*-*-END-of-process.diff-*-*'
X*** /tmp/,RCSt1a18452	Thu Oct 20 00:53:55 1988
X--- process.c	Thu Oct 20 00:48:38 1988
X***************
X*** 38,44 ****
X  #include <netdb.h>
X  #include <netinet/in.h>
X  #endif /* HAVE_SOCKETS */
X! 
X  #if defined(BSD) || defined(STRIDE)
X  #include <sys/ioctl.h>
X  #endif /* BSD or STRIDE */
X--- 38,46 ----
X  #include <netdb.h>
X  #include <netinet/in.h>
X  #endif /* HAVE_SOCKETS */
X! #if !defined(SKTPAIR) && defined(CANT_SELECT_ON_PIPES)
X! static int pipe_port;
X! #endif
X  #if defined(BSD) || defined(STRIDE)
X  #include <sys/ioctl.h>
X  #endif /* BSD or STRIDE */
X***************
X*** 926,931 ****
X--- 928,934 ----
X        forkout = forkin = sv[1];
X      }
X  #else /* not SKTPAIR */
X+ #ifndef CANT_SELECT_ON_PIPES
X      {
X        pipe (sv);
X        inchannel = sv[0];
X***************
X*** 934,939 ****
X--- 937,953 ----
X        outchannel = sv[1];
X        forkin = sv[0];
X      }
X+ #else /* CANT_SELECT_ON_PIPES */
X+   {
X+     pipe_port = getpid() % (IPPORT_USERRESERVED-IPPORT_RESERVED) +
X+       IPPORT_RESERVED + 1;
X+     if (-1 == (outchannel = getunresport(&pipe_port)))
X+       error("getunresport():%s", sys_errlist[errno]);
X+     if (-1 == listen(outchannel, 1))
X+       error("listen():%s", sys_errlist[errno]);
X+     inchannel = outchannel;
X+   }
X+ #endif	/* CANT_SELECT_ON_PIPES */
X  #endif /* not SKTPAIR */
X  
X  #if 0
X***************
X*** 1012,1017 ****
X--- 1026,1054 ----
X  	      abort ();
X  #endif /* not UNIPLUS and not RTU */
X  	  }
X+ #if !defined(SKTPAIR) && defined(CANT_SELECT_ON_PIPES)
X+ 	else
X+ 	{
X+ 	  struct hostent *hp;
X+ 	  struct sockaddr_in sin;
X+ 	  int child_socket;
X+ 	  if (-1 == (child_socket = socket(AF_INET, SOCK_STREAM, 0))) {
X+ 	    error("socket():%s", sys_errlist[errno]);
X+ 	  }
X+ 	  if ((hp = gethostbyname("localhost")) == 0) {
X+ 	    error("Cannot get host address('localhost')");
X+ 	  }
X+ 	  bzero((char *)&sin, sizeof(sin));
X+ 	  bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
X+ 	  sin.sin_family = hp->h_addrtype;
X+ 	  sin.sin_port = htons(pipe_port);
X+ 	  if (-1 == connect(child_socket, &sin, sizeof(sin))) {
X+ 	    error("connect():%s", sys_errlist[errno]);
X+ 	  }
X+ 	  xforkin = xforkout = child_socket;
X+ 	}
X+ #endif /* !SKTPAIR && CANT_SELECT_ON_PIPES */
X+ 
X  #endif /* TIOCNOTTY */
X  #endif /* HAVE_PTYS */
X  	child_setup_tty (xforkout);
*-*-END-of-process.diff-*-*
echo x - s-riscos3-0.h
sed 's/^X//' >s-riscos3-0.h <<'*-*-END-of-s-riscos3-0.h-*-*'
X/* Definitions file for GNU Emacs running on AT&T's System V Release 3
X   Copyright (C) 1987 Free Software Foundation, Inc.
X
XThis file is part of GNU Emacs.
X
XGNU Emacs is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY.  No author or distributor
Xaccepts responsibility to anyone for the consequences of using it
Xor for whether it serves any particular purpose or works at all,
Xunless he says so in writing.  Refer to the GNU Emacs General Public
XLicense for full details.
X
XEveryone is granted permission to copy, modify and redistribute
XGNU Emacs, but only under the conditions described in the
XGNU Emacs General Public License.   A copy of this license is
Xsupposed to have been given to you along with GNU Emacs so you
Xcan know your rights and responsibilities.  It should be in a
Xfile named COPYING.  Among other things, the copyright notice
Xand this notice must be preserved on all copies.  */
X
X
X/*
X *	Define symbols to identify the version of Unix this is.
X *	Define all the symbols that apply correctly.
X */
X
X#define USG				/* System III, System V, etc */
X
X#define USG5
X#define HAVE_SYSVIPC
X
X/* SYSTEM_TYPE should indicate the kind of system you are using.
X It sets the Lisp variable system-type.  */
X
X#define SYSTEM_TYPE "RISC/os"
X
X/* nomultiplejobs should be defined if your system's shell
X does not have "job control" (the ability to stop a program,
X run some other program, then continue the first one).  */
X
X#define NOMULTIPLEJOBS
X
X/* Default is to set interrupt_input to 0: don't do input buffering within Emacs */
X
X/* #define INTERRUPT_INPUT */
X
X/* Letter to use in finding device name of first pty,
X  if system supports pty's.  'p' means it is /dev/ptyp0  */
X
X#define FIRST_PTY_LETTER 'p'
X
X/*
X *	Define HAVE_TERMIO if the system provides sysV-style ioctls
X *	for terminal control.
X */
X
X#define HAVE_TERMIO
X
X/*
X *	Define HAVE_TIMEVAL if the system supports the BSD style clock values.
X *	Look in <sys/time.h> for a timeval structure.
X */
X
X#define HAVE_TIMEVAL
X#if defined(emacs)
X#include <bsd/sys/time.h>
X#endif
X/*
X *	Define HAVE_SELECT if the system supports the `select' system call.
X */
X
X#define HAVE_SELECT
X#define CANT_SELECT_ON_PIPES
X#define HAVE_DUP2
X#define HAVE_GETWD
X#define HAVE_GETTIMEOFDAY
X/*
X *	Define HAVE_PTYS if the system supports pty devices.
X */
X
X#define HAVE_PTYS
X
X/* Define HAVE_SOCKETS if system supports 4.2-compatible sockets.  */
X
X#define HAVE_SOCKETS
X
X/*
X *	Define NONSYSTEM_DIR_LIBRARY to make Emacs emulate
X *      The 4.2 opendir, etc., library functions.
X */
X
X/* #define NONSYSTEM_DIR_LIBRARY */
X
X/*
X * 	Define SYSV_SYSTEM_DIR to use the V.3 getdents/readir
X *	library functions.  Almost, but not quite the same as
X *	the 4.2 functions
X */
X/*#define SYSV_SYSTEM_DIR*/
X
X/* Define this symbol if your system has the functions bcopy, etc. */
X
X#define BSTRING
X
X/* subprocesses should be defined if you want to
X have code for asynchronous subprocesses
X (as used in M-x compile and M-x shell).
X This is supposed to work now on system V release 2.  */
X
X#define subprocesses
X#define IRIS
X/* If your system uses COFF (Common Object File Format) then define the
X   preprocessor symbol "COFF". */
X
X/*#define COFF*/
X
X/* define MAIL_USE_FLOCK if the mailer uses flock
X   to interlock access to /usr/spool/mail/$USER.
X   The alternative is that a lock file named
X   /usr/spool/mail/$USER.lock.  */
X
X/* #define MAIL_USE_FLOCK */
X
X/* Define CLASH_DETECTION if you want lock files to be written
X   so that Emacs can tell instantly when you try to modify
X   a file that someone else has modified in his Emacs.  */
X
X/* #define CLASH_DETECTION */
X
X/* Define SHORTNAMES if the C compiler can distinguish only
X   short names.  It means that the stuff in ../shortnames
X   must be run to convert the long names to short ones.  */
X
X/* #define SHORTNAMES */
X
X/* We use the Berkeley (and usg5.2.2) interface to nlist.  */
X
X#define NLIST_STRUCT
X
X/* The file containing the kernel's symbol table is called /unix.  */
X
X#define KERNEL_FILE "/unix"
X
X/* The symbol in the kernel where the load average is found
X   is named avenrun.  */
X
X#define LDAV_SYMBOL "avenrun"
X
X/* Special hacks needed to make Emacs run on this system.  */
X
X/*
X *	Make the sigsetmask function go away.  Other data.c will use it.
X */
X
X#define sigsetmask(mask)	/* Null expansion */
X
X/* setjmp and longjmp can safely replace _setjmp and _longjmp,
X   but they will run slower.  */
X
X#define _setjmp setjmp
X#define _longjmp longjmp
X
X/* On USG systems the system calls are interruptable by signals
X that the user program has elected to catch.  Thus the system call
X must be retried in these cases.  To handle this without massive
X changes in the source code, we remap the standard system call names
X to names for our own functions in sysdep.c that do the system call
X with retries. */
X
X#define read sys_read
X#define write sys_write
X#define open sys_open
X#define close sys_close
X
X#define INTERRUPTABLE_OPEN
X#define INTERRUPTABLE_CLOSE
X#define INTERRUPTABLE_IO
X
X/* On USG systems these have different names */
X
X#define index strchr
X#define rindex strrchr
X
X/* USG systems tend to put everything declared static
X   into the initialized data area, which becomes pure after dumping Emacs.
X   Foil this.  Emacs carefully avoids static vars inside functions.  */
X
X/* #define static */
X
X/* Compiler bug bites on many systems when default ADDR_CORRECT is used.  */
X
X#define ADDR_CORRECT(x) (x)
X
X/* Use terminfo instead of termcap.  */
X
X#define TERMINFO
X
X#define BROKEN_FIONREAD
X#undef SIGIO
X#define HAVE_X_WINDOWS
X#define X11
X/* Different START_FILES */
X#define START_FILES pre-crt0.o /usr/lib/crt1.o
X#define C_SWITCH_SYSTEM -I/usr/include/bsd
X#define C_DEBUG_SWITCH -O -g3
X#define LIB_STANDARD -lc /usr/lib/crtn.o
X#if defined(HAVE_X_WINDOWS) && defined(X11)
X#define HAVE_VFORK		/* Graciously provided by libX.a */
X#define LIBS_TERMCAP
X#define LIBX11_SYSTEM -lbsd -lcurses
X#else
X#define LIBS_TERMCAP -lbsd -lcurses
X#endif
X#define OBJECTS_SYSTEM getunresport.o
*-*-END-of-s-riscos3-0.h-*-*
echo x - unexmips.c
sed 's/^X//' >unexmips.c <<'*-*-END-of-unexmips.c-*-*'
X/* Unexec for MIPS (including IRIS4D).
X   Note that the GNU project considers support for MIPS operation
X   a peripheral activity which should not be allowed to divert effort
X   from development of the GNU system.  Changes in this code will be
X   installed when users send them in, but aside from that
X   we don't plan to think about it, or about whether other Emacs
X   maintenance might break it.
X
X   Copyright (C) 1988 Free Software Foundation, Inc.
X
X		       NO WARRANTY
X
X  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
XCORRECTION.
X
X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
X
X		GENERAL PUBLIC LICENSE TO COPY
X
X  1. You may copy and distribute verbatim copies of this source file
Xas you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy a valid copyright notice "Copyright
X(C) 1987 Free Software Foundation, Inc."; and include following the
Xcopyright notice a verbatim copy of the above disclaimer of warranty
Xand of this License.  You may charge a distribution fee for the
Xphysical act of transferring a copy.
X
X  2. You may modify your copy or copies of this source file or
Xany portion of it, and copy and distribute such modifications under
Xthe terms of Paragraph 1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating
X    that you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish,
X    that in whole or in part contains or is a derivative of this
X    program or any part thereof, to be licensed at no charge to all
X    third parties on terms identical to those contained in this
X    License Agreement (except that you may choose to grant more extensive
X    warranty protection to some or all third parties, at your option).
X
X    c) You may charge a distribution fee for the physical act of
X    transferring a copy, and you may at your option offer warranty
X    protection in exchange for a fee.
X
XMere aggregation of another unrelated program with this program (or its
Xderivative) on a volume of a storage or distribution medium does not bring
Xthe other program under the scope of these terms.
X
X  3. You may copy and distribute this program (or a portion or derivative
Xof it, under Paragraph 2) in object code or executable form under the terms
Xof Paragraphs 1 and 2 above provided that you also do one of the following:
X
X    a) accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    b) accompany it with a written offer, valid for at least three
X    years, to give any third party free (except for a nominal
X    shipping charge) a complete machine-readable copy of the
X    corresponding source code, to be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    c) accompany it with the information you received as to where the
X    corresponding source code may be obtained.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form alone.)
X
XFor an executable file, complete source code means all the source code for
Xall modules it contains; but, as a special exception, it need not include
Xsource code for modules which are standard libraries that accompany the
Xoperating system on which the executable file runs.
X
X  4. You may not copy, sublicense, distribute or transfer this program
Xexcept as expressly provided under this License Agreement.  Any attempt
Xotherwise to copy, sublicense, distribute or transfer this program is void and
Xyour rights to use the program under this License agreement shall be
Xautomatically terminated.  However, parties who have received computer
Xsoftware programs from you with this License Agreement will not have
Xtheir licenses terminated so long as such parties remain in full compliance.
X
X  5. If you wish to incorporate parts of this program into other free
Xprograms whose distribution conditions are different, write to the Free
XSoftware Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
Xworked out a simple rule that can be stated here, but we will often permit
Xthis.  We will be guided by the two goals of preserving the free status of
Xall derivatives of our free software and of promoting the sharing and reuse of
Xsoftware.
X
X
XIn other words, you are welcome to use, share and improve this program.
XYou are forbidden to forbid anyone else to use, share and improve
Xwhat you give them.   Help stamp out software-hoarding!  */
X
X
X#include "config.h"
X#include <sys/types.h>
X#include <sys/file.h>
X#include <sys/stat.h>
X#include <stdio.h>
X#include <varargs.h>
X#include <filehdr.h>
X#include <aouthdr.h>
X#include <scnhdr.h>
X#include <sym.h>
X
Xextern int errno;
Xextern int sys_nerr;
Xextern char *sys_errlist[];
X#define EEOF -1
X
Xstatic void
Xfatal_unexec(s, va_alist)
X    va_dcl
X{
X    va_list ap;
X    if (errno == EEOF) {
X	fputs("unexec: unexpected end of file, ", stderr);
X    }
X    else if (errno < sys_nerr) {
X	fprintf(stderr, "unexec: %s, ", sys_errlist[errno]);
X    }
X    else {
X	fprintf(stderr, "unexec: error code %d, ", errno);
X    }
X    va_start(ap);
X    _doprnt(s, ap, stderr);
X    fputs(".\n", stderr);
X    exit(1);
X}
X
X#define READ(_fd, _buffer, _size, _error_message, _error_arg) \
X	errno = EEOF; \
X	if (read(_fd, _buffer, _size) != _size) \
X	  fatal_unexec(_error_message, _error_arg);
X
X#define WRITE(_fd, _buffer, _size, _error_message, _error_arg) \
X	if (write(_fd, _buffer, _size) != _size) \
X	  fatal_unexec(_error_message, _error_arg);
X
X#define SEEK(_fd, _position, _error_message, _error_arg) \
X	errno = EEOF; \
X	if (lseek(_fd, _position, L_SET) != _position) \
X	  fatal_unexec(_error_message, _error_arg);
X
X/* Define name of label for entry point for the dumped executable.  */
X
X#ifndef DEFAULT_ENTRY_ADDRESS
X#define DEFAULT_ENTRY_ADDRESS __start
X#endif
X
Xstatic struct scnhdr *text_section;
Xstatic struct scnhdr *init_section;
Xstatic struct scnhdr *finit_section;
Xstatic struct scnhdr *rdata_section;
Xstatic struct scnhdr *data_section;
Xstatic struct scnhdr *lit8_section;
Xstatic struct scnhdr *lit4_section;
Xstatic struct scnhdr *sdata_section;
Xstatic struct scnhdr *sbss_section;
Xstatic struct scnhdr *bss_section;
X
Xstruct headers {
X    struct filehdr fhdr;
X    struct aouthdr aout;
X    struct scnhdr section[10];
X};
X
Xunexec (new_name, a_name, data_start, bss_start, entry_address)
X     char *new_name, *a_name;
X     unsigned data_start, bss_start, entry_address;
X{
X  int new, old;
X  int pagesize, brk;
X  int newsyms, symrel;
X  int nread;
X  struct headers hdr;
X  int i;
X  int vaddr, scnptr;
X#define BUFSIZE 8192
X  char buffer[BUFSIZE];
X
X  old = open (a_name, O_RDONLY, 0);
X  if (old < 0) fatal_unexec("opening %s", a_name);
X
X  new = creat (new_name, 0666);
X  if (new < 0) fatal_unexec("creating %s", new_name);
X
X  hdr = *((struct headers *)TEXT_START);
X  if (hdr.fhdr.f_magic != MIPSELMAGIC
X      && hdr.fhdr.f_magic != MIPSEBMAGIC) {
X      fprintf(stderr, "unexec: input file magic number is %x, not %x or %x.\n",
X	      hdr.fhdr.f_magic, MIPSELMAGIC, MIPSEBMAGIC);
X      exit(1);
X  }
X  if (hdr.fhdr.f_opthdr != sizeof(hdr.aout)) {
X      fprintf(stderr, "unexec: input a.out header is %d bytes, not %d.\n",
X	      hdr.fhdr.f_opthdr, sizeof(hdr.aout));
X      exit(1);
X  }
X#if 0
X  if (hdr.aout.magic != ZMAGIC
X      && hdr.aout.magic != NMAGIC
X      && hdr.aout.magic != OMAGIC) {
X      fprintf(stderr, "unexec: input file a.out magic number is %o, not %o, %o, or %o.\n",
X	      hdr.aout.magic, ZMAGIC, NMAGIC, OMAGIC);
X      exit(1);
X  }
X#else
X  if (hdr.aout.magic != ZMAGIC) {
X      fprintf(stderr, "unexec: input file a.out magic number is %o, not %o.\n",
X	      hdr.aout.magic, ZMAGIC);
X      exit(1);
X  }
X#endif
X
X#define CHECK_SCNHDR(ptr, name, flags) \
X  if (strcmp(hdr.section[i].s_name, name) == 0) { \
X    if (hdr.section[i].s_flags != flags) { \
X      fprintf(stderr, "unexec: %x flags where %x expected in %s section.\n", \
X	      hdr.section[i].s_flags, flags, name); \
X    } \
X    ptr = hdr.section + i; \
X    i += 1; \
X  } \
X  else { \
X    ptr = NULL; \
X  }
X
X  i = 0;
X  CHECK_SCNHDR(text_section,  _TEXT,  STYP_TEXT);
X  CHECK_SCNHDR(init_section,  _INIT,  STYP_INIT);
X  CHECK_SCNHDR(rdata_section, _RDATA, STYP_RDATA);
X  CHECK_SCNHDR(data_section,  _DATA,  STYP_DATA);
X  CHECK_SCNHDR(lit8_section,  _LIT8,  STYP_LIT8);
X  CHECK_SCNHDR(lit4_section,  _LIT4,  STYP_LIT4);
X  CHECK_SCNHDR(sdata_section, _SDATA, STYP_SDATA);
X  CHECK_SCNHDR(sbss_section,  _SBSS,  STYP_SBSS);
X  CHECK_SCNHDR(bss_section,   _BSS,   STYP_BSS);
X  if (i != hdr.fhdr.f_nscns) {
X      fprintf(stderr, "unexec: %d sections found instead of %d.\n",
X	      i, hdr.fhdr.f_nscns);
X  }
X
X  pagesize = getpagesize();
X  brk = (sbrk(0) + pagesize - 1) & (-pagesize);
X  hdr.aout.dsize = brk - DATA_START;
X  hdr.aout.bsize = 0;
X  if (entry_address == 0) {
X    extern DEFAULT_ENTRY_ADDRESS();
X    hdr.aout.entry = (unsigned)DEFAULT_ENTRY_ADDRESS;
X  }
X  else {
X    hdr.aout.entry = entry_address;
X  }
X  hdr.aout.bss_start = hdr.aout.data_start + hdr.aout.dsize;
X  rdata_section->s_size = data_start - DATA_START;
X  data_section->s_vaddr = data_start;
X  data_section->s_paddr = data_start;
X  data_section->s_size = brk - DATA_START;
X  data_section->s_scnptr = rdata_section->s_scnptr
X				+ rdata_section->s_size;
X  vaddr = data_section->s_vaddr + data_section->s_size;
X  scnptr = data_section->s_scnptr + data_section->s_size;
X  if (lit8_section != NULL) {
X    lit8_section->s_vaddr = vaddr;
X    lit8_section->s_paddr = vaddr;
X    lit8_section->s_size = 0;
X    lit8_section->s_scnptr = scnptr;
X  }
X  if (lit4_section != NULL) {
X    lit4_section->s_vaddr = vaddr;
X    lit4_section->s_paddr = vaddr;
X    lit4_section->s_size = 0;
X    lit4_section->s_scnptr = scnptr;
X  }
X  if (sdata_section != NULL) {
X    sdata_section->s_vaddr = vaddr;
X    sdata_section->s_paddr = vaddr;
X    sdata_section->s_size = 0;
X    sdata_section->s_scnptr = scnptr;
X  }
X  if (sbss_section != NULL) {
X    sbss_section->s_vaddr = vaddr;
X    sbss_section->s_paddr = vaddr;
X    sbss_section->s_size = 0;
X    sbss_section->s_scnptr = scnptr;
X  }
X  if (bss_section != NULL) {
X    bss_section->s_vaddr = vaddr;
X    bss_section->s_paddr = vaddr;
X    bss_section->s_size = 0;
X    bss_section->s_scnptr = scnptr;
X  }
X
X  WRITE(new, TEXT_START, hdr.aout.tsize,
X	"writing text section to %s", new_name);
X  WRITE(new, DATA_START, hdr.aout.dsize,
X	"writing text section to %s", new_name);
X
X  SEEK(old, hdr.fhdr.f_symptr, "seeking to start of symbols in %s", a_name);
X  errno = EEOF;
X  nread = read(old, buffer, BUFSIZE);
X  if (nread < sizeof(HDRR)) fatal_unexec("reading symbols from %s", a_name);
X#define symhdr ((pHDRR)buffer)
X  newsyms = hdr.aout.tsize + hdr.aout.dsize;
X  symrel = newsyms - hdr.fhdr.f_symptr;
X  hdr.fhdr.f_symptr = newsyms;
X  symhdr->cbLineOffset += symrel;
X  symhdr->cbDnOffset += symrel;
X  symhdr->cbPdOffset += symrel;
X  symhdr->cbSymOffset += symrel;
X  symhdr->cbOptOffset += symrel;
X  symhdr->cbAuxOffset += symrel;
X  symhdr->cbSsOffset += symrel;
X  symhdr->cbSsExtOffset += symrel;
X  symhdr->cbFdOffset += symrel;
X  symhdr->cbRfdOffset += symrel;
X  symhdr->cbExtOffset += symrel;
X#undef symhdr
X  do {
X      if (write(new, buffer, nread) != nread)
X	fatal_unexec("writing symbols to %s", new_name);
X      nread = read(old, buffer, BUFSIZE);
X      if (nread < 0) fatal_unexec("reading symbols from %s", a_name);
X#undef BUFSIZE
X  } while (nread != 0);
X
X  SEEK(new, 0, "seeking to start of header in %s", new_name);
X  WRITE(new, &hdr, sizeof(hdr),
X	"writing header of %s", new_name);
X
X  close(old);
X  close(new);
X  mark_x(new_name);
X}
X
X/*
X * mark_x
X *
X * After succesfully building the new a.out, mark it executable
X */
Xstatic
Xmark_x (name)
X     char *name;
X{
X  struct stat sbuf;
X  int um = umask (777);
X  umask (um);
X  if (stat(name, &sbuf) < 0)
X    fatal_unexec("getting protection on %s", name);
X  sbuf.st_mode |= 0111 & ~um;
X  if (chmod(name, sbuf.st_mode) < 0)
X    fatal_unexec("setting protection on %s", name);
X}
*-*-END-of-unexmips.c-*-*
exit
--