blob: f482d9ffcb9b32222fbdb7c87ff9207c5c22814c [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"
Andreas Gampe794ad762015-02-23 08:12:24 -080022#include "base/macros.h"
Ian Rogers166db042013-07-26 12:05:57 -070023#include "registers_x86.h"
Ian Rogers67375ac2011-09-14 00:55:44 -070024
Ian Rogersbdb03912011-09-14 00:55:44 -070025namespace art {
26namespace x86 {
27
28class X86Context : public Context {
29 public:
Mathieu Chartier67022432012-11-29 18:04:50 -080030 X86Context() {
31 Reset();
32 }
Ian Rogersbdb03912011-09-14 00:55:44 -070033 virtual ~X86Context() {}
34
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020035 void Reset() OVERRIDE;
Mathieu Chartier67022432012-11-29 18:04:50 -080036
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010037 void FillCalleeSaves(uint8_t* frame, const QuickMethodFrameInfo& fr) OVERRIDE;
Ian Rogersbdb03912011-09-14 00:55:44 -070038
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020039 void SetSP(uintptr_t new_sp) OVERRIDE {
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010040 SetGPR(ESP, new_sp);
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
Andreas Gampe639bdd12015-06-03 11:22:45 -070047 void SetArg0(uintptr_t new_arg0_value) OVERRIDE {
48 SetGPR(EAX, new_arg0_value);
49 }
50
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010051 bool IsAccessibleGPR(uint32_t reg) OVERRIDE {
52 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
53 return gprs_[reg] != nullptr;
54 }
55
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020056 uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE {
Mathieu Chartier17a7fc72014-02-19 11:18:43 -080057 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
Mathieu Chartier815873e2014-02-13 18:02:13 -080058 return gprs_[reg];
59 }
60
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010061 uintptr_t GetGPR(uint32_t reg) OVERRIDE {
Mathieu Chartier17a7fc72014-02-19 11:18:43 -080062 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010063 DCHECK(IsAccessibleGPR(reg));
64 return *gprs_[reg];
Ian Rogersd6b1f612011-09-27 13:38:14 -070065 }
66
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010067 void SetGPR(uint32_t reg, uintptr_t value) OVERRIDE;
Mathieu Chartier67022432012-11-29 18:04:50 -080068
Mark P Mendell966c3ae2015-01-27 15:45:27 +000069 bool IsAccessibleFPR(uint32_t reg) OVERRIDE {
70 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters));
71 return fprs_[reg] != nullptr;
Mark Mendell3d2c8e72015-01-13 17:32:55 -050072 }
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020073
Mark P Mendell966c3ae2015-01-27 15:45:27 +000074 uintptr_t GetFPR(uint32_t reg) OVERRIDE {
75 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters));
76 DCHECK(IsAccessibleFPR(reg));
77 return *fprs_[reg];
78 }
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010079
80 void SetFPR(uint32_t reg, uintptr_t value) OVERRIDE;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020081
82 void SmashCallerSaves() OVERRIDE;
Andreas Gampe794ad762015-02-23 08:12:24 -080083 NO_RETURN void DoLongJump() OVERRIDE;
Ian Rogersbdb03912011-09-14 00:55:44 -070084
85 private:
Mark P Mendell966c3ae2015-01-27 15:45:27 +000086 // Pretend XMM registers are made of uin32_t pieces, because they are manipulated
87 // in uint32_t chunks.
88 enum {
89 XMM0_0 = 0, XMM0_1,
90 XMM1_0, XMM1_1,
91 XMM2_0, XMM2_1,
92 XMM3_0, XMM3_1,
93 XMM4_0, XMM4_1,
94 XMM5_0, XMM5_1,
95 XMM6_0, XMM6_1,
96 XMM7_0, XMM7_1,
97 kNumberOfFloatRegisters};
98
Mathieu Chartier2cebb242015-04-21 16:50:40 -070099 // Pointers to register locations. Values are initialized to null or the special registers below.
Mathieu Chartier67022432012-11-29 18:04:50 -0800100 uintptr_t* gprs_[kNumberOfCpuRegisters];
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000101 uint32_t* fprs_[kNumberOfFloatRegisters];
Andreas Gampe639bdd12015-06-03 11:22:45 -0700102 // Hold values for esp, eip and arg0 if they are not located within a stack frame. EIP is somewhat
Mathieu Chartier67022432012-11-29 18:04:50 -0800103 // special in that it cannot be encoded normally as a register operand to an instruction (except
104 // in 64bit addressing modes).
Andreas Gampe639bdd12015-06-03 11:22:45 -0700105 uintptr_t esp_, eip_, arg0_;
Ian Rogersbdb03912011-09-14 00:55:44 -0700106};
107} // namespace x86
108} // namespace art
109
Ian Rogers166db042013-07-26 12:05:57 -0700110#endif // ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_