Skip to content

Commit 911b3c8

Browse files
authored
support uthread on windows with msvc (#467)
* support uthread on windows with msvc * fix windows test time usage
1 parent 8c87179 commit 911b3c8

9 files changed

Lines changed: 631 additions & 27 deletions

File tree

CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
cmake_minimum_required(VERSION 3.15)
2+
3+
if(POLICY CMP0194)
4+
cmake_policy(SET CMP0194 NEW)
5+
endif()
6+
27
project(async_simple
38
VERSION 1.3
4-
LANGUAGES CXX C ASM)
9+
LANGUAGES C CXX)
10+
11+
if(MSVC)
12+
enable_language(ASM_MASM)
13+
else()
14+
enable_language(ASM)
15+
endif()
516

617
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
718

19+
if(WIN32)
20+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
21+
endif()
22+
823
enable_testing()
924

1025
set(CMAKE_CXX_STANDARD 20)
@@ -158,6 +173,11 @@ elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") # uname -s
158173
set(UTHREAD ON)
159174
message("-- Uthread on")
160175
endif()
176+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
177+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" AND MSVC)
178+
set(UTHREAD ON)
179+
message("-- Uthread on")
180+
endif()
161181
endif()
162182
# End Detecing Uthread
163183

async_simple/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ if(${UTHREAD})
33
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
44
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "13")
55
endif()
6-
file(GLOB uthread_asm_src "uthread/internal/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/*.S")
6+
if(MSVC)
7+
file(GLOB uthread_asm_src "uthread/internal/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/*.asm")
8+
else()
9+
file(GLOB uthread_asm_src "uthread/internal/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/*.S")
10+
endif()
711
endif()
812

913
file(GLOB headers "*.h")
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
2+
; Copyright Oliver Kowalke 2009.
3+
; Distributed under the Boost Software License, Version 1.0.
4+
; (See accompanying file LICENSE_1_0.txt or copy at
5+
; http://www.boost.org/LICENSE_1_0.txt)
6+
7+
; ----------------------------------------------------------------------------------
8+
; | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
9+
; ----------------------------------------------------------------------------------
10+
; | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c |
11+
; ----------------------------------------------------------------------------------
12+
; | SEE registers (XMM6-XMM15) |
13+
; ----------------------------------------------------------------------------------
14+
; ----------------------------------------------------------------------------------
15+
; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16+
; ----------------------------------------------------------------------------------
17+
; | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c |
18+
; ----------------------------------------------------------------------------------
19+
; | SEE registers (XMM6-XMM15) |
20+
; ----------------------------------------------------------------------------------
21+
; ----------------------------------------------------------------------------------
22+
; | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
23+
; ----------------------------------------------------------------------------------
24+
; | 0xe40 | 0x44 | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c |
25+
; ----------------------------------------------------------------------------------
26+
; | SEE registers (XMM6-XMM15) |
27+
; ----------------------------------------------------------------------------------
28+
; ----------------------------------------------------------------------------------
29+
; | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
30+
; ----------------------------------------------------------------------------------
31+
; | 0x60 | 0x64 | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c |
32+
; ----------------------------------------------------------------------------------
33+
; | SEE registers (XMM6-XMM15) |
34+
; ----------------------------------------------------------------------------------
35+
; ----------------------------------------------------------------------------------
36+
; | 32 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
37+
; ----------------------------------------------------------------------------------
38+
; | 0x80 | 0x84 | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c |
39+
; ----------------------------------------------------------------------------------
40+
; | SEE registers (XMM6-XMM15) |
41+
; ----------------------------------------------------------------------------------
42+
; ----------------------------------------------------------------------------------
43+
; | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
44+
; ----------------------------------------------------------------------------------
45+
; | 0xa0 | 0xa4 | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc |
46+
; ----------------------------------------------------------------------------------
47+
; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc |
48+
; ----------------------------------------------------------------------------------
49+
; ----------------------------------------------------------------------------------
50+
; | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
51+
; ----------------------------------------------------------------------------------
52+
; | 0xc0 | 0xc4 | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc |
53+
; ----------------------------------------------------------------------------------
54+
; | limit | base | R12 | R13 |
55+
; ----------------------------------------------------------------------------------
56+
; ----------------------------------------------------------------------------------
57+
; | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
58+
; ----------------------------------------------------------------------------------
59+
; | 0xe0 | 0xe4 | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc |
60+
; ----------------------------------------------------------------------------------
61+
; | R14 | R15 | RDI | RSI |
62+
; ----------------------------------------------------------------------------------
63+
; ----------------------------------------------------------------------------------
64+
; | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
65+
; ----------------------------------------------------------------------------------
66+
; | 0x100 | 0x104 | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c |
67+
; ----------------------------------------------------------------------------------
68+
; | RBX | RBP | hidden | RIP |
69+
; ----------------------------------------------------------------------------------
70+
; ----------------------------------------------------------------------------------
71+
; | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
72+
; ----------------------------------------------------------------------------------
73+
; | 0x120 | 0x124 | 0x128 | 0x12c | 0x130 | 0x134 | 0x138 | 0x13c |
74+
; ----------------------------------------------------------------------------------
75+
; | parameter area |
76+
; ----------------------------------------------------------------------------------
77+
; ----------------------------------------------------------------------------------
78+
; | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
79+
; ----------------------------------------------------------------------------------
80+
; | 0x140 | 0x144 | 0x148 | 0x14c | 0x150 | 0x154 | 0x158 | 0x15c |
81+
; ----------------------------------------------------------------------------------
82+
; | FCTX | DATA | |
83+
; ----------------------------------------------------------------------------------
84+
85+
.code
86+
87+
_fl_jump_fcontext PROC EXPORT FRAME
88+
.endprolog
89+
90+
; prepare stack
91+
lea rsp, [rsp-0118h]
92+
93+
; save XMM storage
94+
movaps [rsp], xmm6
95+
movaps [rsp+010h], xmm7
96+
movaps [rsp+020h], xmm8
97+
movaps [rsp+030h], xmm9
98+
movaps [rsp+040h], xmm10
99+
movaps [rsp+050h], xmm11
100+
movaps [rsp+060h], xmm12
101+
movaps [rsp+070h], xmm13
102+
movaps [rsp+080h], xmm14
103+
movaps [rsp+090h], xmm15
104+
; save MMX control- and status-word
105+
stmxcsr [rsp+0a0h]
106+
; save x87 control-word
107+
fnstcw [rsp+0a4h]
108+
109+
; load NT_TIB
110+
mov r10, gs:[030h]
111+
; save fiber local storage
112+
mov rax, [r10+020h]
113+
mov [rsp+0b0h], rax
114+
; save current deallocation stack
115+
mov rax, [r10+01478h]
116+
mov [rsp+0b8h], rax
117+
; save current stack limit
118+
mov rax, [r10+010h]
119+
mov [rsp+0c0h], rax
120+
; save current stack base
121+
mov rax, [r10+08h]
122+
mov [rsp+0c8h], rax
123+
124+
mov [rsp+0d0h], r12 ; save R12
125+
mov [rsp+0d8h], r13 ; save R13
126+
mov [rsp+0e0h], r14 ; save R14
127+
mov [rsp+0e8h], r15 ; save R15
128+
mov [rsp+0f0h], rdi ; save RDI
129+
mov [rsp+0f8h], rsi ; save RSI
130+
mov [rsp+0100h], rbx ; save RBX
131+
mov [rsp+0108h], rbp ; save RBP
132+
133+
mov [rsp+0110h], rcx ; save hidden address of transport_t
134+
135+
; preserve RSP (pointing to context-data) in R9
136+
mov r9, rsp
137+
138+
; restore RSP (pointing to context-data) from RDX
139+
mov rsp, rdx
140+
141+
; restore XMM storage
142+
movaps xmm6, [rsp]
143+
movaps xmm7, [rsp+010h]
144+
movaps xmm8, [rsp+020h]
145+
movaps xmm9, [rsp+030h]
146+
movaps xmm10, [rsp+040h]
147+
movaps xmm11, [rsp+050h]
148+
movaps xmm12, [rsp+060h]
149+
movaps xmm13, [rsp+070h]
150+
movaps xmm14, [rsp+080h]
151+
movaps xmm15, [rsp+090h]
152+
; restore MMX control- and status-word
153+
ldmxcsr [rsp+0a0h]
154+
; save x87 control-word
155+
fldcw [rsp+0a4h]
156+
157+
; load NT_TIB
158+
mov r10, gs:[030h]
159+
; restore fiber local storage
160+
mov rax, [rsp+0b0h]
161+
mov [r10+020h], rax
162+
; restore current deallocation stack
163+
mov rax, [rsp+0b8h]
164+
mov [r10+01478h], rax
165+
; restore current stack limit
166+
mov rax, [rsp+0c0h]
167+
mov [r10+010h], rax
168+
; restore current stack base
169+
mov rax, [rsp+0c8h]
170+
mov [r10+08h], rax
171+
172+
mov r12, [rsp+0d0h] ; restore R12
173+
mov r13, [rsp+0d8h] ; restore R13
174+
mov r14, [rsp+0e0h] ; restore R14
175+
mov r15, [rsp+0e8h] ; restore R15
176+
mov rdi, [rsp+0f0h] ; restore RDI
177+
mov rsi, [rsp+0f8h] ; restore RSI
178+
mov rbx, [rsp+0100h] ; restore RBX
179+
mov rbp, [rsp+0108h] ; restore RBP
180+
181+
mov rax, [rsp+0110h] ; restore hidden address of transport_t
182+
183+
; prepare stack
184+
lea rsp, [rsp+0118h]
185+
186+
; load return-address
187+
pop r10
188+
189+
; transport_t returned in RAX
190+
; return parent fcontext_t
191+
mov [rax], r9
192+
; return data
193+
mov [rax+08h], r8
194+
195+
; transport_t as 1.arg of context-function
196+
mov rcx, rax
197+
198+
; indirect jump to context
199+
jmp r10
200+
_fl_jump_fcontext ENDP
201+
END

0 commit comments

Comments
 (0)