Sync usage with man page.
[netbsd-mini2440.git] / libexec / ld.aout_so / arch / sparc / md.h
blob3a20b4045e9b2adf298d6333005a0d8d639385d3
1 /* $NetBSD: md.h,v 1.18 2002/12/10 17:14:43 thorpej Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * SPARC machine dependent definitions
36 #define MAX_ALIGNMENT (sizeof (double))
38 #ifdef __NetBSD__
39 #define PAGSIZ AOUT_LDPGSZ
41 #define N_SET_FLAG(ex,f) N_SETMAGIC(ex,N_GETMAGIC(ex), \
42 MID_MACHINE, N_GETFLAG(ex)|(f))
43 #define N_IS_DYNAMIC(ex) ((N_GETFLAG(ex) & EX_DYNAMIC))
46 * Should be handled by a.out.h ?
48 #define N_ADJUST(ex) (((ex).a_entry < PAGSIZ) ? -PAGSIZ : 0)
49 #define TEXT_START(ex) (N_TXTADDR(ex) + N_ADJUST(ex))
50 #define DATA_START(ex) (N_DATADDR(ex) + N_ADJUST(ex))
52 #else /* __NetBSD__ */
54 /* Get the SunOS a.out and relocation nomenclature */
55 #define EX_DYNAMIC 1
57 #define N_IS_DYNAMIC(ex) ((ex).a_dynamic)
59 #define N_SET_FLAG(ex, f) { \
60 (ex).a_dynamic = ((f) & EX_DYNAMIC); \
63 #undef relocation_info
64 #define relocation_info reloc_info_sparc
65 #define r_symbolnum r_index
66 #endif /* __NetBSD__ */
68 #define N_BADMID(ex) \
69 (N_GETMID(ex) != 0 && N_GETMID(ex) != MID_MACHINE && \
70 !md_midcompat(&(ex)))
72 /* Sparc (Sun 4) macros */
73 #define RELOC_ADDRESS(r) ((r)->r_address)
74 #define RELOC_EXTERN_P(r) ((r)->r_extern)
75 #define RELOC_TYPE(r) ((r)->r_symbolnum)
76 #define RELOC_SYMBOL(r) ((r)->r_symbolnum)
77 #define RELOC_MEMORY_SUB_P(r) 0
78 #ifdef RTLD
79 /* XXX - consider this making SUN_COMPAT --> repercussions on rrs.c */
80 #define RELOC_MEMORY_ADD_P(r) 1
81 #else
82 #define RELOC_MEMORY_ADD_P(r) 0
83 #endif
84 #define RELOC_ADD_EXTRA(r) ((r)->r_addend)
85 #define RELOC_PCREL_P(r) \
86 (((r)->r_type >= RELOC_DISP8 && (r)->r_type <= RELOC_WDISP22) \
87 || ((r)->r_type == RELOC_PC10 || (r)->r_type == RELOC_PC22) \
88 || (r)->r_type == RELOC_JMP_TBL)
89 #define RELOC_VALUE_RIGHTSHIFT(r) (reloc_target_rightshift[(r)->r_type])
90 #define RELOC_TARGET_SIZE(r) (reloc_target_size[(r)->r_type])
91 #define RELOC_TARGET_BITPOS(r) 0
92 #define RELOC_TARGET_BITSIZE(r) (reloc_target_bitsize[(r)->r_type])
94 #define RELOC_JMPTAB_P(r) ((r)->r_type == RELOC_JMP_TBL)
96 #define RELOC_BASEREL_P(r) \
97 ((r)->r_type >= RELOC_BASE10 && (r)->r_type <= RELOC_BASE22)
99 #define RELOC_RELATIVE_P(r) ((r)->r_type == RELOC_RELATIVE)
100 #define RELOC_COPY_DAT (RELOC_RELATIVE+1) /*XXX*/
101 #define RELOC_COPY_P(r) ((r)->r_type == RELOC_COPY_DAT)
102 #define RELOC_LAZY_P(r) ((r)->r_type == RELOC_JMP_SLOT)
104 #define RELOC_STATICS_THROUGH_GOT_P(r) (1)
105 #define JMPSLOT_NEEDS_RELOC (1)
106 #define JMPSLOT_NONEXTERN_IS_INTERMODULE (0)
109 * Define the range of usable Global Offset Table offsets
110 * when using sparc 13 bit relocation types (-4096 - 4092);
111 * this is the case if the object files are compiles with `-fpic'.
112 * IF a "large" model is used (i.e. `-fPIC'), pairs of
113 * <RELOC_BASE10,RELOC_BASE22> relocations are used which establish
114 * 32-bit addressability of the GOT table.
116 #define MAX_GOTOFF(t) ((t)==PIC_TYPE_SMALL?4092:LONG_MAX)
117 #define MIN_GOTOFF(t) ((t)==PIC_TYPE_SMALL?-4096:LONG_MIN)
119 #define RELOC_PIC_TYPE(r) ( \
120 ((r)->r_type == RELOC_BASE10 || (r)->r_type == RELOC_BASE22) \
121 ? PIC_TYPE_LARGE \
122 : ((r)->r_type==RELOC_BASE13 ? \
123 PIC_TYPE_SMALL : \
124 PIC_TYPE_NONE) )
126 #define CHECK_GOT_RELOC(r) \
127 ((r)->r_type == RELOC_PC10 || (r)->r_type == RELOC_PC22)
129 #define md_got_reloc(r) (-(r)->r_address)
131 #define RELOC_INIT_SEGMENT_RELOC(r) ((r)->r_type = RELOC_32)
133 #ifdef SUN_COMPAT
135 * Sun plays games with `r_addend'
137 #define md_get_rt_segment_addend(r,a) (0)
138 #endif
140 /* Width of a Global Offset Table entry */
141 typedef long got_t;
143 typedef struct jmpslot {
144 u_long opcode1;
145 u_long opcode2;
146 u_long reloc_index;
147 #define JMPSLOT_RELOC_MASK (0x003fffff) /* 22 bits */
148 } jmpslot_t;
150 #define SAVE 0x9de3bfa0 /* Build stack frame (opcode1) */
151 #define SETHI 0x03000000 /* %hi(addr) -> %g1 (opcode1) */
152 #define CALL 0x40000000 /* Call instruction (opcode2) */
153 #define JMP 0x81c06000 /* Jump %g1 instruction (opcode2) */
154 #define NOP 0x01000000 /* Delay slot NOP for (reloc_index) */
155 #define TRAP 0x91d02001 /* ta 0x1 */
159 * Byte swap defs for cross linking
162 #if !defined(NEED_SWAP)
164 #define md_swapin_exec_hdr(h)
165 #define md_swapout_exec_hdr(h)
166 #define md_swapin_symbols(s,n)
167 #define md_swapout_symbols(s,n)
168 #define md_swapin_zsymbols(s,n)
169 #define md_swapout_zsymbols(s,n)
170 #define md_swapin_reloc(r,n)
171 #define md_swapout_reloc(r,n)
172 #define md_swapin__dynamic(l)
173 #define md_swapout__dynamic(l)
174 #define md_swapin_section_dispatch_table(l)
175 #define md_swapout_section_dispatch_table(l)
176 #define md_swapin_so_debug(d)
177 #define md_swapout_so_debug(d)
178 #define md_swapin_rrs_hash(f,n)
179 #define md_swapout_rrs_hash(f,n)
180 #define md_swapin_sod(l,n)
181 #define md_swapout_sod(l,n)
182 #define md_swapout_jmpslot(j,n)
183 #define md_swapout_got(g,n)
184 #define md_swapin_ranlib_hdr(h,n)
185 #define md_swapout_ranlib_hdr(h,n)
187 #endif /* NEED_SWAP */
189 #ifdef CROSS_LINKER
191 #ifdef NEED_SWAP
193 /* Define IO byte swapping routines */
195 void md_swapin_exec_hdr __P((struct exec *));
196 void md_swapout_exec_hdr __P((struct exec *));
197 void md_swapin_reloc __P((struct relocation_info *, int));
198 void md_swapout_reloc __P((struct relocation_info *, int));
199 void md_swapout_jmpslot __P((jmpslot_t *, int));
201 #define md_swapin_symbols(s,n) swap_symbols(s,n)
202 #define md_swapout_symbols(s,n) swap_symbols(s,n)
203 #define md_swapin_zsymbols(s,n) swap_zsymbols(s,n)
204 #define md_swapout_zsymbols(s,n) swap_zsymbols(s,n)
205 #define md_swapin__dynamic(l) swap__dynamic(l)
206 #define md_swapout__dynamic(l) swap__dynamic(l)
207 #define md_swapin_section_dispatch_table(l) swap_section_dispatch_table(l)
208 #define md_swapout_section_dispatch_table(l) swap_section_dispatch_table(l)
209 #define md_swapin_so_debug(d) swap_so_debug(d)
210 #define md_swapout_so_debug(d) swap_so_debug(d)
211 #define md_swapin_rrs_hash(f,n) swap_rrs_hash(f,n)
212 #define md_swapout_rrs_hash(f,n) swap_rrs_hash(f,n)
213 #define md_swapin_sod(l,n) swapin_sod(l,n)
214 #define md_swapout_sod(l,n) swapout_sod(l,n)
215 #define md_swapout_got(g,n) swap_longs((long*)(g),n)
216 #define md_swapin_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
217 #define md_swapout_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
219 #define md_swap_short(x) ( (((x) >> 8) & 0xff) | (((x) & 0xff) << 8) )
221 #define md_swap_long(x) ( (((x) >> 24) & 0xff ) | (((x) >> 8 ) & 0xff00 ) | \
222 (((x) << 8 ) & 0xff0000) | (((x) << 24) & 0xff000000))
224 #define get_byte(p) ( ((unsigned char *)(p))[0] )
226 #define get_short(p) ( ( ((unsigned char *)(p))[1] << 8) | \
227 ( ((unsigned char *)(p))[0] ) \
229 #define get_long(p) ( ( ((unsigned char *)(p))[3] << 24) | \
230 ( ((unsigned char *)(p))[2] << 16) | \
231 ( ((unsigned char *)(p))[1] << 8 ) | \
232 ( ((unsigned char *)(p))[0] ) \
235 #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
237 #define put_short(p, v) { ((unsigned char *)(p))[1] = \
238 ((((unsigned long)(v)) >> 8) & 0xff); \
239 ((unsigned char *)(p))[0] = \
240 ((((unsigned long)(v)) ) & 0xff); }
242 #define put_long(p, v) { ((unsigned char *)(p))[3] = \
243 ((((unsigned long)(v)) >> 24) & 0xff); \
244 ((unsigned char *)(p))[2] = \
245 ((((unsigned long)(v)) >> 16) & 0xff); \
246 ((unsigned char *)(p))[1] = \
247 ((((unsigned long)(v)) >> 8) & 0xff); \
248 ((unsigned char *)(p))[0] = \
249 ((((unsigned long)(v)) ) & 0xff); }
251 #else /* We need not swap, but must pay attention to alignment: */
253 #define md_swap_short(x) (x)
254 #define md_swap_long(x) (x)
256 #define get_byte(p) ( ((unsigned char *)(p))[0] )
258 #define get_short(p) ( ( ((unsigned char *)(p))[0] << 8) | \
259 ( ((unsigned char *)(p))[1] ) \
262 #define get_long(p) ( ( ((unsigned char *)(p))[0] << 24) | \
263 ( ((unsigned char *)(p))[1] << 16) | \
264 ( ((unsigned char *)(p))[2] << 8 ) | \
265 ( ((unsigned char *)(p))[3] ) \
269 #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
271 #define put_short(p, v) { ((unsigned char *)(p))[0] = \
272 ((((unsigned long)(v)) >> 8) & 0xff); \
273 ((unsigned char *)(p))[1] = \
274 ((((unsigned long)(v)) ) & 0xff); }
276 #define put_long(p, v) { ((unsigned char *)(p))[0] = \
277 ((((unsigned long)(v)) >> 24) & 0xff); \
278 ((unsigned char *)(p))[1] = \
279 ((((unsigned long)(v)) >> 16) & 0xff); \
280 ((unsigned char *)(p))[2] = \
281 ((((unsigned long)(v)) >> 8) & 0xff); \
282 ((unsigned char *)(p))[3] = \
283 ((((unsigned long)(v)) ) & 0xff); }
285 #endif /* NEED_SWAP */
287 #else /* Not a cross linker: use native */
289 #define md_swap_short(x) (x)
290 #define md_swap_long(x) (x)
292 #define get_byte(where) (*(char *)(where))
293 #define get_short(where) (*(short *)(where))
294 #define get_long(where) (*(long *)(where))
296 #define put_byte(where,what) (*(char *)(where) = (what))
297 #define put_short(where,what) (*(short *)(where) = (what))
298 #define put_long(where,what) (*(long *)(where) = (what))
300 #endif /* CROSS_LINKER */