Mercurial > hg > xemacs-beta
comparison src/unexaix.c @ 219:262b8bb4a523 r20-4b8
Import from CVS: tag r20-4b8
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:09:35 +0200 |
parents | e45d5e7c476e |
children | c42ec1d1cded |
comparison
equal
deleted
inserted
replaced
218:c9f226976f56 | 219:262b8bb4a523 |
---|---|
183 #endif | 183 #endif |
184 #include <stdio.h> | 184 #include <stdio.h> |
185 #include <sys/stat.h> | 185 #include <sys/stat.h> |
186 #include <errno.h> | 186 #include <errno.h> |
187 | 187 |
188 extern char *start_of_text (); /* Start of text */ | 188 extern char *start_of_text (void); /* Start of text */ |
189 extern char *start_of_data (); /* Start of initialized data */ | 189 extern char *start_of_data (void); /* Start of initialized data */ |
190 | 190 |
191 extern int _data; | 191 extern int _data; |
192 extern int _edata; | 192 extern int _edata; |
193 extern int _text; | 193 extern int _text; |
194 extern int _etext; | 194 extern int _etext; |
218 #ifdef XCOFF | 218 #ifdef XCOFF |
219 #define ALIGN(val, pwr) (((val) + ((1L<<(pwr))-1)) & ~((1L<<(pwr))-1)) | 219 #define ALIGN(val, pwr) (((val) + ((1L<<(pwr))-1)) & ~((1L<<(pwr))-1)) |
220 static long load_scnptr; | 220 static long load_scnptr; |
221 static long orig_load_scnptr; | 221 static long orig_load_scnptr; |
222 static long orig_data_scnptr; | 222 static long orig_data_scnptr; |
223 static unrelocate_symbols (int, int, char *, char *); | |
223 #endif | 224 #endif |
224 static ulong data_st; /* start of data area written out */ | 225 static ulong data_st; /* start of data area written out */ |
225 | 226 |
226 #ifndef MAX_SECTIONS | 227 #ifndef MAX_SECTIONS |
227 #define MAX_SECTIONS 10 | 228 #define MAX_SECTIONS 10 |
228 #endif | 229 #endif |
229 | 230 |
231 static adjust_lnnoptrs (int, int, char *); | |
230 #endif /* COFF */ | 232 #endif /* COFF */ |
231 | 233 |
232 static int pagemask; | 234 static int pagemask; |
233 | 235 |
234 /* Correct an int which is the bit pattern of a pointer to a byte | 236 /* Correct an int which is the bit pattern of a pointer to a byte |
241 | 243 |
242 #ifdef emacs | 244 #ifdef emacs |
243 #include "lisp.h" | 245 #include "lisp.h" |
244 | 246 |
245 static | 247 static |
246 report_error (file, fd) | 248 report_error (char *file, int fd) |
247 char *file; | |
248 int fd; | |
249 { | 249 { |
250 if (fd) | 250 if (fd) |
251 close (fd); | 251 close (fd); |
252 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil)); | 252 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil)); |
253 } | 253 } |
256 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1 | 256 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1 |
257 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1 | 257 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1 |
258 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 | 258 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 |
259 | 259 |
260 static | 260 static |
261 report_error_1 (fd, msg, a1, a2) | 261 report_error_1 (int fd, char *msg, int a1, int a2) |
262 int fd; | |
263 char *msg; | |
264 int a1, a2; | |
265 { | 262 { |
266 close (fd); | 263 close (fd); |
267 #ifdef emacs | 264 #ifdef emacs |
268 error (msg, a1, a2); | 265 error (msg, a1, a2); |
269 #else | 266 #else |
270 fprintf (stderr, msg, a1, a2); | 267 fprintf (stderr, msg, a1, a2); |
271 fprintf (stderr, "\n"); | 268 fprintf (stderr, "\n"); |
272 #endif | 269 #endif |
273 } | 270 } |
274 | 271 |
275 static int make_hdr (); | 272 static int make_hdr (int, int, unsigned, unsigned, unsigned, char *, char *); |
276 static void mark_x (); | 273 static void mark_x (char *); |
277 static int copy_text_and_data (); | 274 static int copy_text_and_data (int); |
278 static int copy_sym (); | 275 static int copy_sym (int, int, char *, char *); |
276 static write_segment (int, char *, char *); | |
279 | 277 |
280 /* **************************************************************** | 278 /* **************************************************************** |
281 * unexec | 279 * unexec |
282 * | 280 * |
283 * driving logic. | 281 * driving logic. |
284 */ | 282 */ |
285 unexec (new_name, a_name, data_start, bss_start, entry_address) | 283 int unexec (char *new_name, char *a_name, |
286 char *new_name, *a_name; | 284 uintptr_t data_start, |
287 unsigned data_start, bss_start, entry_address; | 285 uintptr_t bss_start, |
286 uintptr_t entry_address) | |
288 { | 287 { |
289 int new, a_out = -1; | 288 int new, a_out = -1; |
290 | 289 |
291 if (a_name && (a_out = open (a_name, 0)) < 0) | 290 if (a_name && (a_out = open (a_name, 0)) < 0) |
292 { | 291 { |
324 * | 323 * |
325 * Make the header in the new a.out from the header in core. | 324 * Make the header in the new a.out from the header in core. |
326 * Modify the text and data sizes. | 325 * Modify the text and data sizes. |
327 */ | 326 */ |
328 static int | 327 static int |
329 make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) | 328 make_hdr (int new, int a_out, unsigned data_start, unsigned bss_start, unsigned entry_address, char *a_name, char *new_name) |
330 int new, a_out; | |
331 unsigned data_start, bss_start, entry_address; | |
332 char *a_name; | |
333 char *new_name; | |
334 { | 329 { |
335 int scns; | 330 int scns; |
336 unsigned int bss_end; | 331 unsigned int bss_end; |
337 | 332 |
338 struct scnhdr section[MAX_SECTIONS]; | 333 struct scnhdr section[MAX_SECTIONS]; |
433 CHECK_SCNHDR(f_xhdr, _EXCEPT, STYP_EXCEPT); | 428 CHECK_SCNHDR(f_xhdr, _EXCEPT, STYP_EXCEPT); |
434 } | 429 } |
435 | 430 |
436 if (f_thdr == 0) | 431 if (f_thdr == 0) |
437 { | 432 { |
438 ERROR1 ("unexec: couldn't find \"%s\" section", _TEXT); | 433 ERROR1 ("unexec: couldn't find \"%s\" section", (int) _TEXT); |
439 } | 434 } |
440 if (f_dhdr == 0) | 435 if (f_dhdr == 0) |
441 { | 436 { |
442 ERROR1 ("unexec: couldn't find \"%s\" section", _DATA); | 437 ERROR1 ("unexec: couldn't find \"%s\" section", (int) _DATA); |
443 } | 438 } |
444 if (f_bhdr == 0) | 439 if (f_bhdr == 0) |
445 { | 440 { |
446 ERROR1 ("unexec: couldn't find \"%s\" section", _BSS); | 441 ERROR1 ("unexec: couldn't find \"%s\" section", (int) _BSS); |
447 } | 442 } |
448 } | 443 } |
449 else | 444 else |
450 { | 445 { |
451 ERROR0 ("can't build a COFF file from scratch yet"); | 446 ERROR0 ("can't build a COFF file from scratch yet"); |
573 | 568 |
574 * | 569 * |
575 * Copy the text and data segments from memory to the new a.out | 570 * Copy the text and data segments from memory to the new a.out |
576 */ | 571 */ |
577 static int | 572 static int |
578 copy_text_and_data (new) | 573 copy_text_and_data (int new) |
579 int new; | |
580 { | 574 { |
581 char *end; | 575 char *end; |
582 char *ptr; | 576 char *ptr; |
583 | 577 |
584 lseek (new, (long) text_scnptr, 0); | 578 lseek (new, (long) text_scnptr, 0); |
593 | 587 |
594 return 0; | 588 return 0; |
595 } | 589 } |
596 | 590 |
597 #define UnexBlockSz (1<<12) /* read/write block size */ | 591 #define UnexBlockSz (1<<12) /* read/write block size */ |
598 write_segment (new, ptr, end) | 592 write_segment (int new, char *ptr, char *end) |
599 int new; | |
600 char *ptr, *end; | |
601 { | 593 { |
602 int i, nwrite, ret; | 594 int i, nwrite, ret; |
603 char buf[80]; | 595 char buf[80]; |
604 extern int errno; | 596 extern int errno; |
605 char zeros[UnexBlockSz]; | 597 char zeros[UnexBlockSz]; |
636 * copy_sym | 628 * copy_sym |
637 * | 629 * |
638 * Copy the relocation information and symbol table from the a.out to the new | 630 * Copy the relocation information and symbol table from the a.out to the new |
639 */ | 631 */ |
640 static int | 632 static int |
641 copy_sym (new, a_out, a_name, new_name) | 633 copy_sym (int new, int a_out, char *a_name, char *new_name) |
642 int new, a_out; | |
643 char *a_name, *new_name; | |
644 { | 634 { |
645 char page[UnexBlockSz]; | 635 char page[UnexBlockSz]; |
646 int n; | 636 int n; |
647 | 637 |
648 if (a_out < 0) | 638 if (a_out < 0) |
674 * mark_x | 664 * mark_x |
675 * | 665 * |
676 * After successfully building the new a.out, mark it executable | 666 * After successfully building the new a.out, mark it executable |
677 */ | 667 */ |
678 static void | 668 static void |
679 mark_x (name) | 669 mark_x (char *name) |
680 char *name; | |
681 { | 670 { |
682 struct stat sbuf; | 671 struct stat sbuf; |
683 int um; | 672 int um; |
684 int new = 0; /* for PERROR */ | 673 int new = 0; /* for PERROR */ |
685 | 674 |
718 using the two descriptors already open (WRITEDESC and READDESC). | 707 using the two descriptors already open (WRITEDESC and READDESC). |
719 Instead of reading one small structure at a time it should use | 708 Instead of reading one small structure at a time it should use |
720 a reasonable size buffer. But I don't have time to work on such | 709 a reasonable size buffer. But I don't have time to work on such |
721 things, so I am installing it as submitted to me. -- RMS. */ | 710 things, so I am installing it as submitted to me. -- RMS. */ |
722 | 711 |
723 adjust_lnnoptrs (writedesc, readdesc, new_name) | 712 adjust_lnnoptrs (int writedesc, int readdesc, char *new_name) |
724 int writedesc; | |
725 int readdesc; | |
726 char *new_name; | |
727 { | 713 { |
728 int nsyms; | 714 int nsyms; |
729 int naux; | 715 int naux; |
730 int new; | 716 int new; |
731 #ifdef amdahl_uts | 717 #ifdef amdahl_uts |
778 | 764 |
779 /* It is probably a false economy to optimise this routine (it used to | 765 /* It is probably a false economy to optimise this routine (it used to |
780 read one LDREL and do do two lseeks per iteration) but the wrath of | 766 read one LDREL and do do two lseeks per iteration) but the wrath of |
781 RMS (see above :-) would be too much to bear */ | 767 RMS (see above :-) would be too much to bear */ |
782 | 768 |
783 unrelocate_symbols (new, a_out, a_name, new_name) | 769 unrelocate_symbols (int new, int a_out, char *a_name, char *new_name) |
784 int new, a_out; | |
785 char *a_name, *new_name; | |
786 { | 770 { |
787 int i; | 771 int i; |
788 int l; | 772 int l; |
789 LDREL *ldrel; | 773 LDREL *ldrel; |
790 LDHDR ldhdr; | 774 LDHDR ldhdr; |