So I'm trying to use the RISC-V SBI debug console extension of OpenSBI on Qemu using inline Rust assembly, but it isn't working.

My first question is, does Qemu's OpenSBI even support this extension? I found that the debug console extension was added to OpenSBI as a experimental feature but I'm not sure if its enabled in Qemu or not.

My second question is, what's wrong with my implementation if the extension is available?

pub fn debug_console_write(text: &str) -> SBIResult {
    let mut sbi_result = SBIResult::new();
    unsafe {
        asm!(
            "li a7, 0x4442434E", // Specifies SBI extension
            "li a6, 0x00", //  Specifies function ID in extension
            "lw a0, ({})", // Provides number of bytes in string
            "lw a1, ({})", // Provides pointer to string
            "li a2, 0", // Provides the high end of the pointers address which should always be 0
            "ecall", // Short for "enviroment call", in this case it's a call to the sbi
            "sw a0, ({})", // Puts error value from sbi call into result struct
            "sw a1, ({})", // Puts value value from sbi call into result struct
            in(reg) &text.len(),
            in(reg) &text.as_ptr(),
            out(reg) sbi_result.error,
            out(reg) sbi_result.value
        );
    }

    return sbi_result
}

My third question is, if the extension isn't available, how can I get output?

Source: View source