Commit | Line | Data |
---|---|---|
1136f72d PR |
1 | /* |
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 | |
6a61ea88 | 17 | * derived from this software without specific prior written permission |
1136f72d PR |
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.5 1993/12/02 01:03:47 jkh Exp $ |
1136f72d PR |
31 | */ |
32 | ||
33 | /* | |
34 | * SPARC machine dependent definitions | |
35 | */ | |
36 | ||
37 | ||
38 | #define MAX_ALIGNMENT (sizeof (double)) | |
39 | ||
40 | #ifdef NetBSD | |
41 | #define PAGSIZ __LDPGSZ | |
42 | ||
43 | #define N_SET_FLAG(ex,f) N_SETMAGIC(ex,N_GETMAGIC(ex), \ | |
44 | MID_MACHINE, N_GETFLAG(ex)|(f)) | |
45 | #define N_IS_DYNAMIC(ex) ((N_GETFLAG(ex) & EX_DYNAMIC)) | |
46 | ||
6a61ea88 JH |
47 | /* |
48 | * Should be handled by a.out.h ? | |
49 | */ | |
50 | #define N_ADJUST(ex) (((ex).a_entry < PAGSIZ) ? -PAGSIZ : 0) | |
51 | #define TEXT_START(ex) (N_TXTADDR(ex) + N_ADJUST(ex)) | |
52 | #define DATA_START(ex) (N_DATADDR(ex) + N_ADJUST(ex)) | |
53 | ||
1136f72d PR |
54 | #else |
55 | ||
56 | /* Get the SunOS a.out and relocation nomenclature */ | |
57 | #define EX_DYNAMIC 1 | |
58 | ||
59 | #define N_IS_DYNAMIC(ex) ((ex).a_dynamic) | |
60 | ||
61 | #define N_SET_FLAG(ex, f) { \ | |
62 | (ex).a_dynamic = ((f) & EX_DYNAMIC); \ | |
63 | } | |
64 | ||
65 | #undef relocation_info | |
66 | #define relocation_info reloc_info_sparc | |
67 | #define r_symbolnum r_index | |
68 | #endif /* NetBSD */ | |
69 | ||
6a61ea88 JH |
70 | #define N_BADMID(ex) \ |
71 | (N_GETMID(ex) != 0 && N_GETMID(ex) != MID_MACHINE && \ | |
72 | !md_midcompat(&(ex))) | |
73 | ||
1136f72d PR |
74 | /* Sparc (Sun 4) macros */ |
75 | #define RELOC_ADDRESS(r) ((r)->r_address) | |
76 | #define RELOC_EXTERN_P(r) ((r)->r_extern) | |
77 | #define RELOC_TYPE(r) ((r)->r_symbolnum) | |
78 | #define RELOC_SYMBOL(r) ((r)->r_symbolnum) | |
79 | #define RELOC_MEMORY_SUB_P(r) 0 | |
80 | #ifdef RTLD | |
81 | /* XXX - consider this making SUN_COMPAT --> repercussions on rrs.c */ | |
82 | #define RELOC_MEMORY_ADD_P(r) 1 | |
83 | #else | |
84 | #define RELOC_MEMORY_ADD_P(r) 0 | |
85 | #endif | |
86 | #define RELOC_ADD_EXTRA(r) ((r)->r_addend) | |
87 | #define RELOC_PCREL_P(r) \ | |
88 | (((r)->r_type >= RELOC_DISP8 && (r)->r_type <= RELOC_WDISP22) \ | |
89 | || ((r)->r_type == RELOC_PC10 || (r)->r_type == RELOC_PC22) \ | |
90 | || (r)->r_type == RELOC_JMP_TBL) | |
91 | #define RELOC_VALUE_RIGHTSHIFT(r) (reloc_target_rightshift[(r)->r_type]) | |
92 | #define RELOC_TARGET_SIZE(r) (reloc_target_size[(r)->r_type]) | |
93 | #define RELOC_TARGET_BITPOS(r) 0 | |
94 | #define RELOC_TARGET_BITSIZE(r) (reloc_target_bitsize[(r)->r_type]) | |
95 | ||
96 | #define RELOC_JMPTAB_P(r) ((r)->r_type == RELOC_JMP_TBL) | |
97 | ||
98 | #define RELOC_BASEREL_P(r) \ | |
99 | ((r)->r_type >= RELOC_BASE10 && (r)->r_type <= RELOC_BASE22) | |
100 | ||
101 | #define RELOC_RELATIVE_P(r) ((r)->r_type == RELOC_RELATIVE) | |
102 | #define RELOC_COPY_DAT (RELOC_RELATIVE+1) /*XXX*/ | |
103 | #define RELOC_COPY_P(r) ((r)->r_type == RELOC_COPY_DAT) | |
104 | #define RELOC_LAZY_P(r) ((r)->r_type == RELOC_JMP_SLOT) | |
105 | ||
106 | #define RELOC_STATICS_THROUGH_GOT_P(r) (1) | |
107 | #define JMPSLOT_NEEDS_RELOC (1) | |
108 | ||
109 | #define CHECK_GOT_RELOC(r) \ | |
110 | ((r)->r_type == RELOC_PC10 || (r)->r_type == RELOC_PC22) | |
111 | ||
112 | #define md_got_reloc(r) (-(r)->r_address) | |
113 | ||
114 | #ifdef SUN_COMPAT | |
115 | /* | |
116 | * Sun plays games with `r_addend' | |
117 | */ | |
118 | #define md_get_rt_segment_addend(r,a) (0) | |
119 | #endif | |
120 | ||
121 | /* Width of a Global Offset Table entry */ | |
122 | typedef long got_t; | |
123 | ||
124 | typedef struct jmpslot { | |
125 | u_long opcode1; | |
126 | u_long opcode2; | |
127 | u_long reloc_index; | |
128 | #define JMPSLOT_RELOC_MASK (0x003fffff) /* 22 bits */ | |
129 | } jmpslot_t; | |
130 | ||
131 | #define SAVE 0x9de3bfa0 /* Build stack frame (opcode1) */ | |
132 | #define SETHI 0x03000000 /* %hi(addr) -> %g1 (opcode1) */ | |
133 | #define CALL 0x40000000 /* Call instruction (opcode2) */ | |
134 | #define JMP 0x81c06000 /* Jump %g1 instruction (opcode2) */ | |
135 | #define NOP 0x01000000 /* Delay slot NOP for (reloc_index) */ | |
27b6ced7 | 136 | #define TRAP 0x91d02001 /* ta 0x1 */ |
1136f72d PR |
137 | |
138 | ||
139 | /* | |
140 | * Byte swap defs for cross linking | |
141 | */ | |
142 | ||
143 | #if !defined(NEED_SWAP) | |
144 | ||
145 | #define md_swapin_exec_hdr(h) | |
146 | #define md_swapout_exec_hdr(h) | |
147 | #define md_swapin_symbols(s,n) | |
148 | #define md_swapout_symbols(s,n) | |
149 | #define md_swapin_zsymbols(s,n) | |
150 | #define md_swapout_zsymbols(s,n) | |
151 | #define md_swapin_reloc(r,n) | |
152 | #define md_swapout_reloc(r,n) | |
6a61ea88 JH |
153 | #define md_swapin__dynamic(l) |
154 | #define md_swapout__dynamic(l) | |
155 | #define md_swapin_section_dispatch_table(l) | |
156 | #define md_swapout_section_dispatch_table(l) | |
157 | #define md_swapin_so_debug(d) | |
158 | #define md_swapout_so_debug(d) | |
1136f72d PR |
159 | #define md_swapin_rrs_hash(f,n) |
160 | #define md_swapout_rrs_hash(f,n) | |
6a61ea88 JH |
161 | #define md_swapin_sod(l,n) |
162 | #define md_swapout_sod(l,n) | |
1136f72d PR |
163 | #define md_swapout_jmpslot(j,n) |
164 | #define md_swapout_got(g,n) | |
165 | #define md_swapin_ranlib_hdr(h,n) | |
166 | #define md_swapout_ranlib_hdr(h,n) | |
167 | ||
168 | #endif /* NEED_SWAP */ | |
169 | ||
170 | #ifdef CROSS_LINKER | |
171 | ||
172 | #ifdef NEED_SWAP | |
173 | ||
174 | /* Define IO byte swapping routines */ | |
175 | ||
176 | void md_swapin_exec_hdr __P((struct exec *)); | |
177 | void md_swapout_exec_hdr __P((struct exec *)); | |
178 | void md_swapin_reloc __P((struct relocation_info *, int)); | |
179 | void md_swapout_reloc __P((struct relocation_info *, int)); | |
180 | void md_swapout_jmpslot __P((jmpslot_t *, int)); | |
181 | ||
6a61ea88 JH |
182 | #define md_swapin_symbols(s,n) swap_symbols(s,n) |
183 | #define md_swapout_symbols(s,n) swap_symbols(s,n) | |
184 | #define md_swapin_zsymbols(s,n) swap_zsymbols(s,n) | |
185 | #define md_swapout_zsymbols(s,n) swap_zsymbols(s,n) | |
186 | #define md_swapin__dynamic(l) swap__dynamic(l) | |
187 | #define md_swapout__dynamic(l) swap__dynamic(l) | |
188 | #define md_swapin_section_dispatch_table(l) swap_section_dispatch_table(l) | |
189 | #define md_swapout_section_dispatch_table(l) swap_section_dispatch_table(l) | |
190 | #define md_swapin_so_debug(d) swap_so_debug(d) | |
191 | #define md_swapout_so_debug(d) swap_so_debug(d) | |
192 | #define md_swapin_rrs_hash(f,n) swap_rrs_hash(f,n) | |
193 | #define md_swapout_rrs_hash(f,n) swap_rrs_hash(f,n) | |
194 | #define md_swapin_sod(l,n) swapin_sod(l,n) | |
195 | #define md_swapout_sod(l,n) swapout_sod(l,n) | |
196 | #define md_swapout_got(g,n) swap_longs((long*)(g),n) | |
197 | #define md_swapin_ranlib_hdr(h,n) swap_ranlib_hdr(h,n) | |
198 | #define md_swapout_ranlib_hdr(h,n) swap_ranlib_hdr(h,n) | |
1136f72d PR |
199 | |
200 | #define md_swap_short(x) ( (((x) >> 8) & 0xff) | (((x) & 0xff) << 8) ) | |
201 | ||
202 | #define md_swap_long(x) ( (((x) >> 24) & 0xff ) | (((x) >> 8 ) & 0xff00 ) | \ | |
203 | (((x) << 8 ) & 0xff0000) | (((x) << 24) & 0xff000000)) | |
204 | ||
205 | #define get_byte(p) ( ((unsigned char *)(p))[0] ) | |
206 | ||
207 | #define get_short(p) ( ( ((unsigned char *)(p))[1] << 8) | \ | |
208 | ( ((unsigned char *)(p))[0] ) \ | |
209 | ) | |
210 | #define get_long(p) ( ( ((unsigned char *)(p))[3] << 24) | \ | |
211 | ( ((unsigned char *)(p))[2] << 16) | \ | |
212 | ( ((unsigned char *)(p))[1] << 8 ) | \ | |
213 | ( ((unsigned char *)(p))[0] ) \ | |
214 | ) | |
215 | ||
216 | #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); } | |
217 | ||
218 | #define put_short(p, v) { ((unsigned char *)(p))[1] = \ | |
219 | ((((unsigned long)(v)) >> 8) & 0xff); \ | |
220 | ((unsigned char *)(p))[0] = \ | |
221 | ((((unsigned long)(v)) ) & 0xff); } | |
222 | ||
223 | #define put_long(p, v) { ((unsigned char *)(p))[3] = \ | |
224 | ((((unsigned long)(v)) >> 24) & 0xff); \ | |
225 | ((unsigned char *)(p))[2] = \ | |
226 | ((((unsigned long)(v)) >> 16) & 0xff); \ | |
227 | ((unsigned char *)(p))[1] = \ | |
228 | ((((unsigned long)(v)) >> 8) & 0xff); \ | |
229 | ((unsigned char *)(p))[0] = \ | |
230 | ((((unsigned long)(v)) ) & 0xff); } | |
231 | ||
232 | #else /* We need not swap, but must pay attention to alignment: */ | |
233 | ||
234 | #define md_swap_short(x) (x) | |
235 | #define md_swap_long(x) (x) | |
236 | ||
237 | #define get_byte(p) ( ((unsigned char *)(p))[0] ) | |
238 | ||
239 | #define get_short(p) ( ( ((unsigned char *)(p))[0] << 8) | \ | |
240 | ( ((unsigned char *)(p))[1] ) \ | |
241 | ) | |
242 | ||
243 | #define get_long(p) ( ( ((unsigned char *)(p))[0] << 24) | \ | |
244 | ( ((unsigned char *)(p))[1] << 16) | \ | |
245 | ( ((unsigned char *)(p))[2] << 8 ) | \ | |
246 | ( ((unsigned char *)(p))[3] ) \ | |
247 | ) | |
248 | ||
249 | ||
250 | #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); } | |
251 | ||
252 | #define put_short(p, v) { ((unsigned char *)(p))[0] = \ | |
253 | ((((unsigned long)(v)) >> 8) & 0xff); \ | |
254 | ((unsigned char *)(p))[1] = \ | |
255 | ((((unsigned long)(v)) ) & 0xff); } | |
256 | ||
257 | #define put_long(p, v) { ((unsigned char *)(p))[0] = \ | |
258 | ((((unsigned long)(v)) >> 24) & 0xff); \ | |
259 | ((unsigned char *)(p))[1] = \ | |
260 | ((((unsigned long)(v)) >> 16) & 0xff); \ | |
261 | ((unsigned char *)(p))[2] = \ | |
262 | ((((unsigned long)(v)) >> 8) & 0xff); \ | |
263 | ((unsigned char *)(p))[3] = \ | |
264 | ((((unsigned long)(v)) ) & 0xff); } | |
265 | ||
266 | #endif /* NEED_SWAP */ | |
267 | ||
268 | #else /* Not a cross linker: use native */ | |
269 | ||
270 | #define md_swap_short(x) (x) | |
271 | #define md_swap_long(x) (x) | |
272 | ||
273 | #define get_byte(where) (*(char *)(where)) | |
274 | #define get_short(where) (*(short *)(where)) | |
275 | #define get_long(where) (*(long *)(where)) | |
276 | ||
277 | #define put_byte(where,what) (*(char *)(where) = (what)) | |
278 | #define put_short(where,what) (*(short *)(where) = (what)) | |
279 | #define put_long(where,what) (*(long *)(where) = (what)) | |
280 | ||
281 | #endif /* CROSS_LINKER */ | |
282 |