icu.s revision 1.34
1/*	$OpenBSD: icu.s,v 1.34 2018/04/11 15:44:08 bluhm 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	.data
34	.globl	_C_LABEL(imen)
35_C_LABEL(imen):
36	.long	0xffff		# interrupt mask enable (all off)
37
38	.text
39/*
40 * Process pending interrupts.
41 *
42 * Important registers:
43 *   ebx - cpl
44 *   esi - address to resume loop at
45 *   edi - scratch for Xsoftnet
46 */
47KIDTVEC(spllower)
48	pushl	%ebx
49	pushl	%esi
50	pushl	%edi
51	movl	CPL,%ebx		# save priority
52	movl	$1f,%esi		# address to resume loop at
531:	movl	%ebx,%eax		# get cpl
54	shrl	$4,%eax			# find its mask.
55	movl	_C_LABEL(iunmask)(,%eax,4),%eax
56	cli
57	andl	CPUVAR(IPENDING),%eax	# any non-masked bits left?
58	jz	2f
59	sti
60	bsfl	%eax,%eax
61	btrl	%eax,CPUVAR(IPENDING)
62	jnc	1b
63	jmp	*_C_LABEL(Xrecurse)(,%eax,4)
642:	movl	%ebx,CPL
65	sti
66	popl	%edi
67	popl	%esi
68	popl	%ebx
69	ret
70
71/*
72 * Handle return from interrupt after device handler finishes.
73 *
74 * Important registers:
75 *   ebx - cpl to restore
76 *   esi - address to resume loop at
77 *   edi - scratch for Xsoftnet
78 */
79KIDTVEC(doreti)
80	popl	%ebx			# get previous priority
81	movl	$1f,%esi		# address to resume loop at
821:	movl	%ebx,%eax
83	shrl	$4,%eax
84	movl	_C_LABEL(iunmask)(,%eax,4),%eax
85	cli
86	andl	CPUVAR(IPENDING),%eax
87	jz	2f
88	sti
89	bsfl    %eax,%eax               # slow, but not worth optimizing
90	btrl    %eax,CPUVAR(IPENDING)
91	jnc     1b			# some intr cleared the in-memory bit
92	cli
93	jmp	*_C_LABEL(Xresume)(,%eax,4)
942:	/* Check for ASTs on exit to user mode. */
95	CHECK_ASTPENDING(%ecx)
96	movl	%ebx,CPL
97	je	3f
98	testb   $SEL_RPL,TF_CS(%esp)
99#ifdef VM86
100	jnz	4f
101	testl	$PSL_VM,TF_EFLAGS(%esp)
102#endif
103	jz	3f
1044:	CLEAR_ASTPENDING(%ecx)
105	sti
106	pushl	%esp
107	call	_C_LABEL(ast)
108	addl	$4,%esp
109	cli
110	jmp	2b
1113:
112#ifdef DIAGNOSTIC
113	movl	$0xf9,%esi
114#endif
115	INTRFASTEXIT
116
117
118/*
119 * Soft interrupt handlers
120 */
121
122KIDTVEC(softtty)
123	movl	$IPL_SOFTTTY,%eax
124	movl	%eax,CPL
125	sti
126	pushl	$I386_SOFTINTR_SOFTTTY
127	call	_C_LABEL(softintr_dispatch)
128	addl	$4,%esp
129	jmp	*%esi
130
131KIDTVEC(softnet)
132	movl	$IPL_SOFTNET,%eax
133	movl	%eax,CPL
134	sti
135	pushl	$I386_SOFTINTR_SOFTNET
136	call	_C_LABEL(softintr_dispatch)
137	addl	$4,%esp
138	jmp	*%esi
139#undef DONETISR
140
141KIDTVEC(softclock)
142	movl	$IPL_SOFTCLOCK,%eax
143	movl	%eax,CPL
144	sti
145	pushl	$I386_SOFTINTR_SOFTCLOCK
146	call	_C_LABEL(softintr_dispatch)
147	addl	$4,%esp
148	jmp	*%esi
149
150