From f0a807fcab6be84bcc36cb3b25ca4b9c33f7f97b Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Fri, 1 Nov 2024 22:21:54 -0600 Subject: [PATCH] gbapatcher: Remove unused data --- gbapatcher/arm9/source/nds_loader_arm9.c | 42 -- gbapatcher/arm9/source/nds_loader_arm9.h | 4 - gbapatcher/bootloader/Makefile | 2 +- gbapatcher/bootloader/source/bios.s | 13 - gbapatcher/bootloader/source/boot.c | 76 +-- gbapatcher/bootloader/source/card.h | 45 -- gbapatcher/bootloader/source/disc_io.h | 82 --- gbapatcher/bootloader/source/dldi_patcher.c | 223 -------- gbapatcher/bootloader/source/dldi_patcher.h | 32 -- gbapatcher/bootloader/source/fat.c | 544 -------------------- gbapatcher/bootloader/source/fat.h | 46 -- gbapatcher/bootloader/source/i2c.c | 132 ----- gbapatcher/bootloader/source/i2c.h | 65 --- gbapatcher/bootloader/source/io_dldi.h | 44 -- gbapatcher/bootloader/source/io_dldi.s | 124 ----- gbapatcher/bootloader/source/load_crt0.s | 36 -- 16 files changed, 2 insertions(+), 1508 deletions(-) delete mode 100644 gbapatcher/bootloader/source/bios.s delete mode 100644 gbapatcher/bootloader/source/card.h delete mode 100644 gbapatcher/bootloader/source/disc_io.h delete mode 100644 gbapatcher/bootloader/source/dldi_patcher.c delete mode 100644 gbapatcher/bootloader/source/dldi_patcher.h delete mode 100644 gbapatcher/bootloader/source/fat.c delete mode 100644 gbapatcher/bootloader/source/fat.h delete mode 100644 gbapatcher/bootloader/source/i2c.c delete mode 100644 gbapatcher/bootloader/source/i2c.h delete mode 100644 gbapatcher/bootloader/source/io_dldi.h delete mode 100644 gbapatcher/bootloader/source/io_dldi.s diff --git a/gbapatcher/arm9/source/nds_loader_arm9.c b/gbapatcher/arm9/source/nds_loader_arm9.c index 97d57c4f46..b3c8e98d8c 100644 --- a/gbapatcher/arm9/source/nds_loader_arm9.c +++ b/gbapatcher/arm9/source/nds_loader_arm9.c @@ -30,50 +30,8 @@ #include "common/tonccpy.h" #include "load_bin.h" -#ifndef _NO_BOOTSTUB_ -#include "bootstub_bin.h" -#endif - #include "nds_loader_arm9.h" #define LCDC_BANK_C (u16*)0x06840000 -#define STORED_FILE_CLUSTER (*(((u32*)LCDC_BANK_C) + 1)) -#define INIT_DISC (*(((u32*)LCDC_BANK_C) + 2)) -#define WANT_TO_PATCH_DLDI (*(((u32*)LCDC_BANK_C) + 3)) - - -/* - b startUp - -storedFileCluster: - .word 0x0FFFFFFF @ default BOOT.NDS -initDisc: - .word 0x00000001 @ init the disc by default -wantToPatchDLDI: - .word 0x00000001 @ by default patch the DLDI section of the loaded NDS -@ Used for passing arguments to the loaded app -argStart: - .word _end - _start -argSize: - .word 0x00000000 -dldiOffset: - .word _dldi_start - _start -dsiSD: - .word 0 -dsiMode: - .word 0 -*/ - -#define STORED_FILE_CLUSTER_OFFSET 4 -#define INIT_DISC_OFFSET 8 -#define WANT_TO_PATCH_DLDI_OFFSET 12 -#define ARG_START_OFFSET 16 -#define ARG_SIZE_OFFSET 20 -#define HAVE_DSISD_OFFSET 28 -#define DSIMODE_OFFSET 32 -#define CLEAR_MASTER_BRIGHT_OFFSET 36 -#define DSMODE_SWITCH_OFFSET 40 -#define LOADFROMRAM_OFFSET 44 - int runNds (const void* loader, u32 loaderSize) { diff --git a/gbapatcher/arm9/source/nds_loader_arm9.h b/gbapatcher/arm9/source/nds_loader_arm9.h index 8e01cd8658..b925a2246b 100644 --- a/gbapatcher/arm9/source/nds_loader_arm9.h +++ b/gbapatcher/arm9/source/nds_loader_arm9.h @@ -29,12 +29,8 @@ extern "C" { #define LOAD_DEFAULT_NDS 0 -int runNds (const void* loader, u32 loaderSize); - int runNdsFile (void); -bool installBootStub(bool havedsiSD); - #ifdef __cplusplus } #endif diff --git a/gbapatcher/bootloader/Makefile b/gbapatcher/bootloader/Makefile index 0b1b3652fb..23723e0cb3 100644 --- a/gbapatcher/bootloader/Makefile +++ b/gbapatcher/bootloader/Makefile @@ -30,7 +30,7 @@ CFLAGS := -g -Wall -O2 \ -flto \ $(ARCH) -CFLAGS += $(INCLUDE) $(EXTRA_CFLAGS) -DARM7 -DNO_SDMMC +CFLAGS += $(INCLUDE) $(EXTRA_CFLAGS) -DARM7 ASFLAGS := -g $(ARCH) -flto $(EXTRA_CFLAGS) $(INCLUDE) LDFLAGS = -nostartfiles -T $(TOPDIR)/load.ld -g $(ARCH) -Wl,-Map,$(TARGET).map diff --git a/gbapatcher/bootloader/source/bios.s b/gbapatcher/bootloader/source/bios.s deleted file mode 100644 index e98f57c4eb..0000000000 --- a/gbapatcher/bootloader/source/bios.s +++ /dev/null @@ -1,13 +0,0 @@ - .text - .align 4 - - .thumb - -@--------------------------------------------------------------------------------- - .global swiDelay - .thumb_func -@--------------------------------------------------------------------------------- -swiDelay: -@--------------------------------------------------------------------------------- - swi 0x03 - bx lr diff --git a/gbapatcher/bootloader/source/boot.c b/gbapatcher/bootloader/source/boot.c index 59900d6ee3..483c79d479 100644 --- a/gbapatcher/bootloader/source/boot.c +++ b/gbapatcher/bootloader/source/boot.c @@ -49,10 +49,6 @@ Helpful information: #include #include #include "common/tonccpy.h" -#include "i2c.h" -#include "fat.h" -#include "dldi_patcher.h" -#include "card.h" #include "boot.h" void arm7clearRAM(); @@ -64,51 +60,6 @@ void arm7clearRAM(); #define TEMP_ARM9_START_ADDRESS (*(vu32*)0x02FFFFF4) -const char* bootName = "BOOT.NDS"; - -extern unsigned long _start; -extern unsigned long storedFileCluster; -extern unsigned long initDisc; -extern unsigned long wantToPatchDLDI; -extern unsigned long argStart; -extern unsigned long argSize; -extern unsigned long dsiSD; -extern unsigned long dsiMode; -extern unsigned long clearMasterBright; -extern unsigned long dsMode; -extern unsigned long loadFromRam; - -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// Firmware stuff - -#define FW_READ 0x03 - -void boot_readFirmware (uint32 address, uint8 * buffer, uint32 size) { - uint32 index; - - // Read command - while (REG_SPICNT & SPI_BUSY); - REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_NVRAM; - REG_SPIDATA = FW_READ; - while (REG_SPICNT & SPI_BUSY); - - // Set the address - REG_SPIDATA = (address>>16) & 0xFF; - while (REG_SPICNT & SPI_BUSY); - REG_SPIDATA = (address>>8) & 0xFF; - while (REG_SPICNT & SPI_BUSY); - REG_SPIDATA = (address) & 0xFF; - while (REG_SPICNT & SPI_BUSY); - - for (index = 0; index < size; index++) { - REG_SPIDATA = 0; - while (REG_SPICNT & SPI_BUSY); - buffer[index] = REG_SPIDATA & 0xFF; - } - REG_SPICNT = 0; -} - - static inline void copyLoop (u32* dest, const u32* src, u32 size) { size = (size +3) & ~3; do { @@ -130,8 +81,6 @@ Modified by Chishm: void resetMemory_ARM7 (void) { int i; - u8 settings1, settings2; - u32 settingsOffset = 0; REG_IME = 0; @@ -160,7 +109,7 @@ void resetMemory_ARM7 (void) arm7clearRAM(); // clear most of EWRAM - except after RAM end - 0xc000, which has the bootstub - toncset((void*)0x02004000, 0, dsiMode&&!dsMode ? 0xFF0000 : 0x3F0000); + toncset((void*)0x02004000, 0, 0x3F0000); *(u32*)(0x2FFFD9C) = 0; // Clear exception handler REG_IE = 0; @@ -168,25 +117,6 @@ void resetMemory_ARM7 (void) (*(vu32*)(0x04000000-4)) = 0; //IRQ_HANDLER ARM7 version (*(vu32*)(0x04000000-8)) = ~0; //VBLANK_INTR_WAIT_FLAGS, ARM7 version REG_POWERCNT = 1; //turn off power to stuff - - // Get settings location - boot_readFirmware((u32)0x00020, (u8*)&settingsOffset, 0x2); - settingsOffset *= 8; - - // Reload DS Firmware settings - boot_readFirmware(settingsOffset + 0x070, &settings1, 0x1); - boot_readFirmware(settingsOffset + 0x170, &settings2, 0x1); - - if ((settings1 & 0x7F) == ((settings2+1) & 0x7F)) { - boot_readFirmware(settingsOffset + 0x000, (u8*)0x02FFFC80, 0x70); - } else { - boot_readFirmware(settingsOffset + 0x100, (u8*)0x02FFFC80, 0x70); - } - - ((vu32*)0x040044f0)[2] = 0x202DDD1D; - ((vu32*)0x040044f0)[3] = 0xE1A00005; - while ((*(vu32*)0x04004400) & 0x2000000); - } @@ -239,10 +169,6 @@ void mpu_reset(); void mpu_reset_end(); int main (void) { -#ifdef NO_DLDI - dsiSD = true; - dsiMode = true; -#endif // ARM9 clears its memory part 2 // copy ARM9 function to RAM, and make the ARM9 jump to it copyLoop((void*)TEMP_MEM, (void*)resetMemory2_ARM9, resetMemory2_ARM9_size); diff --git a/gbapatcher/bootloader/source/card.h b/gbapatcher/bootloader/source/card.h deleted file mode 100644 index cd6f6fb6fb..0000000000 --- a/gbapatcher/bootloader/source/card.h +++ /dev/null @@ -1,45 +0,0 @@ -/*----------------------------------------------------------------- - - Copyright (C) 2005 Michael "Chishm" Chisholm - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - If you use this code, please give due credit and email me about your - project at chishm@hotmail.com -------------------------------------------------------------------*/ - -#ifndef CARD_H -#define CARD_H - -#include "disc_io.h" -#include "io_dldi.h" - -static inline bool CARD_StartUp (void) { - return _io_dldi.fn_startup(); -} - -static inline bool CARD_IsInserted (void) { - return _io_dldi.fn_isInserted(); -} - -static inline bool CARD_ReadSector (u32 sector, void *buffer) { - return _io_dldi.fn_readSectors(sector, 1, buffer); -} - -static inline bool CARD_ReadSectors (u32 sector, int count, void *buffer) { - return _io_dldi.fn_readSectors(sector, count, buffer); -} - -#endif // CARD_H diff --git a/gbapatcher/bootloader/source/disc_io.h b/gbapatcher/bootloader/source/disc_io.h deleted file mode 100644 index 29033b764e..0000000000 --- a/gbapatcher/bootloader/source/disc_io.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - disc_io.h - Interface template for low level disc functions. - - Copyright (c) 2006 Michael "Chishm" Chisholm - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation and/or - other materials provided with the distribution. - 3. The name of the author may not be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - 2006-07-11 - Chishm - * Original release - - 2006-07-16 - Chishm - * Renamed _CF_USE_DMA to _IO_USE_DMA - * Renamed _CF_ALLOW_UNALIGNED to _IO_ALLOW_UNALIGNED -*/ - -#ifndef _DISC_IO_H -#define _DISC_IO_H - -#include -#define BYTES_PER_SECTOR 512 - -//---------------------------------------------------------------------- -// Customisable features - -// Use DMA to read the card, remove this line to use normal reads/writes -// #define _IO_USE_DMA - -// Allow buffers not alligned to 16 bits when reading files. -// Note that this will slow down access speed, so only use if you have to. -// It is also incompatible with DMA -#define _IO_ALLOW_UNALIGNED - -#if defined _IO_USE_DMA && defined _IO_ALLOW_UNALIGNED - #error "You can't use both DMA and unaligned memory" -#endif - -#define FEATURE_MEDIUM_CANREAD 0x00000001 -#define FEATURE_MEDIUM_CANWRITE 0x00000002 -#define FEATURE_SLOT_GBA 0x00000010 -#define FEATURE_SLOT_NDS 0x00000020 - -typedef bool (* FN_MEDIUM_STARTUP)(void) ; -typedef bool (* FN_MEDIUM_ISINSERTED)(void) ; -typedef bool (* FN_MEDIUM_READSECTORS)(u32 sector, u32 numSectors, void* buffer) ; -typedef bool (* FN_MEDIUM_WRITESECTORS)(u32 sector, u32 numSectors, const void* buffer) ; -typedef bool (* FN_MEDIUM_CLEARSTATUS)(void) ; -typedef bool (* FN_MEDIUM_SHUTDOWN)(void) ; - -struct IO_INTERFACE_STRUCT { - unsigned long ioType ; - unsigned long features ; - FN_MEDIUM_STARTUP fn_startup ; - FN_MEDIUM_ISINSERTED fn_isInserted ; - FN_MEDIUM_READSECTORS fn_readSectors ; - FN_MEDIUM_WRITESECTORS fn_writeSectors ; - FN_MEDIUM_CLEARSTATUS fn_clearStatus ; - FN_MEDIUM_SHUTDOWN fn_shutdown ; -} ; - -typedef struct IO_INTERFACE_STRUCT IO_INTERFACE ; - -#endif // define _DISC_IO_H diff --git a/gbapatcher/bootloader/source/dldi_patcher.c b/gbapatcher/bootloader/source/dldi_patcher.c deleted file mode 100644 index 69f292e436..0000000000 --- a/gbapatcher/bootloader/source/dldi_patcher.c +++ /dev/null @@ -1,223 +0,0 @@ -/*----------------------------------------------------------------- - - Copyright (C) 2005 Michael "Chishm" Chisholm - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - If you use this code, please give due credit and email me about your - project at chishm@hotmail.com -------------------------------------------------------------------*/ -#ifndef NO_DLDI -#include -#include -#include "dldi_patcher.h" - -#define FIX_ALL 0x01 -#define FIX_GLUE 0x02 -#define FIX_GOT 0x04 -#define FIX_BSS 0x08 - -enum DldiOffsets { - DO_magicString = 0x00, // "\xED\xA5\x8D\xBF Chishm" - DO_magicToken = 0x00, // 0xBF8DA5ED - DO_magicShortString = 0x04, // " Chishm" - DO_version = 0x0C, - DO_driverSize = 0x0D, - DO_fixSections = 0x0E, - DO_allocatedSpace = 0x0F, - - DO_friendlyName = 0x10, - - DO_text_start = 0x40, // Data start - DO_data_end = 0x44, // Data end - DO_glue_start = 0x48, // Interworking glue start -- Needs address fixing - DO_glue_end = 0x4C, // Interworking glue end - DO_got_start = 0x50, // GOT start -- Needs address fixing - DO_got_end = 0x54, // GOT end - DO_bss_start = 0x58, // bss start -- Needs setting to zero - DO_bss_end = 0x5C, // bss end - - // IO_INTERFACE data - DO_ioType = 0x60, - DO_features = 0x64, - DO_startup = 0x68, - DO_isInserted = 0x6C, - DO_readSectors = 0x70, - DO_writeSectors = 0x74, - DO_clearStatus = 0x78, - DO_shutdown = 0x7C, - DO_code = 0x80 -}; - -static addr_t readAddr (data_t *mem, addr_t offset) { - return ((addr_t*)mem)[offset/sizeof(addr_t)]; -} - -static void writeAddr (data_t *mem, addr_t offset, addr_t value) { - ((addr_t*)mem)[offset/sizeof(addr_t)] = value; -} - - -static addr_t quickFind (const data_t* data, const data_t* search, size_t dataLen, size_t searchLen) { - const int* dataChunk = (const int*) data; - int searchChunk = ((const int*)search)[0]; - addr_t i; - addr_t dataChunkEnd = (addr_t)(dataLen / sizeof(int)); - - for (i = 0; i < dataChunkEnd; i++) { - if (dataChunk[i] == searchChunk) { - if ((i*sizeof(int) + searchLen) > dataLen) { - return -1; - } - if (memcmp (&data[i*sizeof(int)], search, searchLen) == 0) { - return i*sizeof(int); - } - } - } - - return -1; -} - -// Strings are stored with bit 0x20 flipped (case inverted) to prevent accidental DLDI patching of them -#define DLDI_MAGIC_LEN 12 -#define DLDI_MAGIC_MANGLE_VALUE 0x20 -static const data_t dldiMagicStringMangled[DLDI_MAGIC_LEN] = "\xCD\x85\xAD\x9F\0cHISHM"; // Normal DLDI file - -// Demangle the magic string by XORing every byte with 0x20, except the NULL terminator -static void demangleMagicString(data_t *dest, const data_t *src) { - int i; - - memcpy(dest, src, DLDI_MAGIC_LEN); - for (i = 0; i < DLDI_MAGIC_LEN - 1; ++i) { - dest[i] ^= DLDI_MAGIC_MANGLE_VALUE; - } -} - -#define DEVICE_TYPE_DLDI 0x49444C44 - -extern data_t _dldi_start[]; - -bool dldiPatchBinary (data_t *binData, u32 binSize) { - - addr_t memOffset; // Offset of DLDI after the file is loaded into memory - addr_t patchOffset; // Position of patch destination in the file - addr_t relocationOffset; // Value added to all offsets within the patch to fix it properly - addr_t ddmemOffset; // Original offset used in the DLDI file - addr_t ddmemStart; // Start of range that offsets can be in the DLDI file - addr_t ddmemEnd; // End of range that offsets can be in the DLDI file - addr_t ddmemSize; // Size of range that offsets can be in the DLDI file - addr_t addrIter; - - data_t *pDH; - data_t *pAH; - - data_t dldiMagicString[DLDI_MAGIC_LEN]; - size_t dldiFileSize = 0; - - // Find the DLDI reserved space in the file - demangleMagicString(dldiMagicString, dldiMagicStringMangled); - patchOffset = quickFind (binData, dldiMagicString, binSize, sizeof(dldiMagicString)); - - if (patchOffset < 0) { - // does not have a DLDI section - return false; - } - - pDH = _dldi_start; - pAH = &(binData[patchOffset]); - - if (*((u32*)(pDH + DO_ioType)) == DEVICE_TYPE_DLDI) { - // No DLDI patch - return false; - } - - if (pDH[DO_driverSize] > pAH[DO_allocatedSpace]) { - // Not enough space for patch - return false; - } - - dldiFileSize = 1 << pDH[DO_driverSize]; - - memOffset = readAddr (pAH, DO_text_start); - if (memOffset == 0) { - memOffset = readAddr (pAH, DO_startup) - DO_code; - } - ddmemOffset = readAddr (pDH, DO_text_start); - relocationOffset = memOffset - ddmemOffset; - - ddmemStart = readAddr (pDH, DO_text_start); - ddmemSize = (1 << pDH[DO_driverSize]); - ddmemEnd = ddmemStart + ddmemSize; - - // Remember how much space is actually reserved - pDH[DO_allocatedSpace] = pAH[DO_allocatedSpace]; - // Copy the DLDI patch into the application - memcpy (pAH, pDH, dldiFileSize); - - // Fix the section pointers in the header - writeAddr (pAH, DO_text_start, readAddr (pAH, DO_text_start) + relocationOffset); - writeAddr (pAH, DO_data_end, readAddr (pAH, DO_data_end) + relocationOffset); - writeAddr (pAH, DO_glue_start, readAddr (pAH, DO_glue_start) + relocationOffset); - writeAddr (pAH, DO_glue_end, readAddr (pAH, DO_glue_end) + relocationOffset); - writeAddr (pAH, DO_got_start, readAddr (pAH, DO_got_start) + relocationOffset); - writeAddr (pAH, DO_got_end, readAddr (pAH, DO_got_end) + relocationOffset); - writeAddr (pAH, DO_bss_start, readAddr (pAH, DO_bss_start) + relocationOffset); - writeAddr (pAH, DO_bss_end, readAddr (pAH, DO_bss_end) + relocationOffset); - // Fix the function pointers in the header - writeAddr (pAH, DO_startup, readAddr (pAH, DO_startup) + relocationOffset); - writeAddr (pAH, DO_isInserted, readAddr (pAH, DO_isInserted) + relocationOffset); - writeAddr (pAH, DO_readSectors, readAddr (pAH, DO_readSectors) + relocationOffset); - writeAddr (pAH, DO_writeSectors, readAddr (pAH, DO_writeSectors) + relocationOffset); - writeAddr (pAH, DO_clearStatus, readAddr (pAH, DO_clearStatus) + relocationOffset); - writeAddr (pAH, DO_shutdown, readAddr (pAH, DO_shutdown) + relocationOffset); - - // Put the correct DLDI magic string back into the DLDI header - memcpy (pAH, dldiMagicString, sizeof (dldiMagicString)); - - if (pDH[DO_fixSections] & FIX_ALL) { - // Search through and fix pointers within the data section of the file - for (addrIter = (readAddr(pDH, DO_text_start) - ddmemStart); addrIter < (readAddr(pDH, DO_data_end) - ddmemStart); addrIter++) { - if ((ddmemStart <= readAddr(pAH, addrIter)) && (readAddr(pAH, addrIter) < ddmemEnd)) { - writeAddr (pAH, addrIter, readAddr(pAH, addrIter) + relocationOffset); - } - } - } - - if (pDH[DO_fixSections] & FIX_GLUE) { - // Search through and fix pointers within the glue section of the file - for (addrIter = (readAddr(pDH, DO_glue_start) - ddmemStart); addrIter < (readAddr(pDH, DO_glue_end) - ddmemStart); addrIter++) { - if ((ddmemStart <= readAddr(pAH, addrIter)) && (readAddr(pAH, addrIter) < ddmemEnd)) { - writeAddr (pAH, addrIter, readAddr(pAH, addrIter) + relocationOffset); - } - } - } - - if (pDH[DO_fixSections] & FIX_GOT) { - // Search through and fix pointers within the Global Offset Table section of the file - for (addrIter = (readAddr(pDH, DO_got_start) - ddmemStart); addrIter < (readAddr(pDH, DO_got_end) - ddmemStart); addrIter++) { - if ((ddmemStart <= readAddr(pAH, addrIter)) && (readAddr(pAH, addrIter) < ddmemEnd)) { - writeAddr (pAH, addrIter, readAddr(pAH, addrIter) + relocationOffset); - } - } - } - - if (pDH[DO_fixSections] & FIX_BSS) { - // Initialise the BSS to 0 - memset (&pAH[readAddr(pDH, DO_bss_start) - ddmemStart] , 0, readAddr(pDH, DO_bss_end) - readAddr(pDH, DO_bss_start)); - } - - return true; -} -#endif \ No newline at end of file diff --git a/gbapatcher/bootloader/source/dldi_patcher.h b/gbapatcher/bootloader/source/dldi_patcher.h deleted file mode 100644 index f54c531ba1..0000000000 --- a/gbapatcher/bootloader/source/dldi_patcher.h +++ /dev/null @@ -1,32 +0,0 @@ -/*----------------------------------------------------------------- - - Copyright (C) 2005 Michael "Chishm" Chisholm - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - If you use this code, please give due credit and email me about your - project at chishm@hotmail.com -------------------------------------------------------------------*/ - -#ifndef DLDI_PATCHER_H -#define DLDI_PATCHER_H - -#include - -typedef signed int addr_t; -typedef unsigned char data_t; -bool dldiPatchBinary (data_t *binData, u32 binSize); - -#endif // DLDI_PATCHER_H diff --git a/gbapatcher/bootloader/source/fat.c b/gbapatcher/bootloader/source/fat.c deleted file mode 100644 index 5d36f8c392..0000000000 --- a/gbapatcher/bootloader/source/fat.c +++ /dev/null @@ -1,544 +0,0 @@ -/*----------------------------------------------------------------- - fat.c - - NDS MP - GBAMP NDS Firmware Hack Version 2.12 - An NDS aware firmware patch for the GBA Movie Player. - By Michael Chisholm (Chishm) - - Filesystem code based on GBAMP_CF.c by Chishm (me). - -License: - Copyright (C) 2005 Michael "Chishm" Chisholm - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - If you use this code, please give due credit and email me about your - project at chishm@hotmail.com -------------------------------------------------------------------*/ - -#include "fat.h" -#include "card.h" - - -//--------------------------------------------------------------- -// FAT constants - -#define FILE_LAST 0x00 -#define FILE_FREE 0xE5 - -#define ATTRIB_ARCH 0x20 -#define ATTRIB_DIR 0x10 -#define ATTRIB_LFN 0x0F -#define ATTRIB_VOL 0x08 -#define ATTRIB_HID 0x02 -#define ATTRIB_SYS 0x04 -#define ATTRIB_RO 0x01 - -#define FAT16_ROOT_DIR_CLUSTER 0x00 - -// File Constants -#ifndef EOF -#define EOF -1 -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 -#endif - - -//----------------------------------------------------------------- -// FAT constants -#define CLUSTER_EOF_16 0xFFFF - -#define ATTRIB_ARCH 0x20 -#define ATTRIB_DIR 0x10 -#define ATTRIB_LFN 0x0F -#define ATTRIB_VOL 0x08 -#define ATTRIB_HID 0x02 -#define ATTRIB_SYS 0x04 -#define ATTRIB_RO 0x01 - -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// Data Structures - -#define __PACKED __attribute__ ((__packed__)) - -// Boot Sector - must be packed -typedef struct -{ - u8 jmpBoot[3]; - u8 OEMName[8]; - // BIOS Parameter Block - u16 bytesPerSector; - u8 sectorsPerCluster; - u16 reservedSectors; - u8 numFATs; - u16 rootEntries; - u16 numSectorsSmall; - u8 mediaDesc; - u16 sectorsPerFAT; - u16 sectorsPerTrk; - u16 numHeads; - u32 numHiddenSectors; - u32 numSectors; - union // Different types of extended BIOS Parameter Block for FAT16 and FAT32 - { - struct - { - // Ext BIOS Parameter Block for FAT16 - u8 driveNumber; - u8 reserved1; - u8 extBootSig; - u32 volumeID; - u8 volumeLabel[11]; - u8 fileSysType[8]; - // Bootcode - u8 bootCode[448]; - } fat16; - struct - { - // FAT32 extended block - u32 sectorsPerFAT32; - u16 extFlags; - u16 fsVer; - u32 rootClus; - u16 fsInfo; - u16 bkBootSec; - u8 reserved[12]; - // Ext BIOS Parameter Block for FAT16 - u8 driveNumber; - u8 reserved1; - u8 extBootSig; - u32 volumeID; - u8 volumeLabel[11]; - u8 fileSysType[8]; - // Bootcode - u8 bootCode[420]; - } fat32; - } extBlock; - - __PACKED u16 bootSig; - -} __PACKED BOOT_SEC; - -// Directory entry - must be packed -typedef struct -{ - u8 name[8]; - u8 ext[3]; - u8 attrib; - u8 reserved; - u8 cTime_ms; - u16 cTime; - u16 cDate; - u16 aDate; - u16 startClusterHigh; - u16 mTime; - u16 mDate; - u16 startCluster; - u32 fileSize; -} __PACKED DIR_ENT; - -// File information - no need to pack -typedef struct -{ - u32 firstCluster; - u32 length; - u32 curPos; - u32 curClus; // Current cluster to read from - int curSect; // Current sector within cluster - int curByte; // Current byte within sector - char readBuffer[512]; // Buffer used for unaligned reads - u32 appClus; // Cluster to append to - int appSect; // Sector within cluster for appending - int appByte; // Byte within sector for appending - bool read; // Can read from file - bool write; // Can write to file - bool append;// Can append to file - bool inUse; // This file is open - u32 dirEntSector; // The sector where the directory entry is stored - int dirEntOffset; // The offset within the directory sector -} FAT_FILE; - - -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// Global Variables - -// _VARS_IN_RAM variables are stored in the largest section of WRAM -// available: IWRAM on NDS ARM7, EWRAM on NDS ARM9 and GBA - -// Locations on card -int discRootDir; -int discRootDirClus; -int discFAT; -int discSecPerFAT; -int discNumSec; -int discData; -int discBytePerSec; -int discSecPerClus; -int discBytePerClus; - -enum {FS_UNKNOWN, FS_FAT12, FS_FAT16, FS_FAT32} discFileSystem; - -// Global sector buffer to save on stack space -unsigned char globalBuffer[sizeof(BOOT_SEC)]; - - -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -//FAT routines - -u32 FAT_ClustToSect (u32 cluster) { - return (((cluster-2) * discSecPerClus) + discData); -} - -/*----------------------------------------------------------------- -FAT_NextCluster -Internal function - gets the cluster linked from input cluster ------------------------------------------------------------------*/ -u32 FAT_NextCluster(u32 cluster) -{ - u32 nextCluster = CLUSTER_FREE; - u32 sector; - int offset; - - - switch (discFileSystem) - { - case FS_UNKNOWN: - nextCluster = CLUSTER_FREE; - break; - - case FS_FAT12: - sector = discFAT + (((cluster * 3) / 2) / BYTES_PER_SECTOR); - offset = ((cluster * 3) / 2) % BYTES_PER_SECTOR; - CARD_ReadSector(sector, globalBuffer); - nextCluster = ((u8*) globalBuffer)[offset]; - offset++; - - if (offset >= BYTES_PER_SECTOR) { - offset = 0; - sector++; - } - - CARD_ReadSector(sector, globalBuffer); - nextCluster |= (((u8*) globalBuffer)[offset]) << 8; - - if (cluster & 0x01) { - nextCluster = nextCluster >> 4; - } else { - nextCluster &= 0x0FFF; - } - - break; - - case FS_FAT16: - sector = discFAT + ((cluster << 1) / BYTES_PER_SECTOR); - offset = cluster % (BYTES_PER_SECTOR >> 1); - - CARD_ReadSector(sector, globalBuffer); - // read the nextCluster value - nextCluster = ((u16*)globalBuffer)[offset]; - - if (nextCluster >= 0xFFF7) { - nextCluster = CLUSTER_EOF; - } - break; - - case FS_FAT32: - sector = discFAT + ((cluster << 2) / BYTES_PER_SECTOR); - offset = cluster % (BYTES_PER_SECTOR >> 2); - - CARD_ReadSector(sector, globalBuffer); - // read the nextCluster value - nextCluster = (((u32*)globalBuffer)[offset]) & 0x0FFFFFFF; - - if (nextCluster >= 0x0FFFFFF7) { - nextCluster = CLUSTER_EOF; - } - break; - - default: - nextCluster = CLUSTER_FREE; - break; - } - - return nextCluster; -} - -/*----------------------------------------------------------------- -ucase -Returns the uppercase version of the given char -char IN: a character -char return OUT: uppercase version of character ------------------------------------------------------------------*/ -char ucase (char character) -{ - if ((character > 0x60) && (character < 0x7B)) - character = character - 0x20; - return (character); -} - -/*----------------------------------------------------------------- -FAT_InitFiles -Reads the FAT information from the CF card. -You need to call this before reading any files. -bool return OUT: true if successful. ------------------------------------------------------------------*/ -bool FAT_InitFiles (bool initCard) -{ - int i; - int bootSector; - BOOT_SEC* bootSec; - - if (initCard && !CARD_StartUp()) { - return (false); - } - - // Read first sector of card - if (!CARD_ReadSector (0, globalBuffer)) - { - return false; - } - - if (((globalBuffer[0x36] == 'F') && (globalBuffer[0x37] == 'A') && (globalBuffer[0x38] == 'T')) // Check if there is a FAT string, which indicates this is a boot sector - || ((globalBuffer[0x52] == 'F') && (globalBuffer[0x53] == 'A') && (globalBuffer[0x54] == 'T'))) { // Check for FAT32 - bootSector = 0; - } else // This is an MBR - { - // Find first valid partition from MBR - // First check for an active partition - for (i=0x1BE; (i < 0x1FE) && (globalBuffer[i] != 0x80); i+= 0x10); - // If it didn't find an active partition, search for any valid partition - if (i == 0x1FE) - for (i=0x1BE; (i < 0x1FE) && (globalBuffer[i+0x04] == 0x00); i+= 0x10); - - // Go to first valid partition - if (i != 0x1FE) // Make sure it found a partition - { - bootSector = globalBuffer[0x8 + i] + (globalBuffer[0x9 + i] << 8) + (globalBuffer[0xA + i] << 16) + ((globalBuffer[0xB + i] << 24) & 0x0F); - } else { - bootSector = 0; // No partition found, assume this is a MBR free disk - } - } - - // Read in boot sector - bootSec = (BOOT_SEC*) globalBuffer; - CARD_ReadSector (bootSector, bootSec); - - // Store required information about the file system - if (bootSec->sectorsPerFAT != 0) { - discSecPerFAT = bootSec->sectorsPerFAT; - } else { - discSecPerFAT = bootSec->extBlock.fat32.sectorsPerFAT32; - } - - if (bootSec->numSectorsSmall != 0) { - discNumSec = bootSec->numSectorsSmall; - } else { - discNumSec = bootSec->numSectors; - } - - discBytePerSec = BYTES_PER_SECTOR; // Sector size is redefined to be 512 bytes - discSecPerClus = bootSec->sectorsPerCluster * bootSec->bytesPerSector / BYTES_PER_SECTOR; - discBytePerClus = discBytePerSec * discSecPerClus; - discFAT = bootSector + bootSec->reservedSectors; - - discRootDir = discFAT + (bootSec->numFATs * discSecPerFAT); - discData = discRootDir + ((bootSec->rootEntries * sizeof(DIR_ENT)) / BYTES_PER_SECTOR); - - if ((discNumSec - discData) / bootSec->sectorsPerCluster < 4085) { - discFileSystem = FS_FAT12; - } else if ((discNumSec - discData) / bootSec->sectorsPerCluster < 65525) { - discFileSystem = FS_FAT16; - } else { - discFileSystem = FS_FAT32; - } - - if (discFileSystem != FS_FAT32) { - discRootDirClus = FAT16_ROOT_DIR_CLUSTER; - } else // Set up for the FAT32 way - { - discRootDirClus = bootSec->extBlock.fat32.rootClus; - // Check if FAT mirroring is enabled - if (!(bootSec->extBlock.fat32.extFlags & 0x80)) { - // Use the active FAT - discFAT = discFAT + (discSecPerFAT * (bootSec->extBlock.fat32.extFlags & 0x0F)); - } - } - - return (true); -} - - -/*----------------------------------------------------------------- -getBootFileCluster ------------------------------------------------------------------*/ -u32 getBootFileCluster (const char* bootName) -{ - DIR_ENT dir; - int firstSector = 0; - bool notFound = false; - bool found = false; -// int maxSectors; - u32 wrkDirCluster = discRootDirClus; - u32 wrkDirSector = 0; - int wrkDirOffset = 0; - int nameOffset; - - dir.startCluster = CLUSTER_FREE; // default to no file found - dir.startClusterHigh = CLUSTER_FREE; - - - // Check if fat has been initialised - if (discBytePerSec == 0) { - return (CLUSTER_FREE); - } - - char *ptr = (char*)bootName; - while (*ptr != '.') ptr++; - int namelen = ptr - bootName; - -// maxSectors = (wrkDirCluster == FAT16_ROOT_DIR_CLUSTER ? (discData - discRootDir) : discSecPerClus); - // Scan Dir for correct entry - firstSector = discRootDir; - CARD_ReadSector (firstSector + wrkDirSector, globalBuffer); - found = false; - notFound = false; - wrkDirOffset = -1; // Start at entry zero, Compensating for increment - while (!found && !notFound) { - wrkDirOffset++; - if (wrkDirOffset == BYTES_PER_SECTOR / sizeof (DIR_ENT)) { - wrkDirOffset = 0; - wrkDirSector++; - if ((wrkDirSector == discSecPerClus) && (wrkDirCluster != FAT16_ROOT_DIR_CLUSTER)) { - wrkDirSector = 0; - wrkDirCluster = FAT_NextCluster(wrkDirCluster); - if (wrkDirCluster == CLUSTER_EOF) { - notFound = true; - } - firstSector = FAT_ClustToSect(wrkDirCluster); - } else if ((wrkDirCluster == FAT16_ROOT_DIR_CLUSTER) && (wrkDirSector == (discData - discRootDir))) { - notFound = true; // Got to end of root dir - } - CARD_ReadSector (firstSector + wrkDirSector, globalBuffer); - } - dir = ((DIR_ENT*) globalBuffer)[wrkDirOffset]; - found = true; - if ((dir.attrib & ATTRIB_DIR) || (dir.attrib & ATTRIB_VOL)) { - found = false; - } - if (namelen<8 && dir.name[namelen]!=0x20) found = false; - for (nameOffset = 0; nameOffset < namelen && found; nameOffset++) { - if (ucase(dir.name[nameOffset]) != bootName[nameOffset]) - found = false; - } - for (nameOffset = 0; nameOffset < 3 && found; nameOffset++) { - if (ucase(dir.ext[nameOffset]) != bootName[nameOffset+namelen+1]) - found = false; - } - if (dir.name[0] == FILE_LAST) { - notFound = true; - } - } - - // If no file is found, return CLUSTER_FREE - if (notFound) { - return CLUSTER_FREE; - } - - return (dir.startCluster | (dir.startClusterHigh << 16)); -} - -/*----------------------------------------------------------------- -fileRead(buffer, cluster, startOffset, length) ------------------------------------------------------------------*/ -u32 fileRead (char* buffer, u32 cluster, u32 startOffset, u32 length) -{ - int curByte; - int curSect; - - int dataPos = 0; - int chunks; - int beginBytes; - - if (cluster == CLUSTER_FREE || cluster == CLUSTER_EOF) - { - return 0; - } - - // Follow cluster list until desired one is found - for (chunks = startOffset / discBytePerClus; chunks > 0; chunks--) { - cluster = FAT_NextCluster (cluster); - } - - // Calculate the sector and byte of the current position, - // and store them - curSect = (startOffset % discBytePerClus) / BYTES_PER_SECTOR; - curByte = startOffset % BYTES_PER_SECTOR; - - // Load sector buffer for new position in file - CARD_ReadSector(curSect + FAT_ClustToSect(cluster), globalBuffer); - curSect++; - - // Number of bytes needed to read to align with a sector - beginBytes = (BYTES_PER_SECTOR < length + curByte ? (BYTES_PER_SECTOR - curByte) : length); - - // Read first part from buffer, to align with sector boundary - for (dataPos = 0 ; dataPos < beginBytes; dataPos++) { - buffer[dataPos] = globalBuffer[curByte++]; - } - - // Read in all the 512 byte chunks of the file directly, saving time - for (chunks = ((int)length - beginBytes) / BYTES_PER_SECTOR; chunks > 0;) { - int sectorsToRead; - - // Move to the next cluster if necessary - if (curSect >= discSecPerClus) { - curSect = 0; - cluster = FAT_NextCluster (cluster); - } - - // Calculate how many sectors to read (read a maximum of discSecPerClus at a time) - sectorsToRead = discSecPerClus - curSect; - if (chunks < sectorsToRead) - sectorsToRead = chunks; - - // Read the sectors - CARD_ReadSectors(curSect + FAT_ClustToSect(cluster), sectorsToRead, buffer + dataPos); - chunks -= sectorsToRead; - curSect += sectorsToRead; - dataPos += BYTES_PER_SECTOR * sectorsToRead; - } - - // Take care of any bytes left over before end of read - if (dataPos < length) { - - // Update the read buffer - curByte = 0; - if (curSect >= discSecPerClus) { - curSect = 0; - cluster = FAT_NextCluster (cluster); - } - CARD_ReadSector( curSect + FAT_ClustToSect( cluster), globalBuffer); - - // Read in last partial chunk - for (; dataPos < length; dataPos++) { - buffer[dataPos] = globalBuffer[curByte]; - curByte++; - } - } - - return dataPos; -} diff --git a/gbapatcher/bootloader/source/fat.h b/gbapatcher/bootloader/source/fat.h deleted file mode 100644 index d39076baba..0000000000 --- a/gbapatcher/bootloader/source/fat.h +++ /dev/null @@ -1,46 +0,0 @@ -/*----------------------------------------------------------------- - fat.h - - NDS MP - GBAMP NDS Firmware Hack Version 2.12 - An NDS aware firmware patch for the GBA Movie Player. - By Michael Chisholm (Chishm) - - Filesystem code based on GBAMP_CF.c by Chishm (me). - -License: - Copyright (C) 2005 Michael "Chishm" Chisholm - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - If you use this code, please give due credit and email me about your - project at chishm@hotmail.com -------------------------------------------------------------------*/ - -#ifndef FAT_H -#define FAT_H - -#include - -#define CLUSTER_FREE 0x00000000 -#define CLUSTER_EOF 0x0FFFFFFF -#define CLUSTER_FIRST 0x00000002 - -bool FAT_InitFiles (bool initCard); -u32 getBootFileCluster (const char* bootName); -u32 fileRead (char* buffer, u32 cluster, u32 startOffset, u32 length); -u32 FAT_ClustToSect (u32 cluster); - -#endif // FAT_H diff --git a/gbapatcher/bootloader/source/i2c.c b/gbapatcher/bootloader/source/i2c.c deleted file mode 100644 index 44a0556f9c..0000000000 --- a/gbapatcher/bootloader/source/i2c.c +++ /dev/null @@ -1,132 +0,0 @@ -/*--------------------------------------------------------------------------------- - - I2C control for the ARM7 - - Copyright (C) 2011 - Dave Murphy (WinterMute) - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you - must not claim that you wrote the original software. If you use - this software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and - must not be misrepresented as being the original software. - 3. This notice may not be removed or altered from any source - distribution. - ----------------------------------------------------------------------------------*/ - -#include -#include - -static u32 i2cCurrentDelay = 0; - -//--------------------------------------------------------------------------------- -void i2cDelay() { -//--------------------------------------------------------------------------------- - i2cWaitBusy(); - swiDelay(i2cCurrentDelay); -} - -//--------------------------------------------------------------------------------- -void i2cStop(u8 arg0) { -//--------------------------------------------------------------------------------- - if (i2cCurrentDelay) { - REG_I2CCNT = (arg0 << 5) | 0xC0; - i2cDelay(); - REG_I2CCNT = 0xC5; - } else REG_I2CCNT = (arg0 << 5) | 0xC1; -} - - -//--------------------------------------------------------------------------------- -u8 i2cGetResult() { -//--------------------------------------------------------------------------------- - i2cWaitBusy(); - return (REG_I2CCNT >> 4) & 0x01; -} - -//--------------------------------------------------------------------------------- -u8 i2cGetData() { -//--------------------------------------------------------------------------------- - i2cWaitBusy(); - return REG_I2CDATA; -} - -//--------------------------------------------------------------------------------- -void i2cSetDelay(u8 device) { -//--------------------------------------------------------------------------------- - if (device == I2C_PM) { - i2cCurrentDelay = 0x180; - } else { - i2cCurrentDelay = 0; - } -} - -//--------------------------------------------------------------------------------- -u8 i2cSelectDevice(u8 device) { -//--------------------------------------------------------------------------------- - i2cWaitBusy(); - REG_I2CDATA = device; - REG_I2CCNT = 0xC2; - return i2cGetResult(); -} - -//--------------------------------------------------------------------------------- -u8 i2cSelectRegister(u8 reg) { -//--------------------------------------------------------------------------------- - i2cDelay(); - REG_I2CDATA = reg; - REG_I2CCNT = 0xC0; - return i2cGetResult(); -} - -//--------------------------------------------------------------------------------- -u8 i2cWriteRegister(u8 device, u8 reg, u8 data) { -//--------------------------------------------------------------------------------- - i2cSetDelay(device); - int i; - - for (i = 0; i < 8; i++) { - if ((i2cSelectDevice(device) != 0) && (i2cSelectRegister(reg) != 0)) { - i2cDelay(); - REG_I2CDATA = data; - i2cStop(0); - if (i2cGetResult() != 0) return 1; - } - REG_I2CCNT = 0xC5; - } - - return 0; -} - -//--------------------------------------------------------------------------------- -u8 i2cReadRegister(u8 device, u8 reg) { -//--------------------------------------------------------------------------------- - i2cSetDelay(device); - int i; - - for (i = 0; i < 8; i++) { - - if ((i2cSelectDevice(device) != 0) && (i2cSelectRegister(reg) != 0)) { - i2cDelay(); - if (i2cSelectDevice(device | 1)) { - i2cDelay(); - i2cStop(1); - return i2cGetData(); - } - } - - REG_I2CCNT = 0xC5; - } - - return 0xff; -} \ No newline at end of file diff --git a/gbapatcher/bootloader/source/i2c.h b/gbapatcher/bootloader/source/i2c.h deleted file mode 100644 index 72f2bba131..0000000000 --- a/gbapatcher/bootloader/source/i2c.h +++ /dev/null @@ -1,65 +0,0 @@ -/*--------------------------------------------------------------------------------- - - I2C control for the ARM7 - - Copyright (C) 2011 - Dave Murphy (WinterMute) - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you - must not claim that you wrote the original software. If you use - this software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and - must not be misrepresented as being the original software. - 3. This notice may not be removed or altered from any source - distribution. - ----------------------------------------------------------------------------------*/ -#ifndef I2C_ARM7_INCLUDE -#define I2C_ARM7_INCLUDE - -#ifndef ARM7 -#error i2c header is for ARM7 only -#endif - -#include - -#define REG_I2CDATA (*(vu8 *)0x4004500) -#define REG_I2CCNT (*(vu8 *)0x4004501) - -static inline void i2cWaitBusy() { - while (REG_I2CCNT & 0x80); -} - -enum i2cDevices { - I2C_CAM0 = 0x7A, - I2C_CAM1 = 0x78, - I2C_UNK1 = 0xA0, - I2C_UNK2 = 0xE0, - I2C_PM = 0x4A, - I2C_UNK3 = 0x40, - I2C_GPIO = 0x90 -}; - -// Registers for Power Management (I2C_PM) -#define I2CREGPM_BATUNK 0x00 -#define I2CREGPM_PWRIF 0x10 -#define I2CREGPM_PWRCNT 0x11 -#define I2CREGPM_MMCPWR 0x12 -#define I2CREGPM_BATTERY 0x20 -#define I2CREGPM_CAMLED 0x31 -#define I2CREGPM_VOL 0x40 -#define I2CREGPM_RESETFLAG 0x70 - -u8 i2cWriteRegister(u8 device, u8 reg, u8 data); -u8 i2cReadRegister(u8 device, u8 reg); - -#endif // I2C_ARM7_INCLUDE \ No newline at end of file diff --git a/gbapatcher/bootloader/source/io_dldi.h b/gbapatcher/bootloader/source/io_dldi.h deleted file mode 100644 index e0f4efa98a..0000000000 --- a/gbapatcher/bootloader/source/io_dldi.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - io_dldi.h - - Reserved space for post-compilation adding of an extra driver - - Copyright (c) 2006 Michael "Chishm" Chisholm - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation and/or - other materials provided with the distribution. - 3. The name of the author may not be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - 2006-12-22 - Chishm - * Original release -*/ - -#ifndef IO_DLDI_H -#define IO_DLDI_H - -// 'DLDD' -#define DEVICE_TYPE_DLDD 0x49444C44 - -#include "disc_io.h" - -// export interface -extern IO_INTERFACE _io_dldi ; - -#endif // define IO_DLDI_H diff --git a/gbapatcher/bootloader/source/io_dldi.s b/gbapatcher/bootloader/source/io_dldi.s deleted file mode 100644 index 08ac2cf002..0000000000 --- a/gbapatcher/bootloader/source/io_dldi.s +++ /dev/null @@ -1,124 +0,0 @@ -/*----------------------------------------------------------------- - - Copyright (C) 2005 Michael "Chishm" Chisholm - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - If you use this code, please give due credit and email me about your - project at chishm@hotmail.com -------------------------------------------------------------------*/ -@--------------------------------------------------------------------------------- - .align 4 - .arm - .global _dldi_start - .global _io_dldi -@--------------------------------------------------------------------------------- -.equ FEATURE_MEDIUM_CANREAD, 0x00000001 -.equ FEATURE_MEDIUM_CANWRITE, 0x00000002 -.equ FEATURE_SLOT_GBA, 0x00000010 -.equ FEATURE_SLOT_NDS, 0x00000020 - - -_dldi_start: -#ifndef NO_DLDI - -@--------------------------------------------------------------------------------- -@ Driver patch file standard header -- 16 bytes -#ifdef STANDARD_DLDI - .word 0xBF8DA5ED @ Magic number to identify this region -#else - .word 0xBF8DA5EE @ Magic number to identify this region -#endif - .asciz " Chishm" @ Identifying Magic string (8 bytes with null terminator) - .byte 0x01 @ Version number - .byte 0x0f @ 32KiB @ Log [base-2] of the size of this driver in bytes. - .byte 0x00 @ Sections to fix - .byte 0x0f @ 32KiB @ Log [base-2] of the allocated space in bytes. - -@--------------------------------------------------------------------------------- -@ Text identifier - can be anything up to 47 chars + terminating null -- 16 bytes - .align 4 - .asciz "Loader (No interface)" - -@--------------------------------------------------------------------------------- -@ Offsets to important sections within the data -- 32 bytes - .align 6 - .word _dldi_start @ data start - .word _dldi_end @ data end - .word 0x00000000 @ Interworking glue start -- Needs address fixing - .word 0x00000000 @ Interworking glue end - .word 0x00000000 @ GOT start -- Needs address fixing - .word 0x00000000 @ GOT end - .word 0x00000000 @ bss start -- Needs setting to zero - .word 0x00000000 @ bss end -@--------------------------------------------------------------------------------- -@ IO_INTERFACE data -- 32 bytes -_io_dldi: - .ascii "DLDI" @ ioType - .word 0x00000000 @ Features - .word _DLDI_startup @ - .word _DLDI_isInserted @ - .word _DLDI_readSectors @ Function pointers to standard device driver functions - .word _DLDI_writeSectors @ - .word _DLDI_clearStatus @ - .word _DLDI_shutdown @ - - -@--------------------------------------------------------------------------------- - -_DLDI_startup: -_DLDI_isInserted: -_DLDI_readSectors: -_DLDI_writeSectors: -_DLDI_clearStatus: -_DLDI_shutdown: - mov r0, #0x00 @ Return false for every function - bx lr - - - -@--------------------------------------------------------------------------------- - .align - .pool - - .space (_dldi_start + 32768) - . @ Fill to 32KiB - -_dldi_end: - .end -@--------------------------------------------------------------------------------- -#else -@--------------------------------------------------------------------------------- -@ IO_INTERFACE data -- 32 bytes -_io_dldi: - .ascii "DLDI" @ ioType - .word 0x00000000 @ Features - .word _DLDI_startup @ - .word _DLDI_isInserted @ - .word _DLDI_readSectors @ Function pointers to standard device driver functions - .word _DLDI_writeSectors @ - .word _DLDI_clearStatus @ - .word _DLDI_shutdown @ - - _DLDI_startup: -_DLDI_isInserted: -_DLDI_readSectors: -_DLDI_writeSectors: -_DLDI_clearStatus: -_DLDI_shutdown: - mov r0, #0x00 @ Return false for every function - bx lr - - -#endif diff --git a/gbapatcher/bootloader/source/load_crt0.s b/gbapatcher/bootloader/source/load_crt0.s index bf57363123..d8a1064822 100644 --- a/gbapatcher/bootloader/source/load_crt0.s +++ b/gbapatcher/bootloader/source/load_crt0.s @@ -23,48 +23,12 @@ @--------------------------------------------------------------------------------- .section ".init" .global _start - .global storedFileCluster - .global initDisc - .global wantToPatchDLDI - .global argStart - .global argSize - .global dsiSD - .global dsiMode - .global clearMasterBright - .global dsMode - .global loadFromRam @--------------------------------------------------------------------------------- .align 4 .arm @--------------------------------------------------------------------------------- _start: @--------------------------------------------------------------------------------- - b startUp - -storedFileCluster: - .word 0x0FFFFFFF @ default BOOT.NDS -initDisc: - .word 0x00000001 @ init the disc by default -wantToPatchDLDI: - .word 0x00000001 @ by default patch the DLDI section of the loaded NDS -@ Used for passing arguments to the loaded app -argStart: - .word _end - _start -argSize: - .word 0x00000000 -dldiOffset: - .word _dldi_start - _start -dsiSD: - .word 0 -dsiMode: - .word 0 -clearMasterBright: - .word 0 -dsMode: - .word 0 -loadFromRam: - .word 0 - startUp: mov r0, #0x04000000 mov r1, #0