riscemu.MMU module

RiscEmu (c) 2021 Anton Lydike

SPDX-License-Identifier: MIT

class riscemu.MMU.MMU

Bases: object

The MemoryManagementUnit. This provides a unified interface for reading/writing data from/to memory.

It also provides various translations for addresses.

max_size = 4294967295

The maximum size of the memory in bytes

max_alloc_size = 536870912

No single allocation can be bigger than 64 MB

__init__()

Create a new MMU

programs: List[Program]

A list of all loaded programs

sections: List[MemorySection]

A list of all loaded memory sections

global_symbols: Dict[str, int]

The global symbol table

get_sec_containing(addr: int) Optional[MemorySection]

Returns the section that contains the address addr

Parameters:

addr – the Address to look for

Returns:

The LoadedMemorySection or None

get_program_at_addr(addr: int) Optional[Program]
read_ins(addr: int) Instruction

Read a single instruction located at addr

Parameters:

addr – The location

Returns:

The Instruction

read(addr: Union[int, Int32], 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: bytearray)

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

label(symb: str)

Look up the symbol symb in all local symbol tables (and the global one)

Parameters:

symb – The symbol name to look up

read_int(addr: int) Int32
read_float(addr: int) Float32
translate_address(address: int) str
has_continous_free_region(start: int, end: int) bool
load_program(program: Program, align_to: int = 4)
load_section(sec: MemorySection, fixed_position: bool = False) bool
get_guaranteed_free_address() int
context_for(addr: int) InstructionContext
find_entrypoint() Optional[int]