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