Decoder and dispatch function for three-byte opcodes, where
(three-byte-opcode-decode-and-execute proc-mode start-rip temp-rip prefixes rex-byte second-escape-byte x86) → x86
Source: Intel Manual, Volume 2, Appendix A-2
Function:
(defun three-byte-opcode-decode-and-execute (proc-mode start-rip temp-rip prefixes rex-byte second-escape-byte x86) (declare (xargs :stobjs (x86))) (declare (type (integer 0 4) proc-mode) (type (signed-byte 48) start-rip) (type (signed-byte 48) temp-rip) (type (unsigned-byte 52) prefixes) (type (unsigned-byte 8) rex-byte) (type (unsigned-byte 8) second-escape-byte)) (declare (xargs :guard (or (equal second-escape-byte 56) (equal second-escape-byte 58)))) (let ((__function__ 'three-byte-opcode-decode-and-execute)) (declare (ignorable __function__)) (b* ((ctx 'three-byte-opcode-decode-and-execute) ((mv flg0 (the (unsigned-byte 8) opcode) x86) (rme08 proc-mode temp-rip 1 :x x86)) ((when flg0) (!!ms-fresh :opcode-byte-access-error flg0)) ((mv flg temp-rip) (add-to-*ip proc-mode temp-rip 1 x86)) ((when flg) (!!ms-fresh :increment-error flg)) ((the (unsigned-byte 8) mandatory-prefix) (compute-mandatory-prefix-for-three-byte-opcode proc-mode second-escape-byte opcode prefixes)) (modr/m? (three-byte-opcode-modr/m-p proc-mode mandatory-prefix second-escape-byte opcode)) ((mv flg1 (the (unsigned-byte 8) modr/m) x86) (if modr/m? (rme08 proc-mode temp-rip 1 :x x86) (mv nil 0 x86))) ((when flg1) (!!ms-fresh :modr/m-byte-read-error flg1)) ((mv flg temp-rip) (if modr/m? (add-to-*ip proc-mode temp-rip 1 x86) (mv nil temp-rip))) ((when flg) (!!ms-fresh :increment-error flg)) (sib? (and modr/m? (b* ((p4? (eql 103 (prefixes->adr prefixes))) (16-bit-addressp (eql 2 (select-address-size proc-mode p4? x86)))) (x86-decode-sib-p modr/m 16-bit-addressp)))) ((mv flg2 (the (unsigned-byte 8) sib) x86) (if sib? (rme08 proc-mode temp-rip 1 :x x86) (mv nil 0 x86))) ((when flg2) (!!ms-fresh :sib-byte-read-error flg2)) ((mv flg temp-rip) (if sib? (add-to-*ip proc-mode temp-rip 1 x86) (mv nil temp-rip))) ((when flg) (!!ms-fresh :increment-error flg))) (case second-escape-byte (56 (first-three-byte-opcode-execute proc-mode start-rip temp-rip prefixes rex-byte mandatory-prefix opcode modr/m sib x86)) (58 (second-three-byte-opcode-execute proc-mode start-rip temp-rip prefixes rex-byte mandatory-prefix opcode modr/m sib x86)) (otherwise (!!ms-fresh :illegal-value-of-second-escape-byte second-escape-byte))))))
Theorem:
(defthm x86p-three-byte-opcode-decode-and-execute (implies (x86p x86) (x86p (three-byte-opcode-decode-and-execute proc-mode start-rip temp-rip prefixes rex-byte escape-byte x86))))