Search
lxdream.org :: lxdream/src/mem.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.c
changeset 18:9a1b5d75703f
prev17:944f75eea496
next19:9da7a8e38f9d
author nkeynes
date Thu Dec 15 13:33:14 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Implement save states
file annotate diff log raw
1.1 --- a/src/mem.c Tue Dec 13 14:47:59 2005 +0000
1.2 +++ b/src/mem.c Thu Dec 15 13:33:14 2005 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: mem.c,v 1.4 2005-12-13 14:47:59 nkeynes Exp $
1.6 + * $Id: mem.c,v 1.5 2005-12-15 13:33:14 nkeynes Exp $
1.7 * mem.c is responsible for creating and maintaining the overall system memory
1.8 * map, as visible from the SH4 processor.
1.9 *
1.10 @@ -43,7 +43,7 @@
1.11 struct mmio_region *io_rgn[MAX_IO_REGIONS];
1.12 struct mmio_region *P4_io[4096];
1.13
1.14 -int num_io_rgns = 1, num_mem_rgns = 0;
1.15 +int num_io_rgns = 0, num_mem_rgns = 0;
1.16
1.17 void *mem_alloc_pages( int n )
1.18 {
1.19 @@ -97,7 +97,8 @@
1.20 fwrite( &mem_rgn[i].base, sizeof(uint32_t), 1, f );
1.21 fwrite( &mem_rgn[i].flags, sizeof(int), 1, f );
1.22 fwrite( &mem_rgn[i].size, sizeof(uint32_t), 1, f );
1.23 - fwrite( mem_rgn[i].mem, mem_rgn[i].size, 1, f );
1.24 + if( mem_rgn[i].flags != MEM_FLAG_ROM )
1.25 + fwrite( mem_rgn[i].mem, mem_rgn[i].size, 1, f );
1.26 }
1.27
1.28 /* All MMIO regions */
1.29 @@ -105,7 +106,9 @@
1.30 for( i=0; i<num_io_rgns; i++ ) {
1.31 fwrite_string( io_rgn[i]->id, f );
1.32 fwrite( &io_rgn[i]->base, sizeof( uint32_t ), 1, f );
1.33 - fwrite( io_rgn[i]->mem, 4096, 1, f );
1.34 + len = 4096;
1.35 + fwrite( &len, sizeof(len), 1, f );
1.36 + fwrite( io_rgn[i]->mem, len, 1, f );
1.37 }
1.38 }
1.39
1.40 @@ -113,10 +116,47 @@
1.41 {
1.42 char tmp[64];
1.43 uint32_t len;
1.44 + uint32_t base, size;
1.45 + int flags;
1.46 int i;
1.47
1.48 /* All memory regions */
1.49 -
1.50 + fread( &len, sizeof(len), 1, f );
1.51 + if( len != num_mem_rgns )
1.52 + return -1;
1.53 + for( i=0; i<len; i++ ) {
1.54 + fread_string( tmp, sizeof(tmp), f );
1.55 + fread( &base, sizeof(base), 1, f );
1.56 + fread( &flags, sizeof(flags), 1, f );
1.57 + fread( &size, sizeof(size), 1, f );
1.58 + if( strcmp( mem_rgn[i].name, tmp ) != 0 ||
1.59 + base != mem_rgn[i].base ||
1.60 + flags != mem_rgn[i].flags ||
1.61 + size != mem_rgn[i].size ) {
1.62 + ERROR( "Bad memory region %d %s", i, tmp );
1.63 + return -1;
1.64 + }
1.65 + if( flags != MEM_FLAG_ROM )
1.66 + fread( mem_rgn[i].mem, size, 1, f );
1.67 + }
1.68 +
1.69 + /* All MMIO regions */
1.70 + fread( &len, sizeof(len), 1, f );
1.71 + if( len != num_io_rgns )
1.72 + return -1;
1.73 + for( i=0; i<len; i++ ) {
1.74 + fread_string( tmp, sizeof(tmp), f );
1.75 + fread( &base, sizeof(base), 1, f );
1.76 + fread( &size, sizeof(size), 1, f );
1.77 + if( strcmp( io_rgn[i]->id, tmp ) != 0 ||
1.78 + base != io_rgn[i]->base ||
1.79 + size != 4096 ) {
1.80 + ERROR( "Bad MMIO region %d %s", i, tmp );
1.81 + return -1;
1.82 + }
1.83 + fread( io_rgn[i]->mem, size, 1, f );
1.84 + }
1.85 + return 0;
1.86 }
1.87
1.88 struct mem_region *mem_map_region( void *mem, uint32_t base, uint32_t size,
1.89 @@ -147,7 +187,7 @@
1.90
1.91 mem = mem_alloc_pages( size>>PAGE_BITS );
1.92
1.93 - mem_map_region( mem, base, size, name, 6 );
1.94 + mem_map_region( mem, base, size, name, MEM_FLAG_RAM );
1.95 return mem;
1.96 }
1.97
1.98 @@ -168,7 +208,7 @@
1.99 close(fd);
1.100 return NULL;
1.101 }
1.102 - mem_map_region( mem, base, size, file, 4 );
1.103 + mem_map_region( mem, base, size, file, MEM_FLAG_ROM );
1.104
1.105 /* CRC check */
1.106 calc_crc = crc32(0L, mem, size);
1.107 @@ -176,6 +216,7 @@
1.108 WARN( "Bios CRC Mismatch in %s: %08X (expected %08X)",
1.109 file, calc_crc, crc);
1.110 }
1.111 +
1.112 return mem;
1.113 }
1.114
.