user16538
user16538

Reputation: 1130

What's the purpose of the syscall instruction?

Or, in other words: what's the difference between syscall and int <kernel-interrupt-number>?

The only obvious reason that I can think of is that the interrupt number varies across operating systems, and having a new, unique instruction gives more consistency. However system calls numbers and arguments still varies across operating systems, so the gain in consistency is really low.

Probably intercepting interrupts requires more work for the kernel? (Hence there is a performance gain for using syscall)

Upvotes: 2

Views: 2253

Answers (1)

Michael
Michael

Reputation: 58457

You're on the right track; The motivation for the syscall instruction was mainly performance. You can read more about this in AMD's "SYSCALL and SYSRET Instruction Specification".

Some excerpts from the documentation:

To initiate a call to the operating system, an application transfers control to the OS through gate descriptors (task, interrupt, trap, or call gates). Control transfer is done by using either a CALL instruction or a software interrupt. Setting up these control gates (as well as the later return via a RET or IRET instruction) is slowed down by the segmentation-related overhead.
....
SYSCALL and SYSRET are instructions used for low-latency system calls and returns in operating systems with a flat memory model and no segmentation. These instructions have been optimized by reducing the number of checks and memory references that are normally made so that a call or return takes less than one-fourth the number of internal clock cycles when compared to the current CALL/RET instruction method.

Upvotes: 2

Related Questions