• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • ACL2
    • Macro-libraries
    • 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
              • X86-effective-addr-32/64
              • X86-effective-addr-from-sib
              • X86-effective-addr-16
              • X86-effective-addr-16-disp
                • X86-effective-addr
              • 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
            • 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
    • Effective-address-computations

    X86-effective-addr-16-disp

    Calculate the displacement for 16-bit effective address calculation.

    Signature
    (x86-effective-addr-16-disp proc-mode temp-rip mod x86) 
      → 
    (mv flg disp increment-rip-by x86)
    Arguments
    mod — mod field of ModR/M byte.
    Returns
    disp — Type (i16p disp), given (x86p x86).
    increment-rip-by — Type (natp increment-rip-by).
    x86 — Type (x86p x86), given (x86p x86).

    This is according to Intel manual, Mar'17, Vol. 2, Table 2-1.

    The displacement is absent (i.e. 0) when Mod is 00b. An exception to this is when R/M is 110b, in which case there is a 16-bit displacement that is added to the index. This case is not handled by this function, but is instead handled in its caller function x86-effective-addr-16.

    The displacement is a signed 8-bit value when Mod is 01b. The displacement is a signed 16-bit value when Mod is 10b. This function is not called when Mod is 11b.

    If an error occurs when trying to read the displacement, 0 is returned as displacement, but the caller ignores the returned displacement given the error.

    This function is called only when the address size is 16 bits.

    Definitions and Theorems

    Function: x86-effective-addr-16-disp

    (defun x86-effective-addr-16-disp (proc-mode temp-rip mod x86)
      (declare (xargs :stobjs (x86)))
      (declare (type (integer 0 4) proc-mode)
               (type (signed-byte 48) temp-rip)
               (type (unsigned-byte 2) mod))
      (declare (xargs :guard (2bits-p mod)))
      (let ((__function__ 'x86-effective-addr-16-disp))
        (declare (ignorable __function__))
        (case mod
          (0 (mv nil 0 0 x86))
          (1 (b* (((mv flg byte x86)
                   (rime-size-opt proc-mode 1 temp-rip 1 :x nil x86
                                  :mem-ptr? nil))
                  ((when flg) (mv flg 0 0 x86)))
               (mv nil byte 1 x86)))
          (2 (b* (((mv flg word x86)
                   (rime-size-opt proc-mode 2 temp-rip 1 :x nil x86
                                  :mem-ptr? nil))
                  ((when flg) (mv flg 0 0 x86)))
               (mv nil word 2 x86)))
          (otherwise (mv 'mod-value-wrong 0 0 x86)))))

    Theorem: i16p-of-x86-effective-addr-16-disp.disp

    (defthm i16p-of-x86-effective-addr-16-disp.disp
     (implies
         (x86p x86)
         (b* (((mv ?flg ?disp ?increment-rip-by ?x86)
               (x86-effective-addr-16-disp proc-mode temp-rip mod x86)))
           (i16p disp)))
     :rule-classes :rewrite)

    Theorem: natp-of-x86-effective-addr-16-disp.increment-rip-by

    (defthm natp-of-x86-effective-addr-16-disp.increment-rip-by
      (b* (((mv ?flg ?disp ?increment-rip-by ?x86)
            (x86-effective-addr-16-disp proc-mode temp-rip mod x86)))
        (natp increment-rip-by))
      :rule-classes :rewrite)

    Theorem: x86p-of-x86-effective-addr-16-disp.x86

    (defthm x86p-of-x86-effective-addr-16-disp.x86
     (implies
         (x86p x86)
         (b* (((mv ?flg ?disp ?increment-rip-by ?x86)
               (x86-effective-addr-16-disp proc-mode temp-rip mod x86)))
           (x86p x86)))
     :rule-classes :rewrite)

    Theorem: integerp-of-x86-effective-addr-16-disp.disp

    (defthm integerp-of-x86-effective-addr-16-disp.disp
     (implies
         (x86p x86)
         (b* (((mv ?flg ?disp ?increment-rip-by ?x86)
               (x86-effective-addr-16-disp proc-mode temp-rip mod x86)))
           (integerp disp)))
     :rule-classes :type-prescription)

    Theorem: mv-nth-2-x86-effective-addr-16-disp-<=-4

    (defthm mv-nth-2-x86-effective-addr-16-disp-<=-4
     (<=
        (mv-nth 2
                (x86-effective-addr-16-disp proc-mode temp-rip mod x86))
        4)
     :rule-classes :linear)