6.828: Operating System Engineering (26)
某所で内職というソレが聞こえてくる今日この頃、わしも集中して現実トウヒに走りたいのですが、なかなかそうもいかず困っております。
とりあえず IA-32 なマニュアルの下巻の 3 章確認かなぁ。
ちょっと pmap.c のコメント確認しつつ、何をしなければならないか、を整理する必要があるみたいですね。
とりあえづ
boot_alloc() 手続きから。コメント的には
// A simple physical memory allocator, used only a few times // in the process of setting up the virtual memory system. // page_alloc() is the real allocator.
とのこと。また、定義なナニを全部引用するのですが、
static void* boot_alloc(uint32_t n, uint32_t align) { extern char end[]; void *v; // Initialize boot_freemem if this is the first time. // 'end' is a magic symbol automatically generated by the linker, // which points to the end of the kernel's bss segment - // i.e., the first virtual address that the linker // did _not_ assign to any kernel code or global variables. if (boot_freemem == 0) boot_freemem = end; // LAB 2: Your code here: // Step 1: round boot_freemem up to be aligned properly // (hint: look in types.h for some handy macros) // Step 2: save current value of boot_freemem as allocated chunk // Step 3: increase boot_freemem to record allocation // Step 4: return allocated chunk return NULL; }
boot_freemem は以下な形で定義されてて
static char* boot_freemem; // Pointer to next byte of free mem
これは bss に配置されるので最初の値は 0 ですね。なので boot_alloc でカーネルの末端なアドレス (コメントによれば end of the kernel's bss segment) が設定されるものと思われます。_the first virtual address that the linker did _not_ assign to any kernel code or global variables._というのも成程なカンジ。
で、最初上記コメントを見てて意味分からんかったんですが、i386_vm_init() 手続きのナニを見るに
// create initial page directory. pgdir = boot_alloc(PGSIZE, PGSIZE); memset(pgdir, 0, PGSIZE); boot_pgdir = pgdir; boot_cr3 = PADDR(pgdir);
ええと、どうやって allocate するのかが分かれば (を
memset を見るに PGSIZE な空き領域が確保できれば良いのでしょうけど、allocated chunk にするにはどうすれば良いかが分からんw
とりあえず
寝ます。