[openfirmware] r1314 - in dev/ide: . build

svn at openfirmware.info svn at openfirmware.info
Fri Aug 21 11:26:26 CEST 2009


Author: wmb
Date: 2009-08-21 11:26:26 +0200 (Fri, 21 Aug 2009)
New Revision: 1314

Modified:
   dev/ide/atapi.fth
   dev/ide/build/node.hex
   dev/ide/generic.fth
   dev/ide/idedisk.fth
Log:
IDE driver - don't hang under various drive fault conditions.



Modified: dev/ide/atapi.fth
===================================================================
--- dev/ide/atapi.fth	2009-08-21 09:25:46 UTC (rev 1313)
+++ dev/ide/atapi.fth	2009-08-21 09:26:26 UTC (rev 1314)
@@ -13,16 +13,16 @@
    loop
 ;
 
-: atapi-get-drive-parms  ( -- )
+: atapi-get-drive-parms  ( -- found? )
    h# a1 r-csr!         \ send identify command
 
    waitonbusy	\ The busy bit can be set even if there's no slave drive
 
-   r-csr@  dup 0=  swap h# ff =  or  if  exit  then
+   r-csr@  dup 0=  swap h# ff =  or  if  false exit  then
 
    true    atapi-drive?!
 
-   scratchbuf d# 512 pio-rblock drop
+   scratchbuf d# 512 pio-rblock  if  false exit  then
 
    scratchbuf 1+ c@  h# 1f and  dup  drive-type!   ( type )
    5 =  if  d# 2048  else  d# 512  then  /block!
@@ -35,6 +35,7 @@
    \ 2Vi, which do not have the drive-type in the right byte.
    5 drive-type!
 [then]
+   true
 ;
 
 : waitfordrq  ( -- timeout? )

Modified: dev/ide/build/node.hex
===================================================================
--- dev/ide/build/node.hex	2009-08-21 09:25:46 UTC (rev 1313)
+++ dev/ide/build/node.hex	2009-08-21 09:26:26 UTC (rev 1314)
@@ -1,4 +1,4 @@
-" "(f1 03 0e 30 00 00 03 48 12 04 64 69 73 6b 02 01 12 05 62 6c 6f 63 6b 01 1a a5 c0 b6 06 2f 62 6c 6f 63 6b 08 00 b8 a5 c0 b6 09 64 65 62 6c 6f 63 6b 65 72 08 01 b8 b6 0e 69 6e 69 74 2d 64 65 62 6c 6f 63 6b 65 72 08 02 b7 12 00 12 09 64 65 62 )" $,
+" "(f1 03 10 19 00 00 03 50 12 04 64 69 73 6b 02 01 12 05 62 6c 6f 63 6b 01 1a a5 c0 b6 06 2f 62 6c 6f 63 6b 08 00 b8 a5 c0 b6 09 64 65 62 6c 6f 63 6b 65 72 08 01 b8 b6 0e 69 6e 69 74 2d 64 65 62 6c 6f 63 6b 65 72 08 02 b7 12 00 12 09 64 65 62 )" $,
 " "(6c 6f 63 6b 65 72 02 0f c3 08 01 08 01 14 00 07 a4 13 00 25 b2 12 1c 43 61 6e 27 74 20 6f 70 65 6e 20 64 65 62 6c 6f 63 6b 65 72 20 70 61 63 6b 61 67 65 90 92 a5 b2 c2 a5 c0 b6 0a 6f 66 66 73 65 74 2d 6c 6f 77 08 03 b8 a5 c0 b6 0b 6f 66 66 )" $,
 " "(73 65 74 2d 68 69 67 68 08 04 b8 a5 c0 b6 0d 6c 61 62 65 6c 2d 70 61 63 6b 61 67 65 08 05 b8 b6 12 69 6e 69 74 2d 6c 61 62 65 6c 2d 70 61 63 6b 61 67 65 08 06 b7 a5 c3 08 04 a5 c3 08 03 02 02 12 0a 64 69 73 6b 2d 6c 61 62 65 6c 02 0f c3 08 )" $,
 " "(05 08 05 14 00 1b a5 a5 12 06 6f 66 66 73 65 74 08 05 02 0e c3 08 04 c3 08 03 a4 13 00 26 b2 12 1d 43 61 6e 27 74 20 6f 70 65 6e 20 64 69 73 6b 20 6c 61 62 65 6c 20 70 61 63 6b 61 67 65 90 92 a5 b2 c2 ca 09 64 6d 61 2d 61 6c 6c 6f 63 08 07 )" $,
@@ -6,6 +6,6 @@
 " "(c3 08 00 c2 ca 07 23 62 6c 6f 63 6b 73 08 0a b7 12 07 23 62 6c 6f 63 6b 73 02 09 c2 ca 0c 6d 61 78 2d 74 72 61 6e 73 66 65 72 08 0b b7 12 0c 6d 61 78 2d 74 72 61 6e 73 66 65 72 02 09 c2 ca 0b 72 65 61 64 2d 62 6c 6f 63 6b 73 08 0c b7 12 0b )" $,
 " "(72 65 61 64 2d 62 6c 6f 63 6b 73 02 09 c2 ca 0c 77 72 69 74 65 2d 62 6c 6f 63 6b 73 08 0d b7 12 0c 77 72 69 74 65 2d 62 6c 6f 63 6b 73 02 09 c2 a5 c0 ca 08 23 77 72 69 74 74 65 6e 08 0e b8 ca 12 77 72 69 74 65 2d 62 6c 6f 63 6b 73 2d 73 74 )" $,
 " "(61 72 74 08 0f b7 12 0c 77 72 69 74 65 2d 62 6c 6f 63 6b 73 02 09 c3 08 0e c2 ca 13 77 72 69 74 65 2d 62 6c 6f 63 6b 73 2d 66 69 6e 69 73 68 08 10 b7 08 0e c2 ca 04 6f 70 65 6e 08 11 b7 02 0d 47 a8 3b 14 00 06 52 a5 33 b2 12 0b 73 65 74 2d )" $,
-" "(61 64 64 72 65 73 73 02 09 12 0b 69 64 65 2d 69 6e 71 75 69 72 79 02 09 14 00 07 46 13 00 06 b2 a5 33 b2 08 09 50 34 14 00 05 a5 33 b2 c3 08 00 08 02 34 14 00 05 a5 33 b2 08 06 34 14 00 09 08 01 02 06 a5 33 b2 a4 c2 ca 05 63 6c 6f 73 65 08 )" $,
-" "(12 b7 08 05 02 06 08 01 02 06 c2 ca 04 73 65 65 6b 08 13 b7 08 03 08 04 d8 12 04 73 65 65 6b 08 01 02 0e c2 ca 04 72 65 61 64 08 14 b7 12 04 72 65 61 64 08 01 02 0e c2 ca 05 77 72 69 74 65 08 15 b7 12 05 77 72 69 74 65 08 01 02 0e c2 ca 04 )" $,
-" "(6c 6f 61 64 08 16 b7 12 04 6c 6f 61 64 08 05 02 0e c2 ca 04 73 69 7a 65 08 17 b7 12 04 73 69 7a 65 08 05 02 0e c2 00 00 )" $,
+" "(61 64 64 72 65 73 73 02 09 12 0b 69 64 65 2d 69 6e 71 75 69 72 79 02 09 14 00 07 46 13 00 06 b2 a5 33 b2 08 09 50 34 14 00 05 a5 33 b2 c3 08 00 08 0a 34 14 00 05 a5 33 b2 08 02 34 14 00 05 a5 33 b2 08 06 34 14 00 09 08 01 02 06 a5 33 b2 a4 )" $,
+" "(c2 ca 05 63 6c 6f 73 65 08 12 b7 08 05 02 06 08 01 02 06 c2 ca 04 73 65 65 6b 08 13 b7 08 03 08 04 d8 12 04 73 65 65 6b 08 01 02 0e c2 ca 04 72 65 61 64 08 14 b7 12 04 72 65 61 64 08 01 02 0e c2 ca 05 77 72 69 74 65 08 15 b7 12 05 77 72 69 )" $,
+" "(74 65 08 01 02 0e c2 ca 04 6c 6f 61 64 08 16 b7 12 04 6c 6f 61 64 08 05 02 0e c2 ca 04 73 69 7a 65 08 17 b7 12 04 73 69 7a 65 08 05 02 0e c2 00 )" $,

Modified: dev/ide/generic.fth
===================================================================
--- dev/ide/generic.fth	2009-08-21 09:25:46 UTC (rev 1313)
+++ dev/ide/generic.fth	2009-08-21 09:26:26 UTC (rev 1314)
@@ -78,23 +78,19 @@
 : r-dor!    ( val   -- )  dor-magic or dor rb!  ;
 
 \ Spin until BSY == 0, RDY == 1, indicating registers can be touched
-: wait-while-busy  ( -- )
-   get-msecs                            ( start-time )
+: wait-while-busy  ( -- timeout? )
+   get-msecs  d# 5000 +                 ( end-time )
    begin
-      r-csr@                            ( start-time csr )
-      dup 0<>                           ( start-time csr flag )
-      over h# ff <>             and     ( start-time csr flag )
-      swap h# c0 and  h# 40 <>  and     ( start-time csr=0|ff|4x? )
-   while				( start-time )
-      get-msecs over -                  ( start-time delta )
-      d# 5000 <                         ( start-time timeout? )
-   while				( start-time )
-   repeat
-   then				        ( start-time )
-   drop					( )
+      r-csr@  dup 0=                    ( end-time csr flag )
+      over h# ff =              or      ( end-time csr flag )
+      swap h# c0 and  h# 40 =   or      ( end-time csr=0|ff|4x? )  \ !BSY (80), DRDY (40)
+      if  drop false exit  then         ( end-time )
+      dup get-msecs -                   ( end-time remaining-time )
+   0<= until				( end-time )
+   drop	 true				( true )
 ;
 
-: reg!  ( data reg#  --  )  wait-while-busy  chip-base + rb!  ;
+: reg!  ( data reg#  --  )  wait-while-busy drop  chip-base + rb!  ;
 
 : r-data!   ( data  -- )  chip-base w!  ;
 : r-features!  ( data -- )  1 reg!  ;
@@ -131,15 +127,43 @@
 \ 91 constant set-drive-parms-cmd
 \ ec constant identify-cmd
 
-: wait-until-drq  ( -- )
-   begin
-      r-csr@
-      dup 1 and  if  ." IDE data error: " r-error@ . cr abort  then
-      h# c8 and h# 48 =
-   until
+: wait-until-drq  ( -- error? )
+   get-msecs  d# 5000 +          ( end-time )
+   begin                         ( end-time )
+      r-csr@                     ( end-time csr )
+
+      dup h# c8 and h# 48 =  if  ( end-time csr )  \ !BSY (80), DRDY (40), DRQ (8)
+         2drop false exit
+      then                       ( end-time csr )
+
+      h# 21 and  if              ( end-time )  \ DF (20; fault), ERR (1)
+         ." IDE data error: " r-error@ . cr
+         drop true exit
+      then                       ( end-time )
+      dup get-msecs -            ( end-time remaining-time )
+   until                         ( end-time )
+   drop true                     ( true )
 ;
-: wait-until-ready  ( -- )  begin  r-csr@ h# 50 =  until  ;
 
+: wait-until-ready  ( -- error? )
+   get-msecs d# 10000 +   ( end-time )
+   begin                  ( end-time )
+      r-csr@              ( end-time csr )
+
+      dup h# 50 =  if     ( end-time csr )  \ DRDY (40), DSC (10; seek complete)
+         2drop false exit
+      then                ( end-time )
+
+      h# 21 and  if       ( end-time )      \ DF (20; fault), ERR (1)
+         ." IDE Drive Error" cr
+         drop true exit
+      then                ( end-time )
+
+      dup get-msecs -     ( end-time remaining-time )
+   0<= until              ( end-time )
+   drop true
+;
+
 : lblk>cyl-head-sect  ( block# -- cyl# head# sect# )
    /secs /mod                                 ( sect# residue )
    /heads /mod swap rot 1+                    ( cyl# head# sect# )
@@ -149,7 +173,7 @@
 defer pio-end-hack  ' noop to pio-end-hack
 defer pio-start-hack  ' noop to pio-start-hack
 : pio-rblock  ( adr len -- error? )
-   wait-until-drq
+   wait-until-drq  if  2drop true exit  then
    pio-start-hack
    chip-base io-blk-w@  false
    pio-end-hack
@@ -172,28 +196,24 @@
 ' pio-rblocks to rblocks
 
 : pio-wblock  ( adr len -- error? )
-   wait-until-drq
+   wait-until-drq  if  2drop true exit  then
    pio-start-hack
-   chip-base io-blk-w!  false
+   chip-base io-blk-w!
    pio-end-hack
+   false
 ;
 
-: pio-wblocks  ( addr #blks -- actual# | error )
-   over >r                                      ( addr #blks ) ( R: addr )
-   h# 30 r-csr!
+: pio-wblocks  ( addr #blks -- actual# | 0 )
+   h# 30 r-csr!                                     ( addr #blks )
+   
+   tuck  0  ?do                                     ( #blks addr )
+      dup  /block@  pio-wblock  if                  ( #blks addr )
+         2drop  i  unloop exit
+      then                                          ( #blks addr )
 
-   begin
-      wait-until-drq
-      swap                                      ( #blks addr ) ( R: addr )
-
-      pio-start-hack
-      dup /block@ chip-base io-blk-w!
-      pio-end-hack
-
-      /block@ +                                 ( #blks addr' ) ( R: addr )
-      swap 1- ?dup 0=
-   until
-   r> - /block@ /
+      /block@ +                                     ( #blks addr' )
+   loop                                             ( #blks addr )
+   drop                                             ( actual# )
 ;
 defer wblocks
 ' pio-wblocks to wblocks
@@ -217,7 +237,7 @@
    then
    r>  r>  if  rblocks  else  wblocks  then               ( actual# | error )
 
-   dup 0=  if
+   dup 0<=  if
       ." Failed to transfer any blocks" cr
       \ XXX trouble
    then                                           ( actual# )
@@ -235,20 +255,20 @@
 
 : le-w@  ( adr -- w )  dup c@ swap ca1+ c@ bwjoin  ;
 
-: ide-get-drive-parms  ( -- )
+: ide-get-drive-parms  ( -- found? )
    d# 512 /block!
 
    false  atapi-drive?!
    0      drive-type!
 
-   wait-while-busy
+   wait-while-busy  if  false exit  then
    2 r-dor!             \ Turn off IRQ14
 
    0 drive r-head!
 
    h# ec r-csr!		\ Identify command
 
-   scratchbuf d# 512 pio-rblock drop
+   scratchbuf d# 512 pio-rblock  if  false exit  then
 
    scratchbuf 1 wa+ le-w@ /cyls!
    scratchbuf 3 wa+ le-w@ /heads!
@@ -260,15 +280,17 @@
       scratchbuf d# 61 wa+ le-w@
       wljoin /lba!
    then
+
+   true
 ;
 
-: get-drive-parms  ( -- )
+: get-drive-parms  ( -- found? )
    \ Reset this string (primary or secondary) on the first time through,
    \ in order to clear any errors that might be hanging around from uses
    \ of the drive by previous software.
    drive 0=  if  4 r-dor!  0 r-dor!  then
 
-   wait-while-busy
+   wait-while-busy  if  false exit  then
    0 drive r-head!		\ select drive
    0 r-dor!			\ flush ISA bus
    6 reg@ h# a0 drive 4 lshift or  = if
@@ -277,13 +299,21 @@
 	 \ Unfortunately, the vl-reset on the Shark does not seem to fully
 	 \ reset the ATAPI drive, therefore, we are doing it here.
          atapi-reset		\ atapi soft reset
-         atapi-get-drive-parms
+         atapi-get-drive-parms     ( found? )
       else
          r-csr@ 0<>  r-csr@ h# ff <>  and  if
-            drive 0=  if  wait-until-ready  then	\ wait until spin-up
-            r-csr@ h# f0 and h# 50 =  if  ide-get-drive-parms  then
+            drive 0=  if
+               wait-until-ready  if  false exit  then
+            then	\ wait until spin-up
+            r-csr@ h# f0 and h# 50 =  if
+               ide-get-drive-parms                 ( found? )
+            else
+               false                               ( found? )
+            then
          then
       then
+   else
+      false                                        ( found? )
    then
 ;
 
@@ -361,7 +391,7 @@
 
    first-open?  if
       max#drives 0  do
-         0 i  set-address  get-drive-parms  set-drive-cfg  loop
+         0 i  set-address  get-drive-parms  if  set-drive-cfg  then  loop
       false to first-open?
    then
 

Modified: dev/ide/idedisk.fth
===================================================================
--- dev/ide/idedisk.fth	2009-08-21 09:25:46 UTC (rev 1313)
+++ dev/ide/idedisk.fth	2009-08-21 09:26:26 UTC (rev 1314)
@@ -81,6 +81,8 @@
 
    block-size ?dup 0=  if  false exit  then  to /block
 
+   #blocks  0=  if  false exit  then
+
    init-deblocker  0=  if  false exit  then
 
    init-label-package  0=  if




More information about the openfirmware mailing list