-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add files mod to read binary files
- Loading branch information
Showing
10 changed files
with
268 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ version = "0.1.0" | |
edition = "2021" | ||
|
||
[dependencies] | ||
clap = { version = "4.5.1", features = ["derive"] } |
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,17 @@ | ||
pub fn read_file(filename: &str) -> Vec<u8> { | ||
return std::fs::read(filename).unwrap(); | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::read_file; | ||
#[test] | ||
fn test_read_file() { | ||
let file_byte = read_file("./tests/addi.bin"); | ||
for byte in file_byte { | ||
if byte != 0 { | ||
println!("{:x}", byte); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod cpu; | ||
pub mod files; | ||
pub mod memory; | ||
pub mod opcode; | ||
pub mod registers; |
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,19 @@ | ||
use clap::Parser; | ||
|
||
use riscland::cpu; | ||
use riscland::files; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(version)] | ||
struct Args { | ||
// input binary file | ||
#[arg(short, long)] | ||
file: String, | ||
} | ||
|
||
fn main() { | ||
let args = Args::parse(); | ||
let mut cpu = cpu::CPU::new(); | ||
let file_bin = files::read_file(&args.file); | ||
cpu.bus.init_memory(file_bin); | ||
} |
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// pub mod opcode; | ||
|
||
pub const LUI: u32 = 0x37; | ||
pub const AUIPC: u32 = 0x17; | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// pub mod registers; | ||
|
||
use core::fmt; | ||
|
||
#[derive(Clone, Copy)] | ||
|
Binary file not shown.