43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#pragma once
|
|
#include "syscalls.hpp"
|
|
|
|
namespace JabyEngine {
|
|
struct Thread {
|
|
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 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() {
|
|
MainThread::prepare_restore();
|
|
Thread::execute_next();
|
|
}
|
|
};
|
|
} |