Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / arch / sun4v / switchcpu.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: switchcpu.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: @(#)switchcpu.fth 1.3 07/06/14
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47headerless
48
49\ Compare cpu state to given state
50: cpu-status? ( cpu status -- flag )
51 over mid-ok? if ( cpu status )
52 swap >cpu-struct >cpu-status @ = ( flag )
53 else ( cpu status )
54 2drop false ( false )
55 then ( flag )
56;
57
58: cpu-started? ( cpu# -- flag ) CPU-STARTED cpu-status? ;
59: cpu-idled? ( cpu# -- flag ) CPU-PARKED cpu-status? ;
60: idle-cpu ( cpu# -- )
61 dup cpu-started? over mid@ <> and if ( cpu# )
62 xcall-idle-cpu ( fail? )
63 then drop ( )
64;
65: resume-cpu ( cpu# -- )
66 dup cpu-idled? over mid@ <> and if ( cpu# )
67 xcall-resume-cpu ( fail? )
68 then drop ( )
69;
70
71: idle-other-cpus ( -- ) ['] idle-cpu do-foreach-cpu ;
72: resume-other-cpus ( -- ) ['] resume-cpu do-foreach-cpu ;
73
74code do-release-prom ( who? acf -- )
75 tos ip move \ Move acf to ip
76 sp tos pop \ Pop stack
77 tos sc2 move \ sc2 has who?
78 sp tos pop \ Pop stack
79 sc2 sc3 mutex-set prom-lock \ Set prom-lock for who?
80 ip %g0 %g0 jmpl nop \ Jump to acf address
81 \ Not Reached
82c;
83
84: master-release-prom ( n -- )
85 dup >cpu-struct >cpu-status @ if ( n )
86 \ Set PIL level to 0xF before switching and before entering slave loop
87 \ this will disable ALARM interrupt and hence break may not work
88 cmn-warn[
89 " Sending a break while in OpenBoot might fail to get to OK prompt!"
90 ]cmn-end
91 h# f pil! ( n )
92 dup >r 0 0 xcall-slave-enterforth r> xcall-cpu drop ( n )
93 cpu-state >cpu-status @ ( n status )
94 CPU-OBP-WARM = if ( n )
95 ['] slave-bp-loop ( n )
96 else ( n )
97 ['] slave-idle-loop ( n acf )
98 then ( n acf )
99 do-release-prom ( )
100 else ( n )
101 cmn-warn[ " CPU %x is not ready" ]cmn-end ( )
102 then
103;
104
105headers
106
107: switch-cpu ( cpu# -- )
108 \ Simply return if cpu# is the currently running CPU
109 dup mid@ = if drop exit then ( )
110 dup mid-ok? if ( cpu# )
111 dup xcall-get-pc 0= if ( cpu# pc )
112 drop ( cpu# )
113 dup idle-cpu ( cpu# )
114 dup >cpu-struct >cpu-status @ ( cpu# status )
115 CPU-IDLING <> if ( cpu# )
116 d# 5 0 do dup cpu-idled? ?leave d# 100 ms loop
117 dup cpu-idled? ( cpu# switch? )
118 else ( cpu# )
119 true ( cpu# true )
120 then ( cpu# switch? )
121 if master-release-prom else drop then ( )
122 then ( )
123 else ( cpu# )
124 cmn-warn[ " CPU %x is not present or is not responding" ]cmn-end
125 then ( cpu# )
126;
127
128chain: enterforth-chain
129 idle-other-cpus
130;
131
132chain: go-chain
133 resume-other-cpus
134;
135