Search
lxdream.org :: lxdream/src/sh4/mem.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/mem.c
changeset 2:42349f6ea216
prev1:eea311cfd33e
author nkeynes
date Sat Aug 21 06:15:49 2004 +0000 (16 years ago)
permissions -rw-r--r--
last change Commit changes into cvs
file annotate diff log raw
1.1 --- a/src/sh4/mem.c Sat Mar 13 00:03:32 2004 +0000
1.2 +++ b/src/sh4/mem.c Sat Aug 21 06:15:49 2004 +0000
1.3 @@ -11,10 +11,29 @@
1.4 #include "dream.h"
1.5 #include "sh4core.h"
1.6 #include "mem.h"
1.7 +#include "dreamcast.h"
1.8
1.9 #define OC_BASE 0x1C000000
1.10 #define OC_TOP 0x20000000
1.11
1.12 +#ifdef ENABLE_WATCH
1.13 +#define CHECK_READ_WATCH( addr, size ) \
1.14 + if( mem_is_watched(addr,size,WATCH_READ) != NULL ) { \
1.15 + WARN( "Watch triggered at %08X by %d byte read", addr, size ); \
1.16 + dreamcast_stop(); \
1.17 + }
1.18 +#define CHECK_WRITE_WATCH( addr, size, val ) \
1.19 + if( mem_is_watched(addr,size,WATCH_WRITE) != NULL ) { \
1.20 + WARN( "Watch triggered at %08X by %d byte write <= %0*X", addr, size, size*2, val ); \
1.21 + dreamcast_stop(); \
1.22 + }
1.23 +#else
1.24 +#define CHECK_READ_WATCH( addr, size )
1.25 +#define CHECK_WRITE_WATCH( addr, size )
1.26 +#endif
1.27 +
1.28 +#define TRANSLATE_VIDEO_64BIT_ADDRESS(a) ( (((a)&0x00FFFFF8)>>1)|(((a)&0x00000004)<<20)|((a)&0x03)|0x05000000 );
1.29 +
1.30 static char **page_map = NULL;
1.31 static char *cache = NULL;
1.32
1.33 @@ -209,7 +228,12 @@
1.34 {
1.35 struct mmio_region *io = P4_io[(addr&0x1FFFFFFF)>>19];
1.36 if( !io ) {
1.37 - ERROR( "Attempted write to unknown P4 region: %08X", addr );
1.38 + if( (addr & 0xFC000000) == 0xE0000000 ) {
1.39 + /* Store queue */
1.40 + SH4_WRITE_STORE_QUEUE( addr, val );
1.41 + } else {
1.42 + ERROR( "Attempted write to unknown P4 region: %08X", addr );
1.43 + }
1.44 } else {
1.45 io->io_write( addr&0xFFF, val );
1.46 }
1.47 @@ -227,6 +251,10 @@
1.48 if( addr > 0xE0000000 ) /* P4 Area, handled specially */
1.49 return SIGNEXT16(mem_read_p4( addr ));
1.50
1.51 + if( (addr&0x1F800000) == 0x04000000 ) {
1.52 + addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
1.53 + }
1.54 +
1.55 page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
1.56 if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
1.57 if( page == NULL ) {
1.58 @@ -243,9 +271,16 @@
1.59 int32_t mem_read_long( uint32_t addr )
1.60 {
1.61 char *page;
1.62 +
1.63 + CHECK_READ_WATCH(addr,4);
1.64 +
1.65 if( addr > 0xE0000000 ) /* P4 Area, handled specially */
1.66 return mem_read_p4( addr );
1.67
1.68 + if( (addr&0x1F800000) == 0x04000000 ) {
1.69 + addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
1.70 + }
1.71 +
1.72 if( IS_MMU_ENABLED() ) {
1.73 ERROR( "user-mode & mmu translation not implemented, aborting", NULL );
1.74 sh4_stop();
1.75 @@ -270,9 +305,16 @@
1.76 int32_t mem_read_word( uint32_t addr )
1.77 {
1.78 char *page;
1.79 +
1.80 + CHECK_READ_WATCH(addr,2);
1.81 +
1.82 if( addr > 0xE0000000 ) /* P4 Area, handled specially */
1.83 return SIGNEXT16(mem_read_p4( addr ));
1.84
1.85 + if( (addr&0x1F800000) == 0x04000000 ) {
1.86 + addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
1.87 + }
1.88 +
1.89 if( IS_MMU_ENABLED() ) {
1.90 ERROR( "user-mode & mmu translation not implemented, aborting", NULL );
1.91 sh4_stop();
1.92 @@ -297,8 +339,14 @@
1.93 int32_t mem_read_byte( uint32_t addr )
1.94 {
1.95 char *page;
1.96 +
1.97 + CHECK_READ_WATCH(addr,1);
1.98 +
1.99 if( addr > 0xE0000000 ) /* P4 Area, handled specially */
1.100 return SIGNEXT8(mem_read_p4( addr ));
1.101 + if( (addr&0x1F800000) == 0x04000000 ) {
1.102 + addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
1.103 + }
1.104
1.105 if( IS_MMU_ENABLED() ) {
1.106 ERROR( "user-mode & mmu translation not implemented, aborting", NULL );
1.107 @@ -325,14 +373,14 @@
1.108 {
1.109 char *page;
1.110
1.111 + CHECK_WRITE_WATCH(addr,4,val);
1.112 +
1.113 if( addr > 0xE0000000 ) {
1.114 mem_write_p4( addr, val );
1.115 return;
1.116 }
1.117 -
1.118 - if( addr & 0xFFFFF000 == 0x0CFF0000 ||
1.119 - addr & 0x0FFFF000 == 0x0C374000 ) {
1.120 - TRACE( "Long write to watched page: %08X => %08X", val, addr );
1.121 + if( (addr&0x1F800000) == 0x04000000 ) {
1.122 + addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
1.123 }
1.124
1.125 if( IS_MMU_ENABLED() ) {
1.126 @@ -340,6 +388,11 @@
1.127 sh4_stop();
1.128 return;
1.129 }
1.130 + if( (addr&0x1FFFFFFF) < 0x200000 ) {
1.131 + ERROR( "Attempted write to read-only memory: %08X => %08X", val, addr);
1.132 + sh4_stop();
1.133 + return;
1.134 + }
1.135 page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
1.136 if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
1.137 if( page == NULL ) {
1.138 @@ -357,10 +410,15 @@
1.139 {
1.140 char *page;
1.141
1.142 + CHECK_WRITE_WATCH(addr,2,val);
1.143 +
1.144 if( addr > 0xE0000000 ) {
1.145 mem_write_p4( addr, (int16_t)val );
1.146 return;
1.147 }
1.148 + if( (addr&0x1F800000) == 0x04000000 ) {
1.149 + addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
1.150 + }
1.151 if( IS_MMU_ENABLED() ) {
1.152 ERROR( "user-mode & mmu translation not implemented, aborting", NULL );
1.153 sh4_stop();
1.154 @@ -383,10 +441,16 @@
1.155 {
1.156 char *page;
1.157
1.158 + CHECK_WRITE_WATCH(addr,1,val);
1.159 +
1.160 if( addr > 0xE0000000 ) {
1.161 mem_write_p4( addr, (int8_t)val );
1.162 return;
1.163 }
1.164 + if( (addr&0x1F800000) == 0x04000000 ) {
1.165 + addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
1.166 + }
1.167 +
1.168 if( IS_MMU_ENABLED() ) {
1.169 ERROR( "user-mode & mmu translation not implemented, aborting", NULL );
1.170 sh4_stop();
1.171 @@ -414,3 +478,17 @@
1.172 return page+(addr&0xFFF);
1.173 }
1.174 }
1.175 +
1.176 +/* FIXME: Handle all the many special cases when the range doesn't fall cleanly
1.177 + * into the same memory black
1.178 + */
1.179 +
1.180 +void mem_copy_from_sh4( char *dest, uint32_t srcaddr, size_t count ) {
1.181 + char *src = mem_get_region(srcaddr);
1.182 + memcpy( dest, src, count );
1.183 +}
1.184 +
1.185 +void mem_copy_to_sh4( uint32_t destaddr, char *src, size_t count ) {
1.186 + char *dest = mem_get_region(destaddr);
1.187 + memcpy( dest, src, count );
1.188 +}
.