core.cpp 2.1 KB

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