| 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 2 | * Mupen64plus - tlb.c * |
| 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 | #include <string.h> |
| 23 | |
| 24 | #include "api/m64p_types.h" |
| 25 | |
| 26 | #include "memory.h" |
| 27 | |
| 28 | #include "r4300/r4300.h" |
| 29 | #include "r4300/exception.h" |
| 30 | #include "r4300/macros.h" |
| 31 | #include "main/rom.h" |
| 32 | |
| 33 | unsigned int tlb_LUT_r[0x100000]; |
| 34 | unsigned int tlb_LUT_w[0x100000]; |
| 35 | |
| 36 | void tlb_unmap(tlb *entry) |
| 37 | { |
| 38 | unsigned int i; |
| 39 | |
| 40 | if (entry->v_even) |
| 41 | { |
| 42 | for (i=entry->start_even; i<entry->end_even; i += 0x1000) |
| 43 | tlb_LUT_r[i>>12] = 0; |
| 44 | if (entry->d_even) |
| 45 | for (i=entry->start_even; i<entry->end_even; i += 0x1000) |
| 46 | tlb_LUT_w[i>>12] = 0; |
| 47 | } |
| 48 | |
| 49 | if (entry->v_odd) |
| 50 | { |
| 51 | for (i=entry->start_odd; i<entry->end_odd; i += 0x1000) |
| 52 | tlb_LUT_r[i>>12] = 0; |
| 53 | if (entry->d_odd) |
| 54 | for (i=entry->start_odd; i<entry->end_odd; i += 0x1000) |
| 55 | tlb_LUT_w[i>>12] = 0; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void tlb_map(tlb *entry) |
| 60 | { |
| 61 | unsigned int i; |
| 62 | |
| 63 | if (entry->v_even) |
| 64 | { |
| 65 | if (entry->start_even < entry->end_even && |
| 66 | !(entry->start_even >= 0x80000000 && entry->end_even < 0xC0000000) && |
| 67 | entry->phys_even < 0x20000000) |
| 68 | { |
| 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); |
| 71 | if (entry->d_even) |
| 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); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if (entry->v_odd) |
| 78 | { |
| 79 | if (entry->start_odd < entry->end_odd && |
| 80 | !(entry->start_odd >= 0x80000000 && entry->end_odd < 0xC0000000) && |
| 81 | entry->phys_odd < 0x20000000) |
| 82 | { |
| 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); |
| 85 | if (entry->d_odd) |
| 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); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | unsigned int virtual_to_physical_address(unsigned int addresse, int w) |
| 93 | { |
| 94 | if (addresse >= 0x7f000000 && addresse < 0x80000000 && isGoldeneyeRom) |
| 95 | { |
| 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) |
| 101 | { |
| 102 | case 0x45: |
| 103 | // U |
| 104 | return 0xb0034b30 + (addresse & 0xFFFFFF); |
| 105 | break; |
| 106 | case 0x4A: |
| 107 | // J |
| 108 | return 0xb0034b70 + (addresse & 0xFFFFFF); |
| 109 | break; |
| 110 | case 0x50: |
| 111 | // E |
| 112 | return 0xb00329f0 + (addresse & 0xFFFFFF); |
| 113 | break; |
| 114 | default: |
| 115 | // UNKNOWN COUNTRY CODE FOR GOLDENEYE USING AMERICAN VERSION HACK |
| 116 | return 0xb0034b30 + (addresse & 0xFFFFFF); |
| 117 | break; |
| 118 | } |
| 119 | } |
| 120 | if (w == 1) |
| 121 | { |
| 122 | if (tlb_LUT_w[addresse>>12]) |
| 123 | return (tlb_LUT_w[addresse>>12]&0xFFFFF000)|(addresse&0xFFF); |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | if (tlb_LUT_r[addresse>>12]) |
| 128 | return (tlb_LUT_r[addresse>>12]&0xFFFFF000)|(addresse&0xFFF); |
| 129 | } |
| 130 | //printf("tlb exception !!! @ %x, %x, add:%x\n", addresse, w, PC->addr); |
| 131 | //getchar(); |
| 132 | TLB_refill_exception(addresse,w); |
| 133 | //return 0x80000000; |
| 134 | return 0x00000000; |
| 135 | } |