templeos-info/public/Wb/Kernel/BlkDev/DskATA.HC.HTML

643 lines
73 KiB
Plaintext
Raw Normal View History

2024-03-24 21:24:44 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>ATABlkSel</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF9>I64</span><span class=cF0> blk,</span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l2"></a>{
<a name="l3"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type!=</span><span class=cF3>BDT_ATAPI</span><span class=cF0> &amp;&amp; bd-&gt;base1)
<a name="l4"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base1+</span><span class=cF3>ATAR1_CTRL</span><span class=cF0>,0x8);
<a name="l5"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>//48 Bit LBA?</span><span class=cF0>
<a name="l6"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_NSECT</span><span class=cF0>,cnt.u8[1]);
<a name="l7"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SECT</span><span class=cF0>,blk.u8[3]);
<a name="l8"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,blk.u8[4]);
<a name="l9"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,blk.u8[5]);
<a name="l10"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_NSECT</span><span class=cF0>,cnt);
<a name="l11"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SECT</span><span class=cF0>,blk);
<a name="l12"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,blk.u8[1]);
<a name="l13"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,blk.u8[2]);
<a name="l14"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l15"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0> </span><span class=cF2>//28 Bit LBA</span><span class=cF0>
<a name="l16"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_NSECT</span><span class=cF0>,cnt);
<a name="l17"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SECT</span><span class=cF0>,blk);
<a name="l18"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,blk.u8[1]);
<a name="l19"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,blk.u8[2]);
<a name="l20"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4|blk.u8[3]);
<a name="l21"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l22"></a>}
<a name="l23"></a>
<a name="l24"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>F64</span><span class=cF0> timeout)
<a name="l25"></a>{
<a name="l26"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l27"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l28"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;3;i++)
<a name="l29"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_STAT</span><span class=cF0>)&amp;</span><span class=cF3>ATAS_BSY</span><span class=cF7>)</span><span class=cF0>)
<a name="l30"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l31"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l32"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>0&lt;timeout&lt;</span><span class=cF5>tS</span><span class=cF7>)</span><span class=cF0>);
<a name="l33"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l34"></a>}
<a name="l35"></a>
<a name="l36"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAWaitDRQ</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>F64</span><span class=cF0> timeout)
<a name="l37"></a>{
<a name="l38"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l39"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l40"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;3;i++)
<a name="l41"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>bd-&gt;base0+</span><span class=cF3>ATAR0_STAT</span><span class=cF7>)</span><span class=cF0>&amp;</span><span class=cF3>ATAS_DRQ</span><span class=cF0>)
<a name="l42"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l43"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l44"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>0&lt;timeout&lt;</span><span class=cF5>tS</span><span class=cF7>)</span><span class=cF0>);
<a name="l45"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l46"></a>}
<a name="l47"></a>
<a name="l48"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATANop</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>F64</span><span class=cF0> timeout)
<a name="l49"></a>{
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l51"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l52"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l53"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l54"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_FEAT</span><span class=cF0>,0);
<a name="l55"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_CMD</span><span class=cF0>,</span><span class=cF3>ATA_NOP</span><span class=cF0>);
<a name="l56"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,timeout);
<a name="l57"></a>}
<a name="l58"></a>
<a name="l59"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>ATACmd</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>U8</span><span class=cF0> cmd)
<a name="l60"></a>{
<a name="l61"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_FEAT</span><span class=cF0>,0);
<a name="l62"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_CMD</span><span class=cF0>,cmd);
<a name="l63"></a> bd-&gt;last_time=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l64"></a> </span><span class=cF5>PortNop</span><span class=cF0>;
<a name="l65"></a>}
<a name="l66"></a>
<a name="l67"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAGetRes</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>F64</span><span class=cF0> timeout,</span><span class=cF1>U8</span><span class=cF0> *buf,</span><span class=cF9>I64</span><span class=cF0> cnt,
<a name="l68"></a> </span><span class=cF9>I64</span><span class=cF0> _avail,</span><span class=cF1>Bool</span><span class=cF0> one_read)
<a name="l69"></a>{
<a name="l70"></a> </span><span class=cF9>I64</span><span class=cF0> avail,overflow;
<a name="l71"></a> bd-&gt;flags&amp;=~</span><span class=cF3>BDF_LAST_WAS_WRITE</span><span class=cF0>;
<a name="l72"></a> </span><span class=cF5>MemSet</span><span class=cF0>(buf,0,cnt);
<a name="l73"></a> </span><span class=cF1>while</span><span class=cF0> (cnt&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l74"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>ATAWaitDRQ</span><span class=cF7>(</span><span class=cF0>bd,timeout</span><span class=cF7>)</span><span class=cF0>)
<a name="l75"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l76"></a> </span><span class=cF1>if</span><span class=cF0> (_avail)
<a name="l77"></a> avail=_avail;
<a name="l78"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l79"></a> avail=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>)&lt;&lt;8+</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>);
<a name="l80"></a> </span><span class=cF1>if</span><span class=cF0> (avail) {
<a name="l81"></a> </span><span class=cF1>if</span><span class=cF0> (avail&gt;cnt) </span><span class=cF7>{</span><span class=cF0>
<a name="l82"></a> overflow=avail-cnt;
<a name="l83"></a> avail=cnt;
<a name="l84"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l85"></a> overflow=0;
<a name="l86"></a> </span><span class=cF1>if</span><span class=cF0> (avail&amp;2)
<a name="l87"></a> </span><span class=cF5>RepInU16</span><span class=cF0>(buf,avail&gt;&gt;1,bd-&gt;base0+</span><span class=cF3>ATAR0_DATA</span><span class=cF0>);
<a name="l88"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l89"></a> </span><span class=cF5>RepInU32</span><span class=cF0>(buf,avail&gt;&gt;2,bd-&gt;base0+</span><span class=cF3>ATAR0_DATA</span><span class=cF0>);
<a name="l90"></a> cnt-=avail;
<a name="l91"></a> buf+=avail;
<a name="l92"></a> </span><span class=cF1>while</span><span class=cF0> (overflow&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l93"></a> </span><span class=cF5>InU16</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_DATA</span><span class=cF0>);
<a name="l94"></a> overflow-=2;
<a name="l95"></a> </span><span class=cF1>if</span><span class=cF0> (0&lt;timeout&lt;</span><span class=cF5>tS</span><span class=cF0>)
<a name="l96"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l97"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l98"></a> </span><span class=cF1>if</span><span class=cF0> (one_read)
<a name="l99"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l100"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l101"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l102"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l103"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,timeout);
<a name="l104"></a>}
<a name="l105"></a>
<a name="l106"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAPIWritePktWord</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>F64</span><span class=cF0> timeout,...)
<a name="l107"></a>{
<a name="l108"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l109"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;argc;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l110"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>ATAWaitDRQ</span><span class=cF7>(</span><span class=cF0>bd,timeout</span><span class=cF7>)</span><span class=cF0>)
<a name="l111"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l112"></a> </span><span class=cF5>OutU16</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_DATA</span><span class=cF0>,</span><span class=cF5>EndianU16</span><span class=cF7>(</span><span class=cF0>argv[i]</span><span class=cF7>)</span><span class=cF0>);
<a name="l113"></a> bd-&gt;last_time=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l114"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l115"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l116"></a>}
<a name="l117"></a>
<a name="l118"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAPISetMaxSpeed</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd)
<a name="l119"></a>{
<a name="l120"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l121"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l122"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l123"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l124"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,0);
<a name="l125"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,0);
<a name="l126"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_PACKET</span><span class=cF0>);
<a name="l127"></a> </span><span class=cFD>ATAPIWritePktWord</span><span class=cF0>(bd,0,0xBB00,0xFFFF,0xFFFF,0,0,0);
<a name="l128"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,0);
<a name="l129"></a>}
<a name="l130"></a>
<a name="l131"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAPISeek</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF9>I64</span><span class=cF0> native_blk)
<a name="l132"></a>{
<a name="l133"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l134"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l135"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l136"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l137"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,0);
<a name="l138"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,0);
<a name="l139"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_PACKET</span><span class=cF0>);
<a name="l140"></a> </span><span class=cFD>ATAPIWritePktWord</span><span class=cF0>(bd,0,0x2B00,native_blk&gt;&gt;16,native_blk,0,0,0);
<a name="l141"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,0);
<a name="l142"></a>}
<a name="l143"></a>
<a name="l144"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>ATAPIStartStop</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>F64</span><span class=cF0> timeout,</span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF1>start</span><span class=cF0>)
<a name="l145"></a>{
<a name="l146"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l147"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF1>start</span><span class=cF0>)
<a name="l148"></a> i=0x100;
<a name="l149"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l150"></a> i=0;
<a name="l151"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l152"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l153"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l154"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l155"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_PACKET</span><span class=cF0>);
<a name="l156"></a></span><span class=cF2>//Start/Stop</span><span class=cF0>
<a name="l157"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAPIWritePktWord</span><span class=cF7>(</span><span class=cF0>bd,timeout,0x1B00,0,i,0,0,0</span><span class=cF7>)</span><span class=cF0>)
<a name="l158"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,timeout);
<a name="l159"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l160"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l161"></a>}
<a name="l162"></a>
<a name="l163"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFD>ATAGetDevId</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>F64</span><span class=cF0> timeout,</span><span class=cF1>Bool</span><span class=cF0> keep_id_record)
<a name="l164"></a>{
<a name="l165"></a> </span><span class=cF9>I64</span><span class=cF0> res=</span><span class=cF3>BDT_NULL</span><span class=cF0>;
<a name="l166"></a> </span><span class=cF9>U16</span><span class=cF0> *id_record=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l167"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type!=</span><span class=cF3>BDT_ATAPI</span><span class=cF0> &amp;&amp; bd-&gt;base1)
<a name="l168"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base1+</span><span class=cF3>ATAR1_CTRL</span><span class=cF0>,0x8);
<a name="l169"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l170"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l171"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l172"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l173"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_ID_DEV</span><span class=cF0>);
<a name="l174"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAWaitNotBUSY</span><span class=cF7>(</span><span class=cF0>bd,timeout</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l175"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>bd-&gt;base0+</span><span class=cF3>ATAR0_STAT</span><span class=cF7>)</span><span class=cF0>&amp;</span><span class=cF3>ATAS_ERR</span><span class=cF0>)
<a name="l176"></a> res=</span><span class=cF3>BDT_ATAPI</span><span class=cF0>;
<a name="l177"></a> </span><span class=cF1>else</span><span class=cF0> {
<a name="l178"></a> id_record=</span><span class=cF5>ACAlloc</span><span class=cF0>(512);
<a name="l179"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAGetRes</span><span class=cF7>(</span><span class=cF0>bd,timeout,id_record,512,512,</span><span class=cF3>FALSE</span><span class=cF7>)</span><span class=cF0>)
<a name="l180"></a> res=</span><span class=cF3>BDT_ATA</span><span class=cF0>;
<a name="l181"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l182"></a> </span><span class=cF5>Free</span><span class=cF0>(id_record);
<a name="l183"></a> id_record=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l184"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l185"></a> }
<a name="l186"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l187"></a> </span><span class=cF1>if</span><span class=cF0> (keep_id_record) </span><span class=cF7>{</span><span class=cF0>
<a name="l188"></a> </span><span class=cF5>Free</span><span class=cF0>(bd-&gt;dev_id_record);
<a name="l189"></a> bd-&gt;dev_id_record=id_record;
<a name="l190"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l191"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l192"></a>}
<a name="l193"></a>
<a name="l194"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFD>ATAReadNativeMax</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>F64</span><span class=cF0> timeout)
<a name="l195"></a>{</span><span class=cF2>//Returns zero on err</span><span class=cF0>
<a name="l196"></a> </span><span class=cF9>I64</span><span class=cF0> res=0;
<a name="l197"></a> </span><span class=cF1>Bool</span><span class=cF0> okay=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l198"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type==</span><span class=cF3>BDT_ATAPI</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l199"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l200"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l201"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l202"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l203"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_DEV_RST</span><span class=cF0>);
<a name="l204"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>ATAWaitNotBUSY</span><span class=cF7>(</span><span class=cF0>bd,0</span><span class=cF7>)</span><span class=cF0>)
<a name="l205"></a> okay=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l206"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l207"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>bd-&gt;base0+</span><span class=cF3>ATAR0_STAT</span><span class=cF7>)</span><span class=cF0> &amp; </span><span class=cF3>ATAS_BSY</span><span class=cF0>) {
<a name="l208"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags&amp;</span><span class=cF3>BDF_LAST_WAS_WRITE</span><span class=cF0>)
<a name="l209"></a> </span><span class=cF5>OutU16</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_DATA</span><span class=cF0>,0);
<a name="l210"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l211"></a> </span><span class=cF5>InU16</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_DATA</span><span class=cF0>);
<a name="l212"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l213"></a> </span><span class=cF1>if</span><span class=cF0> (0&lt;timeout&lt;</span><span class=cF5>tS</span><span class=cF0>)
<a name="l214"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l215"></a> }
<a name="l216"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAGetDevId</span><span class=cF7>(</span><span class=cF0>bd,timeout,</span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>==</span><span class=cF3>BDT_NULL</span><span class=cF0>)
<a name="l217"></a> okay=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l218"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l219"></a> </span><span class=cF5>BEqu</span><span class=cF0>(&amp;bd-&gt;flags,</span><span class=cF3>BDf_EXT_SIZE</span><span class=cF0>,</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;bd-&gt;dev_id_record[86],10</span><span class=cF7>)</span><span class=cF0>);
<a name="l220"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l221"></a> </span><span class=cF1>if</span><span class=cF0> (okay) </span><span class=cF7>{</span><span class=cF0>
<a name="l222"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0> &amp;&amp; bd-&gt;base1) {
<a name="l223"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base1+</span><span class=cF3>ATAR1_CTRL</span><span class=cF0>,0x8);
<a name="l224"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l225"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_READ_NATIVE_MAX_EXT</span><span class=cF0>);
<a name="l226"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAWaitNotBUSY</span><span class=cF7>(</span><span class=cF0>bd,timeout</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l227"></a> res.u8[0]=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SECT</span><span class=cF0>);
<a name="l228"></a> res.u8[1]=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>);
<a name="l229"></a> res.u8[2]=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>);
<a name="l230"></a>
<a name="l231"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base1+</span><span class=cF3>ATAR1_CTRL</span><span class=cF0>,0x80);
<a name="l232"></a> res.u8[3]=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SECT</span><span class=cF0>);
<a name="l233"></a> res.u8[4]=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>);
<a name="l234"></a> res.u8[5]=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>);
<a name="l235"></a>
<a name="l236"></a> </span><span class=cF1>if</span><span class=cF0> (res&gt;&gt;24==res&amp;0xFFFFFF) {</span><span class=cF2>//Kludge to make QEMU work</span><span class=cF0>
<a name="l237"></a> bd-&gt;flags&amp;=~</span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>;
<a name="l238"></a> res&amp;=0xFFFFFF;
<a name="l239"></a> }
<a name="l240"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l241"></a> } </span><span class=cF1>else</span><span class=cF0> {
<a name="l242"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type!=</span><span class=cF3>BDT_ATAPI</span><span class=cF0> &amp;&amp; bd-&gt;base1)
<a name="l243"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base1+</span><span class=cF3>ATAR1_CTRL</span><span class=cF0>,0x8);
<a name="l244"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l245"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_READ_NATIVE_MAX</span><span class=cF0>);
<a name="l246"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAWaitNotBUSY</span><span class=cF7>(</span><span class=cF0>bd,timeout</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l247"></a> res.u8[0]=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SECT</span><span class=cF0>);
<a name="l248"></a> res.u8[1]=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>);
<a name="l249"></a> res.u8[2]=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>);
<a name="l250"></a> res.u8[3]=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>) &amp; 0xF;
<a name="l251"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l252"></a> }
<a name="l253"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l254"></a> </span><span class=cF1>return</span><span class=cF0> bd-&gt;max_blk=res;
<a name="l255"></a>}
<a name="l256"></a>
<a name="l257"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFD>ATAPIReadCapacity</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF9>I64</span><span class=cF0> *_blk_size=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l258"></a>{</span><span class=cF2>//Supposedly this can return a res +/- 75 sects.</span><span class=cF0>
<a name="l259"></a></span><span class=cF2>//Error might just be for music.</span><span class=cF0>
<a name="l260"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock=</span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
<a name="l261"></a> </span><span class=cF9>U32</span><span class=cF0> buf[2];
<a name="l262"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAWaitNotBUSY</span><span class=cF7>(</span><span class=cF0>bd,0</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l263"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l264"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l265"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l266"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l267"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,8);
<a name="l268"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,0);
<a name="l269"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_PACKET</span><span class=cF0>);
<a name="l270"></a> </span><span class=cFD>ATAPIWritePktWord</span><span class=cF0>(bd,0,0x2500,0,0,0,0,0);
<a name="l271"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>ATAGetRes</span><span class=cF7>(</span><span class=cF0>bd,0,buf,8,0,</span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>)
<a name="l272"></a> buf[0]=buf[1]=0;
<a name="l273"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l274"></a> buf[0]=buf[1]=0;
<a name="l275"></a>
<a name="l276"></a> </span><span class=cF1>if</span><span class=cF0> (unlock) </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
<a name="l277"></a> </span><span class=cF1>if</span><span class=cF0> (_blk_size) *_blk_size=</span><span class=cF5>EndianU32</span><span class=cF0>(buf[1]);
<a name="l278"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>EndianU32</span><span class=cF0>(buf[0]);
<a name="l279"></a>}
<a name="l280"></a>
<a name="l281"></a></span><span class=cF9>CATAPITrack</span><span class=cF0> *</span><span class=cFD>ATAPIReadTrackInfo</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF9>I64</span><span class=cF0> blk)
<a name="l282"></a>{
<a name="l283"></a> </span><span class=cF9>CATAPITrack</span><span class=cF0> *res=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CATAPITrack</span><span class=cF7>)</span><span class=cF0>);
<a name="l284"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock=</span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
<a name="l285"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAWaitNotBUSY</span><span class=cF7>(</span><span class=cF0>bd,0</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l286"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l287"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l288"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l289"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l290"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CATAPITrack</span><span class=cF7>)</span><span class=cF0>&amp;0xFF);
<a name="l291"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CATAPITrack</span><span class=cF7>)</span><span class=cF0>&gt;&gt;8);
<a name="l292"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_PACKET</span><span class=cF0>);
<a name="l293"></a> </span><span class=cFD>ATAPIWritePktWord</span><span class=cF0>(bd,0,0x5200,blk.u16[1],blk.u16[0],
<a name="l294"></a> </span><span class=cF7>(</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CATAPITrack</span><span class=cF0>)&amp;0xFF00</span><span class=cF7>)</span><span class=cF0>&gt;&gt;8,</span><span class=cF7>(</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CATAPITrack</span><span class=cF0>)&amp;0x00FF</span><span class=cF7>)</span><span class=cF0>&lt;&lt;8,0);
<a name="l295"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>ATAGetRes</span><span class=cF7>(</span><span class=cF0>bd,0,res,</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CATAPITrack</span><span class=cF0>),0,</span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>) {
<a name="l296"></a> </span><span class=cF5>Free</span><span class=cF0>(res);
<a name="l297"></a> res=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l298"></a> }
<a name="l299"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l300"></a> </span><span class=cF5>Free</span><span class=cF0>(res);
<a name="l301"></a> res=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l302"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l303"></a> </span><span class=cF1>if</span><span class=cF0> (unlock) </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
<a name="l304"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l305"></a>}
<a name="l306"></a>
<a name="l307"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAInit</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd)
<a name="l308"></a>{
<a name="l309"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock=</span><span class=cF5>BlkDevLock</span><span class=cF0>(bd),okay=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l310"></a>
<a name="l311"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type==</span><span class=cF3>BDT_ATAPI</span><span class=cF0>)
<a name="l312"></a> bd-&gt;flags&amp;=~</span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>;
<a name="l313"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l314"></a> bd-&gt;flags|=</span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>;
<a name="l315"></a>
<a name="l316"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAReadNativeMax</span><span class=cF7>(</span><span class=cF0>bd,</span><span class=cF5>tS</span><span class=cF0>+0.1</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l317"></a> </span><span class=cFD>ATABlkSel</span><span class=cF0>(bd,bd-&gt;max_blk,0);
<a name="l318"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags&amp;</span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l319"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_SET_MAX_EXT</span><span class=cF0>);
<a name="l320"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l321"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_SET_MAX</span><span class=cF0>);
<a name="l322"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAWaitNotBUSY</span><span class=cF7>(</span><span class=cF0>bd,0</span><span class=cF7>)</span><span class=cF0>) {
<a name="l323"></a> okay=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l324"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type==</span><span class=cF3>BDT_ATAPI</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l325"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>ATAPIStartStop</span><span class=cF7>(</span><span class=cF0>bd,0,</span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>) {
<a name="l326"></a> </span><span class=cF1>if</span><span class=cF0>(!</span><span class=cFD>ATAPISetMaxSpeed</span><span class=cF7>(</span><span class=cF0>bd</span><span class=cF7>)</span><span class=cF0>)
<a name="l327"></a> okay=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l328"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l329"></a> okay=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l330"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l331"></a> }
<a name="l332"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l333"></a> </span><span class=cF1>if</span><span class=cF0> (unlock) </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
<a name="l334"></a> </span><span class=cF1>return</span><span class=cF0> okay;
<a name="l335"></a>}
<a name="l336"></a>
<a name="l337"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAPIWaitReady</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>F64</span><span class=cF0> timeout)
<a name="l338"></a>{
<a name="l339"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l340"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>ATAWaitNotBUSY</span><span class=cF7>(</span><span class=cF0>bd,timeout</span><span class=cF7>)</span><span class=cF0> ||
<a name="l341"></a> !</span><span class=cFD>ATANop</span><span class=cF7>(</span><span class=cF0>bd,timeout</span><span class=cF7>)</span><span class=cF0> ||
<a name="l342"></a> !</span><span class=cF5>ATAPIStartStop</span><span class=cF7>(</span><span class=cF0>bd,timeout,</span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>)
<a name="l343"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l344"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>bd-&gt;base0+</span><span class=cF3>ATAR0_STAT</span><span class=cF7>)</span><span class=cF0> &amp; </span><span class=cF3>ATAS_DRDY</span><span class=cF0> &amp;&amp;
<a name="l345"></a> !</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>bd-&gt;base0+</span><span class=cF3>ATAR0_FEAT</span><span class=cF7>)</span><span class=cF0>);
<a name="l346"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l347"></a> </span><span class=cFD>ATAInit</span><span class=cF0>(bd);
<a name="l348"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l349"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>0&lt;timeout&lt;</span><span class=cF5>tS</span><span class=cF7>)</span><span class=cF0>);
<a name="l350"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l351"></a>}
<a name="l352"></a>
<a name="l353"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>ATAReadBlks</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>U8</span><span class=cF0> *buf, </span><span class=cF9>I64</span><span class=cF0> blk, </span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l354"></a>{
<a name="l355"></a> </span><span class=cF9>I64</span><span class=cF0> retries=3;
<a name="l356"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock=</span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
<a name="l357"></a>
<a name="l358"></a> retry:
<a name="l359"></a> </span><span class=cFD>ATABlkSel</span><span class=cF0>(bd,blk,cnt);
<a name="l360"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l361"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_READ_MULTI_EXT</span><span class=cF0>);
<a name="l362"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l363"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_READ_MULTI</span><span class=cF0>);
<a name="l364"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>ATAGetRes</span><span class=cF7>(</span><span class=cF0>bd,</span><span class=cF5>tS</span><span class=cF0>+1.0,buf,cnt*bd-&gt;blk_size,</span><span class=cF3>BLK_SIZE</span><span class=cF0>,</span><span class=cF3>FALSE</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l365"></a> </span><span class=cF1>if</span><span class=cF0> (retries--) {
<a name="l366"></a> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,0);
<a name="l367"></a> </span><span class=cF1>goto</span><span class=cF0> retry;
<a name="l368"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l369"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l370"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l371"></a>
<a name="l372"></a> </span><span class=cFB>blkdev</span><span class=cF0>.read_cnt+=(cnt*bd-&gt;blk_size)&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l373"></a> </span><span class=cF1>if</span><span class=cF0> (unlock) </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
<a name="l374"></a>}
<a name="l375"></a>
<a name="l376"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ATAProbe</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> base0,</span><span class=cF9>I64</span><span class=cF0> base1,</span><span class=cF9>I64</span><span class=cF0> unit)
<a name="l377"></a>{
<a name="l378"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> bd;
<a name="l379"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&amp;bd,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CBlkDev</span><span class=cF7>)</span><span class=cF0>);
<a name="l380"></a> bd.type=</span><span class=cF3>BDT_ATAPI</span><span class=cF0>;
<a name="l381"></a> bd.base0=base0;
<a name="l382"></a> bd.base1=base1;
<a name="l383"></a> bd.unit=unit;
<a name="l384"></a> bd.blk_size=</span><span class=cF3>DVD_BLK_SIZE</span><span class=cF0>;
<a name="l385"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>ATAGetDevId</span><span class=cF0>(&amp;bd,</span><span class=cF5>tS</span><span class=cF0>+0.1,</span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l386"></a>}
<a name="l387"></a>
<a name="l388"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAPIReadBlks2</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>F64</span><span class=cF0> timeout,</span><span class=cF1>U8</span><span class=cF0> *buf,
<a name="l389"></a> </span><span class=cF9>I64</span><span class=cF0> native_blk, </span><span class=cF9>I64</span><span class=cF0> cnt,</span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF1>lock</span><span class=cF0>)
<a name="l390"></a>{
<a name="l391"></a> </span><span class=cF1>Bool</span><span class=cF0> res=</span><span class=cF3>FALSE</span><span class=cF0>,unlock;
<a name="l392"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&lt;=0)
<a name="l393"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l394"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF1>lock</span><span class=cF0>)
<a name="l395"></a> unlock=</span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
<a name="l396"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAPIWaitReady</span><span class=cF7>(</span><span class=cF0>bd,timeout</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l397"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l398"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l399"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l400"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l401"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,bd-&gt;blk_size);
<a name="l402"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,bd-&gt;blk_size.u8[1]);
<a name="l403"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_PACKET</span><span class=cF0>);
<a name="l404"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAPIWritePktWord</span><span class=cF7>(</span><span class=cF0>bd,timeout,0xA800,
<a name="l405"></a> native_blk.u16[1],native_blk,cnt.u16[1],cnt,0</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l406"></a> </span><span class=cFD>ATAGetRes</span><span class=cF7>(</span><span class=cF0>bd,timeout,buf,cnt*bd-&gt;blk_size,0,</span><span class=cF3>FALSE</span><span class=cF7>)</span><span class=cF0>) {
<a name="l407"></a> </span><span class=cFB>blkdev</span><span class=cF0>.read_cnt+=(cnt*bd-&gt;blk_size)&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l408"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l409"></a> }
<a name="l410"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l411"></a></span><span class=cF2>// ATAPIStartStop(bd,0,FALSE);</span><span class=cF0>
<a name="l412"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF1>lock</span><span class=cF0> &amp;&amp; unlock) </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
<a name="l413"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l414"></a>}
<a name="l415"></a>
<a name="l416"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>ATAPIReadBlks</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>U8</span><span class=cF0> *buf, </span><span class=cF9>I64</span><span class=cF0> blk, </span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l417"></a>{
<a name="l418"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv=</span><span class=cF5>Let2Drv</span><span class=cF0>(bd-&gt;first_drv_let);
<a name="l419"></a> </span><span class=cF9>I64</span><span class=cF0> retry,spc=bd-&gt;blk_size&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,n,blk2,
<a name="l420"></a> l2=bd-&gt;max_reads&lt;&lt;1+spc&lt;&lt;1;
<a name="l421"></a> </span><span class=cF1>U8</span><span class=cF0> *dvd_buf=</span><span class=cF5>MAlloc</span><span class=cF0>(l2&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l422"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l423"></a> </span><span class=cF1>if</span><span class=cF0> (blk&lt;=bd-&gt;max_reads)
<a name="l424"></a> blk2=0;
<a name="l425"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l426"></a> blk2=</span><span class=cF5>FloorU64</span><span class=cF0>(blk-bd-&gt;max_reads,spc);
<a name="l427"></a> </span><span class=cF1>if</span><span class=cF0> (blk2+l2&gt;dv-&gt;size+dv-&gt;drv_offset)
<a name="l428"></a> l2=dv-&gt;size+dv-&gt;drv_offset-blk2;
<a name="l429"></a> n=(l2+spc-1)/spc;
<a name="l430"></a>
<a name="l431"></a> retry=4;
<a name="l432"></a> </span><span class=cF1>while</span><span class=cF0> (--retry)
<a name="l433"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAPIReadBlks2</span><span class=cF7>(</span><span class=cF0>bd,</span><span class=cF5>tS</span><span class=cF0>+7.0+0.004*n,dvd_buf,blk2/spc,n,</span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>)
<a name="l434"></a></span><span class=cF2>//n is 0x800 if max_reads. Up to 8 additional seconds</span><span class=cF0>
<a name="l435"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l436"></a> </span><span class=cF1>if</span><span class=cF0> (!retry)
<a name="l437"></a> </span><span class=cFD>ATAPIReadBlks2</span><span class=cF0>(bd,0,dvd_buf,blk2/spc,n,</span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l438"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_READ_CACHE</span><span class=cF0>)
<a name="l439"></a> </span><span class=cFD>DskCacheAdd</span><span class=cF0>(dv,dvd_buf,blk2,n*spc);
<a name="l440"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(buf,dvd_buf+</span><span class=cF7>(</span><span class=cF0>blk-blk2</span><span class=cF7>)</span><span class=cF0>&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,cnt&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l441"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l442"></a> </span><span class=cF5>Free</span><span class=cF0>(dvd_buf);
<a name="l443"></a>}
<a name="l444"></a>
<a name="l445"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATARBlks</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *buf, </span><span class=cF9>I64</span><span class=cF0> blk, </span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l446"></a>{
<a name="l447"></a> </span><span class=cF9>I64</span><span class=cF0> n;
<a name="l448"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd=dv-&gt;bd;
<a name="l449"></a> </span><span class=cF1>while</span><span class=cF0> (cnt&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l450"></a> n=cnt;
<a name="l451"></a> </span><span class=cF1>if</span><span class=cF0> (n&gt;bd-&gt;max_reads)
<a name="l452"></a> n=bd-&gt;max_reads;
<a name="l453"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type==</span><span class=cF3>BDT_ATAPI</span><span class=cF0>)
<a name="l454"></a> </span><span class=cFD>ATAPIReadBlks</span><span class=cF0>(bd,buf,blk,n);
<a name="l455"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l456"></a> </span><span class=cF5>ATAReadBlks</span><span class=cF0>(bd,buf,blk,n);
<a name="l457"></a> buf+=n&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l458"></a> blk+=n;
<a name="l459"></a> cnt-=n;
<a name="l460"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l461"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l462"></a>}
<a name="l463"></a>
<a name="l464"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>ATAWriteBlks</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>U8</span><span class=cF0> *buf, </span><span class=cF9>I64</span><span class=cF0> blk, </span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l465"></a>{</span><span class=cF2>//For low level disk access.</span><span class=cF0>
<a name="l466"></a></span><span class=cF2>//Use BlkWrite() instead.</span><span class=cF0>
<a name="l467"></a> </span><span class=cF9>I64</span><span class=cF0> i,U32s_avail,sects_avail,retries=3;
<a name="l468"></a> </span><span class=cF1>F64</span><span class=cF0> timeout;
<a name="l469"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock=</span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
<a name="l470"></a>retry:
<a name="l471"></a> </span><span class=cFD>ATABlkSel</span><span class=cF0>(bd,blk,cnt);
<a name="l472"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags&amp;</span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l473"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_WRITE_MULTI_EXT</span><span class=cF0>);
<a name="l474"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l475"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_WRITE_MULTI</span><span class=cF0>);
<a name="l476"></a> bd-&gt;flags|=</span><span class=cF3>BDF_LAST_WAS_WRITE</span><span class=cF0>;
<a name="l477"></a> </span><span class=cF1>while</span><span class=cF0> (cnt&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l478"></a> timeout=</span><span class=cF5>tS</span><span class=cF0>+1.0;
<a name="l479"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
<a name="l480"></a> i=</span><span class=cF5>InU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_STAT</span><span class=cF0>);
<a name="l481"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>i &amp; </span><span class=cF3>ATAS_DRDY</span><span class=cF7>)</span><span class=cF0>||!</span><span class=cF7>(</span><span class=cF0>i &amp; </span><span class=cF3>ATAS_DRQ</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l482"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l483"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l484"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l485"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF2>/* i&amp;ATAS_ERR||*/</span><span class=cF0> </span><span class=cF5>tS</span><span class=cF0>&gt;timeout) </span><span class=cF7>{</span><span class=cF0>
<a name="l486"></a> </span><span class=cF1>if</span><span class=cF0> (retries--) {
<a name="l487"></a> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,0);
<a name="l488"></a> </span><span class=cF1>goto</span><span class=cF0> retry;
<a name="l489"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l490"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l491"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l492"></a> }
<a name="l493"></a> sects_avail=1;
<a name="l494"></a> U32s_avail=sects_avail&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>&gt;&gt;2;
<a name="l495"></a> </span><span class=cF5>RepOutU32</span><span class=cF0>(buf,U32s_avail,bd-&gt;base0+</span><span class=cF3>ATAR0_DATA</span><span class=cF0>);
<a name="l496"></a> buf+=U32s_avail&lt;&lt;2;
<a name="l497"></a> cnt-=sects_avail;
<a name="l498"></a> retries=3;
<a name="l499"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l500"></a> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,0);
<a name="l501"></a> </span><span class=cF1>if</span><span class=cF0> (unlock) </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
<a name="l502"></a>}
<a name="l503"></a>
<a name="l504"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAPISync</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd)
<a name="l505"></a>{
<a name="l506"></a> </span><span class=cF1>Bool</span><span class=cF0> okay=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l507"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>ATAWaitNotBUSY</span><span class=cF7>(</span><span class=cF0>bd,0</span><span class=cF7>)</span><span class=cF0>)
<a name="l508"></a> okay=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l509"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l510"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l511"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l512"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l513"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l514"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,0);
<a name="l515"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,0);
<a name="l516"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_PACKET</span><span class=cF0>);
<a name="l517"></a> </span><span class=cFD>ATAPIWritePktWord</span><span class=cF0>(bd,0,0x3500,0,0,0,0,0);
<a name="l518"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>ATAWaitNotBUSY</span><span class=cF7>(</span><span class=cF0>bd,0</span><span class=cF7>)</span><span class=cF0>)
<a name="l519"></a> okay=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l520"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l521"></a> </span><span class=cF1>return</span><span class=cF0> okay;
<a name="l522"></a>}
<a name="l523"></a>
<a name="l524"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>ATAPIClose</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF9>I64</span><span class=cF0> close_field=0x200,</span><span class=cF9>I64</span><span class=cF0> track=0)
<a name="l525"></a>{</span><span class=cF2>//0x200 CD/DVD part 1</span><span class=cF0>
<a name="l526"></a></span><span class=cF2>// 0x300 DVD part 2</span><span class=cF0>
<a name="l527"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l528"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l529"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l530"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l531"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,0);
<a name="l532"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,0);
<a name="l533"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_PACKET</span><span class=cF0>);
<a name="l534"></a> </span><span class=cFD>ATAPIWritePktWord</span><span class=cF0>(bd,0,0x5B00,close_field,track,0,0,0);
<a name="l535"></a> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,0);
<a name="l536"></a>}
<a name="l537"></a>
<a name="l538"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>ATAPIWriteBlks</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>U8</span><span class=cF0> *buf, </span><span class=cF9>I64</span><span class=cF0> native_blk, </span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l539"></a>{
<a name="l540"></a> </span><span class=cF9>I64</span><span class=cF0> U32s_avail;
<a name="l541"></a> </span><span class=cF1>U8</span><span class=cF0> *buf2;
<a name="l542"></a> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,0);
<a name="l543"></a> </span><span class=cFD>ATAPISeek</span><span class=cF0>(bd,native_blk);
<a name="l544"></a>
<a name="l545"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_FEAT</span><span class=cF0>,0);
<a name="l546"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,bd-&gt;blk_size);
<a name="l547"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,bd-&gt;blk_size.u8[1]);
<a name="l548"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l549"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l550"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l551"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l552"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_CMD</span><span class=cF0>,</span><span class=cF3>ATA_PACKET</span><span class=cF0>);
<a name="l553"></a> </span><span class=cFD>ATAPIWritePktWord</span><span class=cF0>(bd,0,0x0400,native_blk.u16[1],native_blk,cnt.u16[1],cnt,0);
<a name="l554"></a> bd-&gt;flags|=</span><span class=cF3>BDF_LAST_WAS_WRITE</span><span class=cF0>;
<a name="l555"></a> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,0);
<a name="l556"></a>
<a name="l557"></a> </span><span class=cFD>ATAPISeek</span><span class=cF0>(bd,native_blk);
<a name="l558"></a>
<a name="l559"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_EXT_SIZE</span><span class=cF0>)
<a name="l560"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xEF|bd-&gt;unit&lt;&lt;4);
<a name="l561"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l562"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_SEL</span><span class=cF0>,0xE0|bd-&gt;unit&lt;&lt;4);
<a name="l563"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF0>,bd-&gt;blk_size);
<a name="l564"></a> </span><span class=cF5>OutU8</span><span class=cF0>(bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF0>,bd-&gt;blk_size.u8[1]);
<a name="l565"></a> </span><span class=cFD>ATACmd</span><span class=cF0>(bd,</span><span class=cF3>ATA_PACKET</span><span class=cF0>);
<a name="l566"></a> </span><span class=cFD>ATAPIWritePktWord</span><span class=cF0>(bd,0,0xAA00,native_blk.u16[1],native_blk,cnt.u16[1],cnt,0);
<a name="l567"></a> buf2=buf+bd-&gt;blk_size*cnt;
<a name="l568"></a> </span><span class=cF1>while</span><span class=cF0> (buf&lt;buf2) </span><span class=cF7>{</span><span class=cF0>
<a name="l569"></a> </span><span class=cFD>ATAWaitDRQ</span><span class=cF0>(bd,0);
<a name="l570"></a> U32s_avail=(</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>bd-&gt;base0+</span><span class=cF3>ATAR0_HCYL</span><span class=cF7>)</span><span class=cF0>&lt;&lt;8+</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>bd-&gt;base0+</span><span class=cF3>ATAR0_LCYL</span><span class=cF7>)</span><span class=cF0>)&gt;&gt;2;
<a name="l571"></a> </span><span class=cF1>if</span><span class=cF0> (buf+U32s_avail&lt;&lt;2&gt;buf2)
<a name="l572"></a> U32s_avail=(buf2-buf)&gt;&gt;2;
<a name="l573"></a> </span><span class=cF1>if</span><span class=cF0> (U32s_avail) {
<a name="l574"></a> </span><span class=cF5>RepOutU32</span><span class=cF0>(buf,U32s_avail,bd-&gt;base0+</span><span class=cF3>ATAR0_DATA</span><span class=cF0>);
<a name="l575"></a> buf+=U32s_avail&lt;&lt;2;
<a name="l576"></a> </span><span class=cFB>blkdev</span><span class=cF0>.write_cnt+=U32s_avail&gt;&gt;(</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>-2);
<a name="l577"></a> }
<a name="l578"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l579"></a> </span><span class=cFD>ATAWaitNotBUSY</span><span class=cF0>(bd,0);
<a name="l580"></a>}
<a name="l581"></a>
<a name="l582"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>ATAWBlks</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *buf, </span><span class=cF9>I64</span><span class=cF0> blk, </span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l583"></a>{
<a name="l584"></a> </span><span class=cF9>I64</span><span class=cF0> n,spc;
<a name="l585"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd=dv-&gt;bd;
<a name="l586"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock;
<a name="l587"></a> spc=bd-&gt;blk_size&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l588"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type==</span><span class=cF3>BDT_ATAPI</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l589"></a> unlock=</span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
<a name="l590"></a> </span><span class=cFD>ATAPIWaitReady</span><span class=cF0>(bd,0);
<a name="l591"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l592"></a> </span><span class=cF1>while</span><span class=cF0> (cnt&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l593"></a> n=cnt;
<a name="l594"></a> </span><span class=cF1>if</span><span class=cF0> (n&gt;bd-&gt;max_writes)
<a name="l595"></a> n=bd-&gt;max_writes;
<a name="l596"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type==</span><span class=cF3>BDT_ATAPI</span><span class=cF0>)
<a name="l597"></a> </span><span class=cFD>ATAPIWriteBlks</span><span class=cF0>(bd,buf,blk/spc,</span><span class=cF7>(</span><span class=cF0>n+spc-1</span><span class=cF7>)</span><span class=cF0>/spc);
<a name="l598"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l599"></a> </span><span class=cF5>ATAWriteBlks</span><span class=cF0>(bd,buf,blk,n);
<a name="l600"></a> buf+=n&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l601"></a> blk+=n;
<a name="l602"></a> cnt-=n;
<a name="l603"></a> </span><span class=cFB>blkdev</span><span class=cF0>.write_cnt+=n;
<a name="l604"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l605"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type==</span><span class=cF3>BDT_ATAPI</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l606"></a> </span><span class=cFD>ATAPISync</span><span class=cF0>(bd);
<a name="l607"></a></span><span class=cF2>// ATAPIStartStop(bd,0,FALSE);</span><span class=cF0>
<a name="l608"></a> </span><span class=cF1>if</span><span class=cF0> (unlock) </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
<a name="l609"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l610"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l611"></a>}
</span></pre></body>
</html>