read the disk using interrupts

This commit is contained in:
kaashoek 2006-07-10 13:08:37 +00:00
parent 7837c71b32
commit 72ea69fbdf
4 changed files with 36 additions and 17 deletions

4
defs.h
View file

@ -70,6 +70,8 @@ int fd_read(struct fd *fd, char *addr, int n);
int fd_write(struct fd *fd, char *addr, int n);
// ide.c
extern int disk_channel;
void ide_init(void);
void ide_intri(void);
void ide_intr(void);
int ide_start_read(uint32_t secno, void *dst, unsigned nsecs);
int ide_read(uint32_t secno, void *dst, unsigned nsecs);

19
ide.c
View file

@ -17,6 +17,7 @@
#define IDE_ERR 0x01
static int diskno = 0;
int disk_channel;
static int
ide_wait_ready(int check_error)
@ -43,6 +44,7 @@ void
ide_intr(void)
{
cprintf("ide_intr\n");
wakeup(&disk_channel);
}
@ -78,12 +80,10 @@ ide_set_disk(int d)
}
int
ide_read(uint32_t secno, void *dst, unsigned nsecs)
ide_start_read(uint32_t secno, void *dst, unsigned nsecs)
{
int r;
if(nsecs > 256)
panic("ide_read");
panic("ide_start_read: nsecs too large");
ide_wait_ready(0);
@ -95,14 +95,19 @@ ide_read(uint32_t secno, void *dst, unsigned nsecs)
outb(0x1F6, 0xE0 | ((diskno&1)<<4) | ((secno>>24)&0x0F));
outb(0x1F7, 0x20); // CMD 0x20 means read sector
#if 0
return 0;
}
int
ide_read(uint32_t secno, void *dst, unsigned nsecs)
{
int r;
for (; nsecs > 0; nsecs--, dst += 512) {
if ((r = ide_wait_ready(1)) < 0)
return r;
insl(0x1F0, dst, 512/4);
}
#endif
return 0;
}

8
main.c
View file

@ -60,12 +60,14 @@ main()
p->ppid = 0;
setupsegs(p);
// become interruptable
write_eflags(read_eflags() | FL_IF);
// turn on timer and enable interrupts on the local APIC
lapic_timerinit();
lapic_enableintr();
// init disk device
ide_init();
// become interruptable
write_eflags(read_eflags() | FL_IF);
p = newproc();
// load_icode(p, _binary_usertests_start, (unsigned) _binary_usertests_size);

View file

@ -227,14 +227,24 @@ sys_cons_putc()
int
sys_block(void)
{
char buf[1];
char buf[512];
int i, j;
cprintf("%d: call sys_block\n", cpu());
ide_init();
ide_read(0, buf, 1);
// cprintf("sec0.0 %x\n", buf[0] & 0xff);
for (i = 0; i < 100; i++) {
if (ide_start_read(i, buf, 1)) {
panic("couldn't start read\n");
}
cprintf("call sleep\n");
sleep (0);
sleep (&disk_channel);
if (ide_read(i, buf, 1)) {
panic("couldn't do read\n");
}
cprintf("sector %d: ", i);
for (j = 0; j < 2; j++)
cprintf("%x ", buf[j] & 0xff);
cprintf("\n");
}
return 0;
}