This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to know if the processor is in EL0 state on armv8?

Hi Fellows,

I want to determine in code, if the processor is in EL0 mode or not. I read CurrentEL register to do this but if my code is running from EL0, it throws an exception since we can't access CurrentEL from EL0. Is there any alternative and easy way to do determine mode that works even at EL0? Thanks.

Regards,

Mughees

  • There's no straightforward method I know of and I guess this is deliberate as any such facility would have to have virtualization support. Any particular reason you want this, are you wanting to run the same code and do different things at different exception levels for instance? I think you'd need to pass a parameter I'm afraid, alternatives like saving the state in a location or the thread id register sound like more trouble than they're worth.

  • Thanks for the reply. I am trying to port an already existing RTOS to this processor and to keep code consistent I need to do this.
  • If you've got full control of the system then there's various things you could do. Something about Spiderman and with great power comes to mind :) You could set the thread id register to zero when you get an interrupt and restore it on return. You could have all your application stacks be at the bottom of store and the system ones at the top so your stack pointer is negative when in the system. Or you might be able to enable access to a system register at EL0 that gives the information you want.

  • Being unable to access CurrentEL is a good indication that you *are* in EL0.

    I would:
    a) argue that code should know which EL it is running in and

    b) if you are checking for security purposes then only >EL1 really cares as EL0 code should never even try to perform a privileged operation. If EL1 checks CurrentEL and the access fails this indicates something has gone horribly wrong and the exception (and resultant privilege escalation) is a good thing.
  • Well I agree about just determining the level, but using the same code and doing something different is a reasonable idea. It is what multiple threads within a single virtual address space do and what the thread id register is for. Plus it is I think quite a good idea to be able to share library code between privilege levels. A while ago I'd been thinking about running the client part of a  database system at a privileged level to control system resources and sharing the code with the user level.

  • Hi,

    What will be the exception level when the board start up?
    Is there a way to set up this?
    How do i chose whether i should go to a higher exception level?

    regards,
    Ajeesh