--- gforth/arch/alpha/disasm.fs 1999/10/13 13:00:08 1.2 +++ gforth/arch/alpha/disasm.fs 2000/09/23 15:47:01 1.7 @@ -1,18 +1,43 @@ - -\ bernd thallner 9725890 e881 \ disassembler in forth for alpha +\ Copyright (C) 1999,2000 Free Software Foundation, Inc. + +\ This file is part of Gforth. + +\ Gforth is free software; you can redistribute it and/or +\ modify it under the terms of the GNU General Public License +\ as published by the Free Software Foundation; either version 2 +\ of the License, or (at your option) any later version. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +\ GNU General Public License for more details. + +\ You should have received a copy of the GNU General Public License +\ along with this program; if not, write to the Free Software +\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + +\ contributed by Bernd Thallner + \ util -: h@ ( addr -- n ) \ 32 bit fetch -dup dup aligned = if - @ - $00000000ffffffff and -else - 4 - @ - $20 rshift -endif -; +\ require asm.fs + +\ : h@ ( addr -- n ) \ 32 bit fetch +\ dup dup aligned = if +\ @ +\ $00000000ffffffff and +\ else +\ 4 - @ +\ $20 rshift +\ endif +\ ; + +also assembler +vocabulary disassembler +get-current +also disassembler definitions create string_table 1000 allot @@ -257,10 +282,10 @@ create decode_code print_string drop ; -: decode_Bra ( instruction tbentry -- ) +: decode_Bra ( addr instruction tbentry -- addr ) swap dup $03e00000 and 21 rshift decode_register - $001fffff and . + $001fffff and 2* 2* 2 pick + 4 + hex. print_string ; @@ -282,7 +307,7 @@ create decode_code : decode_Mem ( instruction tbentry -- ) swap dup $03e00000 and 21 rshift decode_register - dup $0000ffff and . + dup $0000ffff and dup 15 rshift negate 15 lshift or . $001f0000 and 16 rshift decode_register print_string ; @@ -415,7 +440,9 @@ create opcode_table drop \ string_table end -: decode_inst ( n -- ) \ instruction decoder +set-current + +: disasm-inst ( addr n -- addr ) \ instruction decoder dup $fc000000 and 26 rshift cells opcode_table + @@ -424,13 +451,15 @@ drop \ string_table end $2c emit cr ; -: disasm ( addr n -- ) \ disassembler -cr 0 -?do - dup h@ - over $28 emit space . $29 emit space - decode_inst - 4 + -loop -drop -; +: disasm ( addr u -- ) \ gforth + \G disassemble u aus starting at addr + cr bounds + u+do + ." ( " i hex. ." ) " + i i h@ disasm-inst drop + 4 + +loop ; + +' disasm is discode + +previous previous