wined3d: Add AMD Radeon HD 6480G IGP.
[wine.git] / libs / wine / port.c
blobd5ce07aceb1ac01c8c9380594222c3378a6c76ea
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/unicode.h"
29 #include "wine/library.h"
31 /* functions from libwine_port that are also exported from libwine for backwards compatibility,
32 * on platforms that require it */
33 #ifndef __ANDROID__
34 const void *libwine_port_functions[] =
36 wine_cp_enum_table,
37 wine_cp_get_table,
38 wine_cp_mbstowcs,
39 wine_cp_wcstombs,
40 wine_cpsymbol_mbstowcs,
41 wine_cpsymbol_wcstombs,
42 wine_fold_string,
43 wine_utf8_mbstowcs,
44 wine_utf8_wcstombs
46 #endif
48 /* no longer used, for backwards compatibility only */
49 struct wine_pthread_functions;
50 static void *pthread_functions[8];
52 /***********************************************************************
53 * wine_pthread_get_functions
55 void wine_pthread_get_functions( struct wine_pthread_functions *functions, size_t size )
57 memcpy( functions, &pthread_functions, min( size, sizeof(pthread_functions) ));
61 /***********************************************************************
62 * wine_pthread_set_functions
64 void wine_pthread_set_functions( const struct wine_pthread_functions *functions, size_t size )
66 memcpy( &pthread_functions, functions, min( size, sizeof(pthread_functions) ));
70 /***********************************************************************
71 * wine_switch_to_stack
73 * Switch to the specified stack and call the function.
75 void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack )
77 wine_call_on_stack( (int (*)(void *))func, arg, stack );
78 abort();
82 /***********************************************************************
83 * wine_call_on_stack
85 * Switch to the specified stack to call the function and return.
88 #if defined(__i386__) && defined(__GNUC__)
89 __ASM_GLOBAL_FUNC( wine_call_on_stack,
90 "pushl %ebp\n\t"
91 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
92 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
93 "pushl %esi\n\t"
94 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
95 __ASM_CFI(".cfi_rel_offset %esi,0\n\t")
96 "movl %esp,%esi\n\t"
97 __ASM_CFI(".cfi_def_cfa_register %esi\n\t")
98 "movl 12(%esp),%ecx\n\t" /* func */
99 "movl 16(%esp),%edx\n\t" /* arg */
100 "movl 20(%esp),%eax\n\t" /* stack */
101 "andl $~15,%eax\n\t"
102 "subl $12,%eax\n\t"
103 "movl %eax,%esp\n\t"
104 "pushl %edx\n\t"
105 "xorl %ebp,%ebp\n\t"
106 "call *%ecx\n\t"
107 "movl %esi,%esp\n\t"
108 "popl %esi\n\t"
109 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
110 __ASM_CFI(".cfi_same_value %esi\n\t")
111 "popl %ebp\n\t"
112 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
113 __ASM_CFI(".cfi_same_value %ebp\n\t")
114 "ret" )
115 #elif defined(__i386__) && defined(_MSC_VER)
116 __declspec(naked) int wine_call_on_stack( int (*func)(void *), void *arg, void *stack )
118 __asm push ebp;
119 __asm push esi;
120 __asm mov ecx, 12[esp];
121 __asm mov edx, 16[esp];
122 __asm mov esi, 20[esp];
123 __asm xchg esp, esi;
124 __asm push edx;
125 __asm xor ebp, ebp;
126 __asm call [ecx];
127 __asm mov esp, esi;
128 __asm pop esi;
129 __asm pop ebp
130 __asm ret;
132 #elif defined(__x86_64__) && defined(__GNUC__)
133 __ASM_GLOBAL_FUNC( wine_call_on_stack,
134 "pushq %rbp\n\t"
135 __ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
136 __ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
137 "movq %rsp,%rbp\n\t"
138 __ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
139 "movq %rdi,%rax\n\t" /* func */
140 "movq %rsi,%rdi\n\t" /* arg */
141 "andq $~15,%rdx\n\t" /* stack */
142 "movq %rdx,%rsp\n\t"
143 "callq *%rax\n\t" /* call func */
144 "movq %rbp,%rsp\n\t"
145 __ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
146 "popq %rbp\n\t"
147 __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
148 __ASM_CFI(".cfi_same_value %rbp\n\t")
149 "ret")
150 #elif defined(__powerpc__) && defined(__GNUC__)
151 __ASM_GLOBAL_FUNC( wine_call_on_stack,
152 "mflr 0\n\t" /* get return address */
153 "stw 0, 4(1)\n\t" /* save return address */
154 "subi 5, 5, 16\n\t" /* reserve space on new stack */
155 "stw 1, 12(5)\n\t" /* store old sp */
156 "mtctr 3\n\t" /* func -> ctr */
157 "mr 3,4\n\t" /* args -> function param 1 (r3) */
158 "mr 1,5\n\t" /* stack */
159 "li 0, 0\n\t" /* zero */
160 "stw 0, 0(1)\n\t" /* bottom of stack */
161 "stwu 1, -16(1)\n\t" /* create a frame for this function */
162 "bctrl\n\t" /* call ctr */
163 "lwz 1, 28(1)\n\t" /* fetch old sp */
164 "lwz 0, 4(1)\n\t" /* fetch return address */
165 "mtlr 0\n\t" /* return address -> lr */
166 "blr") /* return */
167 #elif defined(__arm__) && defined(__GNUC__)
168 __ASM_GLOBAL_FUNC( wine_call_on_stack,
169 "push {r4,LR}\n\t" /* save return address on stack */
170 "mov r4, sp\n\t" /* store old sp in local var */
171 "mov sp, r2\n\t" /* stack */
172 "mov r2, r0\n\t" /* func -> scratch register */
173 "mov r0, r1\n\t" /* arg */
174 "blx r2\n\t" /* call func */
175 "mov sp, r4\n\t" /* restore old sp from local var */
176 "pop {r4,PC}") /* fetch return address into pc */
177 #elif defined(__aarch64__) && defined(__GNUC__)
178 __ASM_GLOBAL_FUNC( wine_call_on_stack,
179 "stp x29, x30, [sp,#-32]!\n\t" /* save return address on stack */
180 "str x19, [sp,#16]\n\t" /* save register on stack */
181 "mov x19, sp\n\t" /* store old sp in local var */
182 "mov sp, x2\n\t" /* stack */
183 "mov x2, x0\n\t" /* func -> scratch register */
184 "mov x0, x1\n\t" /* arg */
185 "blr x2\n\t" /* call func */
186 "mov sp, x19\n\t" /* restore old sp from local var */
187 "ldr x19, [sp,#16]\n\t" /* restore register from stack */
188 "ldp x29, x30, [sp],#32\n\t" /* restore return address */
189 "ret") /* return */
190 #else
191 #error You must implement wine_call_on_stack for your platform
192 #endif