From 0d13b37a5da465e04ffd76b6d14388e6aae1180c Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 13 Feb 2015 22:30:23 +0000 Subject: [PATCH] tres80: Bring in line with __DISCARD changes --- Kernel/platform-trs80/Makefile | 7 +- Kernel/platform-trs80/devhd.c | 127 +------------------------- Kernel/platform-trs80/devhd.h | 57 ++++++++++-- Kernel/platform-trs80/devhd_discard.c | 93 +++++++++++++++++++ Kernel/platform-trs80/devices.c | 10 -- Kernel/platform-trs80/fuzix.lnk | 2 + Kernel/platform-trs80/main.c | 11 --- 7 files changed, 155 insertions(+), 152 deletions(-) create mode 100644 Kernel/platform-trs80/devhd_discard.c diff --git a/Kernel/platform-trs80/Makefile b/Kernel/platform-trs80/Makefile index e199e028..d28ab0d9 100644 --- a/Kernel/platform-trs80/Makefile +++ b/Kernel/platform-trs80/Makefile @@ -1,13 +1,15 @@ CSRCS = devlpr.c devtty.c devfd.c devhd.c CSRCS += devices.c main.c +DISCARD_CSRCS = discard.c devhd_discard.c ASRCS = trs80.s crt0.s ASRCS += tricks.s commonmem.s floppy.s COBJS = $(CSRCS:.c=.rel) AOBJS = $(ASRCS:.s=.rel) -OBJS = $(COBJS) $(AOBJS) +DISCARD_COBJS = $(DISCARD_CSRCS:.c=.rel) +OBJS = $(COBJS) $(AOBJS) $(DISCARD_COBJS) JUNK = $(CSRCS:.c=.lst) $(CSRCS:.c=.asm) $(CSRCS:.c=.sym) $(ASRCS:.s=.lst) $(ASRCS:.s=.sym) $(CSRCS:.c=.rst) $(ASRCS:.s=.rst) @@ -19,6 +21,9 @@ $(COBJS): %.rel: %.c $(AOBJS): %.rel: %.s $(CROSS_AS) $(ASOPTS) $< +$(DISCARD_COBJS): %.rel: %.c + $(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEGDISC) -c $< + clean: rm -f $(OBJS) $(JUNK) core *~ diff --git a/Kernel/platform-trs80/devhd.c b/Kernel/platform-trs80/devhd.c index 4652435f..8ac2009c 100644 --- a/Kernel/platform-trs80/devhd.c +++ b/Kernel/platform-trs80/devhd.c @@ -2,41 +2,13 @@ * WD1010 hard disk driver */ +#define _HD_PRIVATE #include #include #include #include #include -__sfr __at 0xC0 hd_wpbits; /* Write protect and IRQ (not used) */ -__sfr __at 0xC1 hd_ctrl; /* Reset and enable bits */ -__sfr __at 0xC8 hd_data; -__sfr __at 0xC9 hd_precomp; /* W/O */ -__sfr __at 0xC9 hd_err; /* R/O */ -__sfr __at 0xCA hd_seccnt; -__sfr __at 0xCB hd_secnum; -__sfr __at 0xCC hd_cyllo; -__sfr __at 0xCD hd_cylhi; -__sfr __at 0xCE hd_sdh; -__sfr __at 0xCF hd_status; /* R/O */ -__sfr __at 0xCF hd_cmd; - -#define HDCMD_RESTORE 0x10 -#define HDCMD_READ 0x20 -#define HDCMD_WRITE 0x30 -#define HDCMD_VERIFY 0x40 /* Not on the 1010 later only */ -#define HDCMD_FORMAT 0x50 -#define HDCMD_INIT 0x60 /* Ditto */ -#define HDCMD_SEEK 0x70 - -#define RATE_4MS 0x08 /* 4ms step rate for hd (conservative) */ - -#define HDCTRL_SOFTRESET 0x10 -#define HDCTRL_ENABLE 0x08 -#define HDCTRL_WAITENABLE 0x04 - -#define HDSDH_ECC256 0x80 - /* Used by the asm helpers */ uint8_t hd_page; @@ -46,12 +18,10 @@ uint16_t swap_dev; /* Seek and restore low 4 bits are the step rate, read/write support multi-sector mode but not all emulators do .. */ -#define MAX_HD 4 - struct minipart parts[MAX_HD]; /* Wait for the drive to show ready */ -static uint8_t hd_waitready(void) +uint8_t hd_waitready(void) { uint8_t st; do { @@ -61,7 +31,7 @@ static uint8_t hd_waitready(void) } /* Wait for DRQ or an error */ -static uint8_t hd_waitdrq(void) +uint8_t hd_waitdrq(void) { uint8_t st; do { @@ -70,7 +40,7 @@ static uint8_t hd_waitdrq(void) return st; } -static uint8_t hd_xfer(bool is_read, uint16_t addr) +uint8_t hd_xfer(bool is_read, uint16_t addr) { /* Error ? */ if (hd_status & 0x01) @@ -218,92 +188,3 @@ int hd_write(uint8_t minor, uint8_t rawflag, uint8_t flag) return hd_transfer(minor, false, rawflag); } -/*------------------- below this is thrown after boot ---------------- */ -DISCARDABLE - -/* - * Mini part processing. This and mbr and other things all one day - * need to become a bit more unified. - */ -static void hd_swapon(struct minipart *p, unsigned int d, unsigned int i) -{ - uint16_t cyls; - if (i == 14 || p->cyl[i+1] == 0xFFFF) - cyls = p->g.cyl; - else - cyls = p->cyl[i+1]; - cyls -= p->cyl[i]; - cyls *= p->g.head; - /* This is now the number of sets of 32 sectors (16K) in swap. - We need 32K per process: hardwire it here - FIX if you change - the mapping model */ - - swap_dev = (d << 4) + i + 1 + 0x100; - - if (cyls >= MAX_SWAPS) - cyls = MAX_SWAPS - 1; - for (i = 0; i < cyls; i++) { - swapmap_add(i); - } - kputs("swap-"); -} - -void hd_probe(void) -{ - unsigned int dev = 0; - unsigned int i; - uint8_t *d = tmpbuf(); - /* Second half of second block */ - struct minipart *p = (struct minipart *)(d + 128); - for (dev = 0; dev < 4; dev++) { - hd_sdh = 0x80 | (dev << 3); - hd_cmd = HDCMD_RESTORE | RATE_4MS; - if (hd_waitready() & 1) { - if ((hd_err & 0x12) == 0x12) - continue; - } - hd_seccnt = 1; - hd_sdh = 0x80 | (dev << 3); - hd_secnum = 2; - hd_cyllo = 0; - hd_cylhi = 0; - hd_cmd = HDCMD_READ; - if (hd_waitdrq() & 1) - continue; - if((hd_xfer(1, (uint16_t)d) & 0x41) != 0x40) - continue; - kprintf("hd%c: ", dev + 'a'); - if (p->g.magic != MP_SIG_0) { - p->g.cyl = 1; - p->g.head = 1; - p->g.sec = 32; - p->g.precomp = 0; - p->g.seek = 10; - p->g.secsize = 8; - for (i = 0; i < 15; i++) - p->cyl[i] = 0xFFFFU; - kputs("(unlabelled)\n"); - } else { - for (i = 0; i < 15; i++) { - if (p->cyl[i] != 0xFFFFU) { - if (p->type[i] == 0x56) { - /* Configure swap */ - hd_swapon(p, dev, i); - } - kprintf("hd%c%d ", dev + 'a', i + 1); - } - } - kputs("\n"); - } - if (p->g.seek) { - p->g.seek /= 2; - if (p->g.seek == 0) - p->g.seek = 1; - } - /* Set the step rate */ - hd_cmd = HDCMD_SEEK | p->g.seek; - hd_waitready(); - memcpy(&parts[dev], p, sizeof(parts[dev])); - } - brelse((bufptr)d); -} diff --git a/Kernel/platform-trs80/devhd.h b/Kernel/platform-trs80/devhd.h index bdebb171..12b9e2f7 100644 --- a/Kernel/platform-trs80/devhd.h +++ b/Kernel/platform-trs80/devhd.h @@ -2,14 +2,57 @@ #define __DEVHD_DOT_H__ /* public interface */ -int hd_read(uint8_t minor, uint8_t rawflag, uint8_t flag); -int hd_write(uint8_t minor, uint8_t rawflag, uint8_t flag); -int hd_open(uint8_t minor, uint16_t flag); +extern int hd_read(uint8_t minor, uint8_t rawflag, uint8_t flag); +extern int hd_write(uint8_t minor, uint8_t rawflag, uint8_t flag); +extern int hd_open(uint8_t minor, uint16_t flag); -/* helpers in common memory for the block transfers */ -int hd_xfer_in(uint16_t addr); -int hd_xfer_out(uint16_t addr); +extern void hd_probe(void); + +#ifdef _HD_PRIVATE + +__sfr __at 0xC0 hd_wpbits; /* Write protect and IRQ (not used) */ +__sfr __at 0xC1 hd_ctrl; /* Reset and enable bits */ +__sfr __at 0xC8 hd_data; +__sfr __at 0xC9 hd_precomp; /* W/O */ +__sfr __at 0xC9 hd_err; /* R/O */ +__sfr __at 0xCA hd_seccnt; +__sfr __at 0xCB hd_secnum; +__sfr __at 0xCC hd_cyllo; +__sfr __at 0xCD hd_cylhi; +__sfr __at 0xCE hd_sdh; +__sfr __at 0xCF hd_status; /* R/O */ +__sfr __at 0xCF hd_cmd; + +#define HDCMD_RESTORE 0x10 +#define HDCMD_READ 0x20 +#define HDCMD_WRITE 0x30 +#define HDCMD_VERIFY 0x40 /* Not on the 1010 later only */ +#define HDCMD_FORMAT 0x50 +#define HDCMD_INIT 0x60 /* Ditto */ +#define HDCMD_SEEK 0x70 + +#define RATE_4MS 0x08 /* 4ms step rate for hd (conservative) */ + +#define HDCTRL_SOFTRESET 0x10 +#define HDCTRL_ENABLE 0x08 +#define HDCTRL_WAITENABLE 0x04 -void hd_probe(void); +#define HDSDH_ECC256 0x80 + +/* Seek and restore low 4 bits are the step rate, read/write support + multi-sector mode but not all emulators do .. */ + +#define MAX_HD 4 + +extern struct minipart parts[MAX_HD]; + +extern uint8_t hd_waitready(void); +extern uint8_t hd_waitdrq(void); +extern uint8_t hd_xfer(bool is_read, uint16_t addr); + +/* helpers in common memory for the block transfers */ +extern int hd_xfer_in(uint16_t addr); +extern int hd_xfer_out(uint16_t addr); +#endif #endif /* __DEVHD_DOT_H__ */ diff --git a/Kernel/platform-trs80/devhd_discard.c b/Kernel/platform-trs80/devhd_discard.c new file mode 100644 index 00000000..d5dd0a2e --- /dev/null +++ b/Kernel/platform-trs80/devhd_discard.c @@ -0,0 +1,93 @@ +#define _HD_PRIVATE +#include +#include +#include +#include +#include + +/* + * Mini part processing. This and mbr and other things all one day + * need to become a bit more unified. + */ +static void hd_swapon(struct minipart *p, unsigned int d, unsigned int i) +{ + uint16_t cyls; + if (i == 14 || p->cyl[i+1] == 0xFFFF) + cyls = p->g.cyl; + else + cyls = p->cyl[i+1]; + cyls -= p->cyl[i]; + cyls *= p->g.head; + /* This is now the number of sets of 32 sectors (16K) in swap. + We need 32K per process: hardwire it here - FIX if you change + the mapping model */ + + swap_dev = (d << 4) + i + 1 + 0x100; + + if (cyls >= MAX_SWAPS) + cyls = MAX_SWAPS - 1; + for (i = 0; i < cyls; i++) { + swapmap_add(i); + } + kputs("swap-"); +} + +void hd_probe(void) +{ + unsigned int dev = 0; + unsigned int i; + uint8_t *d = tmpbuf(); + /* Second half of second block */ + struct minipart *p = (struct minipart *)(d + 128); + for (dev = 0; dev < 4; dev++) { + hd_sdh = 0x80 | (dev << 3); + hd_cmd = HDCMD_RESTORE | RATE_4MS; + if (hd_waitready() & 1) { + if ((hd_err & 0x12) == 0x12) + continue; + } + hd_seccnt = 1; + hd_sdh = 0x80 | (dev << 3); + hd_secnum = 2; + hd_cyllo = 0; + hd_cylhi = 0; + hd_cmd = HDCMD_READ; + if (hd_waitdrq() & 1) + continue; + if((hd_xfer(1, (uint16_t)d) & 0x41) != 0x40) + continue; + kprintf("hd%c: ", dev + 'a'); + if (p->g.magic != MP_SIG_0) { + p->g.cyl = 1; + p->g.head = 1; + p->g.sec = 32; + p->g.precomp = 0; + p->g.seek = 10; + p->g.secsize = 8; + for (i = 0; i < 15; i++) + p->cyl[i] = 0xFFFFU; + kputs("(unlabelled)\n"); + } else { + for (i = 0; i < 15; i++) { + if (p->cyl[i] != 0xFFFFU) { + if (p->type[i] == 0x56) { + /* Configure swap */ + hd_swapon(p, dev, i); + } + kprintf("hd%c%d ", dev + 'a', i + 1); + } + } + kputs("\n"); + } + if (p->g.seek) { + p->g.seek /= 2; + if (p->g.seek == 0) + p->g.seek = 1; + } + /* Set the step rate */ + hd_cmd = HDCMD_SEEK | p->g.seek; + hd_waitready(); + memcpy(&parts[dev], p, sizeof(parts[dev])); + } + brelse((bufptr)d); +} diff --git a/Kernel/platform-trs80/devices.c b/Kernel/platform-trs80/devices.c index 7287717e..6a9792dd 100644 --- a/Kernel/platform-trs80/devices.c +++ b/Kernel/platform-trs80/devices.c @@ -34,13 +34,3 @@ bool validdev(uint16_t dev) return true; } -DISCARDABLE - -void device_init(void) -{ -#ifdef CONFIG_RTC - /* Time of day clock */ - inittod(); -#endif - hd_probe(); -} diff --git a/Kernel/platform-trs80/fuzix.lnk b/Kernel/platform-trs80/fuzix.lnk index 7202f5ef..bca84f3d 100644 --- a/Kernel/platform-trs80/fuzix.lnk +++ b/Kernel/platform-trs80/fuzix.lnk @@ -19,6 +19,7 @@ kdata.rel platform-trs80/devfd.rel platform-trs80/floppy.rel platform-trs80/devhd.rel +platform-trs80/devhd_discard.rel platform-trs80/devices.rel devio.rel filesys.rel @@ -37,4 +38,5 @@ vt.rel devsys.rel platform-trs80/devlpr.rel platform-trs80/devtty.rel +platform-trs80/discard.rel -e diff --git a/Kernel/platform-trs80/main.c b/Kernel/platform-trs80/main.c index ad25b077..8572a556 100644 --- a/Kernel/platform-trs80/main.c +++ b/Kernel/platform-trs80/main.c @@ -50,14 +50,3 @@ uint8_t rtc_secs(void) #endif -DISCARDABLE - -void map_init(void) -{ -} - -void pagemap_init(void) -{ - pagemap_add(0x63); /* Mode 3, U64K low 32K mapped as low 32K */ - pagemap_add(0x73); /* Mode 3, U64K high 32K mapped as low 32K */ -} -- 2.34.1