Skip to content

Commit

Permalink
feat: impl register and cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
eigmax committed Oct 27, 2023
1 parent 22e26d1 commit 6753726
Show file tree
Hide file tree
Showing 6 changed files with 581 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ byteorder = "1.5.0"

elf = { version = "0.7", default-features = false }

# for debug
prettytable-rs = "^0.8"

[dev-dependencies]
env_logger = { version = "0.9.0", default-features = false }
keccak-hash = "0.10.0"
1 change: 1 addition & 0 deletions src/cpu/kernel/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub(crate) fn combined_kernel() -> Kernel {
let code_hash = code_hash_be.map(u32::from_be);
log::debug!("code_hash: {:?}", code_hash);


Kernel {
code,
code_hash,
Expand Down
23 changes: 14 additions & 9 deletions src/cpu/kernel/load_elf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate alloc;

use alloc::collections::BTreeMap;

use anyhow::{anyhow, bail, Context, Result};
Expand All @@ -8,7 +7,7 @@ pub const WORD_SIZE: usize = core::mem::size_of::<u32>();

/// A MIPS program
pub struct Program {
/// The entrypoint of the program
/// The entrypoint of the program, PC
pub entry: u32,

/// The initial memory image
Expand Down Expand Up @@ -107,12 +106,18 @@ mod test {
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).unwrap();
let max_mem = 0x40000000;
let _p = Program::load_elf(&buffer, max_mem).unwrap();
/*
log::debug!("entry: {}", p.entry);
p.image.iter().for_each(|(k, v)| {
log::debug!("{}: {}", k, v);
})
*/
let p = Program::load_elf(&buffer, max_mem).unwrap();
println!("entry: {}", p.entry);
let mut entry = p.entry;
let mut step = 0;
loop {
println!("{}: {}", step, entry);
if ! p.image.contains_key(&entry) {
break;
}
entry = p.image[&entry];
step += 1;
}
println!("Done");
}
}
Loading

0 comments on commit 6753726

Please sign in to comment.