diff options
author | Paul Mundt <lethal@linux-sh.org> | 2007-11-20 01:16:25 -0500 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2008-01-27 23:18:49 -0500 |
commit | 1cb80fcfe2beafc55610ebd1cd4a03331d65f8ba (patch) | |
tree | 1562d21f0d948d9a45313c4e6d166af3cc6f0b81 /arch | |
parent | ba2727b556778f8af7cf08956d84723930a83965 (diff) |
sh: Merge sh and sh64 module.c.
This is trivial, in that they're both effectively the same for the base
relocations anyways. SH-5 doesn't need the unaligned bits, and has a
few extra relocations, which are never hit on non-SH5 parts.
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/sh/kernel/module.c | 62 | ||||
-rw-r--r-- | arch/sh64/kernel/module.c | 161 |
2 files changed, 49 insertions, 174 deletions
diff --git a/arch/sh/kernel/module.c b/arch/sh/kernel/module.c index 142a4e5b7ebc..b3d0a03b4c76 100644 --- a/arch/sh/kernel/module.c +++ b/arch/sh/kernel/module.c | |||
@@ -1,5 +1,15 @@ | |||
1 | /* Kernel module help for SH. | 1 | /* Kernel module help for SH. |
2 | 2 | ||
3 | SHcompact version by Kaz Kojima and Paul Mundt. | ||
4 | |||
5 | SHmedia bits: | ||
6 | |||
7 | Copyright 2004 SuperH (UK) Ltd | ||
8 | Author: Richard Curnow | ||
9 | |||
10 | Based on the sh version, and on code from the sh64-specific parts of | ||
11 | modutils, originally written by Richard Curnow and Ben Gaster. | ||
12 | |||
3 | This program is free software; you can redistribute it and/or modify | 13 | 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 | 14 | 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 | 15 | the Free Software Foundation; either version 2 of the License, or |
@@ -21,12 +31,6 @@ | |||
21 | #include <linux/string.h> | 31 | #include <linux/string.h> |
22 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
23 | 33 | ||
24 | #if 0 | ||
25 | #define DEBUGP printk | ||
26 | #else | ||
27 | #define DEBUGP(fmt...) | ||
28 | #endif | ||
29 | |||
30 | void *module_alloc(unsigned long size) | 34 | void *module_alloc(unsigned long size) |
31 | { | 35 | { |
32 | if (size == 0) | 36 | if (size == 0) |
@@ -52,6 +56,7 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, | |||
52 | return 0; | 56 | return 0; |
53 | } | 57 | } |
54 | 58 | ||
59 | #ifdef CONFIG_SUPERH32 | ||
55 | #define COPY_UNALIGNED_WORD(sw, tw, align) \ | 60 | #define COPY_UNALIGNED_WORD(sw, tw, align) \ |
56 | { \ | 61 | { \ |
57 | void *__s = &(sw), *__t = &(tw); \ | 62 | void *__s = &(sw), *__t = &(tw); \ |
@@ -74,6 +79,10 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, | |||
74 | break; \ | 79 | break; \ |
75 | } \ | 80 | } \ |
76 | } | 81 | } |
82 | #else | ||
83 | /* One thing SHmedia doesn't screw up! */ | ||
84 | #define COPY_UNALIGNED_WORD(sw, tw, align) { (tw) = (sw); } | ||
85 | #endif | ||
77 | 86 | ||
78 | int apply_relocate_add(Elf32_Shdr *sechdrs, | 87 | int apply_relocate_add(Elf32_Shdr *sechdrs, |
79 | const char *strtab, | 88 | const char *strtab, |
@@ -89,8 +98,8 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, | |||
89 | uint32_t value; | 98 | uint32_t value; |
90 | int align; | 99 | int align; |
91 | 100 | ||
92 | DEBUGP("Applying relocate section %u to %u\n", relsec, | 101 | pr_debug("Applying relocate section %u to %u\n", relsec, |
93 | sechdrs[relsec].sh_info); | 102 | sechdrs[relsec].sh_info); |
94 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { | 103 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { |
95 | /* This is where to make the change */ | 104 | /* This is where to make the change */ |
96 | location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr | 105 | location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr |
@@ -102,17 +111,44 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, | |||
102 | relocation = sym->st_value + rel[i].r_addend; | 111 | relocation = sym->st_value + rel[i].r_addend; |
103 | align = (int)location & 3; | 112 | align = (int)location & 3; |
104 | 113 | ||
114 | #ifdef CONFIG_SUPERH64 | ||
115 | /* For text addresses, bit2 of the st_other field indicates | ||
116 | * whether the symbol is SHmedia (1) or SHcompact (0). If | ||
117 | * SHmedia, the LSB of the symbol needs to be asserted | ||
118 | * for the CPU to be in SHmedia mode when it starts executing | ||
119 | * the branch target. */ | ||
120 | relocation |= (sym->st_other & 4); | ||
121 | #endif | ||
122 | |||
105 | switch (ELF32_R_TYPE(rel[i].r_info)) { | 123 | switch (ELF32_R_TYPE(rel[i].r_info)) { |
106 | case R_SH_DIR32: | 124 | case R_SH_DIR32: |
107 | COPY_UNALIGNED_WORD (*location, value, align); | 125 | COPY_UNALIGNED_WORD (*location, value, align); |
108 | value += relocation; | 126 | value += relocation; |
109 | COPY_UNALIGNED_WORD (value, *location, align); | 127 | COPY_UNALIGNED_WORD (value, *location, align); |
110 | break; | 128 | break; |
111 | case R_SH_REL32: | 129 | case R_SH_REL32: |
112 | relocation = (relocation - (Elf32_Addr) location); | 130 | relocation = (relocation - (Elf32_Addr) location); |
113 | COPY_UNALIGNED_WORD (*location, value, align); | 131 | COPY_UNALIGNED_WORD (*location, value, align); |
114 | value += relocation; | 132 | value += relocation; |
115 | COPY_UNALIGNED_WORD (value, *location, align); | 133 | COPY_UNALIGNED_WORD (value, *location, align); |
134 | break; | ||
135 | case R_SH_IMM_LOW16: | ||
136 | *location = (*location & ~0x3fffc00) | | ||
137 | ((relocation & 0xffff) << 10); | ||
138 | break; | ||
139 | case R_SH_IMM_MEDLOW16: | ||
140 | *location = (*location & ~0x3fffc00) | | ||
141 | (((relocation >> 16) & 0xffff) << 10); | ||
142 | break; | ||
143 | case R_SH_IMM_LOW16_PCREL: | ||
144 | relocation -= (Elf32_Addr) location; | ||
145 | *location = (*location & ~0x3fffc00) | | ||
146 | ((relocation & 0xffff) << 10); | ||
147 | break; | ||
148 | case R_SH_IMM_MEDLOW16_PCREL: | ||
149 | relocation -= (Elf32_Addr) location; | ||
150 | *location = (*location & ~0x3fffc00) | | ||
151 | (((relocation >> 16) & 0xffff) << 10); | ||
116 | break; | 152 | break; |
117 | default: | 153 | default: |
118 | printk(KERN_ERR "module %s: Unknown relocation: %u\n", | 154 | printk(KERN_ERR "module %s: Unknown relocation: %u\n", |
diff --git a/arch/sh64/kernel/module.c b/arch/sh64/kernel/module.c deleted file mode 100644 index 2598f6b88b44..000000000000 --- a/arch/sh64/kernel/module.c +++ /dev/null | |||
@@ -1,161 +0,0 @@ | |||
1 | /* Kernel module help for sh64. | ||
2 | |||
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. | ||
7 | |||
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. | ||
12 | |||
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 | ||
16 | |||
17 | Copyright 2004 SuperH (UK) Ltd | ||
18 | Author: Richard Curnow | ||
19 | |||
20 | Based on the sh version, and on code from the sh64-specific parts of | ||
21 | modutils, originally written by Richard Curnow and Ben Gaster. | ||
22 | |||
23 | */ | ||
24 | #include <linux/moduleloader.h> | ||
25 | #include <linux/elf.h> | ||
26 | #include <linux/vmalloc.h> | ||
27 | #include <linux/fs.h> | ||
28 | #include <linux/string.h> | ||
29 | #include <linux/kernel.h> | ||
30 | |||
31 | #if 0 | ||
32 | #define DEBUGP printk | ||
33 | #else | ||
34 | #define DEBUGP(fmt...) | ||
35 | #endif | ||
36 | |||
37 | void *module_alloc(unsigned long size) | ||
38 | { | ||
39 | if (size == 0) | ||
40 | return NULL; | ||
41 | return vmalloc(size); | ||
42 | } | ||
43 | |||
44 | |||
45 | /* Free memory returned from module_alloc */ | ||
46 | void module_free(struct module *mod, void *module_region) | ||
47 | { | ||
48 | vfree(module_region); | ||
49 | /* FIXME: If module_region == mod->init_region, trim exception | ||
50 | table entries. */ | ||
51 | } | ||
52 | |||
53 | /* We don't need anything special. */ | ||
54 | int module_frob_arch_sections(Elf_Ehdr *hdr, | ||
55 | Elf_Shdr *sechdrs, | ||
56 | char *secstrings, | ||
57 | struct module *mod) | ||
58 | { | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | int apply_relocate_add(Elf32_Shdr *sechdrs, | ||
63 | const char *strtab, | ||
64 | unsigned int symindex, | ||
65 | unsigned int relsec, | ||
66 | struct module *me) | ||
67 | { | ||
68 | unsigned int i; | ||
69 | Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr; | ||
70 | Elf32_Sym *sym; | ||
71 | Elf32_Addr relocation; | ||
72 | uint32_t *location; | ||
73 | int align; | ||
74 | int is_shmedia; | ||
75 | |||
76 | DEBUGP("Applying relocate section %u to %u\n", relsec, | ||
77 | sechdrs[relsec].sh_info); | ||
78 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { | ||
79 | /* This is where to make the change */ | ||
80 | location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr | ||
81 | + rel[i].r_offset; | ||
82 | /* This is the symbol it is referring to. Note that all | ||
83 | undefined symbols have been resolved. */ | ||
84 | sym = (Elf32_Sym *)sechdrs[symindex].sh_addr | ||
85 | + ELF32_R_SYM(rel[i].r_info); | ||
86 | relocation = sym->st_value + rel[i].r_addend; | ||
87 | align = (int)location & 3; | ||
88 | |||
89 | /* For text addresses, bit2 of the st_other field indicates | ||
90 | * whether the symbol is SHmedia (1) or SHcompact (0). If | ||
91 | * SHmedia, the LSB of the symbol needs to be asserted | ||
92 | * for the CPU to be in SHmedia mode when it starts executing | ||
93 | * the branch target. */ | ||
94 | is_shmedia = (sym->st_other & 4) ? 1 : 0; | ||
95 | if (is_shmedia) { | ||
96 | relocation |= 1; | ||
97 | } | ||
98 | |||
99 | switch (ELF32_R_TYPE(rel[i].r_info)) { | ||
100 | case R_SH_DIR32: | ||
101 | DEBUGP("R_SH_DIR32 @%08lx = %08lx\n", (unsigned long) location, (unsigned long) relocation); | ||
102 | *location += relocation; | ||
103 | break; | ||
104 | case R_SH_REL32: | ||
105 | DEBUGP("R_SH_REL32 @%08lx = %08lx\n", (unsigned long) location, (unsigned long) relocation); | ||
106 | relocation -= (Elf32_Addr) location; | ||
107 | *location += relocation; | ||
108 | break; | ||
109 | case R_SH_IMM_LOW16: | ||
110 | DEBUGP("R_SH_IMM_LOW16 @%08lx = %08lx\n", (unsigned long) location, (unsigned long) relocation); | ||
111 | *location = (*location & ~0x3fffc00) | | ||
112 | ((relocation & 0xffff) << 10); | ||
113 | break; | ||
114 | case R_SH_IMM_MEDLOW16: | ||
115 | DEBUGP("R_SH_IMM_MEDLOW16 @%08lx = %08lx\n", (unsigned long) location, (unsigned long) relocation); | ||
116 | *location = (*location & ~0x3fffc00) | | ||
117 | (((relocation >> 16) & 0xffff) << 10); | ||
118 | break; | ||
119 | case R_SH_IMM_LOW16_PCREL: | ||
120 | DEBUGP("R_SH_IMM_LOW16_PCREL @%08lx = %08lx\n", (unsigned long) location, (unsigned long) relocation); | ||
121 | relocation -= (Elf32_Addr) location; | ||
122 | *location = (*location & ~0x3fffc00) | | ||
123 | ((relocation & 0xffff) << 10); | ||
124 | break; | ||
125 | case R_SH_IMM_MEDLOW16_PCREL: | ||
126 | DEBUGP("R_SH_IMM_MEDLOW16_PCREL @%08lx = %08lx\n", (unsigned long) location, (unsigned long) relocation); | ||
127 | relocation -= (Elf32_Addr) location; | ||
128 | *location = (*location & ~0x3fffc00) | | ||
129 | (((relocation >> 16) & 0xffff) << 10); | ||
130 | break; | ||
131 | default: | ||
132 | printk(KERN_ERR "module %s: Unknown relocation: %u\n", | ||
133 | me->name, ELF32_R_TYPE(rel[i].r_info)); | ||
134 | return -ENOEXEC; | ||
135 | } | ||
136 | } | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | int apply_relocate(Elf32_Shdr *sechdrs, | ||
141 | const char *strtab, | ||
142 | unsigned int symindex, | ||
143 | unsigned int relsec, | ||
144 | struct module *me) | ||
145 | { | ||
146 | printk(KERN_ERR "module %s: REL RELOCATION unsupported\n", | ||
147 | me->name); | ||
148 | return -ENOEXEC; | ||
149 | } | ||
150 | |||
151 | int module_finalize(const Elf_Ehdr *hdr, | ||
152 | const Elf_Shdr *sechdrs, | ||
153 | struct module *me) | ||
154 | { | ||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | void module_arch_cleanup(struct module *mod) | ||
159 | { | ||
160 | } | ||
161 | |||