summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorred031000 <rubenru09@aol.com>2020-04-24 18:15:28 +0100
committerred031000 <rubenru09@aol.com>2020-04-24 18:15:28 +0100
commite028229b82c0e20aa9a8c0a88eece2a41f4a0fd4 (patch)
tree74960adfb31cddcf30675a6b08e33443c9cbc98f
parent8ef3e3d8e1ec8ea4596e50e8453bf42a0ca69fc1 (diff)
protection regions
-rw-r--r--include/nitro/consts.h25
-rw-r--r--include/nitro/mmap.h4
-rw-r--r--include/nitro/os.h1
-rw-r--r--include/nitro/os_alloc.c20
-rw-r--r--include/nitro/os_protectionRegion.c17
-rw-r--r--include/nitro/os_protectionRegion.h47
-rw-r--r--undefined_syms.txt2
7 files changed, 99 insertions, 17 deletions
diff --git a/include/nitro/consts.h b/include/nitro/consts.h
index 3592500a..6fc71be2 100644
--- a/include/nitro/consts.h
+++ b/include/nitro/consts.h
@@ -13,6 +13,31 @@
#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))
diff --git a/include/nitro/mmap.h b/include/nitro/mmap.h
index 82437e64..cbf54451 100644
--- a/include/nitro/mmap.h
+++ b/include/nitro/mmap.h
@@ -5,6 +5,7 @@
#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
@@ -18,8 +19,9 @@
#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 OSi_MAIN_ARENA_HI_DEFAULT (HW_MAIN_MEM + HW_MAIN_MEM_MAIN_SIZE)
+#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)
diff --git a/include/nitro/os.h b/include/nitro/os.h
index f1422647..b8843a73 100644
--- a/include/nitro/os.h
+++ b/include/nitro/os.h
@@ -7,6 +7,7 @@
#include "types.h"
#include "consts.h"
+#include "os_protectionRegion.h"
#include "os_alloc.h"
#include "os_system.h"
diff --git a/include/nitro/os_alloc.c b/include/nitro/os_alloc.c
index b241e399..b6749f27 100644
--- a/include/nitro/os_alloc.c
+++ b/include/nitro/os_alloc.c
@@ -5,16 +5,13 @@
#include "os_alloc.h"
#include "consts.h"
#include "os_system.h"
+#include "os_protectionRegion.h"
extern BOOL OSi_MainExArenaEnabled;
extern BOOL OSi_Initialized; // TODO: located at 0x021d36f0
extern u32 OS_GetConsoleType();
-extern u32 OS_CONSOLE_SIZE_MASK;
-extern u32 OS_CONSOLE_SIZE_4MB;
extern Cell* DLInsert(Cell* list, Cell* cell);
extern Cell* DLAddFront(Cell* list, Cell* cell);
-extern void OS_SetProtectionRegion1(u32 param);
-extern void OS_SetProtectionRegion2(u32 param);
void* OSiHeapInfo[OS_ARENA_MAX] = {
NULL,
@@ -394,19 +391,14 @@ _020CC5B8:
bx lr
}
#else
-void OS_InitArenaEx() {
- void* uVar1;
+void OS_InitArenaEx() { //todo figure out what compiler settings will get this to match
+ OS_SetArenaHi(2, OS_GetInitArenaHi(OS_ARENA_MAINEX));
+ OS_SetArenaLo(2, OS_GetInitArenaLo(OS_ARENA_MAINEX));
- uVar1 = OS_GetInitArenaHi(OS_ARENA_MAINEX);
- OS_SetArenaHi(2,uVar1);
- uVar1 = OS_GetInitArenaLo(OS_ARENA_MAINEX);
- OS_SetArenaLo(2,uVar1);
if (!OSi_MainExArenaEnabled || (OS_GetConsoleType() & OS_CONSOLE_SIZE_MASK) == OS_CONSOLE_SIZE_4MB) {
- return;
+ OS_SetProtectionRegion(1, HW_MAIN_MEM, 4MB);
+ OS_SetProtectionRegion(2, HW_MAIN_MEM_MAIN_END, 128KB);
}
- // TODO:
- // OS_SetProtectionRegion1(&UNK_0200002b);
- // OS_SetProtectionRegion2(0x023e0021);
}
#endif
diff --git a/include/nitro/os_protectionRegion.c b/include/nitro/os_protectionRegion.c
new file mode 100644
index 00000000..b70f9056
--- /dev/null
+++ b/include/nitro/os_protectionRegion.c
@@ -0,0 +1,17 @@
+//
+// Created by red031000 on 2020-04-24.
+//
+
+#include "os_protectionRegion.h"
+
+asm void OS_SetProtectionRegion1(u32 param)
+{
+ mcr p15, 0x0, r0, c6, c1, 0x0
+ bx lr
+}
+
+asm void OS_SetProtectionRegion2(u32 param)
+{
+ mcr p15, 0x0, r0, c6, c2, 0x0
+ bx lr
+} \ No newline at end of file
diff --git a/include/nitro/os_protectionRegion.h b/include/nitro/os_protectionRegion.h
new file mode 100644
index 00000000..7b212934
--- /dev/null
+++ b/include/nitro/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/undefined_syms.txt b/undefined_syms.txt
index 95f239fb..a6954272 100644
--- a/undefined_syms.txt
+++ b/undefined_syms.txt
@@ -290,8 +290,6 @@ FUN_020C9418 = 0x020C9418;
FUN_020C9480 = 0x020C9480;
FUN_020C94E8 = 0x020C94E8;
FUN_020C9550 = 0x020C9550;
-OS_SetProtectionRegion1 = 0x020CC9EC;
-OS_SetProtectionRegion2 = 0x020CC9F4;
OS_SpinWait = 0x020CD380;
FUN_020D5150 = 0x020D5150;
FUN_020D5168 = 0x020D5168;