1#ifndef COROUTINE_WIN64_CONTEXT_H
2#define COROUTINE_WIN64_CONTEXT_H 1
18#define COROUTINE __declspec(noreturn) void
19#define COROUTINE_DECL void
22 COROUTINE_REGISTERS = 8,
23 COROUTINE_XMM_REGISTERS = 1+10*2,
34void coroutine_trampoline(
void);
37 context->stack_pointer = NULL;
40static inline void coroutine_initialize(
42 coroutine_start start,
46 assert(start && stack && size >= 1024);
49 char * top = (
char*)stack + size;
50 context->stack_pointer = (
void**)((uintptr_t)top & ~0xF);
53 context->stack_pointer -= 4;
56 *--context->stack_pointer = 0;
57 *--context->stack_pointer = (
void*)(uintptr_t)start;
58 *--context->stack_pointer = (
void*)coroutine_trampoline;
62 *--context->stack_pointer = (
void*)top;
63 *--context->stack_pointer = (
void*)stack;
65 context->stack_pointer -= COROUTINE_REGISTERS;
66 memset(context->stack_pointer, 0,
sizeof(
void*) * COROUTINE_REGISTERS);
67 memset(context->stack_pointer - COROUTINE_XMM_REGISTERS, 0,
sizeof(
void*) * COROUTINE_XMM_REGISTERS);