feat: spec-compliant AHCI HBA initialization
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / dmm.h
1 #ifndef __LUNAIX_DMM_H
2 #define __LUNAIX_DMM_H
3 // Dynamic Memory (i.e., heap) Manager
4
5 #include <lunaix/mm/mm.h>
6 #include <lunaix/process.h>
7 #include <stddef.h>
8
9 #define M_ALLOCATED 0x1
10 #define M_PREV_FREE 0x2
11
12 #define M_NOT_ALLOCATED 0x0
13 #define M_PREV_ALLOCATED 0x0
14
15 #define CHUNK_S(header) ((header) & ~0x3)
16 #define CHUNK_PF(header) ((header)&M_PREV_FREE)
17 #define CHUNK_A(header) ((header)&M_ALLOCATED)
18
19 #define PACK(size, flags) (((size) & ~0x3) | (flags))
20
21 #define SW(p, w) (*((uint32_t*)(p)) = w)
22 #define LW(p) (*((uint32_t*)(p)))
23
24 #define HPTR(bp) ((uint32_t*)(bp)-1)
25 #define BPTR(bp) ((uint8_t*)(bp) + WSIZE)
26 #define FPTR(hp, size) ((uint32_t*)(hp + size - WSIZE))
27 #define NEXT_CHK(hp) ((uint8_t*)(hp) + CHUNK_S(LW(hp)))
28
29 #define BOUNDARY 4
30 #define WSIZE 4
31
32 #define HEAP_INIT_SIZE 4096
33
34 int
35 dmm_init(heap_context_t* heap);
36
37 int
38 lxbrk(heap_context_t* heap, void* addr, int user);
39
40 void*
41 lxsbrk(heap_context_t* heap, size_t size, int user);
42
43 void*
44 lx_malloc_internal(heap_context_t* heap, size_t size);
45
46 void
47 lx_free_internal(void* ptr);
48
49 #endif /* __LUNAIX_DMM_H */