1 |
cebix |
1.1 |
/* |
2 |
|
|
* UAE - The Un*x Amiga Emulator |
3 |
|
|
* |
4 |
|
|
* memory management |
5 |
|
|
* |
6 |
|
|
* Copyright 1995 Bernd Schmidt |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
#ifndef UAE_MEMORY_H |
10 |
|
|
#define UAE_MEMORY_H |
11 |
|
|
|
12 |
gbeauche |
1.2 |
#if !DIRECT_ADDRESSING && !REAL_ADDRESSING |
13 |
|
|
|
14 |
cebix |
1.1 |
/* Enabling this adds one additional native memory reference per 68k memory |
15 |
|
|
* access, but saves one shift (on the x86). Enabling this is probably |
16 |
|
|
* better for the cache. My favourite benchmark (PP2) doesn't show a |
17 |
|
|
* difference, so I leave this enabled. */ |
18 |
|
|
|
19 |
|
|
#if 1 || defined SAVE_MEMORY |
20 |
|
|
#define SAVE_MEMORY_BANKS |
21 |
|
|
#endif |
22 |
|
|
|
23 |
|
|
typedef uae_u32 (REGPARAM2 *mem_get_func)(uaecptr) REGPARAM; |
24 |
|
|
typedef void (REGPARAM2 *mem_put_func)(uaecptr, uae_u32) REGPARAM; |
25 |
|
|
typedef uae_u8 *(REGPARAM2 *xlate_func)(uaecptr) REGPARAM; |
26 |
|
|
typedef int (REGPARAM2 *check_func)(uaecptr, uae_u32) REGPARAM; |
27 |
|
|
|
28 |
|
|
#undef DIRECT_MEMFUNCS_SUCCESSFUL |
29 |
|
|
|
30 |
|
|
#ifndef CAN_MAP_MEMORY |
31 |
|
|
#undef USE_COMPILER |
32 |
|
|
#endif |
33 |
|
|
|
34 |
|
|
#if defined(USE_COMPILER) && !defined(USE_MAPPED_MEMORY) |
35 |
|
|
#define USE_MAPPED_MEMORY |
36 |
|
|
#endif |
37 |
|
|
|
38 |
|
|
typedef struct { |
39 |
|
|
/* These ones should be self-explanatory... */ |
40 |
|
|
mem_get_func lget, wget, bget; |
41 |
|
|
mem_put_func lput, wput, bput; |
42 |
|
|
/* Use xlateaddr to translate an Amiga address to a uae_u8 * that can |
43 |
|
|
* be used to address memory without calling the wget/wput functions. |
44 |
|
|
* This doesn't work for all memory banks, so this function may call |
45 |
|
|
* abort(). */ |
46 |
|
|
xlate_func xlateaddr; |
47 |
|
|
/* To prevent calls to abort(), use check before calling xlateaddr. |
48 |
|
|
* It checks not only that the memory bank can do xlateaddr, but also |
49 |
|
|
* that the pointer points to an area of at least the specified size. |
50 |
|
|
* This is used for example to translate bitplane pointers in custom.c */ |
51 |
|
|
check_func check; |
52 |
|
|
} addrbank; |
53 |
|
|
|
54 |
|
|
extern uae_u8 filesysory[65536]; |
55 |
|
|
|
56 |
|
|
extern addrbank ram_bank; // Mac RAM |
57 |
|
|
extern addrbank rom_bank; // Mac ROM |
58 |
|
|
extern addrbank frame_bank; // Frame buffer |
59 |
|
|
|
60 |
|
|
/* Default memory access functions */ |
61 |
|
|
|
62 |
|
|
extern int REGPARAM2 default_check(uaecptr addr, uae_u32 size) REGPARAM; |
63 |
|
|
extern uae_u8 *REGPARAM2 default_xlate(uaecptr addr) REGPARAM; |
64 |
|
|
|
65 |
|
|
#define bankindex(addr) (((uaecptr)(addr)) >> 16) |
66 |
|
|
|
67 |
|
|
#ifdef SAVE_MEMORY_BANKS |
68 |
|
|
extern addrbank *mem_banks[65536]; |
69 |
|
|
#define get_mem_bank(addr) (*mem_banks[bankindex(addr)]) |
70 |
|
|
#define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = (b)) |
71 |
|
|
#else |
72 |
|
|
extern addrbank mem_banks[65536]; |
73 |
|
|
#define get_mem_bank(addr) (mem_banks[bankindex(addr)]) |
74 |
|
|
#define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = *(b)) |
75 |
|
|
#endif |
76 |
|
|
|
77 |
|
|
extern void memory_init(void); |
78 |
|
|
extern void map_banks(addrbank *bank, int first, int count); |
79 |
|
|
|
80 |
|
|
#ifndef NO_INLINE_MEMORY_ACCESS |
81 |
|
|
|
82 |
|
|
#define longget(addr) (call_mem_get_func(get_mem_bank(addr).lget, addr)) |
83 |
|
|
#define wordget(addr) (call_mem_get_func(get_mem_bank(addr).wget, addr)) |
84 |
|
|
#define byteget(addr) (call_mem_get_func(get_mem_bank(addr).bget, addr)) |
85 |
|
|
#define longput(addr,l) (call_mem_put_func(get_mem_bank(addr).lput, addr, l)) |
86 |
|
|
#define wordput(addr,w) (call_mem_put_func(get_mem_bank(addr).wput, addr, w)) |
87 |
|
|
#define byteput(addr,b) (call_mem_put_func(get_mem_bank(addr).bput, addr, b)) |
88 |
|
|
|
89 |
|
|
#else |
90 |
|
|
|
91 |
|
|
extern uae_u32 longget(uaecptr addr); |
92 |
|
|
extern uae_u32 wordget(uaecptr addr); |
93 |
|
|
extern uae_u32 byteget(uaecptr addr); |
94 |
|
|
extern void longput(uaecptr addr, uae_u32 l); |
95 |
|
|
extern void wordput(uaecptr addr, uae_u32 w); |
96 |
|
|
extern void byteput(uaecptr addr, uae_u32 b); |
97 |
|
|
|
98 |
|
|
#endif |
99 |
|
|
|
100 |
|
|
#ifndef MD_HAVE_MEM_1_FUNCS |
101 |
|
|
|
102 |
|
|
#define longget_1 longget |
103 |
|
|
#define wordget_1 wordget |
104 |
|
|
#define byteget_1 byteget |
105 |
|
|
#define longput_1 longput |
106 |
|
|
#define wordput_1 wordput |
107 |
|
|
#define byteput_1 byteput |
108 |
|
|
|
109 |
|
|
#endif |
110 |
|
|
|
111 |
gbeauche |
1.2 |
#endif /* !DIRECT_ADDRESSING && !REAL_ADDRESSING */ |
112 |
|
|
|
113 |
cebix |
1.1 |
#if REAL_ADDRESSING |
114 |
gbeauche |
1.3 |
const uintptr MEMBaseDiff = 0; |
115 |
gbeauche |
1.4 |
#endif |
116 |
gbeauche |
1.2 |
#if DIRECT_ADDRESSING |
117 |
|
|
extern uintptr MEMBaseDiff; |
118 |
gbeauche |
1.4 |
#endif |
119 |
|
|
|
120 |
cebix |
1.5 |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
121 |
gbeauche |
1.4 |
static __inline__ uae_u8 *do_get_real_address(uaecptr addr) |
122 |
|
|
{ |
123 |
|
|
return (uae_u8 *)MEMBaseDiff + addr; |
124 |
|
|
} |
125 |
|
|
static __inline__ uae_u32 do_get_virtual_address(uae_u8 *addr) |
126 |
|
|
{ |
127 |
|
|
return (uintptr)addr - MEMBaseDiff; |
128 |
|
|
} |
129 |
cebix |
1.1 |
static __inline__ uae_u32 get_long(uaecptr addr) |
130 |
|
|
{ |
131 |
gbeauche |
1.2 |
uae_u32 * const m = (uae_u32 *)do_get_real_address(addr); |
132 |
|
|
return do_get_mem_long(m); |
133 |
cebix |
1.1 |
} |
134 |
|
|
static __inline__ uae_u32 get_word(uaecptr addr) |
135 |
|
|
{ |
136 |
gbeauche |
1.2 |
uae_u16 * const m = (uae_u16 *)do_get_real_address(addr); |
137 |
|
|
return do_get_mem_word(m); |
138 |
cebix |
1.1 |
} |
139 |
|
|
static __inline__ uae_u32 get_byte(uaecptr addr) |
140 |
|
|
{ |
141 |
gbeauche |
1.2 |
uae_u8 * const m = (uae_u8 *)do_get_real_address(addr); |
142 |
|
|
return do_get_mem_byte(m); |
143 |
cebix |
1.1 |
} |
144 |
|
|
static __inline__ void put_long(uaecptr addr, uae_u32 l) |
145 |
|
|
{ |
146 |
gbeauche |
1.2 |
uae_u32 * const m = (uae_u32 *)do_get_real_address(addr); |
147 |
|
|
do_put_mem_long(m, l); |
148 |
cebix |
1.1 |
} |
149 |
|
|
static __inline__ void put_word(uaecptr addr, uae_u32 w) |
150 |
|
|
{ |
151 |
gbeauche |
1.2 |
uae_u16 * const m = (uae_u16 *)do_get_real_address(addr); |
152 |
|
|
do_put_mem_word(m, w); |
153 |
cebix |
1.1 |
} |
154 |
|
|
static __inline__ void put_byte(uaecptr addr, uae_u32 b) |
155 |
|
|
{ |
156 |
gbeauche |
1.2 |
uae_u8 * const m = (uae_u8 *)do_get_real_address(addr); |
157 |
|
|
do_put_mem_byte(m, b); |
158 |
cebix |
1.1 |
} |
159 |
|
|
static __inline__ uae_u8 *get_real_address(uaecptr addr) |
160 |
|
|
{ |
161 |
gbeauche |
1.2 |
return do_get_real_address(addr); |
162 |
|
|
} |
163 |
|
|
static __inline__ uae_u32 get_virtual_address(uae_u8 *addr) |
164 |
|
|
{ |
165 |
|
|
return do_get_virtual_address(addr); |
166 |
cebix |
1.1 |
} |
167 |
|
|
static __inline__ int valid_address(uaecptr addr, uae_u32 size) |
168 |
|
|
{ |
169 |
|
|
return 1; |
170 |
|
|
} |
171 |
|
|
#else |
172 |
|
|
static __inline__ uae_u32 get_long(uaecptr addr) |
173 |
|
|
{ |
174 |
|
|
return longget_1(addr); |
175 |
|
|
} |
176 |
|
|
static __inline__ uae_u32 get_word(uaecptr addr) |
177 |
|
|
{ |
178 |
|
|
return wordget_1(addr); |
179 |
|
|
} |
180 |
|
|
static __inline__ uae_u32 get_byte(uaecptr addr) |
181 |
|
|
{ |
182 |
|
|
return byteget_1(addr); |
183 |
|
|
} |
184 |
|
|
static __inline__ void put_long(uaecptr addr, uae_u32 l) |
185 |
|
|
{ |
186 |
|
|
longput_1(addr, l); |
187 |
|
|
} |
188 |
|
|
static __inline__ void put_word(uaecptr addr, uae_u32 w) |
189 |
|
|
{ |
190 |
|
|
wordput_1(addr, w); |
191 |
|
|
} |
192 |
|
|
static __inline__ void put_byte(uaecptr addr, uae_u32 b) |
193 |
|
|
{ |
194 |
|
|
byteput_1(addr, b); |
195 |
|
|
} |
196 |
|
|
static __inline__ uae_u8 *get_real_address(uaecptr addr) |
197 |
|
|
{ |
198 |
|
|
return get_mem_bank(addr).xlateaddr(addr); |
199 |
|
|
} |
200 |
gbeauche |
1.2 |
/* gb-- deliberately not implemented since it shall not be used... */ |
201 |
|
|
extern uae_u32 get_virtual_address(uae_u8 *addr); |
202 |
cebix |
1.1 |
static __inline__ int valid_address(uaecptr addr, uae_u32 size) |
203 |
|
|
{ |
204 |
|
|
return get_mem_bank(addr).check(addr, size); |
205 |
|
|
} |
206 |
gbeauche |
1.2 |
#endif /* DIRECT_ADDRESSING || REAL_ADDRESSING */ |
207 |
|
|
|
208 |
|
|
#endif /* MEMORY_H */ |
209 |
cebix |
1.1 |
|