xref: /illumos-gate/usr/src/uts/sparc/os/sundep.c (revision ae115bc7)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*ae115bc7Smrj  * Common Development and Distribution License (the "License").
6*ae115bc7Smrj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/param.h>
307c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
317c478bd9Sstevel@tonic-gate #include <sys/signal.h>
327c478bd9Sstevel@tonic-gate #include <sys/systm.h>
337c478bd9Sstevel@tonic-gate #include <sys/user.h>
347c478bd9Sstevel@tonic-gate #include <sys/mman.h>
357c478bd9Sstevel@tonic-gate #include <sys/class.h>
367c478bd9Sstevel@tonic-gate #include <sys/proc.h>
377c478bd9Sstevel@tonic-gate #include <sys/procfs.h>
387c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
397c478bd9Sstevel@tonic-gate #include <sys/cred.h>
407c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
417c478bd9Sstevel@tonic-gate #include <sys/contract_impl.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
447c478bd9Sstevel@tonic-gate #include <sys/uadmin.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
477c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
487c478bd9Sstevel@tonic-gate #include <sys/session.h>
497c478bd9Sstevel@tonic-gate #include <sys/ucontext.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #include <sys/dnlc.h>
527c478bd9Sstevel@tonic-gate #include <sys/var.h>
537c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
547c478bd9Sstevel@tonic-gate #include <sys/debug.h>
557c478bd9Sstevel@tonic-gate #include <sys/thread.h>
567c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
577c478bd9Sstevel@tonic-gate #include <sys/consdev.h>
587c478bd9Sstevel@tonic-gate #include <sys/frame.h>
597c478bd9Sstevel@tonic-gate #include <sys/stack.h>
607c478bd9Sstevel@tonic-gate #include <sys/swap.h>
617c478bd9Sstevel@tonic-gate #include <sys/vmparam.h>
627c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
637c478bd9Sstevel@tonic-gate #include <sys/cpu.h>
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #include <sys/privregs.h>
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #include <vm/hat.h>
687c478bd9Sstevel@tonic-gate #include <vm/anon.h>
697c478bd9Sstevel@tonic-gate #include <vm/as.h>
707c478bd9Sstevel@tonic-gate #include <vm/page.h>
717c478bd9Sstevel@tonic-gate #include <vm/seg.h>
727c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
737c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
747c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #include <sys/exec.h>
777c478bd9Sstevel@tonic-gate #include <sys/acct.h>
787c478bd9Sstevel@tonic-gate #include <sys/corectl.h>
797c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
807c478bd9Sstevel@tonic-gate #include <sys/tuneable.h>
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #include <c2/audit.h>
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #include <sys/trap.h>
857c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
867c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
877c478bd9Sstevel@tonic-gate #include <sys/memlist.h>
887c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
897c478bd9Sstevel@tonic-gate #include <sys/promif.h>
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * Compare the version of boot that boot says it is against
937c478bd9Sstevel@tonic-gate  * the version of boot the kernel expects.
947c478bd9Sstevel@tonic-gate  *
957c478bd9Sstevel@tonic-gate  * XXX	There should be no need to use promif routines here.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate int
check_boot_version(int boots_version)987c478bd9Sstevel@tonic-gate check_boot_version(int boots_version)
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate 	if (boots_version == BO_VERSION)
1017c478bd9Sstevel@tonic-gate 		return (0);
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	prom_printf("Wrong boot interface - kernel needs v%d found v%d\n",
1047c478bd9Sstevel@tonic-gate 	    BO_VERSION, boots_version);
1057c478bd9Sstevel@tonic-gate 	prom_panic("halting");
1067c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * Kernel setup code, called from startup().
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate void
kern_setup1(void)1137c478bd9Sstevel@tonic-gate kern_setup1(void)
1147c478bd9Sstevel@tonic-gate {
1157c478bd9Sstevel@tonic-gate 	proc_t *pp;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	pp = &p0;
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 	proc_sched = pp;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	/*
1227c478bd9Sstevel@tonic-gate 	 * Initialize process 0 data structures
1237c478bd9Sstevel@tonic-gate 	 */
1247c478bd9Sstevel@tonic-gate 	pp->p_stat = SRUN;
1257c478bd9Sstevel@tonic-gate 	pp->p_flag = SSYS;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	pp->p_pidp = &pid0;
1287c478bd9Sstevel@tonic-gate 	pp->p_pgidp = &pid0;
1297c478bd9Sstevel@tonic-gate 	pp->p_sessp = &session0;
1307c478bd9Sstevel@tonic-gate 	pp->p_tlist = &t0;
1317c478bd9Sstevel@tonic-gate 	pid0.pid_pglink = pp;
132e44bd21cSsusans 	pid0.pid_pgtail = pp;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	/*
1357c478bd9Sstevel@tonic-gate 	 * We assume that the u-area is zeroed out.
1367c478bd9Sstevel@tonic-gate 	 */
137*ae115bc7Smrj 	PTOU(curproc)->u_cmask = (mode_t)CMASK;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	thread_init();		/* init thread_free list */
1407c478bd9Sstevel@tonic-gate 	pid_init();		/* initialize pid (proc) table */
1417c478bd9Sstevel@tonic-gate 	contract_init();	/* initialize contracts */
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	init_pages_pp_maximum();
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /*
1477c478bd9Sstevel@tonic-gate  * Load a procedure into a thread.
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate void
thread_load(kthread_t * t,void (* start)(),caddr_t arg,size_t len)1507c478bd9Sstevel@tonic-gate thread_load(kthread_t *t, void (*start)(), caddr_t arg, size_t len)
1517c478bd9Sstevel@tonic-gate {
1527c478bd9Sstevel@tonic-gate 	struct rwindow *rwin;
1537c478bd9Sstevel@tonic-gate 	caddr_t sp;
1547c478bd9Sstevel@tonic-gate 	size_t framesz;
1557c478bd9Sstevel@tonic-gate 	caddr_t argp;
1567c478bd9Sstevel@tonic-gate 	extern void thread_start();
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	/*
1597c478bd9Sstevel@tonic-gate 	 * Push a "c" call frame onto the stack to represent
1607c478bd9Sstevel@tonic-gate 	 * the caller of "start".
1617c478bd9Sstevel@tonic-gate 	 */
1627c478bd9Sstevel@tonic-gate 	sp = t->t_stk;
1637c478bd9Sstevel@tonic-gate 	if (len != 0) {
1647c478bd9Sstevel@tonic-gate 		/*
1657c478bd9Sstevel@tonic-gate 		 * the object that arg points at is copied into the
1667c478bd9Sstevel@tonic-gate 		 * caller's frame.
1677c478bd9Sstevel@tonic-gate 		 */
1687c478bd9Sstevel@tonic-gate 		framesz = SA(len);
1697c478bd9Sstevel@tonic-gate 		sp -= framesz;
1707c478bd9Sstevel@tonic-gate 		ASSERT(sp > t->t_stkbase);
1717c478bd9Sstevel@tonic-gate 		argp = sp + SA(MINFRAME);
1727c478bd9Sstevel@tonic-gate 		bcopy(arg, argp, len);
1737c478bd9Sstevel@tonic-gate 		arg = argp;
1747c478bd9Sstevel@tonic-gate 	}
1757c478bd9Sstevel@tonic-gate 	/*
1767c478bd9Sstevel@tonic-gate 	 * store arg and len into the frames input register save area.
1777c478bd9Sstevel@tonic-gate 	 * these are then transfered to the first 2 output registers by
1787c478bd9Sstevel@tonic-gate 	 * thread_start() in swtch.s.
1797c478bd9Sstevel@tonic-gate 	 */
1807c478bd9Sstevel@tonic-gate 	rwin = (struct rwindow *)sp;
1817c478bd9Sstevel@tonic-gate 	rwin->rw_in[0] = (intptr_t)arg;
1827c478bd9Sstevel@tonic-gate 	rwin->rw_in[1] = len;
1837c478bd9Sstevel@tonic-gate 	rwin->rw_in[6] = 0;
1847c478bd9Sstevel@tonic-gate 	rwin->rw_in[7] = (intptr_t)start;
1857c478bd9Sstevel@tonic-gate 	/*
1867c478bd9Sstevel@tonic-gate 	 * initialize thread to resume at thread_start().
1877c478bd9Sstevel@tonic-gate 	 */
1887c478bd9Sstevel@tonic-gate 	t->t_pc = (uintptr_t)thread_start - 8;
1897c478bd9Sstevel@tonic-gate 	t->t_sp = (uintptr_t)sp - STACK_BIAS;
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate #if !defined(lwp_getdatamodel)
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate /*
1957c478bd9Sstevel@tonic-gate  * Return the datamodel of the given lwp.
1967c478bd9Sstevel@tonic-gate  */
1977c478bd9Sstevel@tonic-gate model_t
lwp_getdatamodel(klwp_t * lwp)1987c478bd9Sstevel@tonic-gate lwp_getdatamodel(klwp_t *lwp)
1997c478bd9Sstevel@tonic-gate {
2007c478bd9Sstevel@tonic-gate 	return (lwp->lwp_procp->p_model);
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate #endif	/* !lwp_getdatamodel */
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate #if !defined(get_udatamodel)
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate model_t
get_udatamodel(void)2087c478bd9Sstevel@tonic-gate get_udatamodel(void)
2097c478bd9Sstevel@tonic-gate {
2107c478bd9Sstevel@tonic-gate 	return (curproc->p_model);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate #endif	/* !get_udatamodel */
214