(TAGS): Fix typo.
[bpt/emacs.git] / src / unexmips.c
index 8dffa69..cad42a1 100644 (file)
@@ -22,7 +22,8 @@ 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., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 \f
 #include <config.h>
@@ -31,11 +32,52 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #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>
 
+#endif /* not MACH */
+
 #if defined (IRIS_4D) || defined (sony)
 #include "getpagesize.h"
 #include <fcntl.h>
@@ -173,7 +215,8 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
   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)
@@ -234,19 +277,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;
@@ -258,6 +305,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
     {