OLD | NEW |
---|---|
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // CPU specific code for arm independent of OS goes here. | 5 // CPU specific code for arm independent of OS goes here. |
6 #ifdef __arm__ | 6 #ifdef __arm__ |
7 #ifdef __QNXNTO__ | 7 #ifdef __QNXNTO__ |
8 #include <sys/mman.h> // for cache flushing. | 8 #include <sys/mman.h> // for cache flushing. |
9 #undef MAP_TYPE | 9 #undef MAP_TYPE |
10 #else | 10 #else |
11 #include <sys/syscall.h> // for cache flushing. | 11 #include <sys/syscall.h> // for cache flushing. |
12 #endif | 12 #endif |
13 #endif | 13 #endif |
14 | 14 |
15 #include "src/v8.h" | 15 #include "src/v8.h" |
16 | 16 |
17 #if V8_TARGET_ARCH_ARM | 17 #if V8_TARGET_ARCH_ARM |
18 | 18 |
19 #include "src/cpu.h" | 19 #include "src/cpu.h" |
20 #include "src/macro-assembler.h" | 20 #include "src/macro-assembler.h" |
21 #include "src/simulator.h" // for cache flushing. | 21 #include "src/simulator.h" // for cache flushing. |
22 | 22 |
23 namespace v8 { | 23 namespace v8 { |
24 namespace internal { | 24 namespace internal { |
25 | 25 |
26 #if defined(USE_SIMULATOR) | |
27 | |
26 void CPU::FlushICache(void* start, size_t size) { | 28 void CPU::FlushICache(void* start, size_t size) { |
27 // Nothing to do flushing no instructions. | 29 if (size == 0) return; |
28 if (size == 0) { | |
29 return; | |
30 } | |
31 | |
32 #if defined(USE_SIMULATOR) | |
33 // Not generating ARM instructions for C-code. This means that we are | 30 // Not generating ARM instructions for C-code. This means that we are |
34 // building an ARM emulator based target. We should notify the simulator | 31 // building an ARM emulator based target. We should notify the simulator |
35 // that the Icache was flushed. | 32 // that the Icache was flushed. |
36 // None of this code ends up in the snapshot so there are no issues | 33 // None of this code ends up in the snapshot so there are no issues |
37 // around whether or not to generate the code when building snapshots. | 34 // around whether or not to generate the code when building snapshots. |
38 Simulator::FlushICache(Isolate::Current()->simulator_i_cache(), start, size); | 35 Simulator::FlushICache(Isolate::Current()->simulator_i_cache(), start, size); |
36 } | |
37 | |
39 #elif V8_OS_QNX | 38 #elif V8_OS_QNX |
40 msync(start, size, MS_SYNC | MS_INVALIDATE_ICACHE); | 39 |
40 void CPU::FlushICache(void* start, size_t size) { | |
41 if (size > 0) msync(start, size, MS_SYNC | MS_INVALIDATE_ICACHE); | |
42 } | |
43 | |
41 #else | 44 #else |
42 // Ideally, we would call | |
43 // syscall(__ARM_NR_cacheflush, start, | |
44 // reinterpret_cast<intptr_t>(start) + size, 0); | |
45 // however, syscall(int, ...) is not supported on all platforms, especially | |
46 // not when using EABI, so we call the __ARM_NR_cacheflush syscall directly. | |
47 | 45 |
48 register uint32_t beg asm("a1") = reinterpret_cast<uint32_t>(start); | 46 void __attribute__((naked)) CPU::FlushICache(void* start, size_t size) { |
ulan
2014/06/18 14:08:31
Do you know if this attribute is supported by clan
jbramley
2014/06/18 14:19:37
I couldn't find a definite source, but the followi
| |
49 register uint32_t end asm("a2") = | 47 // On entry: |
50 reinterpret_cast<uint32_t>(start) + size; | 48 // r0 = start |
51 register uint32_t flg asm("a3") = 0; | 49 // r1 = size |
52 #if defined (__arm__) && !defined(__thumb__) | 50 asm volatile( |
53 // __arm__ may be defined in thumb mode. | 51 // This assembly works for both ARM and Thumb targets. |
54 register uint32_t scno asm("r7") = __ARM_NR_cacheflush; | 52 |
55 asm volatile( | 53 // Preserve r7, since it is callee-saved. |
56 "svc 0x0" | 54 " push {r7, lr}\n" |
57 : "=r" (beg) | 55 |
58 : "0" (beg), "r" (end), "r" (flg), "r" (scno)); | 56 // Perform the syscall (if size > 0). |
59 #else | 57 " cmp r1, #0\n" |
60 // r7 is reserved by the EABI in thumb mode. | 58 " beq 0f\n" |
61 asm volatile( | 59 // r0 = start |
62 "@ Enter ARM Mode \n\t" | 60 " adds r1, r1, r0\n" // r1 = end (= start + size) |
63 "adr r3, 1f \n\t" | 61 " movs r2, #0\n" // r2 = flags (= 0) |
64 "bx r3 \n\t" | 62 " ldr r7, =%[scno]\n" // r7 = syscall number. |
65 ".ALIGN 4 \n\t" | 63 " svc 0\n" |
66 ".ARM \n" | 64 |
67 "1: push {r7} \n\t" | 65 // Restore r7 and return. |
68 "mov r7, %4 \n\t" | 66 "0:\n" |
69 "svc 0x0 \n\t" | 67 " pop {r7, pc}\n" |
70 "pop {r7} \n\t" | 68 : : [scno] "i" (__ARM_NR_cacheflush) : "memory", "cc"); |
71 "@ Enter THUMB Mode\n\t" | 69 } |
72 "adr r3, 2f+1 \n\t" | 70 |
73 "bx r3 \n\t" | |
74 ".THUMB \n" | |
75 "2: \n\t" | |
76 : "=r" (beg) | |
77 : "0" (beg), "r" (end), "r" (flg), "r" (__ARM_NR_cacheflush) | |
78 : "r3"); | |
79 #endif | |
80 #endif | 71 #endif |
81 } | |
82 | 72 |
83 } } // namespace v8::internal | 73 } } // namespace v8::internal |
84 | 74 |
85 #endif // V8_TARGET_ARCH_ARM | 75 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |