diff options
Diffstat (limited to 'src/core/arm/interpreter/armmmu.cpp')
| -rw-r--r-- | src/core/arm/interpreter/armmmu.cpp | 238 |
1 files changed, 238 insertions, 0 deletions
diff --git a/src/core/arm/interpreter/armmmu.cpp b/src/core/arm/interpreter/armmmu.cpp new file mode 100644 index 000000000..242e6a83c --- /dev/null +++ b/src/core/arm/interpreter/armmmu.cpp | |||
| @@ -0,0 +1,238 @@ | |||
| 1 | /* | ||
| 2 | armmmu.c - Memory Management Unit emulation. | ||
| 3 | ARMulator extensions for the ARM7100 family. | ||
| 4 | Copyright (C) 1999 Ben Williamson | ||
| 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 Free Software | ||
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <assert.h> | ||
| 22 | #include <string.h> | ||
| 23 | #include "armdefs.h" | ||
| 24 | /* two header for arm disassemble */ | ||
| 25 | //#include "skyeye_arch.h" | ||
| 26 | #include "armcpu.h" | ||
| 27 | |||
| 28 | |||
| 29 | extern mmu_ops_t xscale_mmu_ops; | ||
| 30 | exception_t arm_mmu_write(short size, u32 addr, uint32_t *value); | ||
| 31 | exception_t arm_mmu_read(short size, u32 addr, uint32_t *value); | ||
| 32 | #define MMU_OPS (state->mmu.ops) | ||
| 33 | ARMword skyeye_cachetype = -1; | ||
| 34 | |||
| 35 | int | ||
| 36 | mmu_init (ARMul_State * state) | ||
| 37 | { | ||
| 38 | int ret; | ||
| 39 | |||
| 40 | state->mmu.control = 0x70; | ||
| 41 | state->mmu.translation_table_base = 0xDEADC0DE; | ||
| 42 | state->mmu.domain_access_control = 0xDEADC0DE; | ||
| 43 | state->mmu.fault_status = 0; | ||
| 44 | state->mmu.fault_address = 0; | ||
| 45 | state->mmu.process_id = 0; | ||
| 46 | |||
| 47 | switch (state->cpu->cpu_val & state->cpu->cpu_mask) { | ||
| 48 | //case SA1100: | ||
| 49 | //case SA1110: | ||
| 50 | // NOTICE_LOG(ARM11, "SKYEYE: use sa11xx mmu ops\n"); | ||
| 51 | // state->mmu.ops = sa_mmu_ops; | ||
| 52 | // break; | ||
| 53 | //case PXA250: | ||
| 54 | //case PXA270: //xscale | ||
| 55 | // NOTICE_LOG(ARM11, "SKYEYE: use xscale mmu ops\n"); | ||
| 56 | // state->mmu.ops = xscale_mmu_ops; | ||
| 57 | // break; | ||
| 58 | //case 0x41807200: //arm720t | ||
| 59 | //case 0x41007700: //arm7tdmi | ||
| 60 | //case 0x41007100: //arm7100 | ||
| 61 | // NOTICE_LOG(ARM11, "SKYEYE: use arm7100 mmu ops\n"); | ||
| 62 | // state->mmu.ops = arm7100_mmu_ops; | ||
| 63 | // break; | ||
| 64 | //case 0x41009200: | ||
| 65 | // NOTICE_LOG(ARM11, "SKYEYE: use arm920t mmu ops\n"); | ||
| 66 | // state->mmu.ops = arm920t_mmu_ops; | ||
| 67 | // break; | ||
| 68 | //case 0x41069260: | ||
| 69 | // NOTICE_LOG(ARM11, "SKYEYE: use arm926ejs mmu ops\n"); | ||
| 70 | // state->mmu.ops = arm926ejs_mmu_ops; | ||
| 71 | // break; | ||
| 72 | /* case 0x560f5810: */ | ||
| 73 | case 0x0007b000: | ||
| 74 | NOTICE_LOG(ARM11, "SKYEYE: use arm11jzf-s mmu ops\n"); | ||
| 75 | state->mmu.ops = arm1176jzf_s_mmu_ops; | ||
| 76 | break; | ||
| 77 | |||
| 78 | default: | ||
| 79 | ERROR_LOG (ARM11, | ||
| 80 | "SKYEYE: armmmu.c : mmu_init: unknown cpu_val&cpu_mask 0x%x\n", | ||
| 81 | state->cpu->cpu_val & state->cpu->cpu_mask); | ||
| 82 | break; | ||
| 83 | |||
| 84 | }; | ||
| 85 | ret = state->mmu.ops.init (state); | ||
| 86 | state->mmu_inited = (ret == 0); | ||
| 87 | /* initialize mmu_read and mmu_write for disassemble */ | ||
| 88 | //skyeye_config_t *config = get_current_config(); | ||
| 89 | //generic_arch_t *arch_instance = get_arch_instance(config->arch->arch_name); | ||
| 90 | //arch_instance->mmu_read = arm_mmu_read; | ||
| 91 | //arch_instance->mmu_write = arm_mmu_write; | ||
| 92 | |||
| 93 | return ret; | ||
| 94 | } | ||
| 95 | |||
| 96 | int | ||
| 97 | mmu_reset (ARMul_State * state) | ||
| 98 | { | ||
| 99 | if (state->mmu_inited) | ||
| 100 | mmu_exit (state); | ||
| 101 | return mmu_init (state); | ||
| 102 | } | ||
| 103 | |||
| 104 | void | ||
| 105 | mmu_exit (ARMul_State * state) | ||
| 106 | { | ||
| 107 | MMU_OPS.exit (state); | ||
| 108 | state->mmu_inited = 0; | ||
| 109 | } | ||
| 110 | |||
| 111 | fault_t | ||
| 112 | mmu_read_byte (ARMul_State * state, ARMword virt_addr, ARMword * data) | ||
| 113 | { | ||
| 114 | return MMU_OPS.read_byte (state, virt_addr, data); | ||
| 115 | }; | ||
| 116 | |||
| 117 | fault_t | ||
| 118 | mmu_read_halfword (ARMul_State * state, ARMword virt_addr, ARMword * data) | ||
| 119 | { | ||
| 120 | return MMU_OPS.read_halfword (state, virt_addr, data); | ||
| 121 | }; | ||
| 122 | |||
| 123 | fault_t | ||
| 124 | mmu_read_word (ARMul_State * state, ARMword virt_addr, ARMword * data) | ||
| 125 | { | ||
| 126 | return MMU_OPS.read_word (state, virt_addr, data); | ||
| 127 | }; | ||
| 128 | |||
| 129 | fault_t | ||
| 130 | mmu_write_byte (ARMul_State * state, ARMword virt_addr, ARMword data) | ||
| 131 | { | ||
| 132 | fault_t fault; | ||
| 133 | //static int count = 0; | ||
| 134 | //count ++; | ||
| 135 | fault = MMU_OPS.write_byte (state, virt_addr, data); | ||
| 136 | return fault; | ||
| 137 | } | ||
| 138 | |||
| 139 | fault_t | ||
| 140 | mmu_write_halfword (ARMul_State * state, ARMword virt_addr, ARMword data) | ||
| 141 | { | ||
| 142 | fault_t fault; | ||
| 143 | //static int count = 0; | ||
| 144 | //count ++; | ||
| 145 | fault = MMU_OPS.write_halfword (state, virt_addr, data); | ||
| 146 | return fault; | ||
| 147 | } | ||
| 148 | |||
| 149 | fault_t | ||
| 150 | mmu_write_word (ARMul_State * state, ARMword virt_addr, ARMword data) | ||
| 151 | { | ||
| 152 | fault_t fault; | ||
| 153 | fault = MMU_OPS.write_word (state, virt_addr, data); | ||
| 154 | |||
| 155 | /*used for debug for MMU* | ||
| 156 | |||
| 157 | if (!fault){ | ||
| 158 | ARMword tmp; | ||
| 159 | |||
| 160 | if (mmu_read_word(state, virt_addr, &tmp)){ | ||
| 161 | err_msg("load back\n"); | ||
| 162 | exit(-1); | ||
| 163 | }else{ | ||
| 164 | if (tmp != data){ | ||
| 165 | err_msg("load back not equal %d %x\n", count, virt_addr); | ||
| 166 | } | ||
| 167 | } | ||
| 168 | } | ||
| 169 | */ | ||
| 170 | |||
| 171 | return fault; | ||
| 172 | }; | ||
| 173 | |||
| 174 | fault_t | ||
| 175 | mmu_load_instr (ARMul_State * state, ARMword virt_addr, ARMword * instr) | ||
| 176 | { | ||
| 177 | return MMU_OPS.load_instr (state, virt_addr, instr); | ||
| 178 | } | ||
| 179 | |||
| 180 | ARMword | ||
| 181 | mmu_mrc (ARMul_State * state, ARMword instr, ARMword * value) | ||
| 182 | { | ||
| 183 | return MMU_OPS.mrc (state, instr, value); | ||
| 184 | } | ||
| 185 | |||
| 186 | void | ||
| 187 | mmu_mcr (ARMul_State * state, ARMword instr, ARMword value) | ||
| 188 | { | ||
| 189 | MMU_OPS.mcr (state, instr, value); | ||
| 190 | } | ||
| 191 | |||
| 192 | /*ywc 20050416*/ | ||
| 193 | int | ||
| 194 | mmu_v2p_dbct (ARMul_State * state, ARMword virt_addr, ARMword * phys_addr) | ||
| 195 | { | ||
| 196 | return (MMU_OPS.v2p_dbct (state, virt_addr, phys_addr)); | ||
| 197 | } | ||
| 198 | |||
| 199 | // | ||
| 200 | // | ||
| 201 | ///* dis_mmu_read for disassemble */ | ||
| 202 | //exception_t arm_mmu_read(short size, uint32_t addr, uint32_t * value) | ||
| 203 | //{ | ||
| 204 | // ARMul_State *state; | ||
| 205 | // ARM_CPU_State *cpu = get_current_cpu(); | ||
| 206 | // state = &cpu->core[0]; | ||
| 207 | // switch(size){ | ||
| 208 | // case 8: | ||
| 209 | // MMU_OPS.read_byte (state, addr, value); | ||
| 210 | // break; | ||
| 211 | // case 16: | ||
| 212 | // case 32: | ||
| 213 | // break; | ||
| 214 | // default: | ||
| 215 | // ERROR_LOG(ARM11, "Error size %d", size); | ||
| 216 | // break; | ||
| 217 | // } | ||
| 218 | // return No_exp; | ||
| 219 | //} | ||
| 220 | ///* dis_mmu_write for disassemble */ | ||
| 221 | //exception_t arm_mmu_write(short size, uint32_t addr, uint32_t *value) | ||
| 222 | //{ | ||
| 223 | // ARMul_State *state; | ||
| 224 | // ARM_CPU_State *cpu = get_current_cpu(); | ||
| 225 | // state = &cpu->core[0]; | ||
| 226 | // switch(size){ | ||
| 227 | // case 8: | ||
| 228 | // MMU_OPS.write_byte (state, addr, value); | ||
| 229 | // break; | ||
| 230 | // case 16: | ||
| 231 | // case 32: | ||
| 232 | // break; | ||
| 233 | // default: | ||
| 234 | // printf("In %s error size %d Line %d\n", __func__, size, __LINE__); | ||
| 235 | // break; | ||
| 236 | // } | ||
| 237 | // return No_exp; | ||
| 238 | //} | ||