use crate::error::KernelError; use crate::proc::context::CpuContext; use crate::syscall::{SyscallResult, copy_from_user}; pub fn sys_debug_print(ctx: &mut CpuContext) { let ptr = ctx.rdi; let len = ctx.rsi; let irq = match crate::sync::InterruptsDisabledToken::new_checked() { Some(tok) => tok, None => { x86_64::instructions::interrupts::disable(); match crate::sync::InterruptsDisabledToken::new_checked() { Some(tok) => tok, None => { ctx.rax = SyscallResult::error(KernelError::BadState).raw(); return; } } } }; if len > 256 { ctx.rax = SyscallResult::error(KernelError::InvalidAddress).raw(); return; } let mut buf = [0u8; 256]; match copy_from_user(ptr, &mut buf, len as usize, &irq) { Err(e) => ctx.rax = SyscallResult::error(e).raw(), Ok(()) => match core::str::from_utf8(&buf[..len as usize]) { Ok(s) => { crate::kprint!("{}", s); ctx.rax = SyscallResult::ok().raw(); } Err(_) => ctx.rax = SyscallResult::error(KernelError::InvalidParameter).raw(), }, } }