ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/memory.h
Revision: 1.4
Committed: 2001-07-07T09:08:54Z (23 years, 1 month ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.3: +11 -7 lines
Log Message:
- Experimental fixes for 64-bit addressing systems (e.g. Linux/ia64). The
  cpu emulation almost work correctly. FP emulation seems totaly boguous.

File Contents

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