title: How exactly does OS protect kernel
body: <p>my question is how exactly does operating system protect it's kernel part.</p>
  
  <p>From what I've found there are basically 2 modes kernel and user. And there should be some bits in memory segments which tels if a memory segment is kernel or user space segment. But where is the origin of those bits? Is there some "switch" in compiler that marks programs as kernel programs? And for example if driver is in kernel mode how does OS manages its integration to system so there is not malicious software added as a driver?</p>
  
  <p>If someone could enlighten me on this issue, I would be very grateful, thank you</p>