blob: 32ca005a762b55da64fda63eccc211e816a3c5f9 [file] [log] [blame]
Phil Wang751beff2015-08-28 15:17:15 +08001/*
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 Gampe71da4872017-07-26 10:02:07 -070017#include "code_simulator_arm64.h"
Phil Wang751beff2015-08-28 15:17:15 +080018
Ulya Trafimovich5439f052020-07-29 10:03:46 +010019#include <android-base/logging.h>
Andreas Gampebda1d602016-08-29 17:43:45 -070020
Scott Wakeling97c72b72016-06-24 16:19:36 +010021using namespace vixl::aarch64; // NOLINT(build/namespaces)
22
Phil Wang751beff2015-08-28 15:17:15 +080023namespace art {
24namespace arm64 {
25
Scott Wakeling97c72b72016-06-24 16:19:36 +010026// VIXL has not been tested on 32bit architectures, so Simulator is not always
Phil Wang751beff2015-08-28 15:17:15 +080027// 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 Wakeling97c72b72016-06-24 16:19:36 +010029// TODO: when Simulator is always available, remove the these checks.
Phil Wang751beff2015-08-28 15:17:15 +080030
31CodeSimulatorArm64* CodeSimulatorArm64::CreateCodeSimulatorArm64() {
32 if (kCanSimulate) {
33 return new CodeSimulatorArm64();
34 } else {
35 return nullptr;
36 }
37}
38
39CodeSimulatorArm64::CodeSimulatorArm64()
40 : CodeSimulator(), decoder_(nullptr), simulator_(nullptr) {
41 DCHECK(kCanSimulate);
Scott Wakeling97c72b72016-06-24 16:19:36 +010042 decoder_ = new Decoder();
Artem Serova07de552020-11-01 22:42:43 +000043
44 SimStack stack_builder;
45 stack_builder.SetLimitGuardSize(0x4000);
46 stack_builder.SetUsableSize(0x4000);
47 SimStack::Allocated stack = stack_builder.Allocate();
48
49 simulator_ = new Simulator(decoder_, stdout, std::move(stack));
Phil Wang751beff2015-08-28 15:17:15 +080050}
51
52CodeSimulatorArm64::~CodeSimulatorArm64() {
53 DCHECK(kCanSimulate);
54 delete simulator_;
55 delete decoder_;
56}
57
58void CodeSimulatorArm64::RunFrom(intptr_t code_buffer) {
59 DCHECK(kCanSimulate);
Ulya Trafimovich5439f052020-07-29 10:03:46 +010060 simulator_->RunFrom(reinterpret_cast<const Instruction*>(code_buffer));
Phil Wang751beff2015-08-28 15:17:15 +080061}
62
63bool CodeSimulatorArm64::GetCReturnBool() const {
64 DCHECK(kCanSimulate);
Scott Wakeling97c72b72016-06-24 16:19:36 +010065 return simulator_->ReadWRegister(0);
Phil Wang751beff2015-08-28 15:17:15 +080066}
67
68int32_t CodeSimulatorArm64::GetCReturnInt32() const {
69 DCHECK(kCanSimulate);
Scott Wakeling97c72b72016-06-24 16:19:36 +010070 return simulator_->ReadWRegister(0);
Phil Wang751beff2015-08-28 15:17:15 +080071}
72
73int64_t CodeSimulatorArm64::GetCReturnInt64() const {
74 DCHECK(kCanSimulate);
Scott Wakeling97c72b72016-06-24 16:19:36 +010075 return simulator_->ReadXRegister(0);
Phil Wang751beff2015-08-28 15:17:15 +080076}
77
Phil Wang751beff2015-08-28 15:17:15 +080078} // namespace arm64
79} // namespace art