Mercurial > lcfOS
comparison cos/kernel/malloc.c @ 26:dcce92b1efbc
Added mm.c
author | windel |
---|---|
date | Tue, 27 Dec 2011 17:36:52 +0100 |
parents | d3c4bf3720a3 |
children | 47b7df514243 |
comparison
equal
deleted
inserted
replaced
25:d3c4bf3720a3 | 26:dcce92b1efbc |
---|---|
20 static heap_t* kernel_heap = (heap_t*) 0x400000; // 4 MB - 6 MB is heap | 20 static heap_t* kernel_heap = (heap_t*) 0x400000; // 4 MB - 6 MB is heap |
21 /* Allocates 'size' bytes and returns the pointer if succesfull. | 21 /* Allocates 'size' bytes and returns the pointer if succesfull. |
22 Kernelpanic in case of failure.. | 22 Kernelpanic in case of failure.. |
23 */ | 23 */ |
24 | 24 |
25 void* kmalloc(uint64_t size) { | 25 void* kmalloc(uint64_t size) |
26 // printf("Malloc %d bytes\n", size); | 26 { |
27 | |
28 // Start at the beginning of our heap and search a free block: | 27 // Start at the beginning of our heap and search a free block: |
29 heap_t *current = kernel_heap; | 28 heap_t *current = kernel_heap; |
30 while (current->magic == HEAP_MAGIC) | 29 while (current->magic == HEAP_MAGIC) |
31 { | 30 { |
32 if ((current->state == HEAP_FREE) && (current->size >= size)) | 31 if ((current->state == HEAP_FREE) && (current->size >= size)) |
61 current = (heap_t*)(((char*) current) + current->size + sizeof(heap_t)); | 60 current = (heap_t*)(((char*) current) + current->size + sizeof(heap_t)); |
62 } | 61 } |
63 return 0x0; | 62 return 0x0; |
64 } | 63 } |
65 | 64 |
66 void kfree(void* ptr) { | 65 void kfree(void* ptr) |
66 { | |
67 printf("Free address %x\n", ptr); | 67 printf("Free address %x\n", ptr); |
68 } | 68 } |
69 | 69 |
70 void init_heap(void) | 70 void init_heap(void) |
71 { | 71 { |