]> gitweb.factorcode.org Git - factor.git/blob - basis/cpu/x86/32/winnt/bootstrap.factor
Get green threads working on Windows
[factor.git] / basis / cpu / x86 / 32 / winnt / bootstrap.factor
1 ! Copyright (C) 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: bootstrap.image.private compiler.constants
4 cpu.x86.assembler cpu.x86.assembler.operands kernel layouts
5 locals parser sequences ;
6 IN: bootstrap.x86
7
8 : tib-exception-list-offset ( -- n ) 0 bootstrap-cells ;
9 : tib-stack-base-offset ( -- n ) 1 bootstrap-cells ;
10 : tib-stack-limit-offset ( -- n ) 2 bootstrap-cells ;
11
12 : jit-save-tib ( -- )
13     tib-exception-list-offset [] FS PUSH
14     tib-stack-base-offset [] FS PUSH
15     tib-stack-limit-offset [] FS PUSH ;
16
17 : jit-restore-tib ( -- )
18     tib-stack-limit-offset [] FS POP
19     tib-stack-base-offset [] FS POP
20     tib-exception-list-offset [] FS POP ;
21
22 :: jit-update-tib ( ctx-reg -- )
23     ! There's a redundant load here because we're not allowed
24     ! to clobber ctx-reg. Clobbers EAX.
25     ! Save callstack base in TIB
26     EAX ctx-reg context-callstack-seg-offset [+] MOV
27     EAX EAX segment-end-offset [+] MOV
28     tib-stack-base-offset [] EAX FS MOV
29     ! Save callstack limit in TIB
30     EAX ctx-reg context-callstack-seg-offset [+] MOV
31     EAX EAX segment-start-offset [+] MOV
32     tib-stack-limit-offset [] EAX FS MOV ;
33
34 : jit-install-seh ( -- )
35     ! Create a new exception record and store it in the TIB.
36     ! Align stack
37     ESP 3 bootstrap-cells ADD
38     ! Exception handler address filled in by callback.cpp
39     0 PUSH rc-absolute-cell rt-exception-handler jit-rel
40     ! No next handler
41     0 PUSH
42     ! This is the new exception handler
43     tib-exception-list-offset [] ESP FS MOV ;
44
45 :: jit-update-seh ( ctx-reg -- )
46     ! Load exception record structure that jit-install-seh
47     ! created from the bottom of the callstack. Clobbers EAX.
48     EAX ctx-reg context-callstack-bottom-offset [+] MOV
49     EAX bootstrap-cell ADD
50     ! Store exception record in TIB.
51     tib-exception-list-offset [] EAX FS MOV ;
52
53 << "vocab:cpu/x86/32/bootstrap.factor" parse-file suffix! >>
54 call