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 |
/* Enabling this adds one additional native memory reference per 68k memory |
13 |
* access, but saves one shift (on the x86). Enabling this is probably |
14 |
* better for the cache. My favourite benchmark (PP2) doesn't show a |
15 |
* difference, so I leave this enabled. */ |
16 |
|
17 |
#if 1 || defined SAVE_MEMORY |
18 |
#define SAVE_MEMORY_BANKS |
19 |
#endif |
20 |
|
21 |
typedef uae_u32 (REGPARAM2 *mem_get_func)(uaecptr) REGPARAM; |
22 |
typedef void (REGPARAM2 *mem_put_func)(uaecptr, uae_u32) REGPARAM; |
23 |
typedef uae_u8 *(REGPARAM2 *xlate_func)(uaecptr) REGPARAM; |
24 |
typedef int (REGPARAM2 *check_func)(uaecptr, uae_u32) REGPARAM; |
25 |
|
26 |
#undef DIRECT_MEMFUNCS_SUCCESSFUL |
27 |
|
28 |
#ifndef CAN_MAP_MEMORY |
29 |
#undef USE_COMPILER |
30 |
#endif |
31 |
|
32 |
#if defined(USE_COMPILER) && !defined(USE_MAPPED_MEMORY) |
33 |
#define USE_MAPPED_MEMORY |
34 |
#endif |
35 |
|
36 |
typedef struct { |
37 |
/* These ones should be self-explanatory... */ |
38 |
mem_get_func lget, wget, bget; |
39 |
mem_put_func lput, wput, bput; |
40 |
/* Use xlateaddr to translate an Amiga address to a uae_u8 * that can |
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 uae_u8 filesysory[65536]; |
53 |
|
54 |
extern addrbank ram_bank; // Mac RAM |
55 |
extern addrbank rom_bank; // Mac ROM |
56 |
extern addrbank frame_bank; // Frame buffer |
57 |
|
58 |
/* Default memory access functions */ |
59 |
|
60 |
extern int REGPARAM2 default_check(uaecptr addr, uae_u32 size) REGPARAM; |
61 |
extern uae_u8 *REGPARAM2 default_xlate(uaecptr addr) REGPARAM; |
62 |
|
63 |
#define bankindex(addr) (((uaecptr)(addr)) >> 16) |
64 |
|
65 |
#ifdef SAVE_MEMORY_BANKS |
66 |
extern addrbank *mem_banks[65536]; |
67 |
#define get_mem_bank(addr) (*mem_banks[bankindex(addr)]) |
68 |
#define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = (b)) |
69 |
#else |
70 |
extern addrbank mem_banks[65536]; |
71 |
#define get_mem_bank(addr) (mem_banks[bankindex(addr)]) |
72 |
#define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = *(b)) |
73 |
#endif |
74 |
|
75 |
extern void memory_init(void); |
76 |
extern void map_banks(addrbank *bank, int first, int count); |
77 |
|
78 |
#ifndef NO_INLINE_MEMORY_ACCESS |
79 |
|
80 |
#define longget(addr) (call_mem_get_func(get_mem_bank(addr).lget, addr)) |
81 |
#define wordget(addr) (call_mem_get_func(get_mem_bank(addr).wget, addr)) |
82 |
#define byteget(addr) (call_mem_get_func(get_mem_bank(addr).bget, addr)) |
83 |
#define longput(addr,l) (call_mem_put_func(get_mem_bank(addr).lput, addr, l)) |
84 |
#define wordput(addr,w) (call_mem_put_func(get_mem_bank(addr).wput, addr, w)) |
85 |
#define byteput(addr,b) (call_mem_put_func(get_mem_bank(addr).bput, addr, b)) |
86 |
|
87 |
#else |
88 |
|
89 |
extern uae_u32 alongget(uaecptr addr); |
90 |
extern uae_u32 awordget(uaecptr addr); |
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 |
#if REAL_ADDRESSING |
112 |
static __inline__ uae_u32 get_long(uaecptr addr) |
113 |
{ |
114 |
return ntohl(*(uae_u32 *)addr); |
115 |
} |
116 |
static __inline__ uae_u32 get_word(uaecptr addr) |
117 |
{ |
118 |
return ntohs(*(uae_u16 *)addr); |
119 |
} |
120 |
static __inline__ uae_u32 get_byte(uaecptr addr) |
121 |
{ |
122 |
return *(uae_u8 *)addr; |
123 |
} |
124 |
static __inline__ void put_long(uaecptr addr, uae_u32 l) |
125 |
{ |
126 |
*(uae_u32 *)addr = htonl(l); |
127 |
} |
128 |
static __inline__ void put_word(uaecptr addr, uae_u32 w) |
129 |
{ |
130 |
*(uae_u16 *)addr = htons(w); |
131 |
} |
132 |
static __inline__ void put_byte(uaecptr addr, uae_u32 b) |
133 |
{ |
134 |
*(uae_u8 *)addr = b; |
135 |
} |
136 |
static __inline__ uae_u8 *get_real_address(uaecptr addr) |
137 |
{ |
138 |
return (uae_u8 *)addr; |
139 |
} |
140 |
static __inline__ int valid_address(uaecptr addr, uae_u32 size) |
141 |
{ |
142 |
return 1; |
143 |
} |
144 |
#else |
145 |
static __inline__ uae_u32 get_long(uaecptr addr) |
146 |
{ |
147 |
return longget_1(addr); |
148 |
} |
149 |
static __inline__ uae_u32 get_word(uaecptr addr) |
150 |
{ |
151 |
return wordget_1(addr); |
152 |
} |
153 |
static __inline__ uae_u32 get_byte(uaecptr addr) |
154 |
{ |
155 |
return byteget_1(addr); |
156 |
} |
157 |
static __inline__ void put_long(uaecptr addr, uae_u32 l) |
158 |
{ |
159 |
longput_1(addr, l); |
160 |
} |
161 |
static __inline__ void put_word(uaecptr addr, uae_u32 w) |
162 |
{ |
163 |
wordput_1(addr, w); |
164 |
} |
165 |
static __inline__ void put_byte(uaecptr addr, uae_u32 b) |
166 |
{ |
167 |
byteput_1(addr, b); |
168 |
} |
169 |
|
170 |
static __inline__ uae_u8 *get_real_address(uaecptr addr) |
171 |
{ |
172 |
return get_mem_bank(addr).xlateaddr(addr); |
173 |
} |
174 |
|
175 |
static __inline__ int valid_address(uaecptr addr, uae_u32 size) |
176 |
{ |
177 |
return get_mem_bank(addr).check(addr, size); |
178 |
} |
179 |
#endif |
180 |
|
181 |
#endif |