blob: ab9cf69620e3ebd315bdb649c9916deeb40d4b5b [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2012 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// CPU specific code for arm independent of OS goes here.
6
7#include <sys/syscall.h>
8#include <unistd.h>
9
10#ifdef __mips
11#include <asm/cachectl.h>
12#endif // #ifdef __mips
13
Ben Murdochb8a8cc12014-11-26 15:28:44 +000014#if V8_TARGET_ARCH_MIPS64
15
16#include "src/assembler.h"
17#include "src/macro-assembler.h"
18
19#include "src/simulator.h" // For cache flushing.
20
21namespace v8 {
22namespace internal {
23
24
25void CpuFeatures::FlushICache(void* start, size_t size) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026#if !defined(USE_SIMULATOR)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027 // Nothing to do, flushing no instructions.
28 if (size == 0) {
29 return;
30 }
31
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032#if defined(ANDROID) && !defined(__LP64__)
33 // Bionic cacheflush can typically run in userland, avoiding kernel call.
34 char *end = reinterpret_cast<char *>(start) + size;
35 cacheflush(
36 reinterpret_cast<intptr_t>(start), reinterpret_cast<intptr_t>(end), 0);
37#else // ANDROID
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000038 long res; // NOLINT(runtime/int)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000039 // See http://www.linux-mips.org/wiki/Cacheflush_Syscall.
40 res = syscall(__NR_cacheflush, start, size, ICACHE);
41 if (res) {
42 V8_Fatal(__FILE__, __LINE__, "Failed to flush the instruction cache");
43 }
44#endif // ANDROID
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000045#endif // !USE_SIMULATOR.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046}
47
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000048} // namespace internal
49} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050
51#endif // V8_TARGET_ARCH_MIPS64