def test_InstFormat_get_value(): test_format = InstFormat(('field1', Unsigned(2)), ('field2', Unsigned(3)), ('field3', Unsigned(4))) value1 = test_format.get_value(field3=4) assert value1 == 4 value2 = test_format.get_value(field2=7) assert value2 == 0x70
def test_InstFormat_get_mask(): test_format = InstFormat(('field1', Unsigned(2)), ('field2', Unsigned(3)), ('field3', Unsigned(4))) mask1 = test_format.get_mask(field3=0) assert mask1 == 0xf mask2 = test_format.get_mask(field1=2) assert mask2 == 0x180
def test_InstFormat_get_value(): test_format = InstFormat( ('field1', Unsigned(2)), ('field2', Unsigned(3)), ('field3', Unsigned(4)) ) value1 = test_format.get_value(field3=4) assert value1 == 4 value2 = test_format.get_value(field2=7) assert value2 == 0x70
def test_InstFormat_get_mask(): test_format = InstFormat( ('field1', Unsigned(2)), ('field2', Unsigned(3)), ('field3', Unsigned(4)) ) mask1 = test_format.get_mask(field3=0) assert mask1 == 0xf mask2 = test_format.get_mask(field1=2) assert mask2 == 0x180
class Mips(Processor): main_memory = Memory(65536, Unsigned(32)) ir = InstructionPointer(Unsigned(32), main_memory) r = RegisterBank(32, Unsigned(32)) hi = Register(Unsigned(32)) lo = Register(Unsigned(32)) I_Type = InstFormat(('op', Unsigned(6)), ('rs', Unsigned(5)), ('rt', Unsigned(5)), ('immediate', Unsigned(16))) R_Type = InstFormat(('op', Unsigned(6)), ('rs', Unsigned(5)), ('rt', Unsigned(5)), ('rd', Unsigned(5)), ('sa', Unsigned(5)), ('funct', Unsigned(6))) @instruction(R_Type, ir, op=0, rs=0, rt=0, rd=0, sa=0, funct=0x0) @mnemonic("nop") def nop(): pass @instruction(R_Type, ir, op=0, sa=0, funct=0) @mnemonic("move") def move(): pass @instruction(R_Type, ir, op=0, sa=0, funct=0x20) @mnemonic("add {rd}, {rs}, {rt}") #or: "add", "rd":Register, "rs":Register ?? def add(): pass @instruction(R_Type, ir, op=0, sa=0, funct=0x24) @mnemonic("and {rd}, {rs}, {rt}") def and_instr(): pass @instruction(I_Type, ir, op=9) @mnemonic("addiu {rt}, {rs}, {imm}") def addiu(self, **kwargs): pass
def test_InstFormat(): test_format = InstFormat(('field1', Unsigned(2)), ('field2', Unsigned(3)), ('field3', Unsigned(4))) assert test_format.size == 9 assert test_format.fields[0].mask == 0x180 assert test_format.fields[0].position == 7 assert test_format.fields[0].name == "field1" assert test_format.fields[1].mask == 0x70 assert test_format.fields[1].position == 4 assert test_format.fields[1].name == "field2" assert test_format.fields[2].mask == 0xf assert test_format.fields[2].position == 0 assert test_format.fields[2].name == "field3"