1 /* src/vm/jit/powerpc/codegen.c - machine code generator for 32-bit PowerPC
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Andreas Krall
30 Changes: Christian Thalinger
33 $Id: codegen.c 4530 2006-02-21 09:11:53Z twisti $
48 #include "vm/jit/powerpc/arch.h"
49 #include "vm/jit/powerpc/codegen.h"
51 #include "native/native.h"
52 #include "vm/builtin.h"
53 #include "vm/exceptions.h"
54 #include "vm/global.h"
55 #include "vm/loader.h"
56 #include "vm/options.h"
57 #include "vm/stringlocal.h"
59 #include "vm/jit/asmpart.h"
60 #include "vm/jit/codegen-common.h"
61 #include "vm/jit/dseg.h"
62 #include "vm/jit/jit.h"
63 #include "vm/jit/parse.h"
64 #include "vm/jit/patcher.h"
65 #include "vm/jit/reg.h"
67 #if defined(ENABLE_LSRA)
68 # include "vm/jit/allocator/lsra.h"
74 s4 *codegen_trace_args( methodinfo *m, codegendata *cd, registerdata *rd,
75 s4 *mcodeptr, s4 parentargs_base, bool nativestub);
77 /* codegen *********************************************************************
79 Generates machine code.
81 *******************************************************************************/
83 bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
85 s4 len, s1, s2, s3, d, disp;
95 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
96 builtintable_entry *bte;
99 /* prevent compiler warnings */
111 /* space to save used callee saved registers */
113 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
114 savedregs_num += 2 * (FLT_SAV_CNT - rd->savfltreguse);
116 parentargs_base = rd->memuse + savedregs_num;
118 #if defined(USE_THREADS)
119 /* space to save argument of monitor_enter and Return Values to survive */
120 /* monitor_exit. The stack position for the argument can not be shared */
121 /* with place to save the return register on PPC, since both values */
123 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
124 /* reserve 2 slots for long/double return values for monitorexit */
126 if (IS_2_WORD_TYPE(m->parseddesc->returntype.type))
127 parentargs_base += 3;
129 parentargs_base += 2;
134 /* create method header */
136 parentargs_base = (parentargs_base + 3) & ~3;
138 (void) dseg_addaddress(cd, m); /* MethodPointer */
139 (void) dseg_adds4(cd, parentargs_base * 4); /* FrameSize */
141 #if defined(USE_THREADS)
142 /* IsSync contains the offset relative to the stack pointer for the
143 argument of monitor_exit used in the exception handler. Since the
144 offset could be zero and give a wrong meaning of the flag it is
148 if (checksync && (m->flags & ACC_SYNCHRONIZED))
149 (void) dseg_adds4(cd, (rd->memuse + 1) * 4); /* IsSync */
152 (void) dseg_adds4(cd, 0); /* IsSync */
154 (void) dseg_adds4(cd, m->isleafmethod); /* IsLeaf */
155 (void) dseg_adds4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
156 (void) dseg_adds4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
158 dseg_addlinenumbertablesize(cd);
160 (void) dseg_adds4(cd, cd->exceptiontablelength); /* ExTableSize */
162 /* create exception table */
164 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
165 dseg_addtarget(cd, ex->start);
166 dseg_addtarget(cd, ex->end);
167 dseg_addtarget(cd, ex->handler);
168 (void) dseg_addaddress(cd, ex->catchtype.cls);
171 /* initialize mcode variables */
173 mcodeptr = (s4 *) cd->mcodeptr;
175 /* create stack frame (if necessary) */
177 if (!m->isleafmethod) {
179 M_AST(REG_ZERO, REG_SP, LA_LR_OFFSET);
183 M_STWU(REG_SP, REG_SP, -parentargs_base * 4);
185 /* save return address and used callee saved registers */
188 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
189 p--; M_IST(rd->savintregs[i], REG_SP, p * 4);
191 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
192 p -= 2; M_DST(rd->savfltregs[i], REG_SP, p * 4);
195 /* take arguments out of register or stack frame */
199 for (p = 0, l = 0; p < md->paramcount; p++) {
200 t = md->paramtypes[p].type;
201 var = &(rd->locals[l][t]);
203 if (IS_2_WORD_TYPE(t)) /* increment local counter for 2 word types */
207 s1 = md->params[p].regoff;
208 if (IS_INT_LNG_TYPE(t)) { /* integer args */
209 if (IS_2_WORD_TYPE(t))
210 s2 = PACK_REGS(rd->argintregs[GET_LOW_REG(s1)],
211 rd->argintregs[GET_HIGH_REG(s1)]);
213 s2 = rd->argintregs[s1];
214 if (!md->params[p].inmemory) { /* register arguments */
215 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
216 M_TINTMOVE(t, s2, var->regoff);
218 } else { /* reg arg -> spilled */
219 if (IS_2_WORD_TYPE(t)) {
220 M_IST(GET_HIGH_REG(s2), REG_SP, var->regoff * 4);
221 M_IST(GET_LOW_REG(s2), REG_SP, var->regoff * 4 + 4);
223 M_IST(s2, REG_SP, var->regoff * 4);
227 } else { /* stack arguments */
228 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
229 if (IS_2_WORD_TYPE(t)) {
230 M_ILD(GET_HIGH_REG(var->regoff), REG_SP,
231 (parentargs_base + s1) * 4);
232 M_ILD(GET_LOW_REG(var->regoff), REG_SP,
233 (parentargs_base + s1) * 4 + 4);
235 M_ILD(var->regoff, REG_SP, (parentargs_base + s1) * 4);
238 } else { /* stack arg -> spilled */
240 M_ILD(REG_ITMP1, REG_SP, (parentargs_base + s1) * 4);
241 M_IST(REG_ITMP1, REG_SP, var->regoff * 4);
242 if (IS_2_WORD_TYPE(t)) {
243 M_ILD(REG_ITMP1, REG_SP, (parentargs_base + s1) * 4 +4);
244 M_IST(REG_ITMP1, REG_SP, var->regoff * 4 + 4);
247 /* Reuse Memory Position on Caller Stack */
248 var->regoff = parentargs_base + s1;
253 } else { /* floating args */
254 if (!md->params[p].inmemory) { /* register arguments */
255 s2 = rd->argfltregs[s1];
256 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
257 M_FLTMOVE(s2, var->regoff);
259 } else { /* reg arg -> spilled */
260 if (IS_2_WORD_TYPE(t))
261 M_DST(s2, REG_SP, var->regoff * 4);
263 M_FST(s2, REG_SP, var->regoff * 4);
266 } else { /* stack arguments */
267 if (!(var->flags & INMEMORY)) { /* stack-arg -> register */
268 if (IS_2_WORD_TYPE(t))
269 M_DLD(var->regoff, REG_SP, (parentargs_base + s1) * 4);
272 M_FLD(var->regoff, REG_SP, (parentargs_base + s1) * 4);
274 } else { /* stack-arg -> spilled */
276 if (IS_2_WORD_TYPE(t)) {
277 M_DLD(REG_FTMP1, REG_SP, (parentargs_base + s1) * 4);
278 M_DST(REG_FTMP1, REG_SP, var->regoff * 4);
279 var->regoff = parentargs_base + s1;
282 M_FLD(REG_FTMP1, REG_SP, (parentargs_base + s1) * 4);
283 M_FST(REG_FTMP1, REG_SP, var->regoff * 4);
286 /* Reuse Memory Position on Caller Stack */
287 var->regoff = parentargs_base + s1;
294 /* save monitorenter argument */
296 #if defined(USE_THREADS)
297 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
298 /* stack offset for monitor argument */
304 M_LDA(REG_SP, REG_SP, -(INT_ARG_CNT * 4 + FLT_ARG_CNT * 8));
306 for (p = 0; p < INT_ARG_CNT; p++)
307 M_IST(rd->argintregs[p], REG_SP, p * 4);
309 for (p = 0; p < FLT_ARG_CNT * 2; p += 2)
310 M_DST(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 4);
312 s1 += INT_ARG_CNT + FLT_ARG_CNT;
316 /* decide which monitor enter function to call */
318 if (m->flags & ACC_STATIC) {
319 p = dseg_addaddress(cd, m->class);
320 M_ALD(rd->argintregs[0], REG_PV, p);
321 M_AST(rd->argintregs[0], REG_SP, s1 * 4);
322 p = dseg_addaddress(cd, BUILTIN_staticmonitorenter);
323 M_ALD(REG_ITMP3, REG_PV, p);
328 M_TST(rd->argintregs[0]);
330 codegen_addxnullrefs(cd, mcodeptr);
331 M_AST(rd->argintregs[0], REG_SP, s1 * 4);
332 p = dseg_addaddress(cd, BUILTIN_monitorenter);
333 M_ALD(REG_ITMP3, REG_PV, p);
340 for (p = 0; p < INT_ARG_CNT; p++)
341 M_ILD(rd->argintregs[p], REG_SP, p * 4);
343 for (p = 0; p < FLT_ARG_CNT; p++)
344 M_DLD(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 4);
347 M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT) * 8);
353 /* call trace function */
356 mcodeptr = codegen_trace_args(m, cd, rd, mcodeptr, parentargs_base, false);
358 } /* if (runverbose) */
361 /* end of header generation */
363 /* walk through all basic blocks */
364 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
366 bptr->mpc = (s4) ((u1 *) mcodeptr - cd->mcodebase);
368 if (bptr->flags >= BBREACHED) {
370 /* branch resolving */
374 for (brefs = bptr->branchrefs; brefs != NULL; brefs = brefs->next) {
375 gen_resolvebranch((u1*) cd->mcodebase + brefs->branchpos,
381 /* copy interface registers to their destination */
387 #if defined(ENABLE_LSRA)
389 while (src != NULL) {
391 if ((len == 0) && (bptr->type != BBTYPE_STD)) {
392 /* d = reg_of_var(m, src, REG_ITMP1); */
393 if (!(src->flags & INMEMORY))
397 M_INTMOVE(REG_ITMP1, d);
398 store_reg_to_var_int(src, d);
404 while (src != NULL) {
406 if ((len == 0) && (bptr->type != BBTYPE_STD)) {
407 d = reg_of_var(rd, src, REG_ITMP1);
408 M_INTMOVE(REG_ITMP1, d);
409 store_reg_to_var_int(src, d);
411 if (src->type == TYPE_LNG)
412 d = reg_of_var(rd, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
414 d = reg_of_var(rd, src, REG_IFTMP);
415 if ((src->varkind != STACKVAR)) {
417 if (IS_FLT_DBL_TYPE(s2)) {
418 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
419 s1 = rd->interfaces[len][s2].regoff;
422 if (IS_2_WORD_TYPE(s2)) {
424 rd->interfaces[len][s2].regoff * 4);
427 rd->interfaces[len][s2].regoff * 4);
431 if (IS_2_WORD_TYPE(s2)) {
432 store_reg_to_var_dbl(src, d);
434 store_reg_to_var_flt(src, d);
437 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
438 s1 = rd->interfaces[len][s2].regoff;
439 M_TINTMOVE(s2, s1, d);
441 if (IS_2_WORD_TYPE(s2)) {
442 M_ILD(GET_HIGH_REG(d), REG_SP,
443 rd->interfaces[len][s2].regoff * 4);
444 M_ILD(GET_LOW_REG(d), REG_SP,
445 rd->interfaces[len][s2].regoff * 4 + 4);
448 rd->interfaces[len][s2].regoff * 4);
452 if (IS_2_WORD_TYPE(s2)) {
453 store_reg_to_var_lng(src, d);
455 store_reg_to_var_int(src, d);
463 #if defined(ENABLE_LSRA)
466 /* walk through all instructions */
472 for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) {
473 if (iptr->line != currentline) {
474 dseg_addlinenumber(cd, iptr->line, (u1 *) mcodeptr);
475 currentline = iptr->line;
478 MCODECHECK(64); /* an instruction usually needs < 64 words */
481 case ICMD_NOP: /* ... ==> ... */
482 case ICMD_INLINE_START:
483 case ICMD_INLINE_END:
486 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
488 var_to_reg_int(s1, src, REG_ITMP1);
491 codegen_addxnullrefs(cd, mcodeptr);
494 /* constant operations ************************************************/
496 case ICMD_ICONST: /* ... ==> ..., constant */
497 /* op1 = 0, val.i = constant */
499 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
500 ICONST(d, iptr->val.i);
501 store_reg_to_var_int(iptr->dst, d);
504 case ICMD_LCONST: /* ... ==> ..., constant */
505 /* op1 = 0, val.l = constant */
507 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
508 LCONST(d, iptr->val.l);
509 store_reg_to_var_lng(iptr->dst, d);
512 case ICMD_FCONST: /* ... ==> ..., constant */
513 /* op1 = 0, val.f = constant */
515 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
516 a = dseg_addfloat(cd, iptr->val.f);
518 store_reg_to_var_flt(iptr->dst, d);
521 case ICMD_DCONST: /* ... ==> ..., constant */
522 /* op1 = 0, val.d = constant */
524 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
525 a = dseg_adddouble(cd, iptr->val.d);
527 store_reg_to_var_dbl(iptr->dst, d);
530 case ICMD_ACONST: /* ... ==> ..., constant */
531 /* op1 = 0, val.a = constant */
533 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
534 disp = dseg_addaddress(cd, iptr->val.a);
536 if ((iptr->target != NULL) && (iptr->val.a == NULL)) {
537 codegen_addpatchref(cd, mcodeptr,
539 (unresolved_class *) iptr->target, disp);
541 if (opt_showdisassemble)
545 M_ALD(d, REG_PV, disp);
546 store_reg_to_var_adr(iptr->dst, d);
550 /* load/store operations **********************************************/
552 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
553 case ICMD_ALOAD: /* op1 = local variable */
555 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
556 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
557 if ((iptr->dst->varkind == LOCALVAR) &&
558 (iptr->dst->varnum == iptr->op1))
560 if (var->flags & INMEMORY) {
561 M_ILD(d, REG_SP, var->regoff * 4);
563 M_TINTMOVE(var->type, var->regoff, d);
565 store_reg_to_var_int(iptr->dst, d);
568 case ICMD_LLOAD: /* ... ==> ..., content of local variable */
569 /* op1 = local variable */
571 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
572 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
573 if ((iptr->dst->varkind == LOCALVAR) &&
574 (iptr->dst->varnum == iptr->op1))
576 if (var->flags & INMEMORY) {
577 M_ILD(GET_HIGH_REG(d), REG_SP, var->regoff * 4);
578 M_ILD(GET_LOW_REG(d), REG_SP, var->regoff * 4 + 4);
580 M_TINTMOVE(var->type, var->regoff, d);
582 store_reg_to_var_lng(iptr->dst, d);
585 case ICMD_FLOAD: /* ... ==> ..., content of local variable */
586 /* op1 = local variable */
588 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
589 if ((iptr->dst->varkind == LOCALVAR) &&
590 (iptr->dst->varnum == iptr->op1))
592 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
593 if (var->flags & INMEMORY) {
594 M_FLD(d, REG_SP, var->regoff * 4);
596 M_FLTMOVE(var->regoff, d);
598 store_reg_to_var_flt(iptr->dst, d);
601 case ICMD_DLOAD: /* ... ==> ..., content of local variable */
602 /* op1 = local variable */
604 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
605 if ((iptr->dst->varkind == LOCALVAR) &&
606 (iptr->dst->varnum == iptr->op1))
608 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
609 if (var->flags & INMEMORY) {
610 M_DLD(d, REG_SP, var->regoff * 4);
612 M_FLTMOVE(var->regoff, d);
614 store_reg_to_var_dbl(iptr->dst, d);
618 case ICMD_ISTORE: /* ..., value ==> ... */
619 case ICMD_ASTORE: /* op1 = local variable */
621 if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1))
623 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
624 if (var->flags & INMEMORY) {
625 var_to_reg_int(s1, src, REG_ITMP1);
626 M_IST(s1, REG_SP, var->regoff * 4);
628 var_to_reg_int(s1, src, var->regoff);
629 M_TINTMOVE(var->type, s1, var->regoff);
633 case ICMD_LSTORE: /* ..., value ==> ... */
634 /* op1 = local variable */
636 if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1))
638 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
639 if (var->flags & INMEMORY) {
640 var_to_reg_int(s1, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
641 M_IST(GET_HIGH_REG(s1), REG_SP, var->regoff * 4);
642 M_IST(GET_LOW_REG(s1), REG_SP, var->regoff * 4 + 4);
644 var_to_reg_int(s1, src, var->regoff);
645 M_TINTMOVE(var->type, s1, var->regoff);
649 case ICMD_FSTORE: /* ..., value ==> ... */
650 case ICMD_DSTORE: /* op1 = local variable */
652 if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1))
654 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
655 if (var->flags & INMEMORY) {
656 var_to_reg_flt(s1, src, REG_FTMP1);
657 if (var->type == TYPE_DBL)
658 M_DST(s1, REG_SP, var->regoff * 4);
660 M_FST(s1, REG_SP, var->regoff * 4);
662 var_to_reg_flt(s1, src, var->regoff);
663 M_FLTMOVE(s1, var->regoff);
668 /* pop/dup/swap operations ********************************************/
670 /* attention: double and longs are only one entry in CACAO ICMDs */
672 case ICMD_POP: /* ..., value ==> ... */
673 case ICMD_POP2: /* ..., value, value ==> ... */
676 case ICMD_DUP: /* ..., a ==> ..., a, a */
677 M_COPY(src, iptr->dst);
680 case ICMD_DUP_X1: /* ..., a, b ==> ..., b, a, b */
682 M_COPY(src, iptr->dst);
683 M_COPY(src->prev, iptr->dst->prev);
684 M_COPY(iptr->dst, iptr->dst->prev->prev);
687 case ICMD_DUP_X2: /* ..., a, b, c ==> ..., c, a, b, c */
689 M_COPY(src, iptr->dst);
690 M_COPY(src->prev, iptr->dst->prev);
691 M_COPY(src->prev->prev, iptr->dst->prev->prev);
692 M_COPY(iptr->dst, iptr->dst->prev->prev->prev);
695 case ICMD_DUP2: /* ..., a, b ==> ..., a, b, a, b */
697 M_COPY(src, iptr->dst);
698 M_COPY(src->prev, iptr->dst->prev);
701 case ICMD_DUP2_X1: /* ..., a, b, c ==> ..., b, c, a, b, c */
703 M_COPY(src, iptr->dst);
704 M_COPY(src->prev, iptr->dst->prev);
705 M_COPY(src->prev->prev, iptr->dst->prev->prev);
706 M_COPY(iptr->dst, iptr->dst->prev->prev->prev);
707 M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev);
710 case ICMD_DUP2_X2: /* ..., a, b, c, d ==> ..., c, d, a, b, c, d */
712 M_COPY(src, iptr->dst);
713 M_COPY(src->prev, iptr->dst->prev);
714 M_COPY(src->prev->prev, iptr->dst->prev->prev);
715 M_COPY(src->prev->prev->prev, iptr->dst->prev->prev->prev);
716 M_COPY(iptr->dst, iptr->dst->prev->prev->prev->prev);
717 M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev->prev);
720 case ICMD_SWAP: /* ..., a, b ==> ..., b, a */
722 M_COPY(src, iptr->dst->prev);
723 M_COPY(src->prev, iptr->dst);
727 /* integer operations *************************************************/
729 case ICMD_INEG: /* ..., value ==> ..., - value */
731 var_to_reg_int(s1, src, REG_ITMP1);
732 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
734 store_reg_to_var_int(iptr->dst, d);
737 case ICMD_LNEG: /* ..., value ==> ..., - value */
739 var_to_reg_int(s1, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
740 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
741 M_SUBFIC(GET_LOW_REG(s1), 0, GET_LOW_REG(d));
742 M_SUBFZE(GET_HIGH_REG(s1), GET_HIGH_REG(d));
743 store_reg_to_var_lng(iptr->dst, d);
746 case ICMD_I2L: /* ..., value ==> ..., value */
748 var_to_reg_int(s1, src, REG_ITMP2);
749 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
750 M_INTMOVE(s1, GET_LOW_REG(d));
751 M_SRA_IMM(GET_LOW_REG(d), 31, GET_HIGH_REG(d));
752 store_reg_to_var_lng(iptr->dst, d);
755 case ICMD_L2I: /* ..., value ==> ..., value */
757 var_to_reg_lng_low(s1, src, REG_ITMP2);
758 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
760 store_reg_to_var_int(iptr->dst, d);
763 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
765 var_to_reg_int(s1, src, REG_ITMP1);
766 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
768 store_reg_to_var_int(iptr->dst, d);
771 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
773 var_to_reg_int(s1, src, REG_ITMP1);
774 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
776 store_reg_to_var_int(iptr->dst, d);
779 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
781 var_to_reg_int(s1, src, REG_ITMP1);
782 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
784 store_reg_to_var_int(iptr->dst, d);
788 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
790 var_to_reg_int(s1, src->prev, REG_ITMP1);
791 var_to_reg_int(s2, src, REG_ITMP2);
792 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
794 store_reg_to_var_int(iptr->dst, d);
797 case ICMD_IADDCONST: /* ..., value ==> ..., value + constant */
798 /* val.i = constant */
800 var_to_reg_int(s1, src, REG_ITMP1);
801 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
802 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
803 M_IADD_IMM(s1, iptr->val.i, d);
805 ICONST(REG_ITMP2, iptr->val.i);
806 M_IADD(s1, REG_ITMP2, d);
808 store_reg_to_var_int(iptr->dst, d);
811 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
813 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
814 var_to_reg_lng_low(s2, src, REG_ITMP2);
815 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
816 M_ADDC(s1, s2, GET_LOW_REG(d));
817 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
818 var_to_reg_lng_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
819 M_ADDE(s1, s2, GET_HIGH_REG(d));
820 store_reg_to_var_lng(iptr->dst, d);
823 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
824 /* val.l = constant */
826 s3 = iptr->val.l & 0xffffffff;
827 var_to_reg_lng_low(s1, src, REG_ITMP1);
828 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
829 if ((s3 >= -32768) && (s3 <= 32767)) {
830 M_ADDIC(s1, s3, GET_LOW_REG(d));
832 ICONST(REG_ITMP2, s3);
833 M_ADDC(s1, REG_ITMP2, GET_LOW_REG(d));
835 var_to_reg_lng_high(s1, src, REG_ITMP1);
836 s3 = iptr->val.l >> 32;
838 M_ADDME(s1, GET_HIGH_REG(d));
839 } else if (s3 == 0) {
840 M_ADDZE(s1, GET_HIGH_REG(d));
842 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
843 M_ADDE(s1, REG_ITMP3, GET_HIGH_REG(d));
845 store_reg_to_var_lng(iptr->dst, d);
848 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
850 var_to_reg_int(s1, src->prev, REG_ITMP1);
851 var_to_reg_int(s2, src, REG_ITMP2);
852 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
854 store_reg_to_var_int(iptr->dst, d);
857 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
858 /* val.i = constant */
860 var_to_reg_int(s1, src, REG_ITMP1);
861 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
862 if ((iptr->val.i >= -32767) && (iptr->val.i <= 32768)) {
863 M_IADD_IMM(s1, -iptr->val.i, d);
865 ICONST(REG_ITMP2, -iptr->val.i);
866 M_IADD(s1, REG_ITMP2, d);
868 store_reg_to_var_int(iptr->dst, d);
871 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
873 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
874 var_to_reg_lng_low(s2, src, REG_ITMP2);
875 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
876 M_SUBC(s1, s2, GET_LOW_REG(d));
877 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
878 var_to_reg_lng_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
879 M_SUBE(s1, s2, GET_HIGH_REG(d));
880 store_reg_to_var_lng(iptr->dst, d);
883 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
884 /* val.l = constant */
886 s3 = (-iptr->val.l) & 0xffffffff;
887 var_to_reg_lng_low(s1, src, REG_ITMP1);
888 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
889 if ((s3 >= -32768) && (s3 <= 32767)) {
890 M_ADDIC(s1, s3, GET_LOW_REG(d));
892 ICONST(REG_ITMP2, s3);
893 M_ADDC(s1, REG_ITMP2, GET_LOW_REG(d));
895 var_to_reg_lng_high(s1, src, REG_ITMP1);
896 s3 = (-iptr->val.l) >> 32;
898 M_ADDME(s1, GET_HIGH_REG(d));
900 M_ADDZE(s1, GET_HIGH_REG(d));
902 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
903 M_ADDE(s1, REG_ITMP3, GET_HIGH_REG(d));
905 store_reg_to_var_lng(iptr->dst, d);
908 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
910 var_to_reg_int(s1, src->prev, REG_ITMP1);
911 var_to_reg_int(s2, src, REG_ITMP2);
912 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
915 codegen_addxdivrefs(cd, mcodeptr);
916 M_LDAH(REG_ITMP3, REG_ZERO, 0x8000);
917 M_CMP(REG_ITMP3, s1);
918 M_BNE(3 + (s1 != d));
920 M_BNE(1 + (s1 != d));
924 store_reg_to_var_int(iptr->dst, d);
927 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
929 var_to_reg_int(s1, src->prev, REG_ITMP1);
930 var_to_reg_int(s2, src, REG_ITMP2);
931 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
934 codegen_addxdivrefs(cd, mcodeptr);
935 M_LDAH(REG_ITMP3, REG_ZERO, 0x8000);
936 M_CMP(REG_ITMP3, s1);
942 M_IDIV(s1, s2, REG_ITMP3);
943 M_IMUL(REG_ITMP3, s2, REG_ITMP3);
944 M_ISUB(s1, REG_ITMP3, d);
945 store_reg_to_var_int(iptr->dst, d);
948 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
949 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
954 var_to_reg_int(s2, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
955 M_OR_TST(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
957 codegen_addxdivrefs(cd, mcodeptr);
959 s3 = PACK_REGS(rd->argintregs[GET_LOW_REG(md->params[1].regoff)],
960 rd->argintregs[GET_HIGH_REG(md->params[1].regoff)]);
961 M_TINTMOVE(TYPE_LNG, s2, s3);
963 var_to_reg_int(s1, src->prev, PACK_REGS(REG_ITMP2, REG_ITMP1));
964 s3 = PACK_REGS(rd->argintregs[GET_LOW_REG(md->params[0].regoff)],
965 rd->argintregs[GET_HIGH_REG(md->params[0].regoff)]);
966 M_TINTMOVE(TYPE_LNG, s1, s3);
968 disp = dseg_addaddress(cd, bte->fp);
969 M_ALD(REG_ITMP1, REG_PV, disp);
973 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_RESULT2, REG_RESULT));
974 M_TINTMOVE(TYPE_LNG, PACK_REGS(REG_RESULT2, REG_RESULT), d);
975 store_reg_to_var_lng(iptr->dst, d);
978 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
980 var_to_reg_int(s1, src->prev, REG_ITMP1);
981 var_to_reg_int(s2, src, REG_ITMP2);
982 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
984 store_reg_to_var_int(iptr->dst, d);
987 case ICMD_IMULCONST: /* ..., value ==> ..., value * constant */
988 /* val.i = constant */
990 var_to_reg_int(s1, src, REG_ITMP1);
991 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
992 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
993 M_IMUL_IMM(s1, iptr->val.i, d);
995 ICONST(REG_ITMP3, iptr->val.i);
996 M_IMUL(s1, REG_ITMP3, d);
998 store_reg_to_var_int(iptr->dst, d);
1001 case ICMD_IDIVPOW2: /* ..., value ==> ..., value << constant */
1003 var_to_reg_int(s1, src, REG_ITMP1);
1004 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1005 M_SRA_IMM(s1, iptr->val.i, d);
1007 store_reg_to_var_int(iptr->dst, d);
1010 case ICMD_ISHL: /* ..., 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_ITMP2);
1015 M_AND_IMM(s2, 0x1f, REG_ITMP3);
1016 M_SLL(s1, REG_ITMP3, d);
1017 store_reg_to_var_int(iptr->dst, d);
1020 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
1021 /* val.i = constant */
1023 var_to_reg_int(s1, src, REG_ITMP1);
1024 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1025 M_SLL_IMM(s1, iptr->val.i & 0x1f, d);
1026 store_reg_to_var_int(iptr->dst, d);
1029 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
1031 var_to_reg_int(s1, src->prev, REG_ITMP1);
1032 var_to_reg_int(s2, src, REG_ITMP2);
1033 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1034 M_AND_IMM(s2, 0x1f, REG_ITMP3);
1035 M_SRA(s1, REG_ITMP3, d);
1036 store_reg_to_var_int(iptr->dst, d);
1039 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
1040 /* val.i = constant */
1042 var_to_reg_int(s1, src, REG_ITMP1);
1043 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1044 M_SRA_IMM(s1, iptr->val.i & 0x1f, d);
1045 store_reg_to_var_int(iptr->dst, d);
1048 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
1050 var_to_reg_int(s1, src->prev, REG_ITMP1);
1051 var_to_reg_int(s2, src, REG_ITMP2);
1052 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1053 M_AND_IMM(s2, 0x1f, REG_ITMP2);
1054 M_SRL(s1, REG_ITMP2, d);
1055 store_reg_to_var_int(iptr->dst, d);
1058 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
1059 /* val.i = constant */
1061 var_to_reg_int(s1, src, REG_ITMP1);
1062 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1063 if (iptr->val.i & 0x1f) {
1064 M_SRL_IMM(s1, iptr->val.i & 0x1f, d);
1068 store_reg_to_var_int(iptr->dst, d);
1071 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
1073 var_to_reg_int(s1, src->prev, REG_ITMP1);
1074 var_to_reg_int(s2, src, REG_ITMP2);
1075 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1077 store_reg_to_var_int(iptr->dst, d);
1080 case ICMD_IANDCONST: /* ..., value ==> ..., value & constant */
1081 /* val.i = constant */
1083 var_to_reg_int(s1, src, REG_ITMP1);
1084 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1085 if ((iptr->val.i >= 0) && (iptr->val.i <= 65535)) {
1086 M_AND_IMM(s1, iptr->val.i, d);
1089 else if (iptr->val.i == 0xffffff) {
1090 M_RLWINM(s1, 0, 8, 31, d);
1094 ICONST(REG_ITMP3, iptr->val.i);
1095 M_AND(s1, REG_ITMP3, d);
1097 store_reg_to_var_int(iptr->dst, d);
1100 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
1102 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
1103 var_to_reg_lng_low(s2, src, REG_ITMP2);
1104 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1105 M_AND(s1, s2, GET_LOW_REG(d));
1106 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
1107 var_to_reg_lng_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
1108 M_AND(s1, s2, GET_HIGH_REG(d));
1109 store_reg_to_var_lng(iptr->dst, d);
1112 case ICMD_LANDCONST: /* ..., value ==> ..., value & constant */
1113 /* val.l = constant */
1115 s3 = iptr->val.l & 0xffffffff;
1116 var_to_reg_lng_low(s1, src, REG_ITMP1);
1117 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1118 if ((s3 >= 0) && (s3 <= 65535)) {
1119 M_AND_IMM(s1, s3, GET_LOW_REG(d));
1121 ICONST(REG_ITMP3, s3);
1122 M_AND(s1, REG_ITMP3, GET_LOW_REG(d));
1124 var_to_reg_lng_high(s1, src, REG_ITMP1);
1125 s3 = iptr->val.l >> 32;
1126 if ((s3 >= 0) && (s3 <= 65535)) {
1127 M_AND_IMM(s1, s3, GET_HIGH_REG(d));
1129 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
1130 M_AND(s1, REG_ITMP3, GET_HIGH_REG(d));
1132 store_reg_to_var_lng(iptr->dst, d);
1135 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
1136 /* val.i = constant */
1138 var_to_reg_int(s1, src, REG_ITMP1);
1139 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1140 M_MOV(s1, REG_ITMP2);
1142 M_BGE(1 + 2*(iptr->val.i >= 32768));
1143 if (iptr->val.i >= 32768) {
1144 M_ADDIS(REG_ZERO, iptr->val.i >> 16, REG_ITMP2);
1145 M_OR_IMM(REG_ITMP2, iptr->val.i, REG_ITMP2);
1146 M_IADD(s1, REG_ITMP2, REG_ITMP2);
1148 M_IADD_IMM(s1, iptr->val.i, REG_ITMP2);
1151 int b=0, m = iptr->val.i;
1154 M_RLWINM(REG_ITMP2, 0, 0, 30-b, REG_ITMP2);
1156 M_ISUB(s1, REG_ITMP2, d);
1157 store_reg_to_var_int(iptr->dst, d);
1160 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
1162 var_to_reg_int(s1, src->prev, REG_ITMP1);
1163 var_to_reg_int(s2, src, REG_ITMP2);
1164 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1166 store_reg_to_var_int(iptr->dst, d);
1169 case ICMD_IORCONST: /* ..., value ==> ..., value | constant */
1170 /* val.i = constant */
1172 var_to_reg_int(s1, src, REG_ITMP1);
1173 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1174 if ((iptr->val.i >= 0) && (iptr->val.i <= 65535)) {
1175 M_OR_IMM(s1, iptr->val.i, d);
1177 ICONST(REG_ITMP3, iptr->val.i);
1178 M_OR(s1, REG_ITMP3, d);
1180 store_reg_to_var_int(iptr->dst, d);
1183 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
1185 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
1186 var_to_reg_lng_low(s2, src, REG_ITMP2);
1187 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1188 M_OR(s1, s2, GET_LOW_REG(d));
1189 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
1190 var_to_reg_lng_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
1191 M_OR(s1, s2, GET_HIGH_REG(d));
1192 store_reg_to_var_lng(iptr->dst, d);
1195 case ICMD_LORCONST: /* ..., value ==> ..., value | constant */
1196 /* val.l = constant */
1198 s3 = iptr->val.l & 0xffffffff;
1199 var_to_reg_lng_low(s1, src, REG_ITMP1);
1200 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1201 if ((s3 >= 0) && (s3 <= 65535)) {
1202 M_OR_IMM(s1, s3, GET_LOW_REG(d));
1204 ICONST(REG_ITMP3, s3);
1205 M_OR(s1, REG_ITMP3, GET_LOW_REG(d));
1207 var_to_reg_lng_high(s1, src, REG_ITMP1);
1208 s3 = iptr->val.l >> 32;
1209 if ((s3 >= 0) && (s3 <= 65535)) {
1210 M_OR_IMM(s1, s3, GET_HIGH_REG(d));
1212 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
1213 M_OR(s1, REG_ITMP3, GET_HIGH_REG(d));
1215 store_reg_to_var_lng(iptr->dst, d);
1218 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
1220 var_to_reg_int(s1, src->prev, REG_ITMP1);
1221 var_to_reg_int(s2, src, REG_ITMP2);
1222 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1224 store_reg_to_var_int(iptr->dst, d);
1227 case ICMD_IXORCONST: /* ..., value ==> ..., value ^ constant */
1228 /* val.i = constant */
1230 var_to_reg_int(s1, src, REG_ITMP1);
1231 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1232 if ((iptr->val.i >= 0) && (iptr->val.i <= 65535)) {
1233 M_XOR_IMM(s1, iptr->val.i, d);
1235 ICONST(REG_ITMP3, iptr->val.i);
1236 M_XOR(s1, REG_ITMP3, d);
1238 store_reg_to_var_int(iptr->dst, d);
1241 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
1243 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
1244 var_to_reg_lng_low(s2, src, REG_ITMP2);
1245 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1246 M_XOR(s1, s2, GET_LOW_REG(d));
1247 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
1248 var_to_reg_lng_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
1249 M_XOR(s1, s2, GET_HIGH_REG(d));
1250 store_reg_to_var_lng(iptr->dst, d);
1253 case ICMD_LXORCONST: /* ..., value ==> ..., value ^ constant */
1254 /* val.l = constant */
1256 s3 = iptr->val.l & 0xffffffff;
1257 var_to_reg_lng_low(s1, src, REG_ITMP1);
1258 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1259 if ((s3 >= 0) && (s3 <= 65535)) {
1260 M_XOR_IMM(s1, s3, GET_LOW_REG(d));
1262 ICONST(REG_ITMP3, s3);
1263 M_XOR(s1, REG_ITMP3, GET_LOW_REG(d));
1265 var_to_reg_lng_high(s1, src, REG_ITMP1);
1266 s3 = iptr->val.l >> 32;
1267 if ((s3 >= 0) && (s3 <= 65535)) {
1268 M_XOR_IMM(s1, s3, GET_HIGH_REG(d));
1270 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
1271 M_XOR(s1, REG_ITMP3, GET_HIGH_REG(d));
1273 store_reg_to_var_lng(iptr->dst, d);
1276 case ICMD_LCMP: /* ..., val1, val2 ==> ..., val1 cmp val2 */
1277 /*******************************************************************
1278 TODO: CHANGE THIS TO A VERSION THAT WORKS !!!
1279 *******************************************************************/
1280 var_to_reg_lng_high(s1, src->prev, REG_ITMP3);
1281 var_to_reg_lng_high(s2, src, REG_ITMP2);
1282 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
1284 int tempreg = false;
1288 if (src->prev->flags & INMEMORY) {
1289 tempreg = tempreg || (d == REG_ITMP3) || (d == REG_ITMP2);
1291 tempreg = tempreg || (d == GET_HIGH_REG(src->prev->regoff))
1292 || (d == GET_LOW_REG(src->prev->regoff));
1294 if (src->flags & INMEMORY) {
1295 tempreg = tempreg || (d == REG_ITMP3) || (d == REG_ITMP2);
1297 tempreg = tempreg || (d == GET_HIGH_REG(src->regoff))
1298 || (d == GET_LOW_REG(src->regoff));
1301 dreg = tempreg ? REG_ITMP1 : d;
1302 M_IADD_IMM(REG_ZERO, 1, dreg);
1307 var_to_reg_lng_low(s1, src->prev, REG_ITMP3);
1308 var_to_reg_lng_low(s2, src, REG_ITMP2);
1312 M_IADD_IMM(dreg, -1, dreg);
1313 M_IADD_IMM(dreg, -1, dreg);
1314 gen_resolvebranch(br1, (u1*) br1, (u1*) mcodeptr);
1315 gen_resolvebranch(br1+1, (u1*) (br1+1), (u1*) (mcodeptr-2));
1318 store_reg_to_var_lng(iptr->dst, d);
1321 case ICMD_IINC: /* ..., value ==> ..., value + constant */
1322 /* op1 = variable, val.i = constant */
1324 var = &(rd->locals[iptr->op1][TYPE_INT]);
1325 if (var->flags & INMEMORY) {
1327 M_ILD(s1, REG_SP, var->regoff * 4);
1336 M_ADDIS(s1, m >> 16, s1);
1338 M_IADD_IMM(s1, m & 0xffff, s1);
1340 if (var->flags & INMEMORY) {
1341 M_IST(s1, REG_SP, var->regoff * 4);
1346 /* floating operations ************************************************/
1348 case ICMD_FNEG: /* ..., value ==> ..., - value */
1350 var_to_reg_flt(s1, src, REG_FTMP1);
1351 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1353 store_reg_to_var_flt(iptr->dst, d);
1356 case ICMD_DNEG: /* ..., value ==> ..., - value */
1358 var_to_reg_flt(s1, src, REG_FTMP1);
1359 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1361 store_reg_to_var_dbl(iptr->dst, d);
1364 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1366 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1367 var_to_reg_flt(s2, src, REG_FTMP2);
1368 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1370 store_reg_to_var_flt(iptr->dst, d);
1373 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1375 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1376 var_to_reg_flt(s2, src, REG_FTMP2);
1377 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1379 store_reg_to_var_dbl(iptr->dst, d);
1382 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1384 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1385 var_to_reg_flt(s2, src, REG_FTMP2);
1386 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1388 store_reg_to_var_flt(iptr->dst, d);
1391 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1393 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1394 var_to_reg_flt(s2, src, REG_FTMP2);
1395 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1397 store_reg_to_var_dbl(iptr->dst, d);
1400 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1402 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1403 var_to_reg_flt(s2, src, REG_FTMP2);
1404 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1406 store_reg_to_var_flt(iptr->dst, d);
1409 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1411 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1412 var_to_reg_flt(s2, src, REG_FTMP2);
1413 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1415 store_reg_to_var_dbl(iptr->dst, d);
1418 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1420 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1421 var_to_reg_flt(s2, src, REG_FTMP2);
1422 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1424 store_reg_to_var_flt(iptr->dst, d);
1427 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1429 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1430 var_to_reg_flt(s2, src, REG_FTMP2);
1431 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1433 store_reg_to_var_dbl(iptr->dst, d);
1436 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1439 var_to_reg_flt(s1, src, REG_FTMP1);
1440 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1442 disp = dseg_addfloat(cd, 0.0);
1443 M_FLD(REG_FTMP2, REG_PV, disp);
1444 M_FCMPU(s1, REG_FTMP2);
1446 disp = dseg_adds4(cd, 0);
1447 M_CVTDL_C(s1, REG_FTMP1);
1448 M_LDA(REG_ITMP1, REG_PV, disp);
1449 M_STFIWX(REG_FTMP1, 0, REG_ITMP1);
1450 M_ILD(d, REG_PV, disp);
1451 store_reg_to_var_int(iptr->dst, d);
1454 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1456 var_to_reg_flt(s1, src, REG_FTMP1);
1457 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1459 store_reg_to_var_dbl(iptr->dst, d);
1462 case ICMD_D2F: /* ..., value ==> ..., (double) value */
1464 var_to_reg_flt(s1, src, REG_FTMP1);
1465 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1467 store_reg_to_var_flt(iptr->dst, d);
1470 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1473 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1474 var_to_reg_flt(s2, src, REG_FTMP2);
1475 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
1477 M_IADD_IMM(REG_ZERO, -1, d);
1480 M_IADD_IMM(REG_ZERO, 0, d);
1482 M_IADD_IMM(REG_ZERO, 1, d);
1483 store_reg_to_var_int(iptr->dst, d);
1486 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1489 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1490 var_to_reg_flt(s2, src, REG_FTMP2);
1491 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
1493 M_IADD_IMM(REG_ZERO, 1, d);
1496 M_IADD_IMM(REG_ZERO, 0, d);
1498 M_IADD_IMM(REG_ZERO, -1, d);
1499 store_reg_to_var_int(iptr->dst, d);
1503 /* memory operations **************************************************/
1505 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1507 var_to_reg_int(s1, src, REG_ITMP1);
1508 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1509 gen_nullptr_check(s1);
1510 M_ILD(d, s1, OFFSET(java_arrayheader, size));
1511 store_reg_to_var_int(iptr->dst, d);
1514 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1516 var_to_reg_int(s1, src->prev, REG_ITMP1);
1517 var_to_reg_int(s2, src, REG_ITMP2);
1518 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1519 if (iptr->op1 == 0) {
1520 gen_nullptr_check(s1);
1523 M_IADD_IMM(s2, OFFSET(java_chararray, data[0]), REG_ITMP2);
1524 M_LBZX(d, s1, REG_ITMP2);
1526 store_reg_to_var_int(iptr->dst, d);
1529 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1531 var_to_reg_int(s1, src->prev, REG_ITMP1);
1532 var_to_reg_int(s2, src, REG_ITMP2);
1533 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1534 if (iptr->op1 == 0) {
1535 gen_nullptr_check(s1);
1538 M_SLL_IMM(s2, 1, REG_ITMP2);
1539 M_IADD_IMM(REG_ITMP2, OFFSET(java_chararray, data[0]), REG_ITMP2);
1540 M_LHZX(d, s1, REG_ITMP2);
1541 store_reg_to_var_int(iptr->dst, d);
1544 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1546 var_to_reg_int(s1, src->prev, REG_ITMP1);
1547 var_to_reg_int(s2, src, REG_ITMP2);
1548 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1549 if (iptr->op1 == 0) {
1550 gen_nullptr_check(s1);
1553 M_SLL_IMM(s2, 1, REG_ITMP2);
1554 M_IADD_IMM(REG_ITMP2, OFFSET(java_shortarray, data[0]), REG_ITMP2);
1555 M_LHAX(d, s1, REG_ITMP2);
1556 store_reg_to_var_int(iptr->dst, d);
1559 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1561 var_to_reg_int(s1, src->prev, REG_ITMP1);
1562 var_to_reg_int(s2, src, REG_ITMP2);
1563 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1564 if (iptr->op1 == 0) {
1565 gen_nullptr_check(s1);
1568 M_SLL_IMM(s2, 2, REG_ITMP2);
1569 M_IADD_IMM(REG_ITMP2, OFFSET(java_intarray, data[0]), REG_ITMP2);
1570 M_LWZX(d, s1, REG_ITMP2);
1571 store_reg_to_var_int(iptr->dst, d);
1574 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1576 var_to_reg_int(s1, src->prev, REG_ITMP1);
1577 var_to_reg_int(s2, src, REG_ITMP2);
1578 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1579 if (iptr->op1 == 0) {
1580 gen_nullptr_check(s1);
1583 M_SLL_IMM(s2, 3, REG_ITMP2);
1584 M_IADD(s1, REG_ITMP2, REG_ITMP2);
1585 M_ILD(GET_HIGH_REG(d), REG_ITMP2, OFFSET(java_longarray, data[0]));
1586 M_ILD(GET_LOW_REG(d), REG_ITMP2, OFFSET(java_longarray,
1588 store_reg_to_var_lng(iptr->dst, d);
1591 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1593 var_to_reg_int(s1, src->prev, REG_ITMP1);
1594 var_to_reg_int(s2, src, REG_ITMP2);
1595 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1596 if (iptr->op1 == 0) {
1597 gen_nullptr_check(s1);
1600 M_SLL_IMM(s2, 2, REG_ITMP2);
1601 M_IADD_IMM(REG_ITMP2, OFFSET(java_floatarray, data[0]), REG_ITMP2);
1602 M_LFSX(d, s1, REG_ITMP2);
1603 store_reg_to_var_flt(iptr->dst, d);
1606 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1608 var_to_reg_int(s1, src->prev, REG_ITMP1);
1609 var_to_reg_int(s2, src, REG_ITMP2);
1610 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1611 if (iptr->op1 == 0) {
1612 gen_nullptr_check(s1);
1615 M_SLL_IMM(s2, 3, REG_ITMP2);
1616 M_IADD_IMM(REG_ITMP2, OFFSET(java_doublearray, data[0]), REG_ITMP2);
1617 M_LFDX(d, s1, REG_ITMP2);
1618 store_reg_to_var_dbl(iptr->dst, d);
1621 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1623 var_to_reg_int(s1, src->prev, REG_ITMP1);
1624 var_to_reg_int(s2, src, REG_ITMP2);
1625 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1626 if (iptr->op1 == 0) {
1627 gen_nullptr_check(s1);
1630 M_SLL_IMM(s2, 2, REG_ITMP2);
1631 M_IADD_IMM(REG_ITMP2, OFFSET(java_objectarray, data[0]), REG_ITMP2);
1632 M_LWZX(d, s1, REG_ITMP2);
1633 store_reg_to_var_adr(iptr->dst, d);
1637 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1639 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1640 var_to_reg_int(s2, src->prev, REG_ITMP2);
1641 if (iptr->op1 == 0) {
1642 gen_nullptr_check(s1);
1645 var_to_reg_int(s3, src, REG_ITMP3);
1646 M_IADD_IMM(s2, OFFSET(java_bytearray, data[0]), REG_ITMP2);
1647 M_STBX(s3, s1, REG_ITMP2);
1650 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1652 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1653 var_to_reg_int(s2, src->prev, REG_ITMP2);
1654 if (iptr->op1 == 0) {
1655 gen_nullptr_check(s1);
1658 var_to_reg_int(s3, src, REG_ITMP3);
1659 M_SLL_IMM(s2, 1, REG_ITMP2);
1660 M_IADD_IMM(REG_ITMP2, OFFSET(java_chararray, data[0]), REG_ITMP2);
1661 M_STHX(s3, s1, REG_ITMP2);
1664 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1666 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1667 var_to_reg_int(s2, src->prev, REG_ITMP2);
1668 if (iptr->op1 == 0) {
1669 gen_nullptr_check(s1);
1672 var_to_reg_int(s3, src, REG_ITMP3);
1673 M_SLL_IMM(s2, 1, REG_ITMP2);
1674 M_IADD_IMM(REG_ITMP2, OFFSET(java_shortarray, data[0]), REG_ITMP2);
1675 M_STHX(s3, s1, REG_ITMP2);
1678 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1680 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1681 var_to_reg_int(s2, src->prev, REG_ITMP2);
1682 if (iptr->op1 == 0) {
1683 gen_nullptr_check(s1);
1686 var_to_reg_int(s3, src, REG_ITMP3);
1687 M_SLL_IMM(s2, 2, REG_ITMP2);
1688 M_IADD_IMM(REG_ITMP2, OFFSET(java_intarray, data[0]), REG_ITMP2);
1689 M_STWX(s3, s1, REG_ITMP2);
1692 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1694 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1695 var_to_reg_int(s2, src->prev, REG_ITMP2);
1696 if (iptr->op1 == 0) {
1697 gen_nullptr_check(s1);
1700 var_to_reg_lng_high(s3, src, REG_ITMP3);
1701 M_SLL_IMM(s2, 3, REG_ITMP2);
1702 M_IADD_IMM(REG_ITMP2, OFFSET(java_longarray, data[0]), REG_ITMP2);
1703 M_STWX(s3, s1, REG_ITMP2);
1704 M_IADD_IMM(REG_ITMP2, 4, REG_ITMP2);
1705 var_to_reg_lng_low(s3, src, REG_ITMP3);
1706 M_STWX(s3, s1, REG_ITMP2);
1709 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1711 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1712 var_to_reg_int(s2, src->prev, REG_ITMP2);
1713 if (iptr->op1 == 0) {
1714 gen_nullptr_check(s1);
1717 var_to_reg_flt(s3, src, REG_FTMP3);
1718 M_SLL_IMM(s2, 2, REG_ITMP2);
1719 M_IADD_IMM(REG_ITMP2, OFFSET(java_floatarray, data[0]), REG_ITMP2);
1720 M_STFSX(s3, s1, REG_ITMP2);
1723 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1725 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1726 var_to_reg_int(s2, src->prev, REG_ITMP2);
1727 if (iptr->op1 == 0) {
1728 gen_nullptr_check(s1);
1731 var_to_reg_flt(s3, src, REG_FTMP3);
1732 M_SLL_IMM(s2, 3, REG_ITMP2);
1733 M_IADD_IMM(REG_ITMP2, OFFSET(java_doublearray, data[0]), REG_ITMP2);
1734 M_STFDX(s3, s1, REG_ITMP2);
1737 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1739 var_to_reg_int(s1, src->prev->prev, rd->argintregs[0]);
1740 var_to_reg_int(s2, src->prev, REG_ITMP2);
1741 if (iptr->op1 == 0) {
1742 gen_nullptr_check(s1);
1745 var_to_reg_int(s3, src, rd->argintregs[1]);
1747 M_INTMOVE(s1, rd->argintregs[0]);
1748 M_INTMOVE(s3, rd->argintregs[1]);
1749 disp = dseg_addaddress(cd, BUILTIN_canstore);
1750 M_ALD(REG_ITMP1, REG_PV, disp);
1755 codegen_addxstorerefs(cd, mcodeptr);
1757 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1758 var_to_reg_int(s2, src->prev, REG_ITMP2);
1759 var_to_reg_int(s3, src, REG_ITMP3);
1760 M_SLL_IMM(s2, 2, REG_ITMP2);
1761 M_IADD_IMM(REG_ITMP2, OFFSET(java_objectarray, data[0]), REG_ITMP2);
1762 M_STWX(s3, s1, REG_ITMP2);
1766 case ICMD_GETSTATIC: /* ... ==> ..., value */
1767 /* op1 = type, val.a = field address */
1769 if (iptr->val.a == NULL) {
1770 disp = dseg_addaddress(cd, NULL);
1772 codegen_addpatchref(cd, mcodeptr,
1773 PATCHER_get_putstatic,
1774 (unresolved_field *) iptr->target, disp);
1776 if (opt_showdisassemble)
1780 fieldinfo *fi = iptr->val.a;
1782 disp = dseg_addaddress(cd, &(fi->value));
1784 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1785 codegen_addpatchref(cd, mcodeptr,
1786 PATCHER_clinit, fi->class, disp);
1788 if (opt_showdisassemble)
1793 M_ALD(REG_ITMP1, REG_PV, disp);
1794 switch (iptr->op1) {
1796 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1797 M_ILD_INTERN(d, REG_ITMP1, 0);
1798 store_reg_to_var_int(iptr->dst, d);
1801 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1802 M_ILD_INTERN(GET_LOW_REG(d), REG_ITMP1, 4);/* keep this order */
1803 M_ILD_INTERN(GET_HIGH_REG(d), REG_ITMP1, 0);/*keep this order */
1804 store_reg_to_var_lng(iptr->dst, d);
1807 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1808 M_ALD_INTERN(d, REG_ITMP1, 0);
1809 store_reg_to_var_adr(iptr->dst, d);
1812 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1813 M_FLD_INTERN(d, REG_ITMP1, 0);
1814 store_reg_to_var_flt(iptr->dst, d);
1817 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1818 M_DLD_INTERN(d, REG_ITMP1, 0);
1819 store_reg_to_var_dbl(iptr->dst, d);
1824 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1825 /* op1 = type, val.a = field address */
1828 if (iptr->val.a == NULL) {
1829 disp = dseg_addaddress(cd, NULL);
1831 codegen_addpatchref(cd, mcodeptr,
1832 PATCHER_get_putstatic,
1833 (unresolved_field *) iptr->target, disp);
1835 if (opt_showdisassemble)
1839 fieldinfo *fi = iptr->val.a;
1841 disp = dseg_addaddress(cd, &(fi->value));
1843 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1844 codegen_addpatchref(cd, mcodeptr,
1845 PATCHER_clinit, fi->class, disp);
1847 if (opt_showdisassemble)
1852 M_ALD(REG_ITMP1, REG_PV, disp);
1853 switch (iptr->op1) {
1855 var_to_reg_int(s2, src, REG_ITMP2);
1856 M_IST_INTERN(s2, REG_ITMP1, 0);
1859 var_to_reg_int(s2, src, PACK_REGS(REG_ITMP2, REG_ITMP3));
1860 M_IST_INTERN(GET_HIGH_REG(s2), REG_ITMP1, 0);
1861 M_IST_INTERN(GET_LOW_REG(s2), REG_ITMP1, 4);
1864 var_to_reg_int(s2, src, REG_ITMP2);
1865 M_AST_INTERN(s2, REG_ITMP1, 0);
1868 var_to_reg_flt(s2, src, REG_FTMP2);
1869 M_FST_INTERN(s2, REG_ITMP1, 0);
1872 var_to_reg_flt(s2, src, REG_FTMP2);
1873 M_DST_INTERN(s2, REG_ITMP1, 0);
1879 case ICMD_GETFIELD: /* ... ==> ..., value */
1880 /* op1 = type, val.i = field offset */
1882 var_to_reg_int(s1, src, REG_ITMP1);
1883 gen_nullptr_check(s1);
1885 if (iptr->val.a == NULL) {
1886 codegen_addpatchref(cd, mcodeptr,
1887 PATCHER_get_putfield,
1888 (unresolved_field *) iptr->target, 0);
1890 if (opt_showdisassemble)
1896 disp = ((fieldinfo *) (iptr->val.a))->offset;
1899 switch (iptr->op1) {
1901 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1903 store_reg_to_var_int(iptr->dst, d);
1906 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1907 if (GET_HIGH_REG(d) == s1) {
1908 M_ILD(GET_LOW_REG(d), s1, disp + 4);
1909 M_ILD(GET_HIGH_REG(d), s1, disp);
1911 M_ILD(GET_HIGH_REG(d), s1, disp);
1912 M_ILD(GET_LOW_REG(d), s1, disp + 4);
1914 store_reg_to_var_lng(iptr->dst, d);
1917 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1919 store_reg_to_var_adr(iptr->dst, d);
1922 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1924 store_reg_to_var_flt(iptr->dst, d);
1927 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1929 store_reg_to_var_dbl(iptr->dst, d);
1934 case ICMD_PUTFIELD: /* ..., value ==> ... */
1935 /* op1 = type, val.i = field offset */
1937 var_to_reg_int(s1, src->prev, REG_ITMP1);
1938 gen_nullptr_check(s1);
1940 if (!IS_FLT_DBL_TYPE(iptr->op1)) {
1941 if (IS_2_WORD_TYPE(iptr->op1)) {
1942 var_to_reg_int(s2, src, PACK_REGS(REG_ITMP2, REG_ITMP3));
1944 var_to_reg_int(s2, src, REG_ITMP2);
1947 var_to_reg_flt(s2, src, REG_FTMP2);
1950 if (iptr->val.a == NULL) {
1951 codegen_addpatchref(cd, mcodeptr,
1952 PATCHER_get_putfield,
1953 (unresolved_field *) iptr->target, 0);
1955 if (opt_showdisassemble)
1961 disp = ((fieldinfo *) (iptr->val.a))->offset;
1964 switch (iptr->op1) {
1966 M_IST(s2, s1, disp);
1969 M_IST(GET_LOW_REG(s2), s1, disp + 4); /* keep this order */
1970 M_IST(GET_HIGH_REG(s2), s1, disp); /* keep this order */
1973 M_AST(s2, s1, disp);
1976 M_FST(s2, s1, disp);
1979 M_DST(s2, s1, disp);
1985 /* branch operations **************************************************/
1987 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1989 var_to_reg_int(s1, src, REG_ITMP1);
1990 M_INTMOVE(s1, REG_ITMP1_XPTR);
1992 #ifdef ENABLE_VERIFIER
1994 codegen_addpatchref(cd, mcodeptr,
1995 PATCHER_athrow_areturn,
1996 (unresolved_class *) iptr->val.a, 0);
1998 if (opt_showdisassemble)
2001 #endif /* ENABLE_VERIFIER */
2003 disp = dseg_addaddress(cd, asm_handle_exception);
2004 M_ALD(REG_ITMP2, REG_PV, disp);
2007 if (m->isleafmethod) M_MFLR(REG_ITMP3); /* save LR */
2008 M_BL(0); /* get current PC */
2009 M_MFLR(REG_ITMP2_XPC);
2010 if (m->isleafmethod) M_MTLR(REG_ITMP3); /* restore LR */
2011 M_RTS; /* jump to CTR */
2016 case ICMD_GOTO: /* ... ==> ... */
2017 /* op1 = target JavaVM pc */
2019 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2023 case ICMD_JSR: /* ... ==> ... */
2024 /* op1 = target JavaVM pc */
2026 if (m->isleafmethod) M_MFLR(REG_ITMP2);
2029 M_IADD_IMM(REG_ITMP1, m->isleafmethod ? 16 : 12, REG_ITMP1);
2030 if (m->isleafmethod) M_MTLR(REG_ITMP2);
2032 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2035 case ICMD_RET: /* ... ==> ... */
2036 /* op1 = local variable */
2038 var = &(rd->locals[iptr->op1][TYPE_ADR]);
2039 if (var->flags & INMEMORY) {
2040 M_ALD(REG_ITMP1, REG_SP, var->regoff * 4);
2043 M_MTCTR(var->regoff);
2049 case ICMD_IFNULL: /* ..., value ==> ... */
2050 /* op1 = target JavaVM pc */
2052 var_to_reg_int(s1, src, REG_ITMP1);
2055 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2058 case ICMD_IFNONNULL: /* ..., value ==> ... */
2059 /* op1 = target JavaVM pc */
2061 var_to_reg_int(s1, src, REG_ITMP1);
2064 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2072 case ICMD_IFEQ: /* ..., value ==> ... */
2073 /* op1 = target JavaVM pc, val.i = constant */
2075 var_to_reg_int(s1, src, REG_ITMP1);
2076 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
2077 M_CMPI(s1, iptr->val.i);
2079 ICONST(REG_ITMP2, iptr->val.i);
2080 M_CMP(s1, REG_ITMP2);
2082 switch (iptr->opc) {
2102 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2106 case ICMD_IF_LEQ: /* ..., value ==> ... */
2107 /* op1 = target JavaVM pc, val.l = constant */
2109 var_to_reg_lng_low(s1, src, REG_ITMP1);
2110 var_to_reg_lng_high(s2, src, REG_ITMP2);
2111 if (iptr->val.l == 0) {
2112 M_OR_TST(s1, s2, REG_ITMP3);
2113 } else if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2114 M_XOR_IMM(s2, 0, REG_ITMP2);
2115 M_XOR_IMM(s1, iptr->val.l & 0xffff, REG_ITMP1);
2116 M_OR_TST(REG_ITMP1, REG_ITMP2, REG_ITMP3);
2118 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2119 M_XOR(s1, REG_ITMP3, REG_ITMP1);
2120 ICONST(REG_ITMP3, iptr->val.l >> 32);
2121 M_XOR(s2, REG_ITMP3, REG_ITMP2);
2122 M_OR_TST(REG_ITMP1, REG_ITMP2, REG_ITMP3);
2125 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2128 case ICMD_IF_LLT: /* ..., value ==> ... */
2129 /* op1 = target JavaVM pc, val.l = constant */
2130 var_to_reg_lng_low(s1, src, REG_ITMP1);
2131 var_to_reg_lng_high(s2, src, REG_ITMP2);
2132 if (iptr->val.l == 0) {
2133 /* if high word is less than zero, the whole long is too */
2135 } else if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2138 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2140 M_CMPUI(s1, iptr->val.l & 0xffff);
2142 ICONST(REG_ITMP3, iptr->val.l >> 32);
2143 M_CMP(s2, REG_ITMP3);
2145 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2147 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2148 M_CMPU(s1, REG_ITMP3);
2151 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2154 case ICMD_IF_LLE: /* ..., value ==> ... */
2155 /* op1 = target JavaVM pc, val.l = constant */
2157 var_to_reg_lng_low(s1, src, REG_ITMP1);
2158 var_to_reg_lng_high(s2, src, REG_ITMP2);
2159 /* if (iptr->val.l == 0) { */
2160 /* M_OR(s1, s2, REG_ITMP3); */
2161 /* M_CMPI(REG_ITMP3, 0); */
2164 if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2167 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2169 M_CMPUI(s1, iptr->val.l & 0xffff);
2171 ICONST(REG_ITMP3, iptr->val.l >> 32);
2172 M_CMP(s2, REG_ITMP3);
2174 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2176 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2177 M_CMPU(s1, REG_ITMP3);
2180 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2183 case ICMD_IF_LNE: /* ..., value ==> ... */
2184 /* op1 = target JavaVM pc, val.l = constant */
2186 var_to_reg_lng_low(s1, src, REG_ITMP1);
2187 var_to_reg_lng_high(s2, src, REG_ITMP2);
2188 if (iptr->val.l == 0) {
2189 M_OR_TST(s1, s2, REG_ITMP3);
2190 } else if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2191 M_XOR_IMM(s2, 0, REG_ITMP2);
2192 M_XOR_IMM(s1, iptr->val.l & 0xffff, REG_ITMP1);
2193 M_OR_TST(REG_ITMP1, REG_ITMP2, REG_ITMP3);
2195 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2196 M_XOR(s1, REG_ITMP3, REG_ITMP1);
2197 ICONST(REG_ITMP3, iptr->val.l >> 32);
2198 M_XOR(s2, REG_ITMP3, REG_ITMP2);
2199 M_OR_TST(REG_ITMP1, REG_ITMP2, REG_ITMP3);
2202 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2205 case ICMD_IF_LGT: /* ..., value ==> ... */
2206 /* op1 = target JavaVM pc, val.l = constant */
2208 var_to_reg_lng_low(s1, src, REG_ITMP1);
2209 var_to_reg_lng_high(s2, src, REG_ITMP2);
2210 /* if (iptr->val.l == 0) { */
2211 /* M_OR(s1, s2, REG_ITMP3); */
2212 /* M_CMPI(REG_ITMP3, 0); */
2215 if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2218 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2220 M_CMPUI(s1, iptr->val.l & 0xffff);
2222 ICONST(REG_ITMP3, iptr->val.l >> 32);
2223 M_CMP(s2, REG_ITMP3);
2225 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2227 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2228 M_CMPU(s1, REG_ITMP3);
2231 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2234 case ICMD_IF_LGE: /* ..., value ==> ... */
2235 /* op1 = target JavaVM pc, val.l = constant */
2236 var_to_reg_lng_low(s1, src, REG_ITMP1);
2237 var_to_reg_lng_high(s2, src, REG_ITMP2);
2238 if (iptr->val.l == 0) {
2239 /* if high word is greater equal zero, the whole long is too */
2241 } else if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2244 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2246 M_CMPUI(s1, iptr->val.l & 0xffff);
2248 ICONST(REG_ITMP3, iptr->val.l >> 32);
2249 M_CMP(s2, REG_ITMP3);
2251 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2253 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2254 M_CMPU(s1, REG_ITMP3);
2257 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2260 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
2261 case ICMD_IF_ACMPEQ: /* op1 = target JavaVM pc */
2263 var_to_reg_int(s1, src->prev, REG_ITMP1);
2264 var_to_reg_int(s2, src, REG_ITMP2);
2267 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2270 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
2271 /* op1 = target JavaVM pc */
2273 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2274 var_to_reg_lng_high(s2, src, REG_ITMP2);
2276 /* load low-bits before the branch, so we know the distance */
2277 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2278 var_to_reg_lng_low(s2, src, REG_ITMP2);
2282 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2285 case ICMD_IF_ICMPNE: /* ..., value, value ==> ... */
2286 case ICMD_IF_ACMPNE: /* op1 = target JavaVM pc */
2288 var_to_reg_int(s1, src->prev, REG_ITMP1);
2289 var_to_reg_int(s2, src, REG_ITMP2);
2292 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2295 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
2296 /* op1 = target JavaVM pc */
2298 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2299 var_to_reg_lng_high(s2, src, REG_ITMP2);
2302 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2303 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2304 var_to_reg_lng_low(s2, src, REG_ITMP2);
2307 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2310 case ICMD_IF_ICMPLT: /* ..., value, value ==> ... */
2311 /* op1 = target JavaVM pc */
2313 var_to_reg_int(s1, src->prev, REG_ITMP1);
2314 var_to_reg_int(s2, src, REG_ITMP2);
2317 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2320 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
2321 /* op1 = target JavaVM pc */
2323 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2324 var_to_reg_lng_high(s2, src, REG_ITMP2);
2327 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2328 /* load low-bits before the branch, so we know the distance */
2329 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2330 var_to_reg_lng_low(s2, src, REG_ITMP2);
2334 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2337 case ICMD_IF_ICMPGT: /* ..., value, value ==> ... */
2338 /* op1 = target JavaVM pc */
2340 var_to_reg_int(s1, src->prev, REG_ITMP1);
2341 var_to_reg_int(s2, src, REG_ITMP2);
2344 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2347 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
2348 /* op1 = target JavaVM pc */
2350 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2351 var_to_reg_lng_high(s2, src, REG_ITMP2);
2354 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2355 /* load low-bits before the branch, so we know the distance */
2356 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2357 var_to_reg_lng_low(s2, src, REG_ITMP2);
2361 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2364 case ICMD_IF_ICMPLE: /* ..., value, value ==> ... */
2365 /* op1 = target JavaVM pc */
2367 var_to_reg_int(s1, src->prev, REG_ITMP1);
2368 var_to_reg_int(s2, src, REG_ITMP2);
2371 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2374 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
2375 /* op1 = target JavaVM pc */
2377 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2378 var_to_reg_lng_high(s2, src, REG_ITMP2);
2381 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2382 /* load low-bits before the branch, so we know the distance */
2383 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2384 var_to_reg_lng_low(s2, src, REG_ITMP2);
2388 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2391 case ICMD_IF_ICMPGE: /* ..., value, value ==> ... */
2392 /* op1 = target JavaVM pc */
2394 var_to_reg_int(s1, src->prev, REG_ITMP1);
2395 var_to_reg_int(s2, src, REG_ITMP2);
2398 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2401 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
2402 /* op1 = target JavaVM pc */
2404 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2405 var_to_reg_lng_high(s2, src, REG_ITMP2);
2408 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2409 /* load low-bits before the branch, so we know the distance */
2410 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2411 var_to_reg_lng_low(s2, src, REG_ITMP2);
2415 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2418 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2420 var_to_reg_int(s1, src, REG_RESULT);
2421 M_TINTMOVE(src->type, s1, REG_RESULT);
2422 goto nowperformreturn;
2424 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2426 var_to_reg_int(s1, src, REG_RESULT);
2427 M_TINTMOVE(src->type, s1, REG_RESULT);
2429 #ifdef ENABLE_VERIFIER
2431 codegen_addpatchref(cd, mcodeptr,
2432 PATCHER_athrow_areturn,
2433 (unresolved_class *) iptr->val.a, 0);
2435 if (opt_showdisassemble)
2438 #endif /* ENABLE_VERIFIER */
2439 goto nowperformreturn;
2441 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2443 var_to_reg_int(s1, src, PACK_REGS(REG_RESULT2, REG_RESULT));
2444 M_TINTMOVE(src->type, s1, PACK_REGS(REG_RESULT2, REG_RESULT));
2445 goto nowperformreturn;
2447 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2450 var_to_reg_flt(s1, src, REG_FRESULT);
2451 M_FLTMOVE(s1, REG_FRESULT);
2452 goto nowperformreturn;
2454 case ICMD_RETURN: /* ... ==> ... */
2460 p = parentargs_base;
2462 /* call trace function */
2466 M_LDA(REG_SP, REG_SP, -10 * 8);
2467 M_DST(REG_FRESULT, REG_SP, 48+0);
2468 M_IST(REG_RESULT, REG_SP, 48+8);
2469 M_AST(REG_ZERO, REG_SP, 48+12);
2470 M_IST(REG_RESULT2, REG_SP, 48+16);
2472 /* keep this order */
2473 switch (iptr->opc) {
2476 #if defined(__DARWIN__)
2477 M_MOV(REG_RESULT, rd->argintregs[2]);
2478 M_CLR(rd->argintregs[1]);
2480 M_MOV(REG_RESULT, rd->argintregs[3]);
2481 M_CLR(rd->argintregs[2]);
2486 #if defined(__DARWIN__)
2487 M_MOV(REG_RESULT2, rd->argintregs[2]);
2488 M_MOV(REG_RESULT, rd->argintregs[1]);
2490 M_MOV(REG_RESULT2, rd->argintregs[3]);
2491 M_MOV(REG_RESULT, rd->argintregs[2]);
2496 disp = dseg_addaddress(cd, m);
2497 M_ALD(rd->argintregs[0], REG_PV, disp);
2499 M_FLTMOVE(REG_FRESULT, rd->argfltregs[0]);
2500 M_FLTMOVE(REG_FRESULT, rd->argfltregs[1]);
2501 disp = dseg_addaddress(cd, builtin_displaymethodstop);
2502 M_ALD(REG_ITMP2, REG_PV, disp);
2506 M_DLD(REG_FRESULT, REG_SP, 48+0);
2507 M_ILD(REG_RESULT, REG_SP, 48+8);
2508 M_ALD(REG_ZERO, REG_SP, 48+12);
2509 M_ILD(REG_RESULT2, REG_SP, 48+16);
2510 M_LDA(REG_SP, REG_SP, 10 * 8);
2514 #if defined(USE_THREADS)
2515 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2516 /* we need to save the proper return value */
2517 switch (iptr->opc) {
2519 M_IST(REG_RESULT2, REG_SP, rd->memuse * 4 + 8);
2523 M_IST(REG_RESULT , REG_SP, rd->memuse * 4 + 4);
2526 M_FST(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2529 M_DST(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2533 disp = dseg_addaddress(cd, BUILTIN_monitorexit);
2534 M_ALD(REG_ITMP3, REG_PV, disp);
2536 M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 4);
2539 /* and now restore the proper return value */
2540 switch (iptr->opc) {
2542 M_ILD(REG_RESULT2, REG_SP, rd->memuse * 4 + 8);
2546 M_ILD(REG_RESULT , REG_SP, rd->memuse * 4 + 4);
2549 M_FLD(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2552 M_DLD(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2558 /* restore return address */
2560 if (!m->isleafmethod) {
2561 M_ALD(REG_ZERO, REG_SP, p * 4 + LA_LR_OFFSET);
2565 /* restore saved registers */
2567 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
2568 p--; M_ILD(rd->savintregs[i], REG_SP, p * 4);
2570 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
2571 p -= 2; M_DLD(rd->savfltregs[i], REG_SP, p * 4);
2574 /* deallocate stack */
2576 if (parentargs_base)
2577 M_LDA(REG_SP, REG_SP, parentargs_base * 4);
2585 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2590 tptr = (void **) iptr->target;
2592 s4ptr = iptr->val.a;
2593 l = s4ptr[1]; /* low */
2594 i = s4ptr[2]; /* high */
2596 var_to_reg_int(s1, src, REG_ITMP1);
2598 M_INTMOVE(s1, REG_ITMP1);
2599 } else if (l <= 32768) {
2600 M_LDA(REG_ITMP1, s1, -l);
2602 ICONST(REG_ITMP2, l);
2603 M_ISUB(s1, REG_ITMP2, REG_ITMP1);
2609 M_CMPUI(REG_ITMP1, i - 1);
2611 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2613 /* build jump table top down and use address of lowest entry */
2615 /* s4ptr += 3 + i; */
2619 dseg_addtarget(cd, (basicblock *) tptr[0]);
2624 /* length of dataseg after last dseg_addtarget is used by load */
2626 M_SLL_IMM(REG_ITMP1, 2, REG_ITMP1);
2627 M_IADD(REG_ITMP1, REG_PV, REG_ITMP2);
2628 M_ALD(REG_ITMP2, REG_ITMP2, -(cd->dseglen));
2635 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2637 s4 i, l, val, *s4ptr;
2640 tptr = (void **) iptr->target;
2642 s4ptr = iptr->val.a;
2643 l = s4ptr[0]; /* default */
2644 i = s4ptr[1]; /* count */
2646 MCODECHECK((i<<2)+8);
2647 var_to_reg_int(s1, src, REG_ITMP1);
2653 if ((val >= -32768) && (val <= 32767)) {
2656 a = dseg_adds4(cd, val);
2657 M_ILD(REG_ITMP2, REG_PV, a);
2658 M_CMP(s1, REG_ITMP2);
2661 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2665 tptr = (void **) iptr->target;
2666 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2673 case ICMD_BUILTIN: /* ..., [arg1, [arg2 ...]] ==> ... */
2674 /* op1 = arg count val.a = builtintable entry */
2680 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2681 /* op1 = arg count, val.a = method pointer */
2683 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2684 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2685 case ICMD_INVOKEINTERFACE:
2690 unresolved_method *um = iptr->target;
2691 md = um->methodref->parseddesc.md;
2693 md = lm->parseddesc;
2697 s3 = md->paramcount;
2699 MCODECHECK((s3 << 1) + 64);
2701 /* copy arguments to registers or stack location */
2703 for (s3 = s3 - 1; s3 >= 0; s3--, src = src->prev) {
2704 if (src->varkind == ARGVAR)
2706 if (IS_INT_LNG_TYPE(src->type)) {
2707 if (!md->params[s3].inmemory) {
2708 if (IS_2_WORD_TYPE(src->type)) {
2710 rd->argintregs[GET_LOW_REG(md->params[s3].regoff)],
2711 rd->argintregs[GET_HIGH_REG(md->params[s3].regoff)]);
2713 s1 = rd->argintregs[md->params[s3].regoff];
2715 var_to_reg_int(d, src, s1);
2716 M_TINTMOVE(src->type, d, s1);
2718 if (IS_2_WORD_TYPE(src->type)) {
2719 var_to_reg_int(d, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
2720 M_IST(GET_HIGH_REG(d), REG_SP,
2721 md->params[s3].regoff * 4);
2722 M_IST(GET_LOW_REG(d), REG_SP,
2723 md->params[s3].regoff * 4 + 4);
2725 var_to_reg_int(d, src, REG_ITMP1);
2726 M_IST(d, REG_SP, md->params[s3].regoff * 4);
2731 if (!md->params[s3].inmemory) {
2732 s1 = rd->argfltregs[md->params[s3].regoff];
2733 var_to_reg_flt(d, src, s1);
2736 var_to_reg_flt(d, src, REG_FTMP1);
2737 if (IS_2_WORD_TYPE(src->type)) {
2738 M_DST(d, REG_SP, md->params[s3].regoff * 4);
2740 M_FST(d, REG_SP, md->params[s3].regoff * 4);
2746 switch (iptr->opc) {
2748 disp = dseg_addaddress(cd, bte->fp);
2749 d = md->returntype.type;
2751 M_ALD(REG_PV, REG_PV, disp); /* pointer to built-in-function */
2754 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2756 M_LDA(REG_PV, REG_ITMP1, -disp);
2758 /* if op1 == true, we need to check for an exception */
2760 if (iptr->op1 == true) {
2761 M_CMPI(REG_RESULT, 0);
2763 codegen_addxexceptionrefs(cd, mcodeptr);
2767 case ICMD_INVOKESPECIAL:
2768 gen_nullptr_check(rd->argintregs[0]);
2769 M_ILD(REG_ITMP1, rd->argintregs[0], 0); /* hardware nullptr */
2772 case ICMD_INVOKESTATIC:
2774 unresolved_method *um = iptr->target;
2776 disp = dseg_addaddress(cd, NULL);
2778 codegen_addpatchref(cd, mcodeptr,
2779 PATCHER_invokestatic_special, um, disp);
2781 if (opt_showdisassemble)
2784 d = md->returntype.type;
2787 disp = dseg_addaddress(cd, lm->stubroutine);
2788 d = md->returntype.type;
2791 M_ALD(REG_PV, REG_PV, disp);
2794 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2796 M_LDA(REG_PV, REG_ITMP1, -disp);
2799 case ICMD_INVOKEVIRTUAL:
2800 gen_nullptr_check(rd->argintregs[0]);
2803 unresolved_method *um = iptr->target;
2805 codegen_addpatchref(cd, mcodeptr,
2806 PATCHER_invokevirtual, um, 0);
2808 if (opt_showdisassemble)
2812 d = md->returntype.type;
2815 s1 = OFFSET(vftbl_t, table[0]) +
2816 sizeof(methodptr) * lm->vftblindex;
2817 d = md->returntype.type;
2820 M_ALD(REG_METHODPTR, rd->argintregs[0],
2821 OFFSET(java_objectheader, vftbl));
2822 M_ALD(REG_PV, REG_METHODPTR, s1);
2825 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2827 M_LDA(REG_PV, REG_ITMP1, -disp);
2830 case ICMD_INVOKEINTERFACE:
2831 gen_nullptr_check(rd->argintregs[0]);
2834 unresolved_method *um = iptr->target;
2836 codegen_addpatchref(cd, mcodeptr,
2837 PATCHER_invokeinterface, um, 0);
2839 if (opt_showdisassemble)
2844 d = md->returntype.type;
2847 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2848 sizeof(methodptr*) * lm->class->index;
2850 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2852 d = md->returntype.type;
2855 M_ALD(REG_METHODPTR, rd->argintregs[0],
2856 OFFSET(java_objectheader, vftbl));
2857 M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
2858 M_ALD(REG_PV, REG_METHODPTR, s2);
2861 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2863 M_LDA(REG_PV, REG_ITMP1, -disp);
2867 /* d contains return type */
2869 if (d != TYPE_VOID) {
2870 if (IS_INT_LNG_TYPE(iptr->dst->type)) {
2871 if (IS_2_WORD_TYPE(iptr->dst->type)) {
2872 s1 = reg_of_var(rd, iptr->dst,
2873 PACK_REGS(REG_RESULT2, REG_RESULT));
2874 M_TINTMOVE(iptr->dst->type,
2875 PACK_REGS(REG_RESULT2, REG_RESULT), s1);
2876 store_reg_to_var_lng(iptr->dst, s1);
2878 s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
2879 M_TINTMOVE(iptr->dst->type, REG_RESULT, s1);
2880 store_reg_to_var_int(iptr->dst, s1);
2883 s1 = reg_of_var(rd, iptr->dst, REG_FRESULT);
2884 M_FLTMOVE(REG_FRESULT, s1);
2885 if (IS_2_WORD_TYPE(iptr->dst->type)) {
2886 store_reg_to_var_dbl(iptr->dst, s1);
2888 store_reg_to_var_flt(iptr->dst, s1);
2895 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2896 /* op1: 0 == array, 1 == class */
2897 /* val.a: (classinfo*) superclass */
2899 /* superclass is an interface:
2901 * OK if ((sub == NULL) ||
2902 * (sub->vftbl->interfacetablelength > super->index) &&
2903 * (sub->vftbl->interfacetable[-super->index] != NULL));
2905 * superclass is a class:
2907 * OK if ((sub == NULL) || (0
2908 * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
2909 * super->vftbl->diffvall));
2912 if (iptr->op1 == 1) {
2913 /* object type cast-check */
2916 vftbl_t *supervftbl;
2919 super = (classinfo *) iptr->val.a;
2926 superindex = super->index;
2927 supervftbl = super->vftbl;
2930 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
2931 codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
2933 var_to_reg_int(s1, src, REG_ITMP1);
2935 /* calculate interface checkcast code size */
2939 s2 += (opt_showdisassemble ? 1 : 0);
2941 /* calculate class checkcast code size */
2943 s3 = 8 + (s1 == REG_ITMP1);
2945 s3 += (opt_showdisassemble ? 1 : 0);
2947 /* if class is not resolved, check which code to call */
2951 M_BEQ(3 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
2953 disp = dseg_adds4(cd, 0); /* super->flags */
2955 codegen_addpatchref(cd, mcodeptr,
2956 PATCHER_checkcast_instanceof_flags,
2957 (constant_classref *) iptr->target, disp);
2959 if (opt_showdisassemble)
2962 M_ILD(REG_ITMP2, REG_PV, disp);
2963 M_AND_IMM(REG_ITMP2, ACC_INTERFACE, REG_ITMP2);
2967 /* interface checkcast code */
2969 if (!super || (super->flags & ACC_INTERFACE)) {
2975 codegen_addpatchref(cd, mcodeptr,
2976 PATCHER_checkcast_instanceof_interface,
2977 (constant_classref *) iptr->target, 0);
2979 if (opt_showdisassemble)
2983 M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2984 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2985 M_LDATST(REG_ITMP3, REG_ITMP3, -superindex);
2987 codegen_addxcastrefs(cd, mcodeptr);
2988 M_ALD(REG_ITMP3, REG_ITMP2,
2989 OFFSET(vftbl_t, interfacetable[0]) -
2990 superindex * sizeof(methodptr*));
2993 codegen_addxcastrefs(cd, mcodeptr);
2999 /* class checkcast code */
3001 if (!super || !(super->flags & ACC_INTERFACE)) {
3002 disp = dseg_addaddress(cd, supervftbl);
3009 codegen_addpatchref(cd, mcodeptr,
3010 PATCHER_checkcast_class,
3011 (constant_classref *) iptr->target,
3014 if (opt_showdisassemble)
3018 M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
3019 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3020 codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
3022 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
3023 M_ALD(REG_ITMP2, REG_PV, disp);
3024 if (s1 != REG_ITMP1) {
3025 M_ILD(REG_ITMP1, REG_ITMP2, OFFSET(vftbl_t, baseval));
3026 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
3027 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3028 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
3030 M_ISUB(REG_ITMP3, REG_ITMP1, REG_ITMP3);
3032 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
3033 M_ISUB(REG_ITMP3, REG_ITMP2, REG_ITMP3);
3034 M_ALD(REG_ITMP2, REG_PV, disp);
3035 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
3036 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3037 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
3040 M_CMPU(REG_ITMP3, REG_ITMP2);
3042 codegen_addxcastrefs(cd, mcodeptr);
3044 d = reg_of_var(rd, iptr->dst, s1);
3047 /* array type cast-check */
3049 var_to_reg_int(s1, src, rd->argintregs[0]);
3050 M_INTMOVE(s1, rd->argintregs[0]);
3052 disp = dseg_addaddress(cd, iptr->val.a);
3054 if (iptr->val.a == NULL) {
3055 codegen_addpatchref(cd, mcodeptr,
3056 PATCHER_builtin_arraycheckcast,
3057 (constant_classref *) iptr->target,
3060 if (opt_showdisassemble)
3064 M_ALD(rd->argintregs[1], REG_PV, disp);
3065 disp = dseg_addaddress(cd, BUILTIN_arraycheckcast);
3066 M_ALD(REG_ITMP2, REG_PV, disp);
3071 codegen_addxcastrefs(cd, mcodeptr);
3073 var_to_reg_int(s1, src, REG_ITMP1);
3074 d = reg_of_var(rd, iptr->dst, s1);
3077 store_reg_to_var_adr(iptr->dst, d);
3080 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
3081 /* val.a: (classinfo*) superclass */
3083 /* superclass is an interface:
3085 * return (sub != NULL) &&
3086 * (sub->vftbl->interfacetablelength > super->index) &&
3087 * (sub->vftbl->interfacetable[-super->index] != NULL);
3089 * superclass is a class:
3091 * return ((sub != NULL) && (0
3092 * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
3093 * super->vftbl->diffvall));
3098 vftbl_t *supervftbl;
3101 super = (classinfo *) iptr->val.a;
3108 superindex = super->index;
3109 supervftbl = super->vftbl;
3112 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3113 codegen_threadcritrestart(cd, (u1*) mcodeptr - cd->mcodebase);
3115 var_to_reg_int(s1, src, REG_ITMP1);
3116 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
3118 M_MOV(s1, REG_ITMP1);
3122 /* calculate interface instanceof code size */
3126 s2 += (opt_showdisassemble ? 1 : 0);
3128 /* calculate class instanceof code size */
3132 s3 += (opt_showdisassemble ? 1 : 0);
3136 /* if class is not resolved, check which code to call */
3140 M_BEQ(3 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
3142 disp = dseg_adds4(cd, 0); /* super->flags */
3144 codegen_addpatchref(cd, mcodeptr,
3145 PATCHER_checkcast_instanceof_flags,
3146 (constant_classref *) iptr->target, disp);
3148 if (opt_showdisassemble)
3151 M_ILD(REG_ITMP3, REG_PV, disp);
3152 M_AND_IMM(REG_ITMP3, ACC_INTERFACE, REG_ITMP3);
3156 /* interface instanceof code */
3158 if (!super || (super->flags & ACC_INTERFACE)) {
3164 codegen_addpatchref(cd, mcodeptr,
3165 PATCHER_checkcast_instanceof_interface,
3166 (constant_classref *) iptr->target, 0);
3168 if (opt_showdisassemble)
3172 M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3173 M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
3174 M_LDATST(REG_ITMP3, REG_ITMP3, -superindex);
3176 M_ALD(REG_ITMP1, REG_ITMP1,
3177 OFFSET(vftbl_t, interfacetable[0]) -
3178 superindex * sizeof(methodptr*));
3181 M_IADD_IMM(REG_ZERO, 1, d);
3187 /* class instanceof code */
3189 if (!super || !(super->flags & ACC_INTERFACE)) {
3190 disp = dseg_addaddress(cd, supervftbl);
3197 codegen_addpatchref(cd, mcodeptr,
3198 PATCHER_instanceof_class,
3199 (constant_classref *) iptr->target,
3202 if (opt_showdisassemble) {
3207 M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3208 M_ALD(REG_ITMP2, REG_PV, disp);
3209 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3210 codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
3212 M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
3213 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
3214 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
3215 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3216 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
3218 M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
3219 M_CMPU(REG_ITMP1, REG_ITMP2);
3222 M_IADD_IMM(REG_ZERO, 1, d);
3224 store_reg_to_var_int(iptr->dst, d);
3228 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
3229 /* op1 = dimension, val.a = class */
3231 /* check for negative sizes and copy sizes to stack if necessary */
3233 MCODECHECK((iptr->op1 << 1) + 64);
3235 for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
3236 /* copy SAVEDVAR sizes to stack */
3238 if (src->varkind != ARGVAR) {
3239 var_to_reg_int(s2, src, REG_ITMP1);
3240 #if defined(__DARWIN__)
3241 M_IST(s2, REG_SP, LA_SIZE + (s1 + INT_ARG_CNT) * 4);
3243 M_IST(s2, REG_SP, LA_SIZE + (s1 + 3) * 4);
3248 /* a0 = dimension count */
3250 ICONST(rd->argintregs[0], iptr->op1);
3252 /* is patcher function set? */
3254 if (iptr->val.a == NULL) {
3255 disp = dseg_addaddress(cd, NULL);
3257 codegen_addpatchref(cd, mcodeptr,
3258 PATCHER_builtin_multianewarray,
3259 (constant_classref *) iptr->target,
3262 if (opt_showdisassemble)
3266 disp = dseg_addaddress(cd, iptr->val.a);
3269 /* a1 = arraydescriptor */
3271 M_ALD(rd->argintregs[1], REG_PV, disp);
3273 /* a2 = pointer to dimensions = stack pointer */
3275 #if defined(__DARWIN__)
3276 M_LDA(rd->argintregs[2], REG_SP, LA_SIZE + INT_ARG_CNT * 4);
3278 M_LDA(rd->argintregs[2], REG_SP, LA_SIZE + 3 * 4);
3281 disp = dseg_addaddress(cd, BUILTIN_multianewarray);
3282 M_ALD(REG_ITMP3, REG_PV, disp);
3286 /* check for exception before result assignment */
3288 M_CMPI(REG_RESULT, 0);
3290 codegen_addxexceptionrefs(cd, mcodeptr);
3292 d = reg_of_var(rd, iptr->dst, REG_RESULT);
3293 M_INTMOVE(REG_RESULT, d);
3294 store_reg_to_var_adr(iptr->dst, d);
3299 new_internalerror("Unknown ICMD %d", iptr->opc);
3303 } /* for instruction */
3305 /* copy values to interface registers */
3307 src = bptr->outstack;
3308 len = bptr->outdepth;
3309 MCODECHECK(64 + len);
3310 #if defined(ENABLE_LSRA)
3315 if ((src->varkind != STACKVAR)) {
3317 if (IS_FLT_DBL_TYPE(s2)) {
3318 var_to_reg_flt(s1, src, REG_FTMP1);
3319 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
3320 M_FLTMOVE(s1, rd->interfaces[len][s2].regoff);
3323 M_DST(s1, REG_SP, rd->interfaces[len][s2].regoff * 4);
3327 var_to_reg_int(s1, src, REG_ITMP1);
3328 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
3329 M_TINTMOVE(s2, s1, rd->interfaces[len][s2].regoff);
3332 if (IS_2_WORD_TYPE(s2)) {
3333 M_IST(GET_HIGH_REG(s1),
3334 REG_SP, rd->interfaces[len][s2].regoff * 4);
3335 M_IST(GET_LOW_REG(s1), REG_SP,
3336 rd->interfaces[len][s2].regoff * 4 + 4);
3338 M_IST(s1, REG_SP, rd->interfaces[len][s2].regoff * 4);
3346 } /* if (bptr -> flags >= BBREACHED) */
3347 } /* for basic block */
3349 dseg_createlinenumbertable(cd);
3356 /* generate ArithemticException check stubs */
3360 for (bref = cd->xdivrefs; bref != NULL; bref = bref->next) {
3361 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3363 (u1 *) mcodeptr - cd->mcodebase);
3367 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3369 if (xcodeptr != NULL) {
3370 disp = xcodeptr - mcodeptr - 1;
3374 xcodeptr = mcodeptr;
3376 if (m->isleafmethod) {
3378 M_AST(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3381 M_MOV(REG_PV, rd->argintregs[0]);
3382 M_MOV(REG_SP, rd->argintregs[1]);
3384 if (m->isleafmethod)
3385 M_MOV(REG_ZERO, rd->argintregs[2]);
3387 M_ALD(rd->argintregs[2],
3388 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3390 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3392 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 5 * 4));
3393 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3395 disp = dseg_addaddress(cd, stacktrace_inline_arithmeticexception);
3396 M_ALD(REG_ITMP1, REG_PV, disp);
3399 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3401 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3402 M_IADD_IMM(REG_SP, LA_SIZE + 5 * 4, REG_SP);
3404 if (m->isleafmethod) {
3405 M_ALD(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3409 disp = dseg_addaddress(cd, asm_handle_exception);
3410 M_ALD(REG_ITMP3, REG_PV, disp);
3416 /* generate ArrayIndexOutOfBoundsException stubs */
3420 for (bref = cd->xboundrefs; bref != NULL; bref = bref->next) {
3421 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3423 (u1 *) mcodeptr - cd->mcodebase);
3427 /* move index register into REG_ITMP1 */
3429 M_MOV(bref->reg, REG_ITMP1);
3431 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3433 if (xcodeptr != NULL) {
3434 disp = xcodeptr - mcodeptr - 1;
3438 xcodeptr = mcodeptr;
3440 if (m->isleafmethod) {
3442 M_AST(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3445 M_MOV(REG_PV, rd->argintregs[0]);
3446 M_MOV(REG_SP, rd->argintregs[1]);
3448 if (m->isleafmethod)
3449 M_MOV(REG_ZERO, rd->argintregs[2]);
3451 M_ALD(rd->argintregs[2],
3452 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3454 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3455 M_MOV(REG_ITMP1, rd->argintregs[4]);
3457 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 6 * 4));
3458 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 5 * 4);
3460 disp = dseg_addaddress(cd, stacktrace_inline_arrayindexoutofboundsexception);
3461 M_ALD(REG_ITMP1, REG_PV, disp);
3464 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3466 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 5 * 4);
3467 M_IADD_IMM(REG_SP, LA_SIZE + 6 * 4, REG_SP);
3469 if (m->isleafmethod) {
3470 M_ALD(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3474 disp = dseg_addaddress(cd, asm_handle_exception);
3475 M_ALD(REG_ITMP3, REG_PV, disp);
3481 /* generate ArrayStoreException check stubs */
3485 for (bref = cd->xstorerefs; bref != NULL; bref = bref->next) {
3486 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3488 (u1 *) mcodeptr - cd->mcodebase);
3492 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3494 if (xcodeptr != NULL) {
3495 disp = xcodeptr - mcodeptr - 1;
3499 xcodeptr = mcodeptr;
3501 M_MOV(REG_PV, rd->argintregs[0]);
3502 M_MOV(REG_SP, rd->argintregs[1]);
3503 M_ALD(rd->argintregs[2],
3504 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3505 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3507 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 5 * 4));
3508 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3510 disp = dseg_addaddress(cd, stacktrace_inline_arraystoreexception);
3511 M_ALD(REG_ITMP1, REG_PV, disp);
3514 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3516 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3517 M_IADD_IMM(REG_SP, LA_SIZE + 5 * 4, REG_SP);
3519 disp = dseg_addaddress(cd, asm_handle_exception);
3520 M_ALD(REG_ITMP3, REG_PV, disp);
3526 /* generate ClassCastException stubs */
3530 for (bref = cd->xcastrefs; bref != NULL; bref = bref->next) {
3531 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3533 (u1 *) mcodeptr - cd->mcodebase);
3537 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3539 if (xcodeptr != NULL) {
3540 disp = xcodeptr - mcodeptr - 1;
3544 xcodeptr = mcodeptr;
3546 if (m->isleafmethod) {
3548 M_AST(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3551 M_MOV(REG_PV, rd->argintregs[0]);
3552 M_MOV(REG_SP, rd->argintregs[1]);
3554 if (m->isleafmethod)
3555 M_MOV(REG_ZERO, rd->argintregs[2]);
3557 M_ALD(rd->argintregs[2],
3558 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3560 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3562 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 5 * 4));
3563 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3565 disp = dseg_addaddress(cd, stacktrace_inline_classcastexception);
3566 M_ALD(REG_ITMP1, REG_PV, disp);
3569 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3571 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3572 M_IADD_IMM(REG_SP, LA_SIZE + 5 * 4, REG_SP);
3574 if (m->isleafmethod) {
3575 M_ALD(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3579 disp = dseg_addaddress(cd, asm_handle_exception);
3580 M_ALD(REG_ITMP3, REG_PV, disp);
3586 /* generate NullPointerException stubs */
3590 for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
3591 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3593 (u1 *) mcodeptr - cd->mcodebase);
3597 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3599 if (xcodeptr != NULL) {
3600 disp = xcodeptr - mcodeptr - 1;
3604 xcodeptr = mcodeptr;
3606 if (m->isleafmethod) {
3608 M_AST(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3611 M_MOV(REG_PV, rd->argintregs[0]);
3612 M_MOV(REG_SP, rd->argintregs[1]);
3614 if (m->isleafmethod)
3615 M_MOV(REG_ZERO, rd->argintregs[2]);
3617 M_ALD(rd->argintregs[2],
3618 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3620 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3622 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 5 * 4));
3623 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3625 disp = dseg_addaddress(cd, stacktrace_inline_nullpointerexception);
3626 M_ALD(REG_ITMP1, REG_PV, disp);
3629 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3631 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3632 M_IADD_IMM(REG_SP, LA_SIZE + 5 * 4, REG_SP);
3634 if (m->isleafmethod) {
3635 M_ALD(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3639 disp = dseg_addaddress(cd, asm_handle_exception);
3640 M_ALD(REG_ITMP3, REG_PV, disp);
3646 /* generate exception check stubs */
3650 for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
3651 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3653 (u1 *) mcodeptr - cd->mcodebase);
3657 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3659 if (xcodeptr != NULL) {
3660 disp = xcodeptr - mcodeptr - 1;
3664 xcodeptr = mcodeptr;
3666 M_MOV(REG_PV, rd->argintregs[0]);
3667 M_MOV(REG_SP, rd->argintregs[1]);
3668 M_ALD(rd->argintregs[2],
3669 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3670 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3672 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 5 * 4));
3673 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3675 disp = dseg_addaddress(cd, stacktrace_inline_fillInStackTrace);
3676 M_ALD(REG_ITMP1, REG_PV, disp);
3679 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3681 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3682 M_IADD_IMM(REG_SP, LA_SIZE + 5 * 4, REG_SP);
3684 disp = dseg_addaddress(cd, asm_handle_exception);
3685 M_ALD(REG_ITMP3, REG_PV, disp);
3691 /* generate patcher stub call code */
3698 for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
3699 /* check code segment size */
3703 /* Get machine code which is patched back in later. The call is */
3704 /* 1 instruction word long. */
3706 xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
3709 /* patch in the call to call the following code (done at compile */
3712 tmpmcodeptr = mcodeptr; /* save current mcodeptr */
3713 mcodeptr = xcodeptr; /* set mcodeptr to patch position */
3715 M_BR(tmpmcodeptr - (xcodeptr + 1));
3717 mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
3719 /* create stack frame - keep stack 16-byte aligned */
3721 M_AADD_IMM(REG_SP, -8 * 4, REG_SP);
3723 /* calculate return address and move it onto the stack */
3725 M_LDA(REG_ITMP3, REG_PV, pref->branchpos);
3726 M_AST_INTERN(REG_ITMP3, REG_SP, 5 * 4);
3728 /* move pointer to java_objectheader onto stack */
3730 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3731 /* order reversed because of data segment layout */
3733 (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */
3734 disp = dseg_addaddress(cd, NULL); /* vftbl */
3736 M_LDA(REG_ITMP3, REG_PV, disp);
3737 M_AST_INTERN(REG_ITMP3, REG_SP, 4 * 4);
3742 /* move machine code onto stack */
3744 disp = dseg_adds4(cd, mcode);
3745 M_ILD(REG_ITMP3, REG_PV, disp);
3746 M_IST_INTERN(REG_ITMP3, REG_SP, 3 * 4);
3748 /* move class/method/field reference onto stack */
3750 disp = dseg_addaddress(cd, pref->ref);
3751 M_ALD(REG_ITMP3, REG_PV, disp);
3752 M_AST_INTERN(REG_ITMP3, REG_SP, 2 * 4);
3754 /* move data segment displacement onto stack */
3756 disp = dseg_addaddress(cd, pref->disp);
3757 M_ILD(REG_ITMP3, REG_PV, disp);
3758 M_IST_INTERN(REG_ITMP3, REG_SP, 1 * 4);
3760 /* move patcher function pointer onto stack */
3762 disp = dseg_addaddress(cd, pref->patcher);
3763 M_ALD(REG_ITMP3, REG_PV, disp);
3764 M_AST_INTERN(REG_ITMP3, REG_SP, 0 * 4);
3766 disp = dseg_addaddress(cd, asm_wrapper_patcher);
3767 M_ALD(REG_ITMP3, REG_PV, disp);
3775 codegen_finish(m, cd, (ptrint) ((u1 *) mcodeptr - cd->mcodebase));
3777 asm_cacheflush((void *) (ptrint) m->entrypoint, ((u1 *) mcodeptr - cd->mcodebase));
3779 /* everything's ok */
3785 /* createcompilerstub **********************************************************
3787 Creates a stub routine which calls the compiler.
3789 *******************************************************************************/
3791 #define COMPILERSTUB_DATASIZE 2 * SIZEOF_VOID_P
3792 #define COMPILERSTUB_CODESIZE 4 * 4
3794 #define COMPILERSTUB_SIZE COMPILERSTUB_DATASIZE + COMPILERSTUB_CODESIZE
3797 u1 *createcompilerstub(methodinfo *m)
3799 u1 *s; /* memory to hold the stub */
3801 s4 *mcodeptr; /* code generation pointer */
3803 s = CNEW(u1, COMPILERSTUB_SIZE);
3805 /* set data pointer and code pointer */
3808 s = s + COMPILERSTUB_DATASIZE;
3810 mcodeptr = (s4 *) s;
3812 /* Store the methodinfo* in the same place as in the methodheader
3813 for compiled methods. */
3815 d[0] = (ptrint) asm_call_jit_compiler;
3818 M_ALD_INTERN(REG_ITMP1, REG_PV, -1 * SIZEOF_VOID_P);
3819 M_ALD_INTERN(REG_PV, REG_PV, -2 * SIZEOF_VOID_P);
3823 asm_cacheflush((void *) d, COMPILERSTUB_SIZE);
3825 #if defined(ENABLE_STATISTICS)
3827 count_cstub_len += COMPILERSTUB_SIZE;
3834 /* createnativestub ************************************************************
3836 Creates a stub routine which calls a native method.
3838 *******************************************************************************/
3840 u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
3841 registerdata *rd, methoddesc *nmd)
3843 s4 *mcodeptr; /* code generation pointer */
3844 s4 stackframesize; /* size of stackframe if needed */
3847 s4 i, j; /* count variables */
3852 /* set some variables */
3855 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
3857 /* calculate stackframe size */
3860 sizeof(stackframeinfo) / SIZEOF_VOID_P +
3861 sizeof(localref_table) / SIZEOF_VOID_P +
3862 4 + /* 4 stackframeinfo arguments (darwin)*/
3863 nmd->paramcount * 2 + /* assume all arguments are doubles */
3866 stackframesize = (stackframesize + 3) & ~3; /* keep stack 16-byte aligned */
3869 /* create method header */
3871 (void) dseg_addaddress(cd, m); /* MethodPointer */
3872 (void) dseg_adds4(cd, stackframesize * 4); /* FrameSize */
3873 (void) dseg_adds4(cd, 0); /* IsSync */
3874 (void) dseg_adds4(cd, 0); /* IsLeaf */
3875 (void) dseg_adds4(cd, 0); /* IntSave */
3876 (void) dseg_adds4(cd, 0); /* FltSave */
3877 (void) dseg_addlinenumbertablesize(cd);
3878 (void) dseg_adds4(cd, 0); /* ExTableSize */
3881 /* initialize mcode variables */
3883 mcodeptr = (s4 *) cd->mcodebase;
3889 M_AST_INTERN(REG_ZERO, REG_SP, LA_LR_OFFSET);
3890 M_STWU(REG_SP, REG_SP, -(stackframesize * 4));
3894 /* parent_argbase == stackframesize * 4 */
3895 mcodeptr = codegen_trace_args(m, cd, rd, mcodeptr, stackframesize * 4 ,
3900 /* get function address (this must happen before the stackframeinfo) */
3902 funcdisp = dseg_addaddress(cd, f);
3904 #if !defined(WITH_STATIC_CLASSPATH)
3906 codegen_addpatchref(cd, mcodeptr, PATCHER_resolve_native, m, funcdisp);
3908 if (opt_showdisassemble)
3913 /* save integer and float argument registers */
3915 for (i = 0, j = 0; i < md->paramcount && j < INT_ARG_CNT; i++) {
3916 t = md->paramtypes[i].type;
3918 if (IS_INT_LNG_TYPE(t)) {
3919 s1 = md->params[i].regoff;
3920 if (IS_2_WORD_TYPE(t)) {
3921 M_IST(rd->argintregs[GET_HIGH_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3923 M_IST(rd->argintregs[GET_LOW_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3926 M_IST(rd->argintregs[s1], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3932 for (i = 0; i < md->paramcount && j < FLT_ARG_CNT; i++) {
3933 if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
3934 s1 = md->params[i].regoff;
3935 M_DST(rd->argfltregs[s1], REG_SP, LA_SIZE + 4 * 4 + j * 8);
3940 /* create native stack info */
3942 M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[0]);
3943 M_MOV(REG_PV, rd->argintregs[1]);
3944 M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[2]);
3945 M_ALD(rd->argintregs[3], REG_SP, stackframesize * 4 + LA_LR_OFFSET);
3946 disp = dseg_addaddress(cd, codegen_start_native_call);
3947 M_ALD(REG_ITMP1, REG_PV, disp);
3951 /* restore integer and float argument registers */
3953 for (i = 0, j = 0; i < md->paramcount && j < INT_ARG_CNT; i++) {
3954 t = md->paramtypes[i].type;
3956 if (IS_INT_LNG_TYPE(t)) {
3957 s1 = md->params[i].regoff;
3959 if (IS_2_WORD_TYPE(t)) {
3960 M_ILD(rd->argintregs[GET_HIGH_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3962 M_ILD(rd->argintregs[GET_LOW_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3965 M_ILD(rd->argintregs[s1], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3971 for (i = 0; i < md->paramcount && j < FLT_ARG_CNT; i++) {
3972 if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
3973 s1 = md->params[i].regoff;
3974 M_DLD(rd->argfltregs[i], REG_SP, LA_SIZE + 4 * 4 + j * 8);
3979 /* copy or spill arguments to new locations */
3981 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
3982 t = md->paramtypes[i].type;
3984 if (IS_INT_LNG_TYPE(t)) {
3985 if (!md->params[i].inmemory) {
3986 if (IS_2_WORD_TYPE(t))
3988 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
3989 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
3991 s1 = rd->argintregs[md->params[i].regoff];
3993 if (!nmd->params[j].inmemory) {
3994 if (IS_2_WORD_TYPE(t))
3996 rd->argintregs[GET_LOW_REG(nmd->params[j].regoff)],
3997 rd->argintregs[GET_HIGH_REG(nmd->params[j].regoff)]);
3999 s2 = rd->argintregs[nmd->params[j].regoff];
4000 M_TINTMOVE(t, s1, s2);
4003 s2 = nmd->params[j].regoff;
4004 if (IS_2_WORD_TYPE(t)) {
4005 M_IST(GET_HIGH_REG(s1), REG_SP, s2 * 4);
4006 M_IST(GET_LOW_REG(s1), REG_SP, s2 * 4 + 4);
4008 M_IST(s1, REG_SP, s2 * 4);
4013 s1 = md->params[i].regoff + stackframesize;
4014 s2 = nmd->params[j].regoff;
4016 M_ILD(REG_ITMP1, REG_SP, s1 * 4);
4017 if (IS_2_WORD_TYPE(t)) {
4018 M_ILD(REG_ITMP2, REG_SP, s1 * 4 + 4);
4020 M_IST(REG_ITMP1, REG_SP, s2 * 4);
4021 if (IS_2_WORD_TYPE(t)) {
4022 M_IST(REG_ITMP2, REG_SP, s2 * 4 + 4);
4027 /* We only copy spilled float arguments, as the float argument */
4028 /* registers keep unchanged. */
4030 if (md->params[i].inmemory) {
4031 s1 = md->params[i].regoff + stackframesize;
4032 s2 = nmd->params[j].regoff;
4034 if (IS_2_WORD_TYPE(t)) {
4035 M_DLD(REG_FTMP1, REG_SP, s1 * 4);
4036 M_DST(REG_FTMP1, REG_SP, s2 * 4);
4039 M_FLD(REG_FTMP1, REG_SP, s1 * 4);
4040 M_FST(REG_FTMP1, REG_SP, s2 * 4);
4046 /* put class into second argument register */
4048 if (m->flags & ACC_STATIC) {
4049 disp = dseg_addaddress(cd, m->class);
4050 M_ALD(rd->argintregs[1], REG_PV, disp);
4053 /* put env into first argument register */
4055 disp = dseg_addaddress(cd, _Jv_env);
4056 M_ALD(rd->argintregs[0], REG_PV, disp);
4058 /* generate the actual native call */
4060 M_ALD(REG_ITMP3, REG_PV, funcdisp);
4064 /* save return value */
4066 if (md->returntype.type != TYPE_VOID) {
4067 if (IS_INT_LNG_TYPE(md->returntype.type)) {
4068 if (IS_2_WORD_TYPE(md->returntype.type))
4069 M_IST(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
4070 M_IST(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
4072 if (IS_2_WORD_TYPE(md->returntype.type))
4073 M_DST(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4075 M_FST(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4079 /* remove native stackframe info */
4081 M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[0]);
4082 disp = dseg_addaddress(cd, codegen_finish_native_call);
4083 M_ALD(REG_ITMP1, REG_PV, disp);
4087 /* print call trace */
4090 /* just restore the value we need, don't care about the other */
4092 if (md->returntype.type != TYPE_VOID) {
4093 if (IS_INT_LNG_TYPE(md->returntype.type)) {
4094 if (IS_2_WORD_TYPE(md->returntype.type))
4095 M_ILD(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
4096 M_ILD(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
4098 if (IS_2_WORD_TYPE(md->returntype.type))
4099 M_DLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4101 M_FLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4105 M_LDA(REG_SP, REG_SP, -(LA_SIZE + (1 + 2 + 2 + 1) * 4));
4107 /* keep this order */
4108 switch (md->returntype.type) {
4111 #if defined(__DARWIN__)
4112 M_MOV(REG_RESULT, rd->argintregs[2]);
4113 M_CLR(rd->argintregs[1]);
4115 M_MOV(REG_RESULT, rd->argintregs[3]);
4116 M_CLR(rd->argintregs[2]);
4121 #if defined(__DARWIN__)
4122 M_MOV(REG_RESULT2, rd->argintregs[2]);
4123 M_MOV(REG_RESULT, rd->argintregs[1]);
4125 M_MOV(REG_RESULT2, rd->argintregs[3]);
4126 M_MOV(REG_RESULT, rd->argintregs[2]);
4131 M_FLTMOVE(REG_FRESULT, rd->argfltregs[0]);
4132 M_FLTMOVE(REG_FRESULT, rd->argfltregs[1]);
4133 disp = dseg_addaddress(cd, m);
4134 M_ALD(rd->argintregs[0], REG_PV, disp);
4136 disp = dseg_addaddress(cd, builtin_displaymethodstop);
4137 M_ALD(REG_ITMP2, REG_PV, disp);
4141 M_LDA(REG_SP, REG_SP, LA_SIZE + (1 + 2 + 2 + 1) * 4);
4144 /* check for exception */
4146 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
4147 disp = dseg_addaddress(cd, builtin_get_exceptionptrptr);
4148 M_ALD(REG_ITMP1, REG_PV, disp);
4151 M_MOV(REG_RESULT, REG_ITMP2);
4153 disp = dseg_addaddress(cd, &_no_threads_exceptionptr);
4154 M_ALD(REG_ITMP2, REG_PV, disp);
4156 M_ALD(REG_ITMP1_XPTR, REG_ITMP2, 0);/* load exception into reg. itmp1 */
4158 /* restore return value */
4160 if (md->returntype.type != TYPE_VOID) {
4161 if (IS_INT_LNG_TYPE(md->returntype.type)) {
4162 if (IS_2_WORD_TYPE(md->returntype.type))
4163 M_ILD(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
4164 M_ILD(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
4166 if (IS_2_WORD_TYPE(md->returntype.type))
4167 M_DLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4169 M_FLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4173 M_TST(REG_ITMP1_XPTR);
4174 M_BNE(4); /* if no exception then return */
4176 M_ALD(REG_ZERO, REG_SP, stackframesize * 4 + LA_LR_OFFSET); /* load ra */
4178 M_LDA(REG_SP, REG_SP, stackframesize * 4); /* remove stackframe */
4181 /* handle exception */
4184 M_AST(REG_ITMP3, REG_ITMP2, 0); /* store NULL into exceptionptr */
4186 M_ALD(REG_ITMP2, REG_SP, stackframesize * 4 + LA_LR_OFFSET); /* load ra */
4189 M_LDA(REG_SP, REG_SP, stackframesize * 4); /* remove stackframe */
4191 M_IADD_IMM(REG_ITMP2, -4, REG_ITMP2_XPC); /* fault address */
4193 disp = dseg_addaddress(cd, asm_handle_nat_exception);
4194 M_ALD(REG_ITMP3, REG_PV, disp);
4198 /* generate patcher stub call code */
4206 for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
4207 /* Get machine code which is patched back in later. The call is */
4208 /* 1 instruction word long. */
4210 xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
4211 mcode = (u4) *xcodeptr;
4213 /* patch in the call to call the following code (done at compile */
4216 tmpmcodeptr = mcodeptr; /* save current mcodeptr */
4217 mcodeptr = xcodeptr; /* set mcodeptr to patch position */
4219 M_BL(tmpmcodeptr - (xcodeptr + 1));
4221 mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
4223 /* create stack frame - keep stack 16-byte aligned */
4225 M_AADD_IMM(REG_SP, -8 * 4, REG_SP);
4227 /* move return address onto stack */
4230 M_AST(REG_ZERO, REG_SP, 5 * 4);
4232 /* move pointer to java_objectheader onto stack */
4234 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
4235 /* order reversed because of data segment layout */
4237 (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */
4238 disp = dseg_addaddress(cd, NULL); /* vftbl */
4240 M_LDA(REG_ITMP3, REG_PV, disp);
4241 M_AST(REG_ITMP3, REG_SP, 4 * 4);
4246 /* move machine code onto stack */
4248 disp = dseg_adds4(cd, mcode);
4249 M_ILD(REG_ITMP3, REG_PV, disp);
4250 M_IST(REG_ITMP3, REG_SP, 3 * 4);
4252 /* move class/method/field reference onto stack */
4254 disp = dseg_addaddress(cd, pref->ref);
4255 M_ALD(REG_ITMP3, REG_PV, disp);
4256 M_AST(REG_ITMP3, REG_SP, 2 * 4);
4258 /* move data segment displacement onto stack */
4260 disp = dseg_addaddress(cd, pref->disp);
4261 M_ILD(REG_ITMP3, REG_PV, disp);
4262 M_IST(REG_ITMP3, REG_SP, 1 * 4);
4264 /* move patcher function pointer onto stack */
4266 disp = dseg_addaddress(cd, pref->patcher);
4267 M_ALD(REG_ITMP3, REG_PV, disp);
4268 M_AST(REG_ITMP3, REG_SP, 0 * 4);
4270 disp = dseg_addaddress(cd, asm_wrapper_patcher);
4271 M_ALD(REG_ITMP3, REG_PV, disp);
4277 codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
4279 asm_cacheflush((void *) (ptrint) m->entrypoint, ((u1 *) mcodeptr - cd->mcodebase));
4281 return m->entrypoint;
4285 s4 *codegen_trace_args(methodinfo *m, codegendata *cd, registerdata *rd,
4286 s4 *mcodeptr, s4 parentargs_base, bool nativestub)
4297 /* Build up Stackframe for builtin_trace_args call (a multiple of 16) */
4299 /* LA + TRACE_ARGS_NUM u8 args + methodinfo + LR */
4300 /* LA_SIZE(=6*4) + 8*8 + 4 + 4 + 0(Padding) */
4301 /* 6 * 4 + 8 * 8 + 2 * 4 = 12 * 8 = 6 * 16 */
4303 /* LA + (TRACE_ARGS_NUM - INT_ARG_CNT/2) u8 args + methodinfo */
4304 /* + INT_ARG_CNT * 4 ( save integer registers) + LR + 8 + 8 (Padding) */
4305 /* LA_SIZE(=2*4) + 4 * 8 + 4 + 8 * 4 + 4 + 8 */
4306 /* 2 * 4 + 4 * 8 + 10 * 4 + 1 * 8 + 8= 12 * 8 = 6 * 16 */
4308 /* in nativestubs no Place to save the LR (Link Register) would be needed */
4309 /* but since the stack frame has to be aligned the 4 Bytes would have to */
4310 /* be padded again */
4312 #if defined(__DARWIN__)
4313 stack_size = LA_SIZE + (TRACE_ARGS_NUM + 1) * 8;
4315 stack_size = 6 * 16;
4317 M_LDA(REG_SP, REG_SP, -stack_size);
4321 M_IST(REG_ITMP3, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8 + 1 * 4);
4323 M_CLR(REG_ITMP1); /* clear help register */
4325 /* save up to TRACE_ARGS_NUM arguments into the reserved stack space */
4326 #if defined(__DARWIN__)
4327 /* Copy Params starting from first to Stack */
4328 /* since TRACE_ARGS == INT_ARG_CNT all used integer argument regs */
4332 /* Copy Params starting from fifth to Stack (INT_ARG_CNT/2) are in */
4333 /* integer argument regs */
4334 /* all integer argument registers have to be saved */
4335 for (p = 0; p < 8; p++) {
4336 d = rd->argintregs[p];
4337 /* save integer argument registers */
4338 M_IST(d, REG_SP, LA_SIZE + 4 * 8 + 4 + p * 4);
4342 stack_off = LA_SIZE;
4343 for (; p < md->paramcount && p < TRACE_ARGS_NUM; p++, stack_off += 8) {
4344 t = md->paramtypes[p].type;
4345 if (IS_INT_LNG_TYPE(t)) {
4346 if (!md->params[p].inmemory) { /* Param in Arg Reg */
4347 if (IS_2_WORD_TYPE(t)) {
4348 M_IST(rd->argintregs[GET_HIGH_REG(md->params[p].regoff)]
4349 , REG_SP, stack_off);
4350 M_IST(rd->argintregs[GET_LOW_REG(md->params[p].regoff)]
4351 , REG_SP, stack_off + 4);
4353 M_IST(REG_ITMP1, REG_SP, stack_off);
4354 M_IST(rd->argintregs[md->params[p].regoff]
4355 , REG_SP, stack_off + 4);
4357 } else { /* Param on Stack */
4358 s1 = (md->params[p].regoff + parentargs_base) * 4
4360 if (IS_2_WORD_TYPE(t)) {
4361 M_ILD(REG_ITMP2, REG_SP, s1);
4362 M_IST(REG_ITMP2, REG_SP, stack_off);
4363 M_ILD(REG_ITMP2, REG_SP, s1 + 4);
4364 M_IST(REG_ITMP2, REG_SP, stack_off + 4);
4366 M_IST(REG_ITMP1, REG_SP, stack_off);
4367 M_ILD(REG_ITMP2, REG_SP, s1);
4368 M_IST(REG_ITMP2, REG_SP, stack_off + 4);
4371 } else { /* IS_FLT_DBL_TYPE(t) */
4372 if (!md->params[p].inmemory) { /* in Arg Reg */
4373 s1 = rd->argfltregs[md->params[p].regoff];
4374 if (!IS_2_WORD_TYPE(t)) {
4375 M_IST(REG_ITMP1, REG_SP, stack_off);
4376 M_FST(s1, REG_SP, stack_off + 4);
4378 M_DST(s1, REG_SP, stack_off);
4380 } else { /* on Stack */
4381 /* this should not happen */
4386 /* load first 4 (==INT_ARG_CNT/2) arguments into integer registers */
4387 #if defined(__DARWIN__)
4388 for (p = 0; p < 8; p++) {
4389 d = rd->argintregs[p];
4390 M_ILD(d, REG_SP, LA_SIZE + p * 4);
4394 /* Set integer and float argument registers vor trace_args call */
4395 /* offset to saved integer argument registers */
4396 stack_off = LA_SIZE + 4 * 8 + 4;
4397 for (p = 0; (p < 4) && (p < md->paramcount); p++) {
4398 t = md->paramtypes[p].type;
4399 if (IS_INT_LNG_TYPE(t)) {
4400 /* "stretch" int types */
4401 if (!IS_2_WORD_TYPE(t)) {
4402 M_CLR(rd->argintregs[2 * p]);
4403 M_ILD(rd->argintregs[2 * p + 1], REG_SP,stack_off);
4406 M_ILD(rd->argintregs[2 * p + 1], REG_SP,stack_off + 4);
4407 M_ILD(rd->argintregs[2 * p], REG_SP,stack_off);
4410 } else { /* Float/Dbl */
4411 if (!md->params[p].inmemory) { /* Param in Arg Reg */
4412 /* use reserved Place on Stack (sp + 5 * 16) to copy */
4413 /* float/double arg reg to int reg */
4414 s1 = rd->argfltregs[md->params[p].regoff];
4415 if (!IS_2_WORD_TYPE(t)) {
4416 M_FST(s1, REG_SP, 5 * 16);
4417 M_ILD(rd->argintregs[2 * p + 1], REG_SP, 5 * 16);
4418 M_CLR(rd->argintregs[2 * p]);
4420 M_DST(s1, REG_SP, 5 * 16);
4421 M_ILD(rd->argintregs[2 * p + 1], REG_SP, 5 * 16 + 4);
4422 M_ILD(rd->argintregs[2 * p], REG_SP, 5 * 16);
4429 /* put methodinfo pointer on Stackframe */
4430 p = dseg_addaddress(cd, m);
4431 M_ALD(REG_ITMP1, REG_PV, p);
4432 #if defined(__DARWIN__)
4433 M_AST(REG_ITMP1, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8);
4435 M_AST(REG_ITMP1, REG_SP, LA_SIZE + 4 * 8);
4437 p = dseg_addaddress(cd, builtin_trace_args);
4438 M_ALD(REG_ITMP2, REG_PV, p);
4442 #if defined(__DARWIN__)
4443 /* restore integer argument registers from the reserved stack space */
4445 stack_off = LA_SIZE;
4446 for (p = 0; p < md->paramcount && p < TRACE_ARGS_NUM;
4447 p++, stack_off += 8) {
4448 t = md->paramtypes[p].type;
4450 if (IS_INT_LNG_TYPE(t)) {
4451 if (!md->params[p].inmemory) {
4452 if (IS_2_WORD_TYPE(t)) {
4453 M_ILD(rd->argintregs[GET_HIGH_REG(md->params[p].regoff)]
4454 , REG_SP, stack_off);
4455 M_ILD(rd->argintregs[GET_LOW_REG(md->params[p].regoff)]
4456 , REG_SP, stack_off + 4);
4458 M_ILD(rd->argintregs[md->params[p].regoff]
4459 , REG_SP, stack_off + 4);
4466 for (p = 0; p < 8; p++) {
4467 d = rd->argintregs[p];
4468 /* save integer argument registers */
4469 M_ILD(d, REG_SP, LA_SIZE + 4 * 8 + 4 + p * 4);
4474 M_ILD(REG_ITMP3, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8 + 1 * 4);
4476 M_LDA(REG_SP, REG_SP, stack_size);
4483 * These are local overrides for various environment variables in Emacs.
4484 * Please do not remove this and leave it at the end of the file, where
4485 * Emacs will automagically detect them.
4486 * ---------------------------------------------------------------------
4489 * indent-tabs-mode: t