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 | |
| 17 | #ifndef ART_SRC_CONTEXT_H_ |
| 18 | #define ART_SRC_CONTEXT_H_ |
| 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 | |
| 23 | namespace art { |
| 24 | |
| 25 | class Frame; |
| 26 | |
| 27 | // Representation of a thread's context on the executing machine |
| 28 | class Context { |
| 29 | public: |
| 30 | // Creates a context for the running architecture |
| 31 | static Context* Create(); |
| 32 | |
| 33 | virtual ~Context() {} |
| 34 | |
| 35 | // Read values from callee saves in the given frame. The frame also holds |
| 36 | // the method that holds the layout. |
| 37 | virtual void FillCalleeSaves(const Frame& fr) = 0; |
| 38 | |
| 39 | // Set the stack pointer value |
| 40 | virtual void SetSP(uintptr_t new_sp) = 0; |
| 41 | |
| 42 | // Set the program counter value |
| 43 | virtual void SetPC(uintptr_t new_pc) = 0; |
| 44 | |
Ian Rogers | d6b1f61 | 2011-09-27 13:38:14 -0700 | [diff] [blame] | 45 | // Read the given GPR |
| 46 | virtual uintptr_t GetGPR(uint32_t reg) = 0; |
| 47 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 48 | // Switch execution of the executing context to this context |
| 49 | virtual void DoLongJump() = 0; |
| 50 | }; |
| 51 | |
Elliott Hughes | 68fdbd0 | 2011-11-29 19:22:47 -0800 | [diff] [blame] | 52 | class VmapTable { |
| 53 | public: |
Elliott Hughes | ff17f1f | 2012-01-24 18:12:29 -0800 | [diff] [blame] | 54 | explicit VmapTable(const uint16_t* table) : table_(table) { |
Elliott Hughes | 68fdbd0 | 2011-11-29 19:22:47 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | uint16_t operator[](size_t i) const { |
| 58 | return table_[i + 1]; |
| 59 | } |
| 60 | |
| 61 | size_t size() const { |
| 62 | return table_[0]; |
| 63 | } |
| 64 | |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame^] | 65 | /* |
| 66 | * WARNING: This code should be changed or renamed. The "reg" |
| 67 | * argument is a Dalvik virtual register number, but the way |
| 68 | * the vmap and register promotion works a Dalvik vReg can have |
| 69 | * neither, one or both of core register and floating point register |
| 70 | * identities. The "INVALID_VREG" marker of 0xffff below separates the |
| 71 | * core promoted registers from the floating point promoted registers, |
| 72 | * and thus terminates the search before reaching the fp section. |
| 73 | * This is likely the desired behavior for GC, as references won't |
| 74 | * ever be promoted to float registers - but we'll probably want to |
| 75 | * rework this shared code to make it useful for the debugger as well. |
| 76 | */ |
Elliott Hughes | 68fdbd0 | 2011-11-29 19:22:47 -0800 | [diff] [blame] | 77 | // Is register 'reg' in the context or on the stack? |
| 78 | bool IsInContext(size_t reg, uint32_t& vmap_offset) const { |
| 79 | vmap_offset = 0xEBAD0FF5; |
| 80 | // TODO: take advantage of the registers being ordered |
| 81 | for (size_t i = 0; i < size(); ++i) { |
| 82 | // Stop if we find what we are are looking for... |
| 83 | if (table_[i + 1] == reg) { |
| 84 | vmap_offset = i; |
| 85 | return true; |
| 86 | } |
| 87 | // ...or the INVALID_VREG that marks lr. |
| 88 | // TODO: x86? |
| 89 | if (table_[i + 1] == 0xffff) { |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | private: |
| 97 | const uint16_t* table_; |
| 98 | }; |
| 99 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 100 | } // namespace art |
| 101 | |
| 102 | #endif // ART_SRC_CONTEXT_H_ |