i want to give the ans based on pure logic -
-> at any time we can categorize the processes running in the main memory in 2 categories - priviledged(p) & non-priviledged(np),
-> egs for p are - OS, supervisor(in modern systems)
-> p itself is responsible for running np - it takes user processes(np) as input, and runs them by giving them the control...
-> by turing's halting problem proof, there's no general way to know when any process will do what ( ' no t.m. can decide whether a given t.m. will ever even print a given symbol in general ' ) , THUS , p (any OS) can NEVER KNOW when a certain np will try to execute a privilegdes instruction for sure..
-> HENCE, THERE HAS TO BE A HARDWIRED MECHANISM so that whenever an instruction turns out to be priviledged on decoding, the control is returned to a particular process at a particular memory location, which atleast the system believes to be trusted.
[ When i say hardwire, i mean in the microarchitecture level, i.e. no ISA shall give any explicit instruction to make such transition(duh!) , suppose if there is one, then that instruction itself must be priviledged and the system must provide an even higher level hardwired way to shift the control to p, OR any np would simply use that instruction to make transition to priviledged mode. ]
So atleast at the very core the transition must be hardwired, now although formally we can still categorize the transition based on 2 scenarios -
-> the transition is done malliciously -
- the above case is the reason people say - " without proper hardware (hardwired) support, an OS is as good as nothing ", basically implying the OS is highly vulnerable...
-> the transition is done to reduce labor (get help from the OS) -
here the OS developers provide implementation details to language devs. as what shall be the name of the functions they can provide, what they do, what arguments they take, what preliminaries the np must do before they implement the architecture specific procedure to change cpu mode (cpu is hardwired to do the rest on its own) and so on .
On calling these functions ( called system calls ) the compiler uses the implementation details to conform to the pre-requirements the OS requires to do the specific job, then the np making the system call performs the architecture specific way of the changing the mode - usually an instruction listed in ISA of that architecture/system, the system/cpu shifts the control to OS, the OS checks for the details it asked to be there if an np wants it to do anything, if no valid details found OS returns with error message, if found , OS does the job, on completing the job the OS returns the control to the np ....