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 alongget(uaecptr addr); |
92 |
|
|
extern uae_u32 awordget(uaecptr addr); |
93 |
|
|
extern uae_u32 longget(uaecptr addr); |
94 |
|
|
extern uae_u32 wordget(uaecptr addr); |
95 |
|
|
extern uae_u32 byteget(uaecptr addr); |
96 |
|
|
extern void longput(uaecptr addr, uae_u32 l); |
97 |
|
|
extern void wordput(uaecptr addr, uae_u32 w); |
98 |
|
|
extern void byteput(uaecptr addr, uae_u32 b); |
99 |
|
|
|
100 |
|
|
#endif |
101 |
|
|
|
102 |
|
|
#ifndef MD_HAVE_MEM_1_FUNCS |
103 |
|
|
|
104 |
|
|
#define longget_1 longget |
105 |
|
|
#define wordget_1 wordget |
106 |
|
|
#define byteget_1 byteget |
107 |
|
|
#define longput_1 longput |
108 |
|
|
#define wordput_1 wordput |
109 |
|
|
#define byteput_1 byteput |
110 |
|
|
|
111 |
|
|
#endif |
112 |
|
|
|
113 |
gbeauche |
1.2 |
#endif /* !DIRECT_ADDRESSING && !REAL_ADDRESSING */ |
114 |
|
|
|
115 |
cebix |
1.1 |
#if REAL_ADDRESSING |
116 |
gbeauche |
1.3 |
const uintptr MEMBaseDiff = 0; |
117 |
gbeauche |
1.2 |
#define do_get_real_address(a) ((uae_u8 *)(a)) |
118 |
|
|
#define do_get_virtual_address(a) ((uae_u32)(a)) |
119 |
|
|
#endif /* REAL_ADDRESSING */ |
120 |
|
|
|
121 |
|
|
#if DIRECT_ADDRESSING |
122 |
|
|
extern uintptr MEMBaseDiff; |
123 |
|
|
#define do_get_real_address(a) ((uae_u8 *)(a) + MEMBaseDiff) |
124 |
|
|
#define do_get_virtual_address(a) ((uae_u32)(a) - MEMBaseDiff) |
125 |
|
|
#endif /* DIRECT_ADDRESSING */ |
126 |
|
|
|
127 |
|
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
128 |
cebix |
1.1 |
static __inline__ uae_u32 get_long(uaecptr addr) |
129 |
|
|
{ |
130 |
gbeauche |
1.2 |
uae_u32 * const m = (uae_u32 *)do_get_real_address(addr); |
131 |
|
|
return do_get_mem_long(m); |
132 |
cebix |
1.1 |
} |
133 |
|
|
static __inline__ uae_u32 get_word(uaecptr addr) |
134 |
|
|
{ |
135 |
gbeauche |
1.2 |
uae_u16 * const m = (uae_u16 *)do_get_real_address(addr); |
136 |
|
|
return do_get_mem_word(m); |
137 |
cebix |
1.1 |
} |
138 |
|
|
static __inline__ uae_u32 get_byte(uaecptr addr) |
139 |
|
|
{ |
140 |
gbeauche |
1.2 |
uae_u8 * const m = (uae_u8 *)do_get_real_address(addr); |
141 |
|
|
return do_get_mem_byte(m); |
142 |
cebix |
1.1 |
} |
143 |
|
|
static __inline__ void put_long(uaecptr addr, uae_u32 l) |
144 |
|
|
{ |
145 |
gbeauche |
1.2 |
uae_u32 * const m = (uae_u32 *)do_get_real_address(addr); |
146 |
|
|
do_put_mem_long(m, l); |
147 |
cebix |
1.1 |
} |
148 |
|
|
static __inline__ void put_word(uaecptr addr, uae_u32 w) |
149 |
|
|
{ |
150 |
gbeauche |
1.2 |
uae_u16 * const m = (uae_u16 *)do_get_real_address(addr); |
151 |
|
|
do_put_mem_word(m, w); |
152 |
cebix |
1.1 |
} |
153 |
|
|
static __inline__ void put_byte(uaecptr addr, uae_u32 b) |
154 |
|
|
{ |
155 |
gbeauche |
1.2 |
uae_u8 * const m = (uae_u8 *)do_get_real_address(addr); |
156 |
|
|
do_put_mem_byte(m, b); |
157 |
cebix |
1.1 |
} |
158 |
|
|
static __inline__ uae_u8 *get_real_address(uaecptr addr) |
159 |
|
|
{ |
160 |
gbeauche |
1.2 |
return do_get_real_address(addr); |
161 |
|
|
} |
162 |
|
|
static __inline__ uae_u32 get_virtual_address(uae_u8 *addr) |
163 |
|
|
{ |
164 |
|
|
return do_get_virtual_address(addr); |
165 |
cebix |
1.1 |
} |
166 |
|
|
static __inline__ int valid_address(uaecptr addr, uae_u32 size) |
167 |
|
|
{ |
168 |
|
|
return 1; |
169 |
|
|
} |
170 |
|
|
#else |
171 |
|
|
static __inline__ uae_u32 get_long(uaecptr addr) |
172 |
|
|
{ |
173 |
|
|
return longget_1(addr); |
174 |
|
|
} |
175 |
|
|
static __inline__ uae_u32 get_word(uaecptr addr) |
176 |
|
|
{ |
177 |
|
|
return wordget_1(addr); |
178 |
|
|
} |
179 |
|
|
static __inline__ uae_u32 get_byte(uaecptr addr) |
180 |
|
|
{ |
181 |
|
|
return byteget_1(addr); |
182 |
|
|
} |
183 |
|
|
static __inline__ void put_long(uaecptr addr, uae_u32 l) |
184 |
|
|
{ |
185 |
|
|
longput_1(addr, l); |
186 |
|
|
} |
187 |
|
|
static __inline__ void put_word(uaecptr addr, uae_u32 w) |
188 |
|
|
{ |
189 |
|
|
wordput_1(addr, w); |
190 |
|
|
} |
191 |
|
|
static __inline__ void put_byte(uaecptr addr, uae_u32 b) |
192 |
|
|
{ |
193 |
|
|
byteput_1(addr, b); |
194 |
|
|
} |
195 |
|
|
static __inline__ uae_u8 *get_real_address(uaecptr addr) |
196 |
|
|
{ |
197 |
|
|
return get_mem_bank(addr).xlateaddr(addr); |
198 |
|
|
} |
199 |
gbeauche |
1.2 |
/* gb-- deliberately not implemented since it shall not be used... */ |
200 |
|
|
extern uae_u32 get_virtual_address(uae_u8 *addr); |
201 |
cebix |
1.1 |
static __inline__ int valid_address(uaecptr addr, uae_u32 size) |
202 |
|
|
{ |
203 |
|
|
return get_mem_bank(addr).check(addr, size); |
204 |
|
|
} |
205 |
gbeauche |
1.2 |
#endif /* DIRECT_ADDRESSING || REAL_ADDRESSING */ |
206 |
|
|
|
207 |
|
|
#endif /* MEMORY_H */ |
208 |
cebix |
1.1 |
|