Annotation of gforth/arch/mips/asm.fs, revision 1.7

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: 
1.7     ! anton      23: get-current
1.4       anton      24: also assembler definitions
                     25: 
1.1       anton      26: $20 constant asm-registers
                     27: 
1.3       anton      28: \ register names
                     29: 0 constant $zero
                     30: 1 constant $at
                     31: 2 constant $v0
                     32: 3 constant $v1
                     33: \ 4 constant $a0 \ commented out to avoid shadowing hex numbers
                     34: \ 5 constant $a1
                     35: \ 6 constant $a2
                     36: \ 7 constant $a3
                     37: 8 constant $t0
                     38: 9 constant $t1
                     39: 10 constant $t2
                     40: 11 constant $t3
                     41: 12 constant $t4
                     42: 13 constant $t5
                     43: 14 constant $t6
                     44: 15 constant $t7
                     45: 16 constant $s0
                     46: 17 constant $s1
                     47: 18 constant $s2
                     48: 19 constant $s3
                     49: 20 constant $s4
                     50: 21 constant $s5
                     51: 22 constant $s6
                     52: 23 constant $s7
                     53: 24 constant $t8
                     54: 25 constant $t9
                     55: 26 constant $k0
                     56: 27 constant $k1
                     57: 28 constant $gp
                     58: 29 constant $sp
                     59: 30 constant $s8
                     60: 31 constant $ra
1.1       anton      61: 
                     62: $00 constant asm-init-code
                     63: 
1.3       anton      64: $1F constant asm-bm05
                     65: $3F constant asm-bm06
                     66: $FFFF constant asm-bm10
                     67: $3FFFFFF constant asm-bm1A
1.1       anton      68: 
                     69: : asm-expand ( x -- x )
                     70:     dup $0000ffff > if
                     71:        $ffff0000 or
                     72:     endif ;
                     73: 
                     74: : asm-op ( n -- code )
                     75:     asm-bm06 and $1a lshift ;
                     76: 
                     77: : asm-rs ( n code -- code )
                     78:     swap asm-bm05 and $15 lshift or ;
                     79: 
                     80: : asm-rt ( n code -- code )
                     81:     swap asm-bm05 and $10 lshift or ;
                     82: 
                     83: : asm-imm ( n code -- code )
                     84:     swap asm-bm10 and or ;
1.7     ! anton      85: ' asm-imm alias asm-uimm
1.1       anton      86: ' asm-imm alias asm-offset
                     87: 
                     88: : asm-target ( n code -- code )
                     89:     swap 2 rshift asm-bm1A and or ;
                     90: 
                     91: : asm-rd ( n code -- code )
                     92:     swap asm-bm05 and $b lshift or ;
                     93: 
                     94: : asm-shamt ( n code -- code )
                     95:     swap asm-bm05 and $6 lshift or ;
                     96: ' asm-shamt alias asm-sa
                     97: 
                     98: : asm-funct ( n code -- code )
                     99:     swap asm-bm06 and or ;
                    100: 
1.3       anton     101: : asm-special ( code1 -- code2 )
                    102:     asm-init-code asm-funct ;
                    103: 
1.1       anton     104: \ ***** I-types
1.3       anton     105: : asm-I-rt,imm ( code -- )
                    106:     create ,
                    107: does> ( rt imm -- )
                    108:     @ asm-imm asm-rt , ;
                    109: 
1.7     ! anton     110: : asm-I-rt,uimm ( code -- )
        !           111:     create ,
        !           112: does> ( rt uimm -- )
        !           113:     @ asm-uimm asm-rt , ;
        !           114: 
1.3       anton     115: : asm-I-rs,imm ( code -- )
                    116:     create ,
                    117: does> ( rs imm -- )
                    118:     @ swap 2 rshift swap asm-imm asm-rs , ;
                    119: 
                    120: : asm-I-rt,rs,imm ( code -- )
                    121:     create ,
                    122: does> ( rt rs imm -- )
                    123:     @ asm-imm asm-rs asm-rt , ;
                    124: 
1.7     ! anton     125: : asm-I-rt,rs,uimm ( code -- )
        !           126:     create ,
        !           127: does> ( rt rs uimm -- )
        !           128:     @ asm-uimm asm-rs asm-rt , ;
        !           129: 
1.3       anton     130: : asm-I-rs,rt,imm ( code -- )
                    131:     create ,
                    132: does> ( rs rt imm -- )
                    133:     @ swap 2 rshift swap asm-imm asm-rt asm-rs , ;
                    134: 
                    135: : asm-I-rt,offset,rs ( code -- )
                    136:     create ,
                    137: does> ( rt offset rs -- )
                    138:     @ asm-rs asm-offset asm-rt , ;
1.1       anton     139: 
                    140: \ ***** regimm types
                    141: : asm-regimm-rs,imm ( funct -- )
                    142:     $01 asm-op asm-rt asm-I-rs,imm ;
                    143: 
                    144: \ ***** copz types 1
                    145: 
1.3       anton     146: : asm-I-imm,z ( code -- )
                    147:     create ,
                    148: does> ( imm z -- )
                    149:     @ swap asm-op or swap 2 rshift swap asm-imm , ;
1.1       anton     150: 
                    151: : asm-copz-imm ( code -- )
                    152:     $10 asm-op or asm-I-imm,z ;
                    153: 
1.3       anton     154: : asm-I-rt,offset,rs,z ( code -- )
                    155:     create ,
                    156: does> ( rt offset rs z -- )
                    157:     @ swap asm-op or asm-rs asm-offset asm-rt , ;
1.1       anton     158: 
                    159: : asm-copz-rt,offset,rs ( code -- )
                    160:     asm-op asm-I-rt,offset,rs,z ;
                    161: 
1.3       anton     162: : asm-J-target ( code -- )
                    163:     create ,
                    164: does> ( target -- )
                    165:     @ asm-target , ;
1.1       anton     166: 
                    167: \ ***** special types
1.3       anton     168: : asm-special-nothing ( code -- )
                    169:     asm-special create ,
                    170: does> ( addr -- )
                    171:     @ , ;
                    172: 
                    173: : asm-special-rd ( code -- )
                    174:     asm-special create ,
                    175: does> ( rd addr -- )
                    176:     @ asm-rd , ;
                    177: 
                    178: : asm-special-rs ( code -- )
                    179:     asm-special create ,
                    180: does> ( rs addr -- )
                    181:     @ asm-rs , ;
                    182: 
                    183: : asm-special-rd,rs ( code -- )
                    184:     asm-special create ,
                    185: does> ( rd rs addr -- )
                    186:     @ asm-rs asm-rd , ;
                    187: 
                    188: : asm-special-rs,rt ( code -- )
                    189:     asm-special create ,
                    190: does> ( rs rt addr -- )
                    191:     @ asm-rt asm-rs , ;
                    192: 
                    193: : asm-special-rd,rs,rt ( code -- )
                    194:     asm-special create ,
                    195: does> ( rd rs rt addr -- )
                    196:     @ asm-rt asm-rs asm-rd , ;
                    197: 
                    198: : asm-special-rd,rt,rs ( code -- )
                    199:     asm-special create ,
                    200: does> ( rd rt rs addr -- )
                    201:     @ asm-rs asm-rt asm-rd , ;
                    202: 
                    203: : asm-special-rd,rt,sa ( code -- )
                    204:     asm-special create ,
                    205: does> ( rd rt sa addr -- )
                    206:     @ asm-sa asm-rt asm-rd , ;
1.1       anton     207: 
                    208: \ ***** copz types 2
                    209: : asm-copz0 ( funct -- )
1.3       anton     210:     $10 $10 asm-op asm-rs asm-funct create ,
                    211: does> ( addr -- )
                    212:     @ , ;
1.1       anton     213: 
                    214: : asm-copz-rt,rd ( funct -- )
1.3       anton     215:     $10 asm-op or create ,
                    216: does> ( rt rd z addr -- )
                    217:     @ swap asm-op or asm-rd asm-rt , ;
1.1       anton     218: 
                    219: : nop, ( -- )
1.3       anton     220:     0 , ;
1.1       anton     221: 
1.5       anton     222: include ./insts.fs
1.1       anton     223: 
                    224: : move, ( rd rs -- )
1.3       anton     225:     $zero addu, ;
1.1       anton     226: 
                    227: : abs, ( rd rs -- )
                    228:     dup $0008 bgez,
                    229:     2dup move,
1.3       anton     230:     $zero swap subu, ;
1.1       anton     231: 
                    232: : neg, ( rd rs -- )
1.3       anton     233:     $zero swap subu, ;
1.1       anton     234: 
                    235: : negu, ( rd rs -- )
1.3       anton     236:     $zero swap subu, ;
1.1       anton     237: 
                    238: : not, ( rd rs -- )
1.3       anton     239:     $zero nor, ;
1.1       anton     240: 
                    241: : li, ( rd imm -- )
                    242:     dup 0= if
1.3       anton     243:        drop dup $zero = if
1.1       anton     244:            drop nop, assert( false )
                    245:        else
1.3       anton     246:            $zero move,
1.1       anton     247:        endif
                    248:     else
                    249:        dup $8000 u< if
1.3       anton     250:            $zero swap addiu,
1.1       anton     251:        else
                    252:            dup $10000 u< if
1.3       anton     253:                $zero swap ori,
1.1       anton     254:            else
                    255:                dup $ffff and 0= if
                    256:                    $10 rshift lui,
                    257:                else
                    258:                    dup $ffff8000 and $ffff8000 = if
1.3       anton     259:                        $zero swap addiu,
1.1       anton     260:                    else
                    261:                        2dup $10 rshift lui,
                    262:                        over swap ori,
                    263:                    endif
                    264:                endif
                    265:            endif
                    266:        endif
                    267:     endif ;
                    268: 
                    269: : blt, ( rs rt imm -- )                \ <
1.3       anton     270:     >r $at rot rot slt,
                    271:     $at $zero r> bne, ;
1.1       anton     272: 
                    273: : ble, ( rs rt imm -- )                \ <=
1.3       anton     274:     >r $at rot rot swap slt,
                    275:     $at $zero r> beq, ;
1.1       anton     276: 
                    277: : bgt, ( rs rt imm -- )                \ >
1.3       anton     278:     >r $at rot rot swap slt,
                    279:     $at $zero r> bne, ;
1.1       anton     280: 
                    281: : bge, ( rs rt imm -- )                \ >=
1.3       anton     282:     >r $at rot rot slt,
                    283:     $at $zero r> beq, ;
1.1       anton     284: 
                    285: : bltu, ( rs rt imm -- )       \ < unsigned
1.3       anton     286:     >r $at rot rot sltu,
                    287:     $at $zero r> bne, ;
1.1       anton     288: 
                    289: : bleu, ( rs rt imm -- )       \ <= unsigned
1.3       anton     290:     >r $at rot rot swap sltu,
                    291:     $at $zero r> beq, ;
1.1       anton     292: 
                    293: : bgtu, ( rs rt imm -- )       \ > unsigned
1.3       anton     294:     >r $at rot rot swap sltu,
                    295:     $at $zero r> bne, ;
1.1       anton     296: 
                    297: : bgeu, ( rs rt imm -- )       \ >= unsigned
1.3       anton     298:     >r $at rot rot sltu,
                    299:     $at $zero r> beq, ;
1.1       anton     300: 
1.4       anton     301: previous
1.7     ! anton     302: set-current

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>