Implement svcGetCurrentProcessorNumber

This commit is contained in:
wheremyfoodat 2023-08-20 01:51:24 +03:00
parent fc2747a3d3
commit 6895a1d9d6
4 changed files with 48 additions and 5 deletions

View file

@ -106,7 +106,7 @@ void Kernel::rescheduleThreads() {
}
// Internal OS function to spawn a thread
Handle Kernel::makeThread(u32 entrypoint, u32 initialSP, u32 priority, s32 id, u32 arg, ThreadStatus status) {
Handle Kernel::makeThread(u32 entrypoint, u32 initialSP, u32 priority, ProcessorID id, u32 arg, ThreadStatus status) {
int index; // Index of the created thread in the threads array
if (threadCount < appResourceLimits.maxThreads) [[likely]] { // If we have not yet created over too many threads
@ -389,8 +389,14 @@ void Kernel::createThread() {
return;
}
if (id < -2 && id > 3) {
Helpers::warn("Invalid processor ID in CreateThread");
// TODO: This should return an error
id = static_cast<s32>(ProcessorID::AppCore);
}
regs[0] = Result::Success;
regs[1] = makeThread(entrypoint, initialSP, priority, id, arg, ThreadStatus::Ready);
regs[1] = makeThread(entrypoint, initialSP, priority, static_cast<ProcessorID>(id), arg, ThreadStatus::Ready);
requireReschedule();
}
@ -468,6 +474,31 @@ void Kernel::setThreadPriority() {
requireReschedule();
}
void Kernel::getCurrentProcessorNumber() {
const ProcessorID id = threads[currentThreadIndex].processorID;
s32 ret;
// Until we properly implement per-core schedulers, return whatever processor ID passed to svcCreateThread
switch (id) {
case ProcessorID::Default:
ret = static_cast<s32>(ProcessorID::AppCore);
break;
case ProcessorID::AllCPUs:
ret = static_cast<s32>(ProcessorID::AppCore);
Helpers::warn("GetCurrentProcessorNumber on thread created to run on all CPUs...?\n");
break;
default: ret = static_cast<s32>(id); break;
}
if (ret != static_cast<s32>(ProcessorID::AppCore)) {
Helpers::warn("GetCurrentProcessorNumber: Thread not running on appcore\n");
}
regs[0] = ret;
}
void Kernel::exitThread() {
logSVC("ExitThread\n");