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/libexec/rtld-aout/i386/md.h,v 1.18 1999/08/28 00:10:08 peter Exp $
31 * $DragonFly: src/libexec/rtld-aout/i386/Attic/md.h,v 1.4 2004/02/13 03:49:50 dillon Exp $
37 #if defined(CROSS_LINKER) && defined(XHOST) && XHOST==sparc
41 #define MAX_ALIGNMENT (sizeof (long))
44 #define PAGSIZ __LDPGSZ
49 #if defined(NetBSD) || defined(CROSS_LINKER)
51 #define N_SET_FLAG(ex,f) (oldmagic || N_GETMAGIC(ex)==QMAGIC ? (0) : \
57 #define N_IS_DYNAMIC(ex) ((N_GETFLAG(ex) & EX_DYNAMIC))
59 #define N_BADMID(ex) \
60 (N_GETMID(ex) != 0 && N_GETMID(ex) != MID_MACHINE)
65 * DragonFly does it differently
67 #if defined(__DragonFly__) || defined(__FreeBSD__)
68 #define N_SET_FLAG(ex,f) (oldmagic ? (0) : \
73 N_GETFLAG(ex)|(f)) : \
77 N_GETFLAG_NET(ex)|(f)) ))
79 #define N_IS_DYNAMIC(ex) ((N_GETMAGIC_NET(ex) == ZMAGIC) ? \
80 ((N_GETFLAG_NET(ex) & EX_DYNAMIC)) : \
81 ((N_GETFLAG(ex) & EX_DYNAMIC) ))
82 #define N_BADMID(ex) 0
86 * Should be handled by a.out.h ?
88 #define N_ADJUST(ex) (((ex).a_entry < PAGSIZ) ? -PAGSIZ : 0)
89 #define TEXT_START(ex) (N_TXTADDR(ex) + N_ADJUST(ex))
90 #define DATA_START(ex) (N_DATADDR(ex) + N_ADJUST(ex))
92 #define RELOC_STATICS_THROUGH_GOT_P(r) (0)
93 #define JMPSLOT_NEEDS_RELOC (0)
95 #define md_got_reloc(r) (0)
97 #define md_get_rt_segment_addend(r,a) md_get_addend(r,a)
99 #define RELOC_INIT_SEGMENT_RELOC(r) ((r)->r_length = 2)
101 /* Width of a Global Offset Table entry */
102 #define GOT_ENTRY_SIZE 4
105 typedef struct jmpslot {
109 #define JMPSLOT_RELOC_MASK 0xffff
113 #define CALL 0xe890 /* NOP + CALL opcode */
114 #define JUMP 0xe990 /* NOP + JMP opcode */
115 #define TRAP 0xcc /* INT 3 */
118 * Byte swap defs for cross linking
121 #if !defined(NEED_SWAP)
123 #define md_swapin_exec_hdr(h)
124 #define md_swapout_exec_hdr(h)
125 #define md_swapin_symbols(s,n)
126 #define md_swapout_symbols(s,n)
127 #define md_swapin_zsymbols(s,n)
128 #define md_swapout_zsymbols(s,n)
129 #define md_swapin_reloc(r,n)
130 #define md_swapout_reloc(r,n)
131 #define md_swapin__dynamic(l)
132 #define md_swapout__dynamic(l)
133 #define md_swapin_section_dispatch_table(l)
134 #define md_swapout_section_dispatch_table(l)
135 #define md_swapin_so_debug(d)
136 #define md_swapout_so_debug(d)
137 #define md_swapin_rrs_hash(f,n)
138 #define md_swapout_rrs_hash(f,n)
139 #define md_swapin_sod(l,n)
140 #define md_swapout_sod(l,n)
141 #define md_swapout_jmpslot(j,n)
142 #define md_swapout_got(g,n)
143 #define md_swapin_ranlib_hdr(h,n)
144 #define md_swapout_ranlib_hdr(h,n)
146 #endif /* NEED_SWAP */
150 #define get_byte(p) ( ((unsigned char *)(p))[0] )
152 #define get_short(p) ( ( ((unsigned char *)(p))[0] << 8) | \
153 ( ((unsigned char *)(p))[1] ) \
156 #define get_long(p) ( ( ((unsigned char *)(p))[0] << 24) | \
157 ( ((unsigned char *)(p))[1] << 16) | \
158 ( ((unsigned char *)(p))[2] << 8 ) | \
159 ( ((unsigned char *)(p))[3] ) \
162 #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
164 #define put_short(p, v) { ((unsigned char *)(p))[0] = \
165 ((((unsigned long)(v)) >> 8) & 0xff); \
166 ((unsigned char *)(p))[1] = \
167 ((((unsigned long)(v)) ) & 0xff); }
169 #define put_long(p, v) { ((unsigned char *)(p))[0] = \
170 ((((unsigned long)(v)) >> 24) & 0xff); \
171 ((unsigned char *)(p))[1] = \
172 ((((unsigned long)(v)) >> 16) & 0xff); \
173 ((unsigned char *)(p))[2] = \
174 ((((unsigned long)(v)) >> 8) & 0xff); \
175 ((unsigned char *)(p))[3] = \
176 ((((unsigned long)(v)) ) & 0xff); }
180 /* Define IO byte swapping routines */
182 void md_swapin_exec_hdr (struct exec *);
183 void md_swapout_exec_hdr (struct exec *);
184 void md_swapin_reloc (struct relocation_info *, int);
185 void md_swapout_reloc (struct relocation_info *, int);
186 void md_swapout_jmpslot (jmpslot_t *, int);
188 #define md_swapin_symbols(s,n) swap_symbols(s,n)
189 #define md_swapout_symbols(s,n) swap_symbols(s,n)
190 #define md_swapin_zsymbols(s,n) swap_zsymbols(s,n)
191 #define md_swapout_zsymbols(s,n) swap_zsymbols(s,n)
192 #define md_swapin__dynamic(l) swap__dynamic(l)
193 #define md_swapout__dynamic(l) swap__dynamic(l)
194 #define md_swapin_section_dispatch_table(l) swap_section_dispatch_table(l)
195 #define md_swapout_section_dispatch_table(l) swap_section_dispatch_table(l)
196 #define md_swapin_so_debug(d) swap_so_debug(d)
197 #define md_swapout_so_debug(d) swap_so_debug(d)
198 #define md_swapin_rrs_hash(f,n) swap_rrs_hash(f,n)
199 #define md_swapout_rrs_hash(f,n) swap_rrs_hash(f,n)
200 #define md_swapin_sod(l,n) swapin_sod(l,n)
201 #define md_swapout_sod(l,n) swapout_sod(l,n)
202 #define md_swapout_got(g,n) swap_longs((long*)(g),n)
203 #define md_swapin_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
204 #define md_swapout_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
206 #define md_swap_short(x) ( (((x) >> 8) & 0xff) | (((x) & 0xff) << 8) )
208 #define md_swap_long(x) ( (((x) >> 24) & 0xff ) | (((x) >> 8 ) & 0xff00 ) | \
209 (((x) << 8 ) & 0xff0000) | (((x) << 24) & 0xff000000))
211 #else /* We need not swap, but must pay attention to alignment: */
213 #define md_swap_short(x) (x)
214 #define md_swap_long(x) (x)
216 #endif /* NEED_SWAP */
218 #else /* Not a cross linker: use native */
220 #define md_swap_short(x) (x)
221 #define md_swap_long(x) (x)
223 #define get_byte(where) (*(char *)(where))
224 #define get_short(where) (*(short *)(where))
225 #define get_long(where) (*(long *)(where))
227 #define put_byte(where,what) (*(char *)(where) = (what))
228 #define put_short(where,what) (*(short *)(where) = (what))
229 #define put_long(where,what) (*(long *)(where) = (what))
231 #endif /* CROSS_LINKER */
233 void md_init_header (struct exec *, int, int);
234 long md_get_addend (struct relocation_info *, unsigned char *);
235 void md_relocate (struct relocation_info *, long, unsigned char *, int);
236 void md_make_jmpslot (jmpslot_t *, long, long);
237 void md_fix_jmpslot (jmpslot_t *, long, u_long);
238 void md_bind_jmpslot (u_long, caddr_t);
239 int md_make_reloc (struct relocation_info *, struct relocation_info *, int);
240 void md_make_jmpreloc (struct relocation_info *, struct relocation_info *, int);
241 void md_make_gotreloc (struct relocation_info *, struct relocation_info *, int);
242 void md_make_copyreloc (struct relocation_info *, struct relocation_info *);
243 void md_set_breakpoint (long, long *);
246 #endif /* __MD_H__ */