From c752028c73e61dd017fea5c7f27801be8bcb636d Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 31 Aug 2024 19:34:14 +0100 Subject: [PATCH] fix ecah.rs, implement -d, --debuginfo to print debug info in serial (requires recompilation) --- kernel/src/holeybytes/ecah.rs | 15 +++++++-------- repbuild/src/main.rs | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index d0202cf..8571363 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -129,7 +129,7 @@ pub fn handler(vm: &mut Vm) { }; msg_vec.remove(0); - let addr = ((msg_vec[0] as u16) << 8) + msg_vec[1] as u16; + let addr = ((msg_vec[0] as u16) << 8) | msg_vec[1] as u16; msg_vec.remove(0); msg_vec.remove(0); let value = unsafe { @@ -155,7 +155,7 @@ pub fn handler(vm: &mut Vm) { } }; msg_vec.remove(0); - let addr = ((msg_vec[0] as u16) << 8) + msg_vec[1] as u16; + let addr = ((msg_vec[0] as u16) << 8) | msg_vec[1] as u16; msg_vec.remove(0); msg_vec.remove(0); trace!("Setting address {}", addr); @@ -164,15 +164,14 @@ pub fn handler(vm: &mut Vm) { 1 => x86_out(addr, msg_vec[0]), 2 => x86_out_16( addr, - core::mem::transmute::<[u8; 2], u16>( - msg_vec[0..2].try_into().unwrap(), - ), + ((msg_vec[0] as u16) << 8) | msg_vec[1] as u16, ), 4 => x86_out_32( addr, - core::mem::transmute::<[u8; 4], u32>( - msg_vec[0..4].try_into().unwrap(), - ), + ((msg_vec[0] as u32) << 24) + | ((msg_vec[1] as u32) << 16) + | ((msg_vec[2] as u32) << 8) + | (msg_vec[3] as u32), ), _ => panic!("How?"), } diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index af09c6d..8eb4835 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -22,10 +22,13 @@ fn main() -> Result<(), Error> { match args.next().as_deref() { Some("build" | "b") => { let mut release = false; + let mut debuginfo = false; let mut target = Target::X86_64; for arg in args { if arg == "-r" || arg == "--release" { release = true; + } else if arg == "-d" || arg == "--debuginfo" { + debuginfo = true; } else if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" { target = Target::Riscv64Virt; } else if arg == "arm64" || arg == "aarch64" || arg == "aarch64-virt" { @@ -35,14 +38,17 @@ fn main() -> Result<(), Error> { } } - build(release, target).change_context(Error::Build) + build(release, target, debuginfo).change_context(Error::Build) } Some("run" | "r") => { let mut release = false; + let mut debuginfo = false; let mut target = Target::X86_64; for arg in args { if arg == "-r" || arg == "--release" { release = true; + } else if arg == "-d" || arg == "--debuginfo" { + debuginfo = true; } else if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" { target = Target::Riscv64Virt; } else if arg == "arm64" || arg == "aarch64" || arg == "aarch64-virt" { @@ -52,7 +58,7 @@ fn main() -> Result<(), Error> { } } - build(release, target)?; + build(release, target, debuginfo)?; run(release, target) } Some("help" | "h") => { @@ -270,7 +276,7 @@ fn copy_file_to_img(fpath: &str, fs: &FileSystem) { .expect("Copy failed"); } -fn build(release: bool, target: Target) -> Result<(), Error> { +fn build(release: bool, target: Target, debuginfo: bool) -> Result<(), Error> { let fs = get_fs().change_context(Error::Io)?; let mut com = Command::new("cargo"); com.current_dir("kernel"); @@ -278,6 +284,9 @@ fn build(release: bool, target: Target) -> Result<(), Error> { if release { com.arg("-r"); } + if debuginfo { + com.env("RUSTFLAGS", "-Cdebug-assertions=true"); + } if target == Target::Riscv64Virt { com.args(["--target", "targets/riscv64-virt-ableos.json"]);