ARM/Thumb interworking in assembly -
i'm building windows phone project bits of in assembly. assembly file in arm mode (code32
), , tries jump c function know compiled thumb. code goes this:
ldr r12, [pfunc] mov pc, r12 pfunc dcd my_c_function
here's weird thing. value @ pfunc
in snippet pointer @ function thunk plus one. is, 0th bit set, if jump target meant thumb , jump instruction meant bx. thunk arm! thunk loads address of function body plus 1 , executes bx it, switching modes.
trying bx address crash, because switch modes , trying execute arm code in thumb mode not idea. trying jump address (as current code does) crash too, because pc end unaligned.
i could, in theory, manually clean 0th bit , jump, there's gotta error thinking. thunk generated c compiler - right? c compiler knows thunk arm code. address under pfunc generated linker, since it's cross-module call. low bit placed there linker; why doesn't linker know thunks arm?
any explanation, please?
i don't have wp8 device now, can't try in real hardware. staring hard @ generated code debugging technique have :(
edit: if thunks not arm, thumb-2? thumb-2 supports 32-bit command iirc. encoding same in arm mode? how thumb-2 decode commands, anyway?
the details want specified in section "a2.3.2 pseudocode details of operations on arm core registers" of "arm architecture reference manual, armv7-a , armv7-r edition". here relevant pseudocode (from above manual) writes pc register:
bxwritepc(bits(32) address) if currentinstrset() == instrset_thumbee if address<0> == '1' branchto(address<31:1>:'0'); // remaining in thumbee state else unpredictable; else if address<0> == '1' selectinstrset(instrset_thumb); branchto(address<31:1>:'0'); elsif address<1> == '0' selectinstrset(instrset_arm); branchto(address); else // address<1:0> == '10' unpredictable;
if low bit of address (bit 0) set, processor clear bit, switch thumb mode, , perform jump new address.
this behaviour correct armv7 , later (i.e. applies windows phone devices, not android/ios devices).
Comments
Post a Comment