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
8 $constant
"ALIGN-WORD-HEADERS?" URFORTH_ALIGN_HEADERS
10 $constant
"URFORTH-LEVEL" 1
12 ;; bit
15 is
"beta" flag
13 ;; this gives us versions up
to 255.255.32767
14 $constant
"URFORTH-VERSION" 0x00_
01_
0001
16 $constant
"URFORTH-OS" URFORTH_OS
18 $constant
"URFORTH-OS-LINUX/X86" URFORTH_LINUX_X86
19 $constant
"URFORTH-OS-WIN32" URFORTH_WIN32
21 ;; should segfault handler throw an error instead of exiting?
22 $value
"(TRAP-THROW)" urfsegfault_throw_error
25 ;; print stack trace before doing an action?
26 $value
"(TRAP-STACKTRACE)" urfsegfault_stacktrace
29 ;; is multithreading active?
30 ;; this will be set
to `true`
if at least one thread was created
31 ;; this will never be reset
(except in SAVEd images
)
32 $value
"(MT-ACTIVE?)" 0
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;; user area size is
4KB
(hardcoded
)
41 $label ua_default_values
42 rb URFORTH_MAX_USERAREA_SIZE
45 ;; will be patched by the startup
/thread creation code
46 ;; it should always be at zero offset
47 $uservar
"(USER-BASE-ADDR)" ua_ofs_baseaddr
0
50 ;; this will be set by thread creation code
51 ;; this is the full size of tls
+stacks allocation
, that can be used in OS
:MUNMAP
52 $uservar
"(USER-FULL-SIZE)" ua_ofs_fullsize
0
56 ;; patched by the startup code
57 $uservar
"(MAIN-THREAD?)" ua_ofs_is_main_thread
0
60 $uservar
"SP0" ua_ofs_sp0
0
61 $uservar
"RP0" ua_ofs_rp0
0
62 ;; default size
for thread stacks
(note
: main thread has different
-sized stacks
)
63 ;; with those sizes
, it rougly fits into one
4KB page
(including userarea
)
64 $uservar
"#SP" ua_ofs_spsize
500
65 $uservar
"#RP" ua_ofs_rpsize
240
67 $uservar
"BASE" ua_ofs_base
10
69 ;; this can be used in various OOP implementations
70 ;; the kernel doesn
't use it
71 ;; the reason it is there is because THROW will save/restore it
72 $uservar "(SELF)" ua_ofs_self 0
75 ;; this can be used in various locals implementations
76 ;; the kernel doesn't use it
(yet
)
77 ;; the reason it is there is because THROW will save
/restore it
78 $uservar
"(LOCPTR)" ua_ofs_locptr
0
81 $uservar
"PAD-AREA" ua_ofs_padarea
0
83 ;; this will be patched by the startup
/thread creation code
84 $uservar
"(DEFAULT-TIB)" ua_ofs_deftib
0
87 $constant
"(DEFAULT-#TIB)" 4090
91 ;; default user area values
92 ;; this will be created and set by the metacompiler
93 $constant
"(USER-AREA-DEFAULT)" ua_default_values
95 $constant
"(USER-AREA-MAX-SIZE)" URFORTH_MAX_USERAREA_SIZE
97 $variable
"(USER-AREA-USED)" ur_userarea_default_size
100 $
if URFORTH_TLS_TYPE
= URFORTH_TLS_TYPE_FS
101 $value
"(USER-TLS-ENTRY-INDEX)" 0
106 $constant
"HAS-TLS?" URFORTH_TLS_TYPE
109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
110 ;; pad is allocated with BRK
; "#PAD-AREA-RESV" is the space BEFORE
"PAD-AREA"
111 ;; $variable
"PAD-AREA" 0 ;; will be set by startup code
112 $constant
"#PAD-AREA-RESV" 2040
113 $constant
"#PAD-AREA" 2048
116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 ;; optimise branch
to branch
to branch?
120 $value
"(OPT-BRANCHES?)" 1
123 ;; should optimiser replace alias calls with aliased words?
124 ;; this doesn
't affect REPLACED words, tho
125 ;; actually, for this to work, the word size should be exactly 5/8 bytes, and
127 $value "(OPT-ALIASES?)" 0
130 ;; should replaced words be rerouted in the same ways as aliases?
131 ;; this may break further replacing, so it is turned off
132 ;; not yet implemented
133 ;;$value "(OPT-REPLACES?)" 0
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
140 $variable "DP" urforth_code_end
142 $variable "DP-LAST-ADDR" urforth_dict_lastaddr ;; last valid dictionary address
144 $variable "DP-PROTECTED" urforth_dict_protected ;; first unprotected address
147 ;; this is used to temporarily change HERE
148 ;; MUST be inside "(DP-TEMP-BASE)", because first dp-temp-base cell is used to check size
149 $variable "DP-TEMP" 0
151 $variable "(DP-TEMP-BASE)" 0 ;; first cell is size
153 $variable "(DP-TEMP-BUF)" 0
156 ;; voclink always points to another voclink (or contains 0)
157 $variable "(VOC-LINK)" forth_wordlist_voclink ;; voclink always points to wordlist voclink (or contains 0)
161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
162 ;; BSS reserve on SAVE
163 $value "(SAVE-BSS-RESERVE)" URFORTH_BSS_RESERVE
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
174 $constant "HAS-DEBUGGER?" URFORTH_DEBUG
175 $constant "ALIGN-HEADERS?" URFORTH_ALIGN_HEADERS
176 $constant "ALIGN-CFA?" URFORTH_ALIGN_CFA
177 $constant "ALIGN-PFA?" URFORTH_ALIGN_PFA
178 $constant "(#CFA)" URFORTH_CFA_SIZE
181 $constant "(CODE-BASE-ADDR)" urforth_code_base_addr
184 ;; two dwords -- disk and memory
185 $constant "(ELF-HEADER-CODE-SIZE-ADDR)" elfhead_codesize_addr
188 $constant "(ELF-DYNAMIC?)" URFORTH_DYNAMIC_BINARY
191 $if URFORTH_DYNAMIC_BINARY
192 $constant "(CODE-IMPORTS-ADDR)" elfhead_impstart
195 $constant "(CODE-IMPORTS-SIZE)" elfhead_implen
199 $constant "(CODE-ENTRY-ADDR)" urforth_entry_point
203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
204 $value "TLOAD-VERBOSE-LIBS" 1
205 $value "TLOAD-VERBOSE" 0
206 $value "TLOAD-VERBOSE-DEFAULT" 0
207 $value "TLOAD-VERBOSE-RC" 0
210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
211 ;; moved to "10_litbase.f"
212 ;; $constant "TRUE" 1
213 ;; $constant "FALSE" 0
220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
222 ;; all things is this chain will be called before and after saving the image
223 : (startup-init) ... ; (hidden)
225 ;; this chain will be executed on abort, to cleanup the things
226 : (ABORT-CLEANUP) ( -- ) ... ; (hidden)
229 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
231 code: (TLS-BASE-ADDR) ( -- addr )
233 $if URFORTH_TLS_TYPE = URFORTH_TLS_TYPE_FS
234 ld TOS,ts:[ua_ofs_baseaddr]
242 code: (self@) ( -- value )
244 ld TOS,ts:[ua_ofs_self]
248 code: (self!) ( value -- )
249 ld ts:[ua_ofs_self],TOS
254 code: (locptr@) ( -- value )
256 ld TOS,ts:[ua_ofs_locptr]
260 code: (locptr!) ( value -- )
261 ld ts:[ua_ofs_locptr],TOS