This fixes bugs in the handling of v850e bit twiddle instructions that take the
bit position operand as a register, e.g. "set1 reg2, [reg1]". The operand
is a bit position from 0-7 which can be in any register. The simulator is
masking the operand with 7 and then reading the register. This is wrong.
We need to read the register first, and then mask with 7. This patch fixes
the problem.
Gcc doesn't generate these instructions unfortunately, so I need an asm to
show the problem. Gcc also unfortunately doesn't have any print operand code
for the address I need here, so I need a badly written asm (grumble), but
anways, here is a testcase.
char c = 0;
int
sub (int bp)
{
char *ptr = &c;
asm volatile ("set1 %1,[%0]" : : "r" (ptr), "r" (bp));
return 0;
}
int
main()
{
sub (5);
if (c != 0x20)
abort ();
return 0;
}
If I compile this with -mv850e, and run it with an unpatched simulator it
hits the abort. With the patched simulator, it runs correctly returning zero.
I ran the gdb testsuite to test this, but it was pretty pointless since the
instruction is not generated by gcc, and it passed with no regressions as
expected.
The sim/testsuite directory can be used to add SIM specific tests (it
contains two different styles so take care :-). For tests like the
above, people are often reduced to using .word ....