1 /* src/vm/jit/mips/codegen.c - machine code generator for MIPS
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Andreas Krall
30 Changes: Christian Thalinger
33 Contains the codegenerator for an MIPS (R4000 or higher) processor.
34 This module generates MIPS machine code for a sequence of
35 intermediate code commands (ICMDs).
37 $Id: codegen.c 3054 2005-07-18 21:57:01Z twisti $
51 #include "vm/jit/mips/arch.h"
52 #include "vm/jit/mips/codegen.h"
53 #include "vm/jit/mips/types.h"
55 #include "cacao/cacao.h"
56 #include "native/native.h"
57 #include "vm/builtin.h"
58 #include "vm/stringlocal.h"
59 #include "vm/jit/asmpart.h"
60 #include "vm/jit/codegen.inc"
61 #include "vm/jit/jit.h"
64 # include "vm/jit/lsra.h"
65 # include "vm/jit/lsra.inc"
68 #include "vm/jit/patcher.h"
69 #include "vm/jit/reg.h"
70 #include "vm/jit/reg.inc"
73 /* codegen *********************************************************************
75 Generates machine code.
77 *******************************************************************************/
79 void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
81 s4 len, s1, s2, s3, d, disp;
91 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
92 builtintable_entry *bte;
99 savedregs_num = (m->isleafmethod) ? 0 : 1; /* space to save the RA */
101 /* space to save used callee saved registers */
103 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
104 savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);
106 parentargs_base = rd->memuse + savedregs_num;
108 #if defined(USE_THREADS) /* space to save argument of monitor_enter */
109 if (checksync && (m->flags & ACC_SYNCHRONIZED))
113 /* adjust frame size for 16 byte alignment */
115 if (parentargs_base & 1)
118 /* create method header */
120 #if SIZEOF_VOID_P == 4
121 (void) dseg_addaddress(cd, m); /* Filler */
123 (void) dseg_addaddress(cd, m); /* MethodPointer */
124 (void) dseg_adds4(cd, parentargs_base * 8); /* FrameSize */
126 #if defined(USE_THREADS)
127 /* IsSync contains the offset relative to the stack pointer for the
128 argument of monitor_exit used in the exception handler. Since the
129 offset could be zero and give a wrong meaning of the flag it is
133 if (checksync && (m->flags & ACC_SYNCHRONIZED))
134 (void) dseg_adds4(cd, (rd->memuse + 1) * 8); /* IsSync */
137 (void) dseg_adds4(cd, 0); /* IsSync */
139 (void) dseg_adds4(cd, m->isleafmethod); /* IsLeaf */
140 (void) dseg_adds4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
141 (void) dseg_adds4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
142 dseg_addlinenumbertablesize(cd);
143 (void) dseg_adds4(cd, cd->exceptiontablelength); /* ExTableSize */
145 /* create exception table */
147 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
148 dseg_addtarget(cd, ex->start);
149 dseg_addtarget(cd, ex->end);
150 dseg_addtarget(cd, ex->handler);
151 (void) dseg_addaddress(cd, ex->catchtype.cls);
154 /* initialize mcode variables */
156 mcodeptr = (s4 *) cd->mcodebase;
157 cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
158 MCODECHECK(128 + m->paramcount);
160 /* create stack frame (if necessary) */
163 M_LDA(REG_SP, REG_SP, -parentargs_base * 8);
165 /* save return address and used callee saved registers */
168 if (!m->isleafmethod) {
169 p--; M_AST(REG_RA, REG_SP, p * 8);
171 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
172 p--; M_AST(rd->savintregs[i], REG_SP, p * 8);
174 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
175 p--; M_DST(rd->savfltregs[i], REG_SP, p * 8);
178 /* take arguments out of register or stack frame */
182 for (p = 0, l = 0; p < md->paramcount; p++) {
183 t = md->paramtypes[p].type;
184 var = &(rd->locals[l][t]);
186 if (IS_2_WORD_TYPE(t)) /* increment local counter for 2 word types */
190 s1 = md->params[p].regoff;
191 if (IS_INT_LNG_TYPE(t)) { /* integer args */
192 if (!md->params[p].inmemory) { /* register arguments */
193 s2 = rd->argintregs[s1];
194 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
195 M_INTMOVE(s2, var->regoff);
196 } else { /* reg arg -> spilled */
197 M_LST(s2, REG_SP, var->regoff * 8);
200 } else { /* stack arguments */
201 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
202 M_LLD(var->regoff, REG_SP, (parentargs_base + s1) * 8);
203 } else { /* stack arg -> spilled */
204 var->regoff = parentargs_base + s1;
208 } else { /* floating args */
209 if (!md->params[p].inmemory) { /* register arguments */
210 s2 = rd->argfltregs[s1];
211 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
212 M_TFLTMOVE(var->type, s2, var->regoff);
213 } else { /* reg arg -> spilled */
214 M_DST(s2, REG_SP, var->regoff * 8);
217 } else { /* stack arguments */
218 if (!(var->flags & INMEMORY)) { /* stack-arg -> register */
219 M_DLD(var->regoff, REG_SP, (parentargs_base + s1) * 8);
220 } else { /* stack-arg -> spilled */
221 var->regoff = parentargs_base + s1;
227 /* call monitorenter function */
229 #if defined(USE_THREADS)
230 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
231 /* stack offset for monitor argument */
236 M_LDA(REG_SP, REG_SP, -(INT_ARG_CNT + FLT_ARG_CNT) * 8);
238 for (p = 0; p < INT_ARG_CNT; p++)
239 M_LST(rd->argintregs[p], REG_SP, p * 8);
241 for (p = 0; p < FLT_ARG_CNT; p++)
242 M_DST(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8);
244 s1 += INT_ARG_CNT + FLT_ARG_CNT;
247 /* decide which monitor enter function to call */
249 if (m->flags & ACC_STATIC) {
250 p = dseg_addaddress(cd, m->class);
251 M_ALD(REG_ITMP1, REG_PV, p);
252 M_AST(REG_ITMP1, REG_SP, s1 * 8);
253 p = dseg_addaddress(cd, BUILTIN_staticmonitorenter);
254 M_ALD(REG_ITMP3, REG_PV, p);
255 M_JSR(REG_RA, REG_ITMP3);
256 M_INTMOVE(REG_ITMP1, rd->argintregs[0]); /* branch delay */
257 d = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
258 M_LDA(REG_PV, REG_RA, d);
261 M_BEQZ(rd->argintregs[0], 0);
262 codegen_addxnullrefs(cd, mcodeptr);
263 p = dseg_addaddress(cd, BUILTIN_monitorenter);
264 M_ALD(REG_ITMP3, REG_PV, p);
265 M_JSR(REG_RA, REG_ITMP3);
266 M_AST(rd->argintregs[0], REG_SP, s1 * 8); /* br delay */
267 d = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
268 M_LDA(REG_PV, REG_RA, d);
272 for (p = 0; p < INT_ARG_CNT; p++)
273 M_LLD(rd->argintregs[p], REG_SP, p * 8);
275 for (p = 0; p < FLT_ARG_CNT; p++)
276 M_DLD(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8);
279 M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT) * 8);
284 /* copy argument registers to stack and call trace function */
287 M_LDA(REG_SP, REG_SP, -(2 + INT_ARG_CNT + FLT_ARG_CNT + INT_TMP_CNT + FLT_TMP_CNT) * 8);
288 M_LST(REG_RA, REG_SP, 1 * 8);
290 /* save integer argument registers */
292 for (p = 0; p < md->paramcount && p < INT_ARG_CNT; p++)
293 M_LST(rd->argintregs[p], REG_SP, (2 + p) * 8);
295 /* save and copy float arguments into integer registers */
297 for (p = 0; p < md->paramcount && p < FLT_ARG_CNT; p++) {
298 t = md->paramtypes[p].type;
300 if (IS_FLT_DBL_TYPE(t)) {
301 if (IS_2_WORD_TYPE(t)) {
302 M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
303 M_LLD(rd->argintregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
306 M_FST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
307 M_ILD(rd->argintregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
311 M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
315 /* save temporary registers for leaf methods */
317 if (m->isleafmethod) {
318 for (p = 0; p < INT_TMP_CNT; p++)
319 M_LST(rd->tmpintregs[p], REG_SP, (2 + INT_ARG_CNT + FLT_ARG_CNT + p) * 8);
321 for (p = 0; p < FLT_TMP_CNT; p++)
322 M_DST(rd->tmpfltregs[p], REG_SP, (2 + INT_ARG_CNT + FLT_ARG_CNT + INT_TMP_CNT + p) * 8);
325 p = dseg_addaddress(cd, m);
326 M_ALD(REG_ITMP1, REG_PV, p);
327 M_LST(REG_ITMP1, REG_SP, 0);
328 p = dseg_addaddress(cd, (void *) builtin_trace_args);
329 M_ALD(REG_ITMP3, REG_PV, p);
330 M_JSR(REG_RA, REG_ITMP3);
333 M_LLD(REG_RA, REG_SP, 1 * 8);
335 /* restore integer argument registers */
337 for (p = 0; p < md->paramcount && p < INT_ARG_CNT; p++)
338 M_LLD(rd->argintregs[p], REG_SP, (2 + p) * 8);
340 /* restore float argument registers */
342 for (p = 0; p < md->paramcount && p < FLT_ARG_CNT; p++) {
343 t = md->paramtypes[p].type;
345 if (IS_FLT_DBL_TYPE(t)) {
346 if (IS_2_WORD_TYPE(t)) {
347 M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
350 M_FLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
354 M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
358 /* restore temporary registers for leaf methods */
360 if (m->isleafmethod) {
361 for (p = 0; p < INT_TMP_CNT; p++)
362 M_LLD(rd->tmpintregs[p], REG_SP, (2 + INT_ARG_CNT + FLT_ARG_CNT + p) * 8);
364 for (p = 0; p < FLT_TMP_CNT; p++)
365 M_DLD(rd->tmpfltregs[p], REG_SP, (2 + INT_ARG_CNT + FLT_ARG_CNT + INT_TMP_CNT + p) * 8);
368 M_LDA(REG_SP, REG_SP, (2 + INT_ARG_CNT + FLT_ARG_CNT + INT_TMP_CNT + FLT_TMP_CNT) * 8);
373 /* end of header generation */
375 /* walk through all basic blocks */
377 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
379 bptr->mpc = (s4) ((u1 *) mcodeptr - cd->mcodebase);
381 if (bptr->flags >= BBREACHED) {
383 /* branch resolving */
386 for (bref = bptr->branchrefs; bref != NULL; bref = bref->next) {
387 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
393 /* copy interface registers to their destination */
400 while (src != NULL) {
402 if ((len == 0) && (bptr->type != BBTYPE_STD)) {
403 /* d = reg_of_var(m, src, REG_ITMP1); */
404 if (!(src->flags & INMEMORY))
408 M_INTMOVE(REG_ITMP1, d);
409 store_reg_to_var_int(src, d);
415 while (src != NULL) {
417 if ((len == 0) && (bptr->type != BBTYPE_STD)) {
418 d = reg_of_var(rd, src, REG_ITMP1);
419 M_INTMOVE(REG_ITMP1, d);
420 store_reg_to_var_int(src, d);
423 d = reg_of_var(rd, src, REG_IFTMP);
424 if ((src->varkind != STACKVAR)) {
426 if (IS_FLT_DBL_TYPE(s2)) {
427 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
428 s1 = rd->interfaces[len][s2].regoff;
429 M_TFLTMOVE(s2, s1, d);
432 M_DLD(d, REG_SP, 8 * rd->interfaces[len][s2].regoff);
434 store_reg_to_var_flt(src, d);
437 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
438 s1 = rd->interfaces[len][s2].regoff;
442 M_LLD(d, REG_SP, 8 * rd->interfaces[len][s2].regoff);
444 store_reg_to_var_int(src, d);
453 /* walk through all instructions */
459 for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) {
460 if (iptr->line != currentline) {
461 dseg_addlinenumber(cd, iptr->line, (u1 *) mcodeptr);
462 currentline = iptr->line;
465 MCODECHECK(64); /* an instruction usually needs < 64 words */
469 case ICMD_NOP: /* ... ==> ... */
472 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
474 var_to_reg_int(s1, src, REG_ITMP1);
476 codegen_addxnullrefs(cd, mcodeptr);
480 /* constant operations ************************************************/
482 case ICMD_ICONST: /* ... ==> ..., constant */
483 /* op1 = 0, val.i = constant */
485 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
486 ICONST(d, iptr->val.i);
487 store_reg_to_var_int(iptr->dst, d);
490 case ICMD_LCONST: /* ... ==> ..., constant */
491 /* op1 = 0, val.l = constant */
493 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
494 LCONST(d, iptr->val.l);
495 store_reg_to_var_int(iptr->dst, d);
498 case ICMD_FCONST: /* ... ==> ..., constant */
499 /* op1 = 0, val.f = constant */
501 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
502 a = dseg_addfloat(cd, iptr->val.f);
504 store_reg_to_var_flt(iptr->dst, d);
507 case ICMD_DCONST: /* ... ==> ..., constant */
508 /* op1 = 0, val.d = constant */
510 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
511 a = dseg_adddouble(cd, iptr->val.d);
513 store_reg_to_var_flt (iptr->dst, d);
516 case ICMD_ACONST: /* ... ==> ..., constant */
517 /* op1 = 0, val.a = constant */
519 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
521 a = dseg_addaddress(cd, iptr->val.a);
524 M_INTMOVE(REG_ZERO, d);
526 store_reg_to_var_int(iptr->dst, d);
530 /* load/store operations **********************************************/
532 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
533 case ICMD_LLOAD: /* op1 = local variable */
536 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
537 if ((iptr->dst->varkind == LOCALVAR) &&
538 (iptr->dst->varnum == iptr->op1))
540 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
541 if (var->flags & INMEMORY) {
542 M_LLD(d, REG_SP, 8 * var->regoff);
544 M_INTMOVE(var->regoff,d);
546 store_reg_to_var_int(iptr->dst, d);
549 case ICMD_FLOAD: /* ... ==> ..., content of local variable */
550 case ICMD_DLOAD: /* op1 = local variable */
552 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
553 if ((iptr->dst->varkind == LOCALVAR) &&
554 (iptr->dst->varnum == iptr->op1))
556 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
558 int t2 = ((iptr->opc == ICMD_FLOAD) ? TYPE_FLT : TYPE_DBL);
559 if (var->flags & INMEMORY) {
560 M_CCFLD(var->type, t2, d, REG_SP, 8 * var->regoff);
562 M_CCFLTMOVE(var->type, t2, var->regoff, d);
565 store_reg_to_var_flt(iptr->dst, d);
569 case ICMD_ISTORE: /* ..., value ==> ... */
570 case ICMD_LSTORE: /* op1 = local variable */
573 if ((src->varkind == LOCALVAR) &&
574 (src->varnum == iptr->op1))
576 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
577 if (var->flags & INMEMORY) {
578 var_to_reg_int(s1, src, REG_ITMP1);
579 M_LST(s1, REG_SP, 8 * var->regoff);
582 var_to_reg_int(s1, src, var->regoff);
583 M_INTMOVE(s1, var->regoff);
587 case ICMD_FSTORE: /* ..., value ==> ... */
588 case ICMD_DSTORE: /* op1 = local variable */
590 if ((src->varkind == LOCALVAR) &&
591 (src->varnum == iptr->op1))
593 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
595 int t1 = ((iptr->opc == ICMD_FSTORE) ? TYPE_FLT : TYPE_DBL);
596 if (var->flags & INMEMORY) {
597 var_to_reg_flt(s1, src, REG_FTMP1);
598 M_CCFST(t1, var->type, s1, REG_SP, 8 * var->regoff);
601 var_to_reg_flt(s1, src, var->regoff);
602 M_CCFLTMOVE(t1, var->type, s1, var->regoff);
608 /* pop/dup/swap operations ********************************************/
610 /* attention: double and longs are only one entry in CACAO ICMDs */
612 case ICMD_POP: /* ..., value ==> ... */
613 case ICMD_POP2: /* ..., value, value ==> ... */
616 case ICMD_DUP: /* ..., a ==> ..., a, a */
617 M_COPY(src, iptr->dst);
620 case ICMD_DUP_X1: /* ..., a, b ==> ..., b, a, b */
622 M_COPY(src, iptr->dst);
623 M_COPY(src->prev, iptr->dst->prev);
624 M_COPY(iptr->dst, iptr->dst->prev->prev);
627 case ICMD_DUP_X2: /* ..., a, b, c ==> ..., c, a, b, c */
629 M_COPY(src, iptr->dst);
630 M_COPY(src->prev, iptr->dst->prev);
631 M_COPY(src->prev->prev, iptr->dst->prev->prev);
632 M_COPY(iptr->dst, iptr->dst->prev->prev->prev);
635 case ICMD_DUP2: /* ..., a, b ==> ..., a, b, a, b */
637 M_COPY(src, iptr->dst);
638 M_COPY(src->prev, iptr->dst->prev);
641 case ICMD_DUP2_X1: /* ..., a, b, c ==> ..., b, c, a, b, c */
643 M_COPY(src, iptr->dst);
644 M_COPY(src->prev, iptr->dst->prev);
645 M_COPY(src->prev->prev, iptr->dst->prev->prev);
646 M_COPY(iptr->dst, iptr->dst->prev->prev->prev);
647 M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev);
650 case ICMD_DUP2_X2: /* ..., a, b, c, d ==> ..., c, d, a, b, c, d */
652 M_COPY(src, iptr->dst);
653 M_COPY(src->prev, iptr->dst->prev);
654 M_COPY(src->prev->prev, iptr->dst->prev->prev);
655 M_COPY(src->prev->prev->prev, iptr->dst->prev->prev->prev);
656 M_COPY(iptr->dst, iptr->dst->prev->prev->prev->prev);
657 M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev->prev);
660 case ICMD_SWAP: /* ..., a, b ==> ..., b, a */
662 M_COPY(src, iptr->dst->prev);
663 M_COPY(src->prev, iptr->dst);
667 /* integer operations *************************************************/
669 case ICMD_INEG: /* ..., value ==> ..., - value */
671 var_to_reg_int(s1, src, REG_ITMP1);
672 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
673 M_ISUB(REG_ZERO, s1, d);
674 store_reg_to_var_int(iptr->dst, d);
677 case ICMD_LNEG: /* ..., value ==> ..., - value */
679 var_to_reg_int(s1, src, REG_ITMP1);
680 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
681 M_LSUB(REG_ZERO, s1, d);
682 store_reg_to_var_int(iptr->dst, d);
685 case ICMD_I2L: /* ..., value ==> ..., value */
687 var_to_reg_int(s1, src, REG_ITMP1);
688 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
690 store_reg_to_var_int(iptr->dst, d);
693 case ICMD_L2I: /* ..., value ==> ..., value */
695 var_to_reg_int(s1, src, REG_ITMP1);
696 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
697 M_ISLL_IMM(s1, 0, d );
698 store_reg_to_var_int(iptr->dst, d);
701 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
703 var_to_reg_int(s1, src, REG_ITMP1);
704 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
705 M_LSLL_IMM(s1, 56, d);
706 M_LSRA_IMM( d, 56, d);
707 store_reg_to_var_int(iptr->dst, d);
710 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
712 var_to_reg_int(s1, src, REG_ITMP1);
713 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
715 store_reg_to_var_int(iptr->dst, d);
718 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
720 var_to_reg_int(s1, src, REG_ITMP1);
721 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
722 M_LSLL_IMM(s1, 48, d);
723 M_LSRA_IMM( d, 48, d);
724 store_reg_to_var_int(iptr->dst, d);
728 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
730 var_to_reg_int(s1, src->prev, REG_ITMP1);
731 var_to_reg_int(s2, src, REG_ITMP2);
732 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
734 store_reg_to_var_int(iptr->dst, d);
737 case ICMD_IADDCONST: /* ..., value ==> ..., value + constant */
738 /* val.i = constant */
740 var_to_reg_int(s1, src, REG_ITMP1);
741 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
742 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
743 M_IADD_IMM(s1, iptr->val.i, d);
746 ICONST(REG_ITMP2, iptr->val.i);
747 M_IADD(s1, REG_ITMP2, d);
749 store_reg_to_var_int(iptr->dst, d);
752 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
754 var_to_reg_int(s1, src->prev, REG_ITMP1);
755 var_to_reg_int(s2, src, REG_ITMP2);
756 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
758 store_reg_to_var_int(iptr->dst, d);
761 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
762 /* val.l = constant */
764 var_to_reg_int(s1, src, REG_ITMP1);
765 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
766 if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
767 M_LADD_IMM(s1, iptr->val.l, d);
770 LCONST(REG_ITMP2, iptr->val.l);
771 M_LADD(s1, REG_ITMP2, d);
773 store_reg_to_var_int(iptr->dst, d);
776 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
778 var_to_reg_int(s1, src->prev, REG_ITMP1);
779 var_to_reg_int(s2, src, REG_ITMP2);
780 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
782 store_reg_to_var_int(iptr->dst, d);
785 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
786 /* val.i = constant */
788 var_to_reg_int(s1, src, REG_ITMP1);
789 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
790 if ((iptr->val.i >= -32767) && (iptr->val.i <= 32768)) {
791 M_IADD_IMM(s1, -iptr->val.i, d);
794 ICONST(REG_ITMP2, iptr->val.i);
795 M_ISUB(s1, REG_ITMP2, d);
797 store_reg_to_var_int(iptr->dst, d);
800 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
802 var_to_reg_int(s1, src->prev, REG_ITMP1);
803 var_to_reg_int(s2, src, REG_ITMP2);
804 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
806 store_reg_to_var_int(iptr->dst, d);
809 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
810 /* val.l = constant */
812 var_to_reg_int(s1, src, REG_ITMP1);
813 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
814 if ((iptr->val.l >= -32767) && (iptr->val.l <= 32768)) {
815 M_LADD_IMM(s1, -iptr->val.l, d);
818 LCONST(REG_ITMP2, iptr->val.l);
819 M_LSUB(s1, REG_ITMP2, d);
821 store_reg_to_var_int(iptr->dst, d);
824 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
826 var_to_reg_int(s1, src->prev, REG_ITMP1);
827 var_to_reg_int(s2, src, REG_ITMP2);
828 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
833 store_reg_to_var_int(iptr->dst, d);
836 case ICMD_IMULCONST: /* ..., value ==> ..., value * constant */
837 /* val.i = constant */
839 var_to_reg_int(s1, src, REG_ITMP1);
840 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
841 ICONST(REG_ITMP2, iptr->val.i);
842 M_IMUL(s1, REG_ITMP2);
846 store_reg_to_var_int(iptr->dst, d);
849 case ICMD_LMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
851 var_to_reg_int(s1, src->prev, REG_ITMP1);
852 var_to_reg_int(s2, src, REG_ITMP2);
853 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
858 store_reg_to_var_int(iptr->dst, d);
861 case ICMD_LMULCONST: /* ..., value ==> ..., value * constant */
862 /* val.l = constant */
864 var_to_reg_int(s1, src, REG_ITMP1);
865 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
866 LCONST(REG_ITMP2, iptr->val.l);
867 M_LMUL(s1, REG_ITMP2);
871 store_reg_to_var_int(iptr->dst, d);
874 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
876 var_to_reg_int(s1, src->prev, REG_ITMP1);
877 var_to_reg_int(s2, src, REG_ITMP2);
878 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
884 store_reg_to_var_int(iptr->dst, d);
887 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
889 var_to_reg_int(s1, src->prev, REG_ITMP1);
890 var_to_reg_int(s2, src, REG_ITMP2);
891 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
897 store_reg_to_var_int(iptr->dst, d);
900 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
902 var_to_reg_int(s1, src->prev, REG_ITMP1);
903 var_to_reg_int(s2, src, REG_ITMP2);
904 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
910 store_reg_to_var_int(iptr->dst, d);
913 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
915 var_to_reg_int(s1, src->prev, REG_ITMP1);
916 var_to_reg_int(s2, src, REG_ITMP2);
917 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
923 store_reg_to_var_int(iptr->dst, d);
926 case ICMD_IDIVPOW2: /* ..., value ==> ..., value << constant */
927 case ICMD_LDIVPOW2: /* val.i = constant */
929 var_to_reg_int(s1, src, REG_ITMP1);
930 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
931 M_LSRA_IMM(s1, 63, REG_ITMP2);
932 M_LSRL_IMM(REG_ITMP2, 64 - iptr->val.i, REG_ITMP2);
933 M_LADD(s1, REG_ITMP2, REG_ITMP2);
934 M_LSRA_IMM(REG_ITMP2, iptr->val.i, d);
935 store_reg_to_var_int(iptr->dst, d);
938 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
940 var_to_reg_int(s1, src->prev, REG_ITMP1);
941 var_to_reg_int(s2, src, REG_ITMP2);
942 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
944 store_reg_to_var_int(iptr->dst, d);
947 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
948 /* val.i = constant */
950 var_to_reg_int(s1, src, REG_ITMP1);
951 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
952 M_ISLL_IMM(s1, iptr->val.i, d);
953 store_reg_to_var_int(iptr->dst, d);
956 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
958 var_to_reg_int(s1, src->prev, REG_ITMP1);
959 var_to_reg_int(s2, src, REG_ITMP2);
960 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
962 store_reg_to_var_int(iptr->dst, d);
965 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
966 /* val.i = constant */
968 var_to_reg_int(s1, src, REG_ITMP1);
969 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
970 M_ISRA_IMM(s1, iptr->val.i, d);
971 store_reg_to_var_int(iptr->dst, d);
974 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
976 var_to_reg_int(s1, src->prev, REG_ITMP1);
977 var_to_reg_int(s2, src, REG_ITMP2);
978 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
980 store_reg_to_var_int(iptr->dst, d);
983 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
984 /* val.i = constant */
986 var_to_reg_int(s1, src, REG_ITMP1);
987 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
988 M_ISRL_IMM(s1, iptr->val.i, d);
989 store_reg_to_var_int(iptr->dst, d);
992 case ICMD_LSHL: /* ..., val1, val2 ==> ..., val1 << val2 */
994 var_to_reg_int(s1, src->prev, REG_ITMP1);
995 var_to_reg_int(s2, src, REG_ITMP2);
996 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
998 store_reg_to_var_int(iptr->dst, d);
1001 case ICMD_LSHLCONST: /* ..., value ==> ..., value << constant */
1002 /* val.i = constant */
1004 var_to_reg_int(s1, src, REG_ITMP1);
1005 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1006 M_LSLL_IMM(s1, iptr->val.i, d);
1007 store_reg_to_var_int(iptr->dst, d);
1010 case ICMD_LSHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
1012 var_to_reg_int(s1, src->prev, REG_ITMP1);
1013 var_to_reg_int(s2, src, REG_ITMP2);
1014 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1016 store_reg_to_var_int(iptr->dst, d);
1019 case ICMD_LSHRCONST: /* ..., value ==> ..., value >> constant */
1020 /* val.i = constant */
1022 var_to_reg_int(s1, src, REG_ITMP1);
1023 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1024 M_LSRA_IMM(s1, iptr->val.i, d);
1025 store_reg_to_var_int(iptr->dst, d);
1028 case ICMD_LUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
1030 var_to_reg_int(s1, src->prev, REG_ITMP1);
1031 var_to_reg_int(s2, src, REG_ITMP2);
1032 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1034 store_reg_to_var_int(iptr->dst, d);
1037 case ICMD_LUSHRCONST: /* ..., value ==> ..., value >>> constant */
1038 /* val.i = constant */
1040 var_to_reg_int(s1, src, REG_ITMP1);
1041 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1042 M_LSRL_IMM(s1, iptr->val.i, d);
1043 store_reg_to_var_int(iptr->dst, d);
1046 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
1049 var_to_reg_int(s1, src->prev, REG_ITMP1);
1050 var_to_reg_int(s2, src, REG_ITMP2);
1051 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1053 store_reg_to_var_int(iptr->dst, d);
1056 case ICMD_IANDCONST: /* ..., value ==> ..., value & constant */
1057 /* val.i = constant */
1059 var_to_reg_int(s1, src, REG_ITMP1);
1060 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1061 if ((iptr->val.i >= 0) && (iptr->val.i <= 0xffff)) {
1062 M_AND_IMM(s1, iptr->val.i, d);
1065 ICONST(REG_ITMP2, iptr->val.i);
1066 M_AND(s1, REG_ITMP2, d);
1068 store_reg_to_var_int(iptr->dst, d);
1071 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
1072 /* val.i = constant */
1074 var_to_reg_int(s1, src, REG_ITMP1);
1075 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1077 M_MOV(s1, REG_ITMP1);
1080 if ((iptr->val.i >= 0) && (iptr->val.i <= 0xffff)) {
1081 M_AND_IMM(s1, iptr->val.i, d);
1084 M_ISUB(REG_ZERO, s1, d);
1085 M_AND_IMM(d, iptr->val.i, d);
1088 ICONST(REG_ITMP2, iptr->val.i);
1089 M_AND(s1, REG_ITMP2, d);
1092 M_ISUB(REG_ZERO, s1, d);
1093 M_AND(d, REG_ITMP2, d);
1095 M_ISUB(REG_ZERO, d, d);
1096 store_reg_to_var_int(iptr->dst, d);
1099 case ICMD_LANDCONST: /* ..., value ==> ..., value & constant */
1100 /* val.l = constant */
1102 var_to_reg_int(s1, src, REG_ITMP1);
1103 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1104 if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
1105 M_AND_IMM(s1, iptr->val.l, d);
1108 LCONST(REG_ITMP2, iptr->val.l);
1109 M_AND(s1, REG_ITMP2, d);
1111 store_reg_to_var_int(iptr->dst, d);
1114 case ICMD_LREMPOW2: /* ..., value ==> ..., value % constant */
1115 /* val.l = constant */
1117 var_to_reg_int(s1, src, REG_ITMP1);
1118 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1120 M_MOV(s1, REG_ITMP1);
1123 if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
1124 M_AND_IMM(s1, iptr->val.l, d);
1127 M_LSUB(REG_ZERO, s1, d);
1128 M_AND_IMM(d, iptr->val.l, d);
1131 LCONST(REG_ITMP2, iptr->val.l);
1132 M_AND(s1, REG_ITMP2, d);
1135 M_LSUB(REG_ZERO, s1, d);
1136 M_AND(d, REG_ITMP2, d);
1138 M_LSUB(REG_ZERO, d, d);
1139 store_reg_to_var_int(iptr->dst, d);
1142 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
1145 var_to_reg_int(s1, src->prev, REG_ITMP1);
1146 var_to_reg_int(s2, src, REG_ITMP2);
1147 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1149 store_reg_to_var_int(iptr->dst, d);
1152 case ICMD_IORCONST: /* ..., value ==> ..., value | constant */
1153 /* val.i = constant */
1155 var_to_reg_int(s1, src, REG_ITMP1);
1156 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1157 if ((iptr->val.i >= 0) && (iptr->val.i <= 0xffff)) {
1158 M_OR_IMM(s1, iptr->val.i, d);
1161 ICONST(REG_ITMP2, iptr->val.i);
1162 M_OR(s1, REG_ITMP2, d);
1164 store_reg_to_var_int(iptr->dst, d);
1167 case ICMD_LORCONST: /* ..., value ==> ..., value | constant */
1168 /* val.l = constant */
1170 var_to_reg_int(s1, src, REG_ITMP1);
1171 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1172 if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
1173 M_OR_IMM(s1, iptr->val.l, d);
1176 LCONST(REG_ITMP2, iptr->val.l);
1177 M_OR(s1, REG_ITMP2, d);
1179 store_reg_to_var_int(iptr->dst, d);
1182 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
1185 var_to_reg_int(s1, src->prev, REG_ITMP1);
1186 var_to_reg_int(s2, src, REG_ITMP2);
1187 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1189 store_reg_to_var_int(iptr->dst, d);
1192 case ICMD_IXORCONST: /* ..., value ==> ..., value ^ constant */
1193 /* val.i = constant */
1195 var_to_reg_int(s1, src, REG_ITMP1);
1196 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1197 if ((iptr->val.i >= 0) && (iptr->val.i <= 0xffff)) {
1198 M_XOR_IMM(s1, iptr->val.i, d);
1201 ICONST(REG_ITMP2, iptr->val.i);
1202 M_XOR(s1, REG_ITMP2, d);
1204 store_reg_to_var_int(iptr->dst, d);
1207 case ICMD_LXORCONST: /* ..., value ==> ..., value ^ constant */
1208 /* val.l = constant */
1210 var_to_reg_int(s1, src, REG_ITMP1);
1211 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1212 if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
1213 M_XOR_IMM(s1, iptr->val.l, d);
1216 LCONST(REG_ITMP2, iptr->val.l);
1217 M_XOR(s1, REG_ITMP2, d);
1219 store_reg_to_var_int(iptr->dst, d);
1223 case ICMD_LCMP: /* ..., val1, val2 ==> ..., val1 cmp val2 */
1225 var_to_reg_int(s1, src->prev, REG_ITMP1);
1226 var_to_reg_int(s2, src, REG_ITMP2);
1227 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1228 M_CMPLT(s1, s2, REG_ITMP3);
1229 M_CMPLT(s2, s1, REG_ITMP1);
1230 M_LSUB (REG_ITMP1, REG_ITMP3, d);
1231 store_reg_to_var_int(iptr->dst, d);
1235 case ICMD_IINC: /* ..., value ==> ..., value + constant */
1236 /* op1 = variable, val.i = constant */
1238 var = &(rd->locals[iptr->op1][TYPE_INT]);
1239 if (var->flags & INMEMORY) {
1241 M_LLD(s1, REG_SP, 8 * var->regoff);
1245 M_IADD_IMM(s1, iptr->val.i, s1);
1246 if (var->flags & INMEMORY)
1247 M_LST(s1, REG_SP, 8 * var->regoff);
1251 /* floating operations ************************************************/
1253 case ICMD_FNEG: /* ..., value ==> ..., - value */
1255 var_to_reg_flt(s1, src, REG_FTMP1);
1256 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1258 store_reg_to_var_flt(iptr->dst, d);
1261 case ICMD_DNEG: /* ..., value ==> ..., - value */
1263 var_to_reg_flt(s1, src, REG_FTMP1);
1264 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1266 store_reg_to_var_flt(iptr->dst, d);
1269 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1271 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1272 var_to_reg_flt(s2, src, REG_FTMP2);
1273 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1275 store_reg_to_var_flt(iptr->dst, d);
1278 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1280 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1281 var_to_reg_flt(s2, src, REG_FTMP2);
1282 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1284 store_reg_to_var_flt(iptr->dst, d);
1287 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1289 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1290 var_to_reg_flt(s2, src, REG_FTMP2);
1291 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1293 store_reg_to_var_flt(iptr->dst, d);
1296 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1298 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1299 var_to_reg_flt(s2, src, REG_FTMP2);
1300 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1302 store_reg_to_var_flt(iptr->dst, d);
1305 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1307 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1308 var_to_reg_flt(s2, src, REG_FTMP2);
1309 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1311 store_reg_to_var_flt(iptr->dst, d);
1314 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 *** val2 */
1316 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1317 var_to_reg_flt(s2, src, REG_FTMP2);
1318 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1320 store_reg_to_var_flt(iptr->dst, d);
1323 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1325 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1326 var_to_reg_flt(s2, src, REG_FTMP2);
1327 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1329 store_reg_to_var_flt(iptr->dst, d);
1332 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1334 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1335 var_to_reg_flt(s2, src, REG_FTMP2);
1336 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1338 store_reg_to_var_flt(iptr->dst, d);
1342 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1344 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1345 var_to_reg_flt(s2, src, REG_FTMP2);
1346 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1347 M_FDIV(s1,s2, REG_FTMP3);
1348 M_FLOORFL(REG_FTMP3, REG_FTMP3);
1349 M_CVTLF(REG_FTMP3, REG_FTMP3);
1350 M_FMUL(REG_FTMP3, s2, REG_FTMP3);
1351 M_FSUB(s1, REG_FTMP3, d);
1352 store_reg_to_var_flt(iptr->dst, d);
1355 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1357 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1358 var_to_reg_flt(s2, src, REG_FTMP2);
1359 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1360 M_DDIV(s1,s2, REG_FTMP3);
1361 M_FLOORDL(REG_FTMP3, REG_FTMP3);
1362 M_CVTLD(REG_FTMP3, REG_FTMP3);
1363 M_DMUL(REG_FTMP3, s2, REG_FTMP3);
1364 M_DSUB(s1, REG_FTMP3, d);
1365 store_reg_to_var_flt(iptr->dst, d);
1369 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1371 var_to_reg_int(s1, src, REG_ITMP1);
1372 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1375 store_reg_to_var_flt(iptr->dst, d);
1378 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1380 var_to_reg_int(s1, src, REG_ITMP1);
1381 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1384 store_reg_to_var_flt(iptr->dst, d);
1387 case ICMD_F2I: /* ..., (float) value ==> ..., (int) value */
1389 var_to_reg_flt(s1, src, REG_FTMP1);
1390 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1391 M_TRUNCFI(s1, REG_FTMP1);
1392 M_MOVDI(REG_FTMP1, d);
1394 store_reg_to_var_int(iptr->dst, d);
1397 case ICMD_D2I: /* ..., (double) value ==> ..., (int) value */
1399 var_to_reg_flt(s1, src, REG_FTMP1);
1400 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1401 M_TRUNCDI(s1, REG_FTMP1);
1402 M_MOVDI(REG_FTMP1, d);
1404 store_reg_to_var_int(iptr->dst, d);
1407 case ICMD_F2L: /* ..., (float) value ==> ..., (long) value */
1409 var_to_reg_flt(s1, src, REG_FTMP1);
1410 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1411 M_TRUNCFL(s1, REG_FTMP1);
1412 M_MOVDL(REG_FTMP1, d);
1414 store_reg_to_var_int(iptr->dst, d);
1417 case ICMD_D2L: /* ..., (double) value ==> ..., (long) value */
1419 var_to_reg_flt(s1, src, REG_FTMP1);
1420 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1421 M_TRUNCDL(s1, REG_FTMP1);
1422 M_MOVDL(REG_FTMP1, d);
1424 store_reg_to_var_int(iptr->dst, d);
1427 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1429 var_to_reg_flt(s1, src, REG_FTMP1);
1430 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1432 store_reg_to_var_flt(iptr->dst, d);
1435 case ICMD_D2F: /* ..., value ==> ..., (double) value */
1437 var_to_reg_flt(s1, src, REG_FTMP1);
1438 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1440 store_reg_to_var_flt(iptr->dst, d);
1443 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1445 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1446 var_to_reg_flt(s2, src, REG_FTMP2);
1447 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1450 M_LADD_IMM(REG_ZERO, 1, d);
1454 M_LSUB_IMM(REG_ZERO, 1, d);
1455 M_CMOVT(REG_ZERO, d);
1456 store_reg_to_var_int(iptr->dst, d);
1459 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1461 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1462 var_to_reg_flt(s2, src, REG_FTMP2);
1463 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1466 M_LADD_IMM(REG_ZERO, 1, d);
1470 M_LSUB_IMM(REG_ZERO, 1, d);
1471 M_CMOVT(REG_ZERO, d);
1472 store_reg_to_var_int(iptr->dst, d);
1475 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1477 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1478 var_to_reg_flt(s2, src, REG_FTMP2);
1479 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1482 M_LSUB_IMM(REG_ZERO, 1, d);
1486 M_LADD_IMM(REG_ZERO, 1, d);
1487 M_CMOVT(REG_ZERO, d);
1488 store_reg_to_var_int(iptr->dst, d);
1491 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1493 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1494 var_to_reg_flt(s2, src, REG_FTMP2);
1495 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1498 M_LSUB_IMM(REG_ZERO, 1, d);
1502 M_LADD_IMM(REG_ZERO, 1, d);
1503 M_CMOVT(REG_ZERO, d);
1504 store_reg_to_var_int(iptr->dst, d);
1508 /* memory operations **************************************************/
1510 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1512 var_to_reg_int(s1, src, REG_ITMP1);
1513 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1514 gen_nullptr_check(s1);
1515 M_ILD(d, s1, OFFSET(java_arrayheader, size));
1516 store_reg_to_var_int(iptr->dst, d);
1519 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1521 var_to_reg_int(s1, src->prev, REG_ITMP1);
1522 var_to_reg_int(s2, src, REG_ITMP2);
1523 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1524 if (iptr->op1 == 0) {
1525 gen_nullptr_check(s1);
1528 M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP2);
1529 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1530 M_ALD(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1531 store_reg_to_var_int(iptr->dst, d);
1534 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1536 var_to_reg_int(s1, src->prev, REG_ITMP1);
1537 var_to_reg_int(s2, src, REG_ITMP2);
1538 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1539 if (iptr->op1 == 0) {
1540 gen_nullptr_check(s1);
1543 M_ASLL_IMM(s2, 2, REG_ITMP2);
1544 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1545 M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
1546 store_reg_to_var_int(iptr->dst, d);
1549 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1551 var_to_reg_int(s1, src->prev, REG_ITMP1);
1552 var_to_reg_int(s2, src, REG_ITMP2);
1553 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1554 if (iptr->op1 == 0) {
1555 gen_nullptr_check(s1);
1558 M_ASLL_IMM(s2, 3, REG_ITMP2);
1559 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1560 M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0]));
1561 store_reg_to_var_int(iptr->dst, d);
1564 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1566 var_to_reg_int(s1, src->prev, REG_ITMP1);
1567 var_to_reg_int(s2, src, REG_ITMP2);
1568 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1569 if (iptr->op1 == 0) {
1570 gen_nullptr_check(s1);
1573 M_ASLL_IMM(s2, 2, REG_ITMP2);
1574 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1575 M_FLD(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1576 store_reg_to_var_flt(iptr->dst, d);
1579 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1581 var_to_reg_int(s1, src->prev, REG_ITMP1);
1582 var_to_reg_int(s2, src, REG_ITMP2);
1583 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1584 if (iptr->op1 == 0) {
1585 gen_nullptr_check(s1);
1588 M_ASLL_IMM(s2, 3, REG_ITMP2);
1589 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1590 M_DLD(d, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1591 store_reg_to_var_flt(iptr->dst, d);
1594 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1596 var_to_reg_int(s1, src->prev, REG_ITMP1);
1597 var_to_reg_int(s2, src, REG_ITMP2);
1598 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1599 if (iptr->op1 == 0) {
1600 gen_nullptr_check(s1);
1603 M_AADD(s2, s1, REG_ITMP1);
1604 M_AADD(s2, REG_ITMP1, REG_ITMP1);
1605 M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
1606 store_reg_to_var_int(iptr->dst, d);
1609 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1611 var_to_reg_int(s1, src->prev, REG_ITMP1);
1612 var_to_reg_int(s2, src, REG_ITMP2);
1613 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1614 if (iptr->op1 == 0) {
1615 gen_nullptr_check(s1);
1618 M_AADD(s2, s1, REG_ITMP1);
1619 M_AADD(s2, REG_ITMP1, REG_ITMP1);
1620 M_SLDS(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
1621 store_reg_to_var_int(iptr->dst, d);
1624 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1626 var_to_reg_int(s1, src->prev, REG_ITMP1);
1627 var_to_reg_int(s2, src, REG_ITMP2);
1628 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1629 if (iptr->op1 == 0) {
1630 gen_nullptr_check(s1);
1633 M_AADD(s2, s1, REG_ITMP1);
1634 M_BLDS(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
1635 store_reg_to_var_int(iptr->dst, d);
1639 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1641 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1642 var_to_reg_int(s2, src->prev, REG_ITMP2);
1643 if (iptr->op1 == 0) {
1644 gen_nullptr_check(s1);
1647 var_to_reg_int(s3, src, REG_ITMP3);
1648 M_ASLL_IMM(s2, 2, REG_ITMP2);
1649 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1650 M_IST(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
1653 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1655 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1656 var_to_reg_int(s2, src->prev, REG_ITMP2);
1657 if (iptr->op1 == 0) {
1658 gen_nullptr_check(s1);
1661 var_to_reg_int(s3, src, REG_ITMP3);
1662 M_ASLL_IMM(s2, 3, REG_ITMP2);
1663 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1664 M_LST(s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
1667 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1669 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1670 var_to_reg_int(s2, src->prev, REG_ITMP2);
1671 if (iptr->op1 == 0) {
1672 gen_nullptr_check(s1);
1675 var_to_reg_flt(s3, src, REG_FTMP3);
1676 M_ASLL_IMM(s2, 2, REG_ITMP2);
1677 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1678 M_FST(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1681 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1683 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1684 var_to_reg_int(s2, src->prev, REG_ITMP2);
1685 if (iptr->op1 == 0) {
1686 gen_nullptr_check(s1);
1689 var_to_reg_flt(s3, src, REG_FTMP3);
1690 M_ASLL_IMM(s2, 3, REG_ITMP2);
1691 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1692 M_DST(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1695 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1696 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1698 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1699 var_to_reg_int(s2, src->prev, REG_ITMP2);
1700 if (iptr->op1 == 0) {
1701 gen_nullptr_check(s1);
1704 var_to_reg_int(s3, src, REG_ITMP3);
1705 M_AADD(s2, s1, REG_ITMP1);
1706 M_AADD(s2, REG_ITMP1, REG_ITMP1);
1707 M_SST(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
1710 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1712 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1713 var_to_reg_int(s2, src->prev, REG_ITMP2);
1714 if (iptr->op1 == 0) {
1715 gen_nullptr_check(s1);
1718 var_to_reg_int(s3, src, REG_ITMP3);
1719 M_AADD(s2, s1, REG_ITMP1);
1720 M_BST(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1724 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1726 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1727 var_to_reg_int(s2, src->prev, REG_ITMP2);
1728 /* if (iptr->op1 == 0) { */
1729 gen_nullptr_check(s1);
1732 var_to_reg_int(s3, src, REG_ITMP3);
1734 M_MOV(s1, rd->argintregs[0]);
1735 M_MOV(s3, rd->argintregs[1]);
1737 disp = dseg_addaddress(cd, bte->fp);
1738 M_ALD(REG_ITMP3, REG_PV, disp);
1739 M_JSR(REG_RA, REG_ITMP3);
1742 M_BEQZ(REG_RESULT, 0);
1743 codegen_addxstorerefs(cd, mcodeptr);
1746 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1747 var_to_reg_int(s2, src->prev, REG_ITMP2);
1748 var_to_reg_int(s3, src, REG_ITMP3);
1749 M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP2);
1750 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1751 M_AST(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1755 case ICMD_IASTORECONST: /* ..., arrayref, index ==> ... */
1757 var_to_reg_int(s1, src->prev, REG_ITMP1);
1758 var_to_reg_int(s2, src, REG_ITMP2);
1759 if (iptr->op1 == 0) {
1760 gen_nullptr_check(s1);
1763 M_ASLL_IMM(s2, 2, REG_ITMP2);
1764 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1765 M_IST(REG_ZERO, REG_ITMP1, OFFSET(java_intarray, data[0]));
1768 case ICMD_LASTORECONST: /* ..., arrayref, index ==> ... */
1770 var_to_reg_int(s1, src->prev, REG_ITMP1);
1771 var_to_reg_int(s2, src, REG_ITMP2);
1772 if (iptr->op1 == 0) {
1773 gen_nullptr_check(s1);
1776 M_ASLL_IMM(s2, 3, REG_ITMP2);
1777 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1778 M_LST(REG_ZERO, REG_ITMP1, OFFSET(java_longarray, data[0]));
1781 case ICMD_AASTORECONST: /* ..., arrayref, index ==> ... */
1783 var_to_reg_int(s1, src->prev, REG_ITMP1);
1784 var_to_reg_int(s2, src, REG_ITMP2);
1785 if (iptr->op1 == 0) {
1786 gen_nullptr_check(s1);
1789 M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP2);
1790 M_AADD(REG_ITMP2, s1, REG_ITMP1);
1791 M_AST(REG_ZERO, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1794 case ICMD_BASTORECONST: /* ..., arrayref, index ==> ... */
1796 var_to_reg_int(s1, src->prev, REG_ITMP1);
1797 var_to_reg_int(s2, src, REG_ITMP2);
1798 if (iptr->op1 == 0) {
1799 gen_nullptr_check(s1);
1802 M_AADD(s2, s1, REG_ITMP1);
1803 M_BST(REG_ZERO, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1806 case ICMD_CASTORECONST: /* ..., arrayref, index ==> ... */
1807 case ICMD_SASTORECONST: /* ..., arrayref, index ==> ... */
1809 var_to_reg_int(s1, src->prev, REG_ITMP1);
1810 var_to_reg_int(s2, src, REG_ITMP2);
1811 if (iptr->op1 == 0) {
1812 gen_nullptr_check(s1);
1815 M_AADD(s2, s1, REG_ITMP1);
1816 M_AADD(s2, REG_ITMP1, REG_ITMP1);
1817 M_SST(REG_ZERO, REG_ITMP1, OFFSET(java_chararray, data[0]));
1821 case ICMD_GETSTATIC: /* ... ==> ..., value */
1822 /* op1 = type, val.a = field address */
1825 codegen_addpatchref(cd, mcodeptr,
1826 PATCHER_get_putstatic,
1827 (unresolved_field *) iptr->target);
1829 if (opt_showdisassemble) {
1836 fieldinfo *fi = iptr->val.a;
1838 if (!fi->class->initialized) {
1839 codegen_addpatchref(cd, mcodeptr,
1840 PATCHER_clinit, fi->class);
1842 if (opt_showdisassemble) {
1847 a = (ptrint) &(fi->value);
1850 a = dseg_addaddress(cd, a);
1851 M_ALD(REG_ITMP1, REG_PV, a);
1852 switch (iptr->op1) {
1854 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1855 M_ILD(d, REG_ITMP1, 0);
1856 store_reg_to_var_int(iptr->dst, d);
1859 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1860 M_LLD(d, REG_ITMP1, 0);
1861 store_reg_to_var_int(iptr->dst, d);
1864 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1865 M_ALD(d, REG_ITMP1, 0);
1866 store_reg_to_var_int(iptr->dst, d);
1869 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1870 M_FLD(d, REG_ITMP1, 0);
1871 store_reg_to_var_flt(iptr->dst, d);
1874 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1875 M_DLD(d, REG_ITMP1, 0);
1876 store_reg_to_var_flt(iptr->dst, d);
1881 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1882 /* op1 = type, val.a = field address */
1885 codegen_addpatchref(cd, mcodeptr,
1886 PATCHER_get_putstatic,
1887 (unresolved_field *) iptr->target);
1889 if (opt_showdisassemble) {
1896 fieldinfo *fi = iptr->val.a;
1898 if (!fi->class->initialized) {
1899 codegen_addpatchref(cd, mcodeptr,
1900 PATCHER_clinit, fi->class);
1902 if (opt_showdisassemble) {
1907 a = (ptrint) &(fi->value);
1910 a = dseg_addaddress(cd, a);
1911 M_ALD(REG_ITMP1, REG_PV, a);
1912 switch (iptr->op1) {
1914 var_to_reg_int(s2, src, REG_ITMP2);
1915 M_IST(s2, REG_ITMP1, 0);
1918 var_to_reg_int(s2, src, REG_ITMP2);
1919 M_LST(s2, REG_ITMP1, 0);
1922 var_to_reg_int(s2, src, REG_ITMP2);
1923 M_AST(s2, REG_ITMP1, 0);
1926 var_to_reg_flt(s2, src, REG_FTMP2);
1927 M_FST(s2, REG_ITMP1, 0);
1930 var_to_reg_flt(s2, src, REG_FTMP2);
1931 M_DST(s2, REG_ITMP1, 0);
1936 case ICMD_PUTSTATICCONST: /* ... ==> ... */
1937 /* val = value (in current instruction) */
1938 /* op1 = type, val.a = field address (in */
1939 /* following NOP) */
1941 if (!iptr[1].val.a) {
1942 codegen_addpatchref(cd, mcodeptr,
1943 PATCHER_get_putstatic,
1944 (unresolved_field *) iptr[1].target);
1946 if (opt_showdisassemble) {
1953 fieldinfo *fi = iptr[1].val.a;
1955 if (!fi->class->initialized) {
1956 codegen_addpatchref(cd, mcodeptr,
1957 PATCHER_clinit, fi->class);
1959 if (opt_showdisassemble) {
1964 a = (ptrint) &(fi->value);
1967 a = dseg_addaddress(cd, a);
1968 M_ALD(REG_ITMP1, REG_PV, a);
1969 switch (iptr->op1) {
1971 M_IST(REG_ZERO, REG_ITMP1, 0);
1974 M_LST(REG_ZERO, REG_ITMP1, 0);
1977 M_AST(REG_ZERO, REG_ITMP1, 0);
1980 M_FST(REG_ZERO, REG_ITMP1, 0);
1983 M_DST(REG_ZERO, REG_ITMP1, 0);
1989 case ICMD_GETFIELD: /* ... ==> ..., value */
1990 /* op1 = type, val.i = field offset */
1992 var_to_reg_int(s1, src, REG_ITMP1);
1993 gen_nullptr_check(s1);
1996 codegen_addpatchref(cd, mcodeptr,
1997 PATCHER_get_putfield,
1998 (unresolved_field *) iptr->target);
2000 if (opt_showdisassemble) {
2007 a = ((fieldinfo *) (iptr->val.a))->offset;
2010 switch (iptr->op1) {
2012 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
2014 store_reg_to_var_int(iptr->dst, d);
2017 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
2019 store_reg_to_var_int(iptr->dst, d);
2022 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
2024 store_reg_to_var_int(iptr->dst, d);
2027 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
2029 store_reg_to_var_flt(iptr->dst, d);
2032 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
2034 store_reg_to_var_flt(iptr->dst, d);
2037 /* XXX quick hack */
2041 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
2042 /* op1 = type, val.a = field address */
2044 var_to_reg_int(s1, src->prev, REG_ITMP1);
2045 gen_nullptr_check(s1);
2047 if (!IS_FLT_DBL_TYPE(iptr->op1)) {
2048 var_to_reg_int(s2, src, REG_ITMP2);
2050 var_to_reg_flt(s2, src, REG_FTMP2);
2054 codegen_addpatchref(cd, mcodeptr,
2055 PATCHER_get_putfield,
2056 (unresolved_field *) iptr->target);
2058 if (opt_showdisassemble) {
2065 a = ((fieldinfo *) (iptr->val.a))->offset;
2068 switch (iptr->op1) {
2085 /* XXX quick hack */
2089 case ICMD_PUTFIELDCONST: /* ..., objectref ==> ... */
2090 /* val = value (in current instruction) */
2091 /* op1 = type, val.a = field address (in */
2092 /* following NOP) */
2094 var_to_reg_int(s1, src, REG_ITMP1);
2095 gen_nullptr_check(s1);
2097 if (!iptr[1].val.a) {
2098 codegen_addpatchref(cd, mcodeptr,
2099 PATCHER_get_putfield,
2100 (unresolved_field *) iptr[1].target);
2102 if (opt_showdisassemble) {
2109 a = ((fieldinfo *) (iptr[1].val.a))->offset;
2112 switch (iptr[1].op1) {
2114 M_IST(REG_ZERO, s1, a);
2117 M_LST(REG_ZERO, s1, a);
2120 M_AST(REG_ZERO, s1, a);
2123 M_FST(REG_ZERO, s1, a);
2126 M_DST(REG_ZERO, s1, a);
2129 /* XXX quick hack */
2134 /* branch operations **************************************************/
2136 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
2138 var_to_reg_int(s1, src, REG_ITMP1);
2139 M_INTMOVE(s1, REG_ITMP1_XPTR);
2140 a = dseg_addaddress(cd, asm_handle_exception);
2141 M_ALD(REG_ITMP2, REG_PV, a);
2142 M_JSR(REG_ITMP2_XPC, REG_ITMP2);
2144 M_NOP; /* nop ensures that XPC is less than the end */
2145 /* of basic block */
2149 case ICMD_GOTO: /* ... ==> ... */
2150 /* op1 = target JavaVM pc */
2152 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2157 case ICMD_JSR: /* ... ==> ... */
2158 /* op1 = target JavaVM pc */
2160 dseg_addtarget(cd, BlockPtrOfPC(iptr->op1));
2161 M_ALD(REG_ITMP1, REG_PV, -(cd->dseglen));
2162 M_JSR(REG_ITMP1, REG_ITMP1); /* REG_ITMP1 = return address */
2166 case ICMD_RET: /* ... ==> ... */
2167 /* op1 = local variable */
2168 var = &(rd->locals[iptr->op1][TYPE_ADR]);
2169 if (var->flags & INMEMORY) {
2170 M_ALD(REG_ITMP1, REG_SP, 8 * var->regoff);
2179 case ICMD_IFNULL: /* ..., value ==> ... */
2180 /* op1 = target JavaVM pc */
2182 var_to_reg_int(s1, src, REG_ITMP1);
2184 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2188 case ICMD_IFNONNULL: /* ..., value ==> ... */
2189 /* op1 = target JavaVM pc */
2191 var_to_reg_int(s1, src, REG_ITMP1);
2193 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2197 case ICMD_IFEQ: /* ..., value ==> ... */
2198 /* op1 = target JavaVM pc, val.i = constant */
2200 var_to_reg_int(s1, src, REG_ITMP1);
2201 if (iptr->val.i == 0) {
2205 ICONST(REG_ITMP2, iptr->val.i);
2206 M_BEQ(s1, REG_ITMP2, 0);
2208 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2212 case ICMD_IFLT: /* ..., value ==> ... */
2213 /* op1 = target JavaVM pc, val.i = constant */
2215 var_to_reg_int(s1, src, REG_ITMP1);
2216 if (iptr->val.i == 0) {
2220 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
2221 M_CMPLT_IMM(s1, iptr->val.i, REG_ITMP1);
2224 ICONST(REG_ITMP2, iptr->val.i);
2225 M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2227 M_BNEZ(REG_ITMP1, 0);
2229 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2233 case ICMD_IFLE: /* ..., value ==> ... */
2234 /* op1 = target JavaVM pc, val.i = constant */
2236 var_to_reg_int(s1, src, REG_ITMP1);
2237 if (iptr->val.i == 0) {
2241 if ((iptr->val.i >= -32769) && (iptr->val.i <= 32766)) {
2242 M_CMPLT_IMM(s1, iptr->val.i + 1, REG_ITMP1);
2243 M_BNEZ(REG_ITMP1, 0);
2246 ICONST(REG_ITMP2, iptr->val.i);
2247 M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
2248 M_BEQZ(REG_ITMP1, 0);
2251 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2255 case ICMD_IFNE: /* ..., value ==> ... */
2256 /* op1 = target JavaVM pc, val.i = constant */
2258 var_to_reg_int(s1, src, REG_ITMP1);
2259 if (iptr->val.i == 0) {
2263 ICONST(REG_ITMP2, iptr->val.i);
2264 M_BNE(s1, REG_ITMP2, 0);
2266 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2270 case ICMD_IFGT: /* ..., value ==> ... */
2271 /* op1 = target JavaVM pc, val.i = constant */
2273 var_to_reg_int(s1, src, REG_ITMP1);
2274 if (iptr->val.i == 0) {
2278 if ((iptr->val.i >= -32769) && (iptr->val.i <= 32766)) {
2279 M_CMPLT_IMM(s1, iptr->val.i + 1, REG_ITMP1);
2280 M_BEQZ(REG_ITMP1, 0);
2283 ICONST(REG_ITMP2, iptr->val.i);
2284 M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
2285 M_BNEZ(REG_ITMP1, 0);
2288 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2292 case ICMD_IFGE: /* ..., value ==> ... */
2293 /* op1 = target JavaVM pc, val.i = constant */
2295 var_to_reg_int(s1, src, REG_ITMP1);
2296 if (iptr->val.i == 0) {
2300 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
2301 M_CMPLT_IMM(s1, iptr->val.i, REG_ITMP1);
2304 ICONST(REG_ITMP2, iptr->val.i);
2305 M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2307 M_BEQZ(REG_ITMP1, 0);
2309 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2313 case ICMD_IF_LEQ: /* ..., value ==> ... */
2314 /* op1 = target JavaVM pc, val.l = constant */
2316 var_to_reg_int(s1, src, REG_ITMP1);
2317 if (iptr->val.l == 0) {
2321 LCONST(REG_ITMP2, iptr->val.l);
2322 M_BEQ(s1, REG_ITMP2, 0);
2324 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2328 case ICMD_IF_LLT: /* ..., value ==> ... */
2329 /* op1 = target JavaVM pc, val.l = constant */
2331 var_to_reg_int(s1, src, REG_ITMP1);
2332 if (iptr->val.l == 0) {
2336 if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
2337 M_CMPLT_IMM(s1, iptr->val.l, REG_ITMP1);
2340 LCONST(REG_ITMP2, iptr->val.l);
2341 M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2343 M_BNEZ(REG_ITMP1, 0);
2345 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2349 case ICMD_IF_LLE: /* ..., value ==> ... */
2350 /* op1 = target JavaVM pc, val.l = constant */
2352 var_to_reg_int(s1, src, REG_ITMP1);
2353 if (iptr->val.l == 0) {
2357 if ((iptr->val.l >= -32769) && (iptr->val.l <= 32766)) {
2358 M_CMPLT_IMM(s1, iptr->val.l + 1, REG_ITMP1);
2359 M_BNEZ(REG_ITMP1, 0);
2362 LCONST(REG_ITMP2, iptr->val.l);
2363 M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
2364 M_BEQZ(REG_ITMP1, 0);
2367 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2371 case ICMD_IF_LNE: /* ..., value ==> ... */
2372 /* op1 = target JavaVM pc, val.l = constant */
2374 var_to_reg_int(s1, src, REG_ITMP1);
2375 if (iptr->val.l == 0) {
2379 LCONST(REG_ITMP2, iptr->val.l);
2380 M_BNE(s1, REG_ITMP2, 0);
2382 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2386 case ICMD_IF_LGT: /* ..., value ==> ... */
2387 /* op1 = target JavaVM pc, val.l = constant */
2389 var_to_reg_int(s1, src, REG_ITMP1);
2390 if (iptr->val.l == 0) {
2394 if ((iptr->val.l >= -32769) && (iptr->val.l <= 32766)) {
2395 M_CMPLT_IMM(s1, iptr->val.l + 1, REG_ITMP1);
2396 M_BEQZ(REG_ITMP1, 0);
2399 LCONST(REG_ITMP2, iptr->val.l);
2400 M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
2401 M_BNEZ(REG_ITMP1, 0);
2404 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2408 case ICMD_IF_LGE: /* ..., value ==> ... */
2409 /* op1 = target JavaVM pc, val.l = constant */
2411 var_to_reg_int(s1, src, REG_ITMP1);
2412 if (iptr->val.l == 0) {
2416 if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
2417 M_CMPLT_IMM(s1, iptr->val.l, REG_ITMP1);
2420 LCONST(REG_ITMP2, iptr->val.l);
2421 M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
2423 M_BEQZ(REG_ITMP1, 0);
2425 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2429 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
2430 case ICMD_IF_LCMPEQ: /* op1 = target JavaVM pc */
2431 case ICMD_IF_ACMPEQ:
2433 var_to_reg_int(s1, src->prev, REG_ITMP1);
2434 var_to_reg_int(s2, src, REG_ITMP2);
2436 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2440 case ICMD_IF_ICMPNE: /* ..., value, value ==> ... */
2441 case ICMD_IF_LCMPNE: /* op1 = target JavaVM pc */
2442 case ICMD_IF_ACMPNE:
2444 var_to_reg_int(s1, src->prev, REG_ITMP1);
2445 var_to_reg_int(s2, src, REG_ITMP2);
2447 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2451 case ICMD_IF_ICMPLT: /* ..., value, value ==> ... */
2452 case ICMD_IF_LCMPLT: /* op1 = target JavaVM pc */
2454 var_to_reg_int(s1, src->prev, REG_ITMP1);
2455 var_to_reg_int(s2, src, REG_ITMP2);
2456 M_CMPLT(s1, s2, REG_ITMP1);
2457 M_BNEZ(REG_ITMP1, 0);
2458 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2462 case ICMD_IF_ICMPGT: /* ..., value, value ==> ... */
2463 case ICMD_IF_LCMPGT: /* op1 = target JavaVM pc */
2465 var_to_reg_int(s1, src->prev, REG_ITMP1);
2466 var_to_reg_int(s2, src, REG_ITMP2);
2467 M_CMPGT(s1, s2, REG_ITMP1);
2468 M_BNEZ(REG_ITMP1, 0);
2469 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2473 case ICMD_IF_ICMPLE: /* ..., value, value ==> ... */
2474 case ICMD_IF_LCMPLE: /* op1 = target JavaVM pc */
2476 var_to_reg_int(s1, src->prev, REG_ITMP1);
2477 var_to_reg_int(s2, src, REG_ITMP2);
2478 M_CMPGT(s1, s2, REG_ITMP1);
2479 M_BEQZ(REG_ITMP1, 0);
2480 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2484 case ICMD_IF_ICMPGE: /* ..., value, value ==> ... */
2485 case ICMD_IF_LCMPGE: /* op1 = target JavaVM pc */
2487 var_to_reg_int(s1, src->prev, REG_ITMP1);
2488 var_to_reg_int(s2, src, REG_ITMP2);
2489 M_CMPLT(s1, s2, REG_ITMP1);
2490 M_BEQZ(REG_ITMP1, 0);
2491 codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
2495 #ifdef CONDITIONAL_LOADCONST
2496 /* (value xx 0) ? IFxx_ICONST : ELSE_ICONST */
2498 case ICMD_ELSE_ICONST: /* handled by IFxx_ICONST */
2501 case ICMD_IFEQ_ICONST: /* ..., value ==> ..., constant */
2502 /* val.i = constant */
2504 var_to_reg_int(s1, src, REG_ITMP1);
2505 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
2507 if (iptr[1].opc == ICMD_ELSE_ICONST) {
2508 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2509 M_CMPEQ(s1, REG_ZERO, d);
2510 store_reg_to_var_int(iptr->dst, d);
2513 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2514 M_CMPEQ(s1, REG_ZERO, d);
2516 store_reg_to_var_int(iptr->dst, d);
2520 M_MOV(s1, REG_ITMP1);
2523 ICONST(d, iptr[1].val.i);
2525 if ((s3 >= 0) && (s3 <= 255)) {
2526 M_CMOVEQ_IMM(s1, s3, d);
2529 ICONST(REG_ITMP2, s3);
2530 M_CMOVEQ(s1, REG_ITMP2, d);
2532 store_reg_to_var_int(iptr->dst, d);
2535 case ICMD_IFNE_ICONST: /* ..., value ==> ..., constant */
2536 /* val.i = constant */
2538 var_to_reg_int(s1, src, REG_ITMP1);
2539 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
2541 if (iptr[1].opc == ICMD_ELSE_ICONST) {
2542 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2543 M_CMPEQ(s1, REG_ZERO, d);
2544 store_reg_to_var_int(iptr->dst, d);
2547 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2548 M_CMPEQ(s1, REG_ZERO, d);
2550 store_reg_to_var_int(iptr->dst, d);
2554 M_MOV(s1, REG_ITMP1);
2557 ICONST(d, iptr[1].val.i);
2559 if ((s3 >= 0) && (s3 <= 255)) {
2560 M_CMOVNE_IMM(s1, s3, d);
2563 ICONST(REG_ITMP2, s3);
2564 M_CMOVNE(s1, REG_ITMP2, d);
2566 store_reg_to_var_int(iptr->dst, d);
2569 case ICMD_IFLT_ICONST: /* ..., value ==> ..., constant */
2570 /* val.i = constant */
2572 var_to_reg_int(s1, src, REG_ITMP1);
2573 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
2575 if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2576 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2577 M_CMPLT(s1, REG_ZERO, d);
2578 store_reg_to_var_int(iptr->dst, d);
2581 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2582 M_CMPLE(REG_ZERO, s1, d);
2583 store_reg_to_var_int(iptr->dst, d);
2587 M_MOV(s1, REG_ITMP1);
2590 ICONST(d, iptr[1].val.i);
2592 if ((s3 >= 0) && (s3 <= 255)) {
2593 M_CMOVLT_IMM(s1, s3, d);
2596 ICONST(REG_ITMP2, s3);
2597 M_CMOVLT(s1, REG_ITMP2, d);
2599 store_reg_to_var_int(iptr->dst, d);
2602 case ICMD_IFGE_ICONST: /* ..., value ==> ..., constant */
2603 /* val.i = constant */
2605 var_to_reg_int(s1, src, REG_ITMP1);
2606 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
2608 if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2609 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2610 M_CMPLE(REG_ZERO, s1, d);
2611 store_reg_to_var_int(iptr->dst, d);
2614 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2615 M_CMPLT(s1, REG_ZERO, d);
2616 store_reg_to_var_int(iptr->dst, d);
2620 M_MOV(s1, REG_ITMP1);
2623 ICONST(d, iptr[1].val.i);
2625 if ((s3 >= 0) && (s3 <= 255)) {
2626 M_CMOVGE_IMM(s1, s3, d);
2629 ICONST(REG_ITMP2, s3);
2630 M_CMOVGE(s1, REG_ITMP2, d);
2632 store_reg_to_var_int(iptr->dst, d);
2635 case ICMD_IFGT_ICONST: /* ..., value ==> ..., constant */
2636 /* val.i = constant */
2638 var_to_reg_int(s1, src, REG_ITMP1);
2639 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
2641 if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2642 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2643 M_CMPLT(REG_ZERO, s1, d);
2644 store_reg_to_var_int(iptr->dst, d);
2647 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2648 M_CMPLE(s1, REG_ZERO, d);
2649 store_reg_to_var_int(iptr->dst, d);
2653 M_MOV(s1, REG_ITMP1);
2656 ICONST(d, iptr[1].val.i);
2658 if ((s3 >= 0) && (s3 <= 255)) {
2659 M_CMOVGT_IMM(s1, s3, d);
2662 ICONST(REG_ITMP2, s3);
2663 M_CMOVGT(s1, REG_ITMP2, d);
2665 store_reg_to_var_int(iptr->dst, d);
2668 case ICMD_IFLE_ICONST: /* ..., value ==> ..., constant */
2669 /* val.i = constant */
2671 var_to_reg_int(s1, src, REG_ITMP1);
2672 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
2674 if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
2675 if ((s3 == 1) && (iptr[1].val.i == 0)) {
2676 M_CMPLE(s1, REG_ZERO, d);
2677 store_reg_to_var_int(iptr->dst, d);
2680 if ((s3 == 0) && (iptr[1].val.i == 1)) {
2681 M_CMPLT(REG_ZERO, s1, d);
2682 store_reg_to_var_int(iptr->dst, d);
2686 M_MOV(s1, REG_ITMP1);
2689 ICONST(d, iptr[1].val.i);
2691 if ((s3 >= 0) && (s3 <= 255)) {
2692 M_CMOVLE_IMM(s1, s3, d);
2695 ICONST(REG_ITMP2, s3);
2696 M_CMOVLE(s1, REG_ITMP2, d);
2698 store_reg_to_var_int(iptr->dst, d);
2703 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2706 var_to_reg_int(s1, src, REG_RESULT);
2707 M_INTMOVE(s1, REG_RESULT);
2709 #if defined(USE_THREADS)
2710 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2712 a = dseg_addaddress(cd, (void *) builtin_monitorexit);
2713 M_ALD(REG_ITMP3, REG_PV, a);
2714 M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8);
2715 M_JSR(REG_RA, REG_ITMP3);
2716 M_LST(REG_RESULT, REG_SP, rd->memuse * 8); /* delay slot */
2718 disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
2719 M_LDA(REG_PV, REG_RA, disp);
2720 M_LLD(REG_RESULT, REG_SP, rd->memuse * 8);
2723 goto nowperformreturn;
2725 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2727 var_to_reg_flt(s1, src, REG_FRESULT);
2729 int t = ((iptr->opc == ICMD_FRETURN) ? TYPE_FLT : TYPE_DBL);
2730 M_TFLTMOVE(t, s1, REG_FRESULT);
2733 #if defined(USE_THREADS)
2734 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2736 a = dseg_addaddress(cd, (void *) builtin_monitorexit);
2737 M_ALD(REG_ITMP3, REG_PV, a);
2738 M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8);
2739 M_JSR(REG_RA, REG_ITMP3);
2740 M_DST(REG_FRESULT, REG_SP, rd->memuse * 8); /* delay slot */
2742 disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
2743 M_LDA(REG_PV, REG_RA, disp);
2744 M_DLD(REG_FRESULT, REG_SP, rd->memuse * 8);
2747 goto nowperformreturn;
2749 case ICMD_RETURN: /* ... ==> ... */
2751 #if defined(USE_THREADS)
2752 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2754 a = dseg_addaddress(cd, (void *) builtin_monitorexit);
2755 M_ALD(REG_ITMP3, REG_PV, a);
2756 M_JSR(REG_RA, REG_ITMP3);
2757 M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8); /* delay slot */
2758 disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
2759 M_LDA(REG_PV, REG_RA, disp);
2767 p = parentargs_base;
2769 /* restore return address */
2771 if (!m->isleafmethod) {
2772 p--; M_LLD(REG_RA, REG_SP, 8 * p);
2775 /* restore saved registers */
2777 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
2778 p--; M_LLD(rd->savintregs[i], REG_SP, 8 * p);
2780 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
2781 p--; M_DLD(rd->savfltregs[i], REG_SP, 8 * p);
2784 /* call trace function */
2787 M_LDA (REG_SP, REG_SP, -24);
2788 M_LST(REG_RA, REG_SP, 0);
2789 M_LST(REG_RESULT, REG_SP, 8);
2790 M_DST(REG_FRESULT, REG_SP,16);
2791 a = dseg_addaddress(cd, m);
2792 M_ALD(rd->argintregs[0], REG_PV, a);
2793 M_MOV(REG_RESULT, rd->argintregs[1]);
2794 M_FLTMOVE(REG_FRESULT, rd->argfltregs[2]);
2795 M_FMOV(REG_FRESULT, rd->argfltregs[3]);
2796 a = dseg_addaddress(cd, (void *) builtin_displaymethodstop);
2797 M_ALD(REG_ITMP3, REG_PV, a);
2798 M_JSR (REG_RA, REG_ITMP3);
2800 M_DLD(REG_FRESULT, REG_SP,16);
2801 M_LLD(REG_RESULT, REG_SP, 8);
2802 M_LLD(REG_RA, REG_SP, 0);
2803 M_LDA (REG_SP, REG_SP, 24);
2808 /* deallocate stack */
2810 if (parentargs_base) {
2811 M_LDA(REG_SP, REG_SP, parentargs_base * 8);
2822 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2827 tptr = (void **) iptr->target;
2829 s4ptr = iptr->val.a;
2830 l = s4ptr[1]; /* low */
2831 i = s4ptr[2]; /* high */
2833 var_to_reg_int(s1, src, REG_ITMP1);
2835 {M_INTMOVE(s1, REG_ITMP1);}
2836 else if (l <= 32768) {
2837 M_IADD_IMM(s1, -l, REG_ITMP1);
2840 ICONST(REG_ITMP2, l);
2841 M_ISUB(s1, REG_ITMP2, REG_ITMP1);
2847 M_CMPULT_IMM(REG_ITMP1, i, REG_ITMP2);
2848 M_BEQZ(REG_ITMP2, 0);
2849 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2850 M_ASLL_IMM(REG_ITMP1, POINTERSHIFT, REG_ITMP1); /* delay slot*/
2852 /* build jump table top down and use address of lowest entry */
2854 /* s4ptr += 3 + i; */
2858 /* dseg_addtarget(cd, BlockPtrOfPC(*--s4ptr)); */
2859 dseg_addtarget(cd, (basicblock *) tptr[0]);
2864 /* length of dataseg after last dseg_addtarget is used by load */
2866 M_AADD(REG_ITMP1, REG_PV, REG_ITMP2);
2867 M_ALD(REG_ITMP2, REG_ITMP2, -(cd->dseglen));
2874 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2876 s4 i, /*l, */val, *s4ptr;
2879 tptr = (void **) iptr->target;
2881 s4ptr = iptr->val.a;
2882 /*l = s4ptr[0];*/ /* default */
2883 i = s4ptr[1]; /* count */
2885 MCODECHECK((i<<2)+8);
2886 var_to_reg_int(s1, src, REG_ITMP1);
2892 ICONST(REG_ITMP2, val);
2893 M_BEQ(s1, REG_ITMP2, 0);
2894 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2899 tptr = (void **) iptr->target;
2900 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2907 case ICMD_BUILTIN: /* ..., arg1 ==> ... */
2908 /* op1 = arg count val.a = builtintable entry */
2914 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2915 /* op1 = arg count, val.a = method pointer */
2917 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2918 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2919 case ICMD_INVOKEINTERFACE:
2924 md = lm->parseddesc;
2926 unresolved_method *um = iptr->target;
2927 md = um->methodref->parseddesc.md;
2933 MCODECHECK((s3 << 1) + 64);
2935 /* copy arguments to registers or stack location */
2937 for (s3 = s3 - 1; s3 >= 0; s3--, src = src->prev) {
2938 if (src->varkind == ARGVAR)
2940 if (IS_INT_LNG_TYPE(src->type)) {
2941 if (!md->params[s3].inmemory) {
2942 s1 = rd->argintregs[md->params[s3].regoff];
2943 var_to_reg_int(d, src, s1);
2946 var_to_reg_int(d, src, REG_ITMP1);
2947 M_LST(d, REG_SP, md->params[s3].regoff * 8);
2951 if (!md->params[s3].inmemory) {
2952 s1 = rd->argfltregs[md->params[s3].regoff];
2953 var_to_reg_flt(d, src, s1);
2954 M_TFLTMOVE(src->type, d, s1);
2956 var_to_reg_flt(d, src, REG_FTMP1);
2957 M_DST(d, REG_SP, md->params[s3].regoff * 8);
2962 switch (iptr->opc) {
2965 codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target);
2967 if (opt_showdisassemble) {
2974 a = (ptrint) bte->fp;
2977 a = dseg_addaddress(cd, a);
2978 d = md->returntype.type;
2980 M_ALD(REG_ITMP3, REG_PV, a); /* built-in-function pointer */
2981 M_JSR(REG_RA, REG_ITMP3);
2983 goto afteractualcall;
2985 case ICMD_INVOKESPECIAL:
2986 gen_nullptr_check(rd->argintregs[0]);
2987 M_ILD(REG_ITMP1, rd->argintregs[0], 0); /* hardware nullptr */
2990 case ICMD_INVOKESTATIC:
2992 unresolved_method *um = iptr->target;
2994 codegen_addpatchref(cd, mcodeptr,
2995 PATCHER_invokestatic_special, um);
2997 if (opt_showdisassemble) {
3002 d = um->methodref->parseddesc.md->returntype.type;
3005 a = (ptrint) lm->stubroutine;
3006 d = lm->parseddesc->returntype.type;
3009 a = dseg_addaddress(cd, a);
3010 M_ALD(REG_PV, REG_PV, a); /* method pointer in pv */
3013 case ICMD_INVOKEVIRTUAL:
3014 gen_nullptr_check(rd->argintregs[0]);
3017 unresolved_method *um = iptr->target;
3019 codegen_addpatchref(cd, mcodeptr,
3020 PATCHER_invokevirtual, um);
3022 if (opt_showdisassemble) {
3027 d = um->methodref->parseddesc.md->returntype.type;
3030 s1 = OFFSET(vftbl_t, table[0]) +
3031 sizeof(methodptr) * lm->vftblindex;
3032 d = lm->parseddesc->returntype.type;
3035 M_ALD(REG_METHODPTR, rd->argintregs[0],
3036 OFFSET(java_objectheader, vftbl));
3037 M_ALD(REG_PV, REG_METHODPTR, s1);
3040 case ICMD_INVOKEINTERFACE:
3041 gen_nullptr_check(rd->argintregs[0]);
3044 unresolved_method *um = iptr->target;
3046 codegen_addpatchref(cd, mcodeptr,
3047 PATCHER_invokeinterface, um);
3049 if (opt_showdisassemble) {
3055 d = um->methodref->parseddesc.md->returntype.type;
3058 s1 = OFFSET(vftbl_t, interfacetable[0]) -
3059 sizeof(methodptr*) * lm->class->index;
3061 s2 = sizeof(methodptr) * (lm - lm->class->methods);
3063 d = lm->parseddesc->returntype.type;
3066 M_ALD(REG_METHODPTR, rd->argintregs[0],
3067 OFFSET(java_objectheader, vftbl));
3068 M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
3069 M_ALD(REG_PV, REG_METHODPTR, s2);
3073 M_JSR(REG_RA, REG_PV);
3080 s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
3081 if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
3083 s4 ml = -s1, mh = 0;
3084 while (ml < -32768) { ml += 65536; mh--; }
3086 M_IADD_IMM(REG_PV, ml, REG_PV);
3087 M_LADD(REG_PV, REG_RA, REG_PV);
3090 /* d contains return type */
3092 if (d != TYPE_VOID) {
3093 if (IS_INT_LNG_TYPE(iptr->dst->type)) {
3094 s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
3095 M_INTMOVE(REG_RESULT, s1);
3096 store_reg_to_var_int(iptr->dst, s1);
3098 s1 = reg_of_var(rd, iptr->dst, REG_FRESULT);
3099 M_TFLTMOVE(iptr->dst->type, REG_FRESULT, s1);
3100 store_reg_to_var_flt(iptr->dst, s1);
3106 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
3107 /* op1: 0 == array, 1 == class */
3108 /* val.a: (classinfo*) superclass */
3110 /* superclass is an interface:
3112 * OK if ((sub == NULL) ||
3113 * (sub->vftbl->interfacetablelength > super->index) &&
3114 * (sub->vftbl->interfacetable[-super->index] != NULL));
3116 * superclass is a class:
3118 * OK if ((sub == NULL) || (0
3119 * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
3120 * super->vftbl->diffvall));
3125 vftbl_t *supervftbl;
3128 super = (classinfo *) iptr->val.a;
3135 superindex = super->index;
3136 supervftbl = super->vftbl;
3139 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3140 codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
3143 var_to_reg_int(s1, src, REG_ITMP1);
3145 /* calculate interface checkcast code size */
3149 s2 += (opt_showdisassemble ? 2 : 0);
3151 /* calculate class checkcast code size */
3153 s3 = 10 /* 10 + (s1 == REG_ITMP1) */;
3155 s3 += (opt_showdisassemble ? 2 : 0);
3157 /* if class is not resolved, check which code to call */
3160 M_BEQZ(s1, 5 + (opt_showdisassemble ? 2 : 0) + s2 + 2 + s3);
3163 codegen_addpatchref(cd, mcodeptr,
3164 PATCHER_checkcast_instanceof_flags,
3165 (constant_classref *) iptr->target);
3167 if (opt_showdisassemble) {
3171 a = dseg_adds4(cd, 0); /* super->flags */
3172 M_ILD(REG_ITMP2, REG_PV, a);
3173 M_AND_IMM(REG_ITMP2, ACC_INTERFACE, REG_ITMP2);
3174 M_BEQZ(REG_ITMP2, 1 + s2 + 2);
3178 /* interface checkcast code */
3180 if (!super || super->flags & ACC_INTERFACE) {
3186 codegen_addpatchref(cd, mcodeptr,
3187 PATCHER_checkcast_instanceof_interface,
3188 (constant_classref *) iptr->target);
3190 if (opt_showdisassemble) {
3195 M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
3196 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
3197 M_IADD_IMM(REG_ITMP3, -superindex, REG_ITMP3);
3198 M_BLEZ(REG_ITMP3, 0);
3199 codegen_addxcastrefs(cd, mcodeptr);
3201 M_ALD(REG_ITMP3, REG_ITMP2,
3202 OFFSET(vftbl_t, interfacetable[0]) -
3203 superindex * sizeof(methodptr*));
3204 M_BEQZ(REG_ITMP3, 0);
3205 codegen_addxcastrefs(cd, mcodeptr);
3214 /* class checkcast code */
3216 if (!super || !(super->flags & ACC_INTERFACE)) {
3222 codegen_addpatchref(cd, mcodeptr,
3223 PATCHER_checkcast_instanceof_class,
3224 (constant_classref *) iptr->target);
3226 if (opt_showdisassemble) {
3231 M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
3232 a = dseg_addaddress(cd, (void *) supervftbl);
3233 M_ALD(REG_ITMP3, REG_PV, a);
3234 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3235 codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
3237 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
3238 /* if (s1 != REG_ITMP1) { */
3239 /* M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, baseval)); */
3240 /* M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval)); */
3241 /* #if defined(USE_THREADS) && defined(NATIVE_THREADS) */
3242 /* codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase); */
3244 /* M_ISUB(REG_ITMP2, REG_ITMP1, REG_ITMP2); */
3246 M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
3247 M_ISUB(REG_ITMP2, REG_ITMP3, REG_ITMP2);
3248 M_ALD(REG_ITMP3, REG_PV, a);
3249 M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
3250 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3251 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
3254 M_CMPULT(REG_ITMP3, REG_ITMP2, REG_ITMP3);
3255 M_BNEZ(REG_ITMP3, 0);
3256 codegen_addxcastrefs(cd, mcodeptr);
3259 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
3261 store_reg_to_var_int(iptr->dst, d);
3265 case ICMD_ARRAYCHECKCAST: /* ..., objectref ==> ..., objectref */
3266 /* op1: 1... resolved, 0... not resolved */
3268 var_to_reg_int(s1, src, rd->argintregs[0]);
3269 M_INTMOVE(s1, rd->argintregs[0]);
3274 codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target);
3276 if (opt_showdisassemble) {
3283 a = (ptrint) bte->fp;
3286 disp = dseg_addaddress(cd, iptr->target);
3287 M_ALD(rd->argintregs[1], REG_PV, disp);
3288 disp = dseg_addaddress(cd, a);
3289 M_ALD(REG_ITMP3, REG_PV, disp);
3290 M_JSR(REG_RA, REG_ITMP3);
3293 M_BEQZ(REG_RESULT, 0);
3294 codegen_addxcastrefs(cd, mcodeptr);
3297 var_to_reg_int(s1, src, REG_ITMP1);
3298 d = reg_of_var(rd, iptr->dst, s1);
3300 store_reg_to_var_int(iptr->dst, d);
3303 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
3304 /* op1: 0 == array, 1 == class */
3305 /* val.a: (classinfo*) superclass */
3307 /* superclass is an interface:
3309 * return (sub != NULL) &&
3310 * (sub->vftbl->interfacetablelength > super->index) &&
3311 * (sub->vftbl->interfacetable[-super->index] != NULL);
3313 * superclass is a class:
3315 * return ((sub != NULL) && (0
3316 * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
3317 * super->vftbl->diffvall));
3322 vftbl_t *supervftbl;
3325 super = (classinfo *) iptr->val.a;
3332 superindex = super->index;
3333 supervftbl = super->vftbl;
3336 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3337 codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
3340 var_to_reg_int(s1, src, REG_ITMP1);
3341 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
3343 M_MOV(s1, REG_ITMP1);
3347 /* calculate interface instanceof code size */
3351 s2 += (opt_showdisassemble ? 2 : 0);
3353 /* calculate class instanceof code size */
3357 s3 += (opt_showdisassemble ? 2 : 0);
3361 /* if class is not resolved, check which code to call */
3364 M_BEQZ(s1, 5 + (opt_showdisassemble ? 2 : 0) + s2 + 2 + s3);
3367 codegen_addpatchref(cd, mcodeptr,
3368 PATCHER_checkcast_instanceof_flags,
3369 (constant_classref *) iptr->target);
3371 if (opt_showdisassemble) {
3375 a = dseg_adds4(cd, 0); /* super->flags */
3376 M_ILD(REG_ITMP3, REG_PV, a);
3377 M_AND_IMM(REG_ITMP3, ACC_INTERFACE, REG_ITMP3);
3378 M_BEQZ(REG_ITMP3, 1 + s2 + 2);
3382 /* interface instanceof code */
3384 if (!super || (super->flags & ACC_INTERFACE)) {
3390 codegen_addpatchref(cd, mcodeptr,
3391 PATCHER_checkcast_instanceof_interface,
3392 (constant_classref *) iptr->target);
3394 if (opt_showdisassemble) {
3399 M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3400 M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
3401 M_IADD_IMM(REG_ITMP3, -superindex, REG_ITMP3);
3402 M_BLEZ(REG_ITMP3, 3);
3404 M_ALD(REG_ITMP1, REG_ITMP1,
3405 OFFSET(vftbl_t, interfacetable[0]) -
3406 superindex * sizeof(methodptr*));
3407 M_CMPULT(REG_ZERO, REG_ITMP1, d); /* REG_ITMP1 != 0 */
3415 /* class instanceof code */
3417 if (!super || !(super->flags & ACC_INTERFACE)) {
3423 codegen_addpatchref(cd, mcodeptr,
3424 PATCHER_checkcast_instanceof_class,
3425 (constant_classref *) iptr->target);
3427 if (opt_showdisassemble) {
3432 M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3433 a = dseg_addaddress(cd, supervftbl);
3434 M_ALD(REG_ITMP2, REG_PV, a);
3435 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3436 codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
3438 M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
3439 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
3440 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
3441 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3442 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
3444 M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
3445 M_CMPULT(REG_ITMP2, REG_ITMP1, d);
3448 store_reg_to_var_int(iptr->dst, d);
3452 case ICMD_CHECKASIZE: /* ..., size ==> ..., size */
3454 var_to_reg_int(s1, src, REG_ITMP1);
3456 codegen_addxcheckarefs(cd, mcodeptr);
3460 case ICMD_CHECKEXCEPTION: /* ... ==> ... */
3462 M_BEQZ(REG_RESULT, 0);
3463 codegen_addxexceptionrefs(cd, mcodeptr);
3467 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
3468 /* op1 = dimension, val.a = array descriptor */
3470 /* check for negative sizes and copy sizes to stack if necessary */
3472 MCODECHECK((iptr->op1 << 1) + 64);
3474 for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
3475 var_to_reg_int(s2, src, REG_ITMP1);
3477 codegen_addxcheckarefs(cd, mcodeptr);
3480 /* copy SAVEDVAR sizes to stack */
3482 if (src->varkind != ARGVAR) {
3483 M_LST(s2, REG_SP, s1 * 8);
3487 /* is patcher function set? */
3490 codegen_addpatchref(cd, mcodeptr,
3491 (functionptr) iptr->target, iptr->val.a);
3493 if (opt_showdisassemble) {
3500 a = (ptrint) iptr->val.a;
3503 /* a0 = dimension count */
3505 ICONST(rd->argintregs[0], iptr->op1);
3507 /* a1 = arraydescriptor */
3509 a = dseg_addaddress(cd, a);
3510 M_ALD(rd->argintregs[1], REG_PV, a);
3512 /* a2 = pointer to dimensions = stack pointer */
3514 M_INTMOVE(REG_SP, rd->argintregs[2]);
3516 a = dseg_addaddress(cd, BUILTIN_multianewarray);
3517 M_ALD(REG_ITMP3, REG_PV, a);
3518 M_JSR(REG_RA, REG_ITMP3);
3520 s1 = (s4)((u1 *) mcodeptr - cd->mcodebase);
3522 M_LDA(REG_PV, REG_RA, -s1);
3526 s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
3527 M_INTMOVE(REG_RESULT, s1);
3528 store_reg_to_var_int(iptr->dst, s1);
3532 throw_cacao_exception_exit(string_java_lang_InternalError,
3533 "Unknown ICMD %d", iptr->opc);
3536 } /* for instruction */
3538 /* copy values to interface registers */
3540 src = bptr->outstack;
3541 len = bptr->outdepth;
3548 if ((src->varkind != STACKVAR)) {
3550 if (IS_FLT_DBL_TYPE(s2)) {
3551 var_to_reg_flt(s1, src, REG_FTMP1);
3552 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
3553 M_TFLTMOVE(s2, s1, rd->interfaces[len][s2].regoff);
3556 M_DST(s1, REG_SP, 8 * rd->interfaces[len][s2].regoff);
3560 var_to_reg_int(s1, src, REG_ITMP1);
3561 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
3562 M_INTMOVE(s1, rd->interfaces[len][s2].regoff);
3565 M_LST(s1, REG_SP, 8 * rd->interfaces[len][s2].regoff);
3571 } /* if (bptr -> flags >= BBREACHED) */
3572 } /* for basic block */
3574 codegen_createlinenumbertable(cd);
3580 /* generate ArithmeticException stubs */
3584 for (bref = cd->xdivrefs; bref != NULL; bref = bref->next) {
3585 if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3586 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3588 (u1 *) xcodeptr - cd->mcodebase - 4);
3592 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3594 (u1 *) mcodeptr - cd->mcodebase);
3598 M_AADD_IMM(REG_PV, bref->branchpos - 4, REG_ITMP2_XPC);
3600 if (xcodeptr != NULL) {
3601 M_BR(xcodeptr - mcodeptr);
3605 xcodeptr = mcodeptr;
3607 M_MOV(REG_PV, rd->argintregs[0]);
3608 M_MOV(REG_SP, rd->argintregs[1]);
3610 if (m->isleafmethod)
3611 M_MOV(REG_RA, rd->argintregs[2]);
3613 M_ALD(rd->argintregs[2],
3614 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
3616 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3618 M_ASUB_IMM(REG_SP, 2 * 8, REG_SP);
3619 M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
3621 if (m->isleafmethod)
3622 M_AST(REG_RA, REG_SP, 1 * 8);
3624 a = dseg_addaddress(cd, stacktrace_inline_arithmeticexception);
3625 M_ALD(REG_ITMP3, REG_PV, a);
3626 M_JSR(REG_RA, REG_ITMP3);
3628 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3630 if (m->isleafmethod)
3631 M_ALD(REG_RA, REG_SP, 1 * 8);
3633 M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
3634 M_AADD_IMM(REG_SP, 2 * 8, REG_SP);
3636 a = dseg_addaddress(cd, asm_handle_exception);
3637 M_ALD(REG_ITMP3, REG_PV, a);
3643 /* generate ArrayIndexOutOfBoundsException stubs */
3647 for (bref = cd->xboundrefs; bref != NULL; bref = bref->next) {
3648 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3650 (u1 *) mcodeptr - cd->mcodebase);
3654 /* move index register into REG_ITMP1 */
3656 M_MOV(bref->reg, REG_ITMP1);
3657 M_AADD_IMM(REG_PV, bref->branchpos - 4, REG_ITMP2_XPC);
3659 if (xcodeptr != NULL) {
3660 M_BR(xcodeptr - mcodeptr);
3664 xcodeptr = mcodeptr;
3666 M_MOV(REG_PV, rd->argintregs[0]);
3667 M_MOV(REG_SP, rd->argintregs[1]);
3669 if (m->isleafmethod)
3670 M_MOV(REG_RA, rd->argintregs[2]);
3672 M_ALD(rd->argintregs[2],
3673 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
3675 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3676 M_MOV(REG_ITMP1, rd->argintregs[4]);
3678 M_ASUB_IMM(REG_SP, 2 * 8, REG_SP);
3679 M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
3681 if (m->isleafmethod)
3682 M_AST(REG_RA, REG_SP, 1 * 8);
3684 a = dseg_addaddress(cd, stacktrace_inline_arrayindexoutofboundsexception);
3685 M_ALD(REG_ITMP3, REG_PV, a);
3686 M_JSR(REG_RA, REG_ITMP3);
3688 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3690 if (m->isleafmethod)
3691 M_ALD(REG_RA, REG_SP, 1 * 8);
3693 M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
3694 M_AADD_IMM(REG_SP, 2 * 8, REG_SP);
3696 a = dseg_addaddress(cd, asm_handle_exception);
3697 M_ALD(REG_ITMP3, REG_PV, a);
3703 /* generate ArrayStoreException stubs */
3707 for (bref = cd->xstorerefs; bref != NULL; bref = bref->next) {
3708 if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3709 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3711 (u1 *) xcodeptr - cd->mcodebase - 4);
3715 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3717 (u1 *) mcodeptr - cd->mcodebase);
3721 M_AADD_IMM(REG_PV, bref->branchpos - 4, REG_ITMP2_XPC);
3723 if (xcodeptr != NULL) {
3724 M_BR(xcodeptr - mcodeptr);
3728 xcodeptr = mcodeptr;
3730 M_MOV(REG_PV, rd->argintregs[0]);
3731 M_MOV(REG_SP, rd->argintregs[1]);
3732 M_ALD(rd->argintregs[2],
3733 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
3734 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3736 M_ASUB_IMM(REG_SP, 1 * 8, REG_SP);
3737 M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
3739 a = dseg_addaddress(cd, stacktrace_inline_arraystoreexception);
3740 M_ALD(REG_ITMP3, REG_PV, a);
3741 M_JSR(REG_RA, REG_ITMP3);
3743 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3745 M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
3746 M_AADD_IMM(REG_SP, 1 * 8, REG_SP);
3748 a = dseg_addaddress(cd, asm_handle_exception);
3749 M_ALD(REG_ITMP3, REG_PV, a);
3755 /* generate ClassCastException stubs */
3759 for (bref = cd->xcastrefs; bref != NULL; bref = bref->next) {
3760 if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3761 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3763 (u1 *) xcodeptr - cd->mcodebase - 4);
3767 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3769 (u1 *) mcodeptr - cd->mcodebase);
3773 M_AADD_IMM(REG_PV, bref->branchpos - 4, REG_ITMP2_XPC);
3775 if (xcodeptr != NULL) {
3776 M_BR(xcodeptr - mcodeptr);
3780 xcodeptr = mcodeptr;
3782 M_MOV(REG_PV, rd->argintregs[0]);
3783 M_MOV(REG_SP, rd->argintregs[1]);
3785 if (m->isleafmethod)
3786 M_MOV(REG_RA, rd->argintregs[2]);
3788 M_ALD(rd->argintregs[2],
3789 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
3791 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3793 M_ASUB_IMM(REG_SP, 2 * 8, REG_SP);
3794 M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
3796 if (m->isleafmethod)
3797 M_AST(REG_RA, REG_SP, 1 * 8);
3799 a = dseg_addaddress(cd, stacktrace_inline_classcastexception);
3800 M_ALD(REG_ITMP3, REG_PV, a);
3801 M_JSR(REG_RA, REG_ITMP3);
3803 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3805 if (m->isleafmethod)
3806 M_ALD(REG_RA, REG_SP, 1 * 8);
3808 M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
3809 M_AADD_IMM(REG_SP, 2 * 8, REG_SP);
3811 a = dseg_addaddress(cd, asm_handle_exception);
3812 M_ALD(REG_ITMP3, REG_PV, a);
3818 /* generate NegativeArraySizeException stubs */
3822 for (bref = cd->xcheckarefs; bref != NULL; bref = bref->next) {
3823 if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3824 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3826 (u1 *) xcodeptr - cd->mcodebase - 4);
3830 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3832 (u1 *) mcodeptr - cd->mcodebase);
3836 M_AADD_IMM(REG_PV, bref->branchpos - 4, REG_ITMP2_XPC);
3838 if (xcodeptr != NULL) {
3839 M_BR(xcodeptr - mcodeptr);
3843 xcodeptr = mcodeptr;
3845 M_MOV(REG_PV, rd->argintregs[0]);
3846 M_MOV(REG_SP, rd->argintregs[1]);
3847 M_ALD(rd->argintregs[2],
3848 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
3849 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3851 M_ASUB_IMM(REG_SP, 1 * 8, REG_SP);
3852 M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
3854 a = dseg_addaddress(cd, stacktrace_inline_negativearraysizeexception);
3855 M_ALD(REG_ITMP3, REG_PV, a);
3856 M_JSR(REG_RA, REG_ITMP3);
3858 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3860 M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
3861 M_AADD_IMM(REG_SP, 1 * 8, REG_SP);
3863 a = dseg_addaddress(cd, asm_handle_exception);
3864 M_ALD(REG_ITMP3, REG_PV, a);
3870 /* generate NullPointerException stubs */
3874 for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
3875 if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3876 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3878 (u1 *) xcodeptr - cd->mcodebase - 4);
3882 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3884 (u1 *) mcodeptr - cd->mcodebase);
3888 M_AADD_IMM(REG_PV, bref->branchpos - 4, REG_ITMP2_XPC);
3890 if (xcodeptr != NULL) {
3891 M_BR(xcodeptr - mcodeptr);
3895 xcodeptr = mcodeptr;
3897 M_MOV(REG_PV, rd->argintregs[0]);
3898 M_MOV(REG_SP, rd->argintregs[1]);
3900 if (m->isleafmethod)
3901 M_MOV(REG_RA, rd->argintregs[2]);
3903 M_ALD(rd->argintregs[2],
3904 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
3906 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3908 M_ASUB_IMM(REG_SP, 2 * 8, REG_SP);
3909 M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
3911 if (m->isleafmethod)
3912 M_AST(REG_RA, REG_SP, 1 * 8);
3914 a = dseg_addaddress(cd, stacktrace_inline_nullpointerexception);
3915 M_ALD(REG_ITMP3, REG_PV, a);
3916 M_JSR(REG_RA, REG_ITMP3);
3918 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3920 if (m->isleafmethod)
3921 M_ALD(REG_RA, REG_SP, 1 * 8);
3923 M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
3924 M_AADD_IMM(REG_SP, 2 * 8, REG_SP);
3926 a = dseg_addaddress(cd, asm_handle_exception);
3927 M_ALD(REG_ITMP3, REG_PV, a);
3933 /* generate ICMD_CHECKEXCEPTION stubs */
3937 for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
3938 if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3939 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3941 (u1 *) xcodeptr - cd->mcodebase - 4);
3945 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3947 (u1 *) mcodeptr - cd->mcodebase);
3951 M_AADD_IMM(REG_PV, bref->branchpos - 4, REG_ITMP2_XPC);
3953 if (xcodeptr != NULL) {
3954 M_BR(xcodeptr - mcodeptr);
3958 xcodeptr = mcodeptr;
3960 M_MOV(REG_PV, rd->argintregs[0]);
3961 M_MOV(REG_SP, rd->argintregs[1]);
3962 M_ALD(rd->argintregs[2],
3963 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
3964 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3966 M_ASUB_IMM(REG_SP, 1 * 8, REG_SP);
3967 M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
3969 a = dseg_addaddress(cd, stacktrace_inline_fillInStackTrace);
3970 M_ALD(REG_ITMP3, REG_PV, a);
3971 M_JSR(REG_RA, REG_ITMP3);
3973 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3975 M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
3976 M_AADD_IMM(REG_SP, 1 * 8, REG_SP);
3978 a = dseg_addaddress(cd, asm_handle_exception);
3979 M_ALD(REG_ITMP3, REG_PV, a);
3985 /* generate patcher stub call code */
3992 for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
3993 /* check code segment size */
3997 /* Get machine code which is patched back in later. The call is */
3998 /* 2 instruction words long. */
4000 xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
4002 /* We need to split this, because an unaligned 8 byte read causes */
4005 mcode = ((u8) xcodeptr[1] << 32) + (u4) xcodeptr[0];
4007 /* patch in the call to call the following code (done at compile */
4010 tmpmcodeptr = mcodeptr; /* save current mcodeptr */
4011 mcodeptr = xcodeptr; /* set mcodeptr to patch position */
4013 M_BRS(tmpmcodeptr - (xcodeptr + 1));
4014 M_MOV(REG_RA, REG_ITMP3); /* branch delay slot */
4016 mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
4018 /* create stack frame */
4020 M_ASUB_IMM(REG_SP, 5 * 8, REG_SP);
4022 /* move return address onto stack */
4024 M_AST(REG_RA, REG_SP, 4 * 8);
4025 M_MOV(REG_ITMP3, REG_RA); /* restore return address */
4027 /* move pointer to java_objectheader onto stack */
4029 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
4030 /* create a virtual java_objectheader */
4032 (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */
4033 a = dseg_addaddress(cd, NULL); /* vftbl */
4036 M_LDA(REG_ITMP3, REG_PV, a);
4038 M_LUI(REG_ITMP3, (a >> 16) & 0x0000ffff);
4039 M_OR_IMM(REG_ITMP3, a & 0x0000ffff, REG_ITMP3);
4040 M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
4042 M_AST(REG_ITMP3, REG_SP, 3 * 8);
4044 M_AST(REG_ZERO, REG_SP, 3 * 8);
4047 /* move machine code onto stack */
4049 a = dseg_adds8(cd, mcode);
4051 M_LLD(REG_ITMP3, REG_PV, a);
4053 M_LUI(REG_ITMP3, (a >> 16) & 0x0000ffff);
4054 M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
4055 M_LLD(REG_ITMP3, REG_ITMP3, a & 0x0000ffff);
4057 M_LST(REG_ITMP3, REG_SP, 2 * 8);
4059 /* move class/method/field reference onto stack */
4061 a = dseg_addaddress(cd, pref->ref);
4063 M_ALD(REG_ITMP3, REG_PV, a);
4065 M_LUI(REG_ITMP3, (a >> 16) & 0x0000ffff);
4066 M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
4067 M_ALD(REG_ITMP3, REG_ITMP3, a & 0x0000ffff);
4069 M_AST(REG_ITMP3, REG_SP, 1 * 8);
4071 /* move patcher function pointer onto stack */
4073 a = dseg_addaddress(cd, pref->patcher);
4075 M_ALD(REG_ITMP3, REG_PV, a);
4077 M_LUI(REG_ITMP3, (a >> 16) & 0x0000ffff);
4078 M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
4079 M_ALD(REG_ITMP3, REG_ITMP3, a & 0x0000ffff);
4081 M_AST(REG_ITMP3, REG_SP, 0 * 8);
4083 a = dseg_addaddress(cd, asm_wrapper_patcher);
4085 M_ALD(REG_ITMP3, REG_PV, a);
4087 M_LUI(REG_ITMP3, (a >> 16) & 0x0000ffff);
4088 M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
4089 M_ALD(REG_ITMP3, REG_ITMP3, a & 0x0000ffff);
4097 codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
4099 docacheflush((void *) m->entrypoint, ((u1 *) mcodeptr - cd->mcodebase));
4103 /* createcompilerstub **********************************************************
4105 Creates a stub routine which calls the compiler.
4107 *******************************************************************************/
4109 #define COMPILERSTUB_DATASIZE 2 * SIZEOF_VOID_P
4110 #define COMPILERSTUB_CODESIZE 4 * 4
4112 #define COMPILERSTUB_SIZE COMPILERSTUB_DATASIZE + COMPILERSTUB_CODESIZE
4115 functionptr createcompilerstub(methodinfo *m)
4117 ptrint *s; /* memory to hold the stub */
4118 s4 *mcodeptr; /* code generation pointer */
4120 s = (ptrint *) CNEW(u1, COMPILERSTUB_SIZE);
4123 s[1] = (ptrint) asm_call_jit_compiler;
4125 mcodeptr = (s4 *) (s + 2);
4127 M_ALD(REG_ITMP1, REG_PV, -2 * SIZEOF_VOID_P); /* method pointer */
4128 M_ALD(REG_PV, REG_PV, -1 * SIZEOF_VOID_P); /* pointer to compiler */
4132 (void) docacheflush((void *) s, (char *) mcodeptr - (char *) s);
4134 #if defined(STATISTICS)
4136 count_cstub_len += COMPILERSTUB_SIZE;
4139 return (functionptr) (((u1 *) s) + COMPILERSTUB_DATASIZE);
4143 /* createnativestub ************************************************************
4145 Creates a stub routine which calls a native method.
4147 *******************************************************************************/
4149 functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
4150 registerdata *rd, methoddesc *nmd)
4152 s4 *mcodeptr; /* code generation pointer */
4153 s4 stackframesize; /* size of stackframe if needed */
4156 s4 i, j; /* count variables */
4160 /* initialize variables */
4163 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
4166 /* calculate stack frame size */
4169 1 + /* return address */
4170 sizeof(stackframeinfo) / SIZEOF_VOID_P +
4171 md->paramcount + /* for saving arguments over calls */
4172 1 + /* for saving return address */
4176 /* create method header */
4178 #if SIZEOF_VOID_P == 4
4179 (void) dseg_addaddress(cd, m); /* MethodPointer */
4181 (void) dseg_addaddress(cd, m); /* MethodPointer */
4182 (void) dseg_adds4(cd, stackframesize * 8); /* FrameSize */
4183 (void) dseg_adds4(cd, 0); /* IsSync */
4184 (void) dseg_adds4(cd, 0); /* IsLeaf */
4185 (void) dseg_adds4(cd, 0); /* IntSave */
4186 (void) dseg_adds4(cd, 0); /* FltSave */
4187 (void) dseg_addlinenumbertablesize(cd);
4188 (void) dseg_adds4(cd, 0); /* ExTableSize */
4191 /* initialize mcode variables */
4193 mcodeptr = (s4 *) cd->mcodebase;
4194 cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
4197 /* generate stub code */
4199 M_LDA(REG_SP, REG_SP, -stackframesize * 8); /* build up stackframe */
4200 M_AST(REG_RA, REG_SP, stackframesize * 8 - SIZEOF_VOID_P); /* store ra */
4202 /* if function is static, check for initialized */
4204 if ((m->flags & ACC_STATIC) && !m->class->initialized) {
4205 codegen_addpatchref(cd, mcodeptr, PATCHER_clinit, m->class);
4207 if (opt_showdisassemble) {
4212 /* call trace function */
4215 M_LDA(REG_SP, REG_SP, -(1 + INT_ARG_CNT + FLT_ARG_CNT) * 8);
4217 /* save integer argument registers */
4219 for (i = 0; i < md->paramcount && i < INT_ARG_CNT; i++)
4220 if (IS_INT_LNG_TYPE(md->paramtypes[i].type))
4221 M_LST(rd->argintregs[i], REG_SP, (1 + i) * 8);
4223 /* save and copy float arguments into integer registers */
4225 for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
4226 t = md->paramtypes[i].type;
4228 if (IS_FLT_DBL_TYPE(t)) {
4229 if (IS_2_WORD_TYPE(t)) {
4230 M_DST(rd->argfltregs[i], REG_SP, (1 + INT_ARG_CNT + i) * 8);
4231 M_LLD(rd->argintregs[i], REG_SP, (1 + INT_ARG_CNT + i) * 8);
4233 M_FST(rd->argfltregs[i], REG_SP, (1 + INT_ARG_CNT + i) * 8);
4234 M_ILD(rd->argintregs[i], REG_SP, (1 + INT_ARG_CNT + i) * 8);
4239 disp = dseg_addaddress(cd, m);
4240 M_ALD(REG_ITMP1, REG_PV, disp);
4241 M_AST(REG_ITMP1, REG_SP, 0 * 8);
4242 disp = dseg_addaddress(cd, builtin_trace_args);
4243 M_ALD(REG_ITMP3, REG_PV, disp);
4244 M_JSR(REG_RA, REG_ITMP3);
4247 for (i = 0; i < md->paramcount && i < INT_ARG_CNT; i++)
4248 if (IS_INT_LNG_TYPE(md->paramtypes[i].type))
4249 M_LLD(rd->argintregs[i], REG_SP, (1 + i) * 8);
4251 for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
4252 t = md->paramtypes[i].type;
4254 if (IS_FLT_DBL_TYPE(t)) {
4255 if (IS_2_WORD_TYPE(t)) {
4256 M_DLD(rd->argfltregs[i], REG_SP, (1 + INT_ARG_CNT + i) * 8);
4258 M_FLD(rd->argfltregs[i], REG_SP, (1 + INT_ARG_CNT + i) * 8);
4263 M_LDA(REG_SP, REG_SP, (1 + INT_ARG_CNT + FLT_ARG_CNT) * 8);
4267 /* save integer and float argument registers */
4269 for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++)
4270 if (IS_INT_LNG_TYPE(md->paramtypes[i].type))
4271 M_LST(rd->argintregs[i], REG_SP, j++ * 8);
4273 for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++)
4274 if (IS_FLT_DBL_TYPE(md->paramtypes[i].type))
4275 M_DST(rd->argfltregs[i], REG_SP, j++ * 8);
4277 /* create native stackframe info */
4280 stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo),
4282 M_MOV(REG_PV, rd->argintregs[1]);
4283 M_AADD_IMM(REG_SP, stackframesize * 8, rd->argintregs[2]);
4284 M_ALD(rd->argintregs[3], REG_SP, stackframesize * 8 - SIZEOF_VOID_P);
4285 disp = dseg_addaddress(cd, stacktrace_create_native_stackframeinfo);
4286 M_ALD(REG_ITMP3, REG_PV, disp);
4287 M_JSR(REG_RA, REG_ITMP3);
4288 M_NOP; /* XXX fill me! */
4290 /* restore integer and float argument registers */
4292 for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++)
4293 if (IS_INT_LNG_TYPE(md->paramtypes[i].type))
4294 M_LLD(rd->argintregs[i], REG_SP, j++ * 8);
4296 for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++)
4297 if (IS_FLT_DBL_TYPE(md->paramtypes[i].type))
4298 M_DLD(rd->argfltregs[i], REG_SP, j++ * 8);
4301 /* copy or spill arguments to new locations */
4303 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
4304 t = md->paramtypes[i].type;
4306 if (IS_INT_LNG_TYPE(t)) {
4307 if (!md->params[i].inmemory) {
4308 s1 = rd->argintregs[md->params[i].regoff];
4310 if (!nmd->params[j].inmemory) {
4311 s2 = rd->argintregs[nmd->params[j].regoff];
4314 s2 = nmd->params[j].regoff;
4315 M_AST(s1, REG_SP, s2 * 8);
4319 s1 = md->params[i].regoff + stackframesize;
4320 s2 = nmd->params[j].regoff;
4321 M_ALD(REG_ITMP1, REG_SP, s1 * 8);
4322 M_AST(REG_ITMP1, REG_SP, s2 * 8);
4326 if (!md->params[i].inmemory) {
4327 s1 = rd->argfltregs[md->params[i].regoff];
4329 if (!nmd->params[j].inmemory) {
4330 s2 = rd->argfltregs[nmd->params[j].regoff];
4331 M_TFLTMOVE(t, s1, s2);
4333 s2 = nmd->params[j].regoff;
4334 if (IS_2_WORD_TYPE(t))
4335 M_DST(s1, REG_SP, s2 * 8);
4337 M_FST(s1, REG_SP, s2 * 8);
4341 s1 = md->params[i].regoff + stackframesize;
4342 s2 = nmd->params[j].regoff;
4343 M_DLD(REG_FTMP1, REG_SP, s1 * 8);
4344 if (IS_2_WORD_TYPE(t))
4345 M_DST(REG_FTMP1, REG_SP, s2 * 8);
4347 M_FST(REG_FTMP1, REG_SP, s2 * 8);
4352 /* put class into second argument register */
4354 if (m->flags & ACC_STATIC) {
4355 disp = dseg_addaddress(cd, m->class);
4356 M_ALD(rd->argintregs[1], REG_PV, disp);
4359 /* put env into first argument register */
4361 disp = dseg_addaddress(cd, &env);
4362 M_ALD(rd->argintregs[0], REG_PV, disp);
4364 /* do the native function call */
4366 #if !defined(ENABLE_STATICVM)
4368 codegen_addpatchref(cd, mcodeptr, PATCHER_resolve_native, m);
4370 if (opt_showdisassemble) {
4376 disp = dseg_addaddress(cd, f);
4377 M_ALD(REG_ITMP3, REG_PV, disp); /* load adress of native method */
4378 M_JSR(REG_RA, REG_ITMP3); /* call native method */
4379 M_NOP; /* delay slot */
4382 /* remove native stackframe info */
4384 if (IS_INT_LNG_TYPE(md->returntype.type))
4385 M_LST(REG_RESULT, REG_SP, 0 * 8);
4387 M_DST(REG_FRESULT, REG_SP, 0 * 8);
4390 stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo),
4392 disp = dseg_addaddress(cd, stacktrace_remove_stackframeinfo);
4393 M_ALD(REG_ITMP3, REG_PV, disp);
4394 M_JSR(REG_RA, REG_ITMP3);
4395 M_NOP; /* XXX fill me! */
4397 if (IS_INT_LNG_TYPE(md->returntype.type))
4398 M_LLD(REG_RESULT, REG_SP, 0 * 8);
4400 M_DLD(REG_FRESULT, REG_SP, 0 * 8);
4403 /* call finished trace function */
4406 M_LDA(REG_SP, REG_SP, -(2 * 8));
4408 M_AST(REG_RESULT, REG_SP, 0 * 8);
4409 M_DST(REG_FRESULT, REG_SP, 1 * 8);
4411 disp = dseg_addaddress(cd, m);
4412 M_ALD(rd->argintregs[0], REG_PV, disp);
4414 M_MOV(REG_RESULT, rd->argintregs[1]);
4415 M_DMFC1(REG_ITMP1, REG_FRESULT);
4416 M_DMTC1(REG_ITMP1, rd->argfltregs[2]);
4417 M_DMTC1(REG_ITMP1, rd->argfltregs[3]);
4419 disp = dseg_addaddress(cd, builtin_displaymethodstop);
4420 M_ALD(REG_ITMP3, REG_PV, disp);
4421 M_JSR(REG_RA, REG_ITMP3);
4424 M_ALD(REG_RESULT, REG_SP, 0 * 8);
4425 M_DLD(REG_FRESULT, REG_SP, 1 * 8);
4427 M_LDA(REG_SP, REG_SP, 2 * 8);
4430 /* check for exception */
4432 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
4433 disp = dseg_addaddress(cd, builtin_get_exceptionptrptr);
4434 M_ALD(REG_ITMP3, REG_PV, disp);
4435 M_JSR(REG_RA, REG_ITMP3);
4438 if (IS_INT_LNG_TYPE(md->returntype.type))
4439 M_AST(REG_RESULT, REG_SP, 0 * 8);
4441 M_DST(REG_FRESULT, REG_SP, 0 * 8);
4443 M_MOV(REG_RESULT, REG_ITMP3);
4445 if (IS_INT_LNG_TYPE(md->returntype.type))
4446 M_ALD(REG_RESULT, REG_SP, 0 * 8);
4448 M_DLD(REG_FRESULT, REG_SP, 0 * 8);
4450 disp = dseg_addaddress(cd, &_exceptionptr);
4451 M_ALD(REG_ITMP3, REG_PV, disp); /* get address of exceptionptr */
4454 M_ALD(REG_RA, REG_SP, stackframesize * 8 - SIZEOF_VOID_P); /* load ra */
4455 M_ALD(REG_ITMP1, REG_ITMP3, 0); /* load exception into reg. itmp1 */
4457 M_BNEZ(REG_ITMP1, 2); /* if no exception then return */
4458 M_LDA(REG_SP, REG_SP, stackframesize * 8);/* remove stackframe, delay slot*/
4460 M_RET(REG_RA); /* return to caller */
4461 M_NOP; /* delay slot */
4463 /* handle exception */
4465 M_AST(REG_ZERO, REG_ITMP3, 0); /* store NULL into exceptionptr */
4467 disp = dseg_addaddress(cd, asm_handle_nat_exception);
4468 M_ALD(REG_ITMP3, REG_PV, disp); /* load asm exception handler address */
4469 M_JMP(REG_ITMP3); /* jump to asm exception handler */
4470 M_LDA(REG_ITMP2, REG_RA, -4); /* move fault address into reg. itmp2 */
4473 /* generate static stub call code */
4481 for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
4482 /* Get machine code which is patched back in later. The call is */
4483 /* 2 instruction words long. */
4485 xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
4487 /* We need to split this, because an unaligned 8 byte read causes */
4490 mcode = ((u8) xcodeptr[1] << 32) + (u4) xcodeptr[0];
4492 /* patch in the call to call the following code (done at compile */
4495 tmpmcodeptr = mcodeptr; /* save current mcodeptr */
4496 mcodeptr = xcodeptr; /* set mcodeptr to patch position */
4498 M_BRS(tmpmcodeptr - (xcodeptr + 1));
4499 M_NOP; /* branch delay slot */
4501 mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
4503 /* create stack frame */
4505 M_LSUB_IMM(REG_SP, 5 * 8, REG_SP);
4507 /* move return address onto stack */
4509 M_AST(REG_RA, REG_SP, 4 * 8);
4511 /* move pointer to java_objectheader onto stack */
4513 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
4514 /* order reversed because of data segment layout */
4516 (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */
4517 disp = dseg_addaddress(cd, NULL); /* vftbl */
4519 M_LDA(REG_ITMP3, REG_PV, disp);
4520 M_AST(REG_ITMP3, REG_SP, 3 * 8);
4522 M_AST(REG_ZERO, REG_SP, 3 * 8);
4525 /* move machine code onto stack */
4527 disp = dseg_adds8(cd, mcode);
4528 M_LLD(REG_ITMP3, REG_PV, disp);
4529 M_LST(REG_ITMP3, REG_SP, 2 * 8);
4531 /* move class/method/field reference onto stack */
4533 disp = dseg_addaddress(cd, pref->ref);
4534 M_ALD(REG_ITMP3, REG_PV, disp);
4535 M_AST(REG_ITMP3, REG_SP, 1 * 8);
4537 /* move patcher function pointer onto stack */
4539 disp = dseg_addaddress(cd, pref->patcher);
4540 M_ALD(REG_ITMP3, REG_PV, disp);
4541 M_AST(REG_ITMP3, REG_SP, 0 * 8);
4543 disp = dseg_addaddress(cd, asm_wrapper_patcher);
4544 M_ALD(REG_ITMP3, REG_PV, disp);
4550 codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
4552 docacheflush((void *) m->entrypoint, ((u1 *) mcodeptr - cd->mcodebase));
4554 return m->entrypoint;
4559 * These are local overrides for various environment variables in Emacs.
4560 * Please do not remove this and leave it at the end of the file, where
4561 * Emacs will automagically detect them.
4562 * ---------------------------------------------------------------------
4565 * indent-tabs-mode: t