arch/x86_64: Relbase/altstack support for x86_64 from Jason McMullan
[AROS.git] / arch / x86_64-all / clib / longjmp.s
blob1a0f0df0628f4d5dd237d1b3d8668afaf63ae681
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: ANSI C function longjmp()
6 Lang: english
7 */
9 /******************************************************************************
11 NAME
12 #include <setjmp.h>
14 void longjmp (jmp_buf env, int val);
16 FUNCTION
17 Save the current context so that you can return to it later.
19 INPUTS
20 env - The context/environment to restore
21 val - This value is returned by setjmp() when you return to the
22 saved context. You cannot return 0. If val is 0, then
23 setjmp() returns with 1.
25 RESULT
26 This function doesn't return.
28 NOTES
30 EXAMPLE
31 jmp_buf env;
33 ... some code ...
35 if (!setjmp (env))
37 ... this code is executed after setjmp() returns ...
39 // This is no good example on how to use this function
40 // You should not do that
41 if (error)
42 longjmp (env, 5);
44 ... some code ...
46 else
48 ... this code is executed if you call longjmp(env) ...
51 BUGS
53 SEE ALSO
54 setjmp()
56 INTERNALS
58 HISTORY
60 ******************************************************************************/
62 #include "aros/x86_64/asm.h"
64 .text
65 _ALIGNMENT
66 .globl AROS_CDEFNAME(longjmp)
67 _FUNCTION(AROS_CDEFNAME(longjmp))
69 .set FirstArg, 8 /* Skip Return-Adress */
70 .set env, FirstArg
71 .set val, env+8
72 .set retaddr, 0
74 AROS_CDEFNAME(longjmp):
75 /* Make sure return value is not 0 */
76 cmp $0,%rsi
77 jne 1f
79 mov $1,%rsi
82 /* Get the location of the bottom of the stack */
83 mov SysBase(%rip),%rax
84 mov ThisTask(%rax),%rax
85 mov tc_SPLower(%rax),%rax
87 /* Restore top of altstack */
88 mov 128(%rdi),%rcx
89 mov %rcx,0(%rax)
91 mov %rdi, %rax
93 /* Restore stack pointer and all registers from env */
94 mov 120(%rax),%rsp /* Restore original stack */
96 mov 0(%rax),%rcx
97 mov %rcx,retaddr(%rsp) /* Restore return address */
99 push %rsi /* Save return value on new stack */
101 /* Restore all registers */
102 mov 8(%rax),%rbx /* %ebx */
103 mov 16(%rax),%rcx /* %ecx */
104 mov 24(%rax),%rdx /* %edx */
105 mov 32(%rax),%rsi /* %esi */
106 mov 40(%rax),%rdi /* %edi */
107 mov 48(%rax),%rbp /* %ebp */
108 mov 56(%rax),%r8
109 mov 64(%rax),%r9
110 mov 72(%rax),%r10
111 mov 80(%rax),%r11
112 mov 88(%rax),%r12
113 mov 96(%rax),%r13
114 mov 104(%rax),%r14
115 mov 112(%rax),%r15
117 pop %rax /* Fetch return value */