[SeaBIOS] [coreboot] Patch number 4 for floppy in SeaBIOS

Kevin O'Connor kevin at koconnor.net
Wed Dec 11 18:42:36 CET 2013


On Sun, Dec 08, 2013 at 06:13:52PM +0100, Gelip wrote:
> 08.142: Booting from Floppy...

Can you try pulling down the latest code from my github testing banch
and apply the patch below?  (I think real hardware may require an
explicit seek command when reading different cylinders.)

-Kevin


diff --git a/src/hw/floppy.c b/src/hw/floppy.c
index 48958e6..84e59b6 100644
--- a/src/hw/floppy.c
+++ b/src/hw/floppy.c
@@ -320,6 +320,32 @@ floppy_select_drive(u8 floppyid)
     return DISK_RET_SUCCESS;
 }
 
+static int
+floppy_seek(u8 floppyid, u8 cyl)
+{
+    dprintf(1, "Floppy seek %d to cyl %d\n", floppyid, cyl);
+    struct floppy_pio_s pio;
+    pio.cmdlen = 3;
+    pio.resplen = 0;
+    pio.waitirq = 1;
+    pio.data[0] = 0x0f;  // 0f: Seek
+    pio.data[1] = floppyid;
+    pio.data[2] = cyl;
+    int ret = floppy_pio(&pio);
+    if (ret)
+        return ret;
+
+    pio.cmdlen = 1;
+    pio.resplen = 2;
+    pio.waitirq = 0;
+    pio.data[0] = 0x08;  // 08: Check Interrupt Status
+    ret = floppy_pio(&pio);
+    if (ret)
+        return ret;
+
+    return DISK_RET_SUCCESS;
+}
+
 
 /****************************************************************
  * Floppy media sense
@@ -464,6 +490,19 @@ floppy_cmd(struct disk_op_s *op, int blocksize, struct floppy_pio_s *pio)
     if (ret)
         return ret;
 
+    // XXX - seek
+    u8 floppyid = pio->data[1] & 1;
+    if (pio->data[0] == 0xe6 || pio->data[0] == 0xc5) {
+        u8 curcyl = GET_BDA(floppy_track[floppyid]);
+        u8 reqcyl = pio->data[2];
+        if (curcyl != reqcyl) {
+            ret = floppy_seek(floppyid, reqcyl);
+            if (ret)
+                return ret;
+            set_diskette_current_cyl(floppyid, reqcyl);
+        }
+    }
+
     // Setup DMA controller
     int isWrite = pio->data[0] != 0xe6;
     ret = dma_floppy((u32)op->buf_fl, op->count * blocksize, isWrite);
@@ -471,7 +510,7 @@ floppy_cmd(struct disk_op_s *op, int blocksize, struct floppy_pio_s *pio)
         return DISK_RET_EBOUNDARY;
 
     // Invoke floppy controller
-    ret = floppy_select_drive(pio->data[1] & 1);
+    ret = floppy_select_drive(floppyid);
     if (ret)
         return ret;
     pio->resplen = 7;
@@ -495,7 +534,7 @@ floppy_cmd(struct disk_op_s *op, int blocksize, struct floppy_pio_s *pio)
     }
 
     u8 track = (pio->cmdlen == 9 ? pio->data[3] : 0);
-    set_diskette_current_cyl(pio->data[0] & 1, track);
+    set_diskette_current_cyl(floppyid, track);
 
     return DISK_RET_SUCCESS;
 }



More information about the SeaBIOS mailing list