Skip to content

Commit

Permalink
sync-platform: revert prog_code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurélien Nicolas committed Dec 13, 2024
1 parent 2d79869 commit 066212c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions ceno_emul/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::addr::{Addr, RegIdx};
/// - codes of environment calls.
#[derive(Clone, Debug)]
pub struct Platform {
pub prog_code: Range<Addr>,
pub rom: Range<Addr>,
// This is an `Option` to allow `const` here.
pub prog_data: Option<HashSet<Addr>>,
pub stack: Range<Addr>,
pub heap: Range<Addr>,
Expand All @@ -20,8 +21,8 @@ pub struct Platform {
}

pub const CENO_PLATFORM: Platform = Platform {
prog_code: 0x2000_0000..0x3000_0000,
prog_data: None, // This is an `Option` to allow `const` here.
rom: 0x2000_0000..0x3000_0000,
prog_data: None,
stack: 0xB0000000..0xC0000000,
heap: 0x8000_0000..0xFFFF_0000,
public_io: 0x3000_1000..0x3000_2000,
Expand All @@ -32,8 +33,8 @@ pub const CENO_PLATFORM: Platform = Platform {
impl Platform {
// Virtual memory layout.

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

pub fn is_prog_data(&self, addr: Addr) -> bool {
Expand Down Expand Up @@ -69,7 +70,7 @@ impl Platform {
// Startup.

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

// Permissions.
Expand All @@ -83,7 +84,7 @@ impl Platform {
}

pub fn can_execute(&self, addr: Addr) -> bool {
self.is_prog_code(addr)
self.is_rom(addr)
}

// Environment calls.
Expand Down Expand Up @@ -124,16 +125,16 @@ mod tests {
let p = CENO_PLATFORM;
assert!(p.can_execute(p.pc_base()));
// ROM and RAM do not overlap.
assert!(!p.is_prog_code(p.heap.start));
assert!(!p.is_prog_code(p.heap.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));
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));
// Registers do not overlap with ROM or RAM.
for reg in [
Platform::register_vma(0),
Platform::register_vma(VMState::REG_COUNT - 1),
] {
assert!(!p.is_prog_code(reg));
assert!(!p.is_rom(reg));
assert!(!p.is_ram(reg));
}
}
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 @@ -201,7 +201,7 @@ pub fn setup_platform(
};

Platform {
prog_code: program.base_address
rom: 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 066212c

Please sign in to comment.