# HG changeset patch # User nkeynes # Date 1201001437 0 # Node ID 1024c3a9cb88f201cfe310f8edbfb0d3126a5341 # Parent 11564af1448bfa2be139097759e73ad9838db279 Fix backpatching when the block moves during translation --- a/src/sh4/ia32abi.h Tue Jan 22 11:29:43 2008 +0000 +++ b/src/sh4/ia32abi.h Tue Jan 22 11:30:37 2008 +0000 @@ -244,8 +244,8 @@ RET(); for( i=0; i< sh4_x86.backpatch_posn; i++ ) { - *sh4_x86.backpatch_list[i].fixup_addr = - xlat_output - ((uint8_t *)sh4_x86.backpatch_list[i].fixup_addr) - 4; + uint32_t *fixup_addr = (uint32_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset]; + *fixup_addr = xlat_output - (uint8_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset] - 4; if( sh4_x86.backpatch_list[i].exc_code < 0 ) { load_imm32( R_EDX, sh4_x86.backpatch_list[i].fixup_icount ); int stack_adj = -1 - sh4_x86.backpatch_list[i].exc_code; --- a/src/sh4/ia32mac.h Tue Jan 22 11:29:43 2008 +0000 +++ b/src/sh4/ia32mac.h Tue Jan 22 11:30:37 2008 +0000 @@ -269,8 +269,8 @@ RET(); for( i=0; i< sh4_x86.backpatch_posn; i++ ) { - *sh4_x86.backpatch_list[i].fixup_addr = - xlat_output - ((uint8_t *)sh4_x86.backpatch_list[i].fixup_addr) - 4; + uint32_t *fixup_addr = (uint32_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset]; + *fixup_addr = xlat_output - (uint8_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset] - 4; if( sh4_x86.backpatch_list[i].exc_code < 0 ) { load_imm32( R_EDX, sh4_x86.backpatch_list[i].fixup_icount ); int stack_adj = -1 - sh4_x86.backpatch_list[i].exc_code; --- a/src/sh4/ia64abi.h Tue Jan 22 11:29:43 2008 +0000 +++ b/src/sh4/ia64abi.h Tue Jan 22 11:30:37 2008 +0000 @@ -237,8 +237,8 @@ RET(); for( i=0; i< sh4_x86.backpatch_posn; i++ ) { - *sh4_x86.backpatch_list[i].fixup_addr = - xlat_output - ((uint8_t *)sh4_x86.backpatch_list[i].fixup_addr) - 4; + uint32_t *fixup_addr = (uint32_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset]; + *fixup_addr = xlat_output - (uint8_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset] - 4; if( sh4_x86.backpatch_list[i].exc_code < 0 ) { load_imm32( R_EDX, sh4_x86.backpatch_list[i].fixup_icount ); int stack_adj = -1 - sh4_x86.backpatch_list[i].exc_code; --- a/src/sh4/sh4trans.h Tue Jan 22 11:29:43 2008 +0000 +++ b/src/sh4/sh4trans.h Tue Jan 22 11:30:37 2008 +0000 @@ -74,6 +74,7 @@ extern uint8_t *xlat_output; extern struct xlat_recovery_record xlat_recovery[MAX_RECOVERY_SIZE]; +extern xlat_cache_block_t xlat_current_block; extern uint32_t xlat_recovery_posn; /****************************************************************************** --- a/src/sh4/sh4x86.c Tue Jan 22 11:29:43 2008 +0000 +++ b/src/sh4/sh4x86.c Tue Jan 22 11:30:37 2008 +0000 @@ -35,7 +35,7 @@ #define DEFAULT_BACKPATCH_SIZE 4096 struct backpatch_record { - uint32_t *fixup_addr; + uint32_t fixup_offset; uint32_t fixup_icount; int32_t exc_code; }; @@ -115,7 +115,8 @@ if( sh4_x86.in_delay_slot ) { fixup_pc -= 2; } - sh4_x86.backpatch_list[sh4_x86.backpatch_posn].fixup_addr = (uint32_t *)fixup_addr; + sh4_x86.backpatch_list[sh4_x86.backpatch_posn].fixup_offset = + ((uint8_t *)fixup_addr) - ((uint8_t *)xlat_current_block->code); sh4_x86.backpatch_list[sh4_x86.backpatch_posn].fixup_icount = (fixup_pc - sh4_x86.block_start_pc)>>1; sh4_x86.backpatch_list[sh4_x86.backpatch_posn].exc_code = exc_code; sh4_x86.backpatch_posn++; --- a/src/sh4/sh4x86.in Tue Jan 22 11:29:43 2008 +0000 +++ b/src/sh4/sh4x86.in Tue Jan 22 11:30:37 2008 +0000 @@ -35,7 +35,7 @@ #define DEFAULT_BACKPATCH_SIZE 4096 struct backpatch_record { - uint32_t *fixup_addr; + uint32_t fixup_offset; uint32_t fixup_icount; int32_t exc_code; }; @@ -115,7 +115,8 @@ if( sh4_x86.in_delay_slot ) { fixup_pc -= 2; } - sh4_x86.backpatch_list[sh4_x86.backpatch_posn].fixup_addr = (uint32_t *)fixup_addr; + sh4_x86.backpatch_list[sh4_x86.backpatch_posn].fixup_offset = + ((uint8_t *)fixup_addr) - ((uint8_t *)xlat_current_block->code); sh4_x86.backpatch_list[sh4_x86.backpatch_posn].fixup_icount = (fixup_pc - sh4_x86.block_start_pc)>>1; sh4_x86.backpatch_list[sh4_x86.backpatch_posn].exc_code = exc_code; sh4_x86.backpatch_posn++;