GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / m32r / kernel / module.c
blobafe73645d1459e3d87a71fbf2e6c04fb3d1cfbe1
1 /* Kernel module help for M32R.
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
18 #include <linux/moduleloader.h>
19 #include <linux/elf.h>
20 #include <linux/vmalloc.h>
21 #include <linux/fs.h>
22 #include <linux/string.h>
23 #include <linux/kernel.h>
25 #define DEBUGP(fmt...)
27 void *module_alloc(unsigned long size)
29 if (size == 0)
30 return NULL;
31 #ifdef CONFIG_MMU
32 return vmalloc_exec(size);
33 #else
34 return vmalloc(size);
35 #endif
39 /* Free memory returned from module_alloc */
40 void module_free(struct module *mod, void *module_region)
42 vfree(module_region);
45 /* We don't need anything special. */
46 int module_frob_arch_sections(Elf_Ehdr *hdr,
47 Elf_Shdr *sechdrs,
48 char *secstrings,
49 struct module *mod)
51 return 0;
54 #define COPY_UNALIGNED_WORD(sw, tw, align) \
55 { \
56 void *__s = &(sw), *__t = &(tw); \
57 unsigned short *__s2 = __s, *__t2 =__t; \
58 unsigned char *__s1 = __s, *__t1 =__t; \
59 switch ((align)) \
60 { \
61 case 0: \
62 *(unsigned long *) __t = *(unsigned long *) __s; \
63 break; \
64 case 2: \
65 *__t2++ = *__s2++; \
66 *__t2 = *__s2; \
67 break; \
68 default: \
69 *__t1++ = *__s1++; \
70 *__t1++ = *__s1++; \
71 *__t1++ = *__s1++; \
72 *__t1 = *__s1; \
73 break; \
74 } \
77 #define COPY_UNALIGNED_HWORD(sw, tw, align) \
78 { \
79 void *__s = &(sw), *__t = &(tw); \
80 unsigned short *__s2 = __s, *__t2 =__t; \
81 unsigned char *__s1 = __s, *__t1 =__t; \
82 switch ((align)) \
83 { \
84 case 0: \
85 *__t2 = *__s2; \
86 break; \
87 default: \
88 *__t1++ = *__s1++; \
89 *__t1 = *__s1; \
90 break; \
91 } \
94 int apply_relocate_add(Elf32_Shdr *sechdrs,
95 const char *strtab,
96 unsigned int symindex,
97 unsigned int relsec,
98 struct module *me)
100 unsigned int i;
101 Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
102 Elf32_Sym *sym;
103 Elf32_Addr relocation;
104 uint32_t *location;
105 uint32_t value;
106 unsigned short *hlocation;
107 unsigned short hvalue;
108 int svalue;
109 int align;
111 DEBUGP("Applying relocate section %u to %u\n", relsec,
112 sechdrs[relsec].sh_info);
113 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
114 /* This is where to make the change */
115 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
116 + rel[i].r_offset;
117 /* This is the symbol it is referring to. Note that all
118 undefined symbols have been resolved. */
119 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
120 + ELF32_R_SYM(rel[i].r_info);
121 relocation = sym->st_value + rel[i].r_addend;
122 align = (int)location & 3;
124 switch (ELF32_R_TYPE(rel[i].r_info)) {
125 case R_M32R_32_RELA:
126 COPY_UNALIGNED_WORD (*location, value, align);
127 value += relocation;
128 COPY_UNALIGNED_WORD (value, *location, align);
129 break;
130 case R_M32R_HI16_ULO_RELA:
131 COPY_UNALIGNED_WORD (*location, value, align);
132 relocation = (relocation >>16) & 0xffff;
133 /* RELA must has 0 at relocation field. */
134 value += relocation;
135 COPY_UNALIGNED_WORD (value, *location, align);
136 break;
137 case R_M32R_HI16_SLO_RELA:
138 COPY_UNALIGNED_WORD (*location, value, align);
139 if (relocation & 0x8000) relocation += 0x10000;
140 relocation = (relocation >>16) & 0xffff;
141 /* RELA must has 0 at relocation field. */
142 value += relocation;
143 COPY_UNALIGNED_WORD (value, *location, align);
144 break;
145 case R_M32R_16_RELA:
146 hlocation = (unsigned short *)location;
147 relocation = relocation & 0xffff;
148 /* RELA must has 0 at relocation field. */
149 hvalue = relocation;
150 COPY_UNALIGNED_WORD (hvalue, *hlocation, align);
151 break;
152 case R_M32R_SDA16_RELA:
153 case R_M32R_LO16_RELA:
154 COPY_UNALIGNED_WORD (*location, value, align);
155 relocation = relocation & 0xffff;
156 /* RELA must has 0 at relocation field. */
157 value += relocation;
158 COPY_UNALIGNED_WORD (value, *location, align);
159 break;
160 case R_M32R_24_RELA:
161 COPY_UNALIGNED_WORD (*location, value, align);
162 relocation = relocation & 0xffffff;
163 /* RELA must has 0 at relocation field. */
164 value += relocation;
165 COPY_UNALIGNED_WORD (value, *location, align);
166 break;
167 case R_M32R_18_PCREL_RELA:
168 relocation = (relocation - (Elf32_Addr) location);
169 if (relocation < -0x20000 || 0x1fffc < relocation)
171 printk(KERN_ERR "module %s: relocation overflow: %u\n",
172 me->name, relocation);
173 return -ENOEXEC;
175 COPY_UNALIGNED_WORD (*location, value, align);
176 if (value & 0xffff)
178 /* RELA must has 0 at relocation field. */
179 printk(KERN_ERR "module %s: illegal relocation field: %u\n",
180 me->name, value);
181 return -ENOEXEC;
183 relocation = (relocation >> 2) & 0xffff;
184 value += relocation;
185 COPY_UNALIGNED_WORD (value, *location, align);
186 break;
187 case R_M32R_10_PCREL_RELA:
188 hlocation = (unsigned short *)location;
189 relocation = (relocation - (Elf32_Addr) location);
190 COPY_UNALIGNED_HWORD (*hlocation, hvalue, align);
191 svalue = (int)hvalue;
192 svalue = (signed char)svalue << 2;
193 relocation += svalue;
194 relocation = (relocation >> 2) & 0xff;
195 hvalue = hvalue & 0xff00;
196 hvalue += relocation;
197 COPY_UNALIGNED_HWORD (hvalue, *hlocation, align);
198 break;
199 case R_M32R_26_PCREL_RELA:
200 relocation = (relocation - (Elf32_Addr) location);
201 if (relocation < -0x2000000 || 0x1fffffc < relocation)
203 printk(KERN_ERR "module %s: relocation overflow: %u\n",
204 me->name, relocation);
205 return -ENOEXEC;
207 COPY_UNALIGNED_WORD (*location, value, align);
208 if (value & 0xffffff)
210 /* RELA must has 0 at relocation field. */
211 printk(KERN_ERR "module %s: illegal relocation field: %u\n",
212 me->name, value);
213 return -ENOEXEC;
215 relocation = (relocation >> 2) & 0xffffff;
216 value += relocation;
217 COPY_UNALIGNED_WORD (value, *location, align);
218 break;
219 default:
220 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
221 me->name, ELF32_R_TYPE(rel[i].r_info));
222 return -ENOEXEC;
225 return 0;
228 int apply_relocate(Elf32_Shdr *sechdrs,
229 const char *strtab,
230 unsigned int symindex,
231 unsigned int relsec,
232 struct module *me)
234 return 0;
238 int module_finalize(const Elf_Ehdr *hdr,
239 const Elf_Shdr *sechdrs,
240 struct module *me)
242 return 0;
245 void module_arch_cleanup(struct module *mod)