filename | src/sh4/sh4.c |
changeset | 378:f10fbdd4e24b |
next | 401:f79327f39818 |
author | nkeynes |
date | Tue Sep 18 09:12:30 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Ensure correct end-of-block PC Handle syscalls |
view | annotate | diff | log | raw |
1 /**
2 * $Id: sh4.c,v 1.1 2007-09-12 09:20:38 nkeynes Exp $
3 *
4 * SH4 parent module for all CPU modes and SH4 peripheral
5 * modules.
6 *
7 * Copyright (c) 2005 Nathan Keynes.
8 *
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.
13 *
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.
18 */
20 #define MODULE sh4_module
21 #include <math.h>
22 #include "dream.h"
23 #include "sh4/sh4core.h"
24 #include "sh4/sh4mmio.h"
25 #include "sh4/intc.h"
26 #include "mem.h"
27 #include "clock.h"
28 #include "syscall.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 )
49 {
50 if( use ) {
51 xlat_cache_init();
52 sh4_x86_init();
53 sh4_module.run_time_slice = sh4_xlat_run_slice;
54 } else {
55 sh4_module.run_time_slice = sh4_run_slice;
56 }
57 }
59 void sh4_init(void)
60 {
61 register_io_regions( mmio_list_sh4mmio );
62 MMU_init();
63 sh4_reset();
64 }
66 void sh4_reset(void)
67 {
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;
74 sh4r.pc = 0xA0000000;
75 sh4r.new_pc= 0xA0000002;
76 sh4r.vbr = 0x00000000;
77 sh4r.fpscr = 0x00040001;
78 sh4r.sr = 0x700000F0;
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 */
85 CPG_reset();
86 INTC_reset();
87 MMU_reset();
88 TMU_reset();
89 SCIF_reset();
90 }
92 void sh4_stop(void)
93 {
95 }
97 void sh4_save_state( FILE *f )
98 {
99 fwrite( &sh4r, sizeof(sh4r), 1, f );
100 MMU_save_state( f );
101 INTC_save_state( f );
102 TMU_save_state( f );
103 SCIF_save_state( f );
104 }
106 int sh4_load_state( FILE * f )
107 {
108 fread( &sh4r, sizeof(sh4r), 1, f );
109 MMU_load_state( f );
110 INTC_load_state( f );
111 TMU_load_state( f );
112 return SCIF_load_state( f );
113 }
116 void sh4_set_breakpoint( uint32_t pc, int type )
117 {
118 sh4_breakpoints[sh4_breakpoint_count].address = pc;
119 sh4_breakpoints[sh4_breakpoint_count].type = type;
120 sh4_breakpoint_count++;
121 }
123 gboolean sh4_clear_breakpoint( uint32_t pc, int type )
124 {
125 int i;
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;
133 }
134 sh4_breakpoint_count--;
135 return TRUE;
136 }
137 }
138 return FALSE;
139 }
141 int sh4_get_breakpoint( uint32_t pc )
142 {
143 int i;
144 for( i=0; i<sh4_breakpoint_count; i++ ) {
145 if( sh4_breakpoints[i].address == pc )
146 return sh4_breakpoints[i].type;
147 }
148 return 0;
149 }
.