Search
lxdream.org :: lxdream/src/mem.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.h
changeset 953:f4a156508ad1
prev912:c5606ea44232
next975:007bf7eb944f
author nkeynes
date Tue Jan 13 11:56:28 2009 +0000 (11 years ago)
permissions -rw-r--r--
last change Merge lxdream-mem branch back to trunk
file annotate diff log raw
1.1 --- a/src/mem.h Fri Oct 31 03:24:49 2008 +0000
1.2 +++ b/src/mem.h Tue Jan 13 11:56:28 2009 +0000
1.3 @@ -22,45 +22,93 @@
1.4
1.5 #include <stdint.h>
1.6 #include "lxdream.h"
1.7 +#include "hook.h"
1.8
1.9 #ifdef __cplusplus
1.10 extern "C" {
1.11 #endif
1.12
1.13 +
1.14 +typedef FASTCALL int32_t (*mem_read_fn_t)(sh4addr_t);
1.15 +typedef FASTCALL void (*mem_write_fn_t)(sh4addr_t, uint32_t);
1.16 +typedef FASTCALL void (*mem_read_burst_fn_t)(unsigned char *,sh4addr_t);
1.17 +typedef FASTCALL void (*mem_write_burst_fn_t)(sh4addr_t,unsigned char *);
1.18 +typedef FASTCALL void (*mem_prefetch_fn_t)(sh4addr_t);
1.19 +
1.20 +typedef FASTCALL int32_t (*mem_read_exc_fn_t)(sh4addr_t, void *);
1.21 +typedef FASTCALL void (*mem_write_exc_fn_t)(sh4addr_t, uint32_t, void *);
1.22 +typedef FASTCALL void (*mem_read_burst_exc_fn_t)(unsigned char *,sh4addr_t, void *);
1.23 +typedef FASTCALL void (*mem_write_burst_exc_fn_t)(sh4addr_t,unsigned char *, void *);
1.24 +typedef FASTCALL void (*mem_prefetch_exc_fn_t)(sh4addr_t, void *);
1.25 +
1.26 +/**
1.27 + * Basic memory region vtable - read/write at byte, word, long, and burst
1.28 + * (32-byte) sizes.
1.29 + */
1.30 +typedef struct mem_region_fn {
1.31 + mem_read_fn_t read_long;
1.32 + mem_write_fn_t write_long;
1.33 + mem_read_fn_t read_word;
1.34 + mem_write_fn_t write_word;
1.35 + mem_read_fn_t read_byte;
1.36 + mem_write_fn_t write_byte;
1.37 + mem_read_burst_fn_t read_burst;
1.38 + mem_write_burst_fn_t write_burst;
1.39 + /* Prefetch is provided as a convenience for the SH4 - external memory
1.40 + * spaces are automatically forced to unmapped_prefetch by mem.c
1.41 + */
1.42 + mem_prefetch_fn_t prefetch;
1.43 +} *mem_region_fn_t;
1.44 +
1.45 +int32_t FASTCALL unmapped_read_long( sh4addr_t addr );
1.46 +void FASTCALL unmapped_write_long( sh4addr_t addr, uint32_t val );
1.47 +void FASTCALL unmapped_read_burst( unsigned char *dest, sh4addr_t addr );
1.48 +void FASTCALL unmapped_write_burst( sh4addr_t addr, unsigned char *src );
1.49 +void FASTCALL unmapped_prefetch( sh4addr_t addr );
1.50 +extern struct mem_region_fn mem_region_unmapped;
1.51 +
1.52 typedef struct mem_region {
1.53 uint32_t base;
1.54 uint32_t size;
1.55 const char *name;
1.56 sh4ptr_t mem;
1.57 uint32_t flags;
1.58 + mem_region_fn_t fn;
1.59 } *mem_region_t;
1.60
1.61 #define MAX_IO_REGIONS 24
1.62 -#define MAX_MEM_REGIONS 8
1.63 +#define MAX_MEM_REGIONS 16
1.64
1.65 #define MEM_REGION_BIOS "Bios ROM"
1.66 #define MEM_REGION_MAIN "System RAM"
1.67 #define MEM_REGION_VIDEO "Video RAM"
1.68 +#define MEM_REGION_VIDEO64 "Video RAM 64-bit"
1.69 #define MEM_REGION_AUDIO "Audio RAM"
1.70 #define MEM_REGION_AUDIO_SCRATCH "Audio Scratch RAM"
1.71 #define MEM_REGION_FLASH "System Flash"
1.72 +#define MEM_REGION_PVR2TA "PVR2 TA Command"
1.73 +#define MEM_REGION_PVR2YUV "PVR2 YUV Decode"
1.74 +#define MEM_REGION_PVR2VDMA1 "PVR2 VRAM DMA 1"
1.75 +#define MEM_REGION_PVR2VDMA2 "PVR2 VRAM DMA 2"
1.76
1.77 -void *mem_create_ram_region( uint32_t base, uint32_t size, const char *name );
1.78 -void *mem_create_repeating_ram_region( uint32_t base, uint32_t size, const char *name,
1.79 - uint32_t repeat_offset, uint32_t last_repeat );
1.80 +typedef gboolean (*mem_page_remapped_hook_t)(sh4addr_t page, mem_region_fn_t newfn, void *user_data);
1.81 +DECLARE_HOOK( mem_page_remapped_hook, mem_page_remapped_hook_t );
1.82 +
1.83 +struct mem_region *mem_map_region( void *mem, uint32_t base, uint32_t size,
1.84 + const char *name, mem_region_fn_t fn, int flags, uint32_t repeat_offset,
1.85 + uint32_t repeat_until );
1.86 +
1.87 /**
1.88 * Load a ROM image from the specified filename. If the memory region has not
1.89 * been allocated, it is created now, otherwise the existing region is reused.
1.90 * If the CRC check fails, a warning will be printed.
1.91 * @return TRUE if the image was loaded successfully (irrespective of CRC failure).
1.92 */
1.93 -gboolean mem_load_rom( const gchar *filename, uint32_t base, uint32_t size,
1.94 - uint32_t crc, const gchar *region_name );
1.95 +gboolean mem_load_rom( void *output, const gchar *filename, uint32_t size, uint32_t crc );
1.96 void *mem_alloc_pages( int n );
1.97 sh4ptr_t mem_get_region( uint32_t addr );
1.98 sh4ptr_t mem_get_region_by_name( const char *name );
1.99 -int mem_has_page( uint32_t addr );
1.100 -sh4ptr_t mem_get_page( uint32_t addr );
1.101 +gboolean mem_has_page( uint32_t addr );
1.102 int mem_load_block( const gchar *filename, uint32_t base, uint32_t size );
1.103 int mem_save_block( const gchar *filename, uint32_t base, uint32_t size );
1.104 void mem_set_trace( const gchar *tracelist, int flag );
1.105 @@ -101,7 +149,20 @@
1.106 void mem_delete_watch( watch_point_t watch );
1.107 watch_point_t mem_is_watched( uint32_t addr, int size, int op );
1.108
1.109 -extern sh4ptr_t *page_map;
1.110 +extern mem_region_fn_t *ext_address_space;
1.111 +
1.112 +#define SIGNEXT4(n) ((((int32_t)(n))<<28)>>28)
1.113 +#define SIGNEXT8(n) ((int32_t)((int8_t)(n)))
1.114 +#define SIGNEXT12(n) ((((int32_t)(n))<<20)>>20)
1.115 +#define SIGNEXT16(n) ((int32_t)((int16_t)(n)))
1.116 +#define SIGNEXT32(n) ((int64_t)((int32_t)(n)))
1.117 +#define SIGNEXT48(n) ((((int64_t)(n))<<16)>>16)
1.118 +#define ZEROEXT32(n) ((int64_t)((uint64_t)((uint32_t)(n))))
1.119 +
1.120 +/* Ensure the given region allows all of read/write/execute. If not
1.121 + * page-aligned, some surrounding regions will similarly be unprotected.
1.122 + */
1.123 +void mem_unprotect( void *ptr, uint32_t size );
1.124
1.125 #ifdef __cplusplus
1.126 }
.