This module generates MIPS machine code for a sequence of
intermediate code commands (ICMDs).
- $Id: codegen.c 4863 2006-04-30 16:17:44Z edwin $
+ $Id: codegen.c 4905 2006-05-11 13:43:55Z twisti $
*/
if (bptr->bitflags & BBFLAG_REPLACEMENT && bptr->flags >= BBREACHED) {
/* 8-byte align pc */
- if ((ptrint)cd->mcodeptr & 4) {
+ if ((ptrint) cd->mcodeptr & 4) {
M_NOP;
}
- replacementpoint->pc = (u1*)(ptrint)((u1*)cd->mcodeptr - cd->mcodebase);
+ replacementpoint->pc = (u1*)(ptrint) (cd->mcodeptr - cd->mcodebase);
replacementpoint++;
- assert(cd->lastmcodeptr <= (u1*)cd->mcodeptr);
- cd->lastmcodeptr = (u1*)cd->mcodeptr + 2*4; /* br + delay slot */
+ assert(cd->lastmcodeptr <= cd->mcodeptr);
+ cd->lastmcodeptr = cd->mcodeptr + 2 * 4; /* br + delay slot */
}
/* store relative start of block */
- bptr->mpc = (s4) ((u1 *) cd->mcodeptr - cd->mcodebase);
+ bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
if (bptr->flags >= BBREACHED) {
{
branchref *bref;
for (bref = bptr->branchrefs; bref != NULL; bref = bref->next) {
- gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ gen_resolvebranch(cd->mcodebase + bref->branchpos,
bref->branchpos,
bptr->mpc);
}
gen_bound_check;
}
M_AADD(s2, s1, REG_ITMP3);
- M_BLDS(d, REG_ITMP3, OFFSET(java_chararray, data[0]));
+ M_BLDS(d, REG_ITMP3, OFFSET(java_bytearray, data[0]));
emit_store(jd, iptr, iptr->dst, d);
break;
}
M_AADD(s2, s1, REG_ITMP3);
M_AADD(s2, REG_ITMP3, REG_ITMP3);
- M_SLDS(d, REG_ITMP3, OFFSET(java_chararray, data[0]));
+ M_SLDS(d, REG_ITMP3, OFFSET(java_shortarray, data[0]));
emit_store(jd, iptr, iptr->dst, d);
break;
case ICMD_FRETURN: /* ..., retvalue ==> ... */
s1 = emit_load_s1(jd, iptr, src, REG_FRESULT);
- M_FMOV(s1, REG_FRESULT);
+ M_FLTMOVE(s1, REG_FRESULT);
goto nowperformreturn;
case ICMD_DRETURN: /* ..., retvalue ==> ... */
s1 = emit_load_s1(jd, iptr, src, REG_FRESULT);
- M_DMOV(s1, REG_FRESULT);
+ M_DBLMOVE(s1, REG_FRESULT);
goto nowperformreturn;
case ICMD_RETURN: /* ... ==> ... */
M_ALD(REG_ITMP3, REG_PV, disp); /* built-in-function pointer */
M_JSR(REG_RA, REG_ITMP3);
M_NOP;
- disp = (s4) ((u1 *) cd->mcodeptr - cd->mcodebase);
+ disp = (s4) (cd->mcodeptr - cd->mcodebase);
M_LDA(REG_PV, REG_RA, -disp);
/* if op1 == true, we need to check for an exception */
M_ALD(REG_PV, REG_PV, disp); /* method pointer in pv */
M_JSR(REG_RA, REG_PV);
M_NOP;
- disp = (s4) ((u1 *) cd->mcodeptr - cd->mcodebase);
+ disp = (s4) (cd->mcodeptr - cd->mcodebase);
M_LDA(REG_PV, REG_RA, -disp);
break;
M_ALD(REG_PV, REG_METHODPTR, s1);
M_JSR(REG_RA, REG_PV);
M_NOP;
- disp = (s4) ((u1 *) cd->mcodeptr - cd->mcodebase);
+ disp = (s4) (cd->mcodeptr - cd->mcodebase);
M_LDA(REG_PV, REG_RA, -disp);
break;
M_ALD(REG_PV, REG_METHODPTR, s2);
M_JSR(REG_RA, REG_PV);
M_NOP;
- disp = (s4) ((u1 *) cd->mcodeptr - cd->mcodebase);
+ disp = (s4) (cd->mcodeptr - cd->mcodebase);
M_LDA(REG_PV, REG_RA, -disp);
break;
}
}
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- codegen_threadcritrestart(cd, (u1 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
#endif
s1 = emit_load_s1(jd, iptr, src, REG_ITMP1);
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 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritstart(cd, cd->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 *) cd->mcodeptr - cd->mcodebase); */
+ /* codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase); */
/* #endif */
/* M_ISUB(REG_ITMP2, REG_ITMP1, REG_ITMP2); */
/* } else { */
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 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
#endif
/* } */
M_CMPULT(REG_ITMP3, REG_ITMP2, REG_ITMP3);
}
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- codegen_threadcritrestart(cd, (u1 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
#endif
s1 = emit_load_s1(jd, iptr, src, REG_ITMP1);
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 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritstart(cd, cd->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 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
#endif
M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
M_CMPULT(REG_ITMP2, REG_ITMP1, d);
if (IS_2_WORD_TYPE(s2))
M_DST(s1, REG_SP, rd->interfaces[len][s2].regoff * 8);
else
- M_DST(s1, REG_SP, rd->interfaces[len][s2].regoff * 8);
+ M_FST(s1, REG_SP, rd->interfaces[len][s2].regoff * 8);
} else {
if (IS_2_WORD_TYPE(s2))
actual instruction. So codepatching does not change the
following block unintentionally. */
- if ((u1 *) cd->mcodeptr < cd->lastmcodeptr) {
- while ((u1 *) cd->mcodeptr < cd->lastmcodeptr) {
+ if (cd->mcodeptr < cd->lastmcodeptr) {
+ while (cd->mcodeptr < cd->lastmcodeptr)
M_NOP;
- }
}
} /* if (bptr -> flags >= BBREACHED) */
exceptionref *eref;
patchref *pref;
u8 mcode;
- u4 *savedmcodeptr;
- u4 *tmpmcodeptr;
+ u1 *savedmcodeptr;
+ u1 *tmpmcodeptr;
savedmcodeptr = NULL;
/* generate exception stubs */
for (eref = cd->exceptionrefs; eref != NULL; eref = eref->next) {
- gen_resolvebranch((u1 *) cd->mcodebase + eref->branchpos,
- eref->branchpos,
- (u1 *) cd->mcodeptr - cd->mcodebase);
+ gen_resolvebranch(cd->mcodebase + eref->branchpos,
+ eref->branchpos, cd->mcodeptr - cd->mcodebase);
MCODECHECK(100);
M_ALD(REG_ITMP3, REG_PV, disp);
if (savedmcodeptr != NULL) {
- M_BR(savedmcodeptr - cd->mcodeptr);
+ disp = ((u4 *) savedmcodeptr) - (((u4 *) cd->mcodeptr) + 1);
+ M_BR(disp);
M_NOP;
} else {
/* Get machine code which is patched back in later. The
call is 2 instruction words long. */
- tmpmcodeptr = (u4 *) (cd->mcodebase + pref->branchpos);
+ tmpmcodeptr = (u1 *) (cd->mcodebase + pref->branchpos);
/* We need to split this, because an unaligned 8 byte read
causes a SIGSEGV. */
- mcode = ((u8) tmpmcodeptr[1] << 32) + (u4) tmpmcodeptr[0];
+ mcode = ((u8) ((u4 *) tmpmcodeptr)[1] << 32) +
+ ((u4 *) tmpmcodeptr)[0];
/* Patch in the call to call the following code (done at
compile time). */
savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */
cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */
- disp = (s4) (savedmcodeptr - (tmpmcodeptr + 1));
+ disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 1);
if ((disp < (s4) 0xffff8000) || (disp > (s4) 0x00007fff)) {
*exceptionptr =
/* note start of stub code */
- replacementpoint->outcode = (u1*) (ptrint)((u1*)cd->mcodeptr - cd->mcodebase);
+ replacementpoint->outcode = (u1*) (ptrint) (cd->mcodeptr - cd->mcodebase);
/* make machine code for patching */
- tmpmcodeptr = cd->mcodeptr;
- cd->mcodeptr = (u4 *) &(replacementpoint->mcode);
+ savedmcodeptr = cd->mcodeptr;
+ cd->mcodeptr = (u1 *) &(replacementpoint->mcode);
disp = (ptrint)((s4*)replacementpoint->outcode - (s4*)replacementpoint->pc) - 1;
if ((disp < (s4) 0xffff8000) || (disp > (s4) 0x00007fff)) {
M_BR(disp);
M_NOP; /* delay slot */
- cd->mcodeptr = tmpmcodeptr;
+ cd->mcodeptr = savedmcodeptr;
/* create stack frame - 16-byte aligned */
dumpsize = dump_size();
cd = DNEW(codegendata);
- cd->mcodeptr = (u4 *) s;
+ cd->mcodeptr = s;
/* Store the methodinfo* in the same place as in the methodheader
for compiled methods. */
M_JMP(REG_PV);
M_NOP;
- md_cacheflush(s, (s4) ((u1 *) cd->mcodeptr - s));
+ md_cacheflush(s, (s4) (cd->mcodeptr - (u1 *) d));
#if defined(ENABLE_STATISTICS)
if (opt_stat)
{
patchref *pref;
u8 mcode;
- u4 *savedmcodeptr;
- u4 *tmpmcodeptr;
+ u1 *savedmcodeptr;
+ u1 *tmpmcodeptr;
for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
/* Get machine code which is patched back in later. The
call is 2 instruction words long. */
- tmpmcodeptr = (u4 *) (cd->mcodebase + pref->branchpos);
+ tmpmcodeptr = (u1 *) (cd->mcodebase + pref->branchpos);
/* We need to split this, because an unaligned 8 byte read
causes a SIGSEGV. */
- mcode = ((u8) tmpmcodeptr[1] << 32) + (u4) tmpmcodeptr[0];
+ mcode = ((u8) ((u4 *) tmpmcodeptr)[1] << 32) +
+ ((u4 *) tmpmcodeptr)[0];
/* Patch in the call to call the following code (done at
compile time). */
savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */
cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */
- M_BRS(savedmcodeptr - (tmpmcodeptr + 1));
+ disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 1);
+ M_BRS(disp);
M_NOP; /* branch delay slot */
cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */