summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorrtm <rtm>2006-08-08 19:58:06 +0000
committerrtm <rtm>2006-08-08 19:58:06 +0000
commit0e84a0ec6e7893dad13dff9a958c5bc987b79c82 (patch)
tree5739d0a2af8277db7a47c74e52975d9e9d81cef7 /main.c
parente8d11c2e846ad15b32caacc8a919722b76d00f79 (diff)
downloadxv6-labs-0e84a0ec6e7893dad13dff9a958c5bc987b79c82.tar.gz
xv6-labs-0e84a0ec6e7893dad13dff9a958c5bc987b79c82.tar.bz2
xv6-labs-0e84a0ec6e7893dad13dff9a958c5bc987b79c82.zip
fix race in holding() check in acquire()
give cpu1 a TSS and gdt for when it enters scheduler() and a pseudo proc[] entry for each cpu cpu0 waits for each other cpu to start up read() for files
Diffstat (limited to 'main.c')
-rw-r--r--main.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/main.c b/main.c
index 021fb51..c6e27a5 100644
--- a/main.c
+++ b/main.c
@@ -42,18 +42,24 @@ main0(void)
lapic_init(mp_bcpu());
- cprintf("\nxV6\n\n");
+ cprintf("\n\ncpu%d: booting xv6\n\n", cpu());
pic_init(); // initialize PIC
ioapic_init();
kinit(); // physical memory allocator
tvinit(); // trap vectors
- idtinit(); // CPU's idt
+ idtinit(); // this CPU's idt register
+
+ // create a fake process per CPU
+ // so each CPU always has a tss and a gdt
+ for(p = &proc[0]; p < &proc[NCPU]; p++){
+ p->state = IDLEPROC;
+ p->kstack = cpus[p-proc].mpstack;
+ p->pid = p - proc;
+ }
- // create fake process zero
+ // fix process 0 so that copyproc() will work
p = &proc[0];
- memset(p, 0, sizeof *p);
- p->state = SLEEPING;
p->sz = 4 * PAGE;
p->mem = kalloc(p->sz);
memset(p->mem, 0, p->sz);
@@ -63,20 +69,20 @@ main0(void)
p->tf->es = p->tf->ds = p->tf->ss = (SEG_UDATA << 3) | 3;
p->tf->cs = (SEG_UCODE << 3) | 3;
p->tf->eflags = FL_IF;
- p->pid = 0;
- p->ppid = 0;
setupsegs(p);
+ // init disk device
+ ide_init();
+
mp_startthem();
// turn on timer and enable interrupts on the local APIC
lapic_timerinit();
lapic_enableintr();
- // init disk device
- ide_init();
-
// Enable interrupts on this processor.
+ cprintf("cpu%d: nlock %d before -- and sti\n",
+ cpu(), cpus[0].nlock);
cpus[cpu()].nlock--;
sti();
@@ -94,7 +100,7 @@ main0(void)
void
mpmain(void)
{
- cprintf("an application processor\n");
+ cprintf("cpu%d: starting\n", cpu());
idtinit(); // CPU's idt
if(cpu() == 0)
panic("mpmain on cpu 0");
@@ -102,8 +108,13 @@ mpmain(void)
lapic_timerinit();
lapic_enableintr();
+ setupsegs(&proc[cpu()]);
+
+ cpuid(0, 0, 0, 0, 0); // memory barrier
+ cpus[cpu()].booted = 1;
+
// Enable interrupts on this processor.
- cprintf("cpu %d initial nlock %d\n", cpu(), cpus[cpu()].nlock);
+ cprintf("cpu%d: initial nlock %d\n", cpu(), cpus[cpu()].nlock);
cpus[cpu()].nlock--;
sti();