Annotation of gforth/arch/mips/disasm.fs, revision 1.3

1.1       anton       1: \ disasm.fs    disassembler 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.3     ! anton      21: : disasm-illegal ( addr w -- )
        !            22:     \ disassemble illegal instruction w at addr
        !            23:     hex. ." , ( illegal inst ) " drop ;
1.2       anton      24: 
1.3     ! anton      25: : init-disasm-table ( n -- )
        !            26:     \ initialize table with n entries with disasm-illegal
        !            27:     0 ?do
        !            28:        ['] disasm-illegal ,
        !            29:     loop ;
1.2       anton      30: 
1.3     ! anton      31: create opc-table $40 init-disasm-table \ top-level decode table
        !            32: create funct-table $40 init-disasm-table \ special function table
        !            33: create regimm-table $20 init-disasm-table \ regim instructions rt field
        !            34: create copz-rs-table $20 init-disasm-table \ COPz instructions rs field
        !            35: create copz-rt-table $20 init-disasm-table \ COPz instructions rt field
        !            36: create cp0-table $40 init-disasm-table \ COP0 function table
        !            37: 
        !            38: \ fields
        !            39: 
        !            40: : disasm-op ( w -- u )
        !            41:     26 rshift ;
        !            42: 
        !            43: : disasm-rs ( w -- u )
        !            44:     21 rshift $1F and ;
        !            45: 
        !            46: : disasm-rt ( w -- u )
        !            47:     16 rshift $1f and ;
        !            48: 
        !            49: : disasm-rd ( w -- u )
        !            50:     11 rshift $1f and ;
        !            51: 
        !            52: : disasm-shamt ( w -- u )
        !            53:     \ shift amount field
        !            54:     6 rshift $1f and ;
        !            55: 
        !            56: : disasm-funct ( w -- u )
        !            57:     $3f and ;
        !            58: 
        !            59: : disasm-copz ( w -- u )
        !            60:     disasm-op 3 and ;
        !            61: 
        !            62: : disasm-imm ( w -- n )
        !            63:     $ffff and dup 15 rshift negate 15 lshift or ;
        !            64: 
        !            65: : disasm-relative ( addr n -- w )
        !            66:     \ compute printable form of relative address n relative to addr
        !            67:     nip ( + ) ;
        !            68: 
        !            69: \ disassembler central decode cascade
        !            70: 
        !            71: : disasm-inst ( addr w -- )
        !            72:     \G disassemble instruction w at addr (addr is used for computing
        !            73:     \G branch targets)
        !            74:     dup disasm-op cells opc-table + @ execute ;
        !            75: 
        !            76: : disasm-dump ( addr u -- ) \ gforth
        !            77:     \G disassemble u aus starting at addr
        !            78:     bounds u+do
        !            79:        cr ." ( " i hex. ." ) " i i @ disasm-inst
        !            80:        1 cells +loop ;
        !            81: 
        !            82: : disasm-special ( addr w -- )
        !            83:     \ disassemble inst with opcode special
        !            84:     dup disasm-funct cells funct-table + @ execute ;
        !            85: ' disasm-special 0 cells opc-table + !
        !            86: 
        !            87: : disasm-regimm ( addr w -- )
        !            88:     \ disassemble regimm inst
        !            89:     dup disasm-rt cells regimm-table + @ execute ;
        !            90: ' disasm-regimm 1 cells opc-table + !
        !            91: 
        !            92: : disasm-copz-rs ( addr w -- )
        !            93:     \ disassemble inst with opcode COPz
        !            94:     dup disasm-rs cells copz-rs-table + @ execute ;
        !            95: ' disasm-copz-rs $10 cells opc-table + !
        !            96: ' disasm-copz-rs $11 cells opc-table + !
        !            97: ' disasm-copz-rs $12 cells opc-table + !
        !            98: 
        !            99: : disasm-copz-rt ( addr w -- )
        !           100:     \ disassemble inst with opcode COPz, rs=BC
        !           101:     dup disasm-rt cells copz-rt-table + @ execute ;
        !           102: ' disasm-copz-rt $08 cells copz-rs-table + !
        !           103: 
        !           104: : disasm-cp0 ( addr w -- )
        !           105:     \ disassemble inst with opcode COPz, rs=CO
        !           106:     dup disasm-funct cells cp0-table + @ execute ;
        !           107: ' disasm-cp0 $10 cells copz-rs-table + !
        !           108: 
        !           109: \ disassemble various formats
        !           110: 
        !           111: : asm-op ( -- ) ;
        !           112: 
        !           113: : disasm-J-target ( addr w -- )
        !           114:     \ print jump target
        !           115:     $3ffffff and swap $fc000000 and or hex. ;
        !           116: 
        !           117: : asm-J-target ( u "inst" -- ; compiled code: addr w -- )
        !           118:     \ disassemble jump inst with opcode u
        !           119:     :noname POSTPONE disasm-J-target
        !           120:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           121:     swap cells opc-table + ! ;
        !           122: 
        !           123: : disasm-I-rs,rt,imm ( addr w -- )
        !           124:     dup disasm-rs .
        !           125:     dup disasm-rt .
        !           126:     disasm-imm disasm-relative . ;
        !           127: 
        !           128: : asm-I-rs,rt,imm ( u "name" -- ; compiled code: addr w -- )
        !           129:     :noname POSTPONE disasm-I-rs,rt,imm
        !           130:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           131:     swap cells opc-table + ! ;
        !           132: 
        !           133: : asm-rt ( -- ) ;
        !           134: 
        !           135: : disasm-I-rs,imm ( addr w -- )
        !           136:     \ !! does not check for correctly set rt ( should be 0 )
        !           137:     dup disasm-rs .
        !           138:     disasm-imm disasm-relative . ;
        !           139: 
        !           140: : asm-I-rs,imm ( u1 u2 "name" -- ; compiled code: addr w -- )
        !           141:     :noname POSTPONE disasm-I-rs,imm
        !           142:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           143:     swap cells opc-table + ! ;
        !           144: 
        !           145: : disasm-rt,rs,imm ( addr w -- )
        !           146:     dup disasm-rt .
        !           147:     dup disasm-rs .
        !           148:     disasm-imm .
        !           149:     drop ;
1.1       anton     150: 
1.3     ! anton     151: : asm-I-rt,rs,imm ( u "name" -- ; compiled code: addr w -- )
        !           152:     :noname POSTPONE disasm-rt,rs,imm
        !           153:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           154:     swap cells opc-table + ! ;
        !           155: 
        !           156: : disasm-rt,imm ( addr w -- )
        !           157:     dup disasm-rt .
        !           158:     disasm-imm .
1.1       anton     159:     drop ;
                    160: 
1.3     ! anton     161: : asm-I-rt,imm ( u "name" -- ; compiled code: addr w -- )
        !           162:     :noname POSTPONE disasm-rt,imm
        !           163:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           164:     swap cells opc-table + ! ;
        !           165: 
        !           166: : disasm-rt,imm,rs ( addr w -- )
        !           167:     dup disasm-rt .
        !           168:     dup disasm-imm .
        !           169:     dup disasm-rs .
        !           170:     2drop ;
        !           171: 
        !           172: : asm-I-rt,offset,rs ( u "name" -- ; compiled code: addr w -- )
        !           173:     :noname POSTPONE disasm-rt,imm,rs
        !           174:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           175:     swap cells opc-table + ! ;
        !           176: 
        !           177: : disasm-rd,rt,sa ( addr w -- )
        !           178:     dup disasm-rd .
        !           179:     dup disasm-rt .
        !           180:     dup disasm-shamt .
        !           181:     2drop ;
        !           182: 
        !           183: : asm-special-rd,rt,sa ( u "name" -- ; compiled code: addr w -- )
        !           184:     :noname POSTPONE disasm-rd,rt,sa
        !           185:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           186:     swap cells funct-table + ! ;
        !           187: 
        !           188: : disasm-rd,rt,rs ( addr w -- )
        !           189:     dup disasm-rd .
        !           190:     dup disasm-rt .
        !           191:     dup disasm-rs .
        !           192:     2drop ;
        !           193: 
        !           194: : asm-special-rd,rt,rs ( u "name" -- ; compiled code: addr w -- )
        !           195:     :noname POSTPONE disasm-rd,rt,rs
        !           196:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           197:     swap cells funct-table + ! ;
        !           198: 
        !           199: : disasm-rs. ( addr w -- )
        !           200:     dup disasm-rs .
        !           201:     2drop ;
        !           202: 
        !           203: : asm-special-rs ( u "name" -- ; compiled code: addr w -- )
        !           204:     :noname POSTPONE disasm-rs.
        !           205:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           206:     swap cells funct-table + ! ;
        !           207: 
        !           208: : disasm-rd,rs ( addr w -- )
        !           209:     dup disasm-rd .
        !           210:     dup disasm-rs .
        !           211:     2drop ;
        !           212: 
        !           213: : asm-special-rd,rs ( u "name" -- ; compiled code: addr w -- )
        !           214:     :noname POSTPONE disasm-rd,rs
        !           215:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           216:     swap cells funct-table + ! ;
        !           217: 
        !           218: : asm-special-nothing ( u "name" -- ; compiled code: addr w -- )
        !           219:     :noname POSTPONE 2drop
        !           220:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           221:     swap cells funct-table + ! ;
        !           222: 
        !           223: : disasm-rd. ( addr w -- )
        !           224:     dup disasm-rd .
        !           225:     2drop ;
        !           226: 
        !           227: : asm-special-rd ( u "name" -- ; compiled code: addr w -- )
        !           228:     :noname POSTPONE disasm-rd.
        !           229:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           230:     swap cells funct-table + ! ;
        !           231: 
        !           232: : disasm-rs,rt ( addr w -- )
        !           233:     dup disasm-rs .
        !           234:     dup disasm-rt .
        !           235:     2drop ;
        !           236: 
        !           237: : asm-special-rs,rt ( u "name" -- ; compiled code: addr w -- )
        !           238:     :noname POSTPONE disasm-rs,rt
        !           239:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           240:     swap cells funct-table + ! ;
        !           241: 
        !           242: : disasm-rd,rs,rt ( addr w -- )
        !           243:     dup disasm-rd .
        !           244:     dup disasm-rs .
        !           245:     dup disasm-rt .
        !           246:     2drop ;
        !           247: 
        !           248: : asm-special-rd,rs,rt ( u "name" -- ; compiled code: addr w -- )
        !           249:     :noname POSTPONE disasm-rd,rs,rt
        !           250:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           251:     swap cells funct-table + ! ;
        !           252: 
        !           253: : asm-regimm-rs,imm ( u "name" -- )
        !           254:     :noname POSTPONE disasm-I-rs,imm
        !           255:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           256:     swap cells regimm-table + ! ;
        !           257: 
        !           258: : asm-copz-rt,offset,rs ( u "name" -- )
        !           259:     \ ignore these insts, we disassemble using  asm-I-rt,offset,rs
        !           260:     drop name 2drop ;
        !           261: 
        !           262: : asm-copz0 ( u "name" -- )
        !           263:     :noname POSTPONE 2drop
        !           264:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           265:     swap cells cp0-table + ! ;
        !           266: 
        !           267: $00 constant asm-copz-MF
        !           268: $02 constant asm-copz-CF
        !           269: $04 constant asm-copz-MT
        !           270: $06 constant asm-copz-CT
        !           271: $08 constant asm-copz-BC
        !           272: $10 constant asm-copz-C0
        !           273: 
        !           274: $00 constant asm-copz-BCF
        !           275: $01 constant asm-copz-BCT
        !           276: 
        !           277: : asm-rs ( -- ) ;
        !           278: 
        !           279: : disasm-rt,rd,z ( addr w -- )
        !           280:     dup disasm-rt .
        !           281:     dup disasm-rd .
        !           282:     dup disasm-copz .
        !           283:     2drop ;
        !           284: 
        !           285: : asm-copz-rt,rd ( u1 u2 "name" -- )
        !           286:     drop :noname POSTPONE disasm-rt,rd,z
        !           287:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           288:     swap cells copz-rs-table + ! ;
        !           289: 
        !           290: : disasm-I-imm ( addr w -- )
        !           291:     disasm-imm disasm-relative . ;
        !           292: 
        !           293: : asm-copz-imm ( u1 u2 u3 "name" -- )
        !           294:     drop nip :noname POSTPONE disasm-I-imm
        !           295:     name POSTPONE sliteral POSTPONE type POSTPONE ;
        !           296:     swap cells copz-rt-table + ! ;
1.1       anton     297: 
1.3     ! anton     298: include ./insts.fs

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