Module Name: src Committed By: christos Date: Mon Oct 28 21:11:23 UTC 2019
Modified Files: src/sys/arch/vax/boot/boot: mfm.c Log Message: Rewrite the floppy selection logic, and fix an always false condition. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sys/arch/vax/boot/boot/mfm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/vax/boot/boot/mfm.c diff -u src/sys/arch/vax/boot/boot/mfm.c:1.15 src/sys/arch/vax/boot/boot/mfm.c:1.16 --- src/sys/arch/vax/boot/boot/mfm.c:1.15 Mon May 22 12:59:32 2017 +++ src/sys/arch/vax/boot/boot/mfm.c Mon Oct 28 17:11:23 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: mfm.c,v 1.15 2017/05/22 16:59:32 ragge Exp $ */ +/* $NetBSD: mfm.c,v 1.16 2019/10/28 21:11:23 christos Exp $ */ /* * Copyright (c) 1996 Ludd, University of Lule}, Sweden. * All rights reserved. @@ -139,6 +139,15 @@ mfm_rxprepare(void) return error; } +static int +mfm_is_ready(int cnt, int error) +{ + if (error == 0 && (sreg.udc_dstat & UDC_DS_READY) == UDC_DS_READY) + return 1; + printf("diskette not ready(%d): %#x/%#x\n", cnt, error, sreg.udc_dstat); + return 0; +} + int mfm_rxselect(int unit) { @@ -165,42 +174,40 @@ mfm_rxselect(int unit) */ error = mfm_command(DKC_CMD_DRSEL_RX33 | unit); - if ((error != 0) || ((sreg.udc_dstat & UDC_DS_READY) == 0)) { - printf("\nfloppy-drive not ready (new floppy inserted?)\n\n"); + if (mfm_is_ready(0, error)) + return 0; - creg.udc_rtcnt &= ~UDC_RC_INVRDY; /* clear INVRDY-flag */ - error = mfm_command(DKC_CMD_DRSEL_RX33 | unit); - if ((error != 0) || ((sreg.udc_dstat & UDC_DS_READY) == 0)) { - printf("diskette not ready(1): %x/%x\n", - error, sreg.udc_dstat); - printf("floppy-drive offline?\n"); - return (-1); - } - if (sreg.udc_dstat & UDC_DS_TRK00) - error = mfm_command(DKC_CMD_STEPIN_FDD); - else - error = mfm_command(DKC_CMD_STEPOUT_FDD); + printf("\nfloppy-drive not ready (new floppy inserted?)\n\n"); - /* - * now ready should be 0, cause INVRDY is not set - * (retrying a command makes this fail...) - */ - if ((error != 0) || ((sreg.udc_dstat & UDC_DS_READY) == 1)) { - printf("diskette not ready(2): %x/%x\n", - error, sreg.udc_dstat); - } - creg.udc_rtcnt |= UDC_RC_INVRDY; - error = mfm_command(DKC_CMD_DRSEL_RX33 | unit); + /* clear INVRDY-flag and try again */ + creg.udc_rtcnt &= ~UDC_RC_INVRDY; + error = mfm_command(DKC_CMD_DRSEL_RX33 | unit); - if ((error != 0) || ((sreg.udc_dstat & UDC_DS_READY) == 0)) { - printf("diskette not ready(3): %x/%x\n", - error, sreg.udc_dstat); - printf("no floppy inserted or floppy-door open\n"); - return (-1); - } - printf("floppy-drive reselected.\n"); + if (!mfm_is_ready(1, error)) { + printf("floppy-drive offline?\n"); + return -1; + } - return (error); + if (sreg.udc_dstat & UDC_DS_TRK00) + error = mfm_command(DKC_CMD_STEPIN_FDD); + else + error = mfm_command(DKC_CMD_STEPOUT_FDD); + + /* + * now ready should be 0, cause INVRDY is not set + * (retrying a command makes this fail...) + */ + mfm_is_ready(2, error); + + creg.udc_rtcnt |= UDC_RC_INVRDY; + error = mfm_command(DKC_CMD_DRSEL_RX33 | unit); + if (!mfm_is_ready(3, error)) { + printf("no floppy inserted or floppy-door open\n"); + return -1; + } + + printf("floppy-drive reselected.\n"); + return error; } int