blob: 1199365b7d2479dad3883527ad7ad17037bed6b3 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 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.
Andrei Popescu31002712010-02-23 13:46:05 +00004
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_MIPS
Leon Clarkef7060e22010-06-03 12:02:55 +010015
Ben Murdochb8a8cc12014-11-26 15:28:44 +000016#include "src/assembler.h"
17#include "src/macro-assembler.h"
Steve Block44f0eee2011-05-26 01:26:41 +010018
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019#include "src/simulator.h" // For cache flushing.
Andrei Popescu31002712010-02-23 13:46:05 +000020
21namespace v8 {
22namespace internal {
23
Steve Block44f0eee2011-05-26 01:26:41 +010024
Ben Murdochb8a8cc12014-11-26 15:28:44 +000025void CpuFeatures::FlushICache(void* start, size_t size) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026#if !defined(USE_SIMULATOR)
Ben Murdoch257744e2011-11-30 15:57:28 +000027 // Nothing to do, flushing no instructions.
28 if (size == 0) {
29 return;
30 }
31
Ben Murdoch3ef787d2012-04-12 10:51:47 +010032#if defined(ANDROID)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000033 // 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);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010037#else // ANDROID
Andrei Popescu31002712010-02-23 13:46:05 +000038 int res;
Ben Murdoch257744e2011-11-30 15:57:28 +000039 // See http://www.linux-mips.org/wiki/Cacheflush_Syscall.
Andrei Popescu31002712010-02-23 13:46:05 +000040 res = syscall(__NR_cacheflush, start, size, ICACHE);
Andrei Popescu31002712010-02-23 13:46:05 +000041 if (res) {
42 V8_Fatal(__FILE__, __LINE__, "Failed to flush the instruction cache");
43 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +010044#endif // ANDROID
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000045#endif // !USE_SIMULATOR.
Andrei Popescu31002712010-02-23 13:46:05 +000046}
47
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000048} // namespace internal
49} // namespace v8
Andrei Popescu31002712010-02-23 13:46:05 +000050
Leon Clarkef7060e22010-06-03 12:02:55 +010051#endif // V8_TARGET_ARCH_MIPS