Search
lxdream.org :: lxdream/src/mem.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.h
changeset 931:430048ea8b71
prev929:fd8cb0c82f5f
next934:3acd3b3ee6d1
author nkeynes
date Tue Dec 23 05:48:05 2008 +0000 (13 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change More refactoring and general cleanup. Most things should be working again now.
Split off cache and start real implementation, breaking save states in the process
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * mem is responsible for creating and maintaining the overall system memory
     5  * map, as visible from the SH4 processor. (Note the ARM has a different map)
     6  *
     7  * Copyright (c) 2005 Nathan Keynes.
     8  *
     9  * This program is free software; you can redistribute it and/or modify
    10  * it under the terms of the GNU General Public License as published by
    11  * the Free Software Foundation; either version 2 of the License, or
    12  * (at your option) any later version.
    13  *
    14  * This program is distributed in the hope that it will be useful,
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  * GNU General Public License for more details.
    18  */
    20 #ifndef lxdream_mem_H
    21 #define lxdream_mem_H 1
    23 #include <stdint.h>
    24 #include "lxdream.h"
    25 #include "hook.h"
    27 #ifdef __cplusplus
    28 extern "C" {
    29 #endif
    31 /**
    32  * Basic memory region vtable - read/write at byte, word, long, and burst 
    33  * (32-byte) sizes.
    34  */
    35 typedef struct mem_region_fn {
    36     FASTCALL int32_t (*read_long)(sh4addr_t addr);
    37     FASTCALL void (*write_long)(sh4addr_t addr, uint32_t val);
    38     FASTCALL int32_t (*read_word)(sh4addr_t addr);
    39     FASTCALL void (*write_word)(sh4addr_t addr, uint32_t val);
    40     FASTCALL int32_t (*read_byte)(sh4addr_t addr);
    41     FASTCALL void (*write_byte)(sh4addr_t addr, uint32_t val);
    42     FASTCALL void (*read_burst)(unsigned char *dest, sh4addr_t addr);
    43     FASTCALL void (*write_burst)(sh4addr_t addr, unsigned char *src);
    44 } *mem_region_fn_t;
    46 int32_t FASTCALL unmapped_read_long( sh4addr_t addr );
    47 void FASTCALL unmapped_write_long( sh4addr_t addr, uint32_t val );
    48 void FASTCALL unmapped_read_burst( unsigned char *dest, sh4addr_t addr );
    49 void FASTCALL unmapped_write_burst( sh4addr_t addr, unsigned char *src );
    50 extern struct mem_region_fn mem_region_unmapped;
    52 typedef struct mem_region {
    53     uint32_t base;
    54     uint32_t size;
    55     const char *name;
    56     sh4ptr_t mem;
    57     uint32_t flags;
    58     mem_region_fn_t fn;
    59 } *mem_region_t;
    61 #define MAX_IO_REGIONS 24
    62 #define MAX_MEM_REGIONS 16
    64 #define MEM_REGION_BIOS "Bios ROM"
    65 #define MEM_REGION_MAIN "System RAM"
    66 #define MEM_REGION_VIDEO "Video RAM"
    67 #define MEM_REGION_VIDEO64 "Video RAM 64-bit"
    68 #define MEM_REGION_AUDIO "Audio RAM"
    69 #define MEM_REGION_AUDIO_SCRATCH "Audio Scratch RAM"
    70 #define MEM_REGION_FLASH "System Flash"
    72 typedef gboolean (*mem_page_remapped_hook_t)(sh4addr_t page, mem_region_fn_t newfn, void *user_data);
    73 DECLARE_HOOK( mem_page_remapped_hook, mem_page_remapped_hook_t );
    75 void *mem_create_ram_region( uint32_t base, uint32_t size, const char *name, mem_region_fn_t fn );
    76 void *mem_create_repeating_ram_region( uint32_t base, uint32_t size, const char *name, mem_region_fn_t fn,
    77 				       uint32_t repeat_offset, uint32_t last_repeat );
    78 void register_misc_region( uint32_t base, uint32_t size, const char *name, mem_region_fn_t fn );
    80 /**
    81  * Load a ROM image from the specified filename. If the memory region has not
    82  * been allocated, it is created now, otherwise the existing region is reused.
    83  * If the CRC check fails, a warning will be printed.
    84  * @return TRUE if the image was loaded successfully (irrespective of CRC failure).
    85  */
    86 gboolean mem_load_rom( const gchar *filename, uint32_t base, uint32_t size, 
    87 		       uint32_t crc, const gchar *region_name, mem_region_fn_t fn );
    88 void *mem_alloc_pages( int n );
    89 sh4ptr_t mem_get_region( uint32_t addr );
    90 sh4ptr_t mem_get_region_by_name( const char *name );
    91 int mem_has_page( uint32_t addr );
    92 sh4ptr_t mem_get_page( uint32_t addr );
    93 int mem_load_block( const gchar *filename, uint32_t base, uint32_t size );
    94 int mem_save_block( const gchar *filename, uint32_t base, uint32_t size );
    95 void mem_set_trace( const gchar *tracelist, int flag );
    96 void mem_init( void );
    97 void mem_reset( void );
    98 void mem_copy_from_sh4( sh4ptr_t dest, sh4addr_t src, size_t count );
    99 void mem_copy_to_sh4( sh4addr_t dest, sh4ptr_t src, size_t count );
   101 /**
   102  * Write a long value directly to SH4-addressable memory.
   103  * @param dest a valid, writable physical memory address, relative to the SH4
   104  * @param value the value to write.
   105  */
   106 void mem_write_long( sh4addr_t dest, uint32_t value );
   108 #define ENABLE_DEBUG_MODE 1
   110 typedef enum { BREAK_NONE=0, BREAK_ONESHOT=1, BREAK_KEEP=2 } breakpoint_type_t;
   112 struct breakpoint_struct {
   113     uint32_t address;
   114     breakpoint_type_t type;
   115 };
   117 #define MAX_BREAKPOINTS 32
   120 #define MEM_FLAG_ROM 4 /* Mem region is ROM-based */
   121 #define MEM_FLAG_RAM 6 
   123 #define WATCH_WRITE 1
   124 #define WATCH_READ  2
   125 #define WATCH_EXEC  3  /* AKA Breakpoint :) */
   127 typedef struct watch_point *watch_point_t;
   129 watch_point_t mem_new_watch( uint32_t start, uint32_t end, int flags );
   130 void mem_delete_watch( watch_point_t watch );
   131 watch_point_t mem_is_watched( uint32_t addr, int size, int op );
   133 extern sh4ptr_t *page_map;
   134 extern mem_region_fn_t *ext_address_space;
   136 #define SIGNEXT4(n) ((((int32_t)(n))<<28)>>28)
   137 #define SIGNEXT8(n) ((int32_t)((int8_t)(n)))
   138 #define SIGNEXT12(n) ((((int32_t)(n))<<20)>>20)
   139 #define SIGNEXT16(n) ((int32_t)((int16_t)(n)))
   140 #define SIGNEXT32(n) ((int64_t)((int32_t)(n)))
   141 #define SIGNEXT48(n) ((((int64_t)(n))<<16)>>16)
   142 #define ZEROEXT32(n) ((int64_t)((uint64_t)((uint32_t)(n))))
   144 #ifdef __cplusplus
   145 }
   146 #endif
   148 #endif /* !lxdream_mem_H */
.