1 // SPDX-License-Identifier: GPL-2.0
2 /* Kernel module help for sparc64.
4 * Copyright (C) 2001 Rusty Russell.
5 * Copyright (C) 2002 David S. Miller.
8 #include <linux/moduleloader.h>
9 #include <linux/kernel.h>
10 #include <linux/elf.h>
11 #include <linux/vmalloc.h>
13 #include <linux/gfp.h>
14 #include <linux/string.h>
15 #include <linux/ctype.h>
18 #include <asm/processor.h>
19 #include <asm/spitfire.h>
20 #include <asm/cacheflush.h>
24 /* Make generic code ignore STT_REGISTER dummy undefined symbols. */
25 int module_frob_arch_sections(Elf_Ehdr
*hdr
,
35 for (symidx
= 0; sechdrs
[symidx
].sh_type
!= SHT_SYMTAB
; symidx
++) {
36 if (symidx
== hdr
->e_shnum
-1) {
37 printk("%s: no symtab found.\n", mod
->name
);
41 sym
= (Elf_Sym
*)sechdrs
[symidx
].sh_addr
;
42 strtab
= (char *)sechdrs
[sechdrs
[symidx
].sh_link
].sh_addr
;
44 for (i
= 1; i
< sechdrs
[symidx
].sh_size
/ sizeof(Elf_Sym
); i
++) {
45 if (sym
[i
].st_shndx
== SHN_UNDEF
) {
46 if (ELF_ST_TYPE(sym
[i
].st_info
) == STT_REGISTER
)
47 sym
[i
].st_shndx
= SHN_ABS
;
53 int apply_relocate_add(Elf_Shdr
*sechdrs
,
55 unsigned int symindex
,
60 Elf_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
65 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
68 /* This is where to make the change */
69 location
= (u8
*)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
71 loc32
= (u32
*) location
;
74 BUG_ON(((u64
)location
>> (u64
)32) != (u64
)0);
75 #endif /* CONFIG_SPARC64 */
77 /* This is the symbol it is referring to. Note that all
78 undefined symbols have been resolved. */
79 sym
= (Elf_Sym
*)sechdrs
[symindex
].sh_addr
80 + ELF_R_SYM(rel
[i
].r_info
);
81 v
= sym
->st_value
+ rel
[i
].r_addend
;
83 switch (ELF_R_TYPE(rel
[i
].r_info
) & 0xff) {
85 v
-= (Elf_Addr
) location
;
90 location
[0] = v
>> 56;
91 location
[1] = v
>> 48;
92 location
[2] = v
>> 40;
93 location
[3] = v
>> 32;
94 location
[4] = v
>> 24;
95 location
[5] = v
>> 16;
100 case R_SPARC_WDISP19
:
101 v
-= (Elf_Addr
) location
;
102 *loc32
= (*loc32
& ~0x7ffff) |
103 ((v
>> 2) & 0x7ffff);
107 *loc32
= (*loc32
& ~0x1fff) |
109 (ELF_R_TYPE(rel
[i
].r_info
) >> 8))
112 #endif /* CONFIG_SPARC64 */
116 location
[0] = v
>> 24;
117 location
[1] = v
>> 16;
118 location
[2] = v
>> 8;
119 location
[3] = v
>> 0;
122 case R_SPARC_WDISP30
:
123 v
-= (Elf_Addr
) location
;
124 *loc32
= (*loc32
& ~0x3fffffff) |
125 ((v
>> 2) & 0x3fffffff);
128 case R_SPARC_WDISP22
:
129 v
-= (Elf_Addr
) location
;
130 *loc32
= (*loc32
& ~0x3fffff) |
131 ((v
>> 2) & 0x3fffff);
135 *loc32
= (*loc32
& ~0x3ff) | (v
& 0x3ff);
139 *loc32
= (*loc32
& ~0x3fffff) |
140 ((v
>> 10) & 0x3fffff);
144 printk(KERN_ERR
"module %s: Unknown relocation: %x\n",
146 (int) (ELF_R_TYPE(rel
[i
].r_info
) & 0xff));
153 #ifdef CONFIG_SPARC64
154 static void do_patch_sections(const Elf_Ehdr
*hdr
,
155 const Elf_Shdr
*sechdrs
)
157 const Elf_Shdr
*s
, *sun4v_1insn
= NULL
, *sun4v_2insn
= NULL
;
158 char *secstrings
= (void *)hdr
+ sechdrs
[hdr
->e_shstrndx
].sh_offset
;
160 for (s
= sechdrs
; s
< sechdrs
+ hdr
->e_shnum
; s
++) {
161 if (!strcmp(".sun4v_1insn_patch", secstrings
+ s
->sh_name
))
163 if (!strcmp(".sun4v_2insn_patch", secstrings
+ s
->sh_name
))
167 if (sun4v_1insn
&& tlb_type
== hypervisor
) {
168 void *p
= (void *) sun4v_1insn
->sh_addr
;
169 sun4v_patch_1insn_range(p
, p
+ sun4v_1insn
->sh_size
);
171 if (sun4v_2insn
&& tlb_type
== hypervisor
) {
172 void *p
= (void *) sun4v_2insn
->sh_addr
;
173 sun4v_patch_2insn_range(p
, p
+ sun4v_2insn
->sh_size
);
177 int module_finalize(const Elf_Ehdr
*hdr
,
178 const Elf_Shdr
*sechdrs
,
181 do_patch_sections(hdr
, sechdrs
);
183 /* Cheetah's I-cache is fully coherent. */
184 if (tlb_type
== spitfire
) {
188 for (va
= 0; va
< (PAGE_SIZE
<< 1); va
+= 32)
189 spitfire_put_icache_tag(va
, 0x0);
190 __asm__
__volatile__("flush %g6");
195 #endif /* CONFIG_SPARC64 */