The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/i386/i386/exception.s

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1989, 1990 William F. Jolitz.
    3  * Copyright (c) 1990 The Regents of the University of California.
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 4. Neither the name of the University nor the names of its contributors
   15  *    may be used to endorse or promote products derived from this software
   16  *    without specific prior written permission.
   17  *
   18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   28  * SUCH DAMAGE.
   29  *
   30  * $FreeBSD$
   31  */
   32 
   33 #include "opt_apic.h"
   34 #include "opt_npx.h"
   35 
   36 #include <machine/asmacros.h>
   37 #include <machine/psl.h>
   38 #include <machine/trap.h>
   39 
   40 #include "assym.s"
   41 
   42 #define SEL_RPL_MASK    0x0003
   43 
   44         .text
   45 
   46 /*****************************************************************************/
   47 /* Trap handling                                                             */
   48 /*****************************************************************************/
   49 /*
   50  * Trap and fault vector routines.
   51  *
   52  * Most traps are 'trap gates', SDT_SYS386TGT.  A trap gate pushes state on
   53  * the stack that mostly looks like an interrupt, but does not disable 
   54  * interrupts.  A few of the traps we are use are interrupt gates, 
   55  * SDT_SYS386IGT, which are nearly the same thing except interrupts are
   56  * disabled on entry.
   57  *
   58  * The cpu will push a certain amount of state onto the kernel stack for
   59  * the current process.  The amount of state depends on the type of trap 
   60  * and whether the trap crossed rings or not.  See i386/include/frame.h.  
   61  * At the very least the current EFLAGS (status register, which includes 
   62  * the interrupt disable state prior to the trap), the code segment register,
   63  * and the return instruction pointer are pushed by the cpu.  The cpu 
   64  * will also push an 'error' code for certain traps.  We push a dummy 
   65  * error code for those traps where the cpu doesn't in order to maintain 
   66  * a consistent frame.  We also push a contrived 'trap number'.
   67  *
   68  * The cpu does not push the general registers, we must do that, and we 
   69  * must restore them prior to calling 'iret'.  The cpu adjusts the %cs and
   70  * %ss segment registers, but does not mess with %ds, %es, or %fs.  Thus we
   71  * must load them with appropriate values for supervisor mode operation.
   72  */
   73 
   74 MCOUNT_LABEL(user)
   75 MCOUNT_LABEL(btrap)
   76 
   77 IDTVEC(div)
   78         pushl $0; TRAP(T_DIVIDE)
   79 IDTVEC(dbg)
   80         pushl $0; TRAP(T_TRCTRAP)
   81 IDTVEC(nmi)
   82         pushl $0; TRAP(T_NMI)
   83 IDTVEC(bpt)
   84         pushl $0; TRAP(T_BPTFLT)
   85 IDTVEC(ofl)
   86         pushl $0; TRAP(T_OFLOW)
   87 IDTVEC(bnd)
   88         pushl $0; TRAP(T_BOUND)
   89 IDTVEC(ill)
   90         pushl $0; TRAP(T_PRIVINFLT)
   91 IDTVEC(dna)
   92         pushl $0; TRAP(T_DNA)
   93 IDTVEC(fpusegm)
   94         pushl $0; TRAP(T_FPOPFLT)
   95 IDTVEC(tss)
   96         TRAP(T_TSSFLT)
   97 IDTVEC(missing)
   98         TRAP(T_SEGNPFLT)
   99 IDTVEC(stk)
  100         TRAP(T_STKFLT)
  101 IDTVEC(prot)
  102         TRAP(T_PROTFLT)
  103 IDTVEC(page)
  104         TRAP(T_PAGEFLT)
  105 IDTVEC(mchk)
  106         pushl $0; TRAP(T_MCHK)
  107 IDTVEC(rsvd)
  108         pushl $0; TRAP(T_RESERVED)
  109 IDTVEC(fpu)
  110         pushl $0; TRAP(T_ARITHTRAP)
  111 IDTVEC(align)
  112         TRAP(T_ALIGNFLT)
  113 
  114 IDTVEC(xmm)
  115         pushl $0; TRAP(T_XMMFLT)
  116         
  117         /*
  118          * alltraps entry point.  Interrupts are enabled if this was a trap
  119          * gate (TGT), else disabled if this was an interrupt gate (IGT).
  120          * Note that int0x80_syscall is a trap gate.  Only page faults
  121          * use an interrupt gate.
  122          */
  123 
  124         SUPERALIGN_TEXT
  125         .globl  alltraps
  126         .type   alltraps,@function
  127 alltraps:
  128         pushal
  129         pushl   %ds
  130         pushl   %es
  131         pushl   %fs
  132 alltraps_with_regs_pushed:
  133         movl    $KDSEL,%eax
  134         movl    %eax,%ds
  135         movl    %eax,%es
  136         movl    $KPSEL,%eax
  137         movl    %eax,%fs
  138         FAKE_MCOUNT(TF_EIP(%esp))
  139 calltrap:
  140         call    trap
  141 
  142         /*
  143          * Return via doreti to handle ASTs.
  144          */
  145         MEXITCOUNT
  146         jmp     doreti
  147 
  148 /*
  149  * SYSCALL CALL GATE (old entry point for a.out binaries)
  150  *
  151  * The intersegment call has been set up to specify one dummy parameter.
  152  *
  153  * This leaves a place to put eflags so that the call frame can be
  154  * converted to a trap frame. Note that the eflags is (semi-)bogusly
  155  * pushed into (what will be) tf_err and then copied later into the
  156  * final spot. It has to be done this way because esp can't be just
  157  * temporarily altered for the pushfl - an interrupt might come in
  158  * and clobber the saved cs/eip.
  159  */
  160         SUPERALIGN_TEXT
  161 IDTVEC(lcall_syscall)
  162         pushfl                          /* save eflags */
  163         popl    8(%esp)                 /* shuffle into tf_eflags */
  164         pushl   $7                      /* sizeof "lcall 7,0" */
  165         subl    $4,%esp                 /* skip over tf_trapno */
  166         pushal
  167         pushl   %ds
  168         pushl   %es
  169         pushl   %fs
  170         movl    $KDSEL,%eax             /* switch to kernel segments */
  171         movl    %eax,%ds
  172         movl    %eax,%es
  173         movl    $KPSEL,%eax
  174         movl    %eax,%fs
  175         FAKE_MCOUNT(TF_EIP(%esp))
  176         call    syscall
  177         MEXITCOUNT
  178         jmp     doreti
  179 
  180 /*
  181  * Call gate entry for FreeBSD ELF and Linux/NetBSD syscall (int 0x80)
  182  *
  183  * Even though the name says 'int0x80', this is actually a TGT (trap gate)
  184  * rather then an IGT (interrupt gate).  Thus interrupts are enabled on
  185  * entry just as they are for a normal syscall.
  186  */
  187         SUPERALIGN_TEXT
  188 IDTVEC(int0x80_syscall)
  189         pushl   $2                      /* sizeof "int 0x80" */
  190         subl    $4,%esp                 /* skip over tf_trapno */
  191         pushal
  192         pushl   %ds
  193         pushl   %es
  194         pushl   %fs
  195         movl    $KDSEL,%eax             /* switch to kernel segments */
  196         movl    %eax,%ds
  197         movl    %eax,%es
  198         movl    $KPSEL,%eax
  199         movl    %eax,%fs
  200         FAKE_MCOUNT(TF_EIP(%esp))
  201         call    syscall
  202         MEXITCOUNT
  203         jmp     doreti
  204 
  205 ENTRY(fork_trampoline)
  206         pushl   %esp                    /* trapframe pointer */
  207         pushl   %ebx                    /* arg1 */
  208         pushl   %esi                    /* function */
  209         call    fork_exit
  210         addl    $12,%esp
  211         /* cut from syscall */
  212 
  213         /*
  214          * Return via doreti to handle ASTs.
  215          */
  216         MEXITCOUNT
  217         jmp     doreti
  218 
  219 
  220 /*
  221  * To efficiently implement classification of trap and interrupt handlers
  222  * for profiling, there must be only trap handlers between the labels btrap
  223  * and bintr, and only interrupt handlers between the labels bintr and
  224  * eintr.  This is implemented (partly) by including files that contain
  225  * some of the handlers.  Before including the files, set up a normal asm
  226  * environment so that the included files doen't need to know that they are
  227  * included.
  228  */
  229 
  230         .data
  231         .p2align 4
  232         .text
  233         SUPERALIGN_TEXT
  234 MCOUNT_LABEL(bintr)
  235 
  236 #include <i386/isa/atpic_vector.s>
  237 
  238 #ifdef DEV_APIC
  239         .data
  240         .p2align 4
  241         .text
  242         SUPERALIGN_TEXT
  243 
  244 #include <i386/i386/apic_vector.s>
  245 #endif
  246 
  247         .data
  248         .p2align 4
  249         .text
  250         SUPERALIGN_TEXT
  251 #include <i386/i386/vm86bios.s>
  252 
  253         .text
  254 MCOUNT_LABEL(eintr)
  255 
  256 /*
  257  * void doreti(struct trapframe)
  258  *
  259  * Handle return from interrupts, traps and syscalls.
  260  */
  261         .text
  262         SUPERALIGN_TEXT
  263         .type   doreti,@function
  264 doreti:
  265         FAKE_MCOUNT($bintr)             /* init "from" bintr -> doreti */
  266 doreti_next:
  267         /*
  268          * Check if ASTs can be handled now.  PSL_VM must be checked first
  269          * since segment registers only have an RPL in non-VM86 mode.
  270          */
  271         testl   $PSL_VM,TF_EFLAGS(%esp) /* are we in vm86 mode? */
  272         jz      doreti_notvm86
  273         movl    PCPU(CURPCB),%ecx
  274         testl   $PCB_VM86CALL,PCB_FLAGS(%ecx)   /* are we in a vm86 call? */
  275         jz      doreti_ast              /* can handle ASTS now if not */
  276         jmp     doreti_exit
  277 
  278 doreti_notvm86:
  279         testb   $SEL_RPL_MASK,TF_CS(%esp) /* are we returning to user mode? */
  280         jz      doreti_exit             /* can't handle ASTs now if not */
  281 
  282 doreti_ast:
  283         /*
  284          * Check for ASTs atomically with returning.  Disabling CPU
  285          * interrupts provides sufficient locking even in the SMP case,
  286          * since we will be informed of any new ASTs by an IPI.
  287          */
  288         cli
  289         movl    PCPU(CURTHREAD),%eax
  290         testl   $TDF_ASTPENDING | TDF_NEEDRESCHED,TD_FLAGS(%eax)
  291         je      doreti_exit
  292         sti
  293         pushl   %esp                    /* pass a pointer to the trapframe */
  294         call    ast
  295         add     $4,%esp
  296         jmp     doreti_ast
  297 
  298         /*
  299          * doreti_exit: pop registers, iret.
  300          *
  301          *      The segment register pop is a special case, since it may
  302          *      fault if (for example) a sigreturn specifies bad segment
  303          *      registers.  The fault is handled in trap.c.
  304          */
  305 doreti_exit:
  306         MEXITCOUNT
  307 
  308         .globl  doreti_popl_fs
  309 doreti_popl_fs:
  310         popl    %fs
  311         .globl  doreti_popl_es
  312 doreti_popl_es:
  313         popl    %es
  314         .globl  doreti_popl_ds
  315 doreti_popl_ds:
  316         popl    %ds
  317         popal
  318         addl    $8,%esp
  319         .globl  doreti_iret
  320 doreti_iret:
  321         iret
  322 
  323         /*
  324          * doreti_iret_fault and friends.  Alternative return code for
  325          * the case where we get a fault in the doreti_exit code
  326          * above.  trap() (i386/i386/trap.c) catches this specific
  327          * case, sends the process a signal and continues in the
  328          * corresponding place in the code below.
  329          */
  330         ALIGN_TEXT
  331         .globl  doreti_iret_fault
  332 doreti_iret_fault:
  333         subl    $8,%esp
  334         pushal
  335         pushl   %ds
  336         .globl  doreti_popl_ds_fault
  337 doreti_popl_ds_fault:
  338         pushl   %es
  339         .globl  doreti_popl_es_fault
  340 doreti_popl_es_fault:
  341         pushl   %fs
  342         .globl  doreti_popl_fs_fault
  343 doreti_popl_fs_fault:
  344         movl    $0,TF_ERR(%esp) /* XXX should be the error code */
  345         movl    $T_PROTFLT,TF_TRAPNO(%esp)
  346         jmp     alltraps_with_regs_pushed

Cache object: 499016d9c8745b493afbd8397b6c332f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.