gens KMod SH2 weirdness
Posted: Sun Feb 15, 2009 6:26 pm
After I discovered that the assembly rewrite of my 32X gameboy emulator isn't working in Fusion or on a real 32X I decided to try to find out why (I've done all the testing of it so far in gens KMod, since it's the only 32X emulator I know of with any meaningful debugging features).
I still haven't completely fixed my code, but at least I've found a few things that made me wonder how it ever could've worked in gens KMod:
At one place I had a jump-table with 16 LONG addresses, where I would branch to one of those addresses based on bits 12-15 of R0..
I could probably cut that down by one instruction by using a register-indexed mov.l, but anyway.. I'm shifting right by 10 since I want bits 12-15 of the register but I want them multiplied by 4. I had completely forgot to AND out the lowest two bits after the shifts though, which would cause me to get misaligned addresses for the mov.l in some cases. gens KMod seemed to be completely fine with that. Fusion - not so fine
I also realized that I have a lot of mov.l some_label,rn in places where I have no idea if the instruction is aligned on a 4-byte boundary. Again, gens KMod didn't seem to care, but Fusion does.
BTW, not related to gens, but does GNU AS/LD have some flag that gives warnings/errors when you're trying to do a PC-relative mov.l from an place where PC isn't 4-byte aligned? I know it complains when you place data on misaligned addresses, but those are much easier to find yourself.
I still haven't completely fixed my code, but at least I've found a few things that made me wonder how it ever could've worked in gens KMod:
At one place I had a jump-table with 16 LONG addresses, where I would branch to one of those addresses based on bits 12-15 of R0..
Code: Select all
extu.w r0,r2
mov r0,r3
mova write_byte_ftbl,r0
shlr8 r2
shlr2 r2
add r0,r2
mov r3,r0
mov.l @r2,r3
jmp @r3
nop

I also realized that I have a lot of mov.l some_label,rn in places where I have no idea if the instruction is aligned on a 4-byte boundary. Again, gens KMod didn't seem to care, but Fusion does.
BTW, not related to gens, but does GNU AS/LD have some flag that gives warnings/errors when you're trying to do a PC-relative mov.l from an place where PC isn't 4-byte aligned? I know it complains when you place data on misaligned addresses, but those are much easier to find yourself.