| 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 | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 24 | |
| Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 25 | namespace art { |
| 26 | |
| Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 27 | class QuickMethodFrameInfo; |
| Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 28 | |
| Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 29 | // Representation of a thread's context on the executing machine, used to implement long jumps in |
| 30 | // the quick stack frame layout. |
| Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 31 | class Context { |
| 32 | public: |
| 33 | // Creates a context for the running architecture |
| 34 | static Context* Create(); |
| 35 | |
| 36 | virtual ~Context() {} |
| 37 | |
| Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 38 | // Re-initializes the registers for context re-use. |
| 39 | virtual void Reset() = 0; |
| 40 | |
| Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 41 | static uintptr_t* CalleeSaveAddress(uint8_t* frame, int num, size_t frame_size) { |
| 42 | // Callee saves are held at the top of the frame |
| 43 | uint8_t* save_addr = frame + frame_size - ((num + 1) * sizeof(void*)); |
| 44 | #if defined(__i386__) || defined(__x86_64__) |
| 45 | save_addr -= sizeof(void*); // account for return address |
| 46 | #endif |
| 47 | return reinterpret_cast<uintptr_t*>(save_addr); |
| 48 | } |
| 49 | |
| Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 50 | // 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] | 51 | // the method that holds the layout. |
| Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 52 | virtual void FillCalleeSaves(uint8_t* frame, const QuickMethodFrameInfo& fr) = 0; |
| Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 53 | |
| Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 54 | // Sets the stack pointer value. |
| Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 55 | virtual void SetSP(uintptr_t new_sp) = 0; |
| 56 | |
| Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 57 | // Sets the program counter value. |
| Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 58 | virtual void SetPC(uintptr_t new_pc) = 0; |
| 59 | |
| Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 60 | // Sets the first argument register. |
| 61 | virtual void SetArg0(uintptr_t new_arg0_value) = 0; |
| 62 | |
| Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 63 | // Returns whether the given GPR is accessible (read or write). |
| 64 | virtual bool IsAccessibleGPR(uint32_t reg) = 0; |
| 65 | |
| Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 66 | // Gets the given GPRs address. |
| 67 | virtual uintptr_t* GetGPRAddress(uint32_t reg) = 0; |
| 68 | |
| Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 69 | // Reads the given GPR. The caller is responsible for checking the register |
| 70 | // is accessible with IsAccessibleGPR. |
| 71 | virtual uintptr_t GetGPR(uint32_t reg) = 0; |
| Ian Rogers | d6b1f61 | 2011-09-27 13:38:14 -0700 | [diff] [blame] | 72 | |
| Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 73 | // Sets the given GPR. The caller is responsible for checking the register |
| 74 | // is accessible with IsAccessibleGPR. |
| 75 | virtual void SetGPR(uint32_t reg, uintptr_t value) = 0; |
| Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 76 | |
| Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 77 | // Returns whether the given FPR is accessible (read or write). |
| 78 | virtual bool IsAccessibleFPR(uint32_t reg) = 0; |
| Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 79 | |
| Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 80 | // Reads the given FPR. The caller is responsible for checking the register |
| 81 | // is accessible with IsAccessibleFPR. |
| 82 | virtual uintptr_t GetFPR(uint32_t reg) = 0; |
| 83 | |
| 84 | // Sets the given FPR. The caller is responsible for checking the register |
| 85 | // is accessible with IsAccessibleFPR. |
| 86 | virtual void SetFPR(uint32_t reg, uintptr_t value) = 0; |
| Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 87 | |
| 88 | // 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] | 89 | virtual void SmashCallerSaves() = 0; |
| 90 | |
| Nicolas Geoffray | 013d1ee | 2019-12-04 16:18:15 +0000 | [diff] [blame] | 91 | // Set `new_value` to the physical register containing the dex PC pointer in |
| 92 | // an nterp frame. |
| 93 | virtual void SetNterpDexPC(uintptr_t new_value ATTRIBUTE_UNUSED) { |
| 94 | abort(); |
| 95 | } |
| 96 | |
| Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 97 | // Switches execution of the executing context to this context |
| Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 98 | NO_RETURN virtual void DoLongJump() = 0; |
| Elliott Hughes | 9c750f9 | 2012-04-05 12:07:59 -0700 | [diff] [blame] | 99 | |
| 100 | enum { |
| 101 | kBadGprBase = 0xebad6070, |
| 102 | kBadFprBase = 0xebad8070, |
| 103 | }; |
| Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
| Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 106 | } // namespace art |
| 107 | |
| Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 108 | #endif // ART_RUNTIME_ARCH_CONTEXT_H_ |