| 1 | /* This file is obsolete. It needs to be converted to just define a bunch |
| 2 | of stuff that BFD can use to do coff-encapsulated files. --gnu@cygnus.com */ |
| 3 | |
| 4 | /* Another try at encapsulating bsd object files in coff. |
| 5 | Copyright (C) 1988, 1989, Free Software Foundation, Inc. |
| 6 | Written by Pace Willisson 12/9/88 |
| 7 | |
| 8 | This file is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 1, or (at your option) |
| 11 | any later version. |
| 12 | |
| 13 | This file is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this file; if not, write to the Free Software |
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 21 | |
| 22 | /* |
| 23 | * This time, we will only use the coff headers to tell the kernel |
| 24 | * how to exec the file. Therefore, the only fields that need to |
| 25 | * be filled in are the scnptr and vaddr for the text and data |
| 26 | * sections, and the vaddr for the bss. As far as coff is concerned, |
| 27 | * there is no symbol table, relocation, or line numbers. |
| 28 | * |
| 29 | * A normal bsd header (struct exec) is placed after the coff headers, |
| 30 | * and before the real text. I defined a the new fields 'a_machtype' |
| 31 | * and a_flags. If a_machtype is M_386, and a_flags & A_ENCAP is |
| 32 | * true, then the bsd header is preceeded by a coff header. Macros |
| 33 | * like N_TXTOFF and N_TXTADDR use this field to find the bsd header. |
| 34 | * |
| 35 | * The only problem is to track down the bsd exec header. The |
| 36 | * macros HEADER_OFFSET, etc do this. Look at nm.c, dis.c, etc |
| 37 | * for examples. |
| 38 | */ |
| 39 | #ifndef A_OUT_ENCAP_H_SEEN |
| 40 | #define A_OUT_ENCAP_H_SEEN |
| 41 | |
| 42 | #include "a.out.gnu.h" |
| 43 | |
| 44 | #define N_FLAGS_COFF_ENCAPSULATE 0x20 /* coff header precedes bsd header */ |
| 45 | |
| 46 | /* Describe the COFF header used for encapsulation. */ |
| 47 | |
| 48 | struct coffheader |
| 49 | { |
| 50 | /* filehdr */ |
| 51 | unsigned short f_magic; |
| 52 | unsigned short f_nscns; |
| 53 | long f_timdat; |
| 54 | long f_symptr; |
| 55 | long f_nsyms; |
| 56 | unsigned short f_opthdr; |
| 57 | unsigned short f_flags; |
| 58 | /* aouthdr */ |
| 59 | short magic; |
| 60 | short vstamp; |
| 61 | long tsize; |
| 62 | long dsize; |
| 63 | long bsize; |
| 64 | long entry; |
| 65 | long text_start; |
| 66 | long data_start; |
| 67 | struct coffscn |
| 68 | { |
| 69 | char s_name[8]; |
| 70 | long s_paddr; |
| 71 | long s_vaddr; |
| 72 | long s_size; |
| 73 | long s_scnptr; |
| 74 | long s_relptr; |
| 75 | long s_lnnoptr; |
| 76 | unsigned short s_nreloc; |
| 77 | unsigned short s_nlnno; |
| 78 | long s_flags; |
| 79 | } scns[3]; /* text, data, bss */ |
| 80 | }; |
| 81 | \f |
| 82 | /* Describe some of the parameters of the encapsulation, |
| 83 | including how to find the encapsulated BSD header. */ |
| 84 | |
| 85 | #if TARGET == TARGET_I386 |
| 86 | #define COFF_MAGIC 0514 /* I386MAGIC */ |
| 87 | #endif |
| 88 | #if TARGET == TARGET_M68K |
| 89 | #define COFF_MAGIC 0520 /* MC68MAGIC */ |
| 90 | #endif |
| 91 | #if TARGET == TARGET_SPARC |
| 92 | #define COFF_MAGIC UNKNOWN!!! /* Used by TTI */ |
| 93 | #endif |
| 94 | #if TARGET == TARGET_AM29K |
| 95 | #define COFF_MAGIC 0x17A /* Used by asm29k cross-tools */ |
| 96 | #endif |
| 97 | |
| 98 | #ifdef COFF_MAGIC |
| 99 | short __header_offset_temp; |
| 100 | |
| 101 | /* FIXME, this is dumb. The same tools can't handle a.outs for different |
| 102 | architectures, just because COFF_MAGIC is different; so you need a |
| 103 | separate GNU nm for every architecture!!? Also note that for |
| 104 | expediency, this macros accepts COFF_MAGIC in either byte order. |
| 105 | The right thing to do is to call read_aout_header to handle all this. */ |
| 106 | |
| 107 | #define HEADER_OFFSET(f) \ |
| 108 | (__header_offset_temp = 0, \ |
| 109 | fread ((char *)&__header_offset_temp, sizeof (short), 1, (f)), \ |
| 110 | fseek ((f), -sizeof (short), 1), \ |
| 111 | (__header_offset_temp==COFF_MAGIC || __header_offset_temp == \ |
| 112 | ((COFF_MAGIC >> 8)|((COFF_MAGIC&0xFF)<<8)) \ |
| 113 | ? sizeof(struct coffheader) : 0)) |
| 114 | |
| 115 | #define HEADER_OFFSET_FD(fd) \ |
| 116 | (__header_offset_temp = 0, \ |
| 117 | read (fd, (char *)&__header_offset_temp, sizeof (short)), \ |
| 118 | lseek ((fd), -sizeof (short), 1), \ |
| 119 | (__header_offset_temp==COFF_MAGIC || __header_offset_temp == \ |
| 120 | ((COFF_MAGIC >> 8)|((COFF_MAGIC&0xFF)<<8)) \ |
| 121 | ? sizeof(struct coffheader) : 0)) |
| 122 | |
| 123 | |
| 124 | #else |
| 125 | #define HEADER_OFFSET(f) 0 |
| 126 | #define HEADER_OFFSET_FD(fd) 0 |
| 127 | #endif |
| 128 | |
| 129 | #define HEADER_SEEK(f) (fseek ((f), HEADER_OFFSET((f)), 1)) |
| 130 | #define HEADER_SEEK_FD(fd) (lseek ((fd), HEADER_OFFSET_FD((fd)), 1)) |
| 131 | |
| 132 | \f |
| 133 | /* Describe the characteristics of the BSD header |
| 134 | that appears inside the encapsulation. */ |
| 135 | |
| 136 | #undef _N_HDROFF |
| 137 | #undef N_TXTADDR |
| 138 | #undef N_DATADDR |
| 139 | |
| 140 | /* Encapsulated coff files that are linked ZMAGIC have a text segment |
| 141 | offset just past the header (and a matching TXTADDR), excluding |
| 142 | the headers from the text segment proper but keeping the physical |
| 143 | layout and the virtual memory layout page-aligned. |
| 144 | |
| 145 | Non-encapsulated a.out files that are linked ZMAGIC have a text |
| 146 | segment that starts at 0 and an N_TXTADR similarly offset to 0. |
| 147 | They too are page-aligned with each other, but they include the |
| 148 | a.out header as part of the text. |
| 149 | |
| 150 | The _N_HDROFF gets sizeof struct exec added to it, so we have |
| 151 | to compensate here. See <a.out.gnu.h>. */ |
| 152 | |
| 153 | #define _N_HDROFF(x) ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \ |
| 154 | sizeof (struct coffheader) : -sizeof (struct exec)) |
| 155 | |
| 156 | /* Address of text segment in memory after it is loaded. */ |
| 157 | #define N_TXTADDR(x) \ |
| 158 | (TEXT_START_ADDR + \ |
| 159 | ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \ |
| 160 | sizeof (struct coffheader) + sizeof (struct exec) : 0)) |
| 161 | |
| 162 | /* I have no idea what this is doing here. -- gnu@toad.com 20Mar90 |
| 163 | Perhaps it is to give a size that is acceptable to any machine? */ |
| 164 | #undef SEGMENT_SIZE |
| 165 | #define SEGMENT_SIZE 0x400000 |
| 166 | |
| 167 | #define N_DATADDR(x) \ |
| 168 | ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \ |
| 169 | (SEGMENT_SIZE + ((N_TXTADDR(x)+(x).a_text-1) & ~(SEGMENT_SIZE-1))) : \ |
| 170 | (N_TXTADDR(x)+(x).a_text)) |
| 171 | |
| 172 | #endif /* A_OUT_ENCAP_H_SEEN */ |