Sync usage with man page.
[netbsd-mini2440.git] / libexec / ld.aout_so / arch / powerpc / md.c
blob2eb76e423535450675eeddccd129553d13e93893
1 /* $NetBSD: md.c,v 1.5 1998/12/17 20:14:44 pk 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 #include <sys/param.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <sys/types.h>
36 #include <err.h>
37 #include <fcntl.h>
38 #include <a.out.h>
39 #include <stab.h>
40 #include <string.h>
42 #include "ld.h"
43 #ifndef RTLD
44 /* Pull in the ld(1) bits as well */
45 #include "ld_i.h"
46 #endif
48 static int reloc_target_rightshift[] = {
49 -1, 0, 2, 0, 0, 16, 16, 2,
50 -1, -1, 2, 2, -1, -1, 0, 0,
51 16, 16, 2, -1, -1, -1, -1, -1,
52 -1, -1, 0, 0, 0, 0, 16, 16
55 static int reloc_target_bitpos[] = {
56 -1, 0, 2, 0, 0, 0, 0, 2,
57 -1, -1, 2, 2, -1, -1, 0, 0,
58 0, 0, 2, -1, -1, -1, -1, -1,
59 -1, -1, 0, 0, 0, 0, 0, 0
62 static int reloc_target_size[] = {
63 -1, 4, 4, 2, 2, 2, 2, 4,
64 -1, -1, 4, 4, -1, -1, 2, 2,
65 2, 2, 4, -1, -1, -1, -1, -1,
66 -1, -1, 4, 4, 4, 2, 2, 2
69 static int reloc_target_bitsize[] = {
70 -1, 32, 24, 16, 16, 16, 16, 14,
71 -1, -1, 24, 14, -1, -1, 16, 16,
72 16, 16, 24, -1, -1, -1, -1, -1,
73 -1, -1, 32, 32, 32, 16, 16, 16
77 * Get relocation addend corresponding to relocation record RP
78 * from address ADDR
80 long
81 md_get_addend(rp, addr)
82 struct relocation_info *rp;
83 unsigned char *addr;
85 return rp->r_addend;
89 * Put RELOCATION at ADDR according to relocation record RP.
91 void
92 md_relocate(rp, relocation, addr, relocatable_output)
93 struct relocation_info *rp;
94 long relocation;
95 unsigned char *addr;
96 int relocatable_output;
98 register unsigned long mask;
99 int ha_adj = 0;
101 if (relocatable_output) {
103 * Store relocation where the next link-edit run
104 * will look for it.
106 rp->r_addend = relocation;
107 return;
109 if (rp->r_type == RELOC_16_HA
110 || rp->r_type == RELOC_GOT16_HA
111 || rp->r_type == RELOC_PLT16_HA)
112 relocation += (relocation & 0x8000) << 1;
114 relocation >>= RELOC_VALUE_RIGHTSHIFT(rp);
116 /* Unshifted mask for relocation */
117 mask = 1 << RELOC_TARGET_BITSIZE(rp) - 1;
118 mask |= mask - 1;
119 relocation &= mask;
121 /* Shift everything up to where it's going to be used */
122 relocation <<= RELOC_TARGET_BITPOS(rp);
123 mask <<= RELOC_TARGET_BITPOS(rp);
125 switch (RELOC_TARGET_SIZE(rp)) {
126 case 4:
127 *(u_long *)addr &= ~mask;
128 *(u_long *)addr |= relocation;
129 break;
130 case 2:
131 *(u_short *)addr &= ~mask;
132 *(u_short *)addr |= relocation;
133 break;
134 default:
135 errx(1, "Unknown relocation type %d", rp->r_type);
140 * Set up a "direct" transfer (ie. not through the run-time binder) from
141 * jmpslot at OFFSET to ADDR. Used by `ld' when the SYMBOLIC flag is on,
142 * and by `ld.so' after resolving the symbol.
144 void
145 md_fix_jmpslot(sp, offset, addr, first)
146 jmpslot_t *sp;
147 long offset;
148 u_long addr;
149 int first;
151 errx(1, "md_fix_jmpslot unimplemented");
154 void
155 md_set_breakpoint(where, savep)
156 long where;
157 long *savep;
159 *savep = *(long *)where;
160 *(char *)where = TRAP;
165 #ifndef RTLD
167 * Machine dependent part of claim_rrs_reloc().
168 * Set RRS relocation type.
171 md_make_reloc(rp, r, type)
172 struct relocation_info *rp, *r;
173 int type;
175 r->r_type = rp->r_type;
176 r->r_addend = rp->r_addend;
178 if (RELOC_PCREL_P(rp))
179 r->r_addend -= pc_relocation;
181 return 1;
185 * Set up a transfer from jmpslot at OFFSET (relative to the PLT table)
186 * to the binder slot (which is at offset 0 of the PLT).
188 void
189 md_make_jmpslot(sp, offset, index)
190 jmpslot_t *sp;
191 long offset;
192 long index;
194 errx(1, "md_make_jmpslot unimplemented");
198 * Update the relocation record for a RRS jmpslot.
200 void
201 md_make_jmpreloc(rp, r, type)
202 struct relocation_info *rp, *r;
203 int type;
205 errx(1, "md_make_jmpreloc unimplemented");
209 * Set relocation type for a RRS GOT relocation.
211 void
212 md_make_gotreloc(rp, r, type)
213 struct relocation_info *rp, *r;
214 int type;
216 errx(1, "md_make_gotreloc unimplemented");
220 * Set relocation type for a RRS copy operation.
222 void
223 md_make_cpyreloc(rp, r)
224 struct relocation_info *rp, *r;
226 errx(1, "md_make_cpyreloc unimplemented");
230 * Initialize (output) exec header such that useful values are
231 * obtained from subsequent N_*() macro evaluations.
233 void
234 md_init_header(hp, magic, flags)
235 struct exec *hp;
236 int magic, flags;
238 N_SETMAGIC((*hp), magic, MID_MACHINE, flags);
240 /* TEXT_START depends on the value of outheader.a_entry. */
241 if (!(link_mode & SHAREABLE))
242 hp->a_entry = PAGSIZ;
244 #endif /* RTLD */
247 #ifdef NEED_SWAP
249 * Byte swap routines for cross-linking.
252 void
253 md_swapin_exec_hdr(h)
254 struct exec *h;
256 swap_longs((long *)h + 1, sizeof(*h)/sizeof(long) - skip);
259 void
260 md_swapout_exec_hdr(h)
261 struct exec *h;
263 swap_longs((long *)h + 1, sizeof(*h)/sizeof(long) - skip);
267 void
268 md_swapin_reloc(r, n)
269 struct relocation_info *r;
270 int n;
272 errx(1, "md_swapin_reloc unimplemented");
275 void
276 md_swapout_reloc(r, n)
277 struct relocation_info *r;
278 int n;
280 errx(1, "md_swapout_reloc unimplemented");
283 void
284 md_swapout_jmpslot(j, n)
285 jmpslot_t *j;
286 int n;
288 errx(1, "md_swapout_jmpslot unimplemented");
290 #endif /* NEED_SWAP */