Search
lxdream.org :: lxdream/src/mem.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.c
changeset 461:63d4de8dcec6
prev422:61a0598e07ff
next466:a6935f46ed78
author nkeynes
date Tue Oct 23 10:48:24 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Reload BIOS/flash when changed in configuration.
Fix mem_load_rom to deal with repeat loads and dodgy files
file annotate diff log raw
1.1 --- a/src/mem.c Sat Oct 06 09:03:24 2007 +0000
1.2 +++ b/src/mem.c Tue Oct 23 10:48:24 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: mem.c,v 1.15 2007-10-06 08:59:42 nkeynes Exp $
1.6 + * $Id: mem.c,v 1.16 2007-10-23 10:48:24 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 @@ -270,18 +270,21 @@
1.11 char *mem;
1.12 int fd;
1.13 uint32_t calc_crc;
1.14 - fd = open( file, O_RDONLY );
1.15 - if( fd == -1 ) {
1.16 - ERROR( "Bios file not found: %s", file );
1.17 - return NULL;
1.18 +
1.19 + mem = mem_get_region(base);
1.20 + if( mem == NULL ) {
1.21 + mem = mmap( NULL, size, PROT_WRITE|PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0 );
1.22 + if( mem == MAP_FAILED ) {
1.23 + ERROR( "Unable to allocate ROM memory: %s (%s)", file, strerror(errno) );
1.24 + return NULL;
1.25 + }
1.26 + mem_map_region( mem, base, size, file, MEM_FLAG_ROM, size, base );
1.27 + } else {
1.28 + mprotect( mem, size, PROT_READ|PROT_WRITE );
1.29 }
1.30 - mem = mmap( NULL, size, PROT_READ, MAP_PRIVATE, fd, 0 );
1.31 - if( mem == MAP_FAILED ) {
1.32 - ERROR( "Unable to map bios file: %s (%s)", file, strerror(errno) );
1.33 - close(fd);
1.34 - return NULL;
1.35 - }
1.36 - mem_map_region( mem, base, size, file, MEM_FLAG_ROM, size, base );
1.37 +
1.38 + mem_load_block( file, base, size );
1.39 + mprotect( mem, size, PROT_READ );
1.40
1.41 /* CRC check */
1.42 calc_crc = crc32(0L, (unsigned char *)mem, size);
.