Function to read in an ELF or Mach-O binary and load text and data sections into the x86 ISA model's memory.
(binary-file-load-fn filename exld::elf exld::mach-o x86 state &key (elf 't) (mach-o 'nil)) → (mv new-elf new-mach-o new-x86 state)
The following macro makes it convenient to call this function to load a program:
(binary-file-load "fib.o" :elf t) ;; or :mach-o t
Function:
(defun binary-file-load-fn-fn (filename exld::elf exld::mach-o x86 state elf mach-o) (declare (xargs :stobjs (exld::elf exld::mach-o x86 state))) (declare (xargs :guard (and (stringp filename) (booleanp elf) (booleanp mach-o)))) (let ((__function__ 'binary-file-load-fn)) (declare (ignorable __function__)) (cond ((and elf (not mach-o)) (b* (((mv exld::elf state) (exld::populate-elf filename exld::elf state)) ((mv flg x86) (load-elf-sections (exld::@sections exld::elf) x86)) ((when flg) (prog2$ (raise "[ELF]: Error encountered while loading sections in the x86 model's memory!~%") (mv exld::elf exld::mach-o x86 state)))) (mv exld::elf exld::mach-o x86 state))) ((and mach-o (not elf)) (b* (((mv ?alst exld::mach-o state) (exld::populate-mach-o filename exld::mach-o state)) ((mv flg0 x86) (mach-o-load-text-section exld::mach-o x86)) ((mv flg1 x86) (mach-o-load-data-section exld::mach-o x86)) ((when (or flg0 flg1)) (prog2$ (raise "[Mach-O]: Error encountered while loading sections in the x86 model's memory!~%") (mv exld::elf exld::mach-o x86 state)))) (mv exld::elf exld::mach-o x86 state))) (t (prog2$ (raise "~%We support only ELF and Mach-O files for now! Use this function with either :elf t ~ or :mach-o t.~%") (mv exld::elf exld::mach-o x86 state))))))
Theorem:
(defthm good-elf-p-of-binary-file-load-fn.new-elf (implies (exld::elfp exld::good-elf-p) (b* (((mv ?new-elf ?new-mach-o ?new-x86 acl2::?state) (binary-file-load-fn-fn filename exld::elf exld::mach-o x86 state elf mach-o))) (exld::good-elf-p new-elf))) :rule-classes :rewrite)
Theorem:
(defthm good-mach-o-p-of-binary-file-load-fn.new-mach-o (implies (exld::mach-op exld::good-mach-o-p) (b* (((mv ?new-elf ?new-mach-o ?new-x86 acl2::?state) (binary-file-load-fn-fn filename exld::elf exld::mach-o x86 state elf mach-o))) (exld::good-mach-o-p new-mach-o))) :rule-classes :rewrite)
Theorem:
(defthm x86p-of-binary-file-load-fn.new-x86 (implies (x86p x86) (b* (((mv ?new-elf ?new-mach-o ?new-x86 acl2::?state) (binary-file-load-fn-fn filename exld::elf exld::mach-o x86 state elf mach-o))) (x86p new-x86))) :rule-classes :rewrite)