diff --git a/services/log-server/build.rs b/services/log-server/build.rs index 5fd27838d..de9132b19 100644 --- a/services/log-server/build.rs +++ b/services/log-server/build.rs @@ -2,7 +2,7 @@ use std::env; extern crate vergen; -use vergen::{ConstantsFlags, generate_cargo_keys}; +use vergen::{generate_cargo_keys, ConstantsFlags}; fn main() { let target = env::var("TARGET").unwrap(); @@ -16,7 +16,10 @@ fn main() { println!("cargo:rustc-cfg=baremetal"); } - generate_cargo_keys(ConstantsFlags::SHA /*| ConstantsFlags::BUILD_TIMESTAMP*/).unwrap(); + generate_cargo_keys( + ConstantsFlags::SHA, /*| ConstantsFlags::BUILD_TIMESTAMP*/ + ) + .unwrap(); // BUILD_TIMESTAMP doesn't work -- it doesn't update because of the below line // removing the below line causes a lengthy full-rebuild just to capture a timestamp. // so, we're removing the timestamp. diff --git a/services/log-server/src/api.rs b/services/log-server/src/api.rs index a068c0a59..8e8ef9343 100644 --- a/services/log-server/src/api.rs +++ b/services/log-server/src/api.rs @@ -12,13 +12,13 @@ pub enum Opcode { /// A `LogRecord` message, delivering structured log output LogRecord = 0, - /// A `xous::String` destined for stdout + /// A `&[u8]` destined for stdout StandardOutput = 1, - /// A `xous::String` destined for stderr + /// A `&[u8]` destined for stderr StandardError = 2, - /// A `xous::String` containing this program's name + /// A `xous::StringBuffer` containing this program's name ProgramName = 3, /// A panic occurred, and a panic log is forthcoming diff --git a/services/log-server/src/main.rs b/services/log-server/src/main.rs index 1beebbb92..3ea6ce9a8 100644 --- a/services/log-server/src/main.rs +++ b/services/log-server/src/main.rs @@ -86,6 +86,20 @@ mod implementation { pub fn putc(&self, c: u8) { self.tx.send(ControlMessage::Byte(c)).unwrap(); } + + /// Write a buffer to the output and return the number of + /// bytes written. This is mostly compatible with `std::io::Write`, + /// except it is infallible. + pub fn write(&mut self, buf: &[u8]) -> usize { + for c in buf { + self.putc(*c); + } + buf.len() + } + + pub fn write_all(&mut self, buf: &[u8]) -> core::result::Result { + Ok(self.write(buf)) + } } impl Write for OutputWriter { @@ -177,6 +191,20 @@ mod implementation { uart_csr.wo(utra::uart::RXTX, c as u32); } } + + /// Write a buffer to the output and return the number of + /// bytes written. This is mostly compatible with `std::io::Write`, + /// except it is infallible. + pub fn write(&mut self, buf: &[u8]) -> usize { + for c in buf { + self.putc(*c); + } + buf.len() + } + + pub fn write_all(&mut self, buf: &[u8]) -> core::result::Result { + Ok(self.write(buf)) + } } impl Write for OutputWriter { @@ -199,7 +227,7 @@ fn handle_scalar( sender_pid: xous::PID, ) { match msg.id { - 1000 => writeln!(output, "PANIC from PID {} | {}", sender_pid, sender).unwrap(), + 1000 => writeln!(output, "PANIC in PID {}:", sender_pid).unwrap(), 1100 => (), 1101..=1132 => { let mut output_bfr = [0u8; core::mem::size_of::() * 4]; @@ -279,8 +307,10 @@ fn handle_opcode( } } api::Opcode::StandardOutput | api::Opcode::StandardError => { - let string = unsafe { xous::stringbuffer::StringBuffer::from_memory_message(mem) }; - write!(output, "{}", string).unwrap(); + let buffer = + unsafe { core::slice::from_raw_parts(mem.buf.as_ptr(), mem.buf.len()) }; + output.write_all(buffer).unwrap(); + // TODO: If the buffer is mutable, set `length` to 0. } _ => { writeln!(output, "Unhandled opcode").unwrap();