]> code.delx.au - gnu-emacs/blobdiff - src/unexmips.c
(PURESIZE_RATIO): Reduce to 10/6.
[gnu-emacs] / src / unexmips.c
index 7f4d75de256ea85cfd30000c9b5c1381903dd1c5..86129e052cf84af975c450d4418c1b2c2e2c1f94 100644 (file)
@@ -6,13 +6,14 @@
    we don't plan to think about it, or about whether other Emacs
    maintenance might break it.
 
-   Copyright (C) 1988 Free Software Foundation, Inc.
+   Copyright (C) 1988, 1994, 2002, 2003, 2004,
+                 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs 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)
+the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -22,25 +23,69 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 \f
-#include "config.h"
+#include <config.h>
 #include <sys/types.h>
 #include <sys/file.h>
 #include <sys/stat.h>
 #include <stdio.h>
 #include <varargs.h>
+
+#ifdef MACH
+
+#include <a.out.h>
+
+/* I don't know why this isn't defined.  */
+#ifndef STYP_INIT
+#define STYP_INIT  0x80000000
+#endif
+
+/* I don't know why this isn't defined.  */
+#ifndef _RDATA
+#define        _RDATA  ".rdata"
+#define STYP_RDATA 0x00000100
+#endif
+
+/* Small ("near") data section.  */
+#ifndef _SDATA
+#define        _SDATA  ".sdata"
+#define STYP_SDATA 0x00000200
+#endif
+
+/* Small ("near") bss section.  */
+#ifndef _SBSS
+#define _SBSS ".sbss"
+#define STYP_SBSS 0x00000400
+#endif
+
+/* We don't seem to have a sym.h or syms.h anywhere, so we'll do it the
+   hard way.  This stinks.  */
+typedef struct {
+  short   magic;
+  short   vstamp;
+  long    ilineMax;
+  struct { long foo, offset; } offsets[11];
+} HDRR, *pHDRR;
+
+#else /* not MACH */
+
 #include <filehdr.h>
 #include <aouthdr.h>
 #include <scnhdr.h>
 #include <sym.h>
 
-#ifdef IRIS_4D
+#endif /* not MACH */
+
+#if defined (IRIS_4D) || defined (sony)
 #include "getpagesize.h"
+#include <fcntl.h>
 #endif
 
 static void fatal_unexec ();
+static void mark_x ();
 
 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \
        errno = EEOF; \
@@ -57,8 +102,7 @@ static void fatal_unexec ();
          fatal_unexec (_error_message, _error_arg);
 
 extern int errno;
-extern int sys_nerr;
-extern char *sys_errlist[];
+extern char *strerror ();
 #define EEOF -1
 
 static struct scnhdr *text_section;
@@ -111,11 +155,11 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
       && hdr.fhdr.f_magic != (MIPSELMAGIC | 1)
       && hdr.fhdr.f_magic != (MIPSEBMAGIC | 1))
     {
-      fprintf(stderr,
-             "unexec: input file magic number is %x, not %x, %x, %x or %x.\n",
-             hdr.fhdr.f_magic,
-             MIPSELMAGIC, MIPSEBMAGIC,
-             MIPSELMAGIC | 1, MIPSEBMAGIC | 1);
+      fprintf (stderr,
+              "unexec: input file magic number is %x, not %x, %x, %x or %x.\n",
+              hdr.fhdr.f_magic,
+              MIPSELMAGIC, MIPSEBMAGIC,
+              MIPSELMAGIC | 1, MIPSEBMAGIC | 1);
       exit(1);
     }
 #else /* not MIPS2 */
@@ -141,18 +185,16 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
     }
 
 #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 (%x expected) in %s section.\n", \
-                hdr.section[i].s_flags, flags, name);                  \
-      ptr = hdr.section + i;                                           \
-      i += 1;                                                          \
-    }                                                                  \
-  else                                                                 \
-    ptr = NULL;
-
-  i = 0;
+  ptr = NULL;                                                          \
+  for (i = 0; i < hdr.fhdr.f_nscns && !ptr; i++)                       \
+    if (strcmp (hdr.section[i].s_name, name) == 0)                     \
+      {                                                                        \
+       if (hdr.section[i].s_flags != flags)                            \
+         fprintf (stderr, "unexec: %x flags (%x expected) in %s section.\n", \
+                  hdr.section[i].s_flags, flags, name);                \
+       ptr = hdr.section + i;                                          \
+      }                                                                        \
+
   CHECK_SCNHDR (text_section,  _TEXT,  STYP_TEXT);
   CHECK_SCNHDR (init_section,  _INIT,  STYP_INIT);
   CHECK_SCNHDR (rdata_section, _RDATA, STYP_RDATA);
@@ -164,12 +206,18 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
   CHECK_SCNHDR (sdata_section, _SDATA, STYP_SDATA);
   CHECK_SCNHDR (sbss_section,  _SBSS,  STYP_SBSS);
   CHECK_SCNHDR (bss_section,   _BSS,   STYP_BSS);
+#if 0 /* Apparently this error check goes off on irix 3.3,
+        but it doesn't indicate a real problem.  */
   if (i != hdr.fhdr.f_nscns)
     fprintf (stderr, "unexec: %d sections found instead of %d.\n",
             i, hdr.fhdr.f_nscns);
+#endif
+
+  text_section->s_scnptr = 0;
 
   pagesize = getpagesize ();
-  brk = (sbrk (0) + pagesize - 1) & (-pagesize);
+  /* Casting to int avoids compiler error on NEWS-OS 5.0.2.  */
+  brk = (((int) (sbrk (0))) + pagesize - 1) & (-pagesize);
   hdr.aout.dsize = brk - DATA_START;
   hdr.aout.bsize = 0;
   if (entry_address == 0)
@@ -182,6 +230,12 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
 
   hdr.aout.bss_start = hdr.aout.data_start + hdr.aout.dsize;
   rdata_section->s_size = data_start - DATA_START;
+
+  /* Adjust start and virtual addresses of rdata_section, too.  */
+  rdata_section->s_vaddr = DATA_START;
+  rdata_section->s_paddr = DATA_START;
+  rdata_section->s_scnptr = text_section->s_scnptr + hdr.aout.tsize;
+
   data_section->s_vaddr = data_start;
   data_section->s_paddr = data_start;
   data_section->s_size = brk - data_start;
@@ -224,19 +278,23 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
       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,
+  WRITE (new, (char *)TEXT_START, hdr.aout.tsize,
         "writing text section to %s", new_name);
+  WRITE (new, (char *)DATA_START, hdr.aout.dsize,
+        "writing data 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;
+#define symhdr ((pHDRR)buffer)
+#ifdef MACH
+  for (i = 0; i < 11; i++)
+    symhdr->offsets[i].offset += symrel;
+#else
   symhdr->cbLineOffset += symrel;
   symhdr->cbDnOffset += symrel;
   symhdr->cbPdOffset += symrel;
@@ -248,6 +306,7 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
   symhdr->cbFdOffset += symrel;
   symhdr->cbRfdOffset += symrel;
   symhdr->cbExtOffset += symrel;
+#endif
 #undef symhdr
   do
     {
@@ -270,10 +329,10 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
 /*
  * mark_x
  *
- * After succesfully building the new a.out, mark it executable
+ * After successfully building the new a.out, mark it executable
  */
 
-static
+static void
 mark_x (name)
      char *name;
 {
@@ -289,17 +348,18 @@ mark_x (name)
 
 static void
 fatal_unexec (s, va_alist)
-     va_dcl
+    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);
+    fprintf (stderr, "unexec: %s, ", strerror (errno));
   va_start (ap);
   _doprnt (s, ap, stderr);
   fputs (".\n", stderr);
   exit (1);
 }
+
+/* arch-tag: ebdd2058-3bbc-4de4-b5c7-5760379ab153
+   (do not change this comment) */