Mercurial > lcfOS
view kernel/memory.c3 @ 410:6aa9743ed362 tip
Reflect change in c3 public modifier
author | Windel Bouwman |
---|---|
date | Mon, 23 Feb 2015 21:06:04 +0100 |
parents | ad6be5454067 |
children |
line wrap: on
line source
module memory; import arch; import io; const int pagesize = 4096; var int ptr; // Let the heap grow upwards.. public function void init() { ptr = 0x60080000; } public function byte* alloc(int size) { var int ptr2; ptr2 = ptr; io.print2("alloc size ", size); io.print2("alloc address ", ptr); // Increment new free point: ptr = ptr + size; return ptr2; } function bool is_marked(int page) { return true; } function void set_mark(int page, bool mark) { } function byte* allocate_physical() { var int i; for (i = 0; i < 100; i += 1) { if (not is_marked(i)) { return i * pagesize; } } return 0; } function byte* allocate_virtual(byte* address) { var byte* address2; address2 = allocate_physical(); return address2; } // Util function: public function void memcpy(byte* dst, byte* src, int size) { var int i; io.print2("memcpy to ", cast<int>(dst)); io.print2("memcpy from ", cast<int>(src)); io.print2("memcpy size ", size); for (i = 0; i < size; i += 1) { *(dst + i) = *(src + i); } }