• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
      • X86isa
        • Program-execution
        • Sdm-instruction-set-summary
        • Tlb
        • Running-linux
        • Introduction
        • Asmtest
        • X86isa-build-instructions
        • Publications
        • Contributors
        • Machine
          • X86isa-state
          • Syscalls
          • Cpuid
          • Linear-memory
          • Rflag-specifications
          • Characterizing-undefined-behavior
          • Top-level-memory
          • App-view
          • X86-decoder
          • Physical-memory
          • Decoding-and-spec-utils
            • Read-operands-and-write-results
            • Effective-address-computations
            • Select-operand-size
            • Instruction-pointer-operations
            • Stack-pointer-operations
            • Select-segment-register
            • Prefix-modrm-sib-decoding
              • Modr/m-decoding
                • Modr/m-structures
                • Three-byte-opcode-modr/m-p
                • 64-bit-mode-0f-3a-three-byte-opcode-modr/m-p
                • 64-bit-mode-0f-38-three-byte-opcode-modr/m-p
                • 32-bit-mode-0f-3a-three-byte-opcode-modr/m-p
                • 32-bit-mode-0f-38-three-byte-opcode-modr/m-p
                • 64-bit-mode-two-byte-opcode-modr/m-p
                • 32-bit-mode-two-byte-opcode-modr/m-p
                • Two-byte-opcode-modr/m-p
                • Show-no-modr/m-insts
                • 64-bit-mode-one-byte-opcode-modr/m-p
                • 32-bit-mode-one-byte-opcode-modr/m-p
                • Vex-opcode-modr/m-p
                • One-byte-opcode-modr/m-p
              • Mandatory-prefixes-computation
              • Modr/m-detection
              • Legacy-prefixes-decoding
              • Compute-mandatory-prefix-for-three-byte-opcode
              • 64-bit-compute-mandatory-prefix-for-0f-3a-three-byte-opcode
              • 64-bit-compute-mandatory-prefix-for-0f-38-three-byte-opcode
              • 32-bit-compute-mandatory-prefix-for-0f-3a-three-byte-opcode
              • 32-bit-compute-mandatory-prefix-for-0f-38-three-byte-opcode
              • 64-bit-compute-mandatory-prefix-for-two-byte-opcode
              • 32-bit-compute-mandatory-prefix-for-two-byte-opcode
              • Instructions-with-mandatory-prefixes
              • Compute-mandatory-prefix-for-0f-3a-three-byte-opcode
              • Compute-mandatory-prefix-for-0f-38-three-byte-opcode
              • Compute-mandatory-prefix-for-two-byte-opcode
            • Select-address-size
            • Rex-byte-from-vex-prefixes
            • Check-instruction-length
            • Error-objects
            • Rip-guard-okp
            • Sib-decoding
          • Instructions
          • Register-readers-and-writers
          • X86-modes
          • Segmentation
          • Other-non-deterministic-computations
          • Environment
          • Paging
        • Implemented-opcodes
        • To-do
        • Proof-utilities
        • Peripherals
        • Model-validation
        • Modelcalls
        • Concrete-simulation-examples
        • Utils
        • Debugging-code-proofs
      • Axe
      • Execloader
    • Math
    • Testing-utilities
  • Prefix-modrm-sib-decoding

Modr/m-decoding

Functions to detect and decode ModR/M bytes

Definitions and Theorems

Function: 64-bit-mode-one-byte-opcode-modr/m-p$inline

(defun 64-bit-mode-one-byte-opcode-modr/m-p$inline (opcode)
  (declare (type (unsigned-byte 8) opcode))
  (aref1 '64-bit-mode-one-byte-has-modr/m
         *64-bit-mode-one-byte-has-modr/m-ar*
         opcode))

Theorem: booleanp-of-64-bit-mode-one-byte-opcode-modr/m-p

(defthm booleanp-of-64-bit-mode-one-byte-opcode-modr/m-p
 (implies
   (n08p opcode)
   (b* ((bool (64-bit-mode-one-byte-opcode-modr/m-p$inline opcode)))
     (booleanp bool)))
 :rule-classes :rewrite)

Function: 32-bit-mode-one-byte-opcode-modr/m-p$inline

(defun 32-bit-mode-one-byte-opcode-modr/m-p$inline (opcode)
  (declare (type (unsigned-byte 8) opcode))
  (aref1 '32-bit-mode-one-byte-has-modr/m
         *32-bit-mode-one-byte-has-modr/m-ar*
         opcode))

Theorem: booleanp-of-32-bit-mode-one-byte-opcode-modr/m-p

(defthm booleanp-of-32-bit-mode-one-byte-opcode-modr/m-p
 (implies
   (n08p opcode)
   (b* ((bool (32-bit-mode-one-byte-opcode-modr/m-p$inline opcode)))
     (booleanp bool)))
 :rule-classes :rewrite)

Function: one-byte-opcode-modr/m-p$inline

(defun one-byte-opcode-modr/m-p$inline (proc-mode opcode)
  (declare (type (integer 0 4) proc-mode)
           (type (unsigned-byte 8) opcode))
  (if (equal proc-mode 0)
      (64-bit-mode-one-byte-opcode-modr/m-p opcode)
    (32-bit-mode-one-byte-opcode-modr/m-p opcode)))

Theorem: booleanp-of-one-byte-opcode-modr/m-p

(defthm booleanp-of-one-byte-opcode-modr/m-p
 (implies
     (n08p opcode)
     (b* ((bool (one-byte-opcode-modr/m-p$inline proc-mode opcode)))
       (booleanp bool)))
 :rule-classes :rewrite)

Function: 64-bit-mode-two-byte-opcode-modr/m-p

(defun 64-bit-mode-two-byte-opcode-modr/m-p
       (mandatory-prefix opcode)
  (declare (type (unsigned-byte 8)
                 mandatory-prefix)
           (type (unsigned-byte 8) opcode))
  (let ((__function__ '64-bit-mode-two-byte-opcode-modr/m-p))
    (declare (ignorable __function__))
    (case mandatory-prefix
      (102 (aref1 '64-bit-mode-two-byte-66-has-modr/m
                  *64-bit-mode-two-byte-66-has-modr/m-ar*
                  opcode))
      (243 (aref1 '64-bit-mode-two-byte-f3-has-modr/m
                  *64-bit-mode-two-byte-f3-has-modr/m-ar*
                  opcode))
      (242 (aref1 '64-bit-mode-two-byte-f2-has-modr/m
                  *64-bit-mode-two-byte-f2-has-modr/m-ar*
                  opcode))
      (t (aref1 '64-bit-mode-two-byte-no-prefix-has-modr/m
                *64-bit-mode-two-byte-no-prefix-has-modr/m-ar*
                opcode)))))

Theorem: booleanp-of-64-bit-mode-two-byte-opcode-modr/m-p

(defthm booleanp-of-64-bit-mode-two-byte-opcode-modr/m-p
  (implies (n08p opcode)
           (b* ((bool (64-bit-mode-two-byte-opcode-modr/m-p
                           mandatory-prefix opcode)))
             (booleanp bool)))
  :rule-classes :rewrite)

Function: 32-bit-mode-two-byte-opcode-modr/m-p

(defun 32-bit-mode-two-byte-opcode-modr/m-p
       (mandatory-prefix opcode)
  (declare (type (unsigned-byte 8)
                 mandatory-prefix)
           (type (unsigned-byte 8) opcode))
  (let ((__function__ '32-bit-mode-two-byte-opcode-modr/m-p))
    (declare (ignorable __function__))
    (case mandatory-prefix
      (102 (aref1 '32-bit-mode-two-byte-66-has-modr/m
                  *32-bit-mode-two-byte-66-has-modr/m-ar*
                  opcode))
      (243 (aref1 '32-bit-mode-two-byte-f3-has-modr/m
                  *32-bit-mode-two-byte-f3-has-modr/m-ar*
                  opcode))
      (242 (aref1 '32-bit-mode-two-byte-f2-has-modr/m
                  *32-bit-mode-two-byte-f2-has-modr/m-ar*
                  opcode))
      (t (aref1 '32-bit-mode-two-byte-no-prefix-has-modr/m
                *32-bit-mode-two-byte-no-prefix-has-modr/m-ar*
                opcode)))))

Theorem: booleanp-of-32-bit-mode-two-byte-opcode-modr/m-p

(defthm booleanp-of-32-bit-mode-two-byte-opcode-modr/m-p
  (implies (n08p opcode)
           (b* ((bool (32-bit-mode-two-byte-opcode-modr/m-p
                           mandatory-prefix opcode)))
             (booleanp bool)))
  :rule-classes :rewrite)

Function: two-byte-opcode-modr/m-p$inline

(defun two-byte-opcode-modr/m-p$inline
       (proc-mode mandatory-prefix opcode)
 (declare (type (integer 0 4) proc-mode)
          (type (unsigned-byte 8)
                mandatory-prefix)
          (type (unsigned-byte 8) opcode))
 (cond
  ((equal proc-mode 0)
   (64-bit-mode-two-byte-opcode-modr/m-p mandatory-prefix opcode))
  (t
   (32-bit-mode-two-byte-opcode-modr/m-p mandatory-prefix opcode))))

Theorem: booleanp-of-two-byte-opcode-modr/m-p

(defthm booleanp-of-two-byte-opcode-modr/m-p
  (implies (n08p opcode)
           (b* ((bool (two-byte-opcode-modr/m-p$inline
                           proc-mode mandatory-prefix opcode)))
             (booleanp bool)))
  :rule-classes :rewrite)

Function: 64-bit-mode-0f-38-three-byte-opcode-modr/m-p

(defun 64-bit-mode-0f-38-three-byte-opcode-modr/m-p
       (mandatory-prefix opcode)
 (declare (type (unsigned-byte 8)
                mandatory-prefix)
          (type (unsigned-byte 8) opcode))
 (let ((__function__ '64-bit-mode-0f-38-three-byte-opcode-modr/m-p))
  (declare (ignorable __function__))
  (case mandatory-prefix
    (102 (aref1 '64-bit-mode-0f-38-three-byte-66-has-modr/m
                *64-bit-mode-0f-38-three-byte-66-has-modr/m-ar*
                opcode))
    (243 (aref1 '64-bit-mode-0f-38-three-byte-f3-has-modr/m
                *64-bit-mode-0f-38-three-byte-f3-has-modr/m-ar*
                opcode))
    (242 (aref1 '64-bit-mode-0f-38-three-byte-f2-has-modr/m
                *64-bit-mode-0f-38-three-byte-f2-has-modr/m-ar*
                opcode))
    (t (aref1 '64-bit-mode-0f-38-three-byte-no-prefix-has-modr/m
              *64-bit-mode-0f-38-three-byte-no-prefix-has-modr/m-ar*
              opcode)))))

Theorem: booleanp-of-64-bit-mode-0f-38-three-byte-opcode-modr/m-p

(defthm booleanp-of-64-bit-mode-0f-38-three-byte-opcode-modr/m-p
  (implies (n08p opcode)
           (b* ((bool (64-bit-mode-0f-38-three-byte-opcode-modr/m-p
                           mandatory-prefix opcode)))
             (booleanp bool)))
  :rule-classes :rewrite)

Function: 32-bit-mode-0f-38-three-byte-opcode-modr/m-p

(defun 32-bit-mode-0f-38-three-byte-opcode-modr/m-p
       (mandatory-prefix opcode)
 (declare (type (unsigned-byte 8)
                mandatory-prefix)
          (type (unsigned-byte 8) opcode))
 (let ((__function__ '32-bit-mode-0f-38-three-byte-opcode-modr/m-p))
  (declare (ignorable __function__))
  (case mandatory-prefix
    (102 (aref1 '32-bit-mode-0f-38-three-byte-66-has-modr/m
                *32-bit-mode-0f-38-three-byte-66-has-modr/m-ar*
                opcode))
    (243 (aref1 '32-bit-mode-0f-38-three-byte-f3-has-modr/m
                *32-bit-mode-0f-38-three-byte-f3-has-modr/m-ar*
                opcode))
    (242 (aref1 '32-bit-mode-0f-38-three-byte-f2-has-modr/m
                *32-bit-mode-0f-38-three-byte-f2-has-modr/m-ar*
                opcode))
    (t (aref1 '32-bit-mode-0f-38-three-byte-no-prefix-has-modr/m
              *32-bit-mode-0f-38-three-byte-no-prefix-has-modr/m-ar*
              opcode)))))

Theorem: booleanp-of-32-bit-mode-0f-38-three-byte-opcode-modr/m-p

(defthm booleanp-of-32-bit-mode-0f-38-three-byte-opcode-modr/m-p
  (implies (n08p opcode)
           (b* ((bool (32-bit-mode-0f-38-three-byte-opcode-modr/m-p
                           mandatory-prefix opcode)))
             (booleanp bool)))
  :rule-classes :rewrite)

Function: 64-bit-mode-0f-3a-three-byte-opcode-modr/m-p

(defun 64-bit-mode-0f-3a-three-byte-opcode-modr/m-p
       (mandatory-prefix opcode)
 (declare (type (unsigned-byte 8)
                mandatory-prefix)
          (type (unsigned-byte 8) opcode))
 (let ((__function__ '64-bit-mode-0f-3a-three-byte-opcode-modr/m-p))
  (declare (ignorable __function__))
  (case mandatory-prefix
    (102 (aref1 '64-bit-mode-0f-3a-three-byte-66-has-modr/m
                *64-bit-mode-0f-3a-three-byte-66-has-modr/m-ar*
                opcode))
    (243 (aref1 '64-bit-mode-0f-3a-three-byte-f3-has-modr/m
                *64-bit-mode-0f-3a-three-byte-f3-has-modr/m-ar*
                opcode))
    (242 (aref1 '64-bit-mode-0f-3a-three-byte-f2-has-modr/m
                *64-bit-mode-0f-3a-three-byte-f2-has-modr/m-ar*
                opcode))
    (t (aref1 '64-bit-mode-0f-3a-three-byte-no-prefix-has-modr/m
              *64-bit-mode-0f-3a-three-byte-no-prefix-has-modr/m-ar*
              opcode)))))

Theorem: booleanp-of-64-bit-mode-0f-3a-three-byte-opcode-modr/m-p

(defthm booleanp-of-64-bit-mode-0f-3a-three-byte-opcode-modr/m-p
  (implies (n08p opcode)
           (b* ((bool (64-bit-mode-0f-3a-three-byte-opcode-modr/m-p
                           mandatory-prefix opcode)))
             (booleanp bool)))
  :rule-classes :rewrite)

Function: 32-bit-mode-0f-3a-three-byte-opcode-modr/m-p

(defun 32-bit-mode-0f-3a-three-byte-opcode-modr/m-p
       (mandatory-prefix opcode)
 (declare (type (unsigned-byte 8)
                mandatory-prefix)
          (type (unsigned-byte 8) opcode))
 (let ((__function__ '32-bit-mode-0f-3a-three-byte-opcode-modr/m-p))
  (declare (ignorable __function__))
  (case mandatory-prefix
    (102 (aref1 '32-bit-mode-0f-3a-three-byte-66-has-modr/m
                *32-bit-mode-0f-3a-three-byte-66-has-modr/m-ar*
                opcode))
    (243 (aref1 '32-bit-mode-0f-3a-three-byte-f3-has-modr/m
                *32-bit-mode-0f-3a-three-byte-f3-has-modr/m-ar*
                opcode))
    (242 (aref1 '32-bit-mode-0f-3a-three-byte-f2-has-modr/m
                *32-bit-mode-0f-3a-three-byte-f2-has-modr/m-ar*
                opcode))
    (t (aref1 '32-bit-mode-0f-3a-three-byte-no-prefix-has-modr/m
              *32-bit-mode-0f-3a-three-byte-no-prefix-has-modr/m-ar*
              opcode)))))

Theorem: booleanp-of-32-bit-mode-0f-3a-three-byte-opcode-modr/m-p

(defthm booleanp-of-32-bit-mode-0f-3a-three-byte-opcode-modr/m-p
  (implies (n08p opcode)
           (b* ((bool (32-bit-mode-0f-3a-three-byte-opcode-modr/m-p
                           mandatory-prefix opcode)))
             (booleanp bool)))
  :rule-classes :rewrite)

Function: three-byte-opcode-modr/m-p$inline

(defun three-byte-opcode-modr/m-p$inline
       (proc-mode mandatory-prefix escape-byte opcode)
  (declare (type (integer 0 4) proc-mode)
           (type (unsigned-byte 8)
                 mandatory-prefix)
           (type (unsigned-byte 8) escape-byte)
           (type (unsigned-byte 8) opcode))
  (declare (xargs :guard (or (equal escape-byte 56)
                             (equal escape-byte 58))))
  (cond ((equal escape-byte 56)
         (if (equal proc-mode 0)
             (64-bit-mode-0f-38-three-byte-opcode-modr/m-p
                  mandatory-prefix opcode)
           (32-bit-mode-0f-38-three-byte-opcode-modr/m-p
                mandatory-prefix opcode)))
        (t (if (equal proc-mode 0)
               (64-bit-mode-0f-3a-three-byte-opcode-modr/m-p
                    mandatory-prefix opcode)
             (32-bit-mode-0f-3a-three-byte-opcode-modr/m-p
                  mandatory-prefix opcode)))))

Theorem: booleanp-of-three-byte-opcode-modr/m-p

(defthm booleanp-of-three-byte-opcode-modr/m-p
  (implies (n08p opcode)
           (b* ((bool (three-byte-opcode-modr/m-p$inline
                           proc-mode
                           mandatory-prefix escape-byte opcode)))
             (booleanp bool)))
  :rule-classes :rewrite)

Function: show-no-modr/m-insts

(defun show-no-modr/m-insts (inst-lst)
  (declare (xargs :guard (inst-list-p inst-lst)))
  (let ((__function__ 'show-no-modr/m-insts))
    (declare (ignorable __function__))
    (b* (((when (endp inst-lst)) nil)
         (inst (car inst-lst))
         (rest (show-no-modr/m-insts (cdr inst-lst))))
      (if (inst-needs-modr/m-p inst)
          rest
        (cons inst rest)))))

Theorem: inst-list-p-of-show-no-modr/m-insts

(defthm inst-list-p-of-show-no-modr/m-insts
  (implies (inst-list-p inst-lst)
           (b* ((no-modr/m-insts (show-no-modr/m-insts inst-lst)))
             (inst-list-p no-modr/m-insts)))
  :rule-classes :rewrite)

Function: vex-opcode-modr/m-p$inline

(defun vex-opcode-modr/m-p$inline (vex-prefixes opcode)
  (declare (type (unsigned-byte 24) vex-prefixes)
           (type (unsigned-byte 8) opcode))
  (declare (xargs :guard (vex-prefixes-byte0-p vex-prefixes)))
  (if (not (equal opcode 119))
      t
    (not (vex-prefixes-map-p 15 vex-prefixes))))

Theorem: booleanp-of-vex-opcode-modr/m-p

(defthm booleanp-of-vex-opcode-modr/m-p
  (b* ((bool (vex-opcode-modr/m-p$inline vex-prefixes opcode)))
    (booleanp bool))
  :rule-classes :rewrite)

Subtopics

Modr/m-structures
Bitstruct definitions to store a ModR/M byte and its fields.
Three-byte-opcode-modr/m-p
Returns t if a three-byte opcode requires a ModR/M byte; nil otherwise. Doesn't account for AVX/AVX2/AVX512 instructions.
64-bit-mode-0f-3a-three-byte-opcode-modr/m-p
Returns a boolean saying whether, in 64-bit mode, the given opcode in the second three-byte opcode map expects a ModR/M byte.
64-bit-mode-0f-38-three-byte-opcode-modr/m-p
Returns a boolean saying whether, in 64-bit mode, the given opcode in the first three-byte opcode map expects a ModR/M byte.
32-bit-mode-0f-3a-three-byte-opcode-modr/m-p
Returns a boolean saying whether, in 32-bit mode, the given opcode in the second three-byte opcode map expects a ModR/M byte.
32-bit-mode-0f-38-three-byte-opcode-modr/m-p
Returns a boolean saying whether, in 32-bit mode, the given opcode in the first three-byte opcode map expects a ModR/M byte.
64-bit-mode-two-byte-opcode-modr/m-p
Returns a boolean saying whether, in 64-bit mode, the given opcode in the two-byte opcode map expects a ModR/M byte.
32-bit-mode-two-byte-opcode-modr/m-p
Returns a boolean saying whether, in 32-bit mode, the given opcode in the two-byte opcode map expects a ModR/M byte.
Two-byte-opcode-modr/m-p
Returns t if a two-byte opcode requires a ModR/M byte; nil otherwise. Doesn't account for AVX/AVX2/AVX512 instructions.
Show-no-modr/m-insts
Show all the instructions in inst-lst which don't require a ModR/M byte
64-bit-mode-one-byte-opcode-modr/m-p
Returns a boolean saying whether, in 64-bit mode, the given opcode in the one-byte opcode map expects a ModR/M byte.
32-bit-mode-one-byte-opcode-modr/m-p
Returns a boolean saying whether, in 32-bit mode, the given opcode in the one-byte opcode map expects a ModR/M byte.
Vex-opcode-modr/m-p
Returns t if a VEX-encoded opcode requires a ModR/M byte; nil otherwise.
One-byte-opcode-modr/m-p
Returns t if a one-byte opcode requires a ModR/M byte; nil otherwise