Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 16 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_ |
| 18 | #define ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_ |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 19 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 20 | #include "arch/context.h" |
| 21 | #include "base/logging.h" |
| 22 | #include "registers_x86.h" |
Ian Rogers | 67375ac | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 23 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 24 | namespace art { |
| 25 | namespace x86 { |
| 26 | |
| 27 | class X86Context : public Context { |
| 28 | public: |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 29 | X86Context() { |
| 30 | Reset(); |
| 31 | } |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 32 | virtual ~X86Context() {} |
| 33 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 34 | void Reset() OVERRIDE; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 35 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 36 | void FillCalleeSaves(const StackVisitor& fr) OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 37 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 38 | void SetSP(uintptr_t new_sp) OVERRIDE { |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame^] | 39 | SetGPR(ESP, new_sp); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 42 | void SetPC(uintptr_t new_pc) OVERRIDE { |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 43 | eip_ = new_pc; |
| 44 | } |
| 45 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame^] | 46 | bool IsAccessibleGPR(uint32_t reg) OVERRIDE { |
| 47 | DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters)); |
| 48 | return gprs_[reg] != nullptr; |
| 49 | } |
| 50 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 51 | uintptr_t* GetGPRAddress(uint32_t reg) OVERRIDE { |
Mathieu Chartier | 17a7fc7 | 2014-02-19 11:18:43 -0800 | [diff] [blame] | 52 | DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters)); |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 53 | return gprs_[reg]; |
| 54 | } |
| 55 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame^] | 56 | uintptr_t GetGPR(uint32_t reg) OVERRIDE { |
Mathieu Chartier | 17a7fc7 | 2014-02-19 11:18:43 -0800 | [diff] [blame] | 57 | DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfCpuRegisters)); |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame^] | 58 | DCHECK(IsAccessibleGPR(reg)); |
| 59 | return *gprs_[reg]; |
Ian Rogers | d6b1f61 | 2011-09-27 13:38:14 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame^] | 62 | void SetGPR(uint32_t reg, uintptr_t value) OVERRIDE; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 63 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame^] | 64 | bool IsAccessibleFPR(uint32_t reg) OVERRIDE { |
Mark Mendell | 3d2c8e7 | 2015-01-13 17:32:55 -0500 | [diff] [blame] | 65 | DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters)); |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame^] | 66 | return fprs_[reg] != nullptr; |
Mark Mendell | 3d2c8e7 | 2015-01-13 17:32:55 -0500 | [diff] [blame] | 67 | } |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 68 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame^] | 69 | uintptr_t GetFPR(uint32_t reg) OVERRIDE { |
| 70 | DCHECK_LT(reg, static_cast<uint32_t>(kNumberOfFloatRegisters)); |
| 71 | DCHECK(IsAccessibleFPR(reg)); |
| 72 | return *fprs_[reg]; |
| 73 | } |
| 74 | |
| 75 | void SetFPR(uint32_t reg, uintptr_t value) OVERRIDE; |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 76 | |
| 77 | void SmashCallerSaves() OVERRIDE; |
| 78 | void DoLongJump() OVERRIDE; |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 79 | |
| 80 | private: |
Mark Mendell | 3d2c8e7 | 2015-01-13 17:32:55 -0500 | [diff] [blame] | 81 | // Pretend XMM registers are made of uin32_t pieces, because they are manipulated |
| 82 | // in uint32_t chunks. |
| 83 | enum { |
| 84 | XMM0_0 = 0, XMM0_1, |
| 85 | XMM1_0, XMM1_1, |
| 86 | XMM2_0, XMM2_1, |
| 87 | XMM3_0, XMM3_1, |
| 88 | XMM4_0, XMM4_1, |
| 89 | XMM5_0, XMM5_1, |
| 90 | XMM6_0, XMM6_1, |
| 91 | XMM7_0, XMM7_1, |
| 92 | kNumberOfFloatRegisters}; |
| 93 | |
| 94 | // Pointers to register locations. Values are initialized to NULL or the special registers below. |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 95 | uintptr_t* gprs_[kNumberOfCpuRegisters]; |
Mark Mendell | 3d2c8e7 | 2015-01-13 17:32:55 -0500 | [diff] [blame] | 96 | uintptr_t* fprs_[kNumberOfFloatRegisters]; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 97 | // Hold values for esp and eip if they are not located within a stack frame. EIP is somewhat |
| 98 | // special in that it cannot be encoded normally as a register operand to an instruction (except |
| 99 | // in 64bit addressing modes). |
| 100 | uintptr_t esp_, eip_; |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 101 | }; |
| 102 | } // namespace x86 |
| 103 | } // namespace art |
| 104 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 105 | #endif // ART_RUNTIME_ARCH_X86_CONTEXT_X86_H_ |