armmmu.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. armmmu.c - Memory Management Unit emulation.
  3. ARMulator extensions for the ARM7100 family.
  4. Copyright (C) 1999 Ben Williamson
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include <assert.h>
  18. #include <string.h>
  19. #include "armdefs.h"
  20. /* two header for arm disassemble */
  21. //#include "skyeye_arch.h"
  22. #include "armcpu.h"
  23. extern mmu_ops_t xscale_mmu_ops;
  24. exception_t arm_mmu_write(short size, u32 addr, uint32_t *value);
  25. exception_t arm_mmu_read(short size, u32 addr, uint32_t *value);
  26. #define MMU_OPS (state->mmu.ops)
  27. ARMword skyeye_cachetype = -1;
  28. int
  29. mmu_init (ARMul_State * state)
  30. {
  31. int ret;
  32. state->mmu.control = 0x70;
  33. state->mmu.translation_table_base = 0xDEADC0DE;
  34. state->mmu.domain_access_control = 0xDEADC0DE;
  35. state->mmu.fault_status = 0;
  36. state->mmu.fault_address = 0;
  37. state->mmu.process_id = 0;
  38. switch (state->cpu->cpu_val & state->cpu->cpu_mask) {
  39. //case SA1100:
  40. //case SA1110:
  41. // NOTICE_LOG(ARM11, "SKYEYE: use sa11xx mmu ops\n");
  42. // state->mmu.ops = sa_mmu_ops;
  43. // break;
  44. //case PXA250:
  45. //case PXA270: //xscale
  46. // NOTICE_LOG(ARM11, "SKYEYE: use xscale mmu ops\n");
  47. // state->mmu.ops = xscale_mmu_ops;
  48. // break;
  49. //case 0x41807200: //arm720t
  50. //case 0x41007700: //arm7tdmi
  51. //case 0x41007100: //arm7100
  52. // NOTICE_LOG(ARM11, "SKYEYE: use arm7100 mmu ops\n");
  53. // state->mmu.ops = arm7100_mmu_ops;
  54. // break;
  55. //case 0x41009200:
  56. // NOTICE_LOG(ARM11, "SKYEYE: use arm920t mmu ops\n");
  57. // state->mmu.ops = arm920t_mmu_ops;
  58. // break;
  59. //case 0x41069260:
  60. // NOTICE_LOG(ARM11, "SKYEYE: use arm926ejs mmu ops\n");
  61. // state->mmu.ops = arm926ejs_mmu_ops;
  62. // break;
  63. /* case 0x560f5810: */
  64. case 0x0007b000:
  65. NOTICE_LOG(ARM11, "SKYEYE: use arm11jzf-s mmu ops\n");
  66. state->mmu.ops = arm1176jzf_s_mmu_ops;
  67. break;
  68. default:
  69. ERROR_LOG (ARM11,
  70. "SKYEYE: armmmu.c : mmu_init: unknown cpu_val&cpu_mask 0x%x\n",
  71. state->cpu->cpu_val & state->cpu->cpu_mask);
  72. break;
  73. };
  74. ret = state->mmu.ops.init (state);
  75. state->mmu_inited = (ret == 0);
  76. /* initialize mmu_read and mmu_write for disassemble */
  77. //skyeye_config_t *config = get_current_config();
  78. //generic_arch_t *arch_instance = get_arch_instance(config->arch->arch_name);
  79. //arch_instance->mmu_read = arm_mmu_read;
  80. //arch_instance->mmu_write = arm_mmu_write;
  81. return ret;
  82. }
  83. int
  84. mmu_reset (ARMul_State * state)
  85. {
  86. if (state->mmu_inited)
  87. mmu_exit (state);
  88. return mmu_init (state);
  89. }
  90. void
  91. mmu_exit (ARMul_State * state)
  92. {
  93. MMU_OPS.exit (state);
  94. state->mmu_inited = 0;
  95. }
  96. fault_t
  97. mmu_read_byte (ARMul_State * state, ARMword virt_addr, ARMword * data)
  98. {
  99. return MMU_OPS.read_byte (state, virt_addr, data);
  100. };
  101. fault_t
  102. mmu_read_halfword (ARMul_State * state, ARMword virt_addr, ARMword * data)
  103. {
  104. return MMU_OPS.read_halfword (state, virt_addr, data);
  105. };
  106. fault_t
  107. mmu_read_word (ARMul_State * state, ARMword virt_addr, ARMword * data)
  108. {
  109. return MMU_OPS.read_word (state, virt_addr, data);
  110. };
  111. fault_t
  112. mmu_write_byte (ARMul_State * state, ARMword virt_addr, ARMword data)
  113. {
  114. fault_t fault;
  115. //static int count = 0;
  116. //count ++;
  117. fault = MMU_OPS.write_byte (state, virt_addr, data);
  118. return fault;
  119. }
  120. fault_t
  121. mmu_write_halfword (ARMul_State * state, ARMword virt_addr, ARMword data)
  122. {
  123. fault_t fault;
  124. //static int count = 0;
  125. //count ++;
  126. fault = MMU_OPS.write_halfword (state, virt_addr, data);
  127. return fault;
  128. }
  129. fault_t
  130. mmu_write_word (ARMul_State * state, ARMword virt_addr, ARMword data)
  131. {
  132. fault_t fault;
  133. fault = MMU_OPS.write_word (state, virt_addr, data);
  134. /*used for debug for MMU*
  135. if (!fault){
  136. ARMword tmp;
  137. if (mmu_read_word(state, virt_addr, &tmp)){
  138. err_msg("load back\n");
  139. exit(-1);
  140. }else{
  141. if (tmp != data){
  142. err_msg("load back not equal %d %x\n", count, virt_addr);
  143. }
  144. }
  145. }
  146. */
  147. return fault;
  148. };
  149. fault_t
  150. mmu_load_instr (ARMul_State * state, ARMword virt_addr, ARMword * instr)
  151. {
  152. return MMU_OPS.load_instr (state, virt_addr, instr);
  153. }
  154. ARMword
  155. mmu_mrc (ARMul_State * state, ARMword instr, ARMword * value)
  156. {
  157. return MMU_OPS.mrc (state, instr, value);
  158. }
  159. void
  160. mmu_mcr (ARMul_State * state, ARMword instr, ARMword value)
  161. {
  162. MMU_OPS.mcr (state, instr, value);
  163. }
  164. /*ywc 20050416*/
  165. int
  166. mmu_v2p_dbct (ARMul_State * state, ARMword virt_addr, ARMword * phys_addr)
  167. {
  168. return (MMU_OPS.v2p_dbct (state, virt_addr, phys_addr));
  169. }
  170. //
  171. //
  172. ///* dis_mmu_read for disassemble */
  173. //exception_t arm_mmu_read(short size, uint32_t addr, uint32_t * value)
  174. //{
  175. // ARMul_State *state;
  176. // ARM_CPU_State *cpu = get_current_cpu();
  177. // state = &cpu->core[0];
  178. // switch(size){
  179. // case 8:
  180. // MMU_OPS.read_byte (state, addr, value);
  181. // break;
  182. // case 16:
  183. // case 32:
  184. // break;
  185. // default:
  186. // ERROR_LOG(ARM11, "Error size %d", size);
  187. // break;
  188. // }
  189. // return No_exp;
  190. //}
  191. ///* dis_mmu_write for disassemble */
  192. //exception_t arm_mmu_write(short size, uint32_t addr, uint32_t *value)
  193. //{
  194. // ARMul_State *state;
  195. // ARM_CPU_State *cpu = get_current_cpu();
  196. // state = &cpu->core[0];
  197. // switch(size){
  198. // case 8:
  199. // MMU_OPS.write_byte (state, addr, value);
  200. // break;
  201. // case 16:
  202. // case 32:
  203. // break;
  204. // default:
  205. // printf("In %s error size %d Line %d\n", __func__, size, __LINE__);
  206. // break;
  207. // }
  208. // return No_exp;
  209. //}