Annotation of gforth/arch/mips/asm.fs, revision 1.6
1.1 anton 1: \ asm.fs assembler file (for MIPS R3000)
2: \
3: \ Copyright (C) 1995-97 Martin Anton Ertl, Christian Pirker
4: \
5: \ This file is part of RAFTS.
6: \
7: \ RAFTS is free software; you can redistribute it and/or
8: \ modify it under the terms of the GNU General Public License
9: \ as published by the Free Software Foundation; either version 2
10: \ of the License, or (at your option) any later version.
11: \
12: \ This program is distributed in the hope that it will be useful,
13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: \ GNU General Public License for more details.
16: \
17: \ You should have received a copy of the GNU General Public License
18: \ along with this program; if not, write to the Free Software
19: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20:
1.4 anton 21: require code.fs
22:
23: also assembler definitions
24:
1.1 anton 25: $20 constant asm-registers
26:
1.3 anton 27: \ register names
28: 0 constant $zero
29: 1 constant $at
30: 2 constant $v0
31: 3 constant $v1
32: \ 4 constant $a0 \ commented out to avoid shadowing hex numbers
33: \ 5 constant $a1
34: \ 6 constant $a2
35: \ 7 constant $a3
36: 8 constant $t0
37: 9 constant $t1
38: 10 constant $t2
39: 11 constant $t3
40: 12 constant $t4
41: 13 constant $t5
42: 14 constant $t6
43: 15 constant $t7
44: 16 constant $s0
45: 17 constant $s1
46: 18 constant $s2
47: 19 constant $s3
48: 20 constant $s4
49: 21 constant $s5
50: 22 constant $s6
51: 23 constant $s7
52: 24 constant $t8
53: 25 constant $t9
54: 26 constant $k0
55: 27 constant $k1
56: 28 constant $gp
57: 29 constant $sp
58: 30 constant $s8
59: 31 constant $ra
1.1 anton 60:
61: $00 constant asm-init-code
62:
1.3 anton 63: $1F constant asm-bm05
64: $3F constant asm-bm06
65: $FFFF constant asm-bm10
66: $3FFFFFF constant asm-bm1A
1.1 anton 67:
68: : asm-expand ( x -- x )
69: dup $0000ffff > if
70: $ffff0000 or
71: endif ;
72:
73: : asm-op ( n -- code )
74: asm-bm06 and $1a lshift ;
75:
76: : asm-rs ( n code -- code )
77: swap asm-bm05 and $15 lshift or ;
78:
79: : asm-rt ( n code -- code )
80: swap asm-bm05 and $10 lshift or ;
81:
82: : asm-imm ( n code -- code )
83: swap asm-bm10 and or ;
84: ' asm-imm alias asm-offset
85:
86: : asm-target ( n code -- code )
87: swap 2 rshift asm-bm1A and or ;
88:
89: : asm-rd ( n code -- code )
90: swap asm-bm05 and $b lshift or ;
91:
92: : asm-shamt ( n code -- code )
93: swap asm-bm05 and $6 lshift or ;
94: ' asm-shamt alias asm-sa
95:
96: : asm-funct ( n code -- code )
97: swap asm-bm06 and or ;
98:
1.3 anton 99: : asm-special ( code1 -- code2 )
100: asm-init-code asm-funct ;
101:
1.1 anton 102: \ ***** I-types
1.3 anton 103: : asm-I-rt,imm ( code -- )
104: create ,
105: does> ( rt imm -- )
106: @ asm-imm asm-rt , ;
107:
108: : asm-I-rs,imm ( code -- )
109: create ,
110: does> ( rs imm -- )
111: @ swap 2 rshift swap asm-imm asm-rs , ;
112:
113: : asm-I-rt,rs,imm ( code -- )
114: create ,
115: does> ( rt rs imm -- )
116: @ asm-imm asm-rs asm-rt , ;
117:
118: : asm-I-rs,rt,imm ( code -- )
119: create ,
120: does> ( rs rt imm -- )
121: @ swap 2 rshift swap asm-imm asm-rt asm-rs , ;
122:
123: : asm-I-rt,offset,rs ( code -- )
124: create ,
125: does> ( rt offset rs -- )
126: @ asm-rs asm-offset asm-rt , ;
1.1 anton 127:
128: \ ***** regimm types
129: : asm-regimm-rs,imm ( funct -- )
130: $01 asm-op asm-rt asm-I-rs,imm ;
131:
132: \ ***** copz types 1
133:
1.3 anton 134: : asm-I-imm,z ( code -- )
135: create ,
136: does> ( imm z -- )
137: @ swap asm-op or swap 2 rshift swap asm-imm , ;
1.1 anton 138:
139: : asm-copz-imm ( code -- )
140: $10 asm-op or asm-I-imm,z ;
141:
1.3 anton 142: : asm-I-rt,offset,rs,z ( code -- )
143: create ,
144: does> ( rt offset rs z -- )
145: @ swap asm-op or asm-rs asm-offset asm-rt , ;
1.1 anton 146:
147: : asm-copz-rt,offset,rs ( code -- )
148: asm-op asm-I-rt,offset,rs,z ;
149:
1.3 anton 150: : asm-J-target ( code -- )
151: create ,
152: does> ( target -- )
153: @ asm-target , ;
1.1 anton 154:
155: \ ***** special types
1.3 anton 156: : asm-special-nothing ( code -- )
157: asm-special create ,
158: does> ( addr -- )
159: @ , ;
160:
161: : asm-special-rd ( code -- )
162: asm-special create ,
163: does> ( rd addr -- )
164: @ asm-rd , ;
165:
166: : asm-special-rs ( code -- )
167: asm-special create ,
168: does> ( rs addr -- )
169: @ asm-rs , ;
170:
171: : asm-special-rd,rs ( code -- )
172: asm-special create ,
173: does> ( rd rs addr -- )
174: @ asm-rs asm-rd , ;
175:
176: : asm-special-rs,rt ( code -- )
177: asm-special create ,
178: does> ( rs rt addr -- )
179: @ asm-rt asm-rs , ;
180:
181: : asm-special-rd,rs,rt ( code -- )
182: asm-special create ,
183: does> ( rd rs rt addr -- )
184: @ asm-rt asm-rs asm-rd , ;
185:
186: : asm-special-rd,rt,rs ( code -- )
187: asm-special create ,
188: does> ( rd rt rs addr -- )
189: @ asm-rs asm-rt asm-rd , ;
190:
191: : asm-special-rd,rt,sa ( code -- )
192: asm-special create ,
193: does> ( rd rt sa addr -- )
194: @ asm-sa asm-rt asm-rd , ;
1.1 anton 195:
196: \ ***** copz types 2
197: : asm-copz0 ( funct -- )
1.3 anton 198: $10 $10 asm-op asm-rs asm-funct create ,
199: does> ( addr -- )
200: @ , ;
1.1 anton 201:
202: : asm-copz-rt,rd ( funct -- )
1.3 anton 203: $10 asm-op or create ,
204: does> ( rt rd z addr -- )
205: @ swap asm-op or asm-rd asm-rt , ;
1.1 anton 206:
207: : nop, ( -- )
1.3 anton 208: 0 , ;
1.1 anton 209:
1.5 anton 210: include ./insts.fs
1.1 anton 211:
212: : move, ( rd rs -- )
1.3 anton 213: $zero addu, ;
1.1 anton 214:
215: : abs, ( rd rs -- )
216: dup $0008 bgez,
217: 2dup move,
1.3 anton 218: $zero swap subu, ;
1.1 anton 219:
220: : neg, ( rd rs -- )
1.3 anton 221: $zero swap subu, ;
1.1 anton 222:
223: : negu, ( rd rs -- )
1.3 anton 224: $zero swap subu, ;
1.1 anton 225:
226: : not, ( rd rs -- )
1.3 anton 227: $zero nor, ;
1.1 anton 228:
229: : li, ( rd imm -- )
230: dup 0= if
1.3 anton 231: drop dup $zero = if
1.1 anton 232: drop nop, assert( false )
233: else
1.3 anton 234: $zero move,
1.1 anton 235: endif
236: else
237: dup $8000 u< if
1.3 anton 238: $zero swap addiu,
1.1 anton 239: else
240: dup $10000 u< if
1.3 anton 241: $zero swap ori,
1.1 anton 242: else
243: dup $ffff and 0= if
244: $10 rshift lui,
245: else
246: dup $ffff8000 and $ffff8000 = if
1.3 anton 247: $zero swap addiu,
1.1 anton 248: else
249: 2dup $10 rshift lui,
250: over swap ori,
251: endif
252: endif
253: endif
254: endif
255: endif ;
256:
257: : blt, ( rs rt imm -- ) \ <
1.3 anton 258: >r $at rot rot slt,
259: $at $zero r> bne, ;
1.1 anton 260:
261: : ble, ( rs rt imm -- ) \ <=
1.3 anton 262: >r $at rot rot swap slt,
263: $at $zero r> beq, ;
1.1 anton 264:
265: : bgt, ( rs rt imm -- ) \ >
1.3 anton 266: >r $at rot rot swap slt,
267: $at $zero r> bne, ;
1.1 anton 268:
269: : bge, ( rs rt imm -- ) \ >=
1.3 anton 270: >r $at rot rot slt,
271: $at $zero r> beq, ;
1.1 anton 272:
273: : bltu, ( rs rt imm -- ) \ < unsigned
1.3 anton 274: >r $at rot rot sltu,
275: $at $zero r> bne, ;
1.1 anton 276:
277: : bleu, ( rs rt imm -- ) \ <= unsigned
1.3 anton 278: >r $at rot rot swap sltu,
279: $at $zero r> beq, ;
1.1 anton 280:
281: : bgtu, ( rs rt imm -- ) \ > unsigned
1.3 anton 282: >r $at rot rot swap sltu,
283: $at $zero r> bne, ;
1.1 anton 284:
285: : bgeu, ( rs rt imm -- ) \ >= unsigned
1.3 anton 286: >r $at rot rot sltu,
287: $at $zero r> beq, ;
1.1 anton 288:
1.4 anton 289: previous
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>