diff options
-rw-r--r-- | arm9/asm/OS_entropy.s | 68 | ||||
-rw-r--r-- | arm9/lib/include/OS_entropy.h | 27 | ||||
-rw-r--r-- | arm9/lib/include/OS_init.h | 3 | ||||
-rw-r--r-- | arm9/lib/include/OS_spinLock.h | 14 | ||||
-rw-r--r-- | arm9/lib/include/OS_thread.h | 23 | ||||
-rw-r--r-- | arm9/lib/include/consts.h | 13 | ||||
-rw-r--r-- | arm9/lib/include/mmap.h | 51 | ||||
-rw-r--r-- | arm9/lib/include/types.h | 10 | ||||
-rw-r--r-- | arm9/lib/src/OS_entropy.c | 22 |
9 files changed, 163 insertions, 68 deletions
diff --git a/arm9/asm/OS_entropy.s b/arm9/asm/OS_entropy.s deleted file mode 100644 index 839d54f9..00000000 --- a/arm9/asm/OS_entropy.s +++ /dev/null @@ -1,68 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - - .text - - arm_func_start OS_GetLowEntropyData -OS_GetLowEntropyData: ; 0x020CD754 - stmdb sp!, {r4-r7,lr} - sub sp, sp, #0x4 - ldr r1, _020CD82C ; =0x04000006 - ldr r2, _020CD830 ; =0x027FFC00 - ldrh r7, [r1, #0x0] - add r4, r2, #0x80 - mov r6, r0 - add r5, r4, #0x74 - bl OS_GetTickLo - orr r0, r0, r7, lsl #0x10 - str r0, [r6, #0x0] - ldr r1, _020CD834 ; =OSi_TickCounter - ldr r0, _020CD830 ; =0x027FFC00 - ldr r3, [r1, #0x0] - ldrh r5, [r5, #0x4] - ldr r2, [r1, #0x4] - ldr r2, _020CD838 ; =0x04000600 - eor r3, r3, r5, lsl #0x10 - str r3, [r6, #0x4] - ldr r3, [r1, #0x0] - ldr r3, [r1, #0x4] - ldr r1, [r4, #0x74] - ldr r4, [r0, #0x3c] - eor r1, r3, r1 - eor r1, r4, r1 - str r1, [r6, #0x8] - ldr r3, [r6, #0x8] - ldr r2, [r2, #0x0] - add r1, r0, #0x300 - eor r2, r3, r2 - str r2, [r6, #0x8] - ldr r2, [r0, #0x1e8] - ldr r3, _020CD83C ; =0x04000130 - str r2, [r6, #0xc] - ldr r4, [r0, #0x1ec] - ldr r2, _020CD840 ; =0x027FFFA8 - str r4, [r6, #0x10] - ldrh r4, [r1, #0x94] - ldr r0, [r0, #0x390] - eor r0, r0, r4, lsl #0x10 - str r0, [r6, #0x14] - ldrh r4, [r1, #0xaa] - ldrh r0, [r1, #0xac] - orr r0, r0, r4, lsl #0x10 - str r0, [r6, #0x18] - ldrh r3, [r3, #0x0] - ldrh r0, [r2, #0x0] - ldrh r1, [r1, #0x98] - orr r0, r3, r0 - orr r0, r0, r1, lsl #0x10 - str r0, [r6, #0x1c] - add sp, sp, #0x4 - ldmia sp!, {r4-r7,lr} - bx lr - .balign 4 -_020CD82C: .word 0x04000006 -_020CD830: .word 0x027FFC00 -_020CD834: .word OSi_TickCounter -_020CD838: .word 0x04000600 -_020CD83C: .word 0x04000130 -_020CD840: .word 0x027FFFA8 diff --git a/arm9/lib/include/OS_entropy.h b/arm9/lib/include/OS_entropy.h new file mode 100644 index 00000000..b4695a72 --- /dev/null +++ b/arm9/lib/include/OS_entropy.h @@ -0,0 +1,27 @@ +// +// Created by red031000 on 2020-05-03. +// + +#ifndef POKEDIAMOND_OS_ENTROPY_H +#define POKEDIAMOND_OS_ENTROPY_H + +#include "consts.h" + +void OS_GetLowEntropyData(u32 * arr); + +typedef struct NVRAMConfig{ + u8 ncd[110]; // todo: typeof NVRAMConfigData + u16 saveCount; + u16 rc16; +} NVRAMConfig; + +extern vu64 OSi_TickCounter; + +extern u16 OS_GetTickLo(); + +static inline s32 GX_GetVCount() +{ + return reg_GX_VCOUNT; +} + +#endif //POKEDIAMOND_OS_ENTROPY_H diff --git a/arm9/lib/include/OS_init.h b/arm9/lib/include/OS_init.h index c556253a..1ff2837c 100644 --- a/arm9/lib/include/OS_init.h +++ b/arm9/lib/include/OS_init.h @@ -7,7 +7,10 @@ #include "types.h" #include "consts.h" +#include "OS_spinLock.h" +#include "OS_thread.h" #include "OS_protectionRegion.h" +#include "OS_entropy.h" #include "OS_arena.h" #include "OS_alloc.h" #include "OS_system.h" diff --git a/arm9/lib/include/OS_spinLock.h b/arm9/lib/include/OS_spinLock.h new file mode 100644 index 00000000..b7f0a571 --- /dev/null +++ b/arm9/lib/include/OS_spinLock.h @@ -0,0 +1,14 @@ +// +// Created by red031000 on 2020-05-03. +// + +#ifndef POKEDIAMOND_OS_SPINLOCK_H +#define POKEDIAMOND_OS_SPINLOCK_H + +typedef volatile struct OSLockWord { + u32 lockFlag; + u16 ownerID; + u16 extension; +} OSLockWord; + +#endif //POKEDIAMOND_OS_SPINLOCK_H diff --git a/arm9/lib/include/OS_thread.h b/arm9/lib/include/OS_thread.h new file mode 100644 index 00000000..4fb70bf7 --- /dev/null +++ b/arm9/lib/include/OS_thread.h @@ -0,0 +1,23 @@ +// +// Created by red031000 on 2020-05-03. +// + +#ifndef POKEDIAMOND_OS_THREAD_H +#define POKEDIAMOND_OS_THREAD_H + +typedef struct _OSThread OSThread; + +typedef struct OSThreadInfo { + u16 isNeedRescheduling; + u16 irqDepth; + OSThread* current; + OSThread* list; + void* switchCallback; // type: OSSwitchThreadCallback +} OSThreadInfo; + +struct _OSThread +{ + u8 padding[0x80]; //todo: not the correct size but idfk +}; + +#endif //POKEDIAMOND_OS_THREAD_H diff --git a/arm9/lib/include/consts.h b/arm9/lib/include/consts.h index 930f9af5..e07fe323 100644 --- a/arm9/lib/include/consts.h +++ b/arm9/lib/include/consts.h @@ -13,6 +13,19 @@ #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 diff --git a/arm9/lib/include/mmap.h b/arm9/lib/include/mmap.h index 14820c39..d94df843 100644 --- a/arm9/lib/include/mmap.h +++ b/arm9/lib/include/mmap.h @@ -26,6 +26,7 @@ extern u32 SDK_AUTOLOAD_DTCM_START[]; #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_SYSTEM (HW_MAIN_MEM + 0x007ffc00) #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) @@ -34,6 +35,8 @@ extern u32 SDK_AUTOLOAD_DTCM_START[]; #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 HW_BUTTON_XY_BUF (HW_MAIN_MEM + 0x007fffa8) + #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) @@ -42,4 +45,52 @@ extern u32 SDK_AUTOLOAD_DTCM_START[]; #define OSi_WRAM_MAIN_ARENA_HI_DEFAULT (HW_WRAM) #define OSi_WRAM_MAIN_ARENA_LO_DEFAULT (HW_WRAM) +#include "OS_thread.h" //not ideal but it's necessary +#include "OS_spinLock.h" + +typedef struct { + u8 bootCheckInfo[0x20]; // 000-01f: 32byte boot check info + u32 resetParameter; // 020-023: 4byte reset parameter + u8 padding5[0x8]; // 024-02c: (8byte) + u32 romBaseOffset; // 02c-02f: 4byte ROM offset of own program + u8 cartridgeModuleInfo[12]; // 030-03b: 12byte cartridge module info + u32 vblankCount; // 03c-03f: 4byte V-Blank Count + u8 wmBootBuf[0x40]; // 040-07f: 64byte WM multiboot buffer + u8 nvramUserInfo[0x100]; // 080-17f: 256bytes NVRAM user info + u8 isd_reserved1[0x20]; // 180-19f: 32bytes ISDebugger reserved + u8 arenaInfo[0x48]; // 1a0-1e7: 72byte Arena information + u8 real_time_clock[8]; // 1e8-1ef: 8bytes RTC + u32 dmaClearBuf[4]; // 1f0-1ff: 16bytes DMA clear information buffer (for ARM9-TEG) + u8 rom_header[0x160]; // 200-35f: 352bytes ROM registration area info storage buffer + u8 isd_reserved2[32]; // 360-37f: 32bytes ISDebugger reserved + u32 pxiSignalParam[2]; // 380-387: 8bytes Param for PXI Signal + u32 pxiHandleChecker[2]; // 388-38f: 8bytes Flag for PXI Command Handler Installed + u32 mic_last_address; // 390-393: 4bytes MIC latest sampling result storage address + u16 mic_sampling_data; // 394-395: 2bytes MIC sampling result + u16 wm_callback_control; // 396-397: 2bytes Parameter for WM callback synchronization + u16 wm_rssi_pool; // 398-399: 2bytes Random number source depends on WM received signal intensity + u8 padding3[2]; // 39a-39b: (2bytes) + u32 component_param; // 39c-39f: 4bytes Parameter for Component synchronization + OSThreadInfo *threadinfo_mainp; // 3a0-3a3: 4bytes Verify that the pointer to ARM9 thread information is initial value 0 + OSThreadInfo *threadinfo_subp; // 3a4-3a7: 4bytes Verify that the pointer to ARM7 thread information is initial value 0 + u16 button_XY; // 3a8-3a9: 2bytes XY button information storage location + u8 touch_panel[4]; // 3aa-3ad: 4bytes Touch Screen information storage location + u16 autoloadSync; // 3ae-3af: 2bytes autoload sync between processors + u32 lockIDFlag_mainp[2]; // 3b0-3b7: 8bytes lockID management flag (ARM9) + u32 lockIDFlag_subp[2]; // 3b8-3bf: 8bytes lockID management flag (ARM7) + struct OSLockWord lock_VRAM_C; // 3c0-3c7: 8bytes C - lock buffer + struct OSLockWord lock_VRAM_D; // 3c8-3cf: 8bytes VRAM-D - lock buffer + struct OSLockWord lock_WRAM_BLOCK0; // 3d0-3d7: 8bytes Block0 - lock buffer + struct OSLockWord lock_WRAM_BLOCK1; // 3d8-3df: 8bytes CPU internal work RAM - Block1 - lock buffer + struct OSLockWord lock_CARD; // 3e0-3e7: 8bytes Game Card - lock buffer + struct OSLockWord lock_CARTRIDGE; // 3e8-3ef: 8bytes DS Pak - lock buffer + struct OSLockWord lock_INIT; // 3f0-3f7: 8bytes Initialization lock buffer + u16 mmem_checker_mainp; // 3f8-3f9: 2bytes MainMomory Size Checker for Main processor + u16 mmem_checker_subp; // 3fa-3fb: 2bytes MainMomory Size Checker for Sub processor + u8 padding4[2]; // 3fc-3fd: (2bytes) + u16 command_area; // 3fe-3ff: 2bytes Command Area +} OSSystemWork; + +#define OS_GetSystemWork() ((OSSystemWork *)HW_MAIN_MEM_SYSTEM) + #endif
\ No newline at end of file diff --git a/arm9/lib/include/types.h b/arm9/lib/include/types.h index 5ad2c75e..40f8207d 100644 --- a/arm9/lib/include/types.h +++ b/arm9/lib/include/types.h @@ -25,6 +25,16 @@ typedef volatile s64 vs64; typedef float f32; typedef volatile f32 vf32; +typedef u8 REGType8; +typedef u16 REGType16; +typedef u32 REGType32; +typedef u64 REGType64; + +typedef vu8 REGType8v; +typedef vu16 REGType16v; +typedef vu32 REGType32v; +typedef vu64 REGType64v; + typedef int BOOL; #define TRUE 1 #define FALSE 0 diff --git a/arm9/lib/src/OS_entropy.c b/arm9/lib/src/OS_entropy.c new file mode 100644 index 00000000..b33781cc --- /dev/null +++ b/arm9/lib/src/OS_entropy.c @@ -0,0 +1,22 @@ +// +// Created by red031000 on 2020-05-03. +// + +#include "function_target.h" +#include "consts.h" +#include "OS_entropy.h" + +ARM_FUNC void OS_GetLowEntropyData(u32 * arr) +{ + const OSSystemWork* work = OS_GetSystemWork(); + const u8 * macAddress = (u8 *)((u32)(work->nvramUserInfo) + ((sizeof(NVRAMConfig) + 3) & ~3)); + arr[0] = (u32)((GX_GetVCount() << 16) | OS_GetTickLo()); + arr[1] = (u32)(*(u16 *)(macAddress + 4) << 16) ^ (u32)(OSi_TickCounter); + arr[2] = (u32)(OSi_TickCounter >> 32) ^ *(u32 *)macAddress ^ work->vblankCount; + arr[2] ^= reg_G3X_GXSTAT; + arr[3] = *(u32 *)(&work->real_time_clock[0]); + arr[4] = *(u32 *)(&work->real_time_clock[4]); + arr[5] = (((u32)work->mic_sampling_data) << 16) ^ work->mic_last_address; + arr[6] = (u32) ((*(u16 *)(&work->touch_panel[0]) << 16) | *(u16 *)(&work->touch_panel[2])); + arr[7] = (u32)((work->wm_rssi_pool << 16) | (reg_PAD_KEYINPUT | *(vu16 *)HW_BUTTON_XY_BUF)); +} |