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/string.h>
13 #include <linux/slab.h>
14 #include <linux/vmalloc.h>
17 #include <asm/processor.h>
18 #include <asm/spitfire.h>
20 static void *module_map(unsigned long size
)
22 struct vm_struct
*area
;
24 size
= PAGE_ALIGN(size
);
25 if (!size
|| size
> MODULES_LEN
)
28 area
= __get_vm_area(size
, VM_ALLOC
, MODULES_VADDR
, MODULES_END
);
32 return __vmalloc_area(area
, GFP_KERNEL
, PAGE_KERNEL
);
35 void *module_alloc(unsigned long size
)
39 /* We handle the zero case fine, unlike vmalloc */
43 ret
= module_map(size
);
45 ret
= ERR_PTR(-ENOMEM
);
52 /* Free memory returned from module_core_alloc/module_init_alloc */
53 void module_free(struct module
*mod
, void *module_region
)
56 /* FIXME: If module_region == mod->init_region, trim exception
60 /* Make generic code ignore STT_REGISTER dummy undefined symbols. */
61 int module_frob_arch_sections(Elf_Ehdr
*hdr
,
71 for (symidx
= 0; sechdrs
[symidx
].sh_type
!= SHT_SYMTAB
; symidx
++) {
72 if (symidx
== hdr
->e_shnum
-1) {
73 printk("%s: no symtab found.\n", mod
->name
);
77 sym
= (Elf64_Sym
*)sechdrs
[symidx
].sh_addr
;
78 strtab
= (char *)sechdrs
[sechdrs
[symidx
].sh_link
].sh_addr
;
80 for (i
= 1; i
< sechdrs
[symidx
].sh_size
/ sizeof(Elf_Sym
); i
++) {
81 if (sym
[i
].st_shndx
== SHN_UNDEF
&&
82 ELF64_ST_TYPE(sym
[i
].st_info
) == STT_REGISTER
)
83 sym
[i
].st_shndx
= SHN_ABS
;
88 int apply_relocate(Elf64_Shdr
*sechdrs
,
90 unsigned int symindex
,
94 printk(KERN_ERR
"module %s: non-ADD RELOCATION unsupported\n",
99 int apply_relocate_add(Elf64_Shdr
*sechdrs
,
101 unsigned int symindex
,
106 Elf64_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
111 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
114 /* This is where to make the change */
115 location
= (u8
*)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
117 loc32
= (u32
*) location
;
119 BUG_ON(((u64
)location
>> (u64
)32) != (u64
)0);
121 /* This is the symbol it is referring to. Note that all
122 undefined symbols have been resolved. */
123 sym
= (Elf64_Sym
*)sechdrs
[symindex
].sh_addr
124 + ELF64_R_SYM(rel
[i
].r_info
);
125 v
= sym
->st_value
+ rel
[i
].r_addend
;
127 switch (ELF64_R_TYPE(rel
[i
].r_info
) & 0xff) {
129 location
[0] = v
>> 56;
130 location
[1] = v
>> 48;
131 location
[2] = v
>> 40;
132 location
[3] = v
>> 32;
133 location
[4] = v
>> 24;
134 location
[5] = v
>> 16;
135 location
[6] = v
>> 8;
136 location
[7] = v
>> 0;
140 location
[0] = v
>> 24;
141 location
[1] = v
>> 16;
142 location
[2] = v
>> 8;
143 location
[3] = v
>> 0;
146 case R_SPARC_WDISP30
:
147 v
-= (Elf64_Addr
) location
;
148 *loc32
= (*loc32
& ~0x3fffffff) |
149 ((v
>> 2) & 0x3fffffff);
152 case R_SPARC_WDISP22
:
153 v
-= (Elf64_Addr
) location
;
154 *loc32
= (*loc32
& ~0x3fffff) |
155 ((v
>> 2) & 0x3fffff);
158 case R_SPARC_WDISP19
:
159 v
-= (Elf64_Addr
) location
;
160 *loc32
= (*loc32
& ~0x7ffff) |
161 ((v
>> 2) & 0x7ffff);
165 *loc32
= (*loc32
& ~0x3ff) | (v
& 0x3ff);
169 *loc32
= (*loc32
& ~0x3fffff) |
170 ((v
>> 10) & 0x3fffff);
174 *loc32
= (*loc32
& ~0x1fff) |
176 (ELF64_R_TYPE(rel
[i
].r_info
) >> 8))
181 printk(KERN_ERR
"module %s: Unknown relocation: %x\n",
183 (int) (ELF64_R_TYPE(rel
[i
].r_info
) & 0xff));
190 int module_finalize(const Elf_Ehdr
*hdr
,
191 const Elf_Shdr
*sechdrs
,
194 /* Cheetah's I-cache is fully coherent. */
195 if (tlb_type
== spitfire
) {
199 for (va
= 0; va
< (PAGE_SIZE
<< 1); va
+= 32)
200 spitfire_put_icache_tag(va
, 0x0);
201 __asm__
__volatile__("flush %g6");
207 void module_arch_cleanup(struct module
*mod
)