/ COMPUTER-FUNDAMENTAL

User mode vs Kernel mode

I/O protection (Operating System)


OS controls CPU, Memory, and I/O.
OS needs the modes for I/O protection.

CPU has two modes (User, Kernel) to protect I/O devices against hackers.
User mode is normal mode when OS doesn’t need to manage sensitive codes.
Kernal mode is exceptional mode when OS needs to manage sensitive codes to I/O device directly.
Interrupt is happened when OS needs to change from User mode to Kernal mode.

As an example, when a hacker made a malicious program that removes all data in a hardDisk.
To prevent this, only OS has an authorization to access I/O device as an interface,
because it is quite dangerous to approach sensitive data by application itself.

Another example, when the hacker puts machine codes directly into an application,
the program could access CPU without OS.
because of that, CPU should remember that these commands are restricted as well.


IPC


Example

OS has in/out machine commands to put data in I/O device.
Read data command is “in”, write data command is “out”.
Write data command put data into a deveice controller register.

The in/out commands shouldn’t operate on User mode.
Even though an application program has an assembly program that write 0 in Disk,
the assembly program is “out” command, CPU recognizes the commands and call exception.
And then, the process is shut down.

IPC


OS controls every approach to data directly.
So, every request is passing through OS.