filename | src/mem.c |
changeset | 19:9da7a8e38f9d |
prev | 18:9a1b5d75703f |
next | 23:1ec3acd0594d |
author | nkeynes |
date | Thu Dec 22 07:38:12 2005 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Implement 95% of the SCIF serial interface Implement basic load_bin_file function to try to load demos directly Update TMU to run all 3 timers, start on general timing |
file | annotate | diff | log | raw |
1.1 --- a/src/mem.c Thu Dec 15 13:33:14 2005 +00001.2 +++ b/src/mem.c Thu Dec 22 07:38:12 2005 +00001.3 @@ -1,5 +1,5 @@1.4 /**1.5 - * $Id: mem.c,v 1.5 2005-12-15 13:33:14 nkeynes Exp $1.6 + * $Id: mem.c,v 1.6 2005-12-22 07:38:06 nkeynes Exp $1.7 * mem.c is responsible for creating and maintaining the overall system memory1.8 * map, as visible from the SH4 processor.1.9 *1.10 @@ -17,6 +17,7 @@1.11 */1.13 #include <sys/mman.h>1.14 +#include <sys/stat.h>1.15 #include <assert.h>1.16 #include <stdint.h>1.17 #include <stdlib.h>1.18 @@ -159,6 +160,43 @@1.19 return 0;1.20 }1.22 +void mem_save_block( const gchar *file, uint32_t start, uint32_t length )1.23 +{1.24 +1.25 +}1.26 +1.27 +int mem_load_block( const gchar *file, uint32_t start, uint32_t length )1.28 +{1.29 + char *region;1.30 + int len = 4096, total = 0;1.31 + uint32_t addr = start;1.32 + struct stat st;1.33 + FILE *f = fopen(file,"r");1.34 +1.35 + if( f == NULL )1.36 + return errno;1.37 + fstat( fileno(f), &st );1.38 + if( length == 0 || length == -1 )1.39 + length = st.st_size;1.40 +1.41 + while( total < length ) {1.42 + region = mem_get_region(addr);1.43 + len = 4096 - (addr & 0x0FFF);1.44 + if( len > (length-total) )1.45 + len = (length-total);1.46 + if( fread( region, len, 1, f ) != 1 ) {1.47 + ERROR( "Unexpected error: %d %d", len, errno );1.48 + break;1.49 + }1.50 +1.51 + addr += len;1.52 + total += len;1.53 + }1.54 + fclose( f );1.55 + INFO( "Loaded %d of %d bytes to %08X", total, length, start );1.56 + return 0;1.57 +}1.58 +1.59 struct mem_region *mem_map_region( void *mem, uint32_t base, uint32_t size,1.60 char *name, int flags )1.61 {
.