xref: /titanic_50/usr/src/uts/i86pc/ml/syscall_asm.s (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26/*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
27/*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
28/*	  All Rights Reserved					*/
29
30/*	Copyright (c) 1987, 1988 Microsoft Corporation		*/
31/*	  All Rights Reserved					*/
32
33#pragma ident	"%Z%%M%	%I%	%E% SMI"
34
35#include <sys/asm_linkage.h>
36#include <sys/asm_misc.h>
37#include <sys/regset.h>
38#include <sys/psw.h>
39#include <sys/x86_archext.h>
40#include <sys/machbrand.h>
41#include <sys/privregs.h>
42
43#if defined(__lint)
44
45#include <sys/types.h>
46#include <sys/thread.h>
47#include <sys/systm.h>
48
49#else	/* __lint */
50
51#include <sys/segments.h>
52#include <sys/pcb.h>
53#include <sys/trap.h>
54#include <sys/ftrace.h>
55#include <sys/traptrace.h>
56#include <sys/clock.h>
57#include <sys/panic.h>
58#include "assym.h"
59
60#endif	/* __lint */
61
62/*
63 * We implement two flavours of system call entry points
64 *
65 * -	{int,lcall}/iret	(i386)
66 * -	sysenter/sysexit	(Pentium II and beyond)
67 *
68 * The basic pattern used in the handlers is to check to see if we can
69 * do fast (simple) version of the system call; if we can't we use various
70 * C routines that handle corner cases and debugging.
71 *
72 * To reduce the amount of assembler replication, yet keep the system call
73 * implementations vaguely comprehensible, the common code in the body
74 * of the handlers is broken up into a set of preprocessor definitions
75 * below.
76 */
77
78/*
79 * When we have SYSCALLTRACE defined, we sneak an extra
80 * predicate into a couple of tests.
81 */
82#if defined(SYSCALLTRACE)
83#define	ORL_SYSCALLTRACE(r32)	\
84	orl	syscalltrace, r32
85#else
86#define	ORL_SYSCALLTRACE(r32)
87#endif
88
89/*
90 * This check is false whenever we want to go fast i.e.
91 *
92 *	if (code >= NSYSCALL ||
93 *	    t->t_pre_sys || (t->t_proc_flag & TP_WATCHPT) != 0)
94 *		do full version
95 * #ifdef SYSCALLTRACE
96 *	if (syscalltrace)
97 *		do full version
98 * #endif
99 *
100 * Preconditions:
101 * -	t	curthread
102 * -	code	contains the syscall number
103 * Postconditions:
104 * -	%ecx and %edi are smashed
105 * -	condition code flag ZF is cleared if pre-sys is too complex
106 */
107#define	CHECK_PRESYS_NE(t, code)		\
108	movzbl	T_PRE_SYS(t), %edi;		\
109	movzwl	T_PROC_FLAG(t), %ecx;		\
110	andl	$TP_WATCHPT, %ecx;		\
111	orl	%ecx, %edi;			\
112	cmpl	$NSYSCALL, code;		\
113	setae	%cl;				\
114	movzbl	%cl, %ecx;			\
115	orl	%ecx, %edi;			\
116	ORL_SYSCALLTRACE(%edi)
117
118/*
119 * When the brand's callback is invoked, the stack will look like this:
120 *	   --------------------------------------
121 *         | 'scratch space'			|
122 *         | user's %ebx			|
123 *         | user's %gs selector		|
124 *    |    | kernel's %gs selector		|
125 *    |    | lwp pointer			|
126 *    v    | user return address		|
127 *         | callback wrapper return addr 	|
128 *         --------------------------------------
129 *
130 * The lx brand (at least) uses each of these fields.
131 * If the brand code returns, we assume that we are meant to execute the
132 * normal system call path.
133 */
134#define	BRAND_CALLBACK(callback_id)					    \
135	subl	$4, %esp		/* save some scratch space	*/ ;\
136	pushl	%ebx			/* save %ebx to use for scratch	*/ ;\
137	pushl	%gs			/* save the user %gs		*/ ;\
138	movl	$KGS_SEL, %ebx						   ;\
139	pushl	%ebx			/* push kernel's %gs		*/ ;\
140	movw	%bx, %gs		/* switch to the kernel's %gs	*/ ;\
141	movl	%gs:CPU_THREAD, %ebx	/* load the thread pointer	*/ ;\
142	movl	T_LWP(%ebx), %ebx	/* load the lwp pointer		*/ ;\
143	pushl	%ebx			/* push the lwp pointer		*/ ;\
144	movl	LWP_PROCP(%ebx), %ebx	/* load the proc pointer	*/ ;\
145	movl	P_BRAND(%ebx), %ebx	/* load the brand pointer	*/ ;\
146	movl	B_MACHOPS(%ebx), %ebx	/* load the machops pointer	*/ ;\
147	movl	_CONST(_MUL(callback_id, CPTRSIZE))(%ebx), %ebx		   ;\
148	cmpl	$0, %ebx						   ;\
149	je	1f							   ;\
150	movl	%ebx, 16(%esp)		/* save callback to scratch	*/ ;\
151	movl	8(%esp), %ebx		/* grab the the user %gs	*/ ;\
152	movw	%bx, %gs		/* restore the user %gs		*/ ;\
153	movl	12(%esp), %ebx		/* restore %ebx			*/ ;\
154	pushl	20(%esp)		/* push the return address	*/ ;\
155	call	*20(%esp)		/* call callback		*/ ;\
156	addl	$4, %esp		/* get rid of ret addr		*/ ;\
1571:	movl	8(%esp), %ebx		/* grab the the user %gs	*/ ;\
158	movw	%bx, %gs		/* restore the user %gs		*/ ;\
159	movl	12(%esp), %ebx		/* restore user's %ebx		*/ ;\
160	addl	$20, %esp		/* restore stack ptr		*/
161
162#define	MSTATE_TRANSITION(from, to)		\
163	pushl	$to;				\
164	pushl	$from;				\
165	call	syscall_mstate;			\
166	addl	$0x8, %esp
167
168/*
169 * aka CPU_STATS_ADDQ(CPU, sys.syscall, 1)
170 * This must be called with interrupts or preemption disabled.
171 */
172#define	CPU_STATS_SYS_SYSCALL_INC			\
173	addl	$1, %gs:CPU_STATS_SYS_SYSCALL;		\
174	adcl	$0, %gs:CPU_STATS_SYS_SYSCALL+4;
175
176#if !defined(__lint)
177
178/*
179 * ASSERT(lwptoregs(lwp) == rp);
180 *
181 * this may seem obvious, but very odd things happen if this
182 * assertion is false
183 *
184 * Preconditions:
185 *	-none-
186 * Postconditions (if assertion is true):
187 *	%esi and %edi are smashed
188 */
189#if defined(DEBUG)
190
191__lwptoregs_msg:
192	.string	"%M%:%d lwptoregs(%p) [%p] != rp [%p]"
193
194#define	ASSERT_LWPTOREGS(t, rp)				\
195	movl	T_LWP(t), %esi;				\
196	movl	LWP_REGS(%esi), %edi;			\
197	cmpl	rp, %edi;				\
198	je	7f;					\
199	pushl	rp;					\
200	pushl	%edi;					\
201	pushl	%esi;					\
202	pushl	$__LINE__;				\
203	pushl	$__lwptoregs_msg;			\
204	call	panic;					\
2057:
206#else
207#define	ASSERT_LWPTOREGS(t, rp)
208#endif
209
210#endif	/* __lint */
211
212/*
213 * This is an assembler version of this fragment:
214 *
215 * lwp->lwp_state = LWP_SYS;
216 * lwp->lwp_ru.sysc++;
217 * lwp->lwp_eosys = NORMALRETURN;
218 * lwp->lwp_ap = argp;
219 *
220 * Preconditions:
221 *	-none-
222 * Postconditions:
223 *	-none-
224 */
225#define	SET_LWP(lwp, argp)				\
226	movb	$LWP_SYS, LWP_STATE(lwp);		\
227	addl	$1, LWP_RU_SYSC(lwp);			\
228	adcl	$0, LWP_RU_SYSC+4(lwp);			\
229	movb	$NORMALRETURN, LWP_EOSYS(lwp);		\
230	movl	argp, LWP_AP(lwp)
231
232/*
233 * Set up the thread, lwp, find the handler, and copy
234 * in the arguments from userland to the kernel stack.
235 *
236 * Preconditions:
237 * -	%eax contains the syscall number
238 * Postconditions:
239 * -	%eax contains a pointer to the sysent structure
240 * -	%ecx is zeroed
241 * -	%esi, %edi are smashed
242 * -	%esp is SYS_DROPped ready for the syscall
243 */
244#define	SIMPLE_SYSCALL_PRESYS(t, faultlabel)		\
245	movl	T_LWP(t), %esi;				\
246	movw	%ax, T_SYSNUM(t);			\
247	subl	$SYS_DROP, %esp;			\
248	shll	$SYSENT_SIZE_SHIFT, %eax;			\
249	SET_LWP(%esi, %esp);				\
250	leal	sysent(%eax), %eax;			\
251	movzbl	SY_NARG(%eax), %ecx;			\
252	testl	%ecx, %ecx;				\
253	jz	4f;					\
254	movl	%esp, %edi;				\
255	movl	SYS_DROP + REGOFF_UESP(%esp), %esi;	\
256	movl	$faultlabel, T_LOFAULT(t);		\
257	addl	$4, %esi;				\
258	rep;						\
259	  smovl;					\
260	movl	%ecx, T_LOFAULT(t);			\
2614:
262
263/*
264 * Check to see if a simple return is possible i.e.
265 *
266 *	if ((t->t_post_sys_ast | syscalltrace) != 0)
267 *		do full version;
268 *
269 * Preconditions:
270 * -	t is curthread
271 * Postconditions:
272 * -	condition code NE is set if post-sys is too complex
273 * -	rtmp is zeroed if it isn't (we rely on this!)
274 */
275#define	CHECK_POSTSYS_NE(t, rtmp)			\
276	xorl	rtmp, rtmp;				\
277	ORL_SYSCALLTRACE(rtmp);				\
278	orl	T_POST_SYS_AST(t), rtmp;		\
279	cmpl	$0, rtmp
280
281/*
282 * Fix up the lwp, thread, and eflags for a successful return
283 *
284 * Preconditions:
285 * -	zwreg contains zero
286 * Postconditions:
287 * -	%esp has been unSYS_DROPped
288 * -	%esi is smashed (points to lwp)
289 */
290#define	SIMPLE_SYSCALL_POSTSYS(t, zwreg)		\
291	movl	T_LWP(t), %esi;				\
292	addl	$SYS_DROP, %esp;			\
293	movw	zwreg, T_SYSNUM(t);			\
294	movb	$LWP_USER, LWP_STATE(%esi);		\
295	andb	$_CONST(0xffff - PS_C), REGOFF_EFL(%esp)
296
297/*
298 * System call handler.  This is the destination of both the call
299 * gate (lcall 0x27) _and_ the interrupt gate (int 0x91). For our purposes,
300 * there are two significant differences between an interrupt gate and a call
301 * gate:
302 *
303 * 1) An interrupt gate runs the handler with interrupts disabled, whereas a
304 * call gate runs the handler with whatever EFLAGS settings were in effect at
305 * the time of the call.
306 *
307 * 2) An interrupt gate pushes the contents of the EFLAGS register at the time
308 * of the interrupt onto the stack, whereas a call gate does not.
309 *
310 * Because we use the following code sequence to handle system calls made from
311 * _both_ a call gate _and_ an interrupt gate, these two differences must be
312 * respected. In regards to number 1) above, the handler must ensure that a sane
313 * EFLAGS snapshot is stored on the stack so that when the kernel returns back
314 * to the user via iret (which returns to user with the EFLAGS value saved on
315 * the stack), interrupts are re-enabled.
316 *
317 * In regards to number 2) above, the handler must always put a current snapshot
318 * of EFLAGS onto the stack in the appropriate place. If we came in via an
319 * interrupt gate, we will be clobbering the EFLAGS value that was pushed by
320 * the interrupt gate. This is OK, as the only bit that was changed by the
321 * hardware was the IE (interrupt enable) bit, which for an interrupt gate is
322 * now off. If we were to do nothing, the stack would contain an EFLAGS with
323 * IE off, resulting in us eventually returning back to the user with interrupts
324 * disabled. The solution is to turn on the IE bit in the EFLAGS value saved on
325 * the stack.
326 *
327 * Another subtlety which deserves mention is the difference between the two
328 * descriptors. The call gate descriptor is set to instruct the hardware to copy
329 * one parameter from the user stack to the kernel stack, whereas the interrupt
330 * gate descriptor doesn't use the parameter passing mechanism at all. The
331 * kernel doesn't actually use the parameter that is copied by the hardware; the
332 * only reason it does this is so that there is a space on the stack large
333 * enough to hold an EFLAGS register value, which happens to be in the correct
334 * place for use by iret when we go back to userland. How convenient.
335 *
336 * Stack frame description in syscall() and callees.
337 *
338 * |------------|
339 * | regs	| +(8*4)+4	registers
340 * |------------|
341 * | 8 args	| <- %esp	MAXSYSARGS (currently 8) arguments
342 * |------------|
343 *
344 */
345#define	SYS_DROP	_CONST(_MUL(MAXSYSARGS, 4))
346
347#if defined(__lint)
348
349/*ARGSUSED*/
350void
351sys_call()
352{}
353
354void
355_allsyscalls()
356{}
357
358size_t _allsyscalls_size;
359
360#else	/* __lint */
361
362	ENTRY_NP2(brand_sys_call, _allsyscalls)
363	BRAND_CALLBACK(BRAND_CB_SYSCALL)
364
365	ALTENTRY(sys_call)
366	/ on entry	eax = system call number
367
368	/ set up the stack to look as in reg.h
369	subl    $8, %esp        / pad the stack with ERRCODE and TRAPNO
370
371	SYSCALL_PUSH
372
373#ifdef TRAPTRACE
374	TRACE_PTR(%edi, %ebx, %ebx, %ecx, $TT_SYSCALL) / Uses labels "8" and "9"
375	TRACE_REGS(%edi, %esp, %ebx, %ecx)	/ Uses label "9"
376	pushl	%eax
377	TRACE_STAMP(%edi)		/ Clobbers %eax, %edx, uses "9"
378	popl	%eax
379	movl	%eax, TTR_SYSNUM(%edi)
380#endif
381
382_watch_do_syscall:
383	movl	%esp, %ebp
384
385	/ Interrupts may be enabled here, so we must make sure this thread
386	/ doesn't migrate off the CPU while it updates the CPU stats.
387	/
388	/ XXX This is only true if we got here via call gate thru the LDT for
389	/ old style syscalls. Perhaps this preempt++-- will go away soon?
390	movl	%gs:CPU_THREAD, %ebx
391	addb	$1, T_PREEMPT(%ebx)
392	CPU_STATS_SYS_SYSCALL_INC
393	subb	$1, T_PREEMPT(%ebx)
394
395	ENABLE_INTR_FLAGS
396
397	pushl	%eax				/ preserve across mstate call
398	MSTATE_TRANSITION(LMS_USER, LMS_SYSTEM)
399	popl	%eax
400
401	movl	%gs:CPU_THREAD, %ebx
402
403	ASSERT_LWPTOREGS(%ebx, %esp)
404
405	CHECK_PRESYS_NE(%ebx, %eax)
406	jne	_full_syscall_presys
407	SIMPLE_SYSCALL_PRESYS(%ebx, _syscall_fault)
408
409_syslcall_call:
410	call	*SY_CALLC(%eax)
411
412_syslcall_done:
413	CHECK_POSTSYS_NE(%ebx, %ecx)
414	jne	_full_syscall_postsys
415	SIMPLE_SYSCALL_POSTSYS(%ebx, %cx)
416	movl	%eax, REGOFF_EAX(%esp)
417	movl	%edx, REGOFF_EDX(%esp)
418
419	MSTATE_TRANSITION(LMS_SYSTEM, LMS_USER)
420
421	/
422	/ get back via iret
423	/
424	CLI(%edx)
425	jmp	sys_rtt_syscall
426
427_full_syscall_presys:
428	movl	T_LWP(%ebx), %esi
429	subl	$SYS_DROP, %esp
430	movb	$LWP_SYS, LWP_STATE(%esi)
431	pushl	%esp
432	pushl	%ebx
433	call	syscall_entry
434	addl	$8, %esp
435	jmp	_syslcall_call
436
437_full_syscall_postsys:
438	addl	$SYS_DROP, %esp
439	pushl	%edx
440	pushl	%eax
441	pushl	%ebx
442	call	syscall_exit
443	addl	$12, %esp
444	MSTATE_TRANSITION(LMS_SYSTEM, LMS_USER)
445	jmp	_sys_rtt
446
447_syscall_fault:
448	push	$0xe			/ EFAULT
449	call	set_errno
450	addl	$4, %esp
451	xorl	%eax, %eax		/ fake syscall_err()
452	xorl	%edx, %edx
453	jmp	_syslcall_done
454	SET_SIZE(sys_call)
455	SET_SIZE(brand_sys_call)
456
457#endif	/* __lint */
458
459/*
460 * System call handler via the sysenter instruction
461 *
462 * Here's how syscall entry usually works (see sys_call for details).
463 *
464 * There, the caller (lcall or int) in userland has arranged that:
465 *
466 * -	%eax contains the syscall number
467 * -	the user stack contains the args to the syscall
468 *
469 * Normally the lcall instruction into the call gate causes the processor
470 * to push %ss, %esp, <top-of-stack>, %cs, %eip onto the kernel stack.
471 * The sys_call handler then leaves space for r_trapno and r_err, and
472 * pusha's {%eax, %ecx, %edx, %ebx, %esp, %ebp, %esi, %edi}, followed
473 * by %ds, %es, %fs and %gs to capture a 'struct regs' on the stack.
474 * Then the kernel sets %ds, %es and %gs to kernel selectors, and finally
475 * extracts %efl and puts it into r_efl (which happens to live at the offset
476 * that <top-of-stack> was copied into). Note that the value in r_efl has
477 * the IF (interrupt enable) flag turned on. (The int instruction into the
478 * interrupt gate does essentially the same thing, only instead of
479 * <top-of-stack> we get eflags - see comment above.)
480 *
481 * In the sysenter case, things are a lot more primitive.
482 *
483 * The caller in userland has arranged that:
484 *
485 * -	%eax contains the syscall number
486 * -	%ecx contains the user %esp
487 * -	%edx contains the return %eip
488 * -	the user stack contains the args to the syscall
489 *
490 * e.g.
491 *	<args on the stack>
492 *	mov	$SYS_callnum, %eax
493 *	mov	$1f, %edx	/ return %eip
494 *	mov	%esp, %ecx	/ return %esp
495 *	sysenter
496 * 1:
497 *
498 * Hardware and (privileged) initialization code have arranged that by
499 * the time the sysenter instructions completes:
500 *
501 * - %eip is pointing to sys_sysenter (below).
502 * - %cs and %ss are set to kernel text and stack (data) selectors.
503 * - %esp is pointing at the lwp's stack
504 * - Interrupts have been disabled.
505 *
506 * The task for the sysenter handler is:
507 *
508 * -	recreate the same regs structure on the stack and the same
509 *	kernel state as if we'd come in on an lcall
510 * -	do the normal work of a syscall
511 * -	execute the system call epilogue, use sysexit to return to userland.
512 *
513 * Note that we are unable to return both "rvals" to userland with this
514 * call, as %edx is used by the sysexit instruction.
515 *
516 * One final complication in this routine is its interaction with
517 * single-stepping in a debugger.  For most of the system call mechanisms,
518 * the CPU automatically clears the single-step flag before we enter the
519 * kernel.  The sysenter mechanism does not clear the flag, so a user
520 * single-stepping through a libc routine may suddenly find him/herself
521 * single-stepping through the kernel.  To detect this, kmdb compares the
522 * trap %pc to the [brand_]sys_enter addresses on each single-step trap.
523 * If it finds that we have single-stepped to a sysenter entry point, it
524 * explicitly clears the flag and executes the sys_sysenter routine.
525 *
526 * One final complication in this final complication is the fact that we
527 * have two different entry points for sysenter: brand_sys_sysenter and
528 * sys_sysenter.  If we enter at brand_sys_sysenter and start single-stepping
529 * through the kernel with kmdb, we will eventually hit the instruction at
530 * sys_sysenter.  kmdb cannot distinguish between that valid single-step
531 * and the undesirable one mentioned above.  To avoid this situation, we
532 * simply add a jump over the instruction at sys_sysenter to make it
533 * impossible to single-step to it.
534 */
535#if defined(__lint)
536
537void
538sys_sysenter()
539{}
540
541#else	/* __lint */
542
543	ENTRY_NP(brand_sys_sysenter)
544	pushl	%edx
545	BRAND_CALLBACK(BRAND_CB_SYSENTER)
546	popl	%edx
547	/*
548	 * Jump over sys_sysenter to allow single-stepping as described
549	 * above.
550	 */
551	ja	1f
552
553	ALTENTRY(sys_sysenter)
554	nop
5551:
556	/
557	/ do what the call gate would've done to the stack ..
558	/
559	pushl	$UDS_SEL	/ (really %ss, but it's the same ..)
560	pushl	%ecx		/ userland makes this a copy of %esp
561	pushfl
562	orl	$PS_IE, (%esp)	/ turn interrupts on when we return to user
563	pushl	$UCS_SEL
564	pushl	%edx		/ userland makes this a copy of %eip
565	/
566	/ done.  finish building the stack frame
567	/
568	subl	$8, %esp	/ leave space for ERR and TRAPNO
569
570	SYSENTER_PUSH
571
572#ifdef TRAPTRACE
573	TRACE_PTR(%edi, %ebx, %ebx, %ecx, $TT_SYSENTER)	/ uses labels 8 and 9
574	TRACE_REGS(%edi, %esp, %ebx, %ecx)		/ uses label 9
575	pushl	%eax
576	TRACE_STAMP(%edi)		/ clobbers %eax, %edx, uses label 9
577	popl	%eax
578	movl	%eax, TTR_SYSNUM(%edi)
579#endif
580	movl	%esp, %ebp
581
582	CPU_STATS_SYS_SYSCALL_INC
583
584	ENABLE_INTR_FLAGS
585
586	pushl	%eax				/ preserve across mstate call
587	MSTATE_TRANSITION(LMS_USER, LMS_SYSTEM)
588	popl	%eax
589
590	movl	%gs:CPU_THREAD, %ebx
591
592	ASSERT_LWPTOREGS(%ebx, %esp)
593
594	CHECK_PRESYS_NE(%ebx, %eax)
595	jne	_full_syscall_presys
596	SIMPLE_SYSCALL_PRESYS(%ebx, _syscall_fault)
597
598_sysenter_call:
599	call	*SY_CALLC(%eax)
600
601_sysenter_done:
602	CHECK_POSTSYS_NE(%ebx, %ecx)
603	jne	_full_syscall_postsys
604	SIMPLE_SYSCALL_POSTSYS(%ebx, %cx)
605	/
606	/ sysexit uses %edx to restore %eip, so we can't use it
607	/ to return a value, sigh.
608	/
609	movl	%eax, REGOFF_EAX(%esp)
610	/ movl	%edx, REGOFF_EDX(%esp)
611
612	/ Interrupts will be turned on by the 'sti' executed just before
613	/ sysexit. The following ensures that restoring the user's EFLAGS
614	/ doesn't enable interrupts too soon.
615	andl	$_BITNOT(PS_IE), REGOFF_EFL(%esp)
616
617	MSTATE_TRANSITION(LMS_SYSTEM, LMS_USER)
618
619	cli
620
621	SYSCALL_POP
622
623	popl	%edx			/ sysexit: %edx -> %eip
624	addl	$4, %esp		/ get CS off the stack
625	popfl				/ EFL
626	popl	%ecx			/ sysexit: %ecx -> %esp
627	sti
628	sysexit
629	SET_SIZE(sys_sysenter)
630	SET_SIZE(brand_sys_sysenter)
631
632#endif	/* __lint */
633
634#if defined(__lint)
635/*
636 * System call via an int80.  This entry point is only used by the Linux
637 * application environment.  Unlike the sysenter path, there is no default
638 * action to take if no callback is registered for this process.
639 */
640void
641sys_int80()
642{}
643
644#else	/* __lint */
645
646	ENTRY_NP(brand_sys_int80)
647	BRAND_CALLBACK(BRAND_CB_INT80)
648
649	ALTENTRY(sys_int80)
650	/*
651	 * We hit an int80, but this process isn't of a brand with an int80
652	 * handler.  Bad process!  Make it look as if the INT failed.
653	 * Modify %eip to point before the INT, push the expected error
654	 * code and fake a GP fault.
655	 *
656	 */
657	subl	$2, (%esp)	/* int insn 2-bytes */
658	pushl	$_CONST(_MUL(T_INT80, GATE_DESC_SIZE) + 2)
659	jmp	gptrap			/ GP fault
660	SET_SIZE(sys_int80)
661	SET_SIZE(brand_sys_int80)
662
663/*
664 * Declare a uintptr_t which covers the entire pc range of syscall
665 * handlers for the stack walkers that need this.
666 */
667	.align	CPTRSIZE
668	.globl	_allsyscalls_size
669	.type	_allsyscalls_size, @object
670_allsyscalls_size:
671	.NWORD	. - _allsyscalls
672	SET_SIZE(_allsyscalls_size)
673
674#endif	/* __lint */
675
676/*
677 * These are the thread context handlers for lwps using sysenter/sysexit.
678 */
679
680#if defined(__lint)
681
682/*ARGSUSED*/
683void
684sep_save(void *ksp)
685{}
686
687/*ARGSUSED*/
688void
689sep_restore(void *ksp)
690{}
691
692#else	/* __lint */
693
694	/*
695	 * setting this value to zero as we switch away causes the
696	 * stack-pointer-on-sysenter to be NULL, ensuring that we
697	 * don't silently corrupt another (preempted) thread stack
698	 * when running an lwp that (somehow) didn't get sep_restore'd
699	 */
700	ENTRY_NP(sep_save)
701	xorl	%edx, %edx
702	xorl	%eax, %eax
703	movl	$MSR_INTC_SEP_ESP, %ecx
704	wrmsr
705	ret
706	SET_SIZE(sep_save)
707
708	/*
709	 * Update the kernel stack pointer as we resume onto this cpu.
710	 */
711	ENTRY_NP(sep_restore)
712	movl	4(%esp), %eax			/* per-lwp kernel sp */
713	xorl	%edx, %edx
714	movl	$MSR_INTC_SEP_ESP, %ecx
715	wrmsr
716	ret
717	SET_SIZE(sep_restore)
718
719#endif	/* __lint */
720
721/*
722 * Call syscall().  Called from trap() on watchpoint at lcall 0,7
723 */
724
725#if defined(__lint)
726
727void
728watch_syscall(void)
729{}
730
731#else	/* __lint */
732
733	ENTRY_NP(watch_syscall)
734	CLI(%eax)
735	movl	%gs:CPU_THREAD, %ebx
736	movl	T_STACK(%ebx), %esp		/ switch to the thread stack
737	movl	REGOFF_EAX(%esp), %eax		/ recover original syscall#
738	jmp	_watch_do_syscall
739	SET_SIZE(watch_syscall)
740
741#endif	/* __lint */
742