0
votes

I recently read that software breakpoints for Linux on ARM are implemented using UND instruction in ARM mode and the BKPT instruction in Thumb mode. Why are there 2 separate instructions used to raise software interrupts?

1
arm and thumb are two different instruction sets.old_timer
@dwelch I understand they are two different instruction sets. However, why is there a need to have 2 separate breakpoint instructions? ARM does not define what the breakpoint instruction is, Linux does(as opposed to how you have it for x86/x64).user277465
Doesn't ARM have a bkpt instruction starting armv5? Edit: never mind, if it's Linux, it probably needs to support all ARM versions.tangrs
Also there needs to be two separate breakpoint instructions probably because they're two different instruction sets (i.e. one breakpoint instruction for each instruction set). The fact that other instructions just happen to have the same name between instruction sets is probably just for convenience I believe.tangrs
if you are asking about the mnemonic for the human, that is all at the whim of the assembler (The program that reads the ascii and makes machine code) which varies from one assembler to another, just like push was a thumb only instruction and arm didnt have one but then the assemblers started tolerating the mnemonic push for arm instructions. anyway if it is about the ascii/mnemonic commands then that is simply a matter of opinion of the author(s) of the assembler, unless that person or those persons are here to share their whims, not sure you will get an answer.old_timer

1 Answers

0
votes

Thumb compatible code:

0000e150 <pthread_mutexattr_setpshared>:
    e150:   b573        push    {r0, r1, r4, r5, r6, lr}
    e152:   4605        mov r5, r0
    e154:   460c        mov r4, r1
    e156:   4616        mov r6, r2
    e158:   f7fd fa70   bl  b63c <pthread_mutexattr-0xba>
    e15c:   4629        mov r1, r5

Pure arm:

0000d564 <pthread_mutex_init>:
    d564:   e2503000    subs    r3, r0, #0
    d568:   03a00016    moveq   r0, #22
    d56c:   012fff1e    bxeq    lr

arm bkpt 0xe7f001f0

thumb bkpt 0xde01

If try to use always arm bkpt and rewrite first instruction in function: pthread_mutex_init all will be fine but if rewrite first instruction in pthread_mutexattr_setpshared second instruction will be rewrote too.

If always try to use thumb bkpt and rewrite first instruction in pthread_mutex_init resulted instruction will be invalid.