From 172c49843553f48bd2048ffa178485f1044066a8 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 8 Feb 2019 21:39:53 +0000 Subject: [PATCH] rabbit: further work to get to a buildable state --- Kernel/platform-rabbit2000/Makefile | 4 +- Kernel/platform-rabbit2000/fuzix.lnk | 4 +- Kernel/platform-rabbit2000/interrupt.s | 34 +++++++--- Kernel/platform-rabbit2000/main.c | 1 + Kernel/platform-rabbit2000/rabbit.h | 36 +++++++++++ Kernel/platform-rabbit2000/rabbit.s | 58 ++++++++++++++++- Kernel/platform-rabbit2000/spi.c | 86 ++++++++++++++++++++++++++ 7 files changed, 208 insertions(+), 15 deletions(-) create mode 100644 Kernel/platform-rabbit2000/spi.c diff --git a/Kernel/platform-rabbit2000/Makefile b/Kernel/platform-rabbit2000/Makefile index fc94afb6..98ff7430 100644 --- a/Kernel/platform-rabbit2000/Makefile +++ b/Kernel/platform-rabbit2000/Makefile @@ -1,5 +1,5 @@ -ASRCS = crt0.s tricks.s commonmem.s rabbit.s -CSRCS = devices.c main.c devtty.c +ASRCS = crt0.s tricks.s commonmem.s rabbit.s interrupt.s +CSRCS = devices.c main.c devtty.c spi.c DISCARD_CSRCS = DISCARD_DSRCS = ../dev/devsd_discard.c DSRCS = ../dev/devsd.c ../dev/mbr.c ../dev/blkdev.c diff --git a/Kernel/platform-rabbit2000/fuzix.lnk b/Kernel/platform-rabbit2000/fuzix.lnk index 96b79135..5444899b 100644 --- a/Kernel/platform-rabbit2000/fuzix.lnk +++ b/Kernel/platform-rabbit2000/fuzix.lnk @@ -6,13 +6,14 @@ -b _DISCARD=0xD800 platform-rabbit2000/crt0.rel platform-rabbit2000/commonmem.rel +platform-rabbit2000/interrupt.rel platform-rabbit2000/rabbit.rel platform-rabbit2000/main.rel +platform-rabbit2000/tricks.rel start.rel version.rel lowlevel-r2k.rel usermem_std-r2k.rel -platform-rabbit2000/tricks.rel timer.rel kdata.rel usermem.rel @@ -35,6 +36,7 @@ devsys.rel platform-rabbit2000/devtty.rel platform-rabbit2000/devsd.rel platform-rabbit2000/devsd_discard.rel +platform-rabbit2000/spi.rel platform-rabbit2000/mbr.rel platform-rabbit2000/blkdev.rel -e diff --git a/Kernel/platform-rabbit2000/interrupt.s b/Kernel/platform-rabbit2000/interrupt.s index a5188058..2d801f41 100644 --- a/Kernel/platform-rabbit2000/interrupt.s +++ b/Kernel/platform-rabbit2000/interrupt.s @@ -6,10 +6,19 @@ ; .module iir - .area _IIR + .area _DISCARD + + .globl _iir .globl unix_syscall_entry .globl ticktock + .globl sera_rx,serc_rx,serd_rx + .globl sera_tx,serc_tx,serd_tx + + .include 'kernel.def' + .include '../kernel-rabbit.def' + +_iir: periodic: eir0: ; If we use both we'll need to do some @@ -45,7 +54,7 @@ rst28: spare: ret - .bindry 16 + .bndry 16 rst38: ret @@ -65,7 +74,8 @@ spare2: timera: push af - ioi ld a,(TACSR) + ioi + ld a,(TACSR) pop af ipres ret @@ -74,7 +84,8 @@ timera: timerb: push af - ioi ld a,(TBCSR) + ioi + ld a,(TBCSR) pop af ipres ret @@ -83,8 +94,9 @@ timerb: seriala: push af - ioi ld a,(SASR) - or a + ioi + ld a,(SASR) + or a,a jp m,sera_rx jp sera_tx @@ -101,8 +113,9 @@ serialb: serialc: push af - ioi ld a,(SCSR) - or a + ioi + ld a,(SCSR) + or a,a jp m,serc_rx jp serc_tx @@ -111,8 +124,9 @@ serialc: seriald: push af - ioi ld a,(SDSR) - or a + ioi + ld a,(SDSR) + or a,a jp m,serd_rx jp serd_tx diff --git a/Kernel/platform-rabbit2000/main.c b/Kernel/platform-rabbit2000/main.c index f727031e..88a54978 100644 --- a/Kernel/platform-rabbit2000/main.c +++ b/Kernel/platform-rabbit2000/main.c @@ -6,6 +6,7 @@ #include uaddr_t ramtop = PROGTOP; +uint8_t ticker; void pagemap_init(void) { diff --git a/Kernel/platform-rabbit2000/rabbit.h b/Kernel/platform-rabbit2000/rabbit.h index fcfd7005..72005795 100644 --- a/Kernel/platform-rabbit2000/rabbit.h +++ b/Kernel/platform-rabbit2000/rabbit.h @@ -117,3 +117,39 @@ extern void rabbit_bop_watchdog(uint8_t code) __z88dk_fastcall; #define GREV_R2000C 0x03 #define GCPU_R2000 0x01 + +/* This lives in the flash in a protected (mostly) space and is written + into the board at manufacture */ + +struct SysIDBlock { + uint16_t tableVersion; /* ?? */ + uint16_t productID; /* Part Number */ + uint16_t vendorID; /* 1 */ + uint8_t timestamp[7]; + uint32_t flashID; /* Vendor/Product ID */ + uint16_t flashType; /* Write method */ + uint16_t flashSize; /* 4K pages */ + uint16_t sectorSize; /* bytes */ + uint16_t numSectors; + uint16_t flashSpeed; /* ns */ + uint32_t flash2ID; + uint16_t flash2Type; + uint16_t flash2Size; + uint16_t sector2Size; + uint16_t num2Sectors; + uint16_t flash2Speed; + uint32_t ramID; + uint16_t ramSize; /* 4K pages */ + uint16_t ramSpeed; /* ns */ + uint16_t cpuID; + uint32_t crystalFreq; /* HZ */ + uint8_t macAddr[6]; /* If allocated */ + uint8_t serialNumber[24]; + char productName[30]; /* \0 terminated */ + char reserved; + uint32_t idBlockSize; /* Size of SysIDBlock */ + uint16_t userBlockSize; + uint16_t userBlockLoc; /* Offset from this one */ + int idBlockCRC; /* CRC with this field 0 */ + char marker[6]; /* 55 AA 55 AA 55 AA */ +}; diff --git a/Kernel/platform-rabbit2000/rabbit.s b/Kernel/platform-rabbit2000/rabbit.s index 779b7670..ff137dfb 100644 --- a/Kernel/platform-rabbit2000/rabbit.s +++ b/Kernel/platform-rabbit2000/rabbit.s @@ -39,6 +39,7 @@ _int_disabled: .globl _ramsize .globl _procmem + .globl _iir init_early: ret @@ -51,6 +52,22 @@ init_hardware: or a,a sbc hl,de ld (_procmem),hl + + ; + ; Set up the interrupt table + ; + + ld hl,#_iir + ld de,#0 + ld bc,#256 +doldir: + ldi + jp lo,doldir + + xor a,a + ld iir,a + ld eir,a + ret .area _COMMONMEM @@ -69,6 +86,7 @@ _program_vectors: .globl map_kernel_di .globl map_save_kernel .globl map_restore + .globl map_for_swap .globl _kdataseg @@ -87,6 +105,7 @@ map_process_di: or a,l jr z, map_kernel ld a,(hl) +map_for_swap: map_process_a: ioi ld (DATASEG),a @@ -135,7 +154,6 @@ outwait: ld (SADR),a ret - .globl _spi_tx ; ; Low level Rabbit 2000 primitives to use Port B for SPI. ; @@ -156,14 +174,19 @@ outwait: .globl _rabbit_spi_rx .globl _rabbit_spi_slow .globl _rabbit_spi_fast + + .globl rabbit_spi_rxblock + .globl rabbit_spi_txblock ; _rabbit_spi_tx: + ld e,l +rabbit_spi_tx: ; Finish any previous transaction activity ioi ld a,(SBSR) bit 7,a jr nz,_rabbit_spi_tx - ld a,l + ld a,e ioi ld (SBDR),a ld a, #0x8C ; send, our clock (ie master) @@ -196,6 +219,34 @@ rxwait: ld l,a ret + ; + ; SD card block transfer helpers + ; HL = address, 512 bytes map is correct + ; +rabbit_spi_txblock: + ld b,#0 +txloop: + ld e,(hl) + inc hl + call rabbit_spi_tx + ld e,(hl) + inc hl + call rabbit_spi_tx + djnz txloop + ret + +rabbit_spi_rxblock: + ld b,#0 + ex de,hl +rxloop: + call _rabbit_spi_rx + ld (de),a + inc de + call _rabbit_spi_rx + ld (de),a + inc de + djnz rxloop + ret ; ; Slow speed for probing @@ -302,6 +353,9 @@ tickwrap: ld (hl),#11 ; slightly off for 200/second but the rtc .globl _ser'X'_q .globl _ser'X'_rxbuf + .globl ser'X'_rx + .globl ser'X'_tx + ser'X'_rx: push hl push de diff --git a/Kernel/platform-rabbit2000/spi.c b/Kernel/platform-rabbit2000/spi.c new file mode 100644 index 00000000..4ba89756 --- /dev/null +++ b/Kernel/platform-rabbit2000/spi.c @@ -0,0 +1,86 @@ +#include +#include +#include + +static uint8_t reverse[256] = { + 0, + /* TODO */ +}; + +void sd_spi_clock(bool go_fast) +{ + if (go_fast) + rabbit_spi_fast(); + else + rabbit_spi_slow(); +} + +void sd_spi_raise_cs(void) +{ + /* TODO pick a line */ +} + +void sd_spi_lower_cs(void) +{ + /* TODO pick a line */ +} + +void sd_spi_transmit_byte(uint8_t byte) +{ + rabbit_spi_tx(reverse[byte]); +} + +uint8_t sd_spi_receive_byte(void) +{ + return reverse[rabbit_spi_rx()]; +} + +COMMON_MEMORY + +/* + * Could also unroll these a bit for speed + */ + +bool sd_spi_receive_sector(void) __naked +{ + __asm + ld a, (_blk_op+BLKPARAM_IS_USER_OFFSET) + ld hl, (_blk_op+BLKPARAM_ADDR_OFFSET) +#ifdef SWAPDEV + cp #2 + jr nz, not_swapin + ld a,(_blk_op+BLKPARAM_SWAP_PAGE) + call map_for_swap + jr doread +not_swapin: +#endif + or a + jr z,doread + call map_process_always +doread: + call rabbit_spi_rxblock + jp map_kernel + __endasm; +} + +bool sd_spi_transmit_sector(void) __naked +{ + __asm + ld a, (_blk_op+BLKPARAM_IS_USER_OFFSET) + ld hl, (_blk_op+BLKPARAM_ADDR_OFFSET) +#ifdef SWAPDEV + cp #2 + jr nz, not_swapout + ld a, (_blk_op+BLKPARAM_SWAP_PAGE) + call map_for_swap + jr dowrite +not_swapout: +#endif + or a + jr z,dowrite + call map_process_always +dowrite: + call rabbit_spi_txblock + jp map_kernel + __endasm; +} -- 2.34.1