blob: d42420cde13d595dd22bee097158c97dc52b687f [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// Copyright 2014 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 ppc independent of OS goes here.
6#include "src/v8.h"
7
8#if V8_TARGET_ARCH_PPC
9
10#include "src/assembler.h"
11#include "src/macro-assembler.h"
12#include "src/simulator.h" // for cache flushing.
13
14namespace v8 {
15namespace internal {
16
17void CpuFeatures::FlushICache(void* buffer, size_t size) {
18 // Nothing to do flushing no instructions.
19 if (size == 0) {
20 return;
21 }
22
23#if defined(USE_SIMULATOR)
24 // Not generating PPC instructions for C-code. This means that we are
25 // building an PPC emulator based target. We should notify the simulator
26 // that the Icache was flushed.
27 // None of this code ends up in the snapshot so there are no issues
28 // around whether or not to generate the code when building snapshots.
29 Simulator::FlushICache(Isolate::Current()->simulator_i_cache(), buffer, size);
30#else
31
32 if (CpuFeatures::IsSupported(INSTR_AND_DATA_CACHE_COHERENCY)) {
33 __asm__ __volatile__(
34 "sync \n"
35 "icbi 0, %0 \n"
36 "isync \n"
37 : /* no output */
38 : "r"(buffer)
39 : "memory");
40 return;
41 }
42
43 const int kCacheLineSize = CpuFeatures::cache_line_size();
44 intptr_t mask = kCacheLineSize - 1;
45 byte *start =
46 reinterpret_cast<byte *>(reinterpret_cast<intptr_t>(buffer) & ~mask);
47 byte *end = static_cast<byte *>(buffer) + size;
48 for (byte *pointer = start; pointer < end; pointer += kCacheLineSize) {
49 __asm__(
50 "dcbf 0, %0 \n"
51 "sync \n"
52 "icbi 0, %0 \n"
53 "isync \n"
54 : /* no output */
55 : "r"(pointer));
56 }
57
58#endif // USE_SIMULATOR
59}
60}
61} // namespace v8::internal
62
63#endif // V8_TARGET_ARCH_PPC