x86: state.lisp

the x86-64 machine state the semantics bodies read and write.

Other definitions

(defstruct x86) source
(defstruct (x86 (:conc-name x86-))
  (gprs (make-array 16 :element-type '(unsigned-byte 64) :initial-element 0)
   :type (simple-array (unsigned-byte 64) (16)))
  (xmm (make-array 16 :element-type '(unsigned-byte 128) :initial-element 0)
   :type (simple-array (unsigned-byte 128) (16)))
  (ymmh (make-array 16 :element-type '(unsigned-byte 128) :initial-element 0)
   :type (simple-array (unsigned-byte 128) (16)))
  (rflags 2 :type u64)                            ; bit 1 is reserved and reads 1 ([SDM] Vol. 1, 3.4.3)
  (mxcsr #x1F80 :type u32)                        ; SSE/AVX control and status (fp.lisp): at reset
  (fault 0 :type u8)
  (mval 0 :type (unsigned-byte 256)))
(defregs x86) source
(defregs x86
  (gpr :count 16 :width 64 :role :gpr :slot x86-gprs)
  (xmm :count 16 :width 128 :slot x86-xmm)
  (ymmh :count 16 :width 128 :slot x86-ymmh :doc "bits 255-128 of ymm n")
  (rflags :width 64 :role :flags :fields ((cf 0) (pf 2) (af 4) (zf 6) (sf 7) (of 11)))
  (mxcsr :width 32 :fields ((ie 0) (de 1) (ze 2) (oe 3) (ue 4) (pe 5) (daz 6)
                            (im 7) (dm 8) (zm 9) (om 10) (um 11) (pm 12) (rc 13 2) (ftz 15))))
(defexceptions x86) source
(defexceptions x86
  :place (x86-fault cpu)
  :exit (return-from x86-sem nil)
  :kinds ((:divide-error 1) (:debug 2) (:interrupt 3) (:breakpoint 4) (:overflow 5) (:bound 6)
          (:illegal 7) (:cop-unusable 8) (:double-fault 9) (:x87-float 10) (:invalid-tss 11)
          (:segment-not-present 12) (:stack-fault 13) (:protection 14) (:page-fault 15)
          (:alignment 16) (:machine-check 17) (:float 18) (:virtualization 19)
          (:control-protection 20)))
(defmem x86) source
(defmem x86 :order :le :addr-width 64)
(defun x86-reg) source
(defun x86-reg (cpu n w)
  (declare (type x86 cpu))
  (with-isa (x86) (wrap w (reg gpr n))))
(defun x86-set-reg) source
(defun x86-set-reg (cpu n w v)
  (declare (type x86 cpu))
  (with-isa (x86)
    (case w
      (64 (set-reg-ext gpr n 64 v :zero))
      (32 (set-reg-ext gpr n 32 v :zero))
      (16 (set-reg-ext gpr n 16 v :keep))
      (t (set-reg-ext gpr n 8 v :keep)))))
(defun x86-vreg) source
(defun x86-vreg (cpu n w)
  (declare (type x86 cpu))
  (with-isa (x86)
    (if (= w 256)
        (logior (ash (reg ymmh n) 128) (reg xmm n))
        (reg xmm n))))
(defun x86-set-vreg) source
(defun x86-set-vreg (cpu n w v vex)
  (declare (type x86 cpu))
  (with-isa (x86)
    (set-reg xmm n (wrap 128 v))
    (cond ((= w 256) (set-reg ymmh n (bit-field v 128 128)))
          (vex (set-reg ymmh n 0))))
  nil)
(defun x86-mem) source
(defun x86-mem (cpu w) (ldb (byte w 0) (x86-mval cpu)))
(defun x86-set-mem) source
(defun x86-set-mem (cpu w v) (setf (x86-mval cpu) (ldb (byte w 0) v)) nil)
(defun x86-flag) source
(defun x86-flag (cpu name)
  "the status flag NAME (cf pf af zf sf of) of CPU"
  (declare (type x86 cpu))
  (ldb (byte 1 (ecase name (cf 0) (pf 2) (af 4) (zf 6) (sf 7) (of 11))) (x86-rflags cpu)))
(defun x86-set-flag) source
(defun x86-set-flag (cpu name v)
  (declare (type x86 cpu))
  (setf (x86-rflags cpu)
        (dpb v (byte 1 (ecase name (cf 0) (pf 2) (af 4) (zf 6) (sf 7) (of 11))) (x86-rflags cpu))))
(defun x86-cf) source
(defun x86-cf (cpu) (x86-flag cpu 'cf))
(defun x86-pf) source
(defun x86-pf (cpu) (x86-flag cpu 'pf))
(defun x86-af) source
(defun x86-af (cpu) (x86-flag cpu 'af))
(defun x86-zf) source
(defun x86-zf (cpu) (x86-flag cpu 'zf))
(defun x86-sf) source
(defun x86-sf (cpu) (x86-flag cpu 'sf))
(defun x86-of) source
(defun x86-of (cpu) (x86-flag cpu 'of))

Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.