Add stdout/stderr to mikros PAL

This commit is contained in:
pjht 2024-06-02 10:58:18 -05:00
parent 219022ccb6
commit 128078e9f9
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E

View File

@ -1,4 +1,5 @@
use crate::io;
use crate::arch::asm;
pub struct Stdin;
pub struct Stdout;
@ -24,6 +25,11 @@ pub const fn new() -> Stdout {
impl io::Write for Stdout {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
for byte in buf {
unsafe {
asm!("int 0x80", in("rax") 0, in ("rcx") *byte as u64);
};
}
Ok(buf.len())
}
@ -40,6 +46,11 @@ pub const fn new() -> Stderr {
impl io::Write for Stderr {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
for byte in buf {
unsafe {
asm!("int 0x80", in("rax") 0, in ("rcx") *byte as u64);
};
}
Ok(buf.len())
}
@ -54,6 +65,6 @@ pub fn is_ebadf(_err: &io::Error) -> bool {
true
}
pub fn panic_output() -> Option<Vec<u8>> {
None
pub fn panic_output() -> Option<impl io::Write> {
Some(Stderr::new())
}