summaryrefslogtreecommitdiff
path: root/arm9/lib/include
diff options
context:
space:
mode:
Diffstat (limited to 'arm9/lib/include')
-rw-r--r--arm9/lib/include/MB_mb.h45
-rw-r--r--arm9/lib/include/OS_emulator.h13
-rw-r--r--arm9/lib/include/OS_init.h5
-rw-r--r--arm9/lib/include/OS_interrupt.h29
-rw-r--r--arm9/lib/include/OS_reset.h20
-rw-r--r--arm9/lib/include/OS_system.h1
-rw-r--r--arm9/lib/include/OS_tcm.h12
-rw-r--r--arm9/lib/include/OS_terminate_proc.h11
-rw-r--r--arm9/lib/include/OS_thread.h13
-rw-r--r--arm9/lib/include/PXI_fifo.h33
-rw-r--r--arm9/lib/include/consts.h22
-rw-r--r--arm9/lib/include/fx.h18
-rw-r--r--arm9/lib/include/mmap.h2
-rw-r--r--arm9/lib/include/registers.h55
14 files changed, 248 insertions, 31 deletions
diff --git a/arm9/lib/include/MB_mb.h b/arm9/lib/include/MB_mb.h
new file mode 100644
index 00000000..128ea480
--- /dev/null
+++ b/arm9/lib/include/MB_mb.h
@@ -0,0 +1,45 @@
+//
+// Created by red031000 on 2020-05-06.
+//
+
+#ifndef POKEDIAMOND_MB_MB_H
+#define POKEDIAMOND_MB_MB_H
+
+#include "consts.h"
+
+#define MB_TYPE_ILLEGAL 0
+#define MB_TYPE_NORMAL 1
+#define MB_TYPE_MULTIBOOT 2
+
+typedef struct {
+ u16 length;
+ u16 rssi;
+ u16 bssid[3];
+ u16 ssidLength;
+ u8 ssid[32];
+ u16 capaInfo;
+ struct {
+ u16 basic;
+ u16 support;
+ } rateSet;
+ u16 beaconperiod;
+ u16 dtimPeriod;
+ u16 channel;
+ u16 cfpPeriod;
+ u16 cfpMaxDuration;
+} MBParentBssDesc;
+
+typedef struct {
+ u16 boot_type;
+ MBParentBssDesc parent_bss_desc;
+} MBParam;
+
+static inline const MBParam *MB_GetMultiBootParam() {
+ return (const MBParam *)HW_WM_BOOT_BUF;
+}
+
+static inline BOOL MB_IsMultiBootChild() {
+ return MB_GetMultiBootParam()->boot_type == MB_TYPE_MULTIBOOT;
+}
+
+#endif //POKEDIAMOND_MB_MB_H
diff --git a/arm9/lib/include/OS_emulator.h b/arm9/lib/include/OS_emulator.h
new file mode 100644
index 00000000..54105258
--- /dev/null
+++ b/arm9/lib/include/OS_emulator.h
@@ -0,0 +1,13 @@
+//
+// Created by red031000 on 2020-05-05.
+//
+
+#ifndef POKEDIAMOND_OS_EMULATOR_H
+#define POKEDIAMOND_OS_EMULATOR_H
+
+#include "consts.h"
+
+BOOL OS_IsRunOnEmulator();
+u32 OS_GetConsoleType();
+
+#endif //POKEDIAMOND_OS_EMULATOR_H
diff --git a/arm9/lib/include/OS_init.h b/arm9/lib/include/OS_init.h
index 1ff2837c..dd2b20c7 100644
--- a/arm9/lib/include/OS_init.h
+++ b/arm9/lib/include/OS_init.h
@@ -7,13 +7,18 @@
#include "types.h"
#include "consts.h"
+#include "OS_tcm.h"
#include "OS_spinLock.h"
#include "OS_thread.h"
#include "OS_protectionRegion.h"
#include "OS_entropy.h"
+#include "OS_emulator.h"
#include "OS_arena.h"
#include "OS_alloc.h"
#include "OS_system.h"
+#include "OS_terminate_proc.h"
+#include "OS_interrupt.h"
+#include "OS_reset.h"
void OS_Init();
diff --git a/arm9/lib/include/OS_interrupt.h b/arm9/lib/include/OS_interrupt.h
new file mode 100644
index 00000000..b8425b4e
--- /dev/null
+++ b/arm9/lib/include/OS_interrupt.h
@@ -0,0 +1,29 @@
+//
+// Created by red031000 on 2020-05-07.
+//
+
+#ifndef POKEDIAMOND_OS_INTERRUPT_H
+#define POKEDIAMOND_OS_INTERRUPT_H
+
+#include "types.h"
+
+typedef void (*OSIrqFunction) (void);
+
+typedef struct
+{
+ void (*func) (void *);
+ u32 enable;
+ void* arg;
+} OSIrqCallbackInfo;
+
+typedef u32 OSIrqMask;
+
+extern OSIrqFunction OS_IRQTable[];
+extern OSIrqCallbackInfo OSi_IrqCallbackInfo[7+1];
+
+void OS_InitIrqTable();
+void OS_SetIrqFunction(OSIrqMask intrBit, OSIrqFunction function);
+OSIrqFunction OS_GetIrqFunction(OSIrqMask intrBit);
+void OSi_EnterDmaCallback(u32 dmaNo, void (*callback) (void *), void *arg);
+
+#endif //POKEDIAMOND_OS_INTERRUPT_H
diff --git a/arm9/lib/include/OS_reset.h b/arm9/lib/include/OS_reset.h
new file mode 100644
index 00000000..c3b60c98
--- /dev/null
+++ b/arm9/lib/include/OS_reset.h
@@ -0,0 +1,20 @@
+//
+// Created by red031000 on 2020-05-06.
+//
+
+#ifndef POKEDIAMOND_OS_RESET_H
+#define POKEDIAMOND_OS_RESET_H
+
+#include "consts.h"
+#include "PXI_fifo.h"
+
+#define OS_PXI_COMMAND_MASK 0x7f00
+#define OS_PXI_COMMAND_SHIFT 8
+#define OS_PXI_COMMAND_RESET 0x10
+
+void OS_InitReset();
+void OSi_CommonCallback(PXIFifoTag tag, u32 data, BOOL err);
+void OSi_SendToPxi(u16 data);
+void OS_ResetSystem(u32 parameter);
+
+#endif //POKEDIAMOND_OS_RESET_H
diff --git a/arm9/lib/include/OS_system.h b/arm9/lib/include/OS_system.h
index 93903315..9a79c0d1 100644
--- a/arm9/lib/include/OS_system.h
+++ b/arm9/lib/include/OS_system.h
@@ -6,6 +6,7 @@
#define POKEDIAMOND_OS_SYSTEM_H
#include "consts.h"
+#include "function_target.h"
typedef enum {
OS_PROCMODE_USER=16,
diff --git a/arm9/lib/include/OS_tcm.h b/arm9/lib/include/OS_tcm.h
new file mode 100644
index 00000000..7112ca0e
--- /dev/null
+++ b/arm9/lib/include/OS_tcm.h
@@ -0,0 +1,12 @@
+//
+// Created by red031000 on 2020-05-05.
+//
+
+#ifndef POKEDIAMOND_OS_TCM_H
+#define POKEDIAMOND_OS_TCM_H
+
+#include "consts.h"
+
+u32 OS_GetDTCMAddress();
+
+#endif //POKEDIAMOND_OS_TCM_H
diff --git a/arm9/lib/include/OS_terminate_proc.h b/arm9/lib/include/OS_terminate_proc.h
new file mode 100644
index 00000000..26741e5d
--- /dev/null
+++ b/arm9/lib/include/OS_terminate_proc.h
@@ -0,0 +1,11 @@
+//
+// Created by red031000 on 2020-05-07.
+//
+
+#ifndef POKEDIAMOND_OS_TERMINATE_PROC_H
+#define POKEDIAMOND_OS_TERMINATE_PROC_H
+
+void OS_Terminate();
+void OS_Halt();
+
+#endif //POKEDIAMOND_OS_TERMINATE_PROC_H
diff --git a/arm9/lib/include/OS_thread.h b/arm9/lib/include/OS_thread.h
index 4fb70bf7..49ae9f15 100644
--- a/arm9/lib/include/OS_thread.h
+++ b/arm9/lib/include/OS_thread.h
@@ -7,6 +7,14 @@
typedef struct _OSThread OSThread;
+struct _OSThreadQueue
+{
+ OSThread *head;
+ OSThread *tail;
+};
+
+typedef struct _OSThreadQueue OSThreadQueue;
+
typedef struct OSThreadInfo {
u16 isNeedRescheduling;
u16 irqDepth;
@@ -20,4 +28,9 @@ struct _OSThread
u8 padding[0x80]; //todo: not the correct size but idfk
};
+static inline void OS_InitThreadQueue(OSThreadQueue * queue)
+{
+ queue->head = queue->tail = NULL;
+}
+
#endif //POKEDIAMOND_OS_THREAD_H
diff --git a/arm9/lib/include/PXI_fifo.h b/arm9/lib/include/PXI_fifo.h
new file mode 100644
index 00000000..1d45dda2
--- /dev/null
+++ b/arm9/lib/include/PXI_fifo.h
@@ -0,0 +1,33 @@
+//
+// Created by red031000 on 2020-05-06.
+//
+
+#ifndef POKEDIAMOND_PXI_FIFO_H
+#define POKEDIAMOND_PXI_FIFO_H
+
+#include "function_target.h"
+
+ENUMS_ALWAYS_INT_ON
+typedef enum {
+ PXI_FIFO_TAG_EX = 0, // Extension format
+ PXI_FIFO_TAG_USER_0, // for application programmer, use it in free
+ PXI_FIFO_TAG_USER_1, // for application programmer, use it in free
+ PXI_FIFO_TAG_SYSTEM, // SDK inner usage
+ PXI_FIFO_TAG_NVRAM, // NVRAM
+ PXI_FIFO_TAG_RTC, // RTC
+ PXI_FIFO_TAG_TOUCHPANEL, // Touch Panel
+ PXI_FIFO_TAG_SOUND, // Sound
+ PXI_FIFO_TAG_PM, // Power Management
+ PXI_FIFO_TAG_MIC, // Microphone
+ PXI_FIFO_TAG_WM, // Wireless Manager
+ PXI_FIFO_TAG_FS, // File System
+ PXI_FIFO_TAG_OS, // OS
+ PXI_FIFO_TAG_CTRDG, // Cartridge
+ PXI_FIFO_TAG_CARD, // Card
+ PXI_FIFO_TAG_WVR, // Control driving wireless library
+ PXI_FIFO_TAG_CTRDG_Ex, // Cartridge Ex
+ PXI_MAX_FIFO_TAG = 32 // MAX FIFO TAG
+} PXIFifoTag;
+ENUMS_ALWAYS_INT_RESET
+
+#endif //POKEDIAMOND_PXI_FIFO_H
diff --git a/arm9/lib/include/consts.h b/arm9/lib/include/consts.h
index e07fe323..b99b4148 100644
--- a/arm9/lib/include/consts.h
+++ b/arm9/lib/include/consts.h
@@ -6,6 +6,7 @@
#define POKEDIAMOND_CONSTS_H
#include "mmap.h"
+#include "registers.h"
#define HW_PSR_CPU_MODE_MASK 0x1f // CPU mode
@@ -13,19 +14,6 @@
#define HW_PSR_DISABLE_IRQ 0x80 // Disable IRQ
#define HW_PSR_DISABLE_IRQ_FIQ 0xc0 // Disable FIQ and IRQ
-#define HW_REG_BASE 0x04000000
-#define REG_VCOUNT_OFFSET 0x006
-#define REG_VCOUNT_ADDR (HW_REG_BASE + REG_VCOUNT_OFFSET)
-#define reg_GX_VCOUNT (*(REGType16v *)REG_VCOUNT_ADDR)
-
-#define REG_KEYINPUT_OFFSET 0x130
-#define REG_KEYINPUT_ADDR (HW_REG_BASE + REG_KEYINPUT_OFFSET)
-#define reg_PAD_KEYINPUT (*(REGType16v *)REG_KEYINPUT_ADDR)
-
-#define REG_GXSTAT_OFFSET 0x600
-#define REG_GXSTAT_ADDR (HW_REG_BASE + REG_GXSTAT_OFFSET)
-#define reg_G3X_GXSTAT (*(REGType32v *)REG_GXSTAT_ADDR)
-
#define HW_C6_PR_4KB 0x16
#define HW_C6_PR_8KB 0x18
#define HW_C6_PR_16KB 0x1a
@@ -48,9 +36,17 @@
#define HW_C6_PR_2GB 0x3c
#define HW_C6_PR_4GB 0x3e
+#define PXI_PROC_ARM7 0x01
+
+#define OSi_CONSOLE_NOT_DETECT 0xffffffff
+
+#define OS_CONSOLE_NITRO 0x80000000
+#define OS_CONSOLE_DEV_CARD 0x02000000
#define OS_CONSOLE_SIZE_MASK 0x00000003
#define OS_CONSOLE_SIZE_4MB 0x00000001
+#define OSi_TCM_REGION_BASE_MASK 0xfffff000
+
#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/arm9/lib/include/fx.h b/arm9/lib/include/fx.h
index 7e74d079..b1c3aa88 100644
--- a/arm9/lib/include/fx.h
+++ b/arm9/lib/include/fx.h
@@ -46,24 +46,6 @@ typedef s64 fx64c;
#define FX64C_INT_ABS(x) FX_INT_ABS(FX64C, x)
#define FX64C_FRAC(x) FX_FRAC(FX64C, x)
-
-#define HW_REG_DIVCNT 0x04000280
-#define HW_REG_DIV_NUMER 0x04000290
-#define HW_REG_DIV_DENOM 0x04000298
-#define HW_REG_DIV_RESULT 0x040002A0
-#define HW_REG_DIVREM_RESULT 0x040002A8
-
-#define HW_REG_SQRTCNT 0x040002B0
-#define HW_REG_SQRT_RESULT 0x040002B4
-#define HW_REG_SQRT_PARAM 0x040002B8
-
-#define SETREG16(x, y) ((*(vu16 *)x) = y)
-#define SETREG32(x, y) ((*(vu32 *)x) = y)
-#define SETREG64(x, y) ((*(vu64 *)x) = y)
-#define READREG16(x) (*(vu16 *)x)
-#define READREG32(x) (*(vu32 *)x)
-#define READREG64(x) (*(vu64 *)x)
-
#define FX32_MUL(a, b) ((fx32)(((fx64)a * b) >> FX32_INT_SHIFT))
#define FX32_MUL_ADD_MUL(a, b, c, d) ((fx32)(((fx64)a * b + (fx64)c * d) >> FX32_INT_SHIFT))
//the extra term here is for rounding
diff --git a/arm9/lib/include/mmap.h b/arm9/lib/include/mmap.h
index d94df843..1f8f37f9 100644
--- a/arm9/lib/include/mmap.h
+++ b/arm9/lib/include/mmap.h
@@ -23,6 +23,8 @@ extern u32 SDK_AUTOLOAD_DTCM_START[];
#define HW_CARD_ROM_HEADER_SIZE 0x00000160
#define HW_DOWNLOAD_PARAMETER_SIZE 0x00000020
+#define HW_RESET_PARAMETER_BUF (HW_MAIN_MEM + 0x007ffc20)
+#define HW_WM_BOOT_BUF (HW_MAIN_MEM + 0x007ffc40)
#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
diff --git a/arm9/lib/include/registers.h b/arm9/lib/include/registers.h
new file mode 100644
index 00000000..45b36334
--- /dev/null
+++ b/arm9/lib/include/registers.h
@@ -0,0 +1,55 @@
+//
+// Created by red031000 on 2020-05-06.
+//
+
+#ifndef POKEDIAMOND_REGISTERS_H
+#define POKEDIAMOND_REGISTERS_H
+
+#include "types.h"
+
+#define HW_REG_BASE 0x04000000
+#define REG_VCOUNT_OFFSET 0x006
+#define REG_VCOUNT_ADDR (HW_REG_BASE + REG_VCOUNT_OFFSET)
+#define reg_GX_VCOUNT (*(REGType16v *)REG_VCOUNT_ADDR)
+
+#define REG_KEYINPUT_OFFSET 0x130
+#define REG_KEYINPUT_ADDR (HW_REG_BASE + REG_KEYINPUT_OFFSET)
+#define reg_PAD_KEYINPUT (*(REGType16v *)REG_KEYINPUT_ADDR)
+
+#define REG_DIVCNT_OFFSET 0x280
+#define REG_DIVCNT_ADDR (HW_REG_BASE + REG_DIVCNT_OFFSET)
+#define reg_CP_DIVCNT (*(REGType16v *)REG_DIVCNT_ADDR)
+
+#define REG_DIV_NUMER_OFFSET 0x290
+#define REG_DIV_NUMER_ADDR (HW_REG_BASE + REG_DIV_NUMER_OFFSET)
+#define reg_CP_DIV_NUMER (*(REGType64v *)REG_DIV_NUMER_ADDR)
+
+#define REG_DIV_DENOM_OFFSET 0x298
+#define REG_DIV_DENOM_ADDR (HW_REG_BASE + REG_DIV_DENOM_OFFSET)
+#define reg_CP_DIV_DENOM (*(REGType64v *)REG_DIV_DENOM_ADDR)
+
+#define REG_DIV_RESULT_OFFSET 0x2A0
+#define REG_DIV_RESULT_ADDR (HW_REG_BASE + REG_DIV_RESULT_OFFSET)
+#define reg_CP_DIV_RESULT (*(REGType64v *)REG_DIV_RESULT_ADDR)
+
+#define REG_DIVREM_RESULT_OFFSET 0x2A8
+#define REG_DIVREM_RESULT_ADDR (HW_REG_BASE + REG_DIVREM_RESULT_OFFSET)
+#define reg_CP_DIVREM_RESULT (*(REGType64v *)REG_DIVREM_RESULT_ADDR)
+
+#define REG_SQRTCNT_OFFSET 0x2B0
+#define REG_SQRTCNT_ADDR (HW_REG_BASE + REG_SQRTCNT_OFFSET)
+#define reg_CP_SQRTCNT (*(REGType16v *)REG_SQRTCNT_ADDR)
+
+#define REG_SQRT_RESULT_OFFSET 0x2B4
+#define REG_SQRT_RESULT_ADDR (HW_REG_BASE + REG_SQRT_RESULT_OFFSET)
+#define reg_CP_SQRT_RESULT (*(REGType32v *)REG_SQRT_RESULT_ADDR)
+
+#define REG_SQRT_PARAM_OFFSET 0x2B8
+#define REG_SQRT_PARAM_ADDR (HW_REG_BASE + REG_SQRT_PARAM_OFFSET)
+#define reg_CP_SQRT_PARAM (*(REGType64v *)REG_SQRT_PARAM_ADDR)
+
+#define REG_GXSTAT_OFFSET 0x600
+#define REG_GXSTAT_ADDR (HW_REG_BASE + REG_GXSTAT_OFFSET)
+#define reg_G3X_GXSTAT (*(REGType32v *)REG_GXSTAT_ADDR)
+
+#endif //POKEDIAMOND_REGISTERS_H