From fc83627b14536d0b13b2dd751d09cecbea9db378 Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 29 Sep 2020 02:06:41 +0200 Subject: move thread init into arch/ --- lib/thread.cc | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) (limited to 'lib/thread.cc') diff --git a/lib/thread.cc b/lib/thread.cc index ec7fd64..e25fa5a 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -2,11 +2,10 @@ #include "thread.h" -#include "arch/x86_64/asm.h" +#include "arch/x86_64/api.h" #include "executor.h" #include -#include // uintN_t #include #include #include // mmap @@ -35,33 +34,9 @@ namespace nMatcha { // Adjust stack pointer, as stack grows downwards. mStackPtr = static_cast(stack) + STACK_SIZE; - { - static_assert(sizeof(uint64_t) == sizeof(std::uintptr_t), "Pointer must be 64bit!"); - // Setup initial stack frame which will be popped when yielding - // first time into the thread. - // Basic idea is to yield into Thread::entry() function which will - // then call the user function. - - uint64_t* stack = static_cast(mStackPtr); - // Arguments for `thread_create`. - *(--stack) = reinterpret_cast(this); - *(--stack) = reinterpret_cast(Thread::entry); - - // Yield epilogue. - *(--stack) = reinterpret_cast(thread_create); // Return address - *(--stack) = static_cast(0); // rbp - - // Callee saved registers. - *(--stack) = static_cast(0); // rbx - *(--stack) = reinterpret_cast(static_cast(mStackPtr) - 4); // rbp - *(--stack) = static_cast(0); // r12 - *(--stack) = static_cast(0); // r13 - *(--stack) = static_cast(0); // r14 - *(--stack) = static_cast(0); // r15 - - mStackPtr = static_cast(stack); - } + // Arch specific stack initialization. + mStackPtr = init_stack(mStackPtr, Thread::entry, static_cast(this)); } void Thread::entry(void* obj) { -- cgit v1.2.3