revision 585:371342a39c09
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 585:371342a39c09 |
parent | 584:5c29dd7297df |
child | 1065:bc1cc0c54917 |
author | nkeynes |
date | Tue Jan 15 11:07:32 2008 +0000 (16 years ago) |
branch | lxdream-mmu |
Handle sh4 aborts/reset within the translator
src/dreamcast.c | view | annotate | diff | log | ||
src/sh4/sh4.c | view | annotate | diff | log | ||
src/sh4/sh4trans.c | view | annotate | diff | log | ||
src/sh4/sh4trans.h | view | annotate | diff | log | ||
src/sh4/sh4x86.c | view | annotate | diff | log |
1.1 --- a/src/dreamcast.c Tue Jan 15 11:06:24 2008 +00001.2 +++ b/src/dreamcast.c Tue Jan 15 11:07:32 2008 +00001.3 @@ -27,6 +27,7 @@1.4 #include "dreamcast.h"1.5 #include "gdrom/ide.h"1.6 #include "maple/maple.h"1.7 +#include "sh4/sh4trans.h"1.9 /**1.10 * Current state of the DC virtual machine1.11 @@ -131,6 +132,9 @@1.12 void dreamcast_reset( void )1.13 {1.14 int i;1.15 + if( sh4_xlat_is_running() ) {1.16 + sh4_translate_exit( XLAT_EXIT_SYSRESET );1.17 + }1.18 for( i=0; i<num_modules; i++ ) {1.19 if( modules[i]->reset != NULL )1.20 modules[i]->reset();1.21 @@ -201,6 +205,9 @@1.23 void dreamcast_stop( void )1.24 {1.25 + if( sh4_xlat_is_running() ) {1.26 + sh4_translate_exit( XLAT_EXIT_HALT );1.27 + }1.28 if( dreamcast_state == STATE_RUNNING )1.29 dreamcast_state = STATE_STOPPING;1.30 }1.31 @@ -219,9 +226,7 @@1.32 dreamcast_program_name = g_strdup(name);1.33 dreamcast_entry_point = entry_point;1.34 sh4_set_pc(entry_point);1.35 - if( !dreamcast_has_bios ) {1.36 - bios_install();1.37 - }1.38 + bios_install();1.39 dcload_install();1.40 gui_update_state();1.41 }
2.1 --- a/src/sh4/sh4.c Tue Jan 15 11:06:24 2008 +00002.2 +++ b/src/sh4/sh4.c Tue Jan 15 11:07:32 2008 +00002.3 @@ -261,6 +261,7 @@2.4 */2.5 gboolean sh4_raise_exception( int code )2.6 {2.7 + fprintf( stderr, "EXC %04X: %08X\n", code, sh4r.pc );2.8 RAISE( code, EXV_EXCEPTION );2.9 }2.11 @@ -282,7 +283,7 @@2.12 gboolean sh4_raise_trap( int trap )2.13 {2.14 MMIO_WRITE( MMU, TRA, trap<<2 );2.15 - return sh4_raise_exception( EXC_TRAP );2.16 + RAISE( EXC_TRAP, EXV_EXCEPTION );2.17 }2.19 gboolean sh4_raise_slot_exception( int normal_code, int slot_code ) {
3.1 --- a/src/sh4/sh4trans.c Tue Jan 15 11:06:24 2008 +00003.2 +++ b/src/sh4/sh4trans.c Tue Jan 15 11:07:32 2008 +00003.3 @@ -27,6 +27,13 @@3.6 static jmp_buf xlat_jmp_buf;3.7 +static gboolean xlat_running = FALSE;3.8 +3.9 +gboolean sh4_xlat_is_running()3.10 +{3.11 + return xlat_running;3.12 +}3.13 +3.14 /**3.15 * Execute a timeslice using translated code only (ie translate/execute loop)3.16 * Note this version does not support breakpoints3.17 @@ -53,9 +60,12 @@3.18 dreamcast_stop();3.19 return sh4r.slice_cycle;3.20 }3.21 + case XLAT_EXIT_SYSRESET:3.22 + dreamcast_reset();3.23 break;3.24 }3.25 -3.26 +3.27 + xlat_running = TRUE;3.28 void * (*code)() = NULL;3.29 while( sh4r.slice_cycle < nanosecs ) {3.30 if( sh4r.event_pending <= sh4r.slice_cycle ) {3.31 @@ -84,6 +94,8 @@3.32 code = code();3.33 }3.35 + xlat_running = FALSE;3.36 +3.37 if( sh4r.sh4_state != SH4_STATE_STANDBY ) {3.38 TMU_run_slice( nanosecs );3.39 SCIF_run_slice( nanosecs );3.40 @@ -184,21 +196,24 @@3.41 thunk();3.42 }3.43 // finally longjmp back into sh4_xlat_run_slice3.44 + xlat_running = FALSE;3.45 longjmp(xlat_jmp_buf, XLAT_EXIT_CONTINUE);3.46 }3.48 void sh4_translate_exit( int exit_code )3.49 {3.50 void *pc = xlat_get_native_pc();3.51 - assert(pc != NULL);3.52 -3.53 - void *code = xlat_get_code( sh4r.pc );3.54 - xlat_recovery_record_t recover = xlat_get_recovery(code, pc, TRUE);3.55 - if( recover != NULL ) {3.56 - // Can be null if there is no recovery necessary3.57 - sh4_translate_run_recovery(recover);3.58 + if( pc != NULL ) {3.59 + // could be null if we're not actually running inside the translator3.60 + void *code = xlat_get_code( sh4r.pc );3.61 + xlat_recovery_record_t recover = xlat_get_recovery(code, pc, TRUE);3.62 + if( recover != NULL ) {3.63 + // Can be null if there is no recovery necessary3.64 + sh4_translate_run_recovery(recover);3.65 + }3.66 }3.67 // finally longjmp back into sh4_xlat_run_slice3.68 + xlat_running = FALSE;3.69 longjmp(xlat_jmp_buf, exit_code);3.70 }3.72 @@ -224,6 +239,7 @@3.73 // Can be null if there is no recovery necessary3.74 sh4_translate_run_recovery(recover);3.75 xlat_flush_cache();3.76 + xlat_running = FALSE;3.77 longjmp(xlat_jmp_buf, XLAT_EXIT_CONTINUE);3.78 } else {3.79 xlat_flush_cache();3.80 @@ -244,8 +260,8 @@3.81 // fault - off to the fault handler3.82 if( !mmu_update_icache(sh4r.pc) ) {3.83 // double fault - halt3.84 + ERROR( "Double fault - halting" );3.85 dreamcast_stop();3.86 - ERROR( "Double fault - halting" );3.87 return NULL;3.88 }3.89 }
4.1 --- a/src/sh4/sh4trans.h Tue Jan 15 11:06:24 2008 +00004.2 +++ b/src/sh4/sh4trans.h Tue Jan 15 11:07:32 2008 +00004.3 @@ -51,10 +51,21 @@4.4 #define XLAT_EXIT_BREAKPOINT 34.6 /**4.7 + * Translation flag - exit the current block and continue after performing a full4.8 + * system reset (dreamcast_reset())4.9 + */4.10 +#define XLAT_EXIT_SYSRESET 44.11 +4.12 +/**4.13 */4.14 uint32_t sh4_xlat_run_slice( uint32_t nanosecs );4.16 /**4.17 + * Return true if translated code is currently running4.18 + */4.19 +gboolean sh4_xlat_is_running();4.20 +4.21 +/**4.22 * Translate the specified block of code starting from the specified start4.23 * address until the first branch/jump instruction.4.24 */
5.1 --- a/src/sh4/sh4x86.c Tue Jan 15 11:06:24 2008 +00005.2 +++ b/src/sh4/sh4x86.c Tue Jan 15 11:07:32 2008 +00005.3 @@ -387,7 +387,6 @@5.4 * at this point, inline a call to sh4_execute_instruction (with a few5.5 * small repairs to cope with the different environment).5.6 */5.7 - ir = sh4_read_word(pc);5.9 if( !sh4_x86.in_delay_slot ) {5.10 sh4_x86_add_recovery(pc);
.