Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syscall Boilerplate for riscvi32 (no interpreter implementation) #2751

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions o1vm/src/interpreters/riscv32i/column.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{
interpreter::{
IInstruction, Instruction,
Instruction::{IType, RType, SBType, SType, UJType, UType},
RInstruction, SBInstruction, SInstruction, UInstruction,
IInstruction,
Instruction::{self, IType, RType, SBType, SType, SyscallType, UJType, UType},
RInstruction, SBInstruction, SInstruction, UInstruction, UJInstruction,
},
INSTRUCTION_SET_SIZE, SCRATCH_SIZE,
};
Expand Down Expand Up @@ -73,6 +73,17 @@ impl From<Instruction> for usize {
+ UInstruction::COUNT
+ ujtype as usize
}
SyscallType(syscalltype) => {
SCRATCH_SIZE
+ 1
+ RInstruction::COUNT
+ IInstruction::COUNT
+ SInstruction::COUNT
+ SBInstruction::COUNT
+ UInstruction::COUNT
+ UJInstruction::COUNT
+ syscalltype as usize
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions o1vm/src/interpreters/riscv32i/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum Instruction {
SBType(SBInstruction),
UType(UInstruction),
UJType(UJInstruction),
SyscallType(SyscallInstruction),
}

// See
Expand Down Expand Up @@ -101,6 +102,15 @@ pub enum UJInstruction {
JumpAndLinkRegister, // jalr
}

#[derive(
Debug, Clone, Copy, Eq, PartialEq, EnumCount, EnumIter, Default, Hash, Ord, PartialOrd,
)]

pub enum SyscallInstruction {
#[default]
SyscallSuccess,
}

impl IntoIterator for Instruction {
type Item = Instruction;
type IntoIter = std::vec::IntoIter<Instruction>;
Expand Down Expand Up @@ -149,6 +159,13 @@ impl IntoIterator for Instruction {
}
iter_contents.into_iter()
}
Instruction::SyscallType(_) => {
let mut iter_contents = Vec::with_capacity(SyscallInstruction::COUNT);
for syscall in SyscallInstruction::iter() {
iter_contents.push(Instruction::SyscallType(syscall));
}
iter_contents.into_iter()
}
}
}
}
Expand All @@ -162,6 +179,7 @@ impl std::fmt::Display for Instruction {
Instruction::SBType(sbtype) => write!(f, "{}", sbtype),
Instruction::UType(utype) => write!(f, "{}", utype),
Instruction::UJType(ujtype) => write!(f, "{}", ujtype),
Instruction::SyscallType(_syscall) => write!(f, "ecall"),
}
}
}
Expand Down Expand Up @@ -1050,6 +1068,7 @@ pub fn interpret_instruction<Env: InterpreterEnv>(env: &mut Env, instr: Instruct
Instruction::SBType(sbtype) => interpret_sbtype(env, sbtype),
Instruction::UType(utype) => interpret_utype(env, utype),
Instruction::UJType(ujtype) => interpret_ujtype(env, ujtype),
Instruction::SyscallType(syscall) => interpret_syscall(env, syscall),
}
}

Expand All @@ -1076,3 +1095,7 @@ pub fn interpret_utype<Env: InterpreterEnv>(_env: &mut Env, _instr: UInstruction
pub fn interpret_ujtype<Env: InterpreterEnv>(_env: &mut Env, _instr: UJInstruction) {
unimplemented!("TODO")
}

pub fn interpret_syscall<Env: InterpreterEnv>(_env: &mut Env, _instr: SyscallInstruction) {
unimplemented!("TODO")
}
Loading