Function:
(defun read-memory-zero-terminated (ptr x86 acc) (declare (xargs :stobjs (x86))) (declare (type (signed-byte 49) ptr)) (declare (xargs :guard (and (integerp ptr) (<= (- *2^47*) ptr) (<= ptr *2^47*) (nat-listp acc)))) (let ((__function__ 'read-memory-zero-terminated)) (declare (ignorable __function__)) (if (signed-byte-p 48 ptr) (b* (((mv flg (the (unsigned-byte 8) mem-val) x86) (rml08 ptr :r x86)) ((when flg) (mv flg acc x86))) (if (equal 0 mem-val) (mv nil (append (reverse acc) '(0)) x86) (read-memory-zero-terminated (the (signed-byte 49) (1+ ptr)) x86 (cons mem-val acc)))) (mv t (reverse acc) x86))))
Theorem:
(defthm byte-listp-mv-nth-1-read-memory-zero-terminated (implies (and (x86p x86) (byte-listp acc)) (byte-listp (mv-nth 1 (read-memory-zero-terminated ptr x86 acc)))) :rule-classes :type-prescription)
Theorem:
(defthm x86p-mv-nth-2-read-memory-zero-terminated (implies (x86p x86) (x86p (mv-nth 2 (read-memory-zero-terminated ptr x86 acc)))))
Function:
(defun read-string-zero-terminated (ptr x86) (declare (xargs :stobjs (x86))) (declare (type (signed-byte 49) ptr)) (declare (xargs :guard (and (integerp ptr) (<= (- *2^47*) ptr) (<= ptr *2^47*)))) (let ((__function__ 'read-string-zero-terminated)) (declare (ignorable __function__)) (b* (((mv flg bytes x86) (read-memory-zero-terminated ptr x86 nil)) ((when flg) (mv flg "nil" x86)) (charlist (bytes-to-charlist bytes))) (mv nil (coerce charlist 'string) x86))))
Theorem:
(defthm stringp-mv-nth-1-read-string-zero-terminated (implies (force (x86p x86)) (stringp (mv-nth 1 (read-string-zero-terminated ptr x86)))) :rule-classes :type-prescription)
Theorem:
(defthm x86p-mv-nth-2-read-string-zero-terminated (implies (x86p x86) (x86p (mv-nth 2 (read-string-zero-terminated ptr x86)))))
Function:
(defun read-bytes-from-memory (ptr nbytes x86 acc) (declare (xargs :stobjs (x86))) (declare (type (signed-byte 49) ptr) (type (unsigned-byte 48) nbytes)) (declare (xargs :split-types t :guard (and (integerp nbytes) (<= 0 nbytes) (integerp ptr) (<= (- *2^47*) ptr) (< (+ ptr nbytes) *2^47*) (nat-listp acc)))) (let ((__function__ 'read-bytes-from-memory)) (declare (ignorable __function__)) (if (mbt (and (integerp nbytes) (integerp ptr) (<= (- *2^47*) ptr) (< (+ ptr nbytes) *2^47*))) (if (zp nbytes) (mv nil (reverse acc) x86) (b* (((mv flg (the (unsigned-byte 8) byte) x86) (rml08 ptr :r x86)) ((when flg) (mv flg nil x86))) (read-bytes-from-memory (the (signed-byte 49) (1+ ptr)) (the (unsigned-byte 48) (1- nbytes)) x86 (cons byte acc)))) (mv t (reverse acc) x86))))
Theorem:
(defthm byte-listp-mv-nth-1-read-bytes-from-memory (implies (forced-and (x86p x86) (byte-listp acc)) (byte-listp (mv-nth 1 (read-bytes-from-memory ptr nbytes x86 acc)))) :rule-classes :type-prescription)
Theorem:
(defthm x86p-mv-nth-2-read-bytes-from-memory (implies (x86p x86) (x86p (mv-nth 2 (read-bytes-from-memory ptr nbytes x86 acc)))))
Function:
(defun read-string-from-memory (ptr nbytes x86) (declare (xargs :stobjs (x86))) (declare (type (signed-byte 49) ptr) (type (signed-byte 48) nbytes)) (declare (xargs :guard (and (integerp nbytes) (<= 0 nbytes) (integerp ptr) (<= (- *2^47*) ptr) (< (+ ptr nbytes) *2^47*)))) (let ((__function__ 'read-string-from-memory)) (declare (ignorable __function__)) (b* (((mv flg bytes x86) (read-bytes-from-memory ptr nbytes x86 nil)) ((when flg) (mv flg "nil" x86)) (charlist (bytes-to-charlist bytes))) (mv nil (coerce charlist 'string) x86))))
Theorem:
(defthm stringp-mv-nth-1-read-string-from-memory (implies (force (x86p x86)) (stringp (mv-nth 1 (read-string-from-memory ptr nbytes x86)))) :rule-classes :type-prescription)
Theorem:
(defthm x86p-mv-nth-2-read-string-from-memory (implies (x86p x86) (x86p (mv-nth 2 (read-string-from-memory ptr nbytes x86)))))