core.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 "common/logging/log.h"
  6. #include "core/core.h"
  7. #include "core/core_timing.h"
  8. #include "core/mem_map.h"
  9. #include "core/settings.h"
  10. #include "core/arm/arm_interface.h"
  11. #include "core/arm/disassembler/arm_disasm.h"
  12. #include "core/arm/dyncom/arm_dyncom.h"
  13. #include "core/hle/hle.h"
  14. #include "core/hle/kernel/thread.h"
  15. #include "core/hw/hw.h"
  16. namespace Core {
  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::GetCurrentThread()->IsIdle()) {
  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. g_sys_core = new ARM_DynCom(USER32MODE);
  51. g_app_core = new ARM_DynCom(USER32MODE);
  52. // TODO: Whenever TLS is implemented, this should contain
  53. // the address of the 0x200-byte TLS
  54. g_app_core->SetCP15Register(CP15_THREAD_URO, Memory::KERNEL_MEMORY_VADDR);
  55. LOG_DEBUG(Core, "Initialized OK");
  56. return 0;
  57. }
  58. void Shutdown() {
  59. delete g_app_core;
  60. delete g_sys_core;
  61. LOG_DEBUG(Core, "Shutdown OK");
  62. }
  63. } // namespace