|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * memory management
5: *
6: * Copyright 1995 Bernd Schmidt
1.1.1.2 root 7: *
8: * Adaptation to Hatari by Thomas Huth
1.1.1.4 root 9: *
1.1.1.7 root 10: * This file is distributed under the GNU General Public License, version 2
11: * or at your option any later version. Read the file gpl.txt for details.
1.1 root 12: */
13:
1.1.1.3 root 14: #ifndef UAE_MEMORY_H
15: #define UAE_MEMORY_H
16:
17: #include "maccess.h"
1.1 root 18:
1.1.1.5 root 19: #define call_mem_get_func(func, addr) ((*func)(addr))
20: #define call_mem_put_func(func, addr, v) ((*func)(addr, v))
21:
1.1 root 22:
23: /* Enabling this adds one additional native memory reference per 68k memory
24: * access, but saves one shift (on the x86). Enabling this is probably
25: * better for the cache. My favourite benchmark (PP2) doesn't show a
26: * difference, so I leave this enabled. */
27: #if 1 || defined SAVE_MEMORY
28: #define SAVE_MEMORY_BANKS
29: #endif
30:
31:
32: typedef uae_u32 (*mem_get_func)(uaecptr) REGPARAM;
33: typedef void (*mem_put_func)(uaecptr, uae_u32) REGPARAM;
34: typedef uae_u8 *(*xlate_func)(uaecptr) REGPARAM;
35: typedef int (*check_func)(uaecptr, uae_u32) REGPARAM;
36:
37: extern char *address_space, *good_address_map;
38:
39:
1.1.1.8 root 40: enum
41: {
42: ABFLAG_UNK = 0, ABFLAG_RAM = 1, ABFLAG_ROM = 2, ABFLAG_ROMIN = 4, ABFLAG_IO = 8,
43: ABFLAG_NONE = 16, ABFLAG_SAFE = 32, ABFLAG_INDIRECT = 64, ABFLAG_NOALLOC = 128,
44: ABFLAG_RTG = 256, ABFLAG_THREADSAFE = 512, ABFLAG_DIRECTMAP = 1024
45: };
1.1 root 46: typedef struct {
47: /* These ones should be self-explanatory... */
48: mem_get_func lget, wget, bget;
49: mem_put_func lput, wput, bput;
1.1.1.4 root 50: /* Use xlateaddr to translate an Atari address to a uae_u8 * that can
1.1 root 51: * be used to address memory without calling the wget/wput functions.
52: * This doesn't work for all memory banks, so this function may call
53: * abort(). */
54: xlate_func xlateaddr;
55: /* To prevent calls to abort(), use check before calling xlateaddr.
56: * It checks not only that the memory bank can do xlateaddr, but also
57: * that the pointer points to an area of at least the specified size.
58: * This is used for example to translate bitplane pointers in custom.c */
59: check_func check;
1.1.1.8 root 60: /* For those banks that refer to real memory, we can save the whole trouble
61: of going through function calls, and instead simply grab the memory
62: ourselves. This holds the memory address where the start of memory is
63: for this particular bank. */
64: uae_u8 *baseaddr;
65: int flags;
66: uae_u32 mask;
67: uae_u32 start;
1.1 root 68: } addrbank;
69:
70:
71: #define bankindex(addr) (((uaecptr)(addr)) >> 16)
72:
73: #ifdef SAVE_MEMORY_BANKS
74: extern addrbank *mem_banks[65536];
75: #define get_mem_bank(addr) (*mem_banks[bankindex(addr)])
76: #define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = (b))
77: #else
78: extern addrbank mem_banks[65536];
79: #define get_mem_bank(addr) (mem_banks[bankindex(addr)])
80: #define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = *(b))
81: #endif
82:
1.1.1.8 root 83: extern bool memory_region_bus_error ( uaecptr addr );
1.1.1.9 ! root 84: extern void memory_map_Standard_RAM ( Uint32 MMU_Bank0_Size , Uint32 MMU_Bank1_Size );
1.1.1.6 root 85: extern void memory_init(uae_u32 nNewSTMemSize, uae_u32 nNewTTMemSize, uae_u32 nNewRomMemStart);
1.1.1.4 root 86: extern void memory_uninit (void);
1.1 root 87: extern void map_banks(addrbank *bank, int first, int count);
88:
89: #ifndef NO_INLINE_MEMORY_ACCESS
90:
91: #define longget(addr) (call_mem_get_func(get_mem_bank(addr).lget, addr))
92: #define wordget(addr) (call_mem_get_func(get_mem_bank(addr).wget, addr))
93: #define byteget(addr) (call_mem_get_func(get_mem_bank(addr).bget, addr))
94: #define longput(addr,l) (call_mem_put_func(get_mem_bank(addr).lput, addr, l))
95: #define wordput(addr,w) (call_mem_put_func(get_mem_bank(addr).wput, addr, w))
96: #define byteput(addr,b) (call_mem_put_func(get_mem_bank(addr).bput, addr, b))
97:
98: #else
99:
100: extern uae_u32 alongget(uaecptr addr);
101: extern uae_u32 awordget(uaecptr addr);
102: extern uae_u32 longget(uaecptr addr);
103: extern uae_u32 wordget(uaecptr addr);
104: extern uae_u32 byteget(uaecptr addr);
105: extern void longput(uaecptr addr, uae_u32 l);
106: extern void wordput(uaecptr addr, uae_u32 w);
107: extern void byteput(uaecptr addr, uae_u32 b);
108:
109: #endif
110:
111:
1.1.1.5 root 112: static inline uae_u32 get_long(uaecptr addr)
1.1 root 113: {
1.1.1.5 root 114: return longget(addr);
1.1 root 115: }
1.1.1.5 root 116:
117: static inline uae_u32 get_word(uaecptr addr)
1.1 root 118: {
1.1.1.5 root 119: return wordget(addr);
1.1 root 120: }
1.1.1.5 root 121:
122: static inline uae_u32 get_byte(uaecptr addr)
1.1 root 123: {
1.1.1.5 root 124: return byteget(addr);
1.1 root 125: }
1.1.1.5 root 126:
127: static inline void put_long(uaecptr addr, uae_u32 l)
1.1 root 128: {
1.1.1.5 root 129: longput(addr, l);
1.1 root 130: }
1.1.1.5 root 131:
132: static inline void put_word(uaecptr addr, uae_u32 w)
1.1 root 133: {
1.1.1.5 root 134: wordput(addr, w);
1.1 root 135: }
1.1.1.5 root 136:
137: static inline void put_byte(uaecptr addr, uae_u32 b)
1.1 root 138: {
1.1.1.5 root 139: byteput(addr, b);
1.1 root 140: }
141:
1.1.1.5 root 142: static inline uae_u8 *get_real_address(uaecptr addr)
1.1 root 143: {
144: return get_mem_bank(addr).xlateaddr(addr);
145: }
146:
1.1.1.5 root 147: static inline int valid_address(uaecptr addr, uae_u32 size)
1.1 root 148: {
149: return get_mem_bank(addr).check(addr, size);
150: }
151:
152:
1.1.1.3 root 153: #endif /* UAE_MEMORY_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.