1 /* Kernel module help for SH.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include <linux/moduleloader.h>
18 #include <linux/elf.h>
19 #include <linux/vmalloc.h>
21 #include <linux/string.h>
22 #include <linux/kernel.h>
27 #define DEBUGP(fmt...)
30 void *module_alloc(unsigned long size
)
38 /* Free memory returned from module_alloc */
39 void module_free(struct module
*mod
, void *module_region
)
42 /* FIXME: If module_region == mod->init_region, trim exception
46 /* We don't need anything special. */
47 int module_frob_arch_sections(Elf_Ehdr
*hdr
,
55 #define COPY_UNALIGNED_WORD(sw, tw, align) \
57 void *__s = &(sw), *__t = &(tw); \
61 *(unsigned long *) __t = *(unsigned long *) __s; \
64 *((unsigned short *) __t)++ = *((unsigned short *) __s)++; \
65 *((unsigned short *) __t) = *((unsigned short *) __s); \
68 *((unsigned char *) __t)++ = *((unsigned char *) __s)++; \
69 *((unsigned char *) __t)++ = *((unsigned char *) __s)++; \
70 *((unsigned char *) __t)++ = *((unsigned char *) __s)++; \
71 *((unsigned char *) __t) = *((unsigned char *) __s); \
76 int apply_relocate_add(Elf32_Shdr
*sechdrs
,
78 unsigned int symindex
,
83 Elf32_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
85 Elf32_Addr relocation
;
90 DEBUGP("Applying relocate section %u to %u\n", relsec
,
91 sechdrs
[relsec
].sh_info
);
92 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
93 /* This is where to make the change */
94 location
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
96 /* This is the symbol it is referring to. Note that all
97 undefined symbols have been resolved. */
98 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
99 + ELF32_R_SYM(rel
[i
].r_info
);
100 relocation
= sym
->st_value
+ rel
[i
].r_addend
;
101 align
= (int)location
& 3;
103 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
105 COPY_UNALIGNED_WORD (*location
, value
, align
);
107 COPY_UNALIGNED_WORD (value
, *location
, align
);
110 relocation
= (relocation
- (Elf32_Addr
) location
);
111 COPY_UNALIGNED_WORD (*location
, value
, align
);
113 COPY_UNALIGNED_WORD (value
, *location
, align
);
116 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
117 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
124 int apply_relocate(Elf32_Shdr
*sechdrs
,
126 unsigned int symindex
,
130 printk(KERN_ERR
"module %s: REL RELOCATION unsupported\n",
135 int module_finalize(const Elf_Ehdr
*hdr
,
136 const Elf_Shdr
*sechdrs
,