11cb0ef41Sopenharmony_ci// Copyright 2006-2009 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci// CPU specific code for arm independent of OS goes here.
61cb0ef41Sopenharmony_ci#ifdef __arm__
71cb0ef41Sopenharmony_ci#ifdef __QNXNTO__
81cb0ef41Sopenharmony_ci#include <sys/mman.h>  // for cache flushing.
91cb0ef41Sopenharmony_ci#undef MAP_TYPE
101cb0ef41Sopenharmony_ci#elif V8_OS_FREEBSD
111cb0ef41Sopenharmony_ci#include <machine/sysarch.h>  // for cache flushing
121cb0ef41Sopenharmony_ci#include <sys/types.h>
131cb0ef41Sopenharmony_ci#elif V8_OS_STARBOARD
141cb0ef41Sopenharmony_ci#define __ARM_NR_cacheflush 0x0f0002
151cb0ef41Sopenharmony_ci#else
161cb0ef41Sopenharmony_ci#include <sys/syscall.h>  // for cache flushing.
171cb0ef41Sopenharmony_ci#endif
181cb0ef41Sopenharmony_ci#endif
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_ARM
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci#include "src/codegen/cpu-features.h"
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cinamespace v8 {
251cb0ef41Sopenharmony_cinamespace internal {
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci// The inlining of this seems to trigger an LTO bug that clobbers a register,
281cb0ef41Sopenharmony_ci// see https://crbug.com/952759 and https://bugs.llvm.org/show_bug.cgi?id=41575.
291cb0ef41Sopenharmony_ciV8_NOINLINE void CpuFeatures::FlushICache(void* start, size_t size) {
301cb0ef41Sopenharmony_ci#if !defined(USE_SIMULATOR)
311cb0ef41Sopenharmony_ci#if V8_OS_QNX
321cb0ef41Sopenharmony_ci  msync(start, size, MS_SYNC | MS_INVALIDATE_ICACHE);
331cb0ef41Sopenharmony_ci#elif V8_OS_FREEBSD
341cb0ef41Sopenharmony_ci  struct arm_sync_icache_args args = {
351cb0ef41Sopenharmony_ci      .addr = reinterpret_cast<uintptr_t>(start), .len = size};
361cb0ef41Sopenharmony_ci  sysarch(ARM_SYNC_ICACHE, reinterpret_cast<void*>(&args));
371cb0ef41Sopenharmony_ci#else
381cb0ef41Sopenharmony_ci  register uint32_t beg asm("r0") = reinterpret_cast<uint32_t>(start);
391cb0ef41Sopenharmony_ci  register uint32_t end asm("r1") = beg + size;
401cb0ef41Sopenharmony_ci  register uint32_t flg asm("r2") = 0;
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  asm volatile(
431cb0ef41Sopenharmony_ci      // This assembly works for both ARM and Thumb targets.
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci      // Preserve r7; it is callee-saved, and GCC uses it as a frame pointer for
461cb0ef41Sopenharmony_ci      // Thumb targets.
471cb0ef41Sopenharmony_ci      "  push {r7}\n"
481cb0ef41Sopenharmony_ci      // r0 = beg
491cb0ef41Sopenharmony_ci      // r1 = end
501cb0ef41Sopenharmony_ci      // r2 = flags (0)
511cb0ef41Sopenharmony_ci      "  ldr r7, =%c[scno]\n"  // r7 = syscall number
521cb0ef41Sopenharmony_ci      "  svc 0\n"
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci      "  pop {r7}\n"
551cb0ef41Sopenharmony_ci      :
561cb0ef41Sopenharmony_ci      : "r"(beg), "r"(end), "r"(flg), [scno] "i"(__ARM_NR_cacheflush)
571cb0ef41Sopenharmony_ci      : "memory");
581cb0ef41Sopenharmony_ci#endif
591cb0ef41Sopenharmony_ci#endif  // !USE_SIMULATOR
601cb0ef41Sopenharmony_ci}
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci}  // namespace internal
631cb0ef41Sopenharmony_ci}  // namespace v8
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci#endif  // V8_TARGET_ARCH_ARM
66