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/gnu/usr.bin/ld/xbits.c,v 1.7 1999/08/27 23:36:03 peter Exp $
31 * $DragonFly: src/gnu/usr.bin/ld/Attic/xbits.c,v 1.2 2003/06/17 04:25:46 dillon Exp $
35 * "Generic" byte-swap routines.
38 #include <sys/param.h>
41 #include <sys/types.h>
59 for (; n > 0; n--, lp++)
60 *lp = md_swap_long(*lp);
69 s->n_un.n_strx = md_swap_long(s->n_un.n_strx);
70 s->n_desc = md_swap_short(s->n_desc);
71 s->n_value = md_swap_long(s->n_value);
81 s->nz_strx = md_swap_long(s->nz_strx);
82 s->nz_desc = md_swap_short(s->nz_desc);
83 s->nz_value = md_swap_long(s->nz_value);
84 s->nz_size = md_swap_long(s->nz_size);
90 swap_ranlib_hdr(rlp, n)
94 for (; n; n--, rlp++) {
95 rlp->ran_un.ran_strx = md_swap_long(rlp->ran_un.ran_strx);
96 rlp->ran_off = md_swap_long(rlp->ran_off);
104 dp->d_version = md_swap_long(dp->d_version);
105 dp->d_debug = (struct so_debug *)md_swap_long((long)dp->d_debug);
106 dp->d_un.d_sdt = (struct section_dispatch_table *)
107 md_swap_long((long)dp->d_un.d_sdt);
108 dp->d_entry = (struct ld_entry *)md_swap_long((long)dp->d_entry);
112 swap_section_dispatch_table(sdp)
113 struct section_dispatch_table *sdp;
115 swap_longs((long *)sdp, sizeof(*sdp)/sizeof(long));
120 struct so_debug *ddp;
122 swap_longs((long *)ddp, sizeof(*ddp)/sizeof(long));
132 for (; n; n--, sodp++) {
133 sodp->sod_name = md_swap_long(sodp->sod_name);
134 sodp->sod_major = md_swap_short(sodp->sod_major);
135 sodp->sod_minor = md_swap_short(sodp->sod_minor);
136 sodp->sod_next = md_swap_long(sodp->sod_next);
137 bits = ((unsigned long *)sodp)[1];
138 sodp->sod_library = ((bits >> 24) & 1);
149 for (; n; n--, sodp++) {
150 sodp->sod_name = md_swap_long(sodp->sod_name);
151 sodp->sod_major = md_swap_short(sodp->sod_major);
152 sodp->sod_minor = md_swap_short(sodp->sod_minor);
153 sodp->sod_next = md_swap_long(sodp->sod_next);
154 bits = (unsigned long)(sodp->sod_library) << 24;
155 ((unsigned long *)sodp)[1] = bits;
160 swap_rrs_hash(fsp, n)
161 struct rrs_hash *fsp;
164 for (; n; n--, fsp++) {
165 fsp->rh_symbolnum = md_swap_long(fsp->rh_symbolnum);
166 fsp->rh_next = md_swap_long(fsp->rh_next);