Diff for /gforth/arch/mips/disasm.fs between versions 1.5 and 1.16

version 1.5, 2000/06/02 19:20:19 version 1.16, 2010/12/31 18:09:02
Line 1 Line 1
 \ disasm.fs     disassembler file (for MIPS R3000)  \ disasm.fs     disassembler file (for MIPS32)
 \  \
 \ Copyright (C) 1995-97 Martin Anton Ertl, Christian Pirker  \ Copyright (C) 2000,2007,2010 Free Software Foundation, Inc.
 \  
 \ This file is part of RAFTS.  \ This file is part of Gforth.
 \  
 \       RAFTS is free software; you can redistribute it and/or  \ Gforth is free software; you can redistribute it and/or
 \       modify it under the terms of the GNU General Public License  \ modify it under the terms of the GNU General Public License
 \       as published by the Free Software Foundation; either version 2  \ as published by the Free Software Foundation, either version 3
 \       of the License, or (at your option) any later version.  \ of the License, or (at your option) any later version.
 \  
 \       This program is distributed in the hope that it will be useful,  \ This program is distributed in the hope that it will be useful,
 \       but WITHOUT ANY WARRANTY; without even the implied warranty of  \ but WITHOUT ANY WARRANTY; without even the implied warranty of
 \       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 \       GNU General Public License for more details.  \ GNU General Public License for more details.
 \  
 \       You should have received a copy of the GNU General Public License  \ You should have received a copy of the GNU General Public License
 \       along with this program; if not, write to the Free Software  \ along with this program. If not, see http://www.gnu.org/licenses/.
 \       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
   
 \ 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 55 Line 61
   
 : 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 73  does> ( u -- addr ) Line 79  does> ( u -- addr )
   
 $40 disasm-table opc-tab-entry     \ top-level decode table  $40 disasm-table opc-tab-entry     \ top-level decode table
 $40 disasm-table funct-tab-entry   \ special function table  $40 disasm-table funct-tab-entry   \ special function table
   $40 disasm-table funct-tab2-entry  \ special2 function table
 $20 disasm-table regimm-tab-entry  \ regim instructions rt table  $20 disasm-table regimm-tab-entry  \ regim instructions rt table
 $20 disasm-table copz-rs-tab-entry \ COPz instructions rs table  $20 disasm-table copz-rs-tab-entry \ COPz instructions rs table
 $20 disasm-table copz-rt-tab-entry \ COPz BC instructions rt table  $20 disasm-table copz-rt-tab-entry \ COPz BC instructions rt table
Line 80  $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 ul@ disasm-inst
         1 cells +loop ;          4 +loop
       cr ;
   
   ' disasm IS discode
   
   definitions
   
 : disasm-special ( addr w -- )  : disasm-special ( addr w -- )
     \ disassemble inst with opcode special      \ disassemble inst with opcode special
     dup disasm-funct funct-tab-entry @ execute ;      dup disasm-funct funct-tab-entry @ execute ;
 ' disasm-special 0 opc-tab-entry ! \ enter it for opcode special  ' disasm-special 0 opc-tab-entry ! \ enter it for opcode special
   
   : disasm-special2 ( addr w -- ) \ todo factor out!
       \ disassemble inst with opcode special2
       dup disasm-funct funct-tab2-entry @ execute ;
   ' disasm-special2 $1C opc-tab-entry ! \ enter it for opcode special
   
 : disasm-regimm ( addr w -- )  : disasm-regimm ( addr w -- )
     \ disassemble regimm inst      \ disassemble regimm inst
     dup disasm-rt regimm-tab-entry @ execute ;      dup disasm-rt regimm-tab-entry @ execute ;
Line 128  $40 disasm-table cp0-tab-entry     \ COP Line 147  $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 247  does> ( addr w -- ) Line 266  does> ( addr w -- )
 ' disasm-rd.         ' funct-tab-entry   define-format asm-special-rd  ' disasm-rd.         ' funct-tab-entry   define-format asm-special-rd
 ' disasm-rs,rt       ' funct-tab-entry   define-format asm-special-rs,rt  ' disasm-rs,rt       ' funct-tab-entry   define-format asm-special-rs,rt
 ' disasm-rd,rs,rt    ' funct-tab-entry   define-format asm-special-rd,rs,rt  ' disasm-rd,rs,rt    ' funct-tab-entry   define-format asm-special-rd,rs,rt
   ' disasm-rd,rs       ' funct-tab2-entry  define-format asm-special2-rd,rs
   ' disasm-rs,rt       ' funct-tab2-entry  define-format asm-special2-rs,rt
   ' disasm-rd,rs,rt    ' funct-tab2-entry  define-format asm-special2-rd,rs,rt
 ' 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
Line 266  does> ( addr w -- ) Line 288  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.5  
changed lines
  Added in v.1.16


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