arm_dyncom.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/skyeye_common/armemu.h"
  5. #include "core/arm/skyeye_common/vfp/vfp.h"
  6. #include "core/arm/dyncom/arm_dyncom.h"
  7. #include "core/arm/dyncom/arm_dyncom_interpreter.h"
  8. #include "core/core.h"
  9. #include "core/core_timing.h"
  10. const static cpu_config_t s_arm11_cpu_info = {
  11. "armv6", "arm11", 0x0007b000, 0x0007f000, NONCACHE
  12. };
  13. ARM_DynCom::ARM_DynCom() {
  14. state = std::unique_ptr<ARMul_State>(new ARMul_State);
  15. ARMul_EmulateInit();
  16. memset(state.get(), 0, sizeof(ARMul_State));
  17. ARMul_NewState((ARMul_State*)state.get());
  18. state->abort_model = 0;
  19. state->cpu = (cpu_config_t*)&s_arm11_cpu_info;
  20. state->bigendSig = LOW;
  21. ARMul_SelectProcessor(state.get(), ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop);
  22. state->lateabtSig = LOW;
  23. // Reset the core to initial state
  24. ARMul_CoProInit(state.get());
  25. ARMul_Reset(state.get());
  26. state->NextInstr = RESUME; // NOTE: This will be overwritten by LoadContext
  27. state->Emulate = 3;
  28. state->Reg[15] = 0x00000000;
  29. state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack
  30. state->NirqSig = HIGH;
  31. VFPInit(state.get()); // Initialize the VFP
  32. ARMul_EmulateInit();
  33. }
  34. ARM_DynCom::~ARM_DynCom() {
  35. }
  36. void ARM_DynCom::SetPC(u32 pc) {
  37. state->Reg[15] = pc;
  38. }
  39. u32 ARM_DynCom::GetPC() const {
  40. return state->Reg[15];
  41. }
  42. u32 ARM_DynCom::GetReg(int index) const {
  43. return state->Reg[index];
  44. }
  45. void ARM_DynCom::SetReg(int index, u32 value) {
  46. state->Reg[index] = value;
  47. }
  48. u32 ARM_DynCom::GetCPSR() const {
  49. return state->Cpsr;
  50. }
  51. void ARM_DynCom::SetCPSR(u32 cpsr) {
  52. state->Cpsr = cpsr;
  53. }
  54. u64 ARM_DynCom::GetTicks() const {
  55. // TODO(Subv): Remove ARM_DynCom::GetTicks() and use CoreTiming::GetTicks() directly once ARMemu is gone
  56. return CoreTiming::GetTicks();
  57. }
  58. void ARM_DynCom::AddTicks(u64 ticks) {
  59. down_count -= ticks;
  60. if (down_count < 0)
  61. CoreTiming::Advance();
  62. }
  63. void ARM_DynCom::ExecuteInstructions(int num_instructions) {
  64. state->NumInstrsToExecute = num_instructions;
  65. // Dyncom only breaks on instruction dispatch. This only happens on every instruction when
  66. // executing one instruction at a time. Otherwise, if a block is being executed, more
  67. // instructions may actually be executed than specified.
  68. unsigned ticks_executed = InterpreterMainLoop(state.get());
  69. AddTicks(ticks_executed);
  70. }
  71. void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) {
  72. memcpy(ctx.cpu_registers, state->Reg, sizeof(ctx.cpu_registers));
  73. memcpy(ctx.fpu_registers, state->ExtReg, sizeof(ctx.fpu_registers));
  74. ctx.sp = state->Reg[13];
  75. ctx.lr = state->Reg[14];
  76. ctx.pc = state->Reg[15];
  77. ctx.cpsr = state->Cpsr;
  78. ctx.fpscr = state->VFP[1];
  79. ctx.fpexc = state->VFP[2];
  80. ctx.mode = state->NextInstr;
  81. }
  82. void ARM_DynCom::LoadContext(const Core::ThreadContext& ctx) {
  83. memcpy(state->Reg, ctx.cpu_registers, sizeof(ctx.cpu_registers));
  84. memcpy(state->ExtReg, ctx.fpu_registers, sizeof(ctx.fpu_registers));
  85. state->Reg[13] = ctx.sp;
  86. state->Reg[14] = ctx.lr;
  87. state->Reg[15] = ctx.pc;
  88. state->Cpsr = ctx.cpsr;
  89. state->VFP[1] = ctx.fpscr;
  90. state->VFP[2] = ctx.fpexc;
  91. state->NextInstr = ctx.mode;
  92. }
  93. void ARM_DynCom::PrepareReschedule() {
  94. state->NumInstrsToExecute = 0;
  95. }