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
/* Make generic code ignore STT_REGISTER dummy undefined symbols. */
74
int module_frob_arch_sections(Elf_Ehdr *hdr,
84
for (symidx = 0; sechdrs[symidx].sh_type != SHT_SYMTAB; symidx++) {
85
if (symidx == hdr->e_shnum-1) {
86
printk("%s: no symtab found.\n", mod->name);
90
sym = (Elf_Sym *)sechdrs[symidx].sh_addr;
91
strtab = (char *)sechdrs[sechdrs[symidx].sh_link].sh_addr;
93
for (i = 1; i < sechdrs[symidx].sh_size / sizeof(Elf_Sym); i++) {
94
if (sym[i].st_shndx == SHN_UNDEF) {
95
if (ELF_ST_TYPE(sym[i].st_info) == STT_REGISTER) {
96
sym[i].st_shndx = SHN_ABS;
98
char *name = strtab + sym[i].st_name;
106
int apply_relocate_add(Elf_Shdr *sechdrs,
108
unsigned int symindex,
113
Elf_Rela *rel = (void *)sechdrs[relsec].sh_addr;
118
for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
121
/* This is where to make the change */
122
location = (u8 *)sechdrs[sechdrs[relsec].sh_info].sh_addr
124
loc32 = (u32 *) location;
126
#ifdef CONFIG_SPARC64
127
BUG_ON(((u64)location >> (u64)32) != (u64)0);
128
#endif /* CONFIG_SPARC64 */
130
/* This is the symbol it is referring to. Note that all
131
undefined symbols have been resolved. */
132
sym = (Elf_Sym *)sechdrs[symindex].sh_addr
133
+ ELF_R_SYM(rel[i].r_info);
134
v = sym->st_value + rel[i].r_addend;
136
switch (ELF_R_TYPE(rel[i].r_info) & 0xff) {
137
#ifdef CONFIG_SPARC64
139
location[0] = v >> 56;
140
location[1] = v >> 48;
141
location[2] = v >> 40;
142
location[3] = v >> 32;
143
location[4] = v >> 24;
144
location[5] = v >> 16;
145
location[6] = v >> 8;
146
location[7] = v >> 0;
150
v -= (Elf_Addr) location;
154
case R_SPARC_WDISP19:
155
v -= (Elf_Addr) location;
156
*loc32 = (*loc32 & ~0x7ffff) |
157
((v >> 2) & 0x7ffff);
161
*loc32 = (*loc32 & ~0x1fff) |
163
(ELF_R_TYPE(rel[i].r_info) >> 8))
166
#endif /* CONFIG_SPARC64 */
170
location[0] = v >> 24;
171
location[1] = v >> 16;
172
location[2] = v >> 8;
173
location[3] = v >> 0;
176
case R_SPARC_WDISP30:
177
v -= (Elf_Addr) location;
178
*loc32 = (*loc32 & ~0x3fffffff) |
179
((v >> 2) & 0x3fffffff);
182
case R_SPARC_WDISP22:
183
v -= (Elf_Addr) location;
184
*loc32 = (*loc32 & ~0x3fffff) |
185
((v >> 2) & 0x3fffff);
189
*loc32 = (*loc32 & ~0x3ff) | (v & 0x3ff);
193
*loc32 = (*loc32 & ~0x3fffff) |
194
((v >> 10) & 0x3fffff);
198
printk(KERN_ERR "module %s: Unknown relocation: %x\n",
200
(int) (ELF_R_TYPE(rel[i].r_info) & 0xff));
207
#ifdef CONFIG_SPARC64
208
static void do_patch_sections(const Elf_Ehdr *hdr,
209
const Elf_Shdr *sechdrs)
211
const Elf_Shdr *s, *sun4v_1insn = NULL, *sun4v_2insn = NULL;
212
char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
214
for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
215
if (!strcmp(".sun4v_1insn_patch", secstrings + s->sh_name))
217
if (!strcmp(".sun4v_2insn_patch", secstrings + s->sh_name))
221
if (sun4v_1insn && tlb_type == hypervisor) {
222
void *p = (void *) sun4v_1insn->sh_addr;
223
sun4v_patch_1insn_range(p, p + sun4v_1insn->sh_size);
225
if (sun4v_2insn && tlb_type == hypervisor) {
226
void *p = (void *) sun4v_2insn->sh_addr;
227
sun4v_patch_2insn_range(p, p + sun4v_2insn->sh_size);
231
int module_finalize(const Elf_Ehdr *hdr,
232
const Elf_Shdr *sechdrs,
235
/* make jump label nops */
236
jump_label_apply_nops(me);
238
do_patch_sections(hdr, sechdrs);
240
/* Cheetah's I-cache is fully coherent. */
241
if (tlb_type == spitfire) {
245
for (va = 0; va < (PAGE_SIZE << 1); va += 32)
246
spitfire_put_icache_tag(va, 0x0);
247
__asm__ __volatile__("flush %g6");
252
#endif /* CONFIG_SPARC64 */