Search
lxdream.org :: lxdream/src/sh4/sh4core.in :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.in
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.in Thu Dec 06 10:43:30 2007 +0000
1.2 +++ b/src/sh4/sh4core.in 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 @@ -255,22 +256,22 @@
1.40 %%
1.41 AND Rm, Rn {: sh4r.r[Rn] &= sh4r.r[Rm]; :}
1.42 AND #imm, R0 {: R0 &= imm; :}
1.43 -AND.B #imm, @(R0, GBR) {: MEM_WRITE_BYTE( R0 + sh4r.gbr, imm & MEM_READ_BYTE(R0 + sh4r.gbr) ); :}
1.44 + AND.B #imm, @(R0, GBR) {: MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm & tmp ); :}
1.45 NOT Rm, Rn {: sh4r.r[Rn] = ~sh4r.r[Rm]; :}
1.46 OR Rm, Rn {: sh4r.r[Rn] |= sh4r.r[Rm]; :}
1.47 OR #imm, R0 {: R0 |= imm; :}
1.48 -OR.B #imm, @(R0, GBR) {: MEM_WRITE_BYTE( R0 + sh4r.gbr, imm | MEM_READ_BYTE(R0 + sh4r.gbr) ); :}
1.49 + OR.B #imm, @(R0, GBR) {: MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm | tmp ); :}
1.50 TAS.B @Rn {:
1.51 - tmp = MEM_READ_BYTE( sh4r.r[Rn] );
1.52 + MEM_READ_BYTE( sh4r.r[Rn], tmp );
1.53 sh4r.t = ( tmp == 0 ? 1 : 0 );
1.54 MEM_WRITE_BYTE( sh4r.r[Rn], tmp | 0x80 );
1.55 :}
1.56 TST Rm, Rn {: sh4r.t = (sh4r.r[Rn]&sh4r.r[Rm] ? 0 : 1); :}
1.57 TST #imm, R0 {: sh4r.t = (R0 & imm ? 0 : 1); :}
1.58 -TST.B #imm, @(R0, GBR) {: sh4r.t = ( MEM_READ_BYTE(R0 + sh4r.gbr) & imm ? 0 : 1 ); :}
1.59 + TST.B #imm, @(R0, GBR) {: MEM_READ_BYTE(R0+sh4r.gbr, tmp); sh4r.t = ( tmp & imm ? 0 : 1 ); :}
1.60 XOR Rm, Rn {: sh4r.r[Rn] ^= sh4r.r[Rm]; :}
1.61 XOR #imm, R0 {: R0 ^= imm; :}
1.62 -XOR.B #imm, @(R0, GBR) {: MEM_WRITE_BYTE( R0 + sh4r.gbr, imm ^ MEM_READ_BYTE(R0 + sh4r.gbr) ); :}
1.63 + XOR.B #imm, @(R0, GBR) {: MEM_READ_BYTE(R0+sh4r.gbr, tmp); MEM_WRITE_BYTE( R0 + sh4r.gbr, imm ^ tmp ); :}
1.64 XTRCT Rm, Rn {: sh4r.r[Rn] = (sh4r.r[Rn]>>16) | (sh4r.r[Rm]<<16); :}
1.65
1.66 ROTL Rn {:
1.67 @@ -365,12 +366,12 @@
1.68 CHECKWALIGN32( R0 + sh4r.r[Rn] );
1.69 MEM_WRITE_LONG( R0 + sh4r.r[Rn], sh4r.r[Rm] );
1.70 :}
1.71 -MOV.B @(R0, Rm), Rn {: sh4r.r[Rn] = MEM_READ_BYTE( R0 + sh4r.r[Rm] ); :}
1.72 +MOV.B @(R0, Rm), Rn {: MEM_READ_BYTE( R0 + sh4r.r[Rm], sh4r.r[Rn] ); :}
1.73 MOV.W @(R0, Rm), Rn {: CHECKRALIGN16( R0 + sh4r.r[Rm] );
1.74 - sh4r.r[Rn] = MEM_READ_WORD( R0 + sh4r.r[Rm] );
1.75 + MEM_READ_WORD( R0 + sh4r.r[Rm], sh4r.r[Rn] );
1.76 :}
1.77 MOV.L @(R0, Rm), Rn {: CHECKRALIGN32( R0 + sh4r.r[Rm] );
1.78 - sh4r.r[Rn] = MEM_READ_LONG( R0 + sh4r.r[Rm] );
1.79 + MEM_READ_LONG( R0 + sh4r.r[Rm], sh4r.r[Rn] );
1.80 :}
1.81 MOV.L Rm, @(disp, Rn) {:
1.82 tmp = sh4r.r[Rn] + disp;
1.83 @@ -386,19 +387,19 @@
1.84 MOV.L @(disp, Rm), Rn {:
1.85 tmp = sh4r.r[Rm] + disp;
1.86 CHECKRALIGN32( tmp );
1.87 - sh4r.r[Rn] = MEM_READ_LONG( tmp );
1.88 + MEM_READ_LONG( tmp, sh4r.r[Rn] );
1.89 :}
1.90 -MOV.B @Rm, Rn {: sh4r.r[Rn] = MEM_READ_BYTE( sh4r.r[Rm] ); :}
1.91 -MOV.W @Rm, Rn {: CHECKRALIGN16( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_WORD( sh4r.r[Rm] ); :}
1.92 -MOV.L @Rm, Rn {: CHECKRALIGN32( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_LONG( sh4r.r[Rm] ); :}
1.93 +MOV.B @Rm, Rn {: MEM_READ_BYTE( sh4r.r[Rm], sh4r.r[Rn] ); :}
1.94 + MOV.W @Rm, Rn {: CHECKRALIGN16( sh4r.r[Rm] ); MEM_READ_WORD( sh4r.r[Rm], sh4r.r[Rn] ); :}
1.95 + MOV.L @Rm, Rn {: CHECKRALIGN32( sh4r.r[Rm] ); MEM_READ_LONG( sh4r.r[Rm], sh4r.r[Rn] ); :}
1.96 MOV Rm, Rn {: sh4r.r[Rn] = sh4r.r[Rm]; :}
1.97 -MOV.B @Rm+, Rn {: sh4r.r[Rn] = MEM_READ_BYTE( sh4r.r[Rm] ); sh4r.r[Rm] ++; :}
1.98 -MOV.W @Rm+, Rn {: CHECKRALIGN16( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_WORD( sh4r.r[Rm] ); sh4r.r[Rm] += 2; :}
1.99 -MOV.L @Rm+, Rn {: CHECKRALIGN32( sh4r.r[Rm] ); sh4r.r[Rn] = MEM_READ_LONG( sh4r.r[Rm] ); sh4r.r[Rm] += 4; :}
1.100 + MOV.B @Rm+, Rn {: MEM_READ_BYTE( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] ++; :}
1.101 + MOV.W @Rm+, Rn {: CHECKRALIGN16( sh4r.r[Rm] ); MEM_READ_WORD( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] += 2; :}
1.102 + MOV.L @Rm+, Rn {: CHECKRALIGN32( sh4r.r[Rm] ); MEM_READ_LONG( sh4r.r[Rm], sh4r.r[Rn] ); sh4r.r[Rm] += 4; :}
1.103 MOV.L @(disp, PC), Rn {:
1.104 CHECKSLOTILLEGAL();
1.105 tmp = (pc&0xFFFFFFFC) + disp + 4;
1.106 - sh4r.r[Rn] = MEM_READ_LONG( tmp );
1.107 + MEM_READ_LONG( tmp, sh4r.r[Rn] );
1.108 :}
1.109 MOV.B R0, @(disp, GBR) {: MEM_WRITE_BYTE( sh4r.gbr + disp, R0 ); :}
1.110 MOV.W R0, @(disp, GBR) {:
1.111 @@ -411,16 +412,16 @@
1.112 CHECKWALIGN32( tmp );
1.113 MEM_WRITE_LONG( tmp, R0 );
1.114 :}
1.115 -MOV.B @(disp, GBR), R0 {: R0 = MEM_READ_BYTE( sh4r.gbr + disp ); :}
1.116 + MOV.B @(disp, GBR), R0 {: MEM_READ_BYTE( sh4r.gbr + disp, R0 ); :}
1.117 MOV.W @(disp, GBR), R0 {:
1.118 tmp = sh4r.gbr + disp;
1.119 CHECKRALIGN16( tmp );
1.120 - R0 = MEM_READ_WORD( tmp );
1.121 + MEM_READ_WORD( tmp, R0 );
1.122 :}
1.123 MOV.L @(disp, GBR), R0 {:
1.124 tmp = sh4r.gbr + disp;
1.125 CHECKRALIGN32( tmp );
1.126 - R0 = MEM_READ_LONG( tmp );
1.127 + MEM_READ_LONG( tmp, R0 );
1.128 :}
1.129 MOV.B R0, @(disp, Rn) {: MEM_WRITE_BYTE( sh4r.r[Rn] + disp, R0 ); :}
1.130 MOV.W R0, @(disp, Rn) {:
1.131 @@ -428,16 +429,16 @@
1.132 CHECKWALIGN16( tmp );
1.133 MEM_WRITE_WORD( tmp, R0 );
1.134 :}
1.135 -MOV.B @(disp, Rm), R0 {: R0 = MEM_READ_BYTE( sh4r.r[Rm] + disp ); :}
1.136 + MOV.B @(disp, Rm), R0 {: MEM_READ_BYTE( sh4r.r[Rm] + disp, R0 ); :}
1.137 MOV.W @(disp, Rm), R0 {:
1.138 tmp = sh4r.r[Rm] + disp;
1.139 CHECKRALIGN16( tmp );
1.140 - R0 = MEM_READ_WORD( tmp );
1.141 + MEM_READ_WORD( tmp, R0 );
1.142 :}
1.143 MOV.W @(disp, PC), Rn {:
1.144 CHECKSLOTILLEGAL();
1.145 tmp = pc + 4 + disp;
1.146 - sh4r.r[Rn] = MEM_READ_WORD( tmp );
1.147 + MEM_READ_WORD( tmp, sh4r.r[Rn] );
1.148 :}
1.149 MOVA @(disp, PC), R0 {:
1.150 CHECKSLOTILLEGAL();
1.151 @@ -506,9 +507,11 @@
1.152 MAC.W @Rm+, @Rn+ {:
1.153 CHECKRALIGN16( sh4r.r[Rn] );
1.154 CHECKRALIGN16( sh4r.r[Rm] );
1.155 - int32_t stmp = SIGNEXT16(MEM_READ_WORD(sh4r.r[Rn]));
1.156 + MEM_READ_WORD(sh4r.r[Rn], tmp);
1.157 + int32_t stmp = SIGNEXT16(tmp);
1.158 sh4r.r[Rn] += 2;
1.159 - stmp = stmp * SIGNEXT16(MEM_READ_WORD(sh4r.r[Rm]));
1.160 + MEM_READ_WORD(sh4r.r[Rm], tmp);
1.161 + stmp = stmp * SIGNEXT16(tmp);
1.162 sh4r.r[Rm] += 2;
1.163 if( sh4r.s ) {
1.164 int64_t tmpl = (int64_t)((int32_t)sh4r.mac) + (int64_t)stmp;
1.165 @@ -527,9 +530,11 @@
1.166 MAC.L @Rm+, @Rn+ {:
1.167 CHECKRALIGN32( sh4r.r[Rm] );
1.168 CHECKRALIGN32( sh4r.r[Rn] );
1.169 - int64_t tmpl = SIGNEXT32(MEM_READ_LONG(sh4r.r[Rn]));
1.170 + MEM_READ_LONG(sh4r.r[Rn], tmp);
1.171 + int64_t tmpl = SIGNEXT32(tmp);
1.172 sh4r.r[Rn] += 4;
1.173 - tmpl = tmpl * SIGNEXT32(MEM_READ_LONG(sh4r.r[Rm])) + sh4r.mac;
1.174 + MEM_READ_LONG(sh4r.r[Rm], tmp);
1.175 + tmpl = tmpl * SIGNEXT32(tmp) + sh4r.mac;
1.176 sh4r.r[Rm] += 4;
1.177 if( sh4r.s ) {
1.178 /* 48-bit Saturation. Yuch */
1.179 @@ -703,15 +708,17 @@
1.180 :}
1.181 LDS.L @Rm+, MACH {:
1.182 CHECKRALIGN32( sh4r.r[Rm] );
1.183 + MEM_READ_LONG(sh4r.r[Rm], tmp);
1.184 sh4r.mac = (sh4r.mac & 0x00000000FFFFFFFF) |
1.185 - (((uint64_t)MEM_READ_LONG(sh4r.r[Rm]))<<32);
1.186 + (((uint64_t)tmp)<<32);
1.187 sh4r.r[Rm] += 4;
1.188 :}
1.189 LDC.L @Rm+, SR {:
1.190 CHECKSLOTILLEGAL();
1.191 CHECKPRIV();
1.192 CHECKWALIGN32( sh4r.r[Rm] );
1.193 - sh4_write_sr( MEM_READ_LONG(sh4r.r[Rm]) );
1.194 + MEM_READ_LONG(sh4r.r[Rm], tmp);
1.195 + sh4_write_sr( tmp );
1.196 sh4r.r[Rm] +=4;
1.197 :}
1.198 LDS Rm, MACH {:
1.199 @@ -730,7 +737,7 @@
1.200 LDC.L @Rm+, SGR {:
1.201 CHECKPRIV();
1.202 CHECKRALIGN32( sh4r.r[Rm] );
1.203 - sh4r.sgr = MEM_READ_LONG(sh4r.r[Rm]);
1.204 + MEM_READ_LONG(sh4r.r[Rm], sh4r.sgr);
1.205 sh4r.r[Rm] +=4;
1.206 :}
1.207 STS MACL, Rn {: sh4r.r[Rn] = (uint32_t)sh4r.mac; :}
1.208 @@ -746,13 +753,14 @@
1.209 :}
1.210 LDS.L @Rm+, MACL {:
1.211 CHECKRALIGN32( sh4r.r[Rm] );
1.212 + MEM_READ_LONG(sh4r.r[Rm], tmp);
1.213 sh4r.mac = (sh4r.mac & 0xFFFFFFFF00000000LL) |
1.214 - (uint64_t)((uint32_t)MEM_READ_LONG(sh4r.r[Rm]));
1.215 + (uint64_t)((uint32_t)tmp);
1.216 sh4r.r[Rm] += 4;
1.217 :}
1.218 LDC.L @Rm+, GBR {:
1.219 CHECKRALIGN32( sh4r.r[Rm] );
1.220 - sh4r.gbr = MEM_READ_LONG(sh4r.r[Rm]);
1.221 + MEM_READ_LONG(sh4r.r[Rm], sh4r.gbr);
1.222 sh4r.r[Rm] +=4;
1.223 :}
1.224 LDS Rm, MACL {:
1.225 @@ -774,13 +782,13 @@
1.226 :}
1.227 LDS.L @Rm+, PR {:
1.228 CHECKRALIGN32( sh4r.r[Rm] );
1.229 - sh4r.pr = MEM_READ_LONG( sh4r.r[Rm] );
1.230 + MEM_READ_LONG( sh4r.r[Rm], sh4r.pr );
1.231 sh4r.r[Rm] += 4;
1.232 :}
1.233 LDC.L @Rm+, VBR {:
1.234 CHECKPRIV();
1.235 CHECKRALIGN32( sh4r.r[Rm] );
1.236 - sh4r.vbr = MEM_READ_LONG(sh4r.r[Rm]);
1.237 + MEM_READ_LONG(sh4r.r[Rm], sh4r.vbr);
1.238 sh4r.r[Rm] +=4;
1.239 :}
1.240 LDS Rm, PR {: sh4r.pr = sh4r.r[Rm]; :}
1.241 @@ -807,7 +815,7 @@
1.242 LDC.L @Rm+, SSR {:
1.243 CHECKPRIV();
1.244 CHECKRALIGN32( sh4r.r[Rm] );
1.245 - sh4r.ssr = MEM_READ_LONG(sh4r.r[Rm]);
1.246 + MEM_READ_LONG(sh4r.r[Rm], sh4r.ssr);
1.247 sh4r.r[Rm] +=4;
1.248 :}
1.249 LDC Rm, SSR {:
1.250 @@ -823,7 +831,7 @@
1.251 LDC.L @Rm+, SPC {:
1.252 CHECKPRIV();
1.253 CHECKRALIGN32( sh4r.r[Rm] );
1.254 - sh4r.spc = MEM_READ_LONG(sh4r.r[Rm]);
1.255 + MEM_READ_LONG(sh4r.r[Rm], sh4r.spc);
1.256 sh4r.r[Rm] +=4;
1.257 :}
1.258 LDC Rm, SPC {:
1.259 @@ -838,7 +846,7 @@
1.260 :}
1.261 LDS.L @Rm+, FPUL {:
1.262 CHECKRALIGN32( sh4r.r[Rm] );
1.263 - sh4r.fpul = MEM_READ_LONG(sh4r.r[Rm]);
1.264 + MEM_READ_LONG(sh4r.r[Rm], sh4r.fpul);
1.265 sh4r.r[Rm] +=4;
1.266 :}
1.267 LDS Rm, FPUL {: sh4r.fpul = sh4r.r[Rm]; :}
1.268 @@ -850,7 +858,7 @@
1.269 :}
1.270 LDS.L @Rm+, FPSCR {:
1.271 CHECKRALIGN32( sh4r.r[Rm] );
1.272 - sh4r.fpscr = MEM_READ_LONG(sh4r.r[Rm]);
1.273 + MEM_READ_LONG(sh4r.r[Rm], sh4r.fpscr);
1.274 sh4r.r[Rm] +=4;
1.275 sh4r.fr_bank = &sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21][0];
1.276 :}
1.277 @@ -868,7 +876,7 @@
1.278 LDC.L @Rm+, DBR {:
1.279 CHECKPRIV();
1.280 CHECKRALIGN32( sh4r.r[Rm] );
1.281 - sh4r.dbr = MEM_READ_LONG(sh4r.r[Rm]);
1.282 + MEM_READ_LONG(sh4r.r[Rm], sh4r.dbr);
1.283 sh4r.r[Rm] +=4;
1.284 :}
1.285 LDC Rm, DBR {:
1.286 @@ -884,7 +892,7 @@
1.287 LDC.L @Rm+, Rn_BANK {:
1.288 CHECKPRIV();
1.289 CHECKRALIGN32( sh4r.r[Rm] );
1.290 - sh4r.r_bank[Rn_BANK] = MEM_READ_LONG( sh4r.r[Rm] );
1.291 + MEM_READ_LONG( sh4r.r[Rm], sh4r.r_bank[Rn_BANK] );
1.292 sh4r.r[Rm] += 4;
1.293 :}
1.294 LDC Rm, Rn_BANK {:
.