[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 04/23] plat: Hardware context - Add trampoline for starting threads
Before starting threads, we consider they were "interrupted" because we use the hardware support in order to enable interrupts atomically on activating the thread. An interrupted thread may be preempted and therefore we need to save its continuation point - the address that will be first executed when it will be switched back on. Thus we need such a continuation point for starting the thread as well. For this purpose this patch introduces the trampoline which will be the first continuation point of newly created threads. We recycle the padding field of the __regs structure for saving continuations from now on. Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx> --- plat/common/x86/hw_ctx.c | 11 +++++++++++ plat/common/x86/thread_start.S | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/plat/common/x86/hw_ctx.c b/plat/common/x86/hw_ctx.c index e82beb5f..778e546d 100644 --- a/plat/common/x86/hw_ctx.c +++ b/plat/common/x86/hw_ctx.c @@ -48,6 +48,7 @@ static void hw_ctx_start(void *ctx) __noreturn; static void hw_ctx_switch(void *prevctx, void *nextctx); extern void asm_thread_starter(void); +extern void asm_thread_starter_trampoline(void); /* Architecture specific setup of thread creation */ void hw_ctx_init(void *ctx, unsigned long sp) @@ -63,6 +64,16 @@ void hw_ctx_init(void *ctx, unsigned long sp) hw_ctx->regs.eflags = X86_EFLAGS_IF; hw_ctx->regs.rsp = sp; hw_ctx->regs.ss = GDT_DESC_SELECTOR(DATA); + + /* + * We start by setting interrupted on true because this thread + * hasn't yield yet and we'll be using the hardware support to + * start it with enabled interrupts + */ + hw_ctx->interrupted = true; + + /* First continuation is a trampoline to initial thread IP */ + hw_ctx->regs.pad = (unsigned long) asm_thread_starter_trampoline; } extern void asm_ctx_start(unsigned long sp, unsigned long ip) __noreturn; diff --git a/plat/common/x86/thread_start.S b/plat/common/x86/thread_start.S index 57d957a6..105691ee 100644 --- a/plat/common/x86/thread_start.S +++ b/plat/common/x86/thread_start.S @@ -26,12 +26,25 @@ */ /* Taken from Mini-OS arch/x86/x86_64.S */ +#include <uk/arch/limits.h> +#include <x86/regs.h> #include <sw_ctx.h> #define ENTRY(X) .globl X ; X : #include "thread_macros.S" +ENTRY(asm_thread_starter_trampoline) + /* Load current thread */ + and $STACK_MASK_TOP, %rsp + mov (%rsp), %rsp + /* Load current context */ + mov OFFSETOF_UKTHREAD_REGS(%rsp), %rsp + mov (%rsp), %rsp + /* Load exception stack */ + add $OFFSETOF_REGS_RIP, %rsp + iretq + ENTRY(asm_thread_starter) popq %rdi popq %rbx -- 2.20.1 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |