From e5e30d8e9517bd2ba8bf598872ce74588d52990c Mon Sep 17 00:00:00 2001 From: Ryan Burns <52847440+r-burns@users.noreply.github.com> Date: Sat, 17 Dec 2022 17:45:27 -0800 Subject: [PATCH] Match OSArena (#15) Former-commit-id: 25c687bd02e3c88212cff46bf6092a0901d6b2fe --- configure.py | 2 +- include/dolphin/os/OSArena.h | 9 +++++++++ src/Dolphin/os/OSArena.c | 39 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/Dolphin/os/OSArena.c diff --git a/configure.py b/configure.py index a582997d..be05ed8b 100755 --- a/configure.py +++ b/configure.py @@ -806,7 +806,7 @@ LIBS = [ ["Dolphin/os/__start", True], "Dolphin/os/OS", ["Dolphin/os/OSAlarm", True], - "Dolphin/os/OSArena", + ["Dolphin/os/OSArena", True], ["Dolphin/os/OSAudioSystem", True], ["Dolphin/os/OSCache", True], "Dolphin/os/OSContext", diff --git a/include/dolphin/os/OSArena.h b/include/dolphin/os/OSArena.h index a709e519..9dc15701 100644 --- a/include/dolphin/os/OSArena.h +++ b/include/dolphin/os/OSArena.h @@ -1,4 +1,13 @@ #ifndef _DOLPHIN_OSARENA #define _DOLPHIN_OSARENA +#include + +void* OSGetArenaHi(void); +void* OSGetArenaLo(void); +void OSSetArenaHi(void* addr); +void OSSetArenaLo(void* addr); +void* OSAllocFromArenaLo(u32 size, u32 align); +void* OSAllocFromArenaLo(u32 size, u32 align); + #endif // _DOLPHIN_OSARENA diff --git a/src/Dolphin/os/OSArena.c b/src/Dolphin/os/OSArena.c new file mode 100644 index 00000000..da864abf --- /dev/null +++ b/src/Dolphin/os/OSArena.c @@ -0,0 +1,39 @@ +#include + +#define ROUND(n, a) (((u32)(n) + (a)-1) & ~((a)-1)) +#define TRUNC(n, a) (((u32)(n)) & ~((a)-1)) + +void* __OSArenaHi; +void* __OSArenaLo = (void*)-1; + +void* OSGetArenaHi(void) { return __OSArenaHi; } + +void* OSGetArenaLo(void) { return __OSArenaLo; } + +void OSSetArenaHi(void* addr) { __OSArenaHi = addr; } + +void OSSetArenaLo(void* addr) { __OSArenaLo = addr; } + +void* OSAllocFromArenaLo(u32 size, u32 align) { + void* ptr; + u8* arenaLo; + + ptr = OSGetArenaLo(); + arenaLo = ptr = (void*)ROUND(ptr, align); + arenaLo += size; + arenaLo = (u8*)ROUND(arenaLo, align); + OSSetArenaLo(arenaLo); + return ptr; +} + +void* OSAllocFromArenaHi(u32 size, u32 align) { + void* ptr; + u8* arenaHi; + + arenaHi = OSGetArenaHi(); + arenaHi = (u8*)TRUNC(arenaHi, align); + arenaHi -= size; + arenaHi = ptr = (void*)TRUNC(arenaHi, align); + OSSetArenaHi(arenaHi); + return ptr; +}