1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level
1: self
-hosting
32-bit Forth compiler
3 ;; Copyright
(C
) 2020 Ketmar Dark
// Invisible Vector
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 $constant
"WLIST-HASH-BITS" WLIST_HASH_BITS
9 $constant
"(ALIGN-WORD-HEADERS?)" URFORTH_ALIGN_HEADERS
12 $constant
"(URFORTH-LEVEL)" 1
15 ;; bit
15 is
"beta" flag
16 ;; this gives us versions up
to 255.255.32767
17 $constant
"(URFORTH-VERSION)" 0x00_
01_
0001
20 ;; should segfault handler throw an error instead of exiting?
21 $value
"(TRAP-THROW)" urfsegfault_throw_error
24 ;; print stack trace before doing an action?
25 $value
"(TRAP-STACKTRACE)" urfsegfault_stacktrace
28 ;; is multithreading active?
29 ;; this will be set
to `true`
if at least one thread was created
30 ;; this will never be reset
(except in SAVEd images
)
31 $value
"(MT-ACTIVE?)" 0
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 ;; user area size is
4KB
(hardcoded
)
39 $label ua_default_values
40 rb URFORTH_MAX_USERAREA_SIZE
43 ;; will be patched by the startup
/thread creation code
44 ;; it should always be at zero offset
45 $uservar
"(USER-BASE-ADDR)" ua_ofs_baseaddr
0
48 ;; this will be set by thread creation code
49 ;; this is the full size of tls
+stacks allocation
, that can be used in OS
:MUNMAP
50 $uservar
"(USER-FULL-SIZE)" ua_ofs_fullsize
0
54 ;; patched by the startup code
55 $uservar
"(MAIN-THREAD?)" ua_ofs_is_main_thread
0
58 $uservar
"SP0" ua_ofs_sp0
0
59 $uservar
"RP0" ua_ofs_rp0
0
60 ;; default size
for thread stacks
(note
: main thread has different
-sized stacks
)
61 ;; with those sizes
, it rougly fits into one
4KB page
(including userarea
)
62 $uservar
"#SP" ua_ofs_spsize
500
63 $uservar
"#RP" ua_ofs_rpsize
240
65 $uservar
"BASE" ua_ofs_base
10
67 ;; this can be used in various OOP implementations
68 ;; the kernel doesn
't use it
69 ;; the reason it is there is because THROW will save/restore it
70 $uservar "(SELF)" ua_ofs_self 0
73 ;; this can be used in various locals implementations
74 ;; the kernel doesn't use it
(yet
)
75 ;; the reason it is there is because THROW will save
/restore it
76 $uservar
"(LOCPTR)" ua_ofs_locptr
0
79 $uservar
"PAD-AREA" ua_ofs_padarea
0
81 ;; this will be patched by the startup
/thread creation code
82 $uservar
"(DEFAULT-TIB)" ua_ofs_deftib
0
85 $constant
"(DEFAULT-#TIB)" 4090
89 ;; default user area values
90 ;; this will be created and set by the metacompiler
91 $constant
"(USER-AREA-DEFAULT)" ua_default_values
93 $constant
"(USER-AREA-MAX-SIZE)" URFORTH_MAX_USERAREA_SIZE
95 $variable
"(USER-AREA-USED)" ur_userarea_default_size
98 $
if URFORTH_TLS_TYPE
= URFORTH_TLS_TYPE_FS
99 $value
"(USER-TLS-ENTRY-INDEX)" 0
104 $constant
"HAS-TLS?" URFORTH_TLS_TYPE
107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
108 ;; pad is allocated with BRK
; "#PAD-AREA-RESV" is the space BEFORE
"PAD-AREA"
109 ;; $variable
"PAD-AREA" 0 ;; will be set by startup code
110 $constant
"#PAD-AREA-RESV" 2040
111 $constant
"#PAD-AREA" 2048
114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
117 ;; optimise forth code?
118 ;; currently does only alias optimisation
(if "(opt-aliases?)" is true
)
119 $value
"(OPT-FORTH?)" 0
122 ;; should optimiser replace alias calls with aliased words?
123 ;; this doesn
't affect REPLACED words, tho
124 ;; actually, for this to work, the word size should be exactly 5 bytes, and
126 $value "(OPT-ALIASES?)" 1
129 ;; should replaced words be rerouted in the same ways as aliases?
130 ;; this may break further replacing, so it is turned off
131 ;; not yet implemented
132 ;;$value "(OPT-REPLACES?)" 0
136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
139 $variable "DP" urforth_code_end
141 $variable "DP-LAST-ADDR" urforth_dict_lastaddr ;; last valid dictionary address
143 $variable "DP-PROTECTED" urforth_dict_protected ;; first unprotected address
146 ;; this is used to temporarily change HERE
147 ;; MUST be inside "(DP-TEMP-BASE)", because first dp-temp-base cell is used to check size
148 $variable "DP-TEMP" 0
150 $variable "(DP-TEMP-BASE)" 0 ;; first cell is size
152 $variable "(DP-TEMP-BUF)" 0
155 ;; voclink always points to another voclink (or contains 0)
156 $variable "(VOC-LINK)" forth_wordlist_voclink ;; voclink always points to wordlist voclink (or contains 0)
160 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
161 ;; BSS reserve on SAVE
162 $value "(SAVE-BSS-RESERVE)" URFORTH_BSS_RESERVE
166 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
173 $constant "HAS-DEBUGGER?" URFORTH_DEBUG
174 $constant "ALIGN-HEADERS?" URFORTH_ALIGN_HEADERS
175 $constant "ALIGN-CFA?" URFORTH_ALIGN_CFA
176 $constant "ALIGN-PFA?" URFORTH_ALIGN_PFA
178 $constant "(CODE-BASE-ADDR)" urforth_code_base_addr
181 ;; two dwords -- disk and memory
182 $constant "(ELF-HEADER-CODE-SIZE-ADDR)" elfhead_codesize_addr
185 $constant "(ELF-DYNAMIC?)" URFORTH_DYNAMIC_BINARY
188 $if URFORTH_DYNAMIC_BINARY
189 $constant "(CODE-IMPORTS-ADDR)" elfhead_impstart
192 $constant "(CODE-IMPORTS-SIZE)" elfhead_implen
196 $constant "(CODE-ENTRY-ADDR)" urforth_entry_point
200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
201 $value "TLOAD-VERBOSE-LIBS" 1
202 $value "TLOAD-VERBOSE" 0
203 $value "TLOAD-VERBOSE-DEFAULT" 0
204 $value "TLOAD-VERBOSE-RC" 0
207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
208 ;; moved to "10_litbase.f"
209 ;; $constant "TRUE" 1
210 ;; $constant "FALSE" 0
217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
219 ;; all things is this chain will be called before and after saving the image
220 : (startup-init) ... ; (hidden)
222 ;; this chain will be executed on abort, to cleanup the things
223 : (ABORT-CLEANUP) ( -- ) ... ; (hidden)
226 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
228 code: (TLS-BASE-ADDR) ( -- addr )
230 $if URFORTH_TLS_TYPE = URFORTH_TLS_TYPE_FS
231 ld TOS,ts:[ua_ofs_baseaddr]
239 code: (self@) ( -- value )
241 ld TOS,ts:[ua_ofs_self]
245 code: (self!) ( value -- )
246 ld ts:[ua_ofs_self],TOS
251 code: (locptr@) ( -- value )
253 ld TOS,ts:[ua_ofs_locptr]
257 code: (locptr!) ( value -- )
258 ld ts:[ua_ofs_locptr],TOS