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 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <sys/types.h> 30 #include <sys/param.h> 31 #include <sys/sysmacros.h> 32 #include <sys/signal.h> 33 #include <sys/systm.h> 34 #include <sys/user.h> 35 #include <sys/mman.h> 36 #include <sys/class.h> 37 #include <sys/proc.h> 38 #include <sys/procfs.h> 39 #include <sys/kmem.h> 40 #include <sys/cred.h> 41 #include <sys/archsystm.h> 42 #include <sys/contract_impl.h> 43 44 #include <sys/reboot.h> 45 #include <sys/uadmin.h> 46 47 #include <sys/vfs.h> 48 #include <sys/vnode.h> 49 #include <sys/session.h> 50 #include <sys/ucontext.h> 51 52 #include <sys/dnlc.h> 53 #include <sys/var.h> 54 #include <sys/cmn_err.h> 55 #include <sys/debug.h> 56 #include <sys/thread.h> 57 #include <sys/vtrace.h> 58 #include <sys/consdev.h> 59 #include <sys/frame.h> 60 #include <sys/stack.h> 61 #include <sys/swap.h> 62 #include <sys/vmparam.h> 63 #include <sys/cpuvar.h> 64 #include <sys/cpu.h> 65 66 #include <sys/privregs.h> 67 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 77 #include <sys/exec.h> 78 #include <sys/acct.h> 79 #include <sys/corectl.h> 80 #include <sys/modctl.h> 81 #include <sys/tuneable.h> 82 83 #include <c2/audit.h> 84 85 #include <sys/trap.h> 86 #include <sys/sunddi.h> 87 #include <sys/bootconf.h> 88 #include <sys/memlist.h> 89 #include <sys/systeminfo.h> 90 #include <sys/promif.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 * XXX There should be no need to use promif routines here. 97 */ 98 int 99 check_boot_version(int boots_version) 100 { 101 if (boots_version == BO_VERSION) 102 return (0); 103 104 prom_printf("Wrong boot interface - kernel needs v%d found v%d\n", 105 BO_VERSION, boots_version); 106 prom_panic("halting"); 107 /*NOTREACHED*/ 108 } 109 110 /* 111 * Kernel setup code, called from startup(). 112 */ 113 void 114 kern_setup1(void) 115 { 116 proc_t *pp; 117 118 pp = &p0; 119 120 proc_sched = pp; 121 122 /* 123 * Initialize process 0 data structures 124 */ 125 pp->p_stat = SRUN; 126 pp->p_flag = SSYS; 127 128 pp->p_pidp = &pid0; 129 pp->p_pgidp = &pid0; 130 pp->p_sessp = &session0; 131 pp->p_tlist = &t0; 132 pid0.pid_pglink = pp; 133 134 /* 135 * We assume that the u-area is zeroed out. 136 */ 137 u.u_cmask = (mode_t)CMASK; 138 139 thread_init(); /* init thread_free list */ 140 pid_init(); /* initialize pid (proc) table */ 141 contract_init(); /* initialize contracts */ 142 143 init_pages_pp_maximum(); 144 } 145 146 /* 147 * Load a procedure into a thread. 148 */ 149 void 150 thread_load(kthread_t *t, void (*start)(), caddr_t arg, size_t len) 151 { 152 struct rwindow *rwin; 153 caddr_t sp; 154 size_t framesz; 155 caddr_t argp; 156 extern void thread_start(); 157 158 /* 159 * Push a "c" call frame onto the stack to represent 160 * the caller of "start". 161 */ 162 sp = t->t_stk; 163 if (len != 0) { 164 /* 165 * the object that arg points at is copied into the 166 * caller's frame. 167 */ 168 framesz = SA(len); 169 sp -= framesz; 170 ASSERT(sp > t->t_stkbase); 171 argp = sp + SA(MINFRAME); 172 bcopy(arg, argp, len); 173 arg = argp; 174 } 175 /* 176 * store arg and len into the frames input register save area. 177 * these are then transfered to the first 2 output registers by 178 * thread_start() in swtch.s. 179 */ 180 rwin = (struct rwindow *)sp; 181 rwin->rw_in[0] = (intptr_t)arg; 182 rwin->rw_in[1] = len; 183 rwin->rw_in[6] = 0; 184 rwin->rw_in[7] = (intptr_t)start; 185 /* 186 * initialize thread to resume at thread_start(). 187 */ 188 t->t_pc = (uintptr_t)thread_start - 8; 189 t->t_sp = (uintptr_t)sp - STACK_BIAS; 190 } 191 192 #if !defined(lwp_getdatamodel) 193 194 /* 195 * Return the datamodel of the given lwp. 196 */ 197 model_t 198 lwp_getdatamodel(klwp_t *lwp) 199 { 200 return (lwp->lwp_procp->p_model); 201 } 202 203 #endif /* !lwp_getdatamodel */ 204 205 #if !defined(get_udatamodel) 206 207 model_t 208 get_udatamodel(void) 209 { 210 return (curproc->p_model); 211 } 212 213 #endif /* !get_udatamodel */ 214