2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file COPYING in the main directory of this archive
7 #include <linux/moduleloader.h>
9 #include <linux/vmalloc.h>
11 #include <linux/string.h>
12 #include <linux/kernel.h>
17 #define DEBUGP(fmt...)
22 void *module_alloc(unsigned long size)
30 /* Free memory returned from module_alloc */
31 void module_free(struct module *mod, void *module_region)
36 /* We don't need anything special. */
37 int module_frob_arch_sections(Elf_Ehdr *hdr,
45 int apply_relocate(Elf32_Shdr *sechdrs,
47 unsigned int symindex,
52 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
56 DEBUGP("Applying relocate section %u to %u\n", relsec,
57 sechdrs[relsec].sh_info);
58 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
59 /* This is where to make the change */
60 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
62 /* This is the symbol it is referring to. Note that all
63 undefined symbols have been resolved. */
64 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
65 + ELF32_R_SYM(rel[i].r_info);
67 switch (ELF32_R_TYPE(rel[i].r_info)) {
69 /* We add the value into the location given */
70 *location += sym->st_value;
73 /* Add the value, subtract its postition */
74 *location += sym->st_value - (uint32_t)location;
77 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
78 me->name, ELF32_R_TYPE(rel[i].r_info));
85 int apply_relocate_add(Elf32_Shdr *sechdrs,
87 unsigned int symindex,
92 Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
96 DEBUGP("Applying relocate_add section %u to %u\n", relsec,
97 sechdrs[relsec].sh_info);
98 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
99 /* This is where to make the change */
100 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
102 /* This is the symbol it is referring to. Note that all
103 undefined symbols have been resolved. */
104 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
105 + ELF32_R_SYM(rel[i].r_info);
107 switch (ELF32_R_TYPE(rel[i].r_info)) {
109 /* We add the value into the location given */
110 *location = rel[i].r_addend + sym->st_value;
113 /* Add the value, subtract its postition */
114 *location = rel[i].r_addend + sym->st_value - (uint32_t)location;
117 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
118 me->name, ELF32_R_TYPE(rel[i].r_info));
125 int module_finalize(const Elf_Ehdr *hdr,
126 const Elf_Shdr *sechdrs,
129 module_fixup(mod, mod->arch.fixup_start, mod->arch.fixup_end);
134 void module_arch_cleanup(struct module *mod)
138 #endif /* CONFIG_MODULES */
140 void module_fixup(struct module *mod, struct m68k_fixup_info *start,
141 struct m68k_fixup_info *end)
143 struct m68k_fixup_info *fixup;
145 for (fixup = start; fixup < end; fixup++) {
146 switch (fixup->type) {
147 case m68k_fixup_memoffset:
148 *(u32 *)fixup->addr = m68k_memoffset;
150 case m68k_fixup_vnode_shift:
151 *(u16 *)fixup->addr += m68k_virt_to_node_shift;