• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • 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
            • Select-address-size
            • Rex-byte-from-vex-prefixes
            • Check-instruction-length
            • Error-objects
            • Rip-guard-okp
            • Sib-decoding
              • Sib-structures
              • X86-decode-sib-p
            • 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
    • Sib-decoding

    X86-decode-sib-p

    Returns a boolean saying whether a SIB byte is expected to follow a ModR/M byte or not.

    Signature
    (x86-decode-sib-p modr/m 16-bit-addressp) → bool
    Arguments
    16-bit-addressp — Guard (booleanp 16-bit-addressp).
    Returns
    bool — Type (booleanp bool), given (n08p modr/m).

    This is based on Intel manual, Jan'19, Volume 2, Tables 2-1 and 2-2, as well as AMD manual, Dec'17, Volume 3, Tables A-33 and A-35. When the address size is 32 or 64 bits, Intel Table 2-2 and AMD Table A-35 apply: a SIB byte is expected exactly when ModR/M.mod is not #b11 and ModR/M.r/m is #b100. When the address size is 16 bits, no SIB byte is expected.

    Intel Table 2-3 applies to 32-bit addresses, but Section 2.2.1.3 says that it also applies to 64-bit addresses. AMD Table A-35 mentions both 32-bit and 64-bit addressing.

    Intel manual, Jan'19, Volume 2, Table 2-7 is not very clear, giving the impression that a SIB byte may be required when Mod = 00 and R/M = 101 (last column of first row). But AMD manual, Dec'17, Volume 3, Table 1-16 (which corresponds to Intel Table 2-7) clearly says that no SIB byte is present in the first row. Intel's last column of first row means that, in order to use Disp32 instead of RIP+Disp32, 64-bit mode must use the encoding with SIB in the second row.

    The second argument of this function says whether the address size is 16 bits or not (i.e. 32 or 64 bits). In 64-bit mode, this argument is always nil. In 32-bit mode, this argument may be t or nil.

    Definitions and Theorems

    Function: x86-decode-sib-p

    (defun x86-decode-sib-p (modr/m 16-bit-addressp)
      (declare (type (unsigned-byte 8) modr/m))
      (declare (xargs :guard (booleanp 16-bit-addressp)))
      (let ((__function__ 'x86-decode-sib-p))
        (declare (ignorable __function__))
        (and (not 16-bit-addressp)
             (b* ((r/m (modr/m->r/m modr/m))
                  (mod (modr/m->mod modr/m)))
               (and (int= r/m 4)
                    (not (int= mod 3)))))))

    Theorem: booleanp-of-x86-decode-sib-p

    (defthm booleanp-of-x86-decode-sib-p
      (implies (n08p modr/m)
               (b* ((bool (x86-decode-sib-p modr/m 16-bit-addressp)))
                 (booleanp bool)))
      :rule-classes :rewrite)