Search
lxdream.org :: lxdream/src/sh4/sh4mem.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4mem.c
changeset 400:049d72a7a229
prev371:f2fe152cfc9b
next406:9289b62f8f33
author nkeynes
date Thu Sep 20 08:35:04 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add translation cache invalidation
file annotate diff log raw
1.1 --- a/src/sh4/sh4mem.c Sat Sep 08 04:38:11 2007 +0000
1.2 +++ b/src/sh4/sh4mem.c Thu Sep 20 08:35:04 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: sh4mem.c,v 1.22 2007-09-08 04:38:11 nkeynes Exp $
1.6 + * $Id: sh4mem.c,v 1.23 2007-09-20 08:35:04 nkeynes Exp $
1.7 * sh4mem.c is responsible for the SH4's access to memory (including memory
1.8 * mapped I/O), using the page maps created in mem.c
1.9 *
1.10 @@ -152,6 +152,7 @@
1.11 TRACE_IO( "Long read %08X <= %08X", page, (addr&0xFFF), val, addr );
1.12 return val;
1.13 } else {
1.14 + // fprintf( stderr, "MOV.L %08X <= %08X\n",*(int32_t *)(page+(addr&0xFFF)), addr );
1.15 return *(int32_t *)(page+(addr&0xFFF));
1.16 }
1.17 }
1.18 @@ -227,6 +228,7 @@
1.19 TRACE_IO( "Byte read %02X <= %08X", page, (addr&0xFFF), val&0xFF, addr );
1.20 return val;
1.21 } else {
1.22 + // fprintf( stderr, "MOV.B %02X <= %08X\n",(uint32_t)*(uint8_t *)(page+(addr&0xFFF)), addr );
1.23 return SIGNEXT8(*(int8_t *)(page+(addr&0xFFF)));
1.24 }
1.25 }
1.26 @@ -234,7 +236,8 @@
1.27 void sh4_write_long( uint32_t addr, uint32_t val )
1.28 {
1.29 char *page;
1.30 -
1.31 +
1.32 + // fprintf( stderr, "MOV.L %08X => %08X\n", val, addr );
1.33 CHECK_WRITE_WATCH(addr,4,val);
1.34
1.35 if( addr >= 0xE0000000 ) {
1.36 @@ -275,6 +278,7 @@
1.37 TRACE_IO( "Long write %08X => %08X", page, (addr&0xFFF), val, addr );
1.38 io_rgn[(uint32_t)page]->io_write(addr&0xFFF, val);
1.39 } else {
1.40 + xlat_invalidate_long(addr);
1.41 *(uint32_t *)(page+(addr&0xFFF)) = val;
1.42 }
1.43 }
1.44 @@ -283,6 +287,7 @@
1.45 {
1.46 char *page;
1.47
1.48 + // fprintf( stderr, "MOV.W %04X => %08X\n", val, addr );
1.49 CHECK_WRITE_WATCH(addr,2,val);
1.50
1.51 if( addr >= 0xE0000000 ) {
1.52 @@ -302,6 +307,11 @@
1.53 sh4_stop();
1.54 return;
1.55 }
1.56 + if( (addr&0x1FFFFFFF) < 0x200000 ) {
1.57 + ERROR( "Attempted write to read-only memory: %08X => %08X", val, addr);
1.58 + sh4_stop();
1.59 + return;
1.60 + }
1.61 page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
1.62 if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
1.63 if( page == NULL ) {
1.64 @@ -311,6 +321,7 @@
1.65 TRACE_IO( "Word write %04X => %08X", page, (addr&0xFFF), val&0xFFFF, addr );
1.66 io_rgn[(uint32_t)page]->io_write(addr&0xFFF, val);
1.67 } else {
1.68 + xlat_invalidate_word(addr);
1.69 *(uint16_t *)(page+(addr&0xFFF)) = val;
1.70 }
1.71 }
1.72 @@ -319,6 +330,7 @@
1.73 {
1.74 char *page;
1.75
1.76 + // fprintf( stderr, "MOV.B %02X => %08X\n", val, addr );
1.77 CHECK_WRITE_WATCH(addr,1,val);
1.78
1.79 if( addr >= 0xE0000000 ) {
1.80 @@ -339,6 +351,11 @@
1.81 sh4_stop();
1.82 return;
1.83 }
1.84 + if( (addr&0x1FFFFFFF) < 0x200000 ) {
1.85 + ERROR( "Attempted write to read-only memory: %08X => %08X", val, addr);
1.86 + sh4_stop();
1.87 + return;
1.88 + }
1.89 page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
1.90 if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
1.91 if( page == NULL ) {
1.92 @@ -348,6 +365,7 @@
1.93 TRACE_IO( "Byte write %02X => %08X", page, (addr&0xFFF), val&0xFF, addr );
1.94 io_rgn[(uint32_t)page]->io_write( (addr&0xFFF), val);
1.95 } else {
1.96 + xlat_invalidate_word(addr);
1.97 *(uint8_t *)(page+(addr&0xFFF)) = val;
1.98 }
1.99 }
1.100 @@ -355,7 +373,7 @@
1.101
1.102
1.103 /* FIXME: Handle all the many special cases when the range doesn't fall cleanly
1.104 - * into the same memory black
1.105 + * into the same memory block
1.106 */
1.107 void mem_copy_from_sh4( char *dest, uint32_t srcaddr, size_t count ) {
1.108 if( srcaddr >= 0x04000000 && srcaddr < 0x05000000 ) {
1.109 @@ -386,6 +404,7 @@
1.110 if( dest == NULL )
1.111 ERROR( "Attempted block write to unknown address %08X", destaddr );
1.112 else {
1.113 + xlat_invalidate_block( destaddr, count );
1.114 memcpy( dest, src, count );
1.115 }
1.116 }
.