2 * setjmpex/longjmp functions for Wine exception handling
4 * Copyright (c) 1999, 2010 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/exception.h"
26 #if defined(__GNUC__) || defined(__clang__)
30 __ASM_GLOBAL_FUNC( __wine_setjmpex
,
31 "movl 4(%esp),%ecx\n\t" /* jmp_buf */
32 "movl %ebp,0(%ecx)\n\t" /* jmp_buf.Ebp */
33 "movl %ebx,4(%ecx)\n\t" /* jmp_buf.Ebx */
34 "movl %edi,8(%ecx)\n\t" /* jmp_buf.Edi */
35 "movl %esi,12(%ecx)\n\t" /* jmp_buf.Esi */
36 "movl %esp,16(%ecx)\n\t" /* jmp_buf.Esp */
37 "movl 0(%esp),%eax\n\t"
38 "movl %eax,20(%ecx)\n\t" /* jmp_buf.Eip */
42 __ASM_GLOBAL_FUNC( __wine_longjmp
,
43 "movl 4(%esp),%ecx\n\t" /* jmp_buf */
44 "movl 8(%esp),%eax\n\t" /* retval */
45 "movl 0(%ecx),%ebp\n\t" /* jmp_buf.Ebp */
46 "movl 4(%ecx),%ebx\n\t" /* jmp_buf.Ebx */
47 "movl 8(%ecx),%edi\n\t" /* jmp_buf.Edi */
48 "movl 12(%ecx),%esi\n\t" /* jmp_buf.Esi */
49 "movl 16(%ecx),%esp\n\t" /* jmp_buf.Esp */
50 "addl $4,%esp\n\t" /* get rid of return address */
51 "jmp *20(%ecx)\n\t" /* jmp_buf.Eip */ )
53 #elif defined(__x86_64__)
55 __ASM_GLOBAL_FUNC( __wine_setjmpex
,
56 "movq %rdx,(%rcx)\n\t" /* jmp_buf->Frame */
57 "movq %rbx,0x8(%rcx)\n\t" /* jmp_buf->Rbx */
58 "leaq 0x8(%rsp),%rax\n\t"
59 "movq %rax,0x10(%rcx)\n\t" /* jmp_buf->Rsp */
60 "movq %rbp,0x18(%rcx)\n\t" /* jmp_buf->Rbp */
61 "movq %rsi,0x20(%rcx)\n\t" /* jmp_buf->Rsi */
62 "movq %rdi,0x28(%rcx)\n\t" /* jmp_buf->Rdi */
63 "movq %r12,0x30(%rcx)\n\t" /* jmp_buf->R12 */
64 "movq %r13,0x38(%rcx)\n\t" /* jmp_buf->R13 */
65 "movq %r14,0x40(%rcx)\n\t" /* jmp_buf->R14 */
66 "movq %r15,0x48(%rcx)\n\t" /* jmp_buf->R15 */
67 "movq (%rsp),%rax\n\t"
68 "movq %rax,0x50(%rcx)\n\t" /* jmp_buf->Rip */
69 "movdqa %xmm6,0x60(%rcx)\n\t" /* jmp_buf->Xmm6 */
70 "movdqa %xmm7,0x70(%rcx)\n\t" /* jmp_buf->Xmm7 */
71 "movdqa %xmm8,0x80(%rcx)\n\t" /* jmp_buf->Xmm8 */
72 "movdqa %xmm9,0x90(%rcx)\n\t" /* jmp_buf->Xmm9 */
73 "movdqa %xmm10,0xa0(%rcx)\n\t" /* jmp_buf->Xmm10 */
74 "movdqa %xmm11,0xb0(%rcx)\n\t" /* jmp_buf->Xmm11 */
75 "movdqa %xmm12,0xc0(%rcx)\n\t" /* jmp_buf->Xmm12 */
76 "movdqa %xmm13,0xd0(%rcx)\n\t" /* jmp_buf->Xmm13 */
77 "movdqa %xmm14,0xe0(%rcx)\n\t" /* jmp_buf->Xmm14 */
78 "movdqa %xmm15,0xf0(%rcx)\n\t" /* jmp_buf->Xmm15 */
82 __ASM_GLOBAL_FUNC( __wine_longjmp
,
83 "movq %rdx,%rax\n\t" /* retval */
84 "movq 0x8(%rcx),%rbx\n\t" /* jmp_buf->Rbx */
85 "movq 0x18(%rcx),%rbp\n\t" /* jmp_buf->Rbp */
86 "movq 0x20(%rcx),%rsi\n\t" /* jmp_buf->Rsi */
87 "movq 0x28(%rcx),%rdi\n\t" /* jmp_buf->Rdi */
88 "movq 0x30(%rcx),%r12\n\t" /* jmp_buf->R12 */
89 "movq 0x38(%rcx),%r13\n\t" /* jmp_buf->R13 */
90 "movq 0x40(%rcx),%r14\n\t" /* jmp_buf->R14 */
91 "movq 0x48(%rcx),%r15\n\t" /* jmp_buf->R15 */
92 "movdqa 0x60(%rcx),%xmm6\n\t" /* jmp_buf->Xmm6 */
93 "movdqa 0x70(%rcx),%xmm7\n\t" /* jmp_buf->Xmm7 */
94 "movdqa 0x80(%rcx),%xmm8\n\t" /* jmp_buf->Xmm8 */
95 "movdqa 0x90(%rcx),%xmm9\n\t" /* jmp_buf->Xmm9 */
96 "movdqa 0xa0(%rcx),%xmm10\n\t" /* jmp_buf->Xmm10 */
97 "movdqa 0xb0(%rcx),%xmm11\n\t" /* jmp_buf->Xmm11 */
98 "movdqa 0xc0(%rcx),%xmm12\n\t" /* jmp_buf->Xmm12 */
99 "movdqa 0xd0(%rcx),%xmm13\n\t" /* jmp_buf->Xmm13 */
100 "movdqa 0xe0(%rcx),%xmm14\n\t" /* jmp_buf->Xmm14 */
101 "movdqa 0xf0(%rcx),%xmm15\n\t" /* jmp_buf->Xmm15 */
102 "movq 0x50(%rcx),%rdx\n\t" /* jmp_buf->Rip */
103 "movq 0x10(%rcx),%rsp\n\t" /* jmp_buf->Rsp */
106 #elif defined(__arm__)
108 __ASM_GLOBAL_FUNC( __wine_setjmpex
,
109 "str r1, [r0]\n\t" /* jmp_buf->Frame */
110 "str r4, [r0, #0x4]\n\t" /* jmp_buf->R4 */
111 "str r5, [r0, #0x8]\n\t" /* jmp_buf->R5 */
112 "str r6, [r0, #0xc]\n\t" /* jmp_buf->R6 */
113 "str r7, [r0, #0x10]\n\t" /* jmp_buf->R7 */
114 "str r8, [r0, #0x14]\n\t" /* jmp_buf->R8 */
115 "str r9, [r0, #0x18]\n\t" /* jmp_buf->R9 */
116 "str r10, [r0, #0x1c]\n\t" /* jmp_buf->R10 */
117 "str r11, [r0, #0x20]\n\t" /* jmp_buf->R11 */
118 "str sp, [r0, #0x24]\n\t" /* jmp_buf->Sp */
119 "str lr, [r0, #0x28]\n\t" /* jmp_buf->Pc */
122 "str r2, [r0, #0x2c]\n\t" /* jmp_buf->Fpscr */
123 "vstr d8, [r0, #0x30]\n\t" /* jmp_buf->D[0] */
124 "vstr d9, [r0, #0x38]\n\t" /* jmp_buf->D[1] */
125 "vstr d10, [r0, #0x40]\n\t" /* jmp_buf->D[2] */
126 "vstr d11, [r0, #0x48]\n\t" /* jmp_buf->D[3] */
127 "vstr d12, [r0, #0x50]\n\t" /* jmp_buf->D[4] */
128 "vstr d13, [r0, #0x58]\n\t" /* jmp_buf->D[5] */
129 "vstr d14, [r0, #0x60]\n\t" /* jmp_buf->D[6] */
130 "vstr d15, [r0, #0x68]\n\t" /* jmp_buf->D[7] */
135 __ASM_GLOBAL_FUNC( __wine_longjmp
,
136 "ldr r4, [r0, #0x4]\n\t" /* jmp_buf->R4 */
137 "ldr r5, [r0, #0x8]\n\t" /* jmp_buf->R5 */
138 "ldr r6, [r0, #0xc]\n\t" /* jmp_buf->R6 */
139 "ldr r7, [r0, #0x10]\n\t" /* jmp_buf->R7 */
140 "ldr r8, [r0, #0x14]\n\t" /* jmp_buf->R8 */
141 "ldr r9, [r0, #0x18]\n\t" /* jmp_buf->R9 */
142 "ldr r10, [r0, #0x1c]\n\t" /* jmp_buf->R10 */
143 "ldr r11, [r0, #0x20]\n\t" /* jmp_buf->R11 */
144 "ldr sp, [r0, #0x24]\n\t" /* jmp_buf->Sp */
145 "ldr r2, [r0, #0x28]\n\t" /* jmp_buf->Pc */
147 "ldr r3, [r0, #0x2c]\n\t" /* jmp_buf->Fpscr */
149 "vldr d8, [r0, #0x30]\n\t" /* jmp_buf->D[0] */
150 "vldr d9, [r0, #0x38]\n\t" /* jmp_buf->D[1] */
151 "vldr d10, [r0, #0x40]\n\t" /* jmp_buf->D[2] */
152 "vldr d11, [r0, #0x48]\n\t" /* jmp_buf->D[3] */
153 "vldr d12, [r0, #0x50]\n\t" /* jmp_buf->D[4] */
154 "vldr d13, [r0, #0x58]\n\t" /* jmp_buf->D[5] */
155 "vldr d14, [r0, #0x60]\n\t" /* jmp_buf->D[6] */
156 "vldr d15, [r0, #0x68]\n\t" /* jmp_buf->D[7] */
158 "mov r0, r1\n\t" /* retval */
161 #elif defined(__aarch64__)
163 __ASM_GLOBAL_FUNC( __wine_setjmpex
,
164 "str x1, [x0]\n\t" /* jmp_buf->Frame */
165 "stp x19, x20, [x0, #0x10]\n\t" /* jmp_buf->X19, X20 */
166 "stp x21, x22, [x0, #0x20]\n\t" /* jmp_buf->X21, X22 */
167 "stp x23, x24, [x0, #0x30]\n\t" /* jmp_buf->X23, X24 */
168 "stp x25, x26, [x0, #0x40]\n\t" /* jmp_buf->X25, X26 */
169 "stp x27, x28, [x0, #0x50]\n\t" /* jmp_buf->X27, X28 */
170 "stp x29, x30, [x0, #0x60]\n\t" /* jmp_buf->Fp, Lr */
172 "str x2, [x0, #0x70]\n\t" /* jmp_buf->Sp */
174 "str w2, [x0, #0x78]\n\t" /* jmp_buf->Fpcr */
176 "str w2, [x0, #0x7c]\n\t" /* jmp_buf->Fpsr */
177 "stp d8, d9, [x0, #0x80]\n\t" /* jmp_buf->D[0-1] */
178 "stp d10, d11, [x0, #0x90]\n\t" /* jmp_buf->D[2-3] */
179 "stp d12, d13, [x0, #0xa0]\n\t" /* jmp_buf->D[4-5] */
180 "stp d14, d15, [x0, #0xb0]\n\t" /* jmp_buf->D[6-7] */
184 __ASM_GLOBAL_FUNC( __wine_longjmp
,
185 "ldp x19, x20, [x0, #0x10]\n\t" /* jmp_buf->X19, X20 */
186 "ldp x21, x22, [x0, #0x20]\n\t" /* jmp_buf->X21, X22 */
187 "ldp x23, x24, [x0, #0x30]\n\t" /* jmp_buf->X23, X24 */
188 "ldp x25, x26, [x0, #0x40]\n\t" /* jmp_buf->X25, X26 */
189 "ldp x27, x28, [x0, #0x50]\n\t" /* jmp_buf->X27, X28 */
190 "ldp x29, x30, [x0, #0x60]\n\t" /* jmp_buf->Fp, Lr */
191 "ldr x2, [x0, #0x70]\n\t" /* jmp_buf->Sp */
193 "ldr w2, [x0, #0x78]\n\t" /* jmp_buf->Fpcr */
195 "ldr w2, [x0, #0x7c]\n\t" /* jmp_buf->Fpsr */
197 "ldp d8, d9, [x0, #0x80]\n\t" /* jmp_buf->D[0-1] */
198 "ldp d10, d11, [x0, #0x90]\n\t" /* jmp_buf->D[2-3] */
199 "ldp d12, d13, [x0, #0xa0]\n\t" /* jmp_buf->D[4-5] */
200 "ldp d14, d15, [x0, #0xb0]\n\t" /* jmp_buf->D[6-7] */
201 "mov x0, x1\n\t" /* retval */
206 int __cdecl
__wine_setjmpex( __wine_jmp_buf
*buf
, EXCEPTION_REGISTRATION_RECORD
*frame
)
208 return setjmp( buf
);
211 void __cdecl
__wine_longjmp( __wine_jmp_buf
*buf
, int retval
)
213 for (;;) longjmp( buf
, retval
);
218 #endif /* __GNUC__ || __clang__ */