1 /* $NetBSD: kobj_machdep.c,v 1.2 2008/04/28 20:23:13 martin Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 * Copyright 1996-1998 John D. Polstra.
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
43 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
45 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
46 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
51 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 #include <sys/cdefs.h>
55 __KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.2 2008/04/28 20:23:13 martin Exp $");
57 #define ELFSIZE ARCH_ELFSIZE
59 #include <sys/param.h>
60 #include <sys/systm.h>
63 #include <sys/exec_elf.h>
65 #include <arm/cpufunc.h>
68 kobj_reloc(kobj_t ko
, uintptr_t relocbase
, const void *data
,
69 bool isrela
, bool local
)
74 Elf_Word rtype
, symidx
;
79 rela
= (const Elf_Rela
*)data
;
80 where
= (Elf_Addr
*) (relocbase
+ rela
->r_offset
);
81 addend
= rela
->r_addend
;
82 rtype
= ELF_R_TYPE(rela
->r_info
);
83 symidx
= ELF_R_SYM(rela
->r_info
);
85 rel
= (const Elf_Rel
*)data
;
86 where
= (Elf_Addr
*) (relocbase
+ rel
->r_offset
);
88 rtype
= ELF_R_TYPE(rel
->r_info
);
89 symidx
= ELF_R_SYM(rel
->r_info
);
93 case R_ARM_NONE
: /* none */
97 addr
= kobj_sym_lookup(ko
, symidx
);
100 *where
= addr
+ addend
;
103 case R_ARM_COPY
: /* none */
104 /* There shouldn't be copy relocations in kernel objects. */
107 case R_ARM_JUMP_SLOT
:
108 addr
= kobj_sym_lookup(ko
, symidx
);
114 case R_ARM_RELATIVE
: /* A + B */
115 addr
= relocbase
+ addend
;
124 /* Remove the instruction from the 24 bit offset */
125 addend
&= 0x00ffffff;
127 /* Sign extend if necessary */
128 if (addend
& 0x00800000)
129 addend
|= 0xff000000;
131 addr
= kobj_sym_lookup(ko
, symidx
);
135 addend
+= ((uint32_t *)addr
- (uint32_t *)where
);
137 if ((addend
& 0xff800000) != 0x00000000 &&
138 (addend
& 0xff800000) != 0xff800000) {
139 printf ("Relocation %x too far @ %p\n", addend
, where
);
142 *where
= (*where
& 0xff000000) | (addend
& 0x00ffffff);
149 printf("kobj_reloc: unexpected/invalid relocation type %d @ %p symidx %u\n",
150 rtype
, where
, symidx
);
155 kobj_machdep(kobj_t ko
, void *base
, size_t size
, bool load
)
159 cpu_idcache_wbinv_all();