1a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#include "../common/asm-constants.h"
2a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#include "../common/mips-defines.h"
3a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#include <asm/regdef.h>
4a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#include <asm/fpregdef.h>
5a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
6a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#ifdef __mips_hard_float
7a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define HARD_FLOAT
8a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#else
9a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SOFT_FLOAT
10a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#endif
11a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
12a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#if (__mips==32) && (__mips_isa_rev>=2)
13a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define MIPS32R2
14a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#endif
15a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
16a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham/* MIPS definitions and declarations
17a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
18a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham   reg	nick		purpose
19a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham   s0	rPC		interpreted program counter, used for fetching instructions
20a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham   s1	rFP		interpreted frame pointer, used for accessing locals and args
21a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham   s2	rSELF		self (Thread) pointer
22a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham   s3	rIBASE		interpreted instruction base pointer, used for computed goto
23a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham   s4	rINST		first 16-bit code unit of current instruction
24a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham*/
25a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
26a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
27a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham/* single-purpose registers, given names for clarity */
28a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rPC s0
29a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rFP s1
30a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rSELF s2
31a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rIBASE s3
32a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rINST s4
33a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rOBJ s5
34a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rBIX s6
35a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rTEMP s7
36a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
37a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham/* The long arguments sent to function calls in Big-endian mode should be register
38a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandhamswapped when sent to functions in little endian mode. In other words long variable
39a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandhamsent as a0(MSW), a1(LSW) for a function call in LE mode should be sent as a1, a0 in
40a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu GandhamBig Endian mode */
41a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
42a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#ifdef HAVE_LITTLE_ENDIAN
43a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rARG0 a0
44a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rARG1 a1
45a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rARG2 a2
46a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rARG3 a3
47a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rRESULT0 v0
48a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rRESULT1 v1
49a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#else
50a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rARG0 a1
51a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rARG1 a0
52a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rARG2 a3
53a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rARG3 a2
54a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rRESULT0 v1
55a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define rRESULT1 v0
56a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#endif
57a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
58a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
59a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham/* save/restore the PC and/or FP from the glue struct */
60a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_PC_FROM_SELF() lw rPC, offThread_pc(rSELF)
61a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SAVE_PC_TO_SELF() sw rPC, offThread_pc(rSELF)
62a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_FP_FROM_SELF() lw rFP, offThread_curFrame(rSELF)
63a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SAVE_FP_TO_SELF() sw rFP, offThread_curFrame(rSELF)
64a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_PC_FP_FROM_SELF() \
65a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham	LOAD_PC_FROM_SELF();   \
66a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham	LOAD_FP_FROM_SELF()
67a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SAVE_PC_FP_TO_SELF()   \
68a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham	SAVE_PC_TO_SELF();     \
69a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham	SAVE_FP_TO_SELF()
70a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
71a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define EXPORT_PC() \
72a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    sw        rPC, (offStackSaveArea_currentPc - sizeofStackSaveArea)(rFP)
73a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
74a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SAVEAREA_FROM_FP(rd, _fpreg) \
75a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    subu      rd, _fpreg, sizeofStackSaveArea
76a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
77a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define FETCH_INST() lhu rINST, (rPC)
78a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
79a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define FETCH_ADVANCE_INST(_count) lhu rINST, ((_count)*2)(rPC); \
80a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    addu      rPC, rPC, ((_count) * 2)
81a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
82a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define PREFETCH_ADVANCE_INST(_dreg, _sreg, _count) \
83a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    lhu       _dreg, ((_count)*2)(_sreg) ;            \
84a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    addu      _sreg, _sreg, (_count)*2
85a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
86a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define FETCH_ADVANCE_INST_RB(rd) addu rPC, rPC, rd; \
87a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    lhu       rINST, (rPC)
88a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
89a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define FETCH(rd, _count) lhu rd, ((_count) * 2)(rPC)
90a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define FETCH_S(rd, _count) lh rd, ((_count) * 2)(rPC)
91a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
92a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#ifdef HAVE_LITTLE_ENDIAN
93a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
94a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define FETCH_B(rd, _count) lbu rd, ((_count) * 2)(rPC)
95a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define FETCH_C(rd, _count) lbu rd, ((_count) * 2 + 1)(rPC)
96a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
97a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#else
98a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
99a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define FETCH_B(rd, _count) lbu rd, ((_count) * 2 + 1)(rPC)
100a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define FETCH_C(rd, _count) lbu rd, ((_count) * 2)(rPC)
101a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
102a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#endif
103a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
104a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define GET_INST_OPCODE(rd) and rd, rINST, 0xFF
105a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
106a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham/*
107a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham * Put the prefetched instruction's opcode field into the specified register.
108a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham */
109a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
110a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define GET_PREFETCHED_OPCODE(dreg, sreg)   andi     dreg, sreg, 255
111a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
112a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define GOTO_OPCODE(rd) sll rd, rd, ${handler_size_bits}; \
113a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    addu      rd, rIBASE, rd; \
114a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    jr        rd
115a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
116a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define GOTO_OPCODE_BASE(_base, rd)  sll rd, rd, ${handler_size_bits}; \
117a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    addu      rd, _base, rd; \
118a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    jr        rd
119a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
120a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define GET_VREG(rd, rix) LOAD_eas2(rd, rFP, rix)
121a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
122a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define GET_VREG_F(rd, rix) EAS2(AT, rFP, rix); \
123a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    .set noat; l.s rd, (AT); .set at
124a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
125a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SET_VREG(rd, rix) STORE_eas2(rd, rFP, rix)
126a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
127a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SET_VREG_GOTO(rd, rix, dst) .set noreorder; \
128a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    sll       dst, dst, ${handler_size_bits}; \
129a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    addu      dst, rIBASE, dst; \
130a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    sll       t8, rix, 2; \
131a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    addu      t8, t8, rFP; \
132a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    jr        dst; \
133a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    sw        rd, 0(t8); \
134a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    .set reorder
135a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
136a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SET_VREG_F(rd, rix) EAS2(AT, rFP, rix); \
137a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    .set noat; s.s rd, (AT); .set at
138a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
139a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
140a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define GET_OPA(rd) srl rd, rINST, 8
141a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#ifndef MIPS32R2
142a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define GET_OPA4(rd) GET_OPA(rd); and rd, 0xf
143a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#else
144a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define GET_OPA4(rd) ext rd, rINST, 8, 4
145a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#endif
146a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define GET_OPB(rd) srl rd, rINST, 12
147a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
148a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_rSELF_OFF(rd, off) lw rd, offThread_##off## (rSELF)
149a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
150a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_rSELF_method(rd) LOAD_rSELF_OFF(rd, method)
151a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_rSELF_methodClassDex(rd) LOAD_rSELF_OFF(rd, methodClassDex)
152a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_rSELF_interpStackEnd(rd) LOAD_rSELF_OFF(rd, interpStackEnd)
153a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_rSELF_retval(rd) LOAD_rSELF_OFF(rd, retval)
154a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_rSELF_pActiveProfilers(rd) LOAD_rSELF_OFF(rd, pActiveProfilers)
155a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_rSELF_bailPtr(rd) LOAD_rSELF_OFF(rd, bailPtr)
156a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_rSELF_SelfSuspendCount(rd) LOAD_rSELF_OFF(rd, SelfSuspendCount)
157a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
158a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
159a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham/*
160a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham * Form an Effective Address rd = rbase + roff<<n;
161a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham * Uses reg AT
162a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham */
163a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define EASN(rd, rbase, roff, rshift) .set noat; \
164a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    sll       AT, roff, rshift; \
165a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    addu      rd, rbase, AT; \
166a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    .set at
167a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
168a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define EAS1(rd, rbase, roff) EASN(rd, rbase, roff, 1)
169a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define EAS2(rd, rbase, roff) EASN(rd, rbase, roff, 2)
170a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define EAS3(rd, rbase, roff) EASN(rd, rbase, roff, 3)
171a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define EAS4(rd, rbase, roff) EASN(rd, rbase, roff, 4)
172a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
173a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham/*
174a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham * Form an Effective Shift Right rd = rbase + roff>>n;
175a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham * Uses reg AT
176a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham */
177a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define ESRN(rd, rbase, roff, rshift) .set noat; \
178a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    srl       AT, roff, rshift; \
179a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    addu      rd, rbase, AT; \
180a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    .set at
181a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
182a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_eas2(rd, rbase, roff) EAS2(AT, rbase, roff); \
183a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    .set noat; lw rd, 0(AT); .set at
184a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
185a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE_eas2(rd, rbase, roff) EAS2(AT, rbase, roff); \
186a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    .set noat; sw rd, 0(AT); .set at
187a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
188a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_RB_OFF(rd, rbase, off) lw rd, off(rbase)
189a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOADu2_RB_OFF(rd, rbase, off) lhu rd, off(rbase)
190a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE_RB_OFF(rd, rbase, off) sw rd, off(rbase)
191a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
192a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#ifdef HAVE_LITTLE_ENDIAN
193a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
194a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE64_off(rlo, rhi, rbase, off) sw rlo, off(rbase); \
195a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    sw        rhi, (off+4)(rbase)
196a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD64_off(rlo, rhi, rbase, off) lw rlo, off(rbase); \
197a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    lw        rhi, (off+4)(rbase)
198a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
199a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define vSTORE64_off(rlo, rhi, rbase, off) sw rlo, off(rbase); \
200a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    sw        rhi, (off+4)(rbase)
201a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define vLOAD64_off(rlo, rhi, rbase, off) lw rlo, off(rbase); \
202a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    lw        rhi, (off+4)(rbase)
203a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
204a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE64_off_F(rlo, rhi, rbase, off) s.s rlo, off(rbase); \
205a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    s.s       rhi, (off+4)(rbase)
206a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD64_off_F(rlo, rhi, rbase, off) l.s rlo, off(rbase); \
207a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    l.s       rhi, (off+4)(rbase)
208a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#else
209a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
210a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE64_off(rlo, rhi, rbase, off) sw rlo, (off+4)(rbase); \
211a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    sw        rhi, (off)(rbase)
212a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD64_off(rlo, rhi, rbase, off) lw rlo, (off+4)(rbase); \
213a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    lw        rhi, (off)(rbase)
214a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define vSTORE64_off(rlo, rhi, rbase, off) sw rlo, (off+4)(rbase); \
215a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    sw        rhi, (off)(rbase)
216a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define vLOAD64_off(rlo, rhi, rbase, off) lw rlo, (off+4)(rbase); \
217a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    lw        rhi, (off)(rbase)
218a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE64_off_F(rlo, rhi, rbase, off) s.s rlo, (off+4)(rbase); \
219a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    s.s       rhi, (off)(rbase)
220a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD64_off_F(rlo, rhi, rbase, off) l.s rlo, (off+4)(rbase); \
221a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    l.s       rhi, (off)(rbase)
222a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#endif
223a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
224a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE64(rlo, rhi, rbase) STORE64_off(rlo, rhi, rbase, 0)
225a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD64(rlo, rhi, rbase) LOAD64_off(rlo, rhi, rbase, 0)
226a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
227a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define vSTORE64(rlo, rhi, rbase) vSTORE64_off(rlo, rhi, rbase, 0)
228a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define vLOAD64(rlo, rhi, rbase) vLOAD64_off(rlo, rhi, rbase, 0)
229a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
230a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE64_F(rlo, rhi, rbase) STORE64_off_F(rlo, rhi, rbase, 0)
231a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD64_F(rlo, rhi, rbase) LOAD64_off_F(rlo, rhi, rbase, 0)
232a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
233a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE64_lo(rd, rbase) sw rd, 0(rbase)
234a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE64_hi(rd, rbase) sw rd, 4(rbase)
235a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
236a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
237a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_offThread_exception(rd, rbase) LOAD_RB_OFF(rd, rbase, offThread_exception)
238a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offArrayObject_length(rd, rbase) LOAD_RB_OFF(rd, rbase, offArrayObject_length)
239a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offClassObject_accessFlags(rd, rbase) LOAD_RB_OFF(rd, rbase, offClassObject_accessFlags)
240a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offClassObject_descriptor(rd, rbase) LOAD_RB_OFF(rd, rbase, offClassObject_descriptor)
241a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offClassObject_super(rd, rbase) LOAD_RB_OFF(rd, rbase, offClassObject_super)
242a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
243a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offClassObject_vtable(rd, rbase) LOAD_RB_OFF(rd, rbase, offClassObject_vtable)
244a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offClassObject_vtableCount(rd, rbase) LOAD_RB_OFF(rd, rbase, offClassObject_vtableCount)
245a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offDvmDex_pResClasses(rd, rbase) LOAD_RB_OFF(rd, rbase, offDvmDex_pResClasses)
246a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offDvmDex_pResFields(rd, rbase) LOAD_RB_OFF(rd, rbase, offDvmDex_pResFields)
247a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
248a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offDvmDex_pResMethods(rd, rbase) LOAD_RB_OFF(rd, rbase, offDvmDex_pResMethods)
249a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offDvmDex_pResStrings(rd, rbase) LOAD_RB_OFF(rd, rbase, offDvmDex_pResStrings)
250a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offInstField_byteOffset(rd, rbase) LOAD_RB_OFF(rd, rbase, offInstField_byteOffset)
251a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offStaticField_value(rd, rbase) LOAD_RB_OFF(rd, rbase, offStaticField_value)
252a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offMethod_clazz(rd, rbase) LOAD_RB_OFF(rd, rbase, offMethod_clazz)
253a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
254a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offMethod_name(rd, rbase) LOAD_RB_OFF(rd, rbase, offMethod_name)
255a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_base_offObject_clazz(rd, rbase) LOAD_RB_OFF(rd, rbase, offObject_clazz)
256a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
257a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOADu2_offMethod_methodIndex(rd, rbase) LOADu2_RB_OFF(rd, rbase, offMethod_methodIndex)
258a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
259a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
260a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STORE_offThread_exception(rd, rbase) STORE_RB_OFF(rd, rbase, offThread_exception)
261a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
262a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
263a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_STORE(rd, off) sw rd, off(sp)
264a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_LOAD(rd, off) lw rd, off(sp)
265a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define CREATE_STACK(n) subu sp, sp, n
266a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define DELETE_STACK(n) addu sp, sp, n
267a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
268a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SAVE_RA(offset) STACK_STORE(ra, offset)
269a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_RA(offset) STACK_LOAD(ra, offset)
270a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
271a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_ADDR(dest, addr) la dest, addr
272a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define LOAD_IMM(dest, imm) li dest, imm
273a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define MOVE_REG(dest, src) move dest, src
274a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define RETURN jr ra
275a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_SIZE 128
276a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
277a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_OFFSET_ARG04 16
278a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_OFFSET_ARG05 20
279a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_OFFSET_ARG06 24
280a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_OFFSET_ARG07 28
281a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_OFFSET_SCR   32
282a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_OFFSET_SCRMX 80
283a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_OFFSET_GP    84
284a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_OFFSET_rFP   112
285a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
286a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define JAL(n) jal n
287a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define BAL(n) bal n
288a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
289a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_STORE_RA() CREATE_STACK(STACK_SIZE); \
290a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(gp, STACK_OFFSET_GP); \
291a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(ra, 124)
292a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
293a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_STORE_S0() STACK_STORE_RA(); \
294a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(s0, 116)
295a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
296a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_STORE_S0S1() STACK_STORE_S0(); \
297a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(s1, STACK_OFFSET_rFP)
298a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
299a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_LOAD_RA() STACK_LOAD(ra, 124); \
300a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(gp, STACK_OFFSET_GP); \
301a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    DELETE_STACK(STACK_SIZE)
302a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
303a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_LOAD_S0() STACK_LOAD(s0, 116); \
304a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD_RA()
305a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
306a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_LOAD_S0S1() STACK_LOAD(s1, STACK_OFFSET_rFP); \
307a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD_S0()
308a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
309a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_STORE_FULL() CREATE_STACK(STACK_SIZE); \
310a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(ra, 124); \
311a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(fp, 120); \
312a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(s0, 116); \
313a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(s1, STACK_OFFSET_rFP); \
314a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(s2, 108); \
315a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(s3, 104); \
316a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(s4, 100); \
317a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(s5, 96); \
318a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(s6, 92); \
319a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(s7, 88);
320a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
321a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define STACK_LOAD_FULL() STACK_LOAD(gp, STACK_OFFSET_GP); \
322a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(s7, 88); \
323a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(s6, 92); \
324a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(s5, 96); \
325a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(s4, 100); \
326a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(s3, 104); \
327a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(s2, 108); \
328a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(s1, STACK_OFFSET_rFP); \
329a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(s0, 116); \
330a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(fp, 120); \
331a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(ra, 124); \
332a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    DELETE_STACK(STACK_SIZE)
333a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
334a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham/*
335a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham * first 8 words are reserved for function calls
336a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham * Maximum offset is STACK_OFFSET_SCRMX-STACK_OFFSET_SCR
337a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham */
338a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SCRATCH_STORE(r,off) \
339a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_STORE(r, STACK_OFFSET_SCR+off);
340a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#define SCRATCH_LOAD(r,off) \
341a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham    STACK_LOAD(r, STACK_OFFSET_SCR+off);
342a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham
343a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#if defined(WITH_JIT)
344a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#include "../common/jit-config.h"
345a8b91c52fd8a90b784835dfe1f8898035266c4ddRaghu Gandham#endif
346