From 8cc72407d62bac47786ce04cd2c89732ff1cce6f Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 8 Feb 2018 23:07:33 +0000 Subject: [PATCH] ubee: disk probing With these patches I can build a .ds82 image for the rootfs in the B drive and boot it with "1 ro". Read/write seems to eat the disk, so that needs a bit of debugging! --- Kernel/platform-ubee/devices.c | 3 ++ Kernel/platform-ubee/main.c | 63 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/Kernel/platform-ubee/devices.c b/Kernel/platform-ubee/devices.c index 7eb72f73..3b071348 100644 --- a/Kernel/platform-ubee/devices.c +++ b/Kernel/platform-ubee/devices.c @@ -7,6 +7,7 @@ #include #include #include +#include struct devsw dev_tab[] = /* The device driver switch table */ { @@ -38,6 +39,8 @@ void device_init(void) int i; /* Time of day clock */ inittod(); + /* Figure out what disks we have */ + diskprobe(); /* Add 64 swaps (2MB) */ for (i = MAX_SWAPS - 1 ; i >= 0; i--) swapmap_init(i); diff --git a/Kernel/platform-ubee/main.c b/Kernel/platform-ubee/main.c index dc73c822..93fb5984 100644 --- a/Kernel/platform-ubee/main.c +++ b/Kernel/platform-ubee/main.c @@ -65,6 +65,69 @@ void map_init(void) } +uint8_t disk_type[2]; + +/* More _DISCARD material */ + +__sfr __at 0x58 portswitch; +__sfr __at 0x45 probe_reg; +__sfr __at 0x41 fdc_cyl; +__sfr __at 0x48 fdc_stat; + +void do_diskprobe(uint8_t *p) +{ + probe_reg = 0x5A; + /* probe_reg is read/write same value for both controllers so if it + doesn't work we have no disk */ + if (probe_reg != 0x5A) + return; + /* If it mirrored check if a second value mirrors */ + if (fdc_cyl == 0x5A) { + probe_reg = 0x22; + if (fdc_cyl == 0x22) { + /* It's a floppy */ + if (fdc_stat & 0x0F) + *p = DISK_TYPE_FDC_D; /* Dream disc */ + else + *p = DISK_TYPE_FDC; + return; + } + } + /* Double check */ + probe_reg = 0x22; + if (probe_reg != 0x22) + return; + *p = DISK_TYPE_HDC; +} + +static const char dcstr[] = "Disk controller %d: %s\n"; +static const char *diskname[4] = { NULL, "2793", "DreamDisc", "WD1010" }; + +void diskprobe(void) +{ + portswitch = 0; + do_diskprobe(disk_type); + portswitch = 1; + do_diskprobe(disk_type + 1); + /* Hard case: two of the same */ + if (disk_type[0] == disk_type[1]) { + /* No disk at all - we don't care if port 58 works */ + if (!disk_type[0]) + return; + /* We might have internal and external the same ? */ + probe_reg = 0x5C; + portswitch = 0; + probe_reg = 0x00; + portswitch = 1; + if (probe_reg != 0x5C) + disk_type[1] = 0; + } + kprintf(dcstr, 0, diskname[disk_type[0]]); + if (disk_type[1]) + kprintf(dcstr, 1, diskname[disk_type[1]]); +} + + /* The bank bits are not laid out nicely for historical reasons A classic uBee has the bank selection in bits 0/1 -- 2.34.1