blob: d18be54fee2e4db551d65e549ea52d21a13e5971 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 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 */
Ian Rogersbdb03912011-09-14 00:55:44 -070016
Ian Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_
18#define ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_
Ian Rogersbdb03912011-09-14 00:55:44 -070019
Ian Rogers166db042013-07-26 12:05:57 -070020#include "arch/context.h"
21#include "base/logging.h"
22#include "registers_x86.h"
Ian Rogers67375ac2011-09-14 00:55:44 -070023
Ian Rogersbdb03912011-09-14 00:55:44 -070024namespace art {
25namespace x86 {
26
27class X86Context : public Context {
28 public:
Mathieu Chartier67022432012-11-29 18:04:50 -080029 X86Context() {
30 Reset();
31 }
Ian Rogersbdb03912011-09-14 00:55:44 -070032 virtual ~X86Context() {}
33
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020034 void Reset() OVERRIDE;
Mathieu Chartier67022432012-11-29 18:04:50 -080035
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020036 void FillCalleeSaves(const StackVisitor& fr) OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -070037
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020038 void SetSP(uintptr_t new_sp) OVERRIDE {
39 bool success = SetGPR(ESP, new_sp);
40 CHECK(success) << "Failed to set ESP register";
Ian Rogersbdb03912011-09-14 00:55:44 -070041 }
42
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020043 void SetPC(uintptr_t new_pc) OVERRIDE {
Ian Rogersbdb03912011-09-14 00:55:44 -070044 eip_ = new_pc;
45 }
46
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020047 uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE {
Mathieu Chartier17a7fc72014-02-19 11:18:43 -080048 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
Mathieu Chartier815873e2014-02-13 18:02:13 -080049 return gprs_[reg];
50 }
51
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020052 bool GetGPR(uint32_t reg, uintptr_t* val) OVERRIDE {
Mathieu Chartier17a7fc72014-02-19 11:18:43 -080053 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020054 if (gprs_[reg] == nullptr) {
55 return false;
56 } else {
57 DCHECK(val != nullptr);
58 *val = *gprs_[reg];
59 return true;
60 }
Ian Rogersd6b1f612011-09-27 13:38:14 -070061 }
62
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020063 bool SetGPR(uint32_t reg, uintptr_t value) OVERRIDE;
Mathieu Chartier67022432012-11-29 18:04:50 -080064
Mark Mendell3d2c8e72015-01-13 17:32:55 -050065 bool GetFPR(uint32_t reg, uintptr_t* val) OVERRIDE {
66 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters));
67 if (fprs_[reg] == nullptr) {
68 return false;
69 } else {
70 DCHECK(val != nullptr);
71 *val = *fprs_[reg];
72 return true;
73 }
74 }
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020075
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070076 bool SetFPR(uint32_t reg, uintptr_t value) OVERRIDE;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020077
78 void SmashCallerSaves() OVERRIDE;
79 void DoLongJump() OVERRIDE;
Ian Rogersbdb03912011-09-14 00:55:44 -070080
81 private:
Mark Mendell3d2c8e72015-01-13 17:32:55 -050082 // Pretend XMM registers are made of uin32_t pieces, because they are manipulated
83 // in uint32_t chunks.
84 enum {
85 XMM0_0 = 0, XMM0_1,
86 XMM1_0, XMM1_1,
87 XMM2_0, XMM2_1,
88 XMM3_0, XMM3_1,
89 XMM4_0, XMM4_1,
90 XMM5_0, XMM5_1,
91 XMM6_0, XMM6_1,
92 XMM7_0, XMM7_1,
93 kNumberOfFloatRegisters};
94
95 // Pointers to register locations. Values are initialized to NULL or the special registers below.
Mathieu Chartier67022432012-11-29 18:04:50 -080096 uintptr_t* gprs_[kNumberOfCpuRegisters];
Mark Mendell3d2c8e72015-01-13 17:32:55 -050097 uintptr_t* fprs_[kNumberOfFloatRegisters];
Mathieu Chartier67022432012-11-29 18:04:50 -080098 // Hold values for esp and eip if they are not located within a stack frame. EIP is somewhat
99 // special in that it cannot be encoded normally as a register operand to an instruction (except
100 // in 64bit addressing modes).
101 uintptr_t esp_, eip_;
Ian Rogersbdb03912011-09-14 00:55:44 -0700102};
103} // namespace x86
104} // namespace art
105
Ian Rogers166db042013-07-26 12:05:57 -0700106#endif // ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_