0
votes

There was no enough information regarding the svc on the internet . i learned how SVC handler is working but the thing is i am not getting why it is stacking the register R0,R1,R2,R3 and R12 onto the stack. unless it has a purpose it wont store so what is the information ,which is that important to the processor ,present in these registers.

and any one pls suggest how to learn ARM Cortex M3? How to start learning so that there wont be any confusions in the basic things like the one above. thanks you in advance

1

1 Answers

0
votes

This is because each time you call a function, the ABI describes that:

  • Registers r0-r3 can contain the parameters, and can be used as scratch register. This means that there is no need for the function to save them (They will be modified)
  • Other registers need to be saved by the function, ie they need to be restored to the previous value when the function returns.

This is similar for r12.

So if SVC calls a C function handler, registers r0-r3 will be corrupted by the C function while other registers are maintained. In this case, the hardware does the stacking automatically, so that we have the guaranty (If the C function is correct) that all registers have the same value than before calling the SVC.

Note that for SVC, it would have been acceptable to know that these registers are corrupted (Because we know when we call the SVC instruction). But other exceptions (Like interrupts) have the same behaviour, and for these ones this is essential as we do not know when they happen.

Concerning a book, I know this book so I can advise it:

The Definitive Guide to the ARM Cortex-M3, Second Edition 2nd Edition by Joseph Yiu