projects
/
pintos-anon
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reboot when Ctrl+Alt+Del is pressed.
[pintos-anon]
/
src
/
devices
/
disk.c
diff --git
a/src/devices/disk.c
b/src/devices/disk.c
index 206f69c91feceed3f6a5eef2776f1c8e34a8521b..14fc63158be840c550d7eb7a9d42d6ecb23b0c77 100644
(file)
--- a/
src/devices/disk.c
+++ b/
src/devices/disk.c
@@
-30,6
+30,7
@@
/* Alternate Status Register bits. */
#define STA_BSY 0x80 /* Busy. */
/* Alternate Status Register bits. */
#define STA_BSY 0x80 /* Busy. */
+#define STA_DRDY 0x40 /* Device Ready. */
#define STA_DRQ 0x08 /* Data Request. */
/* Control Register bits. */
#define STA_DRQ 0x08 /* Data Request. */
/* Control Register bits. */
@@
-123,9
+124,9
@@
disk_init (void)
default:
NOT_REACHED ();
}
default:
NOT_REACHED ();
}
- lock_init (&c->lock
, c->name
);
+ lock_init (&c->lock);
c->expecting_interrupt = false;
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++)
/* Initialize devices. */
for (dev_no = 0; dev_no < 2; dev_no++)
@@
-142,7
+143,7
@@
disk_init (void)
}
/* Register interrupt handler. */
}
/* 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);
/* Reset hardware. */
reset_channel (c);
@@
-179,7
+180,14
@@
disk_print_stats (void)
}
/* Returns the disk numbered DEV_NO--either 0 or 1 for master or
}
/* Returns the disk numbered DEV_NO--either 0 or 1 for master or
- slave, respectively--within the channel numbered CHAN_NO. */
+ slave, respectively--within the channel numbered CHAN_NO.
+
+ Pintos uses disks this way:
+ 0:0 - boot loader, command line args, and operating system kernel
+ 0:1 - file system
+ 1:0 - scratch
+ 1:1 - swap
+*/
struct disk *
disk_get (int chan_no, int dev_no)
{
struct disk *
disk_get (int chan_no, int dev_no)
{
@@
-205,7
+213,9
@@
disk_size (struct disk *d)
}
/* Reads sector SEC_NO from disk D into BUFFER, which must have
}
/* Reads sector SEC_NO from disk D into BUFFER, which must have
- room for DISK_SECTOR_SIZE bytes. */
+ room for DISK_SECTOR_SIZE bytes.
+ Internally synchronizes accesses to disks, so external
+ per-disk locking is unneeded. */
void
disk_read (struct disk *d, disk_sector_t sec_no, void *buffer)
{
void
disk_read (struct disk *d, disk_sector_t sec_no, void *buffer)
{
@@
-228,7
+238,9
@@
disk_read (struct disk *d, disk_sector_t sec_no, void *buffer)
/* Write sector SEC_NO to disk D from BUFFER, which must contain
DISK_SECTOR_SIZE bytes. Returns after the disk has
/* Write sector SEC_NO to disk D from BUFFER, which must contain
DISK_SECTOR_SIZE bytes. Returns after the disk has
- acknowledged receiving the data. */
+ acknowledged receiving the data.
+ Internally synchronizes accesses to disks, so external
+ per-disk locking is unneeded. */
void
disk_write (struct disk *d, disk_sector_t sec_no, const void *buffer)
{
void
disk_write (struct disk *d, disk_sector_t sec_no, const void *buffer)
{
@@
-285,12
+297,12
@@
reset_channel (struct channel *c)
/* Issue soft reset sequence, which selects device 0 as a side effect.
Also enable interrupts. */
outb (reg_ctl (c), 0);
/* Issue soft reset sequence, which selects device 0 as a side effect.
Also enable interrupts. */
outb (reg_ctl (c), 0);
- timer_
sleep (timer_us2ticks (10)
);
+ timer_
usleep (10
);
outb (reg_ctl (c), CTL_SRST);
outb (reg_ctl (c), CTL_SRST);
- timer_
sleep (timer_us2ticks (10)
);
+ timer_
usleep (10
);
outb (reg_ctl (c), 0);
outb (reg_ctl (c), 0);
- timer_
sleep (timer_ms2ticks (150)
);
+ timer_
msleep (150
);
/* Wait for device 0 to clear BSY. */
if (present[0])
/* Wait for device 0 to clear BSY. */
if (present[0])
@@
-309,7
+321,7
@@
reset_channel (struct channel *c)
{
if (inb (reg_nsect (c)) == 1 && inb (reg_lbal (c)) == 1)
break;
{
if (inb (reg_nsect (c)) == 1 && inb (reg_lbal (c)) == 1)
break;
- timer_
sleep (timer_ms2ticks (10)
);
+ timer_
msleep (10
);
}
wait_while_busy (&c->devices[1]);
}
}
wait_while_busy (&c->devices[1]);
}
@@
-324,15
+336,18
@@
static bool
check_device_type (struct disk *d)
{
struct channel *c = d->channel;
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));
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;
{
d->is_ata = false;
return error != 0x81;
@@
-475,7
+490,7
@@
wait_until_idle (const struct disk *d)
{
if ((inb (reg_status (d->channel)) & (STA_BSY | STA_DRQ)) == 0)
return;
{
if ((inb (reg_status (d->channel)) & (STA_BSY | STA_DRQ)) == 0)
return;
- timer_
sleep (timer_us2ticks (10)
);
+ timer_
usleep (10
);
}
printf ("%s: idle timeout\n", d->name);
}
printf ("%s: idle timeout\n", d->name);
@@
-501,7
+516,7
@@
wait_while_busy (const struct disk *d)
printf ("ok\n");
return (inb (reg_alt_status (c)) & STA_DRQ) != 0;
}
printf ("ok\n");
return (inb (reg_alt_status (c)) & STA_DRQ) != 0;
}
- timer_
sleep (timer_ms2ticks (10)
);
+ timer_
msleep (10
);
}
printf ("failed\n");
}
printf ("failed\n");
@@
-518,7
+533,7
@@
select_device (const struct disk *d)
dev |= DEV_DEV;
outb (reg_device (c), dev);
inb (reg_alt_status (c));
dev |= DEV_DEV;
outb (reg_device (c), dev);
inb (reg_alt_status (c));
- timer_
sleep (timer_ns2ticks (400)
);
+ timer_
nsleep (400
);
}
/* Select disk D in its channel, as select_device(), but wait for
}
/* Select disk D in its channel, as select_device(), but wait for