-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeps430FR.s43
188 lines (160 loc) · 7.02 KB
/
deps430FR.s43
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
; CPU and Model Dependencies - MSP430FR5739 ; M.Kalus Juli 2011
; Template was: deps430f1611.s43
; for TI MSP430F1611 by B. Rodriguez 4 Jan 09
; ----------------------------------------------------------------------
; CamelForth for the Texas Instruments MSP430 FRAM Familiy.
; (c) 2009 Bradford J. Rodriguez.
;
; This program 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.
;
; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;
; Commercial inquiries should be directed to the author at
; 115 First St., #105, Collingwood, Ontario L9Y 4W3 Canada
; or via email to bj@camelforth.com
; ----------------------------------------------------------------------
; NOTES
; Forth words are documented as follows:
;x NAME stack -- stack description
; where x=C for ANS Forth Core words, X for ANS
; Extensions, Z for internal or private words.
;
; Indirect-Threaded Forth model for T.I. MSP430
; cell size is 16 bits (2 bytes)
; char size is 8 bits (1 byte)
; address unit is 8 bits (1 byte), i.e., addresses are byte-aligned.
; ----------------------------------------------------------------------
; REVISION HISTORY
;mk 22 jul 2011 - no Harvard, no Ixxx. Serach for ;mk
;mk Changed:
;mk ICOMMA to COMMA
;mk ISTORE to STORE
;mk IHERE to HERE
;mk IALLOT to ALLOT
; ----------------------------------------------------------------------
; ALIGNMENT AND PORTABILITY OPERATORS
; Many of these are synonyms for other words,
; and so are defined as CODE words.
;C ALIGN -- align HERE
; IHERE 1 AND IALLOT ;
HEADER ALIGNN,5,'ALIGN',DOCOLON
;mk DW IHERE,lit,1,ANDD,IALLOT,EXIT
DW HERE,lit,1,ANDD,ALLOT,EXIT
;C ALIGNED addr -- a-addr align given addr
; DUP 1 AND + ;
HEADER ALIGNED,7,'ALIGNED',DOCOLON
DW DUP,lit,1,ANDD,PLUS,EXIT
;Z CELL -- n size of one cell
HEADER CELL,4,'CELL',DOCON
dw 2
;C CELL+ a-addr1 -- a-addr2 add cell size
; 2 + ;
HEADER CELLPLUS,5,'CELL+',DOCODE
ADD #2,TOS
JMP donext
;C CELLS n1 -- n2 cells->adrs units
HEADER CELLS,5,'CELLS',TWOSTAR+2
;C CHAR+ c-addr1 -- c-addr2 add char size
HEADER CHARPLUS,5,'CHAR+',ONEPLUS+2
;C CHARS n1 -- n2 chars->adrs units
HEADER CHARS,5,'CHARS',donoop
;C >BODY xt -- a-addr adrs of CREATE data
; 2+ ; 8086 (3 byte CALL)
HEADER TOBODY,5,'>BODY',CELLPLUS+2
;X COMPILE, xt -- append execution token
; I called this word ,XT before I discovered that it is defined in the
; ANSI standard as COMPILE,. On a DTC Forth this simply appends xt
; (like , ) but on an STC Forth this must append 'CALL xt'.
HEADER COMMAXT,8,'COMPILE,',DOALIAS
;mk DW ICOMMA
DW COMMA
;Z !CF adrs cfa -- set code action of a word
; I! ;
; Indirect threaded model just stores adrs in cfa field.
;mk In FRAM we may use STORE and COMMA as they are.
HEADER STORECF,3,'!CF',DOALIAS
;mk DW ISTORE
DW STORE
;Z ,CF adrs -- append a code field
; IHERE !CF 2 IALLOT ; MSP430 VERSION (2 bytes)
HEADER COMMACF,3,',CF',DOCOLON
;mk DW IHERE,STORECF,lit,2,IALLOT,EXIT
DW HERE,STORECF,lit,2,ALLOT,EXIT
;Z ,CALL adrs -- append a subroutine CALL
; MSP430: 128x is call, Ad=11, Dreg=0000 (PC) thus append 12B0,adrs.
HEADER COMMACALL,5,',CALL',DOCOLON
;mk DW lit,12B0h,ICOMMA,ICOMMA,EXIT
DW lit,12B0h,COMMA,COMMA,EXIT
;Z ,JMP adrs -- append an absolute 16-bit JMP (MOV #xx,PC)
; MSP430: opcode 4, Sreg=0000, Ad=0, As=11 (immed), Dreg=0000 (PC)
; thus append 4030,adrs.
HEADER COMMAJMP,4,',JMP',DOCOLON
;mk DW lit,4030h,ICOMMA,ICOMMA,EXIT
DW lit,4030h,COMMA,COMMA,EXIT
;Z !COLON -- change code field to DOCOLON
; -2 IALLOT DOCOLON-adrs ,CF ;
; This should be used immediately after CREATE.
; This is made a distinct word, because on an STC
; Forth, colon definitions have no code field.
HEADER STORCOLON,6,'!COLON',DOCOLON
DW lit,-2,ALLOT
DW lit,DOCOLON,COMMACF,EXIT
;Z ,EXIT -- append hi-level EXIT action
; ['] EXIT ,XT ;
; This is made a distinct word, because on an STC
; Forth, it appends a RET instruction, not an xt.
HEADER CEXIT,5,',EXIT',DOCOLON
DW lit,EXIT,COMMAXT,EXIT
; ----------------------------------------------------------------------
; CONTROL STRUCTURES
; These words allow Forth control structure words
; to be defined portably.
;Z ,BRANCH xt -- append a branch instruction
; xt is the branch operator to use, e.g. qbranch or (loop).
; It does NOT append the destination address.
; On the MSP430 this is equivalent to ,XT (above).
HEADER COMMABRANCH,7,',BRANCH',DOALIAS
;mk DW ICOMMA
DW COMMA
;Z ,DEST dest -- append a branch address
; IHERE - , ;
; This appends the given destination address to the branch instruction.
; The MSP430 uses relative addressing from the location of the offset cell,
; i.e., to branch to FOO the offset cell at $ contains FOO-$.
HEADER COMMADEST,5,',DEST',DOCOLON
;mk DW IHERE,MINUS,ICOMMA,EXIT
DW HERE,MINUS,COMMA,EXIT
;Z !DEST dest adrs -- change a branch dest'n
; TUCK - SWAP I! ;
; Changes the destination address found at 'adrs' to the given 'dest'.
; The MSP430 uses relative addressing from the location of the offset cell,
; i.e., to branch to FOO the offset cell at $ contains FOO-$.
HEADER STOREDEST,5,'!DEST',DOCOLON
;mk DW TUCK,MINUS,SWAP,ISTORE,EXIT
DW TUCK,MINUS,SWAP,STORE,EXIT
;Z ,NONE -- append a null destination (Flashable)
; CELL IALLOT ;
; When compiling in Flash ROM a branch to be resolved later, we must
; skip the cell so that it can be programmed at a later time.
; In general Flash memory can only be written once!
; ,NONE should be used wherever !DEST will resolve the branch.
HEADER COMMANONE,5,',NONE',DOCOLON
DW CELL,ALLOT,EXIT
; ----------------------------------------------------------------------
; HEADER STRUCTURE
; The structure of the Forth dictionary headers (name, link, immediate
; flag, and "smudge" bit) does not necessarily differ across CPUs. This
; structure is not easily factored into distinct "portable" words;
; instead, it is implicit in the definitions of FIND and CREATE, and
; also in NFA>LFA, NFA>CFA, IMMED?, IMMEDIATE, HIDE, and REVEAL.
; These words must be (substantially) rewritten if either the header
; structure or its inherent assumptions are changed.