aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc/kernel/module.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/sparc/kernel/module.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/sparc/kernel/module.c')
-rw-r--r--arch/sparc/kernel/module.c159
1 files changed, 159 insertions, 0 deletions
diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c
new file mode 100644
index 000000000000..7931d6f92819
--- /dev/null
+++ b/arch/sparc/kernel/module.c
@@ -0,0 +1,159 @@
1/* Kernel module help for sparc32.
2 *
3 * Copyright (C) 2001 Rusty Russell.
4 * Copyright (C) 2002 David S. Miller.
5 */
6
7#include <linux/moduleloader.h>
8#include <linux/kernel.h>
9#include <linux/elf.h>
10#include <linux/vmalloc.h>
11#include <linux/fs.h>
12#include <linux/string.h>
13
14void *module_alloc(unsigned long size)
15{
16 void *ret;
17
18 /* We handle the zero case fine, unlike vmalloc */
19 if (size == 0)
20 return NULL;
21
22 ret = vmalloc(size);
23 if (!ret)
24 ret = ERR_PTR(-ENOMEM);
25 else
26 memset(ret, 0, size);
27
28 return ret;
29}
30
31/* Free memory returned from module_core_alloc/module_init_alloc */
32void module_free(struct module *mod, void *module_region)
33{
34 vfree(module_region);
35 /* FIXME: If module_region == mod->init_region, trim exception
36 table entries. */
37}
38
39/* Make generic code ignore STT_REGISTER dummy undefined symbols,
40 * and replace references to .func with func as in ppc64's dedotify.
41 */
42int module_frob_arch_sections(Elf_Ehdr *hdr,
43 Elf_Shdr *sechdrs,
44 char *secstrings,
45 struct module *mod)
46{
47 unsigned int symidx;
48 Elf32_Sym *sym;
49 char *strtab;
50 int i;
51
52 for (symidx = 0; sechdrs[symidx].sh_type != SHT_SYMTAB; symidx++) {
53 if (symidx == hdr->e_shnum-1) {
54 printk("%s: no symtab found.\n", mod->name);
55 return -ENOEXEC;
56 }
57 }
58 sym = (Elf32_Sym *)sechdrs[symidx].sh_addr;
59 strtab = (char *)sechdrs[sechdrs[symidx].sh_link].sh_addr;
60
61 for (i = 1; i < sechdrs[symidx].sh_size / sizeof(Elf_Sym); i++) {
62 if (sym[i].st_shndx == SHN_UNDEF) {
63 if (ELF32_ST_TYPE(sym[i].st_info) == STT_REGISTER)
64 sym[i].st_shndx = SHN_ABS;
65 else {
66 char *name = strtab + sym[i].st_name;
67 if (name[0] == '.')
68 memmove(name, name+1, strlen(name));
69 }
70 }
71 }
72 return 0;
73}
74
75int apply_relocate(Elf32_Shdr *sechdrs,
76 const char *strtab,
77 unsigned int symindex,
78 unsigned int relsec,
79 struct module *me)
80{
81 printk(KERN_ERR "module %s: non-ADD RELOCATION unsupported\n",
82 me->name);
83 return -ENOEXEC;
84}
85
86int apply_relocate_add(Elf32_Shdr *sechdrs,
87 const char *strtab,
88 unsigned int symindex,
89 unsigned int relsec,
90 struct module *me)
91{
92 unsigned int i;
93 Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
94 Elf32_Sym *sym;
95 u8 *location;
96 u32 *loc32;
97
98 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
99 Elf32_Addr v;
100
101 /* This is where to make the change */
102 location = (u8 *)sechdrs[sechdrs[relsec].sh_info].sh_addr
103 + rel[i].r_offset;
104 loc32 = (u32 *) location;
105 /* This is the symbol it is referring to. Note that all
106 undefined symbols have been resolved. */
107 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
108 + ELF32_R_SYM(rel[i].r_info);
109 v = sym->st_value + rel[i].r_addend;
110
111 switch (ELF32_R_TYPE(rel[i].r_info)) {
112 case R_SPARC_32:
113 location[0] = v >> 24;
114 location[1] = v >> 16;
115 location[2] = v >> 8;
116 location[3] = v >> 0;
117 break;
118
119 case R_SPARC_WDISP30:
120 v -= (Elf32_Addr) location;
121 *loc32 = (*loc32 & ~0x3fffffff) |
122 ((v >> 2) & 0x3fffffff);
123 break;
124
125 case R_SPARC_WDISP22:
126 v -= (Elf32_Addr) location;
127 *loc32 = (*loc32 & ~0x3fffff) |
128 ((v >> 2) & 0x3fffff);
129 break;
130
131 case R_SPARC_LO10:
132 *loc32 = (*loc32 & ~0x3ff) | (v & 0x3ff);
133 break;
134
135 case R_SPARC_HI22:
136 *loc32 = (*loc32 & ~0x3fffff) |
137 ((v >> 10) & 0x3fffff);
138 break;
139
140 default:
141 printk(KERN_ERR "module %s: Unknown relocation: %x\n",
142 me->name,
143 (int) (ELF32_R_TYPE(rel[i].r_info) & 0xff));
144 return -ENOEXEC;
145 };
146 }
147 return 0;
148}
149
150int module_finalize(const Elf_Ehdr *hdr,
151 const Elf_Shdr *sechdrs,
152 struct module *me)
153{
154 return 0;
155}
156
157void module_arch_cleanup(struct module *mod)
158{
159}