xref: /openbsd/sys/arch/i386/isa/icu.s (revision 7b36286a)
1/*	$OpenBSD: icu.s,v 1.29 2008/05/21 18:49:47 kettenis Exp $	*/
2/*	$NetBSD: icu.s,v 1.45 1996/01/07 03:59:34 mycroft Exp $	*/
3
4/*-
5 * Copyright (c) 1993, 1994, 1995 Charles M. Hannum.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by Charles M. Hannum.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <net/netisr.h>
34
35	.data
36	.globl	_C_LABEL(imen),_C_LABEL(netisr)
37_C_LABEL(imen):
38	.long	0xffff		# interrupt mask enable (all off)
39_C_LABEL(netisr):
40	.long	0		# scheduling bits for network
41
42	.text
43/*
44 * Process pending interrupts.
45 *
46 * Important registers:
47 *   ebx - cpl
48 *   esi - address to resume loop at
49 *   edi - scratch for Xsoftnet
50 */
51IDTVEC(spllower)
52	pushl	%ebx
53	pushl	%esi
54	pushl	%edi
55	movl	CPL,%ebx		# save priority
56	movl	$1f,%esi		# address to resume loop at
571:	movl	%ebx,%eax		# get cpl
58	shrl	$4,%eax			# find its mask.
59	movl	_C_LABEL(iunmask)(,%eax,4),%eax
60	cli
61	andl	CPUVAR(IPENDING),%eax	# any non-masked bits left?
62	jz	2f
63	sti
64	bsfl	%eax,%eax
65	btrl	%eax,CPUVAR(IPENDING)
66	jnc	1b
67	jmp	*_C_LABEL(Xrecurse)(,%eax,4)
682:	movl	%ebx,CPL
69	sti
70	popl	%edi
71	popl	%esi
72	popl	%ebx
73	ret
74
75/*
76 * Handle return from interrupt after device handler finishes.
77 *
78 * Important registers:
79 *   ebx - cpl to restore
80 *   esi - address to resume loop at
81 *   edi - scratch for Xsoftnet
82 */
83IDTVEC(doreti)
84	popl	%ebx			# get previous priority
85	movl	$1f,%esi		# address to resume loop at
861:	movl	%ebx,%eax
87	shrl	$4,%eax
88	movl	_C_LABEL(iunmask)(,%eax,4),%eax
89	cli
90	andl	CPUVAR(IPENDING),%eax
91	jz	2f
92	sti
93	bsfl    %eax,%eax               # slow, but not worth optimizing
94	btrl    %eax,CPUVAR(IPENDING)
95	jnc     1b			# some intr cleared the in-memory bit
96	cli
97	jmp	*_C_LABEL(Xresume)(,%eax,4)
982:	/* Check for ASTs on exit to user mode. */
99	CHECK_ASTPENDING(%ecx)
100	movl	%ebx,CPL
101	je	3f
102	testb   $SEL_RPL,TF_CS(%esp)
103#ifdef VM86
104	jnz	4f
105	testl	$PSL_VM,TF_EFLAGS(%esp)
106#endif
107	jz	3f
1084:	CLEAR_ASTPENDING(%ecx)
109	sti
110	movl	$T_ASTFLT,TF_TRAPNO(%esp)	/* XXX undo later. */
111	/* Pushed T_ASTFLT into tf_trapno on entry. */
112	call	_C_LABEL(trap)
113	cli
114	jmp	2b
1153:	INTRFASTEXIT
116
117
118/*
119 * Soft interrupt handlers
120 */
121
122IDTVEC(softtty)
123	movl	$IPL_SOFTTTY,%eax
124	movl	%eax,CPL
125	sti
126#ifdef MULTIPROCESSOR
127	call	_C_LABEL(i386_softintlock)
128#endif
129	pushl	$I386_SOFTINTR_SOFTTTY
130	call	_C_LABEL(softintr_dispatch)
131	addl	$4,%esp
132#ifdef MULTIPROCESSOR
133	call	_C_LABEL(i386_softintunlock)
134#endif
135	jmp	*%esi
136
137#define DONETISR(s, c) \
138	.globl  _C_LABEL(c)	;\
139	testl	$(1 << s),%edi	;\
140	jz	1f		;\
141	call	_C_LABEL(c)	;\
1421:
143
144IDTVEC(softnet)
145	movl	$IPL_SOFTNET,%eax
146	movl	%eax,CPL
147	sti
148#ifdef MULTIPROCESSOR
149	call	_C_LABEL(i386_softintlock)
150#endif
151	xorl	%edi,%edi
152	xchgl	_C_LABEL(netisr),%edi
153
154#include <net/netisr_dispatch.h>
155
156	pushl	$I386_SOFTINTR_SOFTNET
157	call	_C_LABEL(softintr_dispatch)
158	addl	$4,%esp
159#ifdef MULTIPROCESSOR
160	call	_C_LABEL(i386_softintunlock)
161#endif
162	jmp	*%esi
163#undef DONETISR
164
165IDTVEC(softclock)
166	movl	$IPL_SOFTCLOCK,%eax
167	movl	%eax,CPL
168	sti
169#ifdef MULTIPROCESSOR
170	call	_C_LABEL(i386_softintlock)
171#endif
172	pushl	$I386_SOFTINTR_SOFTCLOCK
173	call	_C_LABEL(softintr_dispatch)
174	addl	$4,%esp
175#ifdef MULTIPROCESSOR
176	call	_C_LABEL(i386_softintunlock)
177#endif
178	jmp	*%esi
179
180