cpu-arm.cc 2.42 KB
Newer Older
1
// Copyright 2006-2009 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4 5

// CPU specific code for arm independent of OS goes here.
6
#ifdef __arm__
7 8 9 10
#ifdef __QNXNTO__
#include <sys/mman.h>  // for cache flushing.
#undef MAP_TYPE
#else
11
#include <sys/syscall.h>  // for cache flushing.
12
#endif
13
#endif
14

15
#include "src/v8.h"
16

17
#if V8_TARGET_ARCH_ARM
18

19
#include "src/assembler.h"
20 21
#include "src/macro-assembler.h"
#include "src/simulator.h"  // for cache flushing.
22

23 24
namespace v8 {
namespace internal {
25

26

27
void CpuFeatures::FlushICache(void* start, size_t size) {
28
  if (size == 0) return;
29

30 31
  if (CpuFeatures::IsSupported(COHERENT_CACHE)) return;

32
#if defined(USE_SIMULATOR)
33
  // Not generating ARM instructions for C-code. This means that we are
34 35
  // building an ARM emulator based target.  We should notify the simulator
  // that the Icache was flushed.
36 37
  // None of this code ends up in the snapshot so there are no issues
  // around whether or not to generate the code when building snapshots.
38
  Simulator::FlushICache(Isolate::Current()->simulator_i_cache(), start, size);
39

40 41
#elif V8_OS_QNX
  msync(start, size, MS_SYNC | MS_INVALIDATE_ICACHE);
42

43
#else
44 45 46 47
  register uint32_t beg asm("r0") = reinterpret_cast<uint32_t>(start);
  register uint32_t end asm("r1") = beg + size;
  register uint32_t flg asm("r2") = 0;

48 49 50 51 52 53 54 55 56 57 58 59
#ifdef __clang__
  // This variant of the asm avoids a constant pool entry, which can be
  // problematic when LTO'ing. It is also slightly shorter.
  register uint32_t scno asm("r7") = __ARM_NR_cacheflush;

  asm volatile("svc 0\n"
               :
               : "r"(beg), "r"(end), "r"(flg), "r"(scno)
               : "memory");
#else
  // Use a different variant of the asm with GCC because some versions doesn't
  // support r7 as an asm input.
60 61 62 63 64 65 66 67 68
  asm volatile(
    // This assembly works for both ARM and Thumb targets.

    // Preserve r7; it is callee-saved, and GCC uses it as a frame pointer for
    // Thumb targets.
    "  push {r7}\n"
                                  // r0 = beg
                                  // r1 = end
                                  // r2 = flags (0)
69
    "  ldr r7, =%c[scno]\n"       // r7 = syscall number
70
    "  svc 0\n"
71

72 73 74 75
    "  pop {r7}\n"
    :
    : "r" (beg), "r" (end), "r" (flg), [scno] "i" (__ARM_NR_cacheflush)
    : "memory");
76
#endif
77
#endif
78 79
}

80 81
}  // namespace internal
}  // namespace v8
82 83

#endif  // V8_TARGET_ARCH_ARM