xref: /titanic_52/usr/src/uts/sparc/os/sundep.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/signal.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/systm.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/user.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/mman.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/class.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/proc.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/procfs.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/cred.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/contract_impl.h>
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/uadmin.h>
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/session.h>
50*7c478bd9Sstevel@tonic-gate #include <sys/ucontext.h>
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate #include <sys/dnlc.h>
53*7c478bd9Sstevel@tonic-gate #include <sys/var.h>
54*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
55*7c478bd9Sstevel@tonic-gate #include <sys/debug.h>
56*7c478bd9Sstevel@tonic-gate #include <sys/thread.h>
57*7c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
58*7c478bd9Sstevel@tonic-gate #include <sys/consdev.h>
59*7c478bd9Sstevel@tonic-gate #include <sys/frame.h>
60*7c478bd9Sstevel@tonic-gate #include <sys/stack.h>
61*7c478bd9Sstevel@tonic-gate #include <sys/swap.h>
62*7c478bd9Sstevel@tonic-gate #include <sys/vmparam.h>
63*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
64*7c478bd9Sstevel@tonic-gate #include <sys/cpu.h>
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate #include <sys/privregs.h>
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #include <vm/hat.h>
69*7c478bd9Sstevel@tonic-gate #include <vm/anon.h>
70*7c478bd9Sstevel@tonic-gate #include <vm/as.h>
71*7c478bd9Sstevel@tonic-gate #include <vm/page.h>
72*7c478bd9Sstevel@tonic-gate #include <vm/seg.h>
73*7c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
74*7c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
75*7c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate #include <sys/exec.h>
78*7c478bd9Sstevel@tonic-gate #include <sys/acct.h>
79*7c478bd9Sstevel@tonic-gate #include <sys/corectl.h>
80*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
81*7c478bd9Sstevel@tonic-gate #include <sys/tuneable.h>
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate #include <c2/audit.h>
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate #include <sys/trap.h>
86*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
87*7c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
88*7c478bd9Sstevel@tonic-gate #include <sys/memlist.h>
89*7c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
90*7c478bd9Sstevel@tonic-gate #include <sys/promif.h>
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate /*
93*7c478bd9Sstevel@tonic-gate  * Compare the version of boot that boot says it is against
94*7c478bd9Sstevel@tonic-gate  * the version of boot the kernel expects.
95*7c478bd9Sstevel@tonic-gate  *
96*7c478bd9Sstevel@tonic-gate  * XXX	There should be no need to use promif routines here.
97*7c478bd9Sstevel@tonic-gate  */
98*7c478bd9Sstevel@tonic-gate int
99*7c478bd9Sstevel@tonic-gate check_boot_version(int boots_version)
100*7c478bd9Sstevel@tonic-gate {
101*7c478bd9Sstevel@tonic-gate 	if (boots_version == BO_VERSION)
102*7c478bd9Sstevel@tonic-gate 		return (0);
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	prom_printf("Wrong boot interface - kernel needs v%d found v%d\n",
105*7c478bd9Sstevel@tonic-gate 	    BO_VERSION, boots_version);
106*7c478bd9Sstevel@tonic-gate 	prom_panic("halting");
107*7c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
108*7c478bd9Sstevel@tonic-gate }
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate /*
111*7c478bd9Sstevel@tonic-gate  * Kernel setup code, called from startup().
112*7c478bd9Sstevel@tonic-gate  */
113*7c478bd9Sstevel@tonic-gate void
114*7c478bd9Sstevel@tonic-gate kern_setup1(void)
115*7c478bd9Sstevel@tonic-gate {
116*7c478bd9Sstevel@tonic-gate 	proc_t *pp;
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	pp = &p0;
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 	proc_sched = pp;
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 	/*
123*7c478bd9Sstevel@tonic-gate 	 * Initialize process 0 data structures
124*7c478bd9Sstevel@tonic-gate 	 */
125*7c478bd9Sstevel@tonic-gate 	pp->p_stat = SRUN;
126*7c478bd9Sstevel@tonic-gate 	pp->p_flag = SSYS;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	pp->p_pidp = &pid0;
129*7c478bd9Sstevel@tonic-gate 	pp->p_pgidp = &pid0;
130*7c478bd9Sstevel@tonic-gate 	pp->p_sessp = &session0;
131*7c478bd9Sstevel@tonic-gate 	pp->p_tlist = &t0;
132*7c478bd9Sstevel@tonic-gate 	pid0.pid_pglink = pp;
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 	/*
135*7c478bd9Sstevel@tonic-gate 	 * We assume that the u-area is zeroed out.
136*7c478bd9Sstevel@tonic-gate 	 */
137*7c478bd9Sstevel@tonic-gate 	u.u_cmask = (mode_t)CMASK;
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 	thread_init();		/* init thread_free list */
140*7c478bd9Sstevel@tonic-gate 	pid_init();		/* initialize pid (proc) table */
141*7c478bd9Sstevel@tonic-gate 	contract_init();	/* initialize contracts */
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 	init_pages_pp_maximum();
144*7c478bd9Sstevel@tonic-gate }
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate /*
147*7c478bd9Sstevel@tonic-gate  * Load a procedure into a thread.
148*7c478bd9Sstevel@tonic-gate  */
149*7c478bd9Sstevel@tonic-gate void
150*7c478bd9Sstevel@tonic-gate thread_load(kthread_t *t, void (*start)(), caddr_t arg, size_t len)
151*7c478bd9Sstevel@tonic-gate {
152*7c478bd9Sstevel@tonic-gate 	struct rwindow *rwin;
153*7c478bd9Sstevel@tonic-gate 	caddr_t sp;
154*7c478bd9Sstevel@tonic-gate 	size_t framesz;
155*7c478bd9Sstevel@tonic-gate 	caddr_t argp;
156*7c478bd9Sstevel@tonic-gate 	extern void thread_start();
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate 	/*
159*7c478bd9Sstevel@tonic-gate 	 * Push a "c" call frame onto the stack to represent
160*7c478bd9Sstevel@tonic-gate 	 * the caller of "start".
161*7c478bd9Sstevel@tonic-gate 	 */
162*7c478bd9Sstevel@tonic-gate 	sp = t->t_stk;
163*7c478bd9Sstevel@tonic-gate 	if (len != 0) {
164*7c478bd9Sstevel@tonic-gate 		/*
165*7c478bd9Sstevel@tonic-gate 		 * the object that arg points at is copied into the
166*7c478bd9Sstevel@tonic-gate 		 * caller's frame.
167*7c478bd9Sstevel@tonic-gate 		 */
168*7c478bd9Sstevel@tonic-gate 		framesz = SA(len);
169*7c478bd9Sstevel@tonic-gate 		sp -= framesz;
170*7c478bd9Sstevel@tonic-gate 		ASSERT(sp > t->t_stkbase);
171*7c478bd9Sstevel@tonic-gate 		argp = sp + SA(MINFRAME);
172*7c478bd9Sstevel@tonic-gate 		bcopy(arg, argp, len);
173*7c478bd9Sstevel@tonic-gate 		arg = argp;
174*7c478bd9Sstevel@tonic-gate 	}
175*7c478bd9Sstevel@tonic-gate 	/*
176*7c478bd9Sstevel@tonic-gate 	 * store arg and len into the frames input register save area.
177*7c478bd9Sstevel@tonic-gate 	 * these are then transfered to the first 2 output registers by
178*7c478bd9Sstevel@tonic-gate 	 * thread_start() in swtch.s.
179*7c478bd9Sstevel@tonic-gate 	 */
180*7c478bd9Sstevel@tonic-gate 	rwin = (struct rwindow *)sp;
181*7c478bd9Sstevel@tonic-gate 	rwin->rw_in[0] = (intptr_t)arg;
182*7c478bd9Sstevel@tonic-gate 	rwin->rw_in[1] = len;
183*7c478bd9Sstevel@tonic-gate 	rwin->rw_in[6] = 0;
184*7c478bd9Sstevel@tonic-gate 	rwin->rw_in[7] = (intptr_t)start;
185*7c478bd9Sstevel@tonic-gate 	/*
186*7c478bd9Sstevel@tonic-gate 	 * initialize thread to resume at thread_start().
187*7c478bd9Sstevel@tonic-gate 	 */
188*7c478bd9Sstevel@tonic-gate 	t->t_pc = (uintptr_t)thread_start - 8;
189*7c478bd9Sstevel@tonic-gate 	t->t_sp = (uintptr_t)sp - STACK_BIAS;
190*7c478bd9Sstevel@tonic-gate }
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate #if !defined(lwp_getdatamodel)
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate /*
195*7c478bd9Sstevel@tonic-gate  * Return the datamodel of the given lwp.
196*7c478bd9Sstevel@tonic-gate  */
197*7c478bd9Sstevel@tonic-gate model_t
198*7c478bd9Sstevel@tonic-gate lwp_getdatamodel(klwp_t *lwp)
199*7c478bd9Sstevel@tonic-gate {
200*7c478bd9Sstevel@tonic-gate 	return (lwp->lwp_procp->p_model);
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate #endif	/* !lwp_getdatamodel */
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate #if !defined(get_udatamodel)
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate model_t
208*7c478bd9Sstevel@tonic-gate get_udatamodel(void)
209*7c478bd9Sstevel@tonic-gate {
210*7c478bd9Sstevel@tonic-gate 	return (curproc->p_model);
211*7c478bd9Sstevel@tonic-gate }
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate #endif	/* !get_udatamodel */
214