xref: /titanic_41/usr/src/uts/intel/ia32/os/sundep.c (revision 4610e4a00999c6d2291b3fc263926b890ec500a5)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
28 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T   */
29 /*	All Rights Reserved   */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/sysmacros.h>
36 #include <sys/signal.h>
37 #include <sys/systm.h>
38 #include <sys/user.h>
39 #include <sys/mman.h>
40 #include <sys/class.h>
41 #include <sys/proc.h>
42 #include <sys/procfs.h>
43 #include <sys/buf.h>
44 #include <sys/kmem.h>
45 #include <sys/cred.h>
46 #include <sys/archsystm.h>
47 #include <sys/vmparam.h>
48 #include <sys/prsystm.h>
49 #include <sys/reboot.h>
50 #include <sys/uadmin.h>
51 #include <sys/vfs.h>
52 #include <sys/vnode.h>
53 #include <sys/file.h>
54 #include <sys/session.h>
55 #include <sys/ucontext.h>
56 #include <sys/dnlc.h>
57 #include <sys/var.h>
58 #include <sys/cmn_err.h>
59 #include <sys/debugreg.h>
60 #include <sys/thread.h>
61 #include <sys/vtrace.h>
62 #include <sys/consdev.h>
63 #include <sys/psw.h>
64 #include <sys/regset.h>
65 #include <sys/privregs.h>
66 #include <sys/stack.h>
67 #include <sys/swap.h>
68 #include <vm/hat.h>
69 #include <vm/anon.h>
70 #include <vm/as.h>
71 #include <vm/page.h>
72 #include <vm/seg.h>
73 #include <vm/seg_kmem.h>
74 #include <vm/seg_map.h>
75 #include <vm/seg_vn.h>
76 #include <sys/exec.h>
77 #include <sys/acct.h>
78 #include <sys/core.h>
79 #include <sys/corectl.h>
80 #include <sys/modctl.h>
81 #include <sys/tuneable.h>
82 #include <c2/audit.h>
83 #include <sys/bootconf.h>
84 #include <sys/dumphdr.h>
85 #include <sys/promif.h>
86 #include <sys/systeminfo.h>
87 #include <sys/kdi.h>
88 #include <sys/contract_impl.h>
89 #include <sys/x86_archext.h>
90 #include <sys/segments.h>
91 
92 /*
93  * Compare the version of boot that boot says it is against
94  * the version of boot the kernel expects.
95  */
96 int
97 check_boot_version(int boots_version)
98 {
99 	if (boots_version == BO_VERSION)
100 		return (0);
101 
102 	prom_printf("Wrong boot interface - kernel needs v%d found v%d\n",
103 	    BO_VERSION, boots_version);
104 	prom_panic("halting");
105 	/*NOTREACHED*/
106 }
107 
108 /*
109  * Process the physical installed list for boot.
110  * Finds:
111  * 1) the pfn of the highest installed physical page,
112  * 2) the number of pages installed
113  * 3) the number of distinct contiguous regions these pages fall into.
114  */
115 void
116 installed_top_size(
117 	struct memlist *list,	/* pointer to start of installed list */
118 	pfn_t *high_pfn,	/* return ptr for top value */
119 	pgcnt_t *pgcnt,		/* return ptr for sum of installed pages */
120 	int	*ranges)	/* return ptr for the count of contig. ranges */
121 {
122 	pfn_t top = 0;
123 	pgcnt_t sumpages = 0;
124 	pfn_t highp;		/* high page in a chunk */
125 	int cnt = 0;
126 
127 	for (; list; list = list->next) {
128 		++cnt;
129 		highp = (list->address + list->size - 1) >> PAGESHIFT;
130 		if (top < highp)
131 			top = highp;
132 		sumpages += btop(list->size);
133 	}
134 
135 	*high_pfn = top;
136 	*pgcnt = sumpages;
137 	*ranges = cnt;
138 }
139 
140 /*
141  * Copy in a memory list from boot to kernel, with a filter function
142  * to remove pages. The filter function can increase the address and/or
143  * decrease the size to filter out pages.  It will also align addresses and
144  * sizes to PAGESIZE.
145  */
146 void
147 copy_memlist_filter(
148 	struct memlist *src,
149 	struct memlist **dstp,
150 	void (*filter)(uint64_t *, uint64_t *))
151 {
152 	struct memlist *dst, *prev;
153 	uint64_t addr;
154 	uint64_t size;
155 	uint64_t eaddr;
156 
157 	dst = *dstp;
158 	prev = dst;
159 
160 	/*
161 	 * Move through the memlist applying a filter against
162 	 * each range of memory. Note that we may apply the
163 	 * filter multiple times against each memlist entry.
164 	 */
165 	for (; src; src = src->next) {
166 		addr = P2ROUNDUP(src->address, PAGESIZE);
167 		eaddr = P2ALIGN(src->address + src->size, PAGESIZE);
168 		while (addr < eaddr) {
169 			size = eaddr - addr;
170 			if (filter != NULL)
171 				filter(&addr, &size);
172 			if (size == 0)
173 				break;
174 			dst->address = addr;
175 			dst->size = size;
176 			dst->next = 0;
177 			if (prev == dst) {
178 				dst->prev = 0;
179 				dst++;
180 			} else {
181 				dst->prev = prev;
182 				prev->next = dst;
183 				dst++;
184 				prev++;
185 			}
186 			addr += size;
187 		}
188 	}
189 
190 	*dstp = dst;
191 }
192 
193 /*
194  * Kernel setup code, called from startup().
195  */
196 void
197 kern_setup1(void)
198 {
199 	proc_t *pp;
200 
201 	pp = &p0;
202 
203 	proc_sched = pp;
204 
205 	/*
206 	 * Initialize process 0 data structures
207 	 */
208 	pp->p_stat = SRUN;
209 	pp->p_flag = SSYS;
210 
211 	pp->p_pidp = &pid0;
212 	pp->p_pgidp = &pid0;
213 	pp->p_sessp = &session0;
214 	pp->p_tlist = &t0;
215 	pid0.pid_pglink = pp;
216 	pid0.pid_pgtail = pp;
217 
218 	/*
219 	 * XXX - we asssume that the u-area is zeroed out except for
220 	 * ttolwp(curthread)->lwp_regs.
221 	 */
222 	u.u_cmask = (mode_t)CMASK;
223 
224 	thread_init();		/* init thread_free list */
225 	pid_init();		/* initialize pid (proc) table */
226 	contract_init();	/* initialize contracts */
227 
228 	init_pages_pp_maximum();
229 }
230 
231 /*
232  * Load a procedure into a thread.
233  */
234 void
235 thread_load(kthread_t *t, void (*start)(), caddr_t arg, size_t len)
236 {
237 	caddr_t sp;
238 	size_t framesz;
239 	caddr_t argp;
240 	long *p;
241 	extern void thread_start();
242 
243 	/*
244 	 * Push a "c" call frame onto the stack to represent
245 	 * the caller of "start".
246 	 */
247 	sp = t->t_stk;
248 	ASSERT(((uintptr_t)t->t_stk & (STACK_ENTRY_ALIGN - 1)) == 0);
249 	if (len != 0) {
250 		/*
251 		 * the object that arg points at is copied into the
252 		 * caller's frame.
253 		 */
254 		framesz = SA(len);
255 		sp -= framesz;
256 		ASSERT(sp > t->t_stkbase);
257 		argp = sp + SA(MINFRAME);
258 		bcopy(arg, argp, len);
259 		arg = argp;
260 	}
261 	/*
262 	 * Set up arguments (arg and len) on the caller's stack frame.
263 	 */
264 	p = (long *)sp;
265 
266 	*--p = 0;		/* fake call */
267 	*--p = 0;		/* null frame pointer terminates stack trace */
268 	*--p = (long)len;
269 	*--p = (intptr_t)arg;
270 	*--p = (intptr_t)start;
271 
272 	/*
273 	 * initialize thread to resume at thread_start() which will
274 	 * turn around and invoke (*start)(arg, len).
275 	 */
276 	t->t_pc = (uintptr_t)thread_start;
277 	t->t_sp = (uintptr_t)p;
278 
279 	ASSERT((t->t_sp & (STACK_ENTRY_ALIGN - 1)) == 0);
280 }
281 
282 /*
283  * load user registers into lwp.
284  */
285 /*ARGSUSED2*/
286 void
287 lwp_load(klwp_t *lwp, gregset_t grp, uintptr_t thrptr)
288 {
289 	struct regs *rp = lwptoregs(lwp);
290 
291 	setgregs(lwp, grp);
292 	rp->r_ps = PSL_USER;
293 
294 	/*
295 	 * For 64-bit lwps, we allow one magic %fs selector value, and one
296 	 * magic %gs selector to point anywhere in the address space using
297 	 * %fsbase and %gsbase behind the scenes.  libc uses %fs to point
298 	 * at the ulwp_t structure.
299 	 *
300 	 * For 32-bit lwps, libc wedges its lwp thread pointer into the
301 	 * ucontext ESP slot (which is otherwise irrelevant to setting a
302 	 * ucontext) and LWPGS_SEL value into gregs[REG_GS].  This is so
303 	 * syslwp_create() can atomically setup %gs.
304 	 *
305 	 * See setup_context() in libc.
306 	 */
307 #ifdef _SYSCALL32_IMPL
308 	if (lwp_getdatamodel(lwp) == DATAMODEL_ILP32) {
309 		if (grp[REG_GS] == LWPGS_SEL)
310 			(void) lwp_setprivate(lwp, _LWP_GSBASE, thrptr);
311 	}
312 #else
313 	if (grp[GS] == LWPGS_SEL)
314 		(void) lwp_setprivate(lwp, _LWP_GSBASE, thrptr);
315 #endif
316 
317 	lwp->lwp_eosys = JUSTRETURN;
318 	lwptot(lwp)->t_post_sys = 1;
319 }
320 
321 /*
322  * set syscall()'s return values for a lwp.
323  */
324 void
325 lwp_setrval(klwp_t *lwp, int v1, int v2)
326 {
327 	lwptoregs(lwp)->r_ps &= ~PS_C;
328 	lwptoregs(lwp)->r_r0 = v1;
329 	lwptoregs(lwp)->r_r1 = v2;
330 }
331 
332 /*
333  * set syscall()'s return values for a lwp.
334  */
335 void
336 lwp_setsp(klwp_t *lwp, caddr_t sp)
337 {
338 	lwptoregs(lwp)->r_sp = (intptr_t)sp;
339 }
340 
341 /*
342  * Copy regs from parent to child.
343  */
344 void
345 lwp_forkregs(klwp_t *lwp, klwp_t *clwp)
346 {
347 #if defined(__amd64)
348 	clwp->lwp_pcb.pcb_flags |= RUPDATE_PENDING;
349 	lwptot(clwp)->t_post_sys = 1;
350 #endif
351 	bcopy(lwp->lwp_regs, clwp->lwp_regs, sizeof (struct regs));
352 }
353 
354 /*
355  * This function is currently unused on x86.
356  */
357 /*ARGSUSED*/
358 void
359 lwp_freeregs(klwp_t *lwp, int isexec)
360 {}
361 
362 /*
363  * This function is currently unused on x86.
364  */
365 void
366 lwp_pcb_exit(void)
367 {}
368 
369 /*
370  * Lwp context ops for segment registers.
371  */
372 
373 /*
374  * Every time we come into the kernel (syscall, interrupt or trap
375  * but not fast-traps) we capture the current values of the user's
376  * segment registers into the lwp's reg structure. This includes
377  * lcall for i386 generic system call support since it is handled
378  * as a segment-not-present trap.
379  *
380  * Here we save the current values from the lwp regs into the pcb
381  * and set the RUPDATE_PENDING bit to tell the rest of the kernel
382  * that the pcb copy of the segment registers is the current one.
383  * This ensures the lwp's next trip to user land via update_sregs.
384  * Finally we set t_post_sys to ensure that no system call fast-path's
385  * its way out of the kernel via sysret.
386  *
387  * (This means that we need to have interrupts disabled when we test
388  * t->t_post_sys in the syscall handlers; if the test fails, we need
389  * to keep interrupts disabled until we return to userland so we can't
390  * be switched away.)
391  *
392  * As a result of all this, we don't really have to do a whole lot if
393  * the thread is just mucking about in the kernel, switching on and
394  * off the cpu for whatever reason it feels like. And yet we still
395  * preserve fast syscalls, cause if we -don't- get descheduled,
396  * we never come here either.
397  */
398 
399 #define	VALID_LWP_DESC(udp) ((udp)->usd_type == SDT_MEMRWA && \
400 	    (udp)->usd_p == 1 && (udp)->usd_dpl == SEL_UPL)
401 
402 void
403 lwp_segregs_save(klwp_t *lwp)
404 {
405 #if defined(__amd64)
406 	pcb_t *pcb = &lwp->lwp_pcb;
407 	struct regs *rp;
408 
409 	ASSERT(VALID_LWP_DESC(&pcb->pcb_fsdesc));
410 	ASSERT(VALID_LWP_DESC(&pcb->pcb_gsdesc));
411 
412 	if ((pcb->pcb_flags & RUPDATE_PENDING) == 0) {
413 		rp = lwptoregs(lwp);
414 
415 		/*
416 		 * If there's no update already pending, capture the current
417 		 * %ds/%es/%fs/%gs values from lwp's regs in case the user
418 		 * changed them; %fsbase and %gsbase are privileged so the
419 		 * kernel versions of these registers in pcb_fsbase and
420 		 * pcb_gsbase are always up-to-date.
421 		 */
422 		pcb->pcb_ds = rp->r_ds;
423 		pcb->pcb_es = rp->r_es;
424 		pcb->pcb_fs = rp->r_fs;
425 		pcb->pcb_gs = rp->r_gs;
426 		pcb->pcb_flags |= RUPDATE_PENDING;
427 		lwp->lwp_thread->t_post_sys = 1;
428 	}
429 #endif	/* __amd64 */
430 
431 	ASSERT(bcmp(&CPU->cpu_gdt[GDT_LWPFS], &lwp->lwp_pcb.pcb_fsdesc,
432 	    sizeof (lwp->lwp_pcb.pcb_fsdesc)) == 0);
433 	ASSERT(bcmp(&CPU->cpu_gdt[GDT_LWPGS], &lwp->lwp_pcb.pcb_gsdesc,
434 	    sizeof (lwp->lwp_pcb.pcb_gsdesc)) == 0);
435 }
436 
437 /*
438  * Restore lwp private fs and gs segment descriptors
439  * on current cpu's GDT.
440  */
441 static void
442 lwp_segregs_restore(klwp_t *lwp)
443 {
444 	cpu_t *cpu = CPU;
445 	pcb_t *pcb = &lwp->lwp_pcb;
446 
447 	ASSERT(VALID_LWP_DESC(&pcb->pcb_fsdesc));
448 	ASSERT(VALID_LWP_DESC(&pcb->pcb_gsdesc));
449 
450 	cpu->cpu_gdt[GDT_LWPFS] = pcb->pcb_fsdesc;
451 	cpu->cpu_gdt[GDT_LWPGS] = pcb->pcb_gsdesc;
452 
453 #if defined(__amd64)
454 	/*
455 	 * Make it impossible for a process to change its data model.
456 	 * We do this by toggling the present bits for the 32 and
457 	 * 64-bit user code descriptors. That way if a user lwp attempts
458 	 * to change its data model (by using the wrong code descriptor in
459 	 * %cs) it will fault immediately. This also allows us to simplify
460 	 * assertions and checks in the kernel.
461 	 */
462 	cpu->cpu_gdt[GDT_UCODE].usd_p = 1;
463 	cpu->cpu_gdt[GDT_U32CODE].usd_p = 0;
464 #endif	/* __amd64 */
465 }
466 
467 #ifdef _SYSCALL32_IMPL
468 
469 static void
470 lwp_segregs_restore32(klwp_t *lwp)
471 {
472 	cpu_t *cpu = CPU;
473 	pcb_t *pcb = &lwp->lwp_pcb;
474 
475 	ASSERT(VALID_LWP_DESC(&pcb->pcb_fsdesc));
476 	ASSERT(VALID_LWP_DESC(&pcb->pcb_gsdesc));
477 
478 	cpu->cpu_gdt[GDT_LWPFS] = pcb->pcb_fsdesc;
479 	cpu->cpu_gdt[GDT_LWPGS] = pcb->pcb_gsdesc;
480 	cpu->cpu_gdt[GDT_UCODE].usd_p = 0;
481 	cpu->cpu_gdt[GDT_U32CODE].usd_p = 1;
482 }
483 
484 #endif	/* _SYSCALL32_IMPL */
485 
486 /*
487  * Add any lwp-associated context handlers to the lwp at the beginning
488  * of the lwp's useful life.
489  *
490  * All paths which create lwp's invoke lwp_create(); lwp_create()
491  * invokes lwp_stk_init() which initializes the stack, sets up
492  * lwp_regs, and invokes this routine.
493  *
494  * All paths which destroy lwp's invoke lwp_exit() to rip the lwp
495  * apart and put it on 'lwp_deathrow'; if the lwp is destroyed it
496  * ends up in thread_free() which invokes freectx(t, 0) before
497  * invoking lwp_stk_fini().  When the lwp is recycled from death
498  * row, lwp_stk_fini() is invoked, then thread_free(), and thus
499  * freectx(t, 0) as before.
500  *
501  * In the case of exec, the surviving lwp is thoroughly scrubbed
502  * clean; exec invokes freectx(t, 1) to destroy associated contexts.
503  * On the way back to the new image, it invokes setregs() which
504  * in turn invokes this routine.
505  */
506 void
507 lwp_installctx(klwp_t *lwp)
508 {
509 	kthread_t *t = lwptot(lwp);
510 	int thisthread = t == curthread;
511 #ifdef _SYSCALL32_IMPL
512 	void (*restop)(klwp_t *) = lwp_getdatamodel(lwp) == DATAMODEL_NATIVE ?
513 	    lwp_segregs_restore : lwp_segregs_restore32;
514 #else
515 	void (*restop)(klwp_t *) = lwp_segregs_restore;
516 #endif
517 
518 	/*
519 	 * Install the basic lwp context handlers on each lwp.
520 	 *
521 	 * On the amd64 kernel, the context handlers are responsible for
522 	 * virtualizing %ds, %es, %fs, and %gs to the lwp.  The register
523 	 * values are only ever changed via sys_rtt when the
524 	 * RUPDATE_PENDING bit is set.  Only sys_rtt gets to clear the bit.
525 	 *
526 	 * On the i386 kernel, the context handlers are responsible for
527 	 * virtualizing %gs/%fs to the lwp by updating the per-cpu GDTs
528 	 */
529 	ASSERT(removectx(t, lwp, lwp_segregs_save, restop,
530 	    NULL, NULL, NULL, NULL) == 0);
531 	if (thisthread)
532 		kpreempt_disable();
533 	installctx(t, lwp, lwp_segregs_save, restop,
534 	    NULL, NULL, NULL, NULL);
535 	if (thisthread) {
536 		/*
537 		 * Since we're the right thread, set the values in the GDT
538 		 */
539 		restop(lwp);
540 		kpreempt_enable();
541 	}
542 
543 	/*
544 	 * If we have sysenter/sysexit instructions enabled, we need
545 	 * to ensure that the hardware mechanism is kept up-to-date with the
546 	 * lwp's kernel stack pointer across context switches.
547 	 *
548 	 * sep_save zeros the sysenter stack pointer msr; sep_restore sets
549 	 * it to the lwp's kernel stack pointer (kstktop).
550 	 */
551 	if (x86_feature & X86_SEP) {
552 #if defined(__amd64)
553 		caddr_t kstktop = (caddr_t)lwp->lwp_regs;
554 #elif defined(__i386)
555 		caddr_t kstktop = ((caddr_t)lwp->lwp_regs - MINFRAME) +
556 		    SA(sizeof (struct regs) + MINFRAME);
557 #endif
558 		ASSERT(removectx(t, kstktop,
559 		    sep_save, sep_restore, NULL, NULL, NULL, NULL) == 0);
560 
561 		if (thisthread)
562 			kpreempt_disable();
563 		installctx(t, kstktop,
564 		    sep_save, sep_restore, NULL, NULL, NULL, NULL);
565 		if (thisthread) {
566 			/*
567 			 * We're the right thread, so set the stack pointer
568 			 * for the first sysenter instruction to use
569 			 */
570 			sep_restore(kstktop);
571 			kpreempt_enable();
572 		}
573 	}
574 }
575 
576 /*
577  * Clear registers on exec(2).
578  */
579 void
580 setregs(uarg_t *args)
581 {
582 	struct regs *rp;
583 	kthread_t *t = curthread;
584 	klwp_t *lwp = ttolwp(t);
585 	pcb_t *pcb = &lwp->lwp_pcb;
586 	greg_t sp;
587 
588 	/*
589 	 * Initialize user registers
590 	 */
591 	(void) save_syscall_args();	/* copy args from registers first */
592 	rp = lwptoregs(lwp);
593 	sp = rp->r_sp;
594 	bzero(rp, sizeof (*rp));
595 
596 	rp->r_ss = UDS_SEL;
597 	rp->r_sp = sp;
598 	rp->r_pc = args->entry;
599 	rp->r_ps = PSL_USER;
600 
601 #if defined(__amd64)
602 
603 	pcb->pcb_fs = pcb->pcb_gs = 0;
604 	pcb->pcb_fsbase = pcb->pcb_gsbase = 0;
605 
606 	if (ttoproc(t)->p_model == DATAMODEL_NATIVE) {
607 		cpu_t *cpu;
608 
609 		rp->r_cs = UCS_SEL;
610 
611 		/*
612 		 * Only allow 64-bit user code descriptor to be present.
613 		 */
614 		kpreempt_disable();
615 		cpu = CPU;
616 		cpu->cpu_gdt[GDT_UCODE].usd_p = 1;
617 		cpu->cpu_gdt[GDT_U32CODE].usd_p = 0;
618 		kpreempt_enable();
619 
620 		/*
621 		 * Arrange that the virtualized %fs and %gs GDT descriptors
622 		 * have a well-defined initial state (present, ring 3
623 		 * and of type data).
624 		 */
625 		pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_udesc;
626 
627 		/*
628 		 * thrptr is either NULL or a value used by DTrace.
629 		 * 64-bit processes use %fs as their "thread" register.
630 		 */
631 		if (args->thrptr)
632 			(void) lwp_setprivate(lwp, _LWP_FSBASE, args->thrptr);
633 
634 	} else {
635 		cpu_t *cpu;
636 
637 		rp->r_cs = U32CS_SEL;
638 		rp->r_ds = rp->r_es = UDS_SEL;
639 
640 		/*
641 		 * only allow 32-bit user code selector to be present.
642 		 */
643 		kpreempt_disable();
644 		cpu = CPU;
645 		cpu->cpu_gdt[GDT_UCODE].usd_p = 0;
646 		cpu->cpu_gdt[GDT_U32CODE].usd_p = 1;
647 		kpreempt_enable();
648 
649 		pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_u32desc;
650 
651 		/*
652 		 * thrptr is either NULL or a value used by DTrace.
653 		 * 32-bit processes use %gs as their "thread" register.
654 		 */
655 		if (args->thrptr)
656 			(void) lwp_setprivate(lwp, _LWP_GSBASE, args->thrptr);
657 
658 	}
659 
660 
661 	pcb->pcb_ds = rp->r_ds;
662 	pcb->pcb_es = rp->r_es;
663 	pcb->pcb_flags |= RUPDATE_PENDING;
664 
665 #elif defined(__i386)
666 
667 	rp->r_cs = UCS_SEL;
668 	rp->r_ds = rp->r_es = UDS_SEL;
669 
670 	/*
671 	 * Arrange that the virtualized %fs and %gs GDT descriptors
672 	 * have a well-defined initial state (present, ring 3
673 	 * and of type data).
674 	 */
675 	pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_udesc;
676 
677 
678 	/*
679 	 * For %gs we need to reset LWP_GSBASE in pcb and the
680 	 * per-cpu GDT descriptor. thrptr is either NULL
681 	 * or a value used by DTrace.
682 	 */
683 	if (args->thrptr)
684 		(void) lwp_setprivate(lwp, _LWP_GSBASE, args->thrptr);
685 #endif
686 
687 	lwp->lwp_eosys = JUSTRETURN;
688 	t->t_post_sys = 1;
689 
690 	/*
691 	 * Here we initialize minimal fpu state.
692 	 * The rest is done at the first floating
693 	 * point instruction that a process executes.
694 	 */
695 	pcb->pcb_fpu.fpu_flags = 0;
696 
697 	/*
698 	 * Add the lwp context handlers that virtualize segment registers,
699 	 * and/or system call stacks etc.
700 	 */
701 	lwp_installctx(lwp);
702 }
703 
704 #if !defined(lwp_getdatamodel)
705 
706 /*
707  * Return the datamodel of the given lwp.
708  */
709 /*ARGSUSED*/
710 model_t
711 lwp_getdatamodel(klwp_t *lwp)
712 {
713 	return (lwp->lwp_procp->p_model);
714 }
715 
716 #endif	/* !lwp_getdatamodel */
717 
718 #if !defined(get_udatamodel)
719 
720 model_t
721 get_udatamodel(void)
722 {
723 	return (curproc->p_model);
724 }
725 
726 #endif	/* !get_udatamodel */
727