Debian Codegraph @

rpython/translator/c/src/stacklet/switch_x86_64_gcc.h

raw symbols SCIP
1
2 static void *slp_switch(void *(*save_state)(void*, void*),
3 void *(*restore_state)(void*, void*),
4 void *extra)
5 {
6 void *result, *garbage1, *garbage2;
7 __asm__ volatile (
8 "pushq %%rbp\n"
9 "pushq %%rbx\n" /* push the registers specified as caller-save */
10 "pushq %%r12\n"
11 "pushq %%r13\n"
12 "pushq %%r14\n"
13 "movq %%rsp, %%rbp\n"
14 "andq $-16, %%rsp\n" /* <= align the stack here... */
15 "pushq %%r15\n"
16 "pushq %%rbp\n" /* ...so that rsp is now a multiple of 16 */
17
18 "movq %%rax, %%r12\n" /* save 'restore_state' for later */
19 "movq %%rsi, %%r13\n" /* save 'extra' for later */
20
21 /* arg 2: extra (already in rsi) */
22 "movq %%rsp, %%rdi\n" /* arg 1: current (old) stack pointer */
23 "call *%%rcx\n" /* call save_state() */
24
25 "testq %%rax, %%rax\n" /* skip the rest if the return value is null */
26 "jz 0f\n"
27
28 "movq %%rax, %%rsp\n" /* change the stack pointer */
29
30 /* From now on, the stack pointer is modified, but the content of the
31 stack is not restored yet. It contains only garbage here. */
32
33 "movq %%r13, %%rsi\n" /* arg 2: extra */
34 "movq %%rax, %%rdi\n" /* arg 1: current (new) stack pointer */
35 "call *%%r12\n" /* call restore_state() */
36
37 /* The stack's content is now restored. */
38
39 "0:\n"
40 "popq %%rbp\n"
41 "popq %%r15\n"
42 "movq %%rbp, %%rsp\n"
43 "popq %%r14\n"
44 "popq %%r13\n"
45 "popq %%r12\n"
46 "popq %%rbx\n"
47 "popq %%rbp\n"
48
49 : "=a"(result), /* output variables */
50 "=c"(garbage1),
51 "=S"(garbage2)
52 : "a"(restore_state), /* input variables */
53 "c"(save_state),
54 "S"(extra)
55 : "memory", "rdx", "rdi", "r8", "r9", "r10", "r11",
56 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
57 "xmm8", "xmm9", "xmm10","xmm11","xmm12","xmm13","xmm14","xmm15"
58 );
59 return result;
60 }