platform-coco3: implement IDE
authorBrett Gordon <beretta42@gmail.com>
Mon, 6 Jul 2015 12:02:42 +0000 (08:02 -0400)
committerAlan Cox <alan@linux.intel.com>
Mon, 6 Jul 2015 15:58:40 +0000 (16:58 +0100)
--047d7b41cc5cd5d441051a33ae0e
Content-Type: text/plain; charset=UTF-8

update to platform-coco3:

* now does IDE via blkdev
* shared dragon-nx32's ide transfer routine(s)
* (re)implements mbr.c for coco's partitioning scheme

--
Brett M. Gordon,
beretta42@gmail.com

<div dir="ltr"><div>update to platform-coco3:</div><div><br></div><div>* now does IDE via blkdev</div><div>* shared dragon-nx32&#39;s ide transfer routine(s)</div><div>* (re)implements mbr.c for coco&#39;s partitioning scheme</div><div><br></div><div><br></div>-- <br><div class="gmail_signature">Brett M. Gordon,<br><a href="mailto:beretta42@gmail.com" target="_blank">beretta42@gmail.com</a></div>
</div>

Kernel/platform-coco3/Makefile
Kernel/platform-coco3/config.h
Kernel/platform-coco3/devices.c
Kernel/platform-coco3/kernel.def
Kernel/platform-coco3/mbr.c [new file with mode: 0644]

index 26452ac..1dbb7fa 100644 (file)
@@ -1,20 +1,21 @@
 
-CSRCS = devtty.c ttydw.c
+CSRCS = devtty.c ttydw.c mbr.c
 CSRCS += devices.c main.c libc.c
 
-DSRCS = ../dev/devdw.c
+DSRCS = ../dev/devdw.c ../dev/blkdev.c ../dev/devide.c
+DSRCS += ../dev/devide_discard.c
 
-ASRCS = coco3.s crt0.s
+ASRCS = coco3.s crt0.s ../platform-dragon-nx32/ide.s
 ASRCS += tricks.s commonmem.s usermem_gime.s drivewire.s
 
 COBJS = $(CSRCS:.c=$(BINEXT))
 AOBJS = $(ASRCS:.s=$(BINEXT))
-DOBJS = devdw.o
+DOBJS = devdw.o blkdev.o devide.o devide_discard.o
 OBJS  = $(COBJS) $(AOBJS) $(DOBJS)
 
 CROSS_CCOPTS += -I../dev/
 
-JUNK = $(CSRCS:.c=.o) $(ASRCS:.s=.o)
+JUNK = $(CSRCS:.c=.o) $(ASRCS:.s=.o) $(DSRCS:.c=.o)
 
 all:   $(OBJS)
 
@@ -37,7 +38,8 @@ image:
        crt0.o commonmem.o \
        coco3.o ../start.o ../version.o ../lowlevel-6809.o \
        tricks.o main.o ../timer.o ../kdata.o devices.o \
-       drivewire.o devdw.o ttydw.o \
+       drivewire.o devdw.o ttydw.o blkdev.o mbr.o devide.o devide_discard.o \
+       ../platform-dragon-nx32/ide.o \
        ../devio.o ../filesys.o ../process.o ../inode.o ../syscall_fs.o \
        ../syscall_proc.o ../syscall_other.o ../mm.o ../bank16k.o ../swap.o \
        ../tty.o ../devsys.o ../usermem.o ../syscall_fs2.o ../syscall_exec16.o \
index 429547b..66d4437 100644 (file)
@@ -70,7 +70,7 @@ extern unsigned char vt_map( unsigned char c );
 #define NUM_DEV_TTY 10
 #define TTYDEV   BOOT_TTY /* Device used by kernel for messages, panics */
 #define NBUFS    6       /* Number of block buffers */
-#define NMOUNTS         2        /* Number of mounts at a time - nothing mountable! */
+#define NMOUNTS         4        /* Number of mounts at a time - nothing mountable! */
 
 #define CONFIG_COCO_KBD   /* Use CoCo key maps rather than Dragon */
 
@@ -81,3 +81,8 @@ extern unsigned char vt_map( unsigned char c );
 #define DW_VWIN_NUM 4     /* No of Virtual Window Ports */
 #define DW_MIN_OFF  3     /* Minor number offset */
 
+/* Block device define */
+#define MAX_BLKDEV  2     /* IDE */
+#define DEVICE_IDE        /* enable if IDE interface present */
+#define IDE_REG_CS1_BASE 0xFF50
+#define IDE_IS_MMIO  1         /* MMIO IDE */
index 323ec60..e518900 100644 (file)
@@ -6,14 +6,15 @@
 #include <tty.h>
 #include <vt.h>
 #include <devtty.h>
+#include <blkdev.h>
 
 struct devsw dev_tab[] =  /* The device driver switch table */
 {
 // minor    open         close        read      write       ioctl
 // -----------------------------------------------------------------
-  /* 0: /dev/fd                Floppy disc block devices  */
-  {  nxio_open,     no_close,    no_rdwr,   no_rdwr,   no_ioctl },
-  /* 1: /dev/hd                Hard disc block devices (absent) */
+  /* 0: /dev/hd                Hard disc block devices (absent) */
+  {  blkdev_open,  no_close,    blkdev_read,   blkdev_write,   blkdev_ioctl },
+  /* 1: /dev/fd                Floppy disc block devices  */
   {  nxio_open,     no_close,    no_rdwr,   no_rdwr,   no_ioctl },
   /* 2: /dev/tty       TTY devices */
   {  tty_open,     my_tty_close,   tty_read,  tty_write,  tty_ioctl },
@@ -40,5 +41,6 @@ bool validdev(uint16_t dev)
 }
 void device_init(void)
 {
+       devide_init( );
 }
 
index b5b150f..b72d531 100644 (file)
@@ -18,3 +18,8 @@ SAM_SAVE macro
 
 SAM_RESTORE macro
        endm
+
+
+;; asm/c shared IDE stuff
+IDEDATA                            equ 0xFF50
+IDEDATA_L                  equ 0xFF58
\ No newline at end of file
diff --git a/Kernel/platform-coco3/mbr.c b/Kernel/platform-coco3/mbr.c
new file mode 100644 (file)
index 0000000..b17228d
--- /dev/null
@@ -0,0 +1,74 @@
+/* 2015-01-04 Will Sowerbutts */
+
+#include <kernel.h>
+#include <kdata.h>
+#include <printf.h>
+#include <blkdev.h>
+
+typedef struct {
+       uint8_t  flags;
+       uint8_t  type;
+       uint16_t start_h;
+       uint32_t start;
+       uint16_t len_h;
+       uint32_t len;
+       uint8_t  res[2];
+} partition_table_entry_t;
+
+
+
+#define MBR_ENTRY_COUNT 14
+#define MBR_SIGNATURE 0x43435054 
+typedef struct {
+       uint32_t  magic;  // magic no. "CCPT", big endian.
+       uint16_t  sz_h;   // high word of size
+       uint32_t  sz;     // low long of size
+       uint8_t   secz;   // sector size
+       uint16_t  cyls;    // number of cylindars
+       uint16_t  heads;  // number of heads
+       uint16_t  secs;   // number of sectors
+       uint16_t  crc;    // CRC of table
+       uint8_t   res[13]; // reserved
+       partition_table_entry_t partition[MBR_ENTRY_COUNT];
+} boot_record_t ;
+
+
+void mbr_parse(char letter)
+{
+       boot_record_t *br;
+       uint8_t i,k = 0;
+       
+       kprintf("hd%c: ", letter);
+       
+       /* allocate temporary memory */
+       br = (boot_record_t *)tmpbuf();
+       
+       blk_op.is_read = true;
+       blk_op.is_user = false;
+       blk_op.addr = br;
+       blk_op.lba = 0;
+       blk_op.nblock = 1;
+       
+       /* FIX: should also check table's CRC */
+       if(!blk_op.blkdev->transfer() || br->magic != MBR_SIGNATURE){
+               kputs("No CCPT");
+               return;
+       }
+       
+       /* add each entry to blkops struct */
+       /*  This adds paritions as it finds good ones? */
+       for(i=0; i<MBR_ENTRY_COUNT; i++){
+               if( ! br->partition[i].flags ){
+                       continue;
+               }
+               else{
+                       blk_op.blkdev->lba_first[k] = br->partition[i].start;
+                       blk_op.blkdev->lba_count[k] = br->partition[i].len;
+                       kprintf("hd%c%d ", letter, k+1);
+                       k++;
+               }
+       }
+               
+       /* release temporary memory */
+       brelse((bufptr)br);
+}