OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_OS_FUCHSIA) | 6 #if defined(TARGET_OS_FUCHSIA) |
7 | 7 |
8 #include "vm/cpuinfo.h" | 8 #include "vm/cpuinfo.h" |
9 | 9 |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
11 | 11 #include "vm/cpuid.h" |
12 // TODO(zra): Use "vm/cpuid.h" | |
13 | 12 |
14 namespace dart { | 13 namespace dart { |
15 | 14 |
16 CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault; | 15 CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault; |
17 const char* CpuInfo::fields_[kCpuInfoMax] = {0}; | 16 const char* CpuInfo::fields_[kCpuInfoMax] = {0}; |
18 | 17 |
19 void CpuInfo::InitOnce() { | 18 void CpuInfo::InitOnce() { |
20 UNIMPLEMENTED(); | 19 // TODO(zra): Add support for HOST_ARCH_ARM64 |
| 20 #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64) |
| 21 method_ = kCpuInfoCpuId; |
| 22 |
| 23 // Initialize the CpuId information. |
| 24 CpuId::InitOnce(); |
| 25 |
| 26 fields_[kCpuInfoProcessor] = "Processor"; |
| 27 fields_[kCpuInfoModel] = "Hardware"; |
| 28 fields_[kCpuInfoHardware] = "Hardware"; |
| 29 fields_[kCpuInfoFeatures] = "Features"; |
| 30 #endif |
21 } | 31 } |
22 | 32 |
23 | 33 |
24 void CpuInfo::Cleanup() { | 34 void CpuInfo::Cleanup() { |
25 UNIMPLEMENTED(); | 35 if (method_ == kCpuInfoCpuId) { |
| 36 CpuId::Cleanup(); |
| 37 } |
26 } | 38 } |
27 | 39 |
28 | 40 |
29 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { | 41 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { |
30 UNIMPLEMENTED(); | 42 if (method_ == kCpuInfoCpuId) { |
31 return false; | 43 return strstr(CpuId::field(idx), search_string); |
| 44 } else { |
| 45 return false; |
| 46 } |
32 } | 47 } |
33 | 48 |
34 | 49 |
35 const char* CpuInfo::ExtractField(CpuInfoIndices idx) { | 50 const char* CpuInfo::ExtractField(CpuInfoIndices idx) { |
36 UNIMPLEMENTED(); | 51 if (method_ == kCpuInfoCpuId) { |
37 return "<undefined>"; | 52 return CpuId::field(idx); |
| 53 } else { |
| 54 return strdup(""); |
| 55 } |
38 } | 56 } |
39 | 57 |
40 | 58 |
41 bool CpuInfo::HasField(const char* field) { | 59 bool CpuInfo::HasField(const char* field) { |
42 UNIMPLEMENTED(); | 60 if (method_ == kCpuInfoCpuId) { |
43 return false; | 61 return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) || |
| 62 (strcmp(field, fields_[kCpuInfoModel]) == 0) || |
| 63 (strcmp(field, fields_[kCpuInfoHardware]) == 0) || |
| 64 (strcmp(field, fields_[kCpuInfoFeatures]) == 0); |
| 65 } else { |
| 66 return false; |
| 67 } |
44 } | 68 } |
45 | 69 |
46 } // namespace dart | 70 } // namespace dart |
47 | 71 |
48 #endif // defined(TARGET_OS_FUCHSIA) | 72 #endif // defined(TARGET_OS_FUCHSIA) |
OLD | NEW |