Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: common.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: @(#)common.fth 1.1 06/02/16 | |
43 | purpose: | |
44 | copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | headers | |
48 | ||
49 | : unaligned-w@ ( adr -- val ) dup c@ swap 1+ c@ swap bwjoin ; | |
50 | ||
51 | struct | |
52 | /w field >send-size | |
53 | /c field >command | |
54 | constant /send-hdr | |
55 | ||
56 | struct | |
57 | /w field >reply-size | |
58 | /c field >status | |
59 | constant /reply-hdr | |
60 | ||
61 | \ 512 max mtu minus 8 byte queue ptk minus header | |
62 | h# 200 8 - /send-hdr - constant blocksize | |
63 | ||
64 | : setup-pkt ( len cmd -- tx-bytes ) | |
65 | outbuf >command c! ( len ) | |
66 | blocksize min dup outbuf >send-size w! ( len' ) | |
67 | /send-hdr + ( tx-bytes ) | |
68 | ; | |
69 | ||
70 | : poll ( acf -- ) | |
71 | >r d# 100 begin r@ execute 0= over 0<> and while 1 - 10 ms repeat | |
72 | r> drop 0= if | |
73 | cmn-error[ " ASR transfer timed out" ]cmn-end | |
74 | -1 throw | |
75 | then | |
76 | ; | |
77 | ||
78 | : svc-enable ( adr len -- status ) | |
79 | enable-cmd setup-pkt ( adr bytes ) | |
80 | swap outbuf /send-hdr + ( bytes adr dest ) | |
81 | outbuf >send-size unaligned-w@ move ( bytes ) | |
82 | ['] send? poll send ( ) | |
83 | ['] recv? poll recv if ( ) | |
84 | inbuf >status c@ ( status ) | |
85 | else ( ) | |
86 | asr-rx-error throw ( err ) | |
87 | then | |
88 | ; | |
89 | ||
90 | : svc-disable ( adr len -- status ) | |
91 | disable-cmd setup-pkt ( adr bytes ) | |
92 | swap outbuf /send-hdr + ( bytes adr dest ) | |
93 | outbuf >send-size unaligned-w@ move ( bytes ) | |
94 | ['] send? poll send ( ) | |
95 | ['] recv? poll recv if ( ) | |
96 | inbuf >status c@ ( status ) | |
97 | else ( ) | |
98 | asr-rx-error throw ( err ) | |
99 | then | |
100 | ; | |
101 | ||
102 | : svc-state ( adr -- buflen|0 status ) | |
103 | 0 state-cmd setup-pkt ( adr bytes ) | |
104 | ['] send? poll send ( adr ) | |
105 | ['] recv? poll recv if ( adr ) | |
106 | inbuf >status c@ ?dup if ( adr status ) | |
107 | nip 0 swap ( 0 status ) | |
108 | else ( adr ) | |
109 | inbuf /reply-hdr + swap ( state adr ) | |
110 | inbuf >reply-size unaligned-w@ dup >r move ( len status ) | |
111 | r> asr-cmd-ok ( len status ) | |
112 | then ( len status ) | |
113 | else ( adr ) | |
114 | drop asr-rx-error throw ( err ) | |
115 | then | |
116 | ; | |
117 | ||
118 | : svc-statelen ( -- len|0 status ) | |
119 | 0 statelen-cmd setup-pkt ( bytes ) | |
120 | ['] send? poll send ( ) | |
121 | ['] recv? poll recv if ( ) | |
122 | inbuf >status c@ ?dup if ( status ) | |
123 | 0 swap ( 0 status ) | |
124 | else ( ) | |
125 | inbuf /reply-hdr + unaligned-w@ asr-cmd-ok ( len status ) | |
126 | then ( len status ) | |
127 | else ( ) | |
128 | asr-rx-error throw ( err ) | |
129 | then | |
130 | ; | |
131 | ||
132 | : svc-query ( buf len -- flags ) | |
133 | query-cmd setup-pkt ( adr bytes ) | |
134 | swap outbuf /send-hdr + ( bytes adr dest ) | |
135 | outbuf >send-size unaligned-w@ move ( bytes ) | |
136 | ['] send? poll send ( ) | |
137 | ['] recv? poll recv if ( ) | |
138 | inbuf >status c@ ?dup if ( error ) | |
139 | throw ( error ) | |
140 | else ( ) | |
141 | inbuf /reply-hdr + c@ ( flags ) | |
142 | then ( flags ) | |
143 | else ( ) | |
144 | asr-rx-error throw ( error ) | |
145 | then | |
146 | ; | |
147 | ||
148 | 0 value svc-opened? | |
149 | ||
150 | : svc-open ( -- ) | |
151 | svc-opened? if exit then | |
152 | asr-sid /send-hdr blocksize + init-svc | |
153 | -1 to svc-opened? | |
154 | ; | |
155 | ||
156 | : svc-close finish-svc ; |