arm_interface.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_types.h"
  6. #include "core/arm/skyeye_common/arm_regformat.h"
  7. #include "core/arm/skyeye_common/vfp/asm_vfp.h"
  8. /// Generic ARM11 CPU interface
  9. class ARM_Interface : NonCopyable {
  10. public:
  11. virtual ~ARM_Interface() {}
  12. struct ThreadContext {
  13. u32 cpu_registers[13];
  14. u32 sp;
  15. u32 lr;
  16. u32 pc;
  17. u32 cpsr;
  18. u32 fpu_registers[64];
  19. u32 fpscr;
  20. u32 fpexc;
  21. };
  22. /**
  23. * Runs the CPU for the given number of instructions
  24. * @param num_instructions Number of instructions to run
  25. */
  26. void Run(int num_instructions) {
  27. ExecuteInstructions(num_instructions);
  28. this->num_instructions += num_instructions;
  29. }
  30. /// Step CPU by one instruction
  31. void Step() {
  32. Run(1);
  33. }
  34. /// Clear all instruction cache
  35. virtual void ClearInstructionCache() = 0;
  36. /**
  37. * Set the Program Counter to an address
  38. * @param addr Address to set PC to
  39. */
  40. virtual void SetPC(u32 addr) = 0;
  41. /*
  42. * Get the current Program Counter
  43. * @return Returns current PC
  44. */
  45. virtual u32 GetPC() const = 0;
  46. /**
  47. * Get an ARM register
  48. * @param index Register index (0-15)
  49. * @return Returns the value in the register
  50. */
  51. virtual u32 GetReg(int index) const = 0;
  52. /**
  53. * Set an ARM register
  54. * @param index Register index (0-15)
  55. * @param value Value to set register to
  56. */
  57. virtual void SetReg(int index, u32 value) = 0;
  58. /**
  59. * Gets the value of a VFP register
  60. * @param index Register index (0-31)
  61. * @return Returns the value in the register
  62. */
  63. virtual u32 GetVFPReg(int index) const = 0;
  64. /**
  65. * Sets a VFP register to the given value
  66. * @param index Register index (0-31)
  67. * @param value Value to set register to
  68. */
  69. virtual void SetVFPReg(int index, u32 value) = 0;
  70. /**
  71. * Gets the current value within a given VFP system register
  72. * @param reg The VFP system register
  73. * @return The value within the VFP system register
  74. */
  75. virtual u32 GetVFPSystemReg(VFPSystemRegister reg) const = 0;
  76. /**
  77. * Sets the VFP system register to the given value
  78. * @param reg The VFP system register
  79. * @param value Value to set the VFP system register to
  80. */
  81. virtual void SetVFPSystemReg(VFPSystemRegister reg, u32 value) = 0;
  82. /**
  83. * Get the current CPSR register
  84. * @return Returns the value of the CPSR register
  85. */
  86. virtual u32 GetCPSR() const = 0;
  87. /**
  88. * Set the current CPSR register
  89. * @param cpsr Value to set CPSR to
  90. */
  91. virtual void SetCPSR(u32 cpsr) = 0;
  92. /**
  93. * Gets the value stored in a CP15 register.
  94. * @param reg The CP15 register to retrieve the value from.
  95. * @return the value stored in the given CP15 register.
  96. */
  97. virtual u32 GetCP15Register(CP15Register reg) = 0;
  98. /**
  99. * Stores the given value into the indicated CP15 register.
  100. * @param reg The CP15 register to store the value into.
  101. * @param value The value to store into the CP15 register.
  102. */
  103. virtual void SetCP15Register(CP15Register reg, u32 value) = 0;
  104. /**
  105. * Advance the CPU core by the specified number of ticks (e.g. to simulate CPU execution time)
  106. * @param ticks Number of ticks to advance the CPU core
  107. */
  108. virtual void AddTicks(u64 ticks) = 0;
  109. /**
  110. * Saves the current CPU context
  111. * @param ctx Thread context to save
  112. */
  113. virtual void SaveContext(ThreadContext& ctx) = 0;
  114. /**
  115. * Loads a CPU context
  116. * @param ctx Thread context to load
  117. */
  118. virtual void LoadContext(const ThreadContext& ctx) = 0;
  119. /// Prepare core for thread reschedule (if needed to correctly handle state)
  120. virtual void PrepareReschedule() = 0;
  121. /// Getter for num_instructions
  122. u64 GetNumInstructions() const {
  123. return num_instructions;
  124. }
  125. s64 down_count = 0; ///< A decreasing counter of remaining cycles before the next event,
  126. /// decreased by the cpu run loop
  127. protected:
  128. /**
  129. * Executes the given number of instructions
  130. * @param num_instructions Number of instructions to executes
  131. */
  132. virtual void ExecuteInstructions(int num_instructions) = 0;
  133. private:
  134. u64 num_instructions = 0; ///< Number of instructions executed
  135. };