summaryrefslogtreecommitdiff
path: root/src/core/core_cpu.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-05-01 22:21:38 -0400
committerGravatar bunnei2018-05-10 19:34:46 -0400
commit559024593086d04e24a99a9f77490a3f97cf952d (patch)
tree0b9163a33ae973bd69cb3883bea1e91a3581f527 /src/core/core_cpu.cpp
parentStubs for QLaunch (#428) (diff)
downloadyuzu-559024593086d04e24a99a9f77490a3f97cf952d.tar.gz
yuzu-559024593086d04e24a99a9f77490a3f97cf952d.tar.xz
yuzu-559024593086d04e24a99a9f77490a3f97cf952d.zip
core: Move common CPU core things to its own class.
Diffstat (limited to 'src/core/core_cpu.cpp')
-rw-r--r--src/core/core_cpu.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/core/core_cpu.cpp b/src/core/core_cpu.cpp
new file mode 100644
index 000000000..81c0e212d
--- /dev/null
+++ b/src/core/core_cpu.cpp
@@ -0,0 +1,72 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "common/logging/log.h"
6#ifdef ARCHITECTURE_x86_64
7#include "core/arm/dynarmic/arm_dynarmic.h"
8#endif
9#include "core/arm/unicorn/arm_unicorn.h"
10#include "core/core_cpu.h"
11#include "core/core_timing.h"
12#include "core/hle/kernel/kernel.h"
13#include "core/hle/kernel/scheduler.h"
14#include "core/hle/kernel/thread.h"
15#include "core/settings.h"
16
17namespace Core {
18
19Cpu::Cpu() {
20 if (Settings::values.use_cpu_jit) {
21#ifdef ARCHITECTURE_x86_64
22 arm_interface = std::make_shared<ARM_Dynarmic>();
23#else
24 cpu_core = std::make_shared<ARM_Unicorn>();
25 NGLOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
26#endif
27 } else {
28 arm_interface = std::make_shared<ARM_Unicorn>();
29 }
30
31 scheduler = std::make_unique<Kernel::Scheduler>(arm_interface.get());
32}
33
34void Cpu::RunLoop(bool tight_loop) {
35 // If we don't have a currently active thread then don't execute instructions,
36 // instead advance to the next event and try to yield to the next thread
37 if (Kernel::GetCurrentThread() == nullptr) {
38 NGLOG_TRACE(Core, "Idling");
39 CoreTiming::Idle();
40 CoreTiming::Advance();
41 PrepareReschedule();
42 } else {
43 CoreTiming::Advance();
44 if (tight_loop) {
45 arm_interface->Run();
46 } else {
47 arm_interface->Step();
48 }
49 }
50
51 Reschedule();
52}
53
54void Cpu::SingleStep() {
55 return RunLoop(false);
56}
57
58void Cpu::PrepareReschedule() {
59 arm_interface->PrepareReschedule();
60 reschedule_pending = true;
61}
62
63void Cpu::Reschedule() {
64 if (!reschedule_pending) {
65 return;
66 }
67
68 reschedule_pending = false;
69 scheduler->Reschedule();
70}
71
72} // namespace Core