Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / libexec / ld.aout_so / arch / arm32 / md.h
blob002df93e5e2f9740b84e08854c4ef5b5b9cb3b17
1 /* $NetBSD: md.h,v 1.4 2000/05/28 01:53:05 matt Exp $ */
3 /*
4 * Copyright (c) 1997 Mark Brinicombe
5 * Copyright (c) 1997 Causality Limited
6 * Copyright (c) 1993 Paul Kranenburg
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Paul Kranenburg.
20 * This product includes software developed by Causality Limited
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 /* Second cut for arm32 */
38 #if defined(CROSS_LINKER) && defined(XHOST) && XHOST==sparc
39 #define NEED_SWAP
40 #endif
42 #define MAX_ALIGNMENT (sizeof (long))
44 #ifdef NetBSD
45 #define PAGSIZ AOUT_LDPGSZ
46 #else
47 #define PAGSIZ 4096
48 #endif
50 #define N_SET_FLAG(ex,f) (N_SETMAGIC(ex, \
51 N_GETMAGIC(ex), \
52 MID_MACHINE, \
53 N_GETFLAG(ex)|(f)))
55 #define N_IS_DYNAMIC(ex) ((N_GETFLAG(ex) & EX_DYNAMIC))
57 #define N_BADMID(ex) (N_GETMID(ex) != MID_MACHINE)
60 * Should be handled by a.out.h ?
62 #define N_ADJUST(ex) (((ex).a_entry < PAGSIZ) ? -PAGSIZ : 0)
63 #ifdef __notyet__
64 #define TEXT_START(ex) (N_TXTADDR(ex) + N_ADJUST(ex))
65 #define DATA_START(ex) (N_DATADDR(ex) + N_ADJUST(ex))
66 #else
67 #define TEXT_START(ex) ((ex).a_entry < PAGSIZ ? 0 : 0x001000)
68 #define DATA_START(ex) (N_GETMAGIC(ex) == OMAGIC \
69 ? TEXT_START(ex) + (ex).a_text \
70 : (TEXT_START(ex) + (ex).a_text + AOUT_LDPGSZ - 1) & ~(AOUT_LDPGSZ - 1))
71 #endif
73 #define RELOC_STATICS_THROUGH_GOT_P(r) (1)
74 #define JMPSLOT_NEEDS_RELOC (1)
75 #define JMPSLOT_NONEXTERN_IS_INTERMODULE (0)
77 #define md_got_reloc(r) (-r->r_address)
79 #define md_get_rt_segment_addend(r,a) md_get_addend(r,a)
81 /* Width of a Global Offset Table entry */
82 #define GOT_ENTRY_SIZE 4
83 typedef long got_t;
85 typedef struct jmpslot {
86 u_long opcode1; /* ldr ip, [pc] */
87 u_long opcode2; /* add pc, pc, ip */
88 u_long address; /* binder/function address */
89 u_long reloc_index; /* relocation index */
90 #define JMPSLOT_RELOC_MASK 0xffffffff
91 } jmpslot_t;
93 #define SAVEPC 0xe1a0c00e /* MOV ip, lr */
94 #define CALL 0xeb000000 /* CALL opcode */
95 #define JUMP 0xe59ff000 /* LDR pc, [pc] (used as JMP) */
96 #define TRAP 0xe6000011 /* Undefined Instruction (used for bpt) */
98 #define GETSLOTADDR 0xe04fc00c /* sub ip, pc, ip */
99 #define ADDPC 0xe08ff00c /* add pc, pc, ip */
100 #define LDRPCADDR 0xe51ff004 /* ldr pc, [pc, #-4] */
101 #define GETRELADDR 0xe59fc000 /* ldr ip, [pc] */
104 void md_swapin_reloc __P((struct relocation_info *, int));
105 void md_swapout_reloc __P((struct relocation_info *, int));
108 * Byte swap defs for cross linking
111 #if !defined(NEED_SWAP)
113 #define md_swapin_exec_hdr(h)
114 #define md_swapout_exec_hdr(h)
115 #define md_swapin_symbols(s,n)
116 #define md_swapout_symbols(s,n)
117 #define md_swapin_zsymbols(s,n)
118 #define md_swapout_zsymbols(s,n)
119 #define md_swapin__dynamic(l)
120 #define md_swapout__dynamic(l)
121 #define md_swapin_section_dispatch_table(l)
122 #define md_swapout_section_dispatch_table(l)
123 #define md_swapin_so_debug(d)
124 #define md_swapout_so_debug(d)
125 #define md_swapin_rrs_hash(f,n)
126 #define md_swapout_rrs_hash(f,n)
127 #define md_swapin_sod(l,n)
128 #define md_swapout_sod(l,n)
129 #define md_swapout_jmpslot(j,n)
130 #define md_swapout_got(g,n)
131 #define md_swapin_ranlib_hdr(h,n)
132 #define md_swapout_ranlib_hdr(h,n)
134 #endif /* NEED_SWAP */
136 #ifdef CROSS_LINKER
138 #define get_byte(p) ( ((unsigned char *)(p))[0] )
140 #define get_short(p) ( ( ((unsigned char *)(p))[0] << 8) | \
141 ( ((unsigned char *)(p))[1] ) \
144 #define get_long(p) ( ( ((unsigned char *)(p))[0] << 24) | \
145 ( ((unsigned char *)(p))[1] << 16) | \
146 ( ((unsigned char *)(p))[2] << 8 ) | \
147 ( ((unsigned char *)(p))[3] ) \
150 #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
152 #define put_short(p, v) { ((unsigned char *)(p))[0] = \
153 ((((unsigned long)(v)) >> 8) & 0xff); \
154 ((unsigned char *)(p))[1] = \
155 ((((unsigned long)(v)) ) & 0xff); }
157 #define put_long(p, v) { ((unsigned char *)(p))[0] = \
158 ((((unsigned long)(v)) >> 24) & 0xff); \
159 ((unsigned char *)(p))[1] = \
160 ((((unsigned long)(v)) >> 16) & 0xff); \
161 ((unsigned char *)(p))[2] = \
162 ((((unsigned long)(v)) >> 8) & 0xff); \
163 ((unsigned char *)(p))[3] = \
164 ((((unsigned long)(v)) ) & 0xff); }
166 #ifdef NEED_SWAP
168 /* Define IO byte swapping routines */
170 void md_swapin_exec_hdr __P((struct exec *));
171 void md_swapout_exec_hdr __P((struct exec *));
172 void md_swapout_jmpslot __P((jmpslot_t *, int));
174 #define md_swapin_symbols(s,n) swap_symbols(s,n)
175 #define md_swapout_symbols(s,n) swap_symbols(s,n)
176 #define md_swapin_zsymbols(s,n) swap_zsymbols(s,n)
177 #define md_swapout_zsymbols(s,n) swap_zsymbols(s,n)
178 #define md_swapin__dynamic(l) swap__dynamic(l)
179 #define md_swapout__dynamic(l) swap__dynamic(l)
180 #define md_swapin_section_dispatch_table(l) swap_section_dispatch_table(l)
181 #define md_swapout_section_dispatch_table(l) swap_section_dispatch_table(l)
182 #define md_swapin_so_debug(d) swap_so_debug(d)
183 #define md_swapout_so_debug(d) swap_so_debug(d)
184 #define md_swapin_rrs_hash(f,n) swap_rrs_hash(f,n)
185 #define md_swapout_rrs_hash(f,n) swap_rrs_hash(f,n)
186 #define md_swapin_sod(l,n) swapin_sod(l,n)
187 #define md_swapout_sod(l,n) swapout_sod(l,n)
188 #define md_swapout_got(g,n) swap_longs((long*)(g),n)
189 #define md_swapin_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
190 #define md_swapout_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
192 #define md_swap_short(x) ( (((x) >> 8) & 0xff) | (((x) & 0xff) << 8) )
194 #define md_swap_long(x) ( (((x) >> 24) & 0xff ) | (((x) >> 8 ) & 0xff00 ) | \
195 (((x) << 8 ) & 0xff0000) | (((x) << 24) & 0xff000000))
197 #else /* We need not swap, but must pay attention to alignment: */
199 #define md_swap_short(x) (x)
200 #define md_swap_long(x) (x)
202 #endif /* NEED_SWAP */
204 #else /* Not a cross linker: use native */
206 #define md_swap_short(x) (x)
207 #define md_swap_long(x) (x)
209 #define get_byte(where) (*(char *)(where))
210 #define get_short(where) (*(short *)(where))
211 #define get_long(where) (*(long *)(where))
213 #define put_byte(where,what) (*(char *)(where) = (what))
214 #define put_short(where,what) (*(short *)(where) = (what))
215 #define put_long(where,what) (*(long *)(where) = (what))
217 #endif /* CROSS_LINKER */
220 * Define all the RELOC_ macros
222 #define RELOC_ADDRESS(r) ((r)->r_address)
223 #define RELOC_EXTERN_P(r) ((r)->r_extern)
224 #define RELOC_TYPE(r) ((r)->r_symbolnum)
225 #define RELOC_SYMBOL(r) ((r)->r_symbolnum)
226 /* #define RELOC_MEMORY_SUB_P(r) ((r)->r_neg) not used */
227 #define RELOC_MEMORY_ADD_P(r) 1
228 #undef RELOC_ADD_EXTRA
229 #define RELOC_PCREL_P(r) (((r)->r_pcrel == 1) ^ ((r)->r_length == 3))
230 #define RELOC_VALUE_RIGHTSHIFT(r) 0
231 /*#define RELOC_TARGET_SIZE(r) ((r)->r_length) not used */
232 /*#define RELOC_TARGET_BITPOS(r) 0 not used */
233 /*#define RELOC_TARGET_BITSIZE(r) 32 not used */
235 #define RELOC_JMPTAB_P(r) ((r)->r_jmptable)
236 #define RELOC_BASEREL_P(r) ((r)->r_baserel)
237 #define RELOC_RELATIVE_P(r) ((r)->r_relative)
238 #define RELOC_COPY_P(r) (0)
239 #define RELOC_LAZY_P(r) ((r)->r_jmptable)
241 /*#define CHECK_GOT_RELOC(r) RELOC_PCREL_P(r)*/
242 #define CHECK_GOT_RELOC(r) (((r)->r_pcrel == 1) && ((r)->r_length == 2))
245 * Define the range of usable Global Offset Table offsets
246 * when using arm LDR instructions with 12 bit offset (-4092 -> 4092);
247 * this is the case if the object files are compiles with -fpic'.
248 * IF a "large" model is used (i.e. -fPIC'), .word instructions
249 * are generated instead providing 32-bit addressability of the GOT table.
252 #define MAX_GOTOFF(t) ((t) == PIC_TYPE_SMALL ? 4092 : LONG_MAX)
253 #define MIN_GOTOFF(t) ((t) == PIC_TYPE_SMALL ? -4092 : LONG_MIN)
255 #define RELOC_PIC_TYPE(r) ((r)->r_baserel ? \
256 ((r)->r_length == 1 ? \
257 PIC_TYPE_SMALL : \
258 PIC_TYPE_LARGE) : \
259 PIC_TYPE_NONE)
261 #define RELOC_INIT_SEGMENT_RELOC(r)