kern
diff 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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/mem.c Sat Mar 26 21:39:14 2011 +0200 1.3 @@ -0,0 +1,40 @@ 1.4 +#include <stdio.h> 1.5 +#include "mem.h" 1.6 +#include "panic.h" 1.7 +#include "vm.h" 1.8 + 1.9 +/* end of kernel image */ 1.10 +extern int _end; 1.11 + 1.12 +static uint32_t brk; 1.13 + 1.14 +void init_mem(struct mboot_info *mb) 1.15 +{ 1.16 + /* start the physical allocated break at the end of 1.17 + * the kernel image 1.18 + */ 1.19 + brk = (uint32_t)&_end; 1.20 +} 1.21 + 1.22 +uint32_t alloc_phys_page(void) 1.23 +{ 1.24 + uint32_t addr, dbg_prev_brk; 1.25 + 1.26 + if(ADDR_TO_PGOFFS(brk)) { 1.27 + /* brk is not aligned, find the next page-aligned address */ 1.28 + addr = (brk + PGSIZE) & ~PGOFFS_MASK; 1.29 + } else { 1.30 + /* brk is aligned, so we can use that address directly */ 1.31 + addr = brk; 1.32 + } 1.33 + 1.34 + if(addr >= MAX_BRK) { 1.35 + panic("alloc_phys_page() out of early alloc space"); 1.36 + } 1.37 + 1.38 + dbg_prev_brk = brk; 1.39 + brk = addr + PGSIZE; /* move the break to the end of the page */ 1.40 + 1.41 + printf("DBG: alloc_phys_page(): %x (brk %x -> %x)\n", addr, dbg_prev_brk, brk); 1.42 + return addr; 1.43 +}