Diff for /gforth/arch/mips/disasm.fs between versions 1.4 and 1.10

version 1.4, 2000/06/02 12:47:36 version 1.10, 2000/07/01 20:48:52
Line 20 Line 20
   
 \ this disassembler is based on data from the R4400 manual  \ this disassembler is based on data from the R4400 manual
 \ http://www.mips.com/Documentation/R4400_Uman_book_Ed2.pdf, in  \ http://www.mips.com/Documentation/R4400_Uman_book_Ed2.pdf, in
 \ particular pages A3,A181,A182 (offset 468 pages in xpdf).  \ particular pages A3, A181, A182 (p. 471, 649, 650 in xpdf).
 \ it is limited to the R3000 (MIPS-I) architecture, though.  \ it is limited to the R3000 (MIPS-I) architecture, though.
   
   \ test this with
   \ gforth arch/mips/disasm.fs -e "here" arch/mips/testdisasm.fs -e "here over - disasm bye" |sed 's/([^)]*) //'|diff -u - arch/mips/testasm.fs
   
   get-current
   vocabulary disassembler
   also disassembler definitions
   
 \ instruction fields  \ instruction fields
   
 : disasm-op ( w -- u )  : disasm-op ( w -- u )
Line 47 Line 54
 : disasm-copz ( w -- u )  : disasm-copz ( w -- u )
     disasm-op 3 and ;      disasm-op 3 and ;
   
   : disasm-uimm ( w -- u )
       $ffff and ;
   
 : disasm-imm ( w -- n )  : disasm-imm ( w -- n )
     $ffff and dup 15 rshift negate 15 lshift or ;      disasm-uimm dup 15 rshift negate 15 lshift or ;
   
 : disasm-relative ( addr n -- w )  : disasm-relative ( addr n -- w )
     \ compute printable form of relative address n relative to addr      \ compute printable form of relative address n relative to addr
     nip ( + ) ;      2 lshift nip ( + ) ;
   
 \ decode tables  \ decode tables
   
Line 77  $40 disasm-table cp0-tab-entry     \ COP Line 87  $40 disasm-table cp0-tab-entry     \ COP
   
 \ disassembler central decode cascade  \ disassembler central decode cascade
   
   dup set-current
   
 : disasm-inst ( addr w -- )  : disasm-inst ( addr w -- )
     \G disassemble instruction w at addr (addr is used for computing      \G disassemble instruction w at addr (addr is used for computing
     \G branch targets)      \G branch targets)
     dup disasm-op opc-tab-entry @ execute ;      dup disasm-op opc-tab-entry @ execute ;
   
 : disasm-dump ( addr u -- ) \ gforth  : disasm ( addr u -- ) \ gforth
     \G disassemble u aus starting at addr      \G disassemble u aus starting at addr
     bounds u+do      bounds u+do
         cr ." ( " i hex. ." ) " i i @ disasm-inst          cr ." ( " i hex. ." ) " i i @ disasm-inst
         1 cells +loop ;          1 cells +loop
       cr ;
   
   ' disasm IS discode
   
   definitions
   
 : disasm-special ( addr w -- )  : disasm-special ( addr w -- )
     \ disassemble inst with opcode special      \ disassemble inst with opcode special
Line 125  $40 disasm-table cp0-tab-entry     \ COP Line 142  $40 disasm-table cp0-tab-entry     \ COP
   
 : disasm-J-target ( addr w -- )  : disasm-J-target ( addr w -- )
     \ print jump target      \ print jump target
     $3ffffff and swap $fc000000 and or hex. ;      2 lshift $0fffffff and swap $f0000000 and or hex. ;
   
 : disasm-I-rs,rt,imm ( addr w -- )  : disasm-I-rs,rt,imm ( addr w -- )
     dup disasm-rs .      dup disasm-rs .
Line 142  $40 disasm-table cp0-tab-entry     \ COP Line 159  $40 disasm-table cp0-tab-entry     \ COP
     disasm-imm .      disasm-imm .
     drop ;      drop ;
   
 : disasm-rt,imm ( addr w -- )  : disasm-rt,rs,uimm ( addr w -- )
     dup disasm-rt .      dup disasm-rt .
     disasm-imm .      dup disasm-rs .
       disasm-uimm hex.
       drop ;
   
   : disasm-rt,uimm ( addr w -- )
       dup disasm-rt .
       disasm-uimm hex.
     drop ;      drop ;
   
 : disasm-rt,imm,rs ( addr w -- )  : disasm-rt,imm,rs ( addr w -- )
Line 195  $40 disasm-table cp0-tab-entry     \ COP Line 218  $40 disasm-table cp0-tab-entry     \ COP
     dup disasm-copz .      dup disasm-copz .
     2drop ;      2drop ;
   
 : disasm-I-imm ( addr w -- )  : disasm-I-imm,z ( addr w -- )
     disasm-imm disasm-relative . ;      tuck disasm-imm disasm-relative .
       disasm-copz . ;
   
 \ meta-defining word for instruction format disassembling definitions  \ meta-defining word for instruction format disassembling definitions
   
Line 226  does> ( addr w -- ) Line 250  does> ( addr w -- )
 ' disasm-I-rs,rt,imm ' opc-tab-entry     define-format asm-I-rs,rt,imm  ' disasm-I-rs,rt,imm ' opc-tab-entry     define-format asm-I-rs,rt,imm
 ' disasm-I-rs,imm    ' opc-tab-entry     define-format asm-I-rs,imm1  ' disasm-I-rs,imm    ' opc-tab-entry     define-format asm-I-rs,imm1
 ' disasm-rt,rs,imm   ' opc-tab-entry     define-format asm-I-rt,rs,imm  ' disasm-rt,rs,imm   ' opc-tab-entry     define-format asm-I-rt,rs,imm
 ' disasm-rt,imm      ' opc-tab-entry     define-format asm-I-rt,imm  ' disasm-rt,rs,uimm   ' opc-tab-entry    define-format asm-I-rt,rs,uimm
   ' disasm-rt,uimm      ' opc-tab-entry    define-format asm-I-rt,uimm
 ' disasm-rt,imm,rs   ' opc-tab-entry     define-format asm-I-rt,offset,rs  ' disasm-rt,imm,rs   ' opc-tab-entry     define-format asm-I-rt,offset,rs
 ' disasm-rd,rt,sa    ' funct-tab-entry   define-format asm-special-rd,rt,sa  ' disasm-rd,rt,sa    ' funct-tab-entry   define-format asm-special-rd,rt,sa
 ' disasm-rd,rt,rs    ' funct-tab-entry   define-format asm-special-rd,rt,rs  ' disasm-rd,rt,rs    ' funct-tab-entry   define-format asm-special-rd,rt,rs
Line 239  does> ( addr w -- ) Line 264  does> ( addr w -- )
 ' disasm-I-rs,imm    ' regimm-tab-entry  define-format asm-regimm-rs,imm  ' disasm-I-rs,imm    ' regimm-tab-entry  define-format asm-regimm-rs,imm
 ' 2drop              ' cp0-tab-entry     define-format asm-copz0  ' 2drop              ' cp0-tab-entry     define-format asm-copz0
 ' disasm-rt,rd,z     ' copz-rs-tab-entry define-format asm-copz-rt,rd1  ' disasm-rt,rd,z     ' copz-rs-tab-entry define-format asm-copz-rt,rd1
 ' disasm-I-imm       ' copz-rt-tab-entry define-format asm-copz-imm1  ' disasm-I-imm,z     ' copz-rt-tab-entry define-format asm-copz-imm1
   
 : asm-I-rs,imm ( u1 u2 "name" -- ; compiled code: addr w -- )  : asm-I-rs,imm ( u1 u2 "name" -- ; compiled code: addr w -- )
     nip asm-I-rs,imm1 ;      nip asm-I-rs,imm1 ;
Line 255  does> ( addr w -- ) Line 280  does> ( addr w -- )
     drop nip asm-copz-imm1 ;      drop nip asm-copz-imm1 ;
   
 include ./insts.fs  include ./insts.fs
   
   previous set-current

Removed from v.1.4  
changed lines
  Added in v.1.10


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