annotate src/unexmips.c @ 3767:6b2ef948e140

[xemacs-hg @ 2006-12-29 18:09:38 by aidan] etc/ChangeLog addition: 2006-12-21 Aidan Kehoe <kehoea@parhasard.net> * unicode/unicode-consortium/8859-7.TXT: Update the mapping to the 2003 version of ISO 8859-7. lisp/ChangeLog addition: 2006-12-21 Aidan Kehoe <kehoea@parhasard.net> * mule/cyrillic.el: * mule/cyrillic.el (iso-8859-5): * mule/cyrillic.el (cyrillic-koi8-r-encode-table): Add syntax, case support for Cyrillic; make some parentheses more Lispy. * mule/european.el: Content moved to latin.el, file deleted. * mule/general-late.el: If Unicode tables are to be loaded at dump time, do it here, not in loadup.el. * mule/greek.el: Add syntax, case support for Greek. * mule/latin.el: Move the content of european.el here. Change the case table mappings to use hexadecimal codes, to make cross reference to the standards easier. In all cases, take character syntax from similar characters in Latin-1 , rather than deciding separately what syntax they should take. Add (incomplete) support for case with Turkish. Remove description of the character sets used from the language environments' doc strings, since now that we create variant language environments on the fly, such descriptions will often be inaccurate. Set the native-coding-system language info property while setting the other coding-system properties of the language. * mule/misc-lang.el (ipa): Remove the language environment. The International Phonetic _Alphabet_ is not a language, it's inane to have a corresponding language environment in XEmacs. * mule/mule-cmds.el (create-variant-language-environment): Also modify the coding-priority when creating a new language environment; document that. * mule/mule-cmds.el (get-language-environment-from-locale): Recognise that the 'native-coding-system language-info property can be a list, interpret it correctly when it is one. 2006-12-21 Aidan Kehoe <kehoea@parhasard.net> * coding.el (coding-system-category): Use the new 'unicode-type property for finding what sort of Unicode coding system subtype a coding system is, instead of the overshadowed 'type property. * dumped-lisp.el (preloaded-file-list): mule/european.el has been removed. * loadup.el (really-early-error-handler): Unicode tables loaded at dump time are now in mule/general-late.el. * simple.el (count-lines): Add some backslashes to to parentheses in docstrings to help fontification along. * simple.el (what-cursor-position): Wrap a line to fit in 80 characters. * unicode.el: Use the 'unicode-type property, not 'type, for setting the Unicode coding-system subtype. src/ChangeLog addition: 2006-12-21 Aidan Kehoe <kehoea@parhasard.net> * file-coding.c: Update the make-coding-system docstring to reflect unicode-type * general-slots.h: New symbol, unicode-type, since 'type was being overridden when accessing a coding system's Unicode subtype. * intl-win32.c: Backslash a few parentheses, to help fontification along. * intl-win32.c (complex_vars_of_intl_win32): Use the 'unicode-type symbol, not 'type, when creating the Microsoft Unicode coding system. * unicode.c (unicode_putprop): * unicode.c (unicode_getprop): * unicode.c (unicode_print): Using 'type as the property name when working out what Unicode subtype a given coding system is was broken, since there's a general coding system property called 'type. Change the former to use 'unicode-type instead.
author aidan
date Fri, 29 Dec 2006 18:09:51 +0000
parents facf3239ba30
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Unexec for MIPS (including IRIS4D).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1988, 1992, 1993, 1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: FSF 19.31. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include <sys/file.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include <stdio.h>
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 0
diff changeset
29 #include <errno.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include <varargs.h>
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 398
diff changeset
31 #include "compiler.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #ifdef MACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include <a.out.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 /* I don't know why this isn't defined. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #ifndef STYP_INIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #define STYP_INIT 0x80000000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 /* I don't know why this isn't defined. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #ifndef _RDATA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #define _RDATA ".rdata"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #define STYP_RDATA 0x00000100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 /* Small ("near") data section. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #ifndef _SDATA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #define _SDATA ".sdata"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #define STYP_SDATA 0x00000200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 /* Small ("near") bss section. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #ifndef _SBSS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #define _SBSS ".sbss"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #define STYP_SBSS 0x00000400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 /* We don't seem to have a sym.h or syms.h anywhere, so we'll do it the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 hard way. This stinks. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 typedef struct {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 short magic;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 short vstamp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 long ilineMax;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 struct { long foo, offset; } offsets[11];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 } HDRR, *pHDRR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 #else /* not MACH */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 #include <filehdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #include <aouthdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 #include <scnhdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 #include <sym.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 #endif /* not MACH */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #if defined (IRIS_4D) || defined (sony)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 #include "getpagesize.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 #include <fcntl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 static void fatal_unexec ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 static void mark_x ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 errno = EEOF; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 if (read (_fd, _buffer, _size) != _size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 fatal_unexec (_error_message, _error_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 #define WRITE(_fd, _buffer, _size, _error_message, _error_arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 if (write (_fd, _buffer, _size) != _size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 fatal_unexec (_error_message, _error_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 #define SEEK(_fd, _position, _error_message, _error_arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 errno = EEOF; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 if (lseek (_fd, _position, L_SET) != _position) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 fatal_unexec (_error_message, _error_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 extern char *strerror ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 #define EEOF -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 static struct scnhdr *text_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 static struct scnhdr *init_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 static struct scnhdr *finit_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 static struct scnhdr *rdata_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 static struct scnhdr *data_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 static struct scnhdr *lit8_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 static struct scnhdr *lit4_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 static struct scnhdr *sdata_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 static struct scnhdr *sbss_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 static struct scnhdr *bss_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 struct headers {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 struct filehdr fhdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 struct aouthdr aout;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 struct scnhdr section[10];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 /* Define name of label for entry point for the dumped executable. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 #ifndef DEFAULT_ENTRY_ADDRESS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 #define DEFAULT_ENTRY_ADDRESS __start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 unexec (new_name, a_name, data_start, bss_start, entry_address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 char *new_name, *a_name;
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 398
diff changeset
128 unsigned data_start;
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 398
diff changeset
129 unsigned UNUSED (bss_start);
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 398
diff changeset
130 unsigned entry_address;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 {
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2286
diff changeset
132 int new_, old;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 int pagesize, brk;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 int newsyms, symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 int nread;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 struct headers hdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 int vaddr, scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 #define BUFSIZE 8192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 char buffer[BUFSIZE];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 old = open (a_name, O_RDONLY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 if (old < 0) fatal_unexec ("opening %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2286
diff changeset
145 new_ = creat (new_name, 0666);
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2286
diff changeset
146 if (new_ < 0) fatal_unexec ("creating %s", new_name);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 hdr = *((struct headers *)TEXT_START);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 #ifdef MIPS2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 if (hdr.fhdr.f_magic != MIPSELMAGIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 && hdr.fhdr.f_magic != MIPSEBMAGIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 && hdr.fhdr.f_magic != (MIPSELMAGIC | 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 && hdr.fhdr.f_magic != (MIPSEBMAGIC | 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 fprintf (stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "unexec: input file magic number is %x, not %x, %x, %x or %x.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 hdr.fhdr.f_magic,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 MIPSELMAGIC, MIPSEBMAGIC,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 MIPSELMAGIC | 1, MIPSEBMAGIC | 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 #else /* not MIPS2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 if (hdr.fhdr.f_magic != MIPSELMAGIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 && hdr.fhdr.f_magic != MIPSEBMAGIC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 fprintf (stderr, "unexec: input file magic number is %x, not %x or %x.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 hdr.fhdr.f_magic, MIPSELMAGIC, MIPSEBMAGIC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 #endif /* not MIPS2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 if (hdr.fhdr.f_opthdr != sizeof (hdr.aout))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 fprintf (stderr, "unexec: input a.out header is %d bytes, not %d.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 hdr.fhdr.f_opthdr, sizeof (hdr.aout));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 if (hdr.aout.magic != ZMAGIC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 fprintf (stderr, "unexec: input file a.out magic number is %o, not %o.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 hdr.aout.magic, ZMAGIC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 #define CHECK_SCNHDR(ptr, name, flags) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ptr = NULL; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 for (i = 0; i < hdr.fhdr.f_nscns && !ptr; i++) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 if (strcmp (hdr.section[i].s_name, name) == 0) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 if (hdr.section[i].s_flags != flags) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 fprintf (stderr, "unexec: %x flags (%x expected) in %s section.\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 hdr.section[i].s_flags, flags, name); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ptr = hdr.section + i; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 CHECK_SCNHDR (text_section, _TEXT, STYP_TEXT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 CHECK_SCNHDR (init_section, _INIT, STYP_INIT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 CHECK_SCNHDR (rdata_section, _RDATA, STYP_RDATA);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 CHECK_SCNHDR (data_section, _DATA, STYP_DATA);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 #ifdef _LIT8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 CHECK_SCNHDR (lit8_section, _LIT8, STYP_LIT8);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 CHECK_SCNHDR (lit4_section, _LIT4, STYP_LIT4);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 #endif /* _LIT8 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 CHECK_SCNHDR (sdata_section, _SDATA, STYP_SDATA);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 CHECK_SCNHDR (sbss_section, _SBSS, STYP_SBSS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 CHECK_SCNHDR (bss_section, _BSS, STYP_BSS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 #if 0 /* Apparently this error check goes off on irix 3.3,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 but it doesn't indicate a real problem. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 if (i != hdr.fhdr.f_nscns)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 fprintf (stderr, "unexec: %d sections found instead of %d.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 i, hdr.fhdr.f_nscns);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 text_section->s_scnptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 pagesize = getpagesize ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 /* Casting to int avoids compiler error on NEWS-OS 5.0.2. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 brk = (((int) (sbrk (0))) + pagesize - 1) & (-pagesize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 hdr.aout.dsize = brk - DATA_START;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 hdr.aout.bsize = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 if (entry_address == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 extern DEFAULT_ENTRY_ADDRESS ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 hdr.aout.entry = (unsigned)DEFAULT_ENTRY_ADDRESS;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 hdr.aout.entry = entry_address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 hdr.aout.bss_start = hdr.aout.data_start + hdr.aout.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 rdata_section->s_size = data_start - DATA_START;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 /* Adjust start and virtual addresses of rdata_section, too. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 rdata_section->s_vaddr = DATA_START;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 rdata_section->s_paddr = DATA_START;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 rdata_section->s_scnptr = text_section->s_scnptr + hdr.aout.tsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 data_section->s_vaddr = data_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 data_section->s_paddr = data_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 data_section->s_size = brk - data_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 data_section->s_scnptr = rdata_section->s_scnptr + rdata_section->s_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 vaddr = data_section->s_vaddr + data_section->s_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 scnptr = data_section->s_scnptr + data_section->s_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 if (lit8_section != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 lit8_section->s_vaddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 lit8_section->s_paddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 lit8_section->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 lit8_section->s_scnptr = scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 if (lit4_section != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 lit4_section->s_vaddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 lit4_section->s_paddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 lit4_section->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 lit4_section->s_scnptr = scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 if (sdata_section != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 sdata_section->s_vaddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 sdata_section->s_paddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 sdata_section->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 sdata_section->s_scnptr = scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 if (sbss_section != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 sbss_section->s_vaddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 sbss_section->s_paddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 sbss_section->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 sbss_section->s_scnptr = scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 if (bss_section != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 bss_section->s_vaddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 bss_section->s_paddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 bss_section->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 bss_section->s_scnptr = scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2286
diff changeset
278 WRITE (new_, (void *) TEXT_START, hdr.aout.tsize,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 "writing text section to %s", new_name);
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2286
diff changeset
280 WRITE (new_, (void *) DATA_START, hdr.aout.dsize,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 "writing data section to %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 SEEK (old, hdr.fhdr.f_symptr, "seeking to start of symbols in %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 errno = EEOF;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 nread = read (old, buffer, BUFSIZE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 if (nread < sizeof (HDRR)) fatal_unexec ("reading symbols from %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 newsyms = hdr.aout.tsize + hdr.aout.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 symrel = newsyms - hdr.fhdr.f_symptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 hdr.fhdr.f_symptr = newsyms;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 #define symhdr ((pHDRR)buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 #ifdef MACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 for (i = 0; i < 11; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 symhdr->offsets[i].offset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 symhdr->cbLineOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 symhdr->cbDnOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 symhdr->cbPdOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 symhdr->cbSymOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 symhdr->cbOptOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 symhdr->cbAuxOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 symhdr->cbSsOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 symhdr->cbSsExtOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 symhdr->cbFdOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 symhdr->cbRfdOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 symhdr->cbExtOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 #undef symhdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 {
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2286
diff changeset
310 if (write (new_, buffer, nread) != nread)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 fatal_unexec ("writing symbols to %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 nread = read (old, buffer, BUFSIZE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 if (nread < 0) fatal_unexec ("reading symbols from %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 #undef BUFSIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 } while (nread != 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2286
diff changeset
317 SEEK (new_, 0, "seeking to start of header in %s", new_name);
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2286
diff changeset
318 WRITE (new_, &hdr, sizeof (hdr),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 "writing header of %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 close (old);
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 2286
diff changeset
322 close (new_);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 mark_x (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 * mark_x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 * After successfully building the new a.out, mark it executable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 mark_x (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 char *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 struct stat sbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 int um = umask (777);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 umask (um);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 if (stat (name, &sbuf) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 fatal_unexec ("getting protection on %s", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 sbuf.st_mode |= 0111 & ~um;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 if (chmod (name, sbuf.st_mode) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 fatal_unexec ("setting protection on %s", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 fatal_unexec (s, va_alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 va_dcl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 va_list ap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 if (errno == EEOF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 fputs ("unexec: unexpected end of file, ", stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 fprintf (stderr, "unexec: %s, ", strerror (errno));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 va_start (ap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 _doprnt (s, ap, stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 fputs (".\n", stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 }