Documentation

Bignum.Arm.Machine.State

ARM Machine State #

This file defines the ARM machine state used for verification.

Main Definitions #

References #

This corresponds to the ARM state in HOL Light's ARM model. Source: s2n-bignum/arm/proofs/arm.ml and instruction.ml

inductive Bignum.Arm.Reg :

ARM general-purpose registers and special registers.

Instances For
    Equations
    Instances For
      Equations
      • One or more equations did not get rendered due to their size.

      ARM condition flag identifiers.

      In HOL Light (s2n-bignum/arm/proofs/instruction.ml:186-192), flags are defined as sub-components of a 4-bit field:

      let NF = define `NF = flags :> bitelement 3`;;
      let ZF = define `ZF = flags :> bitelement 2`;;
      let CF = define `CF = flags :> bitelement 1`;;
      let VF = define `VF = flags :> bitelement 0`;;
      

      Note: Named CFlag (Condition Flag) to avoid conflict with Mathlib's Flag.

      Instances For

        ARM condition flags as a structure.

        Instances For
          def Bignum.Arm.instDecidableEqFlags.decEq (x✝ x✝¹ : Flags) :
          Decidable (x✝ = x✝¹)
          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Read an individual flag by its identifier.

              Equations
              Instances For
                def Bignum.Arm.Flags.write (f : Flags) (fl : Flag) (v : Bool) :

                Write an individual flag by its identifier.

                Equations
                Instances For
                  @[simp]
                  theorem Bignum.Arm.Flags.read_write_same (f : Flags) (fl : Flag) (v : Bool) :
                  (f.write fl v).read fl = v
                  @[simp]
                  theorem Bignum.Arm.Flags.read_write_diff (f : Flags) (fl1 fl2 : Flag) (v : Bool) (h : fl1 fl2) :
                  (f.write fl1 v).read fl2 = f.read fl2

                  ARM machine state #

                  This corresponds to the armstate type in HOL Light. Source: s2n-bignum/arm/proofs/arm.ml

                  Instances For
                    theorem Bignum.Arm.ArmState.ext {s1 s2 : ArmState} (h_regs : s1.regs = s2.regs) (h_flags : s1.flags = s2.flags) (h_mem : s1.mem = s2.mem) :
                    s1 = s2

                    Extensionality theorem for ArmState: two states are equal if all fields are equal.

                    theorem Bignum.Arm.ArmState.ext_iff {s1 s2 : ArmState} :
                    s1 = s2 s1.regs = s2.regs s1.flags = s2.flags s1.mem = s2.mem

                    Read a register value from the state.

                    Corresponds to HOL Light's read function. Example from simple.ml:78: read X0 s = word a

                    Equations
                    Instances For

                      Write a value to a register.

                      Corresponds to HOL Light's state update for registers.

                      Equations
                      Instances For

                        Read an individual flag from the state.

                        Corresponds to HOL Light's read CF s, read ZF s, etc.

                        Equations
                        Instances For

                          Write an individual flag in the state.

                          Corresponds to HOL Light's flag update, e.g., CF := b.

                          Equations
                          Instances For

                            Read a byte from memory.

                            Equations
                            Instances For

                              Write a byte to memory.

                              Equations
                              Instances For

                                Read a 64-bit word from memory.

                                Equations
                                Instances For

                                  Write a 64-bit word to memory.

                                  Equations
                                  Instances For

                                    Read a bignum from memory.

                                    Corresponds to HOL Light's bignum_from_memory. Example from bignum_add.ml:91-92:

                                    bignum_from_memory (x,val m) s = a /\
                                    bignum_from_memory (y,val n) s = b
                                    
                                    Equations
                                    Instances For

                                      Write a bignum to memory.

                                      Equations
                                      Instances For

                                        Update condition flags.

                                        Equations
                                        Instances For

                                          Convenience notation for reading registers. Following HOL Light convention: read PC s means read program counter from state s.

                                          Equations
                                          Instances For

                                            Helper: Create initial state with given register values.

                                            Equations
                                            Instances For

                                              Simplification Lemmas for Register Read/Write #

                                              These lemmas enable automatic simplification of register access patterns in proofs. They are essential for symbolic execution and proving correctness of instruction sequences.

                                              @[simp]

                                              Reading a register immediately after writing to it returns the written value.

                                              @[simp]
                                              theorem Bignum.Arm.ArmState.read_write_diff (s : ArmState) (r1 r2 : Reg) (v : Word64) (h : r1 r2) :
                                              (s.write_reg r1 v).read_reg r2 = s.read_reg r2

                                              Reading a different register is not affected by a write to another register.

                                              @[simp]
                                              theorem Bignum.Arm.ArmState.write_write_same (s : ArmState) (r : Reg) (v1 v2 : Word64) :
                                              (s.write_reg r v1).write_reg r v2 = s.write_reg r v2

                                              Writing twice to the same register: the second write overwrites the first.

                                              @[simp]
                                              theorem Bignum.Arm.ArmState.write_write_comm (s : ArmState) (r1 r2 : Reg) (v1 v2 : Word64) (h : r1 r2) :
                                              (s.write_reg r1 v1).write_reg r2 v2 = (s.write_reg r2 v2).write_reg r1 v1

                                              Writes to different registers commute.

                                              @[simp]
                                              theorem Bignum.Arm.ArmState.read_init (regs : RegWord64) (mem : Memory) (r : Reg) :
                                              (init regs mem).read_reg r = regs r

                                              Reading from initial state with explicit register function.

                                              Simplification Lemmas for Flag Read/Write #

                                              @[simp]

                                              Reading a flag immediately after writing to it returns the written value.

                                              @[simp]
                                              theorem Bignum.Arm.ArmState.read_flag_write_flag_diff (s : ArmState) (f1 f2 : Flag) (v : Bool) (h : f1 f2) :
                                              (s.write_flag f1 v).read_flag f2 = s.read_flag f2

                                              Reading a different flag is not affected by writing another flag.

                                              @[simp]

                                              Writing a flag does not affect registers.

                                              @[simp]

                                              Writing a register does not affect flags.