2014-04-02 17:39:32 +00:00
|
|
|
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "vm/globals.h"
|
|
|
|
#if defined(TARGET_ARCH_ARM64)
|
|
|
|
|
|
|
|
#include "vm/cpu.h"
|
2016-08-08 19:43:13 +00:00
|
|
|
#include "vm/cpu_arm64.h"
|
|
|
|
|
2014-04-02 17:39:32 +00:00
|
|
|
#include "vm/cpuinfo.h"
|
|
|
|
#include "vm/simulator.h"
|
|
|
|
|
2015-05-29 21:35:29 +00:00
|
|
|
#if !defined(USING_SIMULATOR)
|
2017-05-24 21:23:13 +00:00
|
|
|
#if !defined(HOST_OS_FUCHSIA)
|
2017-07-25 23:07:38 +00:00
|
|
|
#include <sys/syscall.h>
|
|
|
|
#else
|
2017-09-15 14:54:18 +00:00
|
|
|
#include <zircon/syscalls.h>
|
2017-05-24 21:23:13 +00:00
|
|
|
#endif
|
2017-07-25 23:07:38 +00:00
|
|
|
#include <unistd.h>
|
2014-04-02 17:39:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
|
|
|
void CPU::FlushICache(uword start, uword size) {
|
2017-03-15 20:11:05 +00:00
|
|
|
#if HOST_OS_IOS
|
2015-10-22 19:26:41 +00:00
|
|
|
// Precompilation never patches code so there should be no I cache flushes.
|
|
|
|
UNREACHABLE();
|
|
|
|
#endif
|
|
|
|
|
2017-03-15 20:11:05 +00:00
|
|
|
#if !defined(USING_SIMULATOR) && !HOST_OS_IOS
|
2014-05-27 18:05:20 +00:00
|
|
|
// Nothing to do. Flushing no instructions.
|
|
|
|
if (size == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-08 21:54:47 +00:00
|
|
|
// ARM recommends using the gcc intrinsic __clear_cache on Linux and Android.
|
|
|
|
// blogs.arm.com/software-enablement/141-caches-and-self-modifying-code/
|
2017-07-25 23:07:38 +00:00
|
|
|
#if defined(HOST_OS_ANDROID) || defined(HOST_OS_LINUX)
|
2016-11-08 21:54:47 +00:00
|
|
|
extern void __clear_cache(char*, char*);
|
|
|
|
char* beg = reinterpret_cast<char*>(start);
|
|
|
|
char* end = reinterpret_cast<char*>(start + size);
|
|
|
|
::__clear_cache(beg, end);
|
2017-07-25 23:07:38 +00:00
|
|
|
#elif defined(HOST_OS_FUCHSIA)
|
2017-09-15 14:54:18 +00:00
|
|
|
zx_status_t result = zx_cache_flush(reinterpret_cast<const void*>(start),
|
|
|
|
size, ZX_CACHE_FLUSH_INSN);
|
|
|
|
ASSERT(result == ZX_OK);
|
2016-11-08 21:54:47 +00:00
|
|
|
#else
|
|
|
|
#error FlushICache only tested/supported on Android, Fuchsia, and Linux
|
|
|
|
#endif
|
2014-05-27 18:05:20 +00:00
|
|
|
|
2014-04-02 17:39:32 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* CPU::Id() {
|
|
|
|
return
|
2015-05-29 21:35:29 +00:00
|
|
|
#if defined(USING_SIMULATOR)
|
2016-11-08 21:54:47 +00:00
|
|
|
"sim"
|
2014-04-02 17:39:32 +00:00
|
|
|
#endif // !defined(HOST_ARCH_ARM64)
|
2016-11-08 21:54:47 +00:00
|
|
|
"arm64";
|
2014-04-02 17:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* HostCPUFeatures::hardware_ = NULL;
|
|
|
|
#if defined(DEBUG)
|
|
|
|
bool HostCPUFeatures::initialized_ = false;
|
|
|
|
#endif
|
|
|
|
|
2015-05-29 21:35:29 +00:00
|
|
|
#if !defined(USING_SIMULATOR)
|
2014-04-02 17:39:32 +00:00
|
|
|
void HostCPUFeatures::InitOnce() {
|
|
|
|
CpuInfo::InitOnce();
|
|
|
|
hardware_ = CpuInfo::GetCpuModel();
|
|
|
|
#if defined(DEBUG)
|
|
|
|
initialized_ = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostCPUFeatures::Cleanup() {
|
|
|
|
DEBUG_ASSERT(initialized_);
|
|
|
|
#if defined(DEBUG)
|
|
|
|
initialized_ = false;
|
|
|
|
#endif
|
|
|
|
ASSERT(hardware_ != NULL);
|
|
|
|
free(const_cast<char*>(hardware_));
|
|
|
|
hardware_ = NULL;
|
|
|
|
CpuInfo::Cleanup();
|
|
|
|
}
|
|
|
|
|
2015-05-29 21:35:29 +00:00
|
|
|
#else // !defined(USING_SIMULATOR)
|
2014-04-02 17:39:32 +00:00
|
|
|
|
|
|
|
void HostCPUFeatures::InitOnce() {
|
|
|
|
CpuInfo::InitOnce();
|
|
|
|
hardware_ = CpuInfo::GetCpuModel();
|
|
|
|
#if defined(DEBUG)
|
|
|
|
initialized_ = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostCPUFeatures::Cleanup() {
|
|
|
|
DEBUG_ASSERT(initialized_);
|
|
|
|
#if defined(DEBUG)
|
|
|
|
initialized_ = false;
|
|
|
|
#endif
|
|
|
|
ASSERT(hardware_ != NULL);
|
|
|
|
free(const_cast<char*>(hardware_));
|
|
|
|
hardware_ = NULL;
|
|
|
|
CpuInfo::Cleanup();
|
|
|
|
}
|
2015-05-29 21:35:29 +00:00
|
|
|
#endif // !defined(USING_SIMULATOR)
|
2014-04-02 17:39:32 +00:00
|
|
|
|
|
|
|
} // namespace dart
|
|
|
|
|
|
|
|
#endif // defined TARGET_ARCH_ARM64
|