Skip to content

Commit

Permalink
Let snapshots stores the load_reservation_address
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Feb 28, 2024
1 parent b7da390 commit 24e8c77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ pub struct Snapshot {
pub page_indices: Vec<u64>,
pub page_flags: Vec<u8>,
pub pages: Vec<Vec<u8>>,
pub load_reservation_address: u64,
}

pub fn make_snapshot<T: CoreMachine>(machine: &mut T) -> Result<Snapshot, Error> {
let mut snap = Snapshot {
version: machine.version(),
pc: machine.pc().to_u64(),
load_reservation_address: machine.memory().lr().to_u64(),
..Default::default()
};
for (i, v) in machine.registers().iter().enumerate() {
Expand Down Expand Up @@ -92,6 +94,8 @@ pub fn resume<T: CoreMachine>(machine: &mut T, snapshot: &Snapshot) -> Result<()
machine.memory_mut().store_bytes(addr_from, &page[..])?;
machine.memory_mut().set_flag(page_index, page_flag)?;
}

machine
.memory_mut()
.set_lr(&T::REG::from_u64(snapshot.load_reservation_address));
Ok(())
}
5 changes: 5 additions & 0 deletions src/snapshot2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ impl<I: Clone + PartialEq, D: DataSource<I>> Snapshot2Context<I, D> {
machine.memory_mut().set_flag(page, *flag)?;
}
}
machine
.memory_mut()
.set_lr(&M::REG::from_u64(snapshot.load_reservation_address));
Ok(())
}

Expand Down Expand Up @@ -204,6 +207,7 @@ impl<I: Clone + PartialEq, D: DataSource<I>> Snapshot2Context<I, D> {
pc: machine.pc().to_u64(),
cycles: machine.cycles(),
max_cycles: machine.max_cycles(),
load_reservation_address: machine.memory().lr().to_u64(),
})
}

Expand Down Expand Up @@ -261,4 +265,5 @@ pub struct Snapshot2<I: Clone + PartialEq> {
pub pc: u64,
pub cycles: u64,
pub max_cycles: u64,
pub load_reservation_address: u64,
}

0 comments on commit 24e8c77

Please sign in to comment.