OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* | 7 /* |
8 * This alters instructions for the IRT so that access to the TLS | 8 * This alters instructions for the IRT so that access to the TLS |
9 * point to the IRT's TLS. | 9 * point to the IRT's TLS. |
10 */ | 10 */ |
(...skipping 22 matching lines...) Expand all Loading... | |
33 return (uint32_t) ((uint8_t *) insn - g_code_start) + g_code_addr; | 33 return (uint32_t) ((uint8_t *) insn - g_code_start) + g_code_addr; |
34 } | 34 } |
35 | 35 |
36 static void ReportError(const void *insn, const char *message) { | 36 static void ReportError(const void *insn, const char *message) { |
37 uint32_t insn_addr = GetInsnAddr(insn); | 37 uint32_t insn_addr = GetInsnAddr(insn); |
38 | 38 |
39 fprintf(stderr, "%#x: %s\n", (unsigned int) insn_addr, message); | 39 fprintf(stderr, "%#x: %s\n", (unsigned int) insn_addr, message); |
40 ++g_errors; | 40 ++g_errors; |
41 } | 41 } |
42 | 42 |
43 static void EditMipsCode(void *code, size_t code_length) { | |
Mark Seaborn
2016/01/11 22:19:28
Nit: can you order this after EditArmCode()?
petarj
2016/01/11 23:21:38
Done.
| |
44 Elf32_Word *const words = code; | |
45 Elf32_Word *const end = (void *) ((uint8_t *) code + code_length); | |
46 Elf32_Word *insn; | |
47 | |
48 for (insn = words; insn < end; ++insn) { | |
49 if ((*insn & 0xFFE0FFFF) == 0x8f000000) { | |
50 /* | |
51 * This is 'lw $REG, 0($t8)'. | |
52 * Turn it into 'lw $REG, 4($t8)'. | |
53 */ | |
54 *insn |= 4; | |
55 ++g_changes; | |
56 } | |
57 } | |
58 } | |
59 | |
43 static void EditArmCode(void *code, size_t code_length) { | 60 static void EditArmCode(void *code, size_t code_length) { |
44 Elf32_Word *const words = code; | 61 Elf32_Word *const words = code; |
45 Elf32_Word *const end = (void *) ((uint8_t *) code + code_length); | 62 Elf32_Word *const end = (void *) ((uint8_t *) code + code_length); |
46 Elf32_Word *insn; | 63 Elf32_Word *insn; |
47 | 64 |
48 for (insn = words; insn < end; ++insn) { | 65 for (insn = words; insn < end; ++insn) { |
49 if (*insn == NACL_INSTR_ARM_LITERAL_POOL_HEAD) { | 66 if (*insn == NACL_INSTR_ARM_LITERAL_POOL_HEAD) { |
50 if ((insn - words) % 4 != 0) { | 67 if ((insn - words) % 4 != 0) { |
51 ReportError(insn, "Roadblock not at start of bundle"); | 68 ReportError(insn, "Roadblock not at start of bundle"); |
52 } else { | 69 } else { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 case EM_386: | 199 case EM_386: |
183 EditX86_32Code(g_code_start, code_length); | 200 EditX86_32Code(g_code_start, code_length); |
184 break; | 201 break; |
185 case EM_X86_64: | 202 case EM_X86_64: |
186 if (g_verbose) { | 203 if (g_verbose) { |
187 printf("%s: x86-64 ELF detected, no instructions changed\n", | 204 printf("%s: x86-64 ELF detected, no instructions changed\n", |
188 infile); | 205 infile); |
189 } | 206 } |
190 return TRUE; | 207 return TRUE; |
191 case EM_MIPS: | 208 case EM_MIPS: |
192 if (g_verbose) { | 209 EditMipsCode(g_code_start, code_length); |
193 printf("%s: MIPS ELF detected, no instructions changed\n", | |
194 infile); | |
195 } | |
196 return TRUE; | 210 return TRUE; |
197 default: | 211 default: |
198 fprintf(stderr, "%s: Unsupported e_machine %d\n", | 212 fprintf(stderr, "%s: Unsupported e_machine %d\n", |
199 infile, e_machine); | 213 infile, e_machine); |
200 return FALSE; | 214 return FALSE; |
201 } | 215 } |
202 | 216 |
203 if (g_verbose) { | 217 if (g_verbose) { |
204 if (g_changes == 0) { | 218 if (g_changes == 0) { |
205 printf("%s: Found no changes to make\n", | 219 printf("%s: Found no changes to make\n", |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 infile); | 402 infile); |
389 return 1; | 403 return 1; |
390 } | 404 } |
391 | 405 |
392 if (g_errors != 0) | 406 if (g_errors != 0) |
393 return 1; | 407 return 1; |
394 | 408 |
395 WriteOutput(outfile); | 409 WriteOutput(outfile); |
396 return 0; | 410 return 0; |
397 } | 411 } |
OLD | NEW |