arm_interpreter.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "core/arm/interpreter/arm_interpreter.h"
  5. #include "core/core.h"
  6. const static cpu_config_t arm11_cpu_info = {
  7. "armv6", "arm11", 0x0007b000, 0x0007f000, NONCACHE
  8. };
  9. ARM_Interpreter::ARM_Interpreter() {
  10. state = new ARMul_State;
  11. ARMul_EmulateInit();
  12. memset(state, 0, sizeof(ARMul_State));
  13. ARMul_NewState(state);
  14. state->abort_model = 0;
  15. state->cpu = (cpu_config_t*)&arm11_cpu_info;
  16. state->bigendSig = LOW;
  17. ARMul_SelectProcessor(state, ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop);
  18. state->lateabtSig = LOW;
  19. // Reset the core to initial state
  20. ARMul_CoProInit(state);
  21. ARMul_Reset(state);
  22. state->NextInstr = RESUME; // NOTE: This will be overwritten by LoadContext
  23. state->Emulate = 3;
  24. state->pc = state->Reg[15] = 0x00000000;
  25. state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack
  26. state->servaddr = 0xFFFF0000;
  27. }
  28. ARM_Interpreter::~ARM_Interpreter() {
  29. delete state;
  30. }
  31. void ARM_Interpreter::SetPC(u32 pc) {
  32. state->pc = state->Reg[15] = pc;
  33. }
  34. u32 ARM_Interpreter::GetPC() const {
  35. return state->pc;
  36. }
  37. u32 ARM_Interpreter::GetReg(int index) const {
  38. return state->Reg[index];
  39. }
  40. void ARM_Interpreter::SetReg(int index, u32 value) {
  41. state->Reg[index] = value;
  42. }
  43. u32 ARM_Interpreter::GetCPSR() const {
  44. return state->Cpsr;
  45. }
  46. void ARM_Interpreter::SetCPSR(u32 cpsr) {
  47. state->Cpsr = cpsr;
  48. }
  49. u64 ARM_Interpreter::GetTicks() const {
  50. return state->NumInstrs;
  51. }
  52. void ARM_Interpreter::AddTicks(u64 ticks) {
  53. state->NumInstrs += ticks;
  54. }
  55. void ARM_Interpreter::ExecuteInstructions(int num_instructions) {
  56. state->NumInstrsToExecute = num_instructions - 1;
  57. ARMul_Emulate32(state);
  58. }
  59. void ARM_Interpreter::SaveContext(Core::ThreadContext& ctx) {
  60. memcpy(ctx.cpu_registers, state->Reg, sizeof(ctx.cpu_registers));
  61. memcpy(ctx.fpu_registers, state->ExtReg, sizeof(ctx.fpu_registers));
  62. ctx.sp = state->Reg[13];
  63. ctx.lr = state->Reg[14];
  64. ctx.pc = state->pc;
  65. ctx.cpsr = state->Cpsr;
  66. ctx.fpscr = state->VFP[1];
  67. ctx.fpexc = state->VFP[2];
  68. ctx.reg_15 = state->Reg[15];
  69. ctx.mode = state->NextInstr;
  70. }
  71. void ARM_Interpreter::LoadContext(const Core::ThreadContext& ctx) {
  72. memcpy(state->Reg, ctx.cpu_registers, sizeof(ctx.cpu_registers));
  73. memcpy(state->ExtReg, ctx.fpu_registers, sizeof(ctx.fpu_registers));
  74. state->Reg[13] = ctx.sp;
  75. state->Reg[14] = ctx.lr;
  76. state->pc = ctx.pc;
  77. state->Cpsr = ctx.cpsr;
  78. state->VFP[1] = ctx.fpscr;
  79. state->VFP[2] = ctx.fpexc;
  80. state->Reg[15] = ctx.reg_15;
  81. state->NextInstr = ctx.mode;
  82. }
  83. void ARM_Interpreter::PrepareReschedule() {
  84. state->NumInstrsToExecute = 0;
  85. }