forked from Isuruni/MYOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkheap.c
38 lines (31 loc) · 1.06 KB
/
kheap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "kheap.h"
u32int g_KerNelPhysicalAddressStart = 0;
u32int g_CurrentPhysicalAddressTop = 0;
void set_physical_address(u32int kerNelPhysicalStart,
u32int kernelPhysicalEnd) {
g_KerNelPhysicalAddressStart = kerNelPhysicalStart;
g_CurrentPhysicalAddressTop = kernelPhysicalEnd;
}
u32int kmalloc_int(u32int size, u32int align, u32int *pAddrPtr) {
if (align == 1) {
if (g_CurrentPhysicalAddressTop & 0x00000FFF) {
// Align the placement address;
g_CurrentPhysicalAddressTop &= 0xFFFFF000;
g_CurrentPhysicalAddressTop += 0x1000;
}
}
if (pAddrPtr) {
*pAddrPtr = g_CurrentPhysicalAddressTop;
}
u32int tmp = g_CurrentPhysicalAddressTop;
g_CurrentPhysicalAddressTop += size;
return tmp;
}
u32int kmalloc_a(u32int size) { return kmalloc_int(size, 1, 0); }
u32int kmalloc_p(u32int size, u32int *pAddrPtr) {
return kmalloc_int(size, 0, pAddrPtr);
}
u32int kmalloc_ap(u32int size, u32int *pAddrPtr) {
return kmalloc_int(size, 1, pAddrPtr);
}
u32int kmalloc(u32int size) { return kmalloc_int(size, 0, 0); }