Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / libexec / ld.aout_so / arch / vax / md.h
blob279215a52d4954d1812d88d0511a776c8a3669c4
1 /* $NetBSD: md.h,v 1.12 2002/12/10 17:14:44 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 1024
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 \
56 && N_GETMID(ex) != MID_VAX1K)
58 #endif
61 * FreeBSD does it differently
63 #ifdef FreeBSD
64 #define N_SET_FLAG(ex,f) (oldmagic ? (0) : \
65 (netzmagic == 0 ? \
66 N_SETMAGIC(ex, \
67 N_GETMAGIC(ex), \
68 MID_MACHINE, \
69 N_GETFLAG(ex)|(f)) : \
70 N_SETMAGIC_NET(ex, \
71 N_GETMAGIC_NET(ex), \
72 MID_MACHINE, \
73 N_GETFLAG_NET(ex)|(f)) ))
75 #define N_IS_DYNAMIC(ex) ((N_GETMAGIC_NET(ex) == ZMAGIC) ? \
76 ((N_GETFLAG_NET(ex) & EX_DYNAMIC)) : \
77 ((N_GETFLAG(ex) & EX_DYNAMIC) ))
78 #define N_BADMID(ex) 0
79 #endif
82 * Should be handled by a.out.h ?
84 #define N_ADJUST(ex) (((ex).a_entry < PAGSIZ) ? -PAGSIZ : 0)
85 #define TEXT_START(ex) (N_TXTADDR(ex) + N_ADJUST(ex))
86 #define DATA_START(ex) (N_DATADDR(ex) + N_ADJUST(ex))
88 int md_convert_textreloc(struct relocation_info *);
91 #define RELOC_STATICS_THROUGH_GOT_P(r) (1)
92 #define RELOC_EXTERNAL_DATA_THROUGH_GOT_P(r) (md_convert_textreloc(r))
93 #define JMPSLOT_NONEXTERN_ARE_INTERMODULE (1)
94 #define JMPSLOT_NEEDS_RELOC (0)
96 #define md_got_reloc(r) (0)
98 #define md_get_rt_segment_addend(r,a) md_get_addend(r,a)
100 /* Width of a Global Offset Table entry */
101 #define GOT_ENTRY_SIZE 4
102 typedef long got_t;
105 * .word ^M<reg-mask>
106 * jsb L^addr
107 * callg (ap), L^addr
109 typedef struct jmpslot {
110 u_short mask;
111 u_char insn[8];
112 u_short reloc_index;
113 } jmpslot_t;
115 #define JMPSLOT_RELOC_MASK 0xffff
116 #define BPT 0x0003 /* Set a breakpoint */
119 * Byte swap defs for cross linking
122 #if !defined(NEED_SWAP)
124 #define md_swapin_exec_hdr(h)
125 #define md_swapout_exec_hdr(h)
126 #define md_swapin_symbols(s,n)
127 #define md_swapout_symbols(s,n)
128 #define md_swapin_zsymbols(s,n)
129 #define md_swapout_zsymbols(s,n)
130 #define md_swapin_reloc(r,n)
131 #define md_swapout_reloc(r,n)
132 #define md_swapin__dynamic(l)
133 #define md_swapout__dynamic(l)
134 #define md_swapin_section_dispatch_table(l)
135 #define md_swapout_section_dispatch_table(l)
136 #define md_swapin_so_debug(d)
137 #define md_swapout_so_debug(d)
138 #define md_swapin_rrs_hash(f,n)
139 #define md_swapout_rrs_hash(f,n)
140 #define md_swapin_sod(l,n)
141 #define md_swapout_sod(l,n)
142 #define md_swapout_jmpslot(j,n)
143 #define md_swapout_got(g,n)
144 #define md_swapin_ranlib_hdr(h,n)
145 #define md_swapout_ranlib_hdr(h,n)
147 #endif /* NEED_SWAP */
149 #ifdef CROSS_LINKER
151 #define get_byte(p) ( ((unsigned char *)(p))[0] )
153 #define get_short(p) ( ( ((unsigned char *)(p))[0] << 8) | \
154 ( ((unsigned char *)(p))[1] ) \
157 #define get_long(p) ( ( ((unsigned char *)(p))[0] << 24) | \
158 ( ((unsigned char *)(p))[1] << 16) | \
159 ( ((unsigned char *)(p))[2] << 8 ) | \
160 ( ((unsigned char *)(p))[3] ) \
163 #define put_byte(p, v) { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
165 #define put_short(p, v) { ((unsigned char *)(p))[0] = \
166 ((((unsigned long)(v)) >> 8) & 0xff); \
167 ((unsigned char *)(p))[1] = \
168 ((((unsigned long)(v)) ) & 0xff); }
170 #define put_long(p, v) { ((unsigned char *)(p))[0] = \
171 ((((unsigned long)(v)) >> 24) & 0xff); \
172 ((unsigned char *)(p))[1] = \
173 ((((unsigned long)(v)) >> 16) & 0xff); \
174 ((unsigned char *)(p))[2] = \
175 ((((unsigned long)(v)) >> 8) & 0xff); \
176 ((unsigned char *)(p))[3] = \
177 ((((unsigned long)(v)) ) & 0xff); }
179 #ifdef NEED_SWAP
181 /* Define IO byte swapping routines */
183 void md_swapin_exec_hdr __P((struct exec *));
184 void md_swapout_exec_hdr __P((struct exec *));
185 void md_swapin_reloc __P((struct relocation_info *, int));
186 void md_swapout_reloc __P((struct relocation_info *, int));
187 void md_swapout_jmpslot __P((jmpslot_t *, int));
189 #define md_swapin_symbols(s,n) swap_symbols(s,n)
190 #define md_swapout_symbols(s,n) swap_symbols(s,n)
191 #define md_swapin_zsymbols(s,n) swap_zsymbols(s,n)
192 #define md_swapout_zsymbols(s,n) swap_zsymbols(s,n)
193 #define md_swapin__dynamic(l) swap__dynamic(l)
194 #define md_swapout__dynamic(l) swap__dynamic(l)
195 #define md_swapin_section_dispatch_table(l) swap_section_dispatch_table(l)
196 #define md_swapout_section_dispatch_table(l) swap_section_dispatch_table(l)
197 #define md_swapin_so_debug(d) swap_so_debug(d)
198 #define md_swapout_so_debug(d) swap_so_debug(d)
199 #define md_swapin_rrs_hash(f,n) swap_rrs_hash(f,n)
200 #define md_swapout_rrs_hash(f,n) swap_rrs_hash(f,n)
201 #define md_swapin_sod(l,n) swapin_sod(l,n)
202 #define md_swapout_sod(l,n) swapout_sod(l,n)
203 #define md_swapout_got(g,n) swap_longs((long*)(g),n)
204 #define md_swapin_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
205 #define md_swapout_ranlib_hdr(h,n) swap_ranlib_hdr(h,n)
207 #define md_swap_short(x) ( (((x) >> 8) & 0xff) | (((x) & 0xff) << 8) )
209 #define md_swap_long(x) ( (((x) >> 24) & 0xff ) | (((x) >> 8 ) & 0xff00 ) | \
210 (((x) << 8 ) & 0xff0000) | (((x) << 24) & 0xff000000))
212 #else /* We need not swap, but must pay attention to alignment: */
214 #define md_swap_short(x) (x)
215 #define md_swap_long(x) (x)
217 #endif /* NEED_SWAP */
219 #else /* Not a cross linker: use native */
221 #define md_swap_short(x) (x)
222 #define md_swap_long(x) (x)
224 #define get_byte(where) (*(char *)(where))
225 #define get_short(where) (*(short *)(where))
226 #define get_long(where) (*(long *)(where))
228 #define put_byte(where,what) (*(char *)(where) = (what))
229 #define put_short(where,what) (*(short *)(where) = (what))
230 #define put_long(where,what) (*(long *)(where) = (what))
232 #endif /* CROSS_LINKER */