#include "types.h"
#include "defs.h"
#include "param.h"
#include "x86.h"
#include "mmu.h"
#include "proc.h"
#include "pmap.h"
static void mpmain(void) __attribute__ ((noreturn));
struct cpu theCpu;
extern int ticks;
void pgfault_test()
{
int *ptr = 0x80000000;
*(ptr + 1) = 0x12345678;
ptr++;
cprintf("PageFaultTest: Magic number is %x./n", *ptr);
}
// Bootstrap processor starts running C code here.
int main(void)
{
extern char edata[], end[];
int *p = (int *)(0x8004), *count = (int *)(0x8000), i;
// clear BSS
memset(edata, 0, end - edata);
cprintf("/nstarting xv6/n/n");
cprintf("main: edata = %x, end = %x, size= %x /n", edata, end, end - edata);
cprintf("/n(Base) cpu%d: starting!/n/n", cpu());
//print the number of memory ranges and the range details:(baseaddr, len)
cprintf("count = %d/n", *count);
for (i = 0; i < *count; i++, p += 5)
cprintf("mem baseaddr: high %x : low %x/nmem length: high %x : low %x/n",
*(p + 1), *p, *(p + 3), *(p + 2));
pic_init(); // interrupt controller init
pmm_init(); // physical memory manager init
vmm_init(); // virtual memory manager init
tvinit(); // trap vectors init
console_init(); // I/O(CRT or Parallel Port) devices & their interrupts init
timer_init(); // uniprocessor timer init
// Finish setting up this processor in mpmain.
mpmain();
}
static void mpmain(void)
{
cprintf("cpu%d: mpmain/n", cpu());
idtinit(); // load the interrupt descriptor table
xchg(&theCpu.booted, 1);
cprintf("cpu%d: can work now!/n", cpu());
sti();
#ifdef PGFAULT
pgfault_test();
#endif
dump_pg();
blackhole();
}
int cpu(void)
{
// Cannot call cpu when interrupts are enabled:
// result not guaranteed to last long enough to be used!
// Would prefer to panic but even printing is chancy here:
// everything, including cprintf, calls cpu, at least indirectly
// through acquire and release.
if (read_eflags() & FL_IF) {
static int n;
if (n++ == 0)
cprintf("cpu called from %x with interrupts enabled/n", ((uint *) read_ebp())[1]);
}
return 0;
}
xv6的main.c源代码
最新推荐文章于 2024-05-09 00:17:16 发布