Kernel is the core part of an operating system that manages system resources. It also acts as a bridge between the application and hardware of the computer. It is one of the first programs loaded on start-up (after the Bootloader).
Kernel mode and User mode of CPU operation
The CPU can execute certain instructions only when it is in kernel mode. These instructions are called privilege instruction. They allow the implementation of special operations whose execution by the user program could interface with the functioning of the operating system or activity of another user program. For example, instruction for managing memory protection.
-
The operating system puts the CPU in kernel mode when it is executing in the kernel so, that kernel can execute some special operation.
-
The operating system puts the CPU in user mode when a user program is in execution so, that the user program cannot interface with the operating system program.
-
User-level instruction does not require special privilege. Example are ADD,PUSH,etc.
System calls are typically implemented in the form of software interrupts, which causes the hardware’s interrupt handler to transfer control over to an appropriate interrupt handler, which is part of the operating system, switching the bit mode to kernel mode in the process. The interrupt handler checks exactly which interrupt was generated, checks additional parameters ( generally passed through registers ) if appropriate, and then calls the appropriate kernel service routine to handle the service requested by the system call.
User programs’ attempts to execute illegal instructions ( privileged or non-existent instructions ), or to access forbidden memory areas, also generate software interrupts, which are trapped by the interrupt handler, and control is transferred to the OS, which issues an appropriate error message, possibly dumps data to a log ( core ) file for later analysis, and then terminates the offending program.