diff options
Diffstat (limited to 'coroutine/x86')
| -rw-r--r-- | coroutine/x86/Context.S | 9 | ||||
| -rw-r--r-- | coroutine/x86/Context.h | 13 |
2 files changed, 15 insertions, 7 deletions
diff --git a/coroutine/x86/Context.S b/coroutine/x86/Context.S index 001b699a30..b04e71aa1c 100644 --- a/coroutine/x86/Context.S +++ b/coroutine/x86/Context.S @@ -2,16 +2,15 @@ ## This file is part of the "Coroutine" project and released under the MIT License. ## ## Created by Samuel Williams on 3/11/2018. -## Copyright, 2018, by Samuel Williams. All rights reserved. +## Copyright, 2018, by Samuel Williams. ## #define TOKEN_PASTE(x,y) x##y -#define PREFIXED_SYMBOL(prefix,name) TOKEN_PASTE(prefix,name) .text -.globl PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer) -PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer): +.globl PREFIXED_SYMBOL(coroutine_transfer) +PREFIXED_SYMBOL(coroutine_transfer): # Save caller registers pushl %ebp @@ -37,6 +36,6 @@ PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer): # Jump to the address on the stack ret -#if defined(__linux__) && defined(__ELF__) +#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__ELF__) .section .note.GNU-stack,"",%progbits #endif diff --git a/coroutine/x86/Context.h b/coroutine/x86/Context.h index a783dd296f..f33b338eab 100644 --- a/coroutine/x86/Context.h +++ b/coroutine/x86/Context.h @@ -1,22 +1,29 @@ +#ifndef COROUTINE_X86_CONTEXT_H +#define COROUTINE_X86_CONTEXT_H 1 + /* * This file is part of the "Coroutine" project and released under the MIT License. * * Created by Samuel Williams on 3/11/2018. - * Copyright, 2018, by Samuel Williams. All rights reserved. + * Copyright, 2018, by Samuel Williams. */ #pragma once #include <assert.h> +#include <stddef.h> +#include <stdint.h> #include <string.h> #define COROUTINE __attribute__((noreturn, fastcall)) void +#define COROUTINE_LIMITED_ADDRESS_SPACE enum {COROUTINE_REGISTERS = 4}; struct coroutine_context { void **stack_pointer; + void *argument; }; typedef COROUTINE(* coroutine_start)(struct coroutine_context *from, struct coroutine_context *self) __attribute__((fastcall)); @@ -38,7 +45,7 @@ static inline void coroutine_initialize( context->stack_pointer = (void**)((uintptr_t)top & ~0xF); *--context->stack_pointer = NULL; - *--context->stack_pointer = (void*)start; + *--context->stack_pointer = (void*)(uintptr_t)start; context->stack_pointer -= COROUTINE_REGISTERS; memset(context->stack_pointer, 0, sizeof(void*) * COROUTINE_REGISTERS); @@ -50,3 +57,5 @@ static inline void coroutine_destroy(struct coroutine_context * context) { context->stack_pointer = NULL; } + +#endif /* COROUTINE_X86_CONTEXT_H */ |
