Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: support.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: @(#)support.fth 1.8 04/04/21 | |
43 | purpose: | |
44 | copyright: Copyright 1997-2000,2004 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | \ An ATA packet looks like: | |
48 | \ byte Meaning | |
49 | \ 0 cmd | |
50 | \ 1 <PAD> | |
51 | \ 2 error | |
52 | \ 3 #blocks | |
53 | \ 4,5,6,7 block# | |
54 | \ 8,9,a,b <PAD> | |
55 | \ | |
56 | \ | |
57 | struct | |
58 | 1 field >cmd-byte | |
59 | 1 field >error | |
60 | 1 field .pad1 | |
61 | 1 field >#blocks | |
62 | 4 field >block# | |
63 | 4 field .pad2 | |
64 | constant /ata-pkt | |
65 | ||
66 | : count! ( data -- ) 2 ata! ; | |
67 | : sec! ( data -- ) 3 ata! ; | |
68 | : cyl-lo! ( data -- ) 4 ata! ; | |
69 | : cyl-hi! ( data -- ) 5 ata! ; | |
70 | : cyl! ( cyl -- ) wbsplit cyl-hi! cyl-lo! ; | |
71 | : head! ( data -- ) 6 ata! ; | |
72 | ||
73 | : >disk ( id -- ) 1 and 4 << ; | |
74 | ||
75 | : select-drive ( id -- ) >disk cmd-reg-bits or head! ; | |
76 | ||
77 | \ | |
78 | \ This routine fills the registers with meaningfull data | |
79 | \ | |
80 | : lba! ( block -- ) | |
81 | lbsplit ( sect cyl-lo cyl-hi xtra ) | |
82 | h# f and ( sect cyl-lo cyl-hi hds ) | |
83 | disk-id >disk or ( sect cyl-lo cyl-hi hds' ) | |
84 | cmd-reg-bits or ( sect cyl-lo cyl-hi hds' ) | |
85 | head! ( sect cyl-lo cyl-hi ) | |
86 | cyl-hi! cyl-lo! sec! ( -- ) | |
87 | ; | |
88 | ||
89 | : drive+cmd! ( cdb -- ) | |
90 | disk-id >disk cmd-reg-bits or head! | |
91 | c@ cmd! 1 ms | |
92 | ; | |
93 | ||
94 | : dataless-xfer ( pkt -- fail? ) | |
95 | >cdb-ptr l@ ( cdb ) | |
96 | d# 2000 wait-!busy? if | |
97 | drive+cmd! ( -- ) | |
98 | timeout wait-!busy? drop ( -- ) | |
99 | false ( false ) | |
100 | else ( cdb ) | |
101 | drop true ( true ) | |
102 | then ( fail? ) | |
103 | ; | |
104 | ||
105 | : addressless-xfer ( pkt -- fail? ) | |
106 | get-pkt-data >r ( buffer cdb ) | |
107 | d# 2000 wait-!busy? if ( buffer cdb ) | |
108 | drive+cmd! ( buffer ) | |
109 | timeout wait-data&!busy? if ( buffer ) | |
110 | cmd-regs swap h# 200 ( cmd-regs buffer len ) | |
111 | dup r> >transfer-bytes l! ( cmd-regs buffer len ) | |
112 | xfer-fn false exit ( false ) | |
113 | then 0 ( buffer 0 ) | |
114 | then ( buffer cdb ) | |
115 | r> 3drop true ( true ) | |
116 | ; | |
117 | ||
118 | : data-xfer ( pkt -- fail? ) | |
119 | get-pkt-data >r ( buffer cdb ) | |
120 | dup >block# l@ lba! ( buffer cdb ) | |
121 | dup >#blocks c@ count! ( buffer cdb ) | |
122 | tuck ( cdb buffer cdb ) | |
123 | d# 2000 wait-!busy? if ( cdb buffer cdb ) | |
124 | >cmd-byte c@ cmd! 1 ms ( cdb buffer ) | |
125 | dup >r ( cdb buffer ) | |
126 | over >#blocks c@ ( cdb buffer #blocks ) | |
127 | ?dup 0= if d# 256 then ( cdb buffer #blocks ) | |
128 | 0 do ( cdb buffer ) | |
129 | timeout wait-data? 0= ?leave ( cdb buffer ) | |
130 | cmd-regs over h# 200 ( cdb buffer cmd-regs buffer len ) | |
131 | xfer-fn ( cdb buffer ) | |
132 | h# 200 + ( cdb buffer' ) | |
133 | \ Wait up to 2 seconds for non busy status | |
134 | d# 200.000 xfer-wait-!busy? 0= ( cdb buffer ) | |
135 | ?leave ( cdb buffer ) | |
136 | loop ( cdb buffer ) | |
137 | nip r> - ( #bytes ) | |
138 | r> >transfer-bytes l! ( -- ) | |
139 | false ( false ) | |
140 | else ( cdb buffer cdb ) | |
141 | r> 2drop 2drop true ( true ) | |
142 | then ( flag ) | |
143 | ; | |
144 | ||
145 | : .identify ( pkt -- fail? ) | |
146 | dup >r (read) ( pkt ) | |
147 | addressless-xfer ?dup if ( -- ) | |
148 | r> drop ( true ) | |
149 | else ( -- ) | |
150 | r> >data-ptr l@ ( buffer ) | |
151 | h# 200 bounds do i w@ flip i w! 2 +loop | |
152 | false ( false ) | |
153 | then ( flag ) | |
154 | ; | |
155 | ||
156 | \ This is how I check if a disc is present, | |
157 | \ If the recalibrate doesn't have device ready set within 100ms of the | |
158 | \ command being issued I assume the device is missing. | |
159 | \ | |
160 | : .recalibrate ( pkt -- fail? ) | |
161 | get-pkt-data drop ( buffer cdb ) | |
162 | nip d# 2000 wait-!busy? if ( cdb ) | |
163 | drive+cmd! ( -- ) | |
164 | d# 100 wait-ready? if ( -- ) | |
165 | true ( true ) | |
166 | else ( -- ) | |
167 | timeout wait-!busy? drop ( -- ) | |
168 | false ( false ) | |
169 | then ( flag? ) | |
170 | else ( cdb ) | |
171 | drop true ( true ) | |
172 | then ( fail? ) | |
173 | ; | |
174 | ||
175 | : run-ata ( pkt -- error? ) | |
176 | dup >r | |
177 | r@ >timeout l@ is timeout ( pkt ) | |
178 | r@ >cdb-ptr l@ >cmd-byte c@ ( pkt cmd ) | |
179 | h# fe and case ( pkt ) | |
180 | h# E0 of dataless-xfer endof \ SPIN UP/DOWN | |
181 | h# EC of .identify endof \ IDENTIFY | |
182 | h# A0 of .identify endof \ IDENTIFY | |
183 | h# 10 of .recalibrate endof \ RECALIBRATE | |
184 | h# 20 of (read) data-xfer endof \ READ SECTORS | |
185 | h# 30 of (write) data-xfer endof \ WRITE SECTORS | |
186 | >r true r> | |
187 | endcase ( fail? ) | |
188 | r> swap if ( pkt ) | |
189 | stat@ over >status l! ( pkt ) | |
190 | err@ over >cdb-ptr l@ ( pkt err cdb ) | |
191 | >error c! ( pkt ) | |
192 | true ( pkt true ) | |
193 | else ( pkt ) | |
194 | false ( pkt false ) | |
195 | then nip ( flag ) | |
196 | ; |