@@ -1392,7 +1392,6 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs)
static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
{
- int ret = 0;
unsigned char ch;
switch (run->riscv_sbi.extension_id) {
case SBI_EXT_0_1_CONSOLE_PUTCHAR:
@@ -1400,22 +1399,20 @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run)
qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch));
break;
case SBI_EXT_0_1_CONSOLE_GETCHAR:
- ret = qemu_chr_fe_read_all(serial_hd(0)->be, &ch, sizeof(ch));
- if (ret == sizeof(ch)) {
+ if (qemu_chr_fe_read_all(serial_hd(0)->be, &ch, sizeof(ch)) == sizeof(ch)) {
run->riscv_sbi.ret[0] = ch;
} else {
- run->riscv_sbi.ret[0] = -1;
+ run->riscv_sbi.ret[0] = SBI_ERR_FAILURE;
}
- ret = 0;
break;
default:
qemu_log_mask(LOG_UNIMP,
- "%s: un-handled SBI EXIT, specific reasons is %lu\n",
+ "%s: Unhandled SBI exit with extension-id %lu\n",
__func__, run->riscv_sbi.extension_id);
- ret = -1;
+ run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED;
break;
}
- return ret;
+ return 0;
}
int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
@@ -69,4 +69,16 @@
#define SBI_EXT_VENDOR_END 0x09FFFFFF
/* clang-format on */
+/* SBI return error codes */
+#define SBI_SUCCESS 0
+#define SBI_ERR_FAILURE -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
+#define SBI_ERR_NO_SHMEM -9
+
#endif