summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/nitro/mmap.h11
-rw-r--r--include/nitro/os_arena.c31
2 files changed, 35 insertions, 7 deletions
diff --git a/include/nitro/mmap.h b/include/nitro/mmap.h
index 79f0bae5..14820c39 100644
--- a/include/nitro/mmap.h
+++ b/include/nitro/mmap.h
@@ -1,6 +1,10 @@
#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
@@ -13,6 +17,9 @@
#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
@@ -22,6 +29,10 @@
#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)
diff --git a/include/nitro/os_arena.c b/include/nitro/os_arena.c
index 0536ec7f..31d66289 100644
--- a/include/nitro/os_arena.c
+++ b/include/nitro/os_arena.c
@@ -9,10 +9,12 @@
extern u32 OS_GetConsoleType();
extern BOOL OSi_MainExArenaEnabled;
extern BOOL OSi_Initialized; // TODO: located at 0x021d36f0
-extern u32 SDK_MAIN_ARENA_LO; // TODO: technically this should be defined in the lcf
-extern u32 SDK_SECTION_ARENA_EX_START; // TODO: technically this should be defined in the lcf
-extern u32 SDK_SECTION_ARENA_ITCM_START; // TODO: technically this should be defined in the lcf
-extern u32 SDK_SECTION_ARENA_DTCM_START; // TODO: technically this should be defined in the lcf
+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
#ifdef MATCH_ASM
asm void OS_InitArena() {
@@ -147,7 +149,7 @@ _020CC5B8:
bx lr
}
#else
-void OS_InitArenaEx() { //todo figure out what compiler settings will get this to match
+void OS_InitArenaEx() {
OS_SetArenaHi(2, OS_GetInitArenaHi(OS_ARENA_MAINEX));
OS_SetArenaLo(2, OS_GetInitArenaLo(OS_ARENA_MAINEX));
@@ -282,7 +284,22 @@ void* OS_GetInitArenaHi(OSArenaId id) {
case OS_ARENA_ITCM:
return (void *)HW_ITCM_ARENA_HI_DEFAULT;
case OS_ARENA_DTCM:
- return (void *)0x027e0080; //todo pretty sure this is incorrect, no constant and doesn't match
+ 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:
@@ -393,7 +410,7 @@ asm void OS_SetArenaHi(OSArenaId id, void* newHi) {
}
#else
void OS_SetArenaHi(OSArenaId id, void* newHi) {
- OSi_GetArenaInfo().lo[id] = newHi;
+ OSi_GetArenaInfo().hi[id] = newHi;
}
#endif