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_CONTEXT_H_ |
| 18 | #define ART_RUNTIME_ARCH_CONTEXT_H_ |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 19 | |
Elliott Hughes | 68fdbd0 | 2011-11-29 19:22:47 -0800 | [diff] [blame] | 20 | #include <stddef.h> |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
| 22 | |
Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 23 | #include "base/macros.h" |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 24 | #include "base/mutex.h" |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 25 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 26 | namespace art { |
| 27 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 28 | class StackVisitor; |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 29 | |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 30 | // Representation of a thread's context on the executing machine, used to implement long jumps in |
| 31 | // the quick stack frame layout. |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 32 | class Context { |
| 33 | public: |
| 34 | // Creates a context for the running architecture |
| 35 | static Context* Create(); |
| 36 | |
| 37 | virtual ~Context() {} |
| 38 | |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 39 | // Re-initializes the registers for context re-use. |
| 40 | virtual void Reset() = 0; |
| 41 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 42 | // Reads values from callee saves in the given frame. The frame also holds |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 43 | // the method that holds the layout. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 44 | virtual void FillCalleeSaves(const StackVisitor& fr) |
| 45 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 46 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 47 | // Sets the stack pointer value. |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 48 | virtual void SetSP(uintptr_t new_sp) = 0; |
| 49 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 50 | // Sets the program counter value. |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 51 | virtual void SetPC(uintptr_t new_pc) = 0; |
| 52 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 53 | // Returns whether the given GPR is accessible (read or write). |
| 54 | virtual bool IsAccessibleGPR(uint32_t reg) = 0; |
| 55 | |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 56 | // Gets the given GPRs address. |
| 57 | virtual uintptr_t* GetGPRAddress(uint32_t reg) = 0; |
| 58 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 59 | // Reads the given GPR. The caller is responsible for checking the register |
| 60 | // is accessible with IsAccessibleGPR. |
| 61 | virtual uintptr_t GetGPR(uint32_t reg) = 0; |
Ian Rogers | d6b1f61 | 2011-09-27 13:38:14 -0700 | [diff] [blame] | 62 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 63 | // Sets the given GPR. The caller is responsible for checking the register |
| 64 | // is accessible with IsAccessibleGPR. |
| 65 | virtual void SetGPR(uint32_t reg, uintptr_t value) = 0; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 66 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 67 | // Returns whether the given FPR is accessible (read or write). |
| 68 | virtual bool IsAccessibleFPR(uint32_t reg) = 0; |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 69 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 70 | // Reads the given FPR. The caller is responsible for checking the register |
| 71 | // is accessible with IsAccessibleFPR. |
| 72 | virtual uintptr_t GetFPR(uint32_t reg) = 0; |
| 73 | |
| 74 | // Sets the given FPR. The caller is responsible for checking the register |
| 75 | // is accessible with IsAccessibleFPR. |
| 76 | virtual void SetFPR(uint32_t reg, uintptr_t value) = 0; |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 77 | |
| 78 | // Smashes the caller save registers. If we're throwing, we don't want to return bogus values. |
Elliott Hughes | 9c750f9 | 2012-04-05 12:07:59 -0700 | [diff] [blame] | 79 | virtual void SmashCallerSaves() = 0; |
| 80 | |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 81 | // Switches execution of the executing context to this context |
Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 82 | NO_RETURN virtual void DoLongJump() = 0; |
Elliott Hughes | 9c750f9 | 2012-04-05 12:07:59 -0700 | [diff] [blame] | 83 | |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 84 | protected: |
Elliott Hughes | 9c750f9 | 2012-04-05 12:07:59 -0700 | [diff] [blame] | 85 | enum { |
| 86 | kBadGprBase = 0xebad6070, |
| 87 | kBadFprBase = 0xebad8070, |
| 88 | }; |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 91 | } // namespace art |
| 92 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 93 | #endif // ART_RUNTIME_ARCH_CONTEXT_H_ |