arm_interpreter.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #include "core/arm/interpreter/arm_interpreter.h"
  5. const static cpu_config_t s_arm11_cpu_info = {
  6. "armv6", "arm11", 0x0007b000, 0x0007f000, NONCACHE
  7. };
  8. ARM_Interpreter::ARM_Interpreter() {
  9. state = new ARMul_State;
  10. ARMul_EmulateInit();
  11. ARMul_NewState(state);
  12. state->abort_model = 0;
  13. state->cpu = (cpu_config_t*)&s_arm11_cpu_info;
  14. state->bigendSig = LOW;
  15. ARMul_SelectProcessor(state, ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop);
  16. state->lateabtSig = LOW;
  17. mmu_init(state);
  18. // Reset the core to initial state
  19. ARMul_Reset(state);
  20. state->NextInstr = 0;
  21. state->Emulate = 3;
  22. state->pc = state->Reg[15] = 0x00000000;
  23. state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack
  24. }
  25. ARM_Interpreter::~ARM_Interpreter() {
  26. delete state;
  27. }
  28. /**
  29. * Set the Program Counter to an address
  30. * @param addr Address to set PC to
  31. */
  32. void ARM_Interpreter::SetPC(u32 pc) {
  33. state->pc = state->Reg[15] = pc;
  34. }
  35. /*
  36. * Get the current Program Counter
  37. * @return Returns current PC
  38. */
  39. u32 ARM_Interpreter::GetPC() const {
  40. return state->pc;
  41. }
  42. /**
  43. * Get an ARM register
  44. * @param index Register index (0-15)
  45. * @return Returns the value in the register
  46. */
  47. u32 ARM_Interpreter::GetReg(int index) const {
  48. return state->Reg[index];
  49. }
  50. /**
  51. * Set an ARM register
  52. * @param index Register index (0-15)
  53. * @param value Value to set register to
  54. */
  55. void ARM_Interpreter::SetReg(int index, u32 value) {
  56. state->Reg[index] = value;
  57. }
  58. /**
  59. * Get the current CPSR register
  60. * @return Returns the value of the CPSR register
  61. */
  62. u32 ARM_Interpreter::GetCPSR() const {
  63. return state->Cpsr;
  64. }
  65. /**
  66. * Set the current CPSR register
  67. * @param cpsr Value to set CPSR to
  68. */
  69. void ARM_Interpreter::SetCPSR(u32 cpsr) {
  70. state->Cpsr = cpsr;
  71. }
  72. /**
  73. * Returns the number of clock ticks since the last reset
  74. * @return Returns number of clock ticks
  75. */
  76. u64 ARM_Interpreter::GetTicks() const {
  77. return ARMul_Time(state);
  78. }
  79. /**
  80. * Executes the given number of instructions
  81. * @param num_instructions Number of instructions to executes
  82. */
  83. void ARM_Interpreter::ExecuteInstructions(int num_instructions) {
  84. state->NumInstrsToExecute = num_instructions;
  85. ARMul_Emulate32(state);
  86. }
  87. /**
  88. * Saves the current CPU context
  89. * @param ctx Thread context to save
  90. * @todo Do we need to save Reg[15] and NextInstr?
  91. */
  92. void ARM_Interpreter::SaveContext(ThreadContext& ctx) {
  93. memcpy(ctx.cpu_registers, state->Reg, sizeof(ctx.cpu_registers));
  94. memcpy(ctx.fpu_registers, state->ExtReg, sizeof(ctx.fpu_registers));
  95. ctx.sp = state->Reg[13];
  96. ctx.lr = state->Reg[14];
  97. ctx.pc = state->pc;
  98. ctx.cpsr = state->Cpsr;
  99. ctx.fpscr = state->VFP[1];
  100. ctx.fpexc = state->VFP[2];
  101. }
  102. /**
  103. * Loads a CPU context
  104. * @param ctx Thread context to load
  105. * @param Do we need to load Reg[15] and NextInstr?
  106. */
  107. void ARM_Interpreter::LoadContext(const ThreadContext& ctx) {
  108. memcpy(state->Reg, ctx.cpu_registers, sizeof(ctx.cpu_registers));
  109. memcpy(state->ExtReg, ctx.fpu_registers, sizeof(ctx.fpu_registers));
  110. state->Reg[13] = ctx.sp;
  111. state->Reg[14] = ctx.lr;
  112. state->pc = ctx.pc;
  113. state->Cpsr = ctx.cpsr;
  114. state->VFP[1] = ctx.fpscr;
  115. state->VFP[2] = ctx.fpexc;
  116. }