1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus - tlb.c *
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 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 #include "api/m64p_types.h"
28 #include "r4300/r4300.h"
29 #include "r4300/exception.h"
30 #include "r4300/macros.h"
33 unsigned int tlb_LUT_r[0x100000];
34 unsigned int tlb_LUT_w[0x100000];
36 void tlb_unmap(tlb *entry)
42 for (i=entry->start_even; i<entry->end_even; i += 0x1000)
45 for (i=entry->start_even; i<entry->end_even; i += 0x1000)
51 for (i=entry->start_odd; i<entry->end_odd; i += 0x1000)
54 for (i=entry->start_odd; i<entry->end_odd; i += 0x1000)
59 void tlb_map(tlb *entry)
65 if (entry->start_even < entry->end_even &&
66 !(entry->start_even >= 0x80000000 && entry->end_even < 0xC0000000) &&
67 entry->phys_even < 0x20000000)
69 for (i=entry->start_even;i<entry->end_even;i+=0x1000)
70 tlb_LUT_r[i>>12] = 0x80000000 | (entry->phys_even + (i - entry->start_even) + 0xFFF);
72 for (i=entry->start_even;i<entry->end_even;i+=0x1000)
73 tlb_LUT_w[i>>12] = 0x80000000 | (entry->phys_even + (i - entry->start_even) + 0xFFF);
79 if (entry->start_odd < entry->end_odd &&
80 !(entry->start_odd >= 0x80000000 && entry->end_odd < 0xC0000000) &&
81 entry->phys_odd < 0x20000000)
83 for (i=entry->start_odd;i<entry->end_odd;i+=0x1000)
84 tlb_LUT_r[i>>12] = 0x80000000 | (entry->phys_odd + (i - entry->start_odd) + 0xFFF);
86 for (i=entry->start_odd;i<entry->end_odd;i+=0x1000)
87 tlb_LUT_w[i>>12] = 0x80000000 | (entry->phys_odd + (i - entry->start_odd) + 0xFFF);
92 unsigned int virtual_to_physical_address(unsigned int addresse, int w)
94 if (addresse >= 0x7f000000 && addresse < 0x80000000 && isGoldeneyeRom)
96 /**************************************************
97 GoldenEye 007 hack allows for use of TLB.
98 Recoded by okaygo to support all US, J, and E ROMS.
99 **************************************************/
100 switch (ROM_HEADER.Country_code & 0xFF)
104 return 0xb0034b30 + (addresse & 0xFFFFFF);
108 return 0xb0034b70 + (addresse & 0xFFFFFF);
112 return 0xb00329f0 + (addresse & 0xFFFFFF);
115 // UNKNOWN COUNTRY CODE FOR GOLDENEYE USING AMERICAN VERSION HACK
116 return 0xb0034b30 + (addresse & 0xFFFFFF);
122 if (tlb_LUT_w[addresse>>12])
123 return (tlb_LUT_w[addresse>>12]&0xFFFFF000)|(addresse&0xFFF);
127 if (tlb_LUT_r[addresse>>12])
128 return (tlb_LUT_r[addresse>>12]&0xFFFFF000)|(addresse&0xFFF);
130 //printf("tlb exception !!! @ %x, %x, add:%x\n", addresse, w, PC->addr);
132 TLB_refill_exception(addresse,w);