A special signal or message generated and send by the user program or
system itself to invoke a module of operating system so that it can work with
it and access the control of the hardware. System call changes the mode of the
application from user mode to kernel mode. Now when the mode is changed the
application can complete its request to access the control of the hardware.
Let us consider a read system call. The system call constitutes
of three parameters, file name, pointer to the buffer and number of bytes to
read. The function call looks like,
count= read(fd, buffer, nbytes)
The count consist of total number of bytes to read and if some error
occur it is set to -1 which is also indicated by a global variable errno.
The program should check this error variable timely to check if any error has
occurred. The 1st and the 3rd parameters are passed by
value and the 2nd parameter is passed by reference i.e. the buffer
address is passed.
Now when the read procedure is called by the user program the control is
transferred to the read procedure. At this stage the parameters are pushed onto
the stack (step 1, 2, 3) and the control is now completely transferred to the
read procedure. Then the system call number is put into the register(step 5)
and a TRAP instruction is executed that switches from user mode to kernel
mode(step 6). Now the system call number is examined and then the dispatcher
dispatches to the correct system call handler via table of pointers to the
system call handler(step 7). After that the system call handler works(step 8).
After the system call handler completes its task the control may be returned to
the user-space library procedure (step 9). Then the control is transferred to
the user program from the read procedure (step 10).
Finally, SP is incremented to clean up the stack. In this way the job of
read system call is completed.
No comments:
Post a Comment