xref: /titanic_44/usr/src/uts/sparc/os/sundep.c (revision ae115bc77f6fcde83175c75b4206dc2e50747966)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <sys/sysmacros.h>
31 #include <sys/signal.h>
32 #include <sys/systm.h>
33 #include <sys/user.h>
34 #include <sys/mman.h>
35 #include <sys/class.h>
36 #include <sys/proc.h>
37 #include <sys/procfs.h>
38 #include <sys/kmem.h>
39 #include <sys/cred.h>
40 #include <sys/archsystm.h>
41 #include <sys/contract_impl.h>
42 
43 #include <sys/reboot.h>
44 #include <sys/uadmin.h>
45 
46 #include <sys/vfs.h>
47 #include <sys/vnode.h>
48 #include <sys/session.h>
49 #include <sys/ucontext.h>
50 
51 #include <sys/dnlc.h>
52 #include <sys/var.h>
53 #include <sys/cmn_err.h>
54 #include <sys/debug.h>
55 #include <sys/thread.h>
56 #include <sys/vtrace.h>
57 #include <sys/consdev.h>
58 #include <sys/frame.h>
59 #include <sys/stack.h>
60 #include <sys/swap.h>
61 #include <sys/vmparam.h>
62 #include <sys/cpuvar.h>
63 #include <sys/cpu.h>
64 
65 #include <sys/privregs.h>
66 
67 #include <vm/hat.h>
68 #include <vm/anon.h>
69 #include <vm/as.h>
70 #include <vm/page.h>
71 #include <vm/seg.h>
72 #include <vm/seg_kmem.h>
73 #include <vm/seg_map.h>
74 #include <vm/seg_vn.h>
75 
76 #include <sys/exec.h>
77 #include <sys/acct.h>
78 #include <sys/corectl.h>
79 #include <sys/modctl.h>
80 #include <sys/tuneable.h>
81 
82 #include <c2/audit.h>
83 
84 #include <sys/trap.h>
85 #include <sys/sunddi.h>
86 #include <sys/bootconf.h>
87 #include <sys/memlist.h>
88 #include <sys/systeminfo.h>
89 #include <sys/promif.h>
90 
91 /*
92  * Compare the version of boot that boot says it is against
93  * the version of boot the kernel expects.
94  *
95  * XXX	There should be no need to use promif routines here.
96  */
97 int
check_boot_version(int boots_version)98 check_boot_version(int boots_version)
99 {
100 	if (boots_version == BO_VERSION)
101 		return (0);
102 
103 	prom_printf("Wrong boot interface - kernel needs v%d found v%d\n",
104 	    BO_VERSION, boots_version);
105 	prom_panic("halting");
106 	/*NOTREACHED*/
107 }
108 
109 /*
110  * Kernel setup code, called from startup().
111  */
112 void
kern_setup1(void)113 kern_setup1(void)
114 {
115 	proc_t *pp;
116 
117 	pp = &p0;
118 
119 	proc_sched = pp;
120 
121 	/*
122 	 * Initialize process 0 data structures
123 	 */
124 	pp->p_stat = SRUN;
125 	pp->p_flag = SSYS;
126 
127 	pp->p_pidp = &pid0;
128 	pp->p_pgidp = &pid0;
129 	pp->p_sessp = &session0;
130 	pp->p_tlist = &t0;
131 	pid0.pid_pglink = pp;
132 	pid0.pid_pgtail = pp;
133 
134 	/*
135 	 * We assume that the u-area is zeroed out.
136 	 */
137 	PTOU(curproc)->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
thread_load(kthread_t * t,void (* start)(),caddr_t arg,size_t len)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
lwp_getdatamodel(klwp_t * lwp)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
get_udatamodel(void)208 get_udatamodel(void)
209 {
210 	return (curproc->p_model);
211 }
212 
213 #endif	/* !get_udatamodel */
214