[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [f-cpu] Manual 0.2.6




----- Original Message -----
From: "Yann Guidon" <whygee@f-cpu.org>
To: <f-cpu@seul.org>
Sent: Thursday, July 25, 2002 1:52 PM
Subject: Re: [f-cpu] Manual 0.2.6


> hi !
>
> Cedric BAIL wrote:
> > Finally you take time to read it, thanks.
> :-)
>
> > >       6.1.2 `loadcons':
> > >               The jury is still discussing this.
> > Ok, but you and thomas write the latest post, because nobody answer, I
> > was thinking it was decided.
> i am definitely against.
>
> > >       7.1.7 `syscall'/`trap':
> > >               It's still not clear what the difference is.
> > >               I suppose both instructions perform an SRB.
> the difference is that "syscall" uses CPU cycles in a shared library
> or something like that, on behalf of the calling task. A trap is
> used for exceptional conditions, not common functions.
> But that old question could still change a bit...

Well, take an example :

On x86, we usually use a INT $0x80 to call a linux syscall, but calling it
from user code has some drawbacks due to the ring change and involve a lot
of cycles lost.

Two new instructions were introduced with AMD and PII+, which looks like a
SYSENTER/SYSCALL and a SYSLEAVE/SYSEXIT (i don't remember if it is AMD which
uses SYSENTER/LEAVE instead of SYSCALL/EXIT or PII+)

SYSENTER:
- just enter syscall handler in supervisor mode and change stack pointer.
the supervisor pc and sp are found in SMR registers (say, SR equivalent in
x86), so we cannot enter in supervisor mode with any sp or pc, of course.
- there is no register saving, so general registers can be usually seen as
parameters for syscall (like INT $0x80 for Linux x86 syscall).
- should only be called from user mode (calling it from supervisor mode
makes non sense since calling SYSLEAVE should return to user mode, so
SYSCALL is not reentrant). Don't know if an exception is raised on this
case.
- the former user pc and sp are saved in two general registers (AMD does
both, but PII+ only does one of both if I remember well).

SYSLEAVE:
- just go back in user mode with restoring user pc and sp from the both
registers where they were saved after executing SYSENTER.
- can only be called from supervisor mode to leave it, so it is a
priviledged instruction (if executing it at user mode, raise an exception)

Both instructions are very very very fast compared with the very slow INT n
to switch between user and superuser modes.

Concerning F-CPU, we could have something like SYSCALL/SYSEXIT but much
simpler :

syscall/sysexit : one SR could contain the supervisor PC (i.e, the start
point of syscall handler, which can only be altered in supervisor mode of
course), or have a fixed entry somewhere like interrupts (16- word entries
if I remember well, Whygee).

SYSCALL R1
- actual user PC is saved in register R1
- supervisor mode is set.
- supervisor PC is fetched from SR[syscall_pc] or simply set to a
(virtual/physically ?) fix address (syscall code must reside on supervisor
pages)
- syscall handler uses its stack pointer (using a different global register
which is much simpler; its stack must contain only supervisor pages to
protect it from user access).
- optional : raise an exception if called from supervisor mode.

NOTE : SYSCALL being used to be called from user mode, the PC entry in
syscall handler should not be blindly provided by the user but by a
supervisor entity (here, a protected SR) or with a fixed address only
accessible in supervisor mode.

SYSEXIT R1
- user mode is set.
- former user PC is restored from R1 (saved by SYSCALL)
- raise an exception if called from user mode.

Please, I'm not telling we must have both instructions but just to instruct
how an implementation of a fast syscall can be.

*************************************************************
To unsubscribe, send an e-mail to majordomo@seul.org with
unsubscribe f-cpu       in the body. http://f-cpu.seul.org/