diff options
author | Revo <projectrevotpp@hotmail.com> | 2020-04-30 19:55:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-30 19:55:00 -0400 |
commit | 081bd6efce613ed078407ab8fd24765275385f9f (patch) | |
tree | ea91f20d1cd1ab5ae06880d1dd2e5a2c61f4db59 /arm9/lib | |
parent | c7dd102f628b7a64a34223278c2de09718da19f4 (diff) | |
parent | 2ac877a24f241d3bc9d875a1338c40d7325929c6 (diff) |
Merge pull request #7 from martmists/os_lib
Add OS* functions
Diffstat (limited to 'arm9/lib')
-rw-r--r-- | arm9/lib/include/consts.h | 45 | ||||
-rw-r--r-- | arm9/lib/include/mmap.h | 45 | ||||
-rw-r--r-- | arm9/lib/include/nitro.h | 18 | ||||
-rw-r--r-- | arm9/lib/include/os.h | 17 | ||||
-rw-r--r-- | arm9/lib/include/os_alloc.h | 38 | ||||
-rw-r--r-- | arm9/lib/include/os_arena.h | 41 | ||||
-rw-r--r-- | arm9/lib/include/os_protectionRegion.h | 47 | ||||
-rw-r--r-- | arm9/lib/include/os_system.h | 44 | ||||
-rw-r--r-- | arm9/lib/include/types.h | 40 | ||||
-rw-r--r-- | arm9/lib/src/OS_arena.c | 169 |
10 files changed, 504 insertions, 0 deletions
diff --git a/arm9/lib/include/consts.h b/arm9/lib/include/consts.h new file mode 100644 index 00000000..6fc71be2 --- /dev/null +++ b/arm9/lib/include/consts.h @@ -0,0 +1,45 @@ +// +// Created by mart on 4/15/20. +// + +#ifndef POKEDIAMOND_CONSTS_H +#define POKEDIAMOND_CONSTS_H + +#include "mmap.h" + +#define HW_PSR_CPU_MODE_MASK 0x1f // CPU mode + +#define HW_PSR_FIQ_DISABLE 0x40 // Disable FIQ +#define HW_PSR_IRQ_DISABLE 0x80 // Disable IRQ +#define HW_PSR_IRQ_FIQ_DISABLE 0xc0 // Disable FIQ and IRQ + +#define HW_C6_PR_4KB 0x16 +#define HW_C6_PR_8KB 0x18 +#define HW_C6_PR_16KB 0x1a +#define HW_C6_PR_32KB 0x1c +#define HW_C6_PR_64KB 0x1e +#define HW_C6_PR_128KB 0x20 +#define HW_C6_PR_256KB 0x22 +#define HW_C6_PR_512KB 0x24 +#define HW_C6_PR_1MB 0x26 +#define HW_C6_PR_2MB 0x28 +#define HW_C6_PR_4MB 0x2a +#define HW_C6_PR_8MB 0x2c +#define HW_C6_PR_16MB 0x2e +#define HW_C6_PR_32MB 0x30 +#define HW_C6_PR_64MB 0x32 +#define HW_C6_PR_128MB 0x34 +#define HW_C6_PR_256MB 0x36 +#define HW_C6_PR_512MB 0x38 +#define HW_C6_PR_1GB 0x3a +#define HW_C6_PR_2GB 0x3c +#define HW_C6_PR_4GB 0x3e + +#define OS_CONSOLE_SIZE_MASK 0x00000003 +#define OS_CONSOLE_SIZE_4MB 0x00000001 + +#define OSi_GetArenaInfo() (*(OSArenaInfo*)HW_ARENA_INFO_BUF) +#define OSi_TRUNC(n, a) (((u32) (n)) & ~((a) - 1)) +#define OSi_ROUND(n, a) (((u32) (n) + (a) - 1) & ~((a) - 1)) + +#endif //POKEDIAMOND_CONSTS_H diff --git a/arm9/lib/include/mmap.h b/arm9/lib/include/mmap.h new file mode 100644 index 00000000..14820c39 --- /dev/null +++ b/arm9/lib/include/mmap.h @@ -0,0 +1,45 @@ +#ifndef NITRO_MMAP_H +#define NITRO_MMAP_H + +#include "types.h" + +extern u32 SDK_AUTOLOAD_DTCM_START[]; + +#define HW_MAIN_MEM 0x02000000 +#define HW_MAIN_MEM_SIZE 0x00400000 +#define HW_MAIN_MEM_EX_SIZE 0x00800000 +#define HW_MAIN_MEM_MAIN_SIZE 0x003E0000 +#define HW_MAIN_MEM_SHARED_SIZE 0x00001000 +#define HW_MAIN_MEM_DEBUGGER_OFFSET 0x00700000 + +#define HW_ITCM 0x01FF8000 +#define HW_ITCM_SIZE 0x00008000 + +#define HW_WRAM 0x037F8000 + +#define HW_DTCM ((u32)SDK_AUTOLOAD_DTCM_START) +#define HW_DTCM_SIZE 0x00004000 + +#define HW_CARD_ROM_HEADER_SIZE 0x00000160 +#define HW_DOWNLOAD_PARAMETER_SIZE 0x00000020 + +#define HW_ARENA_INFO_BUF (HW_MAIN_MEM + 0x007ffda0) // Arena data structure +#define HW_ROM_HEADER_BUF (HW_MAIN_MEM + 0x007ffe00) // ROM registration area data buffer +#define HW_RED_RESERVED (HW_MAIN_MEM + 0x007ff800) // Some kind of reserved data for shared memory +#define HW_MAIN_MEM_MAIN_END (HW_MAIN_MEM + HW_MAIN_MEM_MAIN_SIZE) +#define HW_MAIN_MEM_EX_END (HW_MAIN_MEM + HW_MAIN_MEM_EX_SIZE) +#define HW_MAIN_MEM_SHARED (HW_MAIN_MEM_EX_END - HW_MAIN_MEM_SHARED_SIZE) +#define HW_DTCM_SVC_STACK_END (HW_DTCM + 0x00003fc0) +#define HW_SVC_STACK_SIZE 0x00000040 +#define HW_DTCM_SVC_STACK (HW_DTCM_SVC_STACK_END - HW_SVC_STACK_SIZE) +#define HW_DTCM_IRQ_STACK_END (HW_DTCM_SVC_STACK) + +#define OSi_MAIN_ARENA_HI_DEFAULT (HW_MAIN_MEM_MAIN_END) +#define OSi_MAINEX_ARENA_HI_DEFAULT (HW_MAIN_MEM + HW_MAIN_MEM_DEBUGGER_OFFSET) +#define HW_ITCM_ARENA_HI_DEFAULT (HW_ITCM + HW_ITCM_SIZE) +#define HW_SHARED_ARENA_HI_DEFAULT (HW_RED_RESERVED - HW_CARD_ROM_HEADER_SIZE - HW_DOWNLOAD_PARAMETER_SIZE) +#define HW_SHARED_ARENA_LO_DEFAULT (HW_MAIN_MEM_SHARED) +#define OSi_WRAM_MAIN_ARENA_HI_DEFAULT (HW_WRAM) +#define OSi_WRAM_MAIN_ARENA_LO_DEFAULT (HW_WRAM) + +#endif
\ No newline at end of file diff --git a/arm9/lib/include/nitro.h b/arm9/lib/include/nitro.h new file mode 100644 index 00000000..8cf603f5 --- /dev/null +++ b/arm9/lib/include/nitro.h @@ -0,0 +1,18 @@ +#ifndef POKEDIAMOND_NITRO_H +#define POKEDIAMOND_NITRO_H + +#ifdef __cplusplus +extern "C" { +#endif + +// Include all nitro files +#include "types.h" +#include "consts.h" +#include "os.h" +#include "mmap.h" + +#ifdef __cplusplus +}; +#endif + +#endif //POKEDIAMOND_NITRO_H diff --git a/arm9/lib/include/os.h b/arm9/lib/include/os.h new file mode 100644 index 00000000..591d8db0 --- /dev/null +++ b/arm9/lib/include/os.h @@ -0,0 +1,17 @@ +// +// Created by mart on 4/12/20. +// + +#ifndef POKEDIAMOND_OS_H +#define POKEDIAMOND_OS_H + +#include "types.h" +#include "consts.h" +#include "os_protectionRegion.h" +#include "os_arena.h" +#include "os_alloc.h" +#include "os_system.h" + +void OS_Init(); + +#endif //POKEDIAMOND_OS_H diff --git a/arm9/lib/include/os_alloc.h b/arm9/lib/include/os_alloc.h new file mode 100644 index 00000000..1c4b6122 --- /dev/null +++ b/arm9/lib/include/os_alloc.h @@ -0,0 +1,38 @@ +// +// Created by mart on 4/23/20. +// + +#ifndef POKEDIAMOND_OS_ALLOC_H +#define POKEDIAMOND_OS_ALLOC_H + +#include "types.h" +#include "os_arena.h" + +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 OS_FreeToHeap(OSArenaId id, OSHeapHandle heap, void *ptr); +void* OS_AllocFromHeap(OSArenaId id, OSHeapHandle heap, u32 size); + +#endif //POKEDIAMOND_OS_ALLOC_H diff --git a/arm9/lib/include/os_arena.h b/arm9/lib/include/os_arena.h new file mode 100644 index 00000000..f1893a3d --- /dev/null +++ b/arm9/lib/include/os_arena.h @@ -0,0 +1,41 @@ +// +// Created by red031000 on 2020-04-27. +// + +#ifndef POKEDIAMOND_OS_ARENA_H +#define POKEDIAMOND_OS_ARENA_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; + +void OS_InitArena(); +void OS_InitArenaEx(); +void* OS_GetArenaHi(OSArenaId id); +void* OS_GetArenaLo(OSArenaId id); +void* OS_GetInitArenaHi(OSArenaId id); +void* OS_GetInitArenaLo(OSArenaId id); +void OS_SetArenaHi(OSArenaId id, void *newHi); +void OS_SetArenaLo(OSArenaId id, void *newLo); +void* OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align); +void* OS_AllocFromArenaHi(OSArenaId id, u32 size, u32 align); + +#endif //POKEDIAMOND_OS_ARENA_H diff --git a/arm9/lib/include/os_protectionRegion.h b/arm9/lib/include/os_protectionRegion.h new file mode 100644 index 00000000..7b212934 --- /dev/null +++ b/arm9/lib/include/os_protectionRegion.h @@ -0,0 +1,47 @@ +// +// Created by red031000 on 2020-04-24. +// + +#ifndef POKEDIAMOND_OS_PROTECTIONREGION_H +#define POKEDIAMOND_OS_PROTECTIONREGION_H + +#include "types.h" +#include "consts.h" + +void OS_SetProtectionRegion1(u32 param); +void OS_SetProtectionRegion2(u32 param); + +typedef enum +{ + OSi_PR_BASE_MASK_4KB = 0xfffff000, + OSi_PR_BASE_MASK_8KB = 0xffffe000, + OSi_PR_BASE_MASK_16KB = 0xffffc000, + OSi_PR_BASE_MASK_32KB = 0xffff8000, + OSi_PR_BASE_MASK_64KB = 0xffff0000, + OSi_PR_BASE_MASK_128KB = 0xfffe0000, + OSi_PR_BASE_MASK_256KB = 0xfffc0000, + OSi_PR_BASE_MASK_512KB = 0xfff80000, + OSi_PR_BASE_MASK_1MB = 0xfff00000, + OSi_PR_BASE_MASK_2MB = 0xffe00000, + OSi_PR_BASE_MASK_4MB = 0xffc00000, + OSi_PR_BASE_MASK_8MB = 0xff800000, + OSi_PR_BASE_MASK_16MB = 0xff000000, + OSi_PR_BASE_MASK_32MB = 0xfe000000, + OSi_PR_BASE_MASK_64MB = 0xfc000000, + OSi_PR_BASE_MASK_128MB = 0xf8000000, + OSi_PR_BASE_MASK_256MB = 0xf0000000, + OSi_PR_BASE_MASK_512MB = 0xe0000000, + OSi_PR_BASE_MASK_1GB = 0xc0000000, + OSi_PR_BASE_MASK_2GB = 0x80000000, + OSi_PR_BASE_MASK_4GB = 0x00000000 +} OSiProtectionRegionBaseMask; + +static inline u32 OSi_CalcPRParam(u32 address, u32 size, OSiProtectionRegionBaseMask mask) { + return ((address & mask) | size); +} + +#define OS_SetProtectionRegion(regionNo, address, sizeStr) \ + OS_SetProtectionRegion##regionNo(OSi_CalcPRParam(address, HW_C6_PR_##sizeStr, OSi_PR_BASE_MASK_##sizeStr) \ + | 1) + +#endif //POKEDIAMOND_OS_PROTECTIONREGION_H diff --git a/arm9/lib/include/os_system.h b/arm9/lib/include/os_system.h new file mode 100644 index 00000000..fc6a2f81 --- /dev/null +++ b/arm9/lib/include/os_system.h @@ -0,0 +1,44 @@ +// +// Created by mart on 4/23/20. +// + +#ifndef POKEDIAMOND_OS_SYSTEM_H +#define POKEDIAMOND_OS_SYSTEM_H + +#include "consts.h" + +typedef enum { + OS_PROCMODE_USER=16, + OS_PROCMODE_FIQ=17, + OS_PROCMODE_IRQ=18, + OS_PROCMODE_SVC=19, + OS_PROCMODE_ABORT=23, + OS_PROCMODE_UNDEF=27, + OS_PROCMODE_SYS=31 +} OSProcMode; + +typedef enum { + OS_INTRMODE_IRQ_DISABLE = HW_PSR_IRQ_DISABLE, + OS_INTRMODE_IRQ_ENABLE = 0 +} OSIntrMode_Irq; + +typedef enum { + OS_INTRMODE_FIQ_DISABLE = HW_PSR_FIQ_DISABLE, + OS_INTRMODE_FIQ_ENABLE = 0 +} OSIntrMode_Fiq; + +typedef union { + OSIntrMode_Fiq mode_fiq; + OSIntrMode_Irq mode_irq; +} OSIntrMode; + +OSIntrMode OS_EnableInterrupts(); +OSIntrMode OS_DisableInterrupts(); +OSIntrMode OS_RestoreInterrupts(OSIntrMode state); +OSIntrMode OS_DisableInterrupts_IrqAndFiq(); +OSIntrMode OS_RestoreInterrupts_IrqAndFiq(OSIntrMode state); +OSIntrMode_Irq OS_GetCpsrIrq(); +OSProcMode OS_GetProcMode(); + + +#endif //POKEDIAMOND_OS_SYSTEM_H diff --git a/arm9/lib/include/types.h b/arm9/lib/include/types.h new file mode 100644 index 00000000..5ad2c75e --- /dev/null +++ b/arm9/lib/include/types.h @@ -0,0 +1,40 @@ +#ifndef POKEDIAMOND_NITRO_TYPES_H +#define POKEDIAMOND_NITRO_TYPES_H + +typedef unsigned char u8; +typedef unsigned short int u16; +typedef unsigned long u32; + +typedef signed char s8; +typedef signed short int s16; +typedef signed long s32; + +typedef unsigned long long int u64; +typedef signed long long int s64; + +typedef volatile u8 vu8; +typedef volatile u16 vu16; +typedef volatile u32 vu32; +typedef volatile u64 vu64; + +typedef volatile s8 vs8; +typedef volatile s16 vs16; +typedef volatile s32 vs32; +typedef volatile s64 vs64; + +typedef float f32; +typedef volatile f32 vf32; + +typedef int BOOL; +#define TRUE 1 +#define FALSE 0 + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else // __cplusplus +#define NULL ((void *)0) +#endif // __cplusplus +#endif + +#endif //POKEDIAMOND_NITRO_TYPES_H diff --git a/arm9/lib/src/OS_arena.c b/arm9/lib/src/OS_arena.c new file mode 100644 index 00000000..b4bcbc1c --- /dev/null +++ b/arm9/lib/src/OS_arena.c @@ -0,0 +1,169 @@ +//
+// Created by red031000 on 2020-04-27.
+//
+
+#include "consts.h"
+#include "os_arena.h"
+#include "os_protectionRegion.h"
+
+extern u32 OS_GetConsoleType();
+extern BOOL OSi_MainExArenaEnabled;
+extern BOOL OSi_Initialized; // TODO: located at 0x021d36f0
+void SDK_MAIN_ARENA_LO(); // TODO: technically this should be defined in the lcf
+extern void SDK_SECTION_ARENA_EX_START(); // TODO: technically this should be defined in the lcf
+extern void SDK_SECTION_ARENA_ITCM_START(); // TODO: technically this should be defined in the lcf
+extern void SDK_SECTION_ARENA_DTCM_START(); // TODO: technically this should be defined in the lcf
+extern void SDK_IRQ_STACKSIZE(); // TODO: technically this should be defined in the lcf
+extern void SDK_SYS_STACKSIZE(); // TODO: technically this should be defined in the lcf
+
+void OS_InitArena() {
+ if (OSi_Initialized) {
+ return;
+ }
+ OSi_Initialized = TRUE;
+
+ 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, (void *)0);
+ OS_SetArenaHi(OS_ARENA_MAINEX, (void *)0);
+
+ 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));
+}
+
+void OS_InitArenaEx() {
+ OS_SetArenaHi(2, OS_GetInitArenaHi(OS_ARENA_MAINEX));
+ OS_SetArenaLo(2, OS_GetInitArenaLo(OS_ARENA_MAINEX));
+
+ if (!OSi_MainExArenaEnabled || (OS_GetConsoleType() & OS_CONSOLE_SIZE_MASK) == OS_CONSOLE_SIZE_4MB) {
+ OS_SetProtectionRegion(1, HW_MAIN_MEM, 4MB);
+ OS_SetProtectionRegion(2, HW_MAIN_MEM_MAIN_END, 128KB);
+ }
+}
+
+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) {
+ case OS_ARENA_MAIN:
+ return (void *)OSi_MAIN_ARENA_HI_DEFAULT;
+ case OS_ARENA_MAINEX:
+ if (!OSi_MainExArenaEnabled || (OS_GetConsoleType() & OS_CONSOLE_SIZE_MASK) == OS_CONSOLE_SIZE_4MB) {
+ return (void *)0;
+ } 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)HW_DTCM_IRQ_STACK_END - (s32)SDK_IRQ_STACKSIZE;
+ u32 sysStackLo;
+
+ if (!(s32)SDK_SYS_STACKSIZE) {
+ sysStackLo = HW_DTCM;
+ if (sysStackLo < (u32)SDK_SECTION_ARENA_DTCM_START) {
+ sysStackLo = (u32)SDK_SECTION_ARENA_DTCM_START;
+ }
+ }
+ else if ((s32)SDK_SYS_STACKSIZE < 0) {
+ sysStackLo = (u32)SDK_SECTION_ARENA_DTCM_START - (s32)SDK_SYS_STACKSIZE;
+ }
+ else {
+ sysStackLo = irqStackLo - (s32)SDK_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;
+ default:
+ return NULL;
+ }
+}
+
+void* OS_GetInitArenaLo(OSArenaId id) {
+ switch (id) {
+ case OS_ARENA_MAIN:
+ return (void *)SDK_MAIN_ARENA_LO;
+ case OS_ARENA_MAINEX:
+ if (!OSi_MainExArenaEnabled || (OS_GetConsoleType() & OS_CONSOLE_SIZE_MASK) == OS_CONSOLE_SIZE_4MB) {
+ return NULL;
+ } else {
+ return (void *)SDK_SECTION_ARENA_EX_START;
+ }
+ case OS_ARENA_ITCM:
+ return (void *)SDK_SECTION_ARENA_ITCM_START;
+ case OS_ARENA_DTCM:
+ return (void *)SDK_SECTION_ARENA_DTCM_START;
+ case OS_ARENA_SHARED:
+ return (void *)HW_SHARED_ARENA_LO_DEFAULT;
+ case OS_ARENA_WRAM_MAIN:
+ return (void *)OSi_WRAM_MAIN_ARENA_LO_DEFAULT;
+ default:
+ return NULL;
+ }
+}
+
+void OS_SetArenaHi(OSArenaId id, void* newHi) {
+ OSi_GetArenaInfo().hi[id] = newHi;
+}
+
+void OS_SetArenaLo(OSArenaId id, void* newLo) {
+ OSi_GetArenaInfo().lo[id] = newLo;
+}
+
+void* OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align) {
+ void* ptr;
+ u8* arenaLo;
+ ptr = OS_GetArenaLo(id);
+ if (!ptr) {
+ 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 id, u32 size, u32 align) {
+ void* ptr;
+ u8* arenaHi;
+
+ arenaHi = OS_GetArenaHi(id);
+ if (!arenaHi) {
+ return NULL;
+ }
+
+ arenaHi = (u8 *)OSi_TRUNC(arenaHi, align);
+ arenaHi -= size;
+ arenaHi = ptr = (void *)OSi_TRUNC(arenaHi, align);
+
+ if (arenaHi < (u8*)OS_GetArenaLo(id)) {
+ return NULL;
+ }
+
+ OS_SetArenaHi(id, arenaHi);
+
+ return ptr;
+}
|