• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
      • X86isa
        • Program-execution
        • Introduction
        • X86isa-build-instructions
        • Publications
        • Contributors
        • Machine
          • Syscalls
          • Cpuid
          • X86isa-state
          • Linear-memory
          • Rflag-specifications
            • Rflags-reads-and-writes
              • Write-user-rflags
              • Undef-flg
              • Undef-flg-logic
            • General-sf-spec-fn
            • General-cf-spec-fn
            • General-pf-spec-fn
            • General-of-spec-fn
            • Zf-spec
            • Sbb-af-spec8
            • Sbb-af-spec64
            • Sbb-af-spec32
            • Sbb-af-spec16
            • Adc-af-spec8
            • Adc-af-spec64
            • Adc-af-spec32
            • Adc-af-spec16
            • Sub-af-spec8
            • Sub-af-spec64
            • Sub-af-spec32
            • Sub-af-spec16
            • Add-af-spec8
            • Add-af-spec64
            • Add-af-spec32
            • Add-af-spec16
            • Pf-spec8
            • Pf-spec64
            • Pf-spec32
            • Pf-spec16
            • Of-spec8
            • Of-spec64
            • Of-spec32
            • Of-spec16
            • Cf-spec64
            • Cf-spec32
            • Cf-spec16
            • Sf-spec8
            • Sf-spec64
            • Sf-spec32
            • Sf-spec16
            • Cf-spec8
          • Characterizing-undefined-behavior
          • Top-level-memory
          • App-view
          • X86-decoder
          • Physical-memory
          • Decoding-and-spec-utils
          • Instructions
          • X86-modes
          • Segmentation
          • Register-readers-and-writers
          • Other-non-deterministic-computations
          • Environment
          • Paging
        • Implemented-opcodes
        • Proof-utilities
        • To-do
        • Concrete-simulation-examples
        • Model-validation
        • Utils
        • Debugging-code-proofs
      • Execloader
      • Axe
    • Testing-utilities
    • Math
  • Rflag-specifications
  • Register-readers-and-writers

Rflags-reads-and-writes

Reading from and writing to the rflags register in the x86 state

We define convenient macros flgi and !flgi to read a flag's value and to write a flag's value into the rflags field in the x86 state, respectively. Additionally, !flgi-undefined can be used to write an undefined value into a particular flag.

Definitions and Theorems

Function: undef-flg-logic

(defun undef-flg-logic (x86)
       (declare (xargs :stobjs (x86)))
       (declare (xargs :guard t))
       (let ((__function__ 'undef-flg-logic))
            (declare (ignorable __function__))
            (undef-read x86)))

Theorem: natp-of-undef-flg-logic.unknown

(defthm natp-of-undef-flg-logic.unknown
        (b* (((mv ?unknown ?x86)
              (undef-flg-logic x86)))
            (natp unknown))
        :rule-classes :type-prescription)

Theorem: x86p-of-undef-flg-logic.x86

(defthm x86p-of-undef-flg-logic.x86
        (implies (x86p x86)
                 (b* (((mv ?unknown ?x86)
                       (undef-flg-logic x86)))
                     (x86p x86)))
        :rule-classes :rewrite)

Function: undef-flg$notinline

(defun undef-flg$notinline (x86)
       (declare (xargs :stobjs (x86)))
       (declare (xargs :guard t))
       (let ((__function__ 'undef-flg))
            (declare (ignorable __function__))
            (b* (((mv val x86) (undef-flg-logic x86)))
                (mv (n01 val) x86))))

Theorem: bitp-of-undef-flg.unknown-bit

(defthm bitp-of-undef-flg.unknown-bit
        (b* (((mv ?unknown-bit ?x86)
              (undef-flg$notinline x86)))
            (bitp unknown-bit))
        :rule-classes :type-prescription)

Theorem: x86p-of-undef-flg.x86

(defthm x86p-of-undef-flg.x86
        (implies (x86p x86)
                 (b* (((mv ?unknown-bit ?x86)
                       (undef-flg$notinline x86)))
                     (x86p x86)))
        :rule-classes :rewrite)

Function: write-user-rflags$inline

(defun
 write-user-rflags$inline
 (user-flags-vector undefined-mask x86)
 (declare (xargs :stobjs (x86)))
 (declare (type (unsigned-byte 32)
                user-flags-vector)
          (type (unsigned-byte 32)
                undefined-mask))
 (b*
  ((user-flags-vector (mbe :logic (n32 user-flags-vector)
                           :exec user-flags-vector))
   (undefined-mask (mbe :logic (n32 undefined-mask)
                        :exec undefined-mask))
   ((the (unsigned-byte 32) input-rflags)
    (mbe :logic (n32 (rflags x86))
         :exec (rflags x86))))
  (mbe
     :logic
     (b* ((x86 (if (equal (rflagsbits->cf undefined-mask)
                          1)
                   (!flgi-undefined :cf x86)
                   (!flgi :cf (rflagsbits->cf user-flags-vector)
                          x86)))
          (x86 (if (equal (rflagsbits->pf undefined-mask)
                          1)
                   (!flgi-undefined :pf x86)
                   (!flgi :pf (rflagsbits->pf user-flags-vector)
                          x86)))
          (x86 (if (equal (rflagsbits->af undefined-mask)
                          1)
                   (!flgi-undefined :af x86)
                   (!flgi :af (rflagsbits->af user-flags-vector)
                          x86)))
          (x86 (if (equal (rflagsbits->zf undefined-mask)
                          1)
                   (!flgi-undefined :zf x86)
                   (!flgi :zf (rflagsbits->zf user-flags-vector)
                          x86)))
          (x86 (if (equal (rflagsbits->sf undefined-mask)
                          1)
                   (!flgi-undefined :sf x86)
                   (!flgi :sf (rflagsbits->sf user-flags-vector)
                          x86)))
          (x86 (if (equal (rflagsbits->of undefined-mask)
                          1)
                   (!flgi-undefined :of x86)
                   (!flgi :of (rflagsbits->of user-flags-vector)
                          x86))))
         x86)
     :exec
     (if (eql undefined-mask 0)
         (b* ((x86 (!flgi :cf (rflagsbits->cf user-flags-vector)
                          x86))
              (x86 (!flgi :pf (rflagsbits->pf user-flags-vector)
                          x86))
              (x86 (!flgi :af (rflagsbits->af user-flags-vector)
                          x86))
              (x86 (!flgi :zf (rflagsbits->zf user-flags-vector)
                          x86))
              (x86 (!flgi :sf (rflagsbits->sf user-flags-vector)
                          x86))
              (x86 (!flgi :of (rflagsbits->of user-flags-vector)
                          x86)))
             x86)
         (b* ((x86 (if (equal (rflagsbits->cf undefined-mask)
                              1)
                       (!flgi-undefined :cf x86)
                       (!flgi :cf (rflagsbits->cf user-flags-vector)
                              x86)))
              (x86 (if (equal (rflagsbits->pf undefined-mask)
                              1)
                       (!flgi-undefined :pf x86)
                       (!flgi :pf (rflagsbits->pf user-flags-vector)
                              x86)))
              (x86 (if (equal (rflagsbits->af undefined-mask)
                              1)
                       (!flgi-undefined :af x86)
                       (!flgi :af (rflagsbits->af user-flags-vector)
                              x86)))
              (x86 (if (equal (rflagsbits->zf undefined-mask)
                              1)
                       (!flgi-undefined :zf x86)
                       (!flgi :zf (rflagsbits->zf user-flags-vector)
                              x86)))
              (x86 (if (equal (rflagsbits->sf undefined-mask)
                              1)
                       (!flgi-undefined :sf x86)
                       (!flgi :sf (rflagsbits->sf user-flags-vector)
                              x86)))
              (x86 (if (equal (rflagsbits->of undefined-mask)
                              1)
                       (!flgi-undefined :of x86)
                       (!flgi :of (rflagsbits->of user-flags-vector)
                              x86))))
             x86)))))

Theorem: x86p-of-write-user-rflags

(defthm
     x86p-of-write-user-rflags
     (implies (x86p x86)
              (b* ((x86 (write-user-rflags$inline
                             user-flags-vector undefined-mask x86)))
                  (x86p x86)))
     :rule-classes :rewrite)

Theorem: xr-write-user-rflags

(defthm xr-write-user-rflags
        (implies (and (not (equal fld :rflags))
                      (not (equal fld :undef)))
                 (equal (xr fld index
                            (write-user-rflags flags mask x86))
                        (xr fld index x86))))

Theorem: xr-write-user-rflags-no-mask

(defthm xr-write-user-rflags-no-mask
        (implies (not (equal fld :rflags))
                 (equal (xr fld
                            index (write-user-rflags flags 0 x86))
                        (xr fld index x86))))

Theorem: rflags-and-write-user-rflags-no-mask

(defthm
     rflags-and-write-user-rflags-no-mask
     (equal (write-user-rflags user-flags-vector 0 x86)
            (b* ((x86 (!flgi :cf (rflagsbits->cf user-flags-vector)
                             x86))
                 (x86 (!flgi :pf (rflagsbits->pf user-flags-vector)
                             x86))
                 (x86 (!flgi :af (rflagsbits->af user-flags-vector)
                             x86))
                 (x86 (!flgi :zf (rflagsbits->zf user-flags-vector)
                             x86))
                 (x86 (!flgi :sf (rflagsbits->sf user-flags-vector)
                             x86))
                 (x86 (!flgi :of (rflagsbits->of user-flags-vector)
                             x86)))
                x86)))

Subtopics

Write-user-rflags
Writing user rflags (CF, PF, AF, ZF, SF, and OF), including undefined ones, to the x86 state
Undef-flg
Undef-flg-logic