-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFISH_STM32F4_MACROS.h
185 lines (155 loc) · 3.69 KB
/
FISH_STM32F4_MACROS.h
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
// Valid thru v1.7.2
//#define ss // "single-step" switch for debug/shakedown testing
//------------------------------------------------------------------------------
// Inner Interpreter Macros
// Beauty is you can put any ISA in a macro and no prob till referenced!
NEXT MACRO
// ARMv7-M Thumb = .+5
ldr w, [i], #4 ; get IP->cfa to w, incr i after
// ARMv6-M Thumb = .+4
// LDM i!, {w} // get IP->cfa to w, incr i after
NEXT1
ENDM
#ifndef ss
// ARMv7-M Thumb = .+5
NEXT1 MACRO
BIC w, w, #3 ; Tested WORKS ALSO Thumb2 klooge: clear the 2 LSbits
LDR x, [w], #4 ; contents of cfa -> x, bump w to cfa+4
BX x ; w preserves cfa+4 for DOCOL's benefit
// ARMv6-M Thumb = .+4
// LDM w!, {x} // contents of cfa, (pfa), -> x, bump w to cfa+4
// BLX x // w preserves cfa+4 (pfa) for DOCOL's benefit
ENDM
// ELSE
#else
NEXT1 MACRO
LDR x, =ssNEXT1 // meta-single-step for debugging
BX x
ENDM
// LTORG
#endif
// ENDIF
TPUSH MACRO
PUSHt // push t to p, pre decrement p
NEXT
ENDM
DPUSH MACRO
PUSHw // push w to p, post decrement p
TPUSH
ENDM
//------------------------------------------------------------------------------
// FISH STACK MACRO's
// Beauty is you can put any ISA in a macro and no prob till referenced!
// Cortex M0 THUMB only does STMia and LDMia
// I (rstack value to pstack) expects POP to be post increment
// Meaning that TOS is = to current p or r
// Therefore PUSH is pre decrement
PUSHt MACRO
STR t, [p, #-4]! // Pre-increment
// SUBS p, p, #4 // push t to p, pre decrement p
// STR t, [p]
ENDM
POP2t MACRO
LDR t, [p],#4 // Post-increment
//#ifndef TOSCT
// LDR t, [p] // pop tos to t, post increment p
//#endif
// ADDS p, p, #4
ENDM
NDPOP2t MACRO // macro = copy tos to t, leave it on the stack
LDR t, [p]
ENDM
PUSHn MACRO
STR n, [p, #-4]!
// SUBS p, p, #4 // push n to p, pre decrement p
// STR n, [p]
ENDM
POP2n MACRO
LDR n, [p],#4
// LDR n, [p]
// ADDS p, p, #4
ENDM
PUSHw MACRO
STR w, [p, #-4]!
// SUBS p, p, #4 // push w to p, pre decrement p
// STR w, [p]
ENDM
POP2w MACRO
LDR w, [p],#4
// LDR w, [p]
// ADDS p, p, #4
ENDM
NDPOP2w MACRO // macro = copy tos to w, leave it on the stack
LDR w, [p]
ENDM
PUSHx MACRO
STR x, [p, #-4]!
// SUBS p, p, #4 // push x to p, pre decrement p
// STR x, [p]
ENDM
POP2x MACRO
LDR x, [p],#4
// LDR x, [p]
// ADDS p, p, #4
ENDM
NDPOP2x MACRO // macro = copy tos to w, leave it on the stack
LDR x, [p]
ENDM
PUSHi MACRO
STR i, [p, #-4]!
// SUBS p, p, #4 // push i to p, pore increment p
// STR i, [p]
ENDM
POP2i MACRO
LDR i, [p],#4
// LDR i, [p]
// ADDS p, p, #4
ENDM
PUSHt2r MACRO
STR t, [r, #-4]!
// SUBS r, r, #4 // push t to r, pre decrement r
// STR t, [r]
ENDM
PUSHi2r MACRO
STR i, [r, #-4]! ; save IP to Rstack
// SUBS r, r, #4 // push i to r, pre decrement r
// STR i, [r]
ENDM
POPr2i MACRO
LDR i, [r],#4 ; pop DOCOL'd IP from Rstack
// LDR i, [r] // pop r to i, post increment r
// ADDS r, r, #4
ENDM
//POP2p MACRO
// ENDM
//POP2PC MACRO
// ENDM
POPr2t MACRO
LDR t, [r],#4
// LDR t, [r]
// ADDS r, r, #4
ENDM
PUSHn2r MACRO
STR n, [r, #-4]!
// SUBS r, r, #4 // push t to r, pre decrement r
// STR n, [r]
ENDM
PUSHw2r MACRO
STR w, [r, #-4]!
// SUBS r, r, #4 // push w to r, pre decrement r
// STR w, [r]
ENDM
LIT2t MACRO
// as in xeq token at ToS setup for lit
LDR t, [i], #4
// LDM i!, {t} // fetch memory p points to into {t}, inc i
ENDM
POPp2w MACRO
// as in xeq token on ToS setup for exec
LDR w, [p], #4 ; xeq token at ToS
// LDM p!, {w} // fetch memory p points to into {w}, inc p
ENDM
ILK MACRO reg
; *generalized* v4th InLineKonstant
ldr reg, [i], #4 ; pre-inc IP
ENDM