From 97d86108e844cc3056ca229792117b6bee0a32ba Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Sat, 17 Apr 2021 23:05:01 +0200 Subject: [PATCH] added ebreak/scall aliases to sbreak/scall and replaced dbg with ebreak instruction --- riscemu/CPU.py | 19 +++++++++++++------ riscemu/main.py | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/riscemu/CPU.py b/riscemu/CPU.py index b0eebf7..7cb475b 100644 --- a/riscemu/CPU.py +++ b/riscemu/CPU.py @@ -130,6 +130,7 @@ class CPU: ) def instruction_addi(self, ins: 'LoadedInstruction'): + ASSERT_LEN(ins.args, 3) dst = ins.get_reg(0) src1 = ins.get_reg(1) imm = ins.get_imm(2) @@ -250,23 +251,29 @@ class CPU: self.pc = addr def instruction_ret(self, ins: 'LoadedInstruction'): + ASSERT_LEN(ins.args, 0) self.pc = self.regs.get('ra') + def instruction_ecall(self, ins: 'LoadedInstruction'): + self.instruction_scall(ins) + + def instruction_ebreak(self, ins: 'LoadedInstruction'): + self.instruction_ebreak(ins) + def instruction_scall(self, ins: 'LoadedInstruction'): ASSERT_LEN(ins.args, 0) syscall = Syscall(self.regs.get('a7'), self.regs) self.syscall_int.handle_syscall(syscall) - def instruction_break(self, ins: 'LoadedInstruction'): - INS_NOT_IMPLEMENTED(ins) + def instruction_sbreak(self, ins: 'LoadedInstruction'): + if self.conf.debug_instruction: + import code + code.interact(local=dict(globals(), **locals())) + def instruction_nop(self, ins: 'LoadedInstruction'): pass - def instruction_dbg(self, ins: 'LoadedInstruction'): - if self.conf.debug_instruction: - import code - code.interact(local=dict(globals(), **locals())) @staticmethod def all_instructions(): diff --git a/riscemu/main.py b/riscemu/main.py index ffbb477..f3c53f1 100644 --- a/riscemu/main.py +++ b/riscemu/main.py @@ -11,8 +11,8 @@ if __name__ == '__main__': parser.add_argument('default_stack_size', type=int, help='Default stack size of loaded programs', default=None, metavar='default-stack-size') parser.add_argument('debug_instruction', type=bool, default=True, metavar='debug-instruction', - help='Adds the dbg instruction, which launches an interactive debuggin session, smilar to ' - 'a breakpoint.') + help='Switches to an interactive python interpreter when ebreak/sbreak instruction ' + 'is encountered. Otherwise these instructions are treated as nop.') parser.add_argument('print_tokens', metavar='print-tokens', type=bool, help='Print tokens after tokenization', default=False)