Search
lxdream.org :: lxdream/src/mem.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.h
changeset 1067:d3c00ffccfcd
prev1065:bc1cc0c54917
prev946:d41ee7994db7
author nkeynes
date Fri Mar 02 23:49:10 2012 +1000 (8 years ago)
permissions -rw-r--r--
last change Android WIP:
* Rename gui_jni.c to gui_android.c - now quite android specific.
* Implement generic EGL driver with very minimal Java wrapper
* Run emulation in separate thread, and implement simple queue for
inter-thread communication.
* Add menu/action-bar items for start + reset
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
    32 typedef FASTCALL int32_t (*mem_read_fn_t)(sh4addr_t);
    33 typedef FASTCALL void (*mem_write_fn_t)(sh4addr_t, uint32_t);
    34 typedef FASTCALL void (*mem_read_burst_fn_t)(unsigned char *,sh4addr_t);
    35 typedef FASTCALL void (*mem_write_burst_fn_t)(sh4addr_t,unsigned char *);
    36 typedef FASTCALL void (*mem_prefetch_fn_t)(sh4addr_t);
    38 typedef FASTCALL int32_t (*mem_read_exc_fn_t)(sh4addr_t, void *);
    39 typedef FASTCALL void (*mem_write_exc_fn_t)(sh4addr_t, uint32_t, void *);
    40 typedef FASTCALL void (*mem_read_burst_exc_fn_t)(unsigned char *,sh4addr_t, void *);
    41 typedef FASTCALL void (*mem_write_burst_exc_fn_t)(sh4addr_t,unsigned char *, void *);
    42 typedef FASTCALL void (*mem_prefetch_exc_fn_t)(sh4addr_t, void *);
    44 /**
    45  * Basic memory region vtable - read/write at byte, word, long, and burst 
    46  * (32-byte) sizes.
    47  */
    48 typedef struct mem_region_fn {
    49     mem_read_fn_t read_long;
    50     mem_write_fn_t write_long;
    51     mem_read_fn_t read_word;
    52     mem_write_fn_t write_word;
    53     mem_read_fn_t read_byte;
    54     mem_write_fn_t write_byte;
    55     mem_read_burst_fn_t read_burst;
    56     mem_write_burst_fn_t write_burst;
    57     /* Prefetch is provided as a convenience for the SH4 - external memory 
    58      * spaces are automatically forced to unmapped_prefetch by mem.c
    59      */
    60     mem_prefetch_fn_t prefetch;
    61     /* Convenience for SH4 byte read/modify/write instructions */
    62     mem_read_fn_t read_byte_for_write;
    63 } *mem_region_fn_t;
    65 int32_t FASTCALL unmapped_read_long( sh4addr_t addr );
    66 void FASTCALL unmapped_write_long( sh4addr_t addr, uint32_t val );
    67 void FASTCALL unmapped_read_burst( unsigned char *dest, sh4addr_t addr );
    68 void FASTCALL unmapped_write_burst( sh4addr_t addr, unsigned char *src );
    69 void FASTCALL unmapped_prefetch( sh4addr_t addr );
    70 extern struct mem_region_fn mem_region_unmapped;
    72 typedef struct mem_region {
    73     uint32_t base;
    74     uint32_t size;
    75     const char *name;
    76     sh4ptr_t mem;
    77     uint32_t flags;
    78     mem_region_fn_t fn;
    79 } *mem_region_t;
    81 #define MAX_IO_REGIONS 24
    82 #define MAX_MEM_REGIONS 16
    84 #define MEM_REGION_BIOS "Bios ROM"
    85 #define MEM_REGION_MAIN "System RAM"
    86 #define MEM_REGION_VIDEO "Video RAM"
    87 #define MEM_REGION_VIDEO64 "Video RAM 64-bit"
    88 #define MEM_REGION_AUDIO "Audio RAM"
    89 #define MEM_REGION_AUDIO_SCRATCH "Audio Scratch RAM"
    90 #define MEM_REGION_FLASH "System Flash"
    91 #define MEM_REGION_PVR2TA "PVR2 TA Command"
    92 #define MEM_REGION_PVR2YUV "PVR2 YUV Decode"
    93 #define MEM_REGION_PVR2VDMA1 "PVR2 VRAM DMA 1"
    94 #define MEM_REGION_PVR2VDMA2 "PVR2 VRAM DMA 2"
    96 typedef gboolean (*mem_page_remapped_hook_t)(sh4addr_t page, mem_region_fn_t newfn, void *user_data);
    97 DECLARE_HOOK( mem_page_remapped_hook, mem_page_remapped_hook_t );
    99 struct mem_region *mem_map_region( void *mem, uint32_t base, uint32_t size,
   100                                    const char *name, mem_region_fn_t fn, int flags, uint32_t repeat_offset,
   101                                    uint32_t repeat_until );
   103 /**
   104  * Load a ROM image from the specified filename. If the memory region has not
   105  * been allocated, it is created now, otherwise the existing region is reused.
   106  * If the CRC check fails, a warning will be printed.
   107  * @return TRUE if the image was loaded successfully (irrespective of CRC failure).
   108  */
   109 gboolean mem_load_rom( void *output, const gchar *filename, uint32_t size, uint32_t crc ); 
   110 void *mem_alloc_pages( int n );
   111 sh4ptr_t mem_get_region( uint32_t addr );
   112 sh4ptr_t mem_get_region_by_name( const char *name );
   113 gboolean mem_has_page( uint32_t addr );
   114 int mem_load_block( const gchar *filename, uint32_t base, uint32_t size );
   115 int mem_save_block( const gchar *filename, uint32_t base, uint32_t size );
   116 void mem_set_trace( const gchar *tracelist, int flag );
   117 void mem_init( void );
   118 void mem_reset( void );
   119 void mem_copy_from_sh4( sh4ptr_t dest, sh4addr_t src, size_t count );
   120 void mem_copy_to_sh4( sh4addr_t dest, sh4ptr_t src, size_t count );
   122 /**
   123  * Write a long value directly to SH4-addressable memory.
   124  * @param dest a valid, writable physical memory address, relative to the SH4
   125  * @param value the value to write.
   126  */
   127 void mem_write_long( sh4addr_t dest, uint32_t value );
   129 #define ENABLE_DEBUG_MODE 1
   131 typedef enum { BREAK_NONE=0, BREAK_ONESHOT=1, BREAK_KEEP=2 } breakpoint_type_t;
   133 struct breakpoint_struct {
   134     uint32_t address;
   135     breakpoint_type_t type;
   136 };
   138 #define MAX_BREAKPOINTS 32
   141 #define MEM_FLAG_ROM 4 /* Mem region is ROM-based */
   142 #define MEM_FLAG_RAM 6 
   144 #define WATCH_WRITE 1
   145 #define WATCH_READ  2
   146 #define WATCH_EXEC  3  /* AKA Breakpoint :) */
   148 typedef struct watch_point *watch_point_t;
   150 watch_point_t mem_new_watch( uint32_t start, uint32_t end, int flags );
   151 void mem_delete_watch( watch_point_t watch );
   152 watch_point_t mem_is_watched( uint32_t addr, int size, int op );
   154 extern mem_region_fn_t *ext_address_space;
   156 #define SIGNEXT4(n) ((((int32_t)(n))<<28)>>28)
   157 #define SIGNEXT8(n) ((int32_t)((int8_t)(n)))
   158 #define SIGNEXT12(n) ((((int32_t)(n))<<20)>>20)
   159 #define SIGNEXT16(n) ((int32_t)((int16_t)(n)))
   160 #define SIGNEXT32(n) ((int64_t)((int32_t)(n)))
   161 #define SIGNEXT48(n) ((((int64_t)(n))<<16)>>16)
   162 #define ZEROEXT32(n) ((int64_t)((uint64_t)((uint32_t)(n))))
   164 /* Ensure the given region allows all of read/write/execute. If not 
   165  * page-aligned, some surrounding regions will similarly be unprotected.
   166  */
   167 void mem_unprotect( void *ptr, uint32_t size );
   169 #ifdef __cplusplus
   170 }
   171 #endif
   173 #endif /* !lxdream_mem_H */
.