From db01fd885ba8603c29512879757d556c8cb6b47f Mon Sep 17 00:00:00 2001 From: Brett Gordon Date: Mon, 6 Jul 2015 08:02:42 -0400 Subject: [PATCH] platform-coco3: implement IDE --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
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
--- Kernel/platform-coco3/Makefile | 14 +++--- Kernel/platform-coco3/config.h | 7 ++- Kernel/platform-coco3/devices.c | 8 ++-- Kernel/platform-coco3/kernel.def | 5 +++ Kernel/platform-coco3/mbr.c | 74 ++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 Kernel/platform-coco3/mbr.c diff --git a/Kernel/platform-coco3/Makefile b/Kernel/platform-coco3/Makefile index 26452ac5..1dbb7fae 100644 --- a/Kernel/platform-coco3/Makefile +++ b/Kernel/platform-coco3/Makefile @@ -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 \ diff --git a/Kernel/platform-coco3/config.h b/Kernel/platform-coco3/config.h index 429547bf..66d44371 100644 --- a/Kernel/platform-coco3/config.h +++ b/Kernel/platform-coco3/config.h @@ -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 */ diff --git a/Kernel/platform-coco3/devices.c b/Kernel/platform-coco3/devices.c index 323ec606..e5189006 100644 --- a/Kernel/platform-coco3/devices.c +++ b/Kernel/platform-coco3/devices.c @@ -6,14 +6,15 @@ #include #include #include +#include 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( ); } diff --git a/Kernel/platform-coco3/kernel.def b/Kernel/platform-coco3/kernel.def index b5b150f1..b72d5314 100644 --- a/Kernel/platform-coco3/kernel.def +++ b/Kernel/platform-coco3/kernel.def @@ -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 index 00000000..b17228df --- /dev/null +++ b/Kernel/platform-coco3/mbr.c @@ -0,0 +1,74 @@ +/* 2015-01-04 Will Sowerbutts */ + +#include +#include +#include +#include + +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; ipartition[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); +} -- 2.34.1