riscemu.MMU module¶
RiscEmu (c) 2021 Anton Lydike
SPDX-License-Identifier: MIT
-
class
riscemu.MMU.
MMU
(conf: riscemu.Config.RunConfig)¶ Bases:
object
The MemoryManagementUnit (handles loading binaries, and reading/writing data)
-
max_size
= 4294967295¶ The maximum size of the memory in bytes
-
max_alloc_size
= 536870912¶ No single allocation can be bigger than 64 MB
-
last_bin
: Optional[riscemu.Executable.LoadedExecutable] = None¶ The last loaded executable (the next executable is inserted directly after this one)
-
__init__
(conf: riscemu.Config.RunConfig)¶ Create a new MMU, respeccting the active RunConfiguration
- Parameters
conf – The config to respect
-
sections
: List[riscemu.Executable.LoadedMemorySection]¶ A list of all loaded memory sections
-
binaries
: List[riscemu.Executable.LoadedExecutable]¶ A list of all loaded executables
-
global_symbols
: Dict[str, int]¶ The global symbol table
-
load_bin
(exe: riscemu.Executable.Executable) → riscemu.Executable.LoadedExecutable¶ Load an executable into memory
- Parameters
exe – the executable to load
- Returns
A LoadedExecutable
- Raises
OutOfMemoryException – When all memory is used
-
allocate_section
(name: str, req_size: int, flag: riscemu.Executable.MemoryFlags)¶ Used to allocate a memory region (data only). Use load_bin if you want to load a binary, this is used for stack and maybe malloc in the future.
- Parameters
name – Name of the section to allocate
req_size – The requested size
flag – The flags protecting this memory section
- Returns
The LoadedMemorySection
-
get_sec_containing
(addr: int) → Optional[riscemu.Executable.LoadedMemorySection]¶ Returns the section that contains the address addr
- Parameters
addr – the Address to look for
- Returns
The LoadedMemorySection or None
-
get_bin_containing
(addr: int) → Optional[riscemu.Executable.LoadedExecutable]¶
-
read_ins
(addr: int) → riscemu.Executable.LoadedInstruction¶ Read a single instruction located at addr
- Parameters
addr – The location
- Returns
The Instruction
-
read
(addr: int, size: int) → bytearray¶ Read size bytes of memory at addr
- Parameters
addr – The addres at which to start reading
size – The number of bytes to read
- Returns
The bytearray at addr
-
write
(addr: int, size: int, data)¶ Write bytes into memory
- Parameters
addr – The address at which to write
size – The number of bytes to write
data – The bytearray to write (only first size bytes are written)
-
dump
(addr, *args, **kwargs)¶ Dumpy the memory contents
- Parameters
addr – The address at which to dump
args – args for the dump function of the loaded memory section
kwargs – kwargs for the dump function of the loaded memory section
-
symbol
(symb: str)¶ Look up the symbol symb in all local symbol tables (and the global one)
- Parameters
symb – The symbol name to look up
-