1 /*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * $FreeBSD: src/sys/i386/i386/exception.s,v 1.19.2.2 1999/09/05 08:11:06 peter Exp $
34 */
35
36 #include "npx.h" /* NNPX */
37 #include "assym.s" /* system defines */
38 #include <sys/errno.h> /* error return codes */
39 #include <machine/spl.h> /* SWI_AST_MASK ... */
40 #include <machine/psl.h> /* PSL_I */
41 #include <machine/trap.h> /* trap codes */
42 #include <sys/syscall.h> /* syscall numbers */
43 #include <machine/asmacros.h> /* miscellaneous macros */
44 #include <sys/cdefs.h> /* CPP macros */
45
46 #define KDSEL 0x10 /* kernel data selector */
47 #define SEL_RPL_MASK 0x0003
48 #define TRAPF_CS_OFF (13 * 4)
49
50 .text
51
52 /*****************************************************************************/
53 /* Trap handling */
54 /*****************************************************************************/
55 /*
56 * Trap and fault vector routines
57 */
58 #define IDTVEC(name) ALIGN_TEXT; .globl __CONCAT(_X,name); __CONCAT(_X,name):
59 #define TRAP(a) pushl $(a) ; jmp _alltraps
60
61 /*
62 * XXX - debugger traps are now interrupt gates so at least bdb doesn't lose
63 * control. The sti's give the standard losing behaviour for ddb and kgdb.
64 */
65 #ifdef BDE_DEBUGGER
66 #define BDBTRAP(name) \
67 ss ; \
68 cmpb $0,_bdb_exists ; \
69 je 1f ; \
70 testb $SEL_RPL_MASK,4(%esp) ; \
71 jne 1f ; \
72 ss ; \
73 .globl __CONCAT(__CONCAT(bdb_,name),_ljmp); \
74 __CONCAT(__CONCAT(bdb_,name),_ljmp): \
75 ljmp $0,$0 ; \
76 1:
77 #else
78 #define BDBTRAP(name)
79 #endif
80
81 #define BPTTRAP(a) testl $PSL_I,4+8(%esp) ; je 1f ; sti ; 1: ; TRAP(a)
82
83 MCOUNT_LABEL(user)
84 MCOUNT_LABEL(btrap)
85
86 IDTVEC(div)
87 pushl $0; TRAP(T_DIVIDE)
88 IDTVEC(dbg)
89 BDBTRAP(dbg)
90 pushl $0; BPTTRAP(T_TRCTRAP)
91 IDTVEC(nmi)
92 pushl $0; TRAP(T_NMI)
93 IDTVEC(bpt)
94 BDBTRAP(bpt)
95 pushl $0; BPTTRAP(T_BPTFLT)
96 IDTVEC(ofl)
97 pushl $0; TRAP(T_OFLOW)
98 IDTVEC(bnd)
99 pushl $0; TRAP(T_BOUND)
100 IDTVEC(ill)
101 pushl $0; TRAP(T_PRIVINFLT)
102 IDTVEC(dna)
103 pushl $0; TRAP(T_DNA)
104 IDTVEC(fpusegm)
105 pushl $0; TRAP(T_FPOPFLT)
106 IDTVEC(tss)
107 TRAP(T_TSSFLT)
108 IDTVEC(missing)
109 TRAP(T_SEGNPFLT)
110 IDTVEC(stk)
111 TRAP(T_STKFLT)
112 IDTVEC(prot)
113 TRAP(T_PROTFLT)
114 IDTVEC(page)
115 TRAP(T_PAGEFLT)
116 IDTVEC(mchk)
117 pushl $0; TRAP(T_MCHK)
118 IDTVEC(rsvd)
119 pushl $0; TRAP(T_RESERVED)
120 IDTVEC(fpu)
121 #if NNPX > 0
122 /*
123 * Handle like an interrupt (except for accounting) so that we can
124 * call npxintr to clear the error. It would be better to handle
125 * npx interrupts as traps. This used to be difficult for nested
126 * interrupts, but now it is fairly easy - mask nested ones the
127 * same as SWI_AST's.
128 */
129 pushl $0 /* dummy error code */
130 pushl $0 /* dummy trap type */
131 pushal
132 pushl %ds
133 pushl %es /* now the stack frame is a trap frame */
134 movl $KDSEL,%eax
135 movl %ax,%ds
136 movl %ax,%es
137 FAKE_MCOUNT(12*4(%esp))
138 movl _cpl,%eax
139 pushl %eax
140 pushl $0 /* dummy unit to finish building intr frame */
141 incl _cnt+V_TRAP
142 orl $SWI_AST_MASK,%eax
143 movl %eax,_cpl
144 call _npxintr
145 incb _intr_nesting_level
146 MEXITCOUNT
147 jmp _doreti
148 #else /* NNPX > 0 */
149 pushl $0; TRAP(T_ARITHTRAP)
150 #endif /* NNPX > 0 */
151 IDTVEC(align)
152 TRAP(T_ALIGNFLT)
153
154 SUPERALIGN_TEXT
155 .globl _alltraps
156 _alltraps:
157 pushal
158 pushl %ds
159 pushl %es
160 alltraps_with_regs_pushed:
161 movl $KDSEL,%eax
162 movl %ax,%ds
163 movl %ax,%es
164 FAKE_MCOUNT(12*4(%esp))
165 calltrap:
166 FAKE_MCOUNT(_btrap) /* init "from" _btrap -> calltrap */
167 incl _cnt+V_TRAP
168 movl _cpl,%eax
169 movl %eax,%ebx /* keep orig. cpl here during trap() */
170 orl $SWI_AST_MASK,%eax
171 movl %eax,_cpl
172 call _trap
173
174 /*
175 * Return via _doreti to handle ASTs. Have to change trap frame
176 * to interrupt frame.
177 */
178 pushl %ebx /* cpl to restore */
179 subl $4,%esp
180 incb _intr_nesting_level
181 MEXITCOUNT
182 jmp _doreti
183
184 /*
185 * Call gate entry for syscall.
186 * The intersegment call has been set up to specify one dummy parameter.
187 * This leaves a place to put eflags so that the call frame can be
188 * converted to a trap frame. Note that the eflags is (semi-)bogusly
189 * pushed into (what will be) tf_err and then copied later into the
190 * final spot. It has to be done this way because esp can't be just
191 * temporarily altered for the pushfl - an interrupt might come in
192 * and clobber the saved cs/eip.
193 */
194 SUPERALIGN_TEXT
195 IDTVEC(syscall)
196 pushfl /* save eflags in tf_err for now */
197 subl $4,%esp /* skip over tf_trapno */
198 pushal
199 pushl %ds
200 pushl %es
201 movl $KDSEL,%eax /* switch to kernel segments */
202 movl %ax,%ds
203 movl %ax,%es
204 movl TF_ERR(%esp),%eax /* copy saved eflags to final spot */
205 movl %eax,TF_EFLAGS(%esp)
206 movl $7,TF_ERR(%esp) /* sizeof "lcall 7,0" */
207 FAKE_MCOUNT(12*4(%esp))
208 incl _cnt+V_SYSCALL
209 movl $SWI_AST_MASK,_cpl
210 call _syscall
211 /*
212 * Return via _doreti to handle ASTs.
213 */
214 pushl $0 /* cpl to restore */
215 subl $4,%esp
216 movb $1,_intr_nesting_level
217 MEXITCOUNT
218 jmp _doreti
219
220 /*
221 * Call gate entry for Linux/NetBSD syscall (int 0x80)
222 */
223 SUPERALIGN_TEXT
224 IDTVEC(int0x80_syscall)
225 subl $8,%esp /* skip over tf_trapno and tf_err */
226 pushal
227 pushl %ds
228 pushl %es
229 movl $KDSEL,%eax /* switch to kernel segments */
230 movl %ax,%ds
231 movl %ax,%es
232 movl $2,TF_ERR(%esp) /* sizeof "int 0x80" */
233 FAKE_MCOUNT(12*4(%esp))
234 incl _cnt+V_SYSCALL
235 movl $SWI_AST_MASK,_cpl
236 call _syscall
237 /*
238 * Return via _doreti to handle ASTs.
239 */
240 pushl $0 /* cpl to restore */
241 subl $4,%esp
242 movb $1,_intr_nesting_level
243 MEXITCOUNT
244 jmp _doreti
245
246 /*
247 * Include what was once config+isa-dependent code.
248 * XXX it should be in a stand-alone file. It's still icu-dependent and
249 * belongs in i386/isa.
250 */
251 #include "i386/isa/vector.s"
252
253 /*
254 * Include what was once icu-dependent code.
255 * XXX it should be merged into this file (also move the definition of
256 * imen to vector.s or isa.c).
257 * Before including it, set up a normal asm environment so that vector.s
258 * doesn't have to know that stuff is included after it.
259 */
260 .data
261 ALIGN_DATA
262 .text
263 SUPERALIGN_TEXT
264 #include "i386/isa/icu.s"
Cache object: c8586db24986d713b7bbab33d90f5cd7
|