work on page loading
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "thread.h"
|
||||
#include "../arch/core_ring.h"
|
||||
#include "../memory/pageframealloc.h"
|
||||
#include "../memory/pagetable.h"
|
||||
#include "../debug/kernelpanic.h"
|
||||
#include "../interrupt/guard.h"
|
||||
#include "debug/output.h"
|
||||
@@ -34,9 +35,32 @@ void Thread::kickoffUsermode (Thread *object){
|
||||
((void(*)())object->start)();
|
||||
}
|
||||
|
||||
extern four_lvl_paging_t paging_tree;
|
||||
Thread::Thread (bool kernel, void * start): queue_link(nullptr), isKernel(kernel), start(start), id(idCounter++), kill_flag(false){
|
||||
StackPointer.isr = reinterpret_cast<void *>(reserved_stack_space_isr + STACK_SIZE);
|
||||
StackPointer.user = reinterpret_cast<void *>(PageFrameAllocator::alloc(false) + 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,
|
||||
.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);
|
||||
}
|
||||
|
||||
@@ -48,6 +72,11 @@ 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
|
||||
};
|
||||
context_switch(&next->context, &context);
|
||||
}
|
||||
|
||||
@@ -61,6 +90,13 @@ void* Thread::operator new(size_t sz) noexcept
|
||||
}
|
||||
|
||||
|
||||
void Thread::go() { context_launch(&context); }
|
||||
void Thread::go() {
|
||||
paging_tree.l2.entries[32] = {
|
||||
.present = 1,
|
||||
.user = 1,
|
||||
.address = (uintptr_t)&subtable>>12
|
||||
};
|
||||
context_launch(&context);
|
||||
}
|
||||
|
||||
void Thread::action() { kernelpanic("Wrong entry / missing action in Thread"); }
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "../object/queue.h"
|
||||
#include "../types.h"
|
||||
|
||||
#include "../memory/pagetable.h"
|
||||
|
||||
/// Stack size for each thread
|
||||
constexpr uint32_t STACK_SIZE = 3072;
|
||||
|
||||
@@ -31,6 +33,8 @@ class Thread {
|
||||
bool isKernel;
|
||||
void* start;
|
||||
|
||||
pagetable_t* subtable;
|
||||
|
||||
friend class Queue<Thread>;
|
||||
friend class Semaphore;
|
||||
/*! \brief Memory reserved for this threads stack
|
||||
@@ -120,7 +124,7 @@ class Thread {
|
||||
* Derived classes are meant to override this method to provide
|
||||
* meaningful code to be run in this thread.
|
||||
*/
|
||||
virtual void action() = 0; // XXX: why is this not always pure virtual?
|
||||
virtual void action(); // XXX: why is this not always pure virtual?
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user