From cf581cdca27885a72a57f8580a4e8093ed84c129 Mon Sep 17 00:00:00 2001 From: Douglas Katzman Date: Wed, 9 Aug 2017 14:17:53 -0400 Subject: [PATCH] x86-64: Decode FS: instruction prefix Makes it possible to disassemble foreign code using __thread storage without randomly losing sync. --- src/compiler/x86-64/insts.lisp | 3 +++ src/compiler/x86-64/target-insts.lisp | 4 ++-- tests/assembler.pure.lisp | 11 +++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/compiler/x86-64/insts.lisp b/src/compiler/x86-64/insts.lisp index 5ce45b058..2aed4b712 100644 --- a/src/compiler/x86-64/insts.lisp +++ b/src/compiler/x86-64/insts.lisp @@ -1460,6 +1460,9 @@ #!+sb-thread (emit-byte segment #xf0)))) +(define-instruction fs (segment) + (:printer byte ((op #x64)) nil)) + (define-instruction lock (segment) (:printer byte ((op #b11110000)) nil)) diff --git a/src/compiler/x86-64/target-insts.lisp b/src/compiler/x86-64/target-insts.lisp index e9d7f5aec..06fb7d421 100644 --- a/src/compiler/x86-64/target-insts.lisp +++ b/src/compiler/x86-64/target-insts.lisp @@ -128,8 +128,8 @@ (princ value stream))) ;;; Return either a MACHINE-EA or a register (a fixnum). -;;; VALUE is a list of the mod and r/m fields of the instruction's ModRM byte. -;;; Depending on VALUE, a SIB byte and/or displacement may be read. +;;; MOD and R/M are the extracted bits from the instruction's ModRM byte. +;;; Depending on MOD and R/M, a SIB byte and/or displacement may be read. ;;; The REX.B and REX.X from dstate are appropriately consumed. (defun prefilter-reg/mem (dstate mod r/m) (declare (type disassem-state dstate) diff --git a/tests/assembler.pure.lisp b/tests/assembler.pure.lisp index 758c9b63f..b33c59493 100644 --- a/tests/assembler.pure.lisp +++ b/tests/assembler.pure.lisp @@ -121,3 +121,14 @@ #+x86-64 (try `(add ,rcx-tn ,(memref :qword)) "48034D00 ADD RCX, [$fp]") )) + +(with-test (:name :disassemble-fs-prefix :skipped-on '(not (or :x86-64))) + (let ((bytes (coerce '(#x64 #xF0 #x44 #x08 #x04 #x25 #x00 #x04 #x10 #x20) + '(array (unsigned-byte 8) 1))) + (s (make-string-output-stream))) + (sb-sys:with-pinned-objects (bytes) + (sb-disassem::disassemble-memory (sb-sys:sap-int (sb-sys:vector-sap bytes)) + (length bytes) + :stream s)) + (assert (search "FS LOCK OR [#x20100400], R8B" + (get-output-stream-string s))))) -- 2.11.4.GIT