Search
lxdream.org :: lxdream/src/mem.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.c
changeset 488:d19a63e47cd9
prev480:d28c2992f5ee
next490:1e0f9940e064
author nkeynes
date Sun Nov 04 01:03:00 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Change MAP_ANONYMOUS to MAP_ANON for bsd compatibility
file annotate diff log raw
1.1 --- a/src/mem.c Wed Oct 31 11:53:35 2007 +0000
1.2 +++ b/src/mem.c Sun Nov 04 01:03:00 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: mem.c,v 1.19 2007-10-31 11:53:35 nkeynes Exp $
1.6 + * $Id: mem.c,v 1.20 2007-11-04 01:03:00 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 @@ -17,6 +17,7 @@
1.11 */
1.12 #define MODULE mem_module
1.13
1.14 +#include <sys/types.h>
1.15 #include <sys/mman.h>
1.16 #include <sys/stat.h>
1.17 #include <assert.h>
1.18 @@ -49,7 +50,7 @@
1.19 void *mem_alloc_pages( int n )
1.20 {
1.21 void *mem = mmap( NULL, n * 4096,
1.22 - PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0 );
1.23 + PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0 );
1.24 if( mem == MAP_FAILED ) {
1.25 ERROR( "Memory allocation failure! (%s)", strerror(errno) );
1.26 return NULL;
1.27 @@ -61,7 +62,7 @@
1.28 void mem_init( void )
1.29 {
1.30 page_map = mmap( NULL, sizeof(char *) * PAGE_TABLE_ENTRIES,
1.31 - PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0 );
1.32 + PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0 );
1.33 if( page_map == MAP_FAILED ) {
1.34 ERROR( "Unable to allocate page map! (%s)", strerror(errno) );
1.35 page_map = NULL;
1.36 @@ -270,10 +271,11 @@
1.37 {
1.38 char *mem;
1.39 uint32_t calc_crc;
1.40 + int status;
1.41
1.42 mem = mem_get_region(base);
1.43 if( mem == NULL ) {
1.44 - mem = mmap( NULL, size, PROT_WRITE|PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0 );
1.45 + mem = mmap( NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE, -1, 0 );
1.46 if( mem == MAP_FAILED ) {
1.47 ERROR( "Unable to allocate ROM memory: %s (%s)", file, strerror(errno) );
1.48 return NULL;
1.49 @@ -283,14 +285,16 @@
1.50 mprotect( mem, size, PROT_READ|PROT_WRITE );
1.51 }
1.52
1.53 - mem_load_block( file, base, size );
1.54 + status = mem_load_block( file, base, size );
1.55 mprotect( mem, size, PROT_READ );
1.56
1.57 - /* CRC check */
1.58 - calc_crc = crc32(0L, (unsigned char *)mem, size);
1.59 - if( calc_crc != crc ) {
1.60 - WARN( "Bios CRC Mismatch in %s: %08X (expected %08X)",
1.61 - file, calc_crc, crc);
1.62 + if( status == 0 ) {
1.63 + /* CRC check only if we loaded something */
1.64 + calc_crc = crc32(0L, (unsigned char *)mem, size);
1.65 + if( calc_crc != crc ) {
1.66 + WARN( "Bios CRC Mismatch in %s: %08X (expected %08X)",
1.67 + file, calc_crc, crc);
1.68 + }
1.69 }
1.70
1.71 return mem;
.