2 * $Id: sh4.c,v 1.1 2007-09-12 09:20:38 nkeynes Exp $
4 * SH4 parent module for all CPU modes and SH4 peripheral
7 * Copyright (c) 2005 Nathan Keynes.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #define MODULE sh4_module
23 #include "sh4/sh4core.h"
24 #include "sh4/sh4mmio.h"
30 void sh4_init( void );
31 void sh4_reset( void );
32 void sh4_start( void );
33 void sh4_stop( void );
34 void sh4_save_state( FILE *f );
35 int sh4_load_state( FILE *f );
37 uint32_t sh4_run_slice( uint32_t );
38 uint32_t sh4_xlat_run_slice( uint32_t );
40 struct dreamcast_module sh4_module = { "SH4", sh4_init, sh4_reset,
41 NULL, sh4_run_slice, sh4_stop,
42 sh4_save_state, sh4_load_state };
44 struct sh4_registers sh4r;
45 struct breakpoint_struct sh4_breakpoints[MAX_BREAKPOINTS];
46 int sh4_breakpoint_count = 0;
48 void sh4_set_use_xlat( gboolean use )
53 sh4_module.run_time_slice = sh4_xlat_run_slice;
55 sh4_module.run_time_slice = sh4_run_slice;
61 register_io_regions( mmio_list_sh4mmio );
68 /* zero everything out, for the sake of having a consistent state. */
69 memset( &sh4r, 0, sizeof(sh4r) );
71 /* Resume running if we were halted */
72 sh4r.sh4_state = SH4_STATE_RUNNING;
75 sh4r.new_pc= 0xA0000002;
76 sh4r.vbr = 0x00000000;
77 sh4r.fpscr = 0x00040001;
79 sh4r.fr_bank = &sh4r.fr[0][0];
81 /* Mem reset will do this, but if we want to reset _just_ the SH4... */
82 MMIO_WRITE( MMU, EXPEVT, EXC_POWER_RESET );
84 /* Peripheral modules */
97 void sh4_save_state( FILE *f )
99 fwrite( &sh4r, sizeof(sh4r), 1, f );
101 INTC_save_state( f );
103 SCIF_save_state( f );
106 int sh4_load_state( FILE * f )
108 fread( &sh4r, sizeof(sh4r), 1, f );
110 INTC_load_state( f );
112 return SCIF_load_state( f );
116 void sh4_set_breakpoint( uint32_t pc, int type )
118 sh4_breakpoints[sh4_breakpoint_count].address = pc;
119 sh4_breakpoints[sh4_breakpoint_count].type = type;
120 sh4_breakpoint_count++;
123 gboolean sh4_clear_breakpoint( uint32_t pc, int type )
127 for( i=0; i<sh4_breakpoint_count; i++ ) {
128 if( sh4_breakpoints[i].address == pc &&
129 sh4_breakpoints[i].type == type ) {
130 while( ++i < sh4_breakpoint_count ) {
131 sh4_breakpoints[i-1].address = sh4_breakpoints[i].address;
132 sh4_breakpoints[i-1].type = sh4_breakpoints[i].type;
134 sh4_breakpoint_count--;
141 int sh4_get_breakpoint( uint32_t pc )
144 for( i=0; i<sh4_breakpoint_count; i++ ) {
145 if( sh4_breakpoints[i].address == pc )
146 return sh4_breakpoints[i].type;
.