riscemu.Executable module

RiscEmu (c) 2021 Anton Lydike

SPDX-License-Identifier: MIT

This file holds Executable and LoadedExecutable classes as well as loading and some linking code.

FIXME: refactor this code into muliple files

class riscemu.Executable.MemoryFlags(read_only: bool, executable: bool)

Bases: object

read_only: bool
executable: bool
__init__(read_only: bool, executable: bool)None

Initialize self. See help(type(self)) for accurate signature.

class riscemu.Executable.MemorySection(name: str, flags: riscemu.Executable.MemoryFlags, size: int = 0, content: List[bytearray] = <factory>)

Bases: object

name: str
flags: riscemu.Executable.MemoryFlags
size: int = 0
content: List[bytearray]
add(data: bytearray)
continuous_content(parent: riscemu.Executable.LoadedExecutable)

converts the content into one continuous bytearray

__init__(name: str, flags: riscemu.Executable.MemoryFlags, size: int = 0, content: List[bytearray] = <factory>)None

Initialize self. See help(type(self)) for accurate signature.

class riscemu.Executable.InstructionMemorySection(name: str, flags: riscemu.Executable.MemoryFlags, size: int = 0, content: List[ForwardRef('RiscVInstructionToken')] = <factory>)

Bases: riscemu.Executable.MemorySection

content: List[RiscVInstructionToken]
add_insn(insn: RiscVInstructionToken)
continuous_content(parent: riscemu.Executable.LoadedExecutable)

converts the content into one continuous bytearray

__init__(name: str, flags: riscemu.Executable.MemoryFlags, size: int = 0, content: List[RiscVInstructionToken] = <factory>)None

Initialize self. See help(type(self)) for accurate signature.

class riscemu.Executable.Executable(run_ptr: Tuple[str, int], sections: Dict[str, riscemu.Executable.MemorySection], symbols: Dict[str, Tuple[str, int]], exported_symbols: List[str], name: str)

Bases: object

run_ptr: Tuple[str, int]
sections: Dict[str, riscemu.Executable.MemorySection]
symbols: Dict[str, Tuple[str, int]]
exported_symbols: List[str]
name: str
__init__(run_ptr: Tuple[str, int], sections: Dict[str, riscemu.Executable.MemorySection], symbols: Dict[str, Tuple[str, int]], exported_symbols: List[str], name: str)None

Initialize self. See help(type(self)) for accurate signature.

class riscemu.Executable.LoadedInstruction(name: str, args: List[str], bin: riscemu.Executable.LoadedExecutable)

Bases: object

An instruction which is loaded into memory. It knows the binary it belongs to to resolve symbols

name: str
args: List[str]
bin: riscemu.Executable.LoadedExecutable
get_imm(num: int)

parse and get immediate argument

get_imm_reg(num: int)

parse and get an argument imm(reg)

get_reg(num: int)

parse and get an register argument

__init__(name: str, args: List[str], bin: riscemu.Executable.LoadedExecutable)None

Initialize self. See help(type(self)) for accurate signature.

class riscemu.Executable.LoadedMemorySection(name: str, base: int, size: int, content: Union[List[riscemu.Executable.LoadedInstruction], bytearray], flags: riscemu.Executable.MemoryFlags, owner: str)

Bases: object

A section which is loaded into memory

name: str
base: int
size: int
content: Union[List[riscemu.Executable.LoadedInstruction], bytearray]
flags: riscemu.Executable.MemoryFlags
owner: str
read(offset: int, size: int)
read_instruction(offset)
write(offset, size, data)
dump(at_addr=None, fmt='hex', max_rows=10, group=4, bytes_per_row=16, all=False)
__init__(name: str, base: int, size: int, content: Union[List[riscemu.Executable.LoadedInstruction], bytearray], flags: riscemu.Executable.MemoryFlags, owner: str)None

Initialize self. See help(type(self)) for accurate signature.

class riscemu.Executable.LoadedExecutable(exe: riscemu.Executable.Executable, base_addr: int, global_symbol_table: Dict[str, int])

Bases: object

This represents an executable which is loaded into memory at address base_addr

This is basicalle the “loader” in normal system environments It initializes the stack and heap

It still holds a symbol table, that is not accessible memory since I don’t want to deal with binary strings in memory etc.

__init__(exe: riscemu.Executable.Executable, base_addr: int, global_symbol_table: Dict[str, int])

Initialize self. See help(type(self)) for accurate signature.

name: str
base_addr: int
sections: List[riscemu.Executable.LoadedMemorySection]
sections_by_name: Dict[str, riscemu.Executable.LoadedMemorySection]
symbols: Dict[str, int]
exported_symbols: Dict[str, int]
global_symbol_table: Dict[str, int]
run_ptr: int
lookup_symbol(name)
has_symb(arg)