blob: 478d11e445a4c7044f930cbe46acefef79c315bf [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Rogersbdb03912011-09-14 00:55:44 -070016
17#ifndef ART_SRC_CONTEXT_H_
18#define ART_SRC_CONTEXT_H_
19
Elliott Hughes68fdbd02011-11-29 19:22:47 -080020#include <stddef.h>
Ian Rogersbdb03912011-09-14 00:55:44 -070021#include <stdint.h>
22
23namespace art {
24
25class Frame;
26
27// Representation of a thread's context on the executing machine
28class 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 Rogersd6b1f612011-09-27 13:38:14 -070045 // Read the given GPR
46 virtual uintptr_t GetGPR(uint32_t reg) = 0;
47
Ian Rogersbdb03912011-09-14 00:55:44 -070048 // Switch execution of the executing context to this context
49 virtual void DoLongJump() = 0;
50};
51
Elliott Hughes68fdbd02011-11-29 19:22:47 -080052class VmapTable {
53 public:
Elliott Hughesff17f1f2012-01-24 18:12:29 -080054 explicit VmapTable(const uint16_t* table) : table_(table) {
Elliott Hughes68fdbd02011-11-29 19:22:47 -080055 }
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
65 // Is register 'reg' in the context or on the stack?
66 bool IsInContext(size_t reg, uint32_t& vmap_offset) const {
67 vmap_offset = 0xEBAD0FF5;
68 // TODO: take advantage of the registers being ordered
69 for (size_t i = 0; i < size(); ++i) {
70 // Stop if we find what we are are looking for...
71 if (table_[i + 1] == reg) {
72 vmap_offset = i;
73 return true;
74 }
75 // ...or the INVALID_VREG that marks lr.
76 // TODO: x86?
77 if (table_[i + 1] == 0xffff) {
78 break;
79 }
80 }
81 return false;
82 }
83
84 private:
85 const uint16_t* table_;
86};
87
Ian Rogersbdb03912011-09-14 00:55:44 -070088} // namespace art
89
90#endif // ART_SRC_CONTEXT_H_