A => .gitignore +1 -0
A => mkfile +4 -0
@@ 1,4 @@
+all:QV: sbiserial.bin
+
+%.bin: %.asm sbi.inc riscv.inc sbi.h
+ naken_asm -type bin -q -o $target $stem.asm
A => riscv.inc +27 -0
@@ 1,27 @@
+; vim:set ft=asm:
+
+.macro ecall
+ .dl 0b000000000000_00000_000_00000_1110011
+.endm
+
+.macro b(addr)
+ beq x0, x0, addr
+.endm
+
+.macro beqz(reg, addr)
+ beq x0, reg, addr
+.endm
+
+.macro inc(reg)
+ addi reg, reg, 1
+.endm
+
+.macro li(reg, value)
+ lui reg, value >> 20
+ addi reg, reg, value & 0xFFF
+.endm
+
+.macro lla(reg, value)
+ auipc reg, value >> 20
+ addi reg, reg, value & 0xFFF
+.endm
A => sbi.h +45 -0
@@ 1,45 @@
+#ifndef SBI_H
+#define SBI_H 1
+
+#define SBI_SUCCESS 0
+#define SBI_ERR_FAILED -1
+#define SBI_ERR_NOT_SUPPORTED -2
+#define SBI_ERR_INVALID_PARAM -3
+#define SBI_ERR_DENIED -4
+#define SBI_ERR_INVALID_ADDRESS -5
+#define SBI_ERR_ALREADY_AVAILABLE -6
+#define SBI_ERR_ALREADY_STARTED -7
+#define SBI_ERR_ALREADY_STOPPED -8
+
+/*
+ * Legacy calls use EIDs and their FID is always zero. Other calls (below)
+ * have a per-extension EID, with a different FID for each function in it.
+ */
+#define SBI_LEGACY_SET_TIMER 0x00
+#define SBI_LEGACY_CONSOLE_PUTCHAR 0x01
+#define SBI_LEGACY_CONSOLE_GETCHAR 0x02
+#define SBI_LEGACY_CLEAR_IPI 0x03
+#define SBI_LEGACY_SEND_IPI 0x04
+#define SBI_LEGACY_REMOTE_FENCE_I 0x05
+#define SBI_LEGACY_REMOTE_SFENCE_VMA 0x06
+#define SBI_LEGACY_REMOTE_SFENCE_VMA_ASID 0x07
+#define SBI_LEGACY_SHUTDOWN 0x08
+
+#define SBI_BASE 0x10
+#define SBI_BASE_GET_SPEC_VERSION 0
+#define SBI_BASE_GET_IMPL_ID 1
+#define SBI_BASE_GET_IMPL_VERSION 2
+#define SBI_BASE_PROBE_EXTENSION 3
+#define SBI_BASE_GET_MVENDORID 4
+#define SBI_BASE_GET_MARCHID 5
+#define SBI_BASE_GET_MIMPID 6
+
+/* Possible values returned by SBI_BASE_GET_IMPL_ID */
+#define SBI_IMPL_ID_BBL 0
+#define SBI_IMPL_ID_OPENSBI 1
+#define SBI_IMPL_ID_XVISOR 2
+#define SBI_IMPL_ID_KVM 3
+#define SBI_IMPL_ID_RUSTSBI 4
+#define SBI_IMPL_ID_DIOSIX 5
+
+#endif
A => sbi.inc +14 -0
@@ 1,14 @@
+; vim:set ft=asm:
+
+.include "sbi.h"
+.include "riscv.inc"
+
+.macro sbi_call(eid, fid)
+ addi a7, x0, eid
+ addi a6, x0, fid
+ ecall
+.endm
+
+.macro sbi_call_legacy(eid)
+ sbi_call(eid, 0)
+.endm
A => sbiserial.asm +22 -0
@@ 1,22 @@
+; vim:set ft=asm:
+
+.riscv
+.entry_point start
+
+.include "sbi.inc"
+
+.org 45000000
+
+.func start
+ li(s0, string)
+ dochar:
+ lbu a0, s0, 0
+ beqz(a0, idle)
+ sbi_call_legacy(SBI_LEGACY_CONSOLE_PUTCHAR)
+ inc(s0)
+ b(dochar)
+ idle:
+ b(idle)
+.endf
+
+string: .asciiz "Hello, world!"