Hi guys! i need your help to understand what this arm instruction really does:

"0x00010000: sub PC, PC, #1"; (we are in "Arm" mode)

Now, reading many posts, seems that instruction forces the cpu to enter in thumb mode but ... why? I know that, in Arm mode, PC is word aligned, so PC[1:0] == 0; when this instruction is executed the PC is 0x010007 ( PC = PC + 8 - 1 , this is the effect of pipeline right?). But what happen now? A "prefech abort exception" is raised ? And, above all, when the T bit is set?

The lowest bit of PC tells the CPU which mode to use to decode instructions.

Dosn`t that apply only for earliest APM cores, where T flag was directly located in lowest pc bit, but not in flags?

sub pc,pc #1 - affect only ARM cpus where T flag is located at lowest pc bit, and flags not exist as separate entity(register).
From ARM versions where T moved to flags: instruction version without postfix "s" dosn`t affect flags.

Even more from ARMv6:
instruction variant "sub pc,reg #imm" - not exist anymore, only "subs pc,reg #imm" stayed.
instuction "sub pc, reg #imm" - In linux it is very slow form of switching to thumb mode via handling of exception generated by deprecated instruction. In other OSes it can be not handled at all.
Am I right?

_________________I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.

Dosn`t that apply only for earliest APM cores, where T flag was directly located in lowest pc bit, but not in flags?

sub pc,pc #1 - affect only ARM cpus where T flag is located at lowest pc bit, and flags not exist as separate entity(register).
From ARM versions where T moved to flags: instruction version without postfix "s" dosn`t affect flags.

The implementation could be anything. It doesn't matter to the app or the OS how the CPU implements thumb/arm mode, the instructions will still work fine.

ProMiNick wrote:

Even more from ARMv6:
instruction variant "sub pc,reg #imm" - not exist anymore, only "subs pc,reg #imm" stayed.
instuction "sub pc, reg #imm" - In linux it is very slow form of switching to thumb mode via handling of exception generated by deprecated instruction. In other OSes it can be not handled at all.
Am I right?

The switching is not handled by the OS from an exception. It is all handled by 100% the CPU. The OS won't know what mode the app is running until the next interrupt. The app could change arm/thumb mode many times and the OS would never know or care.

So I'd say that the "slowness" is not important. But as always measure it in the app if you think it is some sort of performance bottleneck. And of course different CPU implementations will have different timings so test it across all versions you intend to support.

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum