diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/elf_loader.ml | 18 | ||||
| -rw-r--r-- | src/isail.ml | 14 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/elf_loader.ml b/src/elf_loader.ml index 88fcfddb..c6fb0589 100644 --- a/src/elf_loader.ml +++ b/src/elf_loader.ml @@ -149,6 +149,24 @@ let load_elf ?writer:(writer=write_sail_lib) name = opt_elf_tohost := tohost_addr); List.iter (load_segment ~writer:writer) segments +let load_binary ?writer:(writer=write_sail_lib) addr name = + let f = open_in_bin name in + let buf = Buffer.create 1024 in + try + while true do + let char = input_char f in + Buffer.add_char buf char; + done; + assert false + with + | End_of_file -> begin + Bytes.iteri (fun i ch -> writer addr i (int_of_char ch)) (Buffer.to_bytes buf); + close_in f + end + | exc -> + close_in f; + raise exc + (* The sail model can access this by externing a unit -> int function as Elf_loader.elf_entry. *) let elf_entry () = !opt_elf_entry diff --git a/src/isail.ml b/src/isail.ml index c3f869a3..4e237943 100644 --- a/src/isail.ml +++ b/src/isail.ml @@ -179,6 +179,8 @@ let help = function ":help <command> - Get a description of <command>. Commands are prefixed with a colon, e.g. :help :type." | ":elf" -> ":elf <file> - Load an ELF file." + | ":bin" -> + ":bin <address> <file> - Load a binary file at the given address." | ":r" | ":run" -> "(:r | :run) - Completely evaluate the currently evaluating expression." | ":s" | ":step" -> @@ -256,7 +258,7 @@ let handle_input' input = | ":commands" -> let commands = [ "Universal commands - :(t)ype :(i)nfer :(q)uit :(v)erbose :clear :commands :help :output :option"; - "Normal mode commands - :elf :(l)oad :(u)nload"; + "Normal mode commands - :elf :bin :(l)oad :(u)nload"; "Evaluation mode commands - :(r)un :(s)tep :(n)ormal"; ""; ":(c)ommand can be called as either :c or :command." ] @@ -320,6 +322,16 @@ let handle_input' input = begin match cmd with | ":elf" -> Elf_loader.load_elf arg + | ":bin" -> + begin + let args = Util.split_on_char ' ' arg in + match args with + | [addr_s; filename] -> + let addr = Big_int.of_string addr_s in + Elf_loader.load_binary addr filename + | _ -> + print_endline "Invalid argument for :bin, expected <addr> <filename>" + end | ":l" | ":load" -> let files = Util.split_on_char ' ' arg in let (_, ast, env) = load_files !interactive_env files in |
