Class MemorySectionManager
Defined in File sim_memory.h
Class Documentation
-
class MemorySectionManager
Memory section management.
Manages a memory page range by dividing it in sections, allowing to set access control flags from one section to another. Sections are identified by an index and always cover the whole page range. Section limits are set by set_section_limits() and take an array of N-1 values, where N is the number of sections. For example, with N=3, and 100 pages, limits = { 16; 32 } will configure the sections limits as : Section 0 = [0; 15], Section 1 = [16; 31], Section 2 = [32; 99]
Public Types
Public Functions
-
MemorySectionManager(flash_addr_t page_count, flash_addr_t page_size, unsigned int section_count)
Construct a section manager.
- Parameters:
page_count – number of pages covering the whole memory area
page_size – page size in bytes
section_count – number of sections
-
inline flash_addr_t page_count() const
Getter for the page count. (as given to the constructor)
-
inline flash_addr_t page_size() const
Getter for the page size in bytes. (as given to the constructor)
-
inline unsigned int section_count() const
Getter for the number of sections.
-
inline unsigned int current_section() const
Return the section containing the current address.
-
void set_section_limits(const std::vector<flash_addr_t> &limits)
Set the section limits in page number. Limits must be given as an array and must be organised as : [ L0, L1, …, Ln-2] where Li is the 1st page of section i+1 and n the number of sections. For example, with 3 sections, limits = { 16, 32 } will set Section 0 as range [0;15], Section 1 as [16;31] and Section 2 as [32;end].
-
inline flash_addr_t section_start(unsigned int section) const
Return the section start address.
-
inline flash_addr_t section_end(unsigned int section) const
Return the section end address.
-
inline flash_addr_t section_size(unsigned int section) const
Return the size in bytes of a section.
-
unsigned int page_to_section(flash_addr_t page) const
Return the section index containing the given page number.
-
inline unsigned int address_to_section(flash_addr_t addr) const
Return the section index containing the given memory address.
-
void set_access_flags(unsigned int src, unsigned int dst, uint8_t flags)
Set the access flags from one section to another.
Example: set_access_flags(0, 1, Read) means that code in section 0 can read but cannot write data located in section 1.
- Parameters:
src – : Section source
dst – : Section destination
flags – : OR’ed combination of access flags
-
void set_access_flags(unsigned int section, uint8_t flags)
Set the access flags from one section to itself.
-
inline uint8_t access_flags(unsigned int section_src, unsigned int section_dst) const
Return the access flags currently set containing the given memory address.
- Parameters:
section_src – : Section source
sectiondst – : Section destination
-
inline uint8_t access_flags(unsigned int section) const
Return the access flags currently set from one section to itself.
-
inline bool can_read(flash_addr_t addr) const
Return the read access flag for a given address.
-
inline bool can_write(flash_addr_t addr) const
Return the write access flag for a given address.
-
inline uint8_t address_access_flags(flash_addr_t addr) const
Return the access flags for a given address.
-
void set_fetch_allowed(unsigned int section, bool allowed)
Set the fetch flag for a section.
-
bool fetch_address(flash_addr_t addr)
Change the current address and return the fetch access flag for the containing section.
-
MemorySectionManager(flash_addr_t page_count, flash_addr_t page_size, unsigned int section_count)