xref: /titanic_52/usr/src/uts/sun4/ml/proc_init.s (revision c9d93b537520c235a6d4a0af53b9bf07cf3390e9)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*c9d93b53SJames Anderson * Common Development and Distribution License (the "License").
6*c9d93b53SJames Anderson * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate/*
22*c9d93b53SJames Anderson * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate#if defined(lint)
277c478bd9Sstevel@tonic-gate#include <sys/types.h>
287c478bd9Sstevel@tonic-gate#else	/* lint */
297c478bd9Sstevel@tonic-gate#include "assym.h"
307c478bd9Sstevel@tonic-gate#endif	/* lint */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
337c478bd9Sstevel@tonic-gate#include <sys/machthread.h>
347c478bd9Sstevel@tonic-gate#include <sys/param.h>
357c478bd9Sstevel@tonic-gate#include <sys/vm_machparam.h>
367c478bd9Sstevel@tonic-gate#include <sys/privregs.h>
377c478bd9Sstevel@tonic-gate#include <sys/intreg.h>
387c478bd9Sstevel@tonic-gate#include <sys/vis.h>
397c478bd9Sstevel@tonic-gate#include <sys/clock.h>
407c478bd9Sstevel@tonic-gate#include <vm/hat_sfmmu.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate#if !defined(lint)
437c478bd9Sstevel@tonic-gate	.weak	cpu_feature_init
447c478bd9Sstevel@tonic-gate	.type	cpu_feature_init, #function
457c478bd9Sstevel@tonic-gate#endif	/* lint */
467c478bd9Sstevel@tonic-gate
47*c9d93b53SJames Anderson#if !defined(lint)
48*c9d93b53SJames Anderson	.weak	cpu_early_feature_init
49*c9d93b53SJames Anderson	.type	cpu_early_feature_init, #function
50*c9d93b53SJames Anderson#endif	/* lint */
51*c9d93b53SJames Anderson
527c478bd9Sstevel@tonic-gate/*
537c478bd9Sstevel@tonic-gate * Processor initialization
547c478bd9Sstevel@tonic-gate *
557c478bd9Sstevel@tonic-gate * This is the kernel entry point for other cpus except the first one.
567c478bd9Sstevel@tonic-gate * When the prom jumps to this location we are still executing with the
577c478bd9Sstevel@tonic-gate * prom's trap table.  It expects the cpuid as its first parameter.
587c478bd9Sstevel@tonic-gate */
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate#if defined(lint)
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate/* ARGSUSED */
637c478bd9Sstevel@tonic-gatevoid
647c478bd9Sstevel@tonic-gatecpu_startup(int cpuid)
657c478bd9Sstevel@tonic-gate{}
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate#else	/* lint */
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate	! allocate a temporary stack to run on while we figure who and
707c478bd9Sstevel@tonic-gate	! what we are.
717c478bd9Sstevel@tonic-gate	.seg	".data"
727c478bd9Sstevel@tonic-gate	.align	8
737c478bd9Sstevel@tonic-gateetmpstk:
747c478bd9Sstevel@tonic-gate	.skip	2048
757c478bd9Sstevel@tonic-gatetmpstk:
767c478bd9Sstevel@tonic-gate	.word	0
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate	ENTRY_NP(cpu_startup)
797c478bd9Sstevel@tonic-gate	!
807c478bd9Sstevel@tonic-gate	! Initialize CPU state registers
817c478bd9Sstevel@tonic-gate	!
827c478bd9Sstevel@tonic-gate	! The boot cpu and other cpus are different.  The boot cpu has gone
837c478bd9Sstevel@tonic-gate	! through boot, and its state might be affected as a result.  The
847c478bd9Sstevel@tonic-gate	! other cpus' states come directly from the prom.
857c478bd9Sstevel@tonic-gate	!
867c478bd9Sstevel@tonic-gate	wrpr	%g0, PSTATE_KERN, %pstate
877c478bd9Sstevel@tonic-gate	wr	%g0, %g0, %fprs		! clear fprs
887c478bd9Sstevel@tonic-gate	CLEARTICKNPT			! allow user rdtick
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate	!
917c478bd9Sstevel@tonic-gate	! Set up temporary stack
927c478bd9Sstevel@tonic-gate	!
937c478bd9Sstevel@tonic-gate	set	tmpstk, %g1
947c478bd9Sstevel@tonic-gate	sub	%g1, SA(KFPUSIZE+GSR_SIZE), %g2
957c478bd9Sstevel@tonic-gate	and	%g2, 0x3F, %g3
967c478bd9Sstevel@tonic-gate	sub	%g2, %g3, %o2
977c478bd9Sstevel@tonic-gate	sub	%o2, SA(MINFRAME) + STACK_BIAS, %sp
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate	mov	%o0, %l1		! save cpuid
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate	call	sfmmu_mp_startup
1027c478bd9Sstevel@tonic-gate	sub	%g0, 1, THREAD_REG	! catch any curthread acceses
1037c478bd9Sstevel@tonic-gate
104*c9d93b53SJames Anderson	! On OPL platforms, context page size TLB programming must be enabled in
105*c9d93b53SJames Anderson	! ASI_MEMCNTL.  To avoid Olympus-C and Jupiter sTLB errata (strands with
106*c9d93b53SJames Anderson	! different TLB page size settings), this must be done here before any
107*c9d93b53SJames Anderson	! reference to non-nucleus memory.  An early hook is added to perform
108*c9d93b53SJames Anderson	! cpu specific initialization.
109*c9d93b53SJames Anderson	!
110*c9d93b53SJames Anderson	sethi	%hi(cpu_early_feature_init), %o0
111*c9d93b53SJames Anderson	or	%o0, %lo(cpu_early_feature_init), %o0
112*c9d93b53SJames Anderson	brz	%o0, 0f
113*c9d93b53SJames Anderson	nop
114*c9d93b53SJames Anderson	call	%o0
115*c9d93b53SJames Anderson	nop
116*c9d93b53SJames Anderson
117*c9d93b53SJames Anderson0:
1187c478bd9Sstevel@tonic-gate	! SET_KCONTEXTREG(reg0, reg1, reg2, reg3, reg4, label1, label2, label3)
1197c478bd9Sstevel@tonic-gate	SET_KCONTEXTREG(%o0, %g1, %g2, %g3, %l3, l1, l2, l3)
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate	! We are now running on the kernel's trap table.
1227c478bd9Sstevel@tonic-gate	!
1237c478bd9Sstevel@tonic-gate	! It is very important to have a thread pointer and a cpu struct
1247c478bd9Sstevel@tonic-gate	! *before* calling into C routines .
1257c478bd9Sstevel@tonic-gate	! Otherwise, overflow/underflow handlers, etc. can get very upset!
1267c478bd9Sstevel@tonic-gate	!
1277c478bd9Sstevel@tonic-gate	!
1287c478bd9Sstevel@tonic-gate	! We don't want to simply increment
1297c478bd9Sstevel@tonic-gate	! ncpus right now because it is in the cache, and
1307c478bd9Sstevel@tonic-gate	! we don't have the cache on yet for this CPU.
1317c478bd9Sstevel@tonic-gate	!
1327c478bd9Sstevel@tonic-gate	set	cpu, %l3
1337c478bd9Sstevel@tonic-gate	sll	%l1, CPTRSHIFT, %l2	! offset into CPU vector.
1347c478bd9Sstevel@tonic-gate	ldn	[%l3 + %l2], %l3	! pointer to CPU struct
1357c478bd9Sstevel@tonic-gate	ldn	[%l3 + CPU_THREAD], THREAD_REG	! set thread pointer (%g7)
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate	!
1387c478bd9Sstevel@tonic-gate	! Set up any required cpu feature
1397c478bd9Sstevel@tonic-gate	!
1407c478bd9Sstevel@tonic-gate	sethi	%hi(cpu_feature_init), %o0
1417c478bd9Sstevel@tonic-gate	or	%o0, %lo(cpu_feature_init), %o0
1427c478bd9Sstevel@tonic-gate	brz	%o0, 1f
1437c478bd9Sstevel@tonic-gate	nop
1447c478bd9Sstevel@tonic-gate	call	%o0
1457c478bd9Sstevel@tonic-gate	nop
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate1:
1487c478bd9Sstevel@tonic-gate	!
1497c478bd9Sstevel@tonic-gate	! Resume the thread allocated for the CPU.
1507c478bd9Sstevel@tonic-gate	!
1517c478bd9Sstevel@tonic-gate 	ldn	[THREAD_REG + T_PC], %i7
1527c478bd9Sstevel@tonic-gate	ldn	[THREAD_REG + T_SP], %fp
1537c478bd9Sstevel@tonic-gate	ret				! "return" into the thread
1547c478bd9Sstevel@tonic-gate	restore				! WILL cause underflow
1557c478bd9Sstevel@tonic-gate	SET_SIZE(cpu_startup)
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate#endif	/* lint */
158