X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fjit%2Falpha%2Fcodegen.c;h=ebd3e527627e76ccb6d1ce5f753d9baebb321922;hb=7cd8277a5e97e742eb461185416b39afd8653149;hp=92f01d1d95c2e3679f88a87db3e7c57cd44addcb;hpb=cac1db8022d8627bed9e5735dbb8102bf3378dd1;p=cacao.git diff --git a/src/vm/jit/alpha/codegen.c b/src/vm/jit/alpha/codegen.c index 92f01d1d9..ebd3e5276 100644 --- a/src/vm/jit/alpha/codegen.c +++ b/src/vm/jit/alpha/codegen.c @@ -1,10 +1,9 @@ -/* jit/alpha/codegen.c - machine code generator for alpha +/* src/vm/jit/alpha/codegen.c - machine code generator for Alpha - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 - Institut f. Computersprachen, TU Wien - R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst, - S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, - J. Wenninger + Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates, + R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner, + C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger, + Institut f. Computersprachen - TU Wien This file is part of CACAO. @@ -28,647 +27,346 @@ Authors: Andreas Krall Reinhard Grafl - $Id: codegen.c 948 2004-03-07 22:12:28Z twisti $ + Changes: Joseph Wenninger + Christian Thalinger + Christian Ullrich + + $Id: codegen.c 3345 2005-10-04 22:14:53Z twisti $ */ #include -#include -#include "types.h" -#include "main.h" -#include "codegen.h" -#include "jit.h" -#include "parse.h" -#include "reg.h" -#include "builtin.h" -#include "asmpart.h" -#include "jni.h" -#include "loader.h" -#include "tables.h" -#include "native.h" -#include "main.h" - -/* include independent code generation stuff */ -#include "codegen.inc" -#include "reg.inc" - - -/* ***************************************************************************** -Datatypes and Register Allocations: ------------------------------------ - -On 64-bit-machines (like the Alpha) all operands are stored in the -registers in a 64-bit form, even when the correspondig JavaVM operands -only need 32 bits. This is done by a canonical representation: - -32-bit integers are allways stored as sign-extended 64-bit values (this -approach is directly supported by the Alpha architecture and is very easy -to implement). +#include "config.h" +#include "vm/types.h" + +#include "md.h" +#include "md-abi.h" +#include "md-abi.inc" + +#include "vm/jit/alpha/arch.h" +#include "vm/jit/alpha/codegen.h" + +#include "cacao/cacao.h" +#include "native/native.h" +#include "vm/builtin.h" +#include "vm/global.h" +#include "vm/loader.h" +#include "vm/stringlocal.h" +#include "vm/tables.h" +#include "vm/jit/asmpart.h" +#include "vm/jit/codegen.inc" +#include "vm/jit/jit.h" + +#if defined(LSRA) +# include "vm/jit/lsra.h" +# include "vm/jit/lsra.inc" +#endif -32-bit-floats are stored in a 64-bit doubleprecision register by simply -expanding the exponent and mantissa with zeroes. (also supported by the -architecture) +#include "vm/jit/parse.h" +#include "vm/jit/patcher.h" +#include "vm/jit/reg.h" +#include "vm/jit/reg.inc" -Stackframes: +/* codegen ********************************************************************* -The calling conventions and the layout of the stack is explained in detail -in the documention file: calling.doc + Generates machine code. *******************************************************************************/ +void codegen(methodinfo *m, codegendata *cd, registerdata *rd) +{ + s4 len, s1, s2, s3, d, disp; + ptrint a; + s4 parentargs_base; + s4 *mcodeptr; + stackptr src; + varinfo *var; + basicblock *bptr; + instruction *iptr; + exceptiontable *ex; + u2 currentline; + methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */ + builtintable_entry *bte; + methoddesc *md; + + /* prevent compiler warnings */ + + d = 0; + currentline = 0; + lm = NULL; + bte = NULL; -/* register descripton - array ************************************************/ - -/* #define REG_RES 0 reserved register for OS or code generator */ -/* #define REG_RET 1 return value register */ -/* #define REG_EXC 2 exception value register (only old jit) */ -/* #define REG_SAV 3 (callee) saved register */ -/* #define REG_TMP 4 scratch temporary register (caller saved) */ -/* #define REG_ARG 5 argument register (caller saved) */ - -/* #define REG_END -1 last entry in tables */ - -int nregdescint[] = { - REG_RET, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, - REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, - REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP, - REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, - REG_END }; - -/* for use of reserved registers, see comment above */ - -int nregdescfloat[] = { - REG_RET, REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, - REG_SAV, REG_SAV, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, - REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP, - REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, - REG_END }; - -/* for use of reserved registers, see comment above */ - - -/* parameter allocation mode */ - -int nreg_parammode = PARAMMODE_NUMBERED; - - /* parameter-registers will be allocated by assigning the - 1. parameter: int/float-reg 16 - 2. parameter: int/float-reg 17 - 3. parameter: int/float-reg 18 .... - */ - - -/* stackframe-infos ***********************************************************/ + { + s4 i, p, t, l; + s4 savedregs_num; -int parentargs_base; /* offset in stackframe for the parameter from the caller*/ + savedregs_num = (m->isleafmethod) ? 0 : 1; /* space to save the RA */ -/* -> see file 'calling.doc' */ + /* space to save used callee saved registers */ + savedregs_num += (INT_SAV_CNT - rd->savintreguse); + savedregs_num += (FLT_SAV_CNT - rd->savfltreguse); -/* additional functions and macros to generate code ***************************/ + parentargs_base = rd->memuse + savedregs_num; -/* #define BlockPtrOfPC(pc) block+block_index[pc] */ -#define BlockPtrOfPC(pc) ((basicblock *) iptr->target) +#if defined(USE_THREADS) /* space to save argument of monitor_enter */ + if (checksync && (m->flags & ACC_SYNCHRONIZED)) + parentargs_base++; -#ifdef STATISTICS -#define COUNT_SPILLS count_spills++ -#else -#define COUNT_SPILLS #endif + /* create method header */ -/* gen_nullptr_check(objreg) */ - -#define gen_nullptr_check(objreg) \ - if (checknull) { \ - M_BEQZ((objreg), 0); \ - codegen_addxnullrefs(mcodeptr); \ - } - - -/* MCODECHECK(icnt) */ - -#define MCODECHECK(icnt) \ - if((mcodeptr + (icnt)) > mcodeend) mcodeptr = codegen_increase((u1*) mcodeptr) - -/* M_INTMOVE: - generates an integer-move from register a to b. - if a and b are the same int-register, no code will be generated. -*/ - -#define M_INTMOVE(a,b) if (a != b) { M_MOV(a, b); } - - -/* M_FLTMOVE: - generates a floating-point-move from register a to b. - if a and b are the same float-register, no code will be generated -*/ - -#define M_FLTMOVE(a,b) if (a != b) { M_FMOV(a, b); } - - -/* var_to_reg_xxx: - this function generates code to fetch data from a pseudo-register - into a real register. - If the pseudo-register has actually been assigned to a real - register, no code will be emitted, since following operations - can use this register directly. - - v: pseudoregister to be fetched from - tempregnum: temporary register to be used if v is actually spilled to ram - - return: the register number, where the operand can be found after - fetching (this wil be either tempregnum or the register - number allready given to v) -*/ + (void) dseg_addaddress(cd, m); /* MethodPointer */ + (void) dseg_adds4(cd, parentargs_base * 8); /* FrameSize */ -#define var_to_reg_int(regnr,v,tempnr) { \ - if ((v)->flags & INMEMORY) \ - {COUNT_SPILLS;M_LLD(tempnr,REG_SP,8*(v)->regoff);regnr=tempnr;} \ - else regnr=(v)->regoff; \ -} +#if defined(USE_THREADS) + /* IsSync contains the offset relative to the stack pointer for the + argument of monitor_exit used in the exception handler. Since the + offset could be zero and give a wrong meaning of the flag it is + offset by one. + */ -#define var_to_reg_flt(regnr,v,tempnr) { \ - if ((v)->flags & INMEMORY) \ - {COUNT_SPILLS;M_DLD(tempnr,REG_SP,8*(v)->regoff);regnr=tempnr;} \ - else regnr=(v)->regoff; \ -} + if (checksync && (m->flags & ACC_SYNCHRONIZED)) + (void) dseg_adds4(cd, (rd->memuse + 1) * 8); /* IsSync */ + else +#endif -/* reg_of_var: - This function determines a register, to which the result of an operation - should go, when it is ultimatively intended to store the result in - pseudoregister v. - If v is assigned to an actual register, this register will be returned. - Otherwise (when v is spilled) this function returns tempregnum. - If not already done, regoff and flags are set in the stack location. -*/ + (void) dseg_adds4(cd, 0); /* IsSync */ + + (void) dseg_adds4(cd, m->isleafmethod); /* IsLeaf */ + (void) dseg_adds4(cd, INT_SAV_CNT - rd->savintreguse);/* IntSave */ + (void) dseg_adds4(cd, FLT_SAV_CNT - rd->savfltreguse);/* FltSave */ -static int reg_of_var(stackptr v, int tempregnum) -{ - varinfo *var; - - switch (v->varkind) { - case TEMPVAR: - if (!(v->flags & INMEMORY)) - return(v->regoff); - break; - case STACKVAR: - var = &(interfaces[v->varnum][v->type]); - v->regoff = var->regoff; - if (!(var->flags & INMEMORY)) - return(var->regoff); - break; - case LOCALVAR: - var = &(locals[v->varnum][v->type]); - v->regoff = var->regoff; - if (!(var->flags & INMEMORY)) - return(var->regoff); - break; - case ARGVAR: - v->regoff = v->varnum; - if (IS_FLT_DBL_TYPE(v->type)) { - if (v->varnum < fltreg_argnum) { - v->regoff = argfltregs[v->varnum]; - return(argfltregs[v->varnum]); - } - } - else - if (v->varnum < intreg_argnum) { - v->regoff = argintregs[v->varnum]; - return(argintregs[v->varnum]); - } - v->regoff -= intreg_argnum; - break; - } - v->flags |= INMEMORY; - return tempregnum; -} + dseg_addlinenumbertablesize(cd); + (void) dseg_adds4(cd, cd->exceptiontablelength); /* ExTableSize */ -/* store_reg_to_var_xxx: - This function generates the code to store the result of an operation - back into a spilled pseudo-variable. - If the pseudo-variable has not been spilled in the first place, this - function will generate nothing. - - v ............ Pseudovariable - tempregnum ... Number of the temporary registers as returned by - reg_of_var. -*/ - -#define store_reg_to_var_int(sptr, tempregnum) { \ - if ((sptr)->flags & INMEMORY) { \ - COUNT_SPILLS; \ - M_LST(tempregnum, REG_SP, 8 * (sptr)->regoff); \ - } \ - } + /* create exception table */ -#define store_reg_to_var_flt(sptr, tempregnum) { \ - if ((sptr)->flags & INMEMORY) { \ - COUNT_SPILLS; \ - M_DST(tempregnum, REG_SP, 8 * (sptr)->regoff); \ - } \ + for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) { + dseg_addtarget(cd, ex->start); + dseg_addtarget(cd, ex->end); + dseg_addtarget(cd, ex->handler); + (void) dseg_addaddress(cd, ex->catchtype.cls); } + + /* initialize mcode variables */ + + mcodeptr = (s4 *) cd->mcodebase; + cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize); + MCODECHECK(128 + m->paramcount); + /* create stack frame (if necessary) */ -/* NullPointerException handlers and exception handling initialisation */ - -typedef struct sigctx_struct { - - long sc_onstack; /* sigstack state to restore */ - long sc_mask; /* signal mask to restore */ - long sc_pc; /* pc at time of signal */ - long sc_ps; /* psl to retore */ - long sc_regs[32]; /* processor regs 0 to 31 */ - long sc_ownedfp; /* fp has been used */ - long sc_fpregs[32]; /* fp regs 0 to 31 */ - unsigned long sc_fpcr; /* floating point control register */ - unsigned long sc_fp_control; /* software fpcr */ - /* rest is unused */ - unsigned long sc_reserved1, sc_reserved2; - unsigned long sc_ssize; - char *sc_sbase; - unsigned long sc_traparg_a0; - unsigned long sc_traparg_a1; - unsigned long sc_traparg_a2; - unsigned long sc_fp_trap_pc; - unsigned long sc_fp_trigger_sum; - unsigned long sc_fp_trigger_inst; - unsigned long sc_retcode[2]; -} sigctx_struct; - - -/* NullPointerException signal handler for hardware null pointer check */ - -void catch_NullPointerException(int sig, int code, sigctx_struct *sigctx) -{ - sigset_t nsig; - int instr; - long faultaddr; - - /* Reset signal handler - necessary for SysV, does no harm for BSD */ - - instr = *((int*)(sigctx->sc_pc)); - faultaddr = sigctx->sc_regs[(instr >> 16) & 0x1f]; - - if (faultaddr == 0) { - signal(sig, (void*) catch_NullPointerException); /* reinstall handler */ - sigemptyset(&nsig); - sigaddset(&nsig, sig); - sigprocmask(SIG_UNBLOCK, &nsig, NULL); /* unblock signal */ - - if (!proto_java_lang_NullPointerException) { - proto_java_lang_NullPointerException = - new_exception(string_java_lang_NullPointerException); - } - - sigctx->sc_regs[REG_ITMP1_XPTR] = - (long) proto_java_lang_NullPointerException; - sigctx->sc_regs[REG_ITMP2_XPC] = sigctx->sc_pc; - sigctx->sc_pc = (long) asm_handle_exception; - return; - - } else { - faultaddr += (long) ((instr << 16) >> 16); - fprintf(stderr, "faulting address: 0x%16lx\n", faultaddr); - panic("Stack overflow"); + if (parentargs_base) { + M_LDA(REG_SP, REG_SP, -parentargs_base * 8); } -} - - -#ifdef __osf__ - -void init_exceptions(void) -{ - -#else /* Linux */ - -/* Linux on Digital Alpha needs an initialisation of the ieee floating point - control for IEEE compliant arithmetic (option -mieee of GCC). Under - Digital Unix this is done automatically. -*/ - -#include - -extern unsigned long ieee_get_fp_control(); -extern void ieee_set_fp_control(unsigned long fp_control); - -void init_exceptions(void) -{ -/* initialize floating point control */ - -ieee_set_fp_control(ieee_get_fp_control() - & ~IEEE_TRAP_ENABLE_INV - & ~IEEE_TRAP_ENABLE_DZE -/* & ~IEEE_TRAP_ENABLE_UNF we dont want underflow */ - & ~IEEE_TRAP_ENABLE_OVF); -#endif - - /* install signal handlers we need to convert to exceptions */ - if (!checknull) { -#if defined(SIGSEGV) - signal(SIGSEGV, (void*) catch_NullPointerException); -#endif + /* save return address and used callee saved registers */ -#if defined(SIGBUS) - signal(SIGBUS, (void*) catch_NullPointerException); -#endif + p = parentargs_base; + if (!m->isleafmethod) { + p--; M_AST(REG_RA, REG_SP, p * 8); + } + for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) { + p--; M_LST(rd->savintregs[i], REG_SP, p * 8); + } + for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) { + p--; M_DST(rd->savfltregs[i], REG_SP, p * 8); } -} - - -/* function gen_mcode ********************************************************** - - generates machine code - -*******************************************************************************/ - -void codegen() -{ - int len, s1, s2, s3, d; - s4 a; - s4 *mcodeptr; - stackptr src; - varinfo *var; - basicblock *bptr; - instruction *iptr; - xtable *ex; - - { - int p, pa, t, l, r; - - savedregs_num = (isleafmethod) ? 0 : 1; /* space to save the RA */ - - /* space to save used callee saved registers */ - savedregs_num += (savintregcnt - maxsavintreguse); - savedregs_num += (savfltregcnt - maxsavfltreguse); + /* take arguments out of register or stack frame */ - parentargs_base = maxmemuse + savedregs_num; + md = m->parseddesc; -#ifdef USE_THREADS /* space to save argument of monitor_enter */ + for (p = 0, l = 0; p < md->paramcount; p++) { + t = md->paramtypes[p].type; + var = &(rd->locals[l][t]); + l++; + if (IS_2_WORD_TYPE(t)) /* increment local counter for 2 word types */ + l++; + if (var->type < 0) + continue; + s1 = md->params[p].regoff; + if (IS_INT_LNG_TYPE(t)) { /* integer args */ + if (!md->params[p].inmemory) { /* register arguments */ + s2 = rd->argintregs[s1]; + if (!(var->flags & INMEMORY)) { /* reg arg -> register */ + M_INTMOVE(s2, var->regoff); - if (checksync && (method->flags & ACC_SYNCHRONIZED)) - parentargs_base++; + } else { /* reg arg -> spilled */ + M_LST(s2, REG_SP, var->regoff * 8); + } -#endif + } else { /* stack arguments */ + if (!(var->flags & INMEMORY)) { /* stack arg -> register */ + M_LLD(var->regoff, REG_SP, (parentargs_base + s1) * 8); - /* create method header */ + } else { /* stack arg -> spilled */ + var->regoff = parentargs_base + s1; + } + } - (void) dseg_addaddress(method); /* MethodPointer */ - (void) dseg_adds4(parentargs_base * 8); /* FrameSize */ + } else { /* floating args */ + if (!md->params[p].inmemory) { /* register arguments */ + s2 = rd->argfltregs[s1]; + if (!(var->flags & INMEMORY)) { /* reg arg -> register */ + M_FLTMOVE(s2, var->regoff); -#ifdef USE_THREADS + } else { /* reg arg -> spilled */ + M_DST(s2, REG_SP, var->regoff * 8); + } - /* IsSync contains the offset relative to the stack pointer for the - argument of monitor_exit used in the exception handler. Since the - offset could be zero and give a wrong meaning of the flag it is - offset by one. - */ + } else { /* stack arguments */ + if (!(var->flags & INMEMORY)) { /* stack-arg -> register */ + M_DLD(var->regoff, REG_SP, (parentargs_base + s1) * 8); - if (checksync && (method->flags & ACC_SYNCHRONIZED)) - (void) dseg_adds4((maxmemuse + 1) * 8); /* IsSync */ - else + } else { /* stack-arg -> spilled */ + var->regoff = parentargs_base + s1; + } + } + } + } /* end for */ -#endif + /* call monitorenter function */ - (void) dseg_adds4(0); /* IsSync */ - - (void) dseg_adds4(isleafmethod); /* IsLeaf */ - (void) dseg_adds4(savintregcnt - maxsavintreguse); /* IntSave */ - (void) dseg_adds4(savfltregcnt - maxsavfltreguse); /* FltSave */ - (void) dseg_adds4(exceptiontablelength); /* ExTableSize */ +#if defined(USE_THREADS) + if (checksync && (m->flags & ACC_SYNCHRONIZED)) { + /* stack offset for monitor argument */ - /* create exception table */ + s1 = rd->memuse; - for (ex = extable; ex != NULL; ex = ex->down) { + if (runverbose) { + M_LDA(REG_SP, REG_SP, -(INT_ARG_CNT + FLT_ARG_CNT) * 8); -#ifdef LOOP_DEBUG - if (ex->start != NULL) - printf("adding start - %d - ", ex->start->debug_nr); - else { - printf("PANIC - start is NULL"); - exit(-1); - } -#endif + for (p = 0; p < INT_ARG_CNT; p++) + M_LST(rd->argintregs[p], REG_SP, p * 8); - dseg_addtarget(ex->start); + for (p = 0; p < FLT_ARG_CNT; p++) + M_DST(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8); -#ifdef LOOP_DEBUG - if (ex->end != NULL) - printf("adding end - %d - ", ex->end->debug_nr); - else { - printf("PANIC - end is NULL"); - exit(-1); + s1 += INT_ARG_CNT + FLT_ARG_CNT; } -#endif - dseg_addtarget(ex->end); + /* decide which monitor enter function to call */ -#ifdef LOOP_DEBUG - if (ex->handler != NULL) - printf("adding handler - %d\n", ex->handler->debug_nr); - else { - printf("PANIC - handler is NULL"); - exit(-1); - } -#endif + if (m->flags & ACC_STATIC) { + disp = dseg_addaddress(cd, m->class); + M_ALD(REG_ITMP1, REG_PV, disp); + M_AST(REG_ITMP1, REG_SP, s1 * 8); + M_INTMOVE(REG_ITMP1, rd->argintregs[0]); + disp = dseg_addaddress(cd, BUILTIN_staticmonitorenter); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, disp); - dseg_addtarget(ex->handler); - - (void) dseg_addaddress(ex->catchtype); + } else { + M_BEQZ(rd->argintregs[0], 0); + codegen_addxnullrefs(cd, mcodeptr); + M_AST(rd->argintregs[0], REG_SP, s1 * 8); + disp = dseg_addaddress(cd, BUILTIN_monitorenter); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, disp); } - - /* initialize mcode variables */ - - mcodeptr = (s4*) mcodebase; - mcodeend = (s4*) (mcodebase + mcodesize); - MCODECHECK(128 + mparamcount); - - /* create stack frame (if necessary) */ - if (parentargs_base) - {M_LDA (REG_SP, REG_SP, -parentargs_base * 8);} + if (runverbose) { + for (p = 0; p < INT_ARG_CNT; p++) + M_LLD(rd->argintregs[p], REG_SP, p * 8); - /* save return address and used callee saved registers */ + for (p = 0; p < FLT_ARG_CNT; p++) + M_DLD(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8); - p = parentargs_base; - if (!isleafmethod) - {p--; M_AST (REG_RA, REG_SP, 8*p);} - for (r = savintregcnt - 1; r >= maxsavintreguse; r--) - {p--; M_LST (savintregs[r], REG_SP, 8 * p);} - for (r = savfltregcnt - 1; r >= maxsavfltreguse; r--) - {p--; M_DST (savfltregs[r], REG_SP, 8 * p);} - - /* save monitorenter argument */ - -#ifdef USE_THREADS - if (checksync && (method->flags & ACC_SYNCHRONIZED)) { - if (method->flags & ACC_STATIC) { - p = dseg_addaddress (class); - M_ALD(REG_ITMP1, REG_PV, p); - M_AST(REG_ITMP1, REG_SP, 8 * maxmemuse); - } - else { - M_AST (argintregs[0], REG_SP, 8 * maxmemuse); - } - } + M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT) * 8); + } + } #endif - /* copy argument registers to stack and call trace function with pointer - to arguments on stack. - */ + /* call trace function */ if (runverbose) { - int disp; - M_LDA(REG_SP, REG_SP, -(14 * 8)); + M_LDA(REG_SP, REG_SP, -((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8)); M_AST(REG_RA, REG_SP, 1 * 8); /* save integer argument registers */ - for (p = 0; p < mparamcount && p < INT_ARG_CNT; p++) { - M_LST(argintregs[p], REG_SP, (2 + p) * 8); - } + + for (p = 0; p < md->paramcount && p < INT_ARG_CNT; p++) + M_LST(rd->argintregs[p], REG_SP, (2 + p) * 8); /* save and copy float arguments into integer registers */ - for (p = 0; p < mparamcount && p < FLT_ARG_CNT; p++) { - t = mparamtypes[p]; + + for (p = 0; p < md->paramcount && p < FLT_ARG_CNT; p++) { + t = md->paramtypes[p].type; if (IS_FLT_DBL_TYPE(t)) { if (IS_2_WORD_TYPE(t)) { - M_DST(argfltregs[p], REG_SP, (8 + p) * 8); + M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8); + } else { - M_FST(argfltregs[p], REG_SP, (8 + p) * 8); + M_FST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8); } - M_LLD(argintregs[p], REG_SP, (8 + p) * 8); + M_LLD(rd->argintregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8); } else { - M_DST(argfltregs[p], REG_SP, (8 + p) * 8); + M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8); } } - p = dseg_addaddress(method); - M_ALD(REG_ITMP1, REG_PV, p); - M_AST(REG_ITMP1, REG_SP, 0); - p = dseg_addaddress((void *) builtin_trace_args); - M_ALD(REG_PV, REG_PV, p); + disp = dseg_addaddress(cd, m); + M_ALD(REG_ITMP1, REG_PV, disp); + M_AST(REG_ITMP1, REG_SP, 0 * 8); + disp = dseg_addaddress(cd, (void *) builtin_trace_args); + M_ALD(REG_PV, REG_PV, disp); M_JSR(REG_RA, REG_PV); - disp = -(int)((u1 *) mcodeptr - mcodebase); + disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase); M_LDA(REG_PV, REG_RA, disp); M_ALD(REG_RA, REG_SP, 1 * 8); - for (p = 0; p < mparamcount && p < INT_ARG_CNT; p++) { - M_LLD(argintregs[p], REG_SP, (2 + p) * 8); - } + /* restore integer argument registers */ + + for (p = 0; p < md->paramcount && p < INT_ARG_CNT; p++) + M_LLD(rd->argintregs[p], REG_SP, (2 + p) * 8); + + /* restore float argument registers */ - for (p = 0; p < mparamcount && p < FLT_ARG_CNT; p++) { - t = mparamtypes[p]; + for (p = 0; p < md->paramcount && p < FLT_ARG_CNT; p++) { + t = md->paramtypes[p].type; if (IS_FLT_DBL_TYPE(t)) { if (IS_2_WORD_TYPE(t)) { - M_DLD(argfltregs[p], REG_SP, (8 + p) * 8); + M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8); + } else { - M_FLD(argfltregs[p], REG_SP, (8 + p) * 8); + M_FLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8); } + } else { - M_DLD(argfltregs[p], REG_SP, (8 + p) * 8); + M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8); } } - M_LDA (REG_SP, REG_SP, 14 * 8); + M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT + 2) * 8); } - /* take arguments out of register or stack frame */ - - for (p = 0, l = 0; p < mparamcount; p++) { - t = mparamtypes[p]; - var = &(locals[l][t]); - l++; - if (IS_2_WORD_TYPE(t)) /* increment local counter for 2 word types */ - l++; - if (var->type < 0) - continue; - r = var->regoff; - if (IS_INT_LNG_TYPE(t)) { /* integer args */ - if (p < INT_ARG_CNT) { /* register arguments */ - if (!(var->flags & INMEMORY)) /* reg arg -> register */ - {M_INTMOVE (argintregs[p], r);} - else /* reg arg -> spilled */ - M_LST (argintregs[p], REG_SP, 8 * r); - } - else { /* stack arguments */ - pa = p - INT_ARG_CNT; - if (!(var->flags & INMEMORY)) /* stack arg -> register */ - M_LLD (r, REG_SP, 8 * (parentargs_base + pa)); - else { /* stack arg -> spilled */ - M_LLD (REG_ITMP1, REG_SP, 8 * (parentargs_base + pa)); - M_LST (REG_ITMP1, REG_SP, 8 * r); - } - } - } - else { /* floating args */ - if (p < FLT_ARG_CNT) { /* register arguments */ - if (!(var->flags & INMEMORY)) /* reg arg -> register */ - {M_FLTMOVE (argfltregs[p], r);} - else /* reg arg -> spilled */ - M_DST (argfltregs[p], REG_SP, 8 * r); - } - else { /* stack arguments */ - pa = p - FLT_ARG_CNT; - if (!(var->flags & INMEMORY)) /* stack-arg -> register */ - M_DLD (r, REG_SP, 8 * (parentargs_base + pa) ); - else { /* stack-arg -> spilled */ - M_DLD (REG_FTMP1, REG_SP, 8 * (parentargs_base + pa)); - M_DST (REG_FTMP1, REG_SP, 8 * r); - } - } - } - } /* end for */ - - /* call trace function */ - -#if 0 - if (runverbose && !isleafmethod) { - M_LDA (REG_SP, REG_SP, -8); - p = dseg_addaddress (method); - M_ALD(REG_ITMP1, REG_PV, p); - M_AST(REG_ITMP1, REG_SP, 0); - p = dseg_addaddress ((void*) (builtin_trace_args)); - M_ALD(REG_PV, REG_PV, p); - M_JSR(REG_RA, REG_PV); - M_LDA(REG_PV, REG_RA, -(int)((u1*) mcodeptr - mcodebase)); - M_LDA(REG_SP, REG_SP, 8); - } -#endif - - /* call monitorenter function */ - -#ifdef USE_THREADS - if (checksync && (method->flags & ACC_SYNCHRONIZED)) { - int disp; - p = dseg_addaddress ((void*) (builtin_monitorenter)); - M_ALD(REG_PV, REG_PV, p); - M_ALD(argintregs[0], REG_SP, 8 * maxmemuse); - M_JSR(REG_RA, REG_PV); - disp = -(int)((u1*) mcodeptr - mcodebase); - M_LDA(REG_PV, REG_RA, disp); - } -#endif } /* end of header generation */ /* walk through all basic blocks */ - for (bptr = block; bptr != NULL; bptr = bptr->next) { - bptr->mpc = (int)((u1*) mcodeptr - mcodebase); + for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) { + + bptr->mpc = (s4) ((u1 *) mcodeptr - cd->mcodebase); if (bptr->flags >= BBREACHED) { @@ -677,7 +375,7 @@ void codegen() { branchref *brefs; for (brefs = bptr->branchrefs; brefs != NULL; brefs = brefs->next) { - gen_resolvebranch((u1*) mcodebase + brefs->branchpos, + gen_resolvebranch((u1*) cd->mcodebase + brefs->branchpos, brefs->branchpos, bptr->mpc); } } @@ -687,75 +385,93 @@ void codegen() src = bptr->instack; len = bptr->indepth; MCODECHECK(64+len); +#ifdef LSRA + if (opt_lsra) { while (src != NULL) { len--; if ((len == 0) && (bptr->type != BBTYPE_STD)) { - d = reg_of_var(src, REG_ITMP1); - M_INTMOVE(REG_ITMP1, d); - store_reg_to_var_int(src, d); - } - else { - d = reg_of_var(src, REG_IFTMP); - if ((src->varkind != STACKVAR)) { - s2 = src->type; - if (IS_FLT_DBL_TYPE(s2)) { - if (!(interfaces[len][s2].flags & INMEMORY)) { - s1 = interfaces[len][s2].regoff; - M_FLTMOVE(s1,d); - } - else { - M_DLD(d, REG_SP, 8 * interfaces[len][s2].regoff); + /* d = reg_of_var(m, src, REG_ITMP1); */ + if (!(src->flags & INMEMORY)) + d = src->regoff; + else + d = REG_ITMP1; + M_INTMOVE(REG_ITMP1, d); + store_reg_to_var_int(src, d); + } + src = src->prev; + } + } else { +#endif + while (src != NULL) { + len--; + if ((len == 0) && (bptr->type != BBTYPE_STD)) { + d = reg_of_var(rd, src, REG_ITMP1); + M_INTMOVE(REG_ITMP1, d); + store_reg_to_var_int(src, d); + } else { + d = reg_of_var(rd, src, REG_IFTMP); + if ((src->varkind != STACKVAR)) { + s2 = src->type; + if (IS_FLT_DBL_TYPE(s2)) { + if (!(rd->interfaces[len][s2].flags & INMEMORY)) { + s1 = rd->interfaces[len][s2].regoff; + M_FLTMOVE(s1, d); + } else { + M_DLD(d, REG_SP, rd->interfaces[len][s2].regoff * 8); } - store_reg_to_var_flt(src, d); + store_reg_to_var_flt(src, d); } - else { - if (!(interfaces[len][s2].flags & INMEMORY)) { - s1 = interfaces[len][s2].regoff; - M_INTMOVE(s1,d); - } else { - M_LLD(d, REG_SP, 8 * interfaces[len][s2].regoff); + if (!(rd->interfaces[len][s2].flags & INMEMORY)) { + s1 = rd->interfaces[len][s2].regoff; + M_INTMOVE(s1, d); + } else { + M_LLD(d, REG_SP, rd->interfaces[len][s2].regoff * 8); } - store_reg_to_var_int(src, d); + store_reg_to_var_int(src, d); } } } - src = src->prev; + src = src->prev; } +#ifdef LSRA + } +#endif /* walk through all instructions */ src = bptr->instack; len = bptr->icount; - for (iptr = bptr->iinstr; - len > 0; - src = iptr->dst, len--, iptr++) { - MCODECHECK(64); /* an instruction usually needs < 64 words */ - switch (iptr->opc) { + for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) { + if (iptr->line != currentline) { + dseg_addlinenumber(cd, iptr->line, (u1 *) mcodeptr); + currentline = iptr->line; + } + + MCODECHECK(64); /* an instruction usually needs < 64 words */ + switch (iptr->opc) { + + case ICMD_INLINE_START: + case ICMD_INLINE_END: + break; case ICMD_NOP: /* ... ==> ... */ break; - case ICMD_NULLCHECKPOP: /* ..., objectref ==> ... */ + case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */ var_to_reg_int(s1, src, REG_ITMP1); M_BEQZ(s1, 0); - codegen_addxnullrefs(mcodeptr); + codegen_addxnullrefs(cd, mcodeptr); break; /* constant operations ************************************************/ -#define ICONST(r,c) if(((c)>=-32768)&&((c)<= 32767)){M_LDA(r,REG_ZERO,c);} \ - else{a=dseg_adds4(c);M_ILD(r,REG_PV,a);} - -#define LCONST(r,c) if(((c)>=-32768)&&((c)<= 32767)){M_LDA(r,REG_ZERO,c);} \ - else{a=dseg_adds8(c);M_LLD(r,REG_PV,a);} - case ICMD_ICONST: /* ... ==> ..., constant */ /* op1 = 0, val.i = constant */ - d = reg_of_var(iptr->dst, REG_ITMP1); + d = reg_of_var(rd, iptr->dst, REG_ITMP1); ICONST(d, iptr->val.i); store_reg_to_var_int(iptr->dst, d); break; @@ -763,7 +479,7 @@ void codegen() case ICMD_LCONST: /* ... ==> ..., constant */ /* op1 = 0, val.l = constant */ - d = reg_of_var(iptr->dst, REG_ITMP1); + d = reg_of_var(rd, iptr->dst, REG_ITMP1); LCONST(d, iptr->val.l); store_reg_to_var_int(iptr->dst, d); break; @@ -771,32 +487,31 @@ void codegen() case ICMD_FCONST: /* ... ==> ..., constant */ /* op1 = 0, val.f = constant */ - d = reg_of_var(iptr->dst, REG_FTMP1); - a = dseg_addfloat(iptr->val.f); - M_FLD(d, REG_PV, a); + d = reg_of_var(rd, iptr->dst, REG_FTMP1); + disp = dseg_addfloat(cd, iptr->val.f); + M_FLD(d, REG_PV, disp); store_reg_to_var_flt(iptr->dst, d); break; case ICMD_DCONST: /* ... ==> ..., constant */ /* op1 = 0, val.d = constant */ - d = reg_of_var(iptr->dst, REG_FTMP1); - a = dseg_adddouble(iptr->val.d); - M_DLD(d, REG_PV, a); + d = reg_of_var(rd, iptr->dst, REG_FTMP1); + disp = dseg_adddouble(cd, iptr->val.d); + M_DLD(d, REG_PV, disp); store_reg_to_var_flt(iptr->dst, d); break; case ICMD_ACONST: /* ... ==> ..., constant */ /* op1 = 0, val.a = constant */ - d = reg_of_var(iptr->dst, REG_ITMP1); + d = reg_of_var(rd, iptr->dst, REG_ITMP1); if (iptr->val.a) { - a = dseg_addaddress (iptr->val.a); - M_ALD(d, REG_PV, a); - } - else { + disp = dseg_addaddress(cd, iptr->val.a); + M_ALD(d, REG_PV, disp); + } else { M_INTMOVE(REG_ZERO, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -807,30 +522,32 @@ void codegen() case ICMD_LLOAD: /* op1 = local variable */ case ICMD_ALOAD: - d = reg_of_var(iptr->dst, REG_ITMP1); + d = reg_of_var(rd, iptr->dst, REG_ITMP1); if ((iptr->dst->varkind == LOCALVAR) && (iptr->dst->varnum == iptr->op1)) break; - var = &(locals[iptr->op1][iptr->opc - ICMD_ILOAD]); - if (var->flags & INMEMORY) - M_LLD(d, REG_SP, 8 * var->regoff); - else - {M_INTMOVE(var->regoff,d);} + var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]); + if (var->flags & INMEMORY) { + M_LLD(d, REG_SP, var->regoff * 8); + } else { + M_INTMOVE(var->regoff, d); + } store_reg_to_var_int(iptr->dst, d); break; case ICMD_FLOAD: /* ... ==> ..., content of local variable */ case ICMD_DLOAD: /* op1 = local variable */ - d = reg_of_var(iptr->dst, REG_FTMP1); + d = reg_of_var(rd, iptr->dst, REG_FTMP1); if ((iptr->dst->varkind == LOCALVAR) && (iptr->dst->varnum == iptr->op1)) break; - var = &(locals[iptr->op1][iptr->opc - ICMD_ILOAD]); - if (var->flags & INMEMORY) - M_DLD(d, REG_SP, 8 * var->regoff); - else - {M_FLTMOVE(var->regoff,d);} + var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]); + if (var->flags & INMEMORY) { + M_DLD(d, REG_SP, var->regoff * 8); + } else { + M_FLTMOVE(var->regoff, d); + } store_reg_to_var_flt(iptr->dst, d); break; @@ -842,15 +559,14 @@ void codegen() if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1)) break; - var = &(locals[iptr->op1][iptr->opc - ICMD_ISTORE]); + var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]); if (var->flags & INMEMORY) { var_to_reg_int(s1, src, REG_ITMP1); - M_LST(s1, REG_SP, 8 * var->regoff); - } - else { + M_LST(s1, REG_SP, var->regoff * 8); + } else { var_to_reg_int(s1, src, var->regoff); M_INTMOVE(s1, var->regoff); - } + } break; case ICMD_FSTORE: /* ..., value ==> ... */ @@ -859,15 +575,14 @@ void codegen() if ((src->varkind == LOCALVAR) && (src->varnum == iptr->op1)) break; - var = &(locals[iptr->op1][iptr->opc - ICMD_ISTORE]); + var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]); if (var->flags & INMEMORY) { var_to_reg_flt(s1, src, REG_FTMP1); - M_DST(s1, REG_SP, 8 * var->regoff); - } - else { + M_DST(s1, REG_SP, var->regoff * 8); + } else { var_to_reg_flt(s1, src, var->regoff); M_FLTMOVE(s1, var->regoff); - } + } break; @@ -879,29 +594,24 @@ void codegen() case ICMD_POP2: /* ..., value, value ==> ... */ break; -#define M_COPY(from,to) \ - d = reg_of_var(to, REG_IFTMP); \ - if ((from->regoff != to->regoff) || \ - ((from->flags ^ to->flags) & INMEMORY)) { \ - if (IS_FLT_DBL_TYPE(from->type)) { \ - var_to_reg_flt(s1, from, d); \ - M_FLTMOVE(s1,d); \ - store_reg_to_var_flt(to, d); \ - }\ - else { \ - var_to_reg_int(s1, from, d); \ - M_INTMOVE(s1,d); \ - store_reg_to_var_int(to, d); \ - }\ - } - case ICMD_DUP: /* ..., a ==> ..., a, a */ M_COPY(src, iptr->dst); break; case ICMD_DUP_X1: /* ..., a, b ==> ..., b, a, b */ - M_COPY(src, iptr->dst->prev->prev); + M_COPY(src, iptr->dst); + M_COPY(src->prev, iptr->dst->prev); + M_COPY(iptr->dst, iptr->dst->prev->prev); + break; + + case ICMD_DUP_X2: /* ..., a, b, c ==> ..., c, a, b, c */ + + M_COPY(src, iptr->dst); + M_COPY(src->prev, iptr->dst->prev); + M_COPY(src->prev->prev, iptr->dst->prev->prev); + M_COPY(iptr->dst, iptr->dst->prev->prev->prev); + break; case ICMD_DUP2: /* ..., a, b ==> ..., a, b, a, b */ @@ -911,14 +621,11 @@ void codegen() case ICMD_DUP2_X1: /* ..., a, b, c ==> ..., b, c, a, b, c */ - M_COPY(src->prev, iptr->dst->prev->prev->prev); - - case ICMD_DUP_X2: /* ..., a, b, c ==> ..., c, a, b, c */ - M_COPY(src, iptr->dst); M_COPY(src->prev, iptr->dst->prev); M_COPY(src->prev->prev, iptr->dst->prev->prev); - M_COPY(src, iptr->dst->prev->prev->prev); + M_COPY(iptr->dst, iptr->dst->prev->prev->prev); + M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev); break; case ICMD_DUP2_X2: /* ..., a, b, c, d ==> ..., c, d, a, b, c, d */ @@ -927,13 +634,13 @@ void codegen() M_COPY(src->prev, iptr->dst->prev); M_COPY(src->prev->prev, iptr->dst->prev->prev); M_COPY(src->prev->prev->prev, iptr->dst->prev->prev->prev); - M_COPY(src, iptr->dst->prev->prev->prev->prev); - M_COPY(src->prev, iptr->dst->prev->prev->prev->prev->prev); + M_COPY(iptr->dst, iptr->dst->prev->prev->prev->prev); + M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev->prev); break; case ICMD_SWAP: /* ..., a, b ==> ..., b, a */ - M_COPY(src, iptr->dst->prev); + M_COPY(src, iptr->dst->prev); M_COPY(src->prev, iptr->dst); break; @@ -943,7 +650,7 @@ void codegen() case ICMD_INEG: /* ..., value ==> ..., - value */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_ISUB(REG_ZERO, s1, d); store_reg_to_var_int(iptr->dst, d); break; @@ -951,7 +658,7 @@ void codegen() case ICMD_LNEG: /* ..., value ==> ..., - value */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_LSUB(REG_ZERO, s1, d); store_reg_to_var_int(iptr->dst, d); break; @@ -959,7 +666,7 @@ void codegen() case ICMD_I2L: /* ..., value ==> ..., value */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_INTMOVE(s1, d); store_reg_to_var_int(iptr->dst, d); break; @@ -967,29 +674,28 @@ void codegen() case ICMD_L2I: /* ..., value ==> ..., value */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); - M_IADD(s1, REG_ZERO, d ); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + M_IADD(s1, REG_ZERO, d); store_reg_to_var_int(iptr->dst, d); break; case ICMD_INT2BYTE: /* ..., value ==> ..., value */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if (has_ext_instr_set) { M_BSEXT(s1, d); - } - else { + } else { M_SLL_IMM(s1, 56, d); M_SRA_IMM( d, 56, d); - } + } store_reg_to_var_int(iptr->dst, d); break; case ICMD_INT2CHAR: /* ..., value ==> ..., value */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_CZEXT(s1, d); store_reg_to_var_int(iptr->dst, d); break; @@ -997,14 +703,13 @@ void codegen() case ICMD_INT2SHORT: /* ..., value ==> ..., value */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if (has_ext_instr_set) { M_SSEXT(s1, d); - } - else { + } else { M_SLL_IMM(s1, 48, d); M_SRA_IMM( d, 48, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1013,7 +718,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_IADD(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1022,14 +727,13 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) { M_IADD_IMM(s1, iptr->val.i, d); - } - else { + } else { ICONST(REG_ITMP2, iptr->val.i); M_IADD(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1037,7 +741,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_LADD(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1046,14 +750,13 @@ void codegen() /* val.l = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) { M_LADD_IMM(s1, iptr->val.l, d); - } - else { + } else { LCONST(REG_ITMP2, iptr->val.l); M_LADD(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1061,7 +764,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_ISUB(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1070,14 +773,13 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) { M_ISUB_IMM(s1, iptr->val.i, d); - } - else { + } else { ICONST(REG_ITMP2, iptr->val.i); M_ISUB(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1085,7 +787,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_LSUB(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1094,14 +796,13 @@ void codegen() /* val.l = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) { M_LSUB_IMM(s1, iptr->val.l, d); - } - else { + } else { LCONST(REG_ITMP2, iptr->val.l); M_LSUB(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1109,7 +810,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_IMUL(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1118,14 +819,13 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) { M_IMUL_IMM(s1, iptr->val.i, d); - } - else { + } else { ICONST(REG_ITMP2, iptr->val.i); M_IMUL(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1133,8 +833,8 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); - M_LMUL (s1, s2, d); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + M_LMUL(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1142,14 +842,57 @@ void codegen() /* val.l = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) { M_LMUL_IMM(s1, iptr->val.l, d); - } - else { + } else { LCONST(REG_ITMP2, iptr->val.l); M_LMUL(s1, REG_ITMP2, d); - } + } + store_reg_to_var_int(iptr->dst, d); + break; + + case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */ + case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */ + + var_to_reg_int(s1, src->prev, REG_ITMP1); + var_to_reg_int(s2, src, REG_ITMP2); + d = reg_of_var(rd, iptr->dst, REG_RESULT); + M_BEQZ(s2, 0); + codegen_addxdivrefs(cd, mcodeptr); + + M_MOV(s1, rd->argintregs[0]); + M_MOV(s2, rd->argintregs[1]); + bte = iptr->val.a; + disp = dseg_addaddress(cd, bte->fp); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + + M_IADD(REG_RESULT, REG_ZERO, d); /* sign extend (bugfix for gcc -O2) */ + store_reg_to_var_int(iptr->dst, d); + break; + + case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */ + case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */ + + var_to_reg_int(s1, src->prev, REG_ITMP1); + var_to_reg_int(s2, src, REG_ITMP2); + d = reg_of_var(rd, iptr->dst, REG_RESULT); + M_BEQZ(s2, 0); + codegen_addxdivrefs(cd, mcodeptr); + + M_MOV(s1, rd->argintregs[0]); + M_MOV(s2, rd->argintregs[1]); + bte = iptr->val.a; + disp = dseg_addaddress(cd, bte->fp); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + + M_INTMOVE(REG_RESULT, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1157,16 +900,15 @@ void codegen() case ICMD_LDIVPOW2: /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if (iptr->val.i <= 15) { M_LDA(REG_ITMP2, s1, (1 << iptr->val.i) -1); M_CMOVGE(s1, s1, REG_ITMP2); - } - else { + } else { M_SRA_IMM(s1, 63, REG_ITMP2); M_SRL_IMM(REG_ITMP2, 64 - iptr->val.i, REG_ITMP2); M_LADD(s1, REG_ITMP2, REG_ITMP2); - } + } M_SRA_IMM(REG_ITMP2, iptr->val.i, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1175,7 +917,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_AND_IMM(s2, 0x1f, REG_ITMP3); M_SLL(s1, REG_ITMP3, d); M_IADD(d, REG_ZERO, d); @@ -1186,7 +928,7 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_SLL_IMM(s1, iptr->val.i & 0x1f, d); M_IADD(d, REG_ZERO, d); store_reg_to_var_int(iptr->dst, d); @@ -1196,7 +938,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_AND_IMM(s2, 0x1f, REG_ITMP3); M_SRA(s1, REG_ITMP3, d); store_reg_to_var_int(iptr->dst, d); @@ -1206,7 +948,7 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_SRA_IMM(s1, iptr->val.i & 0x1f, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1215,7 +957,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_AND_IMM(s2, 0x1f, REG_ITMP2); M_IZEXT(s1, d); M_SRL(d, REG_ITMP2, d); @@ -1227,7 +969,7 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_IZEXT(s1, d); M_SRL_IMM(d, iptr->val.i & 0x1f, d); M_IADD(d, REG_ZERO, d); @@ -1238,7 +980,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_SLL(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1247,7 +989,7 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_SLL_IMM(s1, iptr->val.i & 0x3f, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1256,7 +998,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_SRA(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1265,7 +1007,7 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_SRA_IMM(s1, iptr->val.i & 0x3f, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1274,7 +1016,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_SRL(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1283,7 +1025,7 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_SRL_IMM(s1, iptr->val.i & 0x3f, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1293,7 +1035,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_AND(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1302,20 +1044,17 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) { M_AND_IMM(s1, iptr->val.i, d); - } - else if (iptr->val.i == 0xffff) { + } else if (iptr->val.i == 0xffff) { M_CZEXT(s1, d); - } - else if (iptr->val.i == 0xffffff) { + } else if (iptr->val.i == 0xffffff) { M_ZAPNOT_IMM(s1, 0x07, d); - } - else { + } else { ICONST(REG_ITMP2, iptr->val.i); M_AND(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1323,74 +1062,34 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if (s1 == d) { M_MOV(s1, REG_ITMP1); s1 = REG_ITMP1; - } + } if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) { M_AND_IMM(s1, iptr->val.i, d); M_BGEZ(s1, 3); M_ISUB(REG_ZERO, s1, d); M_AND_IMM(d, iptr->val.i, d); - } - else if (iptr->val.i == 0xffff) { + } else if (iptr->val.i == 0xffff) { M_CZEXT(s1, d); M_BGEZ(s1, 3); M_ISUB(REG_ZERO, s1, d); M_CZEXT(d, d); - } - else if (iptr->val.i == 0xffffff) { + } else if (iptr->val.i == 0xffffff) { M_ZAPNOT_IMM(s1, 0x07, d); M_BGEZ(s1, 3); M_ISUB(REG_ZERO, s1, d); M_ZAPNOT_IMM(d, 0x07, d); - } - else { + } else { ICONST(REG_ITMP2, iptr->val.i); M_AND(s1, REG_ITMP2, d); M_BGEZ(s1, 3); M_ISUB(REG_ZERO, s1, d); M_AND(d, REG_ITMP2, d); - } - M_ISUB(REG_ZERO, d, d); - store_reg_to_var_int(iptr->dst, d); - break; - - case ICMD_IREM0X10001: /* ..., value ==> ..., value % 0x100001 */ - -/* b = value & 0xffff; - a = value >> 16; - a = ((b - a) & 0xffff) + (b < a); -*/ - var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); - if (s1 == d) { - M_MOV(s1, REG_ITMP3); - s1 = REG_ITMP3; - } - M_BLTZ(s1, 7); - M_CZEXT(s1, REG_ITMP2); - M_SRA_IMM(s1, 16, d); - M_CMPLT(REG_ITMP2, d, REG_ITMP1); - M_ISUB(REG_ITMP2, d, d); - M_CZEXT(d, d); - M_IADD(d, REG_ITMP1, d); - M_BR(11 + (s1 == REG_ITMP1)); - M_ISUB(REG_ZERO, s1, REG_ITMP1); - M_CZEXT(REG_ITMP1, REG_ITMP2); - M_SRA_IMM(REG_ITMP1, 16, d); - M_CMPLT(REG_ITMP2, d, REG_ITMP1); - M_ISUB(REG_ITMP2, d, d); - M_CZEXT(d, d); - M_IADD(d, REG_ITMP1, d); + } M_ISUB(REG_ZERO, d, d); - if (s1 == REG_ITMP1) { - var_to_reg_int(s1, src, REG_ITMP1); - } - M_SLL_IMM(s1, 33, REG_ITMP2); - M_CMPEQ(REG_ITMP2, REG_ZERO, REG_ITMP2); - M_ISUB(d, REG_ITMP2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1398,32 +1097,25 @@ void codegen() /* val.l = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) { M_AND_IMM(s1, iptr->val.l, d); - } - else if (iptr->val.l == 0xffffL) { + } else if (iptr->val.l == 0xffffL) { M_CZEXT(s1, d); - } - else if (iptr->val.l == 0xffffffL) { + } else if (iptr->val.l == 0xffffffL) { M_ZAPNOT_IMM(s1, 0x07, d); - } - else if (iptr->val.l == 0xffffffffL) { + } else if (iptr->val.l == 0xffffffffL) { M_IZEXT(s1, d); - } - else if (iptr->val.l == 0xffffffffffL) { + } else if (iptr->val.l == 0xffffffffffL) { M_ZAPNOT_IMM(s1, 0x1f, d); - } - else if (iptr->val.l == 0xffffffffffffL) { + } else if (iptr->val.l == 0xffffffffffffL) { M_ZAPNOT_IMM(s1, 0x3f, d); - } - else if (iptr->val.l == 0xffffffffffffffL) { + } else if (iptr->val.l == 0xffffffffffffffL) { M_ZAPNOT_IMM(s1, 0x7f, d); - } - else { + } else { LCONST(REG_ITMP2, iptr->val.l); M_AND(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1431,105 +1123,63 @@ void codegen() /* val.l = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if (s1 == d) { M_MOV(s1, REG_ITMP1); s1 = REG_ITMP1; - } + } if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) { M_AND_IMM(s1, iptr->val.l, d); M_BGEZ(s1, 3); M_LSUB(REG_ZERO, s1, d); M_AND_IMM(d, iptr->val.l, d); - } - else if (iptr->val.l == 0xffffL) { + } else if (iptr->val.l == 0xffffL) { M_CZEXT(s1, d); M_BGEZ(s1, 3); M_LSUB(REG_ZERO, s1, d); M_CZEXT(d, d); - } - else if (iptr->val.l == 0xffffffL) { + } else if (iptr->val.l == 0xffffffL) { M_ZAPNOT_IMM(s1, 0x07, d); M_BGEZ(s1, 3); M_LSUB(REG_ZERO, s1, d); M_ZAPNOT_IMM(d, 0x07, d); - } - else if (iptr->val.l == 0xffffffffL) { + } else if (iptr->val.l == 0xffffffffL) { M_IZEXT(s1, d); M_BGEZ(s1, 3); M_LSUB(REG_ZERO, s1, d); M_IZEXT(d, d); - } - else if (iptr->val.l == 0xffffffffffL) { + } else if (iptr->val.l == 0xffffffffffL) { M_ZAPNOT_IMM(s1, 0x1f, d); M_BGEZ(s1, 3); M_LSUB(REG_ZERO, s1, d); M_ZAPNOT_IMM(d, 0x1f, d); - } - else if (iptr->val.l == 0xffffffffffffL) { + } else if (iptr->val.l == 0xffffffffffffL) { M_ZAPNOT_IMM(s1, 0x3f, d); M_BGEZ(s1, 3); M_LSUB(REG_ZERO, s1, d); M_ZAPNOT_IMM(d, 0x3f, d); - } - else if (iptr->val.l == 0xffffffffffffffL) { + } else if (iptr->val.l == 0xffffffffffffffL) { M_ZAPNOT_IMM(s1, 0x7f, d); M_BGEZ(s1, 3); M_LSUB(REG_ZERO, s1, d); M_ZAPNOT_IMM(d, 0x7f, d); - } - else { + } else { LCONST(REG_ITMP2, iptr->val.l); M_AND(s1, REG_ITMP2, d); M_BGEZ(s1, 3); M_LSUB(REG_ZERO, s1, d); M_AND(d, REG_ITMP2, d); - } + } M_LSUB(REG_ZERO, d, d); store_reg_to_var_int(iptr->dst, d); break; - case ICMD_LREM0X10001:/* ..., value ==> ..., value % 0x10001 */ - - var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); - if (s1 == d) { - M_MOV(s1, REG_ITMP3); - s1 = REG_ITMP3; - } - M_CZEXT(s1, REG_ITMP2); - M_SRA_IMM(s1, 16, d); - M_CMPLT(REG_ITMP2, d, REG_ITMP1); - M_LSUB(REG_ITMP2, d, d); - M_CZEXT(d, d); - M_LADD(d, REG_ITMP1, d); - M_LDA(REG_ITMP2, REG_ZERO, -1); - M_SRL_IMM(REG_ITMP2, 33, REG_ITMP2); - if (s1 == REG_ITMP1) { - var_to_reg_int(s1, src, REG_ITMP1); - } - M_CMPULT(s1, REG_ITMP2, REG_ITMP2); - M_BNEZ(REG_ITMP2, 11); - M_LDA(d, REG_ZERO, -257); - M_ZAPNOT_IMM(d, 0xcd, d); - M_LSUB(REG_ZERO, s1, REG_ITMP2); - M_CMOVGE(s1, s1, REG_ITMP2); - M_UMULH(REG_ITMP2, d, REG_ITMP2); - M_SRL_IMM(REG_ITMP2, 16, REG_ITMP2); - M_LSUB(REG_ZERO, REG_ITMP2, d); - M_CMOVGE(s1, REG_ITMP2, d); - M_SLL_IMM(d, 16, REG_ITMP2); - M_LADD(d, REG_ITMP2, d); - M_LSUB(s1, d, d); - store_reg_to_var_int(iptr->dst, d); - break; - case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */ case ICMD_LOR: var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_OR( s1,s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1538,14 +1188,13 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) { M_OR_IMM(s1, iptr->val.i, d); - } - else { + } else { ICONST(REG_ITMP2, iptr->val.i); M_OR(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1553,14 +1202,13 @@ void codegen() /* val.l = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) { M_OR_IMM(s1, iptr->val.l, d); - } - else { + } else { LCONST(REG_ITMP2, iptr->val.l); M_OR(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1569,7 +1217,7 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_XOR(s1, s2, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1578,14 +1226,13 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) { M_XOR_IMM(s1, iptr->val.i, d); - } - else { + } else { ICONST(REG_ITMP2, iptr->val.i); M_XOR(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1593,14 +1240,13 @@ void codegen() /* val.l = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) { M_XOR_IMM(s1, iptr->val.l, d); - } - else { + } else { LCONST(REG_ITMP2, iptr->val.l); M_XOR(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1609,10 +1255,10 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); M_CMPLT(s1, s2, REG_ITMP3); M_CMPLT(s2, s1, REG_ITMP1); - M_LSUB (REG_ITMP1, REG_ITMP3, d); + M_LSUB(REG_ITMP1, REG_ITMP3, d); store_reg_to_var_int(iptr->dst, d); break; @@ -1620,25 +1266,22 @@ void codegen() case ICMD_IINC: /* ..., value ==> ..., value + constant */ /* op1 = variable, val.i = constant */ - var = &(locals[iptr->op1][TYPE_INT]); + var = &(rd->locals[iptr->op1][TYPE_INT]); if (var->flags & INMEMORY) { s1 = REG_ITMP1; - M_LLD(s1, REG_SP, 8 * var->regoff); - } - else + M_LLD(s1, REG_SP, var->regoff * 8); + } else s1 = var->regoff; if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) { M_IADD_IMM(s1, iptr->val.i, s1); - } - else if ((iptr->val.i > -256) && (iptr->val.i < 0)) { + } else if ((iptr->val.i > -256) && (iptr->val.i < 0)) { M_ISUB_IMM(s1, (-iptr->val.i), s1); - } - else { + } else { M_LDA (s1, s1, iptr->val.i); M_IADD(s1, REG_ZERO, s1); - } + } if (var->flags & INMEMORY) - M_LST(s1, REG_SP, 8 * var->regoff); + M_LST(s1, REG_SP, var->regoff * 8); break; @@ -1647,7 +1290,7 @@ void codegen() case ICMD_FNEG: /* ..., value ==> ..., - value */ var_to_reg_flt(s1, src, REG_FTMP1); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP2); M_FMOVN(s1, d); store_reg_to_var_flt(iptr->dst, d); break; @@ -1655,7 +1298,7 @@ void codegen() case ICMD_DNEG: /* ..., value ==> ..., - value */ var_to_reg_flt(s1, src, REG_FTMP1); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP2); M_FMOVN(s1, d); store_reg_to_var_flt(iptr->dst, d); break; @@ -1664,21 +1307,19 @@ void codegen() var_to_reg_flt(s1, src->prev, REG_FTMP1); var_to_reg_flt(s2, src, REG_FTMP2); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); if (opt_noieee) { M_FADD(s1, s2, d); - } - else { + } else { if (d == s1 || d == s2) { M_FADDS(s1, s2, REG_FTMP3); M_TRAPB; M_FMOV(REG_FTMP3, d); - } - else { + } else { M_FADDS(s1, s2, d); M_TRAPB; - } } + } store_reg_to_var_flt(iptr->dst, d); break; @@ -1686,21 +1327,19 @@ void codegen() var_to_reg_flt(s1, src->prev, REG_FTMP1); var_to_reg_flt(s2, src, REG_FTMP2); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); if (opt_noieee) { M_DADD(s1, s2, d); - } - else { + } else { if (d == s1 || d == s2) { M_DADDS(s1, s2, REG_FTMP3); M_TRAPB; M_FMOV(REG_FTMP3, d); - } - else { + } else { M_DADDS(s1, s2, d); M_TRAPB; - } } + } store_reg_to_var_flt(iptr->dst, d); break; @@ -1708,21 +1347,19 @@ void codegen() var_to_reg_flt(s1, src->prev, REG_FTMP1); var_to_reg_flt(s2, src, REG_FTMP2); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); if (opt_noieee) { M_FSUB(s1, s2, d); - } - else { + } else { if (d == s1 || d == s2) { M_FSUBS(s1, s2, REG_FTMP3); M_TRAPB; M_FMOV(REG_FTMP3, d); - } - else { + } else { M_FSUBS(s1, s2, d); M_TRAPB; - } } + } store_reg_to_var_flt(iptr->dst, d); break; @@ -1730,21 +1367,19 @@ void codegen() var_to_reg_flt(s1, src->prev, REG_FTMP1); var_to_reg_flt(s2, src, REG_FTMP2); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); if (opt_noieee) { M_DSUB(s1, s2, d); - } - else { + } else { if (d == s1 || d == s2) { M_DSUBS(s1, s2, REG_FTMP3); M_TRAPB; M_FMOV(REG_FTMP3, d); - } - else { + } else { M_DSUBS(s1, s2, d); M_TRAPB; - } } + } store_reg_to_var_flt(iptr->dst, d); break; @@ -1752,43 +1387,39 @@ void codegen() var_to_reg_flt(s1, src->prev, REG_FTMP1); var_to_reg_flt(s2, src, REG_FTMP2); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); if (opt_noieee) { M_FMUL(s1, s2, d); - } - else { + } else { if (d == s1 || d == s2) { M_FMULS(s1, s2, REG_FTMP3); M_TRAPB; M_FMOV(REG_FTMP3, d); - } - else { + } else { M_FMULS(s1, s2, d); M_TRAPB; - } } + } store_reg_to_var_flt(iptr->dst, d); break; - case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 *** val2 */ + case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 *** val2 */ var_to_reg_flt(s1, src->prev, REG_FTMP1); var_to_reg_flt(s2, src, REG_FTMP2); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); if (opt_noieee) { M_DMUL(s1, s2, d); - } - else { + } else { if (d == s1 || d == s2) { M_DMULS(s1, s2, REG_FTMP3); M_TRAPB; M_FMOV(REG_FTMP3, d); - } - else { + } else { M_DMULS(s1, s2, d); M_TRAPB; - } } + } store_reg_to_var_flt(iptr->dst, d); break; @@ -1796,21 +1427,19 @@ void codegen() var_to_reg_flt(s1, src->prev, REG_FTMP1); var_to_reg_flt(s2, src, REG_FTMP2); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); if (opt_noieee) { M_FDIV(s1, s2, d); - } - else { + } else { if (d == s1 || d == s2) { M_FDIVS(s1, s2, REG_FTMP3); M_TRAPB; M_FMOV(REG_FTMP3, d); - } - else { + } else { M_FDIVS(s1, s2, d); M_TRAPB; - } } + } store_reg_to_var_flt(iptr->dst, d); break; @@ -1818,31 +1447,29 @@ void codegen() var_to_reg_flt(s1, src->prev, REG_FTMP1); var_to_reg_flt(s2, src, REG_FTMP2); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); if (opt_noieee) { M_DDIV(s1, s2, d); - } - else { + } else { if (d == s1 || d == s2) { M_DDIVS(s1, s2, REG_FTMP3); M_TRAPB; M_FMOV(REG_FTMP3, d); - } - else { + } else { M_DDIVS(s1, s2, d); M_TRAPB; - } } + } store_reg_to_var_flt(iptr->dst, d); break; case ICMD_I2F: /* ..., value ==> ..., (float) value */ case ICMD_L2F: var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_FTMP3); - a = dseg_adddouble(0.0); - M_LST (s1, REG_PV, a); - M_DLD (d, REG_PV, a); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); + disp = dseg_adddouble(cd, 0.0); + M_LST(s1, REG_PV, disp); + M_DLD(d, REG_PV, disp); M_CVTLF(d, d); store_reg_to_var_flt(iptr->dst, d); break; @@ -1850,10 +1477,10 @@ void codegen() case ICMD_I2D: /* ..., value ==> ..., (double) value */ case ICMD_L2D: var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_FTMP3); - a = dseg_adddouble(0.0); - M_LST (s1, REG_PV, a); - M_DLD (d, REG_PV, a); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); + disp = dseg_adddouble(cd, 0.0); + M_LST(s1, REG_PV, disp); + M_DLD(d, REG_PV, disp); M_CVTLD(d, d); store_reg_to_var_flt(iptr->dst, d); break; @@ -1861,30 +1488,30 @@ void codegen() case ICMD_F2I: /* ..., value ==> ..., (int) value */ case ICMD_D2I: var_to_reg_flt(s1, src, REG_FTMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); - a = dseg_adddouble(0.0); + d = reg_of_var(rd, iptr->dst, REG_ITMP3); + disp = dseg_adddouble(cd, 0.0); M_CVTDL_C(s1, REG_FTMP2); M_CVTLI(REG_FTMP2, REG_FTMP3); - M_DST (REG_FTMP3, REG_PV, a); - M_ILD (d, REG_PV, a); + M_DST(REG_FTMP3, REG_PV, disp); + M_ILD(d, REG_PV, disp); store_reg_to_var_int(iptr->dst, d); break; case ICMD_F2L: /* ..., value ==> ..., (long) value */ case ICMD_D2L: var_to_reg_flt(s1, src, REG_FTMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); - a = dseg_adddouble(0.0); + d = reg_of_var(rd, iptr->dst, REG_ITMP3); + disp = dseg_adddouble(cd, 0.0); M_CVTDL_C(s1, REG_FTMP2); - M_DST (REG_FTMP2, REG_PV, a); - M_LLD (d, REG_PV, a); + M_DST(REG_FTMP2, REG_PV, disp); + M_LLD(d, REG_PV, disp); store_reg_to_var_int(iptr->dst, d); break; case ICMD_F2D: /* ..., value ==> ..., (double) value */ var_to_reg_flt(s1, src, REG_FTMP1); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); M_CVTFDS(s1, d); M_TRAPB; store_reg_to_var_flt(iptr->dst, d); @@ -1893,14 +1520,13 @@ void codegen() case ICMD_D2F: /* ..., value ==> ..., (float) value */ var_to_reg_flt(s1, src, REG_FTMP1); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP3); if (opt_noieee) { M_CVTDF(s1, d); - } - else { + } else { M_CVTDFS(s1, d); M_TRAPB; - } + } store_reg_to_var_flt(iptr->dst, d); break; @@ -1908,7 +1534,7 @@ void codegen() case ICMD_DCMPL: var_to_reg_flt(s1, src->prev, REG_FTMP1); var_to_reg_flt(s2, src, REG_FTMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP3); if (opt_noieee) { M_LSUB_IMM(REG_ZERO, 1, d); M_FCMPEQ(s1, s2, REG_FTMP3); @@ -1917,8 +1543,7 @@ void codegen() M_FCMPLT(s2, s1, REG_FTMP3); M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ M_LADD_IMM(REG_ZERO, 1, d); - } - else { + } else { M_LSUB_IMM(REG_ZERO, 1, d); M_FCMPEQS(s1, s2, REG_FTMP3); M_TRAPB; @@ -1928,7 +1553,7 @@ void codegen() M_TRAPB; M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ M_LADD_IMM(REG_ZERO, 1, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -1936,7 +1561,7 @@ void codegen() case ICMD_DCMPG: var_to_reg_flt(s1, src->prev, REG_FTMP1); var_to_reg_flt(s2, src, REG_FTMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP3); if (opt_noieee) { M_LADD_IMM(REG_ZERO, 1, d); M_FCMPEQ(s1, s2, REG_FTMP3); @@ -1945,8 +1570,7 @@ void codegen() M_FCMPLT(s1, s2, REG_FTMP3); M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ M_LSUB_IMM(REG_ZERO, 1, d); - } - else { + } else { M_LADD_IMM(REG_ZERO, 1, d); M_FCMPEQS(s1, s2, REG_FTMP3); M_TRAPB; @@ -1956,91 +1580,130 @@ void codegen() M_TRAPB; M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ M_LSUB_IMM(REG_ZERO, 1, d); - } + } store_reg_to_var_int(iptr->dst, d); break; /* memory operations **************************************************/ - /* #define gen_bound_check \ - if (checkbounds) {\ - M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\ - M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\ - M_BEQZ(REG_ITMP3, 0);\ - codegen_addxboundrefs(mcodeptr);\ - } - */ - -#define gen_bound_check \ - if (checkbounds) { \ - M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\ - M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\ - M_BEQZ(REG_ITMP3, 0);\ - codegen_addxboundrefs(mcodeptr, s2); \ - } - case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); gen_nullptr_check(s1); M_ILD(d, s1, OFFSET(java_arrayheader, size)); store_reg_to_var_int(iptr->dst, d); break; - case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */ + case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */ var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } - M_SAADDQ(s2, s1, REG_ITMP1); - M_ALD( d, REG_ITMP1, OFFSET(java_objectarray, data[0])); + } + if (has_ext_instr_set) { + M_LADD (s2, s1, REG_ITMP1); + M_BLDU (d, REG_ITMP1, OFFSET (java_bytearray, data[0])); + M_BSEXT (d, d); + } else { + M_LADD(s2, s1, REG_ITMP1); + M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0])); + M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])+1); + M_EXTQH(REG_ITMP2, REG_ITMP1, d); + M_SRA_IMM(d, 56, d); + } store_reg_to_var_int(iptr->dst, d); break; - case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */ + case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */ var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } - M_S8ADDQ(s2, s1, REG_ITMP1); - M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0])); + } + if (has_ext_instr_set) { + M_LADD(s2, s1, REG_ITMP1); + M_LADD(s2, REG_ITMP1, REG_ITMP1); + M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0])); + } else { + M_LADD (s2, s1, REG_ITMP1); + M_LADD (s2, REG_ITMP1, REG_ITMP1); + M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0])); + M_LDA (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0])); + M_EXTWL(REG_ITMP2, REG_ITMP1, d); + } store_reg_to_var_int(iptr->dst, d); - break; + break; - case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */ + case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */ var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } - - M_S4ADDQ(s2, s1, REG_ITMP1); - M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0])); - store_reg_to_var_int(iptr->dst, d); + } + if (has_ext_instr_set) { + M_LADD(s2, s1, REG_ITMP1); + M_LADD(s2, REG_ITMP1, REG_ITMP1); + M_SLDU( d, REG_ITMP1, OFFSET (java_shortarray, data[0])); + M_SSEXT(d, d); + } else { + M_LADD(s2, s1, REG_ITMP1); + M_LADD(s2, REG_ITMP1, REG_ITMP1); + M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0])); + M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])+2); + M_EXTQH(REG_ITMP2, REG_ITMP1, d); + M_SRA_IMM(d, 48, d); + } + store_reg_to_var_int(iptr->dst, d); + break; + + case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */ + + var_to_reg_int(s1, src->prev, REG_ITMP1); + var_to_reg_int(s2, src, REG_ITMP2); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + if (iptr->op1 == 0) { + gen_nullptr_check(s1); + gen_bound_check; + } + M_S4ADDQ(s2, s1, REG_ITMP1); + M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0])); + store_reg_to_var_int(iptr->dst, d); + break; + + case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */ + + var_to_reg_int(s1, src->prev, REG_ITMP1); + var_to_reg_int(s2, src, REG_ITMP2); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + if (iptr->op1 == 0) { + gen_nullptr_check(s1); + gen_bound_check; + } + M_S8ADDQ(s2, s1, REG_ITMP1); + M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0])); + store_reg_to_var_int(iptr->dst, d); break; case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */ var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } + } M_S4ADDQ(s2, s1, REG_ITMP1); M_FLD(d, REG_ITMP1, OFFSET(java_floatarray, data[0])); store_reg_to_var_flt(iptr->dst, d); @@ -2050,129 +1713,128 @@ void codegen() var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_FTMP3); + d = reg_of_var(rd, iptr->dst, REG_FTMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } + } M_S8ADDQ(s2, s1, REG_ITMP1); M_DLD(d, REG_ITMP1, OFFSET(java_doublearray, data[0])); store_reg_to_var_flt(iptr->dst, d); break; - case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */ + case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */ var_to_reg_int(s1, src->prev, REG_ITMP1); var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } - if (has_ext_instr_set) { - M_LADD(s2, s1, REG_ITMP1); - M_LADD(s2, REG_ITMP1, REG_ITMP1); - M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0])); - } - else { - M_LADD (s2, s1, REG_ITMP1); - M_LADD (s2, REG_ITMP1, REG_ITMP1); - M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0])); - M_LDA (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0])); - M_EXTWL(REG_ITMP2, REG_ITMP1, d); - } + } + M_SAADDQ(s2, s1, REG_ITMP1); + M_ALD(d, REG_ITMP1, OFFSET(java_objectarray, data[0])); store_reg_to_var_int(iptr->dst, d); - break; + break; - case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */ - var_to_reg_int(s1, src->prev, REG_ITMP1); - var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */ + + var_to_reg_int(s1, src->prev->prev, REG_ITMP1); + var_to_reg_int(s2, src->prev, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } + } + var_to_reg_int(s3, src, REG_ITMP3); if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); - M_LADD(s2, REG_ITMP1, REG_ITMP1); - M_SLDU( d, REG_ITMP1, OFFSET (java_shortarray, data[0])); - M_SSEXT(d, d); - } - else { + M_BST(s3, REG_ITMP1, OFFSET(java_bytearray, data[0])); + } else { M_LADD(s2, s1, REG_ITMP1); - M_LADD(s2, REG_ITMP1, REG_ITMP1); - M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0])); - M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])+2); - M_EXTQH(REG_ITMP2, REG_ITMP1, d); - M_SRA_IMM(d, 48, d); - } - store_reg_to_var_int(iptr->dst, d); + M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0])); + M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])); + M_INSBL(s3, REG_ITMP1, REG_ITMP3); + M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2); + M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2); + M_LST_U(REG_ITMP2, REG_ITMP1, 0); + } break; - case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */ + case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */ - var_to_reg_int(s1, src->prev, REG_ITMP1); - var_to_reg_int(s2, src, REG_ITMP2); - d = reg_of_var(iptr->dst, REG_ITMP3); + var_to_reg_int(s1, src->prev->prev, REG_ITMP1); + var_to_reg_int(s2, src->prev, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } + } + var_to_reg_int(s3, src, REG_ITMP3); if (has_ext_instr_set) { - M_LADD (s2, s1, REG_ITMP1); - M_BLDU (d, REG_ITMP1, OFFSET (java_bytearray, data[0])); - M_BSEXT (d, d); - } - else { M_LADD(s2, s1, REG_ITMP1); - M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0])); - M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])+1); - M_EXTQH(REG_ITMP2, REG_ITMP1, d); - M_SRA_IMM(d, 56, d); - } - store_reg_to_var_int(iptr->dst, d); + M_LADD(s2, REG_ITMP1, REG_ITMP1); + M_SST(s3, REG_ITMP1, OFFSET(java_chararray, data[0])); + } else { + M_LADD(s2, s1, REG_ITMP1); + M_LADD(s2, REG_ITMP1, REG_ITMP1); + M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0])); + M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0])); + M_INSWL(s3, REG_ITMP1, REG_ITMP3); + M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2); + M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2); + M_LST_U(REG_ITMP2, REG_ITMP1, 0); + } break; - - case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */ + case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */ var_to_reg_int(s1, src->prev->prev, REG_ITMP1); var_to_reg_int(s2, src->prev, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } + } var_to_reg_int(s3, src, REG_ITMP3); - M_SAADDQ(s2, s1, REG_ITMP1); - M_AST (s3, REG_ITMP1, OFFSET(java_objectarray, data[0])); + if (has_ext_instr_set) { + M_LADD(s2, s1, REG_ITMP1); + M_LADD(s2, REG_ITMP1, REG_ITMP1); + M_SST(s3, REG_ITMP1, OFFSET(java_shortarray, data[0])); + } else { + M_LADD(s2, s1, REG_ITMP1); + M_LADD(s2, REG_ITMP1, REG_ITMP1); + M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0])); + M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])); + M_INSWL(s3, REG_ITMP1, REG_ITMP3); + M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2); + M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2); + M_LST_U(REG_ITMP2, REG_ITMP1, 0); + } break; - case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */ + case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */ var_to_reg_int(s1, src->prev->prev, REG_ITMP1); var_to_reg_int(s2, src->prev, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } + } var_to_reg_int(s3, src, REG_ITMP3); - M_S8ADDQ(s2, s1, REG_ITMP1); - M_LST (s3, REG_ITMP1, OFFSET(java_longarray, data[0])); + M_S4ADDQ(s2, s1, REG_ITMP1); + M_IST(s3, REG_ITMP1, OFFSET(java_intarray, data[0])); break; - case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */ + case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */ var_to_reg_int(s1, src->prev->prev, REG_ITMP1); var_to_reg_int(s2, src->prev, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } - + } var_to_reg_int(s3, src, REG_ITMP3); - M_S4ADDQ(s2, s1, REG_ITMP1); - M_IST (s3, REG_ITMP1, OFFSET(java_intarray, data[0])); + M_S8ADDQ(s2, s1, REG_ITMP1); + M_LST(s3, REG_ITMP1, OFFSET(java_longarray, data[0])); break; case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */ @@ -2182,10 +1844,10 @@ void codegen() if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } + } var_to_reg_flt(s3, src, REG_FTMP3); M_S4ADDQ(s2, s1, REG_ITMP1); - M_FST (s3, REG_ITMP1, OFFSET(java_floatarray, data[0])); + M_FST(s3, REG_ITMP1, OFFSET(java_floatarray, data[0])); break; case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */ @@ -2195,295 +1857,456 @@ void codegen() if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } + } var_to_reg_flt(s3, src, REG_FTMP3); M_S8ADDQ(s2, s1, REG_ITMP1); - M_DST (s3, REG_ITMP1, OFFSET(java_doublearray, data[0])); + M_DST(s3, REG_ITMP1, OFFSET(java_doublearray, data[0])); break; - case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */ + case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */ var_to_reg_int(s1, src->prev->prev, REG_ITMP1); var_to_reg_int(s2, src->prev, REG_ITMP2); - if (iptr->op1 == 0) { +/* if (iptr->op1 == 0) { */ gen_nullptr_check(s1); gen_bound_check; - } +/* } */ var_to_reg_int(s3, src, REG_ITMP3); + + M_MOV(s1, rd->argintregs[0]); + M_MOV(s3, rd->argintregs[1]); + bte = iptr->val.a; + disp = dseg_addaddress(cd, bte->fp); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + + M_BEQZ(REG_RESULT, 0); + codegen_addxstorerefs(cd, mcodeptr); + + var_to_reg_int(s1, src->prev->prev, REG_ITMP1); + var_to_reg_int(s2, src->prev, REG_ITMP2); + var_to_reg_int(s3, src, REG_ITMP3); + M_SAADDQ(s2, s1, REG_ITMP1); + M_AST(s3, REG_ITMP1, OFFSET(java_objectarray, data[0])); + break; + + + case ICMD_IASTORECONST: /* ..., arrayref, index ==> ... */ + + var_to_reg_int(s1, src->prev, REG_ITMP1); + var_to_reg_int(s2, src, REG_ITMP2); + if (iptr->op1 == 0) { + gen_nullptr_check(s1); + gen_bound_check; + } + M_S4ADDQ(s2, s1, REG_ITMP1); + M_IST(REG_ZERO, REG_ITMP1, OFFSET(java_intarray, data[0])); + break; + + case ICMD_LASTORECONST: /* ..., arrayref, index ==> ... */ + + var_to_reg_int(s1, src->prev, REG_ITMP1); + var_to_reg_int(s2, src, REG_ITMP2); + if (iptr->op1 == 0) { + gen_nullptr_check(s1); + gen_bound_check; + } + M_S8ADDQ(s2, s1, REG_ITMP1); + M_LST(REG_ZERO, REG_ITMP1, OFFSET(java_longarray, data[0])); + break; + + case ICMD_AASTORECONST: /* ..., arrayref, index ==> ... */ + + var_to_reg_int(s1, src->prev, REG_ITMP1); + var_to_reg_int(s2, src, REG_ITMP2); + if (iptr->op1 == 0) { + gen_nullptr_check(s1); + gen_bound_check; + } + M_SAADDQ(s2, s1, REG_ITMP1); + M_AST(REG_ZERO, REG_ITMP1, OFFSET(java_objectarray, data[0])); + break; + + case ICMD_BASTORECONST: /* ..., arrayref, index ==> ... */ + + var_to_reg_int(s1, src->prev, REG_ITMP1); + var_to_reg_int(s2, src, REG_ITMP2); + if (iptr->op1 == 0) { + gen_nullptr_check(s1); + gen_bound_check; + } if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); - M_LADD(s2, REG_ITMP1, REG_ITMP1); - M_SST (s3, REG_ITMP1, OFFSET(java_chararray, data[0])); - } - else { - M_LADD (s2, s1, REG_ITMP1); - M_LADD (s2, REG_ITMP1, REG_ITMP1); - M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0])); - M_LDA (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0])); - M_INSWL(s3, REG_ITMP1, REG_ITMP3); - M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2); - M_OR (REG_ITMP2, REG_ITMP3, REG_ITMP2); + M_BST(REG_ZERO, REG_ITMP1, OFFSET(java_bytearray, data[0])); + + } else { + M_LADD(s2, s1, REG_ITMP1); + M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0])); + M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])); + M_INSBL(REG_ZERO, REG_ITMP1, REG_ITMP3); + M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2); + M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2); M_LST_U(REG_ITMP2, REG_ITMP1, 0); - } + } break; - case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */ + case ICMD_CASTORECONST: /* ..., arrayref, index ==> ... */ - var_to_reg_int(s1, src->prev->prev, REG_ITMP1); - var_to_reg_int(s2, src->prev, REG_ITMP2); + var_to_reg_int(s1, src->prev, REG_ITMP1); + var_to_reg_int(s2, src, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } - var_to_reg_int(s3, src, REG_ITMP3); + } if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); M_LADD(s2, REG_ITMP1, REG_ITMP1); - M_SST (s3, REG_ITMP1, OFFSET(java_shortarray, data[0])); - } - else { - M_LADD (s2, s1, REG_ITMP1); - M_LADD (s2, REG_ITMP1, REG_ITMP1); - M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0])); - M_LDA (REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])); - M_INSWL(s3, REG_ITMP1, REG_ITMP3); + M_SST(REG_ZERO, REG_ITMP1, OFFSET(java_chararray, data[0])); + + } else { + M_LADD(s2, s1, REG_ITMP1); + M_LADD(s2, REG_ITMP1, REG_ITMP1); + M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0])); + M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0])); + M_INSWL(REG_ZERO, REG_ITMP1, REG_ITMP3); M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2); - M_OR (REG_ITMP2, REG_ITMP3, REG_ITMP2); + M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2); M_LST_U(REG_ITMP2, REG_ITMP1, 0); - } + } break; - case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */ + case ICMD_SASTORECONST: /* ..., arrayref, index ==> ... */ - var_to_reg_int(s1, src->prev->prev, REG_ITMP1); - var_to_reg_int(s2, src->prev, REG_ITMP2); + var_to_reg_int(s1, src->prev, REG_ITMP1); + var_to_reg_int(s2, src, REG_ITMP2); if (iptr->op1 == 0) { gen_nullptr_check(s1); gen_bound_check; - } - var_to_reg_int(s3, src, REG_ITMP3); + } if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); - M_BST (s3, REG_ITMP1, OFFSET(java_bytearray, data[0])); - } - else { - M_LADD (s2, s1, REG_ITMP1); - M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0])); - M_LDA (REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])); - M_INSBL(s3, REG_ITMP1, REG_ITMP3); - M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2); - M_OR (REG_ITMP2, REG_ITMP3, REG_ITMP2); + M_LADD(s2, REG_ITMP1, REG_ITMP1); + M_SST(REG_ZERO, REG_ITMP1, OFFSET(java_shortarray, data[0])); + + } else { + M_LADD(s2, s1, REG_ITMP1); + M_LADD(s2, REG_ITMP1, REG_ITMP1); + M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0])); + M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])); + M_INSWL(REG_ZERO, REG_ITMP1, REG_ITMP3); + M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2); + M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2); M_LST_U(REG_ITMP2, REG_ITMP1, 0); - } + } break; - case ICMD_PUTSTATIC: /* ..., value ==> ... */ + case ICMD_GETSTATIC: /* ... ==> ..., value */ /* op1 = type, val.a = field address */ - /* if class isn't yet initialized, do it */ - if (!((fieldinfo *) iptr->val.a)->class->initialized) { - /* call helper function which patches this code */ - a = dseg_addaddress(((fieldinfo *) iptr->val.a)->class); - M_ALD(REG_ITMP1, REG_PV, a); - a = dseg_addaddress(asm_check_clinit); - M_ALD(REG_PV, REG_PV, a); - M_JSR(REG_RA, REG_PV); + if (!iptr->val.a) { + disp = dseg_addaddress(cd, 0); + + codegen_addpatchref(cd, mcodeptr, + PATCHER_get_putstatic, + (unresolved_field *) iptr->target, disp); - /* recompute pv */ - s1 = (int) ((u1*) mcodeptr - mcodebase); - if (s1 <= 32768) { - M_LDA(REG_PV, REG_RA, -s1); + if (opt_showdisassemble) M_NOP; - } else { - s4 ml = -s1, mh = 0; - while (ml < -32768) { ml += 65536; mh--; } - M_LDA(REG_PV, REG_RA, ml); - M_LDAH(REG_PV, REG_PV, mh); + + } else { + fieldinfo *fi = iptr->val.a; + + disp = dseg_addaddress(cd, &(fi->value)); + + if (!fi->class->initialized) { + codegen_addpatchref(cd, mcodeptr, + PATCHER_clinit, fi->class, 0); + + if (opt_showdisassemble) + M_NOP; } } - - a = dseg_addaddress(&(((fieldinfo *)(iptr->val.a))->value)); - M_ALD(REG_ITMP1, REG_PV, a); + + M_ALD(REG_ITMP1, REG_PV, disp); switch (iptr->op1) { - case TYPE_INT: - var_to_reg_int(s2, src, REG_ITMP2); - M_IST(s2, REG_ITMP1, 0); - break; - case TYPE_LNG: - var_to_reg_int(s2, src, REG_ITMP2); - M_LST(s2, REG_ITMP1, 0); - break; - case TYPE_ADR: - var_to_reg_int(s2, src, REG_ITMP2); - M_AST(s2, REG_ITMP1, 0); - break; - case TYPE_FLT: - var_to_reg_flt(s2, src, REG_FTMP2); - M_FST(s2, REG_ITMP1, 0); - break; - case TYPE_DBL: - var_to_reg_flt(s2, src, REG_FTMP2); - M_DST(s2, REG_ITMP1, 0); - break; - default: panic ("internal error"); - } + case TYPE_INT: + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + M_ILD(d, REG_ITMP1, 0); + store_reg_to_var_int(iptr->dst, d); + break; + case TYPE_LNG: + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + M_LLD(d, REG_ITMP1, 0); + store_reg_to_var_int(iptr->dst, d); + break; + case TYPE_ADR: + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + M_ALD(d, REG_ITMP1, 0); + store_reg_to_var_int(iptr->dst, d); + break; + case TYPE_FLT: + d = reg_of_var(rd, iptr->dst, REG_FTMP1); + M_FLD(d, REG_ITMP1, 0); + store_reg_to_var_flt(iptr->dst, d); + break; + case TYPE_DBL: + d = reg_of_var(rd, iptr->dst, REG_FTMP1); + M_DLD(d, REG_ITMP1, 0); + store_reg_to_var_flt(iptr->dst, d); + break; + } break; - case ICMD_GETSTATIC: /* ... ==> ..., value */ + case ICMD_PUTSTATIC: /* ..., value ==> ... */ /* op1 = type, val.a = field address */ - /* if class isn't yet initialized, do it */ - if (!((fieldinfo *) iptr->val.a)->class->initialized) { - /* call helper function which patches this code */ - a = dseg_addaddress(((fieldinfo *) iptr->val.a)->class); - M_ALD(REG_ITMP1, REG_PV, a); - a = dseg_addaddress(asm_check_clinit); - M_ALD(REG_PV, REG_PV, a); - M_JSR(REG_RA, REG_PV); + if (!iptr->val.a) { + disp = dseg_addaddress(cd, 0); - /* recompute pv */ - s1 = (int) ((u1*) mcodeptr - mcodebase); - if (s1 <= 32768) { - M_LDA(REG_PV, REG_RA, -s1); + codegen_addpatchref(cd, mcodeptr, + PATCHER_get_putstatic, + (unresolved_field *) iptr->target, disp); + + if (opt_showdisassemble) M_NOP; - } else { - s4 ml = -s1, mh = 0; - while (ml < -32768) { ml += 65536; mh--; } - M_LDA(REG_PV, REG_RA, ml); - M_LDAH(REG_PV, REG_PV, mh); + } else { + fieldinfo *fi = iptr->val.a; + + disp = dseg_addaddress(cd, &(fi->value)); + + if (!fi->class->initialized) { + codegen_addpatchref(cd, mcodeptr, + PATCHER_clinit, fi->class, 0); + + if (opt_showdisassemble) + M_NOP; } } - - a = dseg_addaddress (&(((fieldinfo *)(iptr->val.a))->value)); - M_ALD(REG_ITMP1, REG_PV, a); + + M_ALD(REG_ITMP1, REG_PV, disp); switch (iptr->op1) { - case TYPE_INT: - d = reg_of_var(iptr->dst, REG_ITMP3); - M_ILD(d, REG_ITMP1, 0); - store_reg_to_var_int(iptr->dst, d); - break; - case TYPE_LNG: - d = reg_of_var(iptr->dst, REG_ITMP3); - M_LLD(d, REG_ITMP1, 0); - store_reg_to_var_int(iptr->dst, d); - break; - case TYPE_ADR: - d = reg_of_var(iptr->dst, REG_ITMP3); - M_ALD(d, REG_ITMP1, 0); - store_reg_to_var_int(iptr->dst, d); - break; - case TYPE_FLT: - d = reg_of_var(iptr->dst, REG_FTMP1); - M_FLD(d, REG_ITMP1, 0); - store_reg_to_var_flt(iptr->dst, d); - break; - case TYPE_DBL: - d = reg_of_var(iptr->dst, REG_FTMP1); - M_DLD(d, REG_ITMP1, 0); - store_reg_to_var_flt(iptr->dst, d); - break; - default: panic ("internal error"); - } + case TYPE_INT: + var_to_reg_int(s2, src, REG_ITMP2); + M_IST(s2, REG_ITMP1, 0); + break; + case TYPE_LNG: + var_to_reg_int(s2, src, REG_ITMP2); + M_LST(s2, REG_ITMP1, 0); + break; + case TYPE_ADR: + var_to_reg_int(s2, src, REG_ITMP2); + M_AST(s2, REG_ITMP1, 0); + break; + case TYPE_FLT: + var_to_reg_flt(s2, src, REG_FTMP2); + M_FST(s2, REG_ITMP1, 0); + break; + case TYPE_DBL: + var_to_reg_flt(s2, src, REG_FTMP2); + M_DST(s2, REG_ITMP1, 0); + break; + } break; + case ICMD_PUTSTATICCONST: /* ... ==> ... */ + /* val = value (in current instruction) */ + /* op1 = type, val.a = field address (in */ + /* following NOP) */ - case ICMD_PUTFIELD: /* ..., value ==> ... */ - /* op1 = type, val.i = field offset */ + if (!iptr[1].val.a) { + disp = dseg_addaddress(cd, 0); - a = ((fieldinfo *)(iptr->val.a))->offset; - switch (iptr->op1) { - case TYPE_INT: - var_to_reg_int(s1, src->prev, REG_ITMP1); - var_to_reg_int(s2, src, REG_ITMP2); - gen_nullptr_check(s1); - M_IST(s2, s1, a); - break; - case TYPE_LNG: - var_to_reg_int(s1, src->prev, REG_ITMP1); - var_to_reg_int(s2, src, REG_ITMP2); - gen_nullptr_check(s1); - M_LST(s2, s1, a); - break; - case TYPE_ADR: - var_to_reg_int(s1, src->prev, REG_ITMP1); - var_to_reg_int(s2, src, REG_ITMP2); - gen_nullptr_check(s1); - M_AST(s2, s1, a); - break; - case TYPE_FLT: - var_to_reg_int(s1, src->prev, REG_ITMP1); - var_to_reg_flt(s2, src, REG_FTMP2); - gen_nullptr_check(s1); - M_FST(s2, s1, a); - break; - case TYPE_DBL: - var_to_reg_int(s1, src->prev, REG_ITMP1); - var_to_reg_flt(s2, src, REG_FTMP2); - gen_nullptr_check(s1); - M_DST(s2, s1, a); - break; - default: panic ("internal error"); + codegen_addpatchref(cd, mcodeptr, + PATCHER_get_putstatic, + (unresolved_field *) iptr[1].target, disp); + + if (opt_showdisassemble) + M_NOP; + + } else { + fieldinfo *fi = iptr[1].val.a; + + disp = dseg_addaddress(cd, &(fi->value)); + + if (!fi->class->initialized) { + codegen_addpatchref(cd, mcodeptr, + PATCHER_clinit, fi->class, 0); + + if (opt_showdisassemble) + M_NOP; } + } + + M_ALD(REG_ITMP1, REG_PV, disp); + switch (iptr->op1) { + case TYPE_INT: + M_IST(REG_ZERO, REG_ITMP1, 0); + break; + case TYPE_LNG: + M_LST(REG_ZERO, REG_ITMP1, 0); + break; + case TYPE_ADR: + M_AST(REG_ZERO, REG_ITMP1, 0); + break; + case TYPE_FLT: + M_FST(REG_ZERO, REG_ITMP1, 0); + break; + case TYPE_DBL: + M_DST(REG_ZERO, REG_ITMP1, 0); + break; + } break; + case ICMD_GETFIELD: /* ... ==> ..., value */ /* op1 = type, val.i = field offset */ - a = ((fieldinfo *)(iptr->val.a))->offset; + var_to_reg_int(s1, src, REG_ITMP1); + gen_nullptr_check(s1); + + if (!iptr->val.a) { + codegen_addpatchref(cd, mcodeptr, + PATCHER_get_putfield, + (unresolved_field *) iptr->target, 0); + + if (opt_showdisassemble) + M_NOP; + + disp = 0; + + } else { + disp = ((fieldinfo *) (iptr->val.a))->offset; + } + switch (iptr->op1) { - case TYPE_INT: - var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); - gen_nullptr_check(s1); - M_ILD(d, s1, a); - store_reg_to_var_int(iptr->dst, d); - break; - case TYPE_LNG: - var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); - gen_nullptr_check(s1); - M_LLD(d, s1, a); - store_reg_to_var_int(iptr->dst, d); - break; - case TYPE_ADR: - var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); - gen_nullptr_check(s1); - M_ALD(d, s1, a); - store_reg_to_var_int(iptr->dst, d); - break; - case TYPE_FLT: - var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_FTMP1); - gen_nullptr_check(s1); - M_FLD(d, s1, a); - store_reg_to_var_flt(iptr->dst, d); - break; - case TYPE_DBL: - var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_FTMP1); - gen_nullptr_check(s1); - M_DLD(d, s1, a); - store_reg_to_var_flt(iptr->dst, d); - break; - default: panic ("internal error"); - } + case TYPE_INT: + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + M_ILD(d, s1, disp); + store_reg_to_var_int(iptr->dst, d); + break; + case TYPE_LNG: + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + M_LLD(d, s1, disp); + store_reg_to_var_int(iptr->dst, d); + break; + case TYPE_ADR: + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + M_ALD(d, s1, disp); + store_reg_to_var_int(iptr->dst, d); + break; + case TYPE_FLT: + d = reg_of_var(rd, iptr->dst, REG_FTMP1); + M_FLD(d, s1, disp); + store_reg_to_var_flt(iptr->dst, d); + break; + case TYPE_DBL: + d = reg_of_var(rd, iptr->dst, REG_FTMP1); + M_DLD(d, s1, disp); + store_reg_to_var_flt(iptr->dst, d); + break; + } break; + case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */ + /* op1 = type, val.a = field address */ + + var_to_reg_int(s1, src->prev, REG_ITMP1); + gen_nullptr_check(s1); - /* branch operations **************************************************/ + if (!IS_FLT_DBL_TYPE(iptr->op1)) { + var_to_reg_int(s2, src, REG_ITMP2); + } else { + var_to_reg_flt(s2, src, REG_FTMP2); + } -#define ALIGNCODENOP {if((int)((long)mcodeptr&7)){M_NOP;}} + if (!iptr->val.a) { + codegen_addpatchref(cd, mcodeptr, + PATCHER_get_putfield, + (unresolved_field *) iptr->target, 0); + + if (opt_showdisassemble) + M_NOP; + + disp = 0; + + } else { + disp = ((fieldinfo *) (iptr->val.a))->offset; + } + + switch (iptr->op1) { + case TYPE_INT: + M_IST(s2, s1, disp); + break; + case TYPE_LNG: + M_LST(s2, s1, disp); + break; + case TYPE_ADR: + M_AST(s2, s1, disp); + break; + case TYPE_FLT: + M_FST(s2, s1, disp); + break; + case TYPE_DBL: + M_DST(s2, s1, disp); + break; + } + break; + + case ICMD_PUTFIELDCONST: /* ..., objectref ==> ... */ + /* val = value (in current instruction) */ + /* op1 = type, val.a = field address (in */ + /* following NOP) */ + + var_to_reg_int(s1, src, REG_ITMP1); + gen_nullptr_check(s1); + + if (!iptr[1].val.a) { + codegen_addpatchref(cd, mcodeptr, + PATCHER_get_putfield, + (unresolved_field *) iptr[1].target, 0); + + if (opt_showdisassemble) + M_NOP; + + disp = 0; + + } else { + disp = ((fieldinfo *) (iptr[1].val.a))->offset; + } + + switch (iptr[1].op1) { + case TYPE_INT: + M_IST(REG_ZERO, s1, disp); + break; + case TYPE_LNG: + M_LST(REG_ZERO, s1, disp); + break; + case TYPE_ADR: + M_AST(REG_ZERO, s1, disp); + break; + case TYPE_FLT: + M_FST(REG_ZERO, s1, disp); + break; + case TYPE_DBL: + M_DST(REG_ZERO, s1, disp); + break; + } + break; + + + /* branch operations **************************************************/ case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */ var_to_reg_int(s1, src, REG_ITMP1); M_INTMOVE(s1, REG_ITMP1_XPTR); - a = dseg_addaddress(asm_handle_exception); - M_ALD(REG_ITMP2, REG_PV, a); + disp = dseg_addaddress(cd, asm_handle_exception); + M_ALD(REG_ITMP2, REG_PV, disp); M_JMP(REG_ITMP2_XPC, REG_ITMP2); M_NOP; /* nop ensures that XPC is less than the end */ /* of basic block */ @@ -2493,7 +2316,7 @@ void codegen() case ICMD_GOTO: /* ... ==> ... */ /* op1 = target JavaVM pc */ M_BR(0); - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); ALIGNCODENOP; break; @@ -2501,13 +2324,13 @@ void codegen() /* op1 = target JavaVM pc */ M_BSR(REG_ITMP1, 0); - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_RET: /* ... ==> ... */ /* op1 = local variable */ - var = &(locals[iptr->op1][TYPE_ADR]); + var = &(rd->locals[iptr->op1][TYPE_ADR]); if (var->flags & INMEMORY) { M_ALD(REG_ITMP1, REG_SP, 8 * var->regoff); M_RET(REG_ZERO, REG_ITMP1); @@ -2522,7 +2345,7 @@ void codegen() var_to_reg_int(s1, src, REG_ITMP1); M_BEQZ(s1, 0); - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IFNONNULL: /* ..., value ==> ... */ @@ -2530,7 +2353,7 @@ void codegen() var_to_reg_int(s1, src, REG_ITMP1); M_BNEZ(s1, 0); - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IFEQ: /* ..., value ==> ... */ @@ -2550,7 +2373,7 @@ void codegen() } M_BNEZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IFLT: /* ..., value ==> ... */ @@ -2570,7 +2393,7 @@ void codegen() } M_BNEZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IFLE: /* ..., value ==> ... */ @@ -2590,7 +2413,7 @@ void codegen() } M_BNEZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IFNE: /* ..., value ==> ... */ @@ -2610,7 +2433,7 @@ void codegen() } M_BEQZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IFGT: /* ..., value ==> ... */ @@ -2630,7 +2453,7 @@ void codegen() } M_BEQZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IFGE: /* ..., value ==> ... */ @@ -2650,7 +2473,7 @@ void codegen() } M_BEQZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_LEQ: /* ..., value ==> ... */ @@ -2670,7 +2493,7 @@ void codegen() } M_BNEZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_LLT: /* ..., value ==> ... */ @@ -2690,7 +2513,7 @@ void codegen() } M_BNEZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_LLE: /* ..., value ==> ... */ @@ -2710,7 +2533,7 @@ void codegen() } M_BNEZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_LNE: /* ..., value ==> ... */ @@ -2730,7 +2553,7 @@ void codegen() } M_BEQZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_LGT: /* ..., value ==> ... */ @@ -2750,7 +2573,7 @@ void codegen() } M_BEQZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_LGE: /* ..., value ==> ... */ @@ -2770,7 +2593,7 @@ void codegen() } M_BEQZ(REG_ITMP1, 0); } - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */ @@ -2781,7 +2604,7 @@ void codegen() var_to_reg_int(s2, src, REG_ITMP2); M_CMPEQ(s1, s2, REG_ITMP1); M_BNEZ(REG_ITMP1, 0); - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_ICMPNE: /* ..., value, value ==> ... */ @@ -2792,7 +2615,7 @@ void codegen() var_to_reg_int(s2, src, REG_ITMP2); M_CMPEQ(s1, s2, REG_ITMP1); M_BEQZ(REG_ITMP1, 0); - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_ICMPLT: /* ..., value, value ==> ... */ @@ -2802,7 +2625,7 @@ void codegen() var_to_reg_int(s2, src, REG_ITMP2); M_CMPLT(s1, s2, REG_ITMP1); M_BNEZ(REG_ITMP1, 0); - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_ICMPGT: /* ..., value, value ==> ... */ @@ -2812,7 +2635,7 @@ void codegen() var_to_reg_int(s2, src, REG_ITMP2); M_CMPLE(s1, s2, REG_ITMP1); M_BEQZ(REG_ITMP1, 0); - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_ICMPLE: /* ..., value, value ==> ... */ @@ -2822,7 +2645,7 @@ void codegen() var_to_reg_int(s2, src, REG_ITMP2); M_CMPLE(s1, s2, REG_ITMP1); M_BNEZ(REG_ITMP1, 0); - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; case ICMD_IF_ICMPGE: /* ..., value, value ==> ... */ @@ -2832,7 +2655,7 @@ void codegen() var_to_reg_int(s2, src, REG_ITMP2); M_CMPLT(s1, s2, REG_ITMP1); M_BEQZ(REG_ITMP1, 0); - codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr); + codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr); break; /* (value xx 0) ? IFxx_ICONST : ELSE_ICONST */ @@ -2844,33 +2667,32 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); s3 = iptr->val.i; if (iptr[1].opc == ICMD_ELSE_ICONST) { if ((s3 == 1) && (iptr[1].val.i == 0)) { M_CMPEQ(s1, REG_ZERO, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if ((s3 == 0) && (iptr[1].val.i == 1)) { M_CMPEQ(s1, REG_ZERO, d); M_XOR_IMM(d, 1, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if (s1 == d) { M_MOV(s1, REG_ITMP1); s1 = REG_ITMP1; - } - ICONST(d, iptr[1].val.i); } + ICONST(d, iptr[1].val.i); + } if ((s3 >= 0) && (s3 <= 255)) { M_CMOVEQ_IMM(s1, s3, d); - } - else { + } else { ICONST(REG_ITMP2, s3); M_CMOVEQ(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -2878,33 +2700,32 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); s3 = iptr->val.i; if (iptr[1].opc == ICMD_ELSE_ICONST) { if ((s3 == 0) && (iptr[1].val.i == 1)) { M_CMPEQ(s1, REG_ZERO, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if ((s3 == 1) && (iptr[1].val.i == 0)) { M_CMPEQ(s1, REG_ZERO, d); M_XOR_IMM(d, 1, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if (s1 == d) { M_MOV(s1, REG_ITMP1); s1 = REG_ITMP1; - } - ICONST(d, iptr[1].val.i); } + ICONST(d, iptr[1].val.i); + } if ((s3 >= 0) && (s3 <= 255)) { M_CMOVNE_IMM(s1, s3, d); - } - else { + } else { ICONST(REG_ITMP2, s3); M_CMOVNE(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -2912,32 +2733,31 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); s3 = iptr->val.i; if ((iptr[1].opc == ICMD_ELSE_ICONST)) { if ((s3 == 1) && (iptr[1].val.i == 0)) { M_CMPLT(s1, REG_ZERO, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if ((s3 == 0) && (iptr[1].val.i == 1)) { M_CMPLE(REG_ZERO, s1, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if (s1 == d) { M_MOV(s1, REG_ITMP1); s1 = REG_ITMP1; - } - ICONST(d, iptr[1].val.i); } + ICONST(d, iptr[1].val.i); + } if ((s3 >= 0) && (s3 <= 255)) { M_CMOVLT_IMM(s1, s3, d); - } - else { + } else { ICONST(REG_ITMP2, s3); M_CMOVLT(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -2945,32 +2765,31 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); s3 = iptr->val.i; if ((iptr[1].opc == ICMD_ELSE_ICONST)) { if ((s3 == 1) && (iptr[1].val.i == 0)) { M_CMPLE(REG_ZERO, s1, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if ((s3 == 0) && (iptr[1].val.i == 1)) { M_CMPLT(s1, REG_ZERO, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if (s1 == d) { M_MOV(s1, REG_ITMP1); s1 = REG_ITMP1; - } - ICONST(d, iptr[1].val.i); } + ICONST(d, iptr[1].val.i); + } if ((s3 >= 0) && (s3 <= 255)) { M_CMOVGE_IMM(s1, s3, d); - } - else { + } else { ICONST(REG_ITMP2, s3); M_CMOVGE(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -2978,32 +2797,31 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); s3 = iptr->val.i; if ((iptr[1].opc == ICMD_ELSE_ICONST)) { if ((s3 == 1) && (iptr[1].val.i == 0)) { M_CMPLT(REG_ZERO, s1, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if ((s3 == 0) && (iptr[1].val.i == 1)) { M_CMPLE(s1, REG_ZERO, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if (s1 == d) { M_MOV(s1, REG_ITMP1); - s1 = REG_ITMP1; - } - ICONST(d, iptr[1].val.i); + s1 = REG_ITMP1; } + ICONST(d, iptr[1].val.i); + } if ((s3 >= 0) && (s3 <= 255)) { M_CMOVGT_IMM(s1, s3, d); - } - else { + } else { ICONST(REG_ITMP2, s3); M_CMOVGT(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -3011,32 +2829,31 @@ void codegen() /* val.i = constant */ var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); s3 = iptr->val.i; if ((iptr[1].opc == ICMD_ELSE_ICONST)) { if ((s3 == 1) && (iptr[1].val.i == 0)) { M_CMPLE(s1, REG_ZERO, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if ((s3 == 0) && (iptr[1].val.i == 1)) { M_CMPLT(REG_ZERO, s1, d); store_reg_to_var_int(iptr->dst, d); break; - } + } if (s1 == d) { M_MOV(s1, REG_ITMP1); s1 = REG_ITMP1; - } - ICONST(d, iptr[1].val.i); } + ICONST(d, iptr[1].val.i); + } if ((s3 >= 0) && (s3 <= 255)) { M_CMOVLE_IMM(s1, s3, d); - } - else { + } else { ICONST(REG_ITMP2, s3); M_CMOVLE(s1, REG_ITMP2, d); - } + } store_reg_to_var_int(iptr->dst, d); break; @@ -3045,104 +2862,111 @@ void codegen() case ICMD_LRETURN: case ICMD_ARETURN: -#ifdef USE_THREADS - if (checksync && (method->flags & ACC_SYNCHRONIZED)) { - int disp; - a = dseg_addaddress ((void*) (builtin_monitorexit)); - M_ALD(REG_PV, REG_PV, a); - M_ALD(argintregs[0], REG_SP, 8 * maxmemuse); - M_JSR(REG_RA, REG_PV); - disp = -(int)((u1*) mcodeptr - mcodebase); - M_LDA(REG_PV, REG_RA, disp); - } -#endif var_to_reg_int(s1, src, REG_RESULT); M_INTMOVE(s1, REG_RESULT); + goto nowperformreturn; case ICMD_FRETURN: /* ..., retvalue ==> ... */ case ICMD_DRETURN: -#ifdef USE_THREADS - if (checksync && (method->flags & ACC_SYNCHRONIZED)) { - int disp; - a = dseg_addaddress ((void*) (builtin_monitorexit)); - M_ALD(REG_PV, REG_PV, a); - M_ALD(argintregs[0], REG_SP, 8 * maxmemuse); - M_JSR(REG_RA, REG_PV); - disp = -(int)((u1*) mcodeptr - mcodebase); - M_LDA(REG_PV, REG_RA, disp); - } -#endif var_to_reg_flt(s1, src, REG_FRESULT); M_FLTMOVE(s1, REG_FRESULT); - goto nowperformreturn; - case ICMD_RETURN: /* ... ==> ... */ + goto nowperformreturn; -#ifdef USE_THREADS - if (checksync && (method->flags & ACC_SYNCHRONIZED)) { - int disp; - a = dseg_addaddress ((void*) (builtin_monitorexit)); - M_ALD(REG_PV, REG_PV, a); - M_ALD(argintregs[0], REG_SP, 8 * maxmemuse); - M_JSR(REG_RA, REG_PV); - disp = -(int)((u1*) mcodeptr - mcodebase); - M_LDA(REG_PV, REG_RA, disp); - } -#endif + case ICMD_RETURN: /* ... ==> ... */ nowperformreturn: { - int r, p; + s4 i, p; p = parentargs_base; - /* restore return address */ + /* call trace function */ - if (!isleafmethod) - {p--; M_LLD (REG_RA, REG_SP, 8 * p);} + if (runverbose) { + M_LDA(REG_SP, REG_SP, -3 * 8); + M_AST(REG_RA, REG_SP, 0 * 8); + M_LST(REG_RESULT, REG_SP, 1 * 8); + M_DST(REG_FRESULT, REG_SP, 2 * 8); + + disp = dseg_addaddress(cd, m); + M_ALD(rd->argintregs[0], REG_PV, disp); + M_MOV(REG_RESULT, rd->argintregs[1]); + M_FLTMOVE(REG_FRESULT, rd->argfltregs[2]); + M_FLTMOVE(REG_FRESULT, rd->argfltregs[3]); + + disp = dseg_addaddress(cd, (void *) builtin_displaymethodstop); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); - /* restore saved registers */ + M_DLD(REG_FRESULT, REG_SP, 2 * 8); + M_LLD(REG_RESULT, REG_SP, 1 * 8); + M_ALD(REG_RA, REG_SP, 0 * 8); + M_LDA(REG_SP, REG_SP, 3 * 8); + } - for (r = savintregcnt - 1; r >= maxsavintreguse; r--) - {p--; M_LLD(savintregs[r], REG_SP, 8 * p);} - for (r = savfltregcnt - 1; r >= maxsavfltreguse; r--) - {p--; M_DLD(savfltregs[r], REG_SP, 8 * p);} +#if defined(USE_THREADS) + if (checksync && (m->flags & ACC_SYNCHRONIZED)) { + s4 disp; - /* deallocate stack */ + M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8); - if (parentargs_base) - {M_LDA(REG_SP, REG_SP, parentargs_base*8);} + switch (iptr->opc) { + case ICMD_IRETURN: + case ICMD_LRETURN: + case ICMD_ARETURN: + M_LST(REG_RESULT, REG_SP, rd->memuse * 8); + break; + case ICMD_FRETURN: + case ICMD_DRETURN: + M_DST(REG_FRESULT, REG_SP, rd->memuse * 8); + break; + } - /* call trace function */ + disp = dseg_addaddress(cd, BUILTIN_monitorexit); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, disp); - if (runverbose) { - M_LDA (REG_SP, REG_SP, -24); - M_AST(REG_RA, REG_SP, 0); - M_LST(REG_RESULT, REG_SP, 8); - M_DST(REG_FRESULT, REG_SP,16); - a = dseg_addaddress(method); - M_ALD(argintregs[0], REG_PV, a); - M_MOV(REG_RESULT, argintregs[1]); - M_FLTMOVE(REG_FRESULT, argfltregs[2]); - M_FLTMOVE(REG_FRESULT, argfltregs[3]); - a = dseg_addaddress((void *) builtin_displaymethodstop); - M_ALD(REG_PV, REG_PV, a); - M_JSR (REG_RA, REG_PV); - s1 = (int)((u1*) mcodeptr - mcodebase); - if (s1<=32768) M_LDA (REG_PV, REG_RA, -s1); - else { - s4 ml=-s1, mh=0; - while (ml<-32768) { ml+=65536; mh--; } - M_LDA (REG_PV, REG_RA, ml ); - M_LDAH (REG_PV, REG_PV, mh ); - } - M_DLD(REG_FRESULT, REG_SP,16); - M_LLD(REG_RESULT, REG_SP, 8); - M_ALD(REG_RA, REG_SP, 0); - M_LDA (REG_SP, REG_SP, 24); + switch (iptr->opc) { + case ICMD_IRETURN: + case ICMD_LRETURN: + case ICMD_ARETURN: + M_LLD(REG_RESULT, REG_SP, rd->memuse * 8); + break; + case ICMD_FRETURN: + case ICMD_DRETURN: + M_DLD(REG_FRESULT, REG_SP, rd->memuse * 8); + break; } + } +#endif + + /* restore return address */ + + if (!m->isleafmethod) { + p--; M_LLD(REG_RA, REG_SP, p * 8); + } + + /* restore saved registers */ + + for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) { + p--; M_LLD(rd->savintregs[i], REG_SP, p * 8); + } + for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) { + p--; M_DLD(rd->savfltregs[i], REG_SP, p * 8); + } + + /* deallocate stack */ + + if (parentargs_base) { + M_LDA(REG_SP, REG_SP, parentargs_base * 8); + } M_RET(REG_ZERO, REG_RA); ALIGNCODENOP; @@ -3162,15 +2986,14 @@ nowperformreturn: i = s4ptr[2]; /* high */ var_to_reg_int(s1, src, REG_ITMP1); - if (l == 0) - {M_INTMOVE(s1, REG_ITMP1);} - else if (l <= 32768) { + if (l == 0) { + M_INTMOVE(s1, REG_ITMP1); + } else if (l <= 32768) { M_LDA(REG_ITMP1, s1, -l); - } - else { + } else { ICONST(REG_ITMP2, l); M_ISUB(s1, REG_ITMP2, REG_ITMP1); - } + } i = i - l + 1; /* range check */ @@ -3180,12 +3003,9 @@ nowperformreturn: else { M_LDA(REG_ITMP2, REG_ZERO, i - 1); M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2); - } + } M_BEQZ(REG_ITMP2, 0); - - - /* codegen_addreference(BlockPtrOfPC(s4ptr[0]), mcodeptr); */ - codegen_addreference((basicblock *) tptr[0], mcodeptr); + codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr); /* build jump table top down and use address of lowest entry */ @@ -3193,16 +3013,15 @@ nowperformreturn: tptr += i; while (--i >= 0) { - /* dseg_addtarget(BlockPtrOfPC(*--s4ptr)); */ - dseg_addtarget((basicblock *) tptr[0]); + dseg_addtarget(cd, (basicblock *) tptr[0]); --tptr; - } + } } /* length of dataseg after last dseg_addtarget is used by load */ M_SAADDQ(REG_ITMP1, REG_PV, REG_ITMP2); - M_ALD(REG_ITMP2, REG_ITMP2, -dseglen); + M_ALD(REG_ITMP2, REG_ITMP2, -(cd->dseglen)); M_JMP(REG_ZERO, REG_ITMP2); ALIGNCODENOP; break; @@ -3228,341 +3047,564 @@ nowperformreturn: val = s4ptr[0]; if ((val >= 0) && (val <= 255)) { M_CMPEQ_IMM(s1, val, REG_ITMP2); - } - else { + } else { if ((val >= -32768) && (val <= 32767)) { M_LDA(REG_ITMP2, REG_ZERO, val); - } - else { - a = dseg_adds4 (val); - M_ILD(REG_ITMP2, REG_PV, a); - } - M_CMPEQ(s1, REG_ITMP2, REG_ITMP2); + } else { + disp = dseg_adds4(cd, val); + M_ILD(REG_ITMP2, REG_PV, disp); } - M_BNEZ(REG_ITMP2, 0); - /* codegen_addreference(BlockPtrOfPC(s4ptr[1]), mcodeptr); */ - codegen_addreference((basicblock *) tptr[0], mcodeptr); + M_CMPEQ(s1, REG_ITMP2, REG_ITMP2); } + M_BNEZ(REG_ITMP2, 0); + codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr); + } M_BR(0); - /* codegen_addreference(BlockPtrOfPC(l), mcodeptr); */ tptr = (void **) iptr->target; - codegen_addreference((basicblock *) tptr[0], mcodeptr); + codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr); ALIGNCODENOP; break; } - case ICMD_BUILTIN3: /* ..., arg1, arg2, arg3 ==> ... */ - /* op1 = return type, val.a = function pointer*/ - s3 = 3; - goto gen_method; - - case ICMD_BUILTIN2: /* ..., arg1, arg2 ==> ... */ - /* op1 = return type, val.a = function pointer*/ - s3 = 2; - goto gen_method; + case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */ + /* op1 = arg count val.a = builtintable entry */ - case ICMD_BUILTIN1: /* ..., arg1 ==> ... */ - /* op1 = return type, val.a = function pointer*/ - s3 = 1; + bte = iptr->val.a; + md = bte->md; goto gen_method; case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */ /* op1 = arg count, val.a = method pointer */ case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */ - /* op1 = arg count, val.a = method pointer */ - - case ICMD_INVOKEVIRTUAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */ - /* op1 = arg count, val.a = method pointer */ + case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */ + case ICMD_INVOKEINTERFACE: - case ICMD_INVOKEINTERFACE:/*.., objectref, [arg1, [arg2 ...]] ==> ... */ - /* op1 = arg count, val.a = method pointer */ + lm = iptr->val.a; - s3 = iptr->op1; + if (lm) + md = lm->parseddesc; + else { + unresolved_method *um = iptr->target; + md = um->methodref->parseddesc.md; + } -gen_method: { - methodinfo *m; - classinfo *ci; +gen_method: + s3 = md->paramcount; MCODECHECK((s3 << 1) + 64); /* copy arguments to registers or stack location */ - for (; --s3 >= 0; src = src->prev) { + for (s3 = s3 - 1; s3 >= 0; s3--, src = src->prev) { if (src->varkind == ARGVAR) continue; if (IS_INT_LNG_TYPE(src->type)) { - if (s3 < INT_ARG_CNT) { - s1 = argintregs[s3]; + if (!md->params[s3].inmemory) { + s1 = rd->argintregs[md->params[s3].regoff]; var_to_reg_int(d, src, s1); M_INTMOVE(d, s1); - } - else { + } else { var_to_reg_int(d, src, REG_ITMP1); - M_LST(d, REG_SP, 8 * (s3 - INT_ARG_CNT)); - } + M_LST(d, REG_SP, md->params[s3].regoff * 8); } - else - if (s3 < FLT_ARG_CNT) { - s1 = argfltregs[s3]; + + } else { + if (!md->params[s3].inmemory) { + s1 = rd->argfltregs[md->params[s3].regoff]; var_to_reg_flt(d, src, s1); M_FLTMOVE(d, s1); - } - else { + } else { var_to_reg_flt(d, src, REG_FTMP1); - M_DST(d, REG_SP, 8 * (s3 - FLT_ARG_CNT)); - } - } /* end of for */ + M_DST(d, REG_SP, md->params[s3].regoff * 8); + } + } + } - m = iptr->val.a; switch (iptr->opc) { - case ICMD_BUILTIN3: - case ICMD_BUILTIN2: - case ICMD_BUILTIN1: - a = dseg_addaddress ((void*) (m)); + case ICMD_BUILTIN: + if (iptr->target) { + disp = dseg_addaddress(cd, NULL); + + codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target, + disp); - M_ALD(REG_PV, REG_PV, a); /* Pointer to built-in-function */ - d = iptr->op1; - goto makeactualcall; + if (opt_showdisassemble) + M_NOP; - case ICMD_INVOKESTATIC: - case ICMD_INVOKESPECIAL: - a = dseg_addaddress (m->stubroutine); + } else { + disp = dseg_addaddress(cd, bte->fp); + } - M_ALD(REG_PV, REG_PV, a ); /* method pointer in r27 */ + d = md->returntype.type; - d = m->returntype; - goto makeactualcall; + M_ALD(REG_PV, REG_PV, disp); /* Pointer to built-in-function */ + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); - case ICMD_INVOKEVIRTUAL: + /* if op1 == true, we need to check for an exception */ - gen_nullptr_check(argintregs[0]); - M_ALD(REG_METHODPTR, argintregs[0], - OFFSET(java_objectheader, vftbl)); - M_ALD(REG_PV, REG_METHODPTR, OFFSET(vftbl, table[0]) + - sizeof(methodptr) * m->vftblindex); + if (iptr->op1 == true) { + M_BEQZ(REG_RESULT, 0); + codegen_addxexceptionrefs(cd, mcodeptr); + } + break; - d = m->returntype; - goto makeactualcall; + case ICMD_INVOKESPECIAL: + M_BEQZ(rd->argintregs[0], 0); + codegen_addxnullrefs(cd, mcodeptr); + /* fall through */ - case ICMD_INVOKEINTERFACE: - ci = m->class; - - gen_nullptr_check(argintregs[0]); - M_ALD(REG_METHODPTR, argintregs[0], - OFFSET(java_objectheader, vftbl)); - M_ALD(REG_METHODPTR, REG_METHODPTR, - OFFSET(vftbl, interfacetable[0]) - - sizeof(methodptr*) * ci->index); - M_ALD(REG_PV, REG_METHODPTR, - sizeof(methodptr) * (m - ci->methods)); - - d = m->returntype; - goto makeactualcall; - - default: - d = 0; - error ("Unkown ICMD-Command: %d", iptr->opc); + case ICMD_INVOKESTATIC: + if (!lm) { + unresolved_method *um = iptr->target; + + disp = dseg_addaddress(cd, NULL); + + codegen_addpatchref(cd, mcodeptr, + PATCHER_invokestatic_special, um, disp); + + if (opt_showdisassemble) + M_NOP; + + d = um->methodref->parseddesc.md->returntype.type; + + } else { + disp = dseg_addaddress(cd, lm->stubroutine); + d = lm->parseddesc->returntype.type; } -makeactualcall: + M_ALD(REG_PV, REG_PV, disp); /* method pointer in r27 */ + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + break; + + case ICMD_INVOKEVIRTUAL: + gen_nullptr_check(rd->argintregs[0]); - M_JSR (REG_RA, REG_PV); + if (!lm) { + unresolved_method *um = iptr->target; - /* recompute pv */ + codegen_addpatchref(cd, mcodeptr, + PATCHER_invokevirtual, um, 0); - s1 = (int)((u1*) mcodeptr - mcodebase); - if (s1<=32768) M_LDA (REG_PV, REG_RA, -s1); - else { - s4 ml=-s1, mh=0; - while (ml<-32768) { ml+=65536; mh--; } - M_LDA (REG_PV, REG_RA, ml ); - M_LDAH (REG_PV, REG_PV, mh ); + if (opt_showdisassemble) + M_NOP; + + s1 = 0; + d = um->methodref->parseddesc.md->returntype.type; + + } else { + s1 = OFFSET(vftbl_t, table[0]) + + sizeof(methodptr) * lm->vftblindex; + d = lm->parseddesc->returntype.type; + } + + M_ALD(REG_METHODPTR, rd->argintregs[0], + OFFSET(java_objectheader, vftbl)); + M_ALD(REG_PV, REG_METHODPTR, s1); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + break; + + case ICMD_INVOKEINTERFACE: + gen_nullptr_check(rd->argintregs[0]); + + if (!lm) { + unresolved_method *um = iptr->target; + + codegen_addpatchref(cd, mcodeptr, + PATCHER_invokeinterface, um, 0); + + if (opt_showdisassemble) + M_NOP; + + s1 = 0; + s2 = 0; + d = um->methodref->parseddesc.md->returntype.type; + + } else { + s1 = OFFSET(vftbl_t, interfacetable[0]) - + sizeof(methodptr*) * lm->class->index; + + s2 = sizeof(methodptr) * (lm - lm->class->methods); + + d = lm->parseddesc->returntype.type; } + + M_ALD(REG_METHODPTR, rd->argintregs[0], + OFFSET(java_objectheader, vftbl)); + M_ALD(REG_METHODPTR, REG_METHODPTR, s1); + M_ALD(REG_PV, REG_METHODPTR, s2); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + break; + } /* d contains return type */ if (d != TYPE_VOID) { if (IS_INT_LNG_TYPE(iptr->dst->type)) { - s1 = reg_of_var(iptr->dst, REG_RESULT); + s1 = reg_of_var(rd, iptr->dst, REG_RESULT); M_INTMOVE(REG_RESULT, s1); store_reg_to_var_int(iptr->dst, s1); - } - else { - s1 = reg_of_var(iptr->dst, REG_FRESULT); + } else { + s1 = reg_of_var(rd, iptr->dst, REG_FRESULT); M_FLTMOVE(REG_FRESULT, s1); store_reg_to_var_flt(iptr->dst, s1); - } } } break; - case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */ + case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */ /* op1: 0 == array, 1 == class */ /* val.a: (classinfo*) superclass */ -/* superclass is an interface: - * - * return (sub != NULL) && - * (sub->vftbl->interfacetablelength > super->index) && - * (sub->vftbl->interfacetable[-super->index] != NULL); - * - * superclass is a class: - * - * return ((sub != NULL) && (0 - * <= (sub->vftbl->baseval - super->vftbl->baseval) <= - * super->vftbl->diffvall)); - */ + /* superclass is an interface: + * + * OK if ((sub == NULL) || + * (sub->vftbl->interfacetablelength > super->index) && + * (sub->vftbl->interfacetable[-super->index] != NULL)); + * + * superclass is a class: + * + * OK if ((sub == NULL) || (0 + * <= (sub->vftbl->baseval - super->vftbl->baseval) <= + * super->vftbl->diffval)); + */ { - classinfo *super = (classinfo*) iptr->val.a; + classinfo *super; + vftbl_t *supervftbl; + s4 superindex; + + super = (classinfo *) iptr->val.a; + + if (!super) { + superindex = 0; + supervftbl = NULL; + + } else { + superindex = super->index; + supervftbl = super->vftbl; + } +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase); +#endif var_to_reg_int(s1, src, REG_ITMP1); - d = reg_of_var(iptr->dst, REG_ITMP3); - if (s1 == d) { - M_MOV(s1, REG_ITMP1); - s1 = REG_ITMP1; - } - M_CLR(d); - if (iptr->op1) { /* class/interface */ - if (super->flags & ACC_INTERFACE) { /* interface */ - M_BEQZ(s1, 6); - M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl)); - M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl, interfacetablelength)); - M_LDA(REG_ITMP2, REG_ITMP2, - super->index); - M_BLEZ(REG_ITMP2, 2); - M_ALD(REG_ITMP1, REG_ITMP1, - OFFSET(vftbl, interfacetable[0]) - - super->index * sizeof(methodptr*)); - M_CMPULT(REG_ZERO, REG_ITMP1, d); /* REG_ITMP1 != 0 */ - } - else { /* class */ -/* - s2 = super->vftbl->diffval; - M_BEQZ(s1, 4 + (s2 > 255)); - M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl)); - M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval)); - M_LDA(REG_ITMP1, REG_ITMP1, - super->vftbl->baseval); - if (s2 <= 255) - M_CMPULE_IMM(REG_ITMP1, s2, d); - else { - M_LDA(REG_ITMP2, REG_ZERO, s2); - M_CMPULE(REG_ITMP1, REG_ITMP2, d); - } -*/ - M_BEQZ(s1, 7); - M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl)); - a = dseg_addaddress ((void*) super->vftbl); - M_ALD(REG_ITMP2, REG_PV, a); - M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval)); - M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl, baseval)); - M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval)); - M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1); - M_CMPULE(REG_ITMP1, REG_ITMP2, d); - } + + /* calculate interface checkcast code size */ + + s2 = 6; + if (!super) + s2 += opt_showdisassemble ? 1 : 0; + + /* calculate class checkcast code size */ + + s3 = 9 /* 8 + (s1 == REG_ITMP1) */; + if (!super) + s3 += opt_showdisassemble ? 1 : 0; + + /* if class is not resolved, check which code to call */ + + if (!super) { + M_BEQZ(s1, 4 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3); + + disp = dseg_adds4(cd, 0); /* super->flags */ + + codegen_addpatchref(cd, mcodeptr, + PATCHER_checkcast_instanceof_flags, + (constant_classref *) iptr->target, disp); + + if (opt_showdisassemble) + M_NOP; + + M_ILD(REG_ITMP2, REG_PV, disp); + disp = dseg_adds4(cd, ACC_INTERFACE); + M_ILD(REG_ITMP3, REG_PV, disp); + M_AND(REG_ITMP2, REG_ITMP3, REG_ITMP2); + M_BEQZ(REG_ITMP2, s2 + 1); + } + + /* interface checkcast code */ + + if (!super || (super->flags & ACC_INTERFACE)) { + if (super) { + M_BEQZ(s1, s2); + + } else { + codegen_addpatchref(cd, mcodeptr, + PATCHER_checkcast_instanceof_interface, + (constant_classref *) iptr->target, 0); + + if (opt_showdisassemble) + M_NOP; + } + + M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl)); + M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength)); + M_LDA(REG_ITMP3, REG_ITMP3, -superindex); + M_BLEZ(REG_ITMP3, 0); + codegen_addxcastrefs(cd, mcodeptr); + M_ALD(REG_ITMP3, REG_ITMP2, + (s4) (OFFSET(vftbl_t, interfacetable[0]) - + superindex * sizeof(methodptr*))); + M_BEQZ(REG_ITMP3, 0); + codegen_addxcastrefs(cd, mcodeptr); + + if (!super) + M_BR(s3); + } + + /* class checkcast code */ + + if (!super || !(super->flags & ACC_INTERFACE)) { + disp = dseg_addaddress(cd, supervftbl); + + if (super) { + M_BEQZ(s1, s3); + + } else { + codegen_addpatchref(cd, mcodeptr, + PATCHER_checkcast_instanceof_class, + (constant_classref *) iptr->target, + disp); + + if (opt_showdisassemble) + M_NOP; } - else - panic ("internal error: no inlined array instanceof"); + + M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl)); + M_ALD(REG_ITMP3, REG_PV, disp); +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase); +#endif + M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval)); +/* if (s1 != REG_ITMP1) { */ +/* M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, baseval)); */ +/* M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval)); */ +/* #if defined(USE_THREADS) && defined(NATIVE_THREADS) */ +/* codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase); */ +/* #endif */ +/* M_ISUB(REG_ITMP2, REG_ITMP1, REG_ITMP2); */ + +/* } else { */ + M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval)); + M_ISUB(REG_ITMP2, REG_ITMP3, REG_ITMP2); + M_ALD(REG_ITMP3, REG_PV, disp); + M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval)); +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase); +#endif +/* } */ + M_CMPULE(REG_ITMP2, REG_ITMP3, REG_ITMP3); + M_BEQZ(REG_ITMP3, 0); + codegen_addxcastrefs(cd, mcodeptr); + } + d = reg_of_var(rd, iptr->dst, s1); + M_INTMOVE(s1, d); + store_reg_to_var_int(iptr->dst, d); + } + break; + + case ICMD_ARRAYCHECKCAST: /* ..., objectref ==> ..., objectref */ + /* op1: 1... resolved, 0... not resolved */ + + var_to_reg_int(s1, src, rd->argintregs[0]); + M_INTMOVE(s1, rd->argintregs[0]); + + bte = iptr->val.a; + + disp = dseg_addaddress(cd, iptr->target); + + if (!iptr->op1) { + codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target, disp); + + if (opt_showdisassemble) + M_NOP; + + a = 0; + + } else { + a = (ptrint) bte->fp; } + + M_ALD(rd->argintregs[1], REG_PV, disp); + + disp = dseg_addaddress(cd, a); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + + M_BEQZ(REG_RESULT, 0); + codegen_addxcastrefs(cd, mcodeptr); + + var_to_reg_int(s1, src, REG_ITMP1); + d = reg_of_var(rd, iptr->dst, s1); + M_INTMOVE(s1, d); store_reg_to_var_int(iptr->dst, d); break; - case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */ + case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */ /* op1: 0 == array, 1 == class */ /* val.a: (classinfo*) superclass */ -/* superclass is an interface: - * - * OK if ((sub == NULL) || - * (sub->vftbl->interfacetablelength > super->index) && - * (sub->vftbl->interfacetable[-super->index] != NULL)); - * - * superclass is a class: - * - * OK if ((sub == NULL) || (0 - * <= (sub->vftbl->baseval - super->vftbl->baseval) <= - * super->vftbl->diffvall)); - */ + /* superclass is an interface: + * + * return (sub != NULL) && + * (sub->vftbl->interfacetablelength > super->index) && + * (sub->vftbl->interfacetable[-super->index] != NULL); + * + * superclass is a class: + * + * return ((sub != NULL) && (0 + * <= (sub->vftbl->baseval - super->vftbl->baseval) <= + * super->vftbl->diffvall)); + */ { - classinfo *super = (classinfo*) iptr->val.a; + classinfo *super; + vftbl_t *supervftbl; + s4 superindex; + + super = (classinfo *) iptr->val.a; + + if (!super) { + superindex = 0; + supervftbl = NULL; + + } else { + superindex = super->index; + supervftbl = super->vftbl; + } - d = reg_of_var(iptr->dst, REG_ITMP3); - var_to_reg_int(s1, src, d); - if (iptr->op1) { /* class/interface */ - if (super->flags & ACC_INTERFACE) { /* interface */ - M_BEQZ(s1, 6); - M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl)); - M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl, interfacetablelength)); - M_LDA(REG_ITMP2, REG_ITMP2, - super->index); - M_BLEZ(REG_ITMP2, 0); - codegen_addxcastrefs(mcodeptr); - M_ALD(REG_ITMP2, REG_ITMP1, - OFFSET(vftbl, interfacetable[0]) - - super->index * sizeof(methodptr*)); - M_BEQZ(REG_ITMP2, 0); - codegen_addxcastrefs(mcodeptr); - } - else { /* class */ -/* - s2 = super->vftbl->diffval; - M_BEQZ(s1, 4 + (s2 != 0) + (s2 > 255)); - M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl)); - M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval)); - M_LDA(REG_ITMP1, REG_ITMP1, - super->vftbl->baseval); - if (s2 == 0) { - M_BNEZ(REG_ITMP1, 0); - } - else if (s2 <= 255) { - M_CMPULE_IMM(REG_ITMP1, s2, REG_ITMP2); - M_BEQZ(REG_ITMP2, 0); - } - else { - M_LDA(REG_ITMP2, REG_ZERO, s2); - M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2); - M_BEQZ(REG_ITMP2, 0); - } -*/ - M_BEQZ(s1, 8 + (d == REG_ITMP3)); - M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl)); - a = dseg_addaddress ((void*) super->vftbl); - M_ALD(REG_ITMP2, REG_PV, a); - M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval)); - if (d != REG_ITMP3) { - M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl, baseval)); - M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval)); - M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1); - } - else { - M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, baseval)); - M_ISUB(REG_ITMP1, REG_ITMP2, REG_ITMP1); - M_ALD(REG_ITMP2, REG_PV, a); - M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval)); - } - M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2); - M_BEQZ(REG_ITMP2, 0); - codegen_addxcastrefs(mcodeptr); - } +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase); +#endif + var_to_reg_int(s1, src, REG_ITMP1); + d = reg_of_var(rd, iptr->dst, REG_ITMP2); + if (s1 == d) { + M_MOV(s1, REG_ITMP1); + s1 = REG_ITMP1; + } + + /* calculate interface instanceof code size */ + + s2 = 6; + if (!super) + s2 += (d == REG_ITMP2 ? 1 : 0) + (opt_showdisassemble ? 1 : 0); + + /* calculate class instanceof code size */ + + s3 = 7; + if (!super) + s3 += (opt_showdisassemble ? 1 : 0); + + /* if class is not resolved, check which code to call */ + + if (!super) { + M_CLR(d); + M_BEQZ(s1, 4 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3); + + disp = dseg_adds4(cd, 0); /* super->flags */ + + codegen_addpatchref(cd, mcodeptr, + PATCHER_checkcast_instanceof_flags, + (constant_classref *) iptr->target, disp); + + if (opt_showdisassemble) + M_NOP; + + M_ILD(REG_ITMP3, REG_PV, disp); + + disp = dseg_adds4(cd, ACC_INTERFACE); + M_ILD(REG_ITMP2, REG_PV, disp); + M_AND(REG_ITMP3, REG_ITMP2, REG_ITMP3); + M_BEQZ(REG_ITMP3, s2 + 1); + } + + /* interface instanceof code */ + + if (!super || (super->flags & ACC_INTERFACE)) { + if (super) { + M_CLR(d); + M_BEQZ(s1, s2); + + } else { + /* If d == REG_ITMP2, then it's destroyed in check code */ + /* above. */ + if (d == REG_ITMP2) + M_CLR(d); + + codegen_addpatchref(cd, mcodeptr, + PATCHER_checkcast_instanceof_interface, + (constant_classref *) iptr->target, 0); + + if (opt_showdisassemble) + M_NOP; + } + + M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl)); + M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength)); + M_LDA(REG_ITMP3, REG_ITMP3, -superindex); + M_BLEZ(REG_ITMP3, 2); + M_ALD(REG_ITMP1, REG_ITMP1, + (s4) (OFFSET(vftbl_t, interfacetable[0]) - + superindex * sizeof(methodptr*))); + M_CMPULT(REG_ZERO, REG_ITMP1, d); /* REG_ITMP1 != 0 */ + + if (!super) + M_BR(s3); + } + + /* class instanceof code */ + + if (!super || !(super->flags & ACC_INTERFACE)) { + disp = dseg_addaddress(cd, supervftbl); + + if (super) { + M_CLR(d); + M_BEQZ(s1, s3); + + } else { + codegen_addpatchref(cd, mcodeptr, + PATCHER_checkcast_instanceof_class, + (constant_classref *) iptr->target, + disp); + + if (opt_showdisassemble) + M_NOP; } - else - panic ("internal error: no inlined array checkcast"); + + M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl)); + M_ALD(REG_ITMP2, REG_PV, disp); +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase); +#endif + M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval)); + M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval)); + M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval)); +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase); +#endif + M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1); + M_CMPULE(REG_ITMP1, REG_ITMP2, d); } - M_INTMOVE(s1, d); store_reg_to_var_int(iptr->dst, d); - break; - - case ICMD_CHECKASIZE: /* ..., size ==> ..., size */ - - var_to_reg_int(s1, src, REG_ITMP1); - M_BLTZ(s1, 0); - codegen_addxcheckarefs(mcodeptr); + } break; case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */ @@ -3573,52 +3615,61 @@ makeactualcall: MCODECHECK((iptr->op1 << 1) + 64); for (s1 = iptr->op1; --s1 >= 0; src = src->prev) { - var_to_reg_int(s2, src, REG_ITMP1); - M_BLTZ(s2, 0); - codegen_addxcheckarefs(mcodeptr); - - /* copy sizes to stack (argument numbers >= INT_ARG_CNT) */ + /* copy SAVEDVAR sizes to stack */ if (src->varkind != ARGVAR) { - M_LST(s2, REG_SP, 8 * (s1 + INT_ARG_CNT)); - } + var_to_reg_int(s2, src, REG_ITMP1); + M_LST(s2, REG_SP, s1 * 8); } + } /* a0 = dimension count */ - ICONST(argintregs[0], iptr->op1); + ICONST(rd->argintregs[0], iptr->op1); + + /* is patcher function set? */ + + if (iptr->target) { + disp = dseg_addaddress(cd, 0); + + codegen_addpatchref(cd, mcodeptr, + (functionptr) iptr->target, iptr->val.a, + disp); + + if (opt_showdisassemble) + M_NOP; + + } else { + disp = dseg_addaddress(cd, iptr->val.a); + } /* a1 = arraydescriptor */ - a = dseg_addaddress(iptr->val.a); - M_ALD(argintregs[1], REG_PV, a); + M_ALD(rd->argintregs[1], REG_PV, disp); /* a2 = pointer to dimensions = stack pointer */ - M_INTMOVE(REG_SP, argintregs[2]); + M_INTMOVE(REG_SP, rd->argintregs[2]); - a = dseg_addaddress((void*) (builtin_nmultianewarray)); - M_ALD(REG_PV, REG_PV, a); + disp = dseg_addaddress(cd, (void *) BUILTIN_multianewarray); + M_ALD(REG_PV, REG_PV, disp); M_JSR(REG_RA, REG_PV); - s1 = (int)((u1*) mcodeptr - mcodebase); - if (s1 <= 32768) - M_LDA (REG_PV, REG_RA, -s1); - else { - s4 ml = -s1, mh = 0; - while (ml < -32768) {ml += 65536; mh--;} - M_LDA(REG_PV, REG_RA, ml); - M_LDAH(REG_PV, REG_PV, mh); - } - s1 = reg_of_var(iptr->dst, REG_RESULT); - M_INTMOVE(REG_RESULT, s1); - store_reg_to_var_int(iptr->dst, s1); - break; + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + /* check for exception before result assignment */ - default: error ("Unknown pseudo command: %d", iptr->opc); - - + M_BEQZ(REG_RESULT, 0); + codegen_addxexceptionrefs(cd, mcodeptr); + d = reg_of_var(rd, iptr->dst, REG_RESULT); + M_INTMOVE(REG_RESULT, d); + store_reg_to_var_int(iptr->dst, d); + break; + + default: + throw_cacao_exception_exit(string_java_lang_InternalError, + "Unknown ICMD %d", iptr->opc); } /* switch */ } /* for instruction */ @@ -3628,26 +3679,29 @@ makeactualcall: src = bptr->outstack; len = bptr->outdepth; MCODECHECK(64+len); +#ifdef LSRA + if (!opt_lsra) +#endif while (src) { len--; if ((src->varkind != STACKVAR)) { s2 = src->type; if (IS_FLT_DBL_TYPE(s2)) { var_to_reg_flt(s1, src, REG_FTMP1); - if (!(interfaces[len][s2].flags & INMEMORY)) { - M_FLTMOVE(s1,interfaces[len][s2].regoff); + if (!(rd->interfaces[len][s2].flags & INMEMORY)) { + M_FLTMOVE(s1,rd->interfaces[len][s2].regoff); } else { - M_DST(s1, REG_SP, 8 * interfaces[len][s2].regoff); + M_DST(s1, REG_SP, 8 * rd->interfaces[len][s2].regoff); } } else { var_to_reg_int(s1, src, REG_ITMP1); - if (!(interfaces[len][s2].flags & INMEMORY)) { - M_INTMOVE(s1,interfaces[len][s2].regoff); + if (!(rd->interfaces[len][s2].flags & INMEMORY)) { + M_INTMOVE(s1,rd->interfaces[len][s2].regoff); } else { - M_LST(s1, REG_SP, 8 * interfaces[len][s2].regoff); + M_LST(s1, REG_SP, 8 * rd->interfaces[len][s2].regoff); } } } @@ -3656,250 +3710,453 @@ makeactualcall: } /* if (bptr -> flags >= BBREACHED) */ } /* for basic block */ - /* bptr -> mpc = (int)((u1*) mcodeptr - mcodebase); */ + codegen_createlinenumbertable(cd); { - /* generate bound check stubs */ s4 *xcodeptr = NULL; - - for (; xboundrefs != NULL; xboundrefs = xboundrefs->next) { - if ((exceptiontablelength == 0) && (xcodeptr != NULL)) { - gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, - xboundrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - (4 + 4)); + branchref *bref; + + /* generate ArithmeticException stubs */ + + for (bref = cd->xdivrefs; bref != NULL; bref = bref->next) { + if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) { + gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4); continue; } + gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1 *) mcodeptr - cd->mcodebase); - gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, - xboundrefs->branchpos, (u1*) mcodeptr - mcodebase); - - MCODECHECK(8); + MCODECHECK(16); - M_MOV(xboundrefs->reg, REG_ITMP1); - M_LDA(REG_ITMP2_XPC, REG_PV, xboundrefs->branchpos - 4); + M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4); if (xcodeptr != NULL) { - M_BR(xcodeptr - mcodeptr - 1); + disp = xcodeptr - mcodeptr - 1; + M_BR(disp); } else { xcodeptr = mcodeptr; - M_LSUB_IMM(REG_SP, 1 * 8, REG_SP); - M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8); + M_MOV(REG_PV, rd->argintregs[0]); + M_MOV(REG_SP, rd->argintregs[1]); + M_ALD(rd->argintregs[2], + REG_SP, parentargs_base * 8 - SIZEOF_VOID_P); + M_MOV(REG_ITMP2_XPC, rd->argintregs[3]); - a = dseg_addaddress(string_java_lang_ArrayIndexOutOfBoundsException); - M_ALD(argintregs[0], REG_PV, a); - M_MOV(REG_ITMP1, argintregs[1]); + M_LDA(REG_SP, REG_SP, -1 * 8); + M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8); - a = dseg_addaddress(new_exception_int); - M_ALD(REG_PV, REG_PV, a); + disp = dseg_addaddress(cd, stacktrace_inline_arithmeticexception); + M_ALD(REG_PV, REG_PV, disp); M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); - /* recompute pv */ - s1 = (s4) ((u1 *) mcodeptr - mcodebase); - if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1); - else { - s4 ml = -s1, mh = 0; - while (ml < -32768) { ml += 65536; mh--; } - M_LDA(REG_PV, REG_RA, ml); - M_LDAH(REG_PV, REG_PV, mh); - } + M_MOV(REG_RESULT, REG_ITMP1_XPTR); + + M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8); + M_LDA(REG_SP, REG_SP, 1 * 8); + + disp = dseg_addaddress(cd, asm_handle_exception); + M_ALD(REG_ITMP3, REG_PV, disp); + M_JMP(REG_ZERO, REG_ITMP3); + } + } + + /* generate ArrayIndexOutOfBoundsException stubs */ + + xcodeptr = NULL; + + for (bref = cd->xboundrefs; bref != NULL; bref = bref->next) { + gen_resolvebranch((u1*) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1*) mcodeptr - cd->mcodebase); + + MCODECHECK(18); + + /* move index register into REG_ITMP1 */ + + M_MOV(bref->reg, REG_ITMP1); + M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4); + + if (xcodeptr != NULL) { + disp = xcodeptr - mcodeptr - 1; + M_BR(disp); + + } else { + xcodeptr = mcodeptr; + + M_MOV(REG_PV, rd->argintregs[0]); + M_MOV(REG_SP, rd->argintregs[1]); + + if (m->isleafmethod) + M_MOV(REG_RA, rd->argintregs[2]); + else + M_ALD(rd->argintregs[2], + REG_SP, parentargs_base * 8 - SIZEOF_VOID_P); + + M_MOV(REG_ITMP2_XPC, rd->argintregs[3]); + M_MOV(REG_ITMP1, rd->argintregs[4]); + + M_LDA(REG_SP, REG_SP, -2 * 8); + M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8); + + if (m->isleafmethod) + M_AST(REG_RA, REG_SP, 1 * 8); + + disp = dseg_addaddress(cd, stacktrace_inline_arrayindexoutofboundsexception); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); M_MOV(REG_RESULT, REG_ITMP1_XPTR); - M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8); - M_LADD_IMM(REG_SP, 1 * 8, REG_SP); + if (m->isleafmethod) + M_ALD(REG_RA, REG_SP, 1 * 8); - a = dseg_addaddress(asm_handle_exception); - M_ALD(REG_ITMP3, REG_PV, a); + M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8); + M_LDA(REG_SP, REG_SP, 2 * 8); + disp = dseg_addaddress(cd, asm_handle_exception); + M_ALD(REG_ITMP3, REG_PV, disp); M_JMP(REG_ZERO, REG_ITMP3); } } - /* generate negative array size check stubs */ + /* generate ArrayStoreException stubs */ xcodeptr = NULL; - for (; xcheckarefs != NULL; xcheckarefs = xcheckarefs->next) { - if ((exceptiontablelength == 0) && (xcodeptr != NULL)) { - gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, - xcheckarefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4); + for (bref = cd->xstorerefs; bref != NULL; bref = bref->next) { + if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) { + gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4); continue; } - gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, - xcheckarefs->branchpos, (u1*) mcodeptr - mcodebase); + gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1 *) mcodeptr - cd->mcodebase); - MCODECHECK(8); + MCODECHECK(16); - M_LDA(REG_ITMP2_XPC, REG_PV, xcheckarefs->branchpos - 4); + M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4); if (xcodeptr != NULL) { - M_BR(xcodeptr - mcodeptr - 1); + disp = xcodeptr - mcodeptr - 1; + M_BR(disp); } else { xcodeptr = mcodeptr; - M_LSUB_IMM(REG_SP, 1 * 8, REG_SP); - M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8); + M_MOV(REG_PV, rd->argintregs[0]); + M_MOV(REG_SP, rd->argintregs[1]); + M_ALD(rd->argintregs[2], + REG_SP, parentargs_base * 8 - SIZEOF_VOID_P); + M_MOV(REG_ITMP2_XPC, rd->argintregs[3]); - a = dseg_addaddress(string_java_lang_NegativeArraySizeException); - M_ALD(argintregs[0], REG_PV, a); + M_LDA(REG_SP, REG_SP, -1 * 8); + M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8); - a = dseg_addaddress(new_exception); - M_ALD(REG_PV, REG_PV, a); + disp = dseg_addaddress(cd, stacktrace_inline_arraystoreexception); + M_ALD(REG_PV, REG_PV, disp); M_JSR(REG_RA, REG_PV); - - /* recompute pv */ - s1 = (s4) ((u1 *) mcodeptr - mcodebase); - if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1); - else { - s4 ml = -s1, mh = 0; - while (ml < -32768) { ml += 65536; mh--; } - M_LDA(REG_PV, REG_RA, ml); - M_LDAH(REG_PV, REG_PV, mh); - } + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); M_MOV(REG_RESULT, REG_ITMP1_XPTR); - M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8); - M_LADD_IMM(REG_SP, 1 * 8, REG_SP); - - a = dseg_addaddress(asm_handle_exception); - M_ALD(REG_ITMP3, REG_PV, a); + M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8); + M_LDA(REG_SP, REG_SP, 1 * 8); + disp = dseg_addaddress(cd, asm_handle_exception); + M_ALD(REG_ITMP3, REG_PV, disp); M_JMP(REG_ZERO, REG_ITMP3); } } - /* generate cast check stubs */ + /* generate ClassCastException stubs */ xcodeptr = NULL; - for (; xcastrefs != NULL; xcastrefs = xcastrefs->next) { - if ((exceptiontablelength == 0) && (xcodeptr != NULL)) { - gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, - xcastrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4); + for (bref = cd->xcastrefs; bref != NULL; bref = bref->next) { + if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) { + gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4); continue; } - gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, - xcastrefs->branchpos, (u1*) mcodeptr - mcodebase); + gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1 *) mcodeptr - cd->mcodebase); - MCODECHECK(8); + MCODECHECK(18); - M_LDA(REG_ITMP2_XPC, REG_PV, xcastrefs->branchpos - 4); + M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4); if (xcodeptr != NULL) { - M_BR(xcodeptr - mcodeptr - 1); + disp = xcodeptr - mcodeptr - 1; + M_BR(disp); } else { xcodeptr = mcodeptr; - M_LSUB_IMM(REG_SP, 1 * 8, REG_SP); - M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8); + M_MOV(REG_PV, rd->argintregs[0]); + M_MOV(REG_SP, rd->argintregs[1]); - a = dseg_addaddress(string_java_lang_ClassCastException); - M_ALD(argintregs[0], REG_PV, a); + if (m->isleafmethod) + M_MOV(REG_RA, rd->argintregs[2]); + else + M_ALD(rd->argintregs[2], + REG_SP, parentargs_base * 8 - SIZEOF_VOID_P); - a = dseg_addaddress(new_exception); - M_ALD(REG_PV, REG_PV, a); - M_JSR(REG_RA, REG_PV); + M_MOV(REG_ITMP2_XPC, rd->argintregs[3]); - /* recompute pv */ - s1 = (s4) ((u1 *) mcodeptr - mcodebase); - if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1); - else { - s4 ml = -s1, mh = 0; - while (ml < -32768) { ml += 65536; mh--; } - M_LDA(REG_PV, REG_RA, ml); - M_LDAH(REG_PV, REG_PV, mh); - } + M_LDA(REG_SP, REG_SP, -2 * 8); + M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8); + + if (m->isleafmethod) + M_AST(REG_RA, REG_SP, 1 * 8); + + disp = dseg_addaddress(cd, stacktrace_inline_classcastexception); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); M_MOV(REG_RESULT, REG_ITMP1_XPTR); - M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8); - M_LADD_IMM(REG_SP, 1 * 8, REG_SP); + if (m->isleafmethod) + M_ALD(REG_RA, REG_SP, 1 * 8); - a = dseg_addaddress(asm_handle_exception); - M_ALD(REG_ITMP3, REG_PV, a); + M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8); + M_LDA(REG_SP, REG_SP, 2 * 8); + disp = dseg_addaddress(cd, asm_handle_exception); + M_ALD(REG_ITMP3, REG_PV, disp); M_JMP(REG_ZERO, REG_ITMP3); } } - /* generate null pointer check stubs */ + /* generate NullPointerException stubs */ xcodeptr = NULL; - for (; xnullrefs != NULL; xnullrefs = xnullrefs->next) { - if ((exceptiontablelength == 0) && (xcodeptr != NULL)) { - gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, - xnullrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4); + for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) { + if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) { + gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4); continue; } - gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, - xnullrefs->branchpos, (u1*) mcodeptr - mcodebase); + gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1 *) mcodeptr - cd->mcodebase); - MCODECHECK(8); + MCODECHECK(18); - M_LDA(REG_ITMP2_XPC, REG_PV, xnullrefs->branchpos - 4); + M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4); if (xcodeptr != NULL) { - M_BR(xcodeptr - mcodeptr - 1); + disp = xcodeptr - mcodeptr - 1; + M_BR(disp); } else { xcodeptr = mcodeptr; - M_LSUB_IMM(REG_SP, 1 * 8, REG_SP); - M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8); + M_MOV(REG_PV, rd->argintregs[0]); + M_MOV(REG_SP, rd->argintregs[1]); + + if (m->isleafmethod) + M_MOV(REG_RA, rd->argintregs[2]); + else + M_ALD(rd->argintregs[2], + REG_SP, parentargs_base * 8 - SIZEOF_VOID_P); + + M_MOV(REG_ITMP2_XPC, rd->argintregs[3]); - a = dseg_addaddress(string_java_lang_NullPointerException); - M_ALD(argintregs[0], REG_PV, a); + M_LDA(REG_SP, REG_SP, -2 * 8); + M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8); - a = dseg_addaddress(new_exception); - M_ALD(REG_PV, REG_PV, a); + if (m->isleafmethod) + M_AST(REG_RA, REG_SP, 1 * 8); + + disp = dseg_addaddress(cd, stacktrace_inline_nullpointerexception); + M_ALD(REG_PV, REG_PV, disp); M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); - /* recompute pv */ - s1 = (s4) ((u1 *) mcodeptr - mcodebase); - if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1); - else { - s4 ml = -s1, mh = 0; - while (ml < -32768) { ml += 65536; mh--; } - M_LDA(REG_PV, REG_RA, ml); - M_LDAH(REG_PV, REG_PV, mh); - } + M_MOV(REG_RESULT, REG_ITMP1_XPTR); + + if (m->isleafmethod) + M_ALD(REG_RA, REG_SP, 1 * 8); + + M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8); + M_LDA(REG_SP, REG_SP, 2 * 8); + + disp = dseg_addaddress(cd, asm_handle_exception); + M_ALD(REG_ITMP3, REG_PV, disp); + M_JMP(REG_ZERO, REG_ITMP3); + } + } + + /* generate exception check stubs */ + + xcodeptr = NULL; + + for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) { + if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) { + gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4); + continue; + } + + gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, + bref->branchpos, + (u1 *) mcodeptr - cd->mcodebase); + + MCODECHECK(16); + + M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4); + + if (xcodeptr != NULL) { + disp = xcodeptr - mcodeptr - 1; + M_BR(disp); + + } else { + xcodeptr = mcodeptr; + + M_MOV(REG_PV, rd->argintregs[0]); + M_MOV(REG_SP, rd->argintregs[1]); + M_ALD(rd->argintregs[2], + REG_SP, parentargs_base * 8 - SIZEOF_VOID_P); + M_MOV(REG_ITMP2_XPC, rd->argintregs[3]); + + M_LDA(REG_SP, REG_SP, -1 * 8); + M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8); + + disp = dseg_addaddress(cd, stacktrace_inline_fillInStackTrace); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); M_MOV(REG_RESULT, REG_ITMP1_XPTR); - M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8); - M_LADD_IMM(REG_SP, 1 * 8, REG_SP); + M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8); + M_LDA(REG_SP, REG_SP, 1 * 8); + + disp = dseg_addaddress(cd, asm_handle_exception); + M_ALD(REG_ITMP3, REG_PV, disp); + M_JMP(REG_ZERO, REG_ITMP3); + } + } + + /* generate patcher stub call code */ + + { + patchref *pref; + u4 mcode; + s4 *tmpmcodeptr; + + for (pref = cd->patchrefs; pref != NULL; pref = pref->next) { + /* check code segment size */ + + MCODECHECK(30); + + /* Get machine code which is patched back in later. The call is */ + /* 1 instruction word long. */ + + xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos); + mcode = *xcodeptr; + + /* patch in the call to call the following code (done at compile */ + /* time) */ + + tmpmcodeptr = mcodeptr; /* save current mcodeptr */ + mcodeptr = xcodeptr; /* set mcodeptr to patch position */ + + M_BSR(REG_ITMP3, tmpmcodeptr - (xcodeptr + 1)); + + mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */ + + /* create stack frame */ + + M_LSUB_IMM(REG_SP, 6 * 8, REG_SP); + + /* move return address onto stack */ + + M_AST(REG_ITMP3, REG_SP, 5 * 8); + + /* move pointer to java_objectheader onto stack */ + +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + /* create a virtual java_objectheader */ + + (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */ + disp = dseg_addaddress(cd, NULL); /* vftbl */ - a = dseg_addaddress(asm_handle_exception); - M_ALD(REG_ITMP3, REG_PV, a); + M_LDA(REG_ITMP3, REG_PV, disp); + M_AST(REG_ITMP3, REG_SP, 4 * 8); +#else + M_AST(REG_ZERO, REG_SP, 4 * 8); +#endif + + /* move machine code onto stack */ + + disp = dseg_adds4(cd, mcode); + M_ILD(REG_ITMP3, REG_PV, disp); + M_IST(REG_ITMP3, REG_SP, 3 * 8); + + /* move class/method/field reference onto stack */ + + disp = dseg_addaddress(cd, pref->ref); + M_ALD(REG_ITMP3, REG_PV, disp); + M_AST(REG_ITMP3, REG_SP, 2 * 8); + + /* move data segment displacement onto stack */ + + disp = dseg_adds4(cd, pref->disp); + M_ILD(REG_ITMP3, REG_PV, disp); + M_IST(REG_ITMP3, REG_SP, 1 * 8); + /* move patcher function pointer onto stack */ + + disp = dseg_addaddress(cd, pref->patcher); + M_ALD(REG_ITMP3, REG_PV, disp); + M_AST(REG_ITMP3, REG_SP, 0 * 8); + + disp = dseg_addaddress(cd, asm_wrapper_patcher); + M_ALD(REG_ITMP3, REG_PV, disp); M_JMP(REG_ZERO, REG_ITMP3); } } } - codegen_finish((int)((u1*) mcodeptr - mcodebase)); + codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase)); } -/* function createcompilerstub ************************************************* +/* createcompilerstub ********************************************************** - creates a stub routine which calls the compiler + Creates a stub routine which calls the compiler. *******************************************************************************/ #define COMPSTUBSIZE 3 -u1 *createcompilerstub(methodinfo *m) +functionptr createcompilerstub(methodinfo *m) { u8 *s = CNEW(u8, COMPSTUBSIZE); /* memory to hold the stub */ s4 *mcodeptr = (s4 *) s; /* code generation pointer */ @@ -3908,262 +4165,428 @@ u1 *createcompilerstub(methodinfo *m) M_ALD(REG_PV, REG_PV, 16); /* load pointer to the compiler */ M_JMP(0, REG_PV); /* jump to the compiler, return address in reg 0 is used as method pointer */ - s[1] = (u8) m; /* literals to be adressed */ - s[2] = (u8) asm_call_jit_compiler; /* jump directly via PV from above */ + s[1] = (ptrint) m; /* literals to be adressed */ + s[2] = (ptrint) asm_call_jit_compiler; /* jump directly via PV from above */ -#ifdef STATISTICS - count_cstub_len += COMPSTUBSIZE * 8; +#if defined(STATISTICS) + if (opt_stat) + count_cstub_len += COMPSTUBSIZE * 8; #endif - return (u1 *) s; + return (functionptr) s; } -/* function removecompilerstub ************************************************* +/* createnativestub ************************************************************ - deletes a compilerstub from memory (simply by freeing it) + Creates a stub routine which calls a native method. *******************************************************************************/ -void removecompilerstub(u1 *stub) +functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd, + registerdata *rd, methoddesc *nmd) { - CFREE(stub, COMPSTUBSIZE * 8); -} + s4 *mcodeptr; /* code generation pointer */ + s4 stackframesize; /* size of stackframe if needed */ + methoddesc *md; + s4 nativeparams; + s4 i, j; /* count variables */ + s4 t; + s4 s1, s2, disp; + s4 funcdisp; /* displacement of the function */ + /* initialize variables */ -/* function: createnativestub ************************************************** + md = m->parseddesc; + nativeparams = (m->flags & ACC_STATIC) ? 2 : 1; - creates a stub routine which calls a native method -*******************************************************************************/ + /* calculate stack frame size */ -#define NATIVESTUBSIZE 44 -#define NATIVEVERBOSESIZE 39 + 13 -#define NATIVESTUBOFFSET 8 + stackframesize = + 1 + /* return address */ + sizeof(stackframeinfo) / SIZEOF_VOID_P + + 1 + /* methodinfo for call trace */ + (md->paramcount > INT_ARG_CNT ? INT_ARG_CNT : md->paramcount) + + nmd->memuse; -u1 *createnativestub(functionptr f, methodinfo *m) -{ - u8 *s; /* memory pointer to hold the stub */ - u8 *cs; - s4 *mcodeptr; /* code generation pointer */ - int stackframesize = 0; /* size of stackframe if needed */ - int disp; - int stubsize; - - reg_init(); - descriptor2types(m); /* set paramcount and paramtypes */ - - stubsize = runverbose ? NATIVESTUBSIZE + NATIVEVERBOSESIZE : NATIVESTUBSIZE; - s = CNEW(u8, stubsize); /* memory to hold the stub */ - cs = s + NATIVESTUBOFFSET; - mcodeptr = (s4 *) (cs); /* code generation pointer */ - - *(cs-1) = (u8) f; /* address of native method */ - *(cs-2) = (u8) (&_exceptionptr); /* address of exceptionptr */ - *(cs-3) = (u8) asm_handle_nat_exception; /* addr of asm exception handler */ - *(cs-4) = (u8) (&env); /* addr of jni_environement */ - *(cs-5) = (u8) builtin_trace_args; - *(cs-6) = (u8) m; - *(cs-7) = (u8) builtin_displaymethodstop; - *(cs-8) = (u8) m->class; - - M_LDA(REG_SP, REG_SP, -8); /* build up stackframe */ - M_AST(REG_RA, REG_SP, 0); /* store return address */ - - /* max. 39 instructions */ - if (runverbose) { - int p; - int t; - M_LDA(REG_SP, REG_SP, -(14 * 8)); - M_AST(REG_RA, REG_SP, 1 * 8); + /* create method header */ + + (void) dseg_addaddress(cd, m); /* MethodPointer */ + (void) dseg_adds4(cd, stackframesize * 8); /* FrameSize */ + (void) dseg_adds4(cd, 0); /* IsSync */ + (void) dseg_adds4(cd, 0); /* IsLeaf */ + (void) dseg_adds4(cd, 0); /* IntSave */ + (void) dseg_adds4(cd, 0); /* FltSave */ + (void) dseg_addlinenumbertablesize(cd); + (void) dseg_adds4(cd, 0); /* ExTableSize */ + + + /* initialize mcode variables */ + + mcodeptr = (s4 *) cd->mcodebase; + cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize); + + + /* generate stub code */ + + M_LDA(REG_SP, REG_SP, -stackframesize * 8); + M_AST(REG_RA, REG_SP, stackframesize * 8 - SIZEOF_VOID_P); + + + /* call trace function */ + + if (runverbose) { /* save integer argument registers */ - for (p = 0; p < m->paramcount && p < INT_ARG_CNT; p++) { - M_LST(argintregs[p], REG_SP, (2 + p) * 8); + + for (i = 0, j = 1; i < md->paramcount && i < INT_ARG_CNT; i++) { + if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) { + M_LST(rd->argintregs[i], REG_SP, j * 8); + j++; + } } /* save and copy float arguments into integer registers */ - for (p = 0; p < m->paramcount && p < FLT_ARG_CNT; p++) { - t = m->paramtypes[p]; + + for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) { + t = md->paramtypes[i].type; if (IS_FLT_DBL_TYPE(t)) { if (IS_2_WORD_TYPE(t)) { - M_DST(argfltregs[p], REG_SP, (8 + p) * 8); - M_LLD(argintregs[p], REG_SP, (8 + p) * 8); - + M_DST(rd->argfltregs[i], REG_SP, j * 8); + M_LLD(rd->argintregs[i], REG_SP, j * 8); } else { - M_FST(argfltregs[p], REG_SP, (8 + p) * 8); - M_ILD(argintregs[p], REG_SP, (8 + p) * 8); + M_FST(rd->argfltregs[i], REG_SP, j * 8); + M_ILD(rd->argintregs[i], REG_SP, j * 8); } - - } else { - M_DST(argfltregs[p], REG_SP, (8 + p) * 8); + j++; } } - M_ALD(REG_ITMP1, REG_PV, -6 * 8); - M_AST(REG_ITMP1, REG_SP, 0); - M_ALD(REG_PV, REG_PV, -5 * 8); + disp = dseg_addaddress(cd, m); + M_ALD(REG_ITMP1, REG_PV, disp); + M_AST(REG_ITMP1, REG_SP, 0 * 8); + disp = dseg_addaddress(cd, builtin_trace_args); + M_ALD(REG_PV, REG_PV, disp); M_JSR(REG_RA, REG_PV); - disp = -(int) (mcodeptr - (s4*) cs) * 4; - M_LDA(REG_PV, REG_RA, disp); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); - for (p = 0; p < m->paramcount && p < INT_ARG_CNT; p++) { - M_LLD(argintregs[p], REG_SP, (2 + p) * 8); + for (i = 0, j = 1; i < md->paramcount && i < INT_ARG_CNT; i++) { + if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) { + M_LLD(rd->argintregs[i], REG_SP, j * 8); + j++; + } } - for (p = 0; p < m->paramcount && p < FLT_ARG_CNT; p++) { - t = m->paramtypes[p]; + for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) { + t = md->paramtypes[i].type; if (IS_FLT_DBL_TYPE(t)) { if (IS_2_WORD_TYPE(t)) { - M_DLD(argfltregs[p], REG_SP, (8 + p) * 8); - + M_DLD(rd->argfltregs[i], REG_SP, j * 8); } else { - M_FLD(argfltregs[p], REG_SP, (8 + p) * 8); + M_FLD(rd->argfltregs[i], REG_SP, j * 8); } - - } else { - M_DLD(argfltregs[p], REG_SP, (8 + p) * 8); + j++; } } + } - M_ALD(REG_RA, REG_SP, 1 * 8); - M_LDA(REG_SP, REG_SP, 14 * 8); + /* get function address (this must happen before the stackframeinfo) */ + + funcdisp = dseg_addaddress(cd, f); + +#if !defined(ENABLE_STATICVM) + if (f == NULL) { + codegen_addpatchref(cd, mcodeptr, PATCHER_resolve_native, m, funcdisp); + + if (opt_showdisassemble) + M_NOP; } +#endif + + + /* save integer and float argument registers */ - /* save argument registers on stack -- if we have to */ - if ((m->flags & ACC_STATIC && m->paramcount > (INT_ARG_CNT - 2)) || m->paramcount > (INT_ARG_CNT - 1)) { - int i; - int paramshiftcnt = (m->flags & ACC_STATIC) ? 2 : 1; - int stackparamcnt = (m->paramcount > INT_ARG_CNT) ? m->paramcount - INT_ARG_CNT : 0; + for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) { + if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) { + M_LST(rd->argintregs[i], REG_SP, j * 8); + j++; + } + } - stackframesize = stackparamcnt + paramshiftcnt; + for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) { + if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) { + M_DST(rd->argfltregs[i], REG_SP, j * 8); + j++; + } + } - M_LDA(REG_SP, REG_SP, -stackframesize * 8); + /* create native stackframe info */ + + M_AADD_IMM(REG_SP, + stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo), + rd->argintregs[0]); + M_MOV(REG_PV, rd->argintregs[1]); + M_AADD_IMM(REG_SP, stackframesize * 8, rd->argintregs[2]); + M_ALD(rd->argintregs[3], REG_SP, stackframesize * 8 - SIZEOF_VOID_P); + disp = dseg_addaddress(cd, stacktrace_create_native_stackframeinfo); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + + /* restore integer and float argument registers */ + + for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) { + if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) { + M_LLD(rd->argintregs[i], REG_SP, j * 8); + j++; + } + } - /* copy stack arguments into new stack frame -- if any */ - for (i = 0; i < stackparamcnt; i++) { - M_LLD(REG_ITMP1, REG_SP, (stackparamcnt + 1 + i) * 8); - M_LST(REG_ITMP1, REG_SP, (paramshiftcnt + i) * 8); + for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) { + if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) { + M_DLD(rd->argfltregs[i], REG_SP, j * 8); + j++; } + } - if (m->flags & ACC_STATIC) { - if (IS_FLT_DBL_TYPE(m->paramtypes[5])) { - M_DST(argfltregs[5], REG_SP, 1 * 8); - } else { - M_LST(argintregs[5], REG_SP, 1 * 8); - } - if (IS_FLT_DBL_TYPE(m->paramtypes[4])) { - M_DST(argfltregs[4], REG_SP, 0 * 8); + /* copy or spill arguments to new locations */ + + for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) { + t = md->paramtypes[i].type; + + if (IS_INT_LNG_TYPE(t)) { + if (!md->params[i].inmemory) { + s1 = rd->argintregs[md->params[i].regoff]; + + if (!nmd->params[j].inmemory) { + s2 = rd->argintregs[nmd->params[j].regoff]; + M_INTMOVE(s1, s2); + + } else { + s2 = nmd->params[j].regoff; + M_LST(s1, REG_SP, s2 * 8); + } + } else { - M_LST(argintregs[4], REG_SP, 0 * 8); + s1 = md->params[i].regoff + stackframesize; + s2 = nmd->params[j].regoff; + M_LLD(REG_ITMP1, REG_SP, s1 * 8); + M_LST(REG_ITMP1, REG_SP, s2 * 8); } } else { - if (IS_FLT_DBL_TYPE(m->paramtypes[5])) { - M_DST(argfltregs[5], REG_SP, 0 * 8); + if (!md->params[i].inmemory) { + s1 = rd->argfltregs[md->params[i].regoff]; + + if (!nmd->params[j].inmemory) { + s2 = rd->argfltregs[nmd->params[j].regoff]; + M_FLTMOVE(s1, s2); + + } else { + s2 = nmd->params[j].regoff; + if (IS_2_WORD_TYPE(t)) + M_DST(s1, REG_SP, s2 * 8); + else + M_FST(s1, REG_SP, s2 * 8); + } + } else { - M_LST(argintregs[5], REG_SP, 0 * 8); + s1 = md->params[i].regoff + stackframesize; + s2 = nmd->params[j].regoff; + M_DLD(REG_FTMP1, REG_SP, s1 * 8); + if (IS_2_WORD_TYPE(t)) + M_DST(REG_FTMP1, REG_SP, s2 * 8); + else + M_FST(REG_FTMP1, REG_SP, s2 * 8); } } } + /* put class into second argument register */ + if (m->flags & ACC_STATIC) { - M_MOV(argintregs[3], argintregs[5]); - M_MOV(argintregs[2], argintregs[4]); - M_MOV(argintregs[1], argintregs[3]); - M_MOV(argintregs[0], argintregs[2]); - M_FMOV(argfltregs[3], argfltregs[5]); - M_FMOV(argfltregs[2], argfltregs[4]); - M_FMOV(argfltregs[1], argfltregs[3]); - M_FMOV(argfltregs[0], argfltregs[2]); - - /* put class into second argument register */ - M_ALD(argintregs[1], REG_PV, -8 * 8); - - } else { - M_MOV(argintregs[4], argintregs[5]); - M_MOV(argintregs[3], argintregs[4]); - M_MOV(argintregs[2], argintregs[3]); - M_MOV(argintregs[1], argintregs[2]); - M_MOV(argintregs[0], argintregs[1]); - M_FMOV(argfltregs[4], argfltregs[5]); - M_FMOV(argfltregs[3], argfltregs[4]); - M_FMOV(argfltregs[2], argfltregs[3]); - M_FMOV(argfltregs[1], argfltregs[2]); - M_FMOV(argfltregs[0], argfltregs[1]); + disp = dseg_addaddress(cd, m->class); + M_ALD(rd->argintregs[1], REG_PV, disp); } /* put env into first argument register */ - M_ALD(argintregs[0], REG_PV, -4 * 8); - M_ALD(REG_PV, REG_PV, -1 * 8); /* load adress of native method */ + disp = dseg_addaddress(cd, &env); + M_ALD(rd->argintregs[0], REG_PV, disp); + + /* do the native function call */ + + M_ALD(REG_PV, REG_PV, funcdisp); M_JSR(REG_RA, REG_PV); /* call native method */ - disp = -(int) (mcodeptr - (s4*) cs) * 4; - M_LDA(REG_PV, REG_RA, disp); /* recompute pv from ra */ + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); /* recompute pv from ra */ - /* remove stackframe if there is one */ - if (stackframesize) { - M_LDA(REG_SP, REG_SP, stackframesize * 8); - } + /* save return value */ - /* 13 instructions */ - if (runverbose) { - M_LDA(REG_SP, REG_SP, -(2 * 8)); - M_ALD(argintregs[0], REG_PV, -6 * 8); /* load method adress */ + if (IS_INT_LNG_TYPE(md->returntype.type)) M_LST(REG_RESULT, REG_SP, 0 * 8); - M_DST(REG_FRESULT, REG_SP, 1 * 8); - M_MOV(REG_RESULT, argintregs[1]); - M_FMOV(REG_FRESULT, argfltregs[2]); - M_FMOV(REG_FRESULT, argfltregs[3]); - M_ALD(REG_PV, REG_PV, -7 * 8); /* builtin_displaymethodstop */ + else + M_DST(REG_FRESULT, REG_SP, 0 * 8); + + /* remove native stackframe info */ + + M_AADD_IMM(REG_SP, + stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo), + rd->argintregs[0]); + disp = dseg_addaddress(cd, stacktrace_remove_stackframeinfo); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + + /* call finished trace */ + + if (runverbose) { + disp = dseg_addaddress(cd, m); + M_ALD(rd->argintregs[0], REG_PV, disp); + + M_MOV(REG_RESULT, rd->argintregs[1]); + M_FMOV(REG_FRESULT, rd->argfltregs[2]); + M_FMOV(REG_FRESULT, rd->argfltregs[3]); + + disp = dseg_addaddress(cd, builtin_displaymethodstop); + M_ALD(REG_PV, REG_PV, disp); M_JSR(REG_RA, REG_PV); - disp = -(int) (mcodeptr - (s4*) cs) * 4; - M_LDA(REG_PV, REG_RA, disp); - M_LLD(REG_RESULT, REG_SP, 0 * 8); - M_DLD(REG_FRESULT, REG_SP, 1 * 8); - M_LDA(REG_SP, REG_SP, 2 * 8); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); } - M_ALD(REG_ITMP3, REG_PV, -2 * 8); /* get address of exceptionptr */ + /* check for exception */ + +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + disp = dseg_addaddress(cd, builtin_get_exceptionptrptr); + M_ALD(REG_PV, REG_PV, disp); + M_JSR(REG_RA, REG_PV); + disp = (s4) ((u1 *) mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + M_MOV(REG_RESULT, REG_ITMP3); +#else + disp = dseg_addaddress(cd, &_exceptionptr); + M_ALD(REG_RESULT, REG_PV, disp); /* get address of exceptionptr */ +#endif M_ALD(REG_ITMP1, REG_ITMP3, 0); /* load exception into reg. itmp1 */ + + /* restore return value */ + + if (IS_INT_LNG_TYPE(md->returntype.type)) + M_LLD(REG_RESULT, REG_SP, 0 * 8); + else + M_DLD(REG_FRESULT, REG_SP, 0 * 8); + M_BNEZ(REG_ITMP1, 3); /* if no exception then return */ - M_ALD(REG_RA, REG_SP, 0); /* load return address */ - M_LDA(REG_SP, REG_SP, 8); /* remove stackframe */ + M_ALD(REG_RA, REG_SP, (stackframesize - 1) * 8); /* load return address */ + M_LDA(REG_SP, REG_SP, stackframesize * 8); M_RET(REG_ZERO, REG_RA); /* return to caller */ + /* handle exception */ + M_AST(REG_ZERO, REG_ITMP3, 0); /* store NULL into exceptionptr */ - M_ALD(REG_RA, REG_SP, 0); /* load return address */ - M_LDA(REG_SP, REG_SP, 8); /* remove stackframe */ + M_ALD(REG_RA, REG_SP, (stackframesize - 1) * 8); /* load return address */ M_LDA(REG_ITMP2, REG_RA, -4); /* move fault address into reg. itmp2 */ - M_ALD(REG_ITMP3, REG_PV, -3 * 8); /* load asm exception handler address */ + + M_LDA(REG_SP, REG_SP, stackframesize * 8); + + disp = dseg_addaddress(cd, asm_handle_nat_exception); + M_ALD(REG_ITMP3, REG_PV, disp); /* load asm exception handler address */ M_JMP(REG_ZERO, REG_ITMP3); /* jump to asm exception handler */ -#if 0 - dolog_plain("stubsize: %d (for %d params)\n", (int) (mcodeptr - (s4*) s), m->paramcount); -#endif -#ifdef STATISTICS - count_nstub_len += NATIVESTUBSIZE * 8; + /* process patcher calls **************************************************/ + + { + patchref *pref; + s4 *xcodeptr; + u4 mcode; + s4 *tmpmcodeptr; + + /* there can only be one ref entry */ + pref = cd->patchrefs; + + for (pref = cd->patchrefs; pref != NULL; pref = pref->next) { + /* Get machine code which is patched back in later. The call is */ + /* 1 instruction word long. */ + + xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos); + mcode = (u4) *xcodeptr; + + /* patch in the call to call the following code (done at compile */ + /* time) */ + + tmpmcodeptr = mcodeptr; /* save current mcodeptr */ + mcodeptr = xcodeptr; /* set mcodeptr to patch position */ + + M_BSR(REG_ITMP3, tmpmcodeptr - (xcodeptr + 1)); + + mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */ + + /* create stack frame */ + + M_LSUB_IMM(REG_SP, 6 * 8, REG_SP); + + /* move return address onto stack */ + + M_AST(REG_ITMP3, REG_SP, 5 * 8); + + /* move pointer to java_objectheader onto stack */ + +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + /* create a virtual java_objectheader */ + + (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */ + disp = dseg_addaddress(cd, NULL); /* vftbl */ + + M_LDA(REG_ITMP3, REG_PV, disp); + M_AST(REG_ITMP3, REG_SP, 4 * 8); +#else + M_AST(REG_ZERO, REG_SP, 4 * 8); #endif - return (u1*) (s + NATIVESTUBOFFSET); -} + /* move machine code onto stack */ + disp = dseg_adds4(cd, mcode); + M_ILD(REG_ITMP3, REG_PV, disp); + M_IST(REG_ITMP3, REG_SP, 3 * 8); -/* function: removenativestub ************************************************** + /* move class/method/field reference onto stack */ - removes a previously created native-stub from memory - -*******************************************************************************/ + disp = dseg_addaddress(cd, pref->ref); + M_ALD(REG_ITMP3, REG_PV, disp); + M_AST(REG_ITMP3, REG_SP, 2 * 8); -void removenativestub(u1 *stub) -{ - CFREE((u8*) stub - NATIVESTUBOFFSET, NATIVESTUBSIZE * 8); + /* move data segment displacement onto stack */ + + disp = dseg_adds4(cd, pref->disp); + M_ILD(REG_ITMP3, REG_PV, disp); + M_IST(REG_ITMP3, REG_SP, 1 * 8); + + /* move patcher function pointer onto stack */ + + disp = dseg_addaddress(cd, pref->patcher); + M_ALD(REG_ITMP3, REG_PV, disp); + M_AST(REG_ITMP3, REG_SP, 0 * 8); + + disp = dseg_addaddress(cd, asm_wrapper_patcher); + M_ALD(REG_ITMP3, REG_PV, disp); + M_JMP(REG_ZERO, REG_ITMP3); + } + } + + codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase)); + + return m->entrypoint; }