kobj_machdep.c revision 1.1.18.2 1 1.1.18.2 rjs /* $NetBSD: kobj_machdep.c,v 1.1.18.2 2008/02/28 21:58:52 rjs Exp $ */
2 1.1.18.2 rjs
3 1.1.18.2 rjs /*-
4 1.1.18.2 rjs * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.1.18.2 rjs * All rights reserved.
6 1.1.18.2 rjs *
7 1.1.18.2 rjs * Redistribution and use in source and binary forms, with or without
8 1.1.18.2 rjs * modification, are permitted provided that the following conditions
9 1.1.18.2 rjs * are met:
10 1.1.18.2 rjs * 1. Redistributions of source code must retain the above copyright
11 1.1.18.2 rjs * notice, this list of conditions and the following disclaimer.
12 1.1.18.2 rjs * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.18.2 rjs * notice, this list of conditions and the following disclaimer in the
14 1.1.18.2 rjs * documentation and/or other materials provided with the distribution.
15 1.1.18.2 rjs * 3. All advertising materials mentioning features or use of this software
16 1.1.18.2 rjs * must display the following acknowledgement:
17 1.1.18.2 rjs * This product includes software developed by the NetBSD
18 1.1.18.2 rjs * Foundation, Inc. and its contributors.
19 1.1.18.2 rjs * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.1.18.2 rjs * contributors may be used to endorse or promote products derived
21 1.1.18.2 rjs * from this software without specific prior written permission.
22 1.1.18.2 rjs *
23 1.1.18.2 rjs * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1.18.2 rjs * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1.18.2 rjs * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1.18.2 rjs * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1.18.2 rjs * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1.18.2 rjs * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1.18.2 rjs * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1.18.2 rjs * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1.18.2 rjs * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1.18.2 rjs * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1.18.2 rjs * POSSIBILITY OF SUCH DAMAGE.
34 1.1.18.2 rjs */
35 1.1.18.2 rjs
36 1.1.18.2 rjs /*-
37 1.1.18.2 rjs * Copyright 1996-1998 John D. Polstra.
38 1.1.18.2 rjs * All rights reserved.
39 1.1.18.2 rjs *
40 1.1.18.2 rjs * Redistribution and use in source and binary forms, with or without
41 1.1.18.2 rjs * modification, are permitted provided that the following conditions
42 1.1.18.2 rjs * are met:
43 1.1.18.2 rjs * 1. Redistributions of source code must retain the above copyright
44 1.1.18.2 rjs * notice, this list of conditions and the following disclaimer.
45 1.1.18.2 rjs * 2. Redistributions in binary form must reproduce the above copyright
46 1.1.18.2 rjs * notice, this list of conditions and the following disclaimer in the
47 1.1.18.2 rjs * documentation and/or other materials provided with the distribution.
48 1.1.18.2 rjs *
49 1.1.18.2 rjs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
50 1.1.18.2 rjs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 1.1.18.2 rjs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52 1.1.18.2 rjs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
53 1.1.18.2 rjs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
54 1.1.18.2 rjs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 1.1.18.2 rjs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 1.1.18.2 rjs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 1.1.18.2 rjs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
58 1.1.18.2 rjs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 1.1.18.2 rjs */
60 1.1.18.2 rjs
61 1.1.18.2 rjs #include <sys/cdefs.h>
62 1.1.18.2 rjs __KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.1.18.2 2008/02/28 21:58:52 rjs Exp $");
63 1.1.18.2 rjs
64 1.1.18.2 rjs #define ELFSIZE ARCH_ELFSIZE
65 1.1.18.2 rjs
66 1.1.18.2 rjs #include <sys/param.h>
67 1.1.18.2 rjs #include <sys/systm.h>
68 1.1.18.2 rjs #include <sys/kobj.h>
69 1.1.18.2 rjs #include <sys/exec.h>
70 1.1.18.2 rjs #include <sys/exec_elf.h>
71 1.1.18.2 rjs
72 1.1.18.2 rjs #include <arm/cpufunc.h>
73 1.1.18.2 rjs
74 1.1.18.2 rjs int
75 1.1.18.2 rjs kobj_reloc(kobj_t ko, uintptr_t relocbase, const void *data,
76 1.1.18.2 rjs bool isrela, bool local)
77 1.1.18.2 rjs {
78 1.1.18.2 rjs Elf_Addr *where;
79 1.1.18.2 rjs Elf_Addr addr;
80 1.1.18.2 rjs Elf_Addr addend;
81 1.1.18.2 rjs Elf_Word rtype, symidx;
82 1.1.18.2 rjs const Elf_Rel *rel;
83 1.1.18.2 rjs const Elf_Rela *rela;
84 1.1.18.2 rjs
85 1.1.18.2 rjs if (isrela) {
86 1.1.18.2 rjs rela = (const Elf_Rela *)data;
87 1.1.18.2 rjs where = (Elf_Addr *) (relocbase + rela->r_offset);
88 1.1.18.2 rjs addend = rela->r_addend;
89 1.1.18.2 rjs rtype = ELF_R_TYPE(rela->r_info);
90 1.1.18.2 rjs symidx = ELF_R_SYM(rela->r_info);
91 1.1.18.2 rjs } else {
92 1.1.18.2 rjs rel = (const Elf_Rel *)data;
93 1.1.18.2 rjs where = (Elf_Addr *) (relocbase + rel->r_offset);
94 1.1.18.2 rjs addend = *where;
95 1.1.18.2 rjs rtype = ELF_R_TYPE(rel->r_info);
96 1.1.18.2 rjs symidx = ELF_R_SYM(rel->r_info);
97 1.1.18.2 rjs }
98 1.1.18.2 rjs
99 1.1.18.2 rjs switch (rtype) {
100 1.1.18.2 rjs case R_ARM_NONE: /* none */
101 1.1.18.2 rjs break;
102 1.1.18.2 rjs
103 1.1.18.2 rjs case R_ARM_ABS32:
104 1.1.18.2 rjs addr = kobj_sym_lookup(ko, symidx);
105 1.1.18.2 rjs if (addr == 0)
106 1.1.18.2 rjs return -1;
107 1.1.18.2 rjs if (*where != addr)
108 1.1.18.2 rjs *where = addr;
109 1.1.18.2 rjs
110 1.1.18.2 rjs break;
111 1.1.18.2 rjs
112 1.1.18.2 rjs case R_ARM_COPY: /* none */
113 1.1.18.2 rjs /*
114 1.1.18.2 rjs * There shouldn't be copy relocations in kernel
115 1.1.18.2 rjs * objects.
116 1.1.18.2 rjs */
117 1.1.18.2 rjs printf("kobj_reloc: unexpected R_COPY relocation\n");
118 1.1.18.2 rjs return -1;
119 1.1.18.2 rjs
120 1.1.18.2 rjs case R_ARM_JUMP_SLOT:
121 1.1.18.2 rjs addr = kobj_sym_lookup(ko, symidx);
122 1.1.18.2 rjs if (addr) {
123 1.1.18.2 rjs *where = addr;
124 1.1.18.2 rjs return 0;
125 1.1.18.2 rjs }
126 1.1.18.2 rjs return -1;
127 1.1.18.2 rjs
128 1.1.18.2 rjs case R_ARM_RELATIVE: /* A + B */
129 1.1.18.2 rjs addr = relocbase + addend;
130 1.1.18.2 rjs if (*where != addr)
131 1.1.18.2 rjs *where = addr;
132 1.1.18.2 rjs break;
133 1.1.18.2 rjs
134 1.1.18.2 rjs default:
135 1.1.18.2 rjs printf("kobj_reloc: unexpected relocation type %d\n", rtype);
136 1.1.18.2 rjs return -1;
137 1.1.18.2 rjs }
138 1.1.18.2 rjs return 0;
139 1.1.18.2 rjs }
140 1.1.18.2 rjs
141 1.1.18.2 rjs int
142 1.1.18.2 rjs kobj_machdep(kobj_t ko, void *base, size_t size, bool load)
143 1.1.18.2 rjs {
144 1.1.18.2 rjs
145 1.1.18.2 rjs if (load) {
146 1.1.18.2 rjs cpu_idcache_wbinv_all();
147 1.1.18.2 rjs cpu_tlb_flushID();
148 1.1.18.2 rjs }
149 1.1.18.2 rjs
150 1.1.18.2 rjs return 0;
151 1.1.18.2 rjs }
152