Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better KTimer implementation #338

Merged
merged 3 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/kernel/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Kernel {
std::vector<KernelObject> objects;
std::vector<Handle> portHandles;
std::vector<Handle> mutexHandles;
std::vector<Handle> timerHandles;

// Thread indices, sorted by priority
std::vector<int> threadIndices;
Expand Down
1 change: 1 addition & 0 deletions src/core/kernel/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void Kernel::reset() {
}
objects.clear();
mutexHandles.clear();
timerHandles.clear();
portHandles.clear();
threadIndices.clear();
serviceManager.reset();
Expand Down
10 changes: 7 additions & 3 deletions src/core/kernel/timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Handle Kernel::makeTimer(ResetType type) {
Helpers::panic("Created pulse timer");
}

// timerHandles.push_back(ret);
timerHandles.push_back(ret);
return ret;
}

Expand Down Expand Up @@ -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() {
Expand All @@ -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[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);
Expand Down
Loading