blob: a783d48ed24c9231d53b43aeff4514f59166862f [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
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020037 void FillCalleeSaves(const StackVisitor& fr) OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
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
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010047 bool IsAccessibleGPR(uint32_t reg) OVERRIDE {
48 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
49 return gprs_[reg] != nullptr;
50 }
51
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020052 uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE {
Mathieu Chartier17a7fc72014-02-19 11:18:43 -080053 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
Mathieu Chartier815873e2014-02-13 18:02:13 -080054 return gprs_[reg];
55 }
56
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010057 uintptr_t GetGPR(uint32_t reg) OVERRIDE {
Mathieu Chartier17a7fc72014-02-19 11:18:43 -080058 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters));
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010059 DCHECK(IsAccessibleGPR(reg));
60 return *gprs_[reg];
Ian Rogersd6b1f612011-09-27 13:38:14 -070061 }
62
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010063 void SetGPR(uint32_t reg, uintptr_t value) OVERRIDE;
Mathieu Chartier67022432012-11-29 18:04:50 -080064
Mark P Mendell966c3ae2015-01-27 15:45:27 +000065 bool IsAccessibleFPR(uint32_t reg) OVERRIDE {
66 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters));
67 return fprs_[reg] != nullptr;
Mark Mendell3d2c8e72015-01-13 17:32:55 -050068 }
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020069
Mark P Mendell966c3ae2015-01-27 15:45:27 +000070 uintptr_t GetFPR(uint32_t reg) OVERRIDE {
71 DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters));
72 DCHECK(IsAccessibleFPR(reg));
73 return *fprs_[reg];
74 }
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010075
76 void SetFPR(uint32_t reg, uintptr_t value) OVERRIDE;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020077
78 void SmashCallerSaves() OVERRIDE;
Andreas Gampe794ad762015-02-23 08:12:24 -080079 NO_RETURN void DoLongJump() OVERRIDE;
Ian Rogersbdb03912011-09-14 00:55:44 -070080
81 private:
Mark P Mendell966c3ae2015-01-27 15:45:27 +000082 // 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
Mathieu Chartier2cebb242015-04-21 16:50:40 -070095 // 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 P Mendell966c3ae2015-01-27 15:45:27 +000097 uint32_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_