Improve thread code

This commit is contained in:
2024-06-14 19:56:44 +02:00
parent 5540d80d34
commit 4e95d7b6b2
5 changed files with 36 additions and 36 deletions

View File

@@ -1,52 +0,0 @@
#pragma once
#include "syscalls.hpp"
namespace JabyEngine {
struct Thread {
static uintptr_t get_pic() {
return table_of_tables.processes->current_tcb->epc;
}
static constexpr uint32_t idx_from_handle(SysCall::ThreadHandle thread) {
return thread & 0xFFFF;
}
static void prepare_next(SysCall::ThreadHandle thread) {
table_of_tables.processes->current_tcb = &table_of_tables.threads[idx_from_handle(thread)];
}
static void execute_next() {
SysCall::ReturnFromException();
}
static void set_kernel_mode_for(SysCall::ThreadHandle handle) {
table_of_tables.threads[idx_from_handle(handle)].sr = 0x0;
}
static void set_user_mode_for(SysCall::ThreadHandle handle) {
table_of_tables.threads[idx_from_handle(handle)].sr = 0x40000404;
}
};
struct MainThread {
static uintptr_t get_pic() {
return table_of_tables.threads[0].epc;
}
static void prepare_if_main(SysCall::ThreadHandle handle) {
if(table_of_tables.processes->current_tcb == &table_of_tables.threads[0]) {
Thread::prepare_next(handle);
}
}
static void prepare_restore() {
Thread::prepare_next(0);
}
static void restore() {
SysCall::EnterCriticalSection();
MainThread::prepare_restore();
Thread::execute_next();
}
};
}