arm_interface.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. namespace Core {
  8. struct ThreadContext;
  9. }
  10. /// Generic ARM11 CPU interface
  11. class ARM_Interface : NonCopyable {
  12. public:
  13. ARM_Interface() {
  14. num_instructions = 0;
  15. }
  16. virtual ~ARM_Interface() {
  17. }
  18. /**
  19. * Runs the CPU for the given number of instructions
  20. * @param num_instructions Number of instructions to run
  21. */
  22. void Run(int num_instructions) {
  23. ExecuteInstructions(num_instructions);
  24. this->num_instructions += num_instructions;
  25. }
  26. /// Step CPU by one instruction
  27. void Step() {
  28. Run(1);
  29. }
  30. /**
  31. * Set the Program Counter to an address
  32. * @param addr Address to set PC to
  33. */
  34. virtual void SetPC(u32 addr) = 0;
  35. /*
  36. * Get the current Program Counter
  37. * @return Returns current PC
  38. */
  39. virtual u32 GetPC() const = 0;
  40. /**
  41. * Get an ARM register
  42. * @param index Register index (0-15)
  43. * @return Returns the value in the register
  44. */
  45. virtual u32 GetReg(int index) const = 0;
  46. /**
  47. * Set an ARM register
  48. * @param index Register index (0-15)
  49. * @param value Value to set register to
  50. */
  51. virtual void SetReg(int index, u32 value) = 0;
  52. /**
  53. * Get the current CPSR register
  54. * @return Returns the value of the CPSR register
  55. */
  56. virtual u32 GetCPSR() const = 0;
  57. /**
  58. * Set the current CPSR register
  59. * @param cpsr Value to set CPSR to
  60. */
  61. virtual void SetCPSR(u32 cpsr) = 0;
  62. /**
  63. * Returns the number of clock ticks since the last rese
  64. * @return Returns number of clock ticks
  65. */
  66. virtual u64 GetTicks() const = 0;
  67. /**
  68. * Advance the CPU core by the specified number of ticks (e.g. to simulate CPU execution time)
  69. * @param ticks Number of ticks to advance the CPU core
  70. */
  71. virtual void AddTicks(u64 ticks) = 0;
  72. /**
  73. * Saves the current CPU context
  74. * @param ctx Thread context to save
  75. */
  76. virtual void SaveContext(Core::ThreadContext& ctx) = 0;
  77. /**
  78. * Loads a CPU context
  79. * @param ctx Thread context to load
  80. */
  81. virtual void LoadContext(const Core::ThreadContext& ctx) = 0;
  82. /// Prepare core for thread reschedule (if needed to correctly handle state)
  83. virtual void PrepareReschedule() = 0;
  84. /// Getter for num_instructions
  85. u64 GetNumInstructions() {
  86. return num_instructions;
  87. }
  88. s64 down_count; ///< A decreasing counter of remaining cycles before the next event, decreased by the cpu run loop
  89. protected:
  90. /**
  91. * Executes the given number of instructions
  92. * @param num_instructions Number of instructions to executes
  93. */
  94. virtual void ExecuteInstructions(int num_instructions) = 0;
  95. private:
  96. u64 num_instructions; ///< Number of instructions executed
  97. };