blob: 6c7359beeb1bc216b64026de79c1082d0b88012d [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
Ian Rogers57b86d42012-03-27 16:05:41 -070017#ifndef ART_SRC_OAT_RUNTIME_CONTEXT_H_
18#define ART_SRC_OAT_RUNTIME_CONTEXT_H_
Ian Rogersbdb03912011-09-14 00:55:44 -070019
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
Elliott Hughes9c750f92012-04-05 12:07:59 -070048 // Smash the caller save registers. If we're throwing, we don't want to return bogus values.
49 virtual void SmashCallerSaves() = 0;
50
Ian Rogersbdb03912011-09-14 00:55:44 -070051 // Switch execution of the executing context to this context
52 virtual void DoLongJump() = 0;
Elliott Hughes9c750f92012-04-05 12:07:59 -070053
54 enum {
55 kBadGprBase = 0xebad6070,
56 kBadFprBase = 0xebad8070,
57 };
Ian Rogersbdb03912011-09-14 00:55:44 -070058};
59
Elliott Hughes68fdbd02011-11-29 19:22:47 -080060class VmapTable {
61 public:
Elliott Hughesff17f1f2012-01-24 18:12:29 -080062 explicit VmapTable(const uint16_t* table) : table_(table) {
Elliott Hughes68fdbd02011-11-29 19:22:47 -080063 }
64
65 uint16_t operator[](size_t i) const {
66 return table_[i + 1];
67 }
68
69 size_t size() const {
70 return table_[0];
71 }
72
buzbee9c044ce2012-03-18 13:24:07 -070073 /*
74 * WARNING: This code should be changed or renamed. The "reg"
75 * argument is a Dalvik virtual register number, but the way
76 * the vmap and register promotion works a Dalvik vReg can have
77 * neither, one or both of core register and floating point register
78 * identities. The "INVALID_VREG" marker of 0xffff below separates the
79 * core promoted registers from the floating point promoted registers,
80 * and thus terminates the search before reaching the fp section.
81 * This is likely the desired behavior for GC, as references won't
82 * ever be promoted to float registers - but we'll probably want to
83 * rework this shared code to make it useful for the debugger as well.
84 */
Elliott Hughes68fdbd02011-11-29 19:22:47 -080085 // Is register 'reg' in the context or on the stack?
86 bool IsInContext(size_t reg, uint32_t& vmap_offset) const {
87 vmap_offset = 0xEBAD0FF5;
88 // TODO: take advantage of the registers being ordered
89 for (size_t i = 0; i < size(); ++i) {
90 // Stop if we find what we are are looking for...
91 if (table_[i + 1] == reg) {
92 vmap_offset = i;
93 return true;
94 }
95 // ...or the INVALID_VREG that marks lr.
96 // TODO: x86?
97 if (table_[i + 1] == 0xffff) {
98 break;
99 }
100 }
101 return false;
102 }
103
104 private:
105 const uint16_t* table_;
106};
107
Ian Rogersbdb03912011-09-14 00:55:44 -0700108} // namespace art
109
Ian Rogers57b86d42012-03-27 16:05:41 -0700110#endif // ART_SRC_OAT_RUNTIME_CONTEXT_H_