Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / arch / sun4u / slavecpu.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: slavecpu.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)slavecpu.fth 1.14 06/02/16
43purpose:
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47
48code slave-enterforth ( -- )
49 up rp scr get-cpu-struct \ rp is temp reg here
50 scr rp get-rp0
51
52 scr sc1 sc2 sc3 mutex-enter prom-lock
53
54\dtc 'acf enterforth ip set
55\itc 'body enterforth ip set
56 ip base ip add
57\itc next
58\dtc ip %g0 %g0 jmpl nop
59c;
60
61code slave-idle-loop
62 \ base = origin
63 \ up = User Area Pointer
64 \ The User Area is now initialized
65 scr rdpstate \ We should not be spinning in
66 #sync membar \ this loop with IE = 0
67 scr 2 scr or \ set IE = 1
68 scr 0 wrpstate
69 #sync membar
70 up sc1 scr get-cpu-struct \ scr has cpu-struct-ptr
71 scr rp get-rp0
72
73 0 >cpu-status sc1 set
74 CPU-IDLING sc2 move
75 sc2 scr sc1 stx \ Mark as Idle
76
77 sc3 sc4 sc5 mutex-exit prom-lock
78
79 CPU-ENTERFORTH sc2 move
80 begin
81 scr sc1 sc3 ldx
82 sc3 sc2 %g0 subcc
83 0= until nop
84 sc2 scr sc1 stx \ Mark as waiting to enter
85
86 sc3 sc4 sc5 sc6 mutex-enter prom-lock
87
88 CPU-OBP-COLD sc2 move
89 sc2 scr sc1 stx \ Mark as COLD
90
91\dtc 'acf enterforth ip set
92\itc 'body enterforth ip set
93 ip base ip add
94\itc next
95\dtc ip %g0 %g0 jmpl nop
96c;
97
98headerless
99defer slave-idle-loop-hook ( -- ) ' noop is slave-idle-loop-hook
100: (slave-idle-loop)
101 flush-temporary-mappings
102 slave-idle-loop-hook
103 enable-cpu-errors
104 mid@ enable-reentry
105 slave-idle-loop
106;
107
108\
109\ Setup the per cpu rp0, sp0 pointers just the once.
110\ Don't make this a : definition because we don't
111\ have stacks yet!!
112\
113label slave-init
114 up sc1 scr get-cpu-struct
115 CPU-INIT sc1 sc2 scr mark-cpu-state
116 scr sc1 sc2 set-rp0
117 scr sc1 sc2 set-sp0
118
119[ifndef] SUN4V
120 0 >cpu-version-reg sc3 set
121 sc2 rdver
122 sc2 scr sc3 stx \ save CPU version
123[then]
124
125 scr sp get-sp0
126 scr rp get-rp0
127 sp /n sp add \ account for TOS
128
129 'body (slave-idle-loop) ip set
130 ip base ip add
131 next
132end-code
133
134code do-release-prom ( who? acf -- )
135\dtc tos ip move
136\itc tos sc1 move
137 sp tos pop
138 tos sc2 move
139 sp tos pop
140 sc2 sc3 mutex-set prom-lock
141\dtc ip %g0 %g0 jmpl nop
142\itc sc1 %g0 scr rtget
143\itc scr base %g0 jmpl nop
144 \ Not Reached
145c;
146
147: master-release-prom ( n -- )
148 dup >cpu-struct >cpu-status dup @ if ( n adr )
149 CPU-ENTERFORTH swap ! ( n )
150 cpu-state >cpu-status @ ( n status )
151 CPU-OBP-WARM = if ( n )
152 ['] slave-bp-loop ( n )
153 else ( n )
154 ['] slave-idle-loop ( n acf )
155 then ( n acf )
156 do-release-prom ( )
157 else ( n adr )
158 2drop ." CPU Not ready" cr
159 then
160;
161
162headers
163