1 #include <aros/x86_64/asm.h>
2 #include <aros/config.h>
6 .globl AROS_SLIB_ENTRY(StackSwap, Exec, 122)
7 .type AROS_SLIB_ENTRY(StackSwap, Exec, 122), @function
9 AROS_SLIB_ENTRY(StackSwap, Exec, 122):
10 /* struct StackSwap is %rdi */
15 /* StackSwap -> %rbx */
18 /* Disable interrupts */
20 movq %rsi, %rdi /* Put SysBase into rdi (first argument) */
24 movq ThisTask(%rsi), %rax
26 /* Exchange tc_SPLower */
27 movq tc_SPLower(%rax), %rcx
28 xchgq %rcx, stk_Lower(%rbx)
29 movq %rcx, tc_SPLower(%rax)
31 /* Exchange tc_SPUpper */
32 movq tc_SPUpper(%rax), %rcx
33 xchgq %rcx, stk_Upper(%rbx)
34 movq %rcx, tc_SPUpper(%rax)
36 movb tc_Flags(%rax), %cl
37 test $TF_STACKCHK, %cl
40 /* Fill [stk_Lower .. stk_Pointer - 16] with 0xE1 */
42 /* Destination register = %rdi = NEW SPLower.
43 Which was already swapped above, so to be found
44 in task->tc_SPLower */
45 movq tc_SPLower(%rax), %rdi
47 /* %rcx = count register = NEW SP register - NEW SP_Lower - 16 */
48 movq stk_Pointer(%rbx), %rcx
52 /* byte value to store */
55 /* direction to store: forward */
58 /* do the store operation: put %rcx times %al into memory starting at %rdi. */
63 /* StackSwap -> %rdi */
67 /* Get the return address */
70 /* Restore *NEW* stack pointer */
71 xchgq %rsp, stk_Pointer(%rdi)