1 /* Kernel module help for sparc64.
3 * Copyright (C) 2001 Rusty Russell.
4 * Copyright (C) 2002 David S. Miller.
7 #include <linux/moduleloader.h>
8 #include <linux/kernel.h>
10 #include <linux/vmalloc.h>
12 #include <linux/gfp.h>
13 #include <linux/string.h>
14 #include <linux/ctype.h>
17 #include <asm/processor.h>
18 #include <asm/spitfire.h>
24 #include <linux/jump_label.h>
26 static void *module_map(unsigned long size
)
28 if (PAGE_ALIGN(size
) > MODULES_LEN
)
30 return __vmalloc_node_range(size
, 1, MODULES_VADDR
, MODULES_END
,
31 GFP_KERNEL
, PAGE_KERNEL
, -1,
32 __builtin_return_address(0));
35 static char *dot2underscore(char *name
)
40 static void *module_map(unsigned long size
)
45 /* Replace references to .func with _Func */
46 static char *dot2underscore(char *name
)
50 name
[1] = toupper(name
[1]);
54 #endif /* CONFIG_SPARC64 */
56 void *module_alloc(unsigned long size
)
60 /* We handle the zero case fine, unlike vmalloc */
64 ret
= module_map(size
);
66 ret
= ERR_PTR(-ENOMEM
);
73 /* Free memory returned from module_core_alloc/module_init_alloc */
74 void module_free(struct module
*mod
, void *module_region
)
79 /* Make generic code ignore STT_REGISTER dummy undefined symbols. */
80 int module_frob_arch_sections(Elf_Ehdr
*hdr
,
90 for (symidx
= 0; sechdrs
[symidx
].sh_type
!= SHT_SYMTAB
; symidx
++) {
91 if (symidx
== hdr
->e_shnum
-1) {
92 printk("%s: no symtab found.\n", mod
->name
);
96 sym
= (Elf_Sym
*)sechdrs
[symidx
].sh_addr
;
97 strtab
= (char *)sechdrs
[sechdrs
[symidx
].sh_link
].sh_addr
;
99 for (i
= 1; i
< sechdrs
[symidx
].sh_size
/ sizeof(Elf_Sym
); i
++) {
100 if (sym
[i
].st_shndx
== SHN_UNDEF
) {
101 if (ELF_ST_TYPE(sym
[i
].st_info
) == STT_REGISTER
) {
102 sym
[i
].st_shndx
= SHN_ABS
;
104 char *name
= strtab
+ sym
[i
].st_name
;
105 dot2underscore(name
);
112 int apply_relocate(Elf_Shdr
*sechdrs
,
114 unsigned int symindex
,
118 printk(KERN_ERR
"module %s: non-ADD RELOCATION unsupported\n",
123 int apply_relocate_add(Elf_Shdr
*sechdrs
,
125 unsigned int symindex
,
130 Elf_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
135 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
138 /* This is where to make the change */
139 location
= (u8
*)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
141 loc32
= (u32
*) location
;
143 #ifdef CONFIG_SPARC64
144 BUG_ON(((u64
)location
>> (u64
)32) != (u64
)0);
145 #endif /* CONFIG_SPARC64 */
147 /* This is the symbol it is referring to. Note that all
148 undefined symbols have been resolved. */
149 sym
= (Elf_Sym
*)sechdrs
[symindex
].sh_addr
150 + ELF_R_SYM(rel
[i
].r_info
);
151 v
= sym
->st_value
+ rel
[i
].r_addend
;
153 switch (ELF_R_TYPE(rel
[i
].r_info
) & 0xff) {
154 #ifdef CONFIG_SPARC64
156 location
[0] = v
>> 56;
157 location
[1] = v
>> 48;
158 location
[2] = v
>> 40;
159 location
[3] = v
>> 32;
160 location
[4] = v
>> 24;
161 location
[5] = v
>> 16;
162 location
[6] = v
>> 8;
163 location
[7] = v
>> 0;
167 v
-= (Elf_Addr
) location
;
171 case R_SPARC_WDISP19
:
172 v
-= (Elf_Addr
) location
;
173 *loc32
= (*loc32
& ~0x7ffff) |
174 ((v
>> 2) & 0x7ffff);
178 *loc32
= (*loc32
& ~0x1fff) |
180 (ELF_R_TYPE(rel
[i
].r_info
) >> 8))
183 #endif /* CONFIG_SPARC64 */
187 location
[0] = v
>> 24;
188 location
[1] = v
>> 16;
189 location
[2] = v
>> 8;
190 location
[3] = v
>> 0;
193 case R_SPARC_WDISP30
:
194 v
-= (Elf_Addr
) location
;
195 *loc32
= (*loc32
& ~0x3fffffff) |
196 ((v
>> 2) & 0x3fffffff);
199 case R_SPARC_WDISP22
:
200 v
-= (Elf_Addr
) location
;
201 *loc32
= (*loc32
& ~0x3fffff) |
202 ((v
>> 2) & 0x3fffff);
206 *loc32
= (*loc32
& ~0x3ff) | (v
& 0x3ff);
210 *loc32
= (*loc32
& ~0x3fffff) |
211 ((v
>> 10) & 0x3fffff);
215 printk(KERN_ERR
"module %s: Unknown relocation: %x\n",
217 (int) (ELF_R_TYPE(rel
[i
].r_info
) & 0xff));
224 #ifdef CONFIG_SPARC64
225 static void do_patch_sections(const Elf_Ehdr
*hdr
,
226 const Elf_Shdr
*sechdrs
)
228 const Elf_Shdr
*s
, *sun4v_1insn
= NULL
, *sun4v_2insn
= NULL
;
229 char *secstrings
= (void *)hdr
+ sechdrs
[hdr
->e_shstrndx
].sh_offset
;
231 for (s
= sechdrs
; s
< sechdrs
+ hdr
->e_shnum
; s
++) {
232 if (!strcmp(".sun4v_1insn_patch", secstrings
+ s
->sh_name
))
234 if (!strcmp(".sun4v_2insn_patch", secstrings
+ s
->sh_name
))
238 if (sun4v_1insn
&& tlb_type
== hypervisor
) {
239 void *p
= (void *) sun4v_1insn
->sh_addr
;
240 sun4v_patch_1insn_range(p
, p
+ sun4v_1insn
->sh_size
);
242 if (sun4v_2insn
&& tlb_type
== hypervisor
) {
243 void *p
= (void *) sun4v_2insn
->sh_addr
;
244 sun4v_patch_2insn_range(p
, p
+ sun4v_2insn
->sh_size
);
248 int module_finalize(const Elf_Ehdr
*hdr
,
249 const Elf_Shdr
*sechdrs
,
252 /* make jump label nops */
253 jump_label_apply_nops(me
);
255 do_patch_sections(hdr
, sechdrs
);
257 /* Cheetah's I-cache is fully coherent. */
258 if (tlb_type
== spitfire
) {
262 for (va
= 0; va
< (PAGE_SIZE
<< 1); va
+= 32)
263 spitfire_put_icache_tag(va
, 0x0);
264 __asm__
__volatile__("flush %g6");
270 int module_finalize(const Elf_Ehdr
*hdr
,
271 const Elf_Shdr
*sechdrs
,
276 #endif /* CONFIG_SPARC64 */
278 void module_arch_cleanup(struct module
*mod
)