title: Current x86 privilege level on a custom OS
body: <p>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?</p>
  
  <p>For instance, register <code>CR0</code> contains the <code>PE</code> bit, which indicates if we are running on real mode or protected mode, and can be easily retrieved using assembly code.</p>
  
  <p>Is there something equivalent for the privilege level?</p>
  
  <p>The <a href="http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html" rel="nofollow">Intel architecture software developer manual</a> mentions that the <code>EFLAGS</code> register contains two <code>IOPL</code> bits related to I/O privilege levels. Is this the same as the current privilege level (CPL)?</p>