1 /* 2 * SPDX-License-Identifier: BSD-3-Clause 3 * Copyright 2015 Intel Corporation. 4 * Copyright 2012 Hasan Alayli <[email protected]> 5 */ 6 7 #if defined(__x86_64__) 8 __asm__ ( 9 ".text\n" 10 ".p2align 4,,15\n" 11 ".globl ctx_switch\n" 12 ".globl _ctx_switch\n" 13 "ctx_switch:\n" 14 "_ctx_switch:\n" 15 " movq %rsp, 0(%rsi) # save stack_pointer\n" 16 " movq %rbp, 8(%rsi) # save frame_pointer\n" 17 " movq (%rsp), %rax # save insn_pointer\n" 18 " movq %rax, 16(%rsi)\n" 19 " movq %rbx, 24(%rsi)\n # save rbx,r12-r15\n" 20 " movq 24(%rdi), %rbx\n" 21 " movq %r15, 56(%rsi)\n" 22 " movq %r14, 48(%rsi)\n" 23 " movq 48(%rdi), %r14\n" 24 " movq 56(%rdi), %r15\n" 25 " movq %r13, 40(%rsi)\n" 26 " movq %r12, 32(%rsi)\n" 27 " movq 32(%rdi), %r12\n" 28 " movq 40(%rdi), %r13\n" 29 " movq 0(%rdi), %rsp # restore stack_pointer\n" 30 " movq 16(%rdi), %rax # restore insn_pointer\n" 31 " movq 8(%rdi), %rbp # restore frame_pointer\n" 32 " movq %rax, (%rsp)\n" 33 " ret\n" 34 ); 35 #else 36 #pragma GCC error "__x86_64__ is not defined" 37 #endif 38