Search
lxdream.org :: lxdream/src/mem.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.h
changeset 934:3acd3b3ee6d1
prev931:430048ea8b71
next939:6f2302afeb89
author nkeynes
date Fri Dec 26 14:25:23 2008 +0000 (15 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change Change RAM regions to use static arrays rather than mmap regions, for a 2-3% performance gain.
General mem cleanups, including some save state fixes that break states again.
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"
    71 #define MEM_REGION_PVR2TA "PVR2 TA Command"
    72 #define MEM_REGION_PVR2YUV "PVR2 YUV Decode"
    73 #define MEM_REGION_PVR2VDMA1 "PVR2 VRAM DMA 1"
    74 #define MEM_REGION_PVR2VDMA2 "PVR2 VRAM DMA 2"
    76 typedef gboolean (*mem_page_remapped_hook_t)(sh4addr_t page, mem_region_fn_t newfn, void *user_data);
    77 DECLARE_HOOK( mem_page_remapped_hook, mem_page_remapped_hook_t );
    79 struct mem_region *mem_map_region( void *mem, uint32_t base, uint32_t size,
    80                                    const char *name, mem_region_fn_t fn, int flags, uint32_t repeat_offset,
    81                                    uint32_t repeat_until );
    83 /**
    84  * Load a ROM image from the specified filename. If the memory region has not
    85  * been allocated, it is created now, otherwise the existing region is reused.
    86  * If the CRC check fails, a warning will be printed.
    87  * @return TRUE if the image was loaded successfully (irrespective of CRC failure).
    88  */
    89 gboolean mem_load_rom( void *output, const gchar *filename, uint32_t size, uint32_t crc ); 
    90 void *mem_alloc_pages( int n );
    91 sh4ptr_t mem_get_region( uint32_t addr );
    92 sh4ptr_t mem_get_region_by_name( const char *name );
    93 gboolean mem_has_page( uint32_t addr );
    94 int mem_load_block( const gchar *filename, uint32_t base, uint32_t size );
    95 int mem_save_block( const gchar *filename, uint32_t base, uint32_t size );
    96 void mem_set_trace( const gchar *tracelist, int flag );
    97 void mem_init( void );
    98 void mem_reset( void );
    99 void mem_copy_from_sh4( sh4ptr_t dest, sh4addr_t src, size_t count );
   100 void mem_copy_to_sh4( sh4addr_t dest, sh4ptr_t src, size_t count );
   102 /**
   103  * Write a long value directly to SH4-addressable memory.
   104  * @param dest a valid, writable physical memory address, relative to the SH4
   105  * @param value the value to write.
   106  */
   107 void mem_write_long( sh4addr_t dest, uint32_t value );
   109 #define ENABLE_DEBUG_MODE 1
   111 typedef enum { BREAK_NONE=0, BREAK_ONESHOT=1, BREAK_KEEP=2 } breakpoint_type_t;
   113 struct breakpoint_struct {
   114     uint32_t address;
   115     breakpoint_type_t type;
   116 };
   118 #define MAX_BREAKPOINTS 32
   121 #define MEM_FLAG_ROM 4 /* Mem region is ROM-based */
   122 #define MEM_FLAG_RAM 6 
   124 #define WATCH_WRITE 1
   125 #define WATCH_READ  2
   126 #define WATCH_EXEC  3  /* AKA Breakpoint :) */
   128 typedef struct watch_point *watch_point_t;
   130 watch_point_t mem_new_watch( uint32_t start, uint32_t end, int flags );
   131 void mem_delete_watch( watch_point_t watch );
   132 watch_point_t mem_is_watched( uint32_t addr, int size, int op );
   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 */
.