# HG changeset patch # User nkeynes # Date 1214434241 0 # Node ID 4f0ba72e58fef3bcc57b875efde9f2e262978415 # Parent f6eaa3bcfa5b75fe96c1320e5c0b307f16b260ed Fix size test before end-of-block extension, and add assert after sh4_translate_end_block() for consistency --- a/src/sh4/sh4trans.c Wed Jun 25 10:42:43 2008 +0000 +++ b/src/sh4/sh4trans.c Wed Jun 25 22:50:41 2008 +0000 @@ -135,31 +135,31 @@ uint8_t *eob = xlat_output + xlat_current_block->size; if( GET_ICACHE_END() < lastpc ) { - lastpc = GET_ICACHE_END(); + lastpc = GET_ICACHE_END(); } sh4_translate_begin_block(pc); do { - /* check for breakpoints at this pc */ - for( i=0; icode; - xlat_current_block = xlat_extend_block( xlat_output - oldstart + MAX_INSTRUCTION_SIZE ); - xlat_output = xlat_current_block->code + (xlat_output - oldstart); - eob = xlat_current_block->code + xlat_current_block->size; - } - done = sh4_translate_instruction( pc ); - assert( xlat_output <= eob ); - pc += 2; - if ( pc >= lastpc ) { - done = 2; - } + /* check for breakpoints at this pc */ + for( i=0; icode; + xlat_current_block = xlat_extend_block( xlat_output - oldstart + MAX_INSTRUCTION_SIZE ); + xlat_output = xlat_current_block->code + (xlat_output - oldstart); + eob = xlat_current_block->code + xlat_current_block->size; + } + done = sh4_translate_instruction( pc ); + assert( xlat_output <= eob ); + pc += 2; + if ( pc >= lastpc ) { + done = 2; + } } while( !done ); pc += (done - 2); @@ -168,14 +168,15 @@ int epilogue_size = sh4_translate_end_block_size(); uint32_t recovery_size = sizeof(struct xlat_recovery_record)*xlat_recovery_posn; - uint32_t finalsize = xlat_output - xlat_current_block->code + epilogue_size + recovery_size; - if( eob - xlat_output < finalsize ) { - uint8_t *oldstart = xlat_current_block->code; - xlat_current_block = xlat_extend_block( finalsize ); - xlat_output = xlat_current_block->code + (xlat_output - oldstart); + uint32_t finalsize = (xlat_output - xlat_current_block->code) + epilogue_size + recovery_size; + if( xlat_current_block->size < finalsize ) { + uint8_t *oldstart = xlat_current_block->code; + xlat_current_block = xlat_extend_block( finalsize ); + xlat_output = xlat_current_block->code + (xlat_output - oldstart); } sh4_translate_end_block(pc); - + assert( xlat_output <= (xlat_current_block->code + xlat_current_block->size - recovery_size) ); + /* Write the recovery records onto the end of the code block */ memcpy( xlat_output, xlat_recovery, recovery_size); xlat_current_block->recover_table_offset = xlat_output - (uint8_t *)xlat_current_block->code;