Search
lxdream.org :: lxdream/src/mem.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.h
changeset 929:fd8cb0c82f5f
prev912:c5606ea44232
next931:430048ea8b71
author nkeynes
date Sat Dec 20 03:01:40 2008 +0000 (12 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change First pass experiment using cached decoding.
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@586
     2
 * $Id$
nkeynes@31
     3
 *
nkeynes@31
     4
 * mem is responsible for creating and maintaining the overall system memory
nkeynes@31
     5
 * map, as visible from the SH4 processor. (Note the ARM has a different map)
nkeynes@31
     6
 *
nkeynes@31
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@31
     8
 *
nkeynes@31
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@31
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@31
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@31
    12
 * (at your option) any later version.
nkeynes@31
    13
 *
nkeynes@31
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@31
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@31
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@31
    17
 * GNU General Public License for more details.
nkeynes@31
    18
 */
nkeynes@31
    19
nkeynes@736
    20
#ifndef lxdream_mem_H
nkeynes@736
    21
#define lxdream_mem_H 1
nkeynes@10
    22
nkeynes@10
    23
#include <stdint.h>
nkeynes@477
    24
#include "lxdream.h"
nkeynes@10
    25
nkeynes@10
    26
#ifdef __cplusplus
nkeynes@10
    27
extern "C" {
nkeynes@10
    28
#endif
nkeynes@10
    29
nkeynes@929
    30
typedef struct mem_region_fn {
nkeynes@929
    31
    FASTCALL int32_t (*read_long)(sh4addr_t addr);
nkeynes@929
    32
    FASTCALL void (*write_long)(sh4addr_t addr, uint32_t val);
nkeynes@929
    33
    FASTCALL int32_t (*read_word)(sh4addr_t addr);
nkeynes@929
    34
    FASTCALL void (*write_word)(sh4addr_t addr, uint32_t val);
nkeynes@929
    35
    FASTCALL int32_t (*read_byte)(sh4addr_t addr);
nkeynes@929
    36
    FASTCALL void (*write_byte)(sh4addr_t addr, uint32_t val);
nkeynes@929
    37
    FASTCALL void (*read_burst)(unsigned char *dest, sh4addr_t addr);
nkeynes@929
    38
    FASTCALL void (*write_burst)(sh4addr_t addr, unsigned char *src);
nkeynes@929
    39
} *mem_region_fn_t;
nkeynes@929
    40
    
nkeynes@10
    41
typedef struct mem_region {
nkeynes@10
    42
    uint32_t base;
nkeynes@10
    43
    uint32_t size;
nkeynes@422
    44
    const char *name;
nkeynes@502
    45
    sh4ptr_t mem;
nkeynes@510
    46
    uint32_t flags;
nkeynes@929
    47
    mem_region_fn_t fn;
nkeynes@10
    48
} *mem_region_t;
nkeynes@10
    49
nkeynes@10
    50
#define MAX_IO_REGIONS 24
nkeynes@10
    51
#define MAX_MEM_REGIONS 8
nkeynes@10
    52
nkeynes@180
    53
#define MEM_REGION_BIOS "Bios ROM"
nkeynes@10
    54
#define MEM_REGION_MAIN "System RAM"
nkeynes@10
    55
#define MEM_REGION_VIDEO "Video RAM"
nkeynes@10
    56
#define MEM_REGION_AUDIO "Audio RAM"
nkeynes@10
    57
#define MEM_REGION_AUDIO_SCRATCH "Audio Scratch RAM"
nkeynes@146
    58
#define MEM_REGION_FLASH "System Flash"
nkeynes@10
    59
nkeynes@929
    60
void *mem_create_ram_region( uint32_t base, uint32_t size, const char *name, mem_region_fn_t fn );
nkeynes@929
    61
void *mem_create_repeating_ram_region( uint32_t base, uint32_t size, const char *name, mem_region_fn_t fn,
nkeynes@146
    62
				       uint32_t repeat_offset, uint32_t last_repeat );
nkeynes@543
    63
/**
nkeynes@543
    64
 * Load a ROM image from the specified filename. If the memory region has not
nkeynes@543
    65
 * been allocated, it is created now, otherwise the existing region is reused.
nkeynes@543
    66
 * If the CRC check fails, a warning will be printed.
nkeynes@543
    67
 * @return TRUE if the image was loaded successfully (irrespective of CRC failure).
nkeynes@543
    68
 */
nkeynes@543
    69
gboolean mem_load_rom( const gchar *filename, uint32_t base, uint32_t size, 
nkeynes@929
    70
		       uint32_t crc, const gchar *region_name, mem_region_fn_t fn );
nkeynes@19
    71
void *mem_alloc_pages( int n );
nkeynes@502
    72
sh4ptr_t mem_get_region( uint32_t addr );
nkeynes@502
    73
sh4ptr_t mem_get_region_by_name( const char *name );
nkeynes@10
    74
int mem_has_page( uint32_t addr );
nkeynes@502
    75
sh4ptr_t mem_get_page( uint32_t addr );
nkeynes@146
    76
int mem_load_block( const gchar *filename, uint32_t base, uint32_t size );
nkeynes@146
    77
int mem_save_block( const gchar *filename, uint32_t base, uint32_t size );
nkeynes@586
    78
void mem_set_trace( const gchar *tracelist, int flag );
nkeynes@10
    79
void mem_init( void );
nkeynes@10
    80
void mem_reset( void );
nkeynes@912
    81
void mem_copy_from_sh4( sh4ptr_t dest, sh4addr_t src, size_t count );
nkeynes@912
    82
void mem_copy_to_sh4( sh4addr_t dest, sh4ptr_t src, size_t count );
nkeynes@10
    83
nkeynes@669
    84
/**
nkeynes@669
    85
 * Write a long value directly to SH4-addressable memory.
nkeynes@669
    86
 * @param dest a valid, writable physical memory address, relative to the SH4
nkeynes@669
    87
 * @param value the value to write.
nkeynes@669
    88
 */
nkeynes@669
    89
void mem_write_long( sh4addr_t dest, uint32_t value );
nkeynes@669
    90
nkeynes@43
    91
#define ENABLE_DEBUG_MODE 1
nkeynes@43
    92
nkeynes@586
    93
typedef enum { BREAK_NONE=0, BREAK_ONESHOT=1, BREAK_KEEP=2 } breakpoint_type_t;
nkeynes@586
    94
nkeynes@43
    95
struct breakpoint_struct {
nkeynes@43
    96
    uint32_t address;
nkeynes@586
    97
    breakpoint_type_t type;
nkeynes@43
    98
};
nkeynes@43
    99
nkeynes@43
   100
#define MAX_BREAKPOINTS 32
nkeynes@43
   101
nkeynes@586
   102
nkeynes@586
   103
#define MEM_FLAG_ROM 4 /* Mem region is ROM-based */
nkeynes@586
   104
#define MEM_FLAG_RAM 6 
nkeynes@10
   105
nkeynes@10
   106
#define WATCH_WRITE 1
nkeynes@10
   107
#define WATCH_READ  2
nkeynes@10
   108
#define WATCH_EXEC  3  /* AKA Breakpoint :) */
nkeynes@10
   109
nkeynes@10
   110
typedef struct watch_point *watch_point_t;
nkeynes@10
   111
nkeynes@10
   112
watch_point_t mem_new_watch( uint32_t start, uint32_t end, int flags );
nkeynes@10
   113
void mem_delete_watch( watch_point_t watch );
nkeynes@10
   114
watch_point_t mem_is_watched( uint32_t addr, int size, int op );
nkeynes@10
   115
nkeynes@502
   116
extern sh4ptr_t *page_map;
nkeynes@736
   117
nkeynes@10
   118
#ifdef __cplusplus
nkeynes@10
   119
}
nkeynes@10
   120
#endif
nkeynes@736
   121
nkeynes@736
   122
#endif /* !lxdream_mem_H */
.