Commit | Line | Data |
---|---|---|
1fb83be6 KR |
1 | /* BFD back-end for NetBSD/532 a.out-ish binaries. |
2 | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of BFD, the Binary File Descriptor library. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | /* | |
20 | * Created by Ian Dall | |
21 | * 5-Jun-94 | |
22 | * | |
23 | * Largely a copy of netbsd386.c plus some code from aout-pc532-mach.c | |
24 | */ | |
25 | ||
26 | #define BYTES_IN_WORD 4 | |
27 | #define ARCH 32 | |
28 | ||
29 | /* ZMAGIC files never include the header in the text. */ | |
30 | #define N_HEADER_IN_TEXT(x) 1 | |
31 | ||
32 | #define PAGE_SIZE 0x1000 | |
33 | ||
34 | /* ZMAGIC files start at address 0. This does not apply to QMAGIC. */ | |
35 | #define TEXT_START_ADDR PAGE_SIZE | |
36 | #define N_SHARED_LIB(x) 0 | |
37 | ||
38 | /* Use a_entry of 0 to distinguish object files from OMAGIC executables */ | |
39 | #define N_TXTADDR(x) \ | |
40 | ((N_MAGIC(x) == OMAGIC) && \ | |
41 | ((x).a_entry < TEXT_START_ADDR) ? 0 : /* object file or NMAGIC */\ | |
42 | N_SHARED_LIB(x) ? 0 : \ | |
43 | N_HEADER_IN_TEXT(x) ? \ | |
44 | TEXT_START_ADDR + EXEC_BYTES_SIZE : /* no padding */\ | |
45 | TEXT_START_ADDR /* a page of padding */\ | |
46 | ) | |
47 | ||
48 | #define SEGMENT_SIZE PAGE_SIZE | |
49 | ||
50 | #define DEFAULT_ARCH bfd_arch_ns32k | |
51 | ||
52 | #define MY(OP) CAT(netbsd532_,OP) | |
53 | /* This needs to start with a.out so GDB knows it is an a.out variant. */ | |
54 | #define TARGETNAME "a.out-netbsd-532" | |
55 | #define MACHTYPE_OK(mtype) ((mtype) == M_532_NETBSD) | |
56 | ||
57 | #define N_MAGIC(ex) \ | |
58 | ( (((ex).a_info)&0xffff0000) ? ((((ex).a_info))&0xffff) : ((ex).a_info)) | |
59 | #define N_MACHTYPE(ex) \ | |
60 | ( (((ex).a_info)&0xffff0000) ? (((((ex).a_info))>>16)&0x03ff) : 0 ) | |
61 | #define N_FLAGS(ex) \ | |
62 | ( (((ex).a_info)&0xffff0000) ? ((((ex).a_info)>>26)&0x3f) : 0 ) | |
63 | #define N_SET_INFO(ex, mag,mid,flag) \ | |
64 | ( (ex).a_info = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \ | |
65 | (((mag)&0xffff)) ) ) | |
66 | #define N_SET_MAGIC(exec,magic) \ | |
67 | ((exec).a_info = (((exec).a_info & ~0xffff) | ((magic) & 0xffff))) | |
68 | #define N_SET_MACHTYPE(exec,machtype) \ | |
69 | ((exec).a_info = \ | |
70 | (((exec).a_info & ~(0x3ff<<16)) | (((machtype)&0xff) << 16))) | |
71 | #define N_SET_FLAGS(exec, flags) \ | |
72 | ((exec).a_info = \ | |
73 | (((exec).a_info & ~(0x3f<<26)) | (((flags)&0x3f) << 26))) | |
74 | ||
75 | #define N_MAG(MAG) ((MAG) == o_magic? OMAGIC: ((MAG) == z_magic? ZMAGIC: ((MAG) == n_magic? NMAGIC: 0))) | |
76 | ||
77 | #define WRITE_HEADERS(abfd, execp) \ | |
78 | { \ | |
79 | bfd_size_type text_size; /* dummy vars */ \ | |
80 | int mag; \ | |
81 | file_ptr text_end; \ | |
82 | if (adata(abfd).magic == undecided_magic) \ | |
83 | NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end); \ | |
84 | mag = adata(abfd).magic; \ | |
85 | N_SET_INFO(*execp, N_MAG(mag), M_532_NETBSD, aout_backend_info (abfd)->exec_hdr_flags); \ | |
86 | \ | |
87 | execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE; \ | |
88 | execp->a_entry = bfd_get_start_address (abfd); \ | |
89 | \ | |
90 | execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * \ | |
91 | obj_reloc_entry_size (abfd)); \ | |
92 | execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * \ | |
93 | obj_reloc_entry_size (abfd)); \ | |
94 | NAME(aout,swap_exec_header_out) (abfd, execp, &exec_bytes); \ | |
95 | \ | |
96 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) return false; \ | |
97 | if (bfd_write ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd) \ | |
98 | != EXEC_BYTES_SIZE) \ | |
99 | return false; \ | |
100 | /* Now write out reloc info, followed by syms and strings */ \ | |
101 | \ | |
102 | if (bfd_get_outsymbols (abfd) != (asymbol **) NULL \ | |
103 | && bfd_get_symcount (abfd) != 0) \ | |
104 | { \ | |
105 | if (bfd_seek (abfd, (file_ptr)(N_SYMOFF(*execp)), SEEK_SET) \ | |
106 | != 0) \ | |
107 | return false; \ | |
108 | \ | |
109 | if (! NAME(aout,write_syms)(abfd)) return false; \ | |
110 | \ | |
111 | if (bfd_seek (abfd, (file_ptr)(N_TRELOFF(*execp)), SEEK_SET) \ | |
112 | != 0) \ | |
113 | return false; \ | |
114 | \ | |
115 | if (!NAME(aout,squirt_out_relocs) (abfd, obj_textsec (abfd))) \ | |
116 | return false; \ | |
117 | if (bfd_seek (abfd, (file_ptr)(N_DRELOFF(*execp)), SEEK_SET) \ | |
118 | != 0) \ | |
119 | return false; \ | |
120 | \ | |
121 | if (!NAME(aout,squirt_out_relocs)(abfd, obj_datasec (abfd))) \ | |
122 | return false; \ | |
123 | } \ | |
124 | } | |
125 | ||
126 | ||
127 | #include "bfd.h" | |
128 | #include "sysdep.h" | |
129 | #include "aout-ns32k.h" | |
130 | #include "libbfd.h" | |
131 | #include "libaout.h" | |
132 | ||
133 | ||
134 | /* On NetBSD, the magic number is always in ntohl's "network" (big-endian) | |
135 | format. */ | |
136 | #define SWAP_MAGIC(ext) bfd_getb32 (ext) | |
137 | ||
138 | #include "aout/aout64.h" | |
139 | ||
140 | /* Forward declaration. Defined in aout-target.h */ | |
141 | static boolean MY(set_sizes)(); | |
142 | ||
143 | static CONST struct aout_backend_data MY(backend_data) = { | |
144 | 0, /* zmagic contiguous */ | |
145 | 1, /* text incl header */ | |
146 | 0, | |
147 | 0, /* text vma? */ | |
148 | MY(set_sizes), | |
149 | 0, /* exec header is counted */ | |
150 | }; | |
151 | ||
152 | #define MY_backend_data &MY(backend_data) | |
153 | ||
154 | ||
155 | /* We can`t use the MYNS macro here for cpp reasons too subtle | |
156 | * for me -- IWD | |
157 | */ | |
158 | #define MY_bfd_reloc_type_lookup ns32kaout_bfd_reloc_type_lookup | |
159 | ||
160 | /* libaout doesn't use NAME for these ... */ | |
161 | #define MY_get_section_contents aout_32_get_section_contents | |
162 | ||
163 | static boolean | |
164 | MY(write_object_contents) (abfd) | |
165 | bfd *abfd; | |
166 | { | |
167 | struct external_exec exec_bytes; | |
168 | struct internal_exec *execp = exec_hdr (abfd); | |
169 | ||
170 | #if CHOOSE_RELOC_SIZE | |
171 | CHOOSE_RELOC_SIZE(abfd); | |
172 | #else | |
173 | obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; | |
174 | #endif | |
175 | ||
176 | BFD_ASSERT(bfd_get_arch(abfd) == bfd_arch_ns32k); | |
177 | BFD_ASSERT(bfd_get_mach(abfd) == 32532); | |
178 | N_SET_MACHTYPE (*execp, M_532_NETBSD); | |
179 | ||
180 | N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags); | |
181 | ||
182 | WRITE_HEADERS(abfd, execp); | |
183 | ||
184 | return true; | |
185 | } | |
186 | ||
187 | #define MY_write_object_contents MY(write_object_contents) | |
188 | ||
189 | #include "aout-target.h" |