-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.inc
242 lines (208 loc) · 6.55 KB
/
macros.inc
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//---------------------------------------------------------------------------
// Copyright Jacques Deschênes 2021
// This file is part of stm32-tbi
//
// stm32-tbi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// stm32-tbi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY// without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with stm32-tbi. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
/********************
* Version control
*******************/
.equ VER , 0x01 /*major release version */
.equ EXT , 0x00 /*minor extension */
/* registers alias */
T0 .req r0 // temporary register
T1 .req r1 // temporary register
T2 .req r2 // temporary register
T3 .req r3 // temporary register
UP .req r4 // user variables pointer
WP .req r5 // working register
TOS .req r6 // top of data stack
DSP .req r7 // data stack pointer
RSP .req r8 // return stack pointer
INX .req r10 // INEXT address
// IP .req r12 // VM instruction pointer
/* beyond Jupiter specific constants */
.equ LED_GPIO, GPIOC_BASE_ADR
.equ LED_PIN, 13
.equ UART, USART1_BASE_ADR
/* Forth specific constants */
// exception stack is at RAM_END and reserve 128 bytes
.equ RPP , RAM_END-128 /*top of return stack (RP0) reserve 128 bytes growing down */
.equ TIBB , RPP-208 /*terminal input buffer (TIB) reserve 80 bytes */
.equ TIB_SIZE, 80 // 80 bytes, input transaction buffer size.
.equ SPP , RPP-208 /*top of data stack (SP0) groing down */
.equ VID_BUFF, SPP-128-32000 /* video buffer */
.equ WB_BUFF, VID_BUFF-4096 /* flash memory write back buffer */
.equ UPP , RAM_ADR /* start of user area (UP0) */
.equ DTOP, RAM_ADR+0x512
.equ DEND , WB_BUFF-4 /*usable RAM end */
.equ MAPOFFSET, RAM_ADR-0x8000200
.equ COMPO , 0x040 /*lexicon compile only */
.equ IMEDD , 0x080 /*lexicon immediate bit */
.equ MASKK , 0x0FFFFFF1F /*lexicon bit mask, allowed for Chineze character */
.equ CELLL , 4 /*size of a cell */
.equ BASEE , 10 /*default radix */
.equ VOCSS , 8 /*depth of vocabulary stack */
.equ BKSPP , 8 /*backspace */
.equ LF , 10 /*line feed */
.equ CRR , 13 /*carriage return */
.equ ERR , 27 /*error escape */
.equ TIC , 39 /*tick */
/*************************************
system variables offset from UPP
*************************************/
.equ RNDSEED, 4 // prng seed
.equ TICKS, RNDSEED+4 // millseconds counter
.equ CD_TIMER, TICKS+4 // count down timer
.equ BOOT, CD_TIMER+4 // boot program address
.equ STDIN, BOOT+4 //character ouput device
.equ STDOUT, STDIN+4 // character input device
.equ NBASE, STDOUT+4 // numeric conversion base
.equ BCHAR, NBASE+4 // display base character flag
.equ TMP, BCHAR+4 // temporary variable
.equ CSPAN, TMP+4 // character count received by expect
.equ TOIN, CSPAN+4 // >IN parse pointer in TIB
.equ SRC, TOIN+4 // SOURCE
.equ NTIBB, SRC // #TIB characters in TIB
.equ TIBUF, SRC+4 // TIB buffer address
.equ SRCID, TIBUF+4 // evaluation source string or user interface
.equ EVAL, SRCID+4 // eval|compile vector
.equ VHOLD, EVAL+4 // hold pointer
.equ CTXT, VHOLD+4 // context pointer
.equ FORTH_CTOP, CTXT+4 // flash free dictionary address
.equ USER_CTOP, FORTH_CTOP+4 // ram free dictionary address
.equ LASTN, USER_CTOP+4 // last word in dictionary link nfa
.equ RX_QUEUE_SIZE, 16 // uart_rx queue size 16 characters
.equ RX_QUEUE, LASTN+4 // rx queue
.equ RX_HEAD, RX_QUEUE+RX_QUEUE_SIZE // queue head indice
.equ RX_TAIL, RX_HEAD+4 // queue tail indice
.equ VID_CNTR, RX_TAIL+4 // video line counter
.equ VID_STATE, VID_CNTR+4 // video field,ODD=0,EVEN=1
.equ VID_FIELD, VID_STATE+4 // VSYNC,PRE_VID,VID,POST_VID
.equ VID_BUFFER, VID_FIELD+4 // video buffer address
.equ KBD_STRUCT, VID_BUFFER+4 // keyboard structure
.equ KBD_QUEUE_SIZE, 16
.equ KBD_QUEUE, KBD_STRUCT+4
.equ KBD_QHEAD,KBD_QUEUE+KBD_QUEUE_SIZE
.equ KBD_QTAIL,KBD_QHEAD+4
.equ ROW,KBD_QTAIL+4
.equ COL,ROW+4
.equ BK_COLOR,COL+4
.equ PEN_COLOR,BK_COLOR+4
.equ VFPSW, PEN_COLOR+4
.equ VFBASE, VFPSW+4
.equ BEEP_DTMR, VFBASE+4 // BEEP duration timer
.equ CSTATE, BEEP_DTMR+4 // compilation state
/***********************************************
* MACROS
* Assemble inline direct threaded code ending.
***********************************************/
.macro _CALL fn /* low level routine call */
PUSH {LR}
BL \fn
POP {LR}
.endm
.macro _RET /* exit sub-routine */
BX LR
.endm
// dictionary header
.macro _HEADER label, nlen, name
.word LINK
.equ LINK , .
_\label: .byte \nlen // name field
.ascii "\name"
.p2align 2
\label: // code field
.endm
// local function header
.macro _FUNC label
.section .text, "ax", %progbits
.p2align 2
.type \label, %function
\label:
.endm
// global function header
.macro _GBL_FUNC label
.global \label
_FUNC \label
.endm
// load large constant to register
.macro _MOV32 r, value
mov \r,#(\value&0xffff)
movt \r,#(\value>>16)
.endm
.macro _NEXT /* direct jump INEXT */
B INEXT
.endm
.macro _NEST /*start high level word */
BX INX
NOP.N
.endm
.macro _ADR label
.word 1+\label
.endm
.macro _UNNEST /*end high level word */
_ADR UNNEST
.endm
.macro _DOLIT u /*long literals */
_ADR DOLIT
.word \u
.endm
.macro _DOTQP len, text
_ADR DOTQP
.byte \len
.ascii "\text"
.p2align 2
.endm
// POSTPONE COMPILE
.macro _COMPI name
_DOLIT \name + 1
_ADR COMMA
.endm
.macro _ABORQ len,name
_ADR ABORQ
.byte \len
.ascii "\name"
.p2align 2
.endm
.macro _BRAN label
_ADR BRAN
.word \label
.endm
.macro _QBRAN label
_ADR QBRAN
.word \label
.endm
.macro _TBRAN label
_ADR TBRAN
.word \label
.endm
.macro _DONXT label
_ADR DONXT
.word \label
.endm
.macro _PUSH /*push TOS on data stack*/
STR TOS,[DSP,#-4]!
.endm
.macro _POP /*pop data stack to TOS */
LDR TOS,[DSP],#4
.endm
// calling a colon word
// from a code word
.macro _CALL_COLWORD target
ldr WP,=\target
orr WP,#1
b \target
.endm