Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Nov 1999 18:37:12 -0800 (PST)
From:      Julian Elischer <julian@whistle.com>
To:        current@freebsd.org
Subject:   Which is the truth? (sycalls and traps)
Message-ID:  <Pine.BSF.4.10.9911251824550.544-100000@current1.whistle.com>

next in thread | raw e-mail | index | archive | help
in src/lib/libc/i386/SYS.h we see:

#ifdef __ELF__
#define KERNCALL        int $0x80       /* Faster */
#else
#define KERNCALL        LCALL(7,0)      /* The old way */
#endif


and in /usr/src/sys/i386/i386/exception.s

we see:

/*
 * Call gate entry for syscall.
 * The intersegment call has been set up to specify one dummy parameter.
 * This leaves a place to put eflags so that the call frame can be
 * converted to a trap frame. Note that the eflags is (semi-)bogusly
 * pushed into (what will be) tf_err and then copied later into the
 * final spot. It has to be done this way because esp can't be just
 * temporarily altered for the pushfl - an interrupt might come in
 * and clobber the saved cs/eip.
 */
 * converted to a trap frame. Note that the eflags is (semi-)bogusly
 * pushed into (what will be) tf_err and then copied later into the
 * final spot. It has to be done this way because esp can't be just
 * temporarily altered for the pushfl - an interrupt might come in
 * and clobber the saved cs/eip.
 */
        SUPERALIGN_TEXT
IDTVEC(syscall)
        pushfl                          /* save eflags in tf_err for now
*/
        subl    $4,%esp                 /* skip over tf_trapno */
        pushal
        pushl   %ds
        pushl   %es
        pushl   %fs
        movl    $KDSEL,%eax             /* switch to kernel segments */
        movl    %ax,%ds
        movl    %ax,%es
        MOVL_KPSEL_EAX
        movl    %ax,%fs
        movl    TF_ERR(%esp),%eax       /* copy saved eflags to final spot
*/
        movl    %eax,TF_EFLAGS(%esp)
        movl    $7,TF_ERR(%esp)         /* sizeof "lcall 7,0" */
        FAKE_MCOUNT(13*4(%esp))
        MPLOCKED incl _cnt+V_SYSCALL
        SYSCALL_LOCK
        call    _syscall

        /*
         * Return via _doreti to handle ASTs.
         */
        pushl   $0                      /* cpl to restore */
        subl    $4,%esp                 /* dummy unit to finish intr frame
*/
        movb    $1,_intr_nesting_level
        MEXITCOUNT
        jmp     _doreti

/*
 * Call gate entry for Linux/NetBSD syscall (int 0x80)
 */
        SUPERALIGN_TEXT
IDTVEC(int0x80_syscall)
        subl    $8,%esp                 /* skip over tf_trapno and tf_err
*/
        pushal
        pushl   %ds
        pushl   %es
        pushl   %fs
        movl    $KDSEL,%eax             /* switch to kernel segments */
        movl    %ax,%ds
        movl    %ax,%es
        MOVL_KPSEL_EAX
        movl    %ax,%fs
        movl    $2,TF_ERR(%esp)         /* sizeof "int 0x80" */
        FAKE_MCOUNT(13*4(%esp))
        MPLOCKED incl _cnt+V_SYSCALL
        ALTSYSCALL_LOCK
        call    _syscall

        /*
         * Return via _doreti to handle ASTs.
         */
        pushl   $0                      /* cpl to restore */
        subl    $4,%esp                 /* dummy unit to finish intr frame
*/
        movb    $1,_intr_nesting_level
        MEXITCOUNT
        jmp     _doreti


Now, since teh code doesn't lie (one hopes)
I would PRESUME that the first handler is only used for old a.out
binaries, and the second is now the default entrypoint for syscalls
which would lead me to believe that the comment about Linux and NetBSD
is now incorrect and out of date... 
Am I reading this right? 
(I could imagin that someone could come to me and say
"no, because we aren't even using that file any more" or something.
There's a lot of cruft here that makes things hard to understand.)


Am I also right in assuming that all the registers that the user was
running when they did the KERNCALL have been saved on the KERNEL stack by
the time that the above routines are called?

(It's a pitty because if they were saved on the USER stack before teh
kernel switched to the kernel stack it would have a great simplifying 
effect on kernel threads support :-) (I know that could lead to traps
during saving the context but..)


Julian





To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.9911251824550.544-100000>