Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_CONTEXT_H_ |
| 4 | #define ART_SRC_CONTEXT_H_ |
| 5 | |
Elliott Hughes | 68fdbd0 | 2011-11-29 19:22:47 -0800 | [diff] [blame] | 6 | #include <stddef.h> |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
| 9 | namespace art { |
| 10 | |
| 11 | class Frame; |
| 12 | |
| 13 | // Representation of a thread's context on the executing machine |
| 14 | class Context { |
| 15 | public: |
| 16 | // Creates a context for the running architecture |
| 17 | static Context* Create(); |
| 18 | |
| 19 | virtual ~Context() {} |
| 20 | |
| 21 | // Read values from callee saves in the given frame. The frame also holds |
| 22 | // the method that holds the layout. |
| 23 | virtual void FillCalleeSaves(const Frame& fr) = 0; |
| 24 | |
| 25 | // Set the stack pointer value |
| 26 | virtual void SetSP(uintptr_t new_sp) = 0; |
| 27 | |
| 28 | // Set the program counter value |
| 29 | virtual void SetPC(uintptr_t new_pc) = 0; |
| 30 | |
Ian Rogers | d6b1f61 | 2011-09-27 13:38:14 -0700 | [diff] [blame] | 31 | // Read the given GPR |
| 32 | virtual uintptr_t GetGPR(uint32_t reg) = 0; |
| 33 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 34 | // Switch execution of the executing context to this context |
| 35 | virtual void DoLongJump() = 0; |
| 36 | }; |
| 37 | |
Elliott Hughes | 68fdbd0 | 2011-11-29 19:22:47 -0800 | [diff] [blame] | 38 | class VmapTable { |
| 39 | public: |
| 40 | VmapTable(const uint16_t* table) : table_(table) { |
| 41 | } |
| 42 | |
| 43 | uint16_t operator[](size_t i) const { |
| 44 | return table_[i + 1]; |
| 45 | } |
| 46 | |
| 47 | size_t size() const { |
| 48 | return table_[0]; |
| 49 | } |
| 50 | |
| 51 | // Is register 'reg' in the context or on the stack? |
| 52 | bool IsInContext(size_t reg, uint32_t& vmap_offset) const { |
| 53 | vmap_offset = 0xEBAD0FF5; |
| 54 | // TODO: take advantage of the registers being ordered |
| 55 | for (size_t i = 0; i < size(); ++i) { |
| 56 | // Stop if we find what we are are looking for... |
| 57 | if (table_[i + 1] == reg) { |
| 58 | vmap_offset = i; |
| 59 | return true; |
| 60 | } |
| 61 | // ...or the INVALID_VREG that marks lr. |
| 62 | // TODO: x86? |
| 63 | if (table_[i + 1] == 0xffff) { |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | private: |
| 71 | const uint16_t* table_; |
| 72 | }; |
| 73 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 74 | } // namespace art |
| 75 | |
| 76 | #endif // ART_SRC_CONTEXT_H_ |