Sync os_alloc, os_arena between procs

This commit is contained in:
PikalaxALT 2021-12-18 09:26:55 -05:00
parent c23205c1ef
commit 30af64b94a
6 changed files with 371 additions and 94 deletions

View File

@ -15,6 +15,8 @@ include filesystem.mk
$(ASM_OBJS): MWASFLAGS += -DPM_ASM -include config.h
$(C_OBJS): MWCFLAGS += -include global.h
$(BUILD_DIR)/asm/nitrocrypto.o: MWCCVER := 1.2/sp2p3
ifeq ($(NODEP),)
$(ASM_OBJS): $(WORK_DIR)/include/config.h
$(C_OBJS): $(WORK_DIR)/include/global.h

View File

@ -10,6 +10,10 @@
void *OSiHeapInfo[OS_ARENA_MAX] = {};
static
#ifdef SDK_ARM7
inline
#endif //SDK_ARM7
Cell *DLAddFront(Cell *list, Cell *cell) {
cell->next = list;
cell->prev = NULL;
@ -205,3 +209,64 @@ OSHeapHandle OS_CreateHeap(OSArenaId id, void *start, void *end) {
OS_RestoreInterrupts(enabled);
return -1;
}
#define InRange(targ, a, b)((u32)(a) <= (u32)(targ) && (u32)(targ) < (u32)(b))
#define OSi_CHECK(exp) do { \
if (!(exp)) { \
goto exit_OS_CheckHeap; \
} \
} while (0)
s32 OS_CheckHeap(OSArenaId id, OSHeapHandle heap) {
OSHeapInfo *heapInfo;
HeapDesc *hd;
Cell *cell;
long total = 0;
long free = 0;
long retValue = -1;
OSIntrMode enabled = OS_DisableInterrupts();
heapInfo = OSiHeapInfo[id];
if (heap == -1) {
heap = heapInfo->currentHeap;
}
OSi_CHECK(heapInfo->heapArray);
OSi_CHECK(0 <= heap && heap < heapInfo->numHeaps);
hd = &heapInfo->heapArray[heap];
OSi_CHECK(0 <= hd->size);
OSi_CHECK(hd->allocated == NULL || hd->allocated->prev == NULL);
for (cell = hd->allocated; cell; cell = cell->next) {
OSi_CHECK(InRange(cell, heapInfo->arenaStart, heapInfo->arenaEnd));
OSi_CHECK(OFFSET(cell, ALIGNMENT) == 0);
OSi_CHECK(cell->next == NULL || cell->next->prev == cell);
OSi_CHECK(MINOBJSIZE <= cell->size);
OSi_CHECK(OFFSET(cell->size, ALIGNMENT) == 0);
total += cell->size;
OSi_CHECK(0 < total && total <= hd->size);
}
OSi_CHECK(hd->free == NULL || hd->free->prev == NULL);
for (cell = hd->free; cell; cell = cell->next) {
OSi_CHECK(InRange(cell, heapInfo->arenaStart, heapInfo->arenaEnd));
OSi_CHECK(OFFSET(cell, ALIGNMENT) == 0);
OSi_CHECK(cell->next == NULL || cell->next->prev == cell);
OSi_CHECK(MINOBJSIZE <= cell->size);
OSi_CHECK(OFFSET(cell->size, ALIGNMENT) == 0);
OSi_CHECK(cell->next == NULL || (char *) cell + cell->size < (char *) cell->next);
total += cell->size;
free += cell->size - HEADERSIZE;
OSi_CHECK(0 < total && total <= hd->size);
}
OSi_CHECK(total == hd->size);
retValue = free;
exit_OS_CheckHeap:
OS_RestoreInterrupts(enabled);
return retValue;
}

View File

@ -5,6 +5,7 @@ extern void SDK_IRQ_STACKSIZE(void);
extern void SDK_SYS_STACKSIZE(void);
#define OSi_SYS_STACKSIZE ((s32)SDK_SYS_STACKSIZE)
#ifdef SDK_ARM9
extern void SDK_SECTION_ARENA_DTCM_START(void);
#define OSi_DTCM_ARENA_LO_DEFAULT ((s32)SDK_SECTION_ARENA_DTCM_START)
@ -13,15 +14,25 @@ extern void SDK_SECTION_ARENA_ITCM_START(void);
extern void SDK_MAIN_ARENA_LO(void);
#define OSi_MAIN_ARENA_LO_DEFAULT ((s32)SDK_MAIN_ARENA_LO)
#else
extern void SDK_SUBPRIV_ARENA_LO(void);
#define OSi_SUBPRIV_ARENA_LO_DEFAULT ((s32)SDK_SUBPRIV_ARENA_LO)
BOOL OSi_Initialized = FALSE;
BOOL OSi_MainArenaEnabled = FALSE;
extern void SDK_WRAM_ARENA_LO(void);
#define OSi_WRAM_ARENA_LO_DEFAULT ((s32)SDK_WRAM_ARENA_LO)
#endif //SDK_ARM9
static BOOL OSi_Initialized = FALSE;
#ifdef SDK_ARM9
static BOOL OSi_MainArenaEnabled = FALSE;
#endif
void OS_InitArena(void) {
if (OSi_Initialized) {
return;
}
OSi_Initialized = TRUE;
#ifdef SDK_ARM9
OS_SetArenaHi(OS_ARENA_MAIN, OS_GetInitArenaHi(OS_ARENA_MAIN));
OS_SetArenaLo(OS_ARENA_MAIN, OS_GetInitArenaLo(OS_ARENA_MAIN));
OS_SetArenaLo(OS_ARENA_MAINEX, NULL);
@ -34,8 +45,14 @@ void OS_InitArena(void) {
OS_SetArenaLo(OS_ARENA_SHARED, OS_GetInitArenaLo(OS_ARENA_SHARED));
OS_SetArenaHi(OS_ARENA_WRAM_MAIN, OS_GetInitArenaHi(OS_ARENA_WRAM_MAIN));
OS_SetArenaLo(OS_ARENA_WRAM_MAIN, OS_GetInitArenaLo(OS_ARENA_WRAM_MAIN));
#else
OS_InitArenaHiAndLo(OS_ARENA_MAIN_SUBPRIV);
OS_InitArenaHiAndLo(OS_ARENA_WRAM_SUB);
OS_InitArenaHiAndLo(OS_ARENA_WRAM_SUBPRIV);
#endif
}
#ifdef SDK_ARM9
void OS_InitArenaEx(void) {
OS_SetArenaHi(OS_ARENA_MAINEX, OS_GetInitArenaHi(OS_ARENA_MAINEX));
OS_SetArenaLo(OS_ARENA_MAINEX, OS_GetInitArenaLo(OS_ARENA_MAINEX));
@ -44,17 +61,35 @@ void OS_InitArenaEx(void) {
OS_SetProtectionRegion(2, HW_MAIN_MEM_MAIN_END, 128KB);
}
}
void *OS_GetArenaHi(OSArenaId arena) {
return OSi_GetArenaInfo().hi[arena];
#else
static inline void OS_InitArenaHi(OSArenaId id)
{
OS_SetArenaHi(id, OS_GetInitArenaHi((OSArenaId)id));
}
void *OS_GetArenaLo(OSArenaId arena) {
return OSi_GetArenaInfo().lo[arena];
static inline void OS_InitArenaLo(OSArenaId id)
{
OS_SetArenaLo(id, OS_GetInitArenaLo(id));
}
void *OS_GetInitArenaHi(OSArenaId arena) {
switch (arena) {
void OS_InitArenaHiAndLo(OSArenaId id)
{
OS_InitArenaHi(id);
OS_InitArenaLo(id);
}
#endif //SDK_ARM9
void *OS_GetArenaHi(OSArenaId id) {
return OSi_GetArenaInfo().hi[id];
}
void *OS_GetArenaLo(OSArenaId id) {
return OSi_GetArenaInfo().lo[id];
}
void *OS_GetInitArenaHi(OSArenaId id) {
switch (id) {
#ifdef SDK_ARM9
case OS_ARENA_MAIN:
return (void *)OSi_MAIN_ARENA_HI_DEFAULT;
case OS_ARENA_MAINEX:
@ -87,14 +122,39 @@ void *OS_GetInitArenaHi(OSArenaId arena) {
return (void *)HW_SHARED_ARENA_HI_DEFAULT;
case OS_ARENA_WRAM_MAIN:
return (void *)OSi_WRAM_MAIN_ARENA_HI_DEFAULT;
default:
;
#else
case OS_ARENA_MAIN_SUBPRIV:
return (void *)HW_MAIN_MEM_SUB_END;
case OS_ARENA_WRAM_SUB:
return (void *)HW_WRAM_END;
case OS_ARENA_WRAM_SUBPRIV:
{
u32 irqStackLo = (u32)HW_PRV_WRAM_IRQ_STACK_END - OSi_IRQ_STACKSIZE;
u32 sysStackLo = (u32)HW_PRV_WRAM;
if ((u32)OSi_WRAM_ARENA_LO_DEFAULT > (u32)HW_PRV_WRAM) {
sysStackLo = (u32)OSi_WRAM_ARENA_LO_DEFAULT;
}
if (!OSi_SYS_STACKSIZE) {
return (void *)sysStackLo;
} else if (OSi_SYS_STACKSIZE < 0) {
sysStackLo -= OSi_SYS_STACKSIZE;
} else {
sysStackLo = irqStackLo - OSi_SYS_STACKSIZE;
}
return (void *)sysStackLo;
}
#endif //SDK_ARM9
default:
return NULL;
}
return NULL;
}
void *OS_GetInitArenaLo(OSArenaId arena) {
switch (arena) {
void *OS_GetInitArenaLo(OSArenaId id) {
switch (id) {
#ifdef SDK_ARM9
case OS_ARENA_MAIN:
return (void *)OSi_MAIN_ARENA_LO_DEFAULT;
case OS_ARENA_MAINEX:
@ -111,25 +171,44 @@ void *OS_GetInitArenaLo(OSArenaId arena) {
return (void *)HW_SHARED_ARENA_LO_DEFAULT;
case OS_ARENA_WRAM_MAIN:
return (void *)OSi_WRAM_MAIN_ARENA_LO_DEFAULT;
default:
;
#else
case OS_ARENA_MAIN_SUBPRIV:
return (void *)OSi_SUBPRIV_ARENA_LO_DEFAULT;
case OS_ARENA_WRAM_SUB:
{
u32 wramSubLo = ((u32)OSi_WRAM_ARENA_LO_DEFAULT);
if ((u32)HW_WRAM_END < (u32)wramSubLo) {
wramSubLo = (u32)HW_WRAM_END;
}
return (void *)wramSubLo;
}
case OS_ARENA_WRAM_SUBPRIV:
{
u32 privWramLo = HW_PRV_WRAM;
if ((u32)OSi_WRAM_ARENA_LO_DEFAULT > (u32)privWramLo) {
privWramLo = (u32)OSi_WRAM_ARENA_LO_DEFAULT;
}
return (void *)privWramLo;
}
#endif
default:
return NULL;
}
return NULL;
}
void OS_SetArenaHi(OSArenaId arena, void *ptr) {
OSi_GetArenaInfo().hi[arena] = ptr;
void OS_SetArenaHi(OSArenaId id, void *ptr) {
OSi_GetArenaInfo().hi[id] = ptr;
}
void OS_SetArenaLo(OSArenaId arena, void *ptr) {
OSi_GetArenaInfo().lo[arena] = ptr;
}
void *OS_AllocFromArenaLo(OSArenaId arena, u32 size, u32 align) {
void *OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align) {
void *ptr;
u8 *arenaLo;
ptr = OS_GetArenaLo(arena);
ptr = OS_GetArenaLo(id);
if (ptr == NULL) {
return NULL;
}
@ -137,10 +216,10 @@ void *OS_AllocFromArenaLo(OSArenaId arena, u32 size, u32 align) {
arenaLo = ptr = (void *)OSi_ROUND(ptr, align);
arenaLo += size;
arenaLo = (u8 *)OSi_ROUND(arenaLo, align);
if (arenaLo > (u8 *)OS_GetArenaHi(arena)) {
if (arenaLo > (u8 *)OS_GetArenaHi(id)) {
return NULL;
}
OS_SetArenaLo(arena, arenaLo);
OS_SetArenaLo(id, arenaLo);
return ptr;
}

View File

@ -12,6 +12,6 @@ void* OS_GetInitArenaLo(OSArenaId id);
void OS_SetArenaHi(OSArenaId id, void* newHi);
void OS_SetArenaLo(OSArenaId id, void* newLo);
void *OS_AllocFromArenaHi(OSArenaId arena, u32 size, u32 align);
void *OS_AllocFromArenaLo(OSArenaId arena, u32 size, u32 align);
void *OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align);
#endif //NITRO_OS_ARENA_H

View File

@ -10,7 +10,11 @@
void *OSiHeapInfo[OS_ARENA_MAX] = {};
static inline Cell *DLAddFront(Cell *list, Cell *cell) {
static
#ifdef SDK_ARM7
inline
#endif //SDK_ARM7
Cell *DLAddFront(Cell *list, Cell *cell) {
cell->next = list;
cell->prev = NULL;
if (list != NULL) {
@ -173,6 +177,10 @@ void *OS_InitAlloc(OSArenaId id, void *arenaStart, void *arenaEnd, s32 maxHeaps)
return heapInfo->arenaStart;
}
void OS_ClearAlloc(OSArenaId id) {
OSiHeapInfo[id] = NULL; // Act like it never existed
}
OSHeapHandle OS_CreateHeap(OSArenaId id, void *start, void *end) {
OSHeapInfo *heapInfo;
OSHeapHandle heap;

View File

@ -1,26 +1,67 @@
#include <nitro/hw/mmap.h>
#include <nitro/os/arena.h>
#include <nitro.h>
extern void SDK_IRQ_STACKSIZE(void);
#define OSi_IRQ_STACKSIZE ((s32)SDK_IRQ_STACKSIZE)
extern void SDK_SYS_STACKSIZE(void);
#define OSi_SYS_STACKSIZE ((s32)SDK_SYS_STACKSIZE)
#ifdef SDK_ARM9
extern void SDK_SECTION_ARENA_DTCM_START(void);
#define OSi_DTCM_ARENA_LO_DEFAULT ((s32)SDK_SECTION_ARENA_DTCM_START)
extern void SDK_SECTION_ARENA_ITCM_START(void);
#define OSi_ITCM_ARENA_LO_DEFAULT ((s32)SDK_SECTION_ARENA_ITCM_START)
extern void SDK_MAIN_ARENA_LO(void);
#define OSi_MAIN_ARENA_LO_DEFAULT ((s32)SDK_MAIN_ARENA_LO)
#else
extern void SDK_SUBPRIV_ARENA_LO(void);
#define OSi_SUBPRIV_ARENA_LO_DEFAULT ((s32)SDK_SUBPRIV_ARENA_LO)
extern void SDK_WRAM_ARENA_LO(void);
#define OSi_WRAM_ARENA_LO_DEFAULT ((s32)SDK_WRAM_ARENA_LO)
#endif //SDK_ARM9
static BOOL OSi_Initialized = FALSE;
#ifdef SDK_ARM9
static BOOL OSi_MainArenaEnabled = FALSE;
#endif
extern void SDK_SUBPRIV_ARENA_LO(void);
extern void SDK_WRAM_ARENA_LO(void);
extern void SDK_IRQ_STACKSIZE(void);
extern void SDK_SYS_STACKSIZE(void);
void OS_InitArena(void)
{
if (OSi_Initialized)
{
void OS_InitArena(void) {
if (OSi_Initialized) {
return;
}
OSi_Initialized = TRUE;
#ifdef SDK_ARM9
OS_SetArenaHi(OS_ARENA_MAIN, OS_GetInitArenaHi(OS_ARENA_MAIN));
OS_SetArenaLo(OS_ARENA_MAIN, OS_GetInitArenaLo(OS_ARENA_MAIN));
OS_SetArenaLo(OS_ARENA_MAINEX, NULL);
OS_SetArenaHi(OS_ARENA_MAINEX, NULL);
OS_SetArenaHi(OS_ARENA_ITCM, OS_GetInitArenaHi(OS_ARENA_ITCM));
OS_SetArenaLo(OS_ARENA_ITCM, OS_GetInitArenaLo(OS_ARENA_ITCM));
OS_SetArenaHi(OS_ARENA_DTCM, OS_GetInitArenaHi(OS_ARENA_DTCM));
OS_SetArenaLo(OS_ARENA_DTCM, OS_GetInitArenaLo(OS_ARENA_DTCM));
OS_SetArenaHi(OS_ARENA_SHARED, OS_GetInitArenaHi(OS_ARENA_SHARED));
OS_SetArenaLo(OS_ARENA_SHARED, OS_GetInitArenaLo(OS_ARENA_SHARED));
OS_SetArenaHi(OS_ARENA_WRAM_MAIN, OS_GetInitArenaHi(OS_ARENA_WRAM_MAIN));
OS_SetArenaLo(OS_ARENA_WRAM_MAIN, OS_GetInitArenaLo(OS_ARENA_WRAM_MAIN));
#else
OS_InitArenaHiAndLo(OS_ARENA_MAIN_SUBPRIV);
OS_InitArenaHiAndLo(OS_ARENA_WRAM_SUB);
OS_InitArenaHiAndLo(OS_ARENA_WRAM_SUBPRIV);
#endif
}
#ifdef SDK_ARM9
void OS_InitArenaEx(void) {
OS_SetArenaHi(OS_ARENA_MAINEX, OS_GetInitArenaHi(OS_ARENA_MAINEX));
OS_SetArenaLo(OS_ARENA_MAINEX, OS_GetInitArenaLo(OS_ARENA_MAINEX));
if (!OSi_MainArenaEnabled || (OS_GetConsoleType() & OS_CONSOLE_SIZE_MASK) == OS_CONSOLE_SIZE_4MB) {
OS_SetProtectionRegion(1, HW_MAIN_MEM_MAIN, 4MB);
OS_SetProtectionRegion(2, HW_MAIN_MEM_MAIN_END, 128KB);
}
}
#else
static inline void OS_InitArenaHi(OSArenaId id)
{
OS_SetArenaHi(id, OS_GetInitArenaHi((OSArenaId)id));
@ -36,85 +77,167 @@ void OS_InitArenaHiAndLo(OSArenaId id)
OS_InitArenaHi(id);
OS_InitArenaLo(id);
}
#endif //SDK_ARM9
void* OS_GetArenaHi(OSArenaId id)
{
void *OS_GetArenaHi(OSArenaId id) {
return OSi_GetArenaInfo().hi[id];
}
void* OS_GetArenaLo(OSArenaId id)
{
void *OS_GetArenaLo(OSArenaId id) {
return OSi_GetArenaInfo().lo[id];
}
void* OS_GetInitArenaHi(OSArenaId id)
{
void *OS_GetInitArenaHi(OSArenaId id) {
switch (id) {
case OS_ARENA_MAIN_SUBPRIV:
return (void *)HW_MAIN_MEM_SUB_END;
case OS_ARENA_WRAM_SUB:
return (void *)HW_WRAM_END;
case OS_ARENA_WRAM_SUBPRIV:
{
u32 irqStackLo = (u32)HW_PRV_WRAM_IRQ_STACK_END - (s32)SDK_IRQ_STACKSIZE;
u32 sysStackLo = (u32)HW_PRV_WRAM;
#ifdef SDK_ARM9
case OS_ARENA_MAIN:
return (void *)OSi_MAIN_ARENA_HI_DEFAULT;
case OS_ARENA_MAINEX:
if (!OSi_MainArenaEnabled || (OS_GetConsoleType() & OS_CONSOLE_SIZE_MASK) == OS_CONSOLE_SIZE_4MB) {
return NULL;
} else {
return (void *)OSi_MAINEX_ARENA_HI_DEFAULT;
}
case OS_ARENA_ITCM:
return (void *)HW_ITCM_ARENA_HI_DEFAULT;
case OS_ARENA_DTCM: {
u32 irqStackLo;
u32 sysStackLo;
if ((u32)SDK_WRAM_ARENA_LO > (u32)HW_PRV_WRAM)
{
sysStackLo = (u32)SDK_WRAM_ARENA_LO;
}
irqStackLo = (u32)HW_DTCM_IRQ_STACK_END - OSi_IRQ_STACKSIZE;
if (!(s32)SDK_SYS_STACKSIZE)
{
return (void *)sysStackLo;
}
else if ((s32)SDK_SYS_STACKSIZE < 0)
{
sysStackLo -= (s32)SDK_SYS_STACKSIZE;
}
else
{
sysStackLo = irqStackLo - (s32)SDK_SYS_STACKSIZE;
if (OSi_SYS_STACKSIZE == 0) {
sysStackLo = HW_DTCM;
if (sysStackLo < OSi_DTCM_ARENA_LO_DEFAULT) {
sysStackLo = OSi_DTCM_ARENA_LO_DEFAULT;
}
} else if (OSi_SYS_STACKSIZE < 0) {
sysStackLo = OSi_DTCM_ARENA_LO_DEFAULT - OSi_SYS_STACKSIZE;
} else {
sysStackLo = irqStackLo - OSi_SYS_STACKSIZE;
}
return (void *)sysStackLo;
}
case OS_ARENA_SHARED:
return (void *)HW_SHARED_ARENA_HI_DEFAULT;
case OS_ARENA_WRAM_MAIN:
return (void *)OSi_WRAM_MAIN_ARENA_HI_DEFAULT;
#else
case OS_ARENA_MAIN_SUBPRIV:
return (void *)HW_MAIN_MEM_SUB_END;
case OS_ARENA_WRAM_SUB:
return (void *)HW_WRAM_END;
case OS_ARENA_WRAM_SUBPRIV:
{
u32 irqStackLo = (u32)HW_PRV_WRAM_IRQ_STACK_END - OSi_IRQ_STACKSIZE;
u32 sysStackLo = (u32)HW_PRV_WRAM;
if ((u32)OSi_WRAM_ARENA_LO_DEFAULT > (u32)HW_PRV_WRAM) {
sysStackLo = (u32)OSi_WRAM_ARENA_LO_DEFAULT;
}
if (!OSi_SYS_STACKSIZE) {
return (void *)sysStackLo;
} else if (OSi_SYS_STACKSIZE < 0) {
sysStackLo -= OSi_SYS_STACKSIZE;
} else {
sysStackLo = irqStackLo - OSi_SYS_STACKSIZE;
}
default:
return NULL;
return (void *)sysStackLo;
}
#endif //SDK_ARM9
default:
return NULL;
}
}
void* OS_GetInitArenaLo(OSArenaId id) {
void *OS_GetInitArenaLo(OSArenaId id) {
switch (id) {
case OS_ARENA_MAIN_SUBPRIV:
return (void *)SDK_SUBPRIV_ARENA_LO;
case OS_ARENA_WRAM_SUB:
{
u32 wramSubLo = ((u32)SDK_WRAM_ARENA_LO);
if ((u32)HW_WRAM_END < (u32)wramSubLo)
{
wramSubLo = (u32)HW_WRAM_END;
}
return (void *)wramSubLo;
}
case OS_ARENA_WRAM_SUBPRIV:
{
u32 privWramLo = HW_PRV_WRAM;
if ((u32)SDK_WRAM_ARENA_LO > (u32)privWramLo)
{
privWramLo = (u32)SDK_WRAM_ARENA_LO;
}
return (void *)privWramLo;
}
default:
#ifdef SDK_ARM9
case OS_ARENA_MAIN:
return (void *)OSi_MAIN_ARENA_LO_DEFAULT;
case OS_ARENA_MAINEX:
if (!OSi_MainArenaEnabled || (OS_GetConsoleType() & OS_CONSOLE_SIZE_MASK) == OS_CONSOLE_SIZE_4MB) {
return NULL;
} else {
return (void *)OSi_MAINEX_ARENA_LO_DEFAULT;
}
case OS_ARENA_ITCM:
return (void *)OSi_ITCM_ARENA_LO_DEFAULT;
case OS_ARENA_DTCM:
return (void *)OSi_DTCM_ARENA_LO_DEFAULT;
case OS_ARENA_SHARED:
return (void *)HW_SHARED_ARENA_LO_DEFAULT;
case OS_ARENA_WRAM_MAIN:
return (void *)OSi_WRAM_MAIN_ARENA_LO_DEFAULT;
#else
case OS_ARENA_MAIN_SUBPRIV:
return (void *)OSi_SUBPRIV_ARENA_LO_DEFAULT;
case OS_ARENA_WRAM_SUB:
{
u32 wramSubLo = ((u32)OSi_WRAM_ARENA_LO_DEFAULT);
if ((u32)HW_WRAM_END < (u32)wramSubLo) {
wramSubLo = (u32)HW_WRAM_END;
}
return (void *)wramSubLo;
}
case OS_ARENA_WRAM_SUBPRIV:
{
u32 privWramLo = HW_PRV_WRAM;
if ((u32)OSi_WRAM_ARENA_LO_DEFAULT > (u32)privWramLo) {
privWramLo = (u32)OSi_WRAM_ARENA_LO_DEFAULT;
}
return (void *)privWramLo;
}
#endif
default:
return NULL;
}
}
inline void OS_SetArenaHi(OSArenaId id, void* newHi) {
OSi_GetArenaInfo().hi[id] = newHi;
void OS_SetArenaHi(OSArenaId id, void *ptr) {
OSi_GetArenaInfo().hi[id] = ptr;
}
void OS_SetArenaLo(OSArenaId id, void* newLo) {
OSi_GetArenaInfo().lo[id] = newLo;
void OS_SetArenaLo(OSArenaId arena, void *ptr) {
OSi_GetArenaInfo().lo[arena] = ptr;
}
void *OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align) {
void *ptr;
u8 *arenaLo;
ptr = OS_GetArenaLo(id);
if (ptr == NULL) {
return NULL;
}
arenaLo = ptr = (void *)OSi_ROUND(ptr, align);
arenaLo += size;
arenaLo = (u8 *)OSi_ROUND(arenaLo, align);
if (arenaLo > (u8 *)OS_GetArenaHi(id)) {
return NULL;
}
OS_SetArenaLo(id, arenaLo);
return ptr;
}
void *OS_AllocFromArenaHi(OSArenaId arena, u32 size, u32 align) {
void *ptr;
u8 *arenaHi;
arenaHi = OS_GetArenaHi(arena);
if (arenaHi == NULL) {
return NULL;
}
arenaHi = (u8 *)OSi_TRUNC(arenaHi, align);
arenaHi -= size;
arenaHi = ptr = (void *)OSi_TRUNC(arenaHi, align);
if (arenaHi < (u8 *)OS_GetArenaLo(arena)) {
return NULL;
}
OS_SetArenaHi(arena, arenaHi);
return ptr;
}