implemented a bunch of syscalls

This commit is contained in:
Luxferre
2026-06-18 19:54:49 +03:00
parent 7368329c16
commit 172ea779c6
4 changed files with 506 additions and 22 deletions
+10 -3
View File
@@ -7,7 +7,7 @@ A-machine is a simple and straightforward implementation of the RV32I specificat
- [amach.awk](amach.awk), the emulator core itself that supports .dec files,
- and [amach](amach) shell script which is a two-liner that uses POSIX `od` to convert .bin files into .dec files on the fly and then passes them to the emulator core.
Additionally, A-machine is shipped with a reference test suite that assumes that you have a full RISC-V toolchain installed under the `riscv64-linux-gnu-` prefix (adjustable in the `Makefile`). Just run `make run` to build and run all tests. In case you don't have any toolchain available, a file called `rv32imac_tests.bin` is also included into the repo.
Additionally, A-machine is shipped with a reference test suite that assumes that you have a full RISC-V toolchain installed under the `riscv64-linux-gnu-` prefix (adjustable in the `Makefile`). Just run `make run` to build and run all tests. In case you don't have any toolchain available, two files called `rv32imac_tests.bin` and `rv32imac_syscall_tests.bin` are also included into the repo.
The project is to be considered highly experimental and not production-ready in any way.
@@ -32,12 +32,19 @@ POSIXLY_CORRECT=1 awk -f amach.awk [-v LVA=...] -- path/to/program.dec
## Support
Currently, A-machine only supports the **unprivileged** RV32IMAC instruction set with a few additional `ecall` syscalls: 63 (sys_read, for fd 0 only), 64 (sys_write, for fd 1 and 2 only) and 93 (sys_exit). For completeness, `fence` instruction is also supported but yields a no-op, and both `ebreak` and `c.ebreak` are supported to halt execution with a debug message.
Currently, A-machine only supports the **unprivileged** RV32IMAC instruction set with an extended subset of POSIX/Linux-compatible `ecall` system calls (using standard `asm-generic` numbers):
- **Process Control**: `sys_exit` (93), `sys_exit_group` (94).
- **File & Directory I/O**: `sys_openat` (56), `sys_close` (57), `sys_read` (63), `sys_write` (64), `sys_lseek` (62). Multiple file descriptors (with full path resolution, creation/truncation flags, and offset tracking) are supported for files and directories.
- **Directory Operations**: `sys_mkdirat` (34), `sys_unlinkat` (35) (including directory removal), `sys_renameat` (38) / `sys_renameat2` (276), `sys_getdents64` (61) (for listing directory contents).
- **File Metadata & Links**: `sys_newfstatat` (79), `sys_fstat` (80), `sys_readlinkat` (78).
- **System Time & Entropy**: `sys_clock_gettime` (113), `sys_clock_gettime64` (403), `sys_gettimeofday` (169), and `sys_getrandom` (278).
For completeness, `fence` instruction is also supported but yields a no-op, and both `ebreak` and `c.ebreak` are supported to halt execution with a debug message.
## Plans (from higher to lower priority)
- Implement a simple RV32IMAC disassembler in POSIX AWK.
- Introduce more popular Linux-compatible syscalls (that make sense to implement in AWK but don't increase the overall project complexity).
- Test for RV32EMC compatibility (that the code built for the "embedded" variant runs here).
- Implement a privileged instruction set minimum (Zicsr), interrupts and traps.
- If time permits, implement a simple RV32IMAC assembler in POSIX AWK, with full pseudo-instruction support.