add ringswitch stuff
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// vim: set noet ts=4 sw=4:
|
||||
|
||||
#include "thread.h"
|
||||
#include "../arch/core_ring.h"
|
||||
|
||||
#include "../debug/kernelpanic.h"
|
||||
#include "../interrupt/guard.h"
|
||||
@@ -17,11 +18,26 @@ void Thread::kickoff(uintptr_t param1, uintptr_t param2, uintptr_t param3) {
|
||||
// The core must have entered level 1/2 to cause a thread to be scheduled.
|
||||
Guard::leave();
|
||||
|
||||
thread->action();
|
||||
if(!thread->isKernel)
|
||||
Core::Ring::switchToUsermode(thread->StackPointer.user, reinterpret_cast<void*>(kickoffUsermode), thread);
|
||||
else
|
||||
if(thread->start == nullptr)
|
||||
thread->action();
|
||||
else
|
||||
((void(*)())thread->start)();
|
||||
|
||||
}
|
||||
|
||||
void Thread::kickoffUsermode (Thread *object){
|
||||
(void) object;
|
||||
if(object->start == nullptr)
|
||||
object->action();
|
||||
else
|
||||
((void(*)())object->start)();
|
||||
}
|
||||
|
||||
Thread::Thread (bool kernel, void * start): queue_link(nullptr), isKernel(kernel), start(start), id(idCounter++), kill_flag(false){
|
||||
void *tos = reinterpret_cast<void *>(reserved_stack_space_isr + STACK_SIZE);
|
||||
prepareContext(tos, context, kickoff, reinterpret_cast<uintptr_t>(this), 0, 0);
|
||||
}
|
||||
|
||||
Thread::Thread() : queue_link(nullptr), id(idCounter++), kill_flag(false) {
|
||||
|
||||
@@ -28,12 +28,15 @@ class Thread {
|
||||
/*! \brief pointer to the next element of the readylist
|
||||
*/
|
||||
Thread* queue_link;
|
||||
bool isKernel;
|
||||
void* start;
|
||||
|
||||
friend class Queue<Thread>;
|
||||
friend class Semaphore;
|
||||
/*! \brief Memory reserved for this threads stack
|
||||
*/
|
||||
alignas(16) char reserved_stack_space[STACK_SIZE];
|
||||
alignas(16) char reserved_stack_space_user[STACK_SIZE];
|
||||
alignas(16) char reserved_stack_space_isr[STACK_SIZE];
|
||||
|
||||
struct{
|
||||
void* user;
|
||||
@@ -80,6 +83,7 @@ class Thread {
|
||||
*
|
||||
*/
|
||||
explicit Thread();
|
||||
explicit Thread(bool kernel, void * start = nullptr);
|
||||
|
||||
/*! \brief Activates the first thread on this CPU.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user