diff --git a/include/arm11/hardware.h b/include/arm11/hardware.h new file mode 100644 index 0000000..9fdf988 --- /dev/null +++ b/include/arm11/hardware.h @@ -0,0 +1,5 @@ +#pragma once + + + +void hardwareInit(void); diff --git a/include/arm11/loader_init.h b/include/arm11/loader_init.h deleted file mode 100644 index 9fdf988..0000000 --- a/include/arm11/loader_init.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - - - -void hardwareInit(void); diff --git a/include/arm9/crypto.h b/include/arm9/crypto.h index 10e4aea..cc2ceca 100644 --- a/include/arm9/crypto.h +++ b/include/arm9/crypto.h @@ -59,7 +59,6 @@ */ void AES_init(void); - /** * @brief Sets a normal key. * @@ -69,7 +68,6 @@ */ void AES_setNormalKey(u8 keyslot, u8 orderEndianess, const u32 key[4]); - /** * @brief Sets a keyX. * @@ -80,7 +78,6 @@ */ void AES_setKeyX(u8 keyslot, u8 orderEndianess, bool useTwlScrambler, const u32 keyX[4]); - /** * @brief Sets a keyY. * @@ -91,7 +88,6 @@ */ void AES_setKeyY(u8 keyslot, u8 orderEndianess, bool useTwlScrambler, const u32 keyY[4]); - /** * @brief Selects the given keyslot for all following crypto operations. * @@ -99,7 +95,6 @@ */ void AES_selectKeyslot(u8 keyslot); - /** * @brief Copies the given nonce into internal state. * @@ -109,7 +104,6 @@ */ void AES_setNonce(AES_ctx *const ctx, u8 orderEndianess, const u32 nonce[3]); - /** * @brief Copies the given counter/initialization vector into internal state. * @@ -119,7 +113,6 @@ */ void AES_setCtrIv(AES_ctx *const ctx, u8 orderEndianess, const u32 ctrIv[4]); - /** * @brief Increments the internal counter with the given value (CTR mode). * @@ -128,7 +121,6 @@ */ void AES_addCounter(u32 ctr[4], u32 val); - /** * @brief Decrements the internal counter with the given value (CTR mode). * @@ -137,7 +129,6 @@ */ void AES_subCounter(u32 ctr[4], u32 val); - /** * @brief Sets params in the AES context for all following crypto operations. * @@ -147,7 +138,6 @@ */ void AES_setCryptParams(AES_ctx *const ctx, u8 inEndianessOrder, u8 outEndianessOrder); - /** * @brief En-/decrypts data with AES CTR. * diff --git a/include/arm9/hardware.h b/include/arm9/hardware.h new file mode 100644 index 0000000..9fdf988 --- /dev/null +++ b/include/arm9/hardware.h @@ -0,0 +1,5 @@ +#pragma once + + + +void hardwareInit(void); diff --git a/include/arm9/loader_init.h b/include/arm9/loader_init.h deleted file mode 100644 index 9fdf988..0000000 --- a/include/arm9/loader_init.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - - - -void hardwareInit(void); diff --git a/source/arm11/hardware.c b/source/arm11/hardware.c new file mode 100644 index 0000000..8cab4ff --- /dev/null +++ b/source/arm11/hardware.c @@ -0,0 +1,9 @@ +#include "types.h" +#include "pxi.h" + + + +void hardwareInit(void) +{ + PXI_init(); +} diff --git a/source/arm11/loader_init.c b/source/arm11/loader_init.c deleted file mode 100644 index 8cab4ff..0000000 --- a/source/arm11/loader_init.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "types.h" -#include "pxi.h" - - - -void hardwareInit(void) -{ - PXI_init(); -} diff --git a/source/arm11/main.c b/source/arm11/main.c index 9996095..cf48d9a 100644 --- a/source/arm11/main.c +++ b/source/arm11/main.c @@ -1,6 +1,6 @@ #include "types.h" #include "util.h" -#include "arm11/loader_init.h" +#include "arm11/hardware.h" #include "arm11/i2c.h" #include "gfx.h" #include "pxi.h" diff --git a/source/arm9/dev.c b/source/arm9/dev.c index 3d29448..7d37e93 100644 --- a/source/arm9/dev.c +++ b/source/arm9/dev.c @@ -235,7 +235,6 @@ pad[3] ^= ((u32*)BOOT9_BASE)[3]; AES_setKeyY(0x05, AES_INPUT_BIG | AES_INPUT_NORMAL, false, pad); - AES_selectKeyslot(0x05); } diff --git a/source/arm9/hardware.c b/source/arm9/hardware.c new file mode 100644 index 0000000..1388e7f --- /dev/null +++ b/source/arm9/hardware.c @@ -0,0 +1,24 @@ +#include "types.h" +#include "arm9/interrupt.h" +#include "arm9/ndma.h" +#include "arm9/timer.h" +#include "pxi.h" +#include "arm9/crypto.h" + + + +void hardwareInit(void) +{ + IRQ_init(); + NDMA_init(); + TIMER_init(); + PXI_init(); + AES_init(); +} + +void hardwareDeinit(void) +{ + // New 3DS K9L doesn't like FIFO counts >4 and hangs. + // Thx Nintendo + AES_init(); +} diff --git a/source/arm9/loader_init.c b/source/arm9/loader_init.c deleted file mode 100644 index d91418a..0000000 --- a/source/arm9/loader_init.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "types.h" -#include "arm9/interrupt.h" -#include "arm9/ndma.h" -#include "arm9/timer.h" -#include "pxi.h" -#include "arm9/crypto.h" - - - -void hardwareInit(void) -{ - IRQ_init(); - NDMA_init(); - TIMER_init(); - PXI_init(); - AES_init(); -} diff --git a/source/arm9/main.c b/source/arm9/main.c index c88bd7d..7f58e41 100644 --- a/source/arm9/main.c +++ b/source/arm9/main.c @@ -6,7 +6,7 @@ #include "util.h" #include "pxi.h" #include "hid.h" -#include "arm9/loader_init.h" +#include "arm9/hardware.h" #include "fatfs/ff.h" #include "arm9/dev.h" #include "arm9/firm.h" @@ -119,6 +119,8 @@ devs_close(); + hardwareDeinit(); + return 0; } @@ -265,11 +267,11 @@ } #define PDN_REGS_BASE (IO_MEM_ARM9_ARM11 + 0x40000) -#define REG_PDN_MPCORE_CLKCNT *((vu16*)(PDN_REGS_BASE + 0x1300)) +#define REG_PDN_MPCORE_CFG *((vu16*)(PDN_REGS_BASE + 0x0FFC)) static void unit_detect() { - bootInfo.unit_is_new3ds = REG_PDN_MPCORE_CLKCNT != 0; + bootInfo.unit_is_new3ds = REG_PDN_MPCORE_CFG & 2; sprintf(bootInfo.model, "%s 3DS", bootInfo.unit_is_new3ds ? "New" : "Original");