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.4 |
#endif |
118 |
gbeauche |
1.2 |
#if DIRECT_ADDRESSING |
119 |
|
|
extern uintptr MEMBaseDiff; |
120 |
gbeauche |
1.4 |
#endif |
121 |
|
|
|
122 |
cebix |
1.5 |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
123 |
gbeauche |
1.4 |
static __inline__ uae_u8 *do_get_real_address(uaecptr addr) |
124 |
|
|
{ |
125 |
|
|
return (uae_u8 *)MEMBaseDiff + addr; |
126 |
|
|
} |
127 |
|
|
static __inline__ uae_u32 do_get_virtual_address(uae_u8 *addr) |
128 |
|
|
{ |
129 |
|
|
return (uintptr)addr - MEMBaseDiff; |
130 |
|
|
} |
131 |
cebix |
1.1 |
static __inline__ uae_u32 get_long(uaecptr addr) |
132 |
|
|
{ |
133 |
gbeauche |
1.2 |
uae_u32 * const m = (uae_u32 *)do_get_real_address(addr); |
134 |
|
|
return do_get_mem_long(m); |
135 |
cebix |
1.1 |
} |
136 |
|
|
static __inline__ uae_u32 get_word(uaecptr addr) |
137 |
|
|
{ |
138 |
gbeauche |
1.2 |
uae_u16 * const m = (uae_u16 *)do_get_real_address(addr); |
139 |
|
|
return do_get_mem_word(m); |
140 |
cebix |
1.1 |
} |
141 |
|
|
static __inline__ uae_u32 get_byte(uaecptr addr) |
142 |
|
|
{ |
143 |
gbeauche |
1.2 |
uae_u8 * const m = (uae_u8 *)do_get_real_address(addr); |
144 |
|
|
return do_get_mem_byte(m); |
145 |
cebix |
1.1 |
} |
146 |
|
|
static __inline__ void put_long(uaecptr addr, uae_u32 l) |
147 |
|
|
{ |
148 |
gbeauche |
1.2 |
uae_u32 * const m = (uae_u32 *)do_get_real_address(addr); |
149 |
|
|
do_put_mem_long(m, l); |
150 |
cebix |
1.1 |
} |
151 |
|
|
static __inline__ void put_word(uaecptr addr, uae_u32 w) |
152 |
|
|
{ |
153 |
gbeauche |
1.2 |
uae_u16 * const m = (uae_u16 *)do_get_real_address(addr); |
154 |
|
|
do_put_mem_word(m, w); |
155 |
cebix |
1.1 |
} |
156 |
|
|
static __inline__ void put_byte(uaecptr addr, uae_u32 b) |
157 |
|
|
{ |
158 |
gbeauche |
1.2 |
uae_u8 * const m = (uae_u8 *)do_get_real_address(addr); |
159 |
|
|
do_put_mem_byte(m, b); |
160 |
cebix |
1.1 |
} |
161 |
|
|
static __inline__ uae_u8 *get_real_address(uaecptr addr) |
162 |
|
|
{ |
163 |
gbeauche |
1.2 |
return do_get_real_address(addr); |
164 |
|
|
} |
165 |
|
|
static __inline__ uae_u32 get_virtual_address(uae_u8 *addr) |
166 |
|
|
{ |
167 |
|
|
return do_get_virtual_address(addr); |
168 |
cebix |
1.1 |
} |
169 |
|
|
static __inline__ int valid_address(uaecptr addr, uae_u32 size) |
170 |
|
|
{ |
171 |
|
|
return 1; |
172 |
|
|
} |
173 |
|
|
#else |
174 |
|
|
static __inline__ uae_u32 get_long(uaecptr addr) |
175 |
|
|
{ |
176 |
|
|
return longget_1(addr); |
177 |
|
|
} |
178 |
|
|
static __inline__ uae_u32 get_word(uaecptr addr) |
179 |
|
|
{ |
180 |
|
|
return wordget_1(addr); |
181 |
|
|
} |
182 |
|
|
static __inline__ uae_u32 get_byte(uaecptr addr) |
183 |
|
|
{ |
184 |
|
|
return byteget_1(addr); |
185 |
|
|
} |
186 |
|
|
static __inline__ void put_long(uaecptr addr, uae_u32 l) |
187 |
|
|
{ |
188 |
|
|
longput_1(addr, l); |
189 |
|
|
} |
190 |
|
|
static __inline__ void put_word(uaecptr addr, uae_u32 w) |
191 |
|
|
{ |
192 |
|
|
wordput_1(addr, w); |
193 |
|
|
} |
194 |
|
|
static __inline__ void put_byte(uaecptr addr, uae_u32 b) |
195 |
|
|
{ |
196 |
|
|
byteput_1(addr, b); |
197 |
|
|
} |
198 |
|
|
static __inline__ uae_u8 *get_real_address(uaecptr addr) |
199 |
|
|
{ |
200 |
|
|
return get_mem_bank(addr).xlateaddr(addr); |
201 |
|
|
} |
202 |
gbeauche |
1.2 |
/* gb-- deliberately not implemented since it shall not be used... */ |
203 |
|
|
extern uae_u32 get_virtual_address(uae_u8 *addr); |
204 |
cebix |
1.1 |
static __inline__ int valid_address(uaecptr addr, uae_u32 size) |
205 |
|
|
{ |
206 |
|
|
return get_mem_bank(addr).check(addr, size); |
207 |
|
|
} |
208 |
gbeauche |
1.2 |
#endif /* DIRECT_ADDRESSING || REAL_ADDRESSING */ |
209 |
|
|
|
210 |
|
|
#endif /* MEMORY_H */ |
211 |
cebix |
1.1 |
|