From f366a7723c403552bfe8428761ca78164182c889 Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Thu, 22 Oct 2020 15:40:54 +0200 Subject: [PATCH] scaffolding of a system for async --- include/gp/vfs/platforms/gcc-x86_64.hpp | 51 ++++++++++++++++++++++++- include/gp/vfs/process_data.hpp | 2 - include/gp/vfs/scheduler.hpp | 13 +++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/include/gp/vfs/platforms/gcc-x86_64.hpp b/include/gp/vfs/platforms/gcc-x86_64.hpp index 0c1103e..366c4cb 100644 --- a/include/gp/vfs/platforms/gcc-x86_64.hpp +++ b/include/gp/vfs/platforms/gcc-x86_64.hpp @@ -1,9 +1,58 @@ #pragma once +#include + +#define no_inline_decl(a) [[gnu::noinline]] a + namespace gp{ namespace specifics { struct platform_data { - + uint64_t rbx, r12, r13, r14, r15; + + void* stack_ptr; + void* base_ptr; + + void pull() __attribute__((always_inline)) + { + __asm__ __volatile__( + "movq %%rsp, %0\n" + "movq %%rbp, %1\n" + "movq %%rbx, %2\n" + "movq %%r12, %3\n" + "movq %%r13, %4\n" + "movq %%r14, %5\n" + "movq %%r15, %6\n" + : "=m"(stack_ptr) + , "=m"(base_ptr) + , "=m"(rbx) + , "=m"(r12) + , "=m"(r13) + , "=m"(r14) + , "=m"(r15)); + } + + void* push(void* location) __attribute__((always_inline)) + { + void* tmp = static_cast(stack_ptr) - sizeof(void*); + *static_cast(tmp) = location; + __asm__ __volatile__( + "movq %1, %%rsp\n" + "movq %2, %%rbp\n" + "movq %3, %%r12\n" + "movq %4, %%r13\n" + "movq %5, %%r14\n" + "movq %6, %%r15\n" + "popq %0\n" + : "+r"(location) + : "m"(tmp) + , "m"(base_ptr) + , "m"(r12) + , "m"(r13) + , "m"(r14) + , "m"(r15) + : "memory"); + return location; + } }; } } \ No newline at end of file diff --git a/include/gp/vfs/process_data.hpp b/include/gp/vfs/process_data.hpp index 2d04fb3..6db010c 100644 --- a/include/gp/vfs/process_data.hpp +++ b/include/gp/vfs/process_data.hpp @@ -19,8 +19,6 @@ namespace gp { struct process_data{ [[no_unique_address]] gp::specifics::platform_data specifics; - void* stack_ptr; - void* base_ptr; gp::function fn; gp::indexed_array fds; }; diff --git a/include/gp/vfs/scheduler.hpp b/include/gp/vfs/scheduler.hpp index 79b53fe..3cbe276 100644 --- a/include/gp/vfs/scheduler.hpp +++ b/include/gp/vfs/scheduler.hpp @@ -7,8 +7,21 @@ namespace gp{ class scheduler { gp::indexed_array processes; + gp::specifics::platform_data root; + size_t current; + + no_inline_decl( + void yield_impl(bool terminate) + ) { + + } + public: [[noreturn]] void run(); + + void yield(){ + yield_impl(false); + } }; } \ No newline at end of file