You are not logged in.

Read the FAQ and Knowledge Base before posting.
WiFi not emulated and not supported!!
We won't make a 3DS/2DS emulator.

#1 2008-02-27 22:43:18

Registered: 2008-02-27
Posts: 1

ARM emulation issues


Noticed the following two emulation-related things while mucking around with GDB; either I'm confused, or there's a bug in the ARM emulation code. Using desmume from the CVS, checked-out 2008-02-27.

1. 'LDR' (and friends?) in ARM mode does not handle mis-aligned reads correctly.

Like says, giving LDR a non-word-aligned address should forcibly align it, and then rotate the result. Thumb mode instructions do this, but at least many ARM mode LDR ops (like OP_LDR_P_IMM_OFF, for instance) read from the non-aligned address, and then rotate, giving rather unexpected results.

(Actually if I believe this ARM Architecture Reference Manual, the align-and-rotate behaviour is only defined for ARM instructions; Thumb LDR with a mis-aligned address is documented to give unpredictable results.)

2. 'LDMIA' when the base address register is also loaded to.

Executing something like "LDMIA r0!, {r0, r1, r2, r3}" should, again according to the Reference Manual, leave the loaded value in r0, not the written-back incremented address. OP_LDMIA_THUMB writes back the incremented address always.

(Rationale: Reference Manual, page A7-45: "If the base register <Rn> is specified in <registers>, the final value of <Rn> is the loaded value, not the written value." Also, gas gives the following for that opcode: "Warning: this instruction will not write back the base register".)


#2 2008-02-27 23:46:04

Registered: 2007-03-17
Posts: 897

Re: ARM emulation issues

Afaik, both are checked and give the same results on the DS than on desmume. You can compare it with armwrestler, which, among other things, tests those CPU opcodes. If you are still unsure if the results are correct, just code a simple test case, and compare with the DS results.

EDIT: Forgot to say that armwrestler checks alignment reads, so that's meant to work 100% exactly as the DS. About the OP_LDMIA_THUMB, yep, it's wrong, I know. I fixed that one long ago, just never cared to commit it to the public CVS.


Board footer

Powered by FluxBB