Core commit. Compile and run on the OpenPandora
[mupen64plus-pandora.git] / source / mupen64plus-core / src / memory / memory.h
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  *   Mupen64plus - memory.h                                                *
3  *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
4  *   Copyright (C) 2002 Hacktarux                                          *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
20  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21
22 #ifndef MEMORY_H
23 #define MEMORY_H
24
25 #include "osal/preproc.h"
26
27 int init_memory(int DoByteSwap);
28 void free_memory(void);
29 #define read_word_in_memory() readmem[address>>16]()
30 #define read_byte_in_memory() readmemb[address>>16]()
31 #define read_hword_in_memory() readmemh[address>>16]()
32 #define read_dword_in_memory() readmemd[address>>16]()
33 #define write_word_in_memory() writemem[address>>16]()
34 #define write_byte_in_memory() writememb[address >>16]()
35 #define write_hword_in_memory() writememh[address >>16]()
36 #define write_dword_in_memory() writememd[address >>16]()
37 extern unsigned int SP_DMEM[0x1000/4*2];
38 extern unsigned char *SP_DMEMb;
39 extern unsigned int *SP_IMEM;
40 extern unsigned char *SP_IMEMb;
41 extern unsigned int PIF_RAM[0x40/4];
42 extern unsigned char *PIF_RAMb;
43
44 extern ALIGN(16, unsigned int rdram[0x800000/4]);
45
46 extern unsigned int address, word;
47 extern unsigned char cpu_byte;
48 extern unsigned short hword;
49 extern unsigned long long dword, *rdword;
50
51 extern void (*readmem[0x10000])(void);
52 extern void (*readmemb[0x10000])(void);
53 extern void (*readmemh[0x10000])(void);
54 extern void (*readmemd[0x10000])(void);
55 extern void (*writemem[0x10000])(void);
56 extern void (*writememb[0x10000])(void);
57 extern void (*writememh[0x10000])(void);
58 extern void (*writememd[0x10000])(void);
59
60 extern unsigned int *readrdramreg[0x10000];
61 extern unsigned int *readrspreg[0x10000];
62 extern unsigned int *readrsp[0x10000];
63 extern unsigned int *readmi[0x10000];
64 extern unsigned int *readvi[0x10000];
65 extern unsigned int *readai[0x10000];
66 extern unsigned int *readpi[0x10000];
67 extern unsigned int *readri[0x10000];
68 extern unsigned int *readsi[0x10000];
69 extern unsigned int *readdp[0x10000];
70 extern unsigned int *readdps[0x10000];
71
72 typedef struct _RDRAM_register
73 {
74    unsigned int rdram_config;
75    unsigned int rdram_device_id;
76    unsigned int rdram_delay;
77    unsigned int rdram_mode;
78    unsigned int rdram_ref_interval;
79    unsigned int rdram_ref_row;
80    unsigned int rdram_ras_interval;
81    unsigned int rdram_min_interval;
82    unsigned int rdram_addr_select;
83    unsigned int rdram_device_manuf;
84 } RDRAM_register;
85
86 typedef struct _SP_register
87 {
88    unsigned int sp_mem_addr_reg;
89    unsigned int sp_dram_addr_reg;
90    unsigned int sp_rd_len_reg;
91    unsigned int sp_wr_len_reg;
92    unsigned int w_sp_status_reg;
93    unsigned int sp_status_reg;
94    unsigned int sp_dma_full_reg;
95    unsigned int sp_dma_busy_reg;
96    unsigned int sp_semaphore_reg;
97 } SP_register;
98
99 typedef struct _RSP_register
100 {
101    unsigned int rsp_pc;
102    unsigned int rsp_ibist;
103 } RSP_register;
104
105 typedef struct _DPC_register
106 {
107    unsigned int dpc_start;
108    unsigned int dpc_end;
109    unsigned int dpc_current;
110    unsigned int w_dpc_status;
111    unsigned int dpc_status;
112    unsigned int dpc_clock;
113    unsigned int dpc_bufbusy;
114    unsigned int dpc_pipebusy;
115    unsigned int dpc_tmem;
116 } DPC_register;
117
118 typedef struct _DPS_register
119 {
120    unsigned int dps_tbist;
121    unsigned int dps_test_mode;
122    unsigned int dps_buftest_addr;
123    unsigned int dps_buftest_data;
124 } DPS_register;
125
126 typedef struct _mips_register
127 {
128    unsigned int w_mi_init_mode_reg;
129    unsigned int mi_init_mode_reg;
130    unsigned int mi_version_reg;
131    unsigned int mi_intr_reg;
132    unsigned int mi_intr_mask_reg;
133    unsigned int w_mi_intr_mask_reg;
134 } mips_register;
135
136 typedef struct _VI_register
137 {
138    unsigned int vi_status;
139    unsigned int vi_origin;
140    unsigned int vi_width;
141    unsigned int vi_v_intr;
142    unsigned int vi_current;
143    unsigned int vi_burst;
144    unsigned int vi_v_sync;
145    unsigned int vi_h_sync;
146    unsigned int vi_leap;
147    unsigned int vi_h_start;
148    unsigned int vi_v_start;
149    unsigned int vi_v_burst;
150    unsigned int vi_x_scale;
151    unsigned int vi_y_scale;
152    unsigned int vi_delay;
153 } VI_register;
154
155 typedef struct _AI_register
156 {
157    unsigned int ai_dram_addr;
158    unsigned int ai_len;
159    unsigned int ai_control;
160    unsigned int ai_status;
161    unsigned int ai_dacrate;
162    unsigned int ai_bitrate;
163    unsigned int next_delay;
164    unsigned int next_len;
165    unsigned int current_delay;
166    unsigned int current_len;
167 } AI_register;
168
169 typedef struct _PI_register
170 {
171    unsigned int pi_dram_addr_reg;
172    unsigned int pi_cart_addr_reg;
173    unsigned int pi_rd_len_reg;
174    unsigned int pi_wr_len_reg;
175    unsigned int read_pi_status_reg;
176    unsigned int pi_bsd_dom1_lat_reg;
177    unsigned int pi_bsd_dom1_pwd_reg;
178    unsigned int pi_bsd_dom1_pgs_reg;
179    unsigned int pi_bsd_dom1_rls_reg;
180    unsigned int pi_bsd_dom2_lat_reg;
181    unsigned int pi_bsd_dom2_pwd_reg;
182    unsigned int pi_bsd_dom2_pgs_reg;
183    unsigned int pi_bsd_dom2_rls_reg;
184 } PI_register;
185
186 typedef struct _RI_register
187 {
188    unsigned int ri_mode;
189    unsigned int ri_config;
190    unsigned int ri_current_load;
191    unsigned int ri_select;
192    unsigned int ri_refresh;
193    unsigned int ri_latency;
194    unsigned int ri_error;
195    unsigned int ri_werror;
196 } RI_register;
197
198 typedef struct _SI_register
199 {
200    unsigned int si_dram_addr;
201    unsigned int si_pif_addr_rd64b;
202    unsigned int si_pif_addr_wr64b;
203    unsigned int si_stat;
204 } SI_register;
205
206 extern RDRAM_register rdram_register;
207 extern PI_register pi_register;
208 extern mips_register MI_register;
209 extern SP_register sp_register;
210 extern SI_register si_register;
211 extern VI_register vi_register;
212 extern RSP_register rsp_register;
213 extern RI_register ri_register;
214 extern AI_register ai_register;
215 extern DPC_register dpc_register;
216 extern DPS_register dps_register;
217
218 extern unsigned char *rdramb;
219
220 #ifndef M64P_BIG_ENDIAN
221 #define sl(mot) \
222 ( \
223 ((mot & 0x000000FF) << 24) | \
224 ((mot & 0x0000FF00) <<  8) | \
225 ((mot & 0x00FF0000) >>  8) | \
226 ((mot & 0xFF000000) >> 24) \
227 )
228
229 #define S8 3
230 #define S16 2
231 #define Sh16 1
232
233 #else
234
235 #define sl(mot) mot
236 #define S8 0
237 #define S16 0
238 #define Sh16 0
239
240 #endif
241
242 void read_nothing(void);
243 void read_nothingh(void);
244 void read_nothingb(void);
245 void read_nothingd(void);
246 void read_nomem(void);
247 void read_nomemb(void);
248 void read_nomemh(void);
249 void read_nomemd(void);
250 void read_rdram(void);
251 void read_rdramb(void);
252 void read_rdramh(void);
253 void read_rdramd(void);
254 void read_rdramFB(void);
255 void read_rdramFBb(void);
256 void read_rdramFBh(void);
257 void read_rdramFBd(void);
258 void read_rdramreg(void);
259 void read_rdramregb(void);
260 void read_rdramregh(void);
261 void read_rdramregd(void);
262 void read_rsp_mem(void);
263 void read_rsp_memb(void);
264 void read_rsp_memh(void);
265 void read_rsp_memd(void);
266 void read_rsp_reg(void);
267 void read_rsp_regb(void);
268 void read_rsp_regh(void);
269 void read_rsp_regd(void);
270 void read_rsp(void);
271 void read_rspb(void);
272 void read_rsph(void);
273 void read_rspd(void);
274 void read_dp(void);
275 void read_dpb(void);
276 void read_dph(void);
277 void read_dpd(void);
278 void read_dps(void);
279 void read_dpsb(void);
280 void read_dpsh(void);
281 void read_dpsd(void);
282 void read_mi(void);
283 void read_mib(void);
284 void read_mih(void);
285 void read_mid(void);
286 void read_vi(void);
287 void read_vib(void);
288 void read_vih(void);
289 void read_vid(void);
290 void read_ai(void);
291 void read_aib(void);
292 void read_aih(void);
293 void read_aid(void);
294 void read_pi(void);
295 void read_pib(void);
296 void read_pih(void);
297 void read_pid(void);
298 void read_ri(void);
299 void read_rib(void);
300 void read_rih(void);
301 void read_rid(void);
302 void read_si(void);
303 void read_sib(void);
304 void read_sih(void);
305 void read_sid(void);
306 void read_flashram_status(void);
307 void read_flashram_statusb(void);
308 void read_flashram_statush(void);
309 void read_flashram_statusd(void);
310 void read_rom(void);
311 void read_romb(void);
312 void read_romh(void);
313 void read_romd(void);
314 void read_pif(void);
315 void read_pifb(void);
316 void read_pifh(void);
317 void read_pifd(void);
318
319 void write_nothing(void);
320 void write_nothingb(void);
321 void write_nothingh(void);
322 void write_nothingd(void);
323 void write_nomem(void);
324 void write_nomemb(void);
325 void write_nomemd(void);
326 void write_nomemh(void);
327 void write_rdram(void);
328 void write_rdramb(void);
329 void write_rdramh(void);
330 void write_rdramd(void);
331 void write_rdramFB(void);
332 void write_rdramFBb(void);
333 void write_rdramFBh(void);
334 void write_rdramFBd(void);
335 void write_rdramreg(void);
336 void write_rdramregb(void);
337 void write_rdramregh(void);
338 void write_rdramregd(void);
339 void write_rsp_mem(void);
340 void write_rsp_memb(void);
341 void write_rsp_memh(void);
342 void write_rsp_memd(void);
343 void write_rsp_reg(void);
344 void write_rsp_regb(void);
345 void write_rsp_regh(void);
346 void write_rsp_regd(void);
347 void write_rsp(void);
348 void write_rspb(void);
349 void write_rsph(void);
350 void write_rspd(void);
351 void write_dp(void);
352 void write_dpb(void);
353 void write_dph(void);
354 void write_dpd(void);
355 void write_dps(void);
356 void write_dpsb(void);
357 void write_dpsh(void);
358 void write_dpsd(void);
359 void write_mi(void);
360 void write_mib(void);
361 void write_mih(void);
362 void write_mid(void);
363 void write_vi(void);
364 void write_vib(void);
365 void write_vih(void);
366 void write_vid(void);
367 void write_ai(void);
368 void write_aib(void);
369 void write_aih(void);
370 void write_aid(void);
371 void write_pi(void);
372 void write_pib(void);
373 void write_pih(void);
374 void write_pid(void);
375 void write_ri(void);
376 void write_rib(void);
377 void write_rih(void);
378 void write_rid(void);
379 void write_si(void);
380 void write_sib(void);
381 void write_sih(void);
382 void write_sid(void);
383 void write_flashram_dummy(void);
384 void write_flashram_dummyb(void);
385 void write_flashram_dummyh(void);
386 void write_flashram_dummyd(void);
387 void write_flashram_command(void);
388 void write_flashram_commandb(void);
389 void write_flashram_commandh(void);
390 void write_flashram_commandd(void);
391 void write_rom(void);
392 void write_pif(void);
393 void write_pifb(void);
394 void write_pifh(void);
395 void write_pifd(void);
396
397 void make_w_sp_status_reg(void);
398 void make_w_dpc_status(void);
399 void make_w_mi_init_mode_reg(void);
400 void update_MI_intr_mode_reg(void);
401 void update_MI_init_mask_reg(void);
402 void make_w_mi_intr_mask_reg(void);
403 void update_ai_dacrate(unsigned int word);
404 void update_vi_status(unsigned int word);
405 void update_vi_width(unsigned int word);
406
407 /* Returns a pointer to a block of contiguous memory
408  * Can access RDRAM, SP_DMEM, SP_IMEM and ROM, using TLB if necessary
409  * Useful for getting fast access to a zone with executable code. */
410 unsigned int *fast_mem_access(unsigned int address);
411
412 #endif
413