Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / usr.bin / ld / sparc / md-static-funcs.c
1
2 /*
3  * $FreeBSD: src/gnu/usr.bin/ld/sparc/md-static-funcs.c,v 1.5 1999/08/27 23:36:04 peter Exp $
4  *
5  * Simple SPARC relocations for the benefit of self-relocation of ld.so
6  * avoiding the use of global variables (ie. reloc_bitshift[] et. al.).
7  * Only types supported are RELOC_32 and RELOC_RELATIVE.
8  *
9  * This *must* be a static function, so it is not called through a jmpslot.
10  */
11 static void
12 md_relocate_simple(r, relocation, addr)
13 struct relocation_info  *r;
14 long                    relocation;
15 char                    *addr;
16 {
17         register unsigned long  mask;
18         register unsigned long  shift;
19
20         switch (r->r_type) {
21         case RELOC_32:
22                 mask = 0xffffffff;
23                 shift = 0;
24                 break;
25         case RELOC_RELATIVE:
26                 mask = 0x003fffff;
27                 shift = 10;
28                 break;
29         }
30         relocation += (*(long *)addr & mask) << shift;
31         relocation >>= shift;
32         relocation &= mask;
33
34         *(long *) (addr) &= ~mask;
35         *(long *) (addr) |= relocation;
36 }
37