1
0

kmalloc: initial implementation

This commit is contained in:
2012-09-28 00:59:25 -04:00
parent d7292f1fe2
commit ccbee1d142
3 changed files with 226 additions and 1 deletions

View File

@ -19,6 +19,7 @@
*/
#include <atags.h>
#include <kmalloc.h>
#include <mmu.h>
#include <mm.h>
#include <print.h>
@ -41,8 +42,11 @@ void video(void) {
console_init(&myfb);
}
void test_memory() {
void test_mm() {
struct page *p, *q;
print("\ntest_mm():\n");
p = mm_get_free_pages(0);
if (p)
print("%x, %x\n", p, p->address);
@ -69,8 +73,46 @@ void test_memory() {
print("%x, %x\n", p, p->address);
else
print("Error: failed to allocate memory for p\n");
mm_put_free_pages(p);
mm_put_free_pages(q);
}
void test_kmalloc() {
void *a, *b, *c, *d;
print("\ntest_kmalloc():\n");
a = kmalloc(4);
print("a: %x\n", a);
b = kmalloc(13);
print("b: %x\n", b);
c = kmalloc(4);
print("c: %x\n", c);
d = kmalloc(25);
print("d: %x\n", d);
kfree(c);
kfree(b);
kfree(a);
kfree(d);
a = kmalloc(13);
print("a: %x\n", a);
b = kmalloc(4);
print("b: %x\n", b);
c = kmalloc(25);
print("c: %x\n", c);
d = kmalloc(7);
print("d: %x\n", d);
}
void test_memory() {
test_mm();
test_kmalloc();
}
void kmalloc_init();
int main(void) {
char *lower, *upper;
@ -84,6 +126,7 @@ int main(void) {
//setup memory
mm_init();
kmalloc_init();
if (atags_first_mem_region(&atags)) {
print("Error: atags must contain at least one memory region\n");