-
Notifications
You must be signed in to change notification settings - Fork 9
/
m3forth.spf
102 lines (78 loc) · 2.67 KB
/
m3forth.spf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
\ m3forth
DECIMAL
C" 0.5.1" CONSTANT _VERSION
.( m3forth by Oleg Voronin, David Kuehling 2013-2018. Version )
_VERSION COUNT TYPE CR
S" lib/include/double.f" INCLUDED
2VARIABLE FNAME \ program file name
FNAME 2!
2VARIABLE FDEVICE \ device file name
FDEVICE 2!
S" src/cross.spf" INCLUDED
S" lib/include/place.f" INCLUDED
S" src/hex.spf" INCLUDED
CREATE FILENAME 255 ALLOT \ temp buffer
\ ================= device
S" devices/devices.spf" INCLUDED \ device types
FNAME 2@ FILENAME PLACE
S" .elf" FILENAME +PLACE
\ enable generation of word headers if you want to run a full forth-interpreter inside the target system!
INTERPRETER
O_HEADERS INVERT HEADLESS !
FDEVICE 2@ INCLUDED \ include device file, start generating debug info
HOST 'RAMBASE INTERPRETER EQU 'RAMBASE HOST
\ compile asm primitives into cdata space
S" src/prims.spf" INCLUDED
\ now compile the higher-level code written as forth definitions
S" src/kernel.spf" INCLUDED
O_INTERPRETER [IF]
\ execute and build words on target
S" src/interpreter.spf" INCLUDED
[THEN]
HOST FNAME 2@ INCLUDED \ include program file
TARGET UDATA HERE HALIGNED DP !
( * finalize firmware image and add bootup code. do not touch. * )
\ freeze the IDATA section by copying it into a 'self-extracting' image in
\ CDATA space. Running the forth-word of the image, restores the IDATA
\ section at run-time
IDATA IRAM SECTION-IMAGE: IDATA-IMAGE
\ after freezing the image, changes to idata variables do not take effect.
\ this has the side-effect that any words added hereafter, won't be linked
\ into the dictionary (but you can still run the code, if it resides in cdata
\ space)
\ INTERPRETER HEADLESS ON \ headers are a waste of time
\ forth code entry point. note: return stack not yet set up
TARGET CDATA HEX
: (COLD)
IDATA-IMAGE \ initialize IRAM
MAIN
BEGIN AGAIN
;
\ definition for reset interrupt: call into forth interpreter at (cold)
CDATA TARGET LABEL RESET
STACK-BOTTOM fsp #mov \ set data stack pointer
RSTACK-BOTTOM tmp #mov \ set return stack pointer
tmp sp mov
'RAMBASE rambase #mov \ set rambase pointer
0 # r9 movw
-1 # r10 movs
' (COLD) BNARROW,
END-LABEL
\ rewrite reset IRQ entry to point to the above reset code
RESET 1+ RESET_IRQ !
( * done. now the cdata image can be dumped. * )
TARGET HERE CURRENT-SECTION-START HOST - DWARF_END \ elf file created
HOST
FNAME 2@ FILENAME PLACE
S" .bin" FILENAME +PLACE
INTERPRETER CDATA FLASH HOST FILENAME COUNT
INTERPRETER DUMP-SECTION \ create binary file
O_HEX [IF]
FNAME 2@ FILENAME PLACE
S" .hex" FILENAME +PLACE
TARGET HERE SECTION-START HOST TUCK - FILENAME COUNT HEX-SAVE \ create hex file
[THEN]
INTERPRETER
.SUMMARY
.STACK
BYE