coco2cart: assorted fixes
authorAlan Cox <alan@linux.intel.com>
Fri, 21 Apr 2017 23:05:32 +0000 (00:05 +0100)
committerAlan Cox <alan@linux.intel.com>
Fri, 21 Apr 2017 23:05:32 +0000 (00:05 +0100)
- Fix bugs in the sdc driver
- Build both sdc and ide versions
- Make swap auto-switch according to version
- Enable rawmode binary loading

Kernel/platform-coco2cart/Makefile
Kernel/platform-coco2cart/README
Kernel/platform-coco2cart/bootstrap.s
Kernel/platform-coco2cart/bootstrap_sdc.s
Kernel/platform-coco2cart/config.h
Kernel/platform-coco2cart/devsdc.c

index e89219f..e396cc0 100644 (file)
@@ -55,7 +55,7 @@ clean:
 image:
        $(CROSS_LD) -o ../fuzix.bin -Map=../fuzix.map --script=fuzix.link \
        --oformat=decb \
-       crt0.o bootstrap_sdc.o commonmem.o coco2.o discard.o ../simple.o \
+       crt0.o bootstrap.o commonmem.o coco2.o discard.o ../simple.o \
        ../start.o ../version.o ../lowlevel-6809.o \
        tricks.o main.o ../timer.o ../kdata.o devices.o \
        drivewire.o devdw.o mini_ide.o mini_ide_discard.o ide.o \
@@ -68,3 +68,19 @@ image:
        dd if=fuzix.img of=fuzix.rom bs=1024 skip=48 count=16
        dd if=fuzix.img of=fuzix.ide bs=256 skip=26 count=102
        dd if=fuzix.img of=fuzix.ide bs=256 skip=1 count=1 conv=notrunc
+
+       $(CROSS_LD) -o ../fuzix-sdc.bin -Map=../fuzix-sdc.map --script=fuzix.link \
+       --oformat=decb \
+       crt0.o bootstrap_sdc.o commonmem.o coco2.o discard.o ../simple.o \
+       ../start.o ../version.o ../lowlevel-6809.o \
+       tricks.o main.o ../timer.o ../kdata.o devices.o \
+       drivewire.o devdw.o mini_ide.o mini_ide_discard.o ide.o \
+       ../devio.o ../filesys.o ../process.o ../inode.o ../syscall_fs.o \
+       ../syscall_proc.o ../syscall_other.o ../mm.o ../swap.o \
+       ../tty.o ../devsys.o ../usermem.o usermem.o ../syscall_fs2.o \
+       ../syscall_exec16.o devtty.o libc.o ../vt.o video.o  ../syscall_fs3.o \
+       ../font8x8.o devsdc.o sdc.o
+       ../tools/decb-image <../fuzix-sdc.bin fuzix-sdc.img
+       dd if=fuzix-sdc.img of=fuzixsdc.rom bs=1024 skip=48 count=16
+       dd if=fuzix-sdc.img of=fuzix.sdc bs=256 skip=26 count=102
+       dd if=fuzix-sdc.img of=fuzix.sdc bs=256 skip=1 count=1 conv=notrunc
index 070ada0..e973126 100644 (file)
@@ -1,14 +1,12 @@
 COCO2
 =====
 
-(Work in progress)
-
 COCO or Dragon 64 with an IDE port, cartridge and 64K of RAM
 
 Supported hardware:
        IDE (Cloud9 or compatible set at FF50) with either built in
                cartridge RAM or separate cartridge
-       COCO SDC (in progress)
+       COCO SDC
 
 Disk Layout
 ===========
@@ -52,14 +50,13 @@ FF00-FFFF   I/O etc
 Emulating in XRoar
 ==================
 
-Needs the IDE patches
+Needs the IDE patches, no support for COCOSDC emulation in xroar as of 0.33.2
 
 TODO
 ====
 
 Make the boot loader robust (timeout handling)
 Add hash of code not just simple magic - so we know bits match
-Merge coco and IDE boot code so it works out which is present
 
 Support for a real time clock and clock locking
 
@@ -70,9 +67,6 @@ We have about 2K left to try and jam those bits in which might just about be
 enough to add support for very minimal MBR parsing and offsets. That would
 be a big improvement.
 
-Automatically pick swap according to whether IDE or SDC is present.
-
-
 To Test
 =======
 
@@ -80,9 +74,15 @@ Build the image and you'll get a fuzix.ide and fuzix.rom
 
 In the xroar directory where you have a hard disc image do
 
-dd if=/tmp/fuzix.ide of=hd0.img bs=512 seek=3 conv=notrunc
-/opt/xroaride/bin/xroar -default-machine dragon64 -cart ide -cart-rom fuzix.rom
+dd if=platform/fuzix.ide of=hd0.img bs=512 seek=3 conv=notrunc
+/opt/xroaride/bin/xroar -default-machine dragon64 -cart ide -cart-rom platform/fuzix.rom
 
 exec 49152
 
+A 32MB filesystem can be put in slice 1 using dd with an offset of 32MB + 2
+sectors.
+
+For the CocoSDC the same procedure applies (without an emulator however) but
+using the fuzixsdc rom and SD image.
+
 enjoy
index 5a367f0..45d4ca1 100644 (file)
        .module bootstrap
 
        .globl load_image
+       .globl _cocoswap_dev
 
        .area .text
 
+_cocoswap_dev:
+       .dw 0
+
 load_block:
        lda #$FF
        tfr a,dp
index 1dd1715..42fbb32 100644 (file)
        .module bootstrap
 
        .globl load_image
+       .globl _cocoswap_dev
 
        .area .text
+_cocoswap_dev:
+       .dw $0900               ; SD card slice 0 rest of
 
 ;;; Load a sector from SDC
 ;;;   takes: B - sector number, X = dest address
index a007182..a4485c3 100644 (file)
 
 #define CONFIG_BANKS   1
 /* And swapping */
-#define SWAPDEV     0x000              /* Uses part of IDE slice 0 */
-//#define SWAPDEV     0x900            /* Uses part of SD slice 0 */
+
+extern unsigned int cocoswap_dev;
+
+#define SWAPDEV     cocoswap_dev    /* Uses part of IDE slice 0 or SD 0*/
 #define SWAP_SIZE   0x40       /* 32K in 512 byte blocks */
 #define SWAPBASE    0x8000     /* We swap the lot */
 #define SWAPTOP     0xFE00     /* so it's a round number of 512 byte sectors */
index a5814a8..547c63c 100644 (file)
@@ -1,13 +1,12 @@
 /*
-
- CoCoSDC driver
- (c)2015 Brett M. Gordon GPL2
-
+ * CoCoSDC driver
+ * (c)2015 Brett M. Gordon GPL2
+ *
  * Needs work on extended SDC API stuff.
  * init / mounting stuff really needs to set/update blkdev structure for size
- * need to get rawmode=1 and 2 working.
-
-*/
+ *
+ * Only supports simple memory models.
+ */
 
 #include <kernel.h>
 #include <kdata.h>
@@ -42,6 +41,7 @@
 #define sdc_reg_param2 *((volatile uint8_t *)SDC_REG_PARAM2)
 #define sdc_reg_param3 *((volatile uint8_t *)SDC_REG_PARAM3)
 
+static uint8_t sdc_present;
 
 /* Assembler glue */
 
@@ -60,14 +60,14 @@ typedef void (*sdc_transfer_function_t)( unsigned char *addr);
 /* blkdev method: transfer sectors */
 static uint8_t sdc_transfer(uint8_t minor, bool is_read, uint8_t rawflag)
 {
-               uint8_t nb = udata.u_nblock;  /* our return value, preset to failure */
+               uint8_t nb = 0;
        uint32_t lba;             /* holds 32 bit lsn */
-       uint8_t *ptr = ((uint8_t *)&lba)+1;      /* points to 24 bit lba in blk op */
+       uint8_t *ptr = ((uint8_t *)&lba) + 1;      /* points to 24 bit lba in blk op */
        uint8_t t;                /* temporarory sdc status holder */
        uint8_t cmd;              /* holds SDC command value */
        sdc_transfer_function_t fptr;  /* holds which xfer routine we want */
 
-       if (rawflag == 1 && d_blkoff(9) )
+       if (rawflag == 1 && d_blkoff(9))
                return -1;
 
        /* pass rawflag to assembler */
@@ -80,20 +80,19 @@ static uint8_t sdc_transfer(uint8_t minor, bool is_read, uint8_t rawflag)
        ptr[0] |= (minor & 0x7f) << 1;
 
        /* setup cmd pointer and command value from blk_op */
-       if( is_read ){
+       if (is_read) {
                cmd = 0x80;
                fptr = sdc_read_data;
-       }
-       else{
+       } else {
                cmd = 0xa0;
                fptr = sdc_write_data;
        }
 
-       /* apply our drive value 0 or 1*/
-       if( minor & 0x80 )
+       /* apply our drive value 0 or 1 */
+       if (minor & 0x80)
                cmd++;
 
-       while(udata.u_nblock--){
+       while (udata.u_nblock--) {
                /* load up registers */
                sdc_reg_param1 = ptr[0];
                sdc_reg_param2 = ptr[1];
@@ -102,23 +101,26 @@ static uint8_t sdc_transfer(uint8_t minor, bool is_read, uint8_t rawflag)
                asm("\texg x,x\n");     /* delay 16us minimum */
                asm("\texg x,x\n");
                /* wait till SDC is ready */
-               do{
+               do {
                        t=sdc_reg_stat;
-                       if( t & SDC_FAIL ) goto fail;
-               } while( ! (t & SDC_READY) );
+                       if (t & SDC_FAIL)
+                               goto fail;
+               } while(!(t & SDC_READY));
                /* do our low-level xfer function */
-               fptr( udata.u_dptr );
+               fptr(udata.u_dptr);
                /* and wait will ready again, and test for failure */
-               do{
+               do {
                        t=sdc_reg_stat;
-                       if( t & SDC_FAIL ) goto fail;
-               }while ( t & SDC_BUSY );
+                       if( t & SDC_FAIL )
+                               goto fail;
+               } while (t & SDC_BUSY);
                /* increment our blk_op values for next 256 bytes sector */
                udata.u_dptr += 256;
                lba++;
+               nb++;
        }
        /*  Huzzah!  success! */
-       return nb;
+       return nb << 9;
        /* Boo!  failure */
  fail: sdc_reg_ctl = 0x00;
        udata.u_error = EIO;
@@ -136,32 +138,40 @@ int sdc_write(uint8_t minor, uint8_t rawflag, uint8_t flag)
     return sdc_transfer(minor, false, rawflag);
 }
 
-
-
-
+int sdc_open(uint8_t minor, uint16_t flag)
+{
+       if (!sdc_present) {
+               udata.u_error = ENODEV;
+               return -1;
+       }
+       return 0;
+}
 
 __attribute__((section(".discard")))
 /* Returns true if SDC hardware seems to exist */
-bool devsdc_exist()
+
+bool devsdc_exist(void)
 {
        uint8_t t;
-       sdc_reg_data=0x64;
-       t=sdc_reg_fctl;
-       sdc_reg_data=0x00;
-       if( (sdc_reg_fctl ^ t) == 0x60 ) return -1;
+       sdc_reg_data = 0x64;
+       t = sdc_reg_fctl;
+       sdc_reg_data = 0x00;
+       if ((sdc_reg_fctl ^ t) == 0x60)
+               return -1;
        else return 0;
 }
 
 __attribute__((section(".discard")))
 /* Call this to initialize SDC/blkdev interface */
-void devsdc_init()
+void devsdc_init(void)
 {
        kputs("SDC: ");
-       if( devsdc_exist() ){
+       if (devsdc_exist()) {
                /* turn on uber-secret SDC LBA mode*/
                sdc_reg_ctl = 0x43; 
+               sdc_present = 1;
                kputs("Ok.\n");
        }
-       else kprintf("Not Found.\n");
+       else kprintf("Not found.\n");
 }