blob: 895abf99edbf5fb236ab35355eca0e267670a06b [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
Ian Rogers0399dde2012-06-06 17:09:28 -070025class StackVisitor;
Ian Rogersbdb03912011-09-14 00:55:44 -070026
Mathieu Chartier67022432012-11-29 18:04:50 -080027// Representation of a thread's context on the executing machine, used to implement long jumps in
28// the quick stack frame layout.
Ian Rogersbdb03912011-09-14 00:55:44 -070029class Context {
30 public:
31 // Creates a context for the running architecture
32 static Context* Create();
33
34 virtual ~Context() {}
35
Mathieu Chartier67022432012-11-29 18:04:50 -080036 // Re-initializes the registers for context re-use.
37 virtual void Reset() = 0;
38
Ian Rogersbdb03912011-09-14 00:55:44 -070039 // Read values from callee saves in the given frame. The frame also holds
40 // the method that holds the layout.
Ian Rogers0399dde2012-06-06 17:09:28 -070041 virtual void FillCalleeSaves(const StackVisitor& fr) = 0;
Ian Rogersbdb03912011-09-14 00:55:44 -070042
43 // Set the stack pointer value
44 virtual void SetSP(uintptr_t new_sp) = 0;
45
46 // Set the program counter value
47 virtual void SetPC(uintptr_t new_pc) = 0;
48
Ian Rogersd6b1f612011-09-27 13:38:14 -070049 // Read the given GPR
50 virtual uintptr_t GetGPR(uint32_t reg) = 0;
51
Mathieu Chartier67022432012-11-29 18:04:50 -080052 // Set the given GPR.
53 virtual void SetGPR(uint32_t reg, uintptr_t value) = 0;
54
Elliott Hughes9c750f92012-04-05 12:07:59 -070055 // Smash the caller save registers. If we're throwing, we don't want to return bogus values.
56 virtual void SmashCallerSaves() = 0;
57
Ian Rogersbdb03912011-09-14 00:55:44 -070058 // Switch execution of the executing context to this context
59 virtual void DoLongJump() = 0;
Elliott Hughes9c750f92012-04-05 12:07:59 -070060
Mathieu Chartier67022432012-11-29 18:04:50 -080061 protected:
Elliott Hughes9c750f92012-04-05 12:07:59 -070062 enum {
63 kBadGprBase = 0xebad6070,
64 kBadFprBase = 0xebad8070,
65 };
Ian Rogersbdb03912011-09-14 00:55:44 -070066};
67
Ian Rogersbdb03912011-09-14 00:55:44 -070068} // namespace art
69
Ian Rogers57b86d42012-03-27 16:05:41 -070070#endif // ART_SRC_OAT_RUNTIME_CONTEXT_H_