subr_syscall.c revision 1431
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * the University of Utah, and William Jolitz.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed by the University of
19 *	California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 *	from: @(#)trap.c	7.4 (Berkeley) 5/13/91
37 *	$Id: trap.c,v 1.22 1994/04/07 10:51:00 davidg Exp $
38 */
39
40/*
41 * 386 Trap and System call handleing
42 */
43
44#include "isa.h"
45#include "npx.h"
46#include "ddb.h"
47#include "machine/cpu.h"
48#include "machine/psl.h"
49#include "machine/reg.h"
50#include "machine/eflags.h"
51
52#include "param.h"
53#include "systm.h"
54#include "proc.h"
55#include "user.h"
56#include "acct.h"
57#include "kernel.h"
58#ifdef KTRACE
59#include "ktrace.h"
60#endif
61
62#include "vm/vm_param.h"
63#include "vm/pmap.h"
64#include "vm/vm_map.h"
65#include "vm/vm_user.h"
66#include "vm/vm_page.h"
67#include "sys/vmmeter.h"
68
69#include "machine/trap.h"
70
71#ifdef	__GNUC__
72
73/*
74 * The "r" contraint could be "rm" except for fatal bugs in gas.  As usual,
75 * we omit the size from the mov instruction to avoid nonfatal bugs in gas.
76 */
77#define	read_gs()	({ u_short gs; __asm("mov %%gs,%0" : "=r" (gs)); gs; })
78#define	write_gs(newgs)	__asm("mov %0,%%gs" : : "r" ((u_short) newgs))
79
80#else	/* not __GNUC__ */
81
82u_short	read_gs		__P((void));
83void	write_gs	__P((/* promoted u_short */ int gs));
84
85#endif	/* __GNUC__ */
86
87extern int grow(struct proc *,int);
88
89struct	sysent sysent[];
90int	nsysent;
91
92#define MAX_TRAP_MSG		27
93char *trap_msg[] = {
94	"reserved addressing fault",		/*  0 T_RESADFLT */
95	"privileged instruction fault",		/*  1 T_PRIVINFLT */
96	"reserved operand fault",		/*  2 T_RESOPFLT */
97	"breakpoint instruction fault",		/*  3 T_BPTFLT */
98	"",					/*  4 unused */
99	"system call trap",			/*  5 T_SYSCALL */
100	"arithmetic trap",			/*  6 T_ARITHTRAP */
101	"system forced exception",		/*  7 T_ASTFLT */
102	"segmentation (limit) fault",		/*  8 T_SEGFLT */
103	"protection fault",			/*  9 T_PROTFLT */
104	"trace trap",				/* 10 T_TRCTRAP */
105	"",					/* 11 unused */
106	"page fault",				/* 12 T_PAGEFLT */
107	"page table fault",			/* 13 T_TABLEFLT */
108	"alignment fault",			/* 14 T_ALIGNFLT */
109	"kernel stack pointer not valid",	/* 15 T_KSPNOTVAL */
110	"bus error",				/* 16 T_BUSERR */
111	"kernel debugger fault",		/* 17 T_KDBTRAP */
112	"integer divide fault",			/* 18 T_DIVIDE */
113	"non-maskable interrupt trap",		/* 19 T_NMI */
114	"overflow trap",			/* 20 T_OFLOW */
115	"FPU bounds check fault",		/* 21 T_BOUND */
116	"FPU device not available",		/* 22 T_DNA */
117	"double fault",				/* 23 T_DOUBLEFLT */
118	"FPU operand fetch fault",		/* 24 T_FPOPFLT */
119	"invalid TSS fault",			/* 25 T_TSSFLT */
120	"segment not present fault",		/* 26 T_SEGNPFLT */
121	"stack fault",				/* 27 T_STKFLT */
122};
123
124#define pde_v(v) (PTD[((v)>>PD_SHIFT)&1023].pd_v)
125
126/*
127 * trap(frame):
128 *	Exception, fault, and trap interface to BSD kernel. This
129 * common code is called from assembly language IDT gate entry
130 * routines that prepare a suitable stack frame, and restore this
131 * frame after the exception has been processed. Note that the
132 * effect is as if the arguments were passed call by reference.
133 */
134
135/*ARGSUSED*/
136void
137trap(frame)
138	struct trapframe frame;
139{
140	register int i;
141	register struct proc *p = curproc;
142	struct timeval syst;
143	int ucode, type, code, eva, fault_type;
144
145	frame.tf_eflags &= ~PSL_NT;	/* clear nested trap XXX */
146	type = frame.tf_trapno;
147#if NDDB > 0
148	if (curpcb && curpcb->pcb_onfault) {
149		if (frame.tf_trapno == T_BPTFLT
150		    || frame.tf_trapno == T_TRCTRAP)
151			if (kdb_trap (type, 0, &frame))
152				return;
153	}
154#endif
155
156	if (curpcb == 0 || curproc == 0)
157		goto skiptoswitch;
158	if (curpcb->pcb_onfault && frame.tf_trapno != T_PAGEFLT) {
159		extern int _udatasel;
160
161		if (read_gs() != (u_short) _udatasel)
162			/*
163			 * Some user has corrupted %gs but we depend on it in
164			 * copyout() etc.  Fix it up and retry.
165			 *
166			 * (We don't preserve %fs or %gs, so users can change
167			 * them to either _ucodesel, _udatasel or a not-present
168			 * selector, possibly ORed with 0 to 3, making them
169			 * volatile for other users.  Not preserving them saves
170			 * time and doesn't lose functionality or open security
171			 * holes.)
172			 */
173			write_gs(_udatasel);
174		else
175copyfault:
176			frame.tf_eip = (int)curpcb->pcb_onfault;
177		return;
178	}
179
180	syst = p->p_stime;
181	if (ISPL(frame.tf_cs) == SEL_UPL) {
182		type |= T_USER;
183		p->p_regs = (int *)&frame;
184	}
185
186skiptoswitch:
187	ucode=0;
188	eva = rcr2();
189	code = frame.tf_err;
190
191	if ((type & ~T_USER) == T_PAGEFLT)
192		goto pfault;
193
194	switch (type) {
195	case T_SEGNPFLT|T_USER:
196	case T_STKFLT|T_USER:
197	case T_PROTFLT|T_USER:		/* protection fault */
198		ucode = code + BUS_SEGM_FAULT ;
199		i = SIGBUS;
200		break;
201
202	case T_PRIVINFLT|T_USER:	/* privileged instruction fault */
203	case T_RESADFLT|T_USER:		/* reserved addressing fault */
204	case T_RESOPFLT|T_USER:		/* reserved operand fault */
205	case T_FPOPFLT|T_USER:		/* coprocessor operand fault */
206		ucode = type &~ T_USER;
207		i = SIGILL;
208		break;
209
210	case T_ASTFLT|T_USER:		/* Allow process switch */
211		astoff();
212		cnt.v_soft++;
213		if ((p->p_flag & SOWEUPC) && p->p_stats->p_prof.pr_scale) {
214			addupc(frame.tf_eip, &p->p_stats->p_prof, 1);
215			p->p_flag &= ~SOWEUPC;
216		}
217		goto out;
218
219	case T_DNA|T_USER:
220#if NNPX > 0
221		/* if a transparent fault (due to context switch "late") */
222		if (npxdna()) return;
223#endif	/* NNPX > 0 */
224#if   defined(MATH_EMULATE) || defined(GPL_MATH_EMULATE)
225		i = math_emulate(&frame);
226		if (i == 0) return;
227#else	/* MATH_EMULATE || GPL_MATH_EMULATE */
228		panic("trap: math emulation necessary!");
229#endif	/* MATH_EMULATE || GPL_MATH_EMULATE */
230		ucode = FPE_FPU_NP_TRAP;
231		break;
232
233	case T_BOUND|T_USER:
234		ucode = FPE_SUBRNG_TRAP;
235		i = SIGFPE;
236		break;
237
238	case T_OFLOW|T_USER:
239		ucode = FPE_INTOVF_TRAP;
240		i = SIGFPE;
241		break;
242
243	case T_DIVIDE|T_USER:
244		ucode = FPE_INTDIV_TRAP;
245		i = SIGFPE;
246		break;
247
248	case T_ARITHTRAP|T_USER:
249		ucode = code;
250		i = SIGFPE;
251		break;
252
253	pfault:
254	case T_PAGEFLT:			/* allow page faults in kernel mode */
255	case T_PAGEFLT|T_USER:		/* page fault */
256	    {
257		vm_offset_t va;
258		struct vmspace *vm;
259		vm_map_t map = 0;
260		int rv = 0, oldflags;
261		vm_prot_t ftype;
262		unsigned v;
263		extern vm_map_t kernel_map;
264
265		va = trunc_page((vm_offset_t)eva);
266
267		/*
268		 * Don't allow user-mode faults in kernel address space
269		 */
270		if ((type == (T_PAGEFLT|T_USER)) && (va >= KERNBASE)) {
271			goto nogo;
272		}
273
274		if ((p == 0) || (type == T_PAGEFLT && va >= KERNBASE)) {
275			vm = 0;
276			map = kernel_map;
277		} else {
278			vm = p->p_vmspace;
279			map = &vm->vm_map;
280		}
281
282		if (code & PGEX_W)
283			ftype = VM_PROT_READ | VM_PROT_WRITE;
284		else
285			ftype = VM_PROT_READ;
286
287		oldflags = p->p_flag;
288		if (map != kernel_map) {
289			vm_offset_t pa;
290			vm_offset_t v = (vm_offset_t) vtopte(va);
291			vm_page_t ptepg;
292
293			/*
294			 * Keep swapout from messing with us during this
295			 *	critical time.
296			 */
297			p->p_flag |= SLOCK;
298
299			/*
300			 * Grow the stack if necessary
301			 */
302			if ((caddr_t)va > vm->vm_maxsaddr
303			    && (caddr_t)va < (caddr_t)USRSTACK) {
304				if (!grow(p, va)) {
305					rv = KERN_FAILURE;
306					p->p_flag &= ~SLOCK;
307					p->p_flag |= (oldflags & SLOCK);
308					goto nogo;
309				}
310			}
311
312			/*
313			 * Check if page table is mapped, if not,
314			 *	fault it first
315			 */
316
317			/* Fault the pte only if needed: */
318			*(volatile char *)v += 0;
319
320			ptepg = (vm_page_t) pmap_pte_vm_page(vm_map_pmap(map), v);
321			vm_page_hold(ptepg);
322
323			/* Fault in the user page: */
324			rv = vm_fault(map, va, ftype, FALSE);
325
326			vm_page_unhold(ptepg);
327
328			/*
329			 * page table pages don't need to be kept if they
330			 * are not held
331			 */
332			if( ptepg->hold_count == 0 && ptepg->wire_count == 0) {
333				pmap_page_protect( VM_PAGE_TO_PHYS(ptepg),
334					VM_PROT_NONE);
335				if( ptepg->flags & PG_CLEAN)
336					vm_page_free(ptepg);
337			}
338
339
340			p->p_flag &= ~SLOCK;
341			p->p_flag |= (oldflags & SLOCK);
342		} else {
343			/*
344			 * Since we know that kernel virtual address addresses
345			 * always have pte pages mapped, we just have to fault
346			 * the page.
347			 */
348			rv = vm_fault(map, va, ftype, FALSE);
349		}
350
351		if (rv == KERN_SUCCESS) {
352			if (type == T_PAGEFLT)
353				return;
354			goto out;
355		}
356nogo:
357		if (type == T_PAGEFLT) {
358			if (curpcb->pcb_onfault)
359				goto copyfault;
360
361			goto we_re_toast;
362		}
363		i = (rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV;
364
365		/* kludge to pass faulting virtual address to sendsig */
366		ucode = type &~ T_USER;
367		frame.tf_err = eva;
368
369		break;
370	    }
371
372#if NDDB == 0
373	case T_TRCTRAP:	 /* trace trap -- someone single stepping lcall's */
374		frame.tf_eflags &= ~PSL_T;
375
376			/* Q: how do we turn it on again? */
377		return;
378#endif
379
380	case T_BPTFLT|T_USER:		/* bpt instruction fault */
381	case T_TRCTRAP|T_USER:		/* trace trap */
382		frame.tf_eflags &= ~PSL_T;
383		i = SIGTRAP;
384		break;
385
386#if NISA > 0
387	case T_NMI:
388	case T_NMI|T_USER:
389#if NDDB > 0
390		/* NMI can be hooked up to a pushbutton for debugging */
391		printf ("NMI ... going to debugger\n");
392		if (kdb_trap (type, 0, &frame))
393			return;
394#endif
395		/* machine/parity/power fail/"kitchen sink" faults */
396		if (isa_nmi(code) == 0) return;
397		/* FALL THROUGH */
398#endif
399	default:
400	we_re_toast:
401
402		fault_type = type & ~T_USER;
403#if NDDB > 0
404		if ((fault_type == T_BPTFLT) || (fault_type == T_TRCTRAP)) {
405			if (kdb_trap (type, 0, &frame))
406				return;
407		}
408#endif
409		if (fault_type <= MAX_TRAP_MSG)
410			printf("\n\nFatal trap %d: %s while in %s mode\n",
411				fault_type, trap_msg[fault_type],
412				ISPL(frame.tf_cs) == SEL_UPL ? "user" : "kernel");
413		if (fault_type == T_PAGEFLT) {
414			printf("fault virtual address	= 0x%x\n", eva);
415			printf("fault code		= %s %s, %s\n",
416				code & PGEX_U ? "user" : "supervisor",
417				code & PGEX_W ? "write" : "read",
418				code & PGEX_P ? "protection violation" : "page not present");
419		}
420		printf("instruction pointer	= 0x%x\n", frame.tf_eip);
421		printf("processor eflags	= ");
422		if (frame.tf_eflags & EFL_TF)
423			printf("trace/trap, ");
424		if (frame.tf_eflags & EFL_IF)
425			printf("interrupt enabled, ");
426		if (frame.tf_eflags & EFL_NT)
427			printf("nested task, ");
428		if (frame.tf_eflags & EFL_RF)
429			printf("resume, ");
430		if (frame.tf_eflags & EFL_VM)
431			printf("vm86, ");
432		printf("IOPL = %d\n", (frame.tf_eflags & EFL_IOPL) >> 12);
433		printf("current process		= ");
434		if (curproc) {
435			printf("%d (%s)\n",
436			    curproc->p_pid, curproc->p_comm ?
437			    curproc->p_comm : "");
438		} else {
439			printf("Idle\n");
440		}
441		printf("interrupt mask		= ");
442		if ((cpl & net_imask) == net_imask)
443			printf("net ");
444		if ((cpl & tty_imask) == tty_imask)
445			printf("tty ");
446		if ((cpl & bio_imask) == bio_imask)
447			printf("bio ");
448		if (cpl == 0)
449			printf("none");
450		printf("\n");
451
452#ifdef KDB
453		if (kdb_trap(&psl))
454			return;
455#endif
456#if NDDB > 0
457		if (kdb_trap (type, 0, &frame))
458			return;
459#endif
460		if (fault_type <= MAX_TRAP_MSG)
461			panic(trap_msg[fault_type]);
462		else
463			panic("unknown/reserved trap");
464
465		/* NOTREACHED */
466	}
467
468	trapsignal(p, i, ucode);
469	if ((type & T_USER) == 0)
470		return;
471
472#ifdef DIAGNOSTIC
473	fault_type = type & ~T_USER;
474	if (fault_type <= MAX_TRAP_MSG) {
475		uprintf("fatal process exception: %s",
476			trap_msg[fault_type]);
477		if ((fault_type == T_PAGEFLT) || (fault_type == T_PROTFLT))
478			uprintf(", fault VA = 0x%x", eva);
479		uprintf("\n");
480	}
481#endif
482
483out:
484	while (i = CURSIG(p))
485		psig(i);
486	p->p_pri = p->p_usrpri;
487	if (want_resched) {
488		int s;
489		/*
490		 * Since we are curproc, clock will normally just change
491		 * our priority without moving us from one queue to another
492		 * (since the running process is not on a queue.)
493		 * If that happened after we setrq ourselves but before we
494		 * swtch()'ed, we might not be on the queue indicated by
495		 * our priority.
496		 */
497		s = splclock();
498		setrq(p);
499		p->p_stats->p_ru.ru_nivcsw++;
500		swtch();
501		splx(s);
502		while (i = CURSIG(p))
503			psig(i);
504	}
505	if (p->p_stats->p_prof.pr_scale) {
506		int ticks;
507		struct timeval *tv = &p->p_stime;
508
509		ticks = ((tv->tv_sec - syst.tv_sec) * 1000 +
510			(tv->tv_usec - syst.tv_usec) / 1000) / (tick / 1000);
511		if (ticks) {
512#ifdef PROFTIMER
513			extern int profscale;
514			addupc(frame.tf_eip, &p->p_stats->p_prof,
515			    ticks * profscale);
516#else
517			addupc(frame.tf_eip, &p->p_stats->p_prof, ticks);
518#endif
519		}
520	}
521	curpri = p->p_pri;
522}
523
524/*
525 * Compensate for 386 brain damage (missing URKR).
526 * This is a little simpler than the pagefault handler in trap() because
527 * it the page tables have already been faulted in and high addresses
528 * are thrown out early for other reasons.
529 */
530int trapwrite(addr)
531	unsigned addr;
532{
533	struct proc *p;
534	vm_offset_t va, v;
535	struct vmspace *vm;
536	int oldflags;
537	int rv;
538
539	va = trunc_page((vm_offset_t)addr);
540	/*
541	 * XXX - MAX is END.  Changed > to >= for temp. fix.
542	 */
543	if (va >= VM_MAXUSER_ADDRESS)
544		return (1);
545
546	p = curproc;
547	vm = p->p_vmspace;
548
549	oldflags = p->p_flag;
550	p->p_flag |= SLOCK;
551
552	if ((caddr_t)va >= vm->vm_maxsaddr
553	    && (caddr_t)va < (caddr_t)USRSTACK) {
554		if (!grow(p, va)) {
555			p->p_flag &= ~SLOCK;
556			p->p_flag |= (oldflags & SLOCK);
557			return (1);
558		}
559	}
560
561	v = trunc_page(vtopte(va));
562
563	/*
564	 * wire the pte page
565	 */
566	if (va < USRSTACK) {
567		vm_map_pageable(&vm->vm_map, v, round_page(v+1), FALSE);
568	}
569
570	/*
571	 * fault the data page
572	 */
573	rv = vm_fault(&vm->vm_map, va, VM_PROT_READ|VM_PROT_WRITE, FALSE);
574
575	/*
576	 * unwire the pte page
577	 */
578	if (va < USRSTACK) {
579		vm_map_pageable(&vm->vm_map, v, round_page(v+1), TRUE);
580	}
581
582	p->p_flag &= ~SLOCK;
583	p->p_flag |= (oldflags & SLOCK);
584
585	if (rv != KERN_SUCCESS)
586		return 1;
587
588	return (0);
589}
590
591/*
592 * syscall(frame):
593 *	System call request from POSIX system call gate interface to kernel.
594 * Like trap(), argument is call by reference.
595 */
596/*ARGSUSED*/
597void
598syscall(frame)
599	volatile struct trapframe frame;
600{
601	register int *locr0 = ((int *)&frame);
602	register caddr_t params;
603	register int i;
604	register struct sysent *callp;
605	register struct proc *p = curproc;
606	struct timeval syst;
607	int error, opc;
608	int args[8], rval[2];
609	int code;
610
611#ifdef lint
612	r0 = 0; r0 = r0; r1 = 0; r1 = r1;
613#endif
614	syst = p->p_stime;
615	if (ISPL(frame.tf_cs) != SEL_UPL)
616		panic("syscall");
617
618	code = frame.tf_eax;
619	p->p_regs = (int *)&frame;
620	params = (caddr_t)frame.tf_esp + sizeof (int) ;
621
622	/*
623	 * Reconstruct pc, assuming lcall $X,y is 7 bytes, as it is always.
624	 */
625	opc = frame.tf_eip - 7;
626	if (code == 0) {
627		code = fuword(params);
628		params += sizeof (int);
629	}
630	if (code < 0 || code >= nsysent)
631		callp = &sysent[0];
632	else
633		callp = &sysent[code];
634
635	if ((i = callp->sy_narg * sizeof (int)) &&
636	    (error = copyin(params, (caddr_t)args, (u_int)i))) {
637		frame.tf_eax = error;
638		frame.tf_eflags |= PSL_C;	/* carry bit */
639#ifdef KTRACE
640		if (KTRPOINT(p, KTR_SYSCALL))
641			ktrsyscall(p->p_tracep, code, callp->sy_narg, args);
642#endif
643		goto done;
644	}
645#ifdef KTRACE
646	if (KTRPOINT(p, KTR_SYSCALL))
647		ktrsyscall(p->p_tracep, code, callp->sy_narg, args);
648#endif
649	rval[0] = 0;
650	rval[1] = frame.tf_edx;
651/*pg("%d. s %d\n", p->p_pid, code);*/
652	error = (*callp->sy_call)(p, args, rval);
653	if (error == ERESTART)
654		frame.tf_eip = opc;
655	else if (error != EJUSTRETURN) {
656		if (error) {
657/*pg("error %d", error);*/
658			frame.tf_eax = error;
659			frame.tf_eflags |= PSL_C;	/* carry bit */
660		} else {
661			frame.tf_eax = rval[0];
662			frame.tf_edx = rval[1];
663			frame.tf_eflags &= ~PSL_C;	/* carry bit */
664		}
665	}
666	/* else if (error == EJUSTRETURN) */
667		/* nothing to do */
668done:
669	/*
670	 * Reinitialize proc pointer `p' as it may be different
671	 * if this is a child returning from fork syscall.
672	 */
673	p = curproc;
674	while (i = CURSIG(p))
675		psig(i);
676	p->p_pri = p->p_usrpri;
677	if (want_resched) {
678		int s;
679		/*
680		 * Since we are curproc, clock will normally just change
681		 * our priority without moving us from one queue to another
682		 * (since the running process is not on a queue.)
683		 * If that happened after we setrq ourselves but before we
684		 * swtch()'ed, we might not be on the queue indicated by
685		 * our priority.
686		 */
687		s = splclock();
688		setrq(p);
689		p->p_stats->p_ru.ru_nivcsw++;
690		swtch();
691		splx(s);
692		while (i = CURSIG(p))
693			psig(i);
694	}
695	if (p->p_stats->p_prof.pr_scale) {
696		int ticks;
697		struct timeval *tv = &p->p_stime;
698
699		ticks = ((tv->tv_sec - syst.tv_sec) * 1000 +
700			(tv->tv_usec - syst.tv_usec) / 1000) / (tick / 1000);
701		if (ticks) {
702#ifdef PROFTIMER
703			extern int profscale;
704			addupc(frame.tf_eip, &p->p_stats->p_prof,
705			    ticks * profscale);
706#else
707			addupc(frame.tf_eip, &p->p_stats->p_prof, ticks);
708#endif
709		}
710	}
711	curpri = p->p_pri;
712#ifdef KTRACE
713	if (KTRPOINT(p, KTR_SYSRET))
714		ktrsysret(p->p_tracep, code, error, rval[0]);
715#endif
716#ifdef	DIAGNOSTICx
717{ extern int _udatasel, _ucodesel;
718	if (frame.tf_ss != _udatasel)
719		printf("ss %x call %d\n", frame.tf_ss, code);
720	if ((frame.tf_cs&0xffff) != _ucodesel)
721		printf("cs %x call %d\n", frame.tf_cs, code);
722	if (frame.tf_eip > VM_MAXUSER_ADDRESS) {
723		printf("eip %x call %d\n", frame.tf_eip, code);
724		frame.tf_eip = 0;
725	}
726}
727#endif
728}
729