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.12 01/05/29 | |
43 | purpose: | |
44 | copyright: Copyright 1997-2001 Sun Microsystems, Inc. All Rights Reserved | |
45 | ||
46 | \ This is the additional code required to permit atapi packets to | |
47 | \ be run from downstream devices. | |
48 | ||
49 | headers | |
50 | ||
51 | 0 value atapi-debug? | |
52 | 5 value #atapi-retries | |
53 | ||
54 | headerless | |
55 | ||
56 | : atapi-features! ( data -- ) cmd-regs 1 + c! ; | |
57 | : atapi-reason@ ( -- data ) cmd-regs 2 + c@ ; | |
58 | ||
59 | : pkt-size@ ( -- len ) 4 ata@ 5 ata@ bwjoin ; | |
60 | : pkt-size! ( len -- ) wbsplit 5 ata! 4 ata! ; | |
61 | ||
62 | : .dev-ready? ( status -- set? ) h# 88 and h# 8 = ; | |
63 | : dev-ready? ( t -- ok? ) ['] .dev-ready? alt-wait-status ; | |
64 | ||
65 | : .wait-irq? ( status -- set? ) drop ide-irq? ; | |
66 | : wait-irq ( t -- ok? ) ['] .wait-irq? alt-wait-status ; | |
67 | ||
68 | : .atapi-err ( pkt code -- ) | |
69 | atapi-debug? if | |
70 | ." CMD Failed: " dup .x space ." = " | |
71 | ." SenseKey: " | |
72 | dup d# 4 >> case | |
73 | h# 0 of ." No Sense" endof | |
74 | h# 1 of ." Recovered Error" endof | |
75 | h# 2 of ." Not Ready" endof | |
76 | h# 3 of ." M Error" endof | |
77 | h# 4 of ." H/W Error" endof | |
78 | h# 5 of ." Illegal REQ" endof | |
79 | h# 6 of ." ATTENTION" endof | |
80 | h# 7 of ." PROTECT" endof | |
81 | h# b of ." ABRT" endof | |
82 | h# e of ." MISCOMPARE" endof | |
83 | ( ) ." RSVD" | |
84 | endcase space ." ErrBits: " | |
85 | dup h# f and | |
86 | dup h# 8 and if ." MCR " then | |
87 | dup h# 4 and if ." ABRT " then | |
88 | dup h# 2 and if ." EOM " then | |
89 | dup h# 1 and if ." ILI" then | |
90 | 0= if ." None" then | |
91 | cr | |
92 | then | |
93 | swap >status l! | |
94 | ; | |
95 | ||
96 | : run-atapi ( pkt -- error? ) | |
97 | dup >timeout l@ is timeout ( pkt ) | |
98 | d# 2000 alt-wait-!busy? 0= if drop true exit then | |
99 | disk-id >disk h# e0 or lun or head! ( pkt ) | |
100 | 0 atapi-features! ( pkt ) | |
101 | blocksize pkt-size! ( pkt ) | |
102 | h# a0 cmd! ( pkt ) | |
103 | d# 10 alt-wait-data? 0= if ( pkt ) | |
104 | drop true exit ( true ) | |
105 | then ( pkt ) | |
106 | dup >cdb-ptr l@ ( pkt cdb ) | |
107 | d# 12 bounds do ( pkt ) | |
108 | i w@ data! ( pkt ) | |
109 | astat@ .check-data 0= ?leave ( pkt ) | |
110 | 2 +loop ( pkt ) | |
111 | stat@ h# 1 and if ( pkt ) | |
112 | err@ .atapi-err true exit ( true ) | |
113 | then ( pkt ) | |
114 | begin ( pkt more? ) | |
115 | timeout alt-wait-!busy? if | |
116 | astat@ .check-data | |
117 | else false then ( pkt more? ) | |
118 | while ( pkt ) | |
119 | atapi-reason@ 2 and ( pkt? io ) | |
120 | if (read) else (write) then ( pkt? ) | |
121 | dup >transfer-bytes ( pkt lenptr ) | |
122 | dup >r l@ ( pkt len ) | |
123 | over >data-ptr l@ ( pkt len buffer ) | |
124 | over >r + ( pkt buffer' ) | |
125 | pkt-size@ ( pkt buffer' size ) | |
126 | tuck cmd-regs -rot ( pkt size regs buffer size ) | |
127 | ?dup if xfer-fn else 3drop then ( pkt size ) | |
128 | r> + r> l! ( pkt ) | |
129 | repeat ( pkt ) | |
130 | stat@ h# 1 and if ( pkt ) | |
131 | err@ .atapi-err true exit ( flag ) | |
132 | then ( ) | |
133 | drop false ( flag ) | |
134 | ; |