blob: a50064851b5030b1eccb08586bb575ce2a478236 [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
Andreas Gampe794ad762015-02-23 08:12:24 -080023#include "base/macros.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080024#include "base/mutex.h"
Ian Rogersef7d42f2014-01-06 12:55:46 -080025
Ian Rogersbdb03912011-09-14 00:55:44 -070026namespace art {
27
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010028class QuickMethodFrameInfo;
Ian Rogersbdb03912011-09-14 00:55:44 -070029
Mathieu Chartier67022432012-11-29 18:04:50 -080030// Representation of a thread's context on the executing machine, used to implement long jumps in
31// the quick stack frame layout.
Ian Rogersbdb03912011-09-14 00:55:44 -070032class Context {
33 public:
34 // Creates a context for the running architecture
35 static Context* Create();
36
37 virtual ~Context() {}
38
Mathieu Chartier67022432012-11-29 18:04:50 -080039 // Re-initializes the registers for context re-use.
40 virtual void Reset() = 0;
41
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010042 static uintptr_t* CalleeSaveAddress(uint8_t* frame, int num, size_t frame_size) {
43 // Callee saves are held at the top of the frame
44 uint8_t* save_addr = frame + frame_size - ((num + 1) * sizeof(void*));
45#if defined(__i386__) || defined(__x86_64__)
46 save_addr -= sizeof(void*); // account for return address
47#endif
48 return reinterpret_cast<uintptr_t*>(save_addr);
49 }
50
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020051 // Reads values from callee saves in the given frame. The frame also holds
Ian Rogersbdb03912011-09-14 00:55:44 -070052 // the method that holds the layout.
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010053 virtual void FillCalleeSaves(uint8_t* frame, const QuickMethodFrameInfo& fr) = 0;
Ian Rogersbdb03912011-09-14 00:55:44 -070054
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020055 // Sets the stack pointer value.
Ian Rogersbdb03912011-09-14 00:55:44 -070056 virtual void SetSP(uintptr_t new_sp) = 0;
57
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020058 // Sets the program counter value.
Ian Rogersbdb03912011-09-14 00:55:44 -070059 virtual void SetPC(uintptr_t new_pc) = 0;
60
Andreas Gampe639bdd12015-06-03 11:22:45 -070061 // Sets the first argument register.
62 virtual void SetArg0(uintptr_t new_arg0_value) = 0;
63
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010064 // Returns whether the given GPR is accessible (read or write).
65 virtual bool IsAccessibleGPR(uint32_t reg) = 0;
66
Mathieu Chartier815873e2014-02-13 18:02:13 -080067 // Gets the given GPRs address.
68 virtual uintptr_t* GetGPRAddress(uint32_t reg) = 0;
69
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010070 // Reads the given GPR. The caller is responsible for checking the register
71 // is accessible with IsAccessibleGPR.
72 virtual uintptr_t GetGPR(uint32_t reg) = 0;
Ian Rogersd6b1f612011-09-27 13:38:14 -070073
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010074 // Sets the given GPR. The caller is responsible for checking the register
75 // is accessible with IsAccessibleGPR.
76 virtual void SetGPR(uint32_t reg, uintptr_t value) = 0;
Mathieu Chartier67022432012-11-29 18:04:50 -080077
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010078 // Returns whether the given FPR is accessible (read or write).
79 virtual bool IsAccessibleFPR(uint32_t reg) = 0;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020080
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +010081 // Reads the given FPR. The caller is responsible for checking the register
82 // is accessible with IsAccessibleFPR.
83 virtual uintptr_t GetFPR(uint32_t reg) = 0;
84
85 // Sets the given FPR. The caller is responsible for checking the register
86 // is accessible with IsAccessibleFPR.
87 virtual void SetFPR(uint32_t reg, uintptr_t value) = 0;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020088
89 // Smashes the caller save registers. If we're throwing, we don't want to return bogus values.
Elliott Hughes9c750f92012-04-05 12:07:59 -070090 virtual void SmashCallerSaves() = 0;
91
Sebastien Hertz0bcb2902014-06-17 15:52:45 +020092 // Switches execution of the executing context to this context
Andreas Gampe794ad762015-02-23 08:12:24 -080093 NO_RETURN virtual void DoLongJump() = 0;
Elliott Hughes9c750f92012-04-05 12:07:59 -070094
Mathieu Chartier67022432012-11-29 18:04:50 -080095 protected:
Elliott Hughes9c750f92012-04-05 12:07:59 -070096 enum {
97 kBadGprBase = 0xebad6070,
98 kBadFprBase = 0xebad8070,
99 };
Ian Rogersbdb03912011-09-14 00:55:44 -0700100};
101
Ian Rogersbdb03912011-09-14 00:55:44 -0700102} // namespace art
103
Ian Rogers166db042013-07-26 12:05:57 -0700104#endif // ART_RUNTIME_ARCH_CONTEXT_H_