Mercurial > lcfOS
comparison cos/kernel/malloc.c @ 28:47b7df514243
Moved Makefiles
author | windel |
---|---|
date | Wed, 28 Dec 2011 13:38:43 +0100 |
parents | dcce92b1efbc |
children | 7e3bdcb391dc |
comparison
equal
deleted
inserted
replaced
27:7f74363f4c82 | 28:47b7df514243 |
---|---|
1 #include "kernel.h" | 1 #include "kernel.h" |
2 | |
3 // ================= Placement malloc: | |
4 extern uint64_t end; | |
5 uint64_t placement_address = (uint64_t)&end; | |
6 | |
7 void* kmalloc_int(uint64_t size) | |
8 { | |
9 uint64_t tmp = placement_address; | |
10 placement_address += size; | |
11 return (void*)tmp; | |
12 } | |
13 | |
14 void* kmalloc_aligned_int(uint64_t size) | |
15 { | |
16 if ( (placement_address | 0xFFF) != 0 ) | |
17 { | |
18 placement_address &= ~(0xFFF); | |
19 placement_address += 0x1000; | |
20 } | |
21 uint64_t tmp = placement_address; | |
22 placement_address += size; | |
23 return (void*)tmp; | |
24 } | |
25 | |
26 | |
27 // ================= Other malloc | |
28 // TODO: move this to user space? | |
2 | 29 |
3 #define HEAP_MAGIC 0xc0ffee | 30 #define HEAP_MAGIC 0xc0ffee |
4 #define HEAP_START 0x400000 | 31 #define HEAP_START 0x400000 |
5 #define HEAP_SIZE 0x200000 | 32 #define HEAP_SIZE 0x200000 |
6 #define HEAP_INUSE 1 | 33 #define HEAP_INUSE 1 |
15 /* | 42 /* |
16 malloc and free divide the chunks of memory present at the heap | 43 malloc and free divide the chunks of memory present at the heap |
17 of the kernel into smaller parts. | 44 of the kernel into smaller parts. |
18 The heap is located at: 0x | 45 The heap is located at: 0x |
19 */ | 46 */ |
47 | |
20 static heap_t* kernel_heap = (heap_t*) 0x400000; // 4 MB - 6 MB is heap | 48 static heap_t* kernel_heap = (heap_t*) 0x400000; // 4 MB - 6 MB is heap |
21 /* Allocates 'size' bytes and returns the pointer if succesfull. | 49 /* Allocates 'size' bytes and returns the pointer if succesfull. |
22 Kernelpanic in case of failure.. | 50 Kernelpanic in case of failure.. |
23 */ | 51 */ |
24 | 52 |