added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / x86_64-pc / exec / stackswap.S
blob7b6d978e77d2d546624889b3afd4837aa7176394
1 #include <aros/x86_64/asm.h>
2 #include <aros/config.h>
4                 .text
5                 .align  16
6                 .globl  AROS_SLIB_ENTRY(StackSwap, Exec)
7                 .type   AROS_SLIB_ENTRY(StackSwap, Exec), @function
8                 
9 AROS_SLIB_ENTRY(StackSwap, Exec):
10                 /* struct StackSwap is %rdi */
11                 /* SysBase is %rsi */
12                 
13                 pushq   %rbx
14                 
15                 /* StackSwap -> %rbx */
16                 movq    %rdi, %rbx
17                 
18                 /* Disable interrupts */
19                 pushq   %rsi
20                 call    *Disable(%rsi)
21                 popq    %rsi
23                 movq    ThisTask(%rsi), %rax
25                 /* Exchange tc_SPLower */
26                 movq    tc_SPLower(%rax), %rcx
27                 xchgq   %rcx, stk_Lower(%rbx)
28                 movq    %rcx, tc_SPLower(%rax)
30                 /* Exchange tc_SPUpper */
31                 movq    tc_SPUpper(%rax), %rcx
32                 xchgq   %rcx, stk_Upper(%rbx)
33                 movq    %rcx, tc_SPUpper(%rax)
35                 /* StackSwap -> %rdi */
36                 movq    %rbx, %rdi
37                 popq    %rbx
38                 
39                 /* Get the return address */
40                 popq    %rax
41                 
42                 /* Restore *NEW* stack pointer */
43                 xchgq   %rsp, stk_Pointer(%rdi)
44                 
45                 pushq   %rax
46                 call    *Enable(%rsi)
47                 popq    %rax
48                 
49                 jmpq    *%rax
50