summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2011-07-29 07:31:27 -0400
committerFrans Kaashoek <[email protected]>2011-07-29 07:31:27 -0400
commit9aa0337dc1452a911ac52698c833246a618fc9f3 (patch)
tree28e25817d4f7c9f7f1e6988949012f46d6c28fb7 /main.c
parentdccb915282854476ce47752df6631dcce3b8f661 (diff)
downloadxv6-labs-9aa0337dc1452a911ac52698c833246a618fc9f3.tar.gz
xv6-labs-9aa0337dc1452a911ac52698c833246a618fc9f3.tar.bz2
xv6-labs-9aa0337dc1452a911ac52698c833246a618fc9f3.zip
Map kernel high
Very important to give qemu memory through PHYSTOP :(
Diffstat (limited to 'main.c')
-rw-r--r--main.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/main.c b/main.c
index a27c4ff..d596cec 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
#include "types.h"
#include "defs.h"
#include "param.h"
+#include "memlayout.h"
#include "mmu.h"
#include "proc.h"
#include "x86.h"
@@ -9,6 +10,8 @@ static void bootothers(void);
static void mpmain(void);
void jmpkstack(void) __attribute__((noreturn));
void mainc(void);
+static volatile int newpgdir;
+
// Bootstrap processor starts running C code here.
// Allocate a real stack and switch to it, first
@@ -16,6 +19,7 @@ void mainc(void);
int
main(void)
{
+ pginit(pgalloc);
mpinit(); // collect info about this machine
lapicinit(mpbcpu());
seginit(); // set up segments
@@ -46,7 +50,6 @@ mainc(void)
ioapicinit(); // another interrupt controller
consoleinit(); // I/O devices & their interrupts
uartinit(); // serial port
- kvmalloc(); // initialize the kernel page table
pinit(); // process table
tvinit(); // trap vectors
binit(); // buffer cache
@@ -57,7 +60,8 @@ mainc(void)
timerinit(); // uniprocessor timer
userinit(); // first user process
bootothers(); // start other processors
-
+ kvmalloc(); // new kernel page table wo. bottom mapped
+ newpgdir = 1;
// Finish setting up this processor in mpmain.
mpmain();
}
@@ -66,16 +70,25 @@ mainc(void)
// Bootstrap CPU comes here from mainc().
// Other CPUs jump here from bootother.S.
static void
-mpmain(void)
+mpboot(void)
{
- if(cpunum() != mpbcpu()){
- seginit();
- lapicinit(cpunum());
- }
vmenable(); // turn on paging
+ seginit();
+ lapicinit(cpunum());
+ mpmain();
+}
+
+// Common CPU setup code.
+// Bootstrap CPU comes here from mainc().
+// Other CPUs jump here from bootother.S.
+static void
+mpmain(void)
+{
cprintf("cpu%d: starting\n", cpu->id);
idtinit(); // load idt register
xchg(&cpu->booted, 1); // tell bootothers() we're up
+ while (!newpgdir) ; // wait until we have new page dir
+ switchkvm(); // switch to new page dir
scheduler(); // start running processes
}
@@ -91,7 +104,7 @@ bootothers(void)
// Write bootstrap code to unused memory at 0x7000.
// The linker has placed the image of bootother.S in
// _binary_bootother_start.
- code = (uchar*)0x7000;
+ code = p2v(0x7000);
memmove(code, _binary_bootother_start, (uint)_binary_bootother_size);
for(c = cpus; c < cpus+ncpu; c++){
@@ -103,9 +116,9 @@ bootothers(void)
// its first instruction.
stack = kalloc();
*(void**)(code-4) = stack + KSTACKSIZE;
- *(void**)(code-8) = mpmain;
+ *(void**)(code-8) = mpboot;
- lapicstartap(c->id, (uint)code);
+ lapicstartap(c->id, v2p(code));
// Wait for cpu to finish mpmain()
while(c->booted == 0)