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.
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.
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.