summaryrefslogtreecommitdiff
path: root/usr/src/uts/sun4/ml/proc_init.s
blob: 13bd5d3b1c3e8106a924858ea19610986202361d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#if defined(lint)
#include <sys/types.h>
#else	/* lint */
#include "assym.h"
#endif	/* lint */

#include <sys/asm_linkage.h>
#include <sys/machthread.h>
#include <sys/param.h>
#include <sys/vm_machparam.h>
#include <sys/privregs.h>
#include <sys/intreg.h>
#include <sys/vis.h>
#include <sys/clock.h>
#include <vm/hat_sfmmu.h>	

#if !defined(lint)
	.weak	cpu_feature_init
	.type	cpu_feature_init, #function
#endif	/* lint */

/*
 * Processor initialization
 *
 * This is the kernel entry point for other cpus except the first one.
 * When the prom jumps to this location we are still executing with the
 * prom's trap table.  It expects the cpuid as its first parameter.
 */

#if defined(lint)

/* ARGSUSED */
void
cpu_startup(int cpuid)
{}

#else	/* lint */

	! allocate a temporary stack to run on while we figure who and
	! what we are.
	.seg	".data"
	.align	8
etmpstk:
	.skip	2048
tmpstk:
	.word	0

	ENTRY_NP(cpu_startup)
	!
	! Initialize CPU state registers
	!
	! The boot cpu and other cpus are different.  The boot cpu has gone
	! through boot, and its state might be affected as a result.  The
	! other cpus' states come directly from the prom.
	!
	wrpr	%g0, PSTATE_KERN, %pstate
	wr	%g0, %g0, %fprs		! clear fprs
	CLEARTICKNPT			! allow user rdtick

	!
	! Set up temporary stack
	!
	set	tmpstk, %g1
	sub	%g1, SA(KFPUSIZE+GSR_SIZE), %g2
	and	%g2, 0x3F, %g3
	sub	%g2, %g3, %o2
	sub	%o2, SA(MINFRAME) + STACK_BIAS, %sp

	mov	%o0, %l1		! save cpuid

	call	sfmmu_mp_startup
	sub	%g0, 1, THREAD_REG	! catch any curthread acceses
	
	! SET_KCONTEXTREG(reg0, reg1, reg2, reg3, reg4, label1, label2, label3)
	SET_KCONTEXTREG(%o0, %g1, %g2, %g3, %l3, l1, l2, l3)
	
	! We are now running on the kernel's trap table.
	! 
	! It is very important to have a thread pointer and a cpu struct
	! *before* calling into C routines .
	! Otherwise, overflow/underflow handlers, etc. can get very upset!
	! 
	!
	! We don't want to simply increment
	! ncpus right now because it is in the cache, and
	! we don't have the cache on yet for this CPU.
	!
	set	cpu, %l3
	sll	%l1, CPTRSHIFT, %l2	! offset into CPU vector.
	ldn	[%l3 + %l2], %l3	! pointer to CPU struct
	ldn	[%l3 + CPU_THREAD], THREAD_REG	! set thread pointer (%g7)

	!
	! Set up any required cpu feature
	!
	sethi	%hi(cpu_feature_init), %o0
	or	%o0, %lo(cpu_feature_init), %o0
	brz	%o0, 1f
	nop
	call	%o0
	nop

1:
	!
	! Resume the thread allocated for the CPU.
	!
 	ldn	[THREAD_REG + T_PC], %i7
	ldn	[THREAD_REG + T_SP], %fp
	ret				! "return" into the thread
	restore				! WILL cause underflow
	SET_SIZE(cpu_startup)

#endif	/* lint */