From 208509bec179ac5fe924657a2ba9df45a573264f Mon Sep 17 00:00:00 2001 From: kunxian xia Date: Tue, 29 Oct 2024 11:54:50 +0800 Subject: [PATCH] address comments --- Cargo.lock | 13 ------------- Cargo.toml | 2 -- ceno_emul/Cargo.toml | 2 -- ceno_emul/src/elf.rs | 20 ++++++++++++++------ ceno_emul/src/rv32im.rs | 3 +-- 5 files changed, 15 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09cd4ec9e..c80dfdedb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -241,8 +241,6 @@ dependencies = [ "anyhow", "ceno-examples", "elf", - "num-derive", - "num-traits", "strum", "strum_macros", "tracing", @@ -1120,17 +1118,6 @@ dependencies = [ "rand", ] -[[package]] -name = "num-derive" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.82", -] - [[package]] name = "num-format" version = "0.4.4" diff --git a/Cargo.toml b/Cargo.toml index b69a91ef0..aea908372 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,8 +31,6 @@ crossbeam-channel = "0.5" ff = "0.13" goldilocks = { git = "https://github.com/hero78119/Goldilocks" } itertools = "0.13" -num-traits = "0.2" -num-derive = "0.4" paste = "1" plonky2 = "0.2" poseidon = { path = "./poseidon" } diff --git a/ceno_emul/Cargo.toml b/ceno_emul/Cargo.toml index 6b93a3f0a..8f78e5805 100644 --- a/ceno_emul/Cargo.toml +++ b/ceno_emul/Cargo.toml @@ -7,8 +7,6 @@ version.workspace = true [dependencies] anyhow = { version = "1.0", default-features = false } elf = "0.7" -num-derive.workspace = true -num-traits.workspace = true strum.workspace = true strum_macros.workspace = true tracing.workspace = true diff --git a/ceno_emul/src/elf.rs b/ceno_emul/src/elf.rs index 9a1c8742b..21d12779f 100644 --- a/ceno_emul/src/elf.rs +++ b/ceno_emul/src/elf.rs @@ -59,7 +59,7 @@ impl Program { pub fn load_elf(input: &[u8], max_mem: u32) -> Result { let mut instructions: Vec = Vec::new(); let mut image: BTreeMap = BTreeMap::new(); - let mut base_address = max_mem; + let mut base_address = None; let elf = ElfBytes::::minimal_parse(input) .map_err(|err| anyhow!("Elf parse error: {err}"))?; @@ -92,9 +92,9 @@ impl Program { tracing::debug!( "loadable segement {}: PF_R={}, PF_W={}, PF_X={}", idx, - segment.p_flags & PF_R, - segment.p_flags & PF_W, - segment.p_flags & PF_X, + segment.p_flags & PF_R != 0, + segment.p_flags & PF_W != 0, + segment.p_flags & PF_X != 0, ); let file_size: u32 = segment .p_filesz @@ -114,8 +114,12 @@ impl Program { .p_vaddr .try_into() .map_err(|err| anyhow!("vaddr is larger than 32 bits. {err}"))?; - if (segment.p_flags & PF_X) != 0 && base_address > vaddr { - base_address = vaddr; + if (segment.p_flags & PF_X) != 0 { + if base_address.is_none() { + base_address = Some(vaddr); + } else { + return Err(anyhow!("only support one executable segment")); + } } if vaddr % WORD_SIZE as u32 != 0 { bail!("vaddr {vaddr:08x} is unaligned"); @@ -151,6 +155,10 @@ impl Program { } } + if base_address.is_none() { + return Err(anyhow!("does not have executable segment")); + } + let base_address = base_address.unwrap(); assert!(entry >= base_address); assert!((entry - base_address) as usize <= instructions.len() * WORD_SIZE); diff --git a/ceno_emul/src/rv32im.rs b/ceno_emul/src/rv32im.rs index b7618aad0..0ce557be2 100644 --- a/ceno_emul/src/rv32im.rs +++ b/ceno_emul/src/rv32im.rs @@ -15,7 +15,6 @@ // limitations under the License. use anyhow::{Result, anyhow}; -use num_derive::ToPrimitive; use std::sync::OnceLock; use strum_macros::EnumIter; @@ -135,7 +134,7 @@ pub enum InsnFormat { } use InsnFormat::*; -#[derive(Clone, Copy, Debug, PartialEq, EnumIter, ToPrimitive)] +#[derive(Clone, Copy, Debug, PartialEq, EnumIter)] #[allow(clippy::upper_case_acronyms)] pub enum InsnKind { INVALID,