Add an installer-fetchpkgs target and other related stuff to reduce the
[dragonfly.git] / libexec / rtld-aout / i386 / 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/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 $
32  */
33
34 #ifndef __MD_H__
35 #define __MD_H__
36
37 #if defined(CROSS_LINKER) && defined(XHOST) && XHOST==sparc
38 #define NEED_SWAP
39 #endif
40
41 #define MAX_ALIGNMENT           (sizeof (long))
42
43 #ifdef NetBSD
44 #define PAGSIZ                  __LDPGSZ
45 #else
46 #define PAGSIZ                  4096
47 #endif
48
49 #if defined(NetBSD) || defined(CROSS_LINKER)
50
51 #define N_SET_FLAG(ex,f)        (oldmagic || N_GETMAGIC(ex)==QMAGIC ? (0) : \
52                                         N_SETMAGIC(ex,                  \
53                                                    N_GETMAGIC(ex),      \
54                                                    MID_MACHINE,         \
55                                                    N_GETFLAG(ex)|(f)))
56
57 #define N_IS_DYNAMIC(ex)        ((N_GETFLAG(ex) & EX_DYNAMIC))
58
59 #define N_BADMID(ex) \
60         (N_GETMID(ex) != 0 && N_GETMID(ex) != MID_MACHINE)
61
62 #endif
63
64 /*
65  * DragonFly does it differently
66  */
67 #if defined(__DragonFly__) || defined(__FreeBSD__)
68 #define N_SET_FLAG(ex,f)        (oldmagic ? (0) :                       \
69                                   (netzmagic == 0 ?                     \
70                                         N_SETMAGIC(ex,                  \
71                                                    N_GETMAGIC(ex),      \
72                                                    MID_MACHINE,         \
73                                                    N_GETFLAG(ex)|(f)) : \
74                                         N_SETMAGIC_NET(ex,              \
75                                                    N_GETMAGIC_NET(ex),  \
76                                                    MID_MACHINE,         \
77                                                    N_GETFLAG_NET(ex)|(f)) ))
78
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
83 #endif
84
85 /*
86  * Should be handled by a.out.h ?
87  */
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))
91
92 #define RELOC_STATICS_THROUGH_GOT_P(r)  (0)
93 #define JMPSLOT_NEEDS_RELOC             (0)
94
95 #define md_got_reloc(r)                 (0)
96
97 #define md_get_rt_segment_addend(r,a)   md_get_addend(r,a)
98
99 #define RELOC_INIT_SEGMENT_RELOC(r)     ((r)->r_length = 2)
100
101 /* Width of a Global Offset Table entry */
102 #define GOT_ENTRY_SIZE  4
103 typedef long    got_t;
104
105 typedef struct jmpslot {
106         u_short opcode;
107         u_short addr[2];
108         u_short reloc_index;
109 #define JMPSLOT_RELOC_MASK              0xffff
110 } jmpslot_t;
111
112 #define NOP     0x90
113 #define CALL    0xe890          /* NOP + CALL opcode */
114 #define JUMP    0xe990          /* NOP + JMP opcode */
115 #define TRAP    0xcc            /* INT 3 */
116
117 /*
118  * Byte swap defs for cross linking
119  */
120
121 #if !defined(NEED_SWAP)
122
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)
145
146 #endif /* NEED_SWAP */
147
148 #ifdef CROSS_LINKER
149
150 #define get_byte(p)     ( ((unsigned char *)(p))[0] )
151
152 #define get_short(p)    ( ( ((unsigned char *)(p))[0] << 8) | \
153                           ( ((unsigned char *)(p))[1]     )   \
154                         )
155
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]      )   \
160                         )
161
162 #define put_byte(p, v)  { ((unsigned char *)(p))[0] = ((unsigned long)(v)); }
163
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); }
168
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); }
177
178 #ifdef NEED_SWAP
179
180 /* Define IO byte swapping routines */
181
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);
187
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)
205
206 #define md_swap_short(x) ( (((x) >> 8) & 0xff) | (((x) & 0xff) << 8) )
207
208 #define md_swap_long(x) ( (((x) >> 24) & 0xff    ) | (((x) >> 8 ) & 0xff00   ) | \
209                         (((x) << 8 ) & 0xff0000) | (((x) << 24) & 0xff000000))
210
211 #else   /* We need not swap, but must pay attention to alignment: */
212
213 #define md_swap_short(x)        (x)
214 #define md_swap_long(x)         (x)
215
216 #endif /* NEED_SWAP */
217
218 #else   /* Not a cross linker: use native */
219
220 #define md_swap_short(x)                (x)
221 #define md_swap_long(x)                 (x)
222
223 #define get_byte(where)                 (*(char *)(where))
224 #define get_short(where)                (*(short *)(where))
225 #define get_long(where)                 (*(long *)(where))
226
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))
230
231 #endif /* CROSS_LINKER */
232
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 *);
244
245
246 #endif /* __MD_H__ */