diff options
author | red031000 <rubenru09@aol.com> | 2020-05-03 19:22:26 +0100 |
---|---|---|
committer | red031000 <rubenru09@aol.com> | 2020-05-03 19:23:58 +0100 |
commit | 4f6c75ac8381a7a3c2902c97870066ee90f1d320 (patch) | |
tree | dddb158e8ec903382b383796bac8708ce8f8492f /arm9/lib | |
parent | 2ee7030776461ee835dbbd44149f90ae79e7d4c5 (diff) |
match OS_GetLowEntropyData
Diffstat (limited to 'arm9/lib')
-rw-r--r-- | arm9/lib/include/OS_entropy.h | 17 | ||||
-rw-r--r-- | arm9/lib/include/consts.h | 13 | ||||
-rw-r--r-- | arm9/lib/include/mmap.h | 2 | ||||
-rw-r--r-- | arm9/lib/include/types.h | 10 | ||||
-rw-r--r-- | arm9/lib/src/OS_entropy.c | 30 |
5 files changed, 54 insertions, 18 deletions
diff --git a/arm9/lib/include/OS_entropy.h b/arm9/lib/include/OS_entropy.h index f4eef4b5..b4695a72 100644 --- a/arm9/lib/include/OS_entropy.h +++ b/arm9/lib/include/OS_entropy.h @@ -5,6 +5,23 @@ #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/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 ddbd8883..d94df843 100644 --- a/arm9/lib/include/mmap.h +++ b/arm9/lib/include/mmap.h @@ -35,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) 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 index bfc95882..b33781cc 100644 --- a/arm9/lib/src/OS_entropy.c +++ b/arm9/lib/src/OS_entropy.c @@ -6,23 +6,17 @@ #include "consts.h" #include "OS_entropy.h" -u32 * const HW_REG_006 = (u32 *) 0x04000006; -u32 * const HW_REG_130 = (u32 *) 0x04000130; -u32 * const HW_REG_600 = (u32 *) 0x04000600; - -u32 * const OSi_TickCounter = (u32 *) 0x021D37B4; - ARM_FUNC void OS_GetLowEntropyData(u32 * arr) { - OSSystemWork* work = OS_GetSystemWork(); - u16 x = *((u16 *)HW_REG_006); - u8 * nvramUserInfo = work->nvramUserInfo; - u8 r5 = nvramUserInfo[0x74]; - arr[0] = (OS_GetTickLo()<<0x10) | x ; - arr[1] = (OSi_TickCounter[0]<<0x10) ^ r5[2]; - u32 what = OSi_TickCounter[0]; - what = OSi_TickCounter[1]; - arr[2] = *((u32 *)r4) ^ what ^ *(u32 *)((u8 *)work+0x3c); - arr[2] ^= *HW_REG_600; - // ... -}
\ No newline at end of file + 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)); +} |