Skip to content

Commit

Permalink
doc(mmu): add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
4rgon4ut committed Oct 13, 2024
1 parent f560f76 commit f63f5a6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tracer/src/emulator/mmu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,40 @@ impl Mmu {
}
}

/// Asserts the validity of an effective memory address.
/// Panics if the address is invalid.
///
/// # Arguments
/// * `effective_address` Effective memory address to validate
///
/// Memory Layout:
/// DRAM_BASE
/// |
/// Low addresses | High addresses
/// 0x0 V 0xFF...
/// |-----------------------------------------------|--------------|
/// | ... | panic | zero_padding | <-stack | heap-> |
/// |-----------------------------------------------|--------------|
/// *Stack grows downwards up to DRAM_BASE
/// **Heap grows upwards
#[inline]
fn assert_effective_address(&self, effective_address: u64) {
if effective_address < DRAM_BASE {
// less then DRAM_BASE and greater then panic => zero_padding region
assert!(
effective_address <= self.jolt_device.memory_layout.panic,
"Stack overflow: Attempted to write to 0x{:X}, which is in the area or zero padding region.",
effective_address
);
// less then panic => jolt_device region (i.e. input/output)
assert!(
self.jolt_device.is_output(effective_address)
|| self.jolt_device.is_panic(effective_address),
"Unknown memory mapping 0x{:X}.",
effective_address
);
} else {
// greater then memory capacity
assert!(
self.memory.validate_address(effective_address),
"Heap overflow: Attempted to write to 0x{:X}, which is beyond the allocated memory.",
Expand Down

0 comments on commit f63f5a6

Please sign in to comment.