Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / arch / sun4v / guest-state.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: guest-state.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: @(#)guest-state.fth 1.1 07/06/22
43purpose: Functions that support guest state implementation.
44copyright: Copyright 2007 Sun Microsystems, Inc. All rights reserved.
45copyright: Use is subject to license terms.
46
47headerless
48
491 constant sis-normal
502 constant sis-transitional
51
52\ max-state-string-len is the length of the C-string that contains the
53\ software state description (NULL terminated)
54d# 32 constant max-state-string-len
55\ stored-host-string-len is the length of the FORTH-string that contains the
56\ software state description (non-NULL terminated)
57d# 31 constant stored-host-string-len
58
59h# 70 constant soft-state-set
60h# 71 constant soft-state-get
61h# 80 constant fast-trap-num
62
630 value guest-state-output-buffer-ptr
640 value guest-state-input-buffer-ptr
65
660 value phy-guest-state-output-buffer
670 value phy-guest-state-input-buffer
68
690 value stored-host-state-string-ptr
70sis-transitional value stored-host-state
71
72false value host-state-stored?
73false value is-reset-reboot?
74false value host-supports-guest-state
75
76variable stand-init-status false stand-init-status !
77
78
79: stand-init-completed? ( -- completed? ) stand-init-status @ ;
80: stand-init-completed ( -- ) true stand-init-status ! ;
81
82
83\ This function sets the guest state value
84: set-guest-state ( state addr len -- error? )
85 2dup stored-host-string-len <= swap 0>= and if ( state addr len )
86 guest-state-output-buffer-ptr max-state-string-len 0 fill ( state addr len )
87 1+ guest-state-output-buffer-ptr swap move ( state )
88 phy-guest-state-output-buffer ( state a-addr )
89 2 1 soft-state-set fast-trap-num htrap ( error? )
90 else
91 -1 ( error )
92 then
93
94;
95
96\ this function gets the current value of guest state
97: get-guest-state ( -- a-addr state error? )
98 guest-state-input-buffer-ptr
99 phy-guest-state-input-buffer ( a-addr phy )
100 1 2 soft-state-get fast-trap-num htrap ( a-addr state error? )
101;
102
103headers
104
105\ This function will print out the current guest state to the console
106: .guest-state ( -- )
107 get-guest-state drop ( a-addr state )
108 max-state-string-len swap ( str,len state )
109
110 case
111 sis-normal of " SIS_NORMAL " endof ( str,len [state | str,len] )
112 sis-transitional of " SIS_TRANSITIONAL " endof ( str,len [state | str,len] )
113 cmn-fatal[ " Invalid host state %x" ]cmn-end
114 endcase ( str,len str',len' )
115 cmn-type[ " Current guest state: %s %s" ]cmn-end
116;
117
118\ Client Interface Function that allows the os to tell OBP that it supports
119\ the guest state feature.
120
121cif: SUNW,soft-state-supported ( -- )
122 true to host-supports-guest-state ( )
123;
124
125\ OBP2 - Set guest state to SIS_TRANSITIONAL/Openboot Running
126\ The startup hook is called in the startup command.
127defer old-sc-startup-hook ' startup-hook behavior is old-sc-startup-hook
128: guest-state-startup-hook ( -- )
129 old-sc-startup-hook ( )
130 stand-init-completed ( )
131 sis-transitional " Openboot Running" set-guest-state drop ( )
132;
133' guest-state-startup-hook is startup-hook
134
135\ OBP3 - Set guest state to SIS_TRANSITIONAL/Openboot Primary Boot Loader
136\ The boot load hook is called when obp is loading the file to be booted
137defer old-sc-$boot-load-hook ' $boot-load-hook behavior is old-sc-$boot-load-hook
138: guest-state-$boot-load-hook ( -- )
139 old-sc-$boot-load-hook ( )
140 sis-transitional " Openboot Primary Boot Loader" set-guest-state drop ( )
141;
142' guest-state-$boot-load-hook is $boot-load-hook
143
144\ OBP4 - Set guest state to SIS_TRANSITIONAL/Openboot Running UFS Boot
145\ The boot hook is called while openboot is booting.
146defer old-$boot-hook ' $boot-hook behavior is old-$boot-hook
147: guest-state-$boot-hook ( -- )
148 old-$boot-hook ( )
149 sis-transitional " Openboot Running UFS Boot" set-guest-state drop ( )
150;
151' guest-state-$boot-hook is $boot-hook
152
153
154\ OS - Set guest state to SIS_NORMAL/OS Started. No State Support.
155\ The boot hook is called when the host os takes over the trap table. If
156\ the host has not already indicated to OBP that it supports guest state
157\ then the guest state is set to a generic host running state that provides
158\ no information about the hosts state.
159defer old-guest-state-boot-hook ' guest-state-boot-hook behavior is old-guest-state-boot-hook
160: guest-state-boot ( -- )
161 old-guest-state-boot-hook ( )
162 host-supports-guest-state 0= if ( )
163 sis-normal to stored-host-state ( )
164 " OS Started. No state support." ( addr len )
165 stored-host-state-string-ptr swap move ( )
166 then
167;
168' guest-state-boot is guest-state-boot-hook
169
170
171\ OBP5 - Set guest state to SIS_TRANSITIONAL/Openboot Running Host Halted
172\ The client exited hook is called when the obp client exited command is
173\ called.
174defer old-sc-client-exited ' client-exited behavior is old-sc-client-exited
175: guest-state-client-exited-hook
176 old-sc-client-exited ( )
177 sis-transitional " Openboot Running Host Halted" set-guest-state drop ( )
178;
179' guest-state-client-exited-hook is client-exited
180
181
182\ OBP6 - Set guest state to SIS_TRANSITIONAL/Openboot Reset Reboot
183\ The guest-state-restart-hook is called when OBP does a reset command.
184defer old-restart-hook ' restart-hook behavior is old-restart-hook
185: guest-state-restart-hook ( -- )
186 old-restart-hook ( )
187 sis-transitional " Openboot Reset Reboot" set-guest-state drop ( )
188 true to is-reset-reboot? ( )
189;
190' guest-state-restart-hook is restart-hook
191
192
193\ OBP7 - Set guest state to SIS_TRANSITIONAL/Openboot Exited
194\ This hook sets the guest state to OBP exited state when the reset-all
195\ command is exicuted unless the reset-all command was executed by the $reset
196\ command (the guest state should be reset reboot)
197defer old-(reset-all-hook ' (reset-all-hook behavior is old-(reset-all-hook
198: guest-state-(reset-all-hook ( -- )
199 old-(reset-all-hook ( )
200 is-reset-reboot? 0= if ( )
201 sis-transitional " Openboot Exited" set-guest-state drop ( )
202 then
203;
204' guest-state-(reset-all-hook is (reset-all-hook
205
206
207\ OBP7 - Set guest state to SIS_TRANSITIONAL/Openboot Exited
208\ This hook is called when the poweron command is executed.
209defer old-power-off-hook ' power-off-hook behavior is old-power-off-hook
210: guest-state-power-off-hook ( -- )
211 old-power-off-hook ( )
212 sis-transitional " Openboot Exited" set-guest-state drop ( )
213;
214' guest-state-power-off-hook is power-off-hook
215
216
217\ OBP9 - Set guest state to SIS_TRANSITIONAL/Openboot Host Broken
218\ The reenter hook is called when the host has been broken and control
219\ drops back down to OBP. The state is changed to host broken. The
220\ old os state does not need to be saved because the enter cif function
221\ already saved the state.
222defer old-sc-reenter-hook ' reenter-hook behavior is old-sc-reenter-hook
223: guest-state-reenter-hook ( -- )
224 old-sc-reenter-hook
225 sis-transitional " Openboot Host Received Break" set-guest-state drop ( )
226;
227' guest-state-reenter-hook is reenter-hook
228
229
230\ OBP8 - Set guest state to SIS_TRANSITIONAL/Openboot Callback
231defer old-sc-cif-enter-hook ' cif-enter-hook behavior is old-sc-cif-enter-hook
232: guest-state-cif-enter-hook ( -- )
233 old-sc-cif-enter-hook ( )
234 true to host-state-stored? ( )
235 get-guest-state drop to stored-host-state ( a-addr )
236 stored-host-state-string-ptr max-state-string-len move ( )
237 sis-transitional " Openboot Callback" set-guest-state drop ( )
238;
239' guest-state-cif-enter-hook is cif-enter-hook
240
241
242\ OBP8 - Set guest state back to saved host guest state
243\ The cif exit hook is called while the cif gives control back to the host
244defer old-sc-cif-exit-hook ' cif-exit-hook behavior is old-sc-cif-exit-hook
245: guest-state-cif-exit-hook ( -- )
246 old-sc-cif-exit-hook ( )
247 stored-host-state ( state )
248 stored-host-state-string-ptr stored-host-string-len ( state a-addr len )
249 set-guest-state drop ( )
250 false to host-state-stored? ( )
251;
252' guest-state-cif-exit-hook is cif-exit-hook
253
254
255\ OBP9 - Set guest state to saved host guest state
256\ When the go command is called the guest state needs to be restored to the
257\ value that it was before the host called back into OBP.
258chain: go-chain ( -- )
259 host-state-stored? if
260 stored-host-state ( state )
261 stored-host-state-string-ptr stored-host-string-len ( state a-addr len )
262 set-guest-state drop ( )
263 false to host-state-stored? ( )
264 then
265;
266
267
268\ OBP10 - Set guest state to SIS_TRANSITIONAL/Openboot Failed
269\ or SIS_TRANSITIONAL/Openboot Running
270\ or SIS_TRANSITIONAL/Openboot Running Host Halted
271\ When enterforth function is called either a trap has occured
272\ First if openboot took a trap before it was initialized then mark as OBP failed
273\ Second check to see if OBP was broken. If it was set the guest state to OBP
274\ running. If the host had already started booting when a user requested a break in
275\ obp then the guest state is set to running host halted.
276chain: enterforth-chain ( -- )
277 stand-init-completed? 0= if ( )
278 sis-transitional " Openboot Failed" set-guest-state drop ( )
279 exit
280 then
281 aborted? @ if ( )
282 already-go? if ( )
283 sis-transitional " Openboot Running Host Halted" ( state addr len )
284 else
285 sis-transitional " Openboot Running" ( state addr len )
286 then
287 set-guest-state drop ( )
288 then
289;
290
291
292\ The standard initialization for the guest state feature includes
293\ initializing status variables, allocating space to temporarily save a
294\ guest state location, and creating an 32 bit alligned buffer for the
295\ guest state h-calls.
296stand-init: Guest State Initialization
297
298 max-state-string-len alloc-mem to stored-host-state-string-ptr ( )
299
300 max-state-string-len 2* alloc-mem ( addr )
301 max-state-string-len round-up to guest-state-output-buffer-ptr ( )
302 guest-state-output-buffer-ptr max-state-string-len erase ( )
303 guest-state-output-buffer-ptr >physical drop ( phy )
304 to phy-guest-state-output-buffer ( )
305
306 max-state-string-len 2* alloc-mem ( addr )
307 max-state-string-len round-up to guest-state-input-buffer-ptr ( )
308 guest-state-input-buffer-ptr max-state-string-len erase ( )
309 guest-state-input-buffer-ptr >physical drop ( phy )
310 to phy-guest-state-input-buffer ( )
311
312;
313
314headers