blob: 4c3ca9efffe282145c1f0baa0dc5225c2e5bcd6d [file] [log] [blame]
Alexey Frunze00b53b72016-02-02 20:25:45 -08001/*
2 * Copyright (C) 2016 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 */
16
17#include <machine/regdef.h>
18
19/* TODO: add the missing file and use its FP register definitions. */
20/* #include <machine/fpregdef.h> */
21/* FP register definitions */
22#define f0 $$f0
23#define f1 $$f1
24#define f2 $$f2
25#define f3 $$f3
26#define f12 $$f12
27#define f13 $$f13
28
29/*
30 * It looks like the GNU assembler currently does not support the blec and bgtc
31 * idioms, which should translate into bgec and bltc respectively with swapped
32 * left and right register operands.
33 * TODO: remove these macros when the assembler is fixed.
34 */
35.macro blec lreg, rreg, target
36 bgec \rreg, \lreg, \target
37.endm
38.macro bgtc lreg, rreg, target
39 bltc \rreg, \lreg, \target
40.endm
41
42/*
43Mterp and MIPS64 notes:
44
45The following registers have fixed assignments:
46
47 reg nick purpose
48 s0 rPC interpreted program counter, used for fetching instructions
49 s1 rFP interpreted frame pointer, used for accessing locals and args
50 s2 rSELF self (Thread) pointer
51 s3 rINST first 16-bit code unit of current instruction
52 s4 rIBASE interpreted instruction base pointer, used for computed goto
53 s5 rREFS base of object references in shadow frame (ideally, we'll get rid of this later).
54*/
55
56/* During bringup, we'll use the shadow frame model instead of rFP */
57/* single-purpose registers, given names for clarity */
58#define rPC s0
59#define rFP s1
60#define rSELF s2
61#define rINST s3
62#define rIBASE s4
63#define rREFS s5
64
65/*
66 * This is a #include, not a %include, because we want the C pre-processor
67 * to expand the macros into assembler assignment statements.
68 */
69#include "asm_support.h"
70
71/*
72 * Instead of holding a pointer to the shadow frame, we keep rFP at the base of the vregs. So,
73 * to access other shadow frame fields, we need to use a backwards offset. Define those here.
74 */
75#define OFF_FP(a) (a - SHADOWFRAME_VREGS_OFFSET)
76#define OFF_FP_NUMBER_OF_VREGS OFF_FP(SHADOWFRAME_NUMBER_OF_VREGS_OFFSET)
77#define OFF_FP_DEX_PC OFF_FP(SHADOWFRAME_DEX_PC_OFFSET)
78#define OFF_FP_LINK OFF_FP(SHADOWFRAME_LINK_OFFSET)
79#define OFF_FP_METHOD OFF_FP(SHADOWFRAME_METHOD_OFFSET)
80#define OFF_FP_RESULT_REGISTER OFF_FP(SHADOWFRAME_RESULT_REGISTER_OFFSET)
81#define OFF_FP_DEX_PC_PTR OFF_FP(SHADOWFRAME_DEX_PC_PTR_OFFSET)
82#define OFF_FP_CODE_ITEM OFF_FP(SHADOWFRAME_CODE_ITEM_OFFSET)
83#define OFF_FP_SHADOWFRAME (-SHADOWFRAME_VREGS_OFFSET)
84
85/*
86 *
87 * The reference interpreter performs explicit suspect checks, which is somewhat wasteful.
88 * Dalvik's interpreter folded suspend checks into the jump table mechanism, and eventually
89 * mterp should do so as well.
90 */
91#define MTERP_SUSPEND 0
92
93#define MTERP_LOGGING 0
94
95/*
96 * "export" the PC to dex_pc field in the shadow frame, f/b/o future exception objects. Must
97 * be done *before* something throws.
98 *
99 * It's okay to do this more than once.
100 *
101 * NOTE: the fast interpreter keeps track of dex pc as a direct pointer to the mapped
102 * dex byte codes. However, the rest of the runtime expects dex pc to be an instruction
103 * offset into the code_items_[] array. For effiency, we will "export" the
104 * current dex pc as a direct pointer using the EXPORT_PC macro, and rely on GetDexPC
105 * to convert to a dex pc when needed.
106 */
107.macro EXPORT_PC
108 sd rPC, OFF_FP_DEX_PC_PTR(rFP)
109.endm
110
111/*
112 * Refresh handler table.
113 */
114.macro REFRESH_IBASE
115 ld rIBASE, THREAD_CURRENT_IBASE_OFFSET(rSELF)
116.endm
117
118/*
119 * Fetch the next instruction from rPC into rINST. Does not advance rPC.
120 */
121.macro FETCH_INST
122 lhu rINST, 0(rPC)
123.endm
124
125/* Advance rPC by some number of code units. */
126.macro ADVANCE count
127 daddu rPC, rPC, (\count) * 2
128.endm
129
130/*
131 * Fetch the next instruction from the specified offset. Advances rPC
132 * to point to the next instruction.
133 *
134 * This must come AFTER anything that can throw an exception, or the
135 * exception catch may miss. (This also implies that it must come after
136 * EXPORT_PC.)
137 */
138.macro FETCH_ADVANCE_INST count
139 ADVANCE \count
140 FETCH_INST
141.endm
142
143/*
144 * Similar to FETCH_ADVANCE_INST, but does not update rPC. Used to load
145 * rINST ahead of possible exception point. Be sure to manually advance rPC
146 * later.
147 */
148.macro PREFETCH_INST count
149 lhu rINST, ((\count) * 2)(rPC)
150.endm
151
152/*
153 * Put the instruction's opcode field into the specified register.
154 */
155.macro GET_INST_OPCODE reg
156 and \reg, rINST, 255
157.endm
158
159/*
160 * Begin executing the opcode in _reg.
161 */
162.macro GOTO_OPCODE reg
163 .set noat
164 sll AT, \reg, 7
165 daddu AT, rIBASE, AT
166 jic AT, 0
167 .set at
168.endm
169
170/*
171 * Get/set the 32-bit value from a Dalvik register.
172 * Note, GET_VREG does sign extension to 64 bits while
173 * GET_VREG_U does zero extension to 64 bits.
174 * One is useful for arithmetic while the other is
175 * useful for storing the result value as 64-bit.
176 */
177.macro GET_VREG reg, vreg
178 .set noat
179 dlsa AT, \vreg, rFP, 2
180 lw \reg, 0(AT)
181 .set at
182.endm
183.macro GET_VREG_U reg, vreg
184 .set noat
185 dlsa AT, \vreg, rFP, 2
186 lwu \reg, 0(AT)
187 .set at
188.endm
189.macro GET_VREG_FLOAT reg, vreg
190 .set noat
191 dlsa AT, \vreg, rFP, 2
192 lwc1 \reg, 0(AT)
193 .set at
194.endm
195.macro SET_VREG reg, vreg
196 .set noat
197 dlsa AT, \vreg, rFP, 2
198 sw \reg, 0(AT)
199 dlsa AT, \vreg, rREFS, 2
200 sw zero, 0(AT)
201 .set at
202.endm
203.macro SET_VREG_OBJECT reg, vreg
204 .set noat
205 dlsa AT, \vreg, rFP, 2
206 sw \reg, 0(AT)
207 dlsa AT, \vreg, rREFS, 2
208 sw \reg, 0(AT)
209 .set at
210.endm
211.macro SET_VREG_FLOAT reg, vreg
212 .set noat
213 dlsa AT, \vreg, rFP, 2
214 swc1 \reg, 0(AT)
215 dlsa AT, \vreg, rREFS, 2
216 sw zero, 0(AT)
217 .set at
218.endm
219
220/*
221 * Get/set the 64-bit value from a Dalvik register.
222 * Avoid unaligned memory accesses.
223 * Note, SET_VREG_WIDE clobbers the register containing the value being stored.
224 * Note, SET_VREG_DOUBLE clobbers the register containing the Dalvik register number.
225 */
226.macro GET_VREG_WIDE reg, vreg
227 .set noat
228 dlsa AT, \vreg, rFP, 2
229 lw \reg, 0(AT)
230 lw AT, 4(AT)
231 dinsu \reg, AT, 32, 32
232 .set at
233.endm
234.macro GET_VREG_DOUBLE reg, vreg
235 .set noat
236 dlsa AT, \vreg, rFP, 2
237 lwc1 \reg, 0(AT)
238 lw AT, 4(AT)
239 mthc1 AT, \reg
240 .set at
241.endm
242.macro SET_VREG_WIDE reg, vreg
243 .set noat
244 dlsa AT, \vreg, rFP, 2
245 sw \reg, 0(AT)
246 drotr32 \reg, \reg, 0
247 sw \reg, 4(AT)
248 dlsa AT, \vreg, rREFS, 2
249 sw zero, 0(AT)
250 sw zero, 4(AT)
251 .set at
252.endm
253.macro SET_VREG_DOUBLE reg, vreg
254 .set noat
255 dlsa AT, \vreg, rREFS, 2
256 sw zero, 0(AT)
257 sw zero, 4(AT)
258 dlsa AT, \vreg, rFP, 2
259 swc1 \reg, 0(AT)
260 mfhc1 \vreg, \reg
261 sw \vreg, 4(AT)
262 .set at
263.endm
264
265/*
266 * On-stack offsets for spilling/unspilling callee-saved registers
267 * and the frame size.
268 */
269#define STACK_OFFSET_RA 0
270#define STACK_OFFSET_GP 8
271#define STACK_OFFSET_S0 16
272#define STACK_OFFSET_S1 24
273#define STACK_OFFSET_S2 32
274#define STACK_OFFSET_S3 40
275#define STACK_OFFSET_S4 48
276#define STACK_OFFSET_S5 56
277#define STACK_SIZE 64
278
279/* Constants for float/double_to_int/long conversions */
280#define INT_MIN 0x80000000
281#define INT_MIN_AS_FLOAT 0xCF000000
282#define INT_MIN_AS_DOUBLE 0xC1E0000000000000
283#define LONG_MIN 0x8000000000000000
284#define LONG_MIN_AS_FLOAT 0xDF000000
285#define LONG_MIN_AS_DOUBLE 0xC3E0000000000000