Search
lxdream.org :: lxdream/src/mmio.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/mmio.h
changeset 10:c898b37506e0
next31:495e480360d7
author nkeynes
date Sun Dec 11 05:15:36 2005 +0000 (15 years ago)
permissions -rw-r--r--
last change Add CPU disasembly options to mode dropdown
Split sh4/mem.c into core mem.c and sh4/mem.c
Start adding copyright comments to file headers
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/mmio.h Sun Dec 11 05:15:36 2005 +0000
1.3 @@ -0,0 +1,152 @@
1.4 +#ifndef dream_mmio_H
1.5 +#define dream_mmio_H 1
1.6 +
1.7 +#ifdef __cplusplus
1.8 +extern "C" {
1.9 +#if 0
1.10 +}
1.11 +#endif
1.12 +#endif
1.13 +
1.14 +#include <stdint.h>
1.15 +#include <stdlib.h>
1.16 +#include "sh4core.h"
1.17 +
1.18 +#define PAGE_TABLE_ENTRIES 128*1024
1.19 +#define PAGE_SIZE 4096
1.20 +#define PAGE_BITS 12
1.21 +
1.22 +#define PORT_R 1
1.23 +#define PORT_W 2
1.24 +#define PORT_MEM 4 /* store written value */
1.25 +#define PORT_RW 3
1.26 +#define PORT_MR 5
1.27 +#define PORT_MRW 7
1.28 +#define UNDEFINED 0xDEADBEEF /* This has to be a value that nothing inits to */
1.29 +
1.30 +struct mmio_region {
1.31 + char *id, *desc;
1.32 + uint32_t base;
1.33 + int32_t (*io_read)(uint32_t addr);
1.34 + void (*io_write)(uint32_t addr, uint32_t val);
1.35 + char *mem;
1.36 + char *save_mem; /* Used to compare for gui updates */
1.37 + struct mmio_port {
1.38 + char *id, *desc;
1.39 + int width;
1.40 + uint32_t offset;
1.41 + uint32_t def_val;
1.42 + int flags;
1.43 + uint32_t *val;
1.44 + } ports[80];
1.45 + struct mmio_port **index; /* reverse lookup by address */
1.46 + int trace_flag; /* set to 1 to enable transfer traces */
1.47 +};
1.48 +
1.49 +void register_io_region( struct mmio_region *mmio );
1.50 +void register_io_regions( struct mmio_region **mmiolist );
1.51 +
1.52 +extern struct mmio_region *io_rgn[];
1.53 +extern int num_io_rgns;
1.54 +
1.55 +#define MMIO_READ( id, r ) *((int32_t *)(mmio_region_##id.mem + (r)))
1.56 +#define MMIO_WRITE( id, r, v ) *((int32_t *)(mmio_region_##id.mem + (r))) = (v)
1.57 +#define MMIO_REG( id, r ) ((int32_t *)(mmio_region_##id.mem + (r)))
1.58 +#define MMIO_REGID( mid, r ) (mmio_region_##mid.index[(r)>>2] != NULL ? \
1.59 + mmio_region_##mid.index[(r)>>2]->id : "<UNDEF>" )
1.60 +#define MMIO_REGDESC( mid, r) (mmio_region_##mid.index[(r)>>2] != NULL ? \
1.61 + mmio_region_##mid.index[(r)>>2]->desc : "Undefined register" )
1.62 +#define MMIO_TRACE( mid ) mmio_region_##mid.trace_flag = 1
1.63 +#define MMIO_NOTRACE( mid ) mmio_region_##mid.trace_flag = 0
1.64 +
1.65 +#define MMIO_REGID_BYNUM( mid, r ) (io_rgn[mid]->index[(r)>>2] != NULL ? \
1.66 + io_rgn[mid]->index[(r)>>2]->id : "<UNDEF>" )
1.67 +#define MMIO_REGDESC_BYNUM( mid, r ) (io_rgn[mid]->index[(r)>>2] != NULL ? \
1.68 + io_rgn[mid]->index[(r)>>2]->desc : "Undefined register" )
1.69 +#define MMIO_NAME_BYNUM( mid ) (io_rgn[mid]->id)
1.70 +
1.71 +#ifdef __cplusplus
1.72 +}
1.73 +#endif
1.74 +
1.75 +#endif
1.76 +
1.77 +#ifdef MMIO_IMPL
1.78 +
1.79 +#ifndef MMIO_IMPL_INCLUDED
1.80 +#define MMIO_IMPL_INCLUDED
1.81 +#undef MMIO_REGION_BEGIN
1.82 +#undef LONG_PORT
1.83 +#undef WORD_PORT
1.84 +#undef BYTE_PORT
1.85 +#undef MMIO_REGION_END
1.86 +#undef MMIO_REGION_LIST_BEGIN
1.87 +#undef MMIO_REGION
1.88 +#undef MMIO_REGION_LIST_END
1.89 +#define MMIO_REGION_BEGIN(b,id,d) struct mmio_region mmio_region_##id = { #id, d, b, mmio_region_##id##_read, mmio_region_##id##_write, 0, 0, {
1.90 +#define LONG_PORT( o,id,f,def,d ) { #id, d, 32, o, def, f },
1.91 +#define WORD_PORT( o,id,f,def,d ) { #id, d, 16, o, def, f },
1.92 +#define BYTE_PORT( o,id,f,def,d ) { #id, d, 8, o, def, f },
1.93 +#define MMIO_REGION_END {NULL, NULL, 0, 0, 0, 0} } };
1.94 +#define MMIO_REGION_LIST_BEGIN(id) struct mmio_region *mmio_list_##id[] = {
1.95 +#define MMIO_REGION( id ) &mmio_region_##id,
1.96 +#define MMIO_REGION_LIST_END NULL};
1.97 +
1.98 +/* Stub defines for modules we haven't got to yet, or ones which don't
1.99 + * actually need any direct code on read and/or write
1.100 + */
1.101 +#define MMIO_REGION_READ_STUBFN( id ) \
1.102 +int32_t mmio_region_##id##_read( uint32_t reg ) { \
1.103 + int32_t val = MMIO_READ( id, reg ); \
1.104 + WARN( "Read from unimplemented module %s (%03X => %08X) [%s: %s]",\
1.105 + #id, reg, val, MMIO_REGID(id,reg), MMIO_REGDESC(id,reg) ); \
1.106 + return val; \
1.107 +}
1.108 +#define MMIO_REGION_WRITE_STUBFN( id ) \
1.109 +void mmio_region_##id##_write( uint32_t reg, uint32_t val ) { \
1.110 + WARN( "Write to unimplemented module %s (%03X <= %08X) [%s: %s]", \
1.111 + #id, reg, val, MMIO_REGID(id,reg), MMIO_REGDESC(id,reg) ); \
1.112 + MMIO_WRITE( id, reg, val ); \
1.113 +}
1.114 +#define MMIO_REGION_STUBFNS( id ) \
1.115 + MMIO_REGION_READ_STUBFN( id ) \
1.116 + MMIO_REGION_WRITE_STUBFN( id )
1.117 +#define MMIO_REGION_READ_DEFFN( id ) \
1.118 +int32_t mmio_region_##id##_read( uint32_t reg ) { \
1.119 + return MMIO_READ( id, reg ); \
1.120 +}
1.121 +#define MMIO_REGION_WRITE_DEFFN( id ) \
1.122 +void mmio_region_##id##_write( uint32_t reg, uint32_t val ) { \
1.123 + MMIO_WRITE( id, reg, val ); \
1.124 +}
1.125 +#define MMIO_REGION_DEFFNS( id ) \
1.126 + MMIO_REGION_READ_DEFFN( id ) \
1.127 + MMIO_REGION_WRITE_DEFFN( id )
1.128 +#endif
1.129 +
1.130 +#define MMIO_REGION_WRITE_FN( id, reg, val ) \
1.131 +void mmio_region_##id##_write( uint32_t reg, uint32_t val )
1.132 +
1.133 +#define MMIO_REGION_READ_FN( id, reg ) \
1.134 +int32_t mmio_region_##id##_read( uint32_t reg )
1.135 +
1.136 +#else
1.137 +
1.138 +#ifndef MMIO_IFACE_INCLUDED
1.139 +#define MMIO_IFACE_INCLUDED
1.140 +#define MMIO_REGION_BEGIN(b,id,d) \
1.141 +extern struct mmio_region mmio_region_##id; \
1.142 +int32_t mmio_region_##id##_read(uint32_t); \
1.143 +void mmio_region_##id##_write(uint32_t, uint32_t); \
1.144 +enum mmio_region_##id##_port_t {
1.145 +#define LONG_PORT( o,id,f,def,d ) id = o,
1.146 +#define WORD_PORT( o,id,f,def,d ) id = o,
1.147 +#define BYTE_PORT( o,id,f,def,d ) id = o,
1.148 +#define MMIO_REGION_END };
1.149 +#define MMIO_REGION_LIST_BEGIN(id) extern struct mmio_region *mmio_list_##id[];
1.150 +#define MMIO_REGION( id )
1.151 +#define MMIO_REGION_LIST_END
1.152 +#endif
1.153 +
1.154 +#endif
1.155 +
.