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 */
30 /* Exchange tc_SPLower */
31 movq tc_SPLower(%rax), %rcx
32 xchgq %rcx, stk_Lower(%rbx)
33 movq %rcx, tc_SPLower(%rax)
35 /* Exchange tc_SPUpper */
36 movq tc_SPUpper(%rax), %rcx
37 xchgq %rcx, stk_Upper(%rbx)
38 movq %rcx, tc_SPUpper(%rax)
40 movb tc_Flags(%rax), %cl
41 test $TF_STACKCHK, %cl
44 /* Fill [stk_Lower .. stk_Pointer - 16] with 0xE1 */
46 /* Destination register = %rdi = NEW SPLower.
47 Which was already swapped above, so to be found
48 in task->tc_SPLower */
49 movq tc_SPLower(%rax), %rdi
51 /* %rcx = count register = NEW SP register - NEW SP_Lower - 16 */
52 movq stk_Pointer(%rbx), %rcx
56 /* byte value to store */
59 /* direction to store: forward */
62 /* do the store operation: put %rcx times %al into memory starting at %rdi. */
67 /* StackSwap -> %rdi */
71 /* Get the return address */
74 /* Restore *NEW* stack pointer */
75 xchgq %rsp, stk_Pointer(%rdi)