1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus - memory.h *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2002 Hacktarux *
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. *
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. *
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 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25 #include "osal/preproc.h"
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;
44 extern ALIGN(16, unsigned int rdram[0x800000/4]);
46 extern unsigned int address, word;
47 extern unsigned char cpu_byte;
48 extern unsigned short hword;
49 extern unsigned long long dword, *rdword;
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);
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];
72 typedef struct _RDRAM_register
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;
86 typedef struct _SP_register
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;
99 typedef struct _RSP_register
102 unsigned int rsp_ibist;
105 typedef struct _DPC_register
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;
118 typedef struct _DPS_register
120 unsigned int dps_tbist;
121 unsigned int dps_test_mode;
122 unsigned int dps_buftest_addr;
123 unsigned int dps_buftest_data;
126 typedef struct _mips_register
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;
136 typedef struct _VI_register
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;
155 typedef struct _AI_register
157 unsigned int ai_dram_addr;
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;
169 typedef struct _PI_register
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;
186 typedef struct _RI_register
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;
198 typedef struct _SI_register
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;
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;
218 extern unsigned char *rdramb;
220 #ifndef M64P_BIG_ENDIAN
223 ((mot & 0x000000FF) << 24) | \
224 ((mot & 0x0000FF00) << 8) | \
225 ((mot & 0x00FF0000) >> 8) | \
226 ((mot & 0xFF000000) >> 24) \
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);
271 void read_rspb(void);
272 void read_rsph(void);
273 void read_rspd(void);
279 void read_dpsb(void);
280 void read_dpsh(void);
281 void read_dpsd(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);
311 void read_romb(void);
312 void read_romh(void);
313 void read_romd(void);
315 void read_pifb(void);
316 void read_pifh(void);
317 void read_pifd(void);
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);
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);
360 void write_mib(void);
361 void write_mih(void);
362 void write_mid(void);
364 void write_vib(void);
365 void write_vih(void);
366 void write_vid(void);
368 void write_aib(void);
369 void write_aih(void);
370 void write_aid(void);
372 void write_pib(void);
373 void write_pih(void);
374 void write_pid(void);
376 void write_rib(void);
377 void write_rih(void);
378 void write_rid(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);
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);
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);