xv6的main.c源代码

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值