Forgot half of the changes for CPUSTATES and DK_NDRIVE, sorry.
[unix-history] / gnu / usr.bin / ld / sparc / md.h
CommitLineData
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
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 *
80f25b52 30 * $Id: md.h,v 1.2 1993/11/09 04:19:35 paul 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
47#else
48
49/* Get the SunOS a.out and relocation nomenclature */
50#define EX_DYNAMIC 1
51
52#define N_IS_DYNAMIC(ex) ((ex).a_dynamic)
53
54#define N_SET_FLAG(ex, f) { \
55 (ex).a_dynamic = ((f) & EX_DYNAMIC); \
56}
57
58#undef relocation_info
59#define relocation_info reloc_info_sparc
60#define r_symbolnum r_index
61#endif /* NetBSD */
62
63/* Sparc (Sun 4) macros */
64#define RELOC_ADDRESS(r) ((r)->r_address)
65#define RELOC_EXTERN_P(r) ((r)->r_extern)
66#define RELOC_TYPE(r) ((r)->r_symbolnum)
67#define RELOC_SYMBOL(r) ((r)->r_symbolnum)
68#define RELOC_MEMORY_SUB_P(r) 0
69#ifdef RTLD
70/* XXX - consider this making SUN_COMPAT --> repercussions on rrs.c */
71#define RELOC_MEMORY_ADD_P(r) 1
72#else
73#define RELOC_MEMORY_ADD_P(r) 0
74#endif
75#define RELOC_ADD_EXTRA(r) ((r)->r_addend)
76#define RELOC_PCREL_P(r) \
77 (((r)->r_type >= RELOC_DISP8 && (r)->r_type <= RELOC_WDISP22) \
78 || ((r)->r_type == RELOC_PC10 || (r)->r_type == RELOC_PC22) \
79 || (r)->r_type == RELOC_JMP_TBL)
80#define RELOC_VALUE_RIGHTSHIFT(r) (reloc_target_rightshift[(r)->r_type])
81#define RELOC_TARGET_SIZE(r) (reloc_target_size[(r)->r_type])
82#define RELOC_TARGET_BITPOS(r) 0
83#define RELOC_TARGET_BITSIZE(r) (reloc_target_bitsize[(r)->r_type])
84
85#define RELOC_JMPTAB_P(r) ((r)->r_type == RELOC_JMP_TBL)
86
87#define RELOC_BASEREL_P(r) \
88 ((r)->r_type >= RELOC_BASE10 && (r)->r_type <= RELOC_BASE22)
89
90#define RELOC_RELATIVE_P(r) ((r)->r_type == RELOC_RELATIVE)
91#define RELOC_COPY_DAT (RELOC_RELATIVE+1) /*XXX*/
92#define RELOC_COPY_P(r) ((r)->r_type == RELOC_COPY_DAT)
93#define RELOC_LAZY_P(r) ((r)->r_type == RELOC_JMP_SLOT)
94
95#define RELOC_STATICS_THROUGH_GOT_P(r) (1)
96#define JMPSLOT_NEEDS_RELOC (1)
97
98#define CHECK_GOT_RELOC(r) \
99 ((r)->r_type == RELOC_PC10 || (r)->r_type == RELOC_PC22)
100
101#define md_got_reloc(r) (-(r)->r_address)
102
103#ifdef SUN_COMPAT
104/*
105 * Sun plays games with `r_addend'
106 */
107#define md_get_rt_segment_addend(r,a) (0)
108#endif
109
110/* Width of a Global Offset Table entry */
111typedef long got_t;
112
113typedef struct jmpslot {
114 u_long opcode1;
115 u_long opcode2;
116 u_long reloc_index;
117#define JMPSLOT_RELOC_MASK (0x003fffff) /* 22 bits */
118} jmpslot_t;
119
120#define SAVE 0x9de3bfa0 /* Build stack frame (opcode1) */
121#define SETHI 0x03000000 /* %hi(addr) -> %g1 (opcode1) */
122#define CALL 0x40000000 /* Call instruction (opcode2) */
123#define JMP 0x81c06000 /* Jump %g1 instruction (opcode2) */
124#define NOP 0x01000000 /* Delay slot NOP for (reloc_index) */
80f25b52 125#define BPT 0x91d02001 /* breakpoint: `ta 0x1' */
1136f72d
PR
126
127
128/*
129 * Byte swap defs for cross linking
130 */
131
132#if !defined(NEED_SWAP)
133
134#define md_swapin_exec_hdr(h)
135#define md_swapout_exec_hdr(h)
136#define md_swapin_symbols(s,n)
137#define md_swapout_symbols(s,n)
138#define md_swapin_zsymbols(s,n)
139#define md_swapout_zsymbols(s,n)
140#define md_swapin_reloc(r,n)
141#define md_swapout_reloc(r,n)
142#define md_swapin_link_dynamic(l)
143#define md_swapout_link_dynamic(l)
144#define md_swapin_link_dynamic_2(l)
145#define md_swapout_link_dynamic_2(l)
146#define md_swapin_ld_debug(d)
147#define md_swapout_ld_debug(d)
148#define md_swapin_rrs_hash(f,n)
149#define md_swapout_rrs_hash(f,n)
150#define md_swapin_link_object(l,n)
151#define md_swapout_link_object(l,n)
152#define md_swapout_jmpslot(j,n)
153#define md_swapout_got(g,n)
154#define md_swapin_ranlib_hdr(h,n)
155#define md_swapout_ranlib_hdr(h,n)
156
157#endif /* NEED_SWAP */
158
159#ifdef CROSS_LINKER
160
161#ifdef NEED_SWAP
162
163/* Define IO byte swapping routines */
164
165void md_swapin_exec_hdr __P((struct exec *));
166void md_swapout_exec_hdr __P((struct exec *));
167void md_swapin_reloc __P((struct relocation_info *, int));
168void md_swapout_reloc __P((struct relocation_info *, int));
169void md_swapout_jmpslot __P((jmpslot_t *, int));
170
171#define md_swapin_symbols(s,n) swap_symbols(s,n)
172#define md_swapout_symbols(s,n) swap_symbols(s,n)
173#define md_swapin_zsymbols(s,n) swap_zsymbols(s,n)
174#define md_swapout_zsymbols(s,n) swap_zsymbols(s,n)
175#define md_swapin_link_dynamic(l) swap_link_dynamic(l)
176#define md_swapout_link_dynamic(l) swap_link_dynamic(l)
177#define md_swapin_link_dynamic_2(l) swap_link_dynamic_2(l)
178#define md_swapout_link_dynamic_2(l) swap_link_dynamic_2(l)
179#define md_swapin_ld_debug(d) swap_ld_debug(d)
180#define md_swapout_ld_debug(d) swap_ld_debug(d)
181#define md_swapin_rrs_hash(f,n) swap_rrs_hash(f,n)
182#define md_swapout_rrs_hash(f,n) swap_rrs_hash(f,n)
183#define md_swapin_link_object(l,n) swapin_link_object(l,n)
184#define md_swapout_link_object(l,n) swapout_link_object(l,n)
185#define md_swapout_got(g,n) swap_longs((long*)(g),n)
186#define md_swapin_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
187#define md_swapout_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
188
189#define md_swap_short(x) ( (((x) >> 8) & 0xff) | (((x) & 0xff) << 8) )
190
191#define md_swap_long(x) ( (((x) >> 24) & 0xff ) | (((x) >> 8 ) & 0xff00 ) | \
192 (((x) << 8 ) & 0xff0000) | (((x) << 24) & 0xff000000))
193
194#define get_byte(p) ( ((unsigned char *)(p))[0] )
195
196#define get_short(p) ( ( ((unsigned char *)(p))[1] << 8) | \
197 ( ((unsigned char *)(p))[0] ) \
198 )
199#define get_long(p) ( ( ((unsigned char *)(p))[3] << 24) | \
200 ( ((unsigned char *)(p))[2] << 16) | \
201 ( ((unsigned char *)(p))[1] << 8 ) | \
202 ( ((unsigned char *)(p))[0] ) \
203 )
204
205#define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
206
207#define put_short(p, v) { ((unsigned char *)(p))[1] = \
208 ((((unsigned long)(v)) >> 8) & 0xff); \
209 ((unsigned char *)(p))[0] = \
210 ((((unsigned long)(v)) ) & 0xff); }
211
212#define put_long(p, v) { ((unsigned char *)(p))[3] = \
213 ((((unsigned long)(v)) >> 24) & 0xff); \
214 ((unsigned char *)(p))[2] = \
215 ((((unsigned long)(v)) >> 16) & 0xff); \
216 ((unsigned char *)(p))[1] = \
217 ((((unsigned long)(v)) >> 8) & 0xff); \
218 ((unsigned char *)(p))[0] = \
219 ((((unsigned long)(v)) ) & 0xff); }
220
221#else /* We need not swap, but must pay attention to alignment: */
222
223#define md_swap_short(x) (x)
224#define md_swap_long(x) (x)
225
226#define get_byte(p) ( ((unsigned char *)(p))[0] )
227
228#define get_short(p) ( ( ((unsigned char *)(p))[0] << 8) | \
229 ( ((unsigned char *)(p))[1] ) \
230 )
231
232#define get_long(p) ( ( ((unsigned char *)(p))[0] << 24) | \
233 ( ((unsigned char *)(p))[1] << 16) | \
234 ( ((unsigned char *)(p))[2] << 8 ) | \
235 ( ((unsigned char *)(p))[3] ) \
236 )
237
238
239#define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
240
241#define put_short(p, v) { ((unsigned char *)(p))[0] = \
242 ((((unsigned long)(v)) >> 8) & 0xff); \
243 ((unsigned char *)(p))[1] = \
244 ((((unsigned long)(v)) ) & 0xff); }
245
246#define put_long(p, v) { ((unsigned char *)(p))[0] = \
247 ((((unsigned long)(v)) >> 24) & 0xff); \
248 ((unsigned char *)(p))[1] = \
249 ((((unsigned long)(v)) >> 16) & 0xff); \
250 ((unsigned char *)(p))[2] = \
251 ((((unsigned long)(v)) >> 8) & 0xff); \
252 ((unsigned char *)(p))[3] = \
253 ((((unsigned long)(v)) ) & 0xff); }
254
255#endif /* NEED_SWAP */
256
257#else /* Not a cross linker: use native */
258
259#define md_swap_short(x) (x)
260#define md_swap_long(x) (x)
261
262#define get_byte(where) (*(char *)(where))
263#define get_short(where) (*(short *)(where))
264#define get_long(where) (*(long *)(where))
265
266#define put_byte(where,what) (*(char *)(where) = (what))
267#define put_short(where,what) (*(short *)(where) = (what))
268#define put_long(where,what) (*(long *)(where) = (what))
269
270#endif /* CROSS_LINKER */
271