Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andreas Gampe | 71da487 | 2017-07-26 10:02:07 -0700 | [diff] [blame] | 17 | #include "code_simulator_arm64.h" |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 18 | |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 19 | #include <android-base/logging.h> |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 20 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 21 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
| 22 | |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 23 | namespace art { |
| 24 | namespace arm64 { |
| 25 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 26 | // VIXL has not been tested on 32bit architectures, so Simulator is not always |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 27 | // available. To avoid linker error on these architectures, we check if we can simulate |
| 28 | // in the beginning of following methods, with compile time constant `kCanSimulate`. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 29 | // TODO: when Simulator is always available, remove the these checks. |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 30 | |
| 31 | CodeSimulatorArm64* CodeSimulatorArm64::CreateCodeSimulatorArm64() { |
| 32 | if (kCanSimulate) { |
| 33 | return new CodeSimulatorArm64(); |
| 34 | } else { |
| 35 | return nullptr; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | CodeSimulatorArm64::CodeSimulatorArm64() |
| 40 | : CodeSimulator(), decoder_(nullptr), simulator_(nullptr) { |
| 41 | DCHECK(kCanSimulate); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 42 | decoder_ = new Decoder(); |
| 43 | simulator_ = new Simulator(decoder_); |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | CodeSimulatorArm64::~CodeSimulatorArm64() { |
| 47 | DCHECK(kCanSimulate); |
| 48 | delete simulator_; |
| 49 | delete decoder_; |
| 50 | } |
| 51 | |
| 52 | void CodeSimulatorArm64::RunFrom(intptr_t code_buffer) { |
| 53 | DCHECK(kCanSimulate); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 54 | simulator_->RunFrom(reinterpret_cast<const Instruction*>(code_buffer)); |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | bool CodeSimulatorArm64::GetCReturnBool() const { |
| 58 | DCHECK(kCanSimulate); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 59 | return simulator_->ReadWRegister(0); |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | int32_t CodeSimulatorArm64::GetCReturnInt32() const { |
| 63 | DCHECK(kCanSimulate); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 64 | return simulator_->ReadWRegister(0); |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | int64_t CodeSimulatorArm64::GetCReturnInt64() const { |
| 68 | DCHECK(kCanSimulate); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 69 | return simulator_->ReadXRegister(0); |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | } // namespace arm64 |
| 73 | } // namespace art |