summaryrefslogtreecommitdiff
path: root/sys/kern/mm
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern/mm')
-rw-r--r--sys/kern/mm/kalloc.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/sys/kern/mm/kalloc.c b/sys/kern/mm/kalloc.c
index b17d432..f354648 100644
--- a/sys/kern/mm/kalloc.c
+++ b/sys/kern/mm/kalloc.c
@@ -1,7 +1,11 @@
#include <stddef.h>
+#include <stdint.h>
#include <string.h>
+#include <printf.h>
#include <mm/kalloc.h>
+extern uint64_t HEAP_START;
+
typedef struct freenode {
struct freenode *next;
} freenode_t;
@@ -31,10 +35,34 @@ kzalloc(void)
void
kfree(void *p)
{
- if (p == NULL || (unsigned long)p % PAGE_SIZE)
+ if (p == NULL)
return;
freenode_t *tmp = head;
head = p;
head->next = tmp;
}
+
+void
+kalloc_init(void)
+{
+ printf("1\n");
+ freenode_t *p = (freenode_t*)HEAP_START;
+ for (;(unsigned long)p + PAGE_SIZE <= (HEAP_START + 0x100000); p += PAGE_SIZE) {
+ printf("freeing page at %p", p);
+ kfree(p);
+ }
+}
+
+void
+walkfree(void)
+{
+ freenode_t *node = head;
+ int nfree = 0;
+ while (node) {
+ printf("freenode at %p\n", node);
+ node = node->next;
+ nfree++;
+ }
+ printf("found and printed %d free pages!\n", nfree);
+}