Search
lxdream.org :: lxdream/src/mem.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.h
changeset 939:6f2302afeb89
prev934:3acd3b3ee6d1
next946:d41ee7994db7
author nkeynes
date Sat Jan 03 03:30:26 2009 +0000 (13 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change MMU work-in-progress
* Move SDRAM out into separate sdram.c
* Move all page-table management into mmu.c
* Convert UTLB management to use the new page-tables
* Rip out all calls to mmu_vma_to_phys_* and replace with direct access
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 *);
    37 typedef FASTCALL int32_t (*mem_read_exc_fn_t)(sh4addr_t, void *);
    38 typedef FASTCALL void (*mem_write_exc_fn_t)(sh4addr_t, uint32_t, void *);
    39 typedef FASTCALL void (*mem_read_burst_exc_fn_t)(unsigned char *,sh4addr_t, void *);
    40 typedef FASTCALL void (*mem_write_burst_exc_fn_t)(sh4addr_t,unsigned char *, void *);
    42 /**
    43  * Basic memory region vtable - read/write at byte, word, long, and burst 
    44  * (32-byte) sizes.
    45  */
    46 typedef struct mem_region_fn {
    47     FASTCALL int32_t (*read_long)(sh4addr_t addr);
    48     FASTCALL void (*write_long)(sh4addr_t addr, uint32_t val);
    49     FASTCALL int32_t (*read_word)(sh4addr_t addr);
    50     FASTCALL void (*write_word)(sh4addr_t addr, uint32_t val);
    51     FASTCALL int32_t (*read_byte)(sh4addr_t addr);
    52     FASTCALL void (*write_byte)(sh4addr_t addr, uint32_t val);
    53     FASTCALL void (*read_burst)(unsigned char *dest, sh4addr_t addr);
    54     FASTCALL void (*write_burst)(sh4addr_t addr, unsigned char *src);
    55 } *mem_region_fn_t;
    57 int32_t FASTCALL unmapped_read_long( sh4addr_t addr );
    58 void FASTCALL unmapped_write_long( sh4addr_t addr, uint32_t val );
    59 void FASTCALL unmapped_read_burst( unsigned char *dest, sh4addr_t addr );
    60 void FASTCALL unmapped_write_burst( sh4addr_t addr, unsigned char *src );
    61 extern struct mem_region_fn mem_region_unmapped;
    63 typedef struct mem_region {
    64     uint32_t base;
    65     uint32_t size;
    66     const char *name;
    67     sh4ptr_t mem;
    68     uint32_t flags;
    69     mem_region_fn_t fn;
    70 } *mem_region_t;
    72 #define MAX_IO_REGIONS 24
    73 #define MAX_MEM_REGIONS 16
    75 #define MEM_REGION_BIOS "Bios ROM"
    76 #define MEM_REGION_MAIN "System RAM"
    77 #define MEM_REGION_VIDEO "Video RAM"
    78 #define MEM_REGION_VIDEO64 "Video RAM 64-bit"
    79 #define MEM_REGION_AUDIO "Audio RAM"
    80 #define MEM_REGION_AUDIO_SCRATCH "Audio Scratch RAM"
    81 #define MEM_REGION_FLASH "System Flash"
    82 #define MEM_REGION_PVR2TA "PVR2 TA Command"
    83 #define MEM_REGION_PVR2YUV "PVR2 YUV Decode"
    84 #define MEM_REGION_PVR2VDMA1 "PVR2 VRAM DMA 1"
    85 #define MEM_REGION_PVR2VDMA2 "PVR2 VRAM DMA 2"
    87 typedef gboolean (*mem_page_remapped_hook_t)(sh4addr_t page, mem_region_fn_t newfn, void *user_data);
    88 DECLARE_HOOK( mem_page_remapped_hook, mem_page_remapped_hook_t );
    90 struct mem_region *mem_map_region( void *mem, uint32_t base, uint32_t size,
    91                                    const char *name, mem_region_fn_t fn, int flags, uint32_t repeat_offset,
    92                                    uint32_t repeat_until );
    94 /**
    95  * Load a ROM image from the specified filename. If the memory region has not
    96  * been allocated, it is created now, otherwise the existing region is reused.
    97  * If the CRC check fails, a warning will be printed.
    98  * @return TRUE if the image was loaded successfully (irrespective of CRC failure).
    99  */
   100 gboolean mem_load_rom( void *output, const gchar *filename, uint32_t size, uint32_t crc ); 
   101 void *mem_alloc_pages( int n );
   102 sh4ptr_t mem_get_region( uint32_t addr );
   103 sh4ptr_t mem_get_region_by_name( const char *name );
   104 gboolean mem_has_page( uint32_t addr );
   105 int mem_load_block( const gchar *filename, uint32_t base, uint32_t size );
   106 int mem_save_block( const gchar *filename, uint32_t base, uint32_t size );
   107 void mem_set_trace( const gchar *tracelist, int flag );
   108 void mem_init( void );
   109 void mem_reset( void );
   110 void mem_copy_from_sh4( sh4ptr_t dest, sh4addr_t src, size_t count );
   111 void mem_copy_to_sh4( sh4addr_t dest, sh4ptr_t src, size_t count );
   113 /**
   114  * Write a long value directly to SH4-addressable memory.
   115  * @param dest a valid, writable physical memory address, relative to the SH4
   116  * @param value the value to write.
   117  */
   118 void mem_write_long( sh4addr_t dest, uint32_t value );
   120 #define ENABLE_DEBUG_MODE 1
   122 typedef enum { BREAK_NONE=0, BREAK_ONESHOT=1, BREAK_KEEP=2 } breakpoint_type_t;
   124 struct breakpoint_struct {
   125     uint32_t address;
   126     breakpoint_type_t type;
   127 };
   129 #define MAX_BREAKPOINTS 32
   132 #define MEM_FLAG_ROM 4 /* Mem region is ROM-based */
   133 #define MEM_FLAG_RAM 6 
   135 #define WATCH_WRITE 1
   136 #define WATCH_READ  2
   137 #define WATCH_EXEC  3  /* AKA Breakpoint :) */
   139 typedef struct watch_point *watch_point_t;
   141 watch_point_t mem_new_watch( uint32_t start, uint32_t end, int flags );
   142 void mem_delete_watch( watch_point_t watch );
   143 watch_point_t mem_is_watched( uint32_t addr, int size, int op );
   145 extern mem_region_fn_t *ext_address_space;
   147 #define SIGNEXT4(n) ((((int32_t)(n))<<28)>>28)
   148 #define SIGNEXT8(n) ((int32_t)((int8_t)(n)))
   149 #define SIGNEXT12(n) ((((int32_t)(n))<<20)>>20)
   150 #define SIGNEXT16(n) ((int32_t)((int16_t)(n)))
   151 #define SIGNEXT32(n) ((int64_t)((int32_t)(n)))
   152 #define SIGNEXT48(n) ((((int64_t)(n))<<16)>>16)
   153 #define ZEROEXT32(n) ((int64_t)((uint64_t)((uint32_t)(n))))
   155 /* Ensure the given region allows all of read/write/execute. If not 
   156  * page-aligned, some surrounding regions will similarly be unprotected.
   157  */
   158 void mem_unprotect( void *ptr, uint32_t size );
   160 #ifdef __cplusplus
   161 }
   162 #endif
   164 #endif /* !lxdream_mem_H */
.