diff options
Diffstat (limited to 'arch/c6x')
-rw-r--r-- | arch/c6x/include/asm/module.h | 33 | ||||
-rw-r--r-- | arch/c6x/kernel/c6x_ksyms.c | 66 | ||||
-rw-r--r-- | arch/c6x/kernel/module.c | 123 |
3 files changed, 222 insertions, 0 deletions
diff --git a/arch/c6x/include/asm/module.h b/arch/c6x/include/asm/module.h new file mode 100644 index 000000000000..a453f9744f42 --- /dev/null +++ b/arch/c6x/include/asm/module.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * Port on Texas Instruments TMS320C6x architecture | ||
3 | * | ||
4 | * Copyright (C) 2004, 2009, 2010 Texas Instruments Incorporated | ||
5 | * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com) | ||
6 | * | ||
7 | * Updated for 2.6.34 by: Mark Salter (msalter@redhat.com) | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | */ | ||
13 | #ifndef _ASM_C6X_MODULE_H | ||
14 | #define _ASM_C6X_MODULE_H | ||
15 | |||
16 | #define Elf_Shdr Elf32_Shdr | ||
17 | #define Elf_Sym Elf32_Sym | ||
18 | #define Elf_Ehdr Elf32_Ehdr | ||
19 | #define Elf_Addr Elf32_Addr | ||
20 | #define Elf_Word Elf32_Word | ||
21 | |||
22 | /* | ||
23 | * This file contains the C6x architecture specific module code. | ||
24 | */ | ||
25 | struct mod_arch_specific { | ||
26 | }; | ||
27 | |||
28 | struct loaded_sections { | ||
29 | unsigned int new_vaddr; | ||
30 | unsigned int loaded; | ||
31 | }; | ||
32 | |||
33 | #endif /* _ASM_C6X_MODULE_H */ | ||
diff --git a/arch/c6x/kernel/c6x_ksyms.c b/arch/c6x/kernel/c6x_ksyms.c new file mode 100644 index 000000000000..0ba3e0bba3e1 --- /dev/null +++ b/arch/c6x/kernel/c6x_ksyms.c | |||
@@ -0,0 +1,66 @@ | |||
1 | /* | ||
2 | * Port on Texas Instruments TMS320C6x architecture | ||
3 | * | ||
4 | * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated | ||
5 | * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com) | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | */ | ||
12 | #include <linux/module.h> | ||
13 | #include <asm/checksum.h> | ||
14 | #include <linux/io.h> | ||
15 | |||
16 | /* | ||
17 | * libgcc functions - used internally by the compiler... | ||
18 | */ | ||
19 | extern int __c6xabi_divi(int dividend, int divisor); | ||
20 | EXPORT_SYMBOL(__c6xabi_divi); | ||
21 | |||
22 | extern unsigned __c6xabi_divu(unsigned dividend, unsigned divisor); | ||
23 | EXPORT_SYMBOL(__c6xabi_divu); | ||
24 | |||
25 | extern int __c6xabi_remi(int dividend, int divisor); | ||
26 | EXPORT_SYMBOL(__c6xabi_remi); | ||
27 | |||
28 | extern unsigned __c6xabi_remu(unsigned dividend, unsigned divisor); | ||
29 | EXPORT_SYMBOL(__c6xabi_remu); | ||
30 | |||
31 | extern int __c6xabi_divremi(int dividend, int divisor); | ||
32 | EXPORT_SYMBOL(__c6xabi_divremi); | ||
33 | |||
34 | extern unsigned __c6xabi_divremu(unsigned dividend, unsigned divisor); | ||
35 | EXPORT_SYMBOL(__c6xabi_divremu); | ||
36 | |||
37 | extern unsigned long long __c6xabi_mpyll(unsigned long long src1, | ||
38 | unsigned long long src2); | ||
39 | EXPORT_SYMBOL(__c6xabi_mpyll); | ||
40 | |||
41 | extern long long __c6xabi_negll(long long src); | ||
42 | EXPORT_SYMBOL(__c6xabi_negll); | ||
43 | |||
44 | extern unsigned long long __c6xabi_llshl(unsigned long long src1, uint src2); | ||
45 | EXPORT_SYMBOL(__c6xabi_llshl); | ||
46 | |||
47 | extern long long __c6xabi_llshr(long long src1, uint src2); | ||
48 | EXPORT_SYMBOL(__c6xabi_llshr); | ||
49 | |||
50 | extern unsigned long long __c6xabi_llshru(unsigned long long src1, uint src2); | ||
51 | EXPORT_SYMBOL(__c6xabi_llshru); | ||
52 | |||
53 | extern void __c6xabi_strasgi(int *dst, const int *src, unsigned cnt); | ||
54 | EXPORT_SYMBOL(__c6xabi_strasgi); | ||
55 | |||
56 | extern void __c6xabi_push_rts(void); | ||
57 | EXPORT_SYMBOL(__c6xabi_push_rts); | ||
58 | |||
59 | extern void __c6xabi_pop_rts(void); | ||
60 | EXPORT_SYMBOL(__c6xabi_pop_rts); | ||
61 | |||
62 | extern void __c6xabi_strasgi_64plus(int *dst, const int *src, unsigned cnt); | ||
63 | EXPORT_SYMBOL(__c6xabi_strasgi_64plus); | ||
64 | |||
65 | /* lib functions */ | ||
66 | EXPORT_SYMBOL(memcpy); | ||
diff --git a/arch/c6x/kernel/module.c b/arch/c6x/kernel/module.c new file mode 100644 index 000000000000..5fc03f18f56c --- /dev/null +++ b/arch/c6x/kernel/module.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * Port on Texas Instruments TMS320C6x architecture | ||
3 | * | ||
4 | * Copyright (C) 2005, 2009, 2010, 2011 Texas Instruments Incorporated | ||
5 | * Author: Thomas Charleux (thomas.charleux@jaluna.com) | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | */ | ||
12 | #include <linux/moduleloader.h> | ||
13 | #include <linux/elf.h> | ||
14 | #include <linux/vmalloc.h> | ||
15 | #include <linux/kernel.h> | ||
16 | |||
17 | static inline int fixup_pcr(u32 *ip, Elf32_Addr dest, u32 maskbits, int shift) | ||
18 | { | ||
19 | u32 opcode; | ||
20 | long ep = (long)ip & ~31; | ||
21 | long delta = ((long)dest - ep) >> 2; | ||
22 | long mask = (1 << maskbits) - 1; | ||
23 | |||
24 | if ((delta >> (maskbits - 1)) == 0 || | ||
25 | (delta >> (maskbits - 1)) == -1) { | ||
26 | opcode = *ip; | ||
27 | opcode &= ~(mask << shift); | ||
28 | opcode |= ((delta & mask) << shift); | ||
29 | *ip = opcode; | ||
30 | |||
31 | pr_debug("REL PCR_S%d[%p] dest[%p] opcode[%08x]\n", | ||
32 | maskbits, ip, (void *)dest, opcode); | ||
33 | |||
34 | return 0; | ||
35 | } | ||
36 | pr_err("PCR_S%d reloc %p -> %p out of range!\n", | ||
37 | maskbits, ip, (void *)dest); | ||
38 | |||
39 | return -1; | ||
40 | } | ||
41 | |||
42 | /* | ||
43 | * apply a RELA relocation | ||
44 | */ | ||
45 | int apply_relocate_add(Elf32_Shdr *sechdrs, | ||
46 | const char *strtab, | ||
47 | unsigned int symindex, | ||
48 | unsigned int relsec, | ||
49 | struct module *me) | ||
50 | { | ||
51 | Elf32_Rela *rel = (void *) sechdrs[relsec].sh_addr; | ||
52 | Elf_Sym *sym; | ||
53 | u32 *location, opcode; | ||
54 | unsigned int i; | ||
55 | Elf32_Addr v; | ||
56 | Elf_Addr offset = 0; | ||
57 | |||
58 | pr_debug("Applying relocate section %u to %u with offset 0x%x\n", | ||
59 | relsec, sechdrs[relsec].sh_info, offset); | ||
60 | |||
61 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { | ||
62 | /* This is where to make the change */ | ||
63 | location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr | ||
64 | + rel[i].r_offset - offset; | ||
65 | |||
66 | /* This is the symbol it is referring to. Note that all | ||
67 | undefined symbols have been resolved. */ | ||
68 | sym = (Elf_Sym *)sechdrs[symindex].sh_addr | ||
69 | + ELF32_R_SYM(rel[i].r_info); | ||
70 | |||
71 | /* this is the adjustment to be made */ | ||
72 | v = sym->st_value + rel[i].r_addend; | ||
73 | |||
74 | switch (ELF32_R_TYPE(rel[i].r_info)) { | ||
75 | case R_C6000_ABS32: | ||
76 | pr_debug("RELA ABS32: [%p] = 0x%x\n", location, v); | ||
77 | *location = v; | ||
78 | break; | ||
79 | case R_C6000_ABS16: | ||
80 | pr_debug("RELA ABS16: [%p] = 0x%x\n", location, v); | ||
81 | *(u16 *)location = v; | ||
82 | break; | ||
83 | case R_C6000_ABS8: | ||
84 | pr_debug("RELA ABS8: [%p] = 0x%x\n", location, v); | ||
85 | *(u8 *)location = v; | ||
86 | break; | ||
87 | case R_C6000_ABS_L16: | ||
88 | opcode = *location; | ||
89 | opcode &= ~0x7fff80; | ||
90 | opcode |= ((v & 0xffff) << 7); | ||
91 | pr_debug("RELA ABS_L16[%p] v[0x%x] opcode[0x%x]\n", | ||
92 | location, v, opcode); | ||
93 | *location = opcode; | ||
94 | break; | ||
95 | case R_C6000_ABS_H16: | ||
96 | opcode = *location; | ||
97 | opcode &= ~0x7fff80; | ||
98 | opcode |= ((v >> 9) & 0x7fff80); | ||
99 | pr_debug("RELA ABS_H16[%p] v[0x%x] opcode[0x%x]\n", | ||
100 | location, v, opcode); | ||
101 | *location = opcode; | ||
102 | break; | ||
103 | case R_C6000_PCR_S21: | ||
104 | if (fixup_pcr(location, v, 21, 7)) | ||
105 | return -ENOEXEC; | ||
106 | break; | ||
107 | case R_C6000_PCR_S12: | ||
108 | if (fixup_pcr(location, v, 12, 16)) | ||
109 | return -ENOEXEC; | ||
110 | break; | ||
111 | case R_C6000_PCR_S10: | ||
112 | if (fixup_pcr(location, v, 10, 13)) | ||
113 | return -ENOEXEC; | ||
114 | break; | ||
115 | default: | ||
116 | pr_err("module %s: Unknown RELA relocation: %u\n", | ||
117 | me->name, ELF32_R_TYPE(rel[i].r_info)); | ||
118 | return -ENOEXEC; | ||
119 | } | ||
120 | } | ||
121 | |||
122 | return 0; | ||
123 | } | ||