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