icu.s revision 1.16
1/*	$OpenBSD: icu.s,v 1.16 2001/11/12 20:28:20 niklas 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(cpl), _C_LABEL(ipending)
37	.globl	_C_LABEL(astpending), _C_LABEL(netisr)
38_C_LABEL(imen):
39	.long	0xffff		# interrupt mask enable (all off)
40
41	.text
42
43#if defined(PROF) || defined(GPROF)
44	.globl	_C_LABEL(splhigh), _C_LABEL(splx)
45
46	ALIGN_TEXT
47_C_LABEL(splhigh):
48	movl	$IPL_HIGH,%eax
49	xchgl	%eax,_C_LABEL(cpl)
50	ret
51
52	ALIGN_TEXT
53_C_LABEL(splx):
54	movl	4(%esp),%eax
55	movl	%eax,_C_LABEL(cpl)
56	testl	%eax,%eax
57	jnz	_C_LABEL(Xspllower)
58	ret
59#endif /* PROF || GPROF */
60
61/*
62 * Process pending interrupts.
63 *
64 * Important registers:
65 *   ebx - cpl
66 *   esi - address to resume loop at
67 *   edi - scratch for Xsoftnet
68 */
69IDTVEC(spllower)
70	pushl	%ebx
71	pushl	%esi
72	pushl	%edi
73	movl	_C_LABEL(cpl),%ebx	# save priority
74	movl	$1f,%esi		# address to resume loop at
751:	movl	%ebx,%eax		# get cpl
76	shrl	$4,%eax			# find its mask.
77	movl	_C_LABEL(iunmask)(,%eax,4),%eax
78	andl	_C_LABEL(ipending),%eax
79	jz	2f
80	bsfl	%eax,%eax
81	btrl	%eax,_C_LABEL(ipending)
82	jnc	1b
83	jmp	*_C_LABEL(Xrecurse)(,%eax,4)
842:	popl	%edi
85	popl	%esi
86	popl	%ebx
87	ret
88
89/*
90 * Handle return from interrupt after device handler finishes.
91 *
92 * Important registers:
93 *   ebx - cpl to restore
94 *   esi - address to resume loop at
95 *   edi - scratch for Xsoftnet
96 */
97IDTVEC(doreti)
98	popl	%ebx			# get previous priority
99	movl	%ebx,_C_LABEL(cpl)
100	movl	$1f,%esi		# address to resume loop at
1011:	movl	%ebx,%eax		# get cpl
102	shrl	$4,%eax			# find its mask
103	movl	_C_LABEL(iunmask)(,%eax,4),%eax
104	andl	_C_LABEL(ipending),%eax
105	jz	2f
106	bsfl    %eax,%eax               # slow, but not worth optimizing
107	btrl    %eax,_C_LABEL(ipending)
108	jnc     1b			# some intr cleared the in-memory bit
109	cli
110	jmp	*_C_LABEL(Xresume)(,%eax,4)
1112:	/* Check for ASTs on exit to user mode. */
112	cli
113	cmpb	$0,_C_LABEL(astpending)
114	je	3f
115	testb   $SEL_RPL,TF_CS(%esp)
116#ifdef VM86
117	jnz	4f
118	testl	$PSL_VM,TF_EFLAGS(%esp)
119#endif
120	jz	3f
1214:	movb	$0,_C_LABEL(astpending)
122	sti
123	/* Pushed T_ASTFLT into tf_trapno on entry. */
124	call	_C_LABEL(trap)
125	jmp	2b
1263:	INTRFASTEXIT
127
128
129/*
130 * Soft interrupt handlers
131 */
132
133#include "pccom.h"
134
135IDTVEC(softtty)
136#if NPCCOM > 0
137	movl	$IPL_SOFTTTY,%eax
138	movl	%eax,_C_LABEL(cpl)
139	call	_C_LABEL(comsoft)
140	movl	%ebx,_C_LABEL(cpl)
141#endif
142	jmp	%esi
143
144#define DONETISR(s, c) \
145	.globl  _C_LABEL(c)	;\
146	testl	$(1 << s),%edi	;\
147	jz	1f		;\
148	call	_C_LABEL(c)	;\
1491:
150
151IDTVEC(softnet)
152	movl	$IPL_SOFTNET,%eax
153	movl	%eax,_C_LABEL(cpl)
154	xorl	%edi,%edi
155	xchgl	_C_LABEL(netisr),%edi
156#include <net/netisr_dispatch.h>
157	movl	%ebx,_C_LABEL(cpl)
158	jmp	%esi
159#undef DONETISR
160
161IDTVEC(softclock)
162	movl	$IPL_SOFTCLOCK,%eax
163	movl	%eax,_C_LABEL(cpl)
164	call	_C_LABEL(softclock)
165	movl	%ebx,_C_LABEL(cpl)
166	jmp	%esi
167
168