title: What is CPU kernel/privileged mode, and how is it guarded by the OS?
body: <blockquote>
    <p>In Kernel mode, the executing code has complete and unrestricted
    access to the underlying hardware. It can execute any CPU instruction
    and reference any memory address</p>
  </blockquote>
  
  <p>Any example? Like what instructions, and what memory address?(x86 preferably). As for memory, does it mean like the high 1GB address(32 bit) reserved for kernel? Besides, who decides this? Is it the CPU, or OS? If it's the OS, how does the CPU know what part of memory is considered reserved(maybe some bit in the page table)? And how is memory accessed in kernel mode, still by virtual address?</p>
  
  <p>As for entering kernel mode, it is done by certain instructions like <code>int</code> right? I understand the part the all the system calls are heavily guarded, but what if I write a program in assembly code, which includes the <code>int</code> instructions? How is that guarded? I mean when that program is compiled, and eventually I got an executable file, the <code>int</code> instruction has to be in the '.text' section, coz the compiler won't do anything about it right? So what does OS do about it when it runs? Or what's in the '.text' section indeed? Is it THE instructions that are recognised by CPU, or maybe it's still some intermediate format, that would be 'translated' by the OS, so the OS would have a chance to 'reject' certain instructions like 'int', or whatever other 'restricted' instructions before it runs by CPU?</p>
  
  <p>Update:
  For anyone who's interested, here's a great explanation(at least for me) from quora: <a href="https://www.quora.com/What-is-CPU-kernel-mode-and-how-is-it-guarded-by-the-OS/answer/Mostafa-Abd-El-Aziz?__snids__=937993065&amp;__nsrc__=1&amp;__filter__=all" rel="nofollow">https://www.quora.com/What-is-CPU-kernel-mode-and-how-is-it-guarded-by-the-OS/answer/Mostafa-Abd-El-Aziz?<strong>snids</strong>=937993065&amp;<strong>nsrc</strong>=1&amp;<strong>filter</strong>=all</a></p>