From b7f13651554a38ec3dd6b402dbd58ce0e55d5be0 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Sun, 27 Mar 2022 22:00:22 +0200 Subject: [PATCH] ported syscalls to Int32 usage and removed unecessary prints --- README.md | 3 +-- riscemu/assembler.py | 1 - riscemu/syscall.py | 24 ++++++++++++------------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e47bfcf..a8b2b83 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ or [riscemu.datenvorr.at](https://riscemu.datenvorr.at/index.html). This emulator contains: * RISC-V Assembly parser * RISC-V Assembly loader -* Emulation for parts of the basic RISC-V instruction set +* Emulation for most parts of the basic RISC-V instruction set and the M and A extensions * Naive memory emulator * Basic implementation of some syscalls * A debugging environment @@ -97,7 +97,6 @@ generate and make all doc files for you. Finally, you can open the docs locall b * RISC-V reference card: https://www.cl.cam.ac.uk/teaching/1617/ECAD+Arch/files/docs/RISCVGreenCardv8-20151013.pdf ## TODO: - * Currently registers don't enforce 32 bit (no overflows etc) * Correctly handle 12 and 20 bit immediate (currently not limited to bits at all) * Add a cycle limit to the options and CPU to catch infinite loops * Move away from `print` and use `logging.logger` instead diff --git a/riscemu/assembler.py b/riscemu/assembler.py index 793484e..59165bf 100644 --- a/riscemu/assembler.py +++ b/riscemu/assembler.py @@ -84,7 +84,6 @@ class ParseContext: base = 0 if self.section is not None: base = align_addr(self.section.current_address(), alignment) - print("base at {}".format(base)) self._finalize_section() self.section = CurrentSection(name, type, base) diff --git a/riscemu/syscall.py b/riscemu/syscall.py index e46c49a..c7a1c3c 100644 --- a/riscemu/syscall.py +++ b/riscemu/syscall.py @@ -52,7 +52,7 @@ class Syscall: ) def ret(self, code): - self.cpu.regs.set('a0', code) + self.cpu.regs.set('a0', Int32(code)) def get_syscall_symbols(): @@ -91,9 +91,9 @@ class SyscallInterface: read syscall (63): read from file no a0, into addr a1, at most a2 bytes on return a0 will be the number of read bytes or -1 if an error occured """ - fileno = scall.cpu.regs.get('a0') - addr = scall.cpu.regs.get('a1') - size = scall.cpu.regs.get('a2') + fileno = scall.cpu.regs.get('a0').unsigned_value + addr = scall.cpu.regs.get('a1').unsigned_value + size = scall.cpu.regs.get('a2').unsigned_value if fileno not in self.open_files: scall.cpu.regs.set('a0', -1) return @@ -113,9 +113,9 @@ class SyscallInterface: write syscall (64): write a2 bytes from addr a1 into fileno a0 on return a0 will hold the number of bytes written or -1 if an error occured """ - fileno = scall.cpu.regs.get('a0') - addr = scall.cpu.regs.get('a1') - size = scall.cpu.regs.get('a2') + fileno = scall.cpu.regs.get('a0').unsigned_value + addr = scall.cpu.regs.get('a1').unsigned_value + size = scall.cpu.regs.get('a2').unsigned_value if fileno not in self.open_files: return scall.ret(-1) @@ -147,9 +147,9 @@ class SyscallInterface: print(FMT_SYSCALL + '[Syscall] open: opening files not supported without scall-fs flag!' + FMT_NONE) return scall.ret(-1) - mode = scall.cpu.regs.get('a0') - addr = scall.cpu.regs.get('a1') - size = scall.cpu.regs.get('a2') + mode = scall.cpu.regs.get('a0').unsigned_value + addr = scall.cpu.regs.get('a1').unsigned_value + size = scall.cpu.regs.get('a2').unsigned_value mode_st = OPEN_MODES.get(mode, ) if mode_st == -1: @@ -176,7 +176,7 @@ class SyscallInterface: return -1 if an error was encountered, otherwise returns 0 """ - fileno = scall.cpu.regs.get('a0') + fileno = scall.cpu.regs.get('a0').unsigned_value if fileno not in self.open_files: print(FMT_SYSCALL + '[Syscall] close: unknown fileno {}!'.format(fileno) + FMT_NONE) return scall.ret(-1) @@ -191,7 +191,7 @@ class SyscallInterface: Exit syscall. Exits the system with status code a0 """ scall.cpu.halted = True - scall.cpu.exit_code = scall.cpu.regs.get('a0') + scall.cpu.exit_code = scall.cpu.regs.get('a0').value def __repr__(self): return "{}(\n\tfiles={}\n)".format(