- simple main (./100.main)
- system call (./110.system_call)
- library call (./120.libc_call)
- basic operations (./300.operation)
- control flow (./400.control_flow)
- sync (./700.sync), sync_parts (./710.sync_parts)
- multi-threads (./750.multi)
-
Assemble (generate binary)
$ make -f ../Makefile <sample>
-
Execute
$ ./<sample> or $ qemu-riscv64 ./<sample>
-
Disassemble (for full object)
$ make -f ../Makefile <sample>.disasm | less (search "main>" in `less` command)
-
Disassemble (for .S only)
$ make -f ../Makefile <sample>.o.disasm
-
Step execution with gdb
$ make -f ../Makefile <sample> $ gdb ./<sample> (gdb) layout asm (gdb) layout regs (gdb) break main (gdb) run (gdb) stepi : (gdb) quit
-
Step execution with qemu and gdb
- on first terminal for qemu:
$ qemu-riscv64 -g 1234 ./<sample>
- on second terminal for gdb:
$ riscv64-unknown-linux-gnu-gdb ./<sample> (gdb) layout asm (gdb) layout regs (gdb) target remote localhost:1234 (gdb) break main (gdb) continue (gdb) stepi : (gdb) quit
-
RISC-V
-
Linux
-
glibc
- glibc
- sysdeps/unix/sysv/linux/riscv
- glibc
-
RISC-V ABI
-
System call ABI
-
GCC
-
GNU assembler and linker
-
System call
- a7, a0, a1, a2, a3, a4, a5 -> a0, a1
-
Funcation call
- a0, a1, a2, a3, a4, a5, a6, a7 -> a0, a1
-
see:
- RISC-V ELF psABI Document
- glibc's sysdeps/unix/sysv/linux/riscv/syscall.c
-
Cross assembler (RISC-V GNU Compiler Toolchain)
Build with https://github.com/riscv/riscv-gnu-toolchain
-
QEMU User space emulator
apt install qemu-user