ported syscalls to Int32 usage and removed unecessary prints

assembly-parser-rework
Anton Lydike 3 years ago
parent fa4a9b92f3
commit b7f1365155

@ -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

@ -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)

@ -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(

Loading…
Cancel
Save