1 #ifndef COROUTINE_WIN64_CONTEXT_H
2 #define COROUTINE_WIN64_CONTEXT_H 1
18 #define COROUTINE __declspec(noreturn) void
21 COROUTINE_REGISTERS = 8,
22 COROUTINE_XMM_REGISTERS = 1+10*2,
33 void coroutine_trampoline();
35 static inline void coroutine_initialize_main(
struct coroutine_context * context) {
36 context->stack_pointer = NULL;
39 static inline void coroutine_initialize(
41 coroutine_start start,
45 assert(start && stack && size >= 1024);
48 char * top = (
char*)stack + size;
49 context->stack_pointer = (
void**)((uintptr_t)top & ~0xF);
52 context->stack_pointer -= 4;
55 *--context->stack_pointer = 0;
56 *--context->stack_pointer = (
void*)start;
57 *--context->stack_pointer = (
void*)coroutine_trampoline;
61 *--context->stack_pointer = (
void*)top;
62 *--context->stack_pointer = (
void*)stack;
64 context->stack_pointer -= COROUTINE_REGISTERS;
65 memset(context->stack_pointer, 0,
sizeof(
void*) * COROUTINE_REGISTERS);
66 memset(context->stack_pointer - COROUTINE_XMM_REGISTERS, 0,
sizeof(
void*) * COROUTINE_XMM_REGISTERS);