From: Ben Pfaff Date: Wed, 13 Jul 2005 17:40:23 +0000 (+0000) Subject: Fix bug reported by Mike Brown , in which a X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=commitdiff_plain;h=00562fc78061b83b6fff5231d5581ad55497265a Fix bug reported by Mike Brown , in which a secondary device was always detected on an IDE channel that had a primary device. Both qemu and Bochs report error/lbam/lbah register values that are invalid for a device that exists in such a situation, but GSX Server reports 1/0/0, which indicates a valid device. Fortunately, GSX Server does report a useful value in the status register, so the bug fix adds a check for that value also. --- diff --git a/src/devices/disk.c b/src/devices/disk.c index 0a13174..2bae057 100644 --- a/src/devices/disk.c +++ b/src/devices/disk.c @@ -30,6 +30,7 @@ /* Alternate Status Register bits. */ #define STA_BSY 0x80 /* Busy. */ +#define STA_DRDY 0x40 /* Device Ready. */ #define STA_DRQ 0x08 /* Data Request. */ /* Control Register bits. */ @@ -331,15 +332,18 @@ static bool check_device_type (struct disk *d) { struct channel *c = d->channel; - uint8_t error, lbam, lbah; + uint8_t error, lbam, lbah, status; select_device (d); error = inb (reg_error (c)); lbam = inb (reg_lbam (c)); lbah = inb (reg_lbah (c)); + status = inb (reg_status (c)); - if (error != 1 && (error != 0x81 || d->dev_no == 1)) + if ((error != 1 && (error != 0x81 || d->dev_no == 1)) + || (status & STA_DRDY) == 0 + || (status & STA_BSY) != 0) { d->is_ata = false; return error != 0x81;