10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*3446Smrj * Common Development and Distribution License (the "License").
6*3446Smrj * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*3446Smrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/param.h>
300Sstevel@tonic-gate #include <sys/sysmacros.h>
310Sstevel@tonic-gate #include <sys/signal.h>
320Sstevel@tonic-gate #include <sys/systm.h>
330Sstevel@tonic-gate #include <sys/user.h>
340Sstevel@tonic-gate #include <sys/mman.h>
350Sstevel@tonic-gate #include <sys/class.h>
360Sstevel@tonic-gate #include <sys/proc.h>
370Sstevel@tonic-gate #include <sys/procfs.h>
380Sstevel@tonic-gate #include <sys/kmem.h>
390Sstevel@tonic-gate #include <sys/cred.h>
400Sstevel@tonic-gate #include <sys/archsystm.h>
410Sstevel@tonic-gate #include <sys/contract_impl.h>
420Sstevel@tonic-gate
430Sstevel@tonic-gate #include <sys/reboot.h>
440Sstevel@tonic-gate #include <sys/uadmin.h>
450Sstevel@tonic-gate
460Sstevel@tonic-gate #include <sys/vfs.h>
470Sstevel@tonic-gate #include <sys/vnode.h>
480Sstevel@tonic-gate #include <sys/session.h>
490Sstevel@tonic-gate #include <sys/ucontext.h>
500Sstevel@tonic-gate
510Sstevel@tonic-gate #include <sys/dnlc.h>
520Sstevel@tonic-gate #include <sys/var.h>
530Sstevel@tonic-gate #include <sys/cmn_err.h>
540Sstevel@tonic-gate #include <sys/debug.h>
550Sstevel@tonic-gate #include <sys/thread.h>
560Sstevel@tonic-gate #include <sys/vtrace.h>
570Sstevel@tonic-gate #include <sys/consdev.h>
580Sstevel@tonic-gate #include <sys/frame.h>
590Sstevel@tonic-gate #include <sys/stack.h>
600Sstevel@tonic-gate #include <sys/swap.h>
610Sstevel@tonic-gate #include <sys/vmparam.h>
620Sstevel@tonic-gate #include <sys/cpuvar.h>
630Sstevel@tonic-gate #include <sys/cpu.h>
640Sstevel@tonic-gate
650Sstevel@tonic-gate #include <sys/privregs.h>
660Sstevel@tonic-gate
670Sstevel@tonic-gate #include <vm/hat.h>
680Sstevel@tonic-gate #include <vm/anon.h>
690Sstevel@tonic-gate #include <vm/as.h>
700Sstevel@tonic-gate #include <vm/page.h>
710Sstevel@tonic-gate #include <vm/seg.h>
720Sstevel@tonic-gate #include <vm/seg_kmem.h>
730Sstevel@tonic-gate #include <vm/seg_map.h>
740Sstevel@tonic-gate #include <vm/seg_vn.h>
750Sstevel@tonic-gate
760Sstevel@tonic-gate #include <sys/exec.h>
770Sstevel@tonic-gate #include <sys/acct.h>
780Sstevel@tonic-gate #include <sys/corectl.h>
790Sstevel@tonic-gate #include <sys/modctl.h>
800Sstevel@tonic-gate #include <sys/tuneable.h>
810Sstevel@tonic-gate
820Sstevel@tonic-gate #include <c2/audit.h>
830Sstevel@tonic-gate
840Sstevel@tonic-gate #include <sys/trap.h>
850Sstevel@tonic-gate #include <sys/sunddi.h>
860Sstevel@tonic-gate #include <sys/bootconf.h>
870Sstevel@tonic-gate #include <sys/memlist.h>
880Sstevel@tonic-gate #include <sys/systeminfo.h>
890Sstevel@tonic-gate #include <sys/promif.h>
900Sstevel@tonic-gate
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate * Compare the version of boot that boot says it is against
930Sstevel@tonic-gate * the version of boot the kernel expects.
940Sstevel@tonic-gate *
950Sstevel@tonic-gate * XXX There should be no need to use promif routines here.
960Sstevel@tonic-gate */
970Sstevel@tonic-gate int
check_boot_version(int boots_version)980Sstevel@tonic-gate check_boot_version(int boots_version)
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate if (boots_version == BO_VERSION)
1010Sstevel@tonic-gate return (0);
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate prom_printf("Wrong boot interface - kernel needs v%d found v%d\n",
1040Sstevel@tonic-gate BO_VERSION, boots_version);
1050Sstevel@tonic-gate prom_panic("halting");
1060Sstevel@tonic-gate /*NOTREACHED*/
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate /*
1100Sstevel@tonic-gate * Kernel setup code, called from startup().
1110Sstevel@tonic-gate */
1120Sstevel@tonic-gate void
kern_setup1(void)1130Sstevel@tonic-gate kern_setup1(void)
1140Sstevel@tonic-gate {
1150Sstevel@tonic-gate proc_t *pp;
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate pp = &p0;
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate proc_sched = pp;
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate /*
1220Sstevel@tonic-gate * Initialize process 0 data structures
1230Sstevel@tonic-gate */
1240Sstevel@tonic-gate pp->p_stat = SRUN;
1250Sstevel@tonic-gate pp->p_flag = SSYS;
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate pp->p_pidp = &pid0;
1280Sstevel@tonic-gate pp->p_pgidp = &pid0;
1290Sstevel@tonic-gate pp->p_sessp = &session0;
1300Sstevel@tonic-gate pp->p_tlist = &t0;
1310Sstevel@tonic-gate pid0.pid_pglink = pp;
132749Ssusans pid0.pid_pgtail = pp;
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate /*
1350Sstevel@tonic-gate * We assume that the u-area is zeroed out.
1360Sstevel@tonic-gate */
137*3446Smrj PTOU(curproc)->u_cmask = (mode_t)CMASK;
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate thread_init(); /* init thread_free list */
1400Sstevel@tonic-gate pid_init(); /* initialize pid (proc) table */
1410Sstevel@tonic-gate contract_init(); /* initialize contracts */
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate init_pages_pp_maximum();
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate * Load a procedure into a thread.
1480Sstevel@tonic-gate */
1490Sstevel@tonic-gate void
thread_load(kthread_t * t,void (* start)(),caddr_t arg,size_t len)1500Sstevel@tonic-gate thread_load(kthread_t *t, void (*start)(), caddr_t arg, size_t len)
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate struct rwindow *rwin;
1530Sstevel@tonic-gate caddr_t sp;
1540Sstevel@tonic-gate size_t framesz;
1550Sstevel@tonic-gate caddr_t argp;
1560Sstevel@tonic-gate extern void thread_start();
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate /*
1590Sstevel@tonic-gate * Push a "c" call frame onto the stack to represent
1600Sstevel@tonic-gate * the caller of "start".
1610Sstevel@tonic-gate */
1620Sstevel@tonic-gate sp = t->t_stk;
1630Sstevel@tonic-gate if (len != 0) {
1640Sstevel@tonic-gate /*
1650Sstevel@tonic-gate * the object that arg points at is copied into the
1660Sstevel@tonic-gate * caller's frame.
1670Sstevel@tonic-gate */
1680Sstevel@tonic-gate framesz = SA(len);
1690Sstevel@tonic-gate sp -= framesz;
1700Sstevel@tonic-gate ASSERT(sp > t->t_stkbase);
1710Sstevel@tonic-gate argp = sp + SA(MINFRAME);
1720Sstevel@tonic-gate bcopy(arg, argp, len);
1730Sstevel@tonic-gate arg = argp;
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate /*
1760Sstevel@tonic-gate * store arg and len into the frames input register save area.
1770Sstevel@tonic-gate * these are then transfered to the first 2 output registers by
1780Sstevel@tonic-gate * thread_start() in swtch.s.
1790Sstevel@tonic-gate */
1800Sstevel@tonic-gate rwin = (struct rwindow *)sp;
1810Sstevel@tonic-gate rwin->rw_in[0] = (intptr_t)arg;
1820Sstevel@tonic-gate rwin->rw_in[1] = len;
1830Sstevel@tonic-gate rwin->rw_in[6] = 0;
1840Sstevel@tonic-gate rwin->rw_in[7] = (intptr_t)start;
1850Sstevel@tonic-gate /*
1860Sstevel@tonic-gate * initialize thread to resume at thread_start().
1870Sstevel@tonic-gate */
1880Sstevel@tonic-gate t->t_pc = (uintptr_t)thread_start - 8;
1890Sstevel@tonic-gate t->t_sp = (uintptr_t)sp - STACK_BIAS;
1900Sstevel@tonic-gate }
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate #if !defined(lwp_getdatamodel)
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate /*
1950Sstevel@tonic-gate * Return the datamodel of the given lwp.
1960Sstevel@tonic-gate */
1970Sstevel@tonic-gate model_t
lwp_getdatamodel(klwp_t * lwp)1980Sstevel@tonic-gate lwp_getdatamodel(klwp_t *lwp)
1990Sstevel@tonic-gate {
2000Sstevel@tonic-gate return (lwp->lwp_procp->p_model);
2010Sstevel@tonic-gate }
2020Sstevel@tonic-gate
2030Sstevel@tonic-gate #endif /* !lwp_getdatamodel */
2040Sstevel@tonic-gate
2050Sstevel@tonic-gate #if !defined(get_udatamodel)
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate model_t
get_udatamodel(void)2080Sstevel@tonic-gate get_udatamodel(void)
2090Sstevel@tonic-gate {
2100Sstevel@tonic-gate return (curproc->p_model);
2110Sstevel@tonic-gate }
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate #endif /* !get_udatamodel */
214