Search
lxdream.org :: lxdream/src/sh4/sh4core.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.c
changeset 559:06714bc64271
prev550:a27e31340147
next561:533f6b478071
author nkeynes
date Tue Jan 01 04:58:57 2008 +0000 (12 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Commit first pass at full TLB support - still needs a lot more work
file annotate diff log raw
1.1 --- a/src/sh4/sh4core.c Thu Dec 06 10:43:30 2007 +0000
1.2 +++ b/src/sh4/sh4core.c Tue Jan 01 04:58:57 2008 +0000
1.3 @@ -164,12 +164,12 @@
1.4 #define TRACE_RETURN( source, dest )
1.5 #endif
1.6
1.7 -#define MEM_READ_BYTE( addr ) sh4_read_byte(addr)
1.8 -#define MEM_READ_WORD( addr ) sh4_read_word(addr)
1.9 -#define MEM_READ_LONG( addr ) sh4_read_long(addr)
1.10 -#define MEM_WRITE_BYTE( addr, val ) sh4_write_byte(addr, val)
1.11 -#define MEM_WRITE_WORD( addr, val ) sh4_write_word(addr, val)
1.12 -#define MEM_WRITE_LONG( addr, val ) sh4_write_long(addr, val)
1.13 +#define MEM_READ_BYTE( addr, val ) memtmp = sh4_read_byte(addr); if( memtmp >> 32 ) { return TRUE; } else { val = ((uint32_t)memtmp); }
1.14 +#define MEM_READ_WORD( addr, val ) memtmp = sh4_read_word(addr); if( memtmp >> 32 ) { return TRUE; } else { val = ((uint32_t)memtmp); }
1.15 +#define MEM_READ_LONG( addr, val ) memtmp = sh4_read_long(addr); if( memtmp >> 32 ) { return TRUE; } else { val = ((uint32_t)memtmp); }
1.16 +#define MEM_WRITE_BYTE( addr, val ) if( sh4_write_byte(addr, val) ) { return TRUE; }
1.17 +#define MEM_WRITE_WORD( addr, val ) if( sh4_write_word(addr, val) ) { return TRUE; }
1.18 +#define MEM_WRITE_LONG( addr, val ) if( sh4_write_long(addr, val) ) { return TRUE; }
1.19
1.20 #define FP_WIDTH (IS_FPU_DOUBLESIZE() ? 8 : 4)
1.21
1.22 @@ -223,6 +223,7 @@
1.23 uint32_t tmp;
1.24 float ftmp;
1.25 double dtmp;
1.26 + int64_t memtmp; // temporary holder for memory reads
1.27
1.28 #define R0 sh4r.r[0]
1.29 pc = sh4r.pc;
1.30 @@ -246,7 +247,7 @@
1.31 * region, fallback on the full-blown memory read
1.32 */
1.33 sh4_icache = NULL;
1.34 - ir = MEM_READ_WORD(pc);
1.35 + MEM_READ_WORD(pc, ir);
1.36 } else {
1.37 sh4_icache_addr = pageaddr;
1.38 ir = sh4_icache[(pc&0xFFF)>>1];
1.39 @@ -551,21 +552,21 @@
1.40 case 0xC:
1.41 { /* MOV.B @(R0, Rm), Rn */
1.42 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.43 - sh4r.r[Rn] = MEM_READ_BYTE( R0 + sh4r.r[Rm] );
1.44 + MEM_READ_BYTE( R0 + sh4r.r[Rm], sh4r.r[Rn] );
1.45 }
1.46 break;
1.47 case 0xD:
1.48 { /* MOV.W @(R0, Rm), Rn */
1.49 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.50 CHECKRALIGN16( R0 + sh4r.r[Rm] );
1.51 - sh4r.r[Rn] = MEM_READ_WORD( R0 + sh4r.r[Rm] );
1.52 + MEM_READ_WORD( R0 + sh4r.r[Rm], sh4r.r[Rn] );
1.53 }
1.54 break;
1.55 case 0xE:
1.56 { /* MOV.L @(R0, Rm), Rn */
1.57 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.58 CHECKRALIGN32( R0 + sh4r.r[Rm] );
1.59 - sh4r.r[Rn] = MEM_READ_LONG( R0 + sh4r.r[Rm] );
1.60 + MEM_READ_LONG( R0 + sh4r.r[Rm], sh4r.r[Rn] );
1.61 }
1.62 break;
1.63 case 0xF:
1.64 @@ -573,9 +574,11 @@
1.65 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.66 CHECKRALIGN32( sh4r.r[Rm] );
1.67 CHECKRALIGN32( sh4r.r[Rn] );
1.68 - int64_t tmpl = SIGNEXT32(MEM_READ_LONG(sh4r.r[Rn]));
1.69 + MEM_READ_LONG(sh4r.r[Rn], tmp);
1.70 + int64_t tmpl = SIGNEXT32(tmp);
1.71 sh4r.r[Rn] += 4;
1.72 - tmpl = tmpl * SIGNEXT32(MEM_READ_LONG(sh4r.r[Rm])) + sh4r.mac;
1.73 + MEM_READ_LONG(sh4r.r[Rm], tmp);
1.74 + tmpl = tmpl * SIGNEXT32(tmp) + sh4r.mac;
1.75 sh4r.r[Rm] += 4;
1.76 if( sh4r.s ) {
1.77 /* 48-bit Saturation. Yuch */
1.78 @@ -1058,8 +1061,9 @@
1.79 { /* LDS.L @Rm+, MACH */
1.80 uint32_t Rm = ((ir>>8)&0xF);
1.81 CHECKRALIGN32( sh4r.r[Rm] );
1.82 + MEM_READ_LONG(sh4r.r[Rm], tmp);
1.83 sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
1.84 - (((uint64_t)MEM_READ_LONG(sh4r.r[Rm]))<<32);
1.85 + (((uint64_t)tmp)<<32);
1.86 sh4r.r[Rm] += 4;
1.87 }
1.88 break;
1.89 @@ -1067,8 +1071,9 @@
1.90 { /* LDS.L @Rm+, MACL */
1.91 uint32_t Rm = ((ir>>8)&0xF);
1.92 CHECKRALIGN32( sh4r.r[Rm] );
1.93 + MEM_READ_LONG(sh4r.r[Rm], tmp);
1.94 sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
1.95 - (uint64_t)((uint32_t)MEM_READ_LONG(sh4r.r[Rm]));
1.96 + (uint64_t)((uint32_t)tmp);
1.97 sh4r.r[Rm] += 4;
1.98 }
1.99 break;
1.100 @@ -1076,7 +1081,7 @@
1.101 { /* LDS.L @Rm+, PR */
1.102 uint32_t Rm = ((ir>>8)&0xF);
1.103 CHECKRALIGN32( sh4r.r[Rm] );
1.104 - sh4r.pr = MEM_READ_LONG( sh4r.r[Rm] );
1.105 + MEM_READ_LONG( sh4r.r[Rm], sh4r.pr );
1.106 sh4r.r[Rm] += 4;
1.107 }
1.108 break;
1.109 @@ -1085,7 +1090,7 @@
1.110 uint32_t Rm = ((ir>>8)&0xF);
1.111 CHECKPRIV();
1.112 CHECKRALIGN32( sh4r.r[Rm] );
1.113 - sh4r.sgr = MEM_READ_LONG(sh4r.r[Rm]);
1.114 + MEM_READ_LONG(sh4r.r[Rm], sh4r.sgr);
1.115 sh4r.r[Rm] +=4;
1.116 }
1.117 break;
1.118 @@ -1093,7 +1098,7 @@
1.119 { /* LDS.L @Rm+, FPUL */
1.120 uint32_t Rm = ((ir>>8)&0xF);
1.121 CHECKRALIGN32( sh4r.r[Rm] );
1.122 - sh4r.fpul = MEM_READ_LONG(sh4r.r[Rm]);
1.123 + MEM_READ_LONG(sh4r.r[Rm], sh4r.fpul);
1.124 sh4r.r[Rm] +=4;
1.125 }
1.126 break;
1.127 @@ -1101,7 +1106,7 @@
1.128 { /* LDS.L @Rm+, FPSCR */
1.129 uint32_t Rm = ((ir>>8)&0xF);
1.130 CHECKRALIGN32( sh4r.r[Rm] );
1.131 - sh4r.fpscr = MEM_READ_LONG(sh4r.r[Rm]);
1.132 + MEM_READ_LONG(sh4r.r[Rm], sh4r.fpscr);
1.133 sh4r.r[Rm] +=4;
1.134 sh4r.fr_bank = &sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21][0];
1.135 }
1.136 @@ -1111,7 +1116,7 @@
1.137 uint32_t Rm = ((ir>>8)&0xF);
1.138 CHECKPRIV();
1.139 CHECKRALIGN32( sh4r.r[Rm] );
1.140 - sh4r.dbr = MEM_READ_LONG(sh4r.r[Rm]);
1.141 + MEM_READ_LONG(sh4r.r[Rm], sh4r.dbr);
1.142 sh4r.r[Rm] +=4;
1.143 }
1.144 break;
1.145 @@ -1130,7 +1135,8 @@
1.146 CHECKSLOTILLEGAL();
1.147 CHECKPRIV();
1.148 CHECKWALIGN32( sh4r.r[Rm] );
1.149 - sh4_write_sr( MEM_READ_LONG(sh4r.r[Rm]) );
1.150 + MEM_READ_LONG(sh4r.r[Rm], tmp);
1.151 + sh4_write_sr( tmp );
1.152 sh4r.r[Rm] +=4;
1.153 }
1.154 break;
1.155 @@ -1138,7 +1144,7 @@
1.156 { /* LDC.L @Rm+, GBR */
1.157 uint32_t Rm = ((ir>>8)&0xF);
1.158 CHECKRALIGN32( sh4r.r[Rm] );
1.159 - sh4r.gbr = MEM_READ_LONG(sh4r.r[Rm]);
1.160 + MEM_READ_LONG(sh4r.r[Rm], sh4r.gbr);
1.161 sh4r.r[Rm] +=4;
1.162 }
1.163 break;
1.164 @@ -1147,7 +1153,7 @@
1.165 uint32_t Rm = ((ir>>8)&0xF);
1.166 CHECKPRIV();
1.167 CHECKRALIGN32( sh4r.r[Rm] );
1.168 - sh4r.vbr = MEM_READ_LONG(sh4r.r[Rm]);
1.169 + MEM_READ_LONG(sh4r.r[Rm], sh4r.vbr);
1.170 sh4r.r[Rm] +=4;
1.171 }
1.172 break;
1.173 @@ -1156,7 +1162,7 @@
1.174 uint32_t Rm = ((ir>>8)&0xF);
1.175 CHECKPRIV();
1.176 CHECKRALIGN32( sh4r.r[Rm] );
1.177 - sh4r.ssr = MEM_READ_LONG(sh4r.r[Rm]);
1.178 + MEM_READ_LONG(sh4r.r[Rm], sh4r.ssr);
1.179 sh4r.r[Rm] +=4;
1.180 }
1.181 break;
1.182 @@ -1165,7 +1171,7 @@
1.183 uint32_t Rm = ((ir>>8)&0xF);
1.184 CHECKPRIV();
1.185 CHECKRALIGN32( sh4r.r[Rm] );
1.186 - sh4r.spc = MEM_READ_LONG(sh4r.r[Rm]);
1.187 + MEM_READ_LONG(sh4r.r[Rm], sh4r.spc);
1.188 sh4r.r[Rm] +=4;
1.189 }
1.190 break;
1.191 @@ -1179,7 +1185,7 @@
1.192 uint32_t Rm = ((ir>>8)&0xF); uint32_t Rn_BANK = ((ir>>4)&0x7);
1.193 CHECKPRIV();
1.194 CHECKRALIGN32( sh4r.r[Rm] );
1.195 - sh4r.r_bank[Rn_BANK] = MEM_READ_LONG( sh4r.r[Rm] );
1.196 + MEM_READ_LONG( sh4r.r[Rm], sh4r.r_bank[Rn_BANK] );
1.197 sh4r.r[Rm] += 4;
1.198 }
1.199 break;
1.200 @@ -1307,7 +1313,7 @@
1.201 case 0x1:
1.202 { /* TAS.B @Rn */
1.203 uint32_t Rn = ((ir>>8)&0xF);
1.204 - tmp = MEM_READ_BYTE( sh4r.r[Rn] );
1.205 + MEM_READ_BYTE( sh4r.r[Rn], tmp );
1.206 sh4r.t = ( tmp == 0 ? 1 : 0 );
1.207 MEM_WRITE_BYTE( sh4r.r[Rn], tmp | 0x80 );
1.208 }
1.209 @@ -1406,9 +1412,11 @@
1.210 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.211 CHECKRALIGN16( sh4r.r[Rn] );
1.212 CHECKRALIGN16( sh4r.r[Rm] );
1.213 - int32_t stmp = SIGNEXT16(MEM_READ_WORD(sh4r.r[Rn]));
1.214 + MEM_READ_WORD(sh4r.r[Rn], tmp);
1.215 + int32_t stmp = SIGNEXT16(tmp);
1.216 sh4r.r[Rn] += 2;
1.217 - stmp = stmp * SIGNEXT16(MEM_READ_WORD(sh4r.r[Rm]));
1.218 + MEM_READ_WORD(sh4r.r[Rm], tmp);
1.219 + stmp = stmp * SIGNEXT16(tmp);
1.220 sh4r.r[Rm] += 2;
1.221 if( sh4r.s ) {
1.222 int64_t tmpl = (int64_t)((int32_t)sh4r.mac) + (int64_t)stmp;
1.223 @@ -1432,7 +1440,7 @@
1.224 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<2;
1.225 tmp = sh4r.r[Rm] + disp;
1.226 CHECKRALIGN32( tmp );
1.227 - sh4r.r[Rn] = MEM_READ_LONG( tmp );
1.228 + MEM_READ_LONG( tmp, sh4r.r[Rn] );
1.229 }
1.230 break;
1.231 case 0x6:
1.232 @@ -1440,19 +1448,19 @@
1.233 case 0x0:
1.234 { /* MOV.B @Rm, Rn */
1.235 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.236 - sh4r.r[Rn] = MEM_READ_BYTE( sh4r.r[Rm] );
1.237 + MEM_READ_BYTE( sh4r.r[Rm], sh4r.r[Rn] );
1.238 }
1.239 break;
1.240 case 0x1:
1.241 { /* MOV.W @Rm, Rn */
1.242 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.243 - CHECKRALIGN16( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_WORD( sh4r.r[Rm] );
1.244 + CHECKRALIGN16( sh4r.r[Rm] ); MEM_READ_WORD( sh4r.r[Rm], sh4r.r[Rn] );
1.245 }
1.246 break;
1.247 case 0x2:
1.248 { /* MOV.L @Rm, Rn */
1.249 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.250 - CHECKRALIGN32( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_LONG( sh4r.r[Rm] );
1.251 + CHECKRALIGN32( sh4r.r[Rm] ); MEM_READ_LONG( sh4r.r[Rm], sh4r.r[Rn] );
1.252 }
1.253 break;
1.254 case 0x3:
1.255 @@ -1464,19 +1472,19 @@
1.256 case 0x4:
1.257 { /* MOV.B @Rm+, Rn */
1.258 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.259 - sh4r.r[Rn] = MEM_READ_BYTE( sh4r.r[Rm] ); sh4r.r[Rm] ++;
1.260 + MEM_READ_BYTE( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] ++;
1.261 }
1.262 break;
1.263 case 0x5:
1.264 { /* MOV.W @Rm+, Rn */
1.265 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.266 - CHECKRALIGN16( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_WORD( sh4r.r[Rm] ); sh4r.r[Rm] += 2;
1.267 + CHECKRALIGN16( sh4r.r[Rm] ); MEM_READ_WORD( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] += 2;
1.268 }
1.269 break;
1.270 case 0x6:
1.271 { /* MOV.L @Rm+, Rn */
1.272 uint32_t Rn = ((ir>>8)&0xF); uint32_t Rm = ((ir>>4)&0xF);
1.273 - CHECKRALIGN32( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_LONG( sh4r.r[Rm] ); sh4r.r[Rm] += 4;
1.274 + CHECKRALIGN32( sh4r.r[Rm] ); MEM_READ_LONG( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] += 4;
1.275 }
1.276 break;
1.277 case 0x7:
1.278 @@ -1562,7 +1570,7 @@
1.279 case 0x4:
1.280 { /* MOV.B @(disp, Rm), R0 */
1.281 uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF);
1.282 - R0 = MEM_READ_BYTE( sh4r.r[Rm] + disp );
1.283 + MEM_READ_BYTE( sh4r.r[Rm] + disp, R0 );
1.284 }
1.285 break;
1.286 case 0x5:
1.287 @@ -1570,7 +1578,7 @@
1.288 uint32_t Rm = ((ir>>4)&0xF); uint32_t disp = (ir&0xF)<<1;
1.289 tmp = sh4r.r[Rm] + disp;
1.290 CHECKRALIGN16( tmp );
1.291 - R0 = MEM_READ_WORD( tmp );
1.292 + MEM_READ_WORD( tmp, R0 );
1.293 }
1.294 break;
1.295 case 0x8:
1.296 @@ -1640,7 +1648,7 @@
1.297 uint32_t Rn = ((ir>>8)&0xF); uint32_t disp = (ir&0xFF)<<1;
1.298 CHECKSLOTILLEGAL();
1.299 tmp = pc + 4 + disp;
1.300 - sh4r.r[Rn] = MEM_READ_WORD( tmp );
1.301 + MEM_READ_WORD( tmp, sh4r.r[Rn] );
1.302 }
1.303 break;
1.304 case 0xA:
1.305 @@ -1703,7 +1711,7 @@
1.306 case 0x4:
1.307 { /* MOV.B @(disp, GBR), R0 */
1.308 uint32_t disp = (ir&0xFF);
1.309 - R0 = MEM_READ_BYTE( sh4r.gbr + disp );
1.310 + MEM_READ_BYTE( sh4r.gbr + disp, R0 );
1.311 }
1.312 break;
1.313 case 0x5:
1.314 @@ -1711,7 +1719,7 @@
1.315 uint32_t disp = (ir&0xFF)<<1;
1.316 tmp = sh4r.gbr + disp;
1.317 CHECKRALIGN16( tmp );
1.318 - R0 = MEM_READ_WORD( tmp );
1.319 + MEM_READ_WORD( tmp, R0 );
1.320 }
1.321 break;
1.322 case 0x6:
1.323 @@ -1719,7 +1727,7 @@
1.324 uint32_t disp = (ir&0xFF)<<2;
1.325 tmp = sh4r.gbr + disp;
1.326 CHECKRALIGN32( tmp );
1.327 - R0 = MEM_READ_LONG( tmp );
1.328 + MEM_READ_LONG( tmp, R0 );
1.329 }
1.330 break;
1.331 case 0x7:
1.332 @@ -1756,25 +1764,25 @@
1.333 case 0xC:
1.334 { /* TST.B #imm, @(R0, GBR) */
1.335 uint32_t imm = (ir&0xFF);
1.336 - sh4r.t = ( MEM_READ_BYTE(R0 + sh4r.gbr) & imm ? 0 : 1 );
1.337 + MEM_READ_BYTE(R0+sh4r.gbr, tmp); sh4r.t = ( tmp & imm ? 0 : 1 );
1.338 }
1.339 break;
1.340 case 0xD:
1.341 { /* AND.B #imm, @(R0, GBR) */
1.342 uint32_t imm = (ir&0xFF);
1.343 - MEM_WRITE_BYTE( R0 + sh4r.gbr, imm & MEM_READ_BYTE(R0 + sh4r.gbr) );
1.344 + MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm & tmp );
1.345 }
1.346 break;
1.347 case 0xE:
1.348 { /* XOR.B #imm, @(R0, GBR) */
1.349 uint32_t imm = (ir&0xFF);
1.350 - MEM_WRITE_BYTE( R0 + sh4r.gbr, imm ^ MEM_READ_BYTE(R0 + sh4r.gbr) );
1.351 + MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm ^ tmp );
1.352 }
1.353 break;
1.354 case 0xF:
1.355 { /* OR.B #imm, @(R0, GBR) */
1.356 uint32_t imm = (ir&0xFF);
1.357 - MEM_WRITE_BYTE( R0 + sh4r.gbr, imm | MEM_READ_BYTE(R0 + sh4r.gbr) );
1.358 + MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm | tmp );
1.359 }
1.360 break;
1.361 }
1.362 @@ -1784,7 +1792,7 @@
1.363 uint32_t Rn = ((ir>>8)&0xF); uint32_t disp = (ir&0xFF)<<2;
1.364 CHECKSLOTILLEGAL();
1.365 tmp = (pc&0xFFFFFFFC) + disp + 4;
1.366 - sh4r.r[Rn] = MEM_READ_LONG( tmp );
1.367 + MEM_READ_LONG( tmp, sh4r.r[Rn] );
1.368 }
1.369 break;
1.370 case 0xE:
.