+;;; Disassembling x86 code needs to take into account little things
+;;; like instructions that have a byte/word length bit in their
+;;; encoding, prefixes to change the default word length for a single
+;;; instruction, and so on. Unfortunately, there is no easy way with
+;;; this disassembler framework to handle prefixes that will work
+;;; correctly in all cases, so we copy the x86-64 version which at
+;;; least can handle the code output by the compiler.
+;;;
+;;; Width information for an instruction is stored as an inst-prop on
+;;; the dstate. The inst-props are cleared automatically after each
+;;; instruction, must be set by prefilters, and contain a single bit
+;;; of data each (presence/absence). As such, each instruction that
+;;; can emit an operand-size prefix (x66 prefix) needs to have a set
+;;; of printers declared for both the prefixed and non-prefixed
+;;; encodings.
+
+;;; Return the operand size based on the prefixes and width bit from
+;;; the dstate.
+(defun inst-operand-size (dstate)
+ (declare (type sb!disassem:disassem-state dstate))
+ (cond ((sb!disassem:dstate-get-inst-prop dstate 'operand-size-8)
+ :byte)
+ ((sb!disassem:dstate-get-inst-prop dstate 'operand-size-16)
+ :word)
+ (t
+ +default-operand-size+)))
+
+;;; Return the operand size for a "word-sized" operand based on the
+;;; prefixes from the dstate.
+(defun inst-word-operand-size (dstate)
+ (declare (type sb!disassem:disassem-state dstate))
+ (if (sb!disassem:dstate-get-inst-prop dstate 'operand-size-16)
+ :word
+ :dword))
+