diff options
author | Michal Simek <monstr@monstr.eu> | 2009-03-27 09:25:17 -0400 |
---|---|---|
committer | Michal Simek <monstr@monstr.eu> | 2009-03-27 09:25:17 -0400 |
commit | f6b165c6ae540c607a9a62427f1b25bc5743c0aa (patch) | |
tree | dff477a1fb22c944b191947fec6e51c6f3f629a7 | |
parent | 7fbd3232082908e2a50c6776f4779b79085161fa (diff) |
microblaze_v8: kernel modules support
Reviewed-by: Ingo Molnar <mingo@elte.hu>
Acked-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Acked-by: John Linn <john.linn@xilinx.com>
Acked-by: John Williams <john.williams@petalogix.com>
Signed-off-by: Michal Simek <monstr@monstr.eu>
-rw-r--r-- | arch/microblaze/include/asm/module.h | 37 | ||||
-rw-r--r-- | arch/microblaze/kernel/microblaze_ksyms.c | 47 | ||||
-rw-r--r-- | arch/microblaze/kernel/module.c | 151 |
3 files changed, 235 insertions, 0 deletions
diff --git a/arch/microblaze/include/asm/module.h b/arch/microblaze/include/asm/module.h new file mode 100644 index 000000000000..914565a90315 --- /dev/null +++ b/arch/microblaze/include/asm/module.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2006 Atmark Techno, Inc. | ||
3 | * | ||
4 | * This file is subject to the terms and conditions of the GNU General Public | ||
5 | * License. See the file "COPYING" in the main directory of this archive | ||
6 | * for more details. | ||
7 | */ | ||
8 | |||
9 | #ifndef _ASM_MICROBLAZE_MODULE_H | ||
10 | #define _ASM_MICROBLAZE_MODULE_H | ||
11 | |||
12 | /* Microblaze Relocations */ | ||
13 | #define R_MICROBLAZE_NONE 0 | ||
14 | #define R_MICROBLAZE_32 1 | ||
15 | #define R_MICROBLAZE_32_PCREL 2 | ||
16 | #define R_MICROBLAZE_64_PCREL 3 | ||
17 | #define R_MICROBLAZE_32_PCREL_LO 4 | ||
18 | #define R_MICROBLAZE_64 5 | ||
19 | #define R_MICROBLAZE_32_LO 6 | ||
20 | #define R_MICROBLAZE_SRO32 7 | ||
21 | #define R_MICROBLAZE_SRW32 8 | ||
22 | #define R_MICROBLAZE_64_NONE 9 | ||
23 | #define R_MICROBLAZE_32_SYM_OP_SYM 10 | ||
24 | /* Keep this the last entry. */ | ||
25 | #define R_MICROBLAZE_NUM 11 | ||
26 | |||
27 | struct mod_arch_specific { | ||
28 | int foo; | ||
29 | }; | ||
30 | |||
31 | #define Elf_Shdr Elf32_Shdr | ||
32 | #define Elf_Sym Elf32_Sym | ||
33 | #define Elf_Ehdr Elf32_Ehdr | ||
34 | |||
35 | typedef struct { volatile int counter; } module_t; | ||
36 | |||
37 | #endif /* _ASM_MICROBLAZE_MODULE_H */ | ||
diff --git a/arch/microblaze/kernel/microblaze_ksyms.c b/arch/microblaze/kernel/microblaze_ksyms.c new file mode 100644 index 000000000000..5f71790e3c3c --- /dev/null +++ b/arch/microblaze/kernel/microblaze_ksyms.c | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> | ||
3 | * Copyright (C) 2008-2009 PetaLogix | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | */ | ||
9 | |||
10 | #include <linux/module.h> | ||
11 | #include <linux/string.h> | ||
12 | #include <linux/cryptohash.h> | ||
13 | #include <linux/delay.h> | ||
14 | #include <linux/in6.h> | ||
15 | #include <linux/syscalls.h> | ||
16 | |||
17 | #include <asm/checksum.h> | ||
18 | #include <linux/io.h> | ||
19 | #include <asm/page.h> | ||
20 | #include <asm/system.h> | ||
21 | #include <linux/uaccess.h> | ||
22 | |||
23 | /* | ||
24 | * libgcc functions - functions that are used internally by the | ||
25 | * compiler... (prototypes are not correct though, but that | ||
26 | * doesn't really matter since they're not versioned). | ||
27 | */ | ||
28 | extern void __ashldi3(void); | ||
29 | EXPORT_SYMBOL(__ashldi3); | ||
30 | extern void __ashrdi3(void); | ||
31 | EXPORT_SYMBOL(__ashrdi3); | ||
32 | extern void __divsi3(void); | ||
33 | EXPORT_SYMBOL(__divsi3); | ||
34 | extern void __lshrdi3(void); | ||
35 | EXPORT_SYMBOL(__lshrdi3); | ||
36 | extern void __modsi3(void); | ||
37 | EXPORT_SYMBOL(__modsi3); | ||
38 | extern void __mulsi3(void); | ||
39 | EXPORT_SYMBOL(__mulsi3); | ||
40 | extern void __muldi3(void); | ||
41 | EXPORT_SYMBOL(__muldi3); | ||
42 | extern void __ucmpdi2(void); | ||
43 | EXPORT_SYMBOL(__ucmpdi2); | ||
44 | extern void __udivsi3(void); | ||
45 | EXPORT_SYMBOL(__udivsi3); | ||
46 | extern void __umodsi3(void); | ||
47 | EXPORT_SYMBOL(__umodsi3); | ||
diff --git a/arch/microblaze/kernel/module.c b/arch/microblaze/kernel/module.c new file mode 100644 index 000000000000..51414171326f --- /dev/null +++ b/arch/microblaze/kernel/module.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu> | ||
3 | * Copyright (C) 2007-2009 PetaLogix | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | */ | ||
9 | |||
10 | #include <linux/module.h> | ||
11 | #include <linux/moduleloader.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/elf.h> | ||
14 | #include <linux/vmalloc.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/fs.h> | ||
17 | #include <linux/string.h> | ||
18 | |||
19 | #include <asm/pgtable.h> | ||
20 | |||
21 | void *module_alloc(unsigned long size) | ||
22 | { | ||
23 | void *ret; | ||
24 | ret = (size == 0) ? NULL : vmalloc(size); | ||
25 | pr_debug("module_alloc (%08lx@%08lx)\n", size, (unsigned long int)ret); | ||
26 | return ret; | ||
27 | } | ||
28 | |||
29 | void module_free(struct module *module, void *region) | ||
30 | { | ||
31 | pr_debug("module_free(%s,%08lx)\n", module->name, | ||
32 | (unsigned long)region); | ||
33 | vfree(region); | ||
34 | } | ||
35 | |||
36 | int module_frob_arch_sections(Elf_Ehdr *hdr, | ||
37 | Elf_Shdr *sechdrs, | ||
38 | char *secstrings, | ||
39 | struct module *mod) | ||
40 | { | ||
41 | return 0; | ||
42 | } | ||
43 | |||
44 | int apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, | ||
45 | unsigned int symindex, unsigned int relsec, struct module *module) | ||
46 | { | ||
47 | printk(KERN_ERR "module %s: ADD RELOCATION unsupported\n", | ||
48 | module->name); | ||
49 | return -ENOEXEC; | ||
50 | } | ||
51 | |||
52 | int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab, | ||
53 | unsigned int symindex, unsigned int relsec, struct module *module) | ||
54 | { | ||
55 | |||
56 | unsigned int i; | ||
57 | Elf32_Rela *rela = (void *)sechdrs[relsec].sh_addr; | ||
58 | Elf32_Sym *sym; | ||
59 | unsigned long int *location; | ||
60 | unsigned long int locoffs; | ||
61 | unsigned long int value; | ||
62 | #if __GNUC__ < 4 | ||
63 | unsigned long int old_value; | ||
64 | #endif | ||
65 | |||
66 | pr_debug("Applying add relocation section %u to %u\n", | ||
67 | relsec, sechdrs[relsec].sh_info); | ||
68 | |||
69 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) { | ||
70 | |||
71 | location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + | ||
72 | rela[i].r_offset; | ||
73 | sym = (Elf32_Sym *)sechdrs[symindex].sh_addr + | ||
74 | ELF32_R_SYM(rela[i].r_info); | ||
75 | value = sym->st_value + rela[i].r_addend; | ||
76 | |||
77 | switch (ELF32_R_TYPE(rela[i].r_info)) { | ||
78 | |||
79 | /* | ||
80 | * Be careful! mb-gcc / mb-ld splits the relocs between the | ||
81 | * text and the reloc table. In general this means we must | ||
82 | * read the current contents of (*location), add any offset | ||
83 | * then store the result back in | ||
84 | */ | ||
85 | |||
86 | case R_MICROBLAZE_32: | ||
87 | #if __GNUC__ < 4 | ||
88 | old_value = *location; | ||
89 | *location = value + old_value; | ||
90 | |||
91 | pr_debug("R_MICROBLAZE_32 (%08lx->%08lx)\n", | ||
92 | old_value, value); | ||
93 | #else | ||
94 | *location = value; | ||
95 | #endif | ||
96 | break; | ||
97 | |||
98 | case R_MICROBLAZE_64: | ||
99 | #if __GNUC__ < 4 | ||
100 | /* Split relocs only required/used pre gcc4.1.1 */ | ||
101 | old_value = ((location[0] & 0x0000FFFF) << 16) | | ||
102 | (location[1] & 0x0000FFFF); | ||
103 | value += old_value; | ||
104 | #endif | ||
105 | location[0] = (location[0] & 0xFFFF0000) | | ||
106 | (value >> 16); | ||
107 | location[1] = (location[1] & 0xFFFF0000) | | ||
108 | (value & 0xFFFF); | ||
109 | #if __GNUC__ < 4 | ||
110 | pr_debug("R_MICROBLAZE_64 (%08lx->%08lx)\n", | ||
111 | old_value, value); | ||
112 | #endif | ||
113 | break; | ||
114 | |||
115 | case R_MICROBLAZE_64_PCREL: | ||
116 | locoffs = (location[0] & 0xFFFF) << 16 | | ||
117 | (location[1] & 0xFFFF); | ||
118 | value -= (unsigned long int)(location) + 4 + | ||
119 | locoffs; | ||
120 | location[0] = (location[0] & 0xFFFF0000) | | ||
121 | (value >> 16); | ||
122 | location[1] = (location[1] & 0xFFFF0000) | | ||
123 | (value & 0xFFFF); | ||
124 | pr_debug("R_MICROBLAZE_64_PCREL (%08lx)\n", | ||
125 | value); | ||
126 | break; | ||
127 | |||
128 | case R_MICROBLAZE_NONE: | ||
129 | pr_debug("R_MICROBLAZE_NONE\n"); | ||
130 | break; | ||
131 | |||
132 | default: | ||
133 | printk(KERN_ERR "module %s: " | ||
134 | "Unknown relocation: %u\n", | ||
135 | module->name, | ||
136 | ELF32_R_TYPE(rela->r_info)); | ||
137 | return -ENOEXEC; | ||
138 | } | ||
139 | } | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs, | ||
144 | struct module *module) | ||
145 | { | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | void module_arch_cleanup(struct module *mod) | ||
150 | { | ||
151 | } | ||