riscemu.Syscall module

RiscEmu (c) 2021 Anton Lydike

SPDX-License-Identifier: MIT

riscemu.Syscall.SYSCALLS = {63: 'read', 64: 'write', 93: 'exit', 1024: 'open', 1025: 'close'}

All available syscalls (mapped id->name)

riscemu.Syscall.OPEN_MODES = {0: 'rb', 1: 'wb', 2: 'r+b', 3: 'x', 4: 'ab'}

All available file open modes

class riscemu.Syscall.Syscall(id: int, cpu: riscemu.CPU.CPU)

Bases: object

Represents a syscall

id: int

The syscall number (e.g. 64 - write)

cpu: riscemu.CPU.CPU

The CPU object that created the syscall

property name
ret(code)
__init__(id: int, cpu: riscemu.CPU.CPU)None

Initialize self. See help(type(self)) for accurate signature.

riscemu.Syscall.get_syscall_symbols()

Generate global syscall symbols (such as SCALL_READ, SCALL_EXIT etc)

Returns

dictionary of all syscall symbols (SCALL_<name> -> id)

class riscemu.Syscall.SyscallInterface

Bases: object

Handles syscalls

open_files: Dict[int, IO]
next_open_handle: int
handle_syscall(scall: riscemu.Syscall.Syscall)
read(scall: riscemu.Syscall.Syscall)

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

write(scall: riscemu.Syscall.Syscall)

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

open(scall: riscemu.Syscall.Syscall)

open syscall (1024): read path of a2 bytes from addr a1, in mode a0 returns the file no in a0

modes:
  • 0: read

  • 1: write (truncate)

  • 2: read/write (no truncate)

  • 3: only create

  • 4: append

Requires running with flag scall-fs

close(scall: riscemu.Syscall.Syscall)

close syscall (1025): closes file no a0

return -1 if an error was encountered, otherwise returns 0

exit(scall: riscemu.Syscall.Syscall)

Exit syscall. Exits the system with status code a0