First draft conversion of the floppy driver away from the block device
authorDavid Given <dg@cowlark.com>
Fri, 20 Apr 2018 22:22:50 +0000 (00:22 +0200)
committerDavid Given <dg@cowlark.com>
Fri, 20 Apr 2018 22:22:50 +0000 (00:22 +0200)
framework --- smaller and hopefully faster; but it looks like this is revealing
some awful memory corrupt bug and the root filesystem doesn't reliably mount
any more.

Kernel/platform-nc100/devices.c
Kernel/platform-nc200/Makefile
Kernel/platform-nc200/devfd.c
Kernel/platform-nc200/devfd.h

index f28eb81..31f7815 100644 (file)
@@ -19,7 +19,7 @@ struct devsw dev_tab[] =  /* The device driver switch table */
 {
   /* 0: /dev/fd                Floppy disc block devices (NC200 only) */
 #if defined CONFIG_NC200
-  {  blkdev_open, no_close, blkdev_read, blkdev_write, blkdev_ioctl },
+  {  devfd_open, no_close, devfd_read, devfd_write, no_ioctl },
 #else
   {  nxio_open,     no_close,    no_rdwr,   no_rdwr,   no_ioctl },
 #endif
@@ -48,7 +48,6 @@ void device_init(void)
 {
   inittod();
   nc100_tty_init();
-  devfd_init();
 }
 
 __sfr __at 0x30 control;
index c89015e..922bc81 100644 (file)
@@ -1,4 +1,5 @@
 CSRCS = \
+       devfd.c \
        ../platform-nc100/devlpr.c \
        ../platform-nc100/devtty.c \
        ../platform-nc100/devrd.c \
@@ -8,14 +9,18 @@ CSRCS = \
        ../platform-nc100/main.c \
 
 ASRCS = \
+       crt0.s \
+       fdc765.s \
        ../platform-nc100/nc100.s \
-       ../platform-nc100/crt0.s \
        ../platform-nc100/tricks.s \
        ../platform-nc100/commonmem.s \
 
 COBJS = $(CSRCS:.c=.rel)
 AOBJS = $(ASRCS:.s=.rel)
-OBJS  = $(COBJS) $(AOBJS)
+DOBJS = $(DSRCS:.c=.rel)
+OBJS  = $(COBJS) $(AOBJS) $(DOBJS)
+
+CROSS_CCOPTS += -I../dev/
 
 JUNK = \
        $(CSRCS:.c=.lst) \
@@ -38,22 +43,14 @@ clean:
        rm -f $(OBJS) $(JUNK) core *~ 
        rm -f floppyskeleton.img autoprg.bin bootfloppy.img
 
-bootblock.img: ../platform-nc100/bootblock.s
-       sdasz80 -fflopzws bootblock.rel ../platform-nc100/bootblock.s
-       sdldz80 -nwmx -b BOOTBLOCK=0 -i bootblock.ihx bootblock.rel
-       srec_cat -disable-sequence-warning \
-                bootblock.ihx -intel \
-                -output bootblock.img -binary
-
-image: floppyskeleton.img autoprg.bin bootblock.img ../fuzix.bin
-       dd if=bootblock.img of=../fuzix.bin bs=1 conv=notrunc
+image: floppyskeleton.img autoprg.bin ../fuzix.bin
        cp floppyskeleton.img ../fuzixfloppy.img
        truncate ../fuzixfloppy.img --size 7680
        mcopy -i ../fuzixfloppy.img autoprg.bin ::auto.prg
-       dd if=../fuzix.bin bs=16k skip=0 count=1 | mcopy -i ../fuzixfloppy.img - ::load4000.80
-       dd if=../fuzix.bin bs=16k skip=1 count=1 | mcopy -i ../fuzixfloppy.img - ::load4000.81
-       dd if=../fuzix.bin bs=16k skip=2 count=1 | mcopy -i ../fuzixfloppy.img - ::load4000.82
-       echo -n | mcopy -i ../fuzixfloppy.img - ::call4000.80
+       dd if=../fuzix.bin bs=16k skip=0 count=1 | mcopy -i ../fuzixfloppy.img - ::load4000.83
+       dd if=../fuzix.bin bs=16k skip=1 count=1 | mcopy -i ../fuzixfloppy.img - ::load4000.84
+       dd if=../fuzix.bin bs=16k skip=2 count=1 | mcopy -i ../fuzixfloppy.img - ::load4000.85
+       echo -n | mcopy -i ../fuzixfloppy.img - ::call4080.83
 
 floppyskeleton.img: floppyskeleton.s
        sdasz80 -fflopzws floppyskeleton.rel floppyskeleton.s
index 1822ab3..aa1e687 100644 (file)
@@ -8,17 +8,16 @@
 
 static timer_t spindown_timer = 0;
 
-void devfd_init(void)
+int devfd_open(uint8_t minor, uint16_t flag)
 {
-    blkdev_t* blk = blkdev_alloc();
-    if (!blk)
-        return;
-
+    flag;
+    if(minor != 0) {
+        udata.u_error = ENODEV;
+        return -1;
+    }
     fd765_do_nudge_tc();
     fd765_track = 0xff; /* not on a known track */
-    blk->transfer = devfd_transfer;
-    blk->drive_lba_count = 1440; /* 512-byte sectors */
-    blkdev_scan(blk, 0);
+    return 0;
 }
 
 static void nudge_timer(void)
@@ -90,16 +89,24 @@ static void fd_select(int minor)
     nudge_timer();
 }
 
-uint8_t devfd_transfer(void)
+static int devfd_transfer(bool is_read, uint8_t is_raw)
 {
     int ct = 0;
     int tries;
-    int blocks = blk_op.nblock;
-    uint16_t lba = blk_op.lba;
+    int blocks = udata.u_nblock;
+    uint16_t lba = udata.u_block;
+
+    // kprintf("[%s %d @ %x : %d:%x]\n", is_read ? "read" : "write",
+    //     blocks, lba, is_raw, udata.u_dptr);
+    // if (!is_read)
+    //     return blocks << BLKSHIFT;
+
+    if (is_raw && d_blkoff(BLKSHIFT))
+        return -1;
 
     fd_select(0);
-    fd765_is_user = blk_op.is_user;
-    fd765_buffer = blk_op.addr;
+    fd765_is_user = is_raw;
+    fd765_buffer = udata.u_dptr;
 
     while (blocks != 0)
     {
@@ -114,7 +121,7 @@ uint8_t devfd_transfer(void)
             if (fd765_sectors > blocks)
                 fd765_sectors = blocks;
 
-            if (blk_op.is_read)
+            if (is_read)
                 fd765_do_read();
             else
                 fd765_do_write();
@@ -125,7 +132,7 @@ uint8_t devfd_transfer(void)
         }
         if (tries == 3)
         {
-            kprintf("fd%d: I/O error %d:%d\n", blk_op.is_read, lba);
+            kprintf("fd%d: I/O error %d:%d\n", is_read, lba);
             udata.u_error = EIO;
             break;
         }
@@ -134,5 +141,18 @@ uint8_t devfd_transfer(void)
         ct += fd765_sectors;
     }
 
-    return ct;
-}
\ No newline at end of file
+    return ct << BLKSHIFT;
+}
+
+int devfd_read(uint8_t minor, uint8_t is_raw, uint8_t flag)
+{
+    flag;minor;
+    return devfd_transfer(true, is_raw);
+}
+
+int devfd_write(uint8_t minor, uint8_t is_raw, uint8_t flag)
+{
+    flag;minor;
+    return devfd_transfer(false, is_raw);
+}
+
index 2c59a93..3f4ab84 100644 (file)
@@ -2,9 +2,11 @@
 #define __DEVFD_DOT_H__
 
 /* public interface */
-extern void devfd_init(void);
+int devfd_open(uint8_t minor, uint16_t flag);
+int devfd_read(uint8_t minor, uint8_t rawflag, uint8_t flag);
+int devfd_write(uint8_t minor, uint8_t rawflag, uint8_t flag);
+
 extern void devfd_spindown(void);
-extern uint8_t devfd_transfer(void);
 
 extern void fd765_do_nudge_tc(void);
 extern void fd765_do_recalibrate(void);