disable all interrupts when acquiring lock

user program that makes a blocking system call
This commit is contained in:
kaashoek 2006-07-06 21:47:22 +00:00
parent b22d898297
commit 7837c71b32
10 changed files with 58 additions and 14 deletions

View file

@ -20,12 +20,12 @@ bootblock : bootasm.S bootmain.c
$(OBJCOPY) -S -O binary bootblock.o bootblock $(OBJCOPY) -S -O binary bootblock.o bootblock
./sign.pl bootblock ./sign.pl bootblock
kernel : $(OBJS) bootother.S user1 usertests kernel : $(OBJS) bootother.S user1 usertests userfs
$(CC) -nostdinc -I. -c bootother.S $(CC) -nostdinc -I. -c bootother.S
$(LD) -N -e start -Ttext 0x7000 -o bootother.out bootother.o $(LD) -N -e start -Ttext 0x7000 -o bootother.out bootother.o
$(OBJCOPY) -S -O binary bootother.out bootother $(OBJCOPY) -S -O binary bootother.out bootother
$(OBJDUMP) -S bootother.o > bootother.asm $(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 $(OBJDUMP) -S kernel > kernel.asm
vectors.S : vectors.pl 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 $(LD) -N -e main -Ttext 0 -o usertests usertests.o ulib.o
$(OBJDUMP) -S usertests > usertests.asm $(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 ulib.o : ulib.c
$(CC) -nostdinc -I. -c ulib.c $(CC) -nostdinc -I. -c ulib.c

1
defs.h
View file

@ -71,4 +71,5 @@ int fd_write(struct fd *fd, char *addr, int n);
// ide.c // ide.c
void ide_init(void); void ide_init(void);
void ide_intri(void);
int ide_read(uint32_t secno, void *dst, unsigned nsecs); int ide_read(uint32_t secno, void *dst, unsigned nsecs);

13
ide.c
View file

@ -39,6 +39,13 @@ ide_init(void)
ide_wait_ready(0); ide_wait_ready(0);
} }
void
ide_intr(void)
{
cprintf("ide_intr\n");
}
int int
ide_probe_disk1(void) ide_probe_disk1(void)
@ -87,13 +94,15 @@ ide_read(uint32_t secno, void *dst, unsigned nsecs)
outb(0x1F5, (secno >> 16) & 0xFF); outb(0x1F5, (secno >> 16) & 0xFF);
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
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;
} }

13
main.c
View file

@ -13,6 +13,7 @@ extern char edata[], end[];
extern int acpu; extern int acpu;
extern char _binary_user1_start[], _binary_user1_size[]; extern char _binary_user1_start[], _binary_user1_size[];
extern char _binary_usertests_start[], _binary_usertests_size[]; extern char _binary_usertests_start[], _binary_usertests_size[];
extern char _binary_userfs_start[], _binary_userfs_size[];
char buf[512]; char buf[512];
@ -59,20 +60,16 @@ main()
p->ppid = 0; p->ppid = 0;
setupsegs(p); setupsegs(p);
// become interruptable
write_eflags(read_eflags() | FL_IF); 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_timerinit();
lapic_enableintr(); lapic_enableintr();
#if 0
ide_init();
ide_read(0, buf, 1);
cprintf("sec0.0 %x\n", buf[0] & 0xff);
#endif
p = newproc(); 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(); swtch();

View file

@ -1,6 +1,7 @@
#include "types.h" #include "types.h"
#include "defs.h" #include "defs.h"
#include "x86.h" #include "x86.h"
#include "mmu.h"
#define LOCK_FREE -1 #define LOCK_FREE -1
@ -15,7 +16,7 @@ acquire_spinlock(uint32_t* lock)
if (*lock == cpu_id) if (*lock == cpu_id)
return; return;
lapic_disableintr(); write_eflags(read_eflags() & ~FL_IF);
while ( cmpxchg(LOCK_FREE, cpu_id, lock) != cpu_id ) { ; } while ( cmpxchg(LOCK_FREE, cpu_id, lock) != cpu_id ) { ; }
// cprintf ("acquired: %d\n", cpu_id); // cprintf ("acquired: %d\n", cpu_id);
} }
@ -28,7 +29,7 @@ release_spinlock(uint32_t* lock)
if (*lock != cpu_id) if (*lock != cpu_id)
panic("release_spinlock: releasing a lock that i don't own\n"); panic("release_spinlock: releasing a lock that i don't own\n");
*lock = LOCK_FREE; *lock = LOCK_FREE;
lapic_enableintr(); write_eflags(read_eflags() | FL_IF);
} }
void void

View file

@ -224,6 +224,20 @@ sys_cons_putc()
return 0; 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 void
syscall() syscall()
{ {
@ -257,6 +271,9 @@ syscall()
case SYS_close: case SYS_close:
ret = sys_close(); ret = sys_close();
break; break;
case SYS_block:
ret = sys_block();
break;
default: default:
cprintf("unknown sys call %d\n", num); cprintf("unknown sys call %d\n", num);
// XXX fault // XXX fault

View file

@ -6,3 +6,4 @@
#define SYS_write 6 #define SYS_write 6
#define SYS_read 7 #define SYS_read 7
#define SYS_close 8 #define SYS_close 8
#define SYS_block 9

4
trap.c
View file

@ -60,6 +60,10 @@ trap(struct Trapframe *tf)
lapic_timerintr(); lapic_timerintr();
return; return;
} }
if(v == (IRQ_OFFSET + IRQ_IDE)){
ide_intr();
return;
}
// XXX probably ought to lgdt on trap return // XXX probably ought to lgdt on trap return

8
ulib.c
View file

@ -56,3 +56,11 @@ close(int fd)
asm("mov $8, %eax"); asm("mov $8, %eax");
asm("int $48"); asm("int $48");
} }
int
block(void)
{
asm("mov $9, %eax");
asm("int $48");
}

1
x86.h
View file

@ -354,5 +354,6 @@ struct Trapframe {
#define IRQ_OFFSET 32 // IRQ 0 corresponds to int IRQ_OFFSET #define IRQ_OFFSET 32 // IRQ 0 corresponds to int IRQ_OFFSET
#define IRQ_IDE 14
#define IRQ_ERROR 19 #define IRQ_ERROR 19
#define IRQ_SPURIOUS 31 #define IRQ_SPURIOUS 31