First of all, IDA kernel can perform an instruction emulation step in any order (usually consecutive, that's why sometimes you are getting the results that you expect) in accordance with their SDK documentation:
The second step, the emulation, is called for each instruction.
This step must make necessary changes to the database, plan analysis
of subsequent instructions, track register values, memory contents,
etc. Please keep in mind that the kernel may call the emulation step
for any address in the program - there is no ordering of addresses.
Usually, the emulation is called for consecutive addresses but this
is not guaranteed.
Overall, I see a number of issues with your code, that prevent it from operating correctly. I won't be digging deep in each one of them, just provide a quick overview and some hints:
- You are trying to store the data about the flags in your own global variables. This is wrong, since IDA is completely unaware of it. Therefore, you should utilize IDAs structures for that.
For example, the DD flag that you are talking about affects just the size of the operands, utilized in the specific instruction. Therefore, this information should be stored in the
insn_t object. The closest example would be arc processor module (it is written in C, but it is really easy to understand) from the official IDA SDK, specifically, this part:
// fix operand size for byte or word loads/stores
inline void fix_ldst(insn_t &insn)
if ( insn.itype == ARC_ld || insn.itype == ARC_st )
switch ( insn.auxpref & aux_zmask )
insn.Op2.dtype = dt_byte;
insn.Op2.dtype = dt_word;
The information about the flags is stored in
insn.auxpref in this case. You can work your way from there, looking further into the implementation of flag set/clear routines in the same module.
- You've defined dozens and dozens of the same instructions in
INSN_DEFS. Even after processing in
init_instructions you would end up with duplicate entries. Take a look, for example, on
add instruction. The only difference is actually operands and their sizes. You should've defined just one add instruction with 2 arbitrary operands, for example, like that:
All the further processing (number of operands, their values, DD flag, etc.) should be performed in
So, you should introduce quite a lot of code changes in order for this processor module to become operational.