Search code examples
armprocessormode

ARM modes and why are there so many?


I'm currently reading/learning about ARM architecture ... and I was wondering why there are so many modes (FIQ, User, System, Supervisor, IRQ, ...).

My question is why do we need so many modes? Wouldn't just User and System be enough?

Thanks in advance.


Solution

  • It's just an architectural decision. The big advantage of the multiple modes is that they have some banked registers. Those extra registers allow you to write much less complicated exception routines.

    If you were to pick only two, just USR and SYS are probably as good a choice as any, but what would happen when you took an exception? The normal ARM model is to go to an exception mode, set the banked link register for that exception mode to point to the instruction you want to return to after you resolve the exception, save the processor state in the exception mode's SPSR register, and then jump to the exception vector. USR and SYS share all their registers - using this model, you'd blow away your function return address (in LR) every time you took an interrupt!

    The FIQ mode in particular has even more banked registers than the other exception modes. Those extra registers are in keeping with the "F" part of FIQ - it stands for "Fast". Not having to save and restore more processor context in software will speed up your interrupt handler.