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 ;
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 ;
13 tib-exception-list-offset [] FS PUSH
14 tib-stack-base-offset [] FS PUSH
15 tib-stack-limit-offset [] FS PUSH ;
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 ;
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 ;
34 : jit-install-seh ( -- )
35 ! Create a new exception record and store it in the TIB.
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
42 ! This is the new exception handler
43 tib-exception-list-offset [] ESP FS MOV ;
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 ;
53 << "vocab:cpu/x86/32/bootstrap.factor" parse-file suffix! >>