From f96daa407aeed58d580ac1f5d2c9f44c9d06f793 Mon Sep 17 00:00:00 2001 From: Wolfvak Date: Fri, 24 Jul 2020 14:20:51 -0300 Subject: [PATCH] potentially fix non-working FIRM builds, remove duplicated cycle wait functions the sdmmc wait function is exactly the same as the one in the bootrom and worked as a drop in replacement --- Makefile | 2 +- arm9/source/gamecart/command_ak2i.c | 1 - arm9/source/gamecart/command_ntr.c | 8 ++++---- arm9/source/gamecart/delay.h | 10 ---------- arm9/source/gamecart/iodelay.s | 27 --------------------------- arm9/source/gamecart/ndscard.h | 4 ++-- arm9/source/gamecart/protocol.c | 7 ++++--- arm9/source/gamecart/protocol_ctr.c | 5 +++-- arm9/source/gamecart/secure_ntr.c | 1 - arm9/source/nand/sdmmc.c | 4 ++-- arm9/source/nand/wait.h | 5 ----- arm9/source/nand/wait.s | 10 ---------- 12 files changed, 16 insertions(+), 68 deletions(-) delete mode 100644 arm9/source/gamecart/delay.h delete mode 100644 arm9/source/gamecart/iodelay.s delete mode 100644 arm9/source/nand/wait.h delete mode 100644 arm9/source/nand/wait.s diff --git a/Makefile b/Makefile index d5469e9..0725655 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ export CFLAGS := -DDBUILTS="\"$(DBUILTS)\"" -DDBUILTL="\"$(DBUILTL)\"" -DVERSIO -g -Os -Wall -Wextra -Wcast-align -Wformat=2 -Wno-main \ -fomit-frame-pointer -ffast-math -std=gnu11 -MMD -MP \ -Wno-unused-function -Wno-format-truncation $(INCLUDE) -ffunction-sections -fdata-sections -export LDFLAGS := -Tlink.ld -nostartfiles -Wl,--gc-sections,-z,max-page-size=512 +export LDFLAGS := -Tlink.ld -nostartfiles -Wl,--gc-sections,-z,max-page-size=4096 ELF := arm9/arm9.elf arm11/arm11.elf .PHONY: all firm vram0 elf release clean diff --git a/arm9/source/gamecart/command_ak2i.c b/arm9/source/gamecart/command_ak2i.c index 02ce979..6329ff5 100644 --- a/arm9/source/gamecart/command_ak2i.c +++ b/arm9/source/gamecart/command_ak2i.c @@ -9,7 +9,6 @@ #include "command_ak2i.h" #include "protocol_ntr.h" #include "card_ntr.h" -#include "delay.h" u32 AK2I_CmdGetHardwareVersion(void) { diff --git a/arm9/source/gamecart/command_ntr.c b/arm9/source/gamecart/command_ntr.c index 3f2e25a..5d3ab79 100644 --- a/arm9/source/gamecart/command_ntr.c +++ b/arm9/source/gamecart/command_ntr.c @@ -5,18 +5,18 @@ // modifyed by osilloscopion (2 Jul 2016) // +#include + #include "command_ntr.h" #include "protocol_ntr.h" #include "card_ntr.h" -#include "delay.h" - u32 ReadDataFlags = 0; void NTR_CmdReset(void) { cardReset (); - ioDelay2(0xF000); + ARM_WaitCycles(0xF000 * 4); } u32 NTR_CmdGetCartId(void) @@ -34,7 +34,7 @@ void NTR_CmdReadHeader (u8* buffer) { REG_NTRCARDROMCNT=0; REG_NTRCARDMCNT=0; - ioDelay2(167550); + ARM_WaitCycles(167550 * 4); REG_NTRCARDMCNT=NTRCARD_CR1_ENABLE|NTRCARD_CR1_IRQ; REG_NTRCARDROMCNT=NTRCARD_nRESET|NTRCARD_SEC_SEED; while(REG_NTRCARDROMCNT&NTRCARD_BUSY) ; diff --git a/arm9/source/gamecart/delay.h b/arm9/source/gamecart/delay.h deleted file mode 100644 index 98c4b8a..0000000 --- a/arm9/source/gamecart/delay.h +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2014 Normmatt -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include "common.h" - -void ioDelay(u32 us); -void ioDelay2(u32 us); diff --git a/arm9/source/gamecart/iodelay.s b/arm9/source/gamecart/iodelay.s deleted file mode 100644 index aa37b8c..0000000 --- a/arm9/source/gamecart/iodelay.s +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2014 Normmatt -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -.arm -.global ioDelay -.type ioDelay STT_FUNC - -@ioDelay ( u32 us ) -ioDelay: - ldr r1, =0x18000000 @ VRAM -1: - @ Loop doing uncached reads from VRAM to make loop timing more reliable - ldr r2, [r1] - subs r0, #1 - bgt 1b - bx lr - -.global ioDelay2 -.type ioDelay2 STT_FUNC - -@ioDelay2 ( u32 us ) -ioDelay2: -1: - subs r0, #1 - bgt 1b - bx lr diff --git a/arm9/source/gamecart/ndscard.h b/arm9/source/gamecart/ndscard.h index 25fce99..56a543a 100644 --- a/arm9/source/gamecart/ndscard.h +++ b/arm9/source/gamecart/ndscard.h @@ -7,8 +7,8 @@ // #pragma once +#include #include -#include "delay.h" #define u8 uint8_t #define u16 uint16_t @@ -85,7 +85,7 @@ #define CARD_SPICNTH_ENABLE (1<<7) // in byte 1, i.e. 0x8000 #define CARD_SPICNTH_IRQ (1<<6) // in byte 1, i.e. 0x4000 -#define swiDelay(n) ioDelay(n) +#define swiDelay(n) ARM_WaitCycles((n) * 8) #define DMA_SRC(n) (*(vu32*)(0x10002004 + (n * 0x1c))) #define DMA_DEST(n) (*(vu32*)(0x10002008 + (n * 0x1c))) diff --git a/arm9/source/gamecart/protocol.c b/arm9/source/gamecart/protocol.c index db08305..e01fac5 100644 --- a/arm9/source/gamecart/protocol.c +++ b/arm9/source/gamecart/protocol.c @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include + #include "protocol.h" #include "timer.h" @@ -14,7 +16,6 @@ #include "protocol_ntr.h" #include "command_ctr.h" #include "command_ntr.h" -#include "delay.h" // could have been done better, but meh... #define REG_AESCNT (*(vu32*)0x10009000) @@ -177,7 +178,7 @@ void Cart_Secure_Init(u32 *buf, u32 *out) // if (!mac_valid) // ClearScreen(bottomScreen, RGB(255, 0, 0)); - ioDelay(0xF0000); + ARM_WaitCycles(0xF0000 * 8); CTR_SetSecKey(A0_Response); CTR_SetSecSeed(out, true); @@ -207,7 +208,7 @@ void Cart_Secure_Init(u32 *buf, u32 *out) for (int i = 0; i < 5; ++i) { CTR_SendCommand(A2_cmd, 4, 1, 0x701002C, &test); - ioDelay(0xF0000); + ARM_WaitCycles(0xF0000 * 8); } } diff --git a/arm9/source/gamecart/protocol_ctr.c b/arm9/source/gamecart/protocol_ctr.c index b86631b..4597036 100644 --- a/arm9/source/gamecart/protocol_ctr.c +++ b/arm9/source/gamecart/protocol_ctr.c @@ -2,10 +2,11 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include + #include "protocol_ctr.h" #include "protocol.h" -#include "delay.h" #ifdef VERBOSE_COMMANDS #include "draw.h" #endif @@ -143,7 +144,7 @@ void CTR_SendCommand(const u32 command[4], u32 pageSize, u32 blocks, u32 latency // so we have to wait next data ready do { cardCtrl = REG_CTRCARDCNT; } while(!(cardCtrl & CTRCARD_DATA_READY)); // and this tiny delay is necessary - ioDelay(33); + ARM_WaitCycles(33 * 8); // pull ROM CS high REG_CTRCARDCNT = 0x10000000; REG_CTRCARDCNT = CTRKEY_PARAM | CTRCARD_ACTIVATE | CTRCARD_nRESET; diff --git a/arm9/source/gamecart/secure_ntr.c b/arm9/source/gamecart/secure_ntr.c index 79b5679..29f0ff6 100644 --- a/arm9/source/gamecart/secure_ntr.c +++ b/arm9/source/gamecart/secure_ntr.c @@ -23,7 +23,6 @@ #include "card_ntr.h" // #include "draw.h" #include "timer.h" -#include "delay.h" #define BSWAP32(val) ((((val >> 24) & 0xFF)) | (((val >> 16) & 0xFF) << 8) | (((val >> 8) & 0xFF) << 16) | ((val & 0xFF) << 24)) diff --git a/arm9/source/nand/sdmmc.c b/arm9/source/nand/sdmmc.c index 3654f98..ed9cf71 100644 --- a/arm9/source/nand/sdmmc.c +++ b/arm9/source/nand/sdmmc.c @@ -22,10 +22,10 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ +#include #include #include #include "timer.h" -#include "wait.h" #include "sdmmc.h" #define DATA32_SUPPORT @@ -469,7 +469,7 @@ int SD_Init() // We need to send at least 74 clock pulses. set_target(&handleSD); - wait(2 * 128 * 74); + ARM_WaitCycles(2 * 128 * 74); sdmmc_send_command(&handleSD,0,0); sdmmc_send_command(&handleSD,0x10408,0x1AA); diff --git a/arm9/source/nand/wait.h b/arm9/source/nand/wait.h deleted file mode 100644 index d050a24..0000000 --- a/arm9/source/nand/wait.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "common.h" - -void wait(u32 cycles); diff --git a/arm9/source/nand/wait.s b/arm9/source/nand/wait.s deleted file mode 100644 index 2647d90..0000000 --- a/arm9/source/nand/wait.s +++ /dev/null @@ -1,10 +0,0 @@ -.text -.arm -.align 4 - -.global wait -.type wait, %function -wait: - subs r0, r0, #4 - bcs wait - bx lr