From 798b10ec690306e876224746ca52d678d2be078a Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 4 Nov 2023 18:07:13 +0200 Subject: [PATCH 1/3] Fix KTimer not properly triggering --- src/core/kernel/timers.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/kernel/timers.cpp b/src/core/kernel/timers.cpp index 1c18d9de9..4c2bf358c 100644 --- a/src/core/kernel/timers.cpp +++ b/src/core/kernel/timers.cpp @@ -51,6 +51,10 @@ void Kernel::signalTimer(Handle timerHandle, Timer* timer) { case ResetType::Pulse: Helpers::panic("Signalled pulsing timer"); break; } } + + if (timer->interval == 0) { + cancelTimer(timer); + } } void Kernel::svcCreateTimer() { @@ -70,8 +74,8 @@ void Kernel::svcCreateTimer() { void Kernel::svcSetTimer() { Handle handle = regs[0]; // TODO: Is this actually s64 or u64? 3DBrew says s64, but u64 makes more sense - const s64 initial = s64(u64(regs[1]) | (u64(regs[2]) << 32)); - const s64 interval = s64(u64(regs[3]) | (u64(regs[4]) << 32)); + const s64 initial = s64(u64(regs[1]) | (u64(regs[3]) << 32)); + const s64 interval = s64(u64(regs[2]) | (u64(regs[4]) << 32)); logSVC("SetTimer (handle = %X, initial delay = %llX, interval delay = %llX)\n", handle, initial, interval); KernelObject* object = getObject(handle, KernelObjectType::Timer); From 708b10c194e1056e7c342d61974faddf567f833a Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 4 Nov 2023 18:26:20 +0200 Subject: [PATCH 2/3] Fix svcSetTimer ABI maybe...? --- src/core/kernel/timers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/kernel/timers.cpp b/src/core/kernel/timers.cpp index 4c2bf358c..c6097ed77 100644 --- a/src/core/kernel/timers.cpp +++ b/src/core/kernel/timers.cpp @@ -74,8 +74,8 @@ void Kernel::svcCreateTimer() { void Kernel::svcSetTimer() { Handle handle = regs[0]; // TODO: Is this actually s64 or u64? 3DBrew says s64, but u64 makes more sense - const s64 initial = s64(u64(regs[1]) | (u64(regs[3]) << 32)); - const s64 interval = s64(u64(regs[2]) | (u64(regs[4]) << 32)); + const s64 initial = s64(u64(regs[2]) | (u64(regs[3]) << 32)); + const s64 interval = s64(u64(regs[1]) | (u64(regs[4]) << 32)); logSVC("SetTimer (handle = %X, initial delay = %llX, interval delay = %llX)\n", handle, initial, interval); KernelObject* object = getObject(handle, KernelObjectType::Timer); From 1f7fc2274ac5b3a985f1bf7f59ca21f27d67a53a Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 4 Nov 2023 18:28:28 +0200 Subject: [PATCH 3/3] Add vector of timer handles --- include/kernel/kernel.hpp | 1 + src/core/kernel/kernel.cpp | 1 + src/core/kernel/timers.cpp | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/kernel/kernel.hpp b/include/kernel/kernel.hpp index dc821a685..30f1310e7 100644 --- a/include/kernel/kernel.hpp +++ b/include/kernel/kernel.hpp @@ -36,6 +36,7 @@ class Kernel { std::vector objects; std::vector portHandles; std::vector mutexHandles; + std::vector timerHandles; // Thread indices, sorted by priority std::vector threadIndices; diff --git a/src/core/kernel/kernel.cpp b/src/core/kernel/kernel.cpp index b21c4c584..cd691b485 100644 --- a/src/core/kernel/kernel.cpp +++ b/src/core/kernel/kernel.cpp @@ -148,6 +148,7 @@ void Kernel::reset() { } objects.clear(); mutexHandles.clear(); + timerHandles.clear(); portHandles.clear(); threadIndices.clear(); serviceManager.reset(); diff --git a/src/core/kernel/timers.cpp b/src/core/kernel/timers.cpp index c6097ed77..a9c952925 100644 --- a/src/core/kernel/timers.cpp +++ b/src/core/kernel/timers.cpp @@ -9,7 +9,7 @@ Handle Kernel::makeTimer(ResetType type) { Helpers::panic("Created pulse timer"); } - // timerHandles.push_back(ret); + timerHandles.push_back(ret); return ret; }