Sync usage with man page.
[netbsd-mini2440.git] / libexec / ld.aout_so / arch / i386 / md.h
blob4ee9dd4031576273839b7f2a865af774febe297b
1 /* $NetBSD: md.h,v 1.14 2002/12/10 17:14:37 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.
32 #if defined(CROSS_LINKER) && defined(XHOST) && XHOST==sparc
33 #define NEED_SWAP
34 #endif
36 #define MAX_ALIGNMENT (sizeof (long))
38 #ifdef NetBSD
39 #define PAGSIZ AOUT_LDPGSZ
40 #else
41 #define PAGSIZ 4096
42 #endif
44 #if defined(NetBSD) || defined(CROSS_LINKER)
46 #define N_SET_FLAG(ex,f) (oldmagic || N_GETMAGIC(ex)==QMAGIC ? (0) : \
47 N_SETMAGIC(ex, \
48 N_GETMAGIC(ex), \
49 MID_MACHINE, \
50 N_GETFLAG(ex)|(f)))
52 #define N_IS_DYNAMIC(ex) ((N_GETFLAG(ex) & EX_DYNAMIC))
54 #define N_BADMID(ex) \
55 (N_GETMID(ex) != 0 && N_GETMID(ex) != MID_MACHINE)
57 #endif
60 * FreeBSD does it differently
62 #ifdef FreeBSD
63 #define N_SET_FLAG(ex,f) (oldmagic ? (0) : \
64 (netzmagic == 0 ? \
65 N_SETMAGIC(ex, \
66 N_GETMAGIC(ex), \
67 MID_MACHINE, \
68 N_GETFLAG(ex)|(f)) : \
69 N_SETMAGIC_NET(ex, \
70 N_GETMAGIC_NET(ex), \
71 MID_MACHINE, \
72 N_GETFLAG_NET(ex)|(f)) ))
74 #define N_IS_DYNAMIC(ex) ((N_GETMAGIC_NET(ex) == ZMAGIC) ? \
75 ((N_GETFLAG_NET(ex) & EX_DYNAMIC)) : \
76 ((N_GETFLAG(ex) & EX_DYNAMIC) ))
77 #define N_BADMID(ex) 0
78 #endif
81 * Should be handled by a.out.h ?
83 #define N_ADJUST(ex) (((ex).a_entry < PAGSIZ) ? -PAGSIZ : 0)
84 #define TEXT_START(ex) (N_TXTADDR(ex) + N_ADJUST(ex))
85 #define DATA_START(ex) (N_DATADDR(ex) + N_ADJUST(ex))
87 #define RELOC_STATICS_THROUGH_GOT_P(r) (0)
88 #define JMPSLOT_NEEDS_RELOC (0)
89 #define JMPSLOT_NONEXTERN_IS_INTERMODULE (0)
91 #define md_got_reloc(r) (0)
93 #define md_get_rt_segment_addend(r,a) md_get_addend(r,a)
95 /* Width of a Global Offset Table entry */
96 #define GOT_ENTRY_SIZE 4
97 typedef long got_t;
99 typedef struct jmpslot {
100 u_short opcode;
101 u_short addr[2];
102 u_short reloc_index;
103 #define JMPSLOT_RELOC_MASK 0xffff
104 } jmpslot_t;
106 #define NOP 0x90
107 #define CALL 0xe890 /* NOP + CALL opcode */
108 #define JUMP 0xe990 /* NOP + JMP opcode */
109 #define TRAP 0xcc /* INT 3 */
112 * Byte swap defs for cross linking
115 #if !defined(NEED_SWAP)
117 #define md_swapin_exec_hdr(h)
118 #define md_swapout_exec_hdr(h)
119 #define md_swapin_symbols(s,n)
120 #define md_swapout_symbols(s,n)
121 #define md_swapin_zsymbols(s,n)
122 #define md_swapout_zsymbols(s,n)
123 #define md_swapin_reloc(r,n)
124 #define md_swapout_reloc(r,n)
125 #define md_swapin__dynamic(l)
126 #define md_swapout__dynamic(l)
127 #define md_swapin_section_dispatch_table(l)
128 #define md_swapout_section_dispatch_table(l)
129 #define md_swapin_so_debug(d)
130 #define md_swapout_so_debug(d)
131 #define md_swapin_rrs_hash(f,n)
132 #define md_swapout_rrs_hash(f,n)
133 #define md_swapin_sod(l,n)
134 #define md_swapout_sod(l,n)
135 #define md_swapout_jmpslot(j,n)
136 #define md_swapout_got(g,n)
137 #define md_swapin_ranlib_hdr(h,n)
138 #define md_swapout_ranlib_hdr(h,n)
140 #endif /* NEED_SWAP */
142 #ifdef CROSS_LINKER
144 #define get_byte(p) ( ((unsigned char *)(p))[0] )
146 #define get_short(p) ( ( ((unsigned char *)(p))[0] << 8) | \
147 ( ((unsigned char *)(p))[1] ) \
150 #define get_long(p) ( ( ((unsigned char *)(p))[0] << 24) | \
151 ( ((unsigned char *)(p))[1] << 16) | \
152 ( ((unsigned char *)(p))[2] << 8 ) | \
153 ( ((unsigned char *)(p))[3] ) \
156 #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
158 #define put_short(p, v) { ((unsigned char *)(p))[0] = \
159 ((((unsigned long)(v)) >> 8) & 0xff); \
160 ((unsigned char *)(p))[1] = \
161 ((((unsigned long)(v)) ) & 0xff); }
163 #define put_long(p, v) { ((unsigned char *)(p))[0] = \
164 ((((unsigned long)(v)) >> 24) & 0xff); \
165 ((unsigned char *)(p))[1] = \
166 ((((unsigned long)(v)) >> 16) & 0xff); \
167 ((unsigned char *)(p))[2] = \
168 ((((unsigned long)(v)) >> 8) & 0xff); \
169 ((unsigned char *)(p))[3] = \
170 ((((unsigned long)(v)) ) & 0xff); }
172 #ifdef NEED_SWAP
174 /* Define IO byte swapping routines */
176 void md_swapin_exec_hdr __P((struct exec *));
177 void md_swapout_exec_hdr __P((struct exec *));
178 void md_swapin_reloc __P((struct relocation_info *, int));
179 void md_swapout_reloc __P((struct relocation_info *, int));
180 void md_swapout_jmpslot __P((jmpslot_t *, int));
182 #define md_swapin_symbols(s,n) swap_symbols(s,n)
183 #define md_swapout_symbols(s,n) swap_symbols(s,n)
184 #define md_swapin_zsymbols(s,n) swap_zsymbols(s,n)
185 #define md_swapout_zsymbols(s,n) swap_zsymbols(s,n)
186 #define md_swapin__dynamic(l) swap__dynamic(l)
187 #define md_swapout__dynamic(l) swap__dynamic(l)
188 #define md_swapin_section_dispatch_table(l) swap_section_dispatch_table(l)
189 #define md_swapout_section_dispatch_table(l) swap_section_dispatch_table(l)
190 #define md_swapin_so_debug(d) swap_so_debug(d)
191 #define md_swapout_so_debug(d) swap_so_debug(d)
192 #define md_swapin_rrs_hash(f,n) swap_rrs_hash(f,n)
193 #define md_swapout_rrs_hash(f,n) swap_rrs_hash(f,n)
194 #define md_swapin_sod(l,n) swapin_sod(l,n)
195 #define md_swapout_sod(l,n) swapout_sod(l,n)
196 #define md_swapout_got(g,n) swap_longs((long*)(g),n)
197 #define md_swapin_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
198 #define md_swapout_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
200 #define md_swap_short(x) ( (((x) >> 8) & 0xff) | (((x) & 0xff) << 8) )
202 #define md_swap_long(x) ( (((x) >> 24) & 0xff ) | (((x) >> 8 ) & 0xff00 ) | \
203 (((x) << 8 ) & 0xff0000) | (((x) << 24) & 0xff000000))
205 #else /* We need not swap, but must pay attention to alignment: */
207 #define md_swap_short(x) (x)
208 #define md_swap_long(x) (x)
210 #endif /* NEED_SWAP */
212 #else /* Not a cross linker: use native */
214 #define md_swap_short(x) (x)
215 #define md_swap_long(x) (x)
217 #define get_byte(where) (*(char *)(where))
218 #define get_short(where) (*(short *)(where))
219 #define get_long(where) (*(long *)(where))
221 #define put_byte(where,what) (*(char *)(where) = (what))
222 #define put_short(where,what) (*(short *)(where) = (what))
223 #define put_long(where,what) (*(long *)(where) = (what))
225 #endif /* CROSS_LINKER */