arm_dyncom.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cstring>
  5. #include "common/make_unique.h"
  6. #include "core/arm/skyeye_common/armdefs.h"
  7. #include "core/arm/skyeye_common/armsupp.h"
  8. #include "core/arm/skyeye_common/vfp/vfp.h"
  9. #include "core/arm/dyncom/arm_dyncom.h"
  10. #include "core/arm/dyncom/arm_dyncom_interpreter.h"
  11. #include "core/arm/dyncom/arm_dyncom_run.h"
  12. #include "core/core.h"
  13. #include "core/core_timing.h"
  14. ARM_DynCom::ARM_DynCom(PrivilegeMode initial_mode) {
  15. state = Common::make_unique<ARMul_State>();
  16. ARMul_NewState(state.get());
  17. ARMul_SelectProcessor(state.get(), ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop);
  18. state->abort_model = ABORT_BASE_RESTORED;
  19. state->bigendSig = LOW;
  20. state->lateabtSig = LOW;
  21. state->NirqSig = HIGH;
  22. // Reset the core to initial state
  23. ARMul_Reset(state.get());
  24. state->Emulate = RUN;
  25. // Switch to the desired privilege mode.
  26. switch_mode(state.get(), initial_mode);
  27. state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack
  28. state->Reg[15] = 0x00000000;
  29. }
  30. ARM_DynCom::~ARM_DynCom() {
  31. }
  32. void ARM_DynCom::SetPC(u32 pc) {
  33. state->Reg[15] = pc;
  34. }
  35. u32 ARM_DynCom::GetPC() const {
  36. return state->Reg[15];
  37. }
  38. u32 ARM_DynCom::GetReg(int index) const {
  39. return state->Reg[index];
  40. }
  41. void ARM_DynCom::SetReg(int index, u32 value) {
  42. state->Reg[index] = value;
  43. }
  44. u32 ARM_DynCom::GetCPSR() const {
  45. return state->Cpsr;
  46. }
  47. void ARM_DynCom::SetCPSR(u32 cpsr) {
  48. state->Cpsr = cpsr;
  49. }
  50. u32 ARM_DynCom::GetCP15Register(CP15Register reg) {
  51. return state->CP15[reg];
  52. }
  53. void ARM_DynCom::SetCP15Register(CP15Register reg, u32 value) {
  54. state->CP15[reg] = value;
  55. }
  56. void ARM_DynCom::AddTicks(u64 ticks) {
  57. down_count -= ticks;
  58. if (down_count < 0)
  59. CoreTiming::Advance();
  60. }
  61. void ARM_DynCom::ExecuteInstructions(int num_instructions) {
  62. state->NumInstrsToExecute = num_instructions;
  63. // Dyncom only breaks on instruction dispatch. This only happens on every instruction when
  64. // executing one instruction at a time. Otherwise, if a block is being executed, more
  65. // instructions may actually be executed than specified.
  66. unsigned ticks_executed = InterpreterMainLoop(state.get());
  67. AddTicks(ticks_executed);
  68. }
  69. void ARM_DynCom::ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) {
  70. memset(&context, 0, sizeof(Core::ThreadContext));
  71. context.cpu_registers[0] = arg;
  72. context.pc = entry_point;
  73. context.sp = stack_top;
  74. context.cpsr = 0x1F; // Usermode
  75. }
  76. void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) {
  77. memcpy(ctx.cpu_registers, state->Reg, sizeof(ctx.cpu_registers));
  78. memcpy(ctx.fpu_registers, state->ExtReg, sizeof(ctx.fpu_registers));
  79. ctx.sp = state->Reg[13];
  80. ctx.lr = state->Reg[14];
  81. ctx.pc = state->Reg[15];
  82. ctx.cpsr = state->Cpsr;
  83. ctx.fpscr = state->VFP[1];
  84. ctx.fpexc = state->VFP[2];
  85. }
  86. void ARM_DynCom::LoadContext(const Core::ThreadContext& ctx) {
  87. memcpy(state->Reg, ctx.cpu_registers, sizeof(ctx.cpu_registers));
  88. memcpy(state->ExtReg, ctx.fpu_registers, sizeof(ctx.fpu_registers));
  89. state->Reg[13] = ctx.sp;
  90. state->Reg[14] = ctx.lr;
  91. state->Reg[15] = ctx.pc;
  92. state->Cpsr = ctx.cpsr;
  93. state->VFP[1] = ctx.fpscr;
  94. state->VFP[2] = ctx.fpexc;
  95. }
  96. void ARM_DynCom::PrepareReschedule() {
  97. state->NumInstrsToExecute = 0;
  98. }