kern

annotate src/mem.c @ 17:098b1cb5eeaa

forgot to add a shitload of files
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 26 Mar 2011 21:39:14 +0200
parents
children 8be069e6bb05
rev   line source
nuclear@17 1 #include <stdio.h>
nuclear@17 2 #include "mem.h"
nuclear@17 3 #include "panic.h"
nuclear@17 4 #include "vm.h"
nuclear@17 5
nuclear@17 6 /* end of kernel image */
nuclear@17 7 extern int _end;
nuclear@17 8
nuclear@17 9 static uint32_t brk;
nuclear@17 10
nuclear@17 11 void init_mem(struct mboot_info *mb)
nuclear@17 12 {
nuclear@17 13 /* start the physical allocated break at the end of
nuclear@17 14 * the kernel image
nuclear@17 15 */
nuclear@17 16 brk = (uint32_t)&_end;
nuclear@17 17 }
nuclear@17 18
nuclear@17 19 uint32_t alloc_phys_page(void)
nuclear@17 20 {
nuclear@17 21 uint32_t addr, dbg_prev_brk;
nuclear@17 22
nuclear@17 23 if(ADDR_TO_PGOFFS(brk)) {
nuclear@17 24 /* brk is not aligned, find the next page-aligned address */
nuclear@17 25 addr = (brk + PGSIZE) & ~PGOFFS_MASK;
nuclear@17 26 } else {
nuclear@17 27 /* brk is aligned, so we can use that address directly */
nuclear@17 28 addr = brk;
nuclear@17 29 }
nuclear@17 30
nuclear@17 31 if(addr >= MAX_BRK) {
nuclear@17 32 panic("alloc_phys_page() out of early alloc space");
nuclear@17 33 }
nuclear@17 34
nuclear@17 35 dbg_prev_brk = brk;
nuclear@17 36 brk = addr + PGSIZE; /* move the break to the end of the page */
nuclear@17 37
nuclear@17 38 printf("DBG: alloc_phys_page(): %x (brk %x -> %x)\n", addr, dbg_prev_brk, brk);
nuclear@17 39 return addr;
nuclear@17 40 }