winedbg: Get rid of unused mode command.
[wine/multimedia.git] / libs / wine / port.c
blob6d1c13d902359f70b2c2f1bbfbc751272b8cd44b
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/types.h>
28 #include "wine/library.h"
29 #include "wine/pthread.h"
31 static struct wine_pthread_functions pthread_functions;
33 /***********************************************************************
34 * wine_pthread_get_functions
36 void wine_pthread_get_functions( struct wine_pthread_functions *functions, size_t size )
38 memcpy( functions, &pthread_functions, min( size, sizeof(pthread_functions) ));
42 /***********************************************************************
43 * wine_pthread_set_functions
45 void wine_pthread_set_functions( const struct wine_pthread_functions *functions, size_t size )
47 memcpy( &pthread_functions, functions, min( size, sizeof(pthread_functions) ));
51 /***********************************************************************
52 * wine_switch_to_stack
54 * Switch to the specified stack and call the function.
56 void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack );
57 #if defined(__i386__) && defined(__GNUC__)
58 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
59 "movl 4(%esp),%ecx\n\t" /* func */
60 "movl 8(%esp),%edx\n\t" /* arg */
61 "movl 12(%esp),%esp\n\t" /* stack */
62 "andl $~15,%esp\n\t"
63 "subl $12,%esp\n\t"
64 "pushl %edx\n\t"
65 "xorl %ebp,%ebp\n\t"
66 "call *%ecx\n\t"
67 "int $3" /* we never return here */ );
68 #elif defined(__i386__) && defined(_MSC_VER)
69 __declspec(naked) void wine_switch_to_stack( void (*func)(void *), void *arg, void *stack )
71 __asm mov ecx, 4[esp];
72 __asm mov edx, 8[esp];
73 __asm mov esp, 12[esp];
74 __asm push edx;
75 __asm xor ebp, ebp;
76 __asm call [ecx];
77 __asm int 3;
79 #elif defined(__sparc__) && defined(__GNUC__)
80 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
81 "mov %o0, %l0\n\t" /* store first argument */
82 "mov %o1, %l1\n\t" /* store second argument */
83 "sub %o2, 96, %sp\n\t" /* store stack */
84 "call %l0, 0\n\t" /* call func */
85 "mov %l1, %o0\n\t" /* delay slot: arg for func */
86 "ta 0x01"); /* breakpoint - we never get here */
87 #elif defined(__powerpc__) && defined(__APPLE__)
88 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
89 "mtctr r3\n\t" /* func -> ctr */
90 "mr r3,r4\n\t" /* args -> function param 1 (r3) */
91 "mr r1,r5\n\t" /* stack */
92 "subi r1,r1,0x100\n\t" /* adjust stack pointer */
93 "bctr\n" /* call ctr */
94 "1:\tb 1b"); /* loop */
95 #elif defined(__powerpc__) && defined(__GNUC__)
96 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
97 "mtctr 3\n\t" /* func -> ctr */
98 "mr 3,4\n\t" /* args -> function param 1 (r3) */
99 "mr 1,5\n\t" /* stack */
100 "bctr\n\t" /* call ctr */
101 "1:\tb 1b"); /* loop */
102 #elif defined(__ALPHA__) && defined(__GNUC__)
103 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
104 "mov $16,$0\n\t" /* func */
105 "mov $17,$16\n\t" /* arg */
106 "mov $18,$30\n\t" /* stack */
107 "jsr $31,($0),0\n\t" /* call func */
108 "L1:\tbr $31,L1"); /* loop */
109 #elif defined(__x86_64__) && defined(__GNUC__)
110 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
111 "movq %rdi,%rax\n\t" /* func */
112 "movq %rsi,%rdi\n\t" /* arg */
113 "andq $~15,%rdx\n\t" /* stack */
114 "movq %rdx,%rsp\n\t"
115 "xorq %rbp,%rbp\n\t"
116 "callq *%rax\n\t" /* call func */
117 "int $3");
118 #else
119 #error You must implement wine_switch_to_stack for your platform
120 #endif