From 952da9c95080ea2a5ec8d129e88cda878996acb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Nicolas?= Date: Thu, 12 Dec 2024 02:56:18 +0100 Subject: [PATCH] sync-platform: remove stack_top --- ceno_emul/src/platform.rs | 10 ++++------ ceno_emul/src/vm_state.rs | 2 +- ceno_zkvm/src/e2e.rs | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ceno_emul/src/platform.rs b/ceno_emul/src/platform.rs index 40bb09230..0f7c5112d 100644 --- a/ceno_emul/src/platform.rs +++ b/ceno_emul/src/platform.rs @@ -16,7 +16,6 @@ pub struct Platform { pub heap: Range, pub public_io: Range, pub hints: Range, - pub stack_top: Addr, // TODO: remove. /// If true, ecall instructions are no-op instead of trap. Testing only. pub unsafe_ecall_nop: bool, } @@ -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, }; @@ -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 { @@ -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. diff --git a/ceno_emul/src/vm_state.rs b/ceno_emul/src/vm_state.rs index e071cb000..3ad4cdec2 100644 --- a/ceno_emul/src/vm_state.rs +++ b/ceno_emul/src/vm_state.rs @@ -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) diff --git a/ceno_zkvm/src/e2e.rs b/ceno_zkvm/src/e2e.rs index 32ca4c2c8..3c2d0c690 100644 --- a/ceno_zkvm/src/e2e.rs +++ b/ceno_zkvm/src/e2e.rs @@ -177,7 +177,7 @@ 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 @@ -185,7 +185,7 @@ pub fn setup_platform( }; let prog_data = program.image.keys().copied().collect::>(); - 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;