|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * memory management
5: *
6: * Copyright 1995 Bernd Schmidt
7: */
8:
1.1.1.2 ! root 9: typedef ULONG (*mem_get_func)(CPTR) REGPARAM;
! 10: typedef void (*mem_put_func)(CPTR, ULONG) REGPARAM;
! 11: typedef UBYTE *(*xlate_func)(CPTR) REGPARAM;
! 12: typedef int (*check_func)(CPTR, ULONG) REGPARAM;
! 13:
! 14: extern char *address_space, *good_address_map;
! 15: extern UBYTE *chipmemory;
! 16:
! 17: #undef DIRECT_MEMFUNCS_SUCCESSFUL
! 18: #include "machdep/memory.h"
! 19:
! 20: #ifndef CAN_MAP_MEMORY
! 21: #undef USE_COMPILER
! 22: #endif
! 23:
! 24: #if defined(USE_COMPILER) && !defined(USE_MAPPED_MEMORY)
! 25: #define USE_MAPPED_MEMORY
! 26: #endif
! 27:
1.1 root 28: #define kickmem_size 0x080000
29:
30: #define chipmem_start 0x000000
31: #define bogomem_start 0xC00000
32: #define kickmem_start 0xF80000
33:
34: extern int ersatzkickfile;
35:
36: typedef struct {
37: /* These ones should be self-explanatory... */
1.1.1.2 ! root 38: mem_get_func alget, awget, lget, wget, bget;
! 39: mem_put_func lput, wput, bput;
! 40: /* Use xlateaddr to translate an Amiga address to a UBYTE * that can
1.1 root 41: * be used to address memory without calling the wget/wput functions.
42: * This doesn't work for all memory banks, so this function may call
43: * abort(). */
44: xlate_func xlateaddr;
45: /* To prevent calls to abort(), use check before calling xlateaddr.
46: * It checks not only that the memory bank can do xlateaddr, but also
47: * that the pointer points to an area of at least the specified size.
48: * This is used for example to translate bitplane pointers in custom.c */
49: check_func check;
50: } addrbank;
51:
52: extern addrbank chipmem_bank;
53: extern addrbank kickmem_bank;
54: extern addrbank custom_bank;
55: extern addrbank clock_bank;
56: extern addrbank cia_bank;
57: extern addrbank rtarea_bank;
58: extern addrbank expamem_bank;
59: extern addrbank fastmem_bank;
60:
61: extern void rtarea_init (void);
1.1.1.2 ! root 62: extern void rtarea_setup (void);
1.1 root 63: extern void expamem_init (void);
64: extern void expamem_reset (void);
65:
66: extern ULONG fastmem_size, chipmem_size, bogomem_size;
67:
68: /* Default memory access functions */
69:
70: extern int default_check(CPTR addr, ULONG size) REGPARAM;
71: extern UBYTE *default_xlate(CPTR addr) REGPARAM;
1.1.1.2 ! root 72: extern ULONG default_awget(CPTR addr) REGPARAM;
1.1 root 73: extern ULONG default_alget(CPTR addr) REGPARAM;
74:
75: extern addrbank membanks[65536];
76: static __inline__ unsigned int bankindex(CPTR a)
77: {
78: return a>>16;
79: }
80:
81: static __inline__ int check_addr(CPTR a)
82: {
83: #if defined(NO_EXCEPTION_3) || CPU_LEVEL > 1
84: return 1;
85: #else
86: return (a & 1) == 0;
87: #endif
88: }
89: extern int buserr;
90:
91: extern void memory_init(void);
92: extern void map_banks(addrbank *bank, int first, int count);
1.1.1.2 ! root 93:
! 94: #ifndef NO_INLINE_MEMORY_ACCESS
! 95:
! 96: #define alongget(addr) (call_mem_get_func(membanks[bankindex(addr)].alget, addr))
! 97: #define awordget(addr) (call_mem_get_func(membanks[bankindex(addr)].awget, addr))
! 98: #define longget(addr) (call_mem_get_func(membanks[bankindex(addr)].lget, addr))
! 99: #define wordget(addr) (call_mem_get_func(membanks[bankindex(addr)].wget, addr))
! 100: #define byteget(addr) (call_mem_get_func(membanks[bankindex(addr)].bget, addr))
! 101: #define longput(addr,l) (call_mem_put_func(membanks[bankindex(addr)].lput, addr, l))
! 102: #define wordput(addr,w) (call_mem_put_func(membanks[bankindex(addr)].wput, addr, w))
! 103: #define byteput(addr,b) (call_mem_put_func(membanks[bankindex(addr)].bput, addr, b))
! 104:
! 105: #else
! 106:
! 107: extern ULONG alongget(CPTR addr);
! 108: extern ULONG awordget(CPTR addr);
! 109: extern ULONG longget(CPTR addr);
! 110: extern ULONG wordget(CPTR addr);
! 111: extern ULONG byteget(CPTR addr);
! 112: extern void longput(CPTR addr, ULONG l);
! 113: extern void wordput(CPTR addr, ULONG w);
! 114: extern void byteput(CPTR addr, ULONG b);
! 115:
! 116: #endif
! 117:
! 118: #ifndef MD_HAVE_MEM_1_FUNCS
! 119:
! 120: #define alongget_1 alongget
! 121: #define awordget_1 awordget
! 122: #define longget_1 longget
! 123: #define wordget_1 wordget
! 124: #define byteget_1 byteget
! 125: #define longput_1 longput
! 126: #define wordput_1 wordput
! 127: #define byteput_1 byteput
! 128:
! 129: #endif
! 130:
1.1 root 131: static __inline__ ULONG get_along(CPTR addr)
132: {
133: if (check_addr(addr))
1.1.1.2 ! root 134: return longget_1(addr);
1.1 root 135: buserr = 1;
136: return 0;
137: }
1.1.1.2 ! root 138: static __inline__ ULONG get_aword(CPTR addr)
1.1 root 139: {
140: if (check_addr(addr))
1.1.1.2 ! root 141: return wordget_1(addr);
1.1 root 142: buserr = 1;
143: return 0;
144: }
145: static __inline__ ULONG get_long(CPTR addr)
146: {
147: if (check_addr(addr))
1.1.1.2 ! root 148: return longget_1(addr);
1.1 root 149: buserr = 1;
150: return 0;
151: }
1.1.1.2 ! root 152: static __inline__ ULONG get_word(CPTR addr)
1.1 root 153: {
154: if (check_addr(addr))
1.1.1.2 ! root 155: return wordget_1(addr);
1.1 root 156: buserr = 1;
157: return 0;
158: }
1.1.1.2 ! root 159: static __inline__ ULONG get_byte(CPTR addr)
1.1 root 160: {
1.1.1.2 ! root 161: return byteget_1(addr);
1.1 root 162: }
163: static __inline__ void put_long(CPTR addr, ULONG l)
164: {
165: if (!check_addr(addr))
166: buserr = 1;
1.1.1.2 ! root 167: longput_1(addr, l);
1.1 root 168: }
1.1.1.2 ! root 169: static __inline__ void put_word(CPTR addr, ULONG w)
1.1 root 170: {
171: if (!check_addr(addr))
172: buserr = 1;
1.1.1.2 ! root 173: wordput_1(addr, w);
1.1 root 174: }
1.1.1.2 ! root 175: static __inline__ void put_byte(CPTR addr, ULONG b)
1.1 root 176: {
1.1.1.2 ! root 177: byteput_1(addr, b);
1.1 root 178: }
179:
180: static __inline__ UBYTE *get_real_address(CPTR addr)
181: {
182: return membanks[bankindex(addr)].xlateaddr(addr);
183: }
184:
185: static __inline__ int valid_address(CPTR addr, ULONG size)
186: {
187: return membanks[bankindex(addr)].check(addr, size);
188: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.