Commit | Line | Data |
---|---|---|
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 ============================================ | |
42 | id: @(#)switchcpu.fth 1.14 02/09/20 | |
43 | purpose: | |
44 | copyright: Copyright 1995-2002 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | headerless | |
48 | ||
49 | : cpu-status? ( cpu status -- flag ) | |
50 | over mid-ok? if | |
51 | swap >cpu-struct >cpu-status @ = | |
52 | else | |
53 | 2drop false | |
54 | then | |
55 | ; | |
56 | ||
57 | : cpu-started? ( cpu# -- flag ) CPU-STARTED cpu-status? ; | |
58 | : cpu-idled? ( cpu# -- flag ) CPU-PARKED cpu-status? ; | |
59 | : idle-cpu ( cpu# -- ) | |
60 | dup cpu-started? over mid@ <> and if ( cpu# ) | |
61 | xcall-idle-cpu ( fail? ) | |
62 | then drop ( ) | |
63 | ; | |
64 | : resume-cpu ( cpu# -- ) | |
65 | dup cpu-idled? over mid@ <> and if ( cpu# ) | |
66 | xcall-resume-cpu ( fail? ) | |
67 | then drop ( ) | |
68 | ; | |
69 | ||
70 | : idle-other-cpus ( -- ) ['] idle-cpu do-foreach-cpu ; | |
71 | : resume-other-cpus ( -- ) ['] resume-cpu do-foreach-cpu ; | |
72 | ||
73 | headers | |
74 | ||
75 | : switch-cpu ( cpu# -- ) | |
76 | \ Simply return if cpu# is the currently running CPU | |
77 | dup mid@ = if drop exit then | |
78 | dup mid-ok? if ( cpu# ) | |
79 | dup xcall-get-pc 0= if ( cpu# pc ) | |
80 | drop ( cpu# ) | |
81 | dup idle-cpu ( cpu# ) | |
82 | dup >cpu-struct >cpu-status @ ( cpu# status ) | |
83 | CPU-IDLING <> if ( cpu# ) | |
84 | d# 5 0 do dup cpu-idled? ?leave d# 100 ms loop | |
85 | dup cpu-idled? ( cpu# switch? ) | |
86 | else ( cpu# ) | |
87 | true ( cpu# true ) | |
88 | then ( cpu# switch? ) | |
89 | if master-release-prom else drop then | |
90 | then | |
91 | then ( ) | |
92 | drop ." CPU not responding" cr | |
93 | ; | |
94 | ||
95 | chain: enterforth-chain | |
96 | idle-other-cpus | |
97 | ; | |
98 | ||
99 | chain: go-chain | |
100 | resume-other-cpus | |
101 | ; | |
102 |