1 /*
2 * Copyright (C) 2019 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 "berberis/guest_state/guest_state.h"
18
19 #include "berberis/base/macros.h"
20 #include "berberis/guest_state/guest_addr.h"
21
22 namespace berberis {
23
SetReturnValueRegister(CPUState & cpu,GuestAddr val)24 void SetReturnValueRegister(CPUState& cpu, GuestAddr val) {
25 cpu.r[0] = val;
26 }
27
GetReturnValueRegister(const CPUState & cpu)28 GuestAddr GetReturnValueRegister(const CPUState& cpu) {
29 return cpu.r[0];
30 }
31
SetStackRegister(CPUState & cpu,GuestAddr val)32 void SetStackRegister(CPUState& cpu, GuestAddr val) {
33 cpu.r[13] = val;
34 }
35
GetStackRegister(const CPUState & cpu)36 GuestAddr GetStackRegister(const CPUState& cpu) {
37 return cpu.r[13];
38 }
39
SetLinkRegister(CPUState & cpu,GuestAddr val)40 void SetLinkRegister(CPUState& cpu, GuestAddr val) {
41 cpu.r[14] = val;
42 }
43
GetLinkRegister(const CPUState & cpu)44 GuestAddr GetLinkRegister(const CPUState& cpu) {
45 return cpu.r[14];
46 }
47
SetTlsAddr(ThreadState & state,GuestAddr addr)48 void SetTlsAddr(ThreadState& state, GuestAddr addr) {
49 state.tls = addr;
50 }
51
GetTlsAddr(const ThreadState & state)52 GuestAddr GetTlsAddr(const ThreadState& state) {
53 return state.tls;
54 }
55
SetShadowCallStackPointer(CPUState & cpu,GuestAddr scs_sp)56 void SetShadowCallStackPointer(CPUState& cpu, GuestAddr scs_sp) {
57 UNUSED(cpu, scs_sp);
58 }
59
AdvanceInsnAddrBeyondSyscall(CPUState & cpu)60 void AdvanceInsnAddrBeyondSyscall(CPUState& cpu) {
61 if (cpu.insn_addr % 2 == 0) {
62 cpu.insn_addr += 4;
63 } else {
64 // Thumb SVC is always 2 bytes.
65 cpu.insn_addr += 2;
66 }
67 }
68
69 } // namespace berberis
70