11cb0ef41Sopenharmony_ci// Copyright 2012 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
71cb0ef41Sopenharmony_ci#include <sys/syscall.h>
81cb0ef41Sopenharmony_ci#include <unistd.h>
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#ifdef __mips
111cb0ef41Sopenharmony_ci#include <asm/cachectl.h>
121cb0ef41Sopenharmony_ci#endif  // #ifdef __mips
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_MIPS64
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci#include "src/codegen/cpu-features.h"
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cinamespace v8 {
191cb0ef41Sopenharmony_cinamespace internal {
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_civoid CpuFeatures::FlushICache(void* start, size_t size) {
221cb0ef41Sopenharmony_ci#if !defined(USE_SIMULATOR)
231cb0ef41Sopenharmony_ci  // Nothing to do, flushing no instructions.
241cb0ef41Sopenharmony_ci  if (size == 0) {
251cb0ef41Sopenharmony_ci    return;
261cb0ef41Sopenharmony_ci  }
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci#if defined(ANDROID) && !defined(__LP64__)
291cb0ef41Sopenharmony_ci  // Bionic cacheflush can typically run in userland, avoiding kernel call.
301cb0ef41Sopenharmony_ci  char* end = reinterpret_cast<char*>(start) + size;
311cb0ef41Sopenharmony_ci  cacheflush(reinterpret_cast<intptr_t>(start), reinterpret_cast<intptr_t>(end),
321cb0ef41Sopenharmony_ci             0);
331cb0ef41Sopenharmony_ci#else   // ANDROID
341cb0ef41Sopenharmony_ci  long res;  // NOLINT(runtime/int)
351cb0ef41Sopenharmony_ci  // See http://www.linux-mips.org/wiki/Cacheflush_Syscall.
361cb0ef41Sopenharmony_ci  res = syscall(__NR_cacheflush, start, size, ICACHE);
371cb0ef41Sopenharmony_ci  if (res) FATAL("Failed to flush the instruction cache");
381cb0ef41Sopenharmony_ci#endif  // ANDROID
391cb0ef41Sopenharmony_ci#endif  // !USE_SIMULATOR.
401cb0ef41Sopenharmony_ci}
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci}  // namespace internal
431cb0ef41Sopenharmony_ci}  // namespace v8
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci#endif  // V8_TARGET_ARCH_MIPS64
46