riscemu.instructions.InstructionSet module

RiscEmu (c) 2021 Anton Lydike

SPDX-License-Identifier: MIT

class riscemu.instructions.InstructionSet.InstructionSet(cpu: riscemu.CPU.CPU)

Bases: abc.ABC

Represents a collection of instructions

Each instruction set has to inherit from this class. Each instruction should be it’s own method:

instruction_<name>(self, ins: LoadedInstruction)

instructions containing a dot ‘.’ should replace it with an underscore.

__init__(cpu: riscemu.CPU.CPU)

Create a new instance of the Instruction set. This requires access to a CPU, and grabs vertain things from it such as access to the MMU and registers.

load()Dict[str, Callable[[riscemu.Executable.LoadedInstruction], None]]

This is called by the CPU once it instantiates this instruction set

It returns a dictionary of all instructions in this instruction set, pointing to the correct handler for it

get_instructions()

Returns a list of all valid instruction names included in this instruction set

converts underscores in names to dots

parse_mem_ins(ins: riscemu.Executable.LoadedInstruction)Tuple[str, int]

parses both rd, rs, imm and rd, imm(rs) argument format and returns (rd, imm+rs1) (so a register and address tuple for memory instructions)

parse_rd_rs_rs(ins: riscemu.Executable.LoadedInstruction, signed=True)Tuple[str, int, int]

Assumes the command is in <name> rd, rs1, rs2 format Returns the name of rd, and the values in rs1 and rs2

parse_rd_rs_imm(ins: riscemu.Executable.LoadedInstruction, signed=True)Tuple[str, int, int]

Assumes the command is in <name> rd, rs, imm format Returns the name of rd, the value in rs and the immediate imm

parse_rs_rs_imm(ins: riscemu.Executable.LoadedInstruction, signed=True)Tuple[int, int, int]

Assumes the command is in <name> rs1, rs2, imm format Returns the values in rs1, rs2 and the immediate imm

get_reg_content(ins: riscemu.Executable.LoadedInstruction, ind: int)int

get the register name from ins and then return the register contents

property pc

shorthand for self.cpu.pc