blob: ed8cab0cd2db9dedb3e8239f0e1e4ca65a46a9b1 [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 Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_RUNTIME_ARCH_CONTEXT_H_
18#define ART_RUNTIME_ARCH_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
Ian Rogers719d1a32014-03-06 12:13:39 -080023#include "base/mutex.h"
Ian Rogersef7d42f2014-01-06 12:55:46 -080024
Ian Rogersbdb03912011-09-14 00:55:44 -070025namespace art {
26
Ian Rogers0399dde2012-06-06 17:09:28 -070027class StackVisitor;
Ian Rogersbdb03912011-09-14 00:55:44 -070028
Mathieu Chartier67022432012-11-29 18:04:50 -080029// Representation of a thread's context on the executing machine, used to implement long jumps in
30// the quick stack frame layout.
Ian Rogersbdb03912011-09-14 00:55:44 -070031class Context {
32 public:
33 // Creates a context for the running architecture
34 static Context* Create();
35
36 virtual ~Context() {}
37
Mathieu Chartier67022432012-11-29 18:04:50 -080038 // Re-initializes the registers for context re-use.
39 virtual void Reset() = 0;
40
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020041 // Reads values from callee saves in the given frame. The frame also holds
Ian Rogersbdb03912011-09-14 00:55:44 -070042 // the method that holds the layout.
Ian Rogersef7d42f2014-01-06 12:55:46 -080043 virtual void FillCalleeSaves(const StackVisitor& fr)
44 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
Ian Rogersbdb03912011-09-14 00:55:44 -070045
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020046 // Sets the stack pointer value.
Ian Rogersbdb03912011-09-14 00:55:44 -070047 virtual void SetSP(uintptr_t new_sp) = 0;
48
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020049 // Sets the program counter value.
Ian Rogersbdb03912011-09-14 00:55:44 -070050 virtual void SetPC(uintptr_t new_pc) = 0;
51
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010052 // Returns whether the given GPR is accessible (read or write).
53 virtual bool IsAccessibleGPR(uint32_t reg) = 0;
54
Mathieu Chartier815873e2014-02-13 18:02:13 -080055 // Gets the given GPRs address.
56 virtual uintptr_t* GetGPRAddress(uint32_t reg) = 0;
57
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010058 // Reads the given GPR. The caller is responsible for checking the register
59 // is accessible with IsAccessibleGPR.
60 virtual uintptr_t GetGPR(uint32_t reg) = 0;
Ian Rogersd6b1f612011-09-27 13:38:14 -070061
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010062 // Sets the given GPR. The caller is responsible for checking the register
63 // is accessible with IsAccessibleGPR.
64 virtual void SetGPR(uint32_t reg, uintptr_t value) = 0;
Mathieu Chartier67022432012-11-29 18:04:50 -080065
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010066 // Returns whether the given FPR is accessible (read or write).
67 virtual bool IsAccessibleFPR(uint32_t reg) = 0;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020068
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010069 // Reads the given FPR. The caller is responsible for checking the register
70 // is accessible with IsAccessibleFPR.
71 virtual uintptr_t GetFPR(uint32_t reg) = 0;
72
73 // Sets the given FPR. The caller is responsible for checking the register
74 // is accessible with IsAccessibleFPR.
75 virtual void SetFPR(uint32_t reg, uintptr_t value) = 0;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020076
77 // Smashes the caller save registers. If we're throwing, we don't want to return bogus values.
Elliott Hughes9c750f92012-04-05 12:07:59 -070078 virtual void SmashCallerSaves() = 0;
79
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020080 // Switches execution of the executing context to this context
Ian Rogersbdb03912011-09-14 00:55:44 -070081 virtual void DoLongJump() = 0;
Elliott Hughes9c750f92012-04-05 12:07:59 -070082
Mathieu Chartier67022432012-11-29 18:04:50 -080083 protected:
Elliott Hughes9c750f92012-04-05 12:07:59 -070084 enum {
85 kBadGprBase = 0xebad6070,
86 kBadFprBase = 0xebad8070,
87 };
Ian Rogersbdb03912011-09-14 00:55:44 -070088};
89
Ian Rogersbdb03912011-09-14 00:55:44 -070090} // namespace art
91
Ian Rogers166db042013-07-26 12:05:57 -070092#endif // ART_RUNTIME_ARCH_CONTEXT_H_