- /* generate exception and patcher stubs */
-
- {
- exceptionref *eref;
- patchref *pref;
- u4 mcode;
- u1 *savedmcodeptr;
- u1 *tmpmcodeptr;
-
- savedmcodeptr = NULL;
-
- /* generate exception stubs */
-
- for (eref = cd->exceptionrefs; eref != NULL; eref = eref->next) {
- md_codegen_patch_branch(cd, eref->branchpos, cd->mcodeptr - cd->mcodebase);
-
- MCODECHECK(100);
-
- /* Check if the exception is an
- ArrayIndexOutOfBoundsException. If so, move index register
- into REG_ITMP1. */
-
- if (eref->reg != -1)
- M_MOV(eref->reg, REG_ITMP1);
-
- /* calcuate exception address */
-
- M_LDA(REG_ITMP2_XPC, REG_PV, eref->branchpos - 4);
-
- /* move function to call into REG_ITMP3 */
-
- disp = dseg_addaddress(cd, eref->function);
- M_ALD(REG_ITMP3, REG_PV, disp);
- M_ALD(REG_ITMP3, REG_ITMP3, 0); /* TOC */
-
- if (savedmcodeptr != NULL) {
- disp = ((u4 *) savedmcodeptr) - (((u4 *) cd->mcodeptr) + 1);
- M_BR(disp);
-
- } else {
- savedmcodeptr = cd->mcodeptr;
-
- if (jd->isleafmethod) {
- M_MFLR(REG_ZERO);
- M_AST(REG_ZERO, REG_SP, cd->stackframesize * 8 + LA_LR_OFFSET);
- }
-
- M_MOV(REG_PV, rd->argintregs[0]);
- M_MOV(REG_SP, rd->argintregs[1]);
-
- if (jd->isleafmethod)
- M_MOV(REG_ZERO, rd->argintregs[2]);
- else
- M_ALD(rd->argintregs[2],
- REG_SP, cd->stackframesize * 8 + LA_LR_OFFSET);
-
- M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
- M_MOV(REG_ITMP1, rd->argintregs[4]);
-
- M_STDU(REG_SP, REG_SP, -(LA_SIZE + 6 * 8));
- M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 5 * 8);
-
- M_MTCTR(REG_ITMP3);
- M_JSR;
- M_MOV(REG_RESULT, REG_ITMP1_XPTR);
-
- M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 5 * 8);
- M_LADD_IMM(REG_SP, LA_SIZE + 6 * 8, REG_SP);
-
- if (jd->isleafmethod) {
- /* XXX FIXME: REG_ZERO can cause problems here! */
- assert(cd->stackframesize * 8 <= 32767);
-
- M_ALD(REG_ZERO, REG_SP, cd->stackframesize * 8 + LA_LR_OFFSET);
- M_MTLR(REG_ZERO);
- }
-
- disp = dseg_addaddress(cd, asm_handle_exception);
- M_ALD(REG_ITMP3, REG_PV, disp);
- M_MTCTR(REG_ITMP3);
- M_RTS;
- }
- }
-
-
- /* generate code patching stub call code */
-
- for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
- /* check code segment size */
-
- MCODECHECK(16);
-
- /* Get machine code which is patched back in later. The
- call is 1 instruction word long. */
-
- tmpmcodeptr = (u1 *) (cd->mcodebase + pref->branchpos);
-
- mcode = *((u4 *) tmpmcodeptr);
-
- /* 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 = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 1);
- M_BR(disp);
-
- cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */
-
- /* create stack frame - keep stack 16-byte aligned */
-
- M_AADD_IMM(REG_SP, -8 * 8, REG_SP);
-
- /* calculate return address and move it onto the stack */
-
- M_LDA(REG_ITMP3, REG_PV, pref->branchpos);
- M_AST_INTERN(REG_ITMP3, REG_SP, 5 * 8);
-
- /* move pointer to java_objectheader onto stack */
-
-#if defined(ENABLE_THREADS)
- /* order reversed because of data segment layout */
-
- (void) dseg_addaddress(cd, NULL); /* flcword */
- (void) dseg_addaddress(cd, lock_get_initial_lock_word()); /* monitorPtr */
- disp = dseg_addaddress(cd, NULL); /* vftbl */
-
- M_LDA(REG_ITMP3, REG_PV, disp);
- M_AST_INTERN(REG_ITMP3, REG_SP, 4 * 8);
-#else
- /* do nothing */
-#endif
-
- /* move machine code onto stack */
-
- disp = dseg_adds4(cd, mcode);
- M_ILD(REG_ITMP3, REG_PV, disp);
- M_IST_INTERN(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_INTERN(REG_ITMP3, REG_SP, 2 * 8);
-
- /* move data segment displacement onto stack */
-
- disp = dseg_addaddress(cd, pref->disp);
- M_LLD(REG_ITMP3, REG_PV, disp);
- M_IST_INTERN(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_INTERN(REG_ITMP3, REG_SP, 0 * 8);
-
- disp = dseg_addaddress(cd, asm_patcher_wrapper);
- M_ALD(REG_ITMP3, REG_PV, disp);
- M_MTCTR(REG_ITMP3);
- M_RTS;
- }
-
- /* generate replacement-out stubs */
-
-#if 0
- {
- int i;
-
- replacementpoint = jd->code->rplpoints;
-
- for (i = 0; i < jd->code->rplpointcount; ++i, ++replacementpoint) {
- /* check code segment size */
-
- MCODECHECK(100);
-
- /* note start of stub code */
-
- replacementpoint->outcode = (u1 *) (cd->mcodeptr - cd->mcodebase);
-
- /* make machine code for patching */
-
- tmpmcodeptr = cd->mcodeptr;
- cd->mcodeptr = (u1 *) &(replacementpoint->mcode) + 1 /* big-endian */;
-
- disp = (ptrint)((s4*)replacementpoint->outcode - (s4*)replacementpoint->pc) - 1;
- M_BR(disp);
-
- cd->mcodeptr = tmpmcodeptr;
-
- /* create stack frame - keep 16-byte aligned */
-
- M_AADD_IMM(REG_SP, -4 * 4, REG_SP);
-
- /* push address of `rplpoint` struct */
-
- disp = dseg_addaddress(cd, replacementpoint);
- M_ALD(REG_ITMP3, REG_PV, disp);
- M_AST_INTERN(REG_ITMP3, REG_SP, 0 * 4);
-
- /* jump to replacement function */
-
- disp = dseg_addaddress(cd, asm_replacement_out);
- M_ALD(REG_ITMP3, REG_PV, disp);
- M_MTCTR(REG_ITMP3);
- M_RTS;
- }
- }
-#endif
- }
-
- codegen_finish(jd);