core.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <memory>
  5. #include "common/logging/log.h"
  6. #include "core/arm/arm_interface.h"
  7. #include "core/arm/dynarmic/arm_dynarmic.h"
  8. #include "core/arm/dyncom/arm_dyncom.h"
  9. #include "core/core.h"
  10. #include "core/core_timing.h"
  11. #include "core/gdbstub/gdbstub.h"
  12. #include "core/hle/hle.h"
  13. #include "core/hle/kernel/thread.h"
  14. #include "core/hw/hw.h"
  15. #include "core/settings.h"
  16. namespace Core {
  17. std::unique_ptr<ARM_Interface> g_app_core; ///< ARM11 application core
  18. std::unique_ptr<ARM_Interface> g_sys_core; ///< ARM11 system (OS) core
  19. /// Run the core CPU loop
  20. void RunLoop(int tight_loop) {
  21. if (GDBStub::IsServerEnabled()) {
  22. GDBStub::HandlePacket();
  23. // If the loop is halted and we want to step, use a tiny (1) number of instructions to
  24. // execute. Otherwise, get out of the loop function.
  25. if (GDBStub::GetCpuHaltFlag()) {
  26. if (GDBStub::GetCpuStepFlag()) {
  27. GDBStub::SetCpuStepFlag(false);
  28. tight_loop = 1;
  29. } else {
  30. return;
  31. }
  32. }
  33. }
  34. // If we don't have a currently active thread then don't execute instructions,
  35. // instead advance to the next event and try to yield to the next thread
  36. if (Kernel::GetCurrentThread() == nullptr) {
  37. LOG_TRACE(Core_ARM11, "Idling");
  38. CoreTiming::Idle();
  39. CoreTiming::Advance();
  40. HLE::Reschedule(__func__);
  41. } else {
  42. g_app_core->Run(tight_loop);
  43. }
  44. HW::Update();
  45. if (HLE::IsReschedulePending()) {
  46. Kernel::Reschedule();
  47. }
  48. }
  49. /// Step the CPU one instruction
  50. void SingleStep() {
  51. RunLoop(1);
  52. }
  53. /// Halt the core
  54. void Halt(const char* msg) {
  55. // TODO(ShizZy): ImplementMe
  56. }
  57. /// Kill the core
  58. void Stop() {
  59. // TODO(ShizZy): ImplementMe
  60. }
  61. /// Initialize the core
  62. void Init() {
  63. if (Settings::values.use_cpu_jit) {
  64. g_sys_core = std::make_unique<ARM_Dynarmic>(USER32MODE);
  65. g_app_core = std::make_unique<ARM_Dynarmic>(USER32MODE);
  66. } else {
  67. g_sys_core = std::make_unique<ARM_DynCom>(USER32MODE);
  68. g_app_core = std::make_unique<ARM_DynCom>(USER32MODE);
  69. }
  70. LOG_DEBUG(Core, "Initialized OK");
  71. }
  72. void Shutdown() {
  73. g_app_core.reset();
  74. g_sys_core.reset();
  75. LOG_DEBUG(Core, "Shutdown OK");
  76. }
  77. } // namespace