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 3578 2005-11-05 16:31:41Z 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/tables.h"
58 #include "vm/jit/asmpart.h"
59 #include "vm/jit/codegen.inc"
60 #include "vm/jit/jit.h"
63 # include "vm/jit/lsra.inc"
66 #include "vm/jit/parse.h"
67 #include "vm/jit/patcher.h"
68 #include "vm/jit/reg.h"
69 #include "vm/jit/reg.inc"
72 s4 *codegen_trace_args( methodinfo *m, codegendata *cd, registerdata *rd,
73 s4 *mcodeptr, s4 parentargs_base, bool nativestub);
75 /* codegen *********************************************************************
77 Generates machine code.
79 *******************************************************************************/
81 void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
83 s4 len, s1, s2, s3, d, disp;
93 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
94 builtintable_entry *bte;
97 /* prevent compiler warnings */
109 /* space to save used callee saved registers */
111 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
112 savedregs_num += 2 * (FLT_SAV_CNT - rd->savfltreguse);
114 parentargs_base = rd->memuse + savedregs_num;
116 #if defined(USE_THREADS)
117 /* space to save argument of monitor_enter and Return Values to survive */
118 /* monitor_exit. The stack position for the argument can not be shared */
119 /* with place to save the return register on PPC, since both values */
121 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
122 /* reserve 2 slots for long/double return values for monitorexit */
124 if (IS_2_WORD_TYPE(m->parseddesc->returntype.type))
125 parentargs_base += 3;
127 parentargs_base += 2;
132 /* create method header */
134 parentargs_base = (parentargs_base + 3) & ~3;
136 (void) dseg_addaddress(cd, m); /* MethodPointer */
137 (void) dseg_adds4(cd, parentargs_base * 4); /* FrameSize */
139 #if defined(USE_THREADS)
140 /* IsSync contains the offset relative to the stack pointer for the
141 argument of monitor_exit used in the exception handler. Since the
142 offset could be zero and give a wrong meaning of the flag it is
146 if (checksync && (m->flags & ACC_SYNCHRONIZED))
147 (void) dseg_adds4(cd, (rd->memuse + 1) * 4); /* IsSync */
150 (void) dseg_adds4(cd, 0); /* IsSync */
152 (void) dseg_adds4(cd, m->isleafmethod); /* IsLeaf */
153 (void) dseg_adds4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
154 (void) dseg_adds4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
156 dseg_addlinenumbertablesize(cd);
158 (void) dseg_adds4(cd, cd->exceptiontablelength); /* ExTableSize */
160 /* create exception table */
162 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
163 dseg_addtarget(cd, ex->start);
164 dseg_addtarget(cd, ex->end);
165 dseg_addtarget(cd, ex->handler);
166 (void) dseg_addaddress(cd, ex->catchtype.cls);
169 /* initialize mcode variables */
171 mcodeptr = (s4 *) cd->mcodebase;
172 cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
173 MCODECHECK(128 + m->paramcount);
175 /* create stack frame (if necessary) */
177 if (!m->isleafmethod) {
179 M_AST(REG_ZERO, REG_SP, LA_LR_OFFSET);
182 if (parentargs_base) {
183 M_STWU(REG_SP, REG_SP, -parentargs_base * 4);
186 /* save return address and used callee saved registers */
189 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
190 p--; M_IST(rd->savintregs[i], REG_SP, p * 4);
192 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
193 p -= 2; M_DST(rd->savfltregs[i], REG_SP, p * 4);
196 /* take arguments out of register or stack frame */
200 for (p = 0, l = 0; p < md->paramcount; p++) {
201 t = md->paramtypes[p].type;
202 var = &(rd->locals[l][t]);
204 if (IS_2_WORD_TYPE(t)) /* increment local counter for 2 word types */
208 s1 = md->params[p].regoff;
209 if (IS_INT_LNG_TYPE(t)) { /* integer args */
210 if (IS_2_WORD_TYPE(t))
211 s2 = PACK_REGS(rd->argintregs[GET_LOW_REG(s1)],
212 rd->argintregs[GET_HIGH_REG(s1)]);
214 s2 = rd->argintregs[s1];
215 if (!md->params[p].inmemory) { /* register arguments */
216 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
217 M_TINTMOVE(t, s2, var->regoff);
219 } else { /* reg arg -> spilled */
220 if (IS_2_WORD_TYPE(t)) {
221 M_IST(GET_HIGH_REG(s2), REG_SP, var->regoff * 4);
222 M_IST(GET_LOW_REG(s2), REG_SP, var->regoff * 4 + 4);
224 M_IST(s2, REG_SP, var->regoff * 4);
228 } else { /* stack arguments */
229 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
230 if (IS_2_WORD_TYPE(t)) {
231 M_ILD(GET_HIGH_REG(var->regoff), REG_SP,
232 (parentargs_base + s1) * 4);
233 M_ILD(GET_LOW_REG(var->regoff), REG_SP,
234 (parentargs_base + s1) * 4 + 4);
236 M_ILD(var->regoff, REG_SP, (parentargs_base + s1) * 4);
239 } else { /* stack arg -> spilled */
241 M_ILD(REG_ITMP1, REG_SP, (parentargs_base + s1) * 4);
242 M_IST(REG_ITMP1, REG_SP, var->regoff * 4);
243 if (IS_2_WORD_TYPE(t)) {
244 M_ILD(REG_ITMP1, REG_SP, (parentargs_base + s1) * 4 +4);
245 M_IST(REG_ITMP1, REG_SP, var->regoff * 4 + 4);
248 /* Reuse Memory Position on Caller Stack */
249 var->regoff = parentargs_base + s1;
254 } else { /* floating args */
255 if (!md->params[p].inmemory) { /* register arguments */
256 s2 = rd->argfltregs[s1];
257 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
258 M_FLTMOVE(s2, var->regoff);
260 } else { /* reg arg -> spilled */
261 if (IS_2_WORD_TYPE(t))
262 M_DST(s2, REG_SP, var->regoff * 4);
264 M_FST(s2, REG_SP, var->regoff * 4);
267 } else { /* stack arguments */
268 if (!(var->flags & INMEMORY)) { /* stack-arg -> register */
269 if (IS_2_WORD_TYPE(t))
270 M_DLD(var->regoff, REG_SP, (parentargs_base + s1) * 4);
273 M_FLD(var->regoff, REG_SP, (parentargs_base + s1) * 4);
275 } else { /* stack-arg -> spilled */
277 if (IS_2_WORD_TYPE(t)) {
278 M_DLD(REG_FTMP1, REG_SP, (parentargs_base + s1) * 4);
279 M_DST(REG_FTMP1, REG_SP, var->regoff * 4);
280 var->regoff = parentargs_base + s1;
283 M_FLD(REG_FTMP1, REG_SP, (parentargs_base + s1) * 4);
284 M_FST(REG_FTMP1, REG_SP, var->regoff * 4);
287 /* Reuse Memory Position on Caller Stack */
288 var->regoff = parentargs_base + s1;
295 /* save monitorenter argument */
297 #if defined(USE_THREADS)
298 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
299 /* stack offset for monitor argument */
305 M_LDA(REG_SP, REG_SP, -(INT_ARG_CNT * 4 + FLT_ARG_CNT * 8));
307 for (p = 0; p < INT_ARG_CNT; p++)
308 M_IST(rd->argintregs[p], REG_SP, p * 4);
310 for (p = 0; p < FLT_ARG_CNT * 2; p += 2)
311 M_DST(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 4);
313 s1 += INT_ARG_CNT + FLT_ARG_CNT;
317 /* decide which monitor enter function to call */
319 if (m->flags & ACC_STATIC) {
320 p = dseg_addaddress(cd, m->class);
321 M_ALD(REG_ITMP1, REG_PV, p);
322 M_AST(REG_ITMP1, REG_SP, s1 * 4);
323 M_MOV(REG_ITMP1, rd->argintregs[0]);
324 p = dseg_addaddress(cd, BUILTIN_staticmonitorenter);
325 M_ALD(REG_ITMP3, REG_PV, p);
330 M_TST(rd->argintregs[0]);
332 codegen_addxnullrefs(cd, mcodeptr);
333 M_AST(rd->argintregs[0], REG_SP, s1 * 4);
334 p = dseg_addaddress(cd, BUILTIN_monitorenter);
335 M_ALD(REG_ITMP3, REG_PV, p);
342 for (p = 0; p < INT_ARG_CNT; p++)
343 M_ILD(rd->argintregs[p], REG_SP, p * 4);
345 for (p = 0; p < FLT_ARG_CNT; p++)
346 M_DLD(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 4);
349 M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT) * 8);
355 /* call trace function */
358 mcodeptr = codegen_trace_args(m, cd, rd, mcodeptr, parentargs_base, false);
360 } /* if (runverbose) */
363 /* end of header generation */
365 /* walk through all basic blocks */
366 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
368 bptr->mpc = (s4) ((u1 *) mcodeptr - cd->mcodebase);
370 if (bptr->flags >= BBREACHED) {
372 /* branch resolving */
376 for (brefs = bptr->branchrefs; brefs != NULL; brefs = brefs->next) {
377 gen_resolvebranch((u1*) cd->mcodebase + brefs->branchpos,
383 /* copy interface registers to their destination */
391 while (src != NULL) {
393 if ((len == 0) && (bptr->type != BBTYPE_STD)) {
394 /* d = reg_of_var(m, src, REG_ITMP1); */
395 if (!(src->flags & INMEMORY))
399 M_INTMOVE(REG_ITMP1, d);
400 store_reg_to_var_int(src, d);
406 while (src != NULL) {
408 if ((len == 0) && (bptr->type != BBTYPE_STD)) {
409 d = reg_of_var(rd, src, REG_ITMP1);
410 M_INTMOVE(REG_ITMP1, d);
411 store_reg_to_var_int(src, d);
413 if (src->type == TYPE_LNG)
414 d = reg_of_var(rd, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
416 d = reg_of_var(rd, src, REG_IFTMP);
417 if ((src->varkind != STACKVAR)) {
419 if (IS_FLT_DBL_TYPE(s2)) {
420 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
421 s1 = rd->interfaces[len][s2].regoff;
424 if (IS_2_WORD_TYPE(s2)) {
426 4 * rd->interfaces[len][s2].regoff);
429 4 * rd->interfaces[len][s2].regoff);
432 store_reg_to_var_flt(src, d);
434 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
435 s1 = rd->interfaces[len][s2].regoff;
438 if (IS_2_WORD_TYPE(s2)) {
439 M_ILD(GET_HIGH_REG(d), REG_SP,
440 4 * rd->interfaces[len][s2].regoff);
441 M_ILD(GET_LOW_REG(d), REG_SP,
442 4 * rd->interfaces[len][s2].regoff + 4);
445 4 * rd->interfaces[len][s2].regoff);
448 store_reg_to_var_int(src, d);
458 /* walk through all instructions */
464 for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) {
465 if (iptr->line != currentline) {
466 dseg_addlinenumber(cd, iptr->line, (u1 *) mcodeptr);
467 currentline = iptr->line;
470 MCODECHECK(64); /* an instruction usually needs < 64 words */
473 case ICMD_NOP: /* ... ==> ... */
474 case ICMD_INLINE_START:
475 case ICMD_INLINE_END:
478 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
480 var_to_reg_int(s1, src, REG_ITMP1);
483 codegen_addxnullrefs(cd, mcodeptr);
486 /* constant operations ************************************************/
488 case ICMD_ICONST: /* ... ==> ..., constant */
489 /* op1 = 0, val.i = constant */
491 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
492 ICONST(d, iptr->val.i);
493 store_reg_to_var_int(iptr->dst, d);
496 case ICMD_LCONST: /* ... ==> ..., constant */
497 /* op1 = 0, val.l = constant */
499 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
500 LCONST(d, iptr->val.l);
501 store_reg_to_var_int(iptr->dst, d);
504 case ICMD_FCONST: /* ... ==> ..., constant */
505 /* op1 = 0, val.f = constant */
507 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
508 a = dseg_addfloat(cd, iptr->val.f);
510 store_reg_to_var_flt(iptr->dst, d);
513 case ICMD_DCONST: /* ... ==> ..., constant */
514 /* op1 = 0, val.d = constant */
516 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
517 a = dseg_adddouble(cd, iptr->val.d);
519 store_reg_to_var_flt(iptr->dst, d);
522 case ICMD_ACONST: /* ... ==> ..., constant */
523 /* op1 = 0, val.a = constant */
525 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
526 ICONST(d, (u4) iptr->val.a);
527 store_reg_to_var_int(iptr->dst, d);
531 /* load/store operations **********************************************/
533 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
534 case ICMD_ALOAD: /* op1 = local variable */
536 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
537 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
538 if ((iptr->dst->varkind == LOCALVAR) &&
539 (iptr->dst->varnum == iptr->op1))
541 if (var->flags & INMEMORY) {
542 M_ILD(d, REG_SP, var->regoff * 4);
544 M_TINTMOVE(var->type, var->regoff, d);
546 store_reg_to_var_int(iptr->dst, d);
549 case ICMD_LLOAD: /* ... ==> ..., content of local variable */
550 /* op1 = local variable */
552 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
553 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
554 if ((iptr->dst->varkind == LOCALVAR) &&
555 (iptr->dst->varnum == iptr->op1))
557 if (var->flags & INMEMORY) {
558 M_ILD(GET_HIGH_REG(d), REG_SP, var->regoff * 4);
559 M_ILD(GET_LOW_REG(d), REG_SP, var->regoff * 4 + 4);
561 M_TINTMOVE(var->type, var->regoff, d);
563 store_reg_to_var_int(iptr->dst, d);
566 case ICMD_FLOAD: /* ... ==> ..., content of local variable */
567 case ICMD_DLOAD: /* op1 = local variable */
569 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
570 if ((iptr->dst->varkind == LOCALVAR) &&
571 (iptr->dst->varnum == iptr->op1))
573 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
574 if (var->flags & INMEMORY)
575 if (IS_2_WORD_TYPE(var->type))
576 M_DLD(d, REG_SP, var->regoff * 4);
578 M_FLD(d, REG_SP, var->regoff * 4);
580 M_FLTMOVE(var->regoff, d);
582 store_reg_to_var_flt(iptr->dst, d);
586 case ICMD_ISTORE: /* ..., value ==> ... */
587 case ICMD_ASTORE: /* op1 = local variable */
589 if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1))
591 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
592 if (var->flags & INMEMORY) {
593 var_to_reg_int(s1, src, REG_ITMP1);
594 M_IST(s1, REG_SP, var->regoff * 4);
596 var_to_reg_int(s1, src, var->regoff);
597 M_TINTMOVE(var->type, s1, var->regoff);
601 case ICMD_LSTORE: /* ..., value ==> ... */
602 /* op1 = local variable */
604 if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1))
606 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
607 if (var->flags & INMEMORY) {
608 var_to_reg_int(s1, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
609 M_IST(GET_HIGH_REG(s1), REG_SP, var->regoff * 4);
610 M_IST(GET_LOW_REG(s1), REG_SP, var->regoff * 4 + 4);
612 var_to_reg_int(s1, src, var->regoff);
613 M_TINTMOVE(var->type, s1, var->regoff);
617 case ICMD_FSTORE: /* ..., value ==> ... */
618 case ICMD_DSTORE: /* op1 = local variable */
620 if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1))
622 var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
623 if (var->flags & INMEMORY) {
624 var_to_reg_flt(s1, src, REG_FTMP1);
625 if (var->type == TYPE_DBL)
626 M_DST(s1, REG_SP, var->regoff * 4);
628 M_FST(s1, REG_SP, var->regoff * 4);
630 var_to_reg_flt(s1, src, var->regoff);
631 M_FLTMOVE(s1, var->regoff);
636 /* pop/dup/swap operations ********************************************/
638 /* attention: double and longs are only one entry in CACAO ICMDs */
640 case ICMD_POP: /* ..., value ==> ... */
641 case ICMD_POP2: /* ..., value, value ==> ... */
644 case ICMD_DUP: /* ..., a ==> ..., a, a */
645 M_COPY(src, iptr->dst);
648 case ICMD_DUP_X1: /* ..., a, b ==> ..., b, a, b */
650 M_COPY(src, iptr->dst);
651 M_COPY(src->prev, iptr->dst->prev);
652 M_COPY(iptr->dst, iptr->dst->prev->prev);
655 case ICMD_DUP_X2: /* ..., a, b, c ==> ..., c, a, b, c */
657 M_COPY(src, iptr->dst);
658 M_COPY(src->prev, iptr->dst->prev);
659 M_COPY(src->prev->prev, iptr->dst->prev->prev);
660 M_COPY(iptr->dst, iptr->dst->prev->prev->prev);
663 case ICMD_DUP2: /* ..., a, b ==> ..., a, b, a, b */
665 M_COPY(src, iptr->dst);
666 M_COPY(src->prev, iptr->dst->prev);
669 case ICMD_DUP2_X1: /* ..., a, b, c ==> ..., b, c, a, b, c */
671 M_COPY(src, iptr->dst);
672 M_COPY(src->prev, iptr->dst->prev);
673 M_COPY(src->prev->prev, iptr->dst->prev->prev);
674 M_COPY(iptr->dst, iptr->dst->prev->prev->prev);
675 M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev);
678 case ICMD_DUP2_X2: /* ..., a, b, c, d ==> ..., c, d, a, b, c, d */
680 M_COPY(src, iptr->dst);
681 M_COPY(src->prev, iptr->dst->prev);
682 M_COPY(src->prev->prev, iptr->dst->prev->prev);
683 M_COPY(src->prev->prev->prev, iptr->dst->prev->prev->prev);
684 M_COPY(iptr->dst, iptr->dst->prev->prev->prev->prev);
685 M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev->prev);
688 case ICMD_SWAP: /* ..., a, b ==> ..., b, a */
690 M_COPY(src, iptr->dst->prev);
691 M_COPY(src->prev, iptr->dst);
695 /* integer operations *************************************************/
697 case ICMD_INEG: /* ..., value ==> ..., - value */
699 var_to_reg_int(s1, src, REG_ITMP1);
700 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
702 store_reg_to_var_int(iptr->dst, d);
705 case ICMD_LNEG: /* ..., value ==> ..., - value */
707 var_to_reg_int(s1, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
708 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
709 M_SUBFIC(GET_LOW_REG(s1), 0, GET_LOW_REG(d));
710 M_SUBFZE(GET_HIGH_REG(s1), GET_HIGH_REG(d));
711 store_reg_to_var_int(iptr->dst, d);
714 case ICMD_I2L: /* ..., value ==> ..., value */
716 var_to_reg_int(s1, src, REG_ITMP2);
717 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
718 M_INTMOVE(s1, GET_LOW_REG(d));
719 M_SRA_IMM(GET_LOW_REG(d), 31, GET_HIGH_REG(d));
720 store_reg_to_var_int(iptr->dst, d);
723 case ICMD_L2I: /* ..., value ==> ..., value */
725 var_to_reg_int_low(s1, src, REG_ITMP2);
726 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
728 store_reg_to_var_int(iptr->dst, d);
731 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
733 var_to_reg_int(s1, src, REG_ITMP1);
734 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
736 store_reg_to_var_int(iptr->dst, d);
739 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
741 var_to_reg_int(s1, src, REG_ITMP1);
742 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
744 store_reg_to_var_int(iptr->dst, d);
747 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
749 var_to_reg_int(s1, src, REG_ITMP1);
750 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
752 store_reg_to_var_int(iptr->dst, d);
756 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
758 var_to_reg_int(s1, src->prev, REG_ITMP1);
759 var_to_reg_int(s2, src, REG_ITMP2);
760 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
762 store_reg_to_var_int(iptr->dst, d);
765 case ICMD_IADDCONST: /* ..., value ==> ..., value + constant */
766 /* val.i = constant */
768 var_to_reg_int(s1, src, REG_ITMP1);
769 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
770 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
771 M_IADD_IMM(s1, iptr->val.i, d);
773 ICONST(REG_ITMP2, iptr->val.i);
774 M_IADD(s1, REG_ITMP2, d);
776 store_reg_to_var_int(iptr->dst, d);
779 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
781 var_to_reg_int_low(s1, src->prev, REG_ITMP1);
782 var_to_reg_int_low(s2, src, REG_ITMP2);
783 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
784 M_ADDC(s1, s2, GET_LOW_REG(d));
785 var_to_reg_int_high(s1, src->prev, REG_ITMP1);
786 var_to_reg_int_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
787 M_ADDE(s1, s2, GET_HIGH_REG(d));
788 store_reg_to_var_int(iptr->dst, d);
791 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
792 /* val.l = constant */
794 s3 = iptr->val.l & 0xffffffff;
795 var_to_reg_int_low(s1, src, REG_ITMP1);
796 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
797 if ((s3 >= -32768) && (s3 <= 32767)) {
798 M_ADDIC(s1, s3, GET_LOW_REG(d));
800 ICONST(REG_ITMP2, s3);
801 M_ADDC(s1, REG_ITMP2, GET_LOW_REG(d));
803 var_to_reg_int_high(s1, src, REG_ITMP1);
804 s3 = iptr->val.l >> 32;
806 M_ADDME(s1, GET_HIGH_REG(d));
807 } else if (s3 == 0) {
808 M_ADDZE(s1, GET_HIGH_REG(d));
810 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
811 M_ADDE(s1, REG_ITMP3, GET_HIGH_REG(d));
813 store_reg_to_var_int(iptr->dst, d);
816 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
818 var_to_reg_int(s1, src->prev, REG_ITMP1);
819 var_to_reg_int(s2, src, REG_ITMP2);
820 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
822 store_reg_to_var_int(iptr->dst, d);
825 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
826 /* val.i = constant */
828 var_to_reg_int(s1, src, REG_ITMP1);
829 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
830 if ((iptr->val.i >= -32767) && (iptr->val.i <= 32768)) {
831 M_IADD_IMM(s1, -iptr->val.i, d);
833 ICONST(REG_ITMP2, -iptr->val.i);
834 M_IADD(s1, REG_ITMP2, d);
836 store_reg_to_var_int(iptr->dst, d);
839 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
841 var_to_reg_int_low(s1, src->prev, REG_ITMP1);
842 var_to_reg_int_low(s2, src, REG_ITMP2);
843 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
844 M_SUBC(s1, s2, GET_LOW_REG(d));
845 var_to_reg_int_high(s1, src->prev, REG_ITMP1);
846 var_to_reg_int_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
847 M_SUBE(s1, s2, GET_HIGH_REG(d));
848 store_reg_to_var_int(iptr->dst, d);
851 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
852 /* val.l = constant */
854 s3 = (-iptr->val.l) & 0xffffffff;
855 var_to_reg_int_low(s1, src, REG_ITMP1);
856 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
857 if ((s3 >= -32768) && (s3 <= 32767)) {
858 M_ADDIC(s1, s3, GET_LOW_REG(d));
860 ICONST(REG_ITMP2, s3);
861 M_ADDC(s1, REG_ITMP2, GET_LOW_REG(d));
863 var_to_reg_int_high(s1, src, REG_ITMP1);
864 s3 = (-iptr->val.l) >> 32;
866 M_ADDME(s1, GET_HIGH_REG(d));
868 M_ADDZE(s1, GET_HIGH_REG(d));
870 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
871 M_ADDE(s1, REG_ITMP3, GET_HIGH_REG(d));
873 store_reg_to_var_int(iptr->dst, d);
876 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
878 var_to_reg_int(s1, src->prev, REG_ITMP1);
879 var_to_reg_int(s2, src, REG_ITMP2);
880 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
883 codegen_addxdivrefs(cd, mcodeptr);
884 M_LDAH(REG_ITMP3, REG_ZERO, 0x8000);
885 M_CMP(REG_ITMP3, s1);
886 M_BNE(3 + (s1 != d));
888 M_BNE(1 + (s1 != d));
892 store_reg_to_var_int(iptr->dst, d);
895 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
897 var_to_reg_int(s1, src->prev, REG_ITMP1);
898 var_to_reg_int(s2, src, REG_ITMP2);
899 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
902 codegen_addxdivrefs(cd, mcodeptr);
903 M_LDAH(REG_ITMP3, REG_ZERO, 0x8000);
904 M_CMP(REG_ITMP3, s1);
910 M_IDIV(s1, s2, REG_ITMP3);
911 M_IMUL(REG_ITMP3, s2, REG_ITMP3);
912 M_ISUB(s1, REG_ITMP3, d);
913 store_reg_to_var_int(iptr->dst, d);
916 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
917 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
922 var_to_reg_int(s2, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
923 M_OR_TST(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
925 codegen_addxdivrefs(cd, mcodeptr);
927 s3 = PACK_REGS(rd->argintregs[GET_LOW_REG(md->params[1].regoff)],
928 rd->argintregs[GET_HIGH_REG(md->params[1].regoff)]);
929 M_TINTMOVE(TYPE_LNG, s2, s3);
931 var_to_reg_int(s1, src->prev, PACK_REGS(REG_ITMP2, REG_ITMP1));
932 s3 = PACK_REGS(rd->argintregs[GET_LOW_REG(md->params[0].regoff)],
933 rd->argintregs[GET_HIGH_REG(md->params[0].regoff)]);
934 M_TINTMOVE(TYPE_LNG, s1, s3);
936 disp = dseg_addaddress(cd, bte->fp);
937 M_ALD(REG_ITMP1, REG_PV, disp);
941 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_RESULT2, REG_RESULT));
942 M_TINTMOVE(TYPE_LNG, PACK_REGS(REG_RESULT2, REG_RESULT), d);
943 store_reg_to_var_int(iptr->dst, d);
946 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
948 var_to_reg_int(s1, src->prev, REG_ITMP1);
949 var_to_reg_int(s2, src, REG_ITMP2);
950 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
952 store_reg_to_var_int(iptr->dst, d);
955 case ICMD_IMULCONST: /* ..., value ==> ..., value * constant */
956 /* val.i = constant */
958 var_to_reg_int(s1, src, REG_ITMP1);
959 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
960 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
961 M_IMUL_IMM(s1, iptr->val.i, d);
963 ICONST(REG_ITMP3, iptr->val.i);
964 M_IMUL(s1, REG_ITMP3, d);
966 store_reg_to_var_int(iptr->dst, d);
969 case ICMD_IDIVPOW2: /* ..., value ==> ..., value << constant */
971 var_to_reg_int(s1, src, REG_ITMP1);
972 d = reg_of_var(rd, iptr->dst, REG_ITMP3);
973 M_SRA_IMM(s1, iptr->val.i, d);
975 store_reg_to_var_int(iptr->dst, d);
978 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
980 var_to_reg_int(s1, src->prev, REG_ITMP1);
981 var_to_reg_int(s2, src, REG_ITMP2);
982 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
983 M_AND_IMM(s2, 0x1f, REG_ITMP3);
984 M_SLL(s1, REG_ITMP3, d);
985 store_reg_to_var_int(iptr->dst, d);
988 case ICMD_ISHLCONST: /* ..., 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 M_SLL_IMM(s1, iptr->val.i & 0x1f, d);
994 store_reg_to_var_int(iptr->dst, d);
997 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
999 var_to_reg_int(s1, src->prev, REG_ITMP1);
1000 var_to_reg_int(s2, src, REG_ITMP2);
1001 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1002 M_AND_IMM(s2, 0x1f, REG_ITMP3);
1003 M_SRA(s1, REG_ITMP3, d);
1004 store_reg_to_var_int(iptr->dst, d);
1007 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
1008 /* val.i = constant */
1010 var_to_reg_int(s1, src, REG_ITMP1);
1011 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1012 M_SRA_IMM(s1, iptr->val.i & 0x1f, d);
1013 store_reg_to_var_int(iptr->dst, d);
1016 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
1018 var_to_reg_int(s1, src->prev, REG_ITMP1);
1019 var_to_reg_int(s2, src, REG_ITMP2);
1020 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1021 M_AND_IMM(s2, 0x1f, REG_ITMP2);
1022 M_SRL(s1, REG_ITMP2, d);
1023 store_reg_to_var_int(iptr->dst, d);
1026 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
1027 /* val.i = constant */
1029 var_to_reg_int(s1, src, REG_ITMP1);
1030 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1031 if (iptr->val.i & 0x1f) {
1032 M_SRL_IMM(s1, iptr->val.i & 0x1f, d);
1036 store_reg_to_var_int(iptr->dst, d);
1039 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
1041 var_to_reg_int(s1, src->prev, REG_ITMP1);
1042 var_to_reg_int(s2, src, REG_ITMP2);
1043 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1045 store_reg_to_var_int(iptr->dst, d);
1048 case ICMD_IANDCONST: /* ..., value ==> ..., value & constant */
1049 /* val.i = constant */
1051 var_to_reg_int(s1, src, REG_ITMP1);
1052 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1053 if ((iptr->val.i >= 0) && (iptr->val.i <= 65535)) {
1054 M_AND_IMM(s1, iptr->val.i, d);
1057 else if (iptr->val.i == 0xffffff) {
1058 M_RLWINM(s1, 0, 8, 31, d);
1062 ICONST(REG_ITMP3, iptr->val.i);
1063 M_AND(s1, REG_ITMP3, d);
1065 store_reg_to_var_int(iptr->dst, d);
1068 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
1070 var_to_reg_int_low(s1, src->prev, REG_ITMP1);
1071 var_to_reg_int_low(s2, src, REG_ITMP2);
1072 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1073 M_AND(s1, s2, GET_LOW_REG(d));
1074 var_to_reg_int_high(s1, src->prev, REG_ITMP1);
1075 var_to_reg_int_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
1076 M_AND(s1, s2, GET_HIGH_REG(d));
1077 store_reg_to_var_int(iptr->dst, d);
1080 case ICMD_LANDCONST: /* ..., value ==> ..., value & constant */
1081 /* val.l = constant */
1083 s3 = iptr->val.l & 0xffffffff;
1084 var_to_reg_int_low(s1, src, REG_ITMP1);
1085 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1086 if ((s3 >= 0) && (s3 <= 65535)) {
1087 M_AND_IMM(s1, s3, GET_LOW_REG(d));
1089 ICONST(REG_ITMP3, s3);
1090 M_AND(s1, REG_ITMP3, GET_LOW_REG(d));
1092 var_to_reg_int_high(s1, src, REG_ITMP1);
1093 s3 = iptr->val.l >> 32;
1094 if ((s3 >= 0) && (s3 <= 65535)) {
1095 M_AND_IMM(s1, s3, GET_HIGH_REG(d));
1097 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
1098 M_AND(s1, REG_ITMP3, GET_HIGH_REG(d));
1100 store_reg_to_var_int(iptr->dst, d);
1103 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
1104 /* val.i = constant */
1106 var_to_reg_int(s1, src, REG_ITMP1);
1107 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1108 M_MOV(s1, REG_ITMP2);
1110 M_BGE(1 + 2*(iptr->val.i >= 32768));
1111 if (iptr->val.i >= 32768) {
1112 M_ADDIS(REG_ZERO, iptr->val.i >> 16, REG_ITMP2);
1113 M_OR_IMM(REG_ITMP2, iptr->val.i, REG_ITMP2);
1114 M_IADD(s1, REG_ITMP2, REG_ITMP2);
1116 M_IADD_IMM(s1, iptr->val.i, REG_ITMP2);
1119 int b=0, m = iptr->val.i;
1122 M_RLWINM(REG_ITMP2, 0, 0, 30-b, REG_ITMP2);
1124 M_ISUB(s1, REG_ITMP2, d);
1125 store_reg_to_var_int(iptr->dst, d);
1128 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
1130 var_to_reg_int(s1, src->prev, REG_ITMP1);
1131 var_to_reg_int(s2, src, REG_ITMP2);
1132 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1134 store_reg_to_var_int(iptr->dst, d);
1137 case ICMD_IORCONST: /* ..., value ==> ..., value | constant */
1138 /* val.i = constant */
1140 var_to_reg_int(s1, src, REG_ITMP1);
1141 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1142 if ((iptr->val.i >= 0) && (iptr->val.i <= 65535)) {
1143 M_OR_IMM(s1, iptr->val.i, d);
1145 ICONST(REG_ITMP3, iptr->val.i);
1146 M_OR(s1, REG_ITMP3, d);
1148 store_reg_to_var_int(iptr->dst, d);
1151 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
1153 var_to_reg_int_low(s1, src->prev, REG_ITMP1);
1154 var_to_reg_int_low(s2, src, REG_ITMP2);
1155 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1156 M_OR(s1, s2, GET_LOW_REG(d));
1157 var_to_reg_int_high(s1, src->prev, REG_ITMP1);
1158 var_to_reg_int_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
1159 M_OR(s1, s2, GET_HIGH_REG(d));
1160 store_reg_to_var_int(iptr->dst, d);
1163 case ICMD_LORCONST: /* ..., value ==> ..., value | constant */
1164 /* val.l = constant */
1166 s3 = iptr->val.l & 0xffffffff;
1167 var_to_reg_int_low(s1, src, REG_ITMP1);
1168 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1169 if ((s3 >= 0) && (s3 <= 65535)) {
1170 M_OR_IMM(s1, s3, GET_LOW_REG(d));
1172 ICONST(REG_ITMP3, s3);
1173 M_OR(s1, REG_ITMP3, GET_LOW_REG(d));
1175 var_to_reg_int_high(s1, src, REG_ITMP1);
1176 s3 = iptr->val.l >> 32;
1177 if ((s3 >= 0) && (s3 <= 65535)) {
1178 M_OR_IMM(s1, s3, GET_HIGH_REG(d));
1180 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
1181 M_OR(s1, REG_ITMP3, GET_HIGH_REG(d));
1183 store_reg_to_var_int(iptr->dst, d);
1186 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
1188 var_to_reg_int(s1, src->prev, REG_ITMP1);
1189 var_to_reg_int(s2, src, REG_ITMP2);
1190 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1192 store_reg_to_var_int(iptr->dst, d);
1195 case ICMD_IXORCONST: /* ..., value ==> ..., value ^ constant */
1196 /* val.i = constant */
1198 var_to_reg_int(s1, src, REG_ITMP1);
1199 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1200 if ((iptr->val.i >= 0) && (iptr->val.i <= 65535)) {
1201 M_XOR_IMM(s1, iptr->val.i, d);
1203 ICONST(REG_ITMP3, iptr->val.i);
1204 M_XOR(s1, REG_ITMP3, d);
1206 store_reg_to_var_int(iptr->dst, d);
1209 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
1211 var_to_reg_int_low(s1, src->prev, REG_ITMP1);
1212 var_to_reg_int_low(s2, src, REG_ITMP2);
1213 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1214 M_XOR(s1, s2, GET_LOW_REG(d));
1215 var_to_reg_int_high(s1, src->prev, REG_ITMP1);
1216 var_to_reg_int_high(s2, src, REG_ITMP3); /* don't use REG_ITMP2 */
1217 M_XOR(s1, s2, GET_HIGH_REG(d));
1218 store_reg_to_var_int(iptr->dst, d);
1221 case ICMD_LXORCONST: /* ..., value ==> ..., value ^ constant */
1222 /* val.l = constant */
1224 s3 = iptr->val.l & 0xffffffff;
1225 var_to_reg_int_low(s1, src, REG_ITMP1);
1226 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1227 if ((s3 >= 0) && (s3 <= 65535)) {
1228 M_XOR_IMM(s1, s3, GET_LOW_REG(d));
1230 ICONST(REG_ITMP3, s3);
1231 M_XOR(s1, REG_ITMP3, GET_LOW_REG(d));
1233 var_to_reg_int_high(s1, src, REG_ITMP1);
1234 s3 = iptr->val.l >> 32;
1235 if ((s3 >= 0) && (s3 <= 65535)) {
1236 M_XOR_IMM(s1, s3, GET_HIGH_REG(d));
1238 ICONST(REG_ITMP3, s3); /* don't use REG_ITMP2 */
1239 M_XOR(s1, REG_ITMP3, GET_HIGH_REG(d));
1241 store_reg_to_var_int(iptr->dst, d);
1244 case ICMD_LCMP: /* ..., val1, val2 ==> ..., val1 cmp val2 */
1245 /*******************************************************************
1246 TODO: CHANGE THIS TO A VERSION THAT WORKS !!!
1247 *******************************************************************/
1248 var_to_reg_int_high(s1, src->prev, REG_ITMP3);
1249 var_to_reg_int_high(s2, src, REG_ITMP2);
1250 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
1252 int tempreg = false;
1256 if (src->prev->flags & INMEMORY) {
1257 tempreg = tempreg || (d == REG_ITMP3) || (d == REG_ITMP2);
1259 tempreg = tempreg || (d == GET_HIGH_REG(src->prev->regoff))
1260 || (d == GET_LOW_REG(src->prev->regoff));
1262 if (src->flags & INMEMORY) {
1263 tempreg = tempreg || (d == REG_ITMP3) || (d == REG_ITMP2);
1265 tempreg = tempreg || (d == GET_HIGH_REG(src->regoff))
1266 || (d == GET_LOW_REG(src->regoff));
1269 dreg = tempreg ? REG_ITMP1 : d;
1270 M_IADD_IMM(REG_ZERO, 1, dreg);
1275 var_to_reg_int_low(s1, src->prev, REG_ITMP3);
1276 var_to_reg_int_low(s2, src, REG_ITMP2);
1280 M_IADD_IMM(dreg, -1, dreg);
1281 M_IADD_IMM(dreg, -1, dreg);
1282 gen_resolvebranch(br1, (u1*) br1, (u1*) mcodeptr);
1283 gen_resolvebranch(br1+1, (u1*) (br1+1), (u1*) (mcodeptr-2));
1286 store_reg_to_var_int(iptr->dst, d);
1289 case ICMD_IINC: /* ..., value ==> ..., value + constant */
1290 /* op1 = variable, val.i = constant */
1292 var = &(rd->locals[iptr->op1][TYPE_INT]);
1293 if (var->flags & INMEMORY) {
1295 M_ILD(s1, REG_SP, var->regoff * 4);
1304 M_ADDIS(s1, m >> 16, s1);
1306 M_IADD_IMM(s1, m & 0xffff, s1);
1308 if (var->flags & INMEMORY) {
1309 M_IST(s1, REG_SP, var->regoff * 4);
1314 /* floating operations ************************************************/
1316 case ICMD_FNEG: /* ..., value ==> ..., - value */
1318 var_to_reg_flt(s1, src, REG_FTMP1);
1319 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1321 store_reg_to_var_flt(iptr->dst, d);
1324 case ICMD_DNEG: /* ..., value ==> ..., - value */
1326 var_to_reg_flt(s1, src, REG_FTMP1);
1327 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1329 store_reg_to_var_flt(iptr->dst, d);
1332 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1334 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1335 var_to_reg_flt(s2, src, REG_FTMP2);
1336 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1338 store_reg_to_var_flt(iptr->dst, d);
1341 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1343 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1344 var_to_reg_flt(s2, src, REG_FTMP2);
1345 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1347 store_reg_to_var_flt(iptr->dst, d);
1350 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1352 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1353 var_to_reg_flt(s2, src, REG_FTMP2);
1354 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1356 store_reg_to_var_flt(iptr->dst, d);
1359 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1361 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1362 var_to_reg_flt(s2, src, REG_FTMP2);
1363 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1365 store_reg_to_var_flt(iptr->dst, d);
1368 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1370 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1371 var_to_reg_flt(s2, src, REG_FTMP2);
1372 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1374 store_reg_to_var_flt(iptr->dst, d);
1377 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1379 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1380 var_to_reg_flt(s2, src, REG_FTMP2);
1381 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1383 store_reg_to_var_flt(iptr->dst, d);
1386 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1388 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1389 var_to_reg_flt(s2, src, REG_FTMP2);
1390 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1392 store_reg_to_var_flt(iptr->dst, d);
1395 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1397 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1398 var_to_reg_flt(s2, src, REG_FTMP2);
1399 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1401 store_reg_to_var_flt(iptr->dst, d);
1404 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1406 var_to_reg_flt(s1, src, REG_FTMP1);
1407 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1409 disp = dseg_addfloat(cd, 0.0);
1410 M_FLD(REG_FTMP2, REG_PV, disp);
1411 M_FCMPU(s1, REG_FTMP2);
1413 disp = dseg_adds4(cd, 0);
1414 M_CVTDL_C(s1, REG_FTMP1);
1415 M_LDA(REG_ITMP1, REG_PV, disp);
1416 M_STFIWX(REG_FTMP1, 0, REG_ITMP1);
1417 M_ILD(d, REG_PV, disp);
1418 store_reg_to_var_int(iptr->dst, d);
1421 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1423 var_to_reg_flt(s1, src, REG_FTMP1);
1424 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1426 store_reg_to_var_flt(iptr->dst, d);
1429 case ICMD_D2F: /* ..., value ==> ..., (double) value */
1431 var_to_reg_flt(s1, src, REG_FTMP1);
1432 d = reg_of_var(rd, iptr->dst, REG_FTMP3);
1434 store_reg_to_var_flt(iptr->dst, d);
1437 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1439 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1440 var_to_reg_flt(s2, src, REG_FTMP2);
1441 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
1443 M_IADD_IMM(REG_ZERO, -1, d);
1446 M_IADD_IMM(REG_ZERO, 0, d);
1448 M_IADD_IMM(REG_ZERO, 1, d);
1449 store_reg_to_var_int(iptr->dst, d);
1452 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1454 var_to_reg_flt(s1, src->prev, REG_FTMP1);
1455 var_to_reg_flt(s2, src, REG_FTMP2);
1456 d = reg_of_var(rd, iptr->dst, REG_ITMP1);
1458 M_IADD_IMM(REG_ZERO, 1, d);
1461 M_IADD_IMM(REG_ZERO, 0, d);
1463 M_IADD_IMM(REG_ZERO, -1, d);
1464 store_reg_to_var_int(iptr->dst, d);
1468 /* memory operations **************************************************/
1470 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1472 var_to_reg_int(s1, src, REG_ITMP1);
1473 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1474 gen_nullptr_check(s1);
1475 M_ILD(d, s1, OFFSET(java_arrayheader, size));
1476 store_reg_to_var_int(iptr->dst, d);
1479 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1481 var_to_reg_int(s1, src->prev, REG_ITMP1);
1482 var_to_reg_int(s2, src, REG_ITMP2);
1483 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1484 if (iptr->op1 == 0) {
1485 gen_nullptr_check(s1);
1488 M_IADD_IMM(s2, OFFSET(java_chararray, data[0]), REG_ITMP2);
1489 M_LBZX(d, s1, REG_ITMP2);
1491 store_reg_to_var_int(iptr->dst, d);
1494 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1496 var_to_reg_int(s1, src->prev, REG_ITMP1);
1497 var_to_reg_int(s2, src, REG_ITMP2);
1498 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1499 if (iptr->op1 == 0) {
1500 gen_nullptr_check(s1);
1503 M_SLL_IMM(s2, 1, REG_ITMP2);
1504 M_IADD_IMM(REG_ITMP2, OFFSET(java_chararray, data[0]), REG_ITMP2);
1505 M_LHZX(d, s1, REG_ITMP2);
1506 store_reg_to_var_int(iptr->dst, d);
1509 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1511 var_to_reg_int(s1, src->prev, REG_ITMP1);
1512 var_to_reg_int(s2, src, REG_ITMP2);
1513 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1514 if (iptr->op1 == 0) {
1515 gen_nullptr_check(s1);
1518 M_SLL_IMM(s2, 1, REG_ITMP2);
1519 M_IADD_IMM(REG_ITMP2, OFFSET(java_shortarray, data[0]), REG_ITMP2);
1520 M_LHAX(d, s1, REG_ITMP2);
1521 store_reg_to_var_int(iptr->dst, d);
1524 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1526 var_to_reg_int(s1, src->prev, REG_ITMP1);
1527 var_to_reg_int(s2, src, REG_ITMP2);
1528 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1529 if (iptr->op1 == 0) {
1530 gen_nullptr_check(s1);
1533 M_SLL_IMM(s2, 2, REG_ITMP2);
1534 M_IADD_IMM(REG_ITMP2, OFFSET(java_intarray, data[0]), REG_ITMP2);
1535 M_LWZX(d, s1, REG_ITMP2);
1536 store_reg_to_var_int(iptr->dst, d);
1539 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1541 var_to_reg_int(s1, src->prev, REG_ITMP1);
1542 var_to_reg_int(s2, src, REG_ITMP2);
1543 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1544 if (iptr->op1 == 0) {
1545 gen_nullptr_check(s1);
1548 M_SLL_IMM(s2, 3, REG_ITMP2);
1549 M_IADD(s1, REG_ITMP2, REG_ITMP2);
1550 M_ILD(GET_HIGH_REG(d), REG_ITMP2, OFFSET(java_longarray, data[0]));
1551 M_ILD(GET_LOW_REG(d), REG_ITMP2, OFFSET(java_longarray,
1553 store_reg_to_var_int(iptr->dst, d);
1556 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1558 var_to_reg_int(s1, src->prev, REG_ITMP1);
1559 var_to_reg_int(s2, src, REG_ITMP2);
1560 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1561 if (iptr->op1 == 0) {
1562 gen_nullptr_check(s1);
1565 M_SLL_IMM(s2, 2, REG_ITMP2);
1566 M_IADD_IMM(REG_ITMP2, OFFSET(java_floatarray, data[0]), REG_ITMP2);
1567 M_LFSX(d, s1, REG_ITMP2);
1568 store_reg_to_var_flt(iptr->dst, d);
1571 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1573 var_to_reg_int(s1, src->prev, REG_ITMP1);
1574 var_to_reg_int(s2, src, REG_ITMP2);
1575 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1576 if (iptr->op1 == 0) {
1577 gen_nullptr_check(s1);
1580 M_SLL_IMM(s2, 3, REG_ITMP2);
1581 M_IADD_IMM(REG_ITMP2, OFFSET(java_doublearray, data[0]), REG_ITMP2);
1582 M_LFDX(d, s1, REG_ITMP2);
1583 store_reg_to_var_flt(iptr->dst, d);
1586 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1588 var_to_reg_int(s1, src->prev, REG_ITMP1);
1589 var_to_reg_int(s2, src, REG_ITMP2);
1590 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1591 if (iptr->op1 == 0) {
1592 gen_nullptr_check(s1);
1595 M_SLL_IMM(s2, 2, REG_ITMP2);
1596 M_IADD_IMM(REG_ITMP2, OFFSET(java_objectarray, data[0]), REG_ITMP2);
1597 M_LWZX(d, s1, REG_ITMP2);
1598 store_reg_to_var_int(iptr->dst, d);
1602 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1604 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1605 var_to_reg_int(s2, src->prev, REG_ITMP2);
1606 if (iptr->op1 == 0) {
1607 gen_nullptr_check(s1);
1610 var_to_reg_int(s3, src, REG_ITMP3);
1611 M_IADD_IMM(s2, OFFSET(java_bytearray, data[0]), REG_ITMP2);
1612 M_STBX(s3, s1, REG_ITMP2);
1615 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1617 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1618 var_to_reg_int(s2, src->prev, REG_ITMP2);
1619 if (iptr->op1 == 0) {
1620 gen_nullptr_check(s1);
1623 var_to_reg_int(s3, src, REG_ITMP3);
1624 M_SLL_IMM(s2, 1, REG_ITMP2);
1625 M_IADD_IMM(REG_ITMP2, OFFSET(java_chararray, data[0]), REG_ITMP2);
1626 M_STHX(s3, s1, REG_ITMP2);
1629 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1631 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1632 var_to_reg_int(s2, src->prev, REG_ITMP2);
1633 if (iptr->op1 == 0) {
1634 gen_nullptr_check(s1);
1637 var_to_reg_int(s3, src, REG_ITMP3);
1638 M_SLL_IMM(s2, 1, REG_ITMP2);
1639 M_IADD_IMM(REG_ITMP2, OFFSET(java_shortarray, data[0]), REG_ITMP2);
1640 M_STHX(s3, s1, REG_ITMP2);
1643 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1645 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1646 var_to_reg_int(s2, src->prev, REG_ITMP2);
1647 if (iptr->op1 == 0) {
1648 gen_nullptr_check(s1);
1651 var_to_reg_int(s3, src, REG_ITMP3);
1652 M_SLL_IMM(s2, 2, REG_ITMP2);
1653 M_IADD_IMM(REG_ITMP2, OFFSET(java_intarray, data[0]), REG_ITMP2);
1654 M_STWX(s3, s1, REG_ITMP2);
1657 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1659 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1660 var_to_reg_int(s2, src->prev, REG_ITMP2);
1661 if (iptr->op1 == 0) {
1662 gen_nullptr_check(s1);
1665 var_to_reg_int_high(s3, src, REG_ITMP3);
1666 M_SLL_IMM(s2, 3, REG_ITMP2);
1667 M_IADD_IMM(REG_ITMP2, OFFSET(java_longarray, data[0]), REG_ITMP2);
1668 M_STWX(s3, s1, REG_ITMP2);
1669 M_IADD_IMM(REG_ITMP2, 4, REG_ITMP2);
1670 var_to_reg_int_low(s3, src, REG_ITMP3);
1671 M_STWX(s3, s1, REG_ITMP2);
1674 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1676 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1677 var_to_reg_int(s2, src->prev, REG_ITMP2);
1678 if (iptr->op1 == 0) {
1679 gen_nullptr_check(s1);
1682 var_to_reg_flt(s3, src, REG_FTMP3);
1683 M_SLL_IMM(s2, 2, REG_ITMP2);
1684 M_IADD_IMM(REG_ITMP2, OFFSET(java_floatarray, data[0]), REG_ITMP2);
1685 M_STFSX(s3, s1, REG_ITMP2);
1688 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1690 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1691 var_to_reg_int(s2, src->prev, REG_ITMP2);
1692 if (iptr->op1 == 0) {
1693 gen_nullptr_check(s1);
1696 var_to_reg_flt(s3, src, REG_FTMP3);
1697 M_SLL_IMM(s2, 3, REG_ITMP2);
1698 M_IADD_IMM(REG_ITMP2, OFFSET(java_doublearray, data[0]), REG_ITMP2);
1699 M_STFDX(s3, s1, REG_ITMP2);
1702 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1704 var_to_reg_int(s1, src->prev->prev, rd->argintregs[0]);
1705 var_to_reg_int(s2, src->prev, REG_ITMP2);
1706 /* if (iptr->op1 == 0) { */
1707 gen_nullptr_check(s1);
1710 var_to_reg_int(s3, src, rd->argintregs[1]);
1712 M_INTMOVE(s1, rd->argintregs[0]);
1713 M_INTMOVE(s3, rd->argintregs[1]);
1715 disp = dseg_addaddress(cd, bte->fp);
1716 M_ALD(REG_ITMP1, REG_PV, disp);
1721 codegen_addxstorerefs(cd, mcodeptr);
1723 var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
1724 var_to_reg_int(s2, src->prev, REG_ITMP2);
1725 var_to_reg_int(s3, src, REG_ITMP3);
1726 M_SLL_IMM(s2, 2, REG_ITMP2);
1727 M_IADD_IMM(REG_ITMP2, OFFSET(java_objectarray, data[0]), REG_ITMP2);
1728 M_STWX(s3, s1, REG_ITMP2);
1732 case ICMD_GETSTATIC: /* ... ==> ..., value */
1733 /* op1 = type, val.a = field address */
1736 disp = dseg_addaddress(cd, NULL);
1738 codegen_addpatchref(cd, mcodeptr,
1739 PATCHER_get_putstatic,
1740 (unresolved_field *) iptr->target, disp);
1742 if (opt_showdisassemble)
1746 fieldinfo *fi = iptr->val.a;
1748 disp = dseg_addaddress(cd, &(fi->value));
1750 if (!fi->class->initialized) {
1751 codegen_addpatchref(cd, mcodeptr,
1752 PATCHER_clinit, fi->class, disp);
1754 if (opt_showdisassemble)
1759 M_ALD(REG_ITMP1, REG_PV, disp);
1760 switch (iptr->op1) {
1762 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1763 M_ILD_INTERN(d, REG_ITMP1, 0);
1764 store_reg_to_var_int(iptr->dst, d);
1767 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1768 M_ILD_INTERN(GET_LOW_REG(d), REG_ITMP1, 4);/* keep this order */
1769 M_ILD_INTERN(GET_HIGH_REG(d), REG_ITMP1, 0);/*keep this order */
1770 store_reg_to_var_int(iptr->dst, d);
1773 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1774 M_ALD_INTERN(d, REG_ITMP1, 0);
1775 store_reg_to_var_int(iptr->dst, d);
1778 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1779 M_FLD_INTERN(d, REG_ITMP1, 0);
1780 store_reg_to_var_flt(iptr->dst, d);
1783 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1784 M_DLD_INTERN(d, REG_ITMP1, 0);
1785 store_reg_to_var_flt(iptr->dst, d);
1790 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1791 /* op1 = type, val.a = field address */
1795 disp = dseg_addaddress(cd, NULL);
1797 codegen_addpatchref(cd, mcodeptr,
1798 PATCHER_get_putstatic,
1799 (unresolved_field *) iptr->target, disp);
1801 if (opt_showdisassemble)
1805 fieldinfo *fi = iptr->val.a;
1807 disp = dseg_addaddress(cd, &(fi->value));
1809 if (!fi->class->initialized) {
1810 codegen_addpatchref(cd, mcodeptr,
1811 PATCHER_clinit, fi->class, disp);
1813 if (opt_showdisassemble)
1818 M_ALD(REG_ITMP1, REG_PV, disp);
1819 switch (iptr->op1) {
1821 var_to_reg_int(s2, src, REG_ITMP2);
1822 M_IST_INTERN(s2, REG_ITMP1, 0);
1825 var_to_reg_int(s2, src, PACK_REGS(REG_ITMP2, REG_ITMP3));
1826 M_IST_INTERN(GET_HIGH_REG(s2), REG_ITMP1, 0);
1827 M_IST_INTERN(GET_LOW_REG(s2), REG_ITMP1, 4);
1830 var_to_reg_int(s2, src, REG_ITMP2);
1831 M_AST_INTERN(s2, REG_ITMP1, 0);
1834 var_to_reg_flt(s2, src, REG_FTMP2);
1835 M_FST_INTERN(s2, REG_ITMP1, 0);
1838 var_to_reg_flt(s2, src, REG_FTMP2);
1839 M_DST_INTERN(s2, REG_ITMP1, 0);
1845 case ICMD_GETFIELD: /* ... ==> ..., value */
1846 /* op1 = type, val.i = field offset */
1848 var_to_reg_int(s1, src, REG_ITMP1);
1849 gen_nullptr_check(s1);
1852 codegen_addpatchref(cd, mcodeptr,
1853 PATCHER_get_putfield,
1854 (unresolved_field *) iptr->target, 0);
1856 if (opt_showdisassemble)
1862 disp = ((fieldinfo *) (iptr->val.a))->offset;
1865 switch (iptr->op1) {
1867 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1869 store_reg_to_var_int(iptr->dst, d);
1872 d = reg_of_var(rd, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
1873 M_ILD(GET_LOW_REG(d), s1, disp + 4); /* keep this order */
1874 M_ILD(GET_HIGH_REG(d), s1, disp); /* keep this order */
1875 store_reg_to_var_int(iptr->dst, d);
1878 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
1880 store_reg_to_var_int(iptr->dst, d);
1883 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1885 store_reg_to_var_flt(iptr->dst, d);
1888 d = reg_of_var(rd, iptr->dst, REG_FTMP1);
1890 store_reg_to_var_flt(iptr->dst, d);
1895 case ICMD_PUTFIELD: /* ..., value ==> ... */
1896 /* op1 = type, val.i = field offset */
1898 var_to_reg_int(s1, src->prev, REG_ITMP1);
1899 gen_nullptr_check(s1);
1901 if (!IS_FLT_DBL_TYPE(iptr->op1)) {
1902 if (IS_2_WORD_TYPE(iptr->op1)) {
1903 var_to_reg_int(s2, src, PACK_REGS(REG_ITMP2, REG_ITMP3));
1905 var_to_reg_int(s2, src, REG_ITMP2);
1908 var_to_reg_flt(s2, src, REG_FTMP2);
1912 codegen_addpatchref(cd, mcodeptr,
1913 PATCHER_get_putfield,
1914 (unresolved_field *) iptr->target, 0);
1916 if (opt_showdisassemble)
1922 disp = ((fieldinfo *) (iptr->val.a))->offset;
1925 switch (iptr->op1) {
1927 M_IST(s2, s1, disp);
1930 M_IST(GET_LOW_REG(s2), s1, disp + 4); /* keep this order */
1931 M_IST(GET_HIGH_REG(s2), s1, disp); /* keep this order */
1934 M_AST(s2, s1, disp);
1937 M_FST(s2, s1, disp);
1940 M_DST(s2, s1, disp);
1946 /* branch operations **************************************************/
1948 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1950 var_to_reg_int(s1, src, REG_ITMP1);
1951 M_INTMOVE(s1, REG_ITMP1_XPTR);
1954 codegen_addpatchref(cd, mcodeptr,
1955 PATCHER_athrow_areturn,
1956 (unresolved_class *) iptr->val.a, 0);
1958 if (opt_showdisassemble)
1962 disp = dseg_addaddress(cd, asm_handle_exception);
1963 M_ALD(REG_ITMP2, REG_PV, disp);
1966 if (m->isleafmethod) M_MFLR(REG_ITMP3); /* save LR */
1967 M_BL(0); /* get current PC */
1968 M_MFLR(REG_ITMP2_XPC);
1969 if (m->isleafmethod) M_MTLR(REG_ITMP3); /* restore LR */
1970 M_RTS; /* jump to CTR */
1975 case ICMD_GOTO: /* ... ==> ... */
1976 /* op1 = target JavaVM pc */
1978 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
1982 case ICMD_JSR: /* ... ==> ... */
1983 /* op1 = target JavaVM pc */
1985 if (m->isleafmethod) M_MFLR(REG_ITMP2);
1988 M_IADD_IMM(REG_ITMP1, m->isleafmethod ? 16 : 12, REG_ITMP1);
1989 if (m->isleafmethod) M_MTLR(REG_ITMP2);
1991 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
1994 case ICMD_RET: /* ... ==> ... */
1995 /* op1 = local variable */
1997 var = &(rd->locals[iptr->op1][TYPE_ADR]);
1998 if (var->flags & INMEMORY) {
1999 M_ALD(REG_ITMP1, REG_SP, var->regoff * 4);
2002 M_MTCTR(var->regoff);
2008 case ICMD_IFNULL: /* ..., value ==> ... */
2009 /* op1 = target JavaVM pc */
2011 var_to_reg_int(s1, src, REG_ITMP1);
2014 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2017 case ICMD_IFNONNULL: /* ..., value ==> ... */
2018 /* op1 = target JavaVM pc */
2020 var_to_reg_int(s1, src, REG_ITMP1);
2023 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2031 case ICMD_IFEQ: /* ..., value ==> ... */
2032 /* op1 = target JavaVM pc, val.i = constant */
2034 var_to_reg_int(s1, src, REG_ITMP1);
2035 if ((iptr->val.i >= -32768) && (iptr->val.i <= 32767)) {
2036 M_CMPI(s1, iptr->val.i);
2038 ICONST(REG_ITMP2, iptr->val.i);
2039 M_CMP(s1, REG_ITMP2);
2041 switch (iptr->opc) {
2061 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2065 case ICMD_IF_LEQ: /* ..., value ==> ... */
2066 /* op1 = target JavaVM pc, val.l = constant */
2068 var_to_reg_int_low(s1, src, REG_ITMP1);
2069 var_to_reg_int_high(s2, src, REG_ITMP2);
2070 if (iptr->val.l == 0) {
2071 M_OR(s1, s2, REG_ITMP3);
2072 M_CMPI(REG_ITMP3, 0);
2073 } else if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
2074 M_CMPI(s2, (u4) (iptr->val.l >> 32));
2076 M_CMPI(s1, (u4) (iptr->val.l & 0xffffffff));
2078 ICONST(REG_ITMP3, (u4) (iptr->val.l >> 32));
2079 M_CMP(s2, REG_ITMP3);
2081 ICONST(REG_ITMP3, (u4) (iptr->val.l & 0xffffffff));
2082 M_CMP(s1, REG_ITMP3)
2085 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2088 case ICMD_IF_LLT: /* ..., value ==> ... */
2089 /* op1 = target JavaVM pc, val.l = constant */
2090 var_to_reg_int_low(s1, src, REG_ITMP1);
2091 var_to_reg_int_high(s2, src, REG_ITMP2);
2092 /* if (iptr->val.l == 0) { */
2093 /* M_OR(s1, s2, REG_ITMP3); */
2094 /* M_CMPI(REG_ITMP3, 0); */
2097 if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
2098 M_CMPI(s2, (u4) (iptr->val.l >> 32));
2100 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2102 M_CMPI(s1, (u4) (iptr->val.l & 0xffffffff));
2104 ICONST(REG_ITMP3, (u4) (iptr->val.l >> 32));
2105 M_CMP(s2, REG_ITMP3);
2107 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2109 ICONST(REG_ITMP3, (u4) (iptr->val.l & 0xffffffff));
2110 M_CMP(s1, REG_ITMP3)
2113 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2116 case ICMD_IF_LLE: /* ..., value ==> ... */
2117 /* op1 = target JavaVM pc, val.l = constant */
2119 var_to_reg_int_low(s1, src, REG_ITMP1);
2120 var_to_reg_int_high(s2, src, REG_ITMP2);
2121 /* if (iptr->val.l == 0) { */
2122 /* M_OR(s1, s2, REG_ITMP3); */
2123 /* M_CMPI(REG_ITMP3, 0); */
2126 if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
2127 M_CMPI(s2, (u4) (iptr->val.l >> 32));
2129 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2131 M_CMPI(s1, (u4) (iptr->val.l & 0xffffffff));
2133 ICONST(REG_ITMP3, (u4) (iptr->val.l >> 32));
2134 M_CMP(s2, REG_ITMP3);
2136 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2138 ICONST(REG_ITMP3, (u4) (iptr->val.l & 0xffffffff));
2139 M_CMP(s1, REG_ITMP3)
2142 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2145 case ICMD_IF_LNE: /* ..., value ==> ... */
2146 /* op1 = target JavaVM pc, val.l = constant */
2148 var_to_reg_int_low(s1, src, REG_ITMP1);
2149 var_to_reg_int_high(s2, src, REG_ITMP2);
2150 if (iptr->val.l == 0) {
2151 M_OR(s1, s2, REG_ITMP3);
2152 M_CMPI(REG_ITMP3, 0);
2153 } else if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
2154 M_CMPI(s2, (u4) (iptr->val.l >> 32));
2156 M_CMPI(s1, (u4) (iptr->val.l & 0xffffffff));
2158 ICONST(REG_ITMP3, (u4) (iptr->val.l >> 32));
2159 M_CMP(s2, REG_ITMP3);
2161 ICONST(REG_ITMP3, (u4) (iptr->val.l & 0xffffffff));
2162 M_CMP(s1, REG_ITMP3)
2165 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2168 case ICMD_IF_LGT: /* ..., value ==> ... */
2169 /* op1 = target JavaVM pc, val.l = constant */
2171 var_to_reg_int_low(s1, src, REG_ITMP1);
2172 var_to_reg_int_high(s2, src, REG_ITMP2);
2173 /* if (iptr->val.l == 0) { */
2174 /* M_OR(s1, s2, REG_ITMP3); */
2175 /* M_CMPI(REG_ITMP3, 0); */
2178 if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
2179 M_CMPI(s2, (u4) (iptr->val.l >> 32));
2181 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2183 M_CMPI(s1, (u4) (iptr->val.l & 0xffffffff));
2185 ICONST(REG_ITMP3, (u4) (iptr->val.l >> 32));
2186 M_CMP(s2, REG_ITMP3);
2188 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2190 ICONST(REG_ITMP3, (u4) (iptr->val.l & 0xffffffff));
2191 M_CMP(s1, REG_ITMP3)
2194 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2197 case ICMD_IF_LGE: /* ..., value ==> ... */
2198 /* op1 = target JavaVM pc, val.l = constant */
2199 var_to_reg_int_low(s1, src, REG_ITMP1);
2200 var_to_reg_int_high(s2, src, REG_ITMP2);
2201 /* if (iptr->val.l == 0) { */
2202 /* M_OR(s1, s2, REG_ITMP3); */
2203 /* M_CMPI(REG_ITMP3, 0); */
2206 if ((iptr->val.l >= -32768) && (iptr->val.l <= 32767)) {
2207 M_CMPI(s2, (u4) (iptr->val.l >> 32));
2209 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2211 M_CMPI(s1, (u4) (iptr->val.l & 0xffffffff));
2213 ICONST(REG_ITMP3, (u4) (iptr->val.l >> 32));
2214 M_CMP(s2, REG_ITMP3);
2216 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2218 ICONST(REG_ITMP3, (u4) (iptr->val.l & 0xffffffff));
2219 M_CMP(s1, REG_ITMP3)
2222 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2226 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
2227 case ICMD_IF_LCMPEQ: /* op1 = target JavaVM pc */
2228 /******************************************************************
2229 TODO: CMP UPPER 32 BIT OF LONGS, TOO!
2230 *******************************************************************/
2231 case ICMD_IF_ACMPEQ:
2233 var_to_reg_int(s1, src->prev, REG_ITMP1);
2234 var_to_reg_int(s2, src, REG_ITMP2);
2237 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2240 case ICMD_IF_ICMPNE: /* ..., value, value ==> ... */
2241 case ICMD_IF_LCMPNE: /* op1 = target JavaVM pc */
2242 /******************************************************************
2243 TODO: CMP UPPER 32 BIT OF LONGS, TOO!
2244 *******************************************************************/
2245 case ICMD_IF_ACMPNE:
2247 var_to_reg_int(s1, src->prev, REG_ITMP1);
2248 var_to_reg_int(s2, src, REG_ITMP2);
2251 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2254 case ICMD_IF_ICMPLT: /* ..., value, value ==> ... */
2255 case ICMD_IF_LCMPLT: /* op1 = target JavaVM pc */
2256 /******************************************************************
2257 TODO: CMP UPPER 32 BIT OF LONGS, TOO!
2258 *******************************************************************/
2260 var_to_reg_int(s1, src->prev, REG_ITMP1);
2261 var_to_reg_int(s2, src, REG_ITMP2);
2264 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2267 case ICMD_IF_ICMPGT: /* ..., value, value ==> ... */
2268 case ICMD_IF_LCMPGT: /* op1 = target JavaVM pc */
2269 /******************************************************************
2270 TODO: CMP UPPER 32 BIT OF LONGS, TOO!
2271 *******************************************************************/
2273 var_to_reg_int(s1, src->prev, REG_ITMP1);
2274 var_to_reg_int(s2, src, REG_ITMP2);
2277 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2280 case ICMD_IF_ICMPLE: /* ..., value, value ==> ... */
2281 case ICMD_IF_LCMPLE: /* op1 = target JavaVM pc */
2282 /******************************************************************
2283 TODO: CMP UPPER 32 BIT OF LONGS, TOO!
2284 *******************************************************************/
2286 var_to_reg_int(s1, src->prev, REG_ITMP1);
2287 var_to_reg_int(s2, src, REG_ITMP2);
2290 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2293 case ICMD_IF_ICMPGE: /* ..., value, value ==> ... */
2294 case ICMD_IF_LCMPGE: /* op1 = target JavaVM pc */
2295 /******************************************************************
2296 TODO: CMP UPPER 32 BIT OF LONGS, TOO!
2297 *******************************************************************/
2299 var_to_reg_int(s1, src->prev, REG_ITMP1);
2300 var_to_reg_int(s2, src, REG_ITMP2);
2303 codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
2306 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2308 var_to_reg_int(s1, src, REG_RESULT);
2309 M_TINTMOVE(src->type, s1, REG_RESULT);
2310 goto nowperformreturn;
2312 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2314 var_to_reg_int(s1, src, REG_RESULT);
2315 M_TINTMOVE(src->type, s1, REG_RESULT);
2318 codegen_addpatchref(cd, mcodeptr,
2319 PATCHER_athrow_areturn,
2320 (unresolved_class *) iptr->val.a, 0);
2322 if (opt_showdisassemble)
2325 goto nowperformreturn;
2327 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2329 var_to_reg_int(s1, src, PACK_REGS(REG_RESULT2, REG_RESULT));
2330 M_TINTMOVE(src->type, s1, PACK_REGS(REG_RESULT2, REG_RESULT));
2331 goto nowperformreturn;
2333 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2336 var_to_reg_flt(s1, src, REG_FRESULT);
2337 M_FLTMOVE(s1, REG_FRESULT);
2338 goto nowperformreturn;
2340 case ICMD_RETURN: /* ... ==> ... */
2346 p = parentargs_base;
2348 /* call trace function */
2352 M_LDA(REG_SP, REG_SP, -10 * 8);
2353 M_DST(REG_FRESULT, REG_SP, 48+0);
2354 M_IST(REG_RESULT, REG_SP, 48+8);
2355 M_AST(REG_ZERO, REG_SP, 48+12);
2356 M_IST(REG_RESULT2, REG_SP, 48+16);
2358 /* keep this order */
2359 switch (iptr->opc) {
2362 #if defined(__DARWIN__)
2363 M_MOV(REG_RESULT, rd->argintregs[2]);
2364 M_CLR(rd->argintregs[1]);
2366 M_MOV(REG_RESULT, rd->argintregs[3]);
2367 M_CLR(rd->argintregs[2]);
2372 #if defined(__DARWIN__)
2373 M_MOV(REG_RESULT2, rd->argintregs[2]);
2374 M_MOV(REG_RESULT, rd->argintregs[1]);
2376 M_MOV(REG_RESULT2, rd->argintregs[3]);
2377 M_MOV(REG_RESULT, rd->argintregs[2]);
2382 disp = dseg_addaddress(cd, m);
2383 M_ALD(rd->argintregs[0], REG_PV, disp);
2385 M_FLTMOVE(REG_FRESULT, rd->argfltregs[0]);
2386 M_FLTMOVE(REG_FRESULT, rd->argfltregs[1]);
2387 disp = dseg_addaddress(cd, builtin_displaymethodstop);
2388 M_ALD(REG_ITMP2, REG_PV, disp);
2392 M_DLD(REG_FRESULT, REG_SP, 48+0);
2393 M_ILD(REG_RESULT, REG_SP, 48+8);
2394 M_ALD(REG_ZERO, REG_SP, 48+12);
2395 M_ILD(REG_RESULT2, REG_SP, 48+16);
2396 M_LDA(REG_SP, REG_SP, 10 * 8);
2400 #if defined(USE_THREADS)
2401 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2402 /* we need to save the proper return value */
2403 switch (iptr->opc) {
2405 M_IST(REG_RESULT2, REG_SP, rd->memuse * 4 + 8);
2409 M_IST(REG_RESULT , REG_SP, rd->memuse * 4 + 4);
2412 M_FST(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2415 M_DST(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2419 disp = dseg_addaddress(cd, BUILTIN_monitorexit);
2420 M_ALD(REG_ITMP3, REG_PV, disp);
2422 M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 4);
2425 /* and now restore the proper return value */
2426 switch (iptr->opc) {
2428 M_ILD(REG_RESULT2, REG_SP, rd->memuse * 4 + 8);
2432 M_ILD(REG_RESULT , REG_SP, rd->memuse * 4 + 4);
2435 M_FLD(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2438 M_DLD(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
2444 /* restore return address */
2446 if (!m->isleafmethod) {
2447 M_ALD(REG_ZERO, REG_SP, p * 4 + LA_LR_OFFSET);
2451 /* restore saved registers */
2453 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
2454 p--; M_ILD(rd->savintregs[i], REG_SP, p * 4);
2456 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
2457 p -= 2; M_DLD(rd->savfltregs[i], REG_SP, p * 4);
2460 /* deallocate stack */
2462 if (parentargs_base)
2463 M_LDA(REG_SP, REG_SP, parentargs_base * 4);
2471 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2476 tptr = (void **) iptr->target;
2478 s4ptr = iptr->val.a;
2479 l = s4ptr[1]; /* low */
2480 i = s4ptr[2]; /* high */
2482 var_to_reg_int(s1, src, REG_ITMP1);
2484 M_INTMOVE(s1, REG_ITMP1);
2485 } else if (l <= 32768) {
2486 M_LDA(REG_ITMP1, s1, -l);
2488 ICONST(REG_ITMP2, l);
2489 M_ISUB(s1, REG_ITMP2, REG_ITMP1);
2495 M_CMPUI(REG_ITMP1, i - 1);
2497 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2499 /* build jump table top down and use address of lowest entry */
2501 /* s4ptr += 3 + i; */
2505 dseg_addtarget(cd, (basicblock *) tptr[0]);
2510 /* length of dataseg after last dseg_addtarget is used by load */
2512 M_SLL_IMM(REG_ITMP1, 2, REG_ITMP1);
2513 M_IADD(REG_ITMP1, REG_PV, REG_ITMP2);
2514 M_ALD(REG_ITMP2, REG_ITMP2, -(cd->dseglen));
2521 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2523 s4 i, l, val, *s4ptr;
2526 tptr = (void **) iptr->target;
2528 s4ptr = iptr->val.a;
2529 l = s4ptr[0]; /* default */
2530 i = s4ptr[1]; /* count */
2532 MCODECHECK((i<<2)+8);
2533 var_to_reg_int(s1, src, REG_ITMP1);
2539 if ((val >= -32768) && (val <= 32767)) {
2542 a = dseg_adds4(cd, val);
2543 M_ILD(REG_ITMP2, REG_PV, a);
2544 M_CMP(s1, REG_ITMP2);
2547 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2551 tptr = (void **) iptr->target;
2552 codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
2559 case ICMD_BUILTIN: /* ..., [arg1, [arg2 ...]] ==> ... */
2560 /* op1 = arg count val.a = builtintable entry */
2566 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2567 /* op1 = arg count, val.a = method pointer */
2569 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2570 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2571 case ICMD_INVOKEINTERFACE:
2576 md = lm->parseddesc;
2578 unresolved_method *um = iptr->target;
2579 md = um->methodref->parseddesc.md;
2583 s3 = md->paramcount;
2585 MCODECHECK((s3 << 1) + 64);
2587 /* copy arguments to registers or stack location */
2589 for (s3 = s3 - 1; s3 >= 0; s3--, src = src->prev) {
2590 if (src->varkind == ARGVAR)
2592 if (IS_INT_LNG_TYPE(src->type)) {
2593 if (!md->params[s3].inmemory) {
2594 if (IS_2_WORD_TYPE(src->type)) {
2596 rd->argintregs[GET_LOW_REG(md->params[s3].regoff)],
2597 rd->argintregs[GET_HIGH_REG(md->params[s3].regoff)]);
2599 s1 = rd->argintregs[md->params[s3].regoff];
2601 var_to_reg_int(d, src, s1);
2602 M_TINTMOVE(src->type, d, s1);
2604 var_to_reg_int(d, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
2605 M_IST(GET_HIGH_REG(d), REG_SP,
2606 md->params[s3].regoff * 4);
2607 if (IS_2_WORD_TYPE(src->type)) {
2608 M_IST(GET_LOW_REG(d),
2609 REG_SP, md->params[s3].regoff * 4 + 4);
2614 if (!md->params[s3].inmemory) {
2615 s1 = rd->argfltregs[md->params[s3].regoff];
2616 var_to_reg_flt(d, src, s1);
2619 var_to_reg_flt(d, src, REG_FTMP1);
2620 if (IS_2_WORD_TYPE(src->type)) {
2621 M_DST(d, REG_SP, md->params[s3].regoff * 4);
2623 M_FST(d, REG_SP, md->params[s3].regoff * 4);
2629 switch (iptr->opc) {
2632 disp = dseg_addaddress(cd, NULL);
2634 codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target,
2637 if (opt_showdisassemble)
2641 disp = dseg_addaddress(cd, bte->fp);
2644 d = md->returntype.type;
2646 M_ALD(REG_PV, REG_PV, disp); /* pointer to built-in-function */
2649 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2651 M_LDA(REG_PV, REG_ITMP1, -disp);
2653 /* if op1 == true, we need to check for an exception */
2655 if (iptr->op1 == true) {
2656 M_CMPI(REG_RESULT, 0);
2658 codegen_addxexceptionrefs(cd, mcodeptr);
2662 case ICMD_INVOKESPECIAL:
2663 gen_nullptr_check(rd->argintregs[0]);
2664 M_ILD(REG_ITMP1, rd->argintregs[0], 0); /* hardware nullptr */
2667 case ICMD_INVOKESTATIC:
2669 unresolved_method *um = iptr->target;
2671 disp = dseg_addaddress(cd, NULL);
2673 codegen_addpatchref(cd, mcodeptr,
2674 PATCHER_invokestatic_special, um, disp);
2676 if (opt_showdisassemble)
2679 d = md->returntype.type;
2682 disp = dseg_addaddress(cd, lm->stubroutine);
2683 d = md->returntype.type;
2686 M_ALD(REG_PV, REG_PV, disp);
2689 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2691 M_LDA(REG_PV, REG_ITMP1, -disp);
2694 case ICMD_INVOKEVIRTUAL:
2695 gen_nullptr_check(rd->argintregs[0]);
2698 unresolved_method *um = iptr->target;
2700 codegen_addpatchref(cd, mcodeptr,
2701 PATCHER_invokevirtual, um, 0);
2703 if (opt_showdisassemble)
2707 d = md->returntype.type;
2710 s1 = OFFSET(vftbl_t, table[0]) +
2711 sizeof(methodptr) * lm->vftblindex;
2712 d = md->returntype.type;
2715 M_ALD(REG_METHODPTR, rd->argintregs[0],
2716 OFFSET(java_objectheader, vftbl));
2717 M_ALD(REG_PV, REG_METHODPTR, s1);
2720 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2722 M_LDA(REG_PV, REG_ITMP1, -disp);
2725 case ICMD_INVOKEINTERFACE:
2726 gen_nullptr_check(rd->argintregs[0]);
2729 unresolved_method *um = iptr->target;
2731 codegen_addpatchref(cd, mcodeptr,
2732 PATCHER_invokeinterface, um, 0);
2734 if (opt_showdisassemble)
2739 d = md->returntype.type;
2742 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2743 sizeof(methodptr*) * lm->class->index;
2745 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2747 d = md->returntype.type;
2750 M_ALD(REG_METHODPTR, rd->argintregs[0],
2751 OFFSET(java_objectheader, vftbl));
2752 M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
2753 M_ALD(REG_PV, REG_METHODPTR, s2);
2756 disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
2758 M_LDA(REG_PV, REG_ITMP1, -disp);
2762 /* d contains return type */
2764 if (d != TYPE_VOID) {
2765 if (IS_INT_LNG_TYPE(iptr->dst->type)) {
2766 if (IS_2_WORD_TYPE(iptr->dst->type)) {
2767 s1 = reg_of_var(rd, iptr->dst,
2768 PACK_REGS(REG_RESULT2, REG_RESULT));
2769 M_TINTMOVE(iptr->dst->type,
2770 PACK_REGS(REG_RESULT2, REG_RESULT), s1);
2772 s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
2773 M_TINTMOVE(iptr->dst->type, REG_RESULT, s1);
2775 store_reg_to_var_int(iptr->dst, s1);
2778 s1 = reg_of_var(rd, iptr->dst, REG_FRESULT);
2779 M_FLTMOVE(REG_FRESULT, s1);
2780 store_reg_to_var_flt(iptr->dst, s1);
2786 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2787 /* val.a: (classinfo*) superclass */
2789 /* superclass is an interface:
2791 * OK if ((sub == NULL) ||
2792 * (sub->vftbl->interfacetablelength > super->index) &&
2793 * (sub->vftbl->interfacetable[-super->index] != NULL));
2795 * superclass is a class:
2797 * OK if ((sub == NULL) || (0
2798 * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
2799 * super->vftbl->diffvall));
2804 vftbl_t *supervftbl;
2807 super = (classinfo *) iptr->val.a;
2814 superindex = super->index;
2815 supervftbl = super->vftbl;
2818 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
2819 codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
2821 var_to_reg_int(s1, src, REG_ITMP1);
2823 /* calculate interface checkcast code size */
2827 s2 += (opt_showdisassemble ? 1 : 0);
2829 /* calculate class checkcast code size */
2831 s3 = 8 + (s1 == REG_ITMP1);
2833 s3 += (opt_showdisassemble ? 1 : 0);
2835 /* if class is not resolved, check which code to call */
2839 M_BEQ(3 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
2841 disp = dseg_adds4(cd, 0); /* super->flags */
2843 codegen_addpatchref(cd, mcodeptr,
2844 PATCHER_checkcast_instanceof_flags,
2845 (constant_classref *) iptr->target, disp);
2847 if (opt_showdisassemble)
2850 M_ILD(REG_ITMP2, REG_PV, disp);
2851 M_AND_IMM(REG_ITMP2, ACC_INTERFACE, REG_ITMP2);
2855 /* interface checkcast code */
2857 if (!super || (super->flags & ACC_INTERFACE)) {
2863 codegen_addpatchref(cd, mcodeptr,
2864 PATCHER_checkcast_instanceof_interface,
2865 (constant_classref *) iptr->target, 0);
2867 if (opt_showdisassemble)
2871 M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2872 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2873 M_LDATST(REG_ITMP3, REG_ITMP3, -superindex);
2875 codegen_addxcastrefs(cd, mcodeptr);
2876 M_ALD(REG_ITMP3, REG_ITMP2,
2877 OFFSET(vftbl_t, interfacetable[0]) -
2878 superindex * sizeof(methodptr*));
2881 codegen_addxcastrefs(cd, mcodeptr);
2887 /* class checkcast code */
2889 if (!super || !(super->flags & ACC_INTERFACE)) {
2890 disp = dseg_addaddress(cd, supervftbl);
2897 codegen_addpatchref(cd, mcodeptr,
2898 PATCHER_checkcast_class,
2899 (constant_classref *) iptr->target,
2902 if (opt_showdisassemble)
2906 M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2907 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
2908 codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
2910 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2911 M_ALD(REG_ITMP2, REG_PV, disp);
2912 if (s1 != REG_ITMP1) {
2913 M_ILD(REG_ITMP1, REG_ITMP2, OFFSET(vftbl_t, baseval));
2914 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2915 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
2916 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
2918 M_ISUB(REG_ITMP3, REG_ITMP1, REG_ITMP3);
2920 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2921 M_ISUB(REG_ITMP3, REG_ITMP2, REG_ITMP3);
2922 M_ALD(REG_ITMP2, REG_PV, disp);
2923 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2924 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
2925 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
2928 M_CMPU(REG_ITMP3, REG_ITMP2);
2930 codegen_addxcastrefs(cd, mcodeptr);
2932 d = reg_of_var(rd, iptr->dst, s1);
2934 store_reg_to_var_int(iptr->dst, d);
2938 case ICMD_ARRAYCHECKCAST: /* ..., objectref ==> ..., objectref */
2939 /* op1: 1... resolved, 0... not resolved */
2941 var_to_reg_int(s1, src, rd->argintregs[0]);
2942 M_INTMOVE(s1, rd->argintregs[0]);
2946 disp = dseg_addaddress(cd, iptr->target);
2949 codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target, disp);
2951 if (opt_showdisassemble)
2957 a = (ptrint) bte->fp;
2960 M_ALD(rd->argintregs[1], REG_PV, disp);
2961 disp = dseg_addaddress(cd, a);
2962 M_ALD(REG_ITMP2, REG_PV, disp);
2967 codegen_addxcastrefs(cd, mcodeptr);
2969 var_to_reg_int(s1, src, REG_ITMP1);
2970 d = reg_of_var(rd, iptr->dst, s1);
2972 store_reg_to_var_int(iptr->dst, d);
2976 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2977 /* val.a: (classinfo*) superclass */
2979 /* superclass is an interface:
2981 * return (sub != NULL) &&
2982 * (sub->vftbl->interfacetablelength > super->index) &&
2983 * (sub->vftbl->interfacetable[-super->index] != NULL);
2985 * superclass is a class:
2987 * return ((sub != NULL) && (0
2988 * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
2989 * super->vftbl->diffvall));
2994 vftbl_t *supervftbl;
2997 super = (classinfo *) iptr->val.a;
3004 superindex = super->index;
3005 supervftbl = super->vftbl;
3008 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3009 codegen_threadcritrestart(cd, (u1*) mcodeptr - cd->mcodebase);
3011 var_to_reg_int(s1, src, REG_ITMP1);
3012 d = reg_of_var(rd, iptr->dst, REG_ITMP2);
3014 M_MOV(s1, REG_ITMP1);
3018 /* calculate interface instanceof code size */
3022 s2 += (opt_showdisassemble ? 1 : 0);
3024 /* calculate class instanceof code size */
3028 s3 += (opt_showdisassemble ? 1 : 0);
3032 /* if class is not resolved, check which code to call */
3036 M_BEQ(3 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
3038 disp = dseg_adds4(cd, 0); /* super->flags */
3040 codegen_addpatchref(cd, mcodeptr,
3041 PATCHER_checkcast_instanceof_flags,
3042 (constant_classref *) iptr->target, disp);
3044 if (opt_showdisassemble)
3047 M_ILD(REG_ITMP3, REG_PV, disp);
3048 M_AND_IMM(REG_ITMP3, ACC_INTERFACE, REG_ITMP3);
3052 /* interface instanceof code */
3054 if (!super || (super->flags & ACC_INTERFACE)) {
3060 codegen_addpatchref(cd, mcodeptr,
3061 PATCHER_checkcast_instanceof_interface,
3062 (constant_classref *) iptr->target, 0);
3064 if (opt_showdisassemble)
3068 M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3069 M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
3070 M_LDATST(REG_ITMP3, REG_ITMP3, -superindex);
3072 M_ALD(REG_ITMP1, REG_ITMP1,
3073 OFFSET(vftbl_t, interfacetable[0]) -
3074 superindex * sizeof(methodptr*));
3077 M_IADD_IMM(REG_ZERO, 1, d);
3083 /* class instanceof code */
3085 if (!super || !(super->flags & ACC_INTERFACE)) {
3086 disp = dseg_addaddress(cd, supervftbl);
3093 codegen_addpatchref(cd, mcodeptr,
3094 PATCHER_instanceof_class,
3095 (constant_classref *) iptr->target,
3098 if (opt_showdisassemble) {
3103 M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
3104 M_ALD(REG_ITMP2, REG_PV, disp);
3105 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3106 codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
3108 M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
3109 M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
3110 M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
3111 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3112 codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
3114 M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
3115 M_CMPU(REG_ITMP1, REG_ITMP2);
3118 M_IADD_IMM(REG_ZERO, 1, d);
3120 store_reg_to_var_int(iptr->dst, d);
3124 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
3125 /* op1 = dimension, val.a = array descriptor */
3127 /* check for negative sizes and copy sizes to stack if necessary */
3129 MCODECHECK((iptr->op1 << 1) + 64);
3131 for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
3132 /* copy SAVEDVAR sizes to stack */
3134 if (src->varkind != ARGVAR) {
3135 var_to_reg_int(s2, src, REG_ITMP1);
3136 #if defined(__DARWIN__)
3137 M_IST(s2, REG_SP, LA_SIZE + (s1 + INT_ARG_CNT) * 4);
3139 M_IST(s2, REG_SP, LA_SIZE + (s1 + 3) * 4);
3144 /* a0 = dimension count */
3146 ICONST(rd->argintregs[0], iptr->op1);
3148 /* is patcher function set? */
3151 disp = dseg_addaddress(cd, NULL);
3153 codegen_addpatchref(cd, mcodeptr,
3154 (functionptr) (ptrint) iptr->target,
3157 if (opt_showdisassemble)
3161 disp = dseg_addaddress(cd, iptr->val.a);
3164 /* a1 = arraydescriptor */
3166 M_ALD(rd->argintregs[1], REG_PV, disp);
3168 /* a2 = pointer to dimensions = stack pointer */
3170 #if defined(__DARWIN__)
3171 M_LDA(rd->argintregs[2], REG_SP, LA_SIZE + INT_ARG_CNT * 4);
3173 M_LDA(rd->argintregs[2], REG_SP, LA_SIZE + 3 * 4);
3176 disp = dseg_addaddress(cd, BUILTIN_multianewarray);
3177 M_ALD(REG_ITMP3, REG_PV, disp);
3181 /* check for exception before result assignment */
3183 M_CMPI(REG_RESULT, 0);
3185 codegen_addxexceptionrefs(cd, mcodeptr);
3187 d = reg_of_var(rd, iptr->dst, REG_RESULT);
3188 M_INTMOVE(REG_RESULT, d);
3189 store_reg_to_var_int(iptr->dst, d);
3194 throw_cacao_exception_exit(string_java_lang_InternalError,
3195 "Unknown ICMD %d", iptr->opc);
3198 } /* for instruction */
3200 /* copy values to interface registers */
3202 src = bptr->outstack;
3203 len = bptr->outdepth;
3204 MCODECHECK(64 + len);
3210 if ((src->varkind != STACKVAR)) {
3212 if (IS_FLT_DBL_TYPE(s2)) {
3213 var_to_reg_flt(s1, src, REG_FTMP1);
3214 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
3215 M_FLTMOVE(s1, rd->interfaces[len][s2].regoff);
3218 M_DST(s1, REG_SP, rd->interfaces[len][s2].regoff * 4);
3222 var_to_reg_int(s1, src, REG_ITMP1);
3223 if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
3224 M_TINTMOVE(s2, s1, rd->interfaces[len][s2].regoff);
3227 if (IS_2_WORD_TYPE(s2)) {
3228 M_IST(GET_HIGH_REG(s1),
3229 REG_SP, rd->interfaces[len][s2].regoff * 4);
3230 M_IST(GET_LOW_REG(s1), REG_SP,
3231 rd->interfaces[len][s2].regoff * 4 + 4);
3233 M_IST(s1, REG_SP, rd->interfaces[len][s2].regoff * 4);
3241 } /* if (bptr -> flags >= BBREACHED) */
3242 } /* for basic block */
3244 codegen_createlinenumbertable(cd);
3251 /* generate ArithemticException check stubs */
3255 for (bref = cd->xdivrefs; bref != NULL; bref = bref->next) {
3256 if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3257 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3259 (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
3263 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3265 (u1 *) mcodeptr - cd->mcodebase);
3269 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3271 if (xcodeptr != NULL) {
3272 disp = xcodeptr - mcodeptr - 1;
3276 xcodeptr = mcodeptr;
3278 if (m->isleafmethod) {
3280 M_AST(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3283 M_MOV(REG_PV, rd->argintregs[0]);
3284 M_MOV(REG_SP, rd->argintregs[1]);
3286 if (m->isleafmethod)
3287 M_MOV(REG_ZERO, rd->argintregs[2]);
3289 M_ALD(rd->argintregs[2],
3290 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3292 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3294 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 5 * 4));
3295 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3297 disp = dseg_addaddress(cd, stacktrace_inline_arithmeticexception);
3298 M_ALD(REG_ITMP1, REG_PV, disp);
3301 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3303 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3304 M_IADD_IMM(REG_SP, LA_SIZE + 5 * 4, REG_SP);
3306 if (m->isleafmethod) {
3307 M_ALD(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3311 disp = dseg_addaddress(cd, asm_handle_exception);
3312 M_ALD(REG_ITMP3, REG_PV, disp);
3318 /* generate ArrayIndexOutOfBoundsException stubs */
3322 for (bref = cd->xboundrefs; bref != NULL; bref = bref->next) {
3323 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3325 (u1 *) mcodeptr - cd->mcodebase);
3329 /* move index register into REG_ITMP1 */
3331 M_MOV(bref->reg, REG_ITMP1);
3333 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3335 if (xcodeptr != NULL) {
3336 disp = xcodeptr - mcodeptr - 1;
3340 xcodeptr = mcodeptr;
3342 if (m->isleafmethod) {
3344 M_AST(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3347 M_MOV(REG_PV, rd->argintregs[0]);
3348 M_MOV(REG_SP, rd->argintregs[1]);
3350 if (m->isleafmethod)
3351 M_MOV(REG_ZERO, rd->argintregs[2]);
3353 M_ALD(rd->argintregs[2],
3354 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3356 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3357 M_MOV(REG_ITMP1, rd->argintregs[4]);
3359 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 6 * 4));
3360 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 5 * 4);
3362 disp = dseg_addaddress(cd, stacktrace_inline_arrayindexoutofboundsexception);
3363 M_ALD(REG_ITMP1, REG_PV, disp);
3366 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3368 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 5 * 4);
3369 M_IADD_IMM(REG_SP, LA_SIZE + 6 * 4, REG_SP);
3371 if (m->isleafmethod) {
3372 M_ALD(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3376 disp = dseg_addaddress(cd, asm_handle_exception);
3377 M_ALD(REG_ITMP3, REG_PV, disp);
3383 /* generate ArrayStoreException check stubs */
3387 for (bref = cd->xstorerefs; bref != NULL; bref = bref->next) {
3388 if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3389 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3391 (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
3395 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3397 (u1 *) mcodeptr - cd->mcodebase);
3401 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3403 if (xcodeptr != NULL) {
3404 disp = xcodeptr - mcodeptr - 1;
3408 xcodeptr = mcodeptr;
3410 M_MOV(REG_PV, rd->argintregs[0]);
3411 M_MOV(REG_SP, rd->argintregs[1]);
3412 M_ALD(rd->argintregs[2],
3413 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3414 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3416 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 5 * 4));
3417 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3419 disp = dseg_addaddress(cd, stacktrace_inline_arraystoreexception);
3420 M_ALD(REG_ITMP1, REG_PV, disp);
3423 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3425 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3426 M_IADD_IMM(REG_SP, LA_SIZE + 5 * 4, REG_SP);
3428 disp = dseg_addaddress(cd, asm_handle_exception);
3429 M_ALD(REG_ITMP3, REG_PV, disp);
3435 /* generate ClassCastException stubs */
3439 for (bref = cd->xcastrefs; bref != NULL; bref = bref->next) {
3440 if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3441 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3443 (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
3447 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3449 (u1 *) mcodeptr - cd->mcodebase);
3453 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3455 if (xcodeptr != NULL) {
3456 disp = xcodeptr - mcodeptr - 1;
3460 xcodeptr = mcodeptr;
3462 if (m->isleafmethod) {
3464 M_AST(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3467 M_MOV(REG_PV, rd->argintregs[0]);
3468 M_MOV(REG_SP, rd->argintregs[1]);
3470 if (m->isleafmethod)
3471 M_MOV(REG_ZERO, rd->argintregs[2]);
3473 M_ALD(rd->argintregs[2],
3474 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3476 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3478 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 5 * 4));
3479 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3481 disp = dseg_addaddress(cd, stacktrace_inline_classcastexception);
3482 M_ALD(REG_ITMP1, REG_PV, disp);
3485 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3487 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3488 M_IADD_IMM(REG_SP, LA_SIZE + 5 * 4, REG_SP);
3490 if (m->isleafmethod) {
3491 M_ALD(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3495 disp = dseg_addaddress(cd, asm_handle_exception);
3496 M_ALD(REG_ITMP3, REG_PV, disp);
3502 /* generate NullPointerException stubs */
3506 for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
3507 if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3508 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3510 (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
3514 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3516 (u1 *) mcodeptr - cd->mcodebase);
3520 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3522 if (xcodeptr != NULL) {
3523 disp = xcodeptr - mcodeptr - 1;
3527 xcodeptr = mcodeptr;
3529 if (m->isleafmethod) {
3531 M_AST(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3534 M_MOV(REG_PV, rd->argintregs[0]);
3535 M_MOV(REG_SP, rd->argintregs[1]);
3537 if (m->isleafmethod)
3538 M_MOV(REG_ZERO, rd->argintregs[2]);
3540 M_ALD(rd->argintregs[2],
3541 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3543 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3545 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 5 * 4));
3546 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3548 disp = dseg_addaddress(cd, stacktrace_inline_nullpointerexception);
3549 M_ALD(REG_ITMP1, REG_PV, disp);
3552 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3554 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3555 M_IADD_IMM(REG_SP, LA_SIZE + 5 * 4, REG_SP);
3557 if (m->isleafmethod) {
3558 M_ALD(REG_ZERO, REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3562 disp = dseg_addaddress(cd, asm_handle_exception);
3563 M_ALD(REG_ITMP3, REG_PV, disp);
3569 /* generate exception check stubs */
3573 for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
3574 if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
3575 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3577 (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
3581 gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
3583 (u1 *) mcodeptr - cd->mcodebase);
3587 M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
3589 if (xcodeptr != NULL) {
3590 disp = xcodeptr - mcodeptr - 1;
3594 xcodeptr = mcodeptr;
3596 M_MOV(REG_PV, rd->argintregs[0]);
3597 M_MOV(REG_SP, rd->argintregs[1]);
3598 M_ALD(rd->argintregs[2],
3599 REG_SP, parentargs_base * 4 + LA_LR_OFFSET);
3600 M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
3602 M_STWU(REG_SP, REG_SP, -(LA_SIZE + 5 * 4));
3603 M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3605 disp = dseg_addaddress(cd, stacktrace_inline_fillInStackTrace);
3606 M_ALD(REG_ITMP1, REG_PV, disp);
3609 M_MOV(REG_RESULT, REG_ITMP1_XPTR);
3611 M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 4 * 4);
3612 M_IADD_IMM(REG_SP, LA_SIZE + 5 * 4, REG_SP);
3614 disp = dseg_addaddress(cd, asm_handle_exception);
3615 M_ALD(REG_ITMP3, REG_PV, disp);
3621 /* generate patcher stub call code */
3628 for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
3629 /* check code segment size */
3633 /* Get machine code which is patched back in later. The call is */
3634 /* 1 instruction word long. */
3636 xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
3639 /* patch in the call to call the following code (done at compile */
3642 tmpmcodeptr = mcodeptr; /* save current mcodeptr */
3643 mcodeptr = xcodeptr; /* set mcodeptr to patch position */
3645 M_BR(tmpmcodeptr - (xcodeptr + 1));
3647 mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
3649 /* create stack frame - keep stack 16-byte aligned */
3651 M_AADD_IMM(REG_SP, -8 * 4, REG_SP);
3653 /* calculate return address and move it onto the stack */
3655 M_LDA(REG_ITMP3, REG_PV, pref->branchpos);
3656 M_AST_INTERN(REG_ITMP3, REG_SP, 5 * 4);
3658 /* move pointer to java_objectheader onto stack */
3660 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
3661 /* order reversed because of data segment layout */
3663 (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */
3664 disp = dseg_addaddress(cd, NULL); /* vftbl */
3666 M_LDA(REG_ITMP3, REG_PV, disp);
3667 M_AST_INTERN(REG_ITMP3, REG_SP, 4 * 4);
3672 /* move machine code onto stack */
3674 disp = dseg_adds4(cd, mcode);
3675 M_ILD(REG_ITMP3, REG_PV, disp);
3676 M_IST_INTERN(REG_ITMP3, REG_SP, 3 * 4);
3678 /* move class/method/field reference onto stack */
3680 disp = dseg_addaddress(cd, pref->ref);
3681 M_ALD(REG_ITMP3, REG_PV, disp);
3682 M_AST_INTERN(REG_ITMP3, REG_SP, 2 * 4);
3684 /* move data segment displacement onto stack */
3686 disp = dseg_addaddress(cd, pref->disp);
3687 M_ILD(REG_ITMP3, REG_PV, disp);
3688 M_IST_INTERN(REG_ITMP3, REG_SP, 1 * 4);
3690 /* move patcher function pointer onto stack */
3692 disp = dseg_addaddress(cd, pref->patcher);
3693 M_ALD(REG_ITMP3, REG_PV, disp);
3694 M_AST_INTERN(REG_ITMP3, REG_SP, 0 * 4);
3696 disp = dseg_addaddress(cd, asm_wrapper_patcher);
3697 M_ALD(REG_ITMP3, REG_PV, disp);
3705 codegen_finish(m, cd, (ptrint) ((u1 *) mcodeptr - cd->mcodebase));
3707 asm_cacheflush((void *) (ptrint) m->entrypoint, ((u1 *) mcodeptr - cd->mcodebase));
3711 /* createcompilerstub **********************************************************
3713 Creates a stub routine which calls the compiler.
3715 *******************************************************************************/
3717 #define COMPSTUBSIZE 6
3719 functionptr createcompilerstub(methodinfo *m)
3721 s4 *s = CNEW(s4, COMPSTUBSIZE); /* memory to hold the stub */
3722 s4 *mcodeptr = s; /* code generation pointer */
3724 M_LDA(REG_ITMP1, REG_PV, 4 * 4);
3725 M_ALD_INTERN(REG_PV, REG_PV, 5 * 4);
3729 s[4] = (s4) m; /* literals to be adressed */
3730 s[5] = (s4) asm_call_jit_compiler; /* jump directly via PV from above */
3732 asm_cacheflush((void *) s, (u1 *) mcodeptr - (u1 *) s);
3734 #if defined(STATISTICS)
3736 count_cstub_len += COMPSTUBSIZE * 4;
3739 return (functionptr) (ptrint) s;
3743 /* createnativestub ************************************************************
3745 Creates a stub routine which calls a native method.
3747 *******************************************************************************/
3749 functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
3750 registerdata *rd, methoddesc *nmd)
3752 s4 *mcodeptr; /* code generation pointer */
3753 s4 stackframesize; /* size of stackframe if needed */
3756 s4 i, j; /* count variables */
3761 /* set some variables */
3764 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
3766 /* calculate stackframe size */
3769 sizeof(stackframeinfo) / SIZEOF_VOID_P +
3770 sizeof(localref_table) / SIZEOF_VOID_P +
3771 4 + /* 4 stackframeinfo arguments (darwin)*/
3772 nmd->paramcount * 2 + /* assume all arguments are doubles */
3775 stackframesize = (stackframesize + 3) & ~3; /* keep stack 16-byte aligned */
3778 /* create method header */
3780 (void) dseg_addaddress(cd, m); /* MethodPointer */
3781 (void) dseg_adds4(cd, stackframesize * 4); /* FrameSize */
3782 (void) dseg_adds4(cd, 0); /* IsSync */
3783 (void) dseg_adds4(cd, 0); /* IsLeaf */
3784 (void) dseg_adds4(cd, 0); /* IntSave */
3785 (void) dseg_adds4(cd, 0); /* FltSave */
3786 (void) dseg_addlinenumbertablesize(cd);
3787 (void) dseg_adds4(cd, 0); /* ExTableSize */
3790 /* initialize mcode variables */
3792 mcodeptr = (s4 *) cd->mcodebase;
3793 cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
3799 M_AST_INTERN(REG_ZERO, REG_SP, LA_LR_OFFSET);
3800 M_STWU(REG_SP, REG_SP, -(stackframesize * 4));
3804 /* parent_argbase == stackframesize * 4 */
3805 mcodeptr = codegen_trace_args(m, cd, rd, mcodeptr, stackframesize * 4 ,
3810 /* get function address (this must happen before the stackframeinfo) */
3812 funcdisp = dseg_addaddress(cd, f);
3814 #if !defined(ENABLE_STATICVM)
3816 codegen_addpatchref(cd, mcodeptr, PATCHER_resolve_native, m, funcdisp);
3818 if (opt_showdisassemble)
3823 /* save integer and float argument registers */
3825 for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
3826 t = md->paramtypes[i].type;
3828 if (IS_INT_LNG_TYPE(t)) {
3829 s1 = md->params[i].regoff;
3830 if (IS_2_WORD_TYPE(t)) {
3831 M_IST(rd->argintregs[GET_HIGH_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3833 M_IST(rd->argintregs[GET_LOW_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3836 M_IST(rd->argintregs[s1], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3842 for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
3843 if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
3844 s1 = md->params[i].regoff;
3845 M_DST(rd->argfltregs[s1], REG_SP, LA_SIZE + 4 * 4 + j * 8);
3850 /* create native stack info */
3852 M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[0]);
3853 M_MOV(REG_PV, rd->argintregs[1]);
3854 M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[2]);
3855 M_ALD(rd->argintregs[3], REG_SP, stackframesize * 4 + LA_LR_OFFSET);
3856 disp = dseg_addaddress(cd, codegen_start_native_call);
3857 M_ALD(REG_ITMP1, REG_PV, disp);
3861 /* restore integer and float argument registers */
3863 for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
3864 t = md->paramtypes[i].type;
3866 if (IS_INT_LNG_TYPE(t)) {
3867 s1 = md->params[i].regoff;
3869 if (IS_2_WORD_TYPE(t)) {
3870 M_ILD(rd->argintregs[GET_HIGH_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3872 M_ILD(rd->argintregs[GET_LOW_REG(s1)], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3875 M_ILD(rd->argintregs[s1], REG_SP, LA_SIZE + 4 * 4 + j * 4);
3881 for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
3882 if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
3883 s1 = md->params[i].regoff;
3884 M_DLD(rd->argfltregs[i], REG_SP, LA_SIZE + 4 * 4 + j * 8);
3889 /* copy or spill arguments to new locations */
3891 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
3892 t = md->paramtypes[i].type;
3894 if (IS_INT_LNG_TYPE(t)) {
3895 if (!md->params[i].inmemory) {
3896 if (IS_2_WORD_TYPE(t))
3898 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
3899 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
3901 s1 = rd->argintregs[md->params[i].regoff];
3903 if (!nmd->params[j].inmemory) {
3904 if (IS_2_WORD_TYPE(t))
3906 rd->argintregs[GET_LOW_REG(nmd->params[j].regoff)],
3907 rd->argintregs[GET_HIGH_REG(nmd->params[j].regoff)]);
3909 s2 = rd->argintregs[nmd->params[j].regoff];
3910 M_TINTMOVE(t, s1, s2);
3913 s2 = nmd->params[j].regoff;
3914 if (IS_2_WORD_TYPE(t)) {
3915 M_IST(GET_HIGH_REG(s1), REG_SP, s2 * 4);
3916 M_IST(GET_LOW_REG(s1), REG_SP, s2 * 4 + 4);
3918 M_IST(s1, REG_SP, s2 * 4);
3923 s1 = md->params[i].regoff + stackframesize;
3924 s2 = nmd->params[j].regoff;
3926 M_ILD(REG_ITMP1, REG_SP, s1 * 4);
3927 M_IST(REG_ITMP1, REG_SP, s2 * 4);
3928 if (IS_2_WORD_TYPE(t)) {
3929 M_ILD(REG_ITMP1, REG_SP, s1 * 4 + 4);
3930 M_IST(REG_ITMP1, REG_SP, s2 * 4 + 4);
3935 /* We only copy spilled float arguments, as the float argument */
3936 /* registers keep unchanged. */
3938 if (md->params[i].inmemory) {
3939 s1 = md->params[i].regoff + stackframesize;
3940 s2 = nmd->params[j].regoff;
3942 if (IS_2_WORD_TYPE(t)) {
3943 M_DLD(REG_FTMP1, REG_SP, s1 * 4);
3944 M_DST(REG_FTMP1, REG_SP, s2 * 4);
3947 M_FLD(REG_FTMP1, REG_SP, s1 * 4);
3948 M_FST(REG_FTMP1, REG_SP, s2 * 4);
3954 /* put class into second argument register */
3956 if (m->flags & ACC_STATIC) {
3957 disp = dseg_addaddress(cd, m->class);
3958 M_ALD(rd->argintregs[1], REG_PV, disp);
3961 /* put env into first argument register */
3963 disp = dseg_addaddress(cd, &env);
3964 M_ALD(rd->argintregs[0], REG_PV, disp);
3966 /* generate the actual native call */
3968 M_ALD(REG_ITMP3, REG_PV, funcdisp);
3972 /* save return value */
3974 if (IS_INT_LNG_TYPE(md->returntype.type)) {
3975 if (IS_2_WORD_TYPE(md->returntype.type))
3976 M_IST(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
3977 M_IST(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
3979 if (IS_2_WORD_TYPE(md->returntype.type))
3980 M_DST(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
3982 M_FST(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
3985 /* remove native stackframe info */
3987 M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[0]);
3988 disp = dseg_addaddress(cd, codegen_finish_native_call);
3989 M_ALD(REG_ITMP1, REG_PV, disp);
3993 /* print call trace */
3996 /* just restore the value we need, don't care about the other */
3998 if (IS_INT_LNG_TYPE(md->returntype.type)) {
3999 if (IS_2_WORD_TYPE(md->returntype.type))
4000 M_ILD(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
4001 M_ILD(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
4003 if (IS_2_WORD_TYPE(md->returntype.type))
4004 M_DLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4006 M_FLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4009 M_LDA(REG_SP, REG_SP, -(LA_SIZE + (1 + 2 + 2 + 1) * 4));
4011 /* keep this order */
4012 switch (md->returntype.type) {
4015 #if defined(__DARWIN__)
4016 M_MOV(REG_RESULT, rd->argintregs[2]);
4017 M_CLR(rd->argintregs[1]);
4019 M_MOV(REG_RESULT, rd->argintregs[3]);
4020 M_CLR(rd->argintregs[2]);
4025 #if defined(__DARWIN__)
4026 M_MOV(REG_RESULT2, rd->argintregs[2]);
4027 M_MOV(REG_RESULT, rd->argintregs[1]);
4029 M_MOV(REG_RESULT2, rd->argintregs[3]);
4030 M_MOV(REG_RESULT, rd->argintregs[2]);
4035 M_FLTMOVE(REG_FRESULT, rd->argfltregs[0]);
4036 M_FLTMOVE(REG_FRESULT, rd->argfltregs[1]);
4037 disp = dseg_addaddress(cd, m);
4038 M_ALD(rd->argintregs[0], REG_PV, disp);
4040 disp = dseg_addaddress(cd, builtin_displaymethodstop);
4041 M_ALD(REG_ITMP2, REG_PV, disp);
4045 M_LDA(REG_SP, REG_SP, LA_SIZE + (1 + 2 + 2 + 1) * 4);
4048 /* check for exception */
4050 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
4051 disp = dseg_addaddress(cd, builtin_get_exceptionptrptr);
4052 M_ALD(REG_ITMP1, REG_PV, disp);
4055 M_MOV(REG_RESULT, REG_ITMP2);
4057 disp = dseg_addaddress(cd, &_no_threads_exceptionptr);
4058 M_ALD(REG_ITMP2, REG_PV, disp);
4060 M_ALD(REG_ITMP1_XPTR, REG_ITMP2, 0);/* load exception into reg. itmp1 */
4062 /* restore return value */
4064 if (IS_INT_LNG_TYPE(md->returntype.type)) {
4065 if (IS_2_WORD_TYPE(md->returntype.type))
4066 M_ILD(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
4067 M_ILD(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
4069 if (IS_2_WORD_TYPE(md->returntype.type))
4070 M_DLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4072 M_FLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
4075 M_TST(REG_ITMP1_XPTR);
4076 M_BNE(4); /* if no exception then return */
4078 M_ALD(REG_ZERO, REG_SP, stackframesize * 4 + LA_LR_OFFSET); /* load ra */
4080 M_LDA(REG_SP, REG_SP, stackframesize * 4); /* remove stackframe */
4084 /* handle exception */
4087 M_AST(REG_ITMP3, REG_ITMP2, 0); /* store NULL into exceptionptr */
4089 M_ALD(REG_ITMP2, REG_SP, stackframesize * 4 + LA_LR_OFFSET); /* load ra */
4092 M_LDA(REG_SP, REG_SP, stackframesize * 4); /* remove stackframe */
4094 M_IADD_IMM(REG_ITMP2, -4, REG_ITMP2_XPC); /* fault address */
4096 disp = dseg_addaddress(cd, asm_handle_nat_exception);
4097 M_ALD(REG_ITMP3, REG_PV, disp);
4101 /* generate patcher stub call code */
4109 for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
4110 /* Get machine code which is patched back in later. The call is */
4111 /* 1 instruction word long. */
4113 xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
4114 mcode = (u4) *xcodeptr;
4116 /* patch in the call to call the following code (done at compile */
4119 tmpmcodeptr = mcodeptr; /* save current mcodeptr */
4120 mcodeptr = xcodeptr; /* set mcodeptr to patch position */
4122 M_BL(tmpmcodeptr - (xcodeptr + 1));
4124 mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
4126 /* create stack frame - keep stack 16-byte aligned */
4128 M_AADD_IMM(REG_SP, -8 * 4, REG_SP);
4130 /* move return address onto stack */
4133 M_AST(REG_ZERO, REG_SP, 5 * 4);
4135 /* move pointer to java_objectheader onto stack */
4137 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
4138 /* order reversed because of data segment layout */
4140 (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */
4141 disp = dseg_addaddress(cd, NULL); /* vftbl */
4143 M_LDA(REG_ITMP3, REG_PV, disp);
4144 M_AST(REG_ITMP3, REG_SP, 4 * 4);
4149 /* move machine code onto stack */
4151 disp = dseg_adds4(cd, mcode);
4152 M_ILD(REG_ITMP3, REG_PV, disp);
4153 M_IST(REG_ITMP3, REG_SP, 3 * 4);
4155 /* move class/method/field reference onto stack */
4157 disp = dseg_addaddress(cd, pref->ref);
4158 M_ALD(REG_ITMP3, REG_PV, disp);
4159 M_AST(REG_ITMP3, REG_SP, 2 * 4);
4161 /* move data segment displacement onto stack */
4163 disp = dseg_addaddress(cd, pref->disp);
4164 M_ILD(REG_ITMP3, REG_PV, disp);
4165 M_IST(REG_ITMP3, REG_SP, 1 * 4);
4167 /* move patcher function pointer onto stack */
4169 disp = dseg_addaddress(cd, pref->patcher);
4170 M_ALD(REG_ITMP3, REG_PV, disp);
4171 M_AST(REG_ITMP3, REG_SP, 0 * 4);
4173 disp = dseg_addaddress(cd, asm_wrapper_patcher);
4174 M_ALD(REG_ITMP3, REG_PV, disp);
4180 codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
4182 asm_cacheflush((void *) (ptrint) m->entrypoint, ((u1 *) mcodeptr - cd->mcodebase));
4184 return m->entrypoint;
4188 s4 *codegen_trace_args(methodinfo *m, codegendata *cd, registerdata *rd,
4189 s4 *mcodeptr, s4 parentargs_base, bool nativestub)
4200 /* Build up Stackframe for builtin_trace_args call (a multiple of 16) */
4202 /* LA + TRACE_ARGS_NUM u8 args + methodinfo + LR */
4203 /* LA_SIZE(=6*4) + 8*8 + 4 + 4 + 0(Padding) */
4204 /* 6 * 4 + 8 * 8 + 2 * 4 = 12 * 8 = 6 * 16 */
4206 /* LA + (TRACE_ARGS_NUM - INT_ARG_CNT/2) u8 args + methodinfo */
4207 /* + INT_ARG_CNT * 4 ( save integer registers) + LR + 8 + 8 (Padding) */
4208 /* LA_SIZE(=2*4) + 4 * 8 + 4 + 8 * 4 + 4 + 8 */
4209 /* 2 * 4 + 4 * 8 + 10 * 4 + 1 * 8 + 8= 12 * 8 = 6 * 16 */
4211 /* in nativestubs no Place to save the LR (Link Register) would be needed */
4212 /* but since the stack frame has to be aligned the 4 Bytes would have to */
4213 /* be padded again */
4215 #if defined(__DARWIN__)
4216 stack_size = LA_SIZE + (TRACE_ARGS_NUM + 1) * 8;
4218 stack_size = 6 * 16;
4220 M_LDA(REG_SP, REG_SP, -stack_size);
4224 M_IST(REG_ITMP3, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8 + 1 * 4);
4226 M_CLR(REG_ITMP1); /* clear help register */
4228 /* save up to TRACE_ARGS_NUM arguments into the reserved stack space */
4229 #if defined(__DARWIN__)
4230 /* Copy Params starting from first to Stack */
4231 /* since TRACE_ARGS == INT_ARG_CNT all used integer argument regs */
4235 /* Copy Params starting from fifth to Stack (INT_ARG_CNT/2) are in */
4236 /* integer argument regs */
4237 /* all integer argument registers have to be saved */
4238 for (p = 0; p < 8; p++) {
4239 d = rd->argintregs[p];
4240 /* save integer argument registers */
4241 M_IST(d, REG_SP, LA_SIZE + 4 * 8 + 4 + p * 4);
4245 stack_off = LA_SIZE;
4246 for (; p < md->paramcount && p < TRACE_ARGS_NUM; p++, stack_off += 8) {
4247 t = md->paramtypes[p].type;
4248 if (IS_INT_LNG_TYPE(t)) {
4249 if (!md->params[p].inmemory) { /* Param in Arg Reg */
4250 if (IS_2_WORD_TYPE(t)) {
4251 M_IST(rd->argintregs[GET_HIGH_REG(md->params[p].regoff)]
4252 , REG_SP, stack_off);
4253 M_IST(rd->argintregs[GET_LOW_REG(md->params[p].regoff)]
4254 , REG_SP, stack_off + 4);
4256 M_IST(REG_ITMP1, REG_SP, stack_off);
4257 M_IST(rd->argintregs[md->params[p].regoff]
4258 , REG_SP, stack_off + 4);
4260 } else { /* Param on Stack */
4261 s1 = (md->params[p].regoff + parentargs_base) * 4
4263 if (IS_2_WORD_TYPE(t)) {
4264 M_ILD(REG_ITMP2, REG_SP, s1);
4265 M_IST(REG_ITMP2, REG_SP, stack_off);
4266 M_ILD(REG_ITMP2, REG_SP, s1 + 4);
4267 M_IST(REG_ITMP2, REG_SP, stack_off + 4);
4269 M_IST(REG_ITMP1, REG_SP, stack_off);
4270 M_ILD(REG_ITMP2, REG_SP, s1);
4271 M_IST(REG_ITMP2, REG_SP, stack_off + 4);
4274 } else { /* IS_FLT_DBL_TYPE(t) */
4275 if (!md->params[p].inmemory) { /* in Arg Reg */
4276 s1 = rd->argfltregs[md->params[p].regoff];
4277 if (!IS_2_WORD_TYPE(t)) {
4278 M_IST(REG_ITMP1, REG_SP, stack_off);
4279 M_FST(s1, REG_SP, stack_off + 4);
4281 M_DST(s1, REG_SP, stack_off);
4283 } else { /* on Stack */
4284 /* this should not happen */
4289 /* load first 4 (==INT_ARG_CNT/2) arguments into integer registers */
4290 #if defined(__DARWIN__)
4291 for (p = 0; p < 8; p++) {
4292 d = rd->argintregs[p];
4293 M_ILD(d, REG_SP, LA_SIZE + p * 4);
4297 /* Set integer and float argument registers vor trace_args call */
4298 /* offset to saved integer argument registers */
4299 stack_off = LA_SIZE + 4 * 8 + 4;
4300 for (p = 0; (p < 4) && (p < md->paramcount); p++) {
4301 t = md->paramtypes[p].type;
4302 if (IS_INT_LNG_TYPE(t)) {
4303 /* "stretch" int types */
4304 if (!IS_2_WORD_TYPE(t)) {
4305 M_CLR(rd->argintregs[2 * p]);
4306 M_ILD(rd->argintregs[2 * p + 1], REG_SP,stack_off);
4309 M_ILD(rd->argintregs[2 * p + 1], REG_SP,stack_off + 4);
4310 M_ILD(rd->argintregs[2 * p], REG_SP,stack_off);
4313 } else { /* Float/Dbl */
4314 if (!md->params[p].inmemory) { /* Param in Arg Reg */
4315 /* use reserved Place on Stack (sp + 5 * 16) to copy */
4316 /* float/double arg reg to int reg */
4317 s1 = rd->argfltregs[md->params[p].regoff];
4318 if (!IS_2_WORD_TYPE(t)) {
4319 M_FST(s1, REG_SP, 5 * 16);
4320 M_ILD(rd->argintregs[2 * p + 1], REG_SP, 5 * 16);
4321 M_CLR(rd->argintregs[2 * p]);
4323 M_DST(s1, REG_SP, 5 * 16);
4324 M_ILD(rd->argintregs[2 * p + 1], REG_SP, 5 * 16 + 4);
4325 M_ILD(rd->argintregs[2 * p], REG_SP, 5 * 16);
4332 /* put methodinfo pointer on Stackframe */
4333 p = dseg_addaddress(cd, m);
4334 M_ALD(REG_ITMP1, REG_PV, p);
4335 #if defined(__DARWIN__)
4336 M_AST(REG_ITMP1, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8);
4338 M_AST(REG_ITMP1, REG_SP, LA_SIZE + 4 * 8);
4340 p = dseg_addaddress(cd, builtin_trace_args);
4341 M_ALD(REG_ITMP2, REG_PV, p);
4345 #if defined(__DARWIN__)
4346 /* restore integer argument registers from the reserved stack space */
4348 stack_off = LA_SIZE;
4349 for (p = 0; p < md->paramcount && p < TRACE_ARGS_NUM;
4350 p++, stack_off += 8) {
4351 t = md->paramtypes[p].type;
4353 if (IS_INT_LNG_TYPE(t)) {
4354 if (!md->params[p].inmemory) {
4355 if (IS_2_WORD_TYPE(t)) {
4356 M_ILD(rd->argintregs[GET_HIGH_REG(md->params[p].regoff)]
4357 , REG_SP, stack_off);
4358 M_ILD(rd->argintregs[GET_LOW_REG(md->params[p].regoff)]
4359 , REG_SP, stack_off + 4);
4361 M_ILD(rd->argintregs[md->params[p].regoff]
4362 , REG_SP, stack_off + 4);
4369 for (p = 0; p < 8; p++) {
4370 d = rd->argintregs[p];
4371 /* save integer argument registers */
4372 M_ILD(d, REG_SP, LA_SIZE + 4 * 8 + 4 + p * 4);
4377 M_ILD(REG_ITMP3, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8 + 1 * 4);
4379 M_LDA(REG_SP, REG_SP, stack_size);
4386 * These are local overrides for various environment variables in Emacs.
4387 * Please do not remove this and leave it at the end of the file, where
4388 * Emacs will automagically detect them.
4389 * ---------------------------------------------------------------------
4392 * indent-tabs-mode: t