def on_load_elf(sim: OTBNSim, args: List[str]) -> Optional[OTBNSim]: '''Load contents of ELF at path given by only argument''' check_arg_count('load_elf', 1, args) path = args[0] print('LOAD_ELF {!r}'.format(path)) load_elf(sim, path) return None
def on_load_elf(sim: OTBNSim, args: List[str]) -> Optional[OTBNSim]: '''Load contents of ELF at path given by only argument''' if len(args) != 1: raise ValueError( 'load_elf expects exactly 1 argument. Got {}.'.format(args)) path = args[0] print('LOAD_ELF {!r}'.format(path)) load_elf(sim, path) return None
def prepare_sim_for_asm_file(asm_file: str, tmpdir: py.path.local, collect_stats: bool) -> StandaloneSim: '''Set up the simulation of a single assembly file. The returned simulation is ready to be run through the run() method. ''' assert os.path.exists(asm_file) elf_file = asm_and_link_one_file(asm_file, tmpdir) sim = StandaloneSim() load_elf(sim, elf_file) sim.state.ext_regs.commit() sim.start(collect_stats) return sim
def main() -> int: parser = argparse.ArgumentParser() parser.add_argument('elf') parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument( '--dump-dmem', metavar="FILE", type=argparse.FileType('wb'), help=("after execution, write the data memory contents to this file. " "Use '-' to write to STDOUT.")) parser.add_argument( '--dump-regs', metavar="FILE", type=argparse.FileType('w'), help=("after execution, write the GPR and WDR contents to this file. " "Use '-' to write to STDOUT.")) parser.add_argument( '--dump-stats', metavar="FILE", type=argparse.FileType('w'), help=("after execution, write execution statistics to this file. " "Use '-' to write to STDOUT.")) args = parser.parse_args() collect_stats = args.dump_stats is not None sim = StandaloneSim() exp_end_addr = load_elf(sim, args.elf) key0 = int((str("deadbeef") * 12), 16) key1 = int((str("badf00d") * 12), 16) sim.state.wsrs.set_sideload_keys(key0, key1) sim.state.ext_regs.commit() sim.start(collect_stats) sim.run(verbose=args.verbose) if exp_end_addr is not None: if sim.state.pc != exp_end_addr: print('Run stopped at PC {:#x}, but _expected_end_addr was {:#x}.'. format(sim.state.pc, exp_end_addr), file=sys.stderr) return 1 if args.dump_dmem is not None: args.dump_dmem.write(sim.dump_data()) if args.dump_regs is not None: for idx, value in enumerate(sim.state.gprs.peek_unsigned_values()): args.dump_regs.write(' x{:<2} = 0x{:08x}\n'.format(idx, value)) for idx, value in enumerate(sim.state.wdrs.peek_unsigned_values()): args.dump_regs.write(' w{:<2} = 0x{:064x}\n'.format(idx, value)) if collect_stats: assert sim.stats is not None stat_analyzer = ExecutionStatAnalyzer(sim.stats, args.elf) args.dump_stats.write(stat_analyzer.dump()) return 0