kern
view 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 source
1 #include <stdio.h>
2 #include "mem.h"
3 #include "panic.h"
4 #include "vm.h"
6 /* end of kernel image */
7 extern int _end;
9 static uint32_t brk;
11 void init_mem(struct mboot_info *mb)
12 {
13 /* start the physical allocated break at the end of
14 * the kernel image
15 */
16 brk = (uint32_t)&_end;
17 }
19 uint32_t alloc_phys_page(void)
20 {
21 uint32_t addr, dbg_prev_brk;
23 if(ADDR_TO_PGOFFS(brk)) {
24 /* brk is not aligned, find the next page-aligned address */
25 addr = (brk + PGSIZE) & ~PGOFFS_MASK;
26 } else {
27 /* brk is aligned, so we can use that address directly */
28 addr = brk;
29 }
31 if(addr >= MAX_BRK) {
32 panic("alloc_phys_page() out of early alloc space");
33 }
35 dbg_prev_brk = brk;
36 brk = addr + PGSIZE; /* move the break to the end of the page */
38 printf("DBG: alloc_phys_page(): %x (brk %x -> %x)\n", addr, dbg_prev_brk, brk);
39 return addr;
40 }