tum-ei-eda / etiss

Extendable Translating Instruction Set Simulator
https://tum-ei-eda.github.io/etiss/
Other
29 stars 36 forks source link

Overlapping InstructionDefinitions do not behave as expected #59

Closed wysiwyng closed 3 years ago

wysiwyng commented 3 years ago

Consider the following InstructionDefinitions, with IT_T1 being the generic InstructionDefinition and the rest being specialized cases (instruction behavior removed, not needed for this discussion):

// IT_T1; encoding: b1011 | b1111 | firstcond[3:0] | mask[3:0]
static InstructionDefinition it_t1_mask_firstcond (
    ISA16_ARMv7M,
    "it_t1",
    (uint16_t) 0xbf00,
    (uint16_t) 0xff00,
    [] (BitArray & ba,etiss::CodeSet & cs,InstructionContext & ic) { return true; },
    0,
    nullptr
);

// NOP_T1; encoding: b1011 | b1111 | b0000 | b0000
static InstructionDefinition nop_t1_ (
    ISA16_ARMv7M,
    "nop_t1",
    (uint16_t) 0xbf00,
    (uint16_t) 0xffff,
    [] (BitArray & ba,etiss::CodeSet & cs,InstructionContext & ic) { return true; },
    0,
    nullptr
);

// YIELD_T1; encoding: b1011 | b1111 | b0001 | b0000
static InstructionDefinition yield_t1_ (
    ISA16_ARMv7M,
    "yield_t1",
    (uint16_t) 0xbf10,
    (uint16_t) 0xffff,
    [] (BitArray & ba,etiss::CodeSet & cs,InstructionContext & ic) { return true; },
    0,
    nullptr
);

// WFE_T1; encoding: b1011 | b1111 | b0010 | b0000
static InstructionDefinition wfe_t1_ (
    ISA16_ARMv7M,
    "wfe_t1",
    (uint16_t) 0xbf20,
    (uint16_t) 0xffff,
    [] (BitArray & ba,etiss::CodeSet & cs,InstructionContext & ic) { return true; },
    0,
    nullptr
);

// WFI_T1; encoding: b1011 | b1111 | b0011 | b0000
static InstructionDefinition wfi_t1_ (
    ISA16_ARMv7M,
    "wfi_t1",
    (uint16_t) 0xbf30,
    (uint16_t) 0xffff,
    [] (BitArray & ba,etiss::CodeSet & cs,InstructionContext & ic) { return true; },
    0,
    nullptr
);

// SEV_T1; encoding: b1011 | b1111 | b0100 | b0000
static InstructionDefinition sev_t1_ (
    ISA16_ARMv7M,
    "sev_t1",
    (uint16_t) 0xbf40,
    (uint16_t) 0xffff,
    [] (BitArray & ba,etiss::CodeSet & cs,InstructionContext & ic) { return true; },
    0,
    nullptr
);

These instructions compile fine, but during initialization ETISS terminates with the following fatal error: "OverlappedNode delegate must not be a plain Node", in file Instruction.cpp. Using all specialized instructions without IT_T1 works fine, as well as up to two specialized instructions together with IT_T1. Three or more specialized instructions cause the above error.

Background why this is needed: ARMv7M has certain instructions which are "specialized" cases of "generic" instructions, where e.g. if a specific register is used certain behavior will be different. Additionally, the reference manual calls these instructions differently. Some of these special cases can be encoded with conditionals inside one InstructionDefinition, others like the example above get very cumbersome if encoded that way.

wysiwyng commented 3 years ago

closed by 714d597df92c4c1277c3cdb32e0f664fd30e273b