Re: New SYSCALL instruction (was: Re: Call Gates)

Richard B. Johnson (root@analogic.com)
Fri, 20 Jun 1997 10:48:37 -0400 (EDT)


On Fri, 20 Jun 1997, S.Boessenkool wrote:

> [explanation about LDT desc's snipped]
>
> > The way chosen for linux is a bit more hacky, but it has some advantages.
> > Linux uses a user-triggered interrupt; the system call is an "int $80".
> > I think it might be a bit slower, but it saves the flags automatically,
> > allow all types of travels between rings, and this opcode is much smaller
> > than the "call 0007:00000000" one (2 bytes vs 7).
> > It also has the great characteristic of switching to a kernel stack, as it
> > would be really BAD is the kernel had to rely on the user-level stack.

[SNIPPED]

All "interrupts" in the ix86 scheme can be executed as "software" interrupts.
In other architectures they are usually called "traps". In the INT 80 used
for system calls, it's quite efficient from a system point-of-view because
system calls can seldom execute immediately and return to the caller. There
usually has to be some kernel I/O that must be accomplished. The kernel
just reschedules the caller as any normal preemption. The caller gets
control sometime later after the I/O completes. Basically, INT 80 gives
up the caller's time-slice.

You can do exactly the same thing by setting up a trap for an instruction
that is illegal in user-mode. The user's runtime-library sets up register
values so the kernel will know what function it is being asked to
perform, then the illegal instruction is executed. The kernel gets
control and does its thing. The INT 80 saves a few processor cycles
because it doesn't have to index past the illegal instruction when it
performs an IRET back to the user-mode code.

Performing a CALL to someplace, i.e., 7:<0xdeadface> will most always
require a lot of extra overhead even if you don't allow a kernel code
page to fault. You are going to try to execute code at a more priviledged
level. This will cause a trap which must be handled, in addition to the
call overhead. The result is a slower execution speed.

If you are writing kernel code, it's different. You can easily call
code using different selectors because they are at the same priviledge
level.

Regardless of any new trick instructions, my vote is for keeping
system calls from user-mode code exactly as they are.

Cheers,
DJ
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard B. Johnson
Analogic Corporation
Email : rjohnson@analogic.com, johnson@analogic.com
Penguin : Linux version 2.1.42 on an i586 machine (66.15 BogoMips).
Warning : It's hard to stay on the trailing edge of technology.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-