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>
14 #define DEBUGP(fmt...)
18 void *module_alloc(unsigned long size
)
26 /* Free memory returned from module_alloc */
27 void module_free(struct module
*mod
, void *module_region
)
32 /* We don't need anything special. */
33 int module_frob_arch_sections(Elf_Ehdr
*hdr
,
41 int apply_relocate(Elf32_Shdr
*sechdrs
,
43 unsigned int symindex
,
48 Elf32_Rel
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
52 DEBUGP("Applying relocate section %u to %u\n", relsec
,
53 sechdrs
[relsec
].sh_info
);
54 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
55 /* This is where to make the change */
56 location
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
58 /* This is the symbol it is referring to. Note that all
59 undefined symbols have been resolved. */
60 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
61 + ELF32_R_SYM(rel
[i
].r_info
);
63 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
65 /* We add the value into the location given */
66 *location
+= sym
->st_value
;
69 /* Add the value, subtract its postition */
70 *location
+= sym
->st_value
- (uint32_t)location
;
73 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
74 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
81 int apply_relocate_add(Elf32_Shdr
*sechdrs
,
83 unsigned int symindex
,
88 Elf32_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
92 DEBUGP("Applying relocate_add section %u to %u\n", relsec
,
93 sechdrs
[relsec
].sh_info
);
94 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
95 /* This is where to make the change */
96 location
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
98 /* This is the symbol it is referring to. Note that all
99 undefined symbols have been resolved. */
100 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
101 + ELF32_R_SYM(rel
[i
].r_info
);
103 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
105 /* We add the value into the location given */
106 *location
= rel
[i
].r_addend
+ sym
->st_value
;
109 /* Add the value, subtract its postition */
110 *location
= rel
[i
].r_addend
+ sym
->st_value
- (uint32_t)location
;
113 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
114 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
121 int module_finalize(const Elf_Ehdr
*hdr
,
122 const Elf_Shdr
*sechdrs
,
125 module_fixup(mod
, mod
->arch
.fixup_start
, mod
->arch
.fixup_end
);
130 void module_arch_cleanup(struct module
*mod
)
134 #endif /* CONFIG_MODULES */
136 void module_fixup(struct module
*mod
, struct m68k_fixup_info
*start
,
137 struct m68k_fixup_info
*end
)
139 struct m68k_fixup_info
*fixup
;
141 for (fixup
= start
; fixup
< end
; fixup
++) {
142 switch (fixup
->type
) {
143 case m68k_fixup_memoffset
:
144 *(u32
*)fixup
->addr
= m68k_memoffset
;
146 case m68k_fixup_vnode_shift
:
147 *(u16
*)fixup
->addr
+= m68k_virt_to_node_shift
;