Search
lxdream.org :: lxdream/src/mem.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.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/mem.c Sat Dec 20 03:01:40 2008 +0000
1.2 +++ b/src/mem.c Mon Dec 22 09:51:11 2008 +0000
1.3 @@ -36,6 +36,9 @@
1.4 #include "dreamcast.h"
1.5
1.6 sh4ptr_t *page_map = NULL;
1.7 +mem_region_fn_t *ext_address_space = NULL;
1.8 +
1.9 +extern struct mem_region_fn mem_region_unmapped;
1.10
1.11 int mem_load(FILE *f);
1.12 void mem_save(FILE *f);
1.13 @@ -62,15 +65,24 @@
1.14
1.15 void mem_init( void )
1.16 {
1.17 + int i;
1.18 + mem_region_fn_t *ptr;
1.19 page_map = mmap( NULL, sizeof(sh4ptr_t) * LXDREAM_PAGE_TABLE_ENTRIES,
1.20 PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0 );
1.21 if( page_map == MAP_FAILED ) {
1.22 - ERROR( "Unable to allocate page map! (%s)", strerror(errno) );
1.23 - page_map = NULL;
1.24 - return;
1.25 + FATAL( "Unable to allocate page map! (%s)", strerror(errno) );
1.26 + }
1.27 + memset( page_map, 0, sizeof(sh4ptr_t) * LXDREAM_PAGE_TABLE_ENTRIES );
1.28 +
1.29 + ext_address_space = mmap( NULL, sizeof(mem_region_fn_t) * LXDREAM_PAGE_TABLE_ENTRIES,
1.30 + PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0 );
1.31 + if( ext_address_space == MAP_FAILED ) {
1.32 + FATAL( "Unable to allocate external memory map (%s)", strerror(errno) );
1.33 }
1.34
1.35 - memset( page_map, 0, sizeof(sh4ptr_t) * LXDREAM_PAGE_TABLE_ENTRIES );
1.36 + for( ptr = ext_address_space, i = LXDREAM_PAGE_TABLE_ENTRIES; i > 0; ptr++, i-- ) {
1.37 + *ptr = &mem_region_unmapped;
1.38 + }
1.39 }
1.40
1.41 void mem_reset( void )
1.42 @@ -238,8 +250,10 @@
1.43 num_mem_rgns++;
1.44
1.45 do {
1.46 - for( i=0; i<size>>LXDREAM_PAGE_BITS; i++ )
1.47 + for( i=0; i<size>>LXDREAM_PAGE_BITS; i++ ) {
1.48 page_map[(base>>LXDREAM_PAGE_BITS)+i] = mem + (i<<LXDREAM_PAGE_BITS);
1.49 + ext_address_space[(base>>LXDREAM_PAGE_BITS)+i] = fn;
1.50 + }
1.51 base += repeat_offset;
1.52 } while( base <= repeat_until );
1.53
1.54 @@ -336,6 +350,7 @@
1.55 P4_io[(io->base&0x1FFFFFFF)>>19] = io;
1.56 } else {
1.57 page_map[io->base>>12] = (sh4ptr_t)(uintptr_t)num_io_rgns;
1.58 + ext_address_space[io->base>>12] = &io->fn;
1.59 }
1.60 io_rgn[num_io_rgns] = io;
1.61 num_io_rgns++;
.