first app load

This commit is contained in:
2026-02-17 11:36:26 +01:00
parent f0bda5f466
commit 6412d8f104
4 changed files with 18 additions and 24 deletions

View File

@@ -9,6 +9,7 @@
#include "debug/output.h"
static int idCounter = 1; // counter for task IDs
extern four_lvl_paging_t paging_tree;
void Thread::kickoff(uintptr_t param1, uintptr_t param2, uintptr_t param3) {
Thread *thread = reinterpret_cast<Thread *>(param1);
@@ -27,30 +28,33 @@ void Thread::kickoff(uintptr_t param1, uintptr_t param2, uintptr_t param3) {
((void(*)())thread->start)();
}
extern four_lvl_paging_t paging_tree;
void Thread::load_paging(){
paging_tree.l2.entries[32] = {
.present = 1,
.write = 1,
.user = 1,
.address = (uintptr_t)(this->subtable) >> 12
};
load_cr3((void*)&paging_tree.l4);
}
Thread::Thread (bool kernel, void * start): queue_link(nullptr), isKernel(kernel), start(start), id(idCounter++), kill_flag(false){
StackPointer.isr = reinterpret_cast<void *>((uintptr_t)PageFrameAllocator::alloc(true)+STACK_SIZE);//(reserved_stack_space_isr + STACK_SIZE);
StackPointer.user = reinterpret_cast<void *>((uintptr_t)PageFrameAllocator::alloc(false)+STACK_SIZE);
subtable = (pagetable_t*) PageFrameAllocator::alloc(true);
subtable->entries[0] = {
.present = 1,
.user = 1,
.address = (uintptr_t)start >> 12
};
subtable->entries[1] = {
.present = 1,
.write = 1,
.user = 1,
.address = (uintptr_t)StackPointer.user >> 12
};
paging_tree.l2.entries[32] = {
.present = 1,
.user = 1,
.address = (uintptr_t)subtable >> 12
};
//map_pageframe(&paging_tree, (uintptr_t)StackPointer.user, 0x4001000);
prepareContext(StackPointer.isr, context, kickoff, reinterpret_cast<uintptr_t>(this), 0, 0);
@@ -63,13 +67,7 @@ Thread::Thread() : Thread(false, 0) {}
//}
void Thread::resume(Thread *next) {
assert(next != nullptr && "Pointer to next Thread must not be nullptr!");
paging_tree.l2.entries[32] = {
.present = 1,
.user = 1,
.address = (uintptr_t)&next->subtable>>12
};
load_cr3((void*)&paging_tree.l4);
load_paging();
context_switch(&next->context, &context);
}
@@ -84,12 +82,7 @@ void* Thread::operator new(size_t sz) noexcept
void Thread::go() {
paging_tree.l2.entries[32] = {
.present = 1,
.user = 1,
.address = (uintptr_t)&subtable>>12
};
load_cr3((void*)&paging_tree.l4);
load_paging();
context_launch(&context);
}