blob: 82e8315a420339b8d8b715abb09982081306178b [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
buzbee9c044ce2012-03-18 13:24:07 -070065 /*
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 Hughes68fdbd02011-11-29 19:22:47 -080077 // 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 Rogersbdb03912011-09-14 00:55:44 -0700100} // namespace art
101
102#endif // ART_SRC_CONTEXT_H_