Skip to content

Commit e62d687

Browse files
committed
Smaller fixes and add variant to decode
1 parent 78f7c0d commit e62d687

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

riscvmodel/code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, word):
1111
def __str__(self):
1212
return "Invalid instruction word: {:08x}".format(self.word)
1313

14-
def decode(word: int):
14+
def decode(word: int, variant: Variant=RV32I):
1515
if word & 0x3 != 3:
1616
# compact
1717
for icls in get_insns(cls=InstructionCType):
@@ -21,7 +21,7 @@ def decode(word: int):
2121
return i
2222
raise MachineDecodeError(word)
2323
opcode = word & 0x7F
24-
for icls in get_insns():
24+
for icls in get_insns(variant=variant):
2525
if icls.field_opcode.value == opcode and icls.match(word):
2626
i = icls()
2727
i.decode(word)

riscvmodel/insn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def execute(self, model: Model):
3030
class InstructionJAL(InstructionJType):
3131
def execute(self, model: Model):
3232
model.state.intreg[self.rd] = model.state.pc + 4
33-
model.state.pc = self.imm
33+
model.state.pc += self.imm
3434

3535

3636
@isa("jalr", RV32I, opcode=0b1100111, funct3=0b000)

riscvmodel/isa.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,6 @@ def __str__(self):
265265
return "{} x{}, x{}, x{}".format(self.mnemonic, self.rd, self.rs1,
266266
self.rs2)
267267

268-
def __eq__(self, other):
269-
if not super().__eq__(other):
270-
return False
271-
return self.rs1 == other.rs1 and self.rs2 == other.rs2 and self.rd == other.rd
272-
273268

274269
class InstructionIType(InstructionFunct3Type, metaclass=ABCMeta):
275270
"""
@@ -392,12 +387,6 @@ def __str__(self):
392387
return "{} x{}, x{}, 0x{:02x}".format(self.mnemonic, self.rd, self.rs1,
393388
self.shamt)
394389

395-
def __eq__(self, other):
396-
if not super().__eq__(other):
397-
return False
398-
return (self.rd == other.rd and self.rs1 == other.rs1
399-
and self.shamt == other.shamt)
400-
401390

402391
class InstructionSType(InstructionFunct3Type, metaclass=ABCMeta):
403392
"""
@@ -539,13 +528,21 @@ class InstructionJType(Instruction, metaclass=ABCMeta):
539528
:param imm: Immediate for the jump (21-bit, signed, 16-bit aligned)
540529
:type imm: int
541530
"""
531+
532+
field_rd = Field(name="rd", base=7, size=5, description="")
533+
field_imm = Field(name="imm", base=[21,20,12,31], size=[10,1,8,1], description="")
534+
542535
def __init__(self, rd: int = None, imm: int = None):
543536
super(InstructionJType, self).__init__()
544537
self.rd = rd # pylint: disable=invalid-name
545538
self.imm = Immediate(bits=21, signed=True, lsb0=True)
546539
if imm is not None:
547540
self.imm.set(imm)
548541

542+
def ops_from_list(self, ops):
543+
self.rd = int(ops[0][1:])
544+
self.imm.set(int(ops[1]))
545+
549546
def randomize(self, variant: Variant):
550547
self.rd = randrange(0, variant.xlen)
551548
self.imm.randomize()

0 commit comments

Comments
 (0)