Mercurial > lcfOS
comparison cos/kernel/kernel.c @ 20:b1fed2171e1a
Now working with 2 MB pages
author | windel |
---|---|
date | Mon, 28 Nov 2011 20:54:40 +0100 |
parents | f454e3c592dd |
children | 69bc6d477b38 |
comparison
equal
deleted
inserted
replaced
19:f454e3c592dd | 20:b1fed2171e1a |
---|---|
129 /* | 129 /* |
130 malloc and free divide the chunks of memory present at the heap | 130 malloc and free divide the chunks of memory present at the heap |
131 of the kernel into smaller parts. | 131 of the kernel into smaller parts. |
132 The heap is located at: 0x | 132 The heap is located at: 0x |
133 */ | 133 */ |
134 static void* kernel_heap = (void*) 0xD0000000; | 134 static void* kernel_heap = (void*) 0x400000; // 4 MB - 6 MB is heap |
135 /* Allocates 'size' bytes and returns the pointer if succesfull. | 135 /* Allocates 'size' bytes and returns the pointer if succesfull. |
136 Kernelpanic in case of failure.. | 136 Kernelpanic in case of failure.. |
137 */ | 137 */ |
138 void* malloc(uint64_t size) { | 138 void* kmalloc(uint64_t size) { |
139 printf("Malloc %d bytes\n", size); | 139 printf("Malloc %d bytes\n", size); |
140 return kernel_heap; | 140 return kernel_heap; |
141 } | 141 } |
142 | 142 |
143 void free(void* ptr) { | 143 void kfree(void* ptr) { |
144 printf("Free address %x\n", ptr); | 144 printf("Free address %x\n", ptr); |
145 } | 145 } |
146 | 146 |
147 void startPython() | 147 void startPython() |
148 { | 148 { |
149 // TODO: connect to Py_Main | 149 // TODO: connect to Py_Main |
150 | |
151 } | |
152 | |
153 void testMalloc() | |
154 { | |
155 char *a, *b; | |
156 a = kmalloc(100); | |
157 printf("Got a at %x\n", a); | |
158 a[0] = 'A'; | |
159 b = kmalloc(22); | |
160 printf("Got b at %x\n", b); | |
161 b[0] = 'B'; | |
162 kfree(a); | |
150 | 163 |
151 } | 164 } |
152 | 165 |
153 void kmain() | 166 void kmain() |
154 { | 167 { |
155 init_screen(); | 168 init_screen(); |
156 printf("Welcome! .. "); | 169 printf("Welcome! .. "); |
157 | 170 |
158 printf("Enabling interrupts .. "); | 171 printf("Enabling interrupts .. "); |
159 setupIDT(); | 172 setupIDT(); |
173 printf("Testing malloc"); | |
174 testMalloc(); | |
160 printf("Entering mainloop!\n"); | 175 printf("Entering mainloop!\n"); |
161 | 176 |
162 while (1==1) | 177 while (1==1) |
163 { | 178 { |
164 char buffer[70]; | 179 char buffer[70]; |