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