//! Debugging utilties specific to RISC-V

use abi::error::Error;
use kernel_arch_riscv64::sbi;
use libk::debug::{self, DebugSink, LogLevel};

/// SBI-based debug sink
pub struct SbiDebugConsole;

impl DebugSink for SbiDebugConsole {
    fn putc(&self, c: u8) -> Result<(), Error> {
        sbi::sbi_debug_console_write_byte(c);
        Ok(())
    }

    fn supports_control_sequences(&self) -> bool {
        true
    }
}

static SBI_DEBUG: SbiDebugConsole = SbiDebugConsole;

/// Sets up a SBI-based debug log sink
pub fn register_sbi_debug() {
    debug::add_early_sink(&SBI_DEBUG, LogLevel::Debug);
}
