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>
16 #include <asm/processor.h>
17 #include <asm/spitfire.h>
19 static void *module_map(unsigned long size)
21 struct vm_struct *area;
23 size = PAGE_ALIGN(size);
24 if (!size || size > MODULES_LEN)
27 area = __get_vm_area(size, VM_ALLOC, MODULES_VADDR, MODULES_END);
31 return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL);
34 void *module_alloc(unsigned long size)
38 /* We handle the zero case fine, unlike vmalloc */
42 ret = module_map(size);
44 ret = ERR_PTR(-ENOMEM);
51 /* Free memory returned from module_core_alloc/module_init_alloc */
52 void module_free(struct module *mod, void *module_region)
55 /* FIXME: If module_region == mod->init_region, trim exception
59 /* Make generic code ignore STT_REGISTER dummy undefined symbols. */
60 int module_frob_arch_sections(Elf_Ehdr *hdr,
70 for (symidx = 0; sechdrs[symidx].sh_type != SHT_SYMTAB; symidx++) {
71 if (symidx == hdr->e_shnum-1) {
72 printk("%s: no symtab found.\n", mod->name);
76 sym = (Elf_Sym *)sechdrs[symidx].sh_addr;
77 strtab = (char *)sechdrs[sechdrs[symidx].sh_link].sh_addr;
79 for (i = 1; i < sechdrs[symidx].sh_size / sizeof(Elf_Sym); i++) {
80 if (sym[i].st_shndx == SHN_UNDEF &&
81 ELF_ST_TYPE(sym[i].st_info) == STT_REGISTER)
82 sym[i].st_shndx = SHN_ABS;
87 int apply_relocate(Elf_Shdr *sechdrs,
89 unsigned int symindex,
93 printk(KERN_ERR "module %s: non-ADD RELOCATION unsupported\n",
98 int apply_relocate_add(Elf_Shdr *sechdrs,
100 unsigned int symindex,
105 Elf_Rela *rel = (void *)sechdrs[relsec].sh_addr;
110 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
113 /* This is where to make the change */
114 location = (u8 *)sechdrs[sechdrs[relsec].sh_info].sh_addr
116 loc32 = (u32 *) location;
118 BUG_ON(((u64)location >> (u64)32) != (u64)0);
120 /* This is the symbol it is referring to. Note that all
121 undefined symbols have been resolved. */
122 sym = (Elf_Sym *)sechdrs[symindex].sh_addr
123 + ELF_R_SYM(rel[i].r_info);
124 v = sym->st_value + rel[i].r_addend;
126 switch (ELF_R_TYPE(rel[i].r_info) & 0xff) {
128 location[0] = v >> 56;
129 location[1] = v >> 48;
130 location[2] = v >> 40;
131 location[3] = v >> 32;
132 location[4] = v >> 24;
133 location[5] = v >> 16;
134 location[6] = v >> 8;
135 location[7] = v >> 0;
139 location[0] = v >> 24;
140 location[1] = v >> 16;
141 location[2] = v >> 8;
142 location[3] = v >> 0;
146 v -= (Elf_Addr) location;
150 case R_SPARC_WDISP30:
151 v -= (Elf_Addr) location;
152 *loc32 = (*loc32 & ~0x3fffffff) |
153 ((v >> 2) & 0x3fffffff);
156 case R_SPARC_WDISP22:
157 v -= (Elf_Addr) location;
158 *loc32 = (*loc32 & ~0x3fffff) |
159 ((v >> 2) & 0x3fffff);
162 case R_SPARC_WDISP19:
163 v -= (Elf_Addr) location;
164 *loc32 = (*loc32 & ~0x7ffff) |
165 ((v >> 2) & 0x7ffff);
169 *loc32 = (*loc32 & ~0x3ff) | (v & 0x3ff);
173 *loc32 = (*loc32 & ~0x3fffff) |
174 ((v >> 10) & 0x3fffff);
178 *loc32 = (*loc32 & ~0x1fff) |
180 (ELF_R_TYPE(rel[i].r_info) >> 8))
185 printk(KERN_ERR "module %s: Unknown relocation: %x\n",
187 (int) (ELF_R_TYPE(rel[i].r_info) & 0xff));
194 int module_finalize(const Elf_Ehdr *hdr,
195 const Elf_Shdr *sechdrs,
198 /* Cheetah's I-cache is fully coherent. */
199 if (tlb_type == spitfire) {
203 for (va = 0; va < (PAGE_SIZE << 1); va += 32)
204 spitfire_put_icache_tag(va, 0x0);
205 __asm__ __volatile__("flush %g6");
211 void module_arch_cleanup(struct module *mod)