diff options
Diffstat (limited to 'arm9/lib')
-rw-r--r-- | arm9/lib/include/MB_mb.h | 45 | ||||
-rw-r--r-- | arm9/lib/include/OS_init.h | 1 | ||||
-rw-r--r-- | arm9/lib/include/OS_reset.h | 20 | ||||
-rw-r--r-- | arm9/lib/include/OS_system.h | 1 | ||||
-rw-r--r-- | arm9/lib/include/PXI_fifo.h | 33 | ||||
-rw-r--r-- | arm9/lib/include/consts.h | 2 | ||||
-rw-r--r-- | arm9/lib/include/mmap.h | 2 | ||||
-rw-r--r-- | arm9/lib/src/OS_init.c | 1 | ||||
-rw-r--r-- | arm9/lib/src/OS_reset.c | 63 | ||||
-rw-r--r-- | arm9/lib/src/OS_system.c | 1 |
10 files changed, 167 insertions, 2 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_init.h b/arm9/lib/include/OS_init.h index 6fbfc826..0c74035d 100644 --- a/arm9/lib/include/OS_init.h +++ b/arm9/lib/include/OS_init.h @@ -16,6 +16,7 @@ #include "OS_arena.h" #include "OS_alloc.h" #include "OS_system.h" +#include "OS_reset.h" void OS_Init(); 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/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 0e5066de..c37d6269 100644 --- a/arm9/lib/include/consts.h +++ b/arm9/lib/include/consts.h @@ -48,6 +48,8 @@ #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 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/src/OS_init.c b/arm9/lib/src/OS_init.c index 90b01ffa..e2658421 100644 --- a/arm9/lib/src/OS_init.c +++ b/arm9/lib/src/OS_init.c @@ -14,7 +14,6 @@ extern void MI_Init(); extern void OS_InitVAlarm(); extern void OSi_InitVramExclusive(); extern void OS_InitThread(); -extern void OS_InitReset(); extern void CTRDG_Init(); extern void CARD_Init(); extern void PM_Init(); diff --git a/arm9/lib/src/OS_reset.c b/arm9/lib/src/OS_reset.c new file mode 100644 index 00000000..9f492328 --- /dev/null +++ b/arm9/lib/src/OS_reset.c @@ -0,0 +1,63 @@ +// +// Created by red031000 on 2020-05-06. +// + +#include "function_target.h" +#include "OS_reset.h" +#include "MB_mb.h" + +extern u16 OSi_IsInitReset; +extern vu16 OSi_IsResetOccurred; +extern void PXI_Init(); +extern u32 PXI_IsCallbackReady(u32 param1, u32 param2); +extern void PXI_SetFifoRecvCallback(u32 param1, void* callback); +extern void OS_Terminate(); +extern u32 PXI_SendWordByFifo(u32 param1, u32 data, u32 param2); +extern void CARD_LockRom(u16 lockId); +extern u32 OS_GetLockID(); +extern void MI_StopDma(u32 dma); +extern void OS_SetIrqMask(u32 mask); +extern void OS_ResetRequestIrqMask(u32 mask); +extern void OSi_DoResetSystem(); + +ARM_FUNC void OS_InitReset() { + if (OSi_IsInitReset) { + return; + } + OSi_IsInitReset = TRUE; + PXI_Init(); + while (!PXI_IsCallbackReady(PXI_FIFO_TAG_OS, PXI_PROC_ARM7)) { } + + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_OS, OSi_CommonCallback); +} + +ARM_FUNC static void OSi_CommonCallback(PXIFifoTag tag, u32 data, BOOL err) { +#pragma unused(tag, err) //needed because otherwise -W all errors + u16 command = (u16)((data & OS_PXI_COMMAND_MASK) >> OS_PXI_COMMAND_SHIFT); + if (command == OS_PXI_COMMAND_RESET) + { + OSi_IsResetOccurred = TRUE; + return; + } + OS_Terminate(); +} + +ARM_FUNC static void OSi_SendToPxi(u16 data) { + while (PXI_SendWordByFifo(PXI_FIFO_TAG_OS, (u32)data << 0x8, FALSE)) {} +} + +ARM_FUNC void OS_ResetSystem(u32 parameter) { + if (MB_IsMultiBootChild()) { + OS_Terminate(); + } + CARD_LockRom((u16)OS_GetLockID()); + MI_StopDma(0); + MI_StopDma(1); + MI_StopDma(2); + MI_StopDma(3); + OS_SetIrqMask(0x40000); + OS_ResetRequestIrqMask((u32)~0); + *(u32 *)HW_RESET_PARAMETER_BUF = parameter; + OSi_SendToPxi(OS_PXI_COMMAND_RESET); + OSi_DoResetSystem(); //oh boy this is in itcm, that's gonna be fun to deal with Kappa +}
\ No newline at end of file diff --git a/arm9/lib/src/OS_system.c b/arm9/lib/src/OS_system.c index c2b08681..e5dfcb47 100644 --- a/arm9/lib/src/OS_system.c +++ b/arm9/lib/src/OS_system.c @@ -2,7 +2,6 @@ // Created by mart on 4/23/20. // -#include "function_target.h" #include "OS_system.h" ARM_FUNC asm OSIntrMode OS_EnableInterrupts() { |