arm_interpreter.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #include "core/arm/interpreter/arm_interpreter.h"
  5. const static cpu_config_t s_arm11_cpu_info = {
  6. "armv6", "arm11", 0x0007b000, 0x0007f000, NONCACHE
  7. };
  8. ARM_Interpreter::ARM_Interpreter() {
  9. m_state = new ARMul_State;
  10. ARMul_EmulateInit();
  11. ARMul_NewState(m_state);
  12. m_state->abort_model = 0;
  13. m_state->cpu = (cpu_config_t*)&s_arm11_cpu_info;
  14. m_state->bigendSig = LOW;
  15. ARMul_SelectProcessor(m_state, ARM_v6_Prop | ARM_v5_Prop | ARM_v5e_Prop);
  16. m_state->lateabtSig = LOW;
  17. mmu_init(m_state);
  18. // Reset the core to initial state
  19. ARMul_Reset(m_state);
  20. m_state->NextInstr = 0;
  21. m_state->Emulate = 3;
  22. m_state->pc = m_state->Reg[15] = 0x00000000;
  23. m_state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack
  24. }
  25. ARM_Interpreter::~ARM_Interpreter() {
  26. delete m_state;
  27. }
  28. /**
  29. * Set the Program Counter to an address
  30. * @param addr Address to set PC to
  31. */
  32. void ARM_Interpreter::SetPC(u32 pc) {
  33. m_state->pc = m_state->Reg[15] = pc;
  34. }
  35. /*
  36. * Get the current Program Counter
  37. * @return Returns current PC
  38. */
  39. u32 ARM_Interpreter::GetPC() const {
  40. return m_state->pc;
  41. }
  42. /**
  43. * Get an ARM register
  44. * @param index Register index (0-15)
  45. * @return Returns the value in the register
  46. */
  47. u32 ARM_Interpreter::GetReg(int index) const {
  48. return m_state->Reg[index];
  49. }
  50. /**
  51. * Set an ARM register
  52. * @param index Register index (0-15)
  53. * @param value Value to set register to
  54. */
  55. void ARM_Interpreter::SetReg(int index, u32 value) {
  56. m_state->Reg[index] = value;
  57. }
  58. /**
  59. * Get the current CPSR register
  60. * @return Returns the value of the CPSR register
  61. */
  62. u32 ARM_Interpreter::GetCPSR() const {
  63. return m_state->Cpsr;
  64. }
  65. /**
  66. * Returns the number of clock ticks since the last reset
  67. * @return Returns number of clock ticks
  68. */
  69. u64 ARM_Interpreter::GetTicks() const {
  70. return ARMul_Time(m_state);
  71. }
  72. /**
  73. * Executes the given number of instructions
  74. * @param num_instructions Number of instructions to executes
  75. */
  76. void ARM_Interpreter::ExecuteInstructions(int num_instructions) {
  77. m_state->NumInstrsToExecute = num_instructions;
  78. ARMul_Emulate32(m_state);
  79. }