what is the difference between user mode and kernel mode in terms of total number of machine instructions available?
I read this paragraph from " Modern Operating Systems , Tanenbaum " Most computers have two modes of operation: kernel mode and user mode. The operating system is the most fundamental piece of software and runs in kernel mode (also called supervisor mode). In this mode it has complete access to all the hardware and can execute any instruction the machine is capable of executing. The rest of the software runs in user mode, in which only a subset of the machine instructions is available. I am unable to get how they are describing difference in these two modes on basis of machine instructions available , at user end any software has the capability to make any changes at the hardware level ,like we have software which can affect the functioning of CPU , can play with registry details , so how can we say that at user mode , we have only subset of machine instructions available ?
The instructions that are available only in kernel mode are tend to be very few. These instructions are those that are only needed to manage the system. For example, most processors have a HALT instruction that stops the CPU that is used for system shutdowns. Obviously you would not want any user to be able to execute HALT and stop the computer for everyone. Such instructions are then made only accessible in kernel mode. Processors use a table of handlers for interrupt and exceptions. The Operating system creates such a table listing the handlers for these events. Then it loads register(s) giving the location(and size) of the table. The instructions for loading this register(s) are kernel mode only. Otherwise, any application could create total havoc on the system. Instructions of these nature will trigger an exception if executing in user mode. Such instructions tend to be few in number.
Well, in user-mode, there is definitely a subset of instructions available. This is the reason we have System Calls. Example: A user wants to create a new process in C. He cannot do that without entering kernel-mode, because certain set of instructions are only available to kernel-mode, So he uses the system call fork, that executes instructions for creating a new process (not available in user-mode). So System call is a mechanism of requesting a service from kernel of the OS to do something for the user, which he/she cannot write code for. Following excerpt from above link sums it up in the best way: A program is usually limited to its own address space so that it cannot access or modify other running programs or the operating system itself, and is usually prevented from directly manipulating hardware devices (e.g. the frame buffer or network devices). However, many normal applications obviously need access to these components, so system calls are made available by the operating system to provide well defined, safe implementations for such operations. The operating system executes at the highest level of privilege, and allows applications to request services via system calls, which are often initiated via interrupts. An interrupt automatically puts the CPU into some elevated privilege level, and then passes control to the kernel, which determines whether the calling program should be granted the requested service. If the service is granted, the kernel executes a specific set of instructions over which the calling program has no direct control, returns the privilege level to that of the calling program, and then returns control to the calling program.
operating system and concurrent threads
On a system on which the PIC does not support masking, how does software disablement of hard interrupts work?
OS basic graphic driver
What is the true difference between a real mode program and a protected mode program?
How are datatypes that need more than 32 bits stored in a 32 bit OS
How user programs like in Java, make system calls/ call kernel subroutines?
Solution to Critical Section Issue
How can Nucleus get the ID list?
To find execution time on a mult-icore machine
Raspberry Pi bare metal programming
mavericks macports installed outdated
Os fingerprinting with MAC address
How to get return value using Fork() in NachOs?
What exactly happens when an OS goes into kernel mode?
Need for Direct Memory Acess
techniques that can be used to protect critical sections