4 \ Andrew McKewan
, April
1994
5 \ Tom Zimmer
, 05/18/94 port
to Win32f
6 \ Modified
to word in decimal
08/03/94 10:04 tjz
7 \
06-??
-1995 SMuB NEXT sequence defined in FKERNEL
8 \
06-21-1995 SMuB removed redundant COUNT calls from txb
, lxs
.
9 \
04-??
-1997 Extended by C
.L
. to include P6 and MMX instructions
10 \
26-07-2001 Fixed MVX
(Maksimov
)
11 \
11-05-2004 Fixed FDA and CMV
(Serguei Jidkov
)
12 \
01-19-2015 Jos
, Extended
for XMM instructions
(adaptation by Ketmar Dark
)
13 \
25-08-2020 Fixed bug in ENTER
(Ketmar Dark
)
18 also disx86 definitions
21 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 260 constant maxstring
24 : cincr
( n
-- [n
] = [n
]+1 )
28 : c
+place
( ch c
-addr
-- )
29 dup cincr ccount
+ 1- c
!
32 : place
( a u dest
-- )
33 \ put a u at dest as counted string
34 2dup
2>r
1+ swap move \ move first
to handle overlap
35 2r
> c
! \
then store count
character
38 : +place
( a u dest
-- )
39 \ append string a u
to counted string
50 dup
1+ ;; ( dhi dlo dlo
+1 )
51 over
;; ( dhi dlo dlo
+1 dlo
)
52 u
< ;; ( dhi dlo flag
)
53 >r
1+ swap r
> ;; ( dlo
+1 dhi flag
)
61 : (d
.) ( d
-- addr len
)
62 tuck
(dabs
) <# #s rot sign #
>
66 base @
>r hex u
.r r
> base
!
82 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83 0 value
default-16bit?
85 : default-16bit
( -- ) true
to default-16bit?
;
86 : default-32bit
( -- ) false
to default-16bit?
;
88 ' drop defered show-name ( cfa -- ) \ display nearest symbol
92 \ use my z80-like syntax?
94 true value k8syntax-regs?
97 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99 \ disx86 also definitions
103 : dis-wpeek ( addr -- addr word[addr] )
107 : dis-cfetch ( addr -- addr+1 byte[addr] )
111 : dis-c@ ( addr -- byte[addr] )
115 create s-buf MAXSTRING allot
127 \ strip trailing spaces from s-buf
141 : s-lastch-addr ( -- addr )
145 : s-lastch@ ( -- ch )
150 s-buf ccount 1- 0 max swap 1- c!
158 dup 0 > if 0 do bl emit>s loop else drop endif
173 \ want at least one space
183 : (.s") ( addr n -- )
194 >r (d.) r> over - sspaces >s
197 : disasm-s>d ( n -- d )
198 dup 0< if -1 else 0 endif
202 >r disasm-s>d r> d.r>s
210 base @ swap hex 0 (d.) >s ( sspace ) base !
221 : 0h.r>s ( n1 n2 -- )
236 : ?.name>s ( cfa -- )
241 ' ?
.name
>s
to show
-name
245 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
247 ;; main disassembler code
251 false value
16-bit
-data
252 false value
16-bit
-addr
253 false value prefix
-op
254 false value prefix
-op
-a16
-d16 \
0, 1, 2
255 false value prefix
-seg
257 false value xmm
-reg \
for a
32-bit environment
258 false value data
-size
-prefix \
0:don
't need it; 1:"byte"; 2:"word"; 4:"dword"
259 false value disp-as-reg-offset
264 \ k8: use this as hex prefix
265 : .# ( -- ) .s" 0x" ;
268 : .[ [char] [ emit>s ;
269 : .] [char] ] emit>s ;
272 data-size-prefix case
273 1 of .s" byte " endof
274 2 of .s" word " endof
275 4 of .s" dword " endof
276 16-bit-data prefix-op-a16-d16 2 = logand if 0 to prefix-op-a16-d16 .s" word " endif
278 0 to data-size-prefix
293 : set-data-size-with-bit ( bit -- )
295 16-bit-data if 2 else 4 endif
302 : @+ ( addr -- addr n ) dup cell+ swap @ ;
303 : W@+ ( addr -- addr n ) dup 2+ swap W@ ;
305 : sext ( byte -- n ) dup $80 and if $FFFFFF00 or then ;
308 ( mod-r-r/m -- r/m r mod ) \ r including general, special, segment, MMX
309 ( mod-op-r/m -- r/m op mod )
311 255 and 8 /mod 8 /mod
318 : ss. ( n adr len w ) >r drop swap r@ * + r> >s ; \ sspace ;
320 : tttn ( code -- ) 15 and S" o nob aee nebea s nsp npl geleg " 2 ss. s-xstrip ;
322 : sreg ( sreg -- ) 3 rshift 7 and S" escsssdsfsgsXXXX" 2 ss. ;
323 : creg ( eee -- ) 3 rshift 7 and S" cr0???cr2cr3cr4?????????" 3 ss. ;
324 : dreg ( eee -- ) 3 rshift 7 and S" dr0dr1dr2dr3??????dr6dr7" 3 ss. ;
325 : treg ( eee -- ) 3 rshift 7 and S" ?????????tr3tr4tr5tr6tr7" 3 ss. ; \ obsolete
326 : mreg ( n -- ) 7 and S" mm0mm1mm2mm3mm4mm5mm6mm7" 3 ss. ;
328 : reg8 ( n -- ) 7 and S" alcldlblahchdhbh" 2 ss. ;
329 : reg16 ( n -- ) 7 and S" axcxdxbxspbpsidi" 2 ss. ;
333 dup 1 = if .s" TOS" drop exit endif
334 dup 5 = if .s" ERP" drop exit endif
335 dup 6 = if .s" EIP" drop exit endif
337 S" eaxecxedxebxespebpesiedi" 3 ss.
339 : .xmmreg ( n -- ) 7 and S" xmm0xmm1xmm2xmm3xmm4xmm5xmm6xmm7" 4 ss. ; \ 1
341 16-bit-data if reg16 else reg32 then
351 if reg16/32 else reg8 then
356 : [base16] ( r/m -- )
358 4- S" [si][di][bp][bx]" 4 ss.
359 \ r/m = 4 , 5 , 6 , 7
364 S" [bx+si][bx+di][bp+si][bp+di]" 7 ss.
365 \ r/m = 0 , 1 , 2 , 3
369 dup 4 < if [ind16] else [base16] then
376 dup 1 = if .s" [TOS]" drop exit endif
377 dup 5 = if .s" [ERP]" drop exit endif
378 dup 6 = if .s" [EIP]" drop exit endif
380 S" [eax][ecx][edx][ebx][esp][ebp][esi][edi]" 5 ss.
383 \ : [reg] ( r/m -- ) 16-bit-addr
391 \ if S" [bx+si] [bx+di] [bp+si] [bp+di] [si] [di] [bp] [bx]"
393 \ ?do bl skip bl scan
394 \ loop bl skip 2dup bl scan nip - >s 2 sspaces
395 \ else S" [eax][ecx][edx][ebx][esp][ebp][esi][edi]" 5 ss. sspace
399 : [reg*2] ( i -- ) .datasize S" [eax*2][ecx*2][edx*2][ebx*2][XXX*2][ebp*2][esi*2][edi*2]" 7 ss. ;
400 : [reg*4] ( i -- ) .datasize S" [eax*4][ecx*4][edx*4][ebx*4][XXX*4][ebp*4][esi*4][edi*4]" 7 ss. ;
401 : [reg*8] ( i -- ) .datasize S" [eax*8][ecx*8][edx*8][ebx*8][XXX*8][ebp*8][esi*8][edi*8]" 7 ss. ;
406 nip .datasize .segpfx .s" [XXX]"
416 : [reg*2] ( i -- ) 2 [reg*n] ;
417 : [reg*4] ( i -- ) 4 [reg*n] ;
418 : [reg*8] ( i -- ) 8 [reg*n] ;
420 : [index-has-scaled] ( sib -- add-disp-flag )
423 \ no esp scaled index
427 s-lastch@ [char] ] = if s-lastch-addr s-chop else 0 endif >r
434 r> ?dup if [char] + swap c! endif
441 [index-has-scaled] drop
444 : .+sign ( val -- ) 0>= if [char] + emit>s endif ;
446 : .dispnum ( val -- )
447 dup .+sign dup abs 10 < if 0 .r>s else .# 0 h.r>s endif
450 : (.dispvalue) ( val -- )
451 dup data-size-prefix or if .dispnum else drop endif
454 : .disp-value ( val -- )
455 \ disp-as-reg-offset if dup 0>= if .s" +" endif 0 .r>s else show-name endif
456 data-size-prefix if .datasize .segpfx .[ endif
457 disp-as-reg-offset if (.dispvalue) else show-name endif
458 data-size-prefix if .] endif
461 : disp8-value ( adr -- adr' value
)
464 : disp8
( adr
-- adr
' )
465 disp8-value .disp-value
468 : disp16-value ( adr -- adr' value
)
470 dup
0x8000 u
>= if 0x10000 - endif
472 : disp16
( adr
-- adr
' )
473 disp16-value .disp-value
476 : disp32-value ( adr -- adr' value
)
479 : disp32
( adr
-- adr
' )
480 disp32-value .disp-value
483 : disp16/32 ( adr -- adr' )
484 data
-size
-prefix
if .datasize
endif
485 0 to data
-size
-prefix
.segpfx
.[ 16-bit
-addr
if disp16
else disp32
then .]
488 : imm8
-nocomma
( adr
-- adr
' ) .# dis-cfetch h.>s ;
489 : imm8 ( adr -- adr' ) ., imm8
-nocomma
;
491 \
: imm16
( adr
-- adr
' ) .,# w@+ h.>s ;
493 : imm16/32-nocomma ( adr -- adr' ) .#
16-bit
-data
if w@
+ else @
+ endif h
.>s
;
494 : imm16
/32 ( adr
-- adr
' ) ., imm16/32-nocomma ;
496 : sib ( adr mod -- adr )
497 >r dis-cfetch tuck 7 and 5 = r@ 0= and
499 \ disp32 swap [index] rdrop \ ebp base and mod = 00
501 swap [index-has-scaled] if
502 \ need to add disp as scale
504 r> (.dispvalue) \ r@ 0>= if [char] + emit>s endif r> 0 .r>s
512 1 of disp8-value true endof
513 2 of disp32-value true endof
514 otherwise drop false false
517 swap dup [reg32] [index]
520 r> (.dispvalue) \ r@ 0>= if [char] + emit>s endif r> 0 .r>s
531 \ : sib ( adr ext -- adr' )
533 \ swap dis
-cfetch
>r swap
6 rshift
3 and
534 \ ?dup
if 1 = if disp8
else disp32
then then
535 \ r
> dup
7 and dup
5 =
540 \
else .s
" [" dup
3 rshift reg32
-1 s
-buf c
+!
543 \ ?dup
if .s
" *" 0 .r
>s
then .s
" ] "
547 : mod
-reg
-predisp
( -- )
548 s
-lastch@
[char
] ] = if
549 0 to data
-size
-prefix
550 1 to disp
-as
-reg
-offset
554 : mod
-reg
-postdisp
( -- )
555 disp
-as
-reg
-offset
if s
-xstrip
.] endif
558 : mod
-r
/m32
( adr r
/m mod
-- adr
' )
561 drop reg \ mod = 3, register case
565 nip sib \ r/m = 4, sib case
567 2dup 0= swap 5 = and \ mod = 0, r/m = 5,
569 .s" dword " .segpfx .[
570 0 to data-size-prefix
571 2drop disp32 \ disp32 case
583 1 of mod-reg-predisp disp8 mod-reg-postdisp endof
584 2 of mod-reg-predisp disp32 mod-reg-postdisp endof
591 : mod-r/m16 ( adr r/m mod -- adr' )
594 2drop disp16 \ disp16 case
598 1 of swap disp8 swap
[reg16
] endof
599 2 of swap disp16 swap
[reg16
] endof
605 : mod
-r
/m
( adr modr
/m
-- adr
' ) mod/sib nip 16-bit-addr if mod-r/m16 else mod-r/m32 then ;
607 \ : mod-r/m ( adr ext -- adr' )
608 \ dup $C7 and
5 = \
32bit displacement
609 \
16-bit
-addr
0= and \ and not
16bit addressing
610 \
if drop disp32
.s
" [] "
613 \ dup $C0 and $C0
< over
7 and
4 = and
614 \
16-bit
-addr
0= and \ and not
16bit addressing
618 \ dup $C7 and
6 = \
16bit displacement
619 \
16-bit
-addr and \ and
16bit addressing
620 \
if drop disp32
.s
" [] "
625 \
0 of
.s
" 0 " [reg
] endof
626 \
1 of swap disp8 swap
[reg
] endof
627 \
2 of swap disp32 swap
[reg
] endof
631 : r
/m8
0 to size mod
-r
/m
;
632 : r
/m16
/32 1 to size mod
-r
/m
;
633 : r
/m16 true
to 16-bit
-data r
/m16
/32 ;
635 : r
,r
/m
( adr
-- adr
' ) dis-cfetch dup 3 rshift reg ., mod-r/m ;
637 : r/m,r ( adr -- adr' ) dis
-cfetch dup
>r mod
-r
/m
., r
> 3 rshift reg
;
639 : r
/m
( adr op
-- adr
' ) 2 and if r,r/m else r/m,r then ;
642 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
643 ;; -------------------- Simple Opcodes --------------------
649 \ count here place here count cell+ allot drop
650 count cell+ allot drop
653 drop \ instruction code
706 : aam ( adr code -- adr' )
707 .s
" aam" drop dis
-cfetch drop
710 : aad
( adr code
-- adr
' )
711 .s" aad" drop dis-cfetch drop
714 : d16 ( adr code -- adr' )
718 2 to prefix
-op
-a16
-d16
721 : a16
( adr code
-- adr
' )
725 1 to prefix-op-a16-d16
728 : rpz ( adr code -- adr' )
733 : rep
( adr code
-- adr
' )
738 : lok ( adr code -- adr' ) \ This should have error checking added
743 : cs
: ( adr code
-- adr
' )
749 : ds: ( adr code -- adr' )
755 : ss
: ( adr code
-- adr
' )
761 : es: ( adr code -- adr' )
767 : gs
: ( adr code
-- adr
' )
773 : fs: ( adr code -- adr' )
779 : isd
( adr code
-- adr
' )
787 : osd ( adr code -- adr' )
795 : inp
( addr code
-- addr
' )
808 : otp ( addr code -- addr' )
812 dis
-cfetch h
.>s
16-bit
-data
817 dis
-cfetch h
.>s
.s
" ,al"
822 ( addr code
-- addr
' )
835 : otd ( addr code -- addr' )
848 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
849 ;; -------------------- ALU Opcodes
--------------------
854 k8syntax? over
7 = logand
858 S
" addor adcsbbandsubxorcmp" 3 ss
.
863 : alu
( adr op
-- adr
' )
864 \ k8: data size; comment it to avoid prefixes on [reg],reg
865 dup 1 and set-data-size-with-bit
866 dup 3 rshift .alu r/m
869 : ali ( adr op -- adr' )
874 r@
1 and set
-data
-size
-with
-bit
893 : ala
( adr op
-- adr
' )
895 1 and if 0 reg imm16/32 else 0 reg8 imm8 then
899 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
900 ;; -------------------- Test/Xchg --------------------
903 : txb ( addr op -- addr' )
904 dup
3 and S
" testtestxchgxchg" 4 ss
. s
-end-mnemo
906 if 1 to size r
,r
/m \ SMuB removed COUNT
907 else 0 to size r
,r
/m \ SMuB removed COUNT
911 : tst
( addr op
-- addr
' )
912 .s" test" s-end-mnemo
924 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
925 ;; -------------------- Inc/Dec ----------------------
928 : inc ( addr op -- addr' ) .s
" inc" s
-end-mnemo reg16
/32 ;
929 : dec
( addr op
-- addr
' ) .s" dec" s-end-mnemo reg16/32 ;
932 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
933 ;; -------------------- Push/Pop --------------------
936 : psh ( addr op -- addr' ) .s
" push" s
-end-mnemo reg16
/32 ;
937 : pop
( addr op
-- addr
' ) .s" pop" s-end-mnemo reg16/32 ;
938 : pss ( addr op -- addr' ) .s
" push" s
-end-mnemo sreg
;
939 : pps
( addr op
-- addr
' ) .s" pop" s-end-mnemo sreg ;
941 : psa ( addr op -- addr' )
944 16-bit
-data ifnot
.s
" d" endif
948 : ppa
( addr op
-- addr
' )
951 16-bit-data ifnot .s" d" endif
955 : psi ( addr op -- addr' )
956 .s
" push" s
-end-mnemo
957 2 and
if imm8
-nocomma
else imm16
/32-nocomma
endif
960 : psf
( addr op
-- addr
' )
963 16-bit-data ifnot .s" d" endif
967 : ppf ( addr op -- addr' )
970 16-bit
-data ifnot
.s
" d" endif
974 : 8F
. ( addr op
-- addr
' ) drop dis-cfetch .s" pop" s-end-mnemo r/m16/32 ;
976 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
977 ;; -------------------- Move --------------------
981 k8syntax? ifnot .s" mov" else .s" ld" endif
985 : mov ( addr op -- addr' ) mov
-mnemo r
/m
;
987 : mri
( addr op
-- addr
' ) ( mov register, imm )
989 dup 8 and if reg16/32 imm16/32 else reg8 imm8 endif
992 : mvi ( adr op -- adr' ) ( mov mem
, imm
)
995 1 and set
-data
-size
-with
-bit
996 dis
-cfetch mod
-r
/m size
if imm16
/32 else imm8
endif
999 : mrs
( addr op
-- addr
' )
1000 ( 16-bit-data) true if
1004 dis-cfetch dup mod-r/m .,
1011 : msr ( addr op -- addr' )
1012 ( 16-bit
-data
) true
if
1016 dis
-cfetch dup sreg
.,
1023 : mrc
( addr op
-- addr
' ) mov-mnemo drop dis-cfetch dup reg32 ., creg ;
1024 : mcr ( addr op -- addr' ) mov
-mnemo drop dis
-cfetch dup creg
., reg32
;
1025 : mrd
( addr op
-- addr
' ) mov-mnemo drop dis-cfetch dup reg32 ., dreg ;
1026 : mdr ( addr op -- addr' ) mov
-mnemo drop dis
-cfetch dup dreg
., reg32
;
1027 : mrt
( addr op
-- addr
' ) mov-mnemo drop dis-cfetch dup reg32 ., treg ; \ obsolete
1028 : mtr ( addr op -- addr' ) mov
-mnemo drop dis
-cfetch dup treg
., reg32
; \ obsolete
1030 : mv1
( addr op
-- addr
' )
1043 : mv2 ( addr op -- addr' )
1045 \ @@@ Bh fixed bug here
1046 swap disp16
/32 ., swap
1057 : lea
( addr op
-- addr
' ) .s" lea" s-end-mnemo drop 1 to size r,r/m ;
1059 : lxs ( addr op -- addr' )
1065 r
,r
/m \ SMuB removed COUNT
1068 : bnd
( addr op
-- addr
' ) .s" bound" s-end-mnemo drop 1 to size r,r/m ;
1070 : arp ( addr op -- addr' ) .s
" arpl" s
-end-mnemo drop
1 to size true
to 16-bit
-data r
,r
/m
;
1072 : mli
( addr op
-- addr
' )
1074 .s" imul" s-end-mnemo
1075 $69 = if r,r/m imm16/32 else r,r/m imm8 endif
1078 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1079 ;; -------------------- Jumps and Calls --------------------
1082 : rel8 ( addr op -- addr' ) dis
-cfetch sext over
+ ( h
.>s
) base
-addr
- show
-name
;
1084 : rel16
/32 ( addr op
-- addr
' ) 16-bit-addr if w@+ else @+ endif over + base-addr - show-name ;
1086 : jsr ( addr op -- addr' ) .s
" call" s
-end-mnemo drop rel16
/32 ;
1088 : jmp
-jp
-mnemo
( -- ) k8syntax?
if .s
" jp" else .s
" jmp" endif ;
1090 : jmp
( addr op
-- addr
' )
1093 2 and if rel8 else rel16/32 then
1096 : .jxx ( addr op -- addr' )
1098 .s
" jr" s
-end-mnemo tttn
.,
1105 : bra
( addr op
-- addr
' ) .jxx rel8 ;
1106 : lup ( addr op -- addr' ) 3 and S
" loopnzloopz loop jecxz " 6 ss
. s
-end-mnemo rel8
;
1107 : lbr
( addr op
-- addr
' ) .jxx rel16/32 ;
1109 : rtn ( addr op -- addr' )
1112 1 and
0= if s
-end-mnemo w@
+ h
.>s
endif
1115 : rtf
( addr op
-- addr
' )
1117 1 and 0= if sspace w@+ h.>s endif
1120 : ent ( addr op -- addr' ) drop
.s
" enter" s
-end-mnemo w@
+ 0 .r
>s
., dis
-cfetch
0 .r
>s
;
1122 : cis
( addr op
-- addr
' )
1135 : nt3 ( addr op -- addr' ) drop
.s
" int3" ;
1137 : int
( addr op
-- addr
' ) drop .s" int" s-end-mnemo dis-cfetch .# h.>s ;
1143 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1144 ;; -------------------- string ops --------------------
1150 1 and if .s" d" else .s" b" then
1159 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1160 ;; -------------------- Exchange --------------------
1163 : xga ( addr op -- addr' )
1167 .s
" xchg" s
-end-mnemo
.s
" eax," reg16
/32
1171 \
: xch
( addr op
-- addr
' ) .s" xchg" s-end-mnemo drop r,r/m ;
1174 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1175 ;; -------------------- Shifts & Rotates --------------------
1178 : .shift ( n -- ) 7 and S" rolrorrclrcrshlshrxxxsar" 3 ss. s-end-mnemo ;
1180 : shf ( addr op -- addr' )
1186 $C0 of dis
-cfetch h
.>s endof
1192 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1193 ;; -------------------- Extended Opcodes
--------------------
1196 : wf1
( addr
-- addr
' )
1201 6 of .s" fstenv" s-end-mnemo mod-r/m endof
1202 7 of .s" fstcw" s-end-mnemo .s" word " mod-r/m endof
1203 2drop 2- dup .s" fwait"
1210 : wf2 ( addr -- addr' )
1213 $e2 of
.s
" fclex" endof
1214 $e3 of
.s
" finit" endof
1215 swap
2- swap
.s
" fwait"
1219 : wf3
( addr
-- addr
' )
1220 1+ dis-cfetch dup 3 rshift 7 and
1222 6 of .s" fsave" s-end-mnemo mod-r/m endof
1223 7 of .s" fstsw" s-end-mnemo .s" word " mod-r/m endof
1224 2drop 2- dup .s" fwait"
1228 : wf4 ( addr -- addr' )
1231 .s
" fstsw" s
-end-mnemo
.s
" ax"
1237 : fwaitops
( addr op
-- addr
' )
1247 : w8f ( addr op -- addr' )
1248 drop dup c@ dup $f8 and $d8
=
1249 if fwaitops
else drop
.s
" wait" endif
1252 : falu1
( xopcode
-- )
1254 S
" fadd fmul fcom fcompfsub fsubrfdiv fdivr"
1258 : falu5
( xopcode
-- )
1260 s
" fadd fmul ???? ???? fsubrfsub fdivrfdiv "
1264 : sti
. ( op
-- ) 7 and
.s
" st(" 1 .r
>s
.s
" )" ;
1265 \
: sti
. ( op
-- ) 7 and
.s
" st" 1 .r
>s
;
1267 \
: sti
.st
( op
-- )
1269 \
.s
" ST(" 1 .r
>s
.s
" )" .s
" ST " ;
1271 : fd8
( addr opcode
-- addr
' )
1272 drop dis-cfetch dup falu1
1278 if sti. else .s" st," sti. endif
1282 : fdc ( addr opcode -- addr' )
1286 falu1
.s
" double " mod
-r
/m
1292 : fnullary
-f
( op
-- )
1294 S
" f2xm1 fyl2x fptan fpatan fxtractfprem1 fdecstpfincstp"
1297 S
" fprem fyl2xp1fsqrt fsincosfrndintfscale fsin fcos "
1303 : fnullary
-e
( op
-- )
1305 S
" fchs fabs ??? ??? ftst fxam ??? ??? "
1308 S
" fld1 fldl2t fldl2e fldpi fldlg2 fldln2 fldz ??? "
1314 : fnullary
( op
-- )
1315 dup $ef
> if fnullary
-f EXIT
endif
1330 \ S
" fld ??? fst fstp fldenv fldcw fnstenvfnstcw "
1333 : fd9
( addr op
-- addr
' )
1334 drop dis-cfetch dup $c0 < if
1337 $00 of .s" fld" s-end-mnemo .s" float " endof
1338 $10 of .s" fst" s-end-mnemo .s" float " endof
1339 $18 of .s" fstp" s-end-mnemo .s" float " endof
1340 $20 of .s" fldenv" s-end-mnemo endof
1341 $28 of .s" fldcw" s-end-mnemo .s" word " endof
1342 $30 of .s" fnstenv" s-end-mnemo endof
1343 $38 of .s" fnstcw" s-end-mnemo .s" word " endof
1350 if .s" fld" else .s" fxch" endif
1361 S" fiadd fimul ficom ficompfisub fisubrfidiv fidivr"
1368 S" fcmovb fcmove fcmovbefcmovu ??? ??? ??? ??? "
1373 : fda ( addr op -- )
1374 drop dis-cfetch dup $c0 <
1376 dup falu3 .s" dword " mod-r/m
1378 dup \ 11-05-2004 Fixed FDA and CMV (Serguei Jidkov)
1389 S" faddp fmulp ??? ??? fsubrpfsubp fdivrpfdivp "
1394 : fde ( addr op -- addr' )
1395 drop dis
-cfetch dup $c0
< if
1396 dup falu3
.s
" word " mod
-r
/m
1408 S
" fcmovnb fcmovne fcmovnbefcmovnu ??? fucomi fcomi ??? "
1413 : fdb
( addr op
-- addr
' )
1414 drop dis-cfetch dup $c0 < if
1416 $00 of .s" fild" s-end-mnemo .s" dword " endof
1417 $10 of .s" fist" s-end-mnemo .s" dword " endof
1418 $18 of .s" fistp" s-end-mnemo .s" dword " endof
1419 $28 of .s" fld" s-end-mnemo .s" extended " endof
1420 $38 of .s" fstp" s-end-mnemo .s" extended " endof
1426 $e2 of .s" fnclex" endof
1427 $e3 of .s" fninit" endof
1435 S" ffree ??? fst fstp fucom fucomp??? ??? "
1440 : fdd ( addr op -- addr' )
1441 drop dis
-cfetch dup $c0
< if
1444 $
00 of
.s
" fld" s
-end-mnemo
.s
" double " endof
1445 $
10 of
.s
" fst" s
-end-mnemo
.s
" double " endof
1446 $
18 of
.s
" fstp" s
-end-mnemo
.s
" double " endof
1447 $
20 of
.s
" frstor" s
-end-mnemo endof
1448 $
30 of
.s
" fnsave" s
-end-mnemo endof
1449 $
38 of
.s
" fnstsw" s
-end-mnemo
.s
" word " endof
1458 : fdf
( addr op
-- addr
' )
1459 drop dis-cfetch dup $c0 < if
1462 $00 of .s" fild" s-end-mnemo .s" word " endof
1463 $10 of .s" fist" s-end-mnemo .s" word " endof
1464 $18 of .s" fistp" s-end-mnemo .s" word " endof
1465 $20 of .s" fbld" s-end-mnemo .s" tbyte " endof
1466 $28 of .s" fild" s-end-mnemo .s" qword " endof
1467 $30 of .s" fbstp" s-end-mnemo .s" tbyte " endof
1468 $38 of .s" fistp" s-end-mnemo .s" qword " endof
1474 .s" fnstsw" s-end-mnemo ." ax " drop
1478 $00 of .s" ffreep" s-end-mnemo sti. endof
1479 $28 of .s" fucomip" s-end-mnemo sti. endof
1480 $30 of .s" fcomip" s-end-mnemo sti. endof
1487 : gp6 ( addr op -- addr' )
1488 drop dis
-cfetch dup
3 rshift
1489 7 and S
" sldtstr lldtltr verrverw??? ???" 4 ss
.
1494 : gp7
( addr op
-- addr
' )
1495 drop dis-cfetch dup 3 rshift
1496 7 and dup S" sgdt sidt lgdt lidt smsw ??? lmsw invlpg" 6 ss.
1498 4 and 4 = if r/m16 else r/m16/32 then
1503 3 and S" bt btsbtrbtc" 3 ss.
1507 : gp8 ( addr op -- addr' )
1508 drop dis
-cfetch dup btx
.
1512 : lar
( addr op
-- addr
' ) .s" lar" s-end-mnemo drop r,r/m ;
1513 : lsl ( addr op -- addr' ) .s
" lsl" s
-end-mnemo drop r
,r
/m
;
1514 : lss
( addr op
-- addr
' ) .s" lss" s-end-mnemo drop r,r/m ;
1515 : lfs ( addr op -- addr' ) .s
" lfs" s
-end-mnemo drop r
,r
/m
;
1516 : lgs
( addr op
-- addr
' ) .s" lgs" s-end-mnemo drop r,r/m ;
1517 : btx ( addr op -- addr' ) btx
. r
/m
,r
;
1518 : sli
( addr op
-- addr
' ) .s" shld" s-end-mnemo drop r/m,r imm8 ;
1519 : sri ( addr op -- addr' ) .s
" shrd" s
-end-mnemo drop r
/m
,r imm8
;
1520 : slc
( addr op
-- addr
' ) .s" shld" s-end-mnemo drop r/m,r .s" ,cl" ;
1521 : src ( addr op -- addr' ) .s
" shrd" s
-end-mnemo drop r
/m
,r
.s
" ,cl" ;
1522 : iml
( addr op
-- addr
' ) .s" imul" s-end-mnemo drop r,r/m ;
1523 : cxc ( addr op -- addr' ) .s
" cmpxchg" s
-end-mnemo
1 and
to size r
/m
,r
;
1525 : mvx
( addr op
-- addr
' )
1526 dup 8 and if .s" movsx" else .s" movzx" then
1529 dis-cfetch mod/sib r> \ size bit
1531 swap reg32 ., \ word to dword case
1535 DROP DUP 1- C@ \ 26-07-2001 Fixed MVX (Maksimov)
1539 swap reg16/32 ., \ byte case
1543 DROP DUP 1- C@ \ 26-07-2001 Fixed MVX (Maksimov)
1549 : xad ( addr op -- addr' ) .s
" xadd" s
-end-mnemo
1 and
to size r
/m
,r
;
1550 : bsf
( addr op
-- addr
' ) .s" bsf" s-end-mnemo drop r,r/m ;
1551 : bsr ( addr op -- addr' ) .s
" bsr" s
-end-mnemo drop r
,r
/m
;
1552 : cx8
( addr op
-- addr
' ) .s" cmpxchg8b" s-end-mnemo drop dis-cfetch r/m16/32 ;
1553 : bsp ( addr op -- addr' ) .s
" bswap" s
-end-mnemo reg32
;
1555 : F6
. ( addr op
-- addr
' )
1558 dup 3 rshift 7 and dup >r S" testXXXXnot neg mul imuldiv idiv" 4 ss.
1561 r@ 1 and if imm16/32 else imm8 then
1566 : FE. ( addr op -- addr' )
1578 : FF
. ( addr op
-- addr
' )
1582 0 of .s" inc" s-end-mnemo endof
1583 1 of .s" dec" s-end-mnemo endof
1584 2 of .s" call" s-end-mnemo endof
1585 3 of .s" call" s-end-mnemo ." far " endof
1586 4 of jmp-jp-mnemo s-end-mnemo endof
1587 5 of jmp-jp-mnemo s-end-mnemo ." far " endof
1588 6 of .s" push " s-end-mnemo endof
1594 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1595 ;; --------------------- conditional move ---------------
1598 : set ( adr op -- ) .s" set" tttn s-end-mnemo dis-cfetch r/m8 ;
1599 : cmv ( adr op -- ) .s" cmov" tttn s-end-mnemo ( dis-cfetch ) r,r/m ; \ 11-05-2004 Fixed FDA and CMV (Serguei Jidkov)
1601 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1602 ;; --------------------- MMX Operations -----------------
1605 : mmx-size ( op -- ) 3 and S" bwdq" 1 ss. ;
1607 : upl ( adr op -- adr' ) 3 and S
" punpcklbwpunpcklwdpunpckldq" 9 ss
. s
-end-mnemo r
,r
/m
;
1608 : uph
( adr op
-- adr
' ) 3 and S" punpckhbwpunpckhwdpunpckhdq" 9 ss. s-end-mnemo r,r/m ;
1609 : cgt ( adr op -- adr' ) .s
" pcmpgt" mmx
-size s
-end-mnemo r
,r
/m
;
1610 : ceq
( adr op
-- adr
' ) .s" pcmpeq" mmx-size s-end-mnemo r,r/m ;
1615 $10 of .s" psrl" endof
1616 $20 of .s" psra" endof
1617 $30 of .s" psll" endof
1621 : gpa ( adr op -- adr' ) >r dis
-cfetch dup psh
. r
> mmx
-size s
-end-mnemo mreg imm8
;
1622 : puw
( adr op
-- adr
' ) .s" packusdw" s-end-mnemo drop r,r/m ;
1623 : psb ( adr op -- adr' ) .s
" packsswb" s
-end-mnemo drop r
,r
/m
;
1624 : psw
( adr op
-- adr
' ) .s" packssdw" s-end-mnemo drop r,r/m ;
1626 : mpd ( adr op -- adr' )
1627 .s
" movd" s
-end-mnemo
1628 drop dis
-cfetch mod
/sib
1630 if reg32
else mod
-r
/m
then
1633 : mdp
( adr op
-- adr
' )
1634 .s" movd" s-end-mnemo
1635 drop dis-cfetch mod/sib
1637 if swap reg32 else swap mod-r/m then
1641 : mpq ( adr op -- adr' ) .s
" movq" s
-end-mnemo drop r
,r
/m
;
1642 : mqp
( adr op
-- adr
' ) .s" movq" s-end-mnemo drop r/m,r ;
1643 : shx ( adr op -- adr' ) dup psh
. mmx
-size s
-end-mnemo r
,r
/m
;
1644 : mll
( adr op
-- adr
' ) .s" pmullw" s-end-mnemo drop r,r/m ;
1645 : mlh ( adr op -- adr' ) .s
" pmulhw" s
-end-mnemo drop r
,r
/m
;
1646 : mad
( adr op
-- adr
' ) .s" pmaddwd" s-end-mnemo drop r,r/m ;
1647 : sus ( adr op -- adr' ) .s
" psubus" mmx
-size s
-end-mnemo r
,r
/m
;
1648 : sbs
( adr op
-- adr
' ) .s" psubs" mmx-size s-end-mnemo r,r/m ;
1649 : sub ( adr op -- adr' ) .s
" psub" mmx
-size s
-end-mnemo r
,r
/m
;
1650 : aus
( adr op
-- adr
' ) .s" paddus" mmx-size s-end-mnemo r,r/m ;
1651 : ads ( adr op -- adr' ) .s
" padds" mmx
-size s
-end-mnemo r
,r
/m
;
1652 : add
( adr op
-- adr
' ) .s" padd" mmx-size s-end-mnemo r,r/m ;
1653 : pad ( adr op -- adr' ) .s
" pand" s
-end-mnemo drop r
,r
/m
;
1654 : por
( adr op
-- adr
' ) .s" por" s-end-mnemo drop r,r/m ;
1655 : pan ( adr op -- adr' ) .s
" pandn" s
-end-mnemo drop r
,r
/m
;
1656 : pxr
( adr op
-- adr
' ) .s" pxor" s-end-mnemo drop r,r/m ;
1658 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1659 ;; -------------------- Opcode Table --------------------
1662 : ops $10 0 do ' , loop
;
1666 \
0 1 2 3 4 5 6 7 8 9 A B C D E F
1667 ops gp6 gp7 lar lsl ??? ??? clt ??? inv wiv ??? ud2 ??? ??? ??? ??? \
0
1668 ops ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? \
1
1669 ops mrc mrd mcr mdr mrt ??? mtr ??? ??? ??? ??? ??? ??? ??? ??? ??? \
2
1670 ops wmr rtc rmr rpc ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? \
3
1672 ops cmv cmv cmv cmv cmv cmv cmv cmv cmv cmv cmv cmv cmv cmv cmv cmv \
4
1673 ops ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? \
5
1674 ops upl upl upl puw cgt cgt cgt psb uph uph uph psw ??? ??? mpd mpq \
6
1675 ops ??? gpa gpa gpa ceq ceq ceq ems ??? ??? ??? ??? ??? ??? mdp mqp \
7
1677 ops lbr lbr lbr lbr lbr lbr lbr lbr lbr lbr lbr lbr lbr lbr lbr lbr \
8
1678 ops set set set set set set set set set set set set set set set set \
9
1679 ops pss pps cpu btx sli slc ??? ??? pss pps rsm btx sri src ??? iml \ A
1680 ops cxc cxc lss btx lfs lgs mvx mvx ??? ud1 gp8 btx bsf bsr mvx mvx \ B
1682 ops xad xad ??? ??? ??? ??? ??? cx8 bsp bsp bsp bsp bsp bsp bsp bsp \ C
1683 ops ??? shx shx shx ??? mll ??? ??? sus sus ??? pad aus aus ??? pan \ D
1684 ops ??? shx shx ??? ??? mlh ??? ??? sbs sbs ??? por ads ads ??? pxr \ E
1685 ops ??? ??? shx shx ??? mad ??? ??? sub sub sub ??? add add add ??? \ F
1686 \
0 1 2 3 4 5 6 7 8 9 A B C D E F
1688 : 0F
. ( adr code
-- )
1690 dup $
70 and $
50 $
80 within
to mmx
-reg
1691 cells op
-table2
+ @execute
1698 \
0 1 2 3 4 5 6 7 8 9 A B C D E F
1699 ops alu alu alu alu ala ala pss pps alu alu alu alu ala ala pss
0F
. \
0
1700 ops alu alu alu alu ala ala pss pps alu alu alu alu ala ala pss pps \
1
1701 ops alu alu alu alu ala ala es
: daa alu alu alu alu ala ala cs
: das \
2
1702 ops alu alu alu alu ala ala ss
: aaa alu alu alu alu ala ala ds
: aas \
3
1704 ops inc inc inc inc inc inc inc inc dec dec dec dec dec dec dec dec \
4
1705 ops psh psh psh psh psh psh psh psh pop pop pop pop pop pop pop pop \
5
1706 ops psa ppa bnd arp fs
: gs
: d16 a16 psi mli psi mli inb isd osb osd \
6
1707 ops bra bra bra bra bra bra bra bra bra bra bra bra bra bra bra bra \
7
1709 ops ali ali ??? ali txb txb txb txb mov mov mov mov mrs lea msr
8F
. \
8
1710 ops xga xga xga xga xga xga xga xga cbw cdq cis w8f psf ppf sah lah \
9
1711 ops mv1 mv1 mv2 mv2 mvs mvs cps cps tst tst sts sts lds lds scs scs \ A
1712 ops mri mri mri mri mri mri mri mri mri mri mri mri mri mri mri mri \ B
1714 ops shf shf rtn rtn lxs lxs mvi mvi ent lev rtf rtf nt3 int nto irt \ C
1715 ops shf shf shf shf aam aad ??? xlt fd8 fd9 fda fdb fdc fdd fde fdf \ D
1716 ops lup lup lup lup inp inp otp otp jsr jmp cis jmp ind ind otd otd \ E
1717 ops lok ??? rpz rep hlt cmc F6
. F6
. clc stc cli sti cld std FE
. FF
. \ F
1718 \
0 1 2 3 4 5 6 7 8 9 A B C D E F
1721 \
-------------------------- SSE2 Operations
-------------------------------
1723 \
-- swap reg fields in mod
-r
/m byte
1724 : swap
-regs
( u1
-- u2
)
1727 r@
( mod
-r
/m
) 7 and
3 lshift
1728 r@
( mod
-r
/m
) 3 rshift
7 and or
1729 r@
( mod
-r
/m
) $C0 and or
1733 : ?swap
-regs
( u1
-- u2
) DUP $C0 AND $C0
= IF swap
-regs
ENDIF ;
1735 : modbyte
( mod
-r
-r
/m
-- r
/m r mod
) ( r including general
, special
, segment
, MMX
)
1736 ( mod
-op
-r
/m
-- r
/m op mod
)
1737 0xff AND
8 /MOD
8 /MOD
1741 : mod
-r
/m
( addr modr
/m
-- addr
' )
1742 modbyte NIP ( [mod-r-r/m] -- r/m mod )
1743 dis.default-16bit? if mod-r/m16 else mod-r/m32 then
1747 \ : ::imm8 ( addr -- addr' ) ., dis
-cfetch h
.>s
;
1748 : stab
( pos
- ) s
-buf c@
- 1 max sspaces
;
1749 : rstab
( -- ) 0x8 stab
;
1750 : R
:sse2
( -- ) true
TO xmm
-reg false
TO mmx
-reg
;
1751 : R
:reg
( a n
-- a
) 7 and reg
;
1752 : 0f
-prefix?
( adr
-- adr
' flag ) dup 1+ c@ 0xF = ;
1754 : xm-r/m,r ( addr -- addr' ) rstab R
:sse2 r
/m
,r
;
1756 : xm
-r
,r
/m
( addr
-- addr
' ) rstab R:sse2 r,r/m ;
1758 : r32/m,xmmr ( addr -- addr' ) \ the register is always XMM
1759 rstab dis
-cfetch ?swap
-regs
1761 dup
>r mod
-r
/m
., r
> 3 rshift R
:reg
;
1763 : xmmr
,r32
/m
( addr
-- addr
' ) \ dest register is XMM
1764 rstab true to xmm-reg dis-cfetch dup 3 rshift R:reg
1765 ., false to xmm-reg r/m16/32 ;
1767 : r,xmm ( addr -- addr' ) \
1st
=r32
2nd
=XMM
1768 rstab false
to xmm
-reg dis
-cfetch dup
3 rshift
1771 : .cmp
-sse
( adr
-- adr
' )
1774 0 of .s" cmpeq" endof
1775 1 of .s" cmplt" endof
1776 2 of .s" cmple" endof
1777 3 of .s" cmpunord" endof
1778 4 of .s" cmpneq" endof
1779 5 of .s" cmpnlt" endof
1780 6 of .s" cmpnle" endof
1781 7 of .s" cmpord" endof
1784 : dis-cmpps ( adr -- adr' ) .cmp
-sse
.s
" ps" xm
-r
,r
/m
1+ ;
1785 : dis
-cmpss
( adr
-- adr
' ) .cmp-sse .s" ss" xm-r,r/m 1+ ;
1786 : dis-cmppd ( adr -- adr' ) .cmp
-sse
.s
" pd" xm
-r
,r
/m
1+ ;
1787 : dis
-cmpsd
( adr
-- adr
' ) .cmp-sse .s" sd" xm-r,r/m 1+ ;
1789 : save-adr ( adr flag -- flag adr adr ) true swap dup ;
1790 : restore-adr ( true adr adr1 -- false adr adr adr )
1791 2drop nip false swap dup dup ;
1793 : get-adrfl ( flag adr adr' -- adrfl flag
)
1799 : ?dis
-3Aext
( adr
-- adr
' )
1802 $40 of .s" dpps" xm-r,r/m imm8 endof
1803 $41 of .s" dppd" xm-r,r/m imm8 endof
1807 : ?dis-660f ( adr flag -- adr' flag
)
1808 if save
-adr
2 + dis
-cfetch
1810 $
10 of
.s
" movupd" xm
-r
,r
/m endof
1811 $
11 of
.s
" movupd" r32
/m
,xmmr endof
1812 $
12 of
.s
" movlpd" xm
-r
,r
/m endof
1813 $
13 of
.s
" movlpd" r32
/m
,xmmr endof
1814 $
14 of
.s
" unpcklpd" xmmr
,r32
/m endof
1815 $
15 of
.s
" unpckhpd" xmmr
,r32
/m endof
1816 $
16 of
.s
" movhpd" xm
-r
,r
/m endof
1817 $
17 of
.s
" movhpd" r32
/m
,xmmr endof
1818 $
28 of
.s
" movapd" xm
-r
,r
/m endof
1819 $
29 of
.s
" movapd" r32
/m
,xmmr endof
1820 $
2e of
.s
" ucomisd" xm
-r
,r
/m endof
1821 $
2f of
.s
" comisd" xm
-r
,r
/m endof
1822 $
3a of ?dis
-3Aext endof
1823 $
51 of
.s
" sqrtpd" xm
-r
,r
/m endof
1824 $
54 of
.s
" sqrtpd" xm
-r
,r
/m endof
1825 $
54 of
.s
" andpd" xm
-r
,r
/m endof
1826 $
55 of
.s
" andnpd" xm
-r
,r
/m endof
1827 $
56 of
.s
" orpd" xm
-r
,r
/m endof
1828 $
57 of
.s
" xorpd" xm
-r
,r
/m endof
1829 $
58 of
.s
" addpd" xm
-r
,r
/m endof
1830 $
59 of
.s
" mulpd" xm
-r
,r
/m endof
1831 $
5a of
.s
" cvtps2ps" xm
-r
,r
/m endof
1832 $
5b of
.s
" cvtps2dq" xm
-r
,r
/m endof
1833 $
5c of
.s
" subpd" xm
-r
,r
/m endof
1834 $
5d of
.s
" minpd" xm
-r
,r
/m endof
1835 $
5e of
.s
" divpd" xm
-r
,r
/m endof
1836 $
5f of
.s
" maxpd" xm
-r
,r
/m endof
1837 $
6e of
.s
" movd" xm
-r
,r
/m endof
1838 $
7e of
.s
" movd" r32
/m
,xmmr endof
1839 $
6f of
.s
" movqda" xmmr
,r32
/m endof
1840 $
7f of
.s
" movqda" r32
/m
,xmmr endof
1841 $c2 of dis
-cmppd endof
1842 $c6 of
.s
" shufpd" xm
-r
,r
/m imm8 endof
1843 $d7 of
.s
" pmovmskb" r
,xmm endof
1846 else false \ no
66 0f
1849 : ?dis
-0f
( adr flag
-- adr
' flag )
1850 if true swap 1+ dis-cfetch
1852 $10 of .s" movups" xm-r,r/m endof
1853 $11 of .s" movups" r32/m,xmmr endof
1854 $14 of .s" unpcklps" xmmr,r32/m endof
1855 $15 of .s" unpckhps" xmmr,r32/m endof
1856 $28 of .s" movaps" xm-r,r/m endof
1857 $29 of .s" movaps" r32/m,xmmr endof
1858 $2a of .s" movaps" xmmr,r32/m endof
1859 $2e of .s" ucomisd" xm-r,r/m endof
1860 $2f of .s" comiss" xm-r,r/m endof
1861 $51 of .s" sqrtps" xm-r,r/m endof
1862 $52 of .s" rsqrtps" xm-r,r/m endof
1863 $53 of .s" rcpps" xm-r,r/m endof
1864 $54 of .s" andps" xm-r,r/m endof
1865 $55 of .s" andnps" xm-r,r/m endof
1866 $56 of .s" orps" xm-r,r/m endof
1867 $57 of .s" xorps" xm-r,r/m endof
1868 $58 of .s" addps" xm-r,r/m endof
1869 $59 of .s" mulps" xm-r,r/m endof
1870 $5a of .s" cvtps2pd" xm-r,r/m endof
1871 $5b of .s" cvtdq2ps" xm-r,r/m endof
1872 $5c of .s" subps" xm-r,r/m endof
1873 $5d of .s" minps" xm-r,r/m endof
1874 $5e of .s" divps" xm-r,r/m endof
1875 $5f of .s" maxps" xm-r,r/m endof
1876 $c2 of dis-cmpps endof
1877 $c6 of .s" shufps" xm-r,r/m imm8 endof
1883 : ?dis-f20f ( adr flag -- adr' flag
)
1884 if save
-adr
2 + dis
-cfetch
1886 $
10 of
.s
" movsd" xm
-r
,r
/m endof
1887 $
11 of
.s
" movsd" xm
-r
/m
,r endof
1888 $
2a of
.s
" cvtsi2sd" xmmr
,r32
/m endof
1889 $
51 of
.s
" sqrtsd" xm
-r
,r
/m endof
1890 $
52 of
.s
" rsqrtsd" xm
-r
,r
/m endof
1891 $
58 of
.s
" addsd" xm
-r
,r
/m endof
1892 $
59 of
.s
" mulsd" xm
-r
,r
/m endof
1893 $
5a of
.s
" cvtsd2ss" xm
-r
,r
/m endof
1894 $
5c of
.s
" subsd" xm
-r
,r
/m endof
1895 $
5d of
.s
" minsd" xm
-r
,r
/m endof
1896 $
5e of
.s
" divsd" xm
-r
,r
/m endof
1897 $
5f of
.s
" maxsd" xm
-r
,r
/m endof
1898 $c2 of dis
-cmpsd endof
1899 $e6 of
.s
" cvtpd2dq" xmmr
,r32
/m endof
1902 else false \ no f2
0f
1905 : ?dis
-f30f
( adr flag
-- adr
' flag )
1906 if save-adr 2 + dis-cfetch \ f a0 a1
1908 $10 of .s" movss" xm-r,r/m endof
1909 $11 of .s" movss" xm-r/m,r endof
1910 $2a of .s" cvtsi2ss" xmmr,r32/m endof
1911 $51 of .s" sqrtss" xm-r,r/m endof
1912 $52 of .s" rsqrtss" xm-r,r/m endof
1913 $53 of .s" rcpss" xm-r,r/m endof
1914 $58 of .s" addss" xm-r,r/m endof
1915 $59 of .s" mulss" xm-r,r/m endof
1916 $5a of .s" cvtss2sd" xm-r,r/m endof
1917 $5b of .s" cvttps2dq" xm-r/m,r endof
1918 $5c of .s" subss" xm-r,r/m endof
1919 $5d of .s" minss" xm-r,r/m endof
1920 $5e of .s" divss" xm-r,r/m endof
1921 $5f of .s" maxss" xm-r,r/m endof
1922 $6f of .s" movdqu" xm-r,r/m endof
1923 $7f of .s" movdqu" r32/m,xmmr endof
1924 $c2 of dis-cmpss endof
1925 $e6 of .s" cvtdq2pd" xmmr,r32/m endof
1928 else false \ no f3 0f
1932 : pf-coded? ( adr -- adr' flag
)
1935 0x66 of
0f
-prefix? ?dis
-660f endof
1936 0xf2 of
0f
-prefix? ?dis
-f20f endof
1937 0xf3 of
0f
-prefix? ?dis
-f30f endof
1941 : prefix
-coded?
( adr
-- adr
' flag )
1944 else dup dup c@ 0xf = ?dis-0f
1950 \ ------------------- END OF SSE2 Operations -------------------------------
1953 : op-2byte 0xffff and , ' , ;
1955 : inh
-sized
( -<name
>- )
1958 count cell
+ allot drop
1960 count cell
+ allot drop
1963 default-16bit?
if + count
endif
1965 drop \ instruction code
1970 inh
-sized cwd cwd cdw
1971 inh
-sized cbwx cbw cwb
1972 inh
-sized cmpsx cmpsw cmpsd
1973 inh
-sized lodsx lodsw lodsd
1974 inh
-sized movsx movsw movsd
1975 inh
-sized stosx stosw stosd
1976 inh
-sized scasx scasw scasd
1977 inh
-sized insx insw insw
1978 inh
-sized outsx outsw outsd
1979 inh
-sized popax popa popad
1980 inh
-sized pushax pusha pushad
1981 inh
-sized popfx popf popfd
1982 inh
-sized pushfx pushf pushfd
1983 inh
-sized iretx iretw iret
1985 \ FIXME
: 16-bit is broken
1988 0x9866 op
-2byte cbwx
1989 0xA566 op
-2byte movsx
1990 0xA766 op
-2byte cmpsx
1991 0xAB66 op
-2byte stosx
1992 0xAF66 op
-2byte scasx
1993 0xAD66 op
-2byte lodsx
1994 0x6D66 op
-2byte insx
1995 0x6F66 op
-2byte outsx
1996 0x6166 op
-2byte popax
1997 0x6066 op
-2byte pushax
1998 0x9D66 op
-2byte popfx
1999 0x9C66 op
-2byte pushfx
2000 0xCF66 op
-2byte iretx
2003 : (dis
-op
-init
-flags
) ( -- )
2004 false
to data
-size
-prefix
2005 false
to disp
-as
-reg
-offset
2010 : (dis
-op
-done
-flags
) ( -- )
2012 default-16bit? dup
to 16-bit
-data
to 16-bit
-addr
2014 false
to prefix
-op
-a16
-d16
2018 : (dis
-known
-wtable
) ( addr
-- addr
' true // addr false )
2019 dis-wpeek 2byte-oplist ( addr wp tbladdr )
2020 begin 2dup w@ - while dup w@ while 2 +cells repeat
2022 \ dis-wpeek bswap-word 1 and to size
2023 cell+ @ 0 swap execute 2+ true
2029 : (dis-op-intr) ( adr -- adr' )
2031 false
to prefix
-op \ SMuB
2032 (dis
-known
-wtable
) ifnot
2035 dup cells op
-table
+ @execute
2039 : dis
-op
( adr
-- adr
' )
2042 (dis-op-intr) prefix-op ifnot break endif
2043 prefix-seg prefix-op-a16-d16 or ifnot break endif
2049 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2053 : .s-buf ( -- ) s-buf ccount type ;
2057 ;; on error, "next-inst" is unchanged
2058 : (.one-inst) ( -- errorflag )
2060 dup dis-op ;; addr eaddr
2061 over base-addr - .hex8 space ;; type address
2062 swap 2dup - 16 u> if 2drop true endif
2063 over to next-inst ;; update next instruction address
2064 2dup do i c@ .hex2 space loop
2065 - 12 swap - 3 * spaces
2070 : .inst ( adr -- adr' )
2072 (.one
-inst
) if 666 throw
endif
2077 \ @@@ BH fixed bugs in dis
-xx
2080 \
: dis
-db
( adr
-- adr
' ) 0>s .s" db " dis-cfetch h.>s .s-buf ;
2081 \ : dis-dw ( adr -- adr' ) 0>s
.s
" dw " W@
+ h
.>s
.s
-buf
;
2082 \
: dis
-dd
( adr
-- adr
' ) 0>s .s" dd " @+ h.>s .s-buf ;
2083 \ : dis-ds ( adr -- adr' ) 0>s
.s
" string " $
22 emit
>s ccount
2dup
>s
+ $
22 emit
>s
.s
-buf
;
2086 previous definitions
2088 : disasm
-one
( adr
-- adr
' )
2092 : disasm-word ( cfa -- )
2096 word-type-forth of ." forth word" cr endof
2097 word-type-const of ." constant" cr endof
2098 word-type-var of ." variable" cr endof
2099 word-type-value of ." value" cr endof
2100 word-type-defer of ." defer" cr endof
2101 word-type-does of ." doer" cr endof
2102 \ looks like a code word
2104 endcr ." === DISASM FOR '" over cfa->nfa id. ." '===\n" ;; '
2106 over dup word
-code
-end
2107 ;; ( cfa type cfa endaddr
)
2109 ;; ( cfa type cfa endaddr
)
2110 swap
to disx86
:next
-inst
2112 ;; ( cfa type codeend
)
2113 disx86
:next
-inst over u
<
2115 disx86
:(.one
-inst
) cr
2118 ;; ( cfa type codeend
)
2121 endcr
." -------------------\n"