Search
lxdream.org :: lxdream/src/mem.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.h
changeset 953:f4a156508ad1
prev912:c5606ea44232
next975:007bf7eb944f
author nkeynes
date Wed Jan 14 00:16:44 2009 +0000 (15 years ago)
permissions -rw-r--r--
last change Add missed commit of ia64abi.h from previous change.
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 } *mem_region_fn_t;
    63 int32_t FASTCALL unmapped_read_long( sh4addr_t addr );
    64 void FASTCALL unmapped_write_long( sh4addr_t addr, uint32_t val );
    65 void FASTCALL unmapped_read_burst( unsigned char *dest, sh4addr_t addr );
    66 void FASTCALL unmapped_write_burst( sh4addr_t addr, unsigned char *src );
    67 void FASTCALL unmapped_prefetch( sh4addr_t addr );
    68 extern struct mem_region_fn mem_region_unmapped;
    70 typedef struct mem_region {
    71     uint32_t base;
    72     uint32_t size;
    73     const char *name;
    74     sh4ptr_t mem;
    75     uint32_t flags;
    76     mem_region_fn_t fn;
    77 } *mem_region_t;
    79 #define MAX_IO_REGIONS 24
    80 #define MAX_MEM_REGIONS 16
    82 #define MEM_REGION_BIOS "Bios ROM"
    83 #define MEM_REGION_MAIN "System RAM"
    84 #define MEM_REGION_VIDEO "Video RAM"
    85 #define MEM_REGION_VIDEO64 "Video RAM 64-bit"
    86 #define MEM_REGION_AUDIO "Audio RAM"
    87 #define MEM_REGION_AUDIO_SCRATCH "Audio Scratch RAM"
    88 #define MEM_REGION_FLASH "System Flash"
    89 #define MEM_REGION_PVR2TA "PVR2 TA Command"
    90 #define MEM_REGION_PVR2YUV "PVR2 YUV Decode"
    91 #define MEM_REGION_PVR2VDMA1 "PVR2 VRAM DMA 1"
    92 #define MEM_REGION_PVR2VDMA2 "PVR2 VRAM DMA 2"
    94 typedef gboolean (*mem_page_remapped_hook_t)(sh4addr_t page, mem_region_fn_t newfn, void *user_data);
    95 DECLARE_HOOK( mem_page_remapped_hook, mem_page_remapped_hook_t );
    97 struct mem_region *mem_map_region( void *mem, uint32_t base, uint32_t size,
    98                                    const char *name, mem_region_fn_t fn, int flags, uint32_t repeat_offset,
    99                                    uint32_t repeat_until );
   101 /**
   102  * Load a ROM image from the specified filename. If the memory region has not
   103  * been allocated, it is created now, otherwise the existing region is reused.
   104  * If the CRC check fails, a warning will be printed.
   105  * @return TRUE if the image was loaded successfully (irrespective of CRC failure).
   106  */
   107 gboolean mem_load_rom( void *output, const gchar *filename, uint32_t size, uint32_t crc ); 
   108 void *mem_alloc_pages( int n );
   109 sh4ptr_t mem_get_region( uint32_t addr );
   110 sh4ptr_t mem_get_region_by_name( const char *name );
   111 gboolean mem_has_page( uint32_t addr );
   112 int mem_load_block( const gchar *filename, uint32_t base, uint32_t size );
   113 int mem_save_block( const gchar *filename, uint32_t base, uint32_t size );
   114 void mem_set_trace( const gchar *tracelist, int flag );
   115 void mem_init( void );
   116 void mem_reset( void );
   117 void mem_copy_from_sh4( sh4ptr_t dest, sh4addr_t src, size_t count );
   118 void mem_copy_to_sh4( sh4addr_t dest, sh4ptr_t src, size_t count );
   120 /**
   121  * Write a long value directly to SH4-addressable memory.
   122  * @param dest a valid, writable physical memory address, relative to the SH4
   123  * @param value the value to write.
   124  */
   125 void mem_write_long( sh4addr_t dest, uint32_t value );
   127 #define ENABLE_DEBUG_MODE 1
   129 typedef enum { BREAK_NONE=0, BREAK_ONESHOT=1, BREAK_KEEP=2 } breakpoint_type_t;
   131 struct breakpoint_struct {
   132     uint32_t address;
   133     breakpoint_type_t type;
   134 };
   136 #define MAX_BREAKPOINTS 32
   139 #define MEM_FLAG_ROM 4 /* Mem region is ROM-based */
   140 #define MEM_FLAG_RAM 6 
   142 #define WATCH_WRITE 1
   143 #define WATCH_READ  2
   144 #define WATCH_EXEC  3  /* AKA Breakpoint :) */
   146 typedef struct watch_point *watch_point_t;
   148 watch_point_t mem_new_watch( uint32_t start, uint32_t end, int flags );
   149 void mem_delete_watch( watch_point_t watch );
   150 watch_point_t mem_is_watched( uint32_t addr, int size, int op );
   152 extern mem_region_fn_t *ext_address_space;
   154 #define SIGNEXT4(n) ((((int32_t)(n))<<28)>>28)
   155 #define SIGNEXT8(n) ((int32_t)((int8_t)(n)))
   156 #define SIGNEXT12(n) ((((int32_t)(n))<<20)>>20)
   157 #define SIGNEXT16(n) ((int32_t)((int16_t)(n)))
   158 #define SIGNEXT32(n) ((int64_t)((int32_t)(n)))
   159 #define SIGNEXT48(n) ((((int64_t)(n))<<16)>>16)
   160 #define ZEROEXT32(n) ((int64_t)((uint64_t)((uint32_t)(n))))
   162 /* Ensure the given region allows all of read/write/execute. If not 
   163  * page-aligned, some surrounding regions will similarly be unprotected.
   164  */
   165 void mem_unprotect( void *ptr, uint32_t size );
   167 #ifdef __cplusplus
   168 }
   169 #endif
   171 #endif /* !lxdream_mem_H */
.