proc_init.s revision 8664:fa4744ba0999
11573Srgrimes/*
2128004Stjr * CDDL HEADER START
31573Srgrimes *
41573Srgrimes * The contents of this file are subject to the terms of the
51573Srgrimes * Common Development and Distribution License (the "License").
61573Srgrimes * You may not use this file except in compliance with the License.
71573Srgrimes *
81573Srgrimes * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9227753Stheraven * or http://www.opensolaris.org/os/licensing.
10227753Stheraven * See the License for the specific language governing permissions
11227753Stheraven * and limitations under the License.
12227753Stheraven *
13227753Stheraven * When distributing Covered Code, include this CDDL HEADER in each
141573Srgrimes * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151573Srgrimes * If applicable, add the following below this CDDL HEADER, with the
161573Srgrimes * fields enclosed by brackets "[]" replaced with your own identifying
171573Srgrimes * information: Portions Copyright [yyyy] [name of copyright owner]
181573Srgrimes *
191573Srgrimes * CDDL HEADER END
201573Srgrimes */
211573Srgrimes/*
221573Srgrimes * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
231573Srgrimes * Use is subject to license terms.
241573Srgrimes */
251573Srgrimes
261573Srgrimes#if defined(lint)
271573Srgrimes#include <sys/types.h>
281573Srgrimes#else	/* lint */
291573Srgrimes#include "assym.h"
301573Srgrimes#endif	/* lint */
311573Srgrimes
321573Srgrimes#include <sys/asm_linkage.h>
331573Srgrimes#include <sys/machthread.h>
341573Srgrimes#include <sys/param.h>
351573Srgrimes#include <sys/vm_machparam.h>
361573Srgrimes#include <sys/privregs.h>
371573Srgrimes#include <sys/intreg.h>
381573Srgrimes#include <sys/vis.h>
391573Srgrimes#include <sys/clock.h>
401573Srgrimes#include <vm/hat_sfmmu.h>
411573Srgrimes
4292986Sobrien#if !defined(lint)
4392986Sobrien	.weak	cpu_feature_init
441573Srgrimes	.type	cpu_feature_init, #function
45121845Stjr#endif	/* lint */
46105233Stjr
47121845Stjr#if !defined(lint)
481573Srgrimes	.weak	cpu_early_feature_init
491573Srgrimes	.type	cpu_early_feature_init, #function
501573Srgrimes#endif	/* lint */
51129179Stjr
52121845Stjr/*
53129153Stjr * Processor initialization
541573Srgrimes *
55142654Sphantom * This is the kernel entry point for other cpus except the first one.
56142654Sphantom * When the prom jumps to this location we are still executing with the
57142654Sphantom * prom's trap table.  It expects the cpuid as its first parameter.
58142654Sphantom */
59142654Sphantom
60142654Sphantom#if defined(lint)
61142654Sphantom
62142654Sphantom/* ARGSUSED */
63142654Sphantomvoid
64142654Sphantomcpu_startup(int cpuid)
65121845Stjr{}
66172619Sache
67172619Sache#else	/* lint */
68172619Sache
69172619Sache	! allocate a temporary stack to run on while we figure who and
70172619Sache	! what we are.
711573Srgrimes	.seg	".data"
72227753Stheraven	.align	8
731573Srgrimesetmpstk:
74121845Stjr	.skip	2048
75227753Stheraventmpstk:
76227753Stheraven	.word	0
77227753Stheraven
78227753Stheraven	ENTRY_NP(cpu_startup)
79227753Stheraven	!
80227753Stheraven	! Initialize CPU state registers
81227753Stheraven	!
82227753Stheraven	! The boot cpu and other cpus are different.  The boot cpu has gone
831573Srgrimes	! through boot, and its state might be affected as a result.  The
841573Srgrimes	! other cpus' states come directly from the prom.
851573Srgrimes	!
86142654Sphantom	wrpr	%g0, PSTATE_KERN, %pstate
87128004Stjr	wr	%g0, %g0, %fprs		! clear fprs
88128004Stjr	CLEARTICKNPT			! allow user rdtick
89128004Stjr
90128004Stjr	!
91128004Stjr	! Set up temporary stack
92128004Stjr	!
93128004Stjr	set	tmpstk, %g1
94128004Stjr	sub	%g1, SA(KFPUSIZE+GSR_SIZE), %g2
95128004Stjr	and	%g2, 0x3F, %g3
96128004Stjr	sub	%g2, %g3, %o2
97142654Sphantom	sub	%o2, SA(MINFRAME) + STACK_BIAS, %sp
98121845Stjr
99121845Stjr	mov	%o0, %l1		! save cpuid
1001573Srgrimes
101121845Stjr	call	sfmmu_mp_startup
102121845Stjr	sub	%g0, 1, THREAD_REG	! catch any curthread acceses
103121845Stjr
104121845Stjr	! On OPL platforms, context page size TLB programming must be enabled in
105121845Stjr	! ASI_MEMCNTL.  To avoid Olympus-C and Jupiter sTLB errata (strands with
106121845Stjr	! different TLB page size settings), this must be done here before any
107121845Stjr	! reference to non-nucleus memory.  An early hook is added to perform
108121845Stjr	! cpu specific initialization.
109121845Stjr	!
110121845Stjr	sethi	%hi(cpu_early_feature_init), %o0
1111573Srgrimes	or	%o0, %lo(cpu_early_feature_init), %o0
1121573Srgrimes	brz	%o0, 0f
113142654Sphantom	nop
114121845Stjr	call	%o0
115121845Stjr	nop
1161573Srgrimes
117121845Stjr0:
118121845Stjr	! SET_KCONTEXTREG(reg0, reg1, reg2, reg3, reg4, label1, label2, label3)
119121845Stjr	SET_KCONTEXTREG(%o0, %g1, %g2, %g3, %l3, l1, l2, l3)
120121845Stjr
121121845Stjr	! We are now running on the kernel's trap table.
122121845Stjr	!
123121845Stjr	! It is very important to have a thread pointer and a cpu struct
124121845Stjr	! *before* calling into C routines .
125121845Stjr	! Otherwise, overflow/underflow handlers, etc. can get very upset!
126121845Stjr	!
1271573Srgrimes	!
128129179Stjr	! We don't want to simply increment
129142654Sphantom	! ncpus right now because it is in the cache, and
130132497Stjr	! we don't have the cache on yet for this CPU.
131132497Stjr	!
132129179Stjr	set	cpu, %l3
133129179Stjr	sll	%l1, CPTRSHIFT, %l2	! offset into CPU vector.
134129179Stjr	ldn	[%l3 + %l2], %l3	! pointer to CPU struct
135129179Stjr	ldn	[%l3 + CPU_THREAD], THREAD_REG	! set thread pointer (%g7)
136132497Stjr
137132497Stjr	!
138132497Stjr	! Set up any required cpu feature
139132497Stjr	!
140129179Stjr	sethi	%hi(cpu_feature_init), %o0
141129179Stjr	or	%o0, %lo(cpu_feature_init), %o0
142129179Stjr	brz	%o0, 1f
143132497Stjr	nop
144129179Stjr	call	%o0
145129179Stjr	nop
146129179Stjr
147129179Stjr1:
148129179Stjr	!
149129179Stjr	! Resume the thread allocated for the CPU.
150129179Stjr	!
151129179Stjr 	ldn	[THREAD_REG + T_PC], %i7
152129179Stjr	ldn	[THREAD_REG + T_SP], %fp
153129179Stjr	ret				! "return" into the thread
154142654Sphantom	restore				! WILL cause underflow
155132497Stjr	SET_SIZE(cpu_startup)
156132497Stjr
157129179Stjr#endif	/* lint */
158129179Stjr