-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[difftest] t1rocketemu: reimplement EXIT_POS by mmio device
- Loading branch information
Showing
5 changed files
with
125 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::sync::{ | ||
atomic::{AtomicU32, Ordering}, | ||
Arc, | ||
}; | ||
|
||
use tracing::{info, warn}; | ||
|
||
use super::RegDevice; | ||
|
||
#[derive(Default, Debug, Clone)] | ||
pub struct ExitFlagRef(Arc<AtomicU32>); | ||
|
||
impl ExitFlagRef { | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
pub fn is_finish(&self) -> bool { | ||
self.0.load(Ordering::Acquire) != 0 | ||
} | ||
|
||
pub fn mark_finish(&self) { | ||
self.0.store(1, Ordering::Release); | ||
} | ||
} | ||
|
||
pub const EXIT_CODE: u32 = 0xdead_beef; | ||
|
||
/// Reg map: | ||
/// - 0x0000 : WO, write EXIT_CODE to mark simulation finish | ||
pub struct SimCtrl { | ||
exit_flag: ExitFlagRef, | ||
} | ||
|
||
impl SimCtrl { | ||
pub fn new(exit_flag: ExitFlagRef) -> Self { | ||
SimCtrl { exit_flag } | ||
} | ||
} | ||
|
||
impl RegDevice for SimCtrl { | ||
fn reg_read(&mut self, offset: u32) -> u32 { | ||
let _ = offset; | ||
unimplemented!() | ||
} | ||
|
||
fn reg_write(&mut self, reg_offset: u32, value: u32) { | ||
match reg_offset { | ||
0 => { | ||
if value == EXIT_CODE { | ||
self.exit_flag.mark_finish(); | ||
info!("simctrl: write EXIT_POS with EXIT_CODE, ready to quit"); | ||
} else { | ||
warn!("simctrl: write EXIT_POS with value 0x{value:08x}, ignored"); | ||
} | ||
} | ||
_ => panic!(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters