Mercurial > emacs
comparison src/unexec.c @ 485:8c615e453683
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Mon, 13 Jan 1992 21:48:08 +0000 |
parents | bd964fa17294 |
children | e2782df984a2 |
comparison
equal
deleted
inserted
replaced
484:3165b2697c78 | 485:8c615e453683 |
---|---|
72 /* There are several compilation parameters affecting unexec: | 72 /* There are several compilation parameters affecting unexec: |
73 | 73 |
74 * COFF | 74 * COFF |
75 | 75 |
76 Define this if your system uses COFF for executables. | 76 Define this if your system uses COFF for executables. |
77 | |
78 * COFF_ENCAPSULATE | |
79 | |
80 Define this if you are using the GNU coff encapsulated a.out format. | |
81 This is closer to a.out than COFF. You should *not* define COFF if | |
82 you define COFF_ENCAPSULATE | |
83 | |
77 Otherwise we assume you use Berkeley format. | 84 Otherwise we assume you use Berkeley format. |
78 | 85 |
79 * NO_REMAP | 86 * NO_REMAP |
80 | 87 |
81 Define this if you do not want to try to save Emacs's pure data areas | 88 Define this if you do not want to try to save Emacs's pure data areas |
163 | 170 |
164 #ifndef CANNOT_DUMP /* all rest of file! */ | 171 #ifndef CANNOT_DUMP /* all rest of file! */ |
165 | 172 |
166 #ifndef CANNOT_UNEXEC /* most of rest of file */ | 173 #ifndef CANNOT_UNEXEC /* most of rest of file */ |
167 | 174 |
175 #ifdef COFF_ENCAPSULATE | |
176 int need_coff_header = 1; | |
177 #include <coff-encap/a.out.encap.h> /* The location might be a poor assumption */ | |
178 #else | |
168 #include <a.out.h> | 179 #include <a.out.h> |
180 #endif | |
181 | |
169 /* Define getpagesize () if the system does not. | 182 /* Define getpagesize () if the system does not. |
170 Note that this may depend on symbols defined in a.out.h | 183 Note that this may depend on symbols defined in a.out.h |
171 */ | 184 */ |
172 #include "getpagesize.h" | 185 #include "getpagesize.h" |
173 | 186 |
174 #ifndef makedev /* Try to detect types.h already loaded */ | 187 #ifndef makedev /* Try to detect types.h already loaded */ |
175 #include <sys/types.h> | 188 #include <sys/types.h> |
176 #endif | 189 #endif /* makedev */ |
177 #include <stdio.h> | 190 #include <stdio.h> |
178 #include <sys/stat.h> | 191 #include <sys/stat.h> |
179 #include <errno.h> | 192 #include <errno.h> |
180 | 193 |
181 extern char *start_of_text (); /* Start of text */ | 194 extern char *start_of_text (); /* Start of text */ |
216 #define N_SYMOFF(x) LESYM_OFFSET(x) | 229 #define N_SYMOFF(x) LESYM_OFFSET(x) |
217 static EXEC_HDR_TYPE hdr, ohdr; | 230 static EXEC_HDR_TYPE hdr, ohdr; |
218 | 231 |
219 #else /* not HPUX */ | 232 #else /* not HPUX */ |
220 | 233 |
221 #if defined (USG) && !defined (IBMAIX) && !defined (IRIS) | 234 #if defined (USG) && !defined (IBMAIX) && !defined (IRIS) && !defined (COFF_ENCAPSULATE) |
222 static struct bhdr hdr, ohdr; | 235 static struct bhdr hdr, ohdr; |
223 #define a_magic fmagic | 236 #define a_magic fmagic |
224 #define a_text tsize | 237 #define a_text tsize |
225 #define a_data dsize | 238 #define a_data dsize |
226 #define a_bss bsize | 239 #define a_bss bsize |
238 #endif /* IRIS or IBMAIX not USG */ | 251 #endif /* IRIS or IBMAIX not USG */ |
239 #endif /* not HPUX */ | 252 #endif /* not HPUX */ |
240 | 253 |
241 static int unexec_text_start; | 254 static int unexec_text_start; |
242 static int unexec_data_start; | 255 static int unexec_data_start; |
256 | |
257 #ifdef COFF_ENCAPSULATE | |
258 /* coffheader is defined in the GNU a.out.encap.h file. */ | |
259 struct coffheader coffheader; | |
260 #endif | |
243 | 261 |
244 #endif /* not COFF */ | 262 #endif /* not COFF */ |
245 | 263 |
246 static int pagemask; | 264 static int pagemask; |
247 | 265 |
622 #else /* if not COFF */ | 640 #else /* if not COFF */ |
623 | 641 |
624 /* Get symbol table info from header of a.out file if given one. */ | 642 /* Get symbol table info from header of a.out file if given one. */ |
625 if (a_out >= 0) | 643 if (a_out >= 0) |
626 { | 644 { |
645 #ifdef COFF_ENCAPSULATE | |
646 if (read (a_out, &coffheader, sizeof coffheader) != sizeof coffheader) | |
647 { | |
648 PERROR(a_name); | |
649 } | |
650 if (coffheader.f_magic != COFF_MAGIC) | |
651 { | |
652 ERROR1("%s doesn't have legal coff magic number\n", a_name); | |
653 } | |
654 #endif | |
627 if (read (a_out, &ohdr, sizeof hdr) != sizeof hdr) | 655 if (read (a_out, &ohdr, sizeof hdr) != sizeof hdr) |
628 { | 656 { |
629 PERROR (a_name); | 657 PERROR (a_name); |
630 } | 658 } |
631 | 659 |
635 } | 663 } |
636 hdr = ohdr; | 664 hdr = ohdr; |
637 } | 665 } |
638 else | 666 else |
639 { | 667 { |
668 #ifdef COFF_ENCAPSULATE | |
669 /* We probably could without too much trouble. The code is in gld | |
670 * but I don't have that much time or incentive. | |
671 */ | |
672 ERROR0 ("can't build a COFF file from scratch yet"); | |
673 #else | |
640 bzero (hdr, sizeof hdr); | 674 bzero (hdr, sizeof hdr); |
675 #endif | |
641 } | 676 } |
642 | 677 |
643 unexec_text_start = (long) start_of_text (); | 678 unexec_text_start = (long) start_of_text (); |
644 unexec_data_start = data_start; | 679 unexec_data_start = data_start; |
645 | 680 |
663 #ifdef A_TEXT_OFFSET | 698 #ifdef A_TEXT_OFFSET |
664 hdr.a_text += A_TEXT_OFFSET (ohdr); | 699 hdr.a_text += A_TEXT_OFFSET (ohdr); |
665 #endif | 700 #endif |
666 | 701 |
667 #endif /* not NO_REMAP */ | 702 #endif /* not NO_REMAP */ |
703 | |
704 #ifdef COFF_ENCAPSULATE | |
705 /* We are encapsulating BSD format within COFF format. */ | |
706 { | |
707 struct coffscn *tp, *dp, *bp; | |
708 tp = &coffheader.scns[0]; | |
709 dp = &coffheader.scns[1]; | |
710 bp = &coffheader.scns[2]; | |
711 tp->s_size = hdr.a_text + sizeof(struct exec); | |
712 dp->s_paddr = data_start; | |
713 dp->s_vaddr = data_start; | |
714 dp->s_size = hdr.a_data; | |
715 bp->s_paddr = dp->s_vaddr + dp->s_size; | |
716 bp->s_vaddr = bp->s_paddr; | |
717 bp->s_size = hdr.a_bss; | |
718 coffheader.tsize = tp->s_size; | |
719 coffheader.dsize = dp->s_size; | |
720 coffheader.bsize = bp->s_size; | |
721 coffheader.text_start = tp->s_vaddr; | |
722 coffheader.data_start = dp->s_vaddr; | |
723 } | |
724 if (write (new, &coffheader, sizeof coffheader) != sizeof coffheader) | |
725 { | |
726 PERROR(new_name); | |
727 } | |
728 #endif /* COFF_ENCAPSULATE */ | |
668 | 729 |
669 if (write (new, &hdr, sizeof hdr) != sizeof hdr) | 730 if (write (new, &hdr, sizeof hdr) != sizeof hdr) |
670 { | 731 { |
671 PERROR (new_name); | 732 PERROR (new_name); |
672 } | 733 } |