[SeaBIOS] [PATCH v2 0/3] floppy: detect an empty drive without waiting for a timeout

Christian Quante posted 3 patches 1 week, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/seabios tags/patchew/20260713193529.13004-1-christian@quante.one
There is a newer version of this series
src/hw/floppy.c | 75 ++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 68 insertions(+), 7 deletions(-)
[SeaBIOS] [PATCH v2 0/3] floppy: detect an empty drive without waiting for a timeout
Posted by Christian Quante 1 week, 5 days ago
Kevin, thanks for the review.  All three points addressed, plus the error
code question, which turned out to deserve its own patch as you suggested.

  1/3  floppy_drive_seek(), as you asked -- it also removes the reason for
       the second recalibrate you asked about.  The seek in my v1 went
       straight to floppy_drive_pio() and left floppy_track[] in the BDA
       stale; the recalibrate was there to repair that, not because the
       head needed to move.  With the BDA kept correct the head can simply
       stay on cylinder 1, and floppy_prep() seeks where it wants anyway.

  2/3  The probe itself, now returning a status code rather than a bool.
       Behaviour is unchanged from today apart from the wait: an empty
       drive still answers DISK_RET_EMEDIA, just in 0.11 s instead of 10 s.

  3/3  The error code, separate as you preferred.

On 3/3 -- you asked whether I am sure a traditional BIOS answers differently.
I was not, and said so; here is what I found since.

0xC0 does not appear in the classic INT 13h status tables at all (helppc,
the Wikipedia table for AH=01h, techhelp).  It has been in SeaBIOS since the
initial checkin f076a3ee, without a comment or a source.  Bochs BIOS, which
SeaBIOS descends from, answers 0x80 here ("SET_AH(0x80); // drive not ready
(timeout)") and has no READ ID media sensing at all -- that arrived with your
e7c5a7ef in 2013, and DISK_RET_EMEDIA came along with it.

Guests agree.  Building SeaBIOS to return each code in turn on an empty drive.
My guests are German-language, so their messages are quoted as they appear,
with the English sense in brackets:

  PC-DOS 7, "dir a:"
    0x80  "Nicht bereit beim Lesen von Laufwerk A"
          [not ready reading drive A]
    0xC0  "Allgemeiner Fehler beim Lesen von Laufwerk A"
          [general failure reading drive A]
    0xAA  same message as 0xC0
    0x99  same message as 0xC0                 <- an invented code
    0x06  no message at all; DOS retries forever

  Windows for Workgroups 3.11, File Manager, drive A:
    0x80  "In Laufwerk A ist kein Datenträger eingelegt.  Legen Sie einen
           Datenträger ein, und versuchen Sie es erneut."  [Wiederholen]
          [there is no disk in drive A; insert one and try again]
    0xC0  "Der Datenträger in Laufwerk A ist nicht formatiert.  Möchten
           Sie, daß der Datenträger jetzt formatiert wird?"  [Ja] [Nein]
          [the disk in drive A is not formatted; format it now?]

DOS gives 0xC0 the same message as the invented 0x99, so it does not
recognise the code.  Windows does recognise it -- and offers to format a
diskette that is not in the drive.

The two failures are distinct, and 2/3 is what makes them distinguishable in
the first place: an absent medium is now known as such, so it can be reported
as "not ready", while floppy_media_sense() keeps DISK_RET_EMEDIA for a medium
it cannot read.

Tested: empty drive; diskette present; cold start with a freshly inserted
medium, where the change line is set and a naive probe would call the drive
empty; boot from a diskette; and the guests PC-DOS 7, IBM DOS 5.02, Windows
for Workgroups 3.11 and OS/2 2.11.  Each commit builds and was measured
separately -- 1/3 changes nothing, 2/3 takes an INT 13h read of an empty A:
from 10.12 s to 0.11 s, 3/3 changes the code it answers with.

Still not verified against real hardware; I have none with a floppy drive.
The gating on CMOS types 2..5 and the "when in doubt, say present" fallback
are meant to keep that safe, but a second opinion on drives without a change
line would be welcome.

Christian Quante (3):
  floppy: add floppy_drive_seek()
  floppy: detect an empty drive via the disk change line
  floppy: report an empty drive as not ready

 src/hw/floppy.c | 75 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 68 insertions(+), 7 deletions(-)

-- 
2.53.0

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
[SeaBIOS] Re: [PATCH v2 0/3] floppy: detect an empty drive without waiting for a timeout
Posted by Kevin O'Connor via SeaBIOS 1 week, 4 days ago
On Mon, Jul 13, 2026 at 09:35:26PM +0200, Christian Quante wrote:
> Kevin, thanks for the review.  All three points addressed, plus the error
> code question, which turned out to deserve its own patch as you suggested.
> 
>   1/3  floppy_drive_seek(), as you asked -- it also removes the reason for
>        the second recalibrate you asked about.  The seek in my v1 went
>        straight to floppy_drive_pio() and left floppy_track[] in the BDA
>        stale; the recalibrate was there to repair that, not because the
>        head needed to move.  With the BDA kept correct the head can simply
>        stay on cylinder 1, and floppy_prep() seeks where it wants anyway.
> 
>   2/3  The probe itself, now returning a status code rather than a bool.
>        Behaviour is unchanged from today apart from the wait: an empty
>        drive still answers DISK_RET_EMEDIA, just in 0.11 s instead of 10 s.
> 
>   3/3  The error code, separate as you preferred.
> 
> On 3/3 -- you asked whether I am sure a traditional BIOS answers differently.
> I was not, and said so; here is what I found since.
> 
> 0xC0 does not appear in the classic INT 13h status tables at all (helppc,
> the Wikipedia table for AH=01h, techhelp).  It has been in SeaBIOS since the
> initial checkin f076a3ee, without a comment or a source.  Bochs BIOS, which
> SeaBIOS descends from, answers 0x80 here ("SET_AH(0x80); // drive not ready
> (timeout)") and has no READ ID media sensing at all -- that arrived with your
> e7c5a7ef in 2013, and DISK_RET_EMEDIA came along with it.

Ah, it looks like the code in f076a3ee descends from this code in
bochs bios:
```
      // see if drive exists
      if (floppy_drive_exists(drive) == 0) {
        SET_AH(0x80); // not responding
        set_diskette_ret_status(0x80);
        SET_AL(0); // no sectors read
        SET_CF(); // error occurred
        return;
      }

      // see if media in drive, and type is known
      if (floppy_media_known(drive) == 0) {
        if (floppy_media_sense(drive) == 0) {
          SET_AH(0x0C); // Media type not found
          set_diskette_ret_status(0x0C);
          SET_AL(0); // no sectors read
          SET_CF(); // error occurred
          return;
        }
      }
```

It seems I goofed in the translation - should have been 0x0c, but I
incorrectly translated it to 0xc0..

Ralph Brown's interrupt list agrees:
```
(Table 00234)
Values for disk operation status:
 00h    successful completion
...
 0Ch    unsupported track or invalid media
```

So, long story short, I agree the error should be corrected.

Thanks,
-Kevin

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
[SeaBIOS] Re: [PATCH v2 0/3] floppy: detect an empty drive without waiting for a timeout
Posted by Kevin O'Connor via SeaBIOS 1 week, 4 days ago
On Mon, Jul 13, 2026 at 08:05:12PM +0000, Kevin O'Connor via SeaBIOS wrote:
> On Mon, Jul 13, 2026 at 09:35:26PM +0200, Christian Quante wrote:
> > Kevin, thanks for the review.  All three points addressed, plus the error
> > code question, which turned out to deserve its own patch as you suggested.
> >
> >   1/3  floppy_drive_seek(), as you asked -- it also removes the reason for
> >        the second recalibrate you asked about.  The seek in my v1 went
> >        straight to floppy_drive_pio() and left floppy_track[] in the BDA
> >        stale; the recalibrate was there to repair that, not because the
> >        head needed to move.  With the BDA kept correct the head can simply
> >        stay on cylinder 1, and floppy_prep() seeks where it wants anyway.
> >
> >   2/3  The probe itself, now returning a status code rather than a bool.
> >        Behaviour is unchanged from today apart from the wait: an empty
> >        drive still answers DISK_RET_EMEDIA, just in 0.11 s instead of 10 s.
> >
> >   3/3  The error code, separate as you preferred.
> >
> > On 3/3 -- you asked whether I am sure a traditional BIOS answers differently.
> > I was not, and said so; here is what I found since.
> >
> > 0xC0 does not appear in the classic INT 13h status tables at all (helppc,
> > the Wikipedia table for AH=01h, techhelp).  It has been in SeaBIOS since the
> > initial checkin f076a3ee, without a comment or a source.  Bochs BIOS, which
> > SeaBIOS descends from, answers 0x80 here ("SET_AH(0x80); // drive not ready
> > (timeout)") and has no READ ID media sensing at all -- that arrived with your
> > e7c5a7ef in 2013, and DISK_RET_EMEDIA came along with it.

Just for future reference, the e7c5a7ef changes in 2013 appear to stem
from this email:

https://mail.coreboot.org/archives/list/seabios@seabios.org/thread/SGQPBJUCMPKUTC7TLCBFLXWEIS4R2VSE/

-Kevin

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org