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>
22 #include <linux/jump_label.h>
24 static void *module_map(unsigned long size
)
26 if (PAGE_ALIGN(size
) > MODULES_LEN
)
28 return __vmalloc_node_range(size
, 1, MODULES_VADDR
, MODULES_END
,
29 GFP_KERNEL
, PAGE_KERNEL
, -1,
30 __builtin_return_address(0));
33 static char *dot2underscore(char *name
)
38 static void *module_map(unsigned long size
)
43 /* Replace references to .func with _Func */
44 static char *dot2underscore(char *name
)
48 name
[1] = toupper(name
[1]);
52 #endif /* CONFIG_SPARC64 */
54 void *module_alloc(unsigned long size
)
58 /* We handle the zero case fine, unlike vmalloc */
62 ret
= module_map(size
);
64 ret
= ERR_PTR(-ENOMEM
);
71 /* Make generic code ignore STT_REGISTER dummy undefined symbols. */
72 int module_frob_arch_sections(Elf_Ehdr
*hdr
,
82 for (symidx
= 0; sechdrs
[symidx
].sh_type
!= SHT_SYMTAB
; symidx
++) {
83 if (symidx
== hdr
->e_shnum
-1) {
84 printk("%s: no symtab found.\n", mod
->name
);
88 sym
= (Elf_Sym
*)sechdrs
[symidx
].sh_addr
;
89 strtab
= (char *)sechdrs
[sechdrs
[symidx
].sh_link
].sh_addr
;
91 for (i
= 1; i
< sechdrs
[symidx
].sh_size
/ sizeof(Elf_Sym
); i
++) {
92 if (sym
[i
].st_shndx
== SHN_UNDEF
) {
93 if (ELF_ST_TYPE(sym
[i
].st_info
) == STT_REGISTER
) {
94 sym
[i
].st_shndx
= SHN_ABS
;
96 char *name
= strtab
+ sym
[i
].st_name
;
104 int apply_relocate_add(Elf_Shdr
*sechdrs
,
106 unsigned int symindex
,
111 Elf_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
116 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
119 /* This is where to make the change */
120 location
= (u8
*)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
122 loc32
= (u32
*) location
;
124 #ifdef CONFIG_SPARC64
125 BUG_ON(((u64
)location
>> (u64
)32) != (u64
)0);
126 #endif /* CONFIG_SPARC64 */
128 /* This is the symbol it is referring to. Note that all
129 undefined symbols have been resolved. */
130 sym
= (Elf_Sym
*)sechdrs
[symindex
].sh_addr
131 + ELF_R_SYM(rel
[i
].r_info
);
132 v
= sym
->st_value
+ rel
[i
].r_addend
;
134 switch (ELF_R_TYPE(rel
[i
].r_info
) & 0xff) {
135 #ifdef CONFIG_SPARC64
137 location
[0] = v
>> 56;
138 location
[1] = v
>> 48;
139 location
[2] = v
>> 40;
140 location
[3] = v
>> 32;
141 location
[4] = v
>> 24;
142 location
[5] = v
>> 16;
143 location
[6] = v
>> 8;
144 location
[7] = v
>> 0;
148 v
-= (Elf_Addr
) location
;
152 case R_SPARC_WDISP19
:
153 v
-= (Elf_Addr
) location
;
154 *loc32
= (*loc32
& ~0x7ffff) |
155 ((v
>> 2) & 0x7ffff);
159 *loc32
= (*loc32
& ~0x1fff) |
161 (ELF_R_TYPE(rel
[i
].r_info
) >> 8))
164 #endif /* CONFIG_SPARC64 */
168 location
[0] = v
>> 24;
169 location
[1] = v
>> 16;
170 location
[2] = v
>> 8;
171 location
[3] = v
>> 0;
174 case R_SPARC_WDISP30
:
175 v
-= (Elf_Addr
) location
;
176 *loc32
= (*loc32
& ~0x3fffffff) |
177 ((v
>> 2) & 0x3fffffff);
180 case R_SPARC_WDISP22
:
181 v
-= (Elf_Addr
) location
;
182 *loc32
= (*loc32
& ~0x3fffff) |
183 ((v
>> 2) & 0x3fffff);
187 *loc32
= (*loc32
& ~0x3ff) | (v
& 0x3ff);
191 *loc32
= (*loc32
& ~0x3fffff) |
192 ((v
>> 10) & 0x3fffff);
196 printk(KERN_ERR
"module %s: Unknown relocation: %x\n",
198 (int) (ELF_R_TYPE(rel
[i
].r_info
) & 0xff));
205 #ifdef CONFIG_SPARC64
206 int module_finalize(const Elf_Ehdr
*hdr
,
207 const Elf_Shdr
*sechdrs
,
210 /* make jump label nops */
211 jump_label_apply_nops(me
);
213 /* Cheetah's I-cache is fully coherent. */
214 if (tlb_type
== spitfire
) {
218 for (va
= 0; va
< (PAGE_SIZE
<< 1); va
+= 32)
219 spitfire_put_icache_tag(va
, 0x0);
220 __asm__
__volatile__("flush %g6");
225 #endif /* CONFIG_SPARC64 */