1 #ifndef COROUTINE_AMD64_CONTEXT_H
2 #define COROUTINE_AMD64_CONTEXT_H 1
18 #define COROUTINE __attribute__((noreturn)) void
20 enum {COROUTINE_REGISTERS = 6};
30 static inline void coroutine_initialize_main(
struct coroutine_context * context) {
31 context->stack_pointer = NULL;
34 static inline void coroutine_initialize(
36 coroutine_start start,
40 assert(start && stack && size >= 1024);
43 char * top = (
char*)stack + size;
44 context->stack_pointer = (
void**)((uintptr_t)top & ~0xF);
46 *--context->stack_pointer = NULL;
47 *--context->stack_pointer = (
void*)start;
49 context->stack_pointer -= COROUTINE_REGISTERS;
50 memset(context->stack_pointer, 0,
sizeof(
void*) * COROUTINE_REGISTERS);
57 context->stack_pointer = NULL;