Skip to content

Commit

Permalink
sync-platform: rename rom to prog_code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurélien Nicolas committed Dec 12, 2024
1 parent 952da9c commit 4373f07
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
14 changes: 7 additions & 7 deletions ceno_emul/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::addr::{Addr, RegIdx};
/// - codes of environment calls.
#[derive(Clone, Debug)]
pub struct Platform {
pub rom: Range<Addr>, // TODO: rename.
pub prog_code: Range<Addr>,
pub ram: Range<Addr>, // TODO: remove.
pub prog_data: Option<HashSet<Addr>>,
pub stack: Range<Addr>,
Expand All @@ -21,7 +21,7 @@ pub struct Platform {
}

pub const CENO_PLATFORM: Platform = Platform {
rom: 0x2000_0000..0x3000_0000,
prog_code: 0x2000_0000..0x3000_0000,
ram: 0x8000_0000..0xFFFF_0000,
prog_data: None, // This is an `Option` to allow `const` here.
stack: 0xB0000000..0xC0000000,
Expand All @@ -35,7 +35,7 @@ impl Platform {
// Virtual memory layout.

pub fn is_rom(&self, addr: Addr) -> bool {
self.rom.contains(&addr)
self.prog_code.contains(&addr)
}

pub fn is_ram(&self, addr: Addr) -> bool {
Expand All @@ -48,7 +48,7 @@ impl Platform {
pub fn is_prog_data(&self, addr: Addr) -> bool {
self.prog_data
.as_ref()
.map(|set| set.contains(&addr))
.map(|set| set.contains(&(addr & !0x3)))
.unwrap_or(false)
}

Expand All @@ -74,7 +74,7 @@ impl Platform {
// Startup.

pub const fn pc_base(&self) -> Addr {
self.rom.start
self.prog_code.start
}

// Permissions.
Expand Down Expand Up @@ -131,8 +131,8 @@ mod tests {
// ROM and RAM do not overlap.
assert!(!p.is_rom(p.heap.start));
assert!(!p.is_rom(p.heap.end - WORD_SIZE as Addr));
assert!(!p.is_ram(p.rom.start));
assert!(!p.is_ram(p.rom.end - WORD_SIZE as Addr));
assert!(!p.is_ram(p.prog_code.start));
assert!(!p.is_ram(p.prog_code.end - WORD_SIZE as Addr));
// Registers do not overlap with ROM or RAM.
for reg in [
Platform::register_vma(0),
Expand Down
13 changes: 11 additions & 2 deletions ceno_emul/tests/test_elf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use std::{collections::HashSet, sync::Arc};

use anyhow::Result;
use ceno_emul::{ByteAddr, CENO_PLATFORM, EmuContext, InsnKind, Platform, StepRecord, VMState};
use ceno_emul::{
ByteAddr, CENO_PLATFORM, EmuContext, InsnKind, Platform, Program, StepRecord, VMState,
};

#[test]
fn test_ceno_rt_mini() -> Result<()> {
Expand Down Expand Up @@ -60,7 +64,12 @@ fn test_ceno_rt_alloc() -> Result<()> {
#[test]
fn test_ceno_rt_io() -> Result<()> {
let program_elf = ceno_examples::ceno_rt_io;
let mut state = VMState::new_from_elf(CENO_PLATFORM, program_elf)?;
let program = Program::load_elf(program_elf, u32::MAX)?;
let platform = Platform {
prog_data: Some(program.image.keys().copied().collect::<HashSet<u32>>()),
..CENO_PLATFORM
};
let mut state = VMState::new(platform, Arc::new(program));
let _steps = run(&mut state)?;

let all_messages = read_all_messages(&state);
Expand Down
2 changes: 1 addition & 1 deletion ceno_zkvm/src/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub fn setup_platform(
};

Platform {
rom: program.base_address
prog_code: program.base_address
..program.base_address + (program.instructions.len() * WORD_SIZE) as u32,
prog_data: Some(prog_data),
stack,
Expand Down

0 comments on commit 4373f07

Please sign in to comment.