disable all interrupts when acquiring lock
user program that makes a blocking system call
This commit is contained in:
parent
b22d898297
commit
7837c71b32
9
Makefile
9
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
|
||||
|
||||
|
|
1
defs.h
1
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);
|
||||
|
|
9
ide.c
9
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)
|
||||
|
@ -88,11 +95,13 @@ ide_read(uint32_t secno, void *dst, unsigned nsecs)
|
|||
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;
|
||||
}
|
||||
|
|
13
main.c
13
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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
17
syscall.c
17
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
|
||||
|
|
|
@ -6,3 +6,4 @@
|
|||
#define SYS_write 6
|
||||
#define SYS_read 7
|
||||
#define SYS_close 8
|
||||
#define SYS_block 9
|
||||
|
|
4
trap.c
4
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
|
||||
|
|
8
ulib.c
8
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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue