amebazii/map.rs
1/// Represents a memory address range, defined by a starting address and an ending address.
2///
3/// This struct is used to define ranges of memory addresses, providing utilities to check
4/// if a specific address falls within the range. The range is inclusive of the start address
5/// and exclusive of the end address.
6#[derive(Debug, Clone, Copy)]
7pub struct AddressRange(u64, u64);
8
9/// The vector table, it must start with 256 bytes aligned address.
10pub const VECTORS_RAM: AddressRange = AddressRange::new(0x10000000, 0x100000A0);
11
12/// RAM functions entry table, storing function entries in RAM.
13pub const RAM_FUN_TABLE: AddressRange = AddressRange::new(0x10000480, 0x100004F0);
14
15/// RAM image signature, used for storing the image signature in RAM.
16pub const RAM_IMG_SIGN: AddressRange = AddressRange::new(0x100004F0, 0x10000500);
17
18/// Internal RAM for program data and text (Data and Text are loaded into DTCM RAM).
19pub const DTCM_RAM: AddressRange = AddressRange::new(0x10000500, 0x1003FA00);
20
21/// Extension RAM for heap, used as dynamic memory.
22pub const EXTENSION_RAM: AddressRange = AddressRange::new(0x10040000, 0x10060000);
23
24/// External PSRAM for storing text, read-only data (RODATA), and data sections.
25pub const PSRAM: AddressRange = AddressRange::new(0x60000000, 0x60400000);
26
27/// XIP Chiper section, where TEXT and RODATA sections **can** be encrypted.
28///
29/// **Note**: There's some reserved data at the start of each XIP Flash section (0x140)
30/// bytes. We don't include them here.
31pub const XIP_FLASH_C: AddressRange = AddressRange::new(0x9B000140, 0x9B800000);
32
33/// XIP Plaintext section, where RODATA is not encrypted.
34///
35/// **Note**: There's some reserved data at the start of each XIP Flash section (0x140)
36/// bytes. We don't include them here.
37pub const XIP_FLASH_P: AddressRange = AddressRange::new(0x9B800140, 0x9BFF0000);
38
39impl AddressRange {
40 /// Creates a new `AddressRange` instance with a given start and end address.
41 ///
42 /// # Parameters
43 /// - `start`: The starting address of the range (inclusive).
44 /// - `end`: The ending address of the range (exclusive).
45 ///
46 /// # Returns
47 /// Returns a new `AddressRange` representing the memory range between `start` and `end`.
48 pub const fn new(start: u64, end: u64) -> Self {
49 AddressRange(start, end)
50 }
51
52 /// Returns the length of the address range, calculated as the difference between the end and start addresses.
53 ///
54 /// # Returns
55 /// Returns the length of the range as a `u64`.
56 pub const fn len(&self) -> u64 {
57 self.1 - self.0
58 }
59
60 /// Returns the start address of the range.
61 ///
62 /// # Returns
63 /// The start address of the range as a `u64`.
64 pub const fn start(&self) -> u64 {
65 self.0
66 }
67
68 /// Returns the end address of the range.
69 ///
70 /// # Returns
71 /// The end address of the range as a `u64`.
72 pub const fn end(&self) -> u64 {
73 self.1
74 }
75
76 /// Checks if the provided address falls within the range (inclusive of the start, exclusive of the end).
77 ///
78 /// # Parameters
79 /// - `addr`: The address to check.
80 ///
81 /// # Returns
82 /// Returns `true` if the address is within the range, `false` otherwise.
83 #[inline]
84 pub fn contains(&self, addr: u64) -> bool {
85 self.0 <= addr && addr < self.1
86 }
87}