-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5e8077
commit e67ac71
Showing
22 changed files
with
646 additions
and
354 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub const MEMORY_TOP: u32 = 0x80400000; | ||
pub const WORD_SIZE: usize = 4; |
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,2 @@ | ||
pub mod constants; | ||
pub use constants::*; |
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,3 +1,4 @@ | ||
pub mod constants; | ||
pub mod cpu; | ||
pub mod error; | ||
pub mod memory; | ||
|
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,34 @@ | ||
// use crate::constants::WORD_SIZE; | ||
|
||
#[macro_export] | ||
macro_rules! word_align { | ||
($len:expr) => { | ||
($len + $crate::constants::WORD_SIZE - 1) & !($crate::constants::WORD_SIZE - 1) | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! bytes_to_words { | ||
($bytes:expr) => {{ | ||
// Convert the associated data to word representation. | ||
let mut bytes = $bytes.to_vec(); | ||
let padded_len = $crate::word_align!(bytes.len()); | ||
bytes.resize(padded_len, 0); | ||
// Convert to u32 chunks. | ||
bytes | ||
.chunks($crate::constants::WORD_SIZE) | ||
.map(|chunk| u32::from_le_bytes([chunk[0], chunk[1], chunk[2], chunk[3]])) | ||
.collect::<Vec<u32>>() | ||
}}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! words_to_bytes { | ||
($words:expr) => {{ | ||
let mut bytes: Vec<u8> = Vec::with_capacity($words.len() * $crate::constants::WORD_SIZE); | ||
for word in $words { | ||
bytes.extend_from_slice(&word.to_le_bytes()); | ||
} | ||
bytes | ||
}}; | ||
} |
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,2 +1,4 @@ | ||
pub mod alignment; | ||
pub use alignment::*; | ||
pub mod traits; | ||
pub use traits::*; |
Oops, something went wrong.