arm_interface.h 2.6 KB

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