core.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/common_types.h"
  5. #include "core/core.h"
  6. #include "core/core_timing.h"
  7. #include "core/settings.h"
  8. #include "core/arm/disassembler/arm_disasm.h"
  9. #include "core/arm/interpreter/arm_interpreter.h"
  10. #include "core/arm/dyncom/arm_dyncom.h"
  11. #include "core/hle/hle.h"
  12. #include "core/hle/kernel/thread.h"
  13. #include "core/hw/hw.h"
  14. namespace Core {
  15. static u64 last_ticks = 0; ///< Last CPU ticks
  16. static ARM_Disasm* disasm = nullptr; ///< ARM disassembler
  17. ARM_Interface* g_app_core = nullptr; ///< ARM11 application core
  18. ARM_Interface* g_sys_core = nullptr; ///< ARM11 system (OS) core
  19. /// Run the core CPU loop
  20. void RunLoop(int tight_loop) {
  21. // If the current thread is an idle thread, then don't execute instructions,
  22. // instead advance to the next event and try to yield to the next thread
  23. if (Kernel::IsIdleThread(Kernel::GetCurrentThreadHandle())) {
  24. LOG_TRACE(Core_ARM11, "Idling");
  25. CoreTiming::Idle();
  26. CoreTiming::Advance();
  27. HLE::Reschedule(__func__);
  28. } else {
  29. g_app_core->Run(tight_loop);
  30. }
  31. HW::Update();
  32. if (HLE::g_reschedule) {
  33. Kernel::Reschedule();
  34. }
  35. }
  36. /// Step the CPU one instruction
  37. void SingleStep() {
  38. RunLoop(1);
  39. }
  40. /// Halt the core
  41. void Halt(const char *msg) {
  42. // TODO(ShizZy): ImplementMe
  43. }
  44. /// Kill the core
  45. void Stop() {
  46. // TODO(ShizZy): ImplementMe
  47. }
  48. /// Initialize the core
  49. int Init() {
  50. LOG_DEBUG(Core, "initialized OK");
  51. disasm = new ARM_Disasm();
  52. g_sys_core = new ARM_Interpreter();
  53. switch (Settings::values.cpu_core) {
  54. case CPU_Interpreter:
  55. g_app_core = new ARM_DynCom();
  56. break;
  57. case CPU_OldInterpreter:
  58. default:
  59. g_app_core = new ARM_Interpreter();
  60. break;
  61. }
  62. last_ticks = Core::g_app_core->GetTicks();
  63. return 0;
  64. }
  65. void Shutdown() {
  66. delete disasm;
  67. delete g_app_core;
  68. delete g_sys_core;
  69. LOG_DEBUG(Core, "shutdown OK");
  70. }
  71. } // namespace