1

Using compiler option, is it possible to restrict a routine from using certain set of registers?

For example: Restrict a routine to use only R0-R8;

Purpose: If some compiler option available, then I could ensure certain routines (like Interrupt Service Routines) to use only limited register set, and thus do limited Context Save & Restore.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Raju Udava
  • 73
  • 3
  • Here is a similar question on [registers and threads](http://stackoverflow.com/questions/16718484/is-it-possible-to-share-a-register-between-threads). As it relates to the ARM, the IRQ already has banked `sp` and `lr`. The [FIQ](http://stackoverflow.com/questions/973933/what-is-the-difference-between-fiq-and-irq-interrupt-system) has even more banked registers and it is probably your solution. The use of `-ffixed-reg` can also be used. As per the first link, when you reserve **general purpose** registers like this you handicap the compiler and force it to use memory in most functions. – artless noise Oct 30 '14 at 15:38

1 Answers1

3

When this was last discussed, the consensus was that it is not possible on a function-by-function basis.

There are ways to restrict register use throughout an entire compilation, so if you put your interrupt routines in a separate compilation unit, you can use the gcc switch -ffixed-reg. I believe it would be used like -ffixed-R0 if you wanted the compiler to not generate code using R0.

Community
  • 1
  • 1
hcs
  • 1,514
  • 9
  • 14