arm_interface.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.h"
  6. #include "common/common_types.h"
  7. #include "core/arm/skyeye_common/arm_regformat.h"
  8. namespace Core {
  9. struct ThreadContext;
  10. }
  11. /// Generic ARM11 CPU interface
  12. class ARM_Interface : NonCopyable {
  13. public:
  14. ARM_Interface() {
  15. num_instructions = 0;
  16. }
  17. virtual ~ARM_Interface() {
  18. }
  19. /**
  20. * Runs the CPU for the given number of instructions
  21. * @param num_instructions Number of instructions to run
  22. */
  23. void Run(int num_instructions) {
  24. ExecuteInstructions(num_instructions);
  25. this->num_instructions += num_instructions;
  26. }
  27. /// Step CPU by one instruction
  28. void Step() {
  29. Run(1);
  30. }
  31. /**
  32. * Set the Program Counter to an address
  33. * @param addr Address to set PC to
  34. */
  35. virtual void SetPC(u32 addr) = 0;
  36. /*
  37. * Get the current Program Counter
  38. * @return Returns current PC
  39. */
  40. virtual u32 GetPC() const = 0;
  41. /**
  42. * Get an ARM register
  43. * @param index Register index (0-15)
  44. * @return Returns the value in the register
  45. */
  46. virtual u32 GetReg(int index) const = 0;
  47. /**
  48. * Set an ARM register
  49. * @param index Register index (0-15)
  50. * @param value Value to set register to
  51. */
  52. virtual void SetReg(int index, u32 value) = 0;
  53. /**
  54. * Get the current CPSR register
  55. * @return Returns the value of the CPSR register
  56. */
  57. virtual u32 GetCPSR() const = 0;
  58. /**
  59. * Set the current CPSR register
  60. * @param cpsr Value to set CPSR to
  61. */
  62. virtual void SetCPSR(u32 cpsr) = 0;
  63. /**
  64. * Gets the value stored in a CP15 register.
  65. * @param reg The CP15 register to retrieve the value from.
  66. * @return the value stored in the given CP15 register.
  67. */
  68. virtual u32 GetCP15Register(CP15Register reg) = 0;
  69. /**
  70. * Stores the given value into the indicated CP15 register.
  71. * @param reg The CP15 register to store the value into.
  72. * @param value The value to store into the CP15 register.
  73. */
  74. virtual void SetCP15Register(CP15Register reg, u32 value) = 0;
  75. /**
  76. * Advance the CPU core by the specified number of ticks (e.g. to simulate CPU execution time)
  77. * @param ticks Number of ticks to advance the CPU core
  78. */
  79. virtual void AddTicks(u64 ticks) = 0;
  80. /**
  81. * Initializes a CPU context for use on this CPU
  82. * @param context Thread context to reset
  83. * @param stack_top Pointer to the top of the stack
  84. * @param entry_point Entry point for execution
  85. * @param arg User argument for thread
  86. */
  87. virtual void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) = 0;
  88. /**
  89. * Saves the current CPU context
  90. * @param ctx Thread context to save
  91. */
  92. virtual void SaveContext(Core::ThreadContext& ctx) = 0;
  93. /**
  94. * Loads a CPU context
  95. * @param ctx Thread context to load
  96. */
  97. virtual void LoadContext(const Core::ThreadContext& ctx) = 0;
  98. /// Prepare core for thread reschedule (if needed to correctly handle state)
  99. virtual void PrepareReschedule() = 0;
  100. /// Getter for num_instructions
  101. u64 GetNumInstructions() {
  102. return num_instructions;
  103. }
  104. s64 down_count; ///< A decreasing counter of remaining cycles before the next event, decreased by the cpu run loop
  105. protected:
  106. /**
  107. * Executes the given number of instructions
  108. * @param num_instructions Number of instructions to executes
  109. */
  110. virtual void ExecuteInstructions(int num_instructions) = 0;
  111. private:
  112. u64 num_instructions; ///< Number of instructions executed
  113. };