]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/xtensa/kernel/module.c
2 * arch/xtensa/kernel/module.c
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
10 * Copyright (C) 2001 - 2006 Tensilica Inc.
12 * Chris Zankel <chris@zankel.net>
16 #include <linux/module.h>
17 #include <linux/moduleloader.h>
18 #include <linux/elf.h>
19 #include <linux/vmalloc.h>
21 #include <linux/string.h>
22 #include <linux/kernel.h>
23 #include <linux/cache.h>
28 decode_calln_opcode (unsigned char *location
)
31 return (location
[0] & 0xf0) == 0x50;
34 return (location
[0] & 0xf) == 0x5;
39 decode_l32r_opcode (unsigned char *location
)
42 return (location
[0] & 0xf0) == 0x10;
45 return (location
[0] & 0xf) == 0x1;
49 int apply_relocate_add(Elf32_Shdr
*sechdrs
,
51 unsigned int symindex
,
56 Elf32_Rela
*rela
= (void *)sechdrs
[relsec
].sh_addr
;
58 unsigned char *location
;
62 printk("Applying relocate section %u to %u\n", relsec
,
63 sechdrs
[relsec
].sh_info
);
65 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rela
); i
++) {
66 location
= (char *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
68 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
69 + ELF32_R_SYM(rela
[i
].r_info
);
70 value
= sym
->st_value
+ rela
[i
].r_addend
;
72 switch (ELF32_R_TYPE(rela
[i
].r_info
)) {
77 case R_XTENSA_ASM_EXPAND
:
82 *(uint32_t *)location
+= value
;
85 case R_XTENSA_SLOT0_OP
:
86 if (decode_calln_opcode(location
)) {
87 value
-= ((unsigned long)location
& -4) + 4;
88 if ((value
& 3) != 0 ||
89 ((value
+ (1 << 19)) >> 20) != 0) {
90 printk("%s: relocation out of range, "
91 "section %d reloc %d "
94 strtab
+ sym
->st_name
);
97 value
= (signed int)value
>> 2;
99 location
[0] = ((location
[0] & ~0x3) |
100 ((value
>> 16) & 0x3));
101 location
[1] = (value
>> 8) & 0xff;
102 location
[2] = value
& 0xff;
105 location
[0] = ((location
[0] & ~0xc0) |
106 ((value
<< 6) & 0xc0));
107 location
[1] = (value
>> 2) & 0xff;
108 location
[2] = (value
>> 10) & 0xff;
110 } else if (decode_l32r_opcode(location
)) {
111 value
-= (((unsigned long)location
+ 3) & -4);
112 if ((value
& 3) != 0 ||
113 (signed int)value
>> 18 != -1) {
114 printk("%s: relocation out of range, "
115 "section %d reloc %d "
117 mod
->name
, relsec
, i
,
118 strtab
+ sym
->st_name
);
121 value
= (signed int)value
>> 2;
124 location
[1] = (value
>> 8) & 0xff;
125 location
[2] = value
& 0xff;
128 location
[1] = value
& 0xff;
129 location
[2] = (value
>> 8) & 0xff;
132 /* FIXME: Ignore any other opcodes. The Xtensa
133 assembler currently assumes that the linker will
134 always do relaxation and so all PC-relative
135 operands need relocations. (The assembler also
136 writes out the tentative PC-relative values,
137 assuming no link-time relaxation, so it is usually
138 safe to ignore the relocations.) If the
139 assembler's "--no-link-relax" flag can be made to
140 work, and if all kernel modules can be assembled
141 with that flag, then unexpected relocations could
145 case R_XTENSA_SLOT1_OP
:
146 case R_XTENSA_SLOT2_OP
:
147 case R_XTENSA_SLOT3_OP
:
148 case R_XTENSA_SLOT4_OP
:
149 case R_XTENSA_SLOT5_OP
:
150 case R_XTENSA_SLOT6_OP
:
151 case R_XTENSA_SLOT7_OP
:
152 case R_XTENSA_SLOT8_OP
:
153 case R_XTENSA_SLOT9_OP
:
154 case R_XTENSA_SLOT10_OP
:
155 case R_XTENSA_SLOT11_OP
:
156 case R_XTENSA_SLOT12_OP
:
157 case R_XTENSA_SLOT13_OP
:
158 case R_XTENSA_SLOT14_OP
:
159 printk("%s: unexpected FLIX relocation: %u\n",
161 ELF32_R_TYPE(rela
[i
].r_info
));
164 case R_XTENSA_SLOT0_ALT
:
165 case R_XTENSA_SLOT1_ALT
:
166 case R_XTENSA_SLOT2_ALT
:
167 case R_XTENSA_SLOT3_ALT
:
168 case R_XTENSA_SLOT4_ALT
:
169 case R_XTENSA_SLOT5_ALT
:
170 case R_XTENSA_SLOT6_ALT
:
171 case R_XTENSA_SLOT7_ALT
:
172 case R_XTENSA_SLOT8_ALT
:
173 case R_XTENSA_SLOT9_ALT
:
174 case R_XTENSA_SLOT10_ALT
:
175 case R_XTENSA_SLOT11_ALT
:
176 case R_XTENSA_SLOT12_ALT
:
177 case R_XTENSA_SLOT13_ALT
:
178 case R_XTENSA_SLOT14_ALT
:
179 printk("%s: unexpected ALT relocation: %u\n",
181 ELF32_R_TYPE(rela
[i
].r_info
));
185 printk("%s: unexpected relocation: %u\n",
187 ELF32_R_TYPE(rela
[i
].r_info
));