summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaashoek <kaashoek>2006-07-06 21:47:22 +0000
committerkaashoek <kaashoek>2006-07-06 21:47:22 +0000
commit7837c71b32fc716101a859302e0349061416bd6e (patch)
tree57ec72178b980a3cd794b2f93bd021e08004368f
parentb22d898297a2496ba4cfd31d445769fbebc0a46d (diff)
downloadxv6-labs-7837c71b32fc716101a859302e0349061416bd6e.tar.gz
xv6-labs-7837c71b32fc716101a859302e0349061416bd6e.tar.bz2
xv6-labs-7837c71b32fc716101a859302e0349061416bd6e.zip
disable all interrupts when acquiring lock
user program that makes a blocking system call
-rw-r--r--Makefile9
-rw-r--r--defs.h1
-rw-r--r--ide.c13
-rw-r--r--main.c13
-rw-r--r--spinlock.c5
-rw-r--r--syscall.c17
-rw-r--r--syscall.h1
-rw-r--r--trap.c4
-rw-r--r--ulib.c8
-rw-r--r--x86.h1
10 files changed, 58 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index f82d260..9221ded 100644
--- a/Makefile
+++ b/Makefile
@@ -20,12 +20,12 @@ bootblock : bootasm.S bootmain.c
$(OBJCOPY) -S -O binary bootblock.o bootblock
./sign.pl bootblock
-kernel : $(OBJS) bootother.S user1 usertests
+kernel : $(OBJS) bootother.S user1 usertests userfs
$(CC) -nostdinc -I. -c bootother.S
$(LD) -N -e start -Ttext 0x7000 -o bootother.out bootother.o
$(OBJCOPY) -S -O binary bootother.out bootother
$(OBJDUMP) -S bootother.o > bootother.asm
- $(LD) -Ttext 0x100000 -e main -o kernel $(OBJS) -b binary bootother user1 usertests
+ $(LD) -Ttext 0x100000 -e main -o kernel $(OBJS) -b binary bootother user1 usertests userfs
$(OBJDUMP) -S kernel > kernel.asm
vectors.S : vectors.pl
@@ -41,6 +41,11 @@ usertests : usertests.c ulib.o
$(LD) -N -e main -Ttext 0 -o usertests usertests.o ulib.o
$(OBJDUMP) -S usertests > usertests.asm
+userfs : userfs.c ulib.o
+ $(CC) -nostdinc -I. -c userfs.c
+ $(LD) -N -e main -Ttext 0 -o userfs userfs.o ulib.o
+ $(OBJDUMP) -S userfs > userfs.asm
+
ulib.o : ulib.c
$(CC) -nostdinc -I. -c ulib.c
diff --git a/defs.h b/defs.h
index d1025a6..a6f28e4 100644
--- a/defs.h
+++ b/defs.h
@@ -71,4 +71,5 @@ int fd_write(struct fd *fd, char *addr, int n);
// ide.c
void ide_init(void);
+void ide_intri(void);
int ide_read(uint32_t secno, void *dst, unsigned nsecs);
diff --git a/ide.c b/ide.c
index 0e63a86..e870628 100644
--- a/ide.c
+++ b/ide.c
@@ -39,6 +39,13 @@ ide_init(void)
ide_wait_ready(0);
}
+void
+ide_intr(void)
+{
+ cprintf("ide_intr\n");
+}
+
+
int
ide_probe_disk1(void)
@@ -87,13 +94,15 @@ ide_read(uint32_t secno, void *dst, unsigned nsecs)
outb(0x1F5, (secno >> 16) & 0xFF);
outb(0x1F6, 0xE0 | ((diskno&1)<<4) | ((secno>>24)&0x0F));
outb(0x1F7, 0x20); // CMD 0x20 means read sector
-
+
+#if 0
for (; nsecs > 0; nsecs--, dst += 512) {
if ((r = ide_wait_ready(1)) < 0)
return r;
insl(0x1F0, dst, 512/4);
}
-
+#endif
+
return 0;
}
diff --git a/main.c b/main.c
index 296d00f..a075def 100644
--- a/main.c
+++ b/main.c
@@ -13,6 +13,7 @@ extern char edata[], end[];
extern int acpu;
extern char _binary_user1_start[], _binary_user1_size[];
extern char _binary_usertests_start[], _binary_usertests_size[];
+extern char _binary_userfs_start[], _binary_userfs_size[];
char buf[512];
@@ -59,20 +60,16 @@ main()
p->ppid = 0;
setupsegs(p);
+ // become interruptable
write_eflags(read_eflags() | FL_IF);
- // turn on interrupts on boot processor
+ // turn on timer and enable interrupts on the local APIC
lapic_timerinit();
lapic_enableintr();
-#if 0
- ide_init();
- ide_read(0, buf, 1);
- cprintf("sec0.0 %x\n", buf[0] & 0xff);
-#endif
-
p = newproc();
- load_icode(p, _binary_usertests_start, (unsigned) _binary_usertests_size);
+ // load_icode(p, _binary_usertests_start, (unsigned) _binary_usertests_size);
+ load_icode(p, _binary_userfs_start, (unsigned) _binary_userfs_size);
swtch();
diff --git a/spinlock.c b/spinlock.c
index 5cbe062..2d64044 100644
--- a/spinlock.c
+++ b/spinlock.c
@@ -1,6 +1,7 @@
#include "types.h"
#include "defs.h"
#include "x86.h"
+#include "mmu.h"
#define LOCK_FREE -1
@@ -15,7 +16,7 @@ acquire_spinlock(uint32_t* lock)
if (*lock == cpu_id)
return;
- lapic_disableintr();
+ write_eflags(read_eflags() & ~FL_IF);
while ( cmpxchg(LOCK_FREE, cpu_id, lock) != cpu_id ) { ; }
// cprintf ("acquired: %d\n", cpu_id);
}
@@ -28,7 +29,7 @@ release_spinlock(uint32_t* lock)
if (*lock != cpu_id)
panic("release_spinlock: releasing a lock that i don't own\n");
*lock = LOCK_FREE;
- lapic_enableintr();
+ write_eflags(read_eflags() | FL_IF);
}
void
diff --git a/syscall.c b/syscall.c
index 6343531..464d665 100644
--- a/syscall.c
+++ b/syscall.c
@@ -224,6 +224,20 @@ sys_cons_putc()
return 0;
}
+int
+sys_block(void)
+{
+ char buf[1];
+
+ cprintf("%d: call sys_block\n", cpu());
+ ide_init();
+ ide_read(0, buf, 1);
+ // cprintf("sec0.0 %x\n", buf[0] & 0xff);
+ cprintf ("call sleep\n");
+ sleep (0);
+ return 0;
+}
+
void
syscall()
{
@@ -257,6 +271,9 @@ syscall()
case SYS_close:
ret = sys_close();
break;
+ case SYS_block:
+ ret = sys_block();
+ break;
default:
cprintf("unknown sys call %d\n", num);
// XXX fault
diff --git a/syscall.h b/syscall.h
index 764b46f..0378c53 100644
--- a/syscall.h
+++ b/syscall.h
@@ -6,3 +6,4 @@
#define SYS_write 6
#define SYS_read 7
#define SYS_close 8
+#define SYS_block 9
diff --git a/trap.c b/trap.c
index 0459583..6b490b1 100644
--- a/trap.c
+++ b/trap.c
@@ -60,6 +60,10 @@ trap(struct Trapframe *tf)
lapic_timerintr();
return;
}
+ if(v == (IRQ_OFFSET + IRQ_IDE)){
+ ide_intr();
+ return;
+ }
// XXX probably ought to lgdt on trap return
diff --git a/ulib.c b/ulib.c
index d99acdd..5061732 100644
--- a/ulib.c
+++ b/ulib.c
@@ -56,3 +56,11 @@ close(int fd)
asm("mov $8, %eax");
asm("int $48");
}
+
+int
+block(void)
+{
+ asm("mov $9, %eax");
+ asm("int $48");
+}
+
diff --git a/x86.h b/x86.h
index 0063826..451f789 100644
--- a/x86.h
+++ b/x86.h
@@ -354,5 +354,6 @@ struct Trapframe {
#define IRQ_OFFSET 32 // IRQ 0 corresponds to int IRQ_OFFSET
+#define IRQ_IDE 14
#define IRQ_ERROR 19
#define IRQ_SPURIOUS 31