blob: 75eb8ca8d5c9798b266144121dd1393fe1f24403 [file] [log] [blame]
Ian Rogersbdb03912011-09-14 00:55:44 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_CONTEXT_H_
4#define ART_SRC_CONTEXT_H_
5
Elliott Hughes68fdbd02011-11-29 19:22:47 -08006#include <stddef.h>
Ian Rogersbdb03912011-09-14 00:55:44 -07007#include <stdint.h>
8
9namespace art {
10
11class Frame;
12
13// Representation of a thread's context on the executing machine
14class 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 Rogersd6b1f612011-09-27 13:38:14 -070031 // Read the given GPR
32 virtual uintptr_t GetGPR(uint32_t reg) = 0;
33
Ian Rogersbdb03912011-09-14 00:55:44 -070034 // Switch execution of the executing context to this context
35 virtual void DoLongJump() = 0;
36};
37
Elliott Hughes68fdbd02011-11-29 19:22:47 -080038class 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 Rogersbdb03912011-09-14 00:55:44 -070074} // namespace art
75
76#endif // ART_SRC_CONTEXT_H_