riscemu.instructions.instruction_set module
RiscEmu (c) 2021 Anton Lydike
SPDX-License-Identifier: MIT
- class riscemu.instructions.instruction_set.InstructionSet(cpu: CPU)
Bases:
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: 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[[Instruction], 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: Instruction) Tuple[str, Int32]
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: Instruction, signed=True) Tuple[str, Int32, Int32]
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: Instruction, signed=True) Tuple[str, Int32, Int32]
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: Instruction, signed=True) Tuple[Int32, Int32, Int32]
Assumes the command is in <name> rs1, rs2, imm format Returns the values in rs1, rs2 and the immediate imm
- get_reg_content(ins: Instruction, ind: int) Int32
get the register name from ins and then return the register contents
- property pc
shorthand for self.cpu.pc
- property mmu
- property regs