Skip to content

Commit

Permalink
disable all interrupts when acquiring lock
Browse files Browse the repository at this point in the history
user program that makes a blocking system call
  • Loading branch information
kaashoek committed Jul 6, 2006
1 parent b22d898 commit 7837c71
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 14 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
13 changes: 11 additions & 2 deletions ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ ide_init(void)
ide_wait_ready(0);
}

void
ide_intr(void)
{
cprintf("ide_intr\n");
}



int
ide_probe_disk1(void)
Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 5 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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();

Expand Down
5 changes: 3 additions & 2 deletions spinlock.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "types.h"
#include "defs.h"
#include "x86.h"
#include "mmu.h"

#define LOCK_FREE -1

Expand All @@ -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);
}
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
#define SYS_write 6
#define SYS_read 7
#define SYS_close 8
#define SYS_block 9
4 changes: 4 additions & 0 deletions trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions ulib.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ close(int fd)
asm("mov $8, %eax");
asm("int $48");
}

int
block(void)
{
asm("mov $9, %eax");
asm("int $48");
}

1 change: 1 addition & 0 deletions x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7837c71

Please sign in to comment.