Nothing to see here, move along
1use crate::error::KernelError;
2use crate::proc::context::CpuContext;
3use crate::syscall::{SyscallResult, copy_from_user};
4
5pub fn sys_debug_print(ctx: &mut CpuContext) {
6 let ptr = ctx.rdi;
7 let len = ctx.rsi;
8
9 let irq = match crate::sync::InterruptsDisabledToken::new_checked() {
10 Some(tok) => tok,
11 None => {
12 x86_64::instructions::interrupts::disable();
13 match crate::sync::InterruptsDisabledToken::new_checked() {
14 Some(tok) => tok,
15 None => {
16 ctx.rax = SyscallResult::error(KernelError::BadState).raw();
17 return;
18 }
19 }
20 }
21 };
22 if len > 256 {
23 ctx.rax = SyscallResult::error(KernelError::InvalidAddress).raw();
24 return;
25 }
26
27 let mut buf = [0u8; 256];
28 match copy_from_user(ptr, &mut buf, len as usize, &irq) {
29 Err(e) => ctx.rax = SyscallResult::error(e).raw(),
30 Ok(()) => match core::str::from_utf8(&buf[..len as usize]) {
31 Ok(s) => {
32 crate::kprint!("{}", s);
33 ctx.rax = SyscallResult::ok().raw();
34 }
35 Err(_) => ctx.rax = SyscallResult::error(KernelError::InvalidParameter).raw(),
36 },
37 }
38}