2 * Wine portability routines
4 * Copyright 2000 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
22 #include "wine/port.h"
26 #include <sys/types.h>
28 #include "wine/library.h"
30 /* no longer used, for backwards compatibility only */
31 struct wine_pthread_functions
;
32 static void *pthread_functions
[8];
34 /***********************************************************************
35 * wine_pthread_get_functions
37 void wine_pthread_get_functions( struct wine_pthread_functions
*functions
, size_t size
)
39 memcpy( functions
, &pthread_functions
, min( size
, sizeof(pthread_functions
) ));
43 /***********************************************************************
44 * wine_pthread_set_functions
46 void wine_pthread_set_functions( const struct wine_pthread_functions
*functions
, size_t size
)
48 memcpy( &pthread_functions
, functions
, min( size
, sizeof(pthread_functions
) ));
52 /***********************************************************************
53 * wine_switch_to_stack
55 * Switch to the specified stack and call the function.
57 #if defined(__sparc__) && defined(__GNUC__)
58 __ASM_GLOBAL_FUNC( wine_switch_to_stack
,
59 "mov %o0, %l0\n\t" /* store first argument */
60 "mov %o1, %l1\n\t" /* store second argument */
61 "sub %o2, 96, %sp\n\t" /* store stack */
62 "call %l0, 0\n\t" /* call func */
63 "mov %l1, %o0\n\t" /* delay slot: arg for func */
64 "ta 0x01") /* breakpoint - we never get here */
65 #elif defined(__powerpc__) && defined(__APPLE__)
66 __ASM_GLOBAL_FUNC( wine_switch_to_stack
,
67 "mtctr r3\n\t" /* func -> ctr */
68 "mr r3,r4\n\t" /* args -> function param 1 (r3) */
69 "mr r1,r5\n\t" /* stack */
70 "subi r1,r1,0x100\n\t" /* adjust stack pointer */
71 "bctrl\n" /* call ctr */
72 "1:\tb 1b") /* loop */
73 #elif defined(__ALPHA__) && defined(__GNUC__)
74 __ASM_GLOBAL_FUNC( wine_switch_to_stack
,
75 "mov $16,$0\n\t" /* func */
76 "mov $17,$16\n\t" /* arg */
77 "mov $18,$30\n\t" /* stack */
78 "jsr $31,($0),0\n\t" /* call func */
79 "L1:\tbr $31,L1") /* loop */
81 void DECLSPEC_NORETURN
wine_switch_to_stack( void (*func
)(void *), void *arg
, void *stack
)
83 wine_call_on_stack( (int (*)(void *))func
, arg
, stack
);
89 /***********************************************************************
92 * Switch to the specified stack to call the function and return.
95 #if defined(__i386__) && defined(__GNUC__)
96 __ASM_GLOBAL_FUNC( wine_call_on_stack
,
98 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
99 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
101 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
102 __ASM_CFI(".cfi_rel_offset %esi,0\n\t")
104 __ASM_CFI(".cfi_def_cfa_register %esi\n\t")
105 "movl 12(%esp),%ecx\n\t" /* func */
106 "movl 16(%esp),%edx\n\t" /* arg */
107 "movl 20(%esp),%eax\n\t" /* stack */
116 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
117 __ASM_CFI(".cfi_same_value %esi\n\t")
119 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
120 __ASM_CFI(".cfi_same_value %ebp\n\t")
122 #elif defined(__i386__) && defined(_MSC_VER)
123 __declspec(naked
) int wine_call_on_stack( int (*func
)(void *), void *arg
, void *stack
)
127 __asm mov ecx
, 12[esp
];
128 __asm mov edx
, 16[esp
];
129 __asm mov esi
, 20[esp
];
139 #elif defined(__x86_64__) && defined(__GNUC__)
140 __ASM_GLOBAL_FUNC( wine_call_on_stack
,
142 ".cfi_adjust_cfa_offset 8\n\t"
143 ".cfi_rel_offset %rbp,0\n\t"
145 ".cfi_def_cfa_register %rbp\n\t"
146 "movq %rdi,%rax\n\t" /* func */
147 "movq %rsi,%rdi\n\t" /* arg */
148 "andq $~15,%rdx\n\t" /* stack */
150 "callq *%rax\n\t" /* call func */
152 ".cfi_def_cfa_register %rsp\n\t"
154 ".cfi_adjust_cfa_offset -8\n\t"
155 ".cfi_same_value %rbp\n\t"
157 #elif defined(__powerpc__) && defined(__GNUC__)
158 __ASM_GLOBAL_FUNC( wine_call_on_stack
,
159 "mflr 0\n\t" /* get return address */
160 "stw 0, 4(1)\n\t" /* save return address */
161 "subi 5, 5, 16\n\t" /* reserve space on new stack */
162 "stw 1, 12(5)\n\t" /* store old sp */
163 "mtctr 3\n\t" /* func -> ctr */
164 "mr 3,4\n\t" /* args -> function param 1 (r3) */
165 "mr 1,5\n\t" /* stack */
166 "li 0, 0\n\t" /* zero */
167 "stw 0, 0(1)\n\t" /* bottom of stack */
168 "stwu 1, -16(1)\n\t" /* create a frame for this function */
169 "bctrl\n\t" /* call ctr */
170 "lwz 1, 28(1)\n\t" /* fetch old sp */
171 "lwz 0, 4(1)\n\t" /* fetch return address */
172 "mtlr 0\n\t" /* return address -> lr */
174 #elif defined(__arm__)
175 __ASM_GLOBAL_FUNC( wine_call_on_stack
,
176 "str r14, [r13, #4]\n\t" /* save return address on stack */
177 "sub r2, r2, #16\n\t" /* reserve space on new stack */
178 "str r13, [r2, #12]\n\t" /* store old sp */
179 "mov r3, r0\n\t" /* func */
180 "mov r0, r1\n\t" /* arg */
181 "mov r13, r2\n\t" /* stack */
182 "mov r2, #0\n\t" /* zero */
183 "str r2, [r13]\n\t" /* bottom of stack */
184 "sub r13, r13, #16\n\t" /* create a frame for this function */
185 "blx r3\n\t" /* call func */
186 "ldr r13, [r13, #28]\n\t" /* fetch old sp */
187 "ldr r15, [r13, #4]") /* fetch return address and return */
189 #error You must implement wine_switch_to_stack for your platform