xref: /titanic_52/usr/src/uts/sparc/os/sundep.c (revision 74e20cfe817b82802b16fac8690dadcda76f54f5)
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 2005 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 	pid0.pid_pgtail = pp;
134 
135 	/*
136 	 * We assume that the u-area is zeroed out.
137 	 */
138 	u.u_cmask = (mode_t)CMASK;
139 
140 	thread_init();		/* init thread_free list */
141 	pid_init();		/* initialize pid (proc) table */
142 	contract_init();	/* initialize contracts */
143 
144 	init_pages_pp_maximum();
145 }
146 
147 /*
148  * Load a procedure into a thread.
149  */
150 void
151 thread_load(kthread_t *t, void (*start)(), caddr_t arg, size_t len)
152 {
153 	struct rwindow *rwin;
154 	caddr_t sp;
155 	size_t framesz;
156 	caddr_t argp;
157 	extern void thread_start();
158 
159 	/*
160 	 * Push a "c" call frame onto the stack to represent
161 	 * the caller of "start".
162 	 */
163 	sp = t->t_stk;
164 	if (len != 0) {
165 		/*
166 		 * the object that arg points at is copied into the
167 		 * caller's frame.
168 		 */
169 		framesz = SA(len);
170 		sp -= framesz;
171 		ASSERT(sp > t->t_stkbase);
172 		argp = sp + SA(MINFRAME);
173 		bcopy(arg, argp, len);
174 		arg = argp;
175 	}
176 	/*
177 	 * store arg and len into the frames input register save area.
178 	 * these are then transfered to the first 2 output registers by
179 	 * thread_start() in swtch.s.
180 	 */
181 	rwin = (struct rwindow *)sp;
182 	rwin->rw_in[0] = (intptr_t)arg;
183 	rwin->rw_in[1] = len;
184 	rwin->rw_in[6] = 0;
185 	rwin->rw_in[7] = (intptr_t)start;
186 	/*
187 	 * initialize thread to resume at thread_start().
188 	 */
189 	t->t_pc = (uintptr_t)thread_start - 8;
190 	t->t_sp = (uintptr_t)sp - STACK_BIAS;
191 }
192 
193 #if !defined(lwp_getdatamodel)
194 
195 /*
196  * Return the datamodel of the given lwp.
197  */
198 model_t
199 lwp_getdatamodel(klwp_t *lwp)
200 {
201 	return (lwp->lwp_procp->p_model);
202 }
203 
204 #endif	/* !lwp_getdatamodel */
205 
206 #if !defined(get_udatamodel)
207 
208 model_t
209 get_udatamodel(void)
210 {
211 	return (curproc->p_model);
212 }
213 
214 #endif	/* !get_udatamodel */
215