1 /* Kernel module help for sparc32.
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/ctype.h>
15 void *module_alloc(unsigned long size)
19 /* We handle the zero case fine, unlike vmalloc */
25 ret = ERR_PTR(-ENOMEM);
32 /* Free memory returned from module_core_alloc/module_init_alloc */
33 void module_free(struct module *mod, void *module_region)
36 /* FIXME: If module_region == mod->init_region, trim exception
40 /* Make generic code ignore STT_REGISTER dummy undefined symbols,
41 * and replace references to .func with _Func
43 int module_frob_arch_sections(Elf_Ehdr *hdr,
53 for (symidx = 0; sechdrs[symidx].sh_type != SHT_SYMTAB; symidx++) {
54 if (symidx == hdr->e_shnum-1) {
55 printk("%s: no symtab found.\n", mod->name);
59 sym = (Elf32_Sym *)sechdrs[symidx].sh_addr;
60 strtab = (char *)sechdrs[sechdrs[symidx].sh_link].sh_addr;
62 for (i = 1; i < sechdrs[symidx].sh_size / sizeof(Elf_Sym); i++) {
63 if (sym[i].st_shndx == SHN_UNDEF) {
64 if (ELF32_ST_TYPE(sym[i].st_info) == STT_REGISTER)
65 sym[i].st_shndx = SHN_ABS;
67 char *name = strtab + sym[i].st_name;
70 name[1] = toupper(name[1]);
78 int apply_relocate(Elf32_Shdr *sechdrs,
80 unsigned int symindex,
84 printk(KERN_ERR "module %s: non-ADD RELOCATION unsupported\n",
89 int apply_relocate_add(Elf32_Shdr *sechdrs,
91 unsigned int symindex,
96 Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
101 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
104 /* This is where to make the change */
105 location = (u8 *)sechdrs[sechdrs[relsec].sh_info].sh_addr
107 loc32 = (u32 *) location;
108 /* This is the symbol it is referring to. Note that all
109 undefined symbols have been resolved. */
110 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
111 + ELF32_R_SYM(rel[i].r_info);
112 v = sym->st_value + rel[i].r_addend;
114 switch (ELF32_R_TYPE(rel[i].r_info)) {
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 -= (Elf32_Addr) location;
124 *loc32 = (*loc32 & ~0x3fffffff) |
125 ((v >> 2) & 0x3fffffff);
128 case R_SPARC_WDISP22:
129 v -= (Elf32_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) (ELF32_R_TYPE(rel[i].r_info) & 0xff));
153 int module_finalize(const Elf_Ehdr *hdr,
154 const Elf_Shdr *sechdrs,
160 void module_arch_cleanup(struct module *mod)