1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level
1: self
-hosting
32-bit Forth compiler
4 ;; Copyright
(C
) 2020 Ketmar Dark
// Invisible Vector
6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 ;; additional assembler commands
8 ;; WARNING
! there should be NO argument
-less asm commands
9 ;; they will
break the parser
!
10 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 *Imm elf
-entry
-point
-addr
!
20 *ImSize
4 = ERRID_ASM_EXPECT_32BIT_OPERAND not
-?asm
-error
21 *ImmName ccount
*ImSize
*ImmForthType
24 elf
-entry
-point
-addr
real->tc
to elf
-current
-pc
30 : $ALIGN
( -- ) macro
-instrs
:align
;
33 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 : ($VAR
-ETC
-CREATE
) ( tc
-cfa
-- )
36 tk
-str? ERRID_ASM_STRING_EXPECTED not
-?asm
-error
37 ;; create word header and CFA
38 lexer
:tkvalue count
2dup upcase
-str rot execute
42 : ($VAR
-COMPILE
-VALUE
) ( -- )
50 *ImSize
4 = ERRID_ASM_EXPECT_32BIT_OPERAND not
-?asm
-error
51 *ImmName ccount
*ImSize
*ImmForthType asm
-Label
-Fixup
58 : ($VAR
-ETC
) ( tc
-cfa
-- )
63 ;; this one doesn
't take a value
64 : $DVAR ( -- ) ['] tc
-(variable
-header
-str
) ($VAR
-ETC
-CREATE
) 0 tc
-, 0 tc
-, tc
-create
; ;
66 : $VARIABLE
( -- ) ['] tc-(variable-header-str) ($VAR-ETC) ;
67 : $CONSTANT ( -- ) ['] tc
-(constant
-header
-str
) ($VAR
-ETC
) ;
68 : $VALUE
( -- ) ['] tc-(value-header-str) ($VAR-ETC) ;
69 : $DEFER ( -- ) ['] tc
-(defer
-header
-str
) ($VAR
-ETC
) ;
72 tc
-tls
-type tc
-tls
-fs
= if
73 4 ['] tc-(uservar-header-str) ($VAR-ETC-CREATE)
74 ;; create offset constant
75 tk-id? ERRID_ASM_LABEL_EXPECTED not-?asm-error
76 dup lexer:tkvalue count rot asmx86:asm-Make-Label
85 *ImSize 4 = ERRID_ASM_EXPECT_32BIT_OPERAND not-?asm-error
87 asmx86:asm-PC >r dup to elf-current-pc
88 *ImmName ccount *ImSize *ImmForthType asm-Label-Fixup
92 *Imm swap tc-get-ua-rva tc-!
95 ['] tc
-(variable
-header
-str
) ($VAR
-ETC
-CREATE
)
96 ;; create offset constant
97 tk
-id? ERRID_ASM_LABEL_EXPECTED not
-?asm
-error
98 lexer
:tkvalue count asmx86
:asm
-PC asmx86
:asm
-Make
-Label
110 *OpReloc ?abort
" cannot use labels in $allot"
120 *OpReloc ?abort
" cannot use labels in $userallot"
122 tc
-tls
-type tc
-tls
-fs
= if
130 : $VOCABHEADER
( -- )
131 ['] tc-(vocab-header-str) ($VAR-ETC)
133 ;; patch wordlist name pointer
134 *OpReloc if *ImmLabelDefined else true endif
136 ;; address is known, fix name pointer
138 \ tc-here cell- tc-@ ;; get wordlist address
139 *Imm ;; our wordlist address lives here too ;-)
142 dup tc-@ ?abort" trying to create two headers for one wordlist"
145 ;; address is unknown
146 ?abort" cannot create vocabulary headers with forwards (yet)"
151 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
152 -1 value tc-has-debugger? (hidden)
153 0 value tc-urforth-next-ptr (hidden)
155 : (ur-has-dbg?) ( -- flag )
157 " URFORTH_DEBUG" asmx86:asm-Get-Constant if
158 notnot to tc-has-debugger?
160 \ " urforth_next_ptr" asmx86:asm-Get-Label 1 <> ?abort" \`urforth_next_ptr\` must be defined"
161 " urforth_next" asmx86:asm-Get-Label 1 <> ?abort" \`urforth_next\` must be defined"
162 to tc-urforth-next-ptr
173 \ old: either "jmp eax" of "jmp dword [nextref]"
174 \ new: either "jmp eax" of "jmp tc-urforth-next-ptr"
177 \ $25 asm-c, tc-urforth-next-ptr asm-,
178 $E9 asm-c, tc-urforth-next-ptr asm-pc 4+ - asm-,
184 replace asmx86:macro-instrs:NEXT tc-NEXT