Improve thread code
This commit is contained in:
@@ -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();
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user