X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdevices%2Fdisk.c;h=2bae0577ff044ec07657711cae1d7586338b9c49;hb=0a7ce50c8f6dd074fabe327cdad8502097816f3c;hp=1810fc4b1c474961d618a4002cb75ac4299d93a4;hpb=dbbabf1d84fcc6153963431a8977132c48a71cd9;p=pintos-anon diff --git a/src/devices/disk.c b/src/devices/disk.c index 1810fc4..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. */ @@ -123,9 +124,9 @@ disk_init (void) default: NOT_REACHED (); } - lock_init (&c->lock, c->name); + lock_init (&c->lock); c->expecting_interrupt = false; - sema_init (&c->completion_wait, 0, c->name); + sema_init (&c->completion_wait, 0); /* Initialize devices. */ for (dev_no = 0; dev_no < 2; dev_no++) @@ -142,7 +143,7 @@ disk_init (void) } /* Register interrupt handler. */ - intr_register (c->irq, 0, INTR_OFF, interrupt_handler, c->name); + intr_register_ext (c->irq, interrupt_handler, c->name); /* Reset hardware. */ reset_channel (c); @@ -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;