mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 20:49:12 +12:00
hle: Add proper type for result code
This should clean up all HLE errorcode in the codebase. I didn't removed Rust::Result as this should be a cleanup for another iteration.
This commit is contained in:
parent
c6f5d19983
commit
122b1b2727
73 changed files with 540 additions and 419 deletions
|
@ -47,7 +47,7 @@ void Kernel::sortThreads() {
|
|||
bool Kernel::canThreadRun(const Thread& t) {
|
||||
if (t.status == ThreadStatus::Ready) {
|
||||
return true;
|
||||
} else if (t.status == ThreadStatus::WaitSleep || t.status == ThreadStatus::WaitSync1
|
||||
} else if (t.status == ThreadStatus::WaitSleep || t.status == ThreadStatus::WaitSync1
|
||||
|| t.status == ThreadStatus::WaitSyncAny || t.status == ThreadStatus::WaitSyncAll) {
|
||||
const u64 elapsedTicks = cpu.getTicks() - t.sleepTick;
|
||||
|
||||
|
@ -81,7 +81,7 @@ std::optional<int> Kernel::getNextThread() {
|
|||
|
||||
void Kernel::switchToNextThread() {
|
||||
std::optional<int> newThreadIndex = getNextThread();
|
||||
|
||||
|
||||
if (!newThreadIndex.has_value()) {
|
||||
log("Kernel tried to switch to the next thread but none found. Switching to random thread\n");
|
||||
assert(aliveThreadCount != 0);
|
||||
|
@ -101,7 +101,7 @@ void Kernel::switchToNextThread() {
|
|||
// See if there;s a higher priority, ready thread and switch to that
|
||||
void Kernel::rescheduleThreads() {
|
||||
std::optional<int> newThreadIndex = getNextThread();
|
||||
|
||||
|
||||
if (newThreadIndex.has_value() && newThreadIndex.value() != currentThreadIndex) {
|
||||
threads[currentThreadIndex].status = ThreadStatus::Ready;
|
||||
switchThread(newThreadIndex.value());
|
||||
|
@ -273,12 +273,12 @@ int Kernel::wakeupOneThread(u64 waitlist, Handle handle) {
|
|||
switch (t.status) {
|
||||
case ThreadStatus::WaitSync1:
|
||||
t.status = ThreadStatus::Ready;
|
||||
t.gprs[0] = SVCResult::Success; // The thread did not timeout, so write success to r0
|
||||
t.gprs[0] = Result::Success; // The thread did not timeout, so write success to r0
|
||||
break;
|
||||
|
||||
case ThreadStatus::WaitSyncAny:
|
||||
t.status = ThreadStatus::Ready;
|
||||
t.gprs[0] = SVCResult::Success; // The thread did not timeout, so write success to r0
|
||||
t.gprs[0] = Result::Success; // The thread did not timeout, so write success to r0
|
||||
|
||||
// Get the index of the event in the object's waitlist, write it to r1
|
||||
for (size_t i = 0; i < t.waitList.size(); i++) {
|
||||
|
@ -308,12 +308,12 @@ void Kernel::wakeupAllThreads(u64 waitlist, Handle handle) {
|
|||
switch (t.status) {
|
||||
case ThreadStatus::WaitSync1:
|
||||
t.status = ThreadStatus::Ready;
|
||||
t.gprs[0] = SVCResult::Success; // The thread did not timeout, so write success to r0
|
||||
t.gprs[0] = Result::Success; // The thread did not timeout, so write success to r0
|
||||
break;
|
||||
|
||||
case ThreadStatus::WaitSyncAny:
|
||||
t.status = ThreadStatus::Ready;
|
||||
t.gprs[0] = SVCResult::Success; // The thread did not timeout, so write success to r0
|
||||
t.gprs[0] = Result::Success; // The thread did not timeout, so write success to r0
|
||||
|
||||
// Get the index of the event in the object's waitlist, write it to r1
|
||||
for (size_t i = 0; i < t.waitList.size(); i++) {
|
||||
|
@ -352,7 +352,7 @@ void Kernel::sleepThread(s64 ns) {
|
|||
}
|
||||
}
|
||||
|
||||
// Result CreateThread(s32 priority, ThreadFunc entrypoint, u32 arg, u32 stacktop, s32 threadPriority, s32 processorID)
|
||||
// Result CreateThread(s32 priority, ThreadFunc entrypoint, u32 arg, u32 stacktop, s32 threadPriority, s32 processorID)
|
||||
void Kernel::createThread() {
|
||||
u32 priority = regs[0];
|
||||
u32 entrypoint = regs[1];
|
||||
|
@ -365,11 +365,11 @@ void Kernel::createThread() {
|
|||
|
||||
if (priority > 0x3F) [[unlikely]] {
|
||||
Helpers::panic("Created thread with bad priority value %X", priority);
|
||||
regs[0] = SVCResult::BadThreadPriority;
|
||||
regs[0] = Result::OS::OutOfRange;
|
||||
return;
|
||||
}
|
||||
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
regs[1] = makeThread(entrypoint, initialSP, priority, id, arg, ThreadStatus::Ready);
|
||||
rescheduleThreads();
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ void Kernel::svcSleepThread() {
|
|||
const s64 ns = s64(u64(regs[0]) | (u64(regs[1]) << 32));
|
||||
//logSVC("SleepThread(ns = %lld)\n", ns);
|
||||
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
sleepThread(ns);
|
||||
}
|
||||
|
||||
|
@ -388,18 +388,18 @@ void Kernel::getThreadID() {
|
|||
logSVC("GetThreadID(handle = %X)\n", handle);
|
||||
|
||||
if (handle == KernelHandles::CurrentThread) {
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
regs[1] = currentThreadIndex;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto thread = getObject(handle, KernelObjectType::Thread);
|
||||
if (thread == nullptr) [[unlikely]] {
|
||||
regs[0] = SVCResult::BadHandle;
|
||||
regs[0] = Result::Kernel::InvalidHandle;
|
||||
return;
|
||||
}
|
||||
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
regs[1] = thread->getData<Thread>()->index;
|
||||
}
|
||||
|
||||
|
@ -408,14 +408,14 @@ void Kernel::getThreadPriority() {
|
|||
logSVC("GetThreadPriority (handle = %X)\n", handle);
|
||||
|
||||
if (handle == KernelHandles::CurrentThread) {
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
regs[1] = threads[currentThreadIndex].priority;
|
||||
} else {
|
||||
auto object = getObject(handle, KernelObjectType::Thread);
|
||||
if (object == nullptr) [[unlikely]] {
|
||||
regs[0] = SVCResult::BadHandle;
|
||||
regs[0] = Result::Kernel::InvalidHandle;
|
||||
} else {
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
regs[1] = object->getData<Thread>()->priority;
|
||||
}
|
||||
}
|
||||
|
@ -427,20 +427,20 @@ void Kernel::setThreadPriority() {
|
|||
logSVC("SetThreadPriority (handle = %X, priority = %X)\n", handle, priority);
|
||||
|
||||
if (priority > 0x3F) {
|
||||
regs[0] = SVCResult::BadThreadPriority;
|
||||
regs[0] = Result::OS::OutOfRange;
|
||||
return;
|
||||
}
|
||||
|
||||
if (handle == KernelHandles::CurrentThread) {
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
threads[currentThreadIndex].priority = priority;
|
||||
} else {
|
||||
auto object = getObject(handle, KernelObjectType::Thread);
|
||||
if (object == nullptr) [[unlikely]] {
|
||||
regs[0] = SVCResult::BadHandle;
|
||||
regs[0] = Result::Kernel::InvalidHandle;
|
||||
return;
|
||||
} else {
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
object->getData<Thread>()->priority = priority;
|
||||
}
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ void Kernel::svcCreateMutex() {
|
|||
bool locked = regs[1] != 0;
|
||||
logSVC("CreateMutex (locked = %s)\n", locked ? "yes" : "no");
|
||||
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
regs[1] = makeMutex(locked);
|
||||
}
|
||||
|
||||
|
@ -487,18 +487,18 @@ void Kernel::svcReleaseMutex() {
|
|||
const auto object = getObject(handle, KernelObjectType::Mutex);
|
||||
if (object == nullptr) [[unlikely]] {
|
||||
Helpers::panic("Tried to release non-existent mutex");
|
||||
regs[0] = SVCResult::BadHandle;
|
||||
regs[0] = Result::Kernel::InvalidHandle;
|
||||
return;
|
||||
}
|
||||
|
||||
Mutex* moo = object->getData<Mutex>();
|
||||
// A thread can't release a mutex it does not own
|
||||
if (!moo->locked || moo->ownerThread != currentThreadIndex) {
|
||||
regs[0] = SVCResult::InvalidMutexRelease;
|
||||
regs[0] = Result::Kernel::InvalidMutexRelease;
|
||||
return;
|
||||
}
|
||||
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
releaseMutex(moo);
|
||||
}
|
||||
|
||||
|
@ -513,7 +513,7 @@ void Kernel::svcCreateSemaphore() {
|
|||
if (initialCount < 0 || maxCount < 0)
|
||||
Helpers::panic("CreateSemaphore: Negative count value");
|
||||
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
regs[1] = makeSemaphore(initialCount, maxCount);
|
||||
}
|
||||
|
||||
|
@ -525,7 +525,7 @@ void Kernel::svcReleaseSemaphore() {
|
|||
const auto object = getObject(handle, KernelObjectType::Semaphore);
|
||||
if (object == nullptr) [[unlikely]] {
|
||||
Helpers::panic("Tried to release non-existent semaphore");
|
||||
regs[0] = SVCResult::BadHandle;
|
||||
regs[0] = Result::Kernel::InvalidHandle;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -537,7 +537,7 @@ void Kernel::svcReleaseSemaphore() {
|
|||
Helpers::panic("ReleaseSemaphore: Release count too high");
|
||||
|
||||
// Write success and old available count to r0 and r1 respectively
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[0] = Result::Success;
|
||||
regs[1] = s->availableCount;
|
||||
// Bump available count
|
||||
s->availableCount += releaseCount;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue