Calculates effective address when SIB is present.
(x86-effective-addr-from-sib proc-mode temp-rip rex-byte mod sib x86) → (mv flg non-truncated-memory-address disp increment-rip-by x86)
Source: Intel Vol. 2A, Table 2-3.
Also see Intel Vol. 2A, Table 2-2 and Figure 2-6.
In 64-bit mode,
we use
In 64-bit mode,
we use
Note that, in 32-bit mode, we call this function only when the address size is 32 bits. When the address size is 16 bits, there is no SIB byte: See Intel Vol. 2 Table 2-1.
The displacement is read as a signed values: see AMD manual, Dec'17, Volume 3, Section 1.5.
Function:
(defun x86-effective-addr-from-sib (proc-mode temp-rip rex-byte mod sib x86) (declare (xargs :stobjs (x86))) (declare (type (integer 0 4) proc-mode) (type (signed-byte 48) temp-rip) (type (unsigned-byte 8) rex-byte) (type (unsigned-byte 2) mod) (type (unsigned-byte 8) sib)) (declare (xargs :guard (sib-p sib))) (let ((__function__ 'x86-effective-addr-from-sib)) (declare (ignorable __function__)) (b* (((the (unsigned-byte 3) b) (sib->base sib)) (check-alignment? nil) ((mv flg base displacement nrip-bytes x86) (case mod (0 (if (equal b 5) (b* (((mv ?flg0 dword x86) (rime-size-opt proc-mode 4 temp-rip 1 :x check-alignment? x86 :mem-ptr? nil)) ((when flg0) (mv (cons flg0 'rime-size-opt-error) 0 0 0 x86))) (mv nil 0 dword 4 x86)) (mv nil (if (equal proc-mode 0) (rgfi (reg-index b rex-byte 0) x86) (rr32 b x86)) 0 0 x86))) (1 (b* (((mv ?flg1 byte x86) (rime-size-opt proc-mode 1 temp-rip 1 :x check-alignment? x86 :mem-ptr? nil)) ((when flg1) (mv (cons flg1 'rime-size-opt-error) 0 0 0 x86))) (mv nil (if (equal proc-mode 0) (rgfi (reg-index b rex-byte 0) x86) (rr32 b x86)) byte 1 x86))) (2 (b* (((mv ?flg2 dword x86) (rime-size-opt proc-mode 4 temp-rip 1 :x check-alignment? x86 :mem-ptr? nil)) ((when flg2) (mv (cons flg2 'rime-size-opt-error) 0 0 0 x86))) (mv nil (if (equal proc-mode 0) (rgfi (reg-index b rex-byte 0) x86) (rr32 b x86)) dword 4 x86))) (otherwise (mv 'mod-can-not-be-anything-other-than-0-1-or-2 0 0 0 x86)))) (ix (reg-index (sib->index sib) rex-byte 1)) (index (case ix (4 0) (otherwise (if (equal proc-mode 0) (rgfi ix x86) (i32 (rgfi ix x86)))))) (scale (the (unsigned-byte 2) (sib->scale sib))) (scaled-index (ash index scale)) (effective-addr (+ base scaled-index))) (mv flg effective-addr displacement nrip-bytes x86))))
Theorem:
(defthm integerp-of-x86-effective-addr-from-sib.non-truncated-memory-address (implies (and (force (x86p x86)) (integerp temp-rip)) (b* (((mv ?flg ?non-truncated-memory-address ?disp ?increment-rip-by ?x86) (x86-effective-addr-from-sib proc-mode temp-rip rex-byte mod sib x86))) (integerp non-truncated-memory-address))) :rule-classes :type-prescription)
Theorem:
(defthm natp-of-x86-effective-addr-from-sib.increment-rip-by (b* (((mv ?flg ?non-truncated-memory-address ?disp ?increment-rip-by ?x86) (x86-effective-addr-from-sib proc-mode temp-rip rex-byte mod sib x86))) (natp increment-rip-by)) :rule-classes :type-prescription)
Theorem:
(defthm x86p-of-x86-effective-addr-from-sib.x86 (implies (force (x86p x86)) (b* (((mv ?flg ?non-truncated-memory-address ?disp ?increment-rip-by ?x86) (x86-effective-addr-from-sib proc-mode temp-rip rex-byte mod sib x86))) (x86p x86))) :rule-classes :rewrite)
Theorem:
(defthm x86-effective-addr-from-sib-returns-integerp-displacement (implies (x86p x86) (integerp (mv-nth 2 (x86-effective-addr-from-sib proc-mode temp-rip rex-byte mod sib x86)))) :rule-classes (:rewrite :type-prescription))
Theorem:
(defthm x86-effective-addr-from-sib-returns-<=-increment-rip-bytes (<= (mv-nth 3 (x86-effective-addr-from-sib proc-mode temp-rip rex-byte mod sib x86)) 4) :rule-classes :linear)