1/* $NetBSD: spl.S,v 1.2 2002/12/04 01:33:58 fvdl Exp $ */ 2 3/* 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include "opt_vm86.h" 40#include "opt_ddb.h" 41#include <machine/asm.h> 42#include <machine/psl.h> 43#include <machine/trap.h> 44#include <machine/segments.h> 45#include <machine/frameasm.h> 46 47#include "assym.h" 48 49 .data 50 .globl _C_LABEL(netisr) 51#ifndef MULTIPROCESSOR 52 .globl _C_LABEL(astpending) 53#endif 54 .text 55 56#if 0 57#if defined(PROF) || defined(GPROF) 58/* 59 * XXXX TODO 60 */ 61 .globl _C_LABEL(splhigh), _C_LABEL(splx) 62 63 ALIGN_TEXT 64_C_LABEL(splhigh): 65 movl $IPL_HIGH,%eax 66 xchgl %eax,CPUVAR(ILEVEL) 67 ret 68 69 ALIGN_TEXT 70_C_LABEL(splx): 71 movl 4(%esp),%eax 72 movl %eax,CPUVAR(ILEVEL) 73 testl %eax,%eax 74 jnz _C_LABEL(Xspllower) 75 ret 76#endif /* PROF || GPROF */ 77#endif 78 79/* 80 * Process pending interrupts. 81 * 82 * Important registers: 83 * ebx - cpl 84 * esi - address to resume loop at 85 * edi - scratch for Xsoftnet 86 */ 87IDTVEC(spllower) 88#ifdef DDB 89 pushl %ebp 90 movl %esp,%ebp 91#endif 92 pushl %ebx 93 pushl %esi 94 pushl %edi 95 movl CPUVAR(ILEVEL),%ebx # save priority 96 movl $1f,%esi # address to resume loop at 971: movl %ebx,%eax # get cpl 98 movl CPUVAR(IUNMASK)(,%eax,4),%eax 99 andl CPUVAR(IPENDING),%eax # any non-masked bits left? 100 jz 2f 101 bsfl %eax,%eax 102 btrl %eax,CPUVAR(IPENDING) 103 jnc 1b 104 movl CPUVAR(ISOURCES)(,%eax,4),%eax 105 jmp *IS_RECURSE(%eax) 1062: popl %edi 107 popl %esi 108 popl %ebx 109#ifdef DDB 110 leave 111#endif 112 ret 113 114/* 115 * Handle return from interrupt after device handler finishes. 116 * 117 * Important registers: 118 * ebx - cpl to restore 119 * esi - address to resume loop at 120 * edi - scratch for Xsoftnet 121 */ 122IDTVEC(doreti) 123 popl %ebx # get previous priority 124 movl %ebx,CPUVAR(ILEVEL) 125 decl CPUVAR(IDEPTH) 126 movl $1f,%esi # address to resume loop at 1271: movl %ebx,%eax 128 movl CPUVAR(IUNMASK)(,%eax,4),%eax 129 andl CPUVAR(IPENDING),%eax 130 jz 2f 131 bsfl %eax,%eax # slow, but not worth optimizing 132 btrl %eax,CPUVAR(IPENDING) 133 jnc 1b # some intr cleared the in-memory bit 134 movl CPUVAR(ISOURCES)(,%eax, 4),%eax 135 jmp *IS_RESUME(%eax) 1362: /* Check for ASTs on exit to user mode. */ 137 CHECK_ASTPENDING() 138 cli 139 je 3f 140 testb $SEL_RPL,TF_CS(%esp) 141#ifdef VM86 142 jnz 4f 143 testl $PSL_VM,TF_EFLAGS(%esp) 144#endif 145 jz 3f 1464: CLEAR_ASTPENDING() 147 sti 148 movl $T_ASTFLT,TF_TRAPNO(%esp) /* XXX undo later.. */ 149 /* Pushed T_ASTFLT into tf_trapno on entry. */ 150 call _C_LABEL(trap) 151 cli 152 jmp 2b 1533: 154 INTRFASTEXIT 155