In a custom OS running on an x86 in protected mode, is there a way to obtain the current privilege level, other than e.g. executing a privileged instruction and seeing if it crashes?
For instance, register CR0
contains the PE
bit, which indicates if we are running on real mode or protected mode, and can be easily retrieved using assembly code.
Is there something equivalent for the privilege level?
The Intel architecture software developer manual mentions that the EFLAGS
register contains two IOPL
bits related to I/O privilege levels. Is this the same as the current privilege level (CPL)?