blob: f5d2ab19d13adb1876cd0d7a70350aa20c59f6ad [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2009 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5// CPU specific code for arm independent of OS goes here.
Steve Block6ded16b2010-05-10 14:33:55 +01006#ifdef __arm__
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#ifdef __QNXNTO__
8#include <sys/mman.h> // for cache flushing.
9#undef MAP_TYPE
10#else
Steve Blocka7e24c12009-10-30 11:49:00 +000011#include <sys/syscall.h> // for cache flushing.
12#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013#endif
Steve Blocka7e24c12009-10-30 11:49:00 +000014
Ben Murdochb8a8cc12014-11-26 15:28:44 +000015#if V8_TARGET_ARCH_ARM
Leon Clarkef7060e22010-06-03 12:02:55 +010016
Ben Murdochb8a8cc12014-11-26 15:28:44 +000017#include "src/assembler.h"
18#include "src/macro-assembler.h"
Steve Block6ded16b2010-05-10 14:33:55 +010019
Steve Blocka7e24c12009-10-30 11:49:00 +000020namespace v8 {
21namespace internal {
22
Ben Murdochb8a8cc12014-11-26 15:28:44 +000023void CpuFeatures::FlushICache(void* start, size_t size) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000024#if !defined(USE_SIMULATOR)
25#if V8_OS_QNX
Ben Murdochb8a8cc12014-11-26 15:28:44 +000026 msync(start, size, MS_SYNC | MS_INVALIDATE_ICACHE);
Steve Blocka7e24c12009-10-30 11:49:00 +000027#else
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028 register uint32_t beg asm("r0") = reinterpret_cast<uint32_t>(start);
29 register uint32_t end asm("r1") = beg + size;
30 register uint32_t flg asm("r2") = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +000031
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000032#ifdef __clang__
33 // This variant of the asm avoids a constant pool entry, which can be
34 // problematic when LTO'ing. It is also slightly shorter.
35 register uint32_t scno asm("r7") = __ARM_NR_cacheflush;
36
37 asm volatile("svc 0\n"
38 :
39 : "r"(beg), "r"(end), "r"(flg), "r"(scno)
40 : "memory");
41#else
42 // Use a different variant of the asm with GCC because some versions doesn't
43 // support r7 as an asm input.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000044 asm volatile(
45 // This assembly works for both ARM and Thumb targets.
Steve Blocka7e24c12009-10-30 11:49:00 +000046
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047 // Preserve r7; it is callee-saved, and GCC uses it as a frame pointer for
48 // Thumb targets.
49 " push {r7}\n"
50 // r0 = beg
51 // r1 = end
52 // r2 = flags (0)
53 " ldr r7, =%c[scno]\n" // r7 = syscall number
54 " svc 0\n"
Steve Blocka7e24c12009-10-30 11:49:00 +000055
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056 " pop {r7}\n"
57 :
58 : "r" (beg), "r" (end), "r" (flg), [scno] "i" (__ARM_NR_cacheflush)
59 : "memory");
Steve Blocka7e24c12009-10-30 11:49:00 +000060#endif
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000061#endif
62#endif // !USE_SIMULATOR
Steve Blocka7e24c12009-10-30 11:49:00 +000063}
64
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000065} // namespace internal
66} // namespace v8
Leon Clarkef7060e22010-06-03 12:02:55 +010067
68#endif // V8_TARGET_ARCH_ARM