ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/memory.h
Revision: 1.2
Committed: 2000-09-22T17:20:33Z (24 years, 2 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
CVS Tags: snapshot-17022001, snapshot-29052001, release-0_9-1
Changes since 1.1: +39 -11 lines
Log Message:
- merged DIRECT_ADDRESSING and REAL_ADDRESSING
- conditionally removed unused code for direct addressing or real addressing modes

File Contents

# User Rev Content
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.2 #define do_get_real_address(a) ((uae_u8 *)(a))
117     #define do_get_virtual_address(a) ((uae_u32)(a))
118     #define InitMEMBaseDiff(va, ra) do { } while (0)
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     #define InitMEMBaseDiff(va, ra) (MEMBaseDiff = (uintptr)(va) - (uintptr)(ra))
126     #endif /* DIRECT_ADDRESSING */
127    
128     #if REAL_ADDRESSING || DIRECT_ADDRESSING
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