From aa98bd262ea669c705a924a4b642c653c3544933 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 22 Apr 2017 00:05:32 +0100 Subject: [PATCH] coco2cart: assorted fixes - 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 | 18 ++++- Kernel/platform-coco2cart/README | 20 +++--- Kernel/platform-coco2cart/bootstrap.s | 4 ++ Kernel/platform-coco2cart/bootstrap_sdc.s | 3 + Kernel/platform-coco2cart/config.h | 6 +- Kernel/platform-coco2cart/devsdc.c | 80 +++++++++++++---------- 6 files changed, 83 insertions(+), 48 deletions(-) diff --git a/Kernel/platform-coco2cart/Makefile b/Kernel/platform-coco2cart/Makefile index e89219fe..e396cc06 100644 --- a/Kernel/platform-coco2cart/Makefile +++ b/Kernel/platform-coco2cart/Makefile @@ -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 diff --git a/Kernel/platform-coco2cart/README b/Kernel/platform-coco2cart/README index 070ada0e..e9731262 100644 --- a/Kernel/platform-coco2cart/README +++ b/Kernel/platform-coco2cart/README @@ -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 diff --git a/Kernel/platform-coco2cart/bootstrap.s b/Kernel/platform-coco2cart/bootstrap.s index 5a367f07..45d4ca1f 100644 --- a/Kernel/platform-coco2cart/bootstrap.s +++ b/Kernel/platform-coco2cart/bootstrap.s @@ -11,9 +11,13 @@ .module bootstrap .globl load_image + .globl _cocoswap_dev .area .text +_cocoswap_dev: + .dw 0 + load_block: lda #$FF tfr a,dp diff --git a/Kernel/platform-coco2cart/bootstrap_sdc.s b/Kernel/platform-coco2cart/bootstrap_sdc.s index 1dd17152..42fbb328 100644 --- a/Kernel/platform-coco2cart/bootstrap_sdc.s +++ b/Kernel/platform-coco2cart/bootstrap_sdc.s @@ -14,8 +14,11 @@ .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 diff --git a/Kernel/platform-coco2cart/config.h b/Kernel/platform-coco2cart/config.h index a0071822..a4485c33 100644 --- a/Kernel/platform-coco2cart/config.h +++ b/Kernel/platform-coco2cart/config.h @@ -15,8 +15,10 @@ #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 */ diff --git a/Kernel/platform-coco2cart/devsdc.c b/Kernel/platform-coco2cart/devsdc.c index a5814a83..547c63c1 100644 --- a/Kernel/platform-coco2cart/devsdc.c +++ b/Kernel/platform-coco2cart/devsdc.c @@ -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 #include @@ -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"); } -- 2.34.1