63 lines
1.4 KiB
Rust
63 lines
1.4 KiB
Rust
|
|
use extism_pdk::*;
|
||
|
|
use serde::{Deserialize, Serialize};
|
||
|
|
|
||
|
|
#[derive(Serialize, Deserialize, ToBytes, FromBytes)]
|
||
|
|
#[encoding(Json)]
|
||
|
|
pub struct Init {
|
||
|
|
pub verbose: bool,
|
||
|
|
pub mem_size: usize,
|
||
|
|
pub registers: usize,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Serialize, Deserialize, ToBytes, FromBytes)]
|
||
|
|
#[encoding(Json)]
|
||
|
|
pub struct SetVerbose(pub bool);
|
||
|
|
|
||
|
|
#[derive(Serialize, Deserialize, ToBytes, FromBytes)]
|
||
|
|
#[encoding(Json)]
|
||
|
|
pub struct SetMemory {
|
||
|
|
pub offset: usize,
|
||
|
|
pub memory: Vec<u8>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Serialize, Deserialize, ToBytes, FromBytes)]
|
||
|
|
#[encoding(Json)]
|
||
|
|
pub enum RunResult {
|
||
|
|
Success,
|
||
|
|
}
|
||
|
|
|
||
|
|
pub trait CpuTrait {
|
||
|
|
fn new() -> Self
|
||
|
|
where
|
||
|
|
Self: Sized;
|
||
|
|
|
||
|
|
fn set_verbose(&mut self, verbose: bool);
|
||
|
|
|
||
|
|
fn load_memory(&mut self, memory: &[u8]);
|
||
|
|
|
||
|
|
fn execute(&mut self, run_mode: RunMode);
|
||
|
|
|
||
|
|
fn get_registers(&self) -> &[u16];
|
||
|
|
|
||
|
|
fn get_memory(&self) -> &[u8];
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Serialize, Deserialize, ToBytes, FromBytes)]
|
||
|
|
#[encoding(Json)]
|
||
|
|
pub enum RunMode {
|
||
|
|
Run, // Run to completion
|
||
|
|
Debug(DebugMode), // Debug mode
|
||
|
|
StepOver, // Step over calls
|
||
|
|
StepInto, // Step into calls
|
||
|
|
StepOut, // Step out of calls
|
||
|
|
RunFor(usize), // Run for a specific number of cycles
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Serialize, Deserialize, ToBytes, FromBytes)]
|
||
|
|
#[encoding(Json)]
|
||
|
|
pub enum DebugMode {
|
||
|
|
All, // Break on any breakpoint
|
||
|
|
Code, // Break on code breakpoints
|
||
|
|
Data, // Break on data breakpoints
|
||
|
|
}
|