Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kunxian-xia committed Oct 29, 2024
1 parent f86f41c commit 208509b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 25 deletions.
13 changes: 0 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 0 additions & 2 deletions ceno_emul/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions ceno_emul/src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Program {
pub fn load_elf(input: &[u8], max_mem: u32) -> Result<Program> {
let mut instructions: Vec<u32> = Vec::new();
let mut image: BTreeMap<u32, u32> = BTreeMap::new();
let mut base_address = max_mem;
let mut base_address = None;

let elf = ElfBytes::<LittleEndian>::minimal_parse(input)
.map_err(|err| anyhow!("Elf parse error: {err}"))?;
Expand Down Expand Up @@ -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
Expand All @@ -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");
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions ceno_emul/src/rv32im.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// limitations under the License.

use anyhow::{Result, anyhow};
use num_derive::ToPrimitive;
use std::sync::OnceLock;
use strum_macros::EnumIter;

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 208509b

Please sign in to comment.