see the http://github.com/dwelch67/yagbat qemu directory.
Here are some examples of calling a hand or finger from a hand
start_vector: mov sp,
If you look at the instruction set instructions, you will see that you need to use BX or BLX to switch between hand and thumb states. BLX is not as widely supported as BX.
In terms of definition, program counter, pc is two forward instructions during command execution. for the thumb, which is 4 bytes, for the hand is 8 bytes. In any case, two instructions. To simulate bl that cannot be used to change state, you need to load the link registry with the return address and use bx to switch to the function change state depending on the lsbit address. so
mov lr,pc bx r1 here:
mov lr, pc above loads the address here: which is our return address, bx r1 in a state-independent way calls the function. lsbit addresses lr indicates return mode and you need to always use bx to return
pre_thumb: ldr pc,lr thumb_capable: bx lr
The compiler allocates the bl command for function calls, the linker fills the rest later, if it is too far from the target, then it needs a trampoline function, which the linker adds itself. Similarly, if you need to change modes, bl calls the trampoline function, which does this. I modeled that in one of the above, to emulate this, you can see that it is a little wasteful, I hope that my explanation of the compiler allocating space for bl makes it clearer, more wasteful to always plan for a mode change and should insert nops for most function calls in code.
The code also includes a thumb call in assembler:
.thumb .thumb_func .globl XPUT32 XPUT32: push {lr} ;@ call an arm function from thumb asm ldr r2,=PUT32 mov lr,pc bx r2 pop {r2} bx r2
basically the same thing, except that you can’t insert into lr in thumb mode, you can jump out to the computer, but I don’t think that these are switching modes, so you cannot use it, you need a spare register again . You, of course, need to know the calling conventions in order to know which registers you can use, or you can wrap another set of taps and tabs to save everything except lr
push {r2,lr} ;@ call an arm function from thumb asm ldr r2,=PUT32 mov lr,pc bx r2 pop {r2} mov lr,r2 pop {r2} bx lr
A heavy finger or hand to arm you, just use bl if you can. ldr pc, address if you can not.