A simple way to determine the current processor mode on ARMv7-A

On an ARMv7-A processor, I'm looking for a simple way to determine the current processor mode (User, Supervisor, IRQ, etc.) from any mode. This will allow me to dynamically decide whether to perform certain actions, for example, make a call to a supervisor or perform an action directly.

At first glance, this seemed simple. CPSRcontains mode bits ( M) that determine the processor mode.

Section B1.3.3 (Program Status Registers), on page 1150 of the Cb revision of the ARMv7-A Architecture Reference Guide, states:

This field can only be written to PL1 or higher. Its value can be read in any mode, but ARM refuses software running on PL0, using any of its values ​​or trying to change it.

Thus, the use of bits CPSR.Mis deprecated in user mode, but should work.

However, going to the actual reading of CPSR with MRS(this is the only way I know). Section B9.3.8 (MRS) on page 1988 of ARM states:

MRS, which runs in user mode and accesses the CPSR, returns UNKNOWN for the CPSR. {E, A, I, F, M}.

, , . CPSR - , ?

, , undefined , , .

+4
1

. . .

mp3

0

Source: https://habr.com/ru/post/1531845/


All Articles