1 /* src/vm/jit/powerpc/codegen.c - machine code generator for 32-bit PowerPC
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Andreas Krall
30 Changes: Christian Thalinger
33 $Id: codegen.c 3870 2005-12-03 16:09:21Z twisti $
48 #include "vm/jit/powerpc/arch.h"
49 #include "vm/jit/powerpc/codegen.h"
51 #include "cacao/cacao.h"
52 #include "native/native.h"
53 #include "vm/builtin.h"
54 #include "vm/global.h"
55 #include "vm/loader.h"
56 #include "vm/stringlocal.h"
57 #include "vm/jit/asmpart.h"
58 #include "vm/jit/codegen.inc"
59 #include "vm/jit/jit.h"
62 # include "vm/jit/lsra.inc"
65 #include "vm/jit/parse.h"
66 #include "vm/jit/patcher.h"
67 #include "vm/jit/reg.h"
68 #include "vm/jit/reg.inc"
71 s4 *codegen_trace_args( methodinfo *m, codegendata *cd, registerdata *rd,
72 s4 *mcodeptr, s4 parentargs_base, bool nativestub);
74 /* codegen *********************************************************************
76 Generates machine code.
78 *******************************************************************************/
80 bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
82 s4 len, s1, s2, s3, d, disp;
92 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
93 builtintable_entry *bte;
96 /* prevent compiler warnings */
108 /* space to save used callee saved registers */
110 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
111 savedregs_num += 2 * (FLT_SAV_CNT - rd->savfltreguse);
113 parentargs_base = rd->memuse + savedregs_num;
115 #if defined(USE_THREADS)
116 /* space to save argument of monitor_enter and Return Values to survive */
117 /* monitor_exit. The stack position for the argument can not be shared */
118 /* with place to save the return register on PPC, since both values */
120 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
121 /* reserve 2 slots for long/double return values for monitorexit */
123 if (IS_2_WORD_TYPE(m->parseddesc->returntype.type))
124 parentargs_base += 3;
126 parentargs_base += 2;
131 /* create method header */
133 parentargs_base = (parentargs_base + 3) & ~3;
135 (void) dseg_addaddress(cd, m); /* MethodPointer */
136 (void) dseg_adds4(cd, parentargs_base * 4); /* FrameSize */
138 #if defined(USE_THREADS)
139 /* IsSync contains the offset relative to the stack pointer for the
140 argument of monitor_exit used in the exception handler. Since the
141 offset could be zero and give a wrong meaning of the flag it is
145 if (checksync && (m->flags & ACC_SYNCHRONIZED))
146 (void) dseg_adds4(cd, (rd->memuse + 1) * 4); /* IsSync */
149 (void) dseg_adds4(cd, 0); /* IsSync */
151 (void) dseg_adds4(cd, m->isleafmethod); /* IsLeaf */
152 (void) dseg_adds4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
153 (void) dseg_adds4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
155 dseg_addlinenumbertablesize(cd);
157 (void) dseg_adds4(cd, cd->exceptiontablelength); /* ExTableSize */
159 /* create exception table */
161 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
162 dseg_addtarget(cd, ex->start);
163 dseg_addtarget(cd, ex->end);
164 dseg_addtarget(cd, ex->handler);
165 (void) dseg_addaddress(cd, ex->catchtype.cls);
168 /* initialize mcode variables */
170 mcodeptr = (s4 *) cd->mcodebase;
171 cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
172 MCODECHECK(128 + m->paramcount);
174 /* create stack frame (if necessary) */
176 if (!m->isleafmethod) {
178 M_AST(REG_ZERO, REG_SP, LA_LR_OFFSET);
181 if (parentargs_base) {
182 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(REG_ITMP1, REG_PV, p);
321 M_AST(REG_ITMP1, REG_SP, s1 * 4);
322 M_MOV(REG_ITMP1, rd->argintregs[0]);
323 p = dseg_addaddress(cd, BUILTIN_staticmonitorenter);
324 M_ALD(REG_ITMP3, REG_PV, p);
329 M_TST(rd->argintregs[0]);
331 codegen_addxnullrefs(cd, mcodeptr);
332 M_AST(rd->argintregs[0], REG_SP, s1 * 4);
333 p = dseg_addaddress(cd, BUILTIN_monitorenter);
334 M_ALD(REG_ITMP3, REG_PV, p);
341 for (p = 0; p < INT_ARG_CNT; p++)
342 M_ILD(rd->argintregs[p], REG_SP, p * 4);
344 for (p = 0; p < FLT_ARG_CNT; p++)
345 M_DLD(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 4);
348 M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT) * 8);
354 /* call trace function */
357 mcodeptr = codegen_trace_args(m, cd, rd, mcodeptr, parentargs_base, false);
359 } /* if (runverbose) */
362 /* end of header generation */
364 /* walk through all basic blocks */
365 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
367 bptr->mpc = (s4) ((u1 *) mcodeptr - cd->mcodebase);
369 if (bptr->flags >= BBREACHED) {
371 /* branch resolving */
375 for (brefs = bptr->branchrefs; brefs != NULL; brefs = brefs->next) {
376 gen_resolvebranch((u1*) cd->mcodebase + brefs->branchpos,
382 /* copy interface registers to their destination */
390 while (src != NULL) {
392 if ((len == 0) && (bptr->type != BBTYPE_STD)) {
393 /* d = reg_of_var(m, src, REG_ITMP1); */
394 if (!(src->flags & INMEMORY))
398 M_INTMOVE(REG_ITMP1, d);
399 store_reg_to_var_int(src, d);
405 while (src != NULL) {
407 if ((len == 0) && (bptr->type != BBTYPE_STD)) {
408 d = reg_of_var(rd, src, REG_ITMP1);
409 M_INTMOVE(REG_ITMP1, d);
410 store_reg_to_var_int(src, d);
412 if (src->type == TYPE_LNG)
413 d = reg_of_var(rd, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
415 d = reg_of_var(rd, src, REG_IFTMP);
416 if ((src->varkind != STACKVAR)) {
418 if (IS_FLT_DBL_TYPE(s2)) {
419 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
420 s1 = rd->interfaces[len][s2].regoff;
423 if (IS_2_WORD_TYPE(s2)) {
425 rd->interfaces[len][s2].regoff * 4);
428 rd->interfaces[len][s2].regoff * 4);
432 if (IS_2_WORD_TYPE(s2)) {
433 store_reg_to_var_dbl(src, d);
435 store_reg_to_var_flt(src, d);
438 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
439 s1 = rd->interfaces[len][s2].regoff;
440 M_TINTMOVE(s2, s1, d);
442 if (IS_2_WORD_TYPE(s2)) {
443 M_ILD(GET_HIGH_REG(d), REG_SP,
444 rd->interfaces[len][s2].regoff * 4);
445 M_ILD(GET_LOW_REG(d), REG_SP,
446 rd->interfaces[len][s2].regoff * 4 + 4);
449 rd->interfaces[len][s2].regoff * 4);
453 if (IS_2_WORD_TYPE(s2)) {
454 store_reg_to_var_lng(src, d);
456 store_reg_to_var_int(src, d);
467 /* walk through all instructions */
473 for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) {
474 if (iptr->line != currentline) {
475 dseg_addlinenumber(cd, iptr->line, (u1 *) mcodeptr);
476 currentline = iptr->line;
479 MCODECHECK(64); /* an instruction usually needs < 64 words */
482 case ICMD_NOP: /* ... ==> ... */
483 case ICMD_INLINE_START:
484 case ICMD_INLINE_END:
487 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
489 var_to_reg_int(s1, src, REG_ITMP1);
492 codegen_addxnullrefs(cd, mcodeptr);
495 /* constant operations ************************************************/
497 case ICMD_ICONST: /* ... ==> ..., constant */
498 /* op1 = 0, val.i = constant */
500 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
501 ICONST(d, iptr->val.i);
502 store_reg_to_var_int(iptr->dst, d);
505 case ICMD_LCONST: /* ... ==> ..., constant */
506 /* op1 = 0, val.l = constant */
508 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
509 LCONST(d, iptr->val.l);
510 store_reg_to_var_lng(iptr->dst, d);
513 case ICMD_FCONST: /* ... ==> ..., constant */
514 /* op1 = 0, val.f = constant */
516 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
517 a = dseg_addfloat(cd, iptr->val.f);
519 store_reg_to_var_flt(iptr->dst, d);
522 case ICMD_DCONST: /* ... ==> ..., constant */
523 /* op1 = 0, val.d = constant */
525 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
526 a = dseg_adddouble(cd, iptr->val.d);
528 store_reg_to_var_dbl(iptr->dst, d);
531 case ICMD_ACONST: /* ... ==> ..., constant */
532 /* op1 = 0, val.a = constant */
534 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
535 disp = dseg_addaddress(cd, iptr->val.a);
537 if ((iptr->target != NULL) && (iptr->val.a == NULL)) {
538 codegen_addpatchref(cd, mcodeptr,
540 (unresolved_class *) iptr->target, disp);
542 if (opt_showdisassemble)
546 M_ALD(d, REG_PV, disp);
547 store_reg_to_var_adr(iptr->dst, d);
551 /* load/store operations **********************************************/
553 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
554 case ICMD_ALOAD: /* op1 = local variable */
556 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
557 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
558 if ((iptr->dst->varkind == LOCALVAR) &&
559 (iptr->dst->varnum == iptr->op1))
561 if (var->flags & INMEMORY) {
562 M_ILD(d, REG_SP, var->regoff * 4);
564 M_TINTMOVE(var->type, var->regoff, d);
566 store_reg_to_var_int(iptr->dst, d);
569 case ICMD_LLOAD: /* ... ==> ..., content of local variable */
570 /* op1 = local variable */
572 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
573 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
574 if ((iptr->dst->varkind == LOCALVAR) &&
575 (iptr->dst->varnum == iptr->op1))
577 if (var->flags & INMEMORY) {
578 M_ILD(GET_HIGH_REG(d), REG_SP, var->regoff * 4);
579 M_ILD(GET_LOW_REG(d), REG_SP, var->regoff * 4 + 4);
581 M_TINTMOVE(var->type, var->regoff, d);
583 store_reg_to_var_lng(iptr->dst, d);
586 case ICMD_FLOAD: /* ... ==> ..., content of local variable */
587 /* op1 = local variable */
589 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
590 if ((iptr->dst->varkind == LOCALVAR) &&
591 (iptr->dst->varnum == iptr->op1))
593 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
594 if (var->flags & INMEMORY) {
595 M_FLD(d, REG_SP, var->regoff * 4);
597 M_FLTMOVE(var->regoff, d);
599 store_reg_to_var_flt(iptr->dst, d);
602 case ICMD_DLOAD: /* ... ==> ..., content of local variable */
603 /* op1 = local variable */
605 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
606 if ((iptr->dst->varkind == LOCALVAR) &&
607 (iptr->dst->varnum == iptr->op1))
609 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
610 if (var->flags & INMEMORY) {
611 M_DLD(d, REG_SP, var->regoff * 4);
613 M_FLTMOVE(var->regoff, d);
615 store_reg_to_var_dbl(iptr->dst, d);
619 case ICMD_ISTORE: /* ..., value ==> ... */
620 case ICMD_ASTORE: /* op1 = local variable */
622 if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1))
624 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
625 if (var->flags & INMEMORY) {
626 var_to_reg_int(s1, src, REG_ITMP1);
627 M_IST(s1, REG_SP, var->regoff * 4);
629 var_to_reg_int(s1, src, var->regoff);
630 M_TINTMOVE(var->type, s1, var->regoff);
634 case ICMD_LSTORE: /* ..., value ==> ... */
635 /* op1 = local variable */
637 if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1))
639 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
640 if (var->flags & INMEMORY) {
641 var_to_reg_int(s1, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
642 M_IST(GET_HIGH_REG(s1), REG_SP, var->regoff * 4);
643 M_IST(GET_LOW_REG(s1), REG_SP, var->regoff * 4 + 4);
645 var_to_reg_int(s1, src, var->regoff);
646 M_TINTMOVE(var->type, s1, var->regoff);
650 case ICMD_FSTORE: /* ..., value ==> ... */
651 case ICMD_DSTORE: /* op1 = local variable */
653 if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1))
655 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
656 if (var->flags & INMEMORY) {
657 var_to_reg_flt(s1, src, REG_FTMP1);
658 if (var->type == TYPE_DBL)
659 M_DST(s1, REG_SP, var->regoff * 4);
661 M_FST(s1, REG_SP, var->regoff * 4);
663 var_to_reg_flt(s1, src, var->regoff);
664 M_FLTMOVE(s1, var->regoff);
669 /* pop/dup/swap operations ********************************************/
671 /* attention: double and longs are only one entry in CACAO ICMDs */
673 case ICMD_POP: /* ..., value ==> ... */
674 case ICMD_POP2: /* ..., value, value ==> ... */
677 case ICMD_DUP: /* ..., a ==> ..., a, a */
678 M_COPY(src, iptr->dst);
681 case ICMD_DUP_X1: /* ..., a, b ==> ..., b, a, b */
683 M_COPY(src, iptr->dst);
684 M_COPY(src->prev, iptr->dst->prev);
685 M_COPY(iptr->dst, iptr->dst->prev->prev);
688 case ICMD_DUP_X2: /* ..., a, b, c ==> ..., c, a, b, c */
690 M_COPY(src, iptr->dst);
691 M_COPY(src->prev, iptr->dst->prev);
692 M_COPY(src->prev->prev, iptr->dst->prev->prev);
693 M_COPY(iptr->dst, iptr->dst->prev->prev->prev);
696 case ICMD_DUP2: /* ..., a, b ==> ..., a, b, a, b */
698 M_COPY(src, iptr->dst);
699 M_COPY(src->prev, iptr->dst->prev);
702 case ICMD_DUP2_X1: /* ..., a, b, c ==> ..., b, c, a, b, c */
704 M_COPY(src, iptr->dst);
705 M_COPY(src->prev, iptr->dst->prev);
706 M_COPY(src->prev->prev, iptr->dst->prev->prev);
707 M_COPY(iptr->dst, iptr->dst->prev->prev->prev);
708 M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev);
711 case ICMD_DUP2_X2: /* ..., a, b, c, d ==> ..., c, d, a, b, c, d */
713 M_COPY(src, iptr->dst);
714 M_COPY(src->prev, iptr->dst->prev);
715 M_COPY(src->prev->prev, iptr->dst->prev->prev);
716 M_COPY(src->prev->prev->prev, iptr->dst->prev->prev->prev);
717 M_COPY(iptr->dst, iptr->dst->prev->prev->prev->prev);
718 M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev->prev);
721 case ICMD_SWAP: /* ..., a, b ==> ..., b, a */
723 M_COPY(src, iptr->dst->prev);
724 M_COPY(src->prev, iptr->dst);
728 /* integer operations *************************************************/
730 case ICMD_INEG: /* ..., value ==> ..., - value */
732 var_to_reg_int(s1, src, REG_ITMP1);
733 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
735 store_reg_to_var_int(iptr->dst, d);
738 case ICMD_LNEG: /* ..., value ==> ..., - value */
740 var_to_reg_int(s1, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
741 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
742 M_SUBFIC(GET_LOW_REG(s1), 0, GET_LOW_REG(d));
743 M_SUBFZE(GET_HIGH_REG(s1), GET_HIGH_REG(d));
744 store_reg_to_var_lng(iptr->dst, d);
747 case ICMD_I2L: /* ..., value ==> ..., value */
749 var_to_reg_int(s1, src, REG_ITMP2);
750 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
751 M_INTMOVE(s1, GET_LOW_REG(d));
752 M_SRA_IMM(GET_LOW_REG(d), 31, GET_HIGH_REG(d));
753 store_reg_to_var_lng(iptr->dst, d);
756 case ICMD_L2I: /* ..., value ==> ..., value */
758 var_to_reg_lng_low(s1, src, REG_ITMP2);
759 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
761 store_reg_to_var_int(iptr->dst, d);
764 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
766 var_to_reg_int(s1, src, REG_ITMP1);
767 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
769 store_reg_to_var_int(iptr->dst, d);
772 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
774 var_to_reg_int(s1, src, REG_ITMP1);
775 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
777 store_reg_to_var_int(iptr->dst, d);
780 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
782 var_to_reg_int(s1, src, REG_ITMP1);
783 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
785 store_reg_to_var_int(iptr->dst, d);
789 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
791 var_to_reg_int(s1, src->prev, REG_ITMP1);
792 var_to_reg_int(s2, src, REG_ITMP2);
793 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
795 store_reg_to_var_int(iptr->dst, d);
798 case ICMD_IADDCONST: /* ..., value ==> ..., value + constant */
799 /* val.i = constant */
801 var_to_reg_int(s1, src, REG_ITMP1);
802 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
803 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
804 M_IADD_IMM(s1, iptr->val.i, d);
806 ICONST(REG_ITMP2, iptr->val.i);
807 M_IADD(s1, REG_ITMP2, d);
809 store_reg_to_var_int(iptr->dst, d);
812 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
814 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
815 var_to_reg_lng_low(s2, src, REG_ITMP2);
816 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
817 M_ADDC(s1, s2, GET_LOW_REG(d));
818 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
819 var_to_reg_lng_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
820 M_ADDE(s1, s2, GET_HIGH_REG(d));
821 store_reg_to_var_lng(iptr->dst, d);
824 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
825 /* val.l = constant */
827 s3 = iptr->val.l & 0xffffffff;
828 var_to_reg_lng_low(s1, src, REG_ITMP1);
829 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
830 if ((s3 >= -32768) && (s3 <= 32767)) {
831 M_ADDIC(s1, s3, GET_LOW_REG(d));
833 ICONST(REG_ITMP2, s3);
834 M_ADDC(s1, REG_ITMP2, GET_LOW_REG(d));
836 var_to_reg_lng_high(s1, src, REG_ITMP1);
837 s3 = iptr->val.l >> 32;
839 M_ADDME(s1, GET_HIGH_REG(d));
840 } else if (s3 == 0) {
841 M_ADDZE(s1, GET_HIGH_REG(d));
843 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
844 M_ADDE(s1, REG_ITMP3, GET_HIGH_REG(d));
846 store_reg_to_var_lng(iptr->dst, d);
849 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
851 var_to_reg_int(s1, src->prev, REG_ITMP1);
852 var_to_reg_int(s2, src, REG_ITMP2);
853 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
855 store_reg_to_var_int(iptr->dst, d);
858 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
859 /* val.i = constant */
861 var_to_reg_int(s1, src, REG_ITMP1);
862 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
863 if ((iptr->val.i >= -32767) && (iptr->val.i <= 32768)) {
864 M_IADD_IMM(s1, -iptr->val.i, d);
866 ICONST(REG_ITMP2, -iptr->val.i);
867 M_IADD(s1, REG_ITMP2, d);
869 store_reg_to_var_int(iptr->dst, d);
872 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
874 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
875 var_to_reg_lng_low(s2, src, REG_ITMP2);
876 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
877 M_SUBC(s1, s2, GET_LOW_REG(d));
878 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
879 var_to_reg_lng_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
880 M_SUBE(s1, s2, GET_HIGH_REG(d));
881 store_reg_to_var_lng(iptr->dst, d);
884 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
885 /* val.l = constant */
887 s3 = (-iptr->val.l) & 0xffffffff;
888 var_to_reg_lng_low(s1, src, REG_ITMP1);
889 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
890 if ((s3 >= -32768) && (s3 <= 32767)) {
891 M_ADDIC(s1, s3, GET_LOW_REG(d));
893 ICONST(REG_ITMP2, s3);
894 M_ADDC(s1, REG_ITMP2, GET_LOW_REG(d));
896 var_to_reg_lng_high(s1, src, REG_ITMP1);
897 s3 = (-iptr->val.l) >> 32;
899 M_ADDME(s1, GET_HIGH_REG(d));
901 M_ADDZE(s1, GET_HIGH_REG(d));
903 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
904 M_ADDE(s1, REG_ITMP3, GET_HIGH_REG(d));
906 store_reg_to_var_lng(iptr->dst, d);
909 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
911 var_to_reg_int(s1, src->prev, REG_ITMP1);
912 var_to_reg_int(s2, src, REG_ITMP2);
913 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
916 codegen_addxdivrefs(cd, mcodeptr);
917 M_LDAH(REG_ITMP3, REG_ZERO, 0x8000);
918 M_CMP(REG_ITMP3, s1);
919 M_BNE(3 + (s1 != d));
921 M_BNE(1 + (s1 != d));
925 store_reg_to_var_int(iptr->dst, d);
928 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
930 var_to_reg_int(s1, src->prev, REG_ITMP1);
931 var_to_reg_int(s2, src, REG_ITMP2);
932 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
935 codegen_addxdivrefs(cd, mcodeptr);
936 M_LDAH(REG_ITMP3, REG_ZERO, 0x8000);
937 M_CMP(REG_ITMP3, s1);
943 M_IDIV(s1, s2, REG_ITMP3);
944 M_IMUL(REG_ITMP3, s2, REG_ITMP3);
945 M_ISUB(s1, REG_ITMP3, d);
946 store_reg_to_var_int(iptr->dst, d);
949 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
950 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
955 var_to_reg_int(s2, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
956 M_OR_TST(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
958 codegen_addxdivrefs(cd, mcodeptr);
960 s3 = PACK_REGS(rd->argintregs[GET_LOW_REG(md->params[1].regoff)],
961 rd->argintregs[GET_HIGH_REG(md->params[1].regoff)]);
962 M_TINTMOVE(TYPE_LNG, s2, s3);
964 var_to_reg_int(s1, src->prev, PACK_REGS(REG_ITMP2, REG_ITMP1));
965 s3 = PACK_REGS(rd->argintregs[GET_LOW_REG(md->params[0].regoff)],
966 rd->argintregs[GET_HIGH_REG(md->params[0].regoff)]);
967 M_TINTMOVE(TYPE_LNG, s1, s3);
969 disp = dseg_addaddress(cd, bte->fp);
970 M_ALD(REG_ITMP1, REG_PV, disp);
974 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_RESULT2, REG_RESULT));
975 M_TINTMOVE(TYPE_LNG, PACK_REGS(REG_RESULT2, REG_RESULT), d);
976 store_reg_to_var_lng(iptr->dst, d);
979 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
981 var_to_reg_int(s1, src->prev, REG_ITMP1);
982 var_to_reg_int(s2, src, REG_ITMP2);
983 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
985 store_reg_to_var_int(iptr->dst, d);
988 case ICMD_IMULCONST: /* ..., value ==> ..., value * constant */
989 /* val.i = constant */
991 var_to_reg_int(s1, src, REG_ITMP1);
992 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
993 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
994 M_IMUL_IMM(s1, iptr->val.i, d);
996 ICONST(REG_ITMP3, iptr->val.i);
997 M_IMUL(s1, REG_ITMP3, d);
999 store_reg_to_var_int(iptr->dst, d);
1002 case ICMD_IDIVPOW2: /* ..., value ==> ..., value << constant */
1004 var_to_reg_int(s1, src, REG_ITMP1);
1005 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
1006 M_SRA_IMM(s1, iptr->val.i, d);
1008 store_reg_to_var_int(iptr->dst, d);
1011 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
1013 var_to_reg_int(s1, src->prev, REG_ITMP1);
1014 var_to_reg_int(s2, src, REG_ITMP2);
1015 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1016 M_AND_IMM(s2, 0x1f, REG_ITMP3);
1017 M_SLL(s1, REG_ITMP3, d);
1018 store_reg_to_var_int(iptr->dst, d);
1021 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
1022 /* val.i = constant */
1024 var_to_reg_int(s1, src, REG_ITMP1);
1025 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1026 M_SLL_IMM(s1, iptr->val.i & 0x1f, d);
1027 store_reg_to_var_int(iptr->dst, d);
1030 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
1032 var_to_reg_int(s1, src->prev, REG_ITMP1);
1033 var_to_reg_int(s2, src, REG_ITMP2);
1034 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1035 M_AND_IMM(s2, 0x1f, REG_ITMP3);
1036 M_SRA(s1, REG_ITMP3, d);
1037 store_reg_to_var_int(iptr->dst, d);
1040 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
1041 /* val.i = constant */
1043 var_to_reg_int(s1, src, REG_ITMP1);
1044 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1045 M_SRA_IMM(s1, iptr->val.i & 0x1f, d);
1046 store_reg_to_var_int(iptr->dst, d);
1049 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
1051 var_to_reg_int(s1, src->prev, REG_ITMP1);
1052 var_to_reg_int(s2, src, REG_ITMP2);
1053 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1054 M_AND_IMM(s2, 0x1f, REG_ITMP2);
1055 M_SRL(s1, REG_ITMP2, d);
1056 store_reg_to_var_int(iptr->dst, d);
1059 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
1060 /* val.i = constant */
1062 var_to_reg_int(s1, src, REG_ITMP1);
1063 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1064 if (iptr->val.i & 0x1f) {
1065 M_SRL_IMM(s1, iptr->val.i & 0x1f, d);
1069 store_reg_to_var_int(iptr->dst, d);
1072 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
1074 var_to_reg_int(s1, src->prev, REG_ITMP1);
1075 var_to_reg_int(s2, src, REG_ITMP2);
1076 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1078 store_reg_to_var_int(iptr->dst, d);
1081 case ICMD_IANDCONST: /* ..., value ==> ..., value & constant */
1082 /* val.i = constant */
1084 var_to_reg_int(s1, src, REG_ITMP1);
1085 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1086 if ((iptr->val.i >= 0) && (iptr->val.i <= 65535)) {
1087 M_AND_IMM(s1, iptr->val.i, d);
1090 else if (iptr->val.i == 0xffffff) {
1091 M_RLWINM(s1, 0, 8, 31, d);
1095 ICONST(REG_ITMP3, iptr->val.i);
1096 M_AND(s1, REG_ITMP3, d);
1098 store_reg_to_var_int(iptr->dst, d);
1101 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
1103 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
1104 var_to_reg_lng_low(s2, src, REG_ITMP2);
1105 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1106 M_AND(s1, s2, GET_LOW_REG(d));
1107 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
1108 var_to_reg_lng_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
1109 M_AND(s1, s2, GET_HIGH_REG(d));
1110 store_reg_to_var_lng(iptr->dst, d);
1113 case ICMD_LANDCONST: /* ..., value ==> ..., value & constant */
1114 /* val.l = constant */
1116 s3 = iptr->val.l & 0xffffffff;
1117 var_to_reg_lng_low(s1, src, REG_ITMP1);
1118 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1119 if ((s3 >= 0) && (s3 <= 65535)) {
1120 M_AND_IMM(s1, s3, GET_LOW_REG(d));
1122 ICONST(REG_ITMP3, s3);
1123 M_AND(s1, REG_ITMP3, GET_LOW_REG(d));
1125 var_to_reg_lng_high(s1, src, REG_ITMP1);
1126 s3 = iptr->val.l >> 32;
1127 if ((s3 >= 0) && (s3 <= 65535)) {
1128 M_AND_IMM(s1, s3, GET_HIGH_REG(d));
1130 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
1131 M_AND(s1, REG_ITMP3, GET_HIGH_REG(d));
1133 store_reg_to_var_lng(iptr->dst, d);
1136 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
1137 /* val.i = constant */
1139 var_to_reg_int(s1, src, REG_ITMP1);
1140 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1141 M_MOV(s1, REG_ITMP2);
1143 M_BGE(1 + 2*(iptr->val.i >= 32768));
1144 if (iptr->val.i >= 32768) {
1145 M_ADDIS(REG_ZERO, iptr->val.i >> 16, REG_ITMP2);
1146 M_OR_IMM(REG_ITMP2, iptr->val.i, REG_ITMP2);
1147 M_IADD(s1, REG_ITMP2, REG_ITMP2);
1149 M_IADD_IMM(s1, iptr->val.i, REG_ITMP2);
1152 int b=0, m = iptr->val.i;
1155 M_RLWINM(REG_ITMP2, 0, 0, 30-b, REG_ITMP2);
1157 M_ISUB(s1, REG_ITMP2, d);
1158 store_reg_to_var_int(iptr->dst, d);
1161 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
1163 var_to_reg_int(s1, src->prev, REG_ITMP1);
1164 var_to_reg_int(s2, src, REG_ITMP2);
1165 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1167 store_reg_to_var_int(iptr->dst, d);
1170 case ICMD_IORCONST: /* ..., value ==> ..., value | constant */
1171 /* val.i = constant */
1173 var_to_reg_int(s1, src, REG_ITMP1);
1174 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1175 if ((iptr->val.i >= 0) && (iptr->val.i <= 65535)) {
1176 M_OR_IMM(s1, iptr->val.i, d);
1178 ICONST(REG_ITMP3, iptr->val.i);
1179 M_OR(s1, REG_ITMP3, d);
1181 store_reg_to_var_int(iptr->dst, d);
1184 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
1186 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
1187 var_to_reg_lng_low(s2, src, REG_ITMP2);
1188 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1189 M_OR(s1, s2, GET_LOW_REG(d));
1190 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
1191 var_to_reg_lng_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
1192 M_OR(s1, s2, GET_HIGH_REG(d));
1193 store_reg_to_var_lng(iptr->dst, d);
1196 case ICMD_LORCONST: /* ..., value ==> ..., value | constant */
1197 /* val.l = constant */
1199 s3 = iptr->val.l & 0xffffffff;
1200 var_to_reg_lng_low(s1, src, REG_ITMP1);
1201 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1202 if ((s3 >= 0) && (s3 <= 65535)) {
1203 M_OR_IMM(s1, s3, GET_LOW_REG(d));
1205 ICONST(REG_ITMP3, s3);
1206 M_OR(s1, REG_ITMP3, GET_LOW_REG(d));
1208 var_to_reg_lng_high(s1, src, REG_ITMP1);
1209 s3 = iptr->val.l >> 32;
1210 if ((s3 >= 0) && (s3 <= 65535)) {
1211 M_OR_IMM(s1, s3, GET_HIGH_REG(d));
1213 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
1214 M_OR(s1, REG_ITMP3, GET_HIGH_REG(d));
1216 store_reg_to_var_lng(iptr->dst, d);
1219 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
1221 var_to_reg_int(s1, src->prev, REG_ITMP1);
1222 var_to_reg_int(s2, src, REG_ITMP2);
1223 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1225 store_reg_to_var_int(iptr->dst, d);
1228 case ICMD_IXORCONST: /* ..., value ==> ..., value ^ constant */
1229 /* val.i = constant */
1231 var_to_reg_int(s1, src, REG_ITMP1);
1232 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1233 if ((iptr->val.i >= 0) && (iptr->val.i <= 65535)) {
1234 M_XOR_IMM(s1, iptr->val.i, d);
1236 ICONST(REG_ITMP3, iptr->val.i);
1237 M_XOR(s1, REG_ITMP3, d);
1239 store_reg_to_var_int(iptr->dst, d);
1242 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
1244 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
1245 var_to_reg_lng_low(s2, src, REG_ITMP2);
1246 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1247 M_XOR(s1, s2, GET_LOW_REG(d));
1248 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
1249 var_to_reg_lng_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
1250 M_XOR(s1, s2, GET_HIGH_REG(d));
1251 store_reg_to_var_lng(iptr->dst, d);
1254 case ICMD_LXORCONST: /* ..., value ==> ..., value ^ constant */
1255 /* val.l = constant */
1257 s3 = iptr->val.l & 0xffffffff;
1258 var_to_reg_lng_low(s1, src, REG_ITMP1);
1259 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1260 if ((s3 >= 0) && (s3 <= 65535)) {
1261 M_XOR_IMM(s1, s3, GET_LOW_REG(d));
1263 ICONST(REG_ITMP3, s3);
1264 M_XOR(s1, REG_ITMP3, GET_LOW_REG(d));
1266 var_to_reg_lng_high(s1, src, REG_ITMP1);
1267 s3 = iptr->val.l >> 32;
1268 if ((s3 >= 0) && (s3 <= 65535)) {
1269 M_XOR_IMM(s1, s3, GET_HIGH_REG(d));
1271 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
1272 M_XOR(s1, REG_ITMP3, GET_HIGH_REG(d));
1274 store_reg_to_var_lng(iptr->dst, d);
1277 case ICMD_LCMP: /* ..., val1, val2 ==> ..., val1 cmp val2 */
1278 /*******************************************************************
1279 TODO: CHANGE THIS TO A VERSION THAT WORKS !!!
1280 *******************************************************************/
1281 var_to_reg_lng_high(s1, src->prev, REG_ITMP3);
1282 var_to_reg_lng_high(s2, src, REG_ITMP2);
1283 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
1285 int tempreg = false;
1289 if (src->prev->flags & INMEMORY) {
1290 tempreg = tempreg || (d == REG_ITMP3) || (d == REG_ITMP2);
1292 tempreg = tempreg || (d == GET_HIGH_REG(src->prev->regoff))
1293 || (d == GET_LOW_REG(src->prev->regoff));
1295 if (src->flags & INMEMORY) {
1296 tempreg = tempreg || (d == REG_ITMP3) || (d == REG_ITMP2);
1298 tempreg = tempreg || (d == GET_HIGH_REG(src->regoff))
1299 || (d == GET_LOW_REG(src->regoff));
1302 dreg = tempreg ? REG_ITMP1 : d;
1303 M_IADD_IMM(REG_ZERO, 1, dreg);
1308 var_to_reg_lng_low(s1, src->prev, REG_ITMP3);
1309 var_to_reg_lng_low(s2, src, REG_ITMP2);
1313 M_IADD_IMM(dreg, -1, dreg);
1314 M_IADD_IMM(dreg, -1, dreg);
1315 gen_resolvebranch(br1, (u1*) br1, (u1*) mcodeptr);
1316 gen_resolvebranch(br1+1, (u1*) (br1+1), (u1*) (mcodeptr-2));
1319 store_reg_to_var_lng(iptr->dst, d);
1322 case ICMD_IINC: /* ..., value ==> ..., value + constant */
1323 /* op1 = variable, val.i = constant */
1325 var = &(rd->locals[iptr->op1][TYPE_INT]);
1326 if (var->flags & INMEMORY) {
1328 M_ILD(s1, REG_SP, var->regoff * 4);
1337 M_ADDIS(s1, m >> 16, s1);
1339 M_IADD_IMM(s1, m & 0xffff, s1);
1341 if (var->flags & INMEMORY) {
1342 M_IST(s1, REG_SP, var->regoff * 4);
1347 /* floating operations ************************************************/
1349 case ICMD_FNEG: /* ..., value ==> ..., - value */
1351 var_to_reg_flt(s1, src, REG_FTMP1);
1352 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1354 store_reg_to_var_flt(iptr->dst, d);
1357 case ICMD_DNEG: /* ..., value ==> ..., - value */
1359 var_to_reg_flt(s1, src, REG_FTMP1);
1360 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1362 store_reg_to_var_dbl(iptr->dst, d);
1365 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1367 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1368 var_to_reg_flt(s2, src, REG_FTMP2);
1369 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1371 store_reg_to_var_flt(iptr->dst, d);
1374 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1376 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1377 var_to_reg_flt(s2, src, REG_FTMP2);
1378 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1380 store_reg_to_var_dbl(iptr->dst, d);
1383 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1385 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1386 var_to_reg_flt(s2, src, REG_FTMP2);
1387 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1389 store_reg_to_var_flt(iptr->dst, d);
1392 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1394 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1395 var_to_reg_flt(s2, src, REG_FTMP2);
1396 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1398 store_reg_to_var_dbl(iptr->dst, d);
1401 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1403 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1404 var_to_reg_flt(s2, src, REG_FTMP2);
1405 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1407 store_reg_to_var_flt(iptr->dst, d);
1410 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1412 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1413 var_to_reg_flt(s2, src, REG_FTMP2);
1414 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1416 store_reg_to_var_dbl(iptr->dst, d);
1419 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1421 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1422 var_to_reg_flt(s2, src, REG_FTMP2);
1423 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1425 store_reg_to_var_flt(iptr->dst, d);
1428 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1430 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1431 var_to_reg_flt(s2, src, REG_FTMP2);
1432 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1434 store_reg_to_var_dbl(iptr->dst, d);
1437 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1440 var_to_reg_flt(s1, src, REG_FTMP1);
1441 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1443 disp = dseg_addfloat(cd, 0.0);
1444 M_FLD(REG_FTMP2, REG_PV, disp);
1445 M_FCMPU(s1, REG_FTMP2);
1447 disp = dseg_adds4(cd, 0);
1448 M_CVTDL_C(s1, REG_FTMP1);
1449 M_LDA(REG_ITMP1, REG_PV, disp);
1450 M_STFIWX(REG_FTMP1, 0, REG_ITMP1);
1451 M_ILD(d, REG_PV, disp);
1452 store_reg_to_var_int(iptr->dst, d);
1455 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1457 var_to_reg_flt(s1, src, REG_FTMP1);
1458 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1460 store_reg_to_var_dbl(iptr->dst, d);
1463 case ICMD_D2F: /* ..., value ==> ..., (double) value */
1465 var_to_reg_flt(s1, src, REG_FTMP1);
1466 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1468 store_reg_to_var_flt(iptr->dst, d);
1471 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1474 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1475 var_to_reg_flt(s2, src, REG_FTMP2);
1476 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
1478 M_IADD_IMM(REG_ZERO, -1, d);
1481 M_IADD_IMM(REG_ZERO, 0, d);
1483 M_IADD_IMM(REG_ZERO, 1, d);
1484 store_reg_to_var_int(iptr->dst, d);
1487 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1490 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1491 var_to_reg_flt(s2, src, REG_FTMP2);
1492 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
1494 M_IADD_IMM(REG_ZERO, 1, d);
1497 M_IADD_IMM(REG_ZERO, 0, d);
1499 M_IADD_IMM(REG_ZERO, -1, d);
1500 store_reg_to_var_int(iptr->dst, d);
1504 /* memory operations **************************************************/
1506 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1508 var_to_reg_int(s1, src, REG_ITMP1);
1509 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1510 gen_nullptr_check(s1);
1511 M_ILD(d, s1, OFFSET(java_arrayheader, size));
1512 store_reg_to_var_int(iptr->dst, d);
1515 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1517 var_to_reg_int(s1, src->prev, REG_ITMP1);
1518 var_to_reg_int(s2, src, REG_ITMP2);
1519 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1520 if (iptr->op1 == 0) {
1521 gen_nullptr_check(s1);
1524 M_IADD_IMM(s2, OFFSET(java_chararray, data[0]), REG_ITMP2);
1525 M_LBZX(d, s1, REG_ITMP2);
1527 store_reg_to_var_int(iptr->dst, d);
1530 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1532 var_to_reg_int(s1, src->prev, REG_ITMP1);
1533 var_to_reg_int(s2, src, REG_ITMP2);
1534 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1535 if (iptr->op1 == 0) {
1536 gen_nullptr_check(s1);
1539 M_SLL_IMM(s2, 1, REG_ITMP2);
1540 M_IADD_IMM(REG_ITMP2, OFFSET(java_chararray, data[0]), REG_ITMP2);
1541 M_LHZX(d, s1, REG_ITMP2);
1542 store_reg_to_var_int(iptr->dst, d);
1545 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1547 var_to_reg_int(s1, src->prev, REG_ITMP1);
1548 var_to_reg_int(s2, src, REG_ITMP2);
1549 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1550 if (iptr->op1 == 0) {
1551 gen_nullptr_check(s1);
1554 M_SLL_IMM(s2, 1, REG_ITMP2);
1555 M_IADD_IMM(REG_ITMP2, OFFSET(java_shortarray, data[0]), REG_ITMP2);
1556 M_LHAX(d, s1, REG_ITMP2);
1557 store_reg_to_var_int(iptr->dst, d);
1560 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1562 var_to_reg_int(s1, src->prev, REG_ITMP1);
1563 var_to_reg_int(s2, src, REG_ITMP2);
1564 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1565 if (iptr->op1 == 0) {
1566 gen_nullptr_check(s1);
1569 M_SLL_IMM(s2, 2, REG_ITMP2);
1570 M_IADD_IMM(REG_ITMP2, OFFSET(java_intarray, data[0]), REG_ITMP2);
1571 M_LWZX(d, s1, REG_ITMP2);
1572 store_reg_to_var_int(iptr->dst, d);
1575 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1577 var_to_reg_int(s1, src->prev, REG_ITMP1);
1578 var_to_reg_int(s2, src, REG_ITMP2);
1579 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1580 if (iptr->op1 == 0) {
1581 gen_nullptr_check(s1);
1584 M_SLL_IMM(s2, 3, REG_ITMP2);
1585 M_IADD(s1, REG_ITMP2, REG_ITMP2);
1586 M_ILD(GET_HIGH_REG(d), REG_ITMP2, OFFSET(java_longarray, data[0]));
1587 M_ILD(GET_LOW_REG(d), REG_ITMP2, OFFSET(java_longarray,
1589 store_reg_to_var_lng(iptr->dst, d);
1592 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1594 var_to_reg_int(s1, src->prev, REG_ITMP1);
1595 var_to_reg_int(s2, src, REG_ITMP2);
1596 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1597 if (iptr->op1 == 0) {
1598 gen_nullptr_check(s1);
1601 M_SLL_IMM(s2, 2, REG_ITMP2);
1602 M_IADD_IMM(REG_ITMP2, OFFSET(java_floatarray, data[0]), REG_ITMP2);
1603 M_LFSX(d, s1, REG_ITMP2);
1604 store_reg_to_var_flt(iptr->dst, d);
1607 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1609 var_to_reg_int(s1, src->prev, REG_ITMP1);
1610 var_to_reg_int(s2, src, REG_ITMP2);
1611 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1612 if (iptr->op1 == 0) {
1613 gen_nullptr_check(s1);
1616 M_SLL_IMM(s2, 3, REG_ITMP2);
1617 M_IADD_IMM(REG_ITMP2, OFFSET(java_doublearray, data[0]), REG_ITMP2);
1618 M_LFDX(d, s1, REG_ITMP2);
1619 store_reg_to_var_dbl(iptr->dst, d);
1622 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1624 var_to_reg_int(s1, src->prev, REG_ITMP1);
1625 var_to_reg_int(s2, src, REG_ITMP2);
1626 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1627 if (iptr->op1 == 0) {
1628 gen_nullptr_check(s1);
1631 M_SLL_IMM(s2, 2, REG_ITMP2);
1632 M_IADD_IMM(REG_ITMP2, OFFSET(java_objectarray, data[0]), REG_ITMP2);
1633 M_LWZX(d, s1, REG_ITMP2);
1634 store_reg_to_var_adr(iptr->dst, d);
1638 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1640 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1641 var_to_reg_int(s2, src->prev, REG_ITMP2);
1642 if (iptr->op1 == 0) {
1643 gen_nullptr_check(s1);
1646 var_to_reg_int(s3, src, REG_ITMP3);
1647 M_IADD_IMM(s2, OFFSET(java_bytearray, data[0]), REG_ITMP2);
1648 M_STBX(s3, s1, REG_ITMP2);
1651 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1653 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1654 var_to_reg_int(s2, src->prev, REG_ITMP2);
1655 if (iptr->op1 == 0) {
1656 gen_nullptr_check(s1);
1659 var_to_reg_int(s3, src, REG_ITMP3);
1660 M_SLL_IMM(s2, 1, REG_ITMP2);
1661 M_IADD_IMM(REG_ITMP2, OFFSET(java_chararray, data[0]), REG_ITMP2);
1662 M_STHX(s3, s1, REG_ITMP2);
1665 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1667 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1668 var_to_reg_int(s2, src->prev, REG_ITMP2);
1669 if (iptr->op1 == 0) {
1670 gen_nullptr_check(s1);
1673 var_to_reg_int(s3, src, REG_ITMP3);
1674 M_SLL_IMM(s2, 1, REG_ITMP2);
1675 M_IADD_IMM(REG_ITMP2, OFFSET(java_shortarray, data[0]), REG_ITMP2);
1676 M_STHX(s3, s1, REG_ITMP2);
1679 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1681 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1682 var_to_reg_int(s2, src->prev, REG_ITMP2);
1683 if (iptr->op1 == 0) {
1684 gen_nullptr_check(s1);
1687 var_to_reg_int(s3, src, REG_ITMP3);
1688 M_SLL_IMM(s2, 2, REG_ITMP2);
1689 M_IADD_IMM(REG_ITMP2, OFFSET(java_intarray, data[0]), REG_ITMP2);
1690 M_STWX(s3, s1, REG_ITMP2);
1693 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1695 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1696 var_to_reg_int(s2, src->prev, REG_ITMP2);
1697 if (iptr->op1 == 0) {
1698 gen_nullptr_check(s1);
1701 var_to_reg_lng_high(s3, src, REG_ITMP3);
1702 M_SLL_IMM(s2, 3, REG_ITMP2);
1703 M_IADD_IMM(REG_ITMP2, OFFSET(java_longarray, data[0]), REG_ITMP2);
1704 M_STWX(s3, s1, REG_ITMP2);
1705 M_IADD_IMM(REG_ITMP2, 4, REG_ITMP2);
1706 var_to_reg_lng_low(s3, src, REG_ITMP3);
1707 M_STWX(s3, s1, REG_ITMP2);
1710 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1712 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1713 var_to_reg_int(s2, src->prev, REG_ITMP2);
1714 if (iptr->op1 == 0) {
1715 gen_nullptr_check(s1);
1718 var_to_reg_flt(s3, src, REG_FTMP3);
1719 M_SLL_IMM(s2, 2, REG_ITMP2);
1720 M_IADD_IMM(REG_ITMP2, OFFSET(java_floatarray, data[0]), REG_ITMP2);
1721 M_STFSX(s3, s1, REG_ITMP2);
1724 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1726 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1727 var_to_reg_int(s2, src->prev, REG_ITMP2);
1728 if (iptr->op1 == 0) {
1729 gen_nullptr_check(s1);
1732 var_to_reg_flt(s3, src, REG_FTMP3);
1733 M_SLL_IMM(s2, 3, REG_ITMP2);
1734 M_IADD_IMM(REG_ITMP2, OFFSET(java_doublearray, data[0]), REG_ITMP2);
1735 M_STFDX(s3, s1, REG_ITMP2);
1738 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1740 var_to_reg_int(s1, src->prev->prev, rd->argintregs[0]);
1741 var_to_reg_int(s2, src->prev, REG_ITMP2);
1742 if (iptr->op1 == 0) {
1743 gen_nullptr_check(s1);
1746 var_to_reg_int(s3, src, rd->argintregs[1]);
1748 M_INTMOVE(s1, rd->argintregs[0]);
1749 M_INTMOVE(s3, rd->argintregs[1]);
1750 disp = dseg_addaddress(cd, BUILTIN_canstore);
1751 M_ALD(REG_ITMP1, REG_PV, disp);
1756 codegen_addxstorerefs(cd, mcodeptr);
1758 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1759 var_to_reg_int(s2, src->prev, REG_ITMP2);
1760 var_to_reg_int(s3, src, REG_ITMP3);
1761 M_SLL_IMM(s2, 2, REG_ITMP2);
1762 M_IADD_IMM(REG_ITMP2, OFFSET(java_objectarray, data[0]), REG_ITMP2);
1763 M_STWX(s3, s1, REG_ITMP2);
1767 case ICMD_GETSTATIC: /* ... ==> ..., value */
1768 /* op1 = type, val.a = field address */
1771 disp = dseg_addaddress(cd, NULL);
1773 codegen_addpatchref(cd, mcodeptr,
1774 PATCHER_get_putstatic,
1775 (unresolved_field *) iptr->target, disp);
1777 if (opt_showdisassemble)
1781 fieldinfo *fi = iptr->val.a;
1783 disp = dseg_addaddress(cd, &(fi->value));
1785 if (!(fi->class->state & CLASS_INITIALIZED)) {
1786 codegen_addpatchref(cd, mcodeptr,
1787 PATCHER_clinit, fi->class, disp);
1789 if (opt_showdisassemble)
1794 M_ALD(REG_ITMP1, REG_PV, disp);
1795 switch (iptr->op1) {
1797 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1798 M_ILD_INTERN(d, REG_ITMP1, 0);
1799 store_reg_to_var_int(iptr->dst, d);
1802 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1803 M_ILD_INTERN(GET_LOW_REG(d), REG_ITMP1, 4);/* keep this order */
1804 M_ILD_INTERN(GET_HIGH_REG(d), REG_ITMP1, 0);/*keep this order */
1805 store_reg_to_var_lng(iptr->dst, d);
1808 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1809 M_ALD_INTERN(d, REG_ITMP1, 0);
1810 store_reg_to_var_adr(iptr->dst, d);
1813 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1814 M_FLD_INTERN(d, REG_ITMP1, 0);
1815 store_reg_to_var_flt(iptr->dst, d);
1818 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1819 M_DLD_INTERN(d, REG_ITMP1, 0);
1820 store_reg_to_var_dbl(iptr->dst, d);
1825 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1826 /* op1 = type, val.a = field address */
1830 disp = dseg_addaddress(cd, NULL);
1832 codegen_addpatchref(cd, mcodeptr,
1833 PATCHER_get_putstatic,
1834 (unresolved_field *) iptr->target, disp);
1836 if (opt_showdisassemble)
1840 fieldinfo *fi = iptr->val.a;
1842 disp = dseg_addaddress(cd, &(fi->value));
1844 if (!(fi->class->state & CLASS_INITIALIZED)) {
1845 codegen_addpatchref(cd, mcodeptr,
1846 PATCHER_clinit, fi->class, disp);
1848 if (opt_showdisassemble)
1853 M_ALD(REG_ITMP1, REG_PV, disp);
1854 switch (iptr->op1) {
1856 var_to_reg_int(s2, src, REG_ITMP2);
1857 M_IST_INTERN(s2, REG_ITMP1, 0);
1860 var_to_reg_int(s2, src, PACK_REGS(REG_ITMP2, REG_ITMP3));
1861 M_IST_INTERN(GET_HIGH_REG(s2), REG_ITMP1, 0);
1862 M_IST_INTERN(GET_LOW_REG(s2), REG_ITMP1, 4);
1865 var_to_reg_int(s2, src, REG_ITMP2);
1866 M_AST_INTERN(s2, REG_ITMP1, 0);
1869 var_to_reg_flt(s2, src, REG_FTMP2);
1870 M_FST_INTERN(s2, REG_ITMP1, 0);
1873 var_to_reg_flt(s2, src, REG_FTMP2);
1874 M_DST_INTERN(s2, REG_ITMP1, 0);
1880 case ICMD_GETFIELD: /* ... ==> ..., value */
1881 /* op1 = type, val.i = field offset */
1883 var_to_reg_int(s1, src, REG_ITMP1);
1884 gen_nullptr_check(s1);
1887 codegen_addpatchref(cd, mcodeptr,
1888 PATCHER_get_putfield,
1889 (unresolved_field *) iptr->target, 0);
1891 if (opt_showdisassemble)
1897 disp = ((fieldinfo *) (iptr->val.a))->offset;
1900 switch (iptr->op1) {
1902 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1904 store_reg_to_var_int(iptr->dst, d);
1907 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1908 if (GET_HIGH_REG(d) == s1) {
1909 M_ILD(GET_LOW_REG(d), s1, disp + 4);
1910 M_ILD(GET_HIGH_REG(d), s1, disp);
1912 M_ILD(GET_HIGH_REG(d), s1, disp);
1913 M_ILD(GET_LOW_REG(d), s1, disp + 4);
1915 store_reg_to_var_lng(iptr->dst, d);
1918 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1920 store_reg_to_var_adr(iptr->dst, d);
1923 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1925 store_reg_to_var_flt(iptr->dst, d);
1928 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1930 store_reg_to_var_dbl(iptr->dst, d);
1935 case ICMD_PUTFIELD: /* ..., value ==> ... */
1936 /* op1 = type, val.i = field offset */
1938 var_to_reg_int(s1, src->prev, REG_ITMP1);
1939 gen_nullptr_check(s1);
1941 if (!IS_FLT_DBL_TYPE(iptr->op1)) {
1942 if (IS_2_WORD_TYPE(iptr->op1)) {
1943 var_to_reg_int(s2, src, PACK_REGS(REG_ITMP2, REG_ITMP3));
1945 var_to_reg_int(s2, src, REG_ITMP2);
1948 var_to_reg_flt(s2, src, REG_FTMP2);
1952 codegen_addpatchref(cd, mcodeptr,
1953 PATCHER_get_putfield,
1954 (unresolved_field *) iptr->target, 0);
1956 if (opt_showdisassemble)
1962 disp = ((fieldinfo *) (iptr->val.a))->offset;
1965 switch (iptr->op1) {
1967 M_IST(s2, s1, disp);
1970 M_IST(GET_LOW_REG(s2), s1, disp + 4); /* keep this order */
1971 M_IST(GET_HIGH_REG(s2), s1, disp); /* keep this order */
1974 M_AST(s2, s1, disp);
1977 M_FST(s2, s1, disp);
1980 M_DST(s2, s1, disp);
1986 /* branch operations **************************************************/
1988 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1990 var_to_reg_int(s1, src, REG_ITMP1);
1991 M_INTMOVE(s1, REG_ITMP1_XPTR);
1993 #ifdef ENABLE_VERIFIER
1995 codegen_addpatchref(cd, mcodeptr,
1996 PATCHER_athrow_areturn,
1997 (unresolved_class *) iptr->val.a, 0);
1999 if (opt_showdisassemble)
2002 #endif /* ENABLE_VERIFIER */
2004 disp = dseg_addaddress(cd, asm_handle_exception);
2005 M_ALD(REG_ITMP2, REG_PV, disp);
2008 if (m->isleafmethod) M_MFLR(REG_ITMP3); /* save LR */
2009 M_BL(0); /* get current PC */
2010 M_MFLR(REG_ITMP2_XPC);
2011 if (m->isleafmethod) M_MTLR(REG_ITMP3); /* restore LR */
2012 M_RTS; /* jump to CTR */
2017 case ICMD_GOTO: /* ... ==> ... */
2018 /* op1 = target JavaVM pc */
2020 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2024 case ICMD_JSR: /* ... ==> ... */
2025 /* op1 = target JavaVM pc */
2027 if (m->isleafmethod) M_MFLR(REG_ITMP2);
2030 M_IADD_IMM(REG_ITMP1, m->isleafmethod ? 16 : 12, REG_ITMP1);
2031 if (m->isleafmethod) M_MTLR(REG_ITMP2);
2033 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2036 case ICMD_RET: /* ... ==> ... */
2037 /* op1 = local variable */
2039 var = &(rd->locals[iptr->op1][TYPE_ADR]);
2040 if (var->flags & INMEMORY) {
2041 M_ALD(REG_ITMP1, REG_SP, var->regoff * 4);
2044 M_MTCTR(var->regoff);
2050 case ICMD_IFNULL: /* ..., value ==> ... */
2051 /* op1 = target JavaVM pc */
2053 var_to_reg_int(s1, src, REG_ITMP1);
2056 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2059 case ICMD_IFNONNULL: /* ..., value ==> ... */
2060 /* op1 = target JavaVM pc */
2062 var_to_reg_int(s1, src, REG_ITMP1);
2065 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2073 case ICMD_IFEQ: /* ..., value ==> ... */
2074 /* op1 = target JavaVM pc, val.i = constant */
2076 var_to_reg_int(s1, src, REG_ITMP1);
2077 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
2078 M_CMPI(s1, iptr->val.i);
2080 ICONST(REG_ITMP2, iptr->val.i);
2081 M_CMP(s1, REG_ITMP2);
2083 switch (iptr->opc) {
2103 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2107 case ICMD_IF_LEQ: /* ..., value ==> ... */
2108 /* op1 = target JavaVM pc, val.l = constant */
2110 var_to_reg_lng_low(s1, src, REG_ITMP1);
2111 var_to_reg_lng_high(s2, src, REG_ITMP2);
2112 if (iptr->val.l == 0) {
2113 M_OR_TST(s1, s2, REG_ITMP3);
2114 } else if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2115 M_XOR_IMM(s2, 0, REG_ITMP2);
2116 M_XOR_IMM(s1, iptr->val.l & 0xffff, REG_ITMP1);
2117 M_OR_TST(REG_ITMP1, REG_ITMP2, REG_ITMP3);
2119 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2120 M_XOR(s1, REG_ITMP3, REG_ITMP1);
2121 ICONST(REG_ITMP3, iptr->val.l >> 32);
2122 M_XOR(s2, REG_ITMP3, REG_ITMP2);
2123 M_OR_TST(REG_ITMP1, REG_ITMP2, REG_ITMP3);
2126 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2129 case ICMD_IF_LLT: /* ..., value ==> ... */
2130 /* op1 = target JavaVM pc, val.l = constant */
2131 var_to_reg_lng_low(s1, src, REG_ITMP1);
2132 var_to_reg_lng_high(s2, src, REG_ITMP2);
2133 if (iptr->val.l == 0) {
2134 /* if high word is less than zero, the whole long is too */
2136 } else if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2139 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2141 M_CMPUI(s1, iptr->val.l & 0xffff);
2143 ICONST(REG_ITMP3, iptr->val.l >> 32);
2144 M_CMP(s2, REG_ITMP3);
2146 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2148 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2149 M_CMPU(s1, REG_ITMP3);
2152 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2155 case ICMD_IF_LLE: /* ..., value ==> ... */
2156 /* op1 = target JavaVM pc, val.l = constant */
2158 var_to_reg_lng_low(s1, src, REG_ITMP1);
2159 var_to_reg_lng_high(s2, src, REG_ITMP2);
2160 /* if (iptr->val.l == 0) { */
2161 /* M_OR(s1, s2, REG_ITMP3); */
2162 /* M_CMPI(REG_ITMP3, 0); */
2165 if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2168 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2170 M_CMPUI(s1, iptr->val.l & 0xffff);
2172 ICONST(REG_ITMP3, iptr->val.l >> 32);
2173 M_CMP(s2, REG_ITMP3);
2175 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2177 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2178 M_CMPU(s1, REG_ITMP3);
2181 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2184 case ICMD_IF_LNE: /* ..., value ==> ... */
2185 /* op1 = target JavaVM pc, val.l = constant */
2187 var_to_reg_lng_low(s1, src, REG_ITMP1);
2188 var_to_reg_lng_high(s2, src, REG_ITMP2);
2189 if (iptr->val.l == 0) {
2190 M_OR_TST(s1, s2, REG_ITMP3);
2191 } else if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2192 M_XOR_IMM(s2, 0, REG_ITMP2);
2193 M_XOR_IMM(s1, iptr->val.l & 0xffff, REG_ITMP1);
2194 M_OR_TST(REG_ITMP1, REG_ITMP2, REG_ITMP3);
2196 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2197 M_XOR(s1, REG_ITMP3, REG_ITMP1);
2198 ICONST(REG_ITMP3, iptr->val.l >> 32);
2199 M_XOR(s2, REG_ITMP3, REG_ITMP2);
2200 M_OR_TST(REG_ITMP1, REG_ITMP2, REG_ITMP3);
2203 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2206 case ICMD_IF_LGT: /* ..., value ==> ... */
2207 /* op1 = target JavaVM pc, val.l = constant */
2209 var_to_reg_lng_low(s1, src, REG_ITMP1);
2210 var_to_reg_lng_high(s2, src, REG_ITMP2);
2211 /* if (iptr->val.l == 0) { */
2212 /* M_OR(s1, s2, REG_ITMP3); */
2213 /* M_CMPI(REG_ITMP3, 0); */
2216 if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2219 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2221 M_CMPUI(s1, iptr->val.l & 0xffff);
2223 ICONST(REG_ITMP3, iptr->val.l >> 32);
2224 M_CMP(s2, REG_ITMP3);
2226 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2228 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2229 M_CMPU(s1, REG_ITMP3);
2232 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2235 case ICMD_IF_LGE: /* ..., value ==> ... */
2236 /* op1 = target JavaVM pc, val.l = constant */
2237 var_to_reg_lng_low(s1, src, REG_ITMP1);
2238 var_to_reg_lng_high(s2, src, REG_ITMP2);
2239 if (iptr->val.l == 0) {
2240 /* if high word is greater equal zero, the whole long is too */
2242 } else if ((iptr->val.l >= 0) && (iptr->val.l <= 0xffff)) {
2245 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2247 M_CMPUI(s1, iptr->val.l & 0xffff);
2249 ICONST(REG_ITMP3, iptr->val.l >> 32);
2250 M_CMP(s2, REG_ITMP3);
2252 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2254 ICONST(REG_ITMP3, iptr->val.l & 0xffffffff);
2255 M_CMPU(s1, REG_ITMP3);
2258 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2261 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
2262 case ICMD_IF_ACMPEQ: /* op1 = target JavaVM pc */
2264 var_to_reg_int(s1, src->prev, REG_ITMP1);
2265 var_to_reg_int(s2, src, REG_ITMP2);
2268 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2271 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
2272 /* op1 = target JavaVM pc */
2274 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2275 var_to_reg_lng_high(s2, src, REG_ITMP2);
2277 /* load low-bits before the branch, so we know the distance */
2278 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2279 var_to_reg_lng_low(s2, src, REG_ITMP2);
2283 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2286 case ICMD_IF_ICMPNE: /* ..., value, value ==> ... */
2287 case ICMD_IF_ACMPNE: /* op1 = target JavaVM pc */
2289 var_to_reg_int(s1, src->prev, REG_ITMP1);
2290 var_to_reg_int(s2, src, REG_ITMP2);
2293 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2296 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
2297 /* op1 = target JavaVM pc */
2299 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2300 var_to_reg_lng_high(s2, src, REG_ITMP2);
2303 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2304 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2305 var_to_reg_lng_low(s2, src, REG_ITMP2);
2308 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2311 case ICMD_IF_ICMPLT: /* ..., value, value ==> ... */
2312 /* op1 = target JavaVM pc */
2314 var_to_reg_int(s1, src->prev, REG_ITMP1);
2315 var_to_reg_int(s2, src, REG_ITMP2);
2318 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2321 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
2322 /* op1 = target JavaVM pc */
2324 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2325 var_to_reg_lng_high(s2, src, REG_ITMP2);
2328 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2329 /* load low-bits before the branch, so we know the distance */
2330 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2331 var_to_reg_lng_low(s2, src, REG_ITMP2);
2335 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2338 case ICMD_IF_ICMPGT: /* ..., value, value ==> ... */
2339 /* op1 = target JavaVM pc */
2341 var_to_reg_int(s1, src->prev, REG_ITMP1);
2342 var_to_reg_int(s2, src, REG_ITMP2);
2345 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2348 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
2349 /* op1 = target JavaVM pc */
2351 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2352 var_to_reg_lng_high(s2, src, REG_ITMP2);
2355 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2356 /* load low-bits before the branch, so we know the distance */
2357 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2358 var_to_reg_lng_low(s2, src, REG_ITMP2);
2362 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2365 case ICMD_IF_ICMPLE: /* ..., value, value ==> ... */
2366 /* op1 = target JavaVM pc */
2368 var_to_reg_int(s1, src->prev, REG_ITMP1);
2369 var_to_reg_int(s2, src, REG_ITMP2);
2372 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2375 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
2376 /* op1 = target JavaVM pc */
2378 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2379 var_to_reg_lng_high(s2, src, REG_ITMP2);
2382 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2383 /* load low-bits before the branch, so we know the distance */
2384 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2385 var_to_reg_lng_low(s2, src, REG_ITMP2);
2389 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2392 case ICMD_IF_ICMPGE: /* ..., value, value ==> ... */
2393 /* op1 = target JavaVM pc */
2395 var_to_reg_int(s1, src->prev, REG_ITMP1);
2396 var_to_reg_int(s2, src, REG_ITMP2);
2399 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2402 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
2403 /* op1 = target JavaVM pc */
2405 var_to_reg_lng_high(s1, src->prev, REG_ITMP1);
2406 var_to_reg_lng_high(s2, src, REG_ITMP2);
2409 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2410 /* load low-bits before the branch, so we know the distance */
2411 var_to_reg_lng_low(s1, src->prev, REG_ITMP1);
2412 var_to_reg_lng_low(s2, src, REG_ITMP2);
2416 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2419 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2421 var_to_reg_int(s1, src, REG_RESULT);
2422 M_TINTMOVE(src->type, s1, REG_RESULT);
2423 goto nowperformreturn;
2425 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2427 var_to_reg_int(s1, src, REG_RESULT);
2428 M_TINTMOVE(src->type, s1, REG_RESULT);
2430 #ifdef ENABLE_VERIFIER
2432 codegen_addpatchref(cd, mcodeptr,
2433 PATCHER_athrow_areturn,
2434 (unresolved_class *) iptr->val.a, 0);
2436 if (opt_showdisassemble)
2439 #endif /* ENABLE_VERIFIER */
2440 goto nowperformreturn;
2442 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2444 var_to_reg_int(s1, src, PACK_REGS(REG_RESULT2, REG_RESULT));
2445 M_TINTMOVE(src->type, s1, PACK_REGS(REG_RESULT2, REG_RESULT));
2446 goto nowperformreturn;
2448 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2451 var_to_reg_flt(s1, src, REG_FRESULT);
2452 M_FLTMOVE(s1, REG_FRESULT);
2453 goto nowperformreturn;
2455 case ICMD_RETURN: /* ... ==> ... */
2461 p = parentargs_base;
2463 /* call trace function */
2467 M_LDA(REG_SP, REG_SP, -10 * 8);
2468 M_DST(REG_FRESULT, REG_SP, 48+0);
2469 M_IST(REG_RESULT, REG_SP, 48+8);
2470 M_AST(REG_ZERO, REG_SP, 48+12);
2471 M_IST(REG_RESULT2, REG_SP, 48+16);
2473 /* keep this order */
2474 switch (iptr->opc) {
2477 #if defined(__DARWIN__)
2478 M_MOV(REG_RESULT, rd->argintregs[2]);
2479 M_CLR(rd->argintregs[1]);
2481 M_MOV(REG_RESULT, rd->argintregs[3]);
2482 M_CLR(rd->argintregs[2]);
2487 #if defined(__DARWIN__)
2488 M_MOV(REG_RESULT2, rd->argintregs[2]);
2489 M_MOV(REG_RESULT, rd->argintregs[1]);
2491 M_MOV(REG_RESULT2, rd->argintregs[3]);
2492 M_MOV(REG_RESULT, rd->argintregs[2]);
2497 disp = dseg_addaddress(cd, m);
2498 M_ALD(rd->argintregs[0], REG_PV, disp);
2500 M_FLTMOVE(REG_FRESULT, rd->argfltregs[0]);
2501 M_FLTMOVE(REG_FRESULT, rd->argfltregs[1]);
2502 disp = dseg_addaddress(cd, builtin_displaymethodstop);
2503 M_ALD(REG_ITMP2, REG_PV, disp);
2507 M_DLD(REG_FRESULT, REG_SP, 48+0);
2508 M_ILD(REG_RESULT, REG_SP, 48+8);
2509 M_ALD(REG_ZERO, REG_SP, 48+12);
2510 M_ILD(REG_RESULT2, REG_SP, 48+16);
2511 M_LDA(REG_SP, REG_SP, 10 * 8);
2515 #if defined(USE_THREADS)
2516 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2517 /* we need to save the proper return value */
2518 switch (iptr->opc) {
2520 M_IST(REG_RESULT2, REG_SP, rd->memuse * 4 + 8);
2524 M_IST(REG_RESULT , REG_SP, rd->memuse * 4 + 4);
2527 M_FST(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2530 M_DST(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2534 disp = dseg_addaddress(cd, BUILTIN_monitorexit);
2535 M_ALD(REG_ITMP3, REG_PV, disp);
2537 M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 4);
2540 /* and now restore the proper return value */
2541 switch (iptr->opc) {
2543 M_ILD(REG_RESULT2, REG_SP, rd->memuse * 4 + 8);
2547 M_ILD(REG_RESULT , REG_SP, rd->memuse * 4 + 4);
2550 M_FLD(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2553 M_DLD(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2559 /* restore return address */
2561 if (!m->isleafmethod) {
2562 M_ALD(REG_ZERO, REG_SP, p * 4 + LA_LR_OFFSET);
2566 /* restore saved registers */
2568 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
2569 p--; M_ILD(rd->savintregs[i], REG_SP, p * 4);
2571 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
2572 p -= 2; M_DLD(rd->savfltregs[i], REG_SP, p * 4);
2575 /* deallocate stack */
2577 if (parentargs_base)
2578 M_LDA(REG_SP, REG_SP, parentargs_base * 4);
2586 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2591 tptr = (void **) iptr->target;
2593 s4ptr = iptr->val.a;
2594 l = s4ptr[1]; /* low */
2595 i = s4ptr[2]; /* high */
2597 var_to_reg_int(s1, src, REG_ITMP1);
2599 M_INTMOVE(s1, REG_ITMP1);
2600 } else if (l <= 32768) {
2601 M_LDA(REG_ITMP1, s1, -l);
2603 ICONST(REG_ITMP2, l);
2604 M_ISUB(s1, REG_ITMP2, REG_ITMP1);
2610 M_CMPUI(REG_ITMP1, i - 1);
2612 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2614 /* build jump table top down and use address of lowest entry */
2616 /* s4ptr += 3 + i; */
2620 dseg_addtarget(cd, (basicblock *) tptr[0]);
2625 /* length of dataseg after last dseg_addtarget is used by load */
2627 M_SLL_IMM(REG_ITMP1, 2, REG_ITMP1);
2628 M_IADD(REG_ITMP1, REG_PV, REG_ITMP2);
2629 M_ALD(REG_ITMP2, REG_ITMP2, -(cd->dseglen));
2636 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2638 s4 i, l, val, *s4ptr;
2641 tptr = (void **) iptr->target;
2643 s4ptr = iptr->val.a;
2644 l = s4ptr[0]; /* default */
2645 i = s4ptr[1]; /* count */
2647 MCODECHECK((i<<2)+8);
2648 var_to_reg_int(s1, src, REG_ITMP1);
2654 if ((val >= -32768) && (val <= 32767)) {
2657 a = dseg_adds4(cd, val);
2658 M_ILD(REG_ITMP2, REG_PV, a);
2659 M_CMP(s1, REG_ITMP2);
2662 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2666 tptr = (void **) iptr->target;
2667 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2674 case ICMD_BUILTIN: /* ..., [arg1, [arg2 ...]] ==> ... */
2675 /* op1 = arg count val.a = builtintable entry */
2681 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2682 /* op1 = arg count, val.a = method pointer */
2684 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2685 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2686 case ICMD_INVOKEINTERFACE:
2691 unresolved_method *um = iptr->target;
2692 md = um->methodref->parseddesc.md;
2694 md = lm->parseddesc;
2698 s3 = md->paramcount;
2700 MCODECHECK((s3 << 1) + 64);
2702 /* copy arguments to registers or stack location */
2704 for (s3 = s3 - 1; s3 >= 0; s3--, src = src->prev) {
2705 if (src->varkind == ARGVAR)
2707 if (IS_INT_LNG_TYPE(src->type)) {
2708 if (!md->params[s3].inmemory) {
2709 if (IS_2_WORD_TYPE(src->type)) {
2711 rd->argintregs[GET_LOW_REG(md->params[s3].regoff)],
2712 rd->argintregs[GET_HIGH_REG(md->params[s3].regoff)]);
2714 s1 = rd->argintregs[md->params[s3].regoff];
2716 var_to_reg_int(d, src, s1);
2717 M_TINTMOVE(src->type, d, s1);
2719 if (IS_2_WORD_TYPE(src->type)) {
2720 var_to_reg_int(d, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
2721 M_IST(GET_HIGH_REG(d), REG_SP,
2722 md->params[s3].regoff * 4);
2723 M_IST(GET_LOW_REG(d), REG_SP,
2724 md->params[s3].regoff * 4 + 4);
2726 var_to_reg_int(d, src, REG_ITMP1);
2727 M_IST(d, REG_SP, md->params[s3].regoff * 4);
2732 if (!md->params[s3].inmemory) {
2733 s1 = rd->argfltregs[md->params[s3].regoff];
2734 var_to_reg_flt(d, src, s1);
2737 var_to_reg_flt(d, src, REG_FTMP1);
2738 if (IS_2_WORD_TYPE(src->type)) {
2739 M_DST(d, REG_SP, md->params[s3].regoff * 4);
2741 M_FST(d, REG_SP, md->params[s3].regoff * 4);
2747 switch (iptr->opc) {
2749 disp = dseg_addaddress(cd, bte->fp);
2750 d = md->returntype.type;
2752 M_ALD(REG_PV, REG_PV, disp); /* pointer to built-in-function */
2755 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2757 M_LDA(REG_PV, REG_ITMP1, -disp);
2759 /* if op1 == true, we need to check for an exception */
2761 if (iptr->op1 == true) {
2762 M_CMPI(REG_RESULT, 0);
2764 codegen_addxexceptionrefs(cd, mcodeptr);
2768 case ICMD_INVOKESPECIAL:
2769 gen_nullptr_check(rd->argintregs[0]);
2770 M_ILD(REG_ITMP1, rd->argintregs[0], 0); /* hardware nullptr */
2773 case ICMD_INVOKESTATIC:
2775 unresolved_method *um = iptr->target;
2777 disp = dseg_addaddress(cd, NULL);
2779 codegen_addpatchref(cd, mcodeptr,
2780 PATCHER_invokestatic_special, um, disp);
2782 if (opt_showdisassemble)
2785 d = md->returntype.type;
2788 disp = dseg_addaddress(cd, lm->stubroutine);
2789 d = md->returntype.type;
2792 M_ALD(REG_PV, REG_PV, disp);
2795 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2797 M_LDA(REG_PV, REG_ITMP1, -disp);
2800 case ICMD_INVOKEVIRTUAL:
2801 gen_nullptr_check(rd->argintregs[0]);
2804 unresolved_method *um = iptr->target;
2806 codegen_addpatchref(cd, mcodeptr,
2807 PATCHER_invokevirtual, um, 0);
2809 if (opt_showdisassemble)
2813 d = md->returntype.type;
2816 s1 = OFFSET(vftbl_t, table[0]) +
2817 sizeof(methodptr) * lm->vftblindex;
2818 d = md->returntype.type;
2821 M_ALD(REG_METHODPTR, rd->argintregs[0],
2822 OFFSET(java_objectheader, vftbl));
2823 M_ALD(REG_PV, REG_METHODPTR, s1);
2826 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2828 M_LDA(REG_PV, REG_ITMP1, -disp);
2831 case ICMD_INVOKEINTERFACE:
2832 gen_nullptr_check(rd->argintregs[0]);
2835 unresolved_method *um = iptr->target;
2837 codegen_addpatchref(cd, mcodeptr,
2838 PATCHER_invokeinterface, um, 0);
2840 if (opt_showdisassemble)
2845 d = md->returntype.type;
2848 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2849 sizeof(methodptr*) * lm->class->index;
2851 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2853 d = md->returntype.type;
2856 M_ALD(REG_METHODPTR, rd->argintregs[0],
2857 OFFSET(java_objectheader, vftbl));
2858 M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
2859 M_ALD(REG_PV, REG_METHODPTR, s2);
2862 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2864 M_LDA(REG_PV, REG_ITMP1, -disp);
2868 /* d contains return type */
2870 if (d != TYPE_VOID) {
2871 if (IS_INT_LNG_TYPE(iptr->dst->type)) {
2872 if (IS_2_WORD_TYPE(iptr->dst->type)) {
2873 s1 = reg_of_var(rd, iptr->dst,
2874 PACK_REGS(REG_RESULT2, REG_RESULT));
2875 M_TINTMOVE(iptr->dst->type,
2876 PACK_REGS(REG_RESULT2, REG_RESULT), s1);
2877 store_reg_to_var_lng(iptr->dst, s1);
2879 s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
2880 M_TINTMOVE(iptr->dst->type, REG_RESULT, s1);
2881 store_reg_to_var_int(iptr->dst, s1);
2884 s1 = reg_of_var(rd, iptr->dst, REG_FRESULT);
2885 M_FLTMOVE(REG_FRESULT, s1);
2886 if (IS_2_WORD_TYPE(iptr->dst->type)) {
2887 store_reg_to_var_dbl(iptr->dst, s1);
2889 store_reg_to_var_flt(iptr->dst, s1);
2896 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2897 /* op1: 0 == array, 1 == class */
2898 /* val.a: (classinfo*) superclass */
2900 /* superclass is an interface:
2902 * OK if ((sub == NULL) ||
2903 * (sub->vftbl->interfacetablelength > super->index) &&
2904 * (sub->vftbl->interfacetable[-super->index] != NULL));
2906 * superclass is a class:
2908 * OK if ((sub == NULL) || (0
2909 * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
2910 * super->vftbl->diffvall));
2913 if (iptr->op1 == 1) {
2914 /* object type cast-check */
2917 vftbl_t *supervftbl;
2920 super = (classinfo *) iptr->val.a;
2927 superindex = super->index;
2928 supervftbl = super->vftbl;
2931 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
2932 codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
2934 var_to_reg_int(s1, src, REG_ITMP1);
2936 /* calculate interface checkcast code size */
2940 s2 += (opt_showdisassemble ? 1 : 0);
2942 /* calculate class checkcast code size */
2944 s3 = 8 + (s1 == REG_ITMP1);
2946 s3 += (opt_showdisassemble ? 1 : 0);
2948 /* if class is not resolved, check which code to call */
2952 M_BEQ(3 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
2954 disp = dseg_adds4(cd, 0); /* super->flags */
2956 codegen_addpatchref(cd, mcodeptr,
2957 PATCHER_checkcast_instanceof_flags,
2958 (constant_classref *) iptr->target, disp);
2960 if (opt_showdisassemble)
2963 M_ILD(REG_ITMP2, REG_PV, disp);
2964 M_AND_IMM(REG_ITMP2, ACC_INTERFACE, REG_ITMP2);
2968 /* interface checkcast code */
2970 if (!super || (super->flags & ACC_INTERFACE)) {
2976 codegen_addpatchref(cd, mcodeptr,
2977 PATCHER_checkcast_instanceof_interface,
2978 (constant_classref *) iptr->target, 0);
2980 if (opt_showdisassemble)
2984 M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2985 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2986 M_LDATST(REG_ITMP3, REG_ITMP3, -superindex);
2988 codegen_addxcastrefs(cd, mcodeptr);
2989 M_ALD(REG_ITMP3, REG_ITMP2,
2990 OFFSET(vftbl_t, interfacetable[0]) -
2991 superindex * sizeof(methodptr*));
2994 codegen_addxcastrefs(cd, mcodeptr);
3000 /* class checkcast code */
3002 if (!super || !(super->flags & ACC_INTERFACE)) {
3003 disp = dseg_addaddress(cd, supervftbl);
3010 codegen_addpatchref(cd, mcodeptr,
3011 PATCHER_checkcast_class,
3012 (constant_classref *) iptr->target,
3015 if (opt_showdisassemble)
3019 M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
3020 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3021 codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
3023 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
3024 M_ALD(REG_ITMP2, REG_PV, disp);
3025 if (s1 != REG_ITMP1) {
3026 M_ILD(REG_ITMP1, REG_ITMP2, OFFSET(vftbl_t, baseval));
3027 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
3028 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3029 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
3031 M_ISUB(REG_ITMP3, REG_ITMP1, REG_ITMP3);
3033 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
3034 M_ISUB(REG_ITMP3, REG_ITMP2, REG_ITMP3);
3035 M_ALD(REG_ITMP2, REG_PV, disp);
3036 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
3037 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3038 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
3041 M_CMPU(REG_ITMP3, REG_ITMP2);
3043 codegen_addxcastrefs(cd, mcodeptr);
3045 d = reg_of_var(rd, iptr->dst, s1);
3048 /* array type cast-check */
3050 var_to_reg_int(s1, src, rd->argintregs[0]);
3051 M_INTMOVE(s1, rd->argintregs[0]);
3053 disp = dseg_addaddress(cd, iptr->val.a);
3055 if (iptr->val.a == NULL) {
3056 codegen_addpatchref(cd, mcodeptr,
3057 PATCHER_builtin_arraycheckcast,
3058 (constant_classref *) iptr->target,
3061 if (opt_showdisassemble)
3065 M_ALD(rd->argintregs[1], REG_PV, disp);
3066 disp = dseg_addaddress(cd, BUILTIN_arraycheckcast);
3067 M_ALD(REG_ITMP2, REG_PV, disp);
3072 codegen_addxcastrefs(cd, mcodeptr);
3074 var_to_reg_int(s1, src, REG_ITMP1);
3075 d = reg_of_var(rd, iptr->dst, s1);
3078 store_reg_to_var_adr(iptr->dst, d);
3081 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
3082 /* val.a: (classinfo*) superclass */
3084 /* superclass is an interface:
3086 * return (sub != NULL) &&
3087 * (sub->vftbl->interfacetablelength > super->index) &&
3088 * (sub->vftbl->interfacetable[-super->index] != NULL);
3090 * superclass is a class:
3092 * return ((sub != NULL) && (0
3093 * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
3094 * super->vftbl->diffvall));
3099 vftbl_t *supervftbl;
3102 super = (classinfo *) iptr->val.a;
3109 superindex = super->index;
3110 supervftbl = super->vftbl;
3113 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3114 codegen_threadcritrestart(cd, (u1*) mcodeptr - cd->mcodebase);
3116 var_to_reg_int(s1, src, REG_ITMP1);
3117 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
3119 M_MOV(s1, REG_ITMP1);
3123 /* calculate interface instanceof code size */
3127 s2 += (opt_showdisassemble ? 1 : 0);
3129 /* calculate class instanceof code size */
3133 s3 += (opt_showdisassemble ? 1 : 0);
3137 /* if class is not resolved, check which code to call */
3141 M_BEQ(3 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
3143 disp = dseg_adds4(cd, 0); /* super->flags */
3145 codegen_addpatchref(cd, mcodeptr,
3146 PATCHER_checkcast_instanceof_flags,
3147 (constant_classref *) iptr->target, disp);
3149 if (opt_showdisassemble)
3152 M_ILD(REG_ITMP3, REG_PV, disp);
3153 M_AND_IMM(REG_ITMP3, ACC_INTERFACE, REG_ITMP3);
3157 /* interface instanceof code */
3159 if (!super || (super->flags & ACC_INTERFACE)) {
3165 codegen_addpatchref(cd, mcodeptr,
3166 PATCHER_checkcast_instanceof_interface,
3167 (constant_classref *) iptr->target, 0);
3169 if (opt_showdisassemble)
3173 M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3174 M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
3175 M_LDATST(REG_ITMP3, REG_ITMP3, -superindex);
3177 M_ALD(REG_ITMP1, REG_ITMP1,
3178 OFFSET(vftbl_t, interfacetable[0]) -
3179 superindex * sizeof(methodptr*));
3182 M_IADD_IMM(REG_ZERO, 1, d);
3188 /* class instanceof code */
3190 if (!super || !(super->flags & ACC_INTERFACE)) {
3191 disp = dseg_addaddress(cd, supervftbl);
3198 codegen_addpatchref(cd, mcodeptr,
3199 PATCHER_instanceof_class,
3200 (constant_classref *) iptr->target,
3203 if (opt_showdisassemble) {
3208 M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3209 M_ALD(REG_ITMP2, REG_PV, disp);
3210 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3211 codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
3213 M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
3214 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
3215 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
3216 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3217 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
3219 M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
3220 M_CMPU(REG_ITMP1, REG_ITMP2);
3223 M_IADD_IMM(REG_ZERO, 1, d);
3225 store_reg_to_var_int(iptr->dst, d);
3229 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
3230 /* op1 = dimension, val.a = array descriptor */
3232 /* check for negative sizes and copy sizes to stack if necessary */
3234 MCODECHECK((iptr->op1 << 1) + 64);
3236 for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
3237 /* copy SAVEDVAR sizes to stack */
3239 if (src->varkind != ARGVAR) {
3240 var_to_reg_int(s2, src, REG_ITMP1);
3241 #if defined(__DARWIN__)
3242 M_IST(s2, REG_SP, LA_SIZE + (s1 + INT_ARG_CNT) * 4);
3244 M_IST(s2, REG_SP, LA_SIZE + (s1 + 3) * 4);
3249 /* a0 = dimension count */
3251 ICONST(rd->argintregs[0], iptr->op1);
3253 /* is patcher function set? */
3256 disp = dseg_addaddress(cd, NULL);
3258 codegen_addpatchref(cd, mcodeptr,
3259 PATCHER_builtin_multianewarray,
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);
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 codegen_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 COMPSTUBSIZE 6
3793 u1 *createcompilerstub(methodinfo *m)
3795 s4 *s = CNEW(s4, COMPSTUBSIZE); /* memory to hold the stub */
3796 s4 *mcodeptr = s; /* code generation pointer */
3798 M_LDA(REG_ITMP1, REG_PV, 4 * 4);
3799 M_ALD_INTERN(REG_PV, REG_PV, 5 * 4);
3803 s[4] = (s4) m; /* literals to be adressed */
3804 s[5] = (s4) asm_call_jit_compiler; /* jump directly via PV from above */
3806 asm_cacheflush((void *) s, (u1 *) mcodeptr - (u1 *) s);
3808 #if defined(STATISTICS)
3810 count_cstub_len += COMPSTUBSIZE * 4;
3817 /* createnativestub ************************************************************
3819 Creates a stub routine which calls a native method.
3821 *******************************************************************************/
3823 u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
3824 registerdata *rd, methoddesc *nmd)
3826 s4 *mcodeptr; /* code generation pointer */
3827 s4 stackframesize; /* size of stackframe if needed */
3830 s4 i, j; /* count variables */
3835 /* set some variables */
3838 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
3840 /* calculate stackframe size */
3843 sizeof(stackframeinfo) / SIZEOF_VOID_P +
3844 sizeof(localref_table) / SIZEOF_VOID_P +
3845 4 + /* 4 stackframeinfo arguments (darwin)*/
3846 nmd->paramcount * 2 + /* assume all arguments are doubles */
3849 stackframesize = (stackframesize + 3) & ~3; /* keep stack 16-byte aligned */
3852 /* create method header */
3854 (void) dseg_addaddress(cd, m); /* MethodPointer */
3855 (void) dseg_adds4(cd, stackframesize * 4); /* FrameSize */
3856 (void) dseg_adds4(cd, 0); /* IsSync */
3857 (void) dseg_adds4(cd, 0); /* IsLeaf */
3858 (void) dseg_adds4(cd, 0); /* IntSave */
3859 (void) dseg_adds4(cd, 0); /* FltSave */
3860 (void) dseg_addlinenumbertablesize(cd);
3861 (void) dseg_adds4(cd, 0); /* ExTableSize */
3864 /* initialize mcode variables */
3866 mcodeptr = (s4 *) cd->mcodebase;
3867 cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
3873 M_AST_INTERN(REG_ZERO, REG_SP, LA_LR_OFFSET);
3874 M_STWU(REG_SP, REG_SP, -(stackframesize * 4));
3878 /* parent_argbase == stackframesize * 4 */
3879 mcodeptr = codegen_trace_args(m, cd, rd, mcodeptr, stackframesize * 4 ,
3884 /* get function address (this must happen before the stackframeinfo) */
3886 funcdisp = dseg_addaddress(cd, f);
3888 #if !defined(ENABLE_STATICVM)
3890 codegen_addpatchref(cd, mcodeptr, PATCHER_resolve_native, m, funcdisp);
3892 if (opt_showdisassemble)
3897 /* save integer and float argument registers */
3899 for (i = 0, j = 0; i < md->paramcount && j < INT_ARG_CNT; i++) {
3900 t = md->paramtypes[i].type;
3902 if (IS_INT_LNG_TYPE(t)) {
3903 s1 = md->params[i].regoff;
3904 if (IS_2_WORD_TYPE(t)) {
3905 M_IST(rd->argintregs[GET_HIGH_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3907 M_IST(rd->argintregs[GET_LOW_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3910 M_IST(rd->argintregs[s1], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3916 for (i = 0; i < md->paramcount && j < FLT_ARG_CNT; i++) {
3917 if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
3918 s1 = md->params[i].regoff;
3919 M_DST(rd->argfltregs[s1], REG_SP, LA_SIZE + 4 * 4 + j * 8);
3924 /* create native stack info */
3926 M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[0]);
3927 M_MOV(REG_PV, rd->argintregs[1]);
3928 M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[2]);
3929 M_ALD(rd->argintregs[3], REG_SP, stackframesize * 4 + LA_LR_OFFSET);
3930 disp = dseg_addaddress(cd, codegen_start_native_call);
3931 M_ALD(REG_ITMP1, REG_PV, disp);
3935 /* restore integer and float argument registers */
3937 for (i = 0, j = 0; i < md->paramcount && j < INT_ARG_CNT; i++) {
3938 t = md->paramtypes[i].type;
3940 if (IS_INT_LNG_TYPE(t)) {
3941 s1 = md->params[i].regoff;
3943 if (IS_2_WORD_TYPE(t)) {
3944 M_ILD(rd->argintregs[GET_HIGH_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3946 M_ILD(rd->argintregs[GET_LOW_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3949 M_ILD(rd->argintregs[s1], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3955 for (i = 0; i < md->paramcount && j < FLT_ARG_CNT; i++) {
3956 if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
3957 s1 = md->params[i].regoff;
3958 M_DLD(rd->argfltregs[i], REG_SP, LA_SIZE + 4 * 4 + j * 8);
3963 /* copy or spill arguments to new locations */
3965 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
3966 t = md->paramtypes[i].type;
3968 if (IS_INT_LNG_TYPE(t)) {
3969 if (!md->params[i].inmemory) {
3970 if (IS_2_WORD_TYPE(t))
3972 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
3973 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
3975 s1 = rd->argintregs[md->params[i].regoff];
3977 if (!nmd->params[j].inmemory) {
3978 if (IS_2_WORD_TYPE(t))
3980 rd->argintregs[GET_LOW_REG(nmd->params[j].regoff)],
3981 rd->argintregs[GET_HIGH_REG(nmd->params[j].regoff)]);
3983 s2 = rd->argintregs[nmd->params[j].regoff];
3984 M_TINTMOVE(t, s1, s2);
3987 s2 = nmd->params[j].regoff;
3988 if (IS_2_WORD_TYPE(t)) {
3989 M_IST(GET_HIGH_REG(s1), REG_SP, s2 * 4);
3990 M_IST(GET_LOW_REG(s1), REG_SP, s2 * 4 + 4);
3992 M_IST(s1, REG_SP, s2 * 4);
3997 s1 = md->params[i].regoff + stackframesize;
3998 s2 = nmd->params[j].regoff;
4000 M_ILD(REG_ITMP1, REG_SP, s1 * 4);
4001 if (IS_2_WORD_TYPE(t)) {
4002 M_ILD(REG_ITMP2, REG_SP, s1 * 4 + 4);
4004 M_IST(REG_ITMP1, REG_SP, s2 * 4);
4005 if (IS_2_WORD_TYPE(t)) {
4006 M_IST(REG_ITMP2, REG_SP, s2 * 4 + 4);
4011 /* We only copy spilled float arguments, as the float argument */
4012 /* registers keep unchanged. */
4014 if (md->params[i].inmemory) {
4015 s1 = md->params[i].regoff + stackframesize;
4016 s2 = nmd->params[j].regoff;
4018 if (IS_2_WORD_TYPE(t)) {
4019 M_DLD(REG_FTMP1, REG_SP, s1 * 4);
4020 M_DST(REG_FTMP1, REG_SP, s2 * 4);
4023 M_FLD(REG_FTMP1, REG_SP, s1 * 4);
4024 M_FST(REG_FTMP1, REG_SP, s2 * 4);
4030 /* put class into second argument register */
4032 if (m->flags & ACC_STATIC) {
4033 disp = dseg_addaddress(cd, m->class);
4034 M_ALD(rd->argintregs[1], REG_PV, disp);
4037 /* put env into first argument register */
4039 disp = dseg_addaddress(cd, &env);
4040 M_ALD(rd->argintregs[0], REG_PV, disp);
4042 /* generate the actual native call */
4044 M_ALD(REG_ITMP3, REG_PV, funcdisp);
4048 /* save return value */
4050 if (md->returntype.type != TYPE_VOID) {
4051 if (IS_INT_LNG_TYPE(md->returntype.type)) {
4052 if (IS_2_WORD_TYPE(md->returntype.type))
4053 M_IST(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
4054 M_IST(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
4056 if (IS_2_WORD_TYPE(md->returntype.type))
4057 M_DST(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4059 M_FST(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4063 /* remove native stackframe info */
4065 M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[0]);
4066 disp = dseg_addaddress(cd, codegen_finish_native_call);
4067 M_ALD(REG_ITMP1, REG_PV, disp);
4071 /* print call trace */
4074 /* just restore the value we need, don't care about the other */
4076 if (md->returntype.type != TYPE_VOID) {
4077 if (IS_INT_LNG_TYPE(md->returntype.type)) {
4078 if (IS_2_WORD_TYPE(md->returntype.type))
4079 M_ILD(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
4080 M_ILD(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
4082 if (IS_2_WORD_TYPE(md->returntype.type))
4083 M_DLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4085 M_FLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4089 M_LDA(REG_SP, REG_SP, -(LA_SIZE + (1 + 2 + 2 + 1) * 4));
4091 /* keep this order */
4092 switch (md->returntype.type) {
4095 #if defined(__DARWIN__)
4096 M_MOV(REG_RESULT, rd->argintregs[2]);
4097 M_CLR(rd->argintregs[1]);
4099 M_MOV(REG_RESULT, rd->argintregs[3]);
4100 M_CLR(rd->argintregs[2]);
4105 #if defined(__DARWIN__)
4106 M_MOV(REG_RESULT2, rd->argintregs[2]);
4107 M_MOV(REG_RESULT, rd->argintregs[1]);
4109 M_MOV(REG_RESULT2, rd->argintregs[3]);
4110 M_MOV(REG_RESULT, rd->argintregs[2]);
4115 M_FLTMOVE(REG_FRESULT, rd->argfltregs[0]);
4116 M_FLTMOVE(REG_FRESULT, rd->argfltregs[1]);
4117 disp = dseg_addaddress(cd, m);
4118 M_ALD(rd->argintregs[0], REG_PV, disp);
4120 disp = dseg_addaddress(cd, builtin_displaymethodstop);
4121 M_ALD(REG_ITMP2, REG_PV, disp);
4125 M_LDA(REG_SP, REG_SP, LA_SIZE + (1 + 2 + 2 + 1) * 4);
4128 /* check for exception */
4130 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
4131 disp = dseg_addaddress(cd, builtin_get_exceptionptrptr);
4132 M_ALD(REG_ITMP1, REG_PV, disp);
4135 M_MOV(REG_RESULT, REG_ITMP2);
4137 disp = dseg_addaddress(cd, &_no_threads_exceptionptr);
4138 M_ALD(REG_ITMP2, REG_PV, disp);
4140 M_ALD(REG_ITMP1_XPTR, REG_ITMP2, 0);/* load exception into reg. itmp1 */
4142 /* restore return value */
4144 if (md->returntype.type != TYPE_VOID) {
4145 if (IS_INT_LNG_TYPE(md->returntype.type)) {
4146 if (IS_2_WORD_TYPE(md->returntype.type))
4147 M_ILD(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
4148 M_ILD(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
4150 if (IS_2_WORD_TYPE(md->returntype.type))
4151 M_DLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4153 M_FLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4157 M_TST(REG_ITMP1_XPTR);
4158 M_BNE(4); /* if no exception then return */
4160 M_ALD(REG_ZERO, REG_SP, stackframesize * 4 + LA_LR_OFFSET); /* load ra */
4162 M_LDA(REG_SP, REG_SP, stackframesize * 4); /* remove stackframe */
4165 /* handle exception */
4168 M_AST(REG_ITMP3, REG_ITMP2, 0); /* store NULL into exceptionptr */
4170 M_ALD(REG_ITMP2, REG_SP, stackframesize * 4 + LA_LR_OFFSET); /* load ra */
4173 M_LDA(REG_SP, REG_SP, stackframesize * 4); /* remove stackframe */
4175 M_IADD_IMM(REG_ITMP2, -4, REG_ITMP2_XPC); /* fault address */
4177 disp = dseg_addaddress(cd, asm_handle_nat_exception);
4178 M_ALD(REG_ITMP3, REG_PV, disp);
4182 /* generate patcher stub call code */
4190 for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
4191 /* Get machine code which is patched back in later. The call is */
4192 /* 1 instruction word long. */
4194 xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
4195 mcode = (u4) *xcodeptr;
4197 /* patch in the call to call the following code (done at compile */
4200 tmpmcodeptr = mcodeptr; /* save current mcodeptr */
4201 mcodeptr = xcodeptr; /* set mcodeptr to patch position */
4203 M_BL(tmpmcodeptr - (xcodeptr + 1));
4205 mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
4207 /* create stack frame - keep stack 16-byte aligned */
4209 M_AADD_IMM(REG_SP, -8 * 4, REG_SP);
4211 /* move return address onto stack */
4214 M_AST(REG_ZERO, REG_SP, 5 * 4);
4216 /* move pointer to java_objectheader onto stack */
4218 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
4219 /* order reversed because of data segment layout */
4221 (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */
4222 disp = dseg_addaddress(cd, NULL); /* vftbl */
4224 M_LDA(REG_ITMP3, REG_PV, disp);
4225 M_AST(REG_ITMP3, REG_SP, 4 * 4);
4230 /* move machine code onto stack */
4232 disp = dseg_adds4(cd, mcode);
4233 M_ILD(REG_ITMP3, REG_PV, disp);
4234 M_IST(REG_ITMP3, REG_SP, 3 * 4);
4236 /* move class/method/field reference onto stack */
4238 disp = dseg_addaddress(cd, pref->ref);
4239 M_ALD(REG_ITMP3, REG_PV, disp);
4240 M_AST(REG_ITMP3, REG_SP, 2 * 4);
4242 /* move data segment displacement onto stack */
4244 disp = dseg_addaddress(cd, pref->disp);
4245 M_ILD(REG_ITMP3, REG_PV, disp);
4246 M_IST(REG_ITMP3, REG_SP, 1 * 4);
4248 /* move patcher function pointer onto stack */
4250 disp = dseg_addaddress(cd, pref->patcher);
4251 M_ALD(REG_ITMP3, REG_PV, disp);
4252 M_AST(REG_ITMP3, REG_SP, 0 * 4);
4254 disp = dseg_addaddress(cd, asm_wrapper_patcher);
4255 M_ALD(REG_ITMP3, REG_PV, disp);
4261 codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
4263 asm_cacheflush((void *) (ptrint) m->entrypoint, ((u1 *) mcodeptr - cd->mcodebase));
4265 return m->entrypoint;
4269 s4 *codegen_trace_args(methodinfo *m, codegendata *cd, registerdata *rd,
4270 s4 *mcodeptr, s4 parentargs_base, bool nativestub)
4281 /* Build up Stackframe for builtin_trace_args call (a multiple of 16) */
4283 /* LA + TRACE_ARGS_NUM u8 args + methodinfo + LR */
4284 /* LA_SIZE(=6*4) + 8*8 + 4 + 4 + 0(Padding) */
4285 /* 6 * 4 + 8 * 8 + 2 * 4 = 12 * 8 = 6 * 16 */
4287 /* LA + (TRACE_ARGS_NUM - INT_ARG_CNT/2) u8 args + methodinfo */
4288 /* + INT_ARG_CNT * 4 ( save integer registers) + LR + 8 + 8 (Padding) */
4289 /* LA_SIZE(=2*4) + 4 * 8 + 4 + 8 * 4 + 4 + 8 */
4290 /* 2 * 4 + 4 * 8 + 10 * 4 + 1 * 8 + 8= 12 * 8 = 6 * 16 */
4292 /* in nativestubs no Place to save the LR (Link Register) would be needed */
4293 /* but since the stack frame has to be aligned the 4 Bytes would have to */
4294 /* be padded again */
4296 #if defined(__DARWIN__)
4297 stack_size = LA_SIZE + (TRACE_ARGS_NUM + 1) * 8;
4299 stack_size = 6 * 16;
4301 M_LDA(REG_SP, REG_SP, -stack_size);
4305 M_IST(REG_ITMP3, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8 + 1 * 4);
4307 M_CLR(REG_ITMP1); /* clear help register */
4309 /* save up to TRACE_ARGS_NUM arguments into the reserved stack space */
4310 #if defined(__DARWIN__)
4311 /* Copy Params starting from first to Stack */
4312 /* since TRACE_ARGS == INT_ARG_CNT all used integer argument regs */
4316 /* Copy Params starting from fifth to Stack (INT_ARG_CNT/2) are in */
4317 /* integer argument regs */
4318 /* all integer argument registers have to be saved */
4319 for (p = 0; p < 8; p++) {
4320 d = rd->argintregs[p];
4321 /* save integer argument registers */
4322 M_IST(d, REG_SP, LA_SIZE + 4 * 8 + 4 + p * 4);
4326 stack_off = LA_SIZE;
4327 for (; p < md->paramcount && p < TRACE_ARGS_NUM; p++, stack_off += 8) {
4328 t = md->paramtypes[p].type;
4329 if (IS_INT_LNG_TYPE(t)) {
4330 if (!md->params[p].inmemory) { /* Param in Arg Reg */
4331 if (IS_2_WORD_TYPE(t)) {
4332 M_IST(rd->argintregs[GET_HIGH_REG(md->params[p].regoff)]
4333 , REG_SP, stack_off);
4334 M_IST(rd->argintregs[GET_LOW_REG(md->params[p].regoff)]
4335 , REG_SP, stack_off + 4);
4337 M_IST(REG_ITMP1, REG_SP, stack_off);
4338 M_IST(rd->argintregs[md->params[p].regoff]
4339 , REG_SP, stack_off + 4);
4341 } else { /* Param on Stack */
4342 s1 = (md->params[p].regoff + parentargs_base) * 4
4344 if (IS_2_WORD_TYPE(t)) {
4345 M_ILD(REG_ITMP2, REG_SP, s1);
4346 M_IST(REG_ITMP2, REG_SP, stack_off);
4347 M_ILD(REG_ITMP2, REG_SP, s1 + 4);
4348 M_IST(REG_ITMP2, REG_SP, stack_off + 4);
4350 M_IST(REG_ITMP1, REG_SP, stack_off);
4351 M_ILD(REG_ITMP2, REG_SP, s1);
4352 M_IST(REG_ITMP2, REG_SP, stack_off + 4);
4355 } else { /* IS_FLT_DBL_TYPE(t) */
4356 if (!md->params[p].inmemory) { /* in Arg Reg */
4357 s1 = rd->argfltregs[md->params[p].regoff];
4358 if (!IS_2_WORD_TYPE(t)) {
4359 M_IST(REG_ITMP1, REG_SP, stack_off);
4360 M_FST(s1, REG_SP, stack_off + 4);
4362 M_DST(s1, REG_SP, stack_off);
4364 } else { /* on Stack */
4365 /* this should not happen */
4370 /* load first 4 (==INT_ARG_CNT/2) arguments into integer registers */
4371 #if defined(__DARWIN__)
4372 for (p = 0; p < 8; p++) {
4373 d = rd->argintregs[p];
4374 M_ILD(d, REG_SP, LA_SIZE + p * 4);
4378 /* Set integer and float argument registers vor trace_args call */
4379 /* offset to saved integer argument registers */
4380 stack_off = LA_SIZE + 4 * 8 + 4;
4381 for (p = 0; (p < 4) && (p < md->paramcount); p++) {
4382 t = md->paramtypes[p].type;
4383 if (IS_INT_LNG_TYPE(t)) {
4384 /* "stretch" int types */
4385 if (!IS_2_WORD_TYPE(t)) {
4386 M_CLR(rd->argintregs[2 * p]);
4387 M_ILD(rd->argintregs[2 * p + 1], REG_SP,stack_off);
4390 M_ILD(rd->argintregs[2 * p + 1], REG_SP,stack_off + 4);
4391 M_ILD(rd->argintregs[2 * p], REG_SP,stack_off);
4394 } else { /* Float/Dbl */
4395 if (!md->params[p].inmemory) { /* Param in Arg Reg */
4396 /* use reserved Place on Stack (sp + 5 * 16) to copy */
4397 /* float/double arg reg to int reg */
4398 s1 = rd->argfltregs[md->params[p].regoff];
4399 if (!IS_2_WORD_TYPE(t)) {
4400 M_FST(s1, REG_SP, 5 * 16);
4401 M_ILD(rd->argintregs[2 * p + 1], REG_SP, 5 * 16);
4402 M_CLR(rd->argintregs[2 * p]);
4404 M_DST(s1, REG_SP, 5 * 16);
4405 M_ILD(rd->argintregs[2 * p + 1], REG_SP, 5 * 16 + 4);
4406 M_ILD(rd->argintregs[2 * p], REG_SP, 5 * 16);
4413 /* put methodinfo pointer on Stackframe */
4414 p = dseg_addaddress(cd, m);
4415 M_ALD(REG_ITMP1, REG_PV, p);
4416 #if defined(__DARWIN__)
4417 M_AST(REG_ITMP1, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8);
4419 M_AST(REG_ITMP1, REG_SP, LA_SIZE + 4 * 8);
4421 p = dseg_addaddress(cd, builtin_trace_args);
4422 M_ALD(REG_ITMP2, REG_PV, p);
4426 #if defined(__DARWIN__)
4427 /* restore integer argument registers from the reserved stack space */
4429 stack_off = LA_SIZE;
4430 for (p = 0; p < md->paramcount && p < TRACE_ARGS_NUM;
4431 p++, stack_off += 8) {
4432 t = md->paramtypes[p].type;
4434 if (IS_INT_LNG_TYPE(t)) {
4435 if (!md->params[p].inmemory) {
4436 if (IS_2_WORD_TYPE(t)) {
4437 M_ILD(rd->argintregs[GET_HIGH_REG(md->params[p].regoff)]
4438 , REG_SP, stack_off);
4439 M_ILD(rd->argintregs[GET_LOW_REG(md->params[p].regoff)]
4440 , REG_SP, stack_off + 4);
4442 M_ILD(rd->argintregs[md->params[p].regoff]
4443 , REG_SP, stack_off + 4);
4450 for (p = 0; p < 8; p++) {
4451 d = rd->argintregs[p];
4452 /* save integer argument registers */
4453 M_ILD(d, REG_SP, LA_SIZE + 4 * 8 + 4 + p * 4);
4458 M_ILD(REG_ITMP3, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8 + 1 * 4);
4460 M_LDA(REG_SP, REG_SP, stack_size);
4467 * These are local overrides for various environment variables in Emacs.
4468 * Please do not remove this and leave it at the end of the file, where
4469 * Emacs will automagically detect them.
4470 * ---------------------------------------------------------------------
4473 * indent-tabs-mode: t