|
1 | | -; ***************************** u2wstub.asm ******************************** |
2 | | -; Author: Agner Fog |
3 | | -; Date created: 2008-05-25 |
4 | | -; |
5 | | -; Description: |
6 | | -; Call stub for calling 64-bit Linux, BSD or Mac functions from Windows |
7 | | -; |
8 | | -; (c) 2008 GNU General Public License www.gnu.org/copyleft/gpl.html |
9 | | -; ***************************************************************************** |
10 | | -; |
11 | | -; This call stub takes care of the differences between the calling conventions |
12 | | -; of 64-bit Windows and 64-bit Unix systems (Linux, BSD, Mac OS X) when a |
13 | | -; function compiled for a Unix system is called from Windows. No stub is needed |
14 | | -; in 32-bit systems. |
15 | | -; |
16 | | -; See the manual for instructions |
17 | | -; |
18 | | -; Requirements: |
19 | | -; The converted function must meet the following requirements: |
20 | | -; |
21 | | -; * Must not call any system functions or any library functions or |
22 | | -; access any data not available on the target system. |
23 | | -; |
24 | | -; * Must have no more than 4 parameters. |
25 | | -; |
26 | | -; * The parameters cannot be a composite type (struct, class), but |
27 | | -; pointers and references to composite types are allowed. |
28 | | -; |
29 | | -; * If any parameters are of type float or double then there can be |
30 | | -; no parameters of any other type than float and double. |
31 | | -; |
32 | | -; * Cannot have a variable number of parameter, such as printf |
33 | | -; |
34 | | -; * The return can be void or any type. If the return is a composite type |
35 | | -; then this may use a return pointer, counting as one parameter. |
36 | | -; |
37 | | -; * The function should preferably have extern "C" declaration in both |
38 | | -; systems. If the declaration is not extern "C" then the mangled names |
39 | | -; must be translated manually. |
40 | | -; |
41 | | -; * The function should preferably not use the red zone. Compile the Unix |
42 | | -; function with option -mno-red-zone if possible. If the function uses |
43 | | -; the red zone then it will still work in Windows most of the time, but |
44 | | -; it may fail with an extremely low frequency in case the system discards |
45 | | -; the area above the stack when it is low on memory. |
46 | | -; |
47 | | -; If the function has more than four parameters or a mixture of floating |
48 | | -; point and non-floating point parameters then you have to make your own |
49 | | -; stub assembler code to account for the differences in parameter transfer |
50 | | -; methods. |
51 | | -; |
52 | | -; If the converted Unix function calls another converted Unix function then |
53 | | -; no stub is needed for the latter call. If the converted Unix function calls |
54 | | -; a Windows function then the call must go through a reverse stub created |
55 | | -; from w2ustub. |
56 | | -; |
57 | | -; See www.agner.org/optimize/calling_conventions.pdf for further details |
58 | | -; about differences in calling conventions. |
59 | | -; **************************************************************************** |
60 | | - |
61 | | -.code |
62 | | - |
63 | | -extern uname: near |
64 | | - |
65 | | -wname proc ; call from Windows goes here |
66 | | - |
67 | | - ; Make space for 10 xmm registers, 2 G.P. registers, |
68 | | - ; and align stack by 16 |
69 | | - sub rsp, 184; 10*16 + 2*8 + 8 |
70 | | - |
71 | | - ; Register rsi, rdi and xmm6 - xmm15 have callee-save status |
72 | | - ; in Windows, but not in Unix: |
73 | | - mov [rsp], rsi |
74 | | - mov [rsp+8], rdi |
75 | | - movaps [rsp+10h], xmm6 |
76 | | - movaps [rsp+20h], xmm7 |
77 | | - movaps [rsp+30h], xmm8 |
78 | | - movaps [rsp+40h], xmm9 |
79 | | - movaps [rsp+50h], xmm10 |
80 | | - movaps [rsp+60h], xmm11 |
81 | | - movaps [rsp+70h], xmm12 |
82 | | - movaps [rsp+80h], xmm13 |
83 | | - movaps [rsp+90h], xmm14 |
84 | | - movaps [rsp+0A0h],xmm15 |
85 | | - |
86 | | - ; Windows parameters (rcx,rdx,r8,r9) -> Unix parameters (rdi,rsi,rdx,rcx) |
87 | | - mov rdi, rcx |
88 | | - mov rsi, rdx |
89 | | - mov rdx, r8 |
90 | | - mov rcx, r9 |
91 | | - |
92 | | - call uname ; Call to Unix function here |
93 | | - |
94 | | - ; Restore saved registers |
95 | | - mov rsi, [rsp] |
96 | | - mov rdi, [rsp+8] |
97 | | - movaps xmm6, [rsp+10h] |
98 | | - movaps xmm7, [rsp+20h] |
99 | | - movaps xmm8, [rsp+30h] |
100 | | - movaps xmm9, [rsp+40h] |
101 | | - movaps xmm10, [rsp+50h] |
102 | | - movaps xmm11, [rsp+60h] |
103 | | - movaps xmm12, [rsp+70h] |
104 | | - movaps xmm13, [rsp+80h] |
105 | | - movaps xmm14, [rsp+90h] |
106 | | - movaps xmm15, [rsp+0A0h] |
107 | | - |
108 | | - ; restore stack pointer |
109 | | - add rsp, 184 |
110 | | - ret |
111 | | - |
112 | | -wname endp |
113 | | - |
114 | | -end |
| 1 | +; ***************************** u2wstub.asm ******************************** |
| 2 | +; Author: Agner Fog |
| 3 | +; Date created: 2008-05-25 |
| 4 | +; |
| 5 | +; Description: |
| 6 | +; Call stub for calling 64-bit Linux, BSD or Mac functions from Windows |
| 7 | +; |
| 8 | +; (c) 2008 GNU General Public License www.gnu.org/copyleft/gpl.html |
| 9 | +; ***************************************************************************** |
| 10 | +; |
| 11 | +; This call stub takes care of the differences between the calling conventions |
| 12 | +; of 64-bit Windows and 64-bit Unix systems (Linux, BSD, Mac OS X) when a |
| 13 | +; function compiled for a Unix system is called from Windows. No stub is needed |
| 14 | +; in 32-bit systems. |
| 15 | +; |
| 16 | +; See the manual for instructions |
| 17 | +; |
| 18 | +; Requirements: |
| 19 | +; The converted function must meet the following requirements: |
| 20 | +; |
| 21 | +; * Must not call any system functions or any library functions or |
| 22 | +; access any data not available on the target system. |
| 23 | +; |
| 24 | +; * Must have no more than 4 parameters. |
| 25 | +; |
| 26 | +; * The parameters cannot be a composite type (struct, class), but |
| 27 | +; pointers and references to composite types are allowed. |
| 28 | +; |
| 29 | +; * If any parameters are of type float or double then there can be |
| 30 | +; no parameters of any other type than float and double. |
| 31 | +; |
| 32 | +; * Cannot have a variable number of parameter, such as printf |
| 33 | +; |
| 34 | +; * The return can be void or any type. If the return is a composite type |
| 35 | +; then this may use a return pointer, counting as one parameter. |
| 36 | +; |
| 37 | +; * The function should preferably have extern "C" declaration in both |
| 38 | +; systems. If the declaration is not extern "C" then the mangled names |
| 39 | +; must be translated manually. |
| 40 | +; |
| 41 | +; * The function should preferably not use the red zone. Compile the Unix |
| 42 | +; function with option -mno-red-zone if possible. If the function uses |
| 43 | +; the red zone then it will still work in Windows most of the time, but |
| 44 | +; it may fail with an extremely low frequency in case the system discards |
| 45 | +; the area above the stack when it is low on memory. |
| 46 | +; |
| 47 | +; If the function has more than four parameters or a mixture of floating |
| 48 | +; point and non-floating point parameters then you have to make your own |
| 49 | +; stub assembler code to account for the differences in parameter transfer |
| 50 | +; methods. |
| 51 | +; |
| 52 | +; If the converted Unix function calls another converted Unix function then |
| 53 | +; no stub is needed for the latter call. If the converted Unix function calls |
| 54 | +; a Windows function then the call must go through a reverse stub created |
| 55 | +; from w2ustub. |
| 56 | +; |
| 57 | +; See www.agner.org/optimize/calling_conventions.pdf for further details |
| 58 | +; about differences in calling conventions. |
| 59 | +; **************************************************************************** |
| 60 | + |
| 61 | +.code |
| 62 | + |
| 63 | +extern uname: near |
| 64 | + |
| 65 | +wname proc ; call from Windows goes here |
| 66 | + |
| 67 | + ; Make space for 10 xmm registers, 2 G.P. registers, |
| 68 | + ; and align stack by 16 |
| 69 | + sub rsp, 184; 10*16 + 2*8 + 8 |
| 70 | + |
| 71 | + ; Register rsi, rdi and xmm6 - xmm15 have callee-save status |
| 72 | + ; in Windows, but not in Unix: |
| 73 | + mov [rsp], rsi |
| 74 | + mov [rsp+8], rdi |
| 75 | + movaps [rsp+10h], xmm6 |
| 76 | + movaps [rsp+20h], xmm7 |
| 77 | + movaps [rsp+30h], xmm8 |
| 78 | + movaps [rsp+40h], xmm9 |
| 79 | + movaps [rsp+50h], xmm10 |
| 80 | + movaps [rsp+60h], xmm11 |
| 81 | + movaps [rsp+70h], xmm12 |
| 82 | + movaps [rsp+80h], xmm13 |
| 83 | + movaps [rsp+90h], xmm14 |
| 84 | + movaps [rsp+0A0h],xmm15 |
| 85 | + |
| 86 | + ; Windows parameters (rcx,rdx,r8,r9) -> Unix parameters (rdi,rsi,rdx,rcx) |
| 87 | + mov rdi, rcx |
| 88 | + mov rsi, rdx |
| 89 | + mov rdx, r8 |
| 90 | + mov rcx, r9 |
| 91 | + |
| 92 | + call uname ; Call to Unix function here |
| 93 | + |
| 94 | + ; Restore saved registers |
| 95 | + mov rsi, [rsp] |
| 96 | + mov rdi, [rsp+8] |
| 97 | + movaps xmm6, [rsp+10h] |
| 98 | + movaps xmm7, [rsp+20h] |
| 99 | + movaps xmm8, [rsp+30h] |
| 100 | + movaps xmm9, [rsp+40h] |
| 101 | + movaps xmm10, [rsp+50h] |
| 102 | + movaps xmm11, [rsp+60h] |
| 103 | + movaps xmm12, [rsp+70h] |
| 104 | + movaps xmm13, [rsp+80h] |
| 105 | + movaps xmm14, [rsp+90h] |
| 106 | + movaps xmm15, [rsp+0A0h] |
| 107 | + |
| 108 | + ; restore stack pointer |
| 109 | + add rsp, 184 |
| 110 | + ret |
| 111 | + |
| 112 | +wname endp |
| 113 | + |
| 114 | +end |
0 commit comments