Search
lxdream.org :: lxdream/src/sh4/sh4mem.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4mem.c
changeset 930:07e5b11419db
prev929:fd8cb0c82f5f
next931:430048ea8b71
author nkeynes
date Mon Dec 22 09:51:11 2008 +0000 (11 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change Remove pointer cache and add full address-space map. Much better
file annotate diff log raw
1.1 --- a/src/sh4/sh4mem.c Sat Dec 20 03:01:40 2008 +0000
1.2 +++ b/src/sh4/sh4mem.c Mon Dec 22 09:51:11 2008 +0000
1.3 @@ -50,6 +50,8 @@
1.4
1.5 extern struct mmio_region *P4_io[];
1.6
1.7 +mem_region_fn_t *sh4_address_space;
1.8 +
1.9 /********************* The "unmapped" address space ********************/
1.10 /* Always reads as 0, writes have no effect */
1.11 static int32_t FASTCALL unmapped_read_long( sh4addr_t addr )
1.12 @@ -422,93 +424,89 @@
1.13 int32_t FASTCALL sh4_read_long( sh4addr_t addr )
1.14 {
1.15 rl_count++;
1.16 - uint32_t page = (addr & 0xFFFFF000);
1.17 - if( page == last_page ) {
1.18 - hit_count++;
1.19 - return last_region->read_long(addr);
1.20 - } else {
1.21 - miss_count++;
1.22 - last_page = page;
1.23 - last_region = sh7750_decode_address(addr);
1.24 - return last_region->read_long(addr);
1.25 - }
1.26 + return sh4_address_space[addr>>12]->read_long(addr);
1.27 }
1.28
1.29 int32_t FASTCALL sh4_read_word( sh4addr_t addr )
1.30 {
1.31 rw_count++;
1.32 - uint32_t page = (addr & 0xFFFFF000);
1.33 - if( page == last_page ) {
1.34 - hit_count++;
1.35 - return last_region->read_word(addr);
1.36 - } else {
1.37 - miss_count++;
1.38 - last_page = page;
1.39 - last_region = sh7750_decode_address(addr);
1.40 - return last_region->read_word(addr);
1.41 - }
1.42 + return sh4_address_space[addr>>12]->read_word(addr);
1.43 }
1.44
1.45 int32_t FASTCALL sh4_read_byte( sh4addr_t addr )
1.46 {
1.47 rb_count++;
1.48 - uint32_t page = (addr & 0xFFFFF000);
1.49 - if( page == last_page ) {
1.50 - hit_count++;
1.51 - return last_region->read_byte(addr);
1.52 - } else {
1.53 - miss_count++;
1.54 - last_page = page;
1.55 - last_region = sh7750_decode_address(addr);
1.56 - return last_region->read_byte(addr);
1.57 - }
1.58 + return sh4_address_space[addr>>12]->read_byte(addr);
1.59 }
1.60
1.61 void FASTCALL sh4_write_long( sh4addr_t addr, uint32_t val )
1.62 {
1.63 wl_count++;
1.64 - uint32_t page = (addr & 0xFFFFF000);
1.65 - if( page == last_page ) {
1.66 - hit_count++;
1.67 - last_region->write_long(addr, val);
1.68 - } else {
1.69 - miss_count++;
1.70 - last_page = page;
1.71 - last_region = sh7750_decode_address(addr);
1.72 - last_region->write_long(addr,val);
1.73 - }
1.74 + sh4_address_space[addr>>12]->write_long(addr, val);
1.75 }
1.76
1.77 void FASTCALL sh4_write_word( sh4addr_t addr, uint32_t val )
1.78 {
1.79 ww_count++;
1.80 - uint32_t page = (addr & 0xFFFFF000);
1.81 - if( page == last_page ) {
1.82 - hit_count++;
1.83 - last_region->write_word(addr, val);
1.84 - } else {
1.85 - miss_count++;
1.86 - last_page = page;
1.87 - last_region = sh7750_decode_address(addr);
1.88 - last_region->write_word(addr,val);
1.89 - }
1.90 + sh4_address_space[addr>>12]->write_word(addr,val);
1.91 }
1.92
1.93 void FASTCALL sh4_write_byte( sh4addr_t addr, uint32_t val )
1.94 {
1.95 wb_count++;
1.96 - uint32_t page = (addr & 0xFFFFF000);
1.97 - if( page == last_page ) {
1.98 - hit_count++;
1.99 - last_region->write_byte(addr, val);
1.100 - } else {
1.101 - miss_count++;
1.102 - last_page = page;
1.103 - last_region = sh7750_decode_address(addr);
1.104 - last_region->write_byte(addr,val);
1.105 + sh4_address_space[addr>>12]->write_byte(addr, val);
1.106 +}
1.107 +
1.108 +extern mem_region_fn_t *ext_address_space;
1.109 +
1.110 +static void sh4_register_mem_region( uint32_t start, uint32_t end, mem_region_fn_t fn )
1.111 +{
1.112 + int count = (end - start) >> 12;
1.113 + mem_region_fn_t *ptr = &sh4_address_space[start>>12];
1.114 + while( count-- > 0 ) {
1.115 + *ptr++ = fn;
1.116 }
1.117 }
1.118 +
1.119
1.120 +void sh4_mem_init()
1.121 +{
1.122 + int i;
1.123 + mem_region_fn_t *ptr;
1.124 + sh4_address_space = mem_alloc_pages( sizeof(mem_region_fn_t) * 256 );
1.125 + for( i=0, ptr = sh4_address_space; i<7; i++, ptr += LXDREAM_PAGE_TABLE_ENTRIES ) {
1.126 + memcpy( ptr, ext_address_space, sizeof(mem_region_fn_t) * LXDREAM_PAGE_TABLE_ENTRIES );
1.127 + }
1.128 +
1.129 + /* Setup main P4 regions */
1.130 + sh4_register_mem_region( 0xE0000000, 0xE4000000, &p4_region_storequeue );
1.131 + sh4_register_mem_region( 0xE4000000, 0xF0000000, &mem_region_unmapped );
1.132 + sh4_register_mem_region( 0xF0000000, 0xF1000000, &p4_region_icache_addr );
1.133 + sh4_register_mem_region( 0xF1000000, 0xF2000000, &p4_region_icache_data );
1.134 + sh4_register_mem_region( 0xF2000000, 0xF3000000, &p4_region_itlb_addr );
1.135 + sh4_register_mem_region( 0xF3000000, 0xF4000000, &p4_region_itlb_data );
1.136 + sh4_register_mem_region( 0xF4000000, 0xF5000000, &p4_region_ocache_addr );
1.137 + sh4_register_mem_region( 0xF5000000, 0xF6000000, &p4_region_ocache_data );
1.138 + sh4_register_mem_region( 0xF6000000, 0xF7000000, &p4_region_utlb_addr );
1.139 + sh4_register_mem_region( 0xF7000000, 0xF8000000, &p4_region_utlb_data );
1.140 + sh4_register_mem_region( 0xF8000000, 0x00000000, &mem_region_unmapped );
1.141 +
1.142 + /* Setup P4 control region */
1.143 + sh4_register_mem_region( 0xFF000000, 0xFF001000, &mmio_region_MMU.fn );
1.144 + sh4_register_mem_region( 0xFF100000, 0xFF101000, &mmio_region_PMM.fn );
1.145 + sh4_register_mem_region( 0xFF200000, 0xFF201000, &mmio_region_UBC.fn );
1.146 + sh4_register_mem_region( 0xFF800000, 0xFF801000, &mmio_region_BSC.fn );
1.147 + sh4_register_mem_region( 0xFF900000, 0xFFA00000, &mem_region_unmapped ); // SDMR2 + SDMR3
1.148 + sh4_register_mem_region( 0xFFA00000, 0xFFA01000, &mmio_region_DMAC.fn );
1.149 + sh4_register_mem_region( 0xFFC00000, 0xFFC01000, &mmio_region_CPG.fn );
1.150 + sh4_register_mem_region( 0xFFC80000, 0xFFC81000, &mmio_region_RTC.fn );
1.151 + sh4_register_mem_region( 0xFFD00000, 0xFFD01000, &mmio_region_INTC.fn );
1.152 + sh4_register_mem_region( 0xFFD80000, 0xFFD81000, &mmio_region_TMU.fn );
1.153 + sh4_register_mem_region( 0xFFE00000, 0xFFE01000, &mmio_region_SCI.fn );
1.154 + sh4_register_mem_region( 0xFFE80000, 0xFFE81000, &mmio_region_SCIF.fn );
1.155 + sh4_register_mem_region( 0xFFF00000, 0xFFF01000, &mem_region_unmapped ); // H-UDI
1.156 +}
1.157 +
1.158 void print_sh4mem_stats() {
1.159 printf( "Decodes to p4: %d sq: %d\n", p4_count+sq_count, sq_count );
1.160 printf( "Decodes to sdram: %d\n", decode_sdram );
.