summaryrefslogtreecommitdiff
path: root/include/nitro/os_alloc.h
blob: 904b3e9e2426b0ae4e629f3890633c2e4f7c438c (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Created by mart on 4/23/20.
//

#ifndef POKEDIAMOND_OS_ALLOC_H
#define POKEDIAMOND_OS_ALLOC_H

#include "types.h"

typedef enum {
    OS_ARENA_MAIN = 0,
    OS_ARENA_MAIN_SUBPRIV = 1,
    OS_ARENA_MAINEX = 2,
    OS_ARENA_ITCM = 3,
    OS_ARENA_DTCM = 4,
    OS_ARENA_SHARED = 5,
    OS_ARENA_WRAM_MAIN = 6,
    OS_ARENA_WRAM_SUB = 7,
    OS_ARENA_WRAM_SUBPRIV = 8,
    OS_ARENA_MAX = 9
} OSArenaId;

typedef struct {
    void* lo[OS_ARENA_MAX];
    void* hi[OS_ARENA_MAX];
    u16 initialized;
    u8 padding[2];
} OSArenaInfo;

typedef int OSHeapHandle;

typedef struct Cell Cell;

struct Cell {
    Cell* prev;
    Cell* next;
    long size;
};

typedef struct {
    long size;
    Cell *free;
    Cell *allocated;
} HeapDesc;

typedef struct {
    volatile OSHeapHandle currentHeap;
    int numHeaps;
    void* arenaStart;
    void* arenaEnd;
    HeapDesc* heapArray;
} OSHeapInfo;

void* OSiHeapInfo[OS_ARENA_MAX] = {
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
};

void* OS_AllocFromArenaHi(OSArenaId id, u32 size, u32 align);
void* OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align);
void OS_SetArenaLo(OSArenaId id, void *newLo);
void OS_SetArenaHi(OSArenaId id, void *newHi);
void* OS_GetInitArenaLo(OSArenaId id);
void* OS_GetInitArenaHi(OSArenaId id);
void* OS_GetArenaLo(OSArenaId id);
void* OS_GetArenaHi(OSArenaId id);
void OS_InitArenaEx();
void OS_InitArena();
void OS_FreeToHeap(OSArenaId id, OSHeapHandle heap, void *ptr);
void* OS_AllocFromHeap(OSArenaId id, OSHeapHandle heap, u32 size);

#endif //POKEDIAMOND_OS_ALLOC_H