OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #include "vm/globals.h" | |
6 #if defined(TARGET_ARCH_MIPS) | |
7 | |
8 #include "vm/cpu.h" | |
9 #include "vm/cpu_mips.h" | |
10 | |
11 #include "vm/cpuinfo.h" | |
12 #include "vm/simulator.h" | |
13 | |
14 #if !defined(USING_SIMULATOR) | |
15 #include <asm/cachectl.h> /* NOLINT */ | |
16 #include <sys/syscall.h> /* NOLINT */ | |
17 #include <unistd.h> /* NOLINT */ | |
18 #endif | |
19 | |
20 namespace dart { | |
21 | |
22 void CPU::FlushICache(uword start, uword size) { | |
23 #if !defined(USING_SIMULATOR) | |
24 int res; | |
25 // See http://www.linux-mips.org/wiki/Cacheflush_Syscall. | |
26 res = syscall(__NR_cacheflush, start, size, ICACHE); | |
27 ASSERT(res == 0); | |
28 #else // defined(HOST_ARCH_MIPS) | |
29 // When running in simulated mode we do not need to flush the ICache because | |
30 // we are not running on the actual hardware. | |
31 #endif // defined(HOST_ARCH_MIPS) | |
32 } | |
33 | |
34 | |
35 const char* CPU::Id() { | |
36 return | |
37 #if defined(USING_SIMULATOR) | |
38 "sim" | |
39 #endif // !defined(HOST_ARCH_MIPS) | |
40 "mips"; | |
41 } | |
42 | |
43 | |
44 const char* HostCPUFeatures::hardware_ = NULL; | |
45 MIPSVersion HostCPUFeatures::mips_version_ = MIPSvUnknown; | |
46 #if defined(DEBUG) | |
47 bool HostCPUFeatures::initialized_ = false; | |
48 #endif | |
49 | |
50 | |
51 #if !defined(USING_SIMULATOR) | |
52 void HostCPUFeatures::InitOnce() { | |
53 CpuInfo::InitOnce(); | |
54 hardware_ = CpuInfo::GetCpuModel(); | |
55 // Has a floating point unit. | |
56 ASSERT(CpuInfo::FieldContains(kCpuInfoModel, "FPU")); | |
57 | |
58 // We want to know the ISA version, but on MIPS, CpuInfo can't tell us, so | |
59 // we use the same ISA version that Dart's C++ compiler targeted. | |
60 #if defined(_MIPS_ARCH_MIPS32R2) | |
61 mips_version_ = MIPS32r2; | |
62 #elif defined(_MIPS_ARCH_MIPS32) | |
63 mips_version_ = MIPS32; | |
64 #endif | |
65 | |
66 #if defined(DEBUG) | |
67 initialized_ = true; | |
68 #endif | |
69 } | |
70 | |
71 | |
72 void HostCPUFeatures::Cleanup() { | |
73 DEBUG_ASSERT(initialized_); | |
74 #if defined(DEBUG) | |
75 initialized_ = false; | |
76 #endif | |
77 ASSERT(hardware_ != NULL); | |
78 free(const_cast<char*>(hardware_)); | |
79 hardware_ = NULL; | |
80 CpuInfo::Cleanup(); | |
81 } | |
82 | |
83 #else | |
84 | |
85 void HostCPUFeatures::InitOnce() { | |
86 CpuInfo::InitOnce(); | |
87 hardware_ = CpuInfo::GetCpuModel(); | |
88 mips_version_ = MIPS32r2; | |
89 #if defined(DEBUG) | |
90 initialized_ = true; | |
91 #endif | |
92 } | |
93 | |
94 | |
95 void HostCPUFeatures::Cleanup() { | |
96 DEBUG_ASSERT(initialized_); | |
97 #if defined(DEBUG) | |
98 initialized_ = false; | |
99 #endif | |
100 ASSERT(hardware_ != NULL); | |
101 free(const_cast<char*>(hardware_)); | |
102 hardware_ = NULL; | |
103 CpuInfo::Cleanup(); | |
104 } | |
105 #endif // defined(HOST_ARCH_MIPS) | |
106 | |
107 } // namespace dart | |
108 | |
109 #endif // defined TARGET_ARCH_MIPS | |
OLD | NEW |