We can now change threads

This commit is contained in:
wheremyfoodat 2022-09-20 15:30:41 +03:00
parent 1678cd6172
commit 9b95bd87f1
10 changed files with 159 additions and 14 deletions

View file

@ -6,6 +6,7 @@
#include "kernel_types.hpp"
#include "helpers.hpp"
#include "memory.hpp"
#include "resource_limits.hpp"
#include "services/service_manager.hpp"
class CPU;
@ -17,12 +18,13 @@ class Kernel {
// The handle number for the next kernel object to be created
u32 handleCounter;
std::array<Thread, appResourceLimits.maxThreads> threads;
std::vector<KernelObject> objects;
std::vector<Handle> portHandles;
Handle currentProcess;
Handle currentThread;
Handle mainThread;
int currentThreadIndex;
Handle srvHandle; // Handle for the special service manager port "srv:"
u32 arbiterCount;
u32 threadCount;
@ -64,6 +66,8 @@ class Kernel {
Handle makeSession(Handle port);
Handle makeThread(u32 entrypoint, u32 initialSP, u32 priority, u32 id, ThreadStatus status = ThreadStatus::Dormant);
void switchThread(int newThreadIndex);
std::optional<Handle> getPortHandle(const char* name);
void deleteObjectData(KernelObject& object);

View file

@ -1,4 +1,5 @@
#pragma once
#include <array>
#include <cstring>
#include "handles.hpp"
#include "helpers.hpp"
@ -101,11 +102,15 @@ struct Thread {
u32 entrypoint; // Initial r15 value
u32 priority;
u32 processorID;
ThreadStatus status;
Handle handle; // OS handle for this thread
Thread(u32 initialSP, u32 entrypoint, u32 priority, u32 processorID, ThreadStatus status = ThreadStatus::Dormant)
: initialSP(initialSP), entrypoint(entrypoint), priority(priority), processorID(processorID), status(status) {}
// Thread context used for switching between threads
std::array<u32, 16> gprs;
std::array<u32, 32> fprs; // Stored as u32 because dynarmic does it
u32 cpsr;
u32 fpscr;
u32 tlsBase; // Base pointer for thread-local storage
};
static const char* kernelObjectTypeToString(KernelObjectType t) {

View file

@ -1,5 +1,5 @@
#pragma once
#include "kernel_types.hpp"
#include "helpers.hpp"
// Values and resource limit structure taken from Citra