Commit | Line | Data |
---|---|---|
1136f72d | 1 | /* |
0f052032 JH |
2 | * Copyright (c) 1993 Paul Kranenburg |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by Paul Kranenburg. | |
16 | * 4. The name of the author may not be used to endorse or promote products | |
17 | * derived from this software withough specific prior written permission | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | * | |
6a61ea88 | 30 | * $Id: md.h,v 1.8 1994/01/19 15:00:37 davidg Exp $ |
1136f72d PR |
31 | */ |
32 | ||
33 | ||
34 | #if defined(CROSS_LINKER) && defined(XHOST) && XHOST==sparc | |
35 | ||
36 | #define NEED_SWAP | |
37 | ||
38 | #endif | |
39 | ||
40 | #define MAX_ALIGNMENT (sizeof (long)) | |
41 | ||
42 | #ifdef NetBSD | |
43 | #define PAGSIZ __LDPGSZ | |
44 | #else | |
45 | #define PAGSIZ 4096 | |
46 | #endif | |
47 | ||
6a61ea88 JH |
48 | #if defined(NetBSD) || defined(CROSS_LINKER) |
49 | ||
50 | #define N_SET_FLAG(ex,f) (oldmagic || N_GETMAGIC(ex)==QMAGIC ? (0) : \ | |
51 | N_SETMAGIC(ex, \ | |
52 | N_GETMAGIC(ex), \ | |
53 | MID_MACHINE, \ | |
54 | N_GETFLAG(ex)|(f))) | |
55 | ||
56 | #define N_IS_DYNAMIC(ex) ((N_GETFLAG(ex) & EX_DYNAMIC)) | |
57 | ||
58 | #define N_BADMID(ex) \ | |
59 | (N_GETMID(ex) != 0 && N_GETMID(ex) != MID_MACHINE) | |
60 | ||
61 | #endif | |
62 | ||
63 | /* | |
64 | * FreeBSD does it differently | |
65 | */ | |
66 | #ifdef FreeBSD | |
67 | #define N_SET_FLAG(ex,f) (oldmagic ? (0) : \ | |
68 | (netzmagic == 0 ? \ | |
69 | N_SETMAGIC(ex, \ | |
70 | N_GETMAGIC(ex), \ | |
71 | MID_MACHINE, \ | |
72 | N_GETFLAG(ex)|(f)) : \ | |
73 | N_SETMAGIC_NET(ex, \ | |
74 | N_GETMAGIC_NET(ex), \ | |
75 | MID_MACHINE, \ | |
76 | N_GETFLAG_NET(ex)|(f)) )) | |
77 | ||
78 | #define N_IS_DYNAMIC(ex) ((N_GETMAGIC_NET(ex) == ZMAGIC) ? \ | |
79 | ((N_GETFLAG_NET(ex) & EX_DYNAMIC)) : \ | |
80 | ((N_GETFLAG(ex) & EX_DYNAMIC) )) | |
81 | #define N_BADMID(ex) 0 | |
82 | #endif | |
1136f72d PR |
83 | |
84 | /* | |
85 | * Should be handled by a.out.h ? | |
86 | */ | |
87 | #define N_ADJUST(ex) (((ex).a_entry < PAGSIZ) ? -PAGSIZ : 0) | |
88 | #define TEXT_START(ex) (N_TXTADDR(ex) + N_ADJUST(ex)) | |
89 | #define DATA_START(ex) (N_DATADDR(ex) + N_ADJUST(ex)) | |
90 | ||
91 | #define RELOC_STATICS_THROUGH_GOT_P(r) (0) | |
92 | #define JMPSLOT_NEEDS_RELOC (0) | |
93 | ||
94 | #define md_got_reloc(r) (0) | |
95 | ||
96 | #define md_get_rt_segment_addend(r,a) md_get_addend(r,a) | |
97 | ||
98 | /* Width of a Global Offset Table entry */ | |
99 | #define GOT_ENTRY_SIZE 4 | |
100 | typedef long got_t; | |
101 | ||
102 | typedef struct jmpslot { | |
103 | u_short opcode; | |
104 | u_short addr[2]; | |
105 | u_short reloc_index; | |
106 | #define JMPSLOT_RELOC_MASK 0xffff | |
107 | } jmpslot_t; | |
108 | ||
109 | #define NOP 0x90 | |
110 | #define CALL 0xe890 /* NOP + CALL opcode */ | |
111 | #define JUMP 0xe990 /* NOP + JMP opcode */ | |
27b6ced7 | 112 | #define TRAP 0xcc /* INT 3 */ |
1136f72d PR |
113 | |
114 | /* | |
115 | * Byte swap defs for cross linking | |
116 | */ | |
117 | ||
118 | #if !defined(NEED_SWAP) | |
119 | ||
120 | #define md_swapin_exec_hdr(h) | |
121 | #define md_swapout_exec_hdr(h) | |
122 | #define md_swapin_symbols(s,n) | |
123 | #define md_swapout_symbols(s,n) | |
124 | #define md_swapin_zsymbols(s,n) | |
125 | #define md_swapout_zsymbols(s,n) | |
126 | #define md_swapin_reloc(r,n) | |
127 | #define md_swapout_reloc(r,n) | |
6a61ea88 JH |
128 | #define md_swapin__dynamic(l) |
129 | #define md_swapout__dynamic(l) | |
130 | #define md_swapin_section_dispatch_table(l) | |
131 | #define md_swapout_section_dispatch_table(l) | |
132 | #define md_swapin_so_debug(d) | |
133 | #define md_swapout_so_debug(d) | |
1136f72d PR |
134 | #define md_swapin_rrs_hash(f,n) |
135 | #define md_swapout_rrs_hash(f,n) | |
6a61ea88 JH |
136 | #define md_swapin_sod(l,n) |
137 | #define md_swapout_sod(l,n) | |
1136f72d PR |
138 | #define md_swapout_jmpslot(j,n) |
139 | #define md_swapout_got(g,n) | |
140 | #define md_swapin_ranlib_hdr(h,n) | |
141 | #define md_swapout_ranlib_hdr(h,n) | |
142 | ||
143 | #endif /* NEED_SWAP */ | |
144 | ||
145 | #ifdef CROSS_LINKER | |
146 | ||
147 | #ifdef NEED_SWAP | |
148 | ||
149 | /* Define IO byte swapping routines */ | |
150 | ||
151 | void md_swapin_exec_hdr __P((struct exec *)); | |
152 | void md_swapout_exec_hdr __P((struct exec *)); | |
153 | void md_swapin_reloc __P((struct relocation_info *, int)); | |
154 | void md_swapout_reloc __P((struct relocation_info *, int)); | |
155 | void md_swapout_jmpslot __P((jmpslot_t *, int)); | |
156 | ||
6a61ea88 JH |
157 | #define md_swapin_symbols(s,n) swap_symbols(s,n) |
158 | #define md_swapout_symbols(s,n) swap_symbols(s,n) | |
159 | #define md_swapin_zsymbols(s,n) swap_zsymbols(s,n) | |
160 | #define md_swapout_zsymbols(s,n) swap_zsymbols(s,n) | |
161 | #define md_swapin__dynamic(l) swap__dynamic(l) | |
162 | #define md_swapout__dynamic(l) swap__dynamic(l) | |
163 | #define md_swapin_section_dispatch_table(l) swap_section_dispatch_table(l) | |
164 | #define md_swapout_section_dispatch_table(l) swap_section_dispatch_table(l) | |
165 | #define md_swapin_so_debug(d) swap_so_debug(d) | |
166 | #define md_swapout_so_debug(d) swap_so_debug(d) | |
167 | #define md_swapin_rrs_hash(f,n) swap_rrs_hash(f,n) | |
168 | #define md_swapout_rrs_hash(f,n) swap_rrs_hash(f,n) | |
169 | #define md_swapin_sod(l,n) swapin_sod(l,n) | |
170 | #define md_swapout_sod(l,n) swapout_sod(l,n) | |
171 | #define md_swapout_got(g,n) swap_longs((long*)(g),n) | |
172 | #define md_swapin_ranlib_hdr(h,n) swap_ranlib_hdr(h,n) | |
173 | #define md_swapout_ranlib_hdr(h,n) swap_ranlib_hdr(h,n) | |
1136f72d PR |
174 | |
175 | #define md_swap_short(x) ( (((x) >> 8) & 0xff) | (((x) & 0xff) << 8) ) | |
176 | ||
177 | #define md_swap_long(x) ( (((x) >> 24) & 0xff ) | (((x) >> 8 ) & 0xff00 ) | \ | |
178 | (((x) << 8 ) & 0xff0000) | (((x) << 24) & 0xff000000)) | |
179 | ||
180 | #define get_byte(p) ( ((unsigned char *)(p))[0] ) | |
181 | ||
182 | #define get_short(p) ( ( ((unsigned char *)(p))[1] << 8) | \ | |
183 | ( ((unsigned char *)(p))[0] ) \ | |
184 | ) | |
185 | #define get_long(p) ( ( ((unsigned char *)(p))[3] << 24) | \ | |
186 | ( ((unsigned char *)(p))[2] << 16) | \ | |
187 | ( ((unsigned char *)(p))[1] << 8 ) | \ | |
188 | ( ((unsigned char *)(p))[0] ) \ | |
189 | ) | |
190 | ||
191 | #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); } | |
192 | ||
193 | #define put_short(p, v) { ((unsigned char *)(p))[1] = \ | |
194 | ((((unsigned long)(v)) >> 8) & 0xff); \ | |
195 | ((unsigned char *)(p))[0] = \ | |
196 | ((((unsigned long)(v)) ) & 0xff); } | |
197 | ||
198 | #define put_long(p, v) { ((unsigned char *)(p))[3] = \ | |
199 | ((((unsigned long)(v)) >> 24) & 0xff); \ | |
200 | ((unsigned char *)(p))[2] = \ | |
201 | ((((unsigned long)(v)) >> 16) & 0xff); \ | |
202 | ((unsigned char *)(p))[1] = \ | |
203 | ((((unsigned long)(v)) >> 8) & 0xff); \ | |
204 | ((unsigned char *)(p))[0] = \ | |
205 | ((((unsigned long)(v)) ) & 0xff); } | |
206 | ||
207 | #else /* We need not swap, but must pay attention to alignment: */ | |
208 | ||
209 | #define md_swap_short(x) (x) | |
210 | #define md_swap_long(x) (x) | |
211 | ||
212 | #define get_byte(p) ( ((unsigned char *)(p))[0] ) | |
213 | ||
214 | #define get_short(p) ( ( ((unsigned char *)(p))[0] << 8) | \ | |
215 | ( ((unsigned char *)(p))[1] ) \ | |
216 | ) | |
217 | ||
218 | #define get_long(p) ( ( ((unsigned char *)(p))[0] << 24) | \ | |
219 | ( ((unsigned char *)(p))[1] << 16) | \ | |
220 | ( ((unsigned char *)(p))[2] << 8 ) | \ | |
221 | ( ((unsigned char *)(p))[3] ) \ | |
222 | ) | |
223 | ||
224 | ||
225 | #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); } | |
226 | ||
227 | #define put_short(p, v) { ((unsigned char *)(p))[0] = \ | |
228 | ((((unsigned long)(v)) >> 8) & 0xff); \ | |
229 | ((unsigned char *)(p))[1] = \ | |
230 | ((((unsigned long)(v)) ) & 0xff); } | |
231 | ||
232 | #define put_long(p, v) { ((unsigned char *)(p))[0] = \ | |
233 | ((((unsigned long)(v)) >> 24) & 0xff); \ | |
234 | ((unsigned char *)(p))[1] = \ | |
235 | ((((unsigned long)(v)) >> 16) & 0xff); \ | |
236 | ((unsigned char *)(p))[2] = \ | |
237 | ((((unsigned long)(v)) >> 8) & 0xff); \ | |
238 | ((unsigned char *)(p))[3] = \ | |
239 | ((((unsigned long)(v)) ) & 0xff); } | |
240 | ||
241 | #endif /* NEED_SWAP */ | |
242 | ||
243 | #else /* Not a cross linker: use native */ | |
244 | ||
245 | #define md_swap_short(x) (x) | |
246 | #define md_swap_long(x) (x) | |
247 | ||
248 | #define get_byte(where) (*(char *)(where)) | |
249 | #define get_short(where) (*(short *)(where)) | |
250 | #define get_long(where) (*(long *)(where)) | |
251 | ||
252 | #define put_byte(where,what) (*(char *)(where) = (what)) | |
253 | #define put_short(where,what) (*(short *)(where) = (what)) | |
254 | #define put_long(where,what) (*(long *)(where) = (what)) | |
255 | ||
256 | #endif /* CROSS_LINKER */ | |
257 |