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