2 * Copyright (c) 1993 Paul Kranenburg
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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 without specific prior written permission
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.
30 * $FreeBSD: src/gnu/usr.bin/ld/sparc/md.h,v 1.11 1999/08/27 23:36:04 peter Exp $
34 * SPARC machine dependent definitions
38 #define MAX_ALIGNMENT (sizeof (double))
41 #define PAGSIZ __LDPGSZ
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))
48 * Should be handled by a.out.h ?
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))
56 /* Get the SunOS a.out and relocation nomenclature */
59 #define N_IS_DYNAMIC(ex) ((ex).a_dynamic)
61 #define N_SET_FLAG(ex, f) { \
62 (ex).a_dynamic = ((f) & EX_DYNAMIC); \
65 #undef relocation_info
66 #define relocation_info reloc_info_sparc
67 #define r_symbolnum r_index
70 #define N_BADMID(ex) \
71 (N_GETMID(ex) != 0 && N_GETMID(ex) != MID_MACHINE && \
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
81 /* XXX - consider this making SUN_COMPAT --> repercussions on rrs.c */
82 #define RELOC_MEMORY_ADD_P(r) 1
84 #define RELOC_MEMORY_ADD_P(r) 0
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])
96 #define RELOC_JMPTAB_P(r) ((r)->r_type == RELOC_JMP_TBL)
98 #define RELOC_BASEREL_P(r) \
99 ((r)->r_type >= RELOC_BASE10 && (r)->r_type <= RELOC_BASE22)
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)
106 #define RELOC_STATICS_THROUGH_GOT_P(r) (1)
107 #define JMPSLOT_NEEDS_RELOC (1)
110 * Define the range of usable Global Offset Table offsets
111 * when using sparc 13 bit relocation types (-4096 - 4092).
113 #define MAX_GOTSIZE (8192)
114 #define MAX_GOTOFF (4092)
115 #define MIN_GOTOFF (-4096)
117 #define CHECK_GOT_RELOC(r) \
118 ((r)->r_type == RELOC_PC10 || (r)->r_type == RELOC_PC22)
120 #define md_got_reloc(r) (-(r)->r_address)
122 #define RELOC_INIT_SEGMENT_RELOC(r) ((r)->r_type = RELOC_32)
126 * Sun plays games with `r_addend'
128 #define md_get_rt_segment_addend(r,a) (0)
131 /* Width of a Global Offset Table entry */
134 typedef struct jmpslot {
138 #define JMPSLOT_RELOC_MASK (0x003fffff) /* 22 bits */
141 #define SAVE 0x9de3bfa0 /* Build stack frame (opcode1) */
142 #define SETHI 0x03000000 /* %hi(addr) -> %g1 (opcode1) */
143 #define CALL 0x40000000 /* Call instruction (opcode2) */
144 #define JMP 0x81c06000 /* Jump %g1 instruction (opcode2) */
145 #define NOP 0x01000000 /* Delay slot NOP for (reloc_index) */
146 #define TRAP 0x91d02001 /* ta 0x1 */
150 * Byte swap defs for cross linking
153 #if !defined(NEED_SWAP)
155 #define md_swapin_exec_hdr(h)
156 #define md_swapout_exec_hdr(h)
157 #define md_swapin_symbols(s,n)
158 #define md_swapout_symbols(s,n)
159 #define md_swapin_zsymbols(s,n)
160 #define md_swapout_zsymbols(s,n)
161 #define md_swapin_reloc(r,n)
162 #define md_swapout_reloc(r,n)
163 #define md_swapin__dynamic(l)
164 #define md_swapout__dynamic(l)
165 #define md_swapin_section_dispatch_table(l)
166 #define md_swapout_section_dispatch_table(l)
167 #define md_swapin_so_debug(d)
168 #define md_swapout_so_debug(d)
169 #define md_swapin_rrs_hash(f,n)
170 #define md_swapout_rrs_hash(f,n)
171 #define md_swapin_sod(l,n)
172 #define md_swapout_sod(l,n)
173 #define md_swapout_jmpslot(j,n)
174 #define md_swapout_got(g,n)
175 #define md_swapin_ranlib_hdr(h,n)
176 #define md_swapout_ranlib_hdr(h,n)
178 #endif /* NEED_SWAP */
184 /* Define IO byte swapping routines */
186 void md_swapin_exec_hdr __P((struct exec *));
187 void md_swapout_exec_hdr __P((struct exec *));
188 void md_swapin_reloc __P((struct relocation_info *, int));
189 void md_swapout_reloc __P((struct relocation_info *, int));
190 void md_swapout_jmpslot __P((jmpslot_t *, int));
192 #define md_swapin_symbols(s,n) swap_symbols(s,n)
193 #define md_swapout_symbols(s,n) swap_symbols(s,n)
194 #define md_swapin_zsymbols(s,n) swap_zsymbols(s,n)
195 #define md_swapout_zsymbols(s,n) swap_zsymbols(s,n)
196 #define md_swapin__dynamic(l) swap__dynamic(l)
197 #define md_swapout__dynamic(l) swap__dynamic(l)
198 #define md_swapin_section_dispatch_table(l) swap_section_dispatch_table(l)
199 #define md_swapout_section_dispatch_table(l) swap_section_dispatch_table(l)
200 #define md_swapin_so_debug(d) swap_so_debug(d)
201 #define md_swapout_so_debug(d) swap_so_debug(d)
202 #define md_swapin_rrs_hash(f,n) swap_rrs_hash(f,n)
203 #define md_swapout_rrs_hash(f,n) swap_rrs_hash(f,n)
204 #define md_swapin_sod(l,n) swapin_sod(l,n)
205 #define md_swapout_sod(l,n) swapout_sod(l,n)
206 #define md_swapout_got(g,n) swap_longs((long*)(g),n)
207 #define md_swapin_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
208 #define md_swapout_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
210 #define md_swap_short(x) ( (((x) >> 8) & 0xff) | (((x) & 0xff) << 8) )
212 #define md_swap_long(x) ( (((x) >> 24) & 0xff ) | (((x) >> 8 ) & 0xff00 ) | \
213 (((x) << 8 ) & 0xff0000) | (((x) << 24) & 0xff000000))
215 #define get_byte(p) ( ((unsigned char *)(p))[0] )
217 #define get_short(p) ( ( ((unsigned char *)(p))[1] << 8) | \
218 ( ((unsigned char *)(p))[0] ) \
220 #define get_long(p) ( ( ((unsigned char *)(p))[3] << 24) | \
221 ( ((unsigned char *)(p))[2] << 16) | \
222 ( ((unsigned char *)(p))[1] << 8 ) | \
223 ( ((unsigned char *)(p))[0] ) \
226 #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
228 #define put_short(p, v) { ((unsigned char *)(p))[1] = \
229 ((((unsigned long)(v)) >> 8) & 0xff); \
230 ((unsigned char *)(p))[0] = \
231 ((((unsigned long)(v)) ) & 0xff); }
233 #define put_long(p, v) { ((unsigned char *)(p))[3] = \
234 ((((unsigned long)(v)) >> 24) & 0xff); \
235 ((unsigned char *)(p))[2] = \
236 ((((unsigned long)(v)) >> 16) & 0xff); \
237 ((unsigned char *)(p))[1] = \
238 ((((unsigned long)(v)) >> 8) & 0xff); \
239 ((unsigned char *)(p))[0] = \
240 ((((unsigned long)(v)) ) & 0xff); }
242 #else /* We need not swap, but must pay attention to alignment: */
244 #define md_swap_short(x) (x)
245 #define md_swap_long(x) (x)
247 #define get_byte(p) ( ((unsigned char *)(p))[0] )
249 #define get_short(p) ( ( ((unsigned char *)(p))[0] << 8) | \
250 ( ((unsigned char *)(p))[1] ) \
253 #define get_long(p) ( ( ((unsigned char *)(p))[0] << 24) | \
254 ( ((unsigned char *)(p))[1] << 16) | \
255 ( ((unsigned char *)(p))[2] << 8 ) | \
256 ( ((unsigned char *)(p))[3] ) \
260 #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
262 #define put_short(p, v) { ((unsigned char *)(p))[0] = \
263 ((((unsigned long)(v)) >> 8) & 0xff); \
264 ((unsigned char *)(p))[1] = \
265 ((((unsigned long)(v)) ) & 0xff); }
267 #define put_long(p, v) { ((unsigned char *)(p))[0] = \
268 ((((unsigned long)(v)) >> 24) & 0xff); \
269 ((unsigned char *)(p))[1] = \
270 ((((unsigned long)(v)) >> 16) & 0xff); \
271 ((unsigned char *)(p))[2] = \
272 ((((unsigned long)(v)) >> 8) & 0xff); \
273 ((unsigned char *)(p))[3] = \
274 ((((unsigned long)(v)) ) & 0xff); }
276 #endif /* NEED_SWAP */
278 #else /* Not a cross linker: use native */
280 #define md_swap_short(x) (x)
281 #define md_swap_long(x) (x)
283 #define get_byte(where) (*(char *)(where))
284 #define get_short(where) (*(short *)(where))
285 #define get_long(where) (*(long *)(where))
287 #define put_byte(where,what) (*(char *)(where) = (what))
288 #define put_short(where,what) (*(short *)(where) = (what))
289 #define put_long(where,what) (*(long *)(where) = (what))
291 #endif /* CROSS_LINKER */
293 void md_init_header __P((struct exec *, int, int));
294 long md_get_addend __P((struct relocation_info *, unsigned char *));
295 void md_relocate __P((struct relocation_info *, long, unsigned char *, int));
296 void md_make_jmpslot __P((jmpslot_t *, long, long));
297 void md_fix_jmpslot __P((jmpslot_t *, long, u_long));
298 int md_make_reloc __P((struct relocation_info *, struct relocation_info *, int));
299 void md_make_jmpreloc __P((struct relocation_info *, struct relocation_info *, int));
300 void md_make_gotreloc __P((struct relocation_info *, struct relocation_info *, int));
301 void md_make_copyreloc __P((struct relocation_info *, struct relocation_info *));
302 void md_set_breakpoint __P((long, long *));