Alex Rivera | Logout

how does the processor know an instruction is making a system call

Asked 2012-09-01T10:33:39.540
10

system call -- It is an instruction that generates an interrupt that causes OS to gain control of processor.

so if a running process issue a system call (e.g. create/terminate/read/write etc), a interrupt is generated which cause the KERNEL TO TAKE CONTROL of the processor which then executes the required interrupt handler routine. correct?

then can anyone tell me how the processor known that this instruction is supposed to block the process, go to privileged mode, and bring kernel code.

I mean as a programmer i would just type stream1=system.io.readfile(ABC) or something, which translates to open and read file ABC.

Now what is monitoring the execution of this process, is there a magical power in the cpu to detect this?

As from what i have read a PROCESSOR can only execute only process at a time, so WHERE IS THE MONITOR PROGRAM RUNNING?

How can the KERNEL monitor if a system call is made or not when IT IS NOT IN RUNNING STATE!!

or does the computer have a SYSTEM CALL INSTRUCTION TABLE which it compares with before executing any instruction?

please help

thanku

Edit
Report

1 Answer

9

The kernel doesn't monitor the process to detect a system call. Instead, the process generates an interrupt which transfers control to the kernel, because that's what software-generated interrupts do according to the instruction set reference manual.

For example, on Unix the process stuffs the syscall number in eax and runs an an int 0x80 instruction, which generates interrupt 0x80. The CPU reacts to this by looking in the Interrupt Descriptor Table to find the kernel's handler for that interrupt. This handler is the entry point for system calls.

So, to call _exit(0) (the raw system call, not the glibc exit() function which flushes buffers) in 32-bit x86 Linux:

movl  $1, %eax   # The system-call number.  __NR_exit is 1 for 32-bit
xor   %ebx,%ebx  # put the arg (exit status) in ebx
int   $0x80
answered 2012-09-01T10:35:51.060

Your Answer