read the disk using interrupts
This commit is contained in:
parent
7837c71b32
commit
72ea69fbdf
4
defs.h
4
defs.h
|
@ -70,6 +70,8 @@ int fd_read(struct fd *fd, char *addr, int n);
|
||||||
int fd_write(struct fd *fd, char *addr, int n);
|
int fd_write(struct fd *fd, char *addr, int n);
|
||||||
|
|
||||||
// ide.c
|
// ide.c
|
||||||
|
extern int disk_channel;
|
||||||
void ide_init(void);
|
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);
|
int ide_read(uint32_t secno, void *dst, unsigned nsecs);
|
||||||
|
|
19
ide.c
19
ide.c
|
@ -17,6 +17,7 @@
|
||||||
#define IDE_ERR 0x01
|
#define IDE_ERR 0x01
|
||||||
|
|
||||||
static int diskno = 0;
|
static int diskno = 0;
|
||||||
|
int disk_channel;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ide_wait_ready(int check_error)
|
ide_wait_ready(int check_error)
|
||||||
|
@ -43,6 +44,7 @@ void
|
||||||
ide_intr(void)
|
ide_intr(void)
|
||||||
{
|
{
|
||||||
cprintf("ide_intr\n");
|
cprintf("ide_intr\n");
|
||||||
|
wakeup(&disk_channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,12 +80,10 @@ ide_set_disk(int d)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
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)
|
if(nsecs > 256)
|
||||||
panic("ide_read");
|
panic("ide_start_read: nsecs too large");
|
||||||
|
|
||||||
ide_wait_ready(0);
|
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(0x1F6, 0xE0 | ((diskno&1)<<4) | ((secno>>24)&0x0F));
|
||||||
outb(0x1F7, 0x20); // CMD 0x20 means read sector
|
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) {
|
for (; nsecs > 0; nsecs--, dst += 512) {
|
||||||
if ((r = ide_wait_ready(1)) < 0)
|
if ((r = ide_wait_ready(1)) < 0)
|
||||||
return r;
|
return r;
|
||||||
insl(0x1F0, dst, 512/4);
|
insl(0x1F0, dst, 512/4);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
main.c
8
main.c
|
@ -60,12 +60,14 @@ main()
|
||||||
p->ppid = 0;
|
p->ppid = 0;
|
||||||
setupsegs(p);
|
setupsegs(p);
|
||||||
|
|
||||||
// become interruptable
|
|
||||||
write_eflags(read_eflags() | FL_IF);
|
|
||||||
|
|
||||||
// turn on timer and enable interrupts on the local APIC
|
// turn on timer and enable interrupts on the local APIC
|
||||||
lapic_timerinit();
|
lapic_timerinit();
|
||||||
lapic_enableintr();
|
lapic_enableintr();
|
||||||
|
// init disk device
|
||||||
|
ide_init();
|
||||||
|
|
||||||
|
// become interruptable
|
||||||
|
write_eflags(read_eflags() | FL_IF);
|
||||||
|
|
||||||
p = newproc();
|
p = newproc();
|
||||||
// load_icode(p, _binary_usertests_start, (unsigned) _binary_usertests_size);
|
// load_icode(p, _binary_usertests_start, (unsigned) _binary_usertests_size);
|
||||||
|
|
22
syscall.c
22
syscall.c
|
@ -227,14 +227,24 @@ sys_cons_putc()
|
||||||
int
|
int
|
||||||
sys_block(void)
|
sys_block(void)
|
||||||
{
|
{
|
||||||
char buf[1];
|
char buf[512];
|
||||||
|
int i, j;
|
||||||
|
|
||||||
cprintf("%d: call sys_block\n", cpu());
|
cprintf("%d: call sys_block\n", cpu());
|
||||||
ide_init();
|
for (i = 0; i < 100; i++) {
|
||||||
ide_read(0, buf, 1);
|
if (ide_start_read(i, buf, 1)) {
|
||||||
// cprintf("sec0.0 %x\n", buf[0] & 0xff);
|
panic("couldn't start read\n");
|
||||||
cprintf ("call sleep\n");
|
}
|
||||||
sleep (0);
|
cprintf("call sleep\n");
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue