|
|
@ -5,7 +5,8 @@ if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='RISC-V Userspace parser and emulator', prog='riscemu')
|
|
|
|
parser = argparse.ArgumentParser(description='RISC-V Userspace parser and emulator', prog='riscemu')
|
|
|
|
parser.add_argument('file', metavar='file.asm', type=str, help='The assembly file to interpret and run')
|
|
|
|
parser.add_argument('files', metavar='file.asm', type=str, nargs='+',
|
|
|
|
|
|
|
|
help='The assembly files to load, the last one will be run')
|
|
|
|
|
|
|
|
|
|
|
|
# RunConfig parameters
|
|
|
|
# RunConfig parameters
|
|
|
|
parser.add_argument('--no-color', type=bool, help='no colored output', default=False,
|
|
|
|
parser.add_argument('--no-color', type=bool, help='no colored output', default=False,
|
|
|
@ -35,7 +36,10 @@ if __name__ == '__main__':
|
|
|
|
FMT_PRINT = ""
|
|
|
|
FMT_PRINT = ""
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
tk = RiscVTokenizer(RiscVInput.from_file(args.file))
|
|
|
|
cpu = CPU(cfg)
|
|
|
|
|
|
|
|
loaded_exe = None
|
|
|
|
|
|
|
|
for file in args.files:
|
|
|
|
|
|
|
|
tk = RiscVTokenizer(RiscVInput.from_file(file))
|
|
|
|
tk.tokenize()
|
|
|
|
tk.tokenize()
|
|
|
|
|
|
|
|
|
|
|
|
if args.print_tokens:
|
|
|
|
if args.print_tokens:
|
|
|
@ -43,14 +47,14 @@ if __name__ == '__main__':
|
|
|
|
for token in tk.tokens:
|
|
|
|
for token in tk.tokens:
|
|
|
|
print(token)
|
|
|
|
print(token)
|
|
|
|
|
|
|
|
|
|
|
|
executable = ExecutableParser(tk).parse()
|
|
|
|
loaded_exe = cpu.load(ExecutableParser(tk).parse())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# run the last loaded executable
|
|
|
|
|
|
|
|
cpu.run_loaded(loaded_exe)
|
|
|
|
except RiscemuBaseException as e:
|
|
|
|
except RiscemuBaseException as e:
|
|
|
|
print("Error while parsing: {}".format(e.message()))
|
|
|
|
print("Error while parsing: {}".format(e.message()))
|
|
|
|
import traceback
|
|
|
|
import traceback
|
|
|
|
traceback.print_exception(type(e), e, e.__traceback__)
|
|
|
|
traceback.print_exception(type(e), e, e.__traceback__)
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
cpu = CPU(cfg)
|
|
|
|
|
|
|
|
le = cpu.load(executable)
|
|
|
|
|
|
|
|
cpu.run_loaded(le)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|