From 533a9e57de8cb74594499f625810ad812359d3fb Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 29 Sep 2020 04:31:51 +0200 Subject: added basic arm64 support --- lib/arch/arm64/init_stack.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/arch/arm64/init_stack.cc (limited to 'lib/arch/arm64/init_stack.cc') diff --git a/lib/arch/arm64/init_stack.cc b/lib/arch/arm64/init_stack.cc new file mode 100644 index 0000000..b28d957 --- /dev/null +++ b/lib/arch/arm64/init_stack.cc @@ -0,0 +1,37 @@ +#include +#include // uintN_t + +extern "C" void thread_create(); + +void* init_stack(void* stack_ptr, void (*entry)(void*), void* ctx) { + 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(stack_ptr); + // Arguments for `thread_create`. + *(--stack) = reinterpret_cast(ctx); + *(--stack) = reinterpret_cast(entry); + + // Yield epilogue. + *(--stack) = reinterpret_cast(thread_create); // x30 (LR) + *(--stack) = static_cast(0); // x29 (FP) + + // Callee saved registers. + *(--stack) = static_cast(0); // x28 + *(--stack) = static_cast(0); // x27 + *(--stack) = static_cast(0); // x26 + *(--stack) = static_cast(0); // x25 + *(--stack) = static_cast(0); // x24 + *(--stack) = static_cast(0); // x23 + *(--stack) = static_cast(0); // x22 + *(--stack) = static_cast(0); // x21 + *(--stack) = static_cast(0); // x20 + *(--stack) = static_cast(0); // x19 + + assert((reinterpret_cast(stack) & 0xf) == 0); // 16byte aligned + return static_cast(stack); +} -- cgit v1.2.3