Skip to content

Commit

Permalink
sync-platform: remove stack_top
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurélien Nicolas committed Dec 12, 2024
1 parent 82a9150 commit 952da9c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions ceno_emul/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub struct Platform {
pub heap: Range<Addr>,
pub public_io: Range<Addr>,
pub hints: Range<Addr>,
pub stack_top: Addr, // TODO: remove.
/// If true, ecall instructions are no-op instead of trap. Testing only.
pub unsafe_ecall_nop: bool,
}
Expand All @@ -29,7 +28,6 @@ pub const CENO_PLATFORM: Platform = Platform {
heap: 0x8000_0000..0xFFFF_0000,
public_io: 0x3000_1000..0x3000_2000,
hints: 0x4000_0000..0x5000_0000,
stack_top: 0xC0000000,
unsafe_ecall_nop: false,
};

Expand Down Expand Up @@ -82,11 +80,11 @@ impl Platform {
// Permissions.

pub fn can_read(&self, addr: Addr) -> bool {
self.is_rom(addr) || self.is_ram(addr) || self.is_pub_io(addr) || self.is_hints(addr)
self.can_write(addr)
}

pub fn can_write(&self, addr: Addr) -> bool {
self.is_ram(addr)
self.is_ram(addr) || self.is_pub_io(addr) || self.is_hints(addr)
}

pub fn can_execute(&self, addr: Addr) -> bool {
Expand Down Expand Up @@ -131,8 +129,8 @@ mod tests {
let p = CENO_PLATFORM;
assert!(p.can_execute(p.pc_base()));
// ROM and RAM do not overlap.
assert!(!p.is_rom(p.ram.start));
assert!(!p.is_rom(p.ram.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.
Expand Down
2 changes: 1 addition & 1 deletion ceno_emul/src/vm_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl EmuContext for VMState {
tracing::warn!("ecall ignored: syscall_id={}", function);
self.store_register(DecodedInstruction::RD_NULL as RegIdx, 0)?;
// Example ecall effect - any writable address will do.
let addr = (self.platform.stack_top - WORD_SIZE as u32).into();
let addr = (self.platform.stack.end - WORD_SIZE as u32).into();
self.store_memory(addr, self.peek_memory(addr))?;
self.set_pc(ByteAddr(self.pc) + PC_STEP_SIZE);
Ok(true)
Expand Down
4 changes: 2 additions & 2 deletions ceno_zkvm/src/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ pub fn setup_platform(
Preset::Ceno => CENO_PLATFORM,
Preset::Sp1 => Platform {
// The stack section is not mentioned in ELF headers, so we repeat the constant STACK_TOP here.
stack_top: 0x0020_0400,
stack: 0x0020_0400..0x0020_0400,
ram: 0x0010_0000..0xFFFF_0000,
unsafe_ecall_nop: true,
..CENO_PLATFORM
},
};

let prog_data = program.image.keys().copied().collect::<HashSet<Addr>>();
let stack = preset.stack_top - stack_size..preset.stack_top;
let stack = preset.stack.end - stack_size..preset.stack.end;
let heap = {
// Detect heap as starting after program data.
let heap_start = program.image.keys().max().unwrap() + WORD_SIZE as u32;
Expand Down

0 comments on commit 952da9c

Please sign in to comment.