• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #include "code_simulator_arm64.h"
18 
19 #include <android-base/logging.h>
20 
21 using namespace vixl::aarch64;  // NOLINT(build/namespaces)
22 
23 namespace art {
24 
25 // Enable the simulator debugger, disabled by default.
26 static constexpr bool kSimDebuggerEnabled = false;
27 
28 namespace arm64 {
29 
30 // VIXL has not been tested on 32bit architectures, so Simulator is not always
31 // available. To avoid linker error on these architectures, we check if we can simulate
32 // in the beginning of following methods, with compile time constant `kCanSimulate`.
33 // TODO: when Simulator is always available, remove the these checks.
34 
CreateCodeSimulatorArm64()35 CodeSimulatorArm64* CodeSimulatorArm64::CreateCodeSimulatorArm64() {
36   if (kCanSimulate) {
37     return new CodeSimulatorArm64();
38   } else {
39     return nullptr;
40   }
41 }
42 
CodeSimulatorArm64()43 CodeSimulatorArm64::CodeSimulatorArm64()
44     : CodeSimulator(), decoder_(nullptr), simulator_(nullptr) {
45   DCHECK(kCanSimulate);
46   decoder_ = new Decoder();
47 
48   SimStack stack_builder;
49   stack_builder.SetLimitGuardSize(0x4000);
50   stack_builder.SetUsableSize(0x4000);
51   SimStack::Allocated stack = stack_builder.Allocate();
52 
53   simulator_ = new Simulator(decoder_, stdout, std::move(stack));
54   simulator_->SetVectorLengthInBits(kArm64DefaultSVEVectorLength);
55   simulator_->DisableGCSCheck();
56   simulator_->SetDebuggerEnabled(kSimDebuggerEnabled);
57 }
58 
~CodeSimulatorArm64()59 CodeSimulatorArm64::~CodeSimulatorArm64() {
60   DCHECK(kCanSimulate);
61   delete simulator_;
62   delete decoder_;
63 }
64 
RunFrom(intptr_t code_buffer)65 void CodeSimulatorArm64::RunFrom(intptr_t code_buffer) {
66   DCHECK(kCanSimulate);
67   simulator_->RunFrom(reinterpret_cast<const Instruction*>(code_buffer));
68 }
69 
GetCReturnBool() const70 bool CodeSimulatorArm64::GetCReturnBool() const {
71   DCHECK(kCanSimulate);
72   return simulator_->ReadWRegister(0);
73 }
74 
GetCReturnInt32() const75 int32_t CodeSimulatorArm64::GetCReturnInt32() const {
76   DCHECK(kCanSimulate);
77   return simulator_->ReadWRegister(0);
78 }
79 
GetCReturnInt64() const80 int64_t CodeSimulatorArm64::GetCReturnInt64() const {
81   DCHECK(kCanSimulate);
82   return simulator_->ReadXRegister(0);
83 }
84 
85 }  // namespace arm64
86 }  // namespace art
87