13ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch// Copyright 2012 the V8 project authors. All rights reserved.
23100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// Redistribution and use in source and binary forms, with or without
33100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// modification, are permitted provided that the following conditions are
43100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// met:
53100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//
63100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//     * Redistributions of source code must retain the above copyright
73100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//       notice, this list of conditions and the following disclaimer.
83100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//     * Redistributions in binary form must reproduce the above
93100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//       copyright notice, this list of conditions and the following
103100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//       disclaimer in the documentation and/or other materials provided
113100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//       with the distribution.
123100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//     * Neither the name of Google Inc. nor the names of its
133100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//       contributors may be used to endorse or promote products derived
143100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//       from this software without specific prior written permission.
153100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu//
163100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
283100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu// CPU specific code for arm independent of OS goes here.
293100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
303100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#include <sys/syscall.h>
313100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#include <unistd.h>
323100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
333100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#ifdef __mips
343100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#include <asm/cachectl.h>
353100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#endif  // #ifdef __mips
363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#include "v8.h"
38f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
39f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke#if defined(V8_TARGET_ARCH_MIPS)
40f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
413100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#include "cpu.h"
4244f0eee88ff00398ff7f715fab053374d808c90dSteve Block#include "macro-assembler.h"
4344f0eee88ff00398ff7f715fab053374d808c90dSteve Block
4444f0eee88ff00398ff7f715fab053374d808c90dSteve Block#include "simulator.h"  // For cache flushing.
453100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
463100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescunamespace v8 {
473100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescunamespace internal {
483100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
4944f0eee88ff00398ff7f715fab053374d808c90dSteve Block
503ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdochvoid CPU::SetUp() {
51257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  CpuFeatures::Probe();
52257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch}
53257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
54257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
55257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdochbool CPU::SupportsCrankshaft() {
56257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  return CpuFeatures::IsSupported(FPU);
573100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}
583100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
5944f0eee88ff00398ff7f715fab053374d808c90dSteve Block
603100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescuvoid CPU::FlushICache(void* start, size_t size) {
61257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  // Nothing to do, flushing no instructions.
62257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  if (size == 0) {
63257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch    return;
64257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  }
65257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch
6644f0eee88ff00398ff7f715fab053374d808c90dSteve Block#if !defined (USE_SIMULATOR)
673ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch#if defined(ANDROID)
683ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  // Bionic cacheflush can typically run in userland, avoiding kernel call.
693ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  char *end = reinterpret_cast<char *>(start) + size;
703ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch  cacheflush(
713ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch    reinterpret_cast<intptr_t>(start), reinterpret_cast<intptr_t>(end), 0);
723ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch#else  // ANDROID
733100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  int res;
74257744e915dfc84d6d07a6b2accf8402d9ffc708Ben Murdoch  // See http://www.linux-mips.org/wiki/Cacheflush_Syscall.
753100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  res = syscall(__NR_cacheflush, start, size, ICACHE);
763100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  if (res) {
773100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu    V8_Fatal(__FILE__, __LINE__, "Failed to flush the instruction cache");
783100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  }
793ef787dbeca8a5fb1086949cda830dccee07bfbdBen Murdoch#endif  // ANDROID
8044f0eee88ff00398ff7f715fab053374d808c90dSteve Block#else  // USE_SIMULATOR.
8144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // Not generating mips instructions for C-code. This means that we are
8244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // building a mips emulator based target.  We should notify the simulator
8344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // that the Icache was flushed.
8444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // None of this code ends up in the snapshot so there are no issues
8544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // around whether or not to generate the code when building snapshots.
8644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  Simulator::FlushICache(Isolate::Current()->simulator_i_cache(), start, size);
8744f0eee88ff00398ff7f715fab053374d808c90dSteve Block#endif  // USE_SIMULATOR.
883100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}
893100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
903100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
913100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescuvoid CPU::DebugBreak() {
923100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#ifdef __mips
933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  asm volatile("break");
943100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#endif  // #ifdef __mips
953100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu}
963100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
9744f0eee88ff00398ff7f715fab053374d808c90dSteve Block
983100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu} }  // namespace v8::internal
993100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu
100f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke#endif  // V8_TARGET_ARCH_MIPS
101