]> Devi Nivas Git - cs3210-lab1.git/commitdiff
disable all interrupts when acquiring lock
authorkaashoek <kaashoek>
Thu, 6 Jul 2006 21:47:22 +0000 (21:47 +0000)
committerkaashoek <kaashoek>
Thu, 6 Jul 2006 21:47:22 +0000 (21:47 +0000)
user program that makes a blocking system call

Makefile
defs.h
ide.c
main.c
spinlock.c
syscall.c
syscall.h
trap.c
ulib.c
x86.h

index f82d260d731de34ad35dcf2d4c097a858c3838f3..9221deddff4ff4291946016e20825e1bf0e566d3 100644 (file)
--- 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 d1025a60ebcaf0e933bb54b34e91ebc656dc13d4..a6f28e4cc282cd5dce934df53812bde17be9beee 100644 (file)
--- 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 0e63a865b1b76cf66e64e1fffba6ad229b5292f2..e8706283fa9c8217ea4d89bc308b658e962f543c 100644 (file)
--- 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 296d00f5012847396ff584411227b9ed7037dd0d..a075defc6f112d6da1ef6f9b2f18ad8c98e3163c 100644 (file)
--- 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();
 
index 5cbe0626841370029418a723338d4fb7d6b82753..2d64044d00d9b973319df0b2f5a905f298bee887 100644 (file)
@@ -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
index 63435311913ae56f271fa8eccd029f0cf765c9c2..464d665d704e007f633f930b0ba35c68fcd2ea2e 100644 (file)
--- 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
index 764b46f74316fe9ee8e299a63ea73437f37b9b4c..0378c53f75105b113ab894ad1ebac9303f54eeb8 100644 (file)
--- 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 045958315d43ed0c349ba4621702aa615d32f457..6b490b1b473fdbe28804d8148da0c2586cc85f56 100644 (file)
--- 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 d99acdd62c3b24b332f6178e200aed00a029eb00..50617328df6ebc1d763d41f73e36c0efabdfbeb5 100644 (file)
--- 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 00638265e68e839073b13d51aa27487596ca2786..451f789db0f6d0bcc91969e14d8bcadda541b159 100644 (file)
--- 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