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>
19 #include <asm/cacheflush.h>
25 #include <linux/jump_label.h>
27 static void *module_map(unsigned long size
)
29 if (PAGE_ALIGN(size
) > MODULES_LEN
)
31 return __vmalloc_node_range(size
, 1, MODULES_VADDR
, MODULES_END
,
32 GFP_KERNEL
, PAGE_KERNEL
, 0, NUMA_NO_NODE
,
33 __builtin_return_address(0));
36 static void *module_map(unsigned long size
)
40 #endif /* CONFIG_SPARC64 */
42 void *module_alloc(unsigned long size
)
46 ret
= module_map(size
);
53 /* Make generic code ignore STT_REGISTER dummy undefined symbols. */
54 int module_frob_arch_sections(Elf_Ehdr
*hdr
,
64 for (symidx
= 0; sechdrs
[symidx
].sh_type
!= SHT_SYMTAB
; symidx
++) {
65 if (symidx
== hdr
->e_shnum
-1) {
66 printk("%s: no symtab found.\n", mod
->name
);
70 sym
= (Elf_Sym
*)sechdrs
[symidx
].sh_addr
;
71 strtab
= (char *)sechdrs
[sechdrs
[symidx
].sh_link
].sh_addr
;
73 for (i
= 1; i
< sechdrs
[symidx
].sh_size
/ sizeof(Elf_Sym
); i
++) {
74 if (sym
[i
].st_shndx
== SHN_UNDEF
) {
75 if (ELF_ST_TYPE(sym
[i
].st_info
) == STT_REGISTER
)
76 sym
[i
].st_shndx
= SHN_ABS
;
82 int apply_relocate_add(Elf_Shdr
*sechdrs
,
84 unsigned int symindex
,
89 Elf_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
94 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
97 /* This is where to make the change */
98 location
= (u8
*)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
100 loc32
= (u32
*) location
;
102 #ifdef CONFIG_SPARC64
103 BUG_ON(((u64
)location
>> (u64
)32) != (u64
)0);
104 #endif /* CONFIG_SPARC64 */
106 /* This is the symbol it is referring to. Note that all
107 undefined symbols have been resolved. */
108 sym
= (Elf_Sym
*)sechdrs
[symindex
].sh_addr
109 + ELF_R_SYM(rel
[i
].r_info
);
110 v
= sym
->st_value
+ rel
[i
].r_addend
;
112 switch (ELF_R_TYPE(rel
[i
].r_info
) & 0xff) {
114 v
-= (Elf_Addr
) location
;
117 #ifdef CONFIG_SPARC64
119 location
[0] = v
>> 56;
120 location
[1] = v
>> 48;
121 location
[2] = v
>> 40;
122 location
[3] = v
>> 32;
123 location
[4] = v
>> 24;
124 location
[5] = v
>> 16;
125 location
[6] = v
>> 8;
126 location
[7] = v
>> 0;
129 case R_SPARC_WDISP19
:
130 v
-= (Elf_Addr
) location
;
131 *loc32
= (*loc32
& ~0x7ffff) |
132 ((v
>> 2) & 0x7ffff);
136 *loc32
= (*loc32
& ~0x1fff) |
138 (ELF_R_TYPE(rel
[i
].r_info
) >> 8))
141 #endif /* CONFIG_SPARC64 */
145 location
[0] = v
>> 24;
146 location
[1] = v
>> 16;
147 location
[2] = v
>> 8;
148 location
[3] = v
>> 0;
151 case R_SPARC_WDISP30
:
152 v
-= (Elf_Addr
) location
;
153 *loc32
= (*loc32
& ~0x3fffffff) |
154 ((v
>> 2) & 0x3fffffff);
157 case R_SPARC_WDISP22
:
158 v
-= (Elf_Addr
) location
;
159 *loc32
= (*loc32
& ~0x3fffff) |
160 ((v
>> 2) & 0x3fffff);
164 *loc32
= (*loc32
& ~0x3ff) | (v
& 0x3ff);
168 *loc32
= (*loc32
& ~0x3fffff) |
169 ((v
>> 10) & 0x3fffff);
173 printk(KERN_ERR
"module %s: Unknown relocation: %x\n",
175 (int) (ELF_R_TYPE(rel
[i
].r_info
) & 0xff));
182 #ifdef CONFIG_SPARC64
183 static void do_patch_sections(const Elf_Ehdr
*hdr
,
184 const Elf_Shdr
*sechdrs
)
186 const Elf_Shdr
*s
, *sun4v_1insn
= NULL
, *sun4v_2insn
= NULL
;
187 char *secstrings
= (void *)hdr
+ sechdrs
[hdr
->e_shstrndx
].sh_offset
;
189 for (s
= sechdrs
; s
< sechdrs
+ hdr
->e_shnum
; s
++) {
190 if (!strcmp(".sun4v_1insn_patch", secstrings
+ s
->sh_name
))
192 if (!strcmp(".sun4v_2insn_patch", secstrings
+ s
->sh_name
))
196 if (sun4v_1insn
&& tlb_type
== hypervisor
) {
197 void *p
= (void *) sun4v_1insn
->sh_addr
;
198 sun4v_patch_1insn_range(p
, p
+ sun4v_1insn
->sh_size
);
200 if (sun4v_2insn
&& tlb_type
== hypervisor
) {
201 void *p
= (void *) sun4v_2insn
->sh_addr
;
202 sun4v_patch_2insn_range(p
, p
+ sun4v_2insn
->sh_size
);
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 do_patch_sections(hdr
, sechdrs
);
215 /* Cheetah's I-cache is fully coherent. */
216 if (tlb_type
== spitfire
) {
220 for (va
= 0; va
< (PAGE_SIZE
<< 1); va
+= 32)
221 spitfire_put_icache_tag(va
, 0x0);
222 __asm__
__volatile__("flush %g6");
227 #endif /* CONFIG_SPARC64 */