From 48045460db2871280668df32b78a10b18d2c9001 Mon Sep 17 00:00:00 2001 From: yutaka Date: Wed, 2 Apr 2008 10:09:55 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=BBsdmc-launcher-writer=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=20=E3=83=BBnvram=E3=83=A9=E3=82=A4=E3=83=96=E3=83=A9?= =?UTF-8?q?=E3=83=AA=E3=81=AE=E8=BF=BD=E5=8A=A0=20=E3=83=BBgcd=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=83=96=E3=83=A9=E3=83=AA=E3=81=AE=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E5=89=8A=E9=99=A4=20(=E5=85=83=E3=81=8B=E3=82=89=E4=BD=BF?= =?UTF-8?q?=E3=81=A3=E3=81=A6=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1043 b08762b0-b915-fc4b-9d8c-17b2551a87ff --- build/buildtools/commondefs.firm | 1 + build/gcdfirm/Makefile | 5 +- .../sdmc-launcher-writer/ARM7/Makefile | 55 + .../gcdfirm/sdmc-launcher-writer/ARM7/main.c | 287 +++ .../sdmc-launcher-writer}/ARM9/Makefile | 38 +- .../gcdfirm/sdmc-launcher-writer/ARM9/font.c | 588 ++++++ .../sdmc-launcher-writer/ARM9/include/font.h | 60 + .../ARM9/include/screen.h | 52 + .../gcdfirm/sdmc-launcher-writer/ARM9/main.c | 231 +++ .../sdmc-launcher-writer/ARM9/screen.c | 120 ++ build/gcdfirm/sdmc-launcher-writer/Makefile | 57 + .../sdmc-launcher-writer/wram_regs/Makefile | 57 + .../wram_regs/wram_regs.c | 91 + build/libraries/Makefile | 6 +- build/libraries/gcd/common/blowfish.c | 149 -- build/libraries/gcd/common/ds_blowfish.c | 186 -- .../libraries/gcd/common/ds_blowfish_table.c | 286 --- build/libraries/gcd/common/gcd.c | 1215 ------------ build/libraries/gcd/common/gcd_init.c | 1696 ----------------- build/libraries/{gcd => nvram}/ARM7/Makefile | 13 +- build/libraries/nvram/ARM7/nvram_misc.c | 180 ++ build/libraries/{gcd => nvram}/Makefile | 15 +- include/firm.h | 1 + include/firm/gcd.h | 26 - include/firm/gcd/gcd.h | 779 -------- include/firm/gcd/gcd_misc.h | 516 ----- 26 files changed, 1814 insertions(+), 4896 deletions(-) create mode 100644 build/gcdfirm/sdmc-launcher-writer/ARM7/Makefile create mode 100644 build/gcdfirm/sdmc-launcher-writer/ARM7/main.c rename build/{libraries/gcd => gcdfirm/sdmc-launcher-writer}/ARM9/Makefile (62%) create mode 100644 build/gcdfirm/sdmc-launcher-writer/ARM9/font.c create mode 100644 build/gcdfirm/sdmc-launcher-writer/ARM9/include/font.h create mode 100644 build/gcdfirm/sdmc-launcher-writer/ARM9/include/screen.h create mode 100644 build/gcdfirm/sdmc-launcher-writer/ARM9/main.c create mode 100644 build/gcdfirm/sdmc-launcher-writer/ARM9/screen.c create mode 100644 build/gcdfirm/sdmc-launcher-writer/Makefile create mode 100644 build/gcdfirm/sdmc-launcher-writer/wram_regs/Makefile create mode 100644 build/gcdfirm/sdmc-launcher-writer/wram_regs/wram_regs.c delete mode 100644 build/libraries/gcd/common/blowfish.c delete mode 100644 build/libraries/gcd/common/ds_blowfish.c delete mode 100644 build/libraries/gcd/common/ds_blowfish_table.c delete mode 100644 build/libraries/gcd/common/gcd.c delete mode 100644 build/libraries/gcd/common/gcd_init.c rename build/libraries/{gcd => nvram}/ARM7/Makefile (81%) create mode 100644 build/libraries/nvram/ARM7/nvram_misc.c rename build/libraries/{gcd => nvram}/Makefile (80%) delete mode 100644 include/firm/gcd.h delete mode 100644 include/firm/gcd/gcd.h delete mode 100644 include/firm/gcd/gcd_misc.h diff --git a/build/buildtools/commondefs.firm b/build/buildtools/commondefs.firm index afe93ae2..14147dc7 100644 --- a/build/buildtools/commondefs.firm +++ b/build/buildtools/commondefs.firm @@ -88,6 +88,7 @@ FIRM_LIBS_BASE ?= \ libfs_sp \ libaes_sp \ libpm_sp \ + libnvram_sp \ endif diff --git a/build/gcdfirm/Makefile b/build/gcdfirm/Makefile index d6d1b53b..a13d738f 100644 --- a/build/gcdfirm/Makefile +++ b/build/gcdfirm/Makefile @@ -12,8 +12,8 @@ # in whole or in part, without the prior written consent of Nintendo. # # $Date:: $ -# $Rev:$ -# $Author:$ +# $Rev$ +# $Author$ #---------------------------------------------------------------------------- include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs @@ -25,6 +25,7 @@ SUBDIRS = \ gcdfirm-disp \ gcdfirm-print \ sdmc-launcher \ + sdmc-launcher-writer \ #---------------------------------------------------------------------------- diff --git a/build/gcdfirm/sdmc-launcher-writer/ARM7/Makefile b/build/gcdfirm/sdmc-launcher-writer/ARM7/Makefile new file mode 100644 index 00000000..4a2ee6a5 --- /dev/null +++ b/build/gcdfirm/sdmc-launcher-writer/ARM7/Makefile @@ -0,0 +1,55 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - menu-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +TWL_PROC = ARM7 + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = sdmc_launcher_writer7.tef + +SRCS = main.c + +CRT0_O = crt0_firm.o + +ADDRESS_STATIC = 0x037b8000 + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + +LINCLUDES = $(ROOT)/build/libraries/fatfs/ARM7.TWL/include \ + $(ROOT)/build/libraries/fatfs/ARM7.TWL/include/fatfs \ + $(ROOT)/build/libraries/fatfs/ARM7.TWL/include/twl/fatfs/ARM7 + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/gcdfirm/sdmc-launcher-writer/ARM7/main.c b/build/gcdfirm/sdmc-launcher-writer/ARM7/main.c new file mode 100644 index 00000000..79887536 --- /dev/null +++ b/build/gcdfirm/sdmc-launcher-writer/ARM7/main.c @@ -0,0 +1,287 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - gcdfirm - sdmc-launcher-writer + File: main.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include + +#include +#include + +#define PRINT_DEBUG + +#ifndef PRINT_DEBUG +#undef OS_TPrintf +#undef OS_PutChar +#define OS_TPrintf(...) ((void)0) +#define OS_PutChar(...) ((void)0) +#endif // PRINT_DEBUG + +/* + デバッグLEDをFINALROMとは別にOn/Offできます。 +*/ +#define USE_DEBUG_LED + +#ifdef USE_DEBUG_LED +static u8 step = 0x00; +#define InitDebugLED() I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x03, 0x00) +#define SetDebugLED(pattern) I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, (pattern)); +#else +#define InitDebugLED() ((void)0) +#define SetDebugLED(pattern) ((void)0) +#endif + +#define THREAD_PRIO_FATFS 8 + +#define DMA_FATFS_1 0 +#define DMA_FATFS_2 1 +#define DMA_CARD 2 + +static u8* const nor = (u8*)HW_TWL_MAIN_MEM; +static u8* const nand = (u8*)HW_TWL_MAIN_MEM + offsetof(NANDHeader,l); + +static OSThread idleThread; +static u64 idleStack[32]; +static void IdleThread(void* arg) +{ +#pragma unused(arg) + OS_EnableInterrupts(); + while (1) + { + OS_Halt(); + } +} +static void CreateIdleThread(void) +{ + OS_CreateThread(&idleThread, IdleThread, NULL, &idleStack[32], sizeof(idleStack), OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&idleThread); +} + +// MCU旧バージョン対策 +#if SDK_TS_VERSION <= 200 +static u8 version = 0; +#define IS_OLD_MCU (version ? (version < 0x20) : ((version=MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR )) < 0x20)) +#else +#define IS_OLD_MCU FALSE +#define MCU_OLD_REG_TEMP_ADDR MCU_REG_TEMP_ADDR // avoid compiler error +#endif + +/*************************************************************** + PreInit + + FromBootの対応&メインメモリの初期化 + OS_Init前なので注意 (ARM9によるメインメモリ初期化で消されないように注意) +***************************************************************/ +static void PreInit(void) +{ + GCDHeader* const gh = &OSi_GetFromBromAddr()->header.gcd; + /* + バッテリー残量チェック + */ + if ( !IS_OLD_MCU ) // MCU旧バージョン対策 + { + if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) + { +#ifndef SDK_FINALROM + OS_TPanic("Battery is empty.\n"); +#else + PM_Shutdown(); +#endif + } + } + MI_CpuCopyFast( gh, (void*)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END - HW_ROM_HEADER_BUF ); +// MI_CpuCopyFast( gh, (void*)HW_CARD_ROM_HEADER, HW_CARD_ROM_HEADER_SIZE ); + // FromBrom全消去 + MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) ); +} + +/*************************************************************** + PostInit + + 各種初期化 +***************************************************************/ +static void PostInit(void) +{ +#if SDK_TS_VERSION <= 200 + // PMICの設定 for old version + PM_InitFIRM(); +#endif +#if SDK_TS_VERSION <= 200 + PMi_SetParams( REG_PMIC_BL_BRT_A_ADDR, PMIC_BACKLIGHT_BRIGHT_DEFAULT, PMIC_BL_BRT_A_MASK ); + PMi_SetParams( REG_PMIC_BL_BRT_B_ADDR, PMIC_BACKLIGHT_BRIGHT_DEFAULT, PMIC_BL_BRT_B_MASK ); +#else + MCUi_WriteRegister( MCU_REG_BL_ADDR, MCU_REG_BL_BRIGHTNESS_MASK ); +#endif + PM_BackLightOn( TRUE ); + // アイドルスレッドの作成 + CreateIdleThread(); + // XYボタン通知 + PAD_InitXYButton(); + /* + バッテリー残量チェック + */ + if ( !IS_OLD_MCU ) // MCU旧バージョン対策 + { + if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) + { +#ifndef SDK_FINALROM + OS_TPanic("Battery is empty.\n"); +#else + PM_Shutdown(); +#endif + } + } +} + +/*************************************************************** + EraseAll + + 不正終了しました + いろいろ消してください + DSモードにして終わるのがよいか? +***************************************************************/ +static void EraseAll(void) +{ + GCDHeader* const gh = &OSi_GetFromBromAddr()->header.gcd; + AESi_ResetAesKeyA(); + AESi_ResetAesKeyB(); + AESi_ResetAesKeyC(); + MI_CpuClearFast( nor, (gh->l.nandfirm_size + 512) * 2 ); +} + +extern SDMC_ERR_CODE FATFSi_sdmcGoIdle(u16 ports, void (*func1)(),void (*func2)()); +void TwlSpMain( void ) +{ + GCDHeader* const gh = &OSi_GetFromBromAddr()->header.gcd; + u32 offset = gh->l.nandfirm_offset; + u32 size = gh->l.nandfirm_size; + u32 nsize = size - offsetof(NANDHeader,l); // size to write to nand + u32 sectors = (nsize + 511)/512; + u8* nor2 = nor + size; // buffer to verify + u8* nand2 = nand + size; // buffer to verify + + s32 lock_id; + SdmcResultInfo sdResult; + + InitDebugLED(); + SetDebugLED(++step); // 0x01 + + PreInit(); + SetDebugLED(++step); // 0x02 + + OS_InitFIRM(); + OS_EnableIrq(); + OS_EnableInterrupts(); + SetDebugLED(++step); // 0x03 + + PostInit(); + SetDebugLED(++step); // 0x04 + + // NAND初期化 + if (SDMC_NORMAL != FATFSi_sdmcInit( (SDMC_DMA_NO)DMA_FATFS_1, (SDMC_DMA_NO)DMA_FATFS_2 )) + { + OS_TPrintf("Failed to call FATFSi_sdmcInit().\n"); + goto err; + } + FATFSi_sdmcGoIdle( 2, NULL, NULL ); + FATFSi_sdmcSelect( SDMC_PORT_NAND ); + SetDebugLED(++step); // 0x05 + + // CARD初期化 + CARD_Init(); + CARD_Enable(TRUE); + lock_id = OS_GetLockID(); + CARD_LockRom((u16)lock_id); + SetDebugLED(++step); // 0x06 + + PXI_SendStream(&size, sizeof(size)); + + if ( size < sizeof(NANDHeader) ) + { + OS_TPrintf("No NAND firm is there.\n"); + goto err; + } + SetDebugLED(++step); // 0x07 + + // read all + CARD_ReadRom( DMA_CARD, (void*)offset, nor, size ); + SetDebugLED(++step); // 0x08 + + PXI_NotifyID( FIRM_PXI_ID_NULL ); + + // write NOR + NVRAMi_Write( 0, nor, sizeof(NORHeaderDS)); + SetDebugLED(++step); // 0x09 + + { // write boot_nandfirm flag + s32 tmp = -1; + NVRAMi_Write( 0x2ff, &tmp, 1 ); + } + SetDebugLED(++step); // 0x0a + + // write NAND + if ( FATFSi_sdmcWriteFifo( nand, sectors, 1, NULL, &sdResult ) ) + { + OS_TPrintf("Failed to call FATFSi_sdmcWriteFifo() to write header.\n"); + goto err; + } + SetDebugLED(++step); // 0x0b + + PXI_NotifyID( FIRM_PXI_ID_NULL ); + + // verify NOR + NVRAMi_Read( 0, nor2, sizeof(NORHeaderDS) ); + if ( MI_CpuComp8( nor, nor2, sizeof(NORHeaderDS) ) ) + { + OS_TPrintf("Failed to verify firm data in NOR.\n"); + goto err; + } + SetDebugLED(++step); // 0x0c + + // verify NAND + if ( FATFSi_sdmcReadFifo( nand2, sectors, 1, NULL, &sdResult ) ) + { + OS_TPrintf("Failed to call FATFSi_sdmcReadFifo() to write header.\n"); + goto err; + } + SetDebugLED(++step); // 0x0d + if ( MI_CpuComp8( nand, nand2, nsize ) ) + { + OS_TPrintf("Failed to verify firm data in NAND.\n"); + goto err; + } + SetDebugLED(0); // 0x00 + + PXI_NotifyID( FIRM_PXI_ID_NULL ); + + if ( PXI_RecvID() != FIRM_PXI_ID_NULL ) + { + goto err; + } + + OS_TPrintf("Success all.\n"); + MCUi_WriteRegister( MCU_REG_COMMAND_ADDR, MCU_REG_COMMAND_RESET_MASK ); + OS_Terminate(); + +err: + SetDebugLED((u8)(step|0xF0)); + EraseAll(); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + OS_Terminate(); +} + + diff --git a/build/libraries/gcd/ARM9/Makefile b/build/gcdfirm/sdmc-launcher-writer/ARM9/Makefile similarity index 62% rename from build/libraries/gcd/ARM9/Makefile rename to build/gcdfirm/sdmc-launcher-writer/ARM9/Makefile index 8099e9b7..f433ab79 100644 --- a/build/libraries/gcd/ARM9/Makefile +++ b/build/gcdfirm/sdmc-launcher-writer/ARM9/Makefile @@ -1,6 +1,6 @@ #! make -f #---------------------------------------------------------------------------- -# Project: TwlIPL +# Project: TwlFirm - nandfirm - menu-launcher # File: Makefile # # Copyright 2007 Nintendo. All rights reserved. @@ -16,42 +16,38 @@ # $Author$ #---------------------------------------------------------------------------- -SUBDIRS = +SUBDIRS = + +#LINCLUDES = ../include #---------------------------------------------------------------------------- -# build ARM & THUMB libraries -TWL_CODEGEN_ALL ?= True +TARGET_BIN = sdmc_launcher_writer9.srl +SRCS = main.c \ + screen.c \ + font.c +CRT0_O = crt0_firm.o -SRCDIR = . ../common -SRCS = \ - gcd.c \ - gcd_init.c \ - blowfish.c \ - ds_blowfish.c \ - ds_blowfish_table.c \ +ADDRESS_STATIC = 0x037c0000 -TARGET_LIB = libgcd$(FIRM_LIBSUFFIX).a -INCDIR = ../include +MAKEROM_ARM7 = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/sdmc_launcher_writer7.tef +MAKEROM_ARM7_BASE = $(basename $(MAKEROM_ARM7)) -#---------------------------------------------------------------------------- +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs -INSTALL_TARGETS = $(TARGETS) -INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) - #---------------------------------------------------------------------------- do-build: $(TARGETS) + include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules -LDEPENDS_OBJ := $(MAKEFIRM_RSA_PUBKEY) \ - -gcd_acsign.c : $(LDEPENDS_OBJ) - touch gcd_acsign.c #===== End of Makefile ===== diff --git a/build/gcdfirm/sdmc-launcher-writer/ARM9/font.c b/build/gcdfirm/sdmc-launcher-writer/ARM9/font.c new file mode 100644 index 00000000..ee49f50b --- /dev/null +++ b/build/gcdfirm/sdmc-launcher-writer/ARM9/font.c @@ -0,0 +1,588 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - SPI - demos - pm-1 + File: font.c + + Copyright 2003-2005 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: font.c,v $ + Revision 1.3 2005/02/28 05:26:11 yosizaki + do-indent. + + Revision 1.2 2004/11/02 07:19:52 terui + コメント内スペルミスを修正。 + + Revision 1.1 2004/08/07 01:59:51 yada + modified much + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#include "font.h" + + +/*---------------------------------------------------------------------------* + Character data + *---------------------------------------------------------------------------*/ +const u32 d_CharData[8 * 256] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 0000h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01010010, 0x01010010, 0x00000110, // 0001h + 0x00011010, 0x01100010, 0x00000010, 0x00000010, + 0x00000000, 0x01011010, 0x01010010, 0x00010010, // 0002h + 0x00100010, 0x00100010, 0x00100001, 0x00100001, + 0x00000000, 0x01010001, 0x01010001, 0x01111111, // 0003h + 0x00000001, 0x00000001, 0x00000001, 0x01111110, + 0x00000000, 0x01010000, 0x01111111, 0x00100000, // 0004h + 0x00100000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x01010000, 0x01010100, 0x00001010, // 0005h + 0x00010001, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01011000, 0x01011000, 0x01111111, // 0006h + 0x00001000, 0x00101010, 0x01001010, 0x01001001, + 0x00000000, 0x01010010, 0x01101111, 0x01010010, // 0007h + 0x00010010, 0x00010010, 0x00010010, 0x00001001, + 0x00000000, 0x01010010, 0x01011111, 0x00000100, // 0008h + 0x00011111, 0x00001000, 0x00000001, 0x00011110, + 0x00000000, 0x01010000, 0x01011000, 0x00000110, // 0009h + 0x00000001, 0x00000110, 0x00011000, 0x00100000, + 0x00000000, 0x01010000, 0x01111101, 0x00010001, // 000ah + 0x00010001, 0x00010001, 0x00010001, 0x00001010, + 0x00000000, 0x01010000, 0x01011110, 0x00100000, // 000bh + 0x00000000, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x01010100, 0x01011111, 0x00001000, // 000ch + 0x00010000, 0x00000001, 0x00000001, 0x00011110, + 0x00000000, 0x01010001, 0x01010001, 0x00000001, // 000dh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01010000, 0x01111111, 0x00011000, // 000eh + 0x00010100, 0x00010100, 0x00011000, 0x00001100, + 0x00000000, 0x01010010, 0x01111111, 0x00010010, // 000fh + 0x00010010, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x00001110, 0x01010100, 0x01010010, // 0010h + 0x00111111, 0x00000100, 0x00000100, 0x00011000, + 0x00000000, 0x01010100, 0x01011111, 0x00000100, // 0011h + 0x01110100, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x01010100, 0x01011111, 0x00000010, // 0012h + 0x00011110, 0x00100001, 0x00100000, 0x00011110, + 0x00000000, 0x01010000, 0x01011100, 0x00100011, // 0013h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01010000, 0x01111111, 0x00010000, // 0014h + 0x00001000, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x01010010, 0x01010010, 0x00001100, // 0015h + 0x00000010, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x01010001, 0x01111101, 0x00010001, // 0016h + 0x00010001, 0x00111001, 0x01010101, 0x00011001, + 0x00000000, 0x01010100, 0x01010011, 0x01110010, // 0017h + 0x00010001, 0x00010001, 0x00001010, 0x00000100, + 0x00000000, 0x01011110, 0x01011000, 0x00000100, // 0018h + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x01010000, 0x01011100, 0x00010010, // 0019h + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01011101, 0x01010001, 0x00111101, // 001ah + 0x00010001, 0x00011001, 0x00110101, 0x00001001, + 0x00000000, 0x01110001, 0x01011101, 0x00110001, // 001bh + 0x00010001, 0x00111001, 0x01010101, 0x00011001, + 0x00000000, 0x01110100, 0x01010011, 0x00110010, // 001ch + 0x00010001, 0x00010001, 0x00001010, 0x00000100, + 0x00000000, 0x01101110, 0x01011000, 0x00100100, // 001dh + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x01110000, 0x01011100, 0x00110010, // 001eh + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01111101, 0x01010001, 0x00111101, // 001fh + 0x00010001, 0x00011001, 0x00110101, 0x00001001, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 0020h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 0021h + 0x00001000, 0x00001000, 0x00000000, 0x00001000, + 0x00000000, 0x01101100, 0x01001000, 0x00100100, // 0022h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00100100, 0x01111111, 0x00100100, // 0023h + 0x00100100, 0x01111111, 0x00010010, 0x00010010, + 0x00000000, 0x00001000, 0x01111110, 0x00001001, // 0024h + 0x00111110, 0x01001000, 0x00111111, 0x00001000, + 0x00000000, 0x01000010, 0x00100101, 0x00010010, // 0025h + 0x00001000, 0x00100100, 0x01010010, 0x00100001, + 0x00000000, 0x00001110, 0x00010001, 0x00001001, // 0026h + 0x01000110, 0x00101001, 0x00110001, 0x01001110, + 0x00000000, 0x00011000, 0x00010000, 0x00001000, // 0027h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01110000, 0x00001000, 0x00000100, // 0028h + 0x00000100, 0x00000100, 0x00001000, 0x01110000, + 0x00000000, 0x00000111, 0x00001000, 0x00010000, // 0029h + 0x00010000, 0x00010000, 0x00001000, 0x00000111, + 0x00000000, 0x00001000, 0x01001001, 0x00101010, // 002ah + 0x00011100, 0x00101010, 0x01001001, 0x00001000, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 002bh + 0x01111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002ch + 0x00000000, 0x00001100, 0x00001000, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002dh + 0x01111111, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002eh + 0x00000000, 0x00000000, 0x00000000, 0x00001100, + 0x00000000, 0x01000000, 0x00100000, 0x00010000, // 002fh + 0x00001000, 0x00000100, 0x00000010, 0x00000001, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0030h + 0x01000001, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x00011100, 0x00010000, 0x00010000, // 0031h + 0x00010000, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x00111110, 0x01000001, 0x01000000, // 0032h + 0x00111110, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x00111110, 0x01000001, 0x01000000, // 0033h + 0x00111110, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x00100000, 0x00110000, 0x00101000, // 0034h + 0x00100100, 0x00100010, 0x01111111, 0x00100000, + 0x00000000, 0x01111111, 0x00000001, 0x00111111, // 0035h + 0x01000000, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x00111110, 0x00000001, 0x00111111, // 0036h + 0x01000001, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x01111111, 0x00100000, 0x00100000, // 0037h + 0x00010000, 0x00010000, 0x00001000, 0x00001000, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0038h + 0x00111110, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0039h + 0x01000001, 0x01111110, 0x01000000, 0x00111110, + 0x00000000, 0x00000000, 0x00001100, 0x00000000, // 003ah + 0x00000000, 0x00000000, 0x00001100, 0x00000000, + 0x00000000, 0x00000000, 0x00001100, 0x00000000, // 003bh + 0x00000000, 0x00001100, 0x00001000, 0x00000100, + 0x00000000, 0x01100000, 0x00011000, 0x00000110, // 003ch + 0x00000001, 0x00000110, 0x00011000, 0x01100000, + 0x00000000, 0x00000000, 0x01111111, 0x00000000, // 003dh + 0x00000000, 0x00000000, 0x01111111, 0x00000000, + 0x00000000, 0x00000011, 0x00001100, 0x00110000, // 003eh + 0x01000000, 0x00110000, 0x00001100, 0x00000011, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 003fh + 0x00110000, 0x00001000, 0x00000000, 0x00001000, + 0x00000000, 0x00011100, 0x00100010, 0x01001001, // 0040h + 0x01010101, 0x01010101, 0x01010101, 0x00111010, + 0x00000000, 0x00001000, 0x00010100, 0x00010100, // 0041h + 0x00100010, 0x00111110, 0x01000001, 0x01000001, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0042h + 0x00111111, 0x01000001, 0x01000001, 0x00111111, + 0x00000000, 0x00111100, 0x01000010, 0x00000001, // 0043h + 0x00000001, 0x00000001, 0x01000010, 0x00111100, + 0x00000000, 0x00011111, 0x00100001, 0x01000001, // 0044h + 0x01000001, 0x01000001, 0x00100001, 0x00011111, + 0x00000000, 0x01111111, 0x00000001, 0x00000001, // 0045h + 0x01111111, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x01111111, 0x00000001, 0x00000001, // 0046h + 0x00111111, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00111100, 0x01000010, 0x00000001, // 0047h + 0x01111001, 0x01000001, 0x01000010, 0x00111100, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0048h + 0x01111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00111110, 0x00001000, 0x00001000, // 0049h + 0x00001000, 0x00001000, 0x00001000, 0x00111110, + 0x00000000, 0x01000000, 0x01000000, 0x01000000, // 004ah + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01100001, 0x00011001, 0x00000101, // 004bh + 0x00000011, 0x00000101, 0x00011001, 0x01100001, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 004ch + 0x00000001, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x01000001, 0x01100011, 0x01010101, // 004dh + 0x01001001, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x01000001, 0x01000011, 0x01000101, // 004eh + 0x01001001, 0x01010001, 0x01100001, 0x01000001, + 0x00000000, 0x00011100, 0x00100010, 0x01000001, // 004fh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0050h + 0x00111111, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00011100, 0x00100010, 0x01000001, // 0051h + 0x01000001, 0x01011001, 0x00100010, 0x01011100, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0052h + 0x00111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00111110, 0x01000001, 0x00000001, // 0053h + 0x00111110, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x01111111, 0x00001000, 0x00001000, // 0054h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0055h + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01000001, 0x01000001, 0x00100010, // 0056h + 0x00100010, 0x00010100, 0x00010100, 0x00001000, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0057h + 0x01001001, 0x01010101, 0x01100011, 0x01000001, + 0x00000000, 0x01000001, 0x00100010, 0x00010100, // 0058h + 0x00001000, 0x00010100, 0x00100010, 0x01000001, + 0x00000000, 0x01000001, 0x00100010, 0x00010100, // 0059h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01111111, 0x00100000, 0x00010000, // 005ah + 0x00001000, 0x00000100, 0x00000010, 0x01111111, + 0x00000000, 0x01111100, 0x00000100, 0x00000100, // 005bh + 0x00000100, 0x00000100, 0x00000100, 0x01111100, + 0x00000000, 0x00100010, 0x00010100, 0x00111110, // 005ch + 0x00001000, 0x00111110, 0x00001000, 0x00001000, + 0x00000000, 0x00011111, 0x00010000, 0x00010000, // 005dh + 0x00010000, 0x00010000, 0x00010000, 0x00011111, + 0x00000000, 0x00001000, 0x00010100, 0x00100010, // 005eh + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 005fh + 0x00000000, 0x00000000, 0x00000000, 0x01111111, + 0x00000000, 0x00010000, 0x00001000, 0x00011000, // 0060h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00011110, 0x00100001, // 0061h + 0x00111110, 0x00100001, 0x00100001, 0x01011110, + 0x00000000, 0x00000001, 0x00000001, 0x00111111, // 0062h + 0x01000001, 0x01000001, 0x01000001, 0x00111111, + 0x00000000, 0x00000000, 0x00111100, 0x01000010, // 0063h + 0x00000001, 0x00000001, 0x01000010, 0x00111100, + 0x00000000, 0x01000000, 0x01000000, 0x01111110, // 0064h + 0x01000001, 0x01000001, 0x01000001, 0x01111110, + 0x00000000, 0x00000000, 0x00111110, 0x01000001, // 0065h + 0x01111111, 0x00000001, 0x01000001, 0x00111110, + 0x00000000, 0x00110000, 0x00001000, 0x00001000, // 0066h + 0x01111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x01111110, 0x01000001, // 0067h + 0x01000001, 0x01111110, 0x01000000, 0x00111110, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 0068h + 0x00111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00001000, 0x00000000, 0x00001000, // 0069h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00100000, 0x00000000, 0x00100000, // 006ah + 0x00100000, 0x00100001, 0x00100001, 0x00011110, + 0x00000000, 0x00000001, 0x00000001, 0x01100001, // 006bh + 0x00011001, 0x00000111, 0x00011001, 0x01100001, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 006ch + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00110111, 0x01001001, // 006dh + 0x01001001, 0x01001001, 0x01001001, 0x01001001, + 0x00000000, 0x00000000, 0x00111111, 0x01000001, // 006eh + 0x01000001, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00000000, 0x00011100, 0x00100010, // 006fh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00000000, 0x00111101, 0x01000011, // 0070h + 0x01000001, 0x01000011, 0x00111101, 0x00000001, + 0x00000000, 0x00000000, 0x01011110, 0x01100001, // 0071h + 0x01000001, 0x01100001, 0x01011110, 0x01000000, + 0x00000000, 0x00000000, 0x00110001, 0x00001101, // 0072h + 0x00000011, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00000000, 0x00111110, 0x01000001, // 0073h + 0x00001110, 0x00110000, 0x01000001, 0x00111110, + 0x00000000, 0x00000100, 0x00000100, 0x01111111, // 0074h + 0x00000100, 0x00000100, 0x00000100, 0x01111000, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0075h + 0x01000001, 0x01000001, 0x01000001, 0x01111110, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0076h + 0x00100010, 0x00100010, 0x00010100, 0x00001000, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0077h + 0x01001001, 0x00101010, 0x00101010, 0x00010100, + 0x00000000, 0x00000000, 0x00100001, 0x00010010, // 0078h + 0x00001100, 0x00001100, 0x00010010, 0x00100001, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0079h + 0x00100010, 0x00011100, 0x00001000, 0x00000110, + 0x00000000, 0x00000000, 0x00111111, 0x00010000, // 007ah + 0x00001000, 0x00000100, 0x00000010, 0x00111111, + 0x00000000, 0x00001000, 0x00011110, 0x01100100, // 007bh + 0x00011000, 0x00100100, 0x00000100, 0x01111000, + 0x00000000, 0x00000000, 0x00011110, 0x00000100, // 007ch + 0x00011110, 0x00110101, 0x00101101, 0x00010010, + 0x00000000, 0x00000000, 0x00000000, 0x00010001, // 007dh + 0x00100001, 0x00100001, 0x00000001, 0x00000010, + 0x00000000, 0x00000000, 0x00011100, 0x00000000, // 007eh + 0x00011110, 0x00100000, 0x00100000, 0x00011100, + 0x00000000, 0x00000000, 0x00011100, 0x00000000, // 007fh + 0x00111110, 0x00010000, 0x00001100, 0x00110010, + 0x00000000, 0x00000000, 0x00000100, 0x00101111, // 0080h + 0x01000100, 0x00011110, 0x00100101, 0x00010110, + 0x00000000, 0x00000000, 0x00001010, 0x00011110, // 0081h + 0x00101011, 0x00100010, 0x00010100, 0x00000100, + 0x00000000, 0x00000000, 0x00001000, 0x00011101, // 0082h + 0x00101011, 0x00101001, 0x00011001, 0x00000100, + 0x00000000, 0x00000000, 0x00001000, 0x00111000, // 0083h + 0x00001000, 0x00011110, 0x00101001, 0x00000110, + 0x00000000, 0x00000000, 0x00000000, 0x00011100, // 0084h + 0x00100011, 0x00100000, 0x00100000, 0x00011100, + 0x00000000, 0x00000110, 0x01001001, 0x00110000, // 0085h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000100, 0x00111111, 0x00000100, // 0086h + 0x00111110, 0x01010101, 0x01001101, 0x00100110, + 0x00000000, 0x00000000, 0x00100001, 0x01000001, // 0087h + 0x01000001, 0x01000001, 0x00000001, 0x00000010, + 0x00000000, 0x00111100, 0x00000000, 0x00111110, // 0088h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x00011100, 0x00000000, 0x00111110, // 0089h + 0x00010000, 0x00001000, 0x00010100, 0x01100010, + 0x00000000, 0x00100100, 0x01011111, 0x00000100, // 008ah + 0x00111110, 0x01000101, 0x01000101, 0x00100010, + 0x00000000, 0x00100010, 0x01001111, 0x01010010, // 008bh + 0x01010010, 0x00010010, 0x00010010, 0x00001001, + 0x00000000, 0x00000100, 0x00111110, 0x00001000, // 008ch + 0x00111110, 0x00010000, 0x00000010, 0x00111100, + 0x00000000, 0x00100000, 0x00011000, 0x00000110, // 008dh + 0x00000001, 0x00000110, 0x00011000, 0x00100000, + 0x00000000, 0x00100000, 0x01111101, 0x00100001, // 008eh + 0x00100001, 0x00100001, 0x00100001, 0x00010010, + 0x00000000, 0x00011110, 0x00100000, 0x00000000, // 008fh + 0x00000000, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x00001000, 0x01111111, 0x00010000, // 0090h + 0x00100000, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 0091h + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00010000, 0x01111111, 0x00011000, // 0092h + 0x00010100, 0x00010100, 0x00011000, 0x00001100, + 0x00000000, 0x00100010, 0x01111111, 0x00100010, // 0093h + 0x00100010, 0x00000010, 0x00000010, 0x01111100, + 0x00000000, 0x00111100, 0x00010000, 0x00001100, // 0094h + 0x01111111, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x00000100, 0x00011111, 0x00000100, // 0095h + 0x01110100, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x00001000, 0x01111111, 0x00000100, // 0096h + 0x00111100, 0x01000010, 0x01000000, 0x00111100, + 0x00000000, 0x00000000, 0x00011100, 0x00100011, // 0097h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01111111, 0x00010000, 0x00001000, // 0098h + 0x00001000, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x00000010, 0x00110010, 0x00001100, // 0099h + 0x00000010, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x00100100, 0x01001111, 0x01000010, // 009ah + 0x00010001, 0x00111100, 0x00010010, 0x00001100, + 0x00000000, 0x00000010, 0x01111010, 0x01000010, // 009bh + 0x00000010, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x00100010, 0x00111110, 0x01010010, // 009ch + 0x01001011, 0x01101101, 0x01010101, 0x00110010, + 0x00000000, 0x00110010, 0x01001011, 0x01000110, // 009dh + 0x01000110, 0x01110010, 0x01001011, 0x00110010, + 0x00000000, 0x00011100, 0x00101010, 0x01001001, // 009eh + 0x01001001, 0x01000101, 0x01000101, 0x00110010, + 0x00000000, 0x00100001, 0x01111101, 0x00100001, // 009fh + 0x00100001, 0x00111001, 0x01100101, 0x00011001, + 0x00000000, 0x00000100, 0x00100011, 0x01100010, // 00a0h + 0x00100001, 0x00100001, 0x00010010, 0x00001100, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a1h + 0x00000000, 0x00000100, 0x00001010, 0x00000100, + 0x00000000, 0x01110000, 0x00010000, 0x00010000, // 00a2h + 0x00010000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a3h + 0x00001000, 0x00001000, 0x00001000, 0x00001110, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a4h + 0x00000000, 0x00000010, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00011000, // 00a5h + 0x00011000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01111111, 0x01000000, 0x01111111, // 00a6h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x00000000, 0x00111111, 0x00100000, // 00a7h + 0x00010100, 0x00001100, 0x00000100, 0x00000010, + 0x00000000, 0x00000000, 0x00100000, 0x00100000, // 00a8h + 0x00010000, 0x00001111, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00000100, 0x00111111, // 00a9h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x00000000, 0x00000000, 0x00111110, // 00aah + 0x00001000, 0x00001000, 0x00001000, 0x01111111, + 0x00000000, 0x00000000, 0x00010000, 0x00111111, // 00abh + 0x00011000, 0x00010100, 0x00010010, 0x00011001, + 0x00000000, 0x00000000, 0x00000010, 0x00111111, // 00ach + 0x00100010, 0x00010010, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00111110, // 00adh + 0x00100000, 0x00100000, 0x00100000, 0x01111111, + 0x00000000, 0x00000000, 0x00111110, 0x00100000, // 00aeh + 0x00111110, 0x00100000, 0x00100000, 0x00111110, + 0x00000000, 0x00000000, 0x00100101, 0x00101010, // 00afh + 0x00101010, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00b0h + 0x01111111, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01111111, 0x01000000, 0x00101000, // 00b1h + 0x00011000, 0x00001000, 0x00001000, 0x00000100, + 0x00000000, 0x01000000, 0x00100000, 0x00011000, // 00b2h + 0x00010111, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x00001000, 0x01111111, 0x01000001, // 00b3h + 0x01000001, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00000000, 0x00111110, 0x00001000, // 00b4h + 0x00001000, 0x00001000, 0x00001000, 0x01111111, + 0x00000000, 0x00100000, 0x01111111, 0x00110000, // 00b5h + 0x00101000, 0x00100100, 0x00100010, 0x00110001, + 0x00000000, 0x00000100, 0x01111111, 0x01000100, // 00b6h + 0x01000100, 0x01000100, 0x01000010, 0x00100001, + 0x00000000, 0x00000100, 0x00111111, 0x00001000, // 00b7h + 0x01111111, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x01111100, 0x01000100, 0x01000100, // 00b8h + 0x01000010, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00000010, 0x01111110, 0x00100010, // 00b9h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01111110, 0x01000000, 0x01000000, // 00bah + 0x01000000, 0x01000000, 0x01000000, 0x01111110, + 0x00000000, 0x00100010, 0x01111111, 0x00100010, // 00bbh + 0x00100010, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x00000011, 0x00000100, 0x01000011, // 00bch + 0x01000100, 0x00100000, 0x00011000, 0x00000111, + 0x00000000, 0x01111111, 0x01000000, 0x00100000, // 00bdh + 0x00010000, 0x00011000, 0x00100100, 0x01000011, + 0x00000000, 0x00000010, 0x01111111, 0x01000010, // 00beh + 0x00100010, 0x00000010, 0x00000010, 0x01111100, + 0x00000000, 0x01000001, 0x01000010, 0x01000000, // 00bfh + 0x00100000, 0x00100000, 0x00011000, 0x00000110, + 0x00000000, 0x01111110, 0x01000010, 0x01001110, // 00c0h + 0x01110001, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x01100000, 0x00011110, 0x00010000, // 00c1h + 0x01111111, 0x00010000, 0x00010000, 0x00001100, + 0x00000000, 0x01000101, 0x01001010, 0x01001010, // 00c2h + 0x01000000, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00111110, 0x00000000, 0x01111111, // 00c3h + 0x00010000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x00000010, 0x00000010, 0x00000110, // 00c4h + 0x00011010, 0x01100010, 0x00000010, 0x00000010, + 0x00000000, 0x00010000, 0x00010000, 0x01111111, // 00c5h + 0x00010000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x00000000, 0x00111110, 0x00000000, // 00c6h + 0x00000000, 0x00000000, 0x00000000, 0x01111111, + 0x00000000, 0x01111110, 0x01000000, 0x01000100, // 00c7h + 0x00101000, 0x00010000, 0x00101000, 0x01000110, + 0x00000000, 0x00001000, 0x01111111, 0x00100000, // 00c8h + 0x00010000, 0x00011100, 0x01101011, 0x00001000, + 0x00000000, 0x01000000, 0x01000000, 0x01000000, // 00c9h + 0x00100000, 0x00100000, 0x00011000, 0x00000111, + 0x00000000, 0x00010010, 0x00100010, 0x00100010, // 00cah + 0x01000010, 0x01000010, 0x01000001, 0x01000001, + 0x00000000, 0x00000001, 0x00000001, 0x01111111, // 00cbh + 0x00000001, 0x00000001, 0x00000001, 0x01111110, + 0x00000000, 0x01111111, 0x01000000, 0x01000000, // 00cch + 0x01000000, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00000000, 0x00000100, 0x00001010, // 00cdh + 0x00010001, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x00001000, 0x00001000, 0x01111111, // 00ceh + 0x00001000, 0x00101010, 0x01001010, 0x01001001, + 0x00000000, 0x01111111, 0x01000000, 0x01000000, // 00cfh + 0x00100010, 0x00010100, 0x00001000, 0x00010000, + 0x00000000, 0x00001110, 0x01110000, 0x00001110, // 00d0h + 0x01110000, 0x00000110, 0x00011000, 0x01100000, + 0x00000000, 0x00001000, 0x00001000, 0x00000100, // 00d1h + 0x00000100, 0x00100010, 0x01000010, 0x01111111, + 0x00000000, 0x01000000, 0x01000000, 0x00100100, // 00d2h + 0x00101000, 0x00010000, 0x00101100, 0x01000011, + 0x00000000, 0x01111111, 0x00000100, 0x01111111, // 00d3h + 0x00000100, 0x00000100, 0x00000100, 0x01111000, + 0x00000000, 0x00000010, 0x01111111, 0x01000010, // 00d4h + 0x00100010, 0x00010100, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00111110, 0x00100000, // 00d5h + 0x00100000, 0x00100000, 0x00100000, 0x01111111, + 0x00000000, 0x01111110, 0x01000000, 0x01000000, // 00d6h + 0x01111110, 0x01000000, 0x01000000, 0x01111110, + 0x00000000, 0x00111110, 0x00000000, 0x01111111, // 00d7h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01000010, 0x01000010, 0x01000010, // 00d8h + 0x01000010, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00001010, 0x00001010, 0x00001010, // 00d9h + 0x01001010, 0x01001010, 0x00101010, 0x00011001, + 0x00000000, 0x00000010, 0x00000010, 0x01000010, // 00dah + 0x01000010, 0x00100010, 0x00010010, 0x00001110, + 0x00000000, 0x01111111, 0x01000001, 0x01000001, // 00dbh + 0x01000001, 0x01000001, 0x01000001, 0x01111111, + 0x00000000, 0x01111111, 0x01000001, 0x01000001, // 00dch + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01000011, 0x01000100, 0x01000000, // 00ddh + 0x01000000, 0x00100000, 0x00010000, 0x00001111, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00deh + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00dfh + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00011110, 0x00001000, 0x00000100, // 00e0h + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x00000000, 0x00001100, 0x00010010, // 00e1h + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01111101, 0x00100001, 0x01111101, // 00e2h + 0x00100001, 0x00111001, 0x01100101, 0x00011001, + 0x00000000, 0x00111100, 0x00010000, 0x00111100, // 00e3h + 0x00010000, 0x00011100, 0x00110010, 0x00001100, + 0x00000000, 0x00001110, 0x00101000, 0x00101000, // 00e4h + 0x00111110, 0x01100101, 0x00100101, 0x00010010, + 0x00000000, 0x00000100, 0x00101111, 0x01000100, // 00e5h + 0x00000110, 0x01000101, 0x01000101, 0x00111110, + 0x00000000, 0x00100010, 0x00100010, 0x00111110, // 00e6h + 0x01010010, 0x01010101, 0x01001101, 0x00100110, + 0x00000000, 0x00000100, 0x00011111, 0x00000010, // 00e7h + 0x00011111, 0x01000010, 0x01000010, 0x00111100, + 0x00000000, 0x00010010, 0x00111110, 0x01010011, // 00e8h + 0x01000010, 0x00100100, 0x00000100, 0x00000100, + 0x00000000, 0x00001000, 0x00111101, 0x01001011, // 00e9h + 0x01001001, 0x01001001, 0x00111000, 0x00000100, + 0x00000000, 0x00001000, 0x00111000, 0x00001000, // 00eah + 0x00001000, 0x00011110, 0x00101001, 0x00000110, + 0x00000000, 0x00011000, 0x00100000, 0x00000100, // 00ebh + 0x00111010, 0x01000110, 0x01000000, 0x00111000, + 0x00000000, 0x01000010, 0x01000010, 0x01000010, // 00ech + 0x01000110, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00111110, 0x00010000, 0x00111100, // 00edh + 0x01000011, 0x01001100, 0x01010010, 0x00111100, + 0x00000000, 0x00100010, 0x00110011, 0x00101010, // 00eeh + 0x00100110, 0x00100010, 0x00100011, 0x01000010, + 0x00000000, 0x00111110, 0x00010000, 0x00111100, // 00efh + 0x01000011, 0x01000000, 0x01000010, 0x00111100, + 0x00000000, 0x00000010, 0x00111011, 0x01000110, // 00f0h + 0x01000010, 0x01000011, 0x01000010, 0x00110010, + 0x00000000, 0x00000100, 0x00000100, 0x00000010, // 00f1h + 0x01000110, 0x01000101, 0x01000101, 0x00111001, + 0x00000000, 0x01010100, 0x01111111, 0x00100100, // 00f2h + 0x00100100, 0x00100100, 0x00100010, 0x00010001, + 0x00000000, 0x01010100, 0x01011111, 0x00000100, // 00f3h + 0x00111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01011110, 0x01100010, 0x00100010, // 00f4h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01010010, 0x01111110, 0x00100010, // 00f5h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01010000, 0x01111111, 0x00100000, // 00f6h + 0x00100000, 0x00100000, 0x00100000, 0x00111111, + 0x00000000, 0x01010010, 0x01010010, 0x00111111, // 00f7h + 0x00010010, 0x00010000, 0x00010000, 0x00001100, + 0x00000000, 0x01010011, 0x01010100, 0x00100011, // 00f8h + 0x00100100, 0x00010000, 0x00001000, 0x00000111, + 0x00000000, 0x01010000, 0x01011111, 0x00010000, // 00f9h + 0x00001000, 0x00001100, 0x00010010, 0x00100001, + 0x00000000, 0x01010010, 0x01111111, 0x00100010, // 00fah + 0x00010010, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x01010001, 0x01010010, 0x00100000, // 00fbh + 0x00100000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x01011110, 0x01010010, 0x00100110, // 00fch + 0x00111001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01010000, 0x01011110, 0x00010000, // 00fdh + 0x01111111, 0x00010000, 0x00010000, 0x00001100, + 0x00000000, 0x00100101, 0x01001010, 0x00101010, // 00feh + 0x00100000, 0x00010000, 0x00001000, 0x00000111, + 0x00000000, 0x01011110, 0x01010000, 0x00111111, // 00ffh + 0x00001000, 0x00001000, 0x00001000, 0x00000110 +}; + + +/*---------------------------------------------------------------------------* + Palette data + *---------------------------------------------------------------------------*/ +const u32 d_PaletteData[8 * 16] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // black + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x001f0000, 0x00000000, 0x00000000, 0x00000000, // red + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03e00000, 0x00000000, 0x00000000, 0x00000000, // green + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7c000000, 0x00000000, 0x00000000, 0x00000000, // blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03ff0000, 0x00000000, 0x00000000, 0x00000000, // yellow + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7c1f0000, 0x00000000, 0x00000000, 0x00000000, // purple + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7fe00000, 0x00000000, 0x00000000, 0x00000000, // light blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00180000, 0x00000000, 0x00000000, 0x00000000, // dark red + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03000000, 0x00000000, 0x00000000, 0x00000000, // dark green + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x60000000, 0x00000000, 0x00000000, 0x00000000, // dark blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03180000, 0x00000000, 0x00000000, 0x00000000, // dark yellow + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x60180000, 0x00000000, 0x00000000, 0x00000000, // dark purple + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x63000000, 0x00000000, 0x00000000, 0x00000000, // dark light blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x56b50000, 0x00000000, 0x00000000, 0x00000000, // gray + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x2d6b0000, 0x00000000, 0x00000000, 0x00000000, // dark gray + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7fff0000, 0x00000000, 0x00000000, 0x00000000, // white + 0x00000000, 0x00000000, 0x00000000, 0x00000000 +}; + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/gcdfirm/sdmc-launcher-writer/ARM9/include/font.h b/build/gcdfirm/sdmc-launcher-writer/ARM9/include/font.h new file mode 100644 index 00000000..30d49e95 --- /dev/null +++ b/build/gcdfirm/sdmc-launcher-writer/ARM9/include/font.h @@ -0,0 +1,60 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - SPI - demos - pm-1 + File: font.h + + Copyright 2003-2005 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: font.h,v $ + Revision 1.2 2005/02/28 05:26:12 yosizaki + do-indent. + + Revision 1.1 2004/08/07 01:59:51 yada + modified much + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#ifndef FONT_H_ +#define FONT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +typedef enum +{ + FONT_BLOCK = 0, + FONT_RED = 1, + FONT_GREEN = 2, + FONT_BLUE = 3, + FONT_YELLOW = 4, + FONT_PURPLE = 5, + FONT_CYAAN = 6, + FONT_WHITE = 15 +} +MYFontColor; + +extern const u32 d_CharData[8 * 256]; +extern const u32 d_PaletteData[8 * 16]; + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* FONT_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/gcdfirm/sdmc-launcher-writer/ARM9/include/screen.h b/build/gcdfirm/sdmc-launcher-writer/ARM9/include/screen.h new file mode 100644 index 00000000..81ed6790 --- /dev/null +++ b/build/gcdfirm/sdmc-launcher-writer/ARM9/include/screen.h @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - SPI - demos - pm-1 + File: screen.h + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: screen.h,v $ + Revision 1.3 2006/01/18 02:12:28 kitase_hirotake + do-indent + + Revision 1.2 2005/02/28 05:26:12 yosizaki + do-indent. + + Revision 1.1 2004/08/07 01:59:51 yada + modified much + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#ifndef SCREEN_H_ +#define SCREEN_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ +#include + +extern u16 gScreen[32 * 32]; + +void ClearScreen(void); +void PrintString(s16 x, s16 y, u8 palette, char *text, ...); +void ColorString(s16 x, s16 y, s16 length, u8 palette); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* SCREEN_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/gcdfirm/sdmc-launcher-writer/ARM9/main.c b/build/gcdfirm/sdmc-launcher-writer/ARM9/main.c new file mode 100644 index 00000000..4255e74a --- /dev/null +++ b/build/gcdfirm/sdmc-launcher-writer/ARM9/main.c @@ -0,0 +1,231 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - ts_dev9 + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include "font.h" +#include "screen.h" + +//#define PRINT_DEBUG + +#ifndef PRINT_DEBUG +#undef OS_TPrintf +#define OS_TPrintf(...) ((void)0) +#endif // PRINT_DEBUG + +static void myInit(void); +static void myVBlankIntr(void); + +/*************************************************************** + PreInit + + FromBootの対応&OS_Init前に必要なメインメモリの初期化 +***************************************************************/ +static void PreInit(void) +{ + /* + メインメモリ関連 + */ + // SHARED領域クリア + MI_CpuClearFast((void*)HW_WRAM_EX_LOCK_BUF, (HW_WRAM_EX_LOCK_BUF_END - HW_WRAM_EX_LOCK_BUF)); + MI_CpuClearFast((void*)HW_BIOS_EXCP_STACK_MAIN, (HW_REAL_TIME_CLOCK_BUF - HW_BIOS_EXCP_STACK_MAIN)); + MI_CpuClearFast((void*)HW_PXI_SIGNAL_PARAM_ARM9, (HW_MMEMCHECKER_MAIN - HW_PXI_SIGNAL_PARAM_ARM9)); + MI_CpuClearFast((void*)HW_ROM_HEADER_BUF, (HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF)); + + // FromBrom全消去 + MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) ); + + // ブートタイプの変更 + ( (OSBootInfo *)OS_GetBootInfo() )->boot_type = OS_BOOTTYPE_NAND; +} + +/*************************************************************** + PostInit + + 各種初期化 +***************************************************************/ +static void PostInit(void) +{ +} + +/*************************************************************** + EraseAll + + 不正終了しました + いろいろ消してください + DSモードにして終わるのがよいか? +***************************************************************/ +static void EraseAll(void) +{ +} + +void TwlMain( void ) +{ + u32 len; +#define X_OFF 2 + s16 y = 2; + + PreInit(); + myInit(); + PostInit(); + + CARD_Init(); + + //---- clear screen buffer + ClearScreen(); + + PrintString( X_OFF, y, FONT_CYAAN, "NAND Firm Writer" ); + PrintString( X_OFF+18, y++, FONT_YELLOW, "%s", __DATE__ ); + PrintString( X_OFF+21, y++, FONT_YELLOW, "%s", __TIME__ ); + OS_WaitVBlankIntr(); + y++; + + PXI_RecvStream(&len, sizeof(len)); + PrintString( X_OFF, y++, FONT_WHITE, "Firm length: %d bytes", len ); + OS_WaitVBlankIntr(); + y++; + + PrintString( X_OFF, y++, FONT_WHITE, "Load NAND Firm..." ); + OS_WaitVBlankIntr(); + + if ( PXI_RecvID() != FIRM_PXI_ID_NULL ) + { + goto err; + } + PrintString( X_OFF+20, y++, FONT_GREEN, "Done." ); + PrintString( X_OFF, y++, FONT_WHITE, "Write NAND Firm..." ); + OS_WaitVBlankIntr(); + + if ( PXI_RecvID() != FIRM_PXI_ID_NULL ) + { + goto err; + } + PrintString( X_OFF+20, y++, FONT_GREEN, "Done." ); + PrintString( X_OFF, y++, FONT_WHITE, "Verify NAND Firm..." ); + OS_WaitVBlankIntr(); + + if ( PXI_RecvID() != FIRM_PXI_ID_NULL ) + { + goto err; + } + PrintString( X_OFF+20, y++, FONT_GREEN, "Done." ); + + PrintString( X_OFF, 20, FONT_GREEN, "SUCCESS ALL!" ); + do + { + OS_WaitVBlankIntr(); + } + while ( PAD_DetectFold() && (PAD_Read() & PAD_ALL_MASK) == (PAD_BUTTON_START|PAD_BUTTON_SELECT|PAD_BUTTON_X)); + + PXI_NotifyID( FIRM_PXI_ID_NULL ); + OS_Terminate(); + +err: + PrintString( X_OFF+20, y++, FONT_RED, "Failed." ); + OS_WaitVBlankIntr(); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + OS_Terminate(); +} + +//---------------------------------------------------------------- +// myInit +// +void myInit(void) +{ + //---- init + OS_InitFIRM(); + OS_InitTick(); + OS_InitAlarm(); + FX_Init(); + GX_Init(); + GX_DispOff(); + GXS_DispOff(); + + //---- init displaying + GX_SetBankForLCDC(GX_VRAM_LCDC_ALL); + MI_CpuClearFast((void *)HW_LCDC_VRAM, HW_LCDC_VRAM_SIZE); + (void)GX_DisableBankForLCDC(); + + MI_CpuFillFast((void *)HW_OAM, 192, HW_OAM_SIZE); + MI_CpuClearFast((void *)HW_PLTT, HW_PLTT_SIZE); + MI_CpuFillFast((void *)HW_DB_OAM, 192, HW_DB_OAM_SIZE); + MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE); + + //---- setting 2D for top screen + GX_SetBankForBG(GX_VRAM_BG_128_A); + + G2_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256, + GX_BG_COLORMODE_16, + GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01); + G2_SetBG0Priority(0); + G2_BG0Mosaic(FALSE); + GX_SetGraphicsMode(GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BG0_AS_2D); + GX_SetVisiblePlane(GX_PLANEMASK_BG0); + + GX_LoadBG0Char(d_CharData, 0, sizeof(d_CharData)); + GX_LoadBGPltt(d_PaletteData, 0, sizeof(d_PaletteData)); + + + + //---- setting 2D for bottom screen + GX_SetBankForSubBG(GX_VRAM_SUB_BG_128_C); + + G2S_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256, + GX_BG_COLORMODE_16, + GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01); + G2S_SetBG0Priority(0); + G2S_BG0Mosaic(FALSE); + GXS_SetGraphicsMode(GX_BGMODE_0); + GXS_SetVisiblePlane(GX_PLANEMASK_BG0); + + GXS_LoadBG0Char(d_CharData, 0, sizeof(d_CharData)); + GXS_LoadBGPltt(d_PaletteData, 0, sizeof(d_PaletteData)); + + + //---- screen + MI_CpuFillFast((void *)gScreen, 0, sizeof(gScreen)); + DC_FlushRange(gScreen, sizeof(gScreen)); + /* DMA操作でIOレジスタへアクセスするのでキャッシュの Wait は不要 */ + // DC_WaitWriteBufferEmpty(); + GX_LoadBG0Scr(gScreen, 0, sizeof(gScreen)); + GXS_LoadBG0Scr(gScreen, 0, sizeof(gScreen)); + + //---- init interrupt + OS_SetIrqFunction(OS_IE_V_BLANK, myVBlankIntr); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + //---- start displaying + GX_DispOn(); + GXS_DispOn(); +} + +//---------------------------------------------------------------- +// myVBlankIntr +// vblank interrupt handler +// +static void myVBlankIntr(void) +{ + //---- upload pseudo screen to VRAM + DC_FlushRange(gScreen, sizeof(gScreen)); + /* DMA操作でIOレジスタへアクセスするのでキャッシュの Wait は不要 */ + // DC_WaitWriteBufferEmpty(); + GX_LoadBG0Scr(gScreen, 0, sizeof(gScreen)); + GXS_LoadBG0Scr(gScreen, 0, sizeof(gScreen)); + + OS_SetIrqCheckFlag(OS_IE_V_BLANK); +} + diff --git a/build/gcdfirm/sdmc-launcher-writer/ARM9/screen.c b/build/gcdfirm/sdmc-launcher-writer/ARM9/screen.c new file mode 100644 index 00000000..8e20145a --- /dev/null +++ b/build/gcdfirm/sdmc-launcher-writer/ARM9/screen.c @@ -0,0 +1,120 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - SPI - demos - pm-1 + File: screen.c + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: screen.c,v $ + Revision 1.3 2006/01/18 02:12:28 kitase_hirotake + do-indent + + Revision 1.2 2005/02/28 05:26:12 yosizaki + do-indent. + + Revision 1.1 2004/08/07 01:59:51 yada + modified much + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include "screen.h" + +u16 gScreen[32 * 32]; +//u16 gScreen2[ 32 * 32 ]; + +// ** these code are refer to rtc sample. thanks. +/*---------------------------------------------------------------------------* + Name: ClearScreen + + Description: clear screen buffer + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void ClearScreen(void) +{ + MI_CpuClearFast((void *)gScreen, sizeof(gScreen)); +} + +/*---------------------------------------------------------------------------* + Name: PrintString + + Description: enter string into screen buffer + string must be within 32 chars + + Arguments: x : x + y : y + palette : color (0-15) + text : string. end mark is NULL + + Returns: None. + *---------------------------------------------------------------------------*/ +void PrintString(s16 x, s16 y, u8 palette, char *text, ...) +{ + va_list vlist; + char temp[32 + 2], *tempPtr; + s32 i; + u16 *p, *pLimit; + + va_start(vlist, text); + (void)vsnprintf(temp, 33, text, vlist); + va_end(vlist); + + *(u16 *)(&temp[32]) = 0; + p = &gScreen[((y * 32) + x) % (32 * 32)]; + pLimit = &gScreen[32 * 32]; + tempPtr = &temp[0]; + + for (i = 0; *tempPtr; i++, tempPtr++) + { + *p = (u16)((palette << 12) | *tempPtr); + if (++p >= pLimit) + { + p = &gScreen[0]; + } + } +} + +/*---------------------------------------------------------------------------* + Name: ColorString + + Description: change string color which is put in screen buffer + + Arguments: x : x + y : y + length : number of characters to change color + palette : color (0-15) + + Returns: None. + *---------------------------------------------------------------------------*/ +void ColorString(s16 x, s16 y, s16 length, u8 palette) +{ + s32 i; + u16 *p, *pLimit; + + if (length < 0) + return; + + p = &gScreen[((y * 32) + x) % (32 * 32)]; + pLimit = &gScreen[32 * 32]; + + for (i = 0; i < length; i++) + { + u16 temp = *p; + temp &= 0x0fff; + temp |= (palette << 12); + *p = temp; + + if (++p >= pLimit) + { + p = &gScreen[0]; + } + } +} diff --git a/build/gcdfirm/sdmc-launcher-writer/Makefile b/build/gcdfirm/sdmc-launcher-writer/Makefile new file mode 100644 index 00000000..075eea7e --- /dev/null +++ b/build/gcdfirm/sdmc-launcher-writer/Makefile @@ -0,0 +1,57 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - gcdfirm - sdmc-launcher-writer +# File: Makefile +# +# Copyright 2008 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + wram_regs \ + ARM7 \ + ARM9 \ + +ifneq ($(TWL_IPL_RED_PRIVATE_ROOT),) + +TARGET_FIRM_BIN = sdmc_launcher_writer-$(TWL_BUILD_TYPE)$(CODEGEN_ARCH).gcd + +NANDFIRM_BIN = ../../nandfirm/sdmc-launcher/sdmc_launcher-$(TWL_BUILD_TYPE)$(CODEGEN_ARCH).nand + +BINDIR = . +MAKEFIRM_ARM9 = ARM9/bin/$(TWL_BUILDTYPE_ARM9)/sdmc_launcher_writer9.tef +MAKEFIRM_ARM7 = ARM7/bin/$(TWL_BUILDTYPE_ARM7)/sdmc_launcher_writer7.tef +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_gcd.der +LDEPENDS_BIN += wram_regs/wram_regs.rbin + +MAKEFIRM_FLAGS += -p +FIRM_SPEC = gcdfirm.gcdsf + +MAKEFIRM_DEFS += -DNANDFIRM_BIN=$(NANDFIRM_BIN) + +LDIRT_CLEAN += $(wildcard *.gcd) \ + rsa_public.sbin \ + +endif + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/gcdfirm/sdmc-launcher-writer/wram_regs/Makefile b/build/gcdfirm/sdmc-launcher-writer/wram_regs/Makefile new file mode 100644 index 00000000..1c1afc6d --- /dev/null +++ b/build/gcdfirm/sdmc-launcher-writer/wram_regs/Makefile @@ -0,0 +1,57 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - menu-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM := TWL +override TARGET_CODEGEN := ARM +override TWL_ARCHGEN := LIMITED + +override TARGET_FINALROM := TRUE +override TARGET_RELEASE := +override TARGET_DEBUG := + +SUBDIRS = + +LINCLUDES = ../include + + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/gcdfirm/sdmc-launcher-writer/wram_regs/wram_regs.c b/build/gcdfirm/sdmc-launcher-writer/wram_regs/wram_regs.c new file mode 100644 index 00000000..2454b302 --- /dev/null +++ b/build/gcdfirm/sdmc-launcher-writer/wram_regs/wram_regs.c @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - nandfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM9 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_A_SIZE ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE - HW_WRAM_C_SIZE ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/libraries/Makefile b/build/libraries/Makefile index 2c3fb71b..f316ea53 100644 --- a/build/libraries/Makefile +++ b/build/libraries/Makefile @@ -12,8 +12,8 @@ # in whole or in part, without the prior written consent of Nintendo. # # $Date:: $ -# $Rev:$ -# $Author:$ +# $Rev$ +# $Author$ #---------------------------------------------------------------------------- include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs @@ -30,7 +30,7 @@ SUBDIRS_P = \ fatfs \ aes \ pm \ - gcd \ + nvram \ #---------------------------------------------------------------------------- diff --git a/build/libraries/gcd/common/blowfish.c b/build/libraries/gcd/common/blowfish.c deleted file mode 100644 index 60f8fb2d..00000000 --- a/build/libraries/gcd/common/blowfish.c +++ /dev/null @@ -1,149 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlBrom - libraries - GCD - File: blowfish.c - - Copyright 2007 Nintendo. All rights reserved. - - These coded instructions, statements, and computer programs contain - proprietary information of Nintendo of America Inc. and/or Nintendo - Company Ltd., and are protected by Federal copyright law. They may - not be disclosed to third parties or copied or duplicated in any form, - in whole or in part, without the prior written consent of Nintendo. - - $Log: $ - $NoKeywords: $ - *---------------------------------------------------------------------------*/ -#include - -#define MAXKEYBYTES 56 /* 448 bits */ -#define N 16 - - -static u32 F(const BLOWFISH_CTX *ctx, u32 x); - -void InitBlowfish(BLOWFISH_CTX *ctx, const unsigned char *key, int keyLen) -{ - int i, j, k; - u32 data, datal, datar; - - j = 0; - for (i = 0; i < N + 2; ++i) { - data = 0x00000000; - for (k = 0; k < 4; ++k) { - data = (data << 8) | key[j]; - j = j + 1; - if (j >= keyLen) - j = 0; - } - ctx->P[i] = ctx->P[i] ^ data; - } - - datal = 0x00000000; - datar = 0x00000000; - - for (i = 0; i < N + 2; i += 2) { - EncryptByBlowfish(ctx, &datal, &datar); - ctx->P[i] = datal; - ctx->P[i + 1] = datar; - } - - for (i = 0; i < 4; ++i) { - for (j = 0; j < 256; j += 2) { - EncryptByBlowfish(ctx, &datal, &datar); - ctx->S[i][j] = datal; - ctx->S[i][j + 1] = datar; - } - } - -} - - -void EncryptByBlowfish(const BLOWFISH_CTX *ctx, u32 *xl, u32 *xr) -{ - u32 Xl; - u32 Xr; - u32 temp; - int i; - - Xl = *xl; - Xr = *xr; - - for (i = 0; i < N; ++i) { - Xl = Xl ^ ctx->P[i]; - Xr = F(ctx, Xl) ^ Xr; - - temp = Xl; - - Xl = Xr; - Xr = temp; - } - - temp = Xl; - Xl = Xr; - Xr = temp; - - Xr = Xr ^ ctx->P[N]; - Xl = Xl ^ ctx->P[N + 1]; - - *xl = Xl; - *xr = Xr; -} - -void DecryptByBlowfish(const BLOWFISH_CTX *ctx, u32 *xl, u32 *xr) -{ - u32 Xl; - u32 Xr; - u32 temp; - int i; - - - Xl = *xl; - Xr = *xr; - - for (i = N + 1; i > 1; --i) { - Xl = Xl ^ ctx->P[i]; - Xr = F(ctx, Xl) ^ Xr; - - /* Exchange Xl and Xr */ - temp = Xl; - Xl = Xr; - Xr = temp; - } - - /* Exchange Xl and Xr */ - temp = Xl; - Xl = Xr; - Xr = temp; - - Xr = Xr ^ ctx->P[1]; - Xl = Xl ^ ctx->P[0]; - - *xl = Xl; - *xr = Xr; -} - - -static u32 F(const BLOWFISH_CTX *ctx, u32 x) { - u32 a, b, c, d; - u32 y; - - d = x & 0x00FF; - x >>= 8; - - c = x & 0x00FF; - x >>= 8; - - b = x & 0x00FF; - x >>= 8; - - a = x & 0x00FF; - - y = ctx->S[0][a] + ctx->S[1][b]; - - y = y ^ ctx->S[2][c]; - y = y + ctx->S[3][d]; - - return y; -} - - diff --git a/build/libraries/gcd/common/ds_blowfish.c b/build/libraries/gcd/common/ds_blowfish.c deleted file mode 100644 index 1a6b3bd1..00000000 --- a/build/libraries/gcd/common/ds_blowfish.c +++ /dev/null @@ -1,186 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlBrom - libraries - GCD - File: ds_blowfish.c - - Copyright 2007 Nintendo. All rights reserved. - - These coded instructions, statements, and computer programs contain - proprietary information of Nintendo of America Inc. and/or Nintendo - Company Ltd., and are protected by Federal copyright law. They may - not be disclosed to third parties or copied or duplicated in any form, - in whole or in part, without the prior written consent of Nintendo. - - $Log: $ - $NoKeywords: $ - *---------------------------------------------------------------------------*/ -#include -#include - - -#ifdef PRINT_DEBUG -#define DBG_PRINTF vlink_dos_printf -#define DBG_CHAR vlink_dos_put_console -#else -#define DBG_PRINTF( ... ) ((void)0) -#define DBG_CHAR( c ) ((void)0) -#endif - -static void my_memcopy(void *src, void *dst, int size); - - -// DS - -static char *normal_mode_key ATTRIBUTE_ALIGN(4) = "NmMdOnly"; -static char *png_off_key ATTRIBUTE_ALIGN(4) = "enPngOFF"; -static char *encrypt_object_key ATTRIBUTE_ALIGN(4) = "encryObj"; - -extern GCDSharedWork GCDi_SharedWork[2]; -extern GCDSecureWork GCDi_SecureWork[2]; - -static void GCDi_InitBlowfishKeyAndTableDS(BLOWFISH_CTX *ctx, u32 *keyBufp, s32 keyLen) -{ - EncryptByBlowfish(ctx, &(keyBufp)[2], &(keyBufp)[1]); - EncryptByBlowfish(ctx, &(keyBufp)[1], &(keyBufp)[0]); - InitBlowfish(ctx, (u8 *)keyBufp, keyLen); -} - -static void GCDi_MakeBlowfishTableDS(GCDSlot slot, BLOWFISH_CTX *tableBufp, const u32 *keyp, u32 *keyBufp, s32 keyLen) -{ - const BLOWFISH_CTX *blowfishInitTablep = &GCDi_BlowfishInitTableDS; - GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - u32 *blowfishedKeyp; - - MI_CpuCopy32((void *)blowfishInitTablep, (void *)tableBufp, sizeof(BLOWFISH_CTX)); - - keyBufp[0] = *keyp; - keyBufp[1] = (*keyp >> 1); - keyBufp[2] = (*keyp << 1); - - GCDi_InitBlowfishKeyAndTableDS(tableBufp, keyBufp, keyLen); - - *(u64 *)sec->cardNormalModeKey = *(u64 *)rh->l.romNormalModeKey; - blowfishedKeyp = sec->cardNormalModeKey; - - DecryptByBlowfish(tableBufp, &(blowfishedKeyp)[1], &(blowfishedKeyp)[0]); - - if (keyLen > 8) { - sec->isGenUnScrambleKey = 1; - } - GCDi_InitBlowfishKeyAndTableDS(tableBufp, keyBufp, keyLen); -} - -void GCDi_InitCardOpBlowfishDS( GCDSlot slot ) -{ - GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - GCDi_MakeBlowfishTableDS(slot, &sec->blowfishCardTable, &rh->l.initialCode, sec->cardKeyBuf, 8); -} - -static void GCDi_ChangeObjectTableDS(GCDSlot slot, s32 keyLen) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - BLOWFISH_CTX *tableBufp = &sec->blowfishCardTable; - u32 *keyBufp = sec->cardKeyBuf; - - keyBufp[1] = (keyBufp[1] << 1); - keyBufp[2] = (keyBufp[2] >> 1); - GCDi_InitBlowfishKeyAndTableDS(tableBufp, keyBufp, keyLen); -} - - -#define UNDEF_CODE 0xe7ffdeff -#define ENCRYPT_DEF_SIZE 0x800 -/* あとで名前変える */ -#define ENC_DESTINATION_BUF_SIZE 0x4000 -static u32 encDestBuf[ENC_DESTINATION_BUF_SIZE/sizeof(u32)]; - -void GCDi_DecryptObjectFileDS( GCDSlot slot ) -{ - GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - GCDSharedWork* sh = &GCDi_SharedWork[slot]; - BLOWFISH_CTX *tableBufp = &sec->blowfishCardTable; - u32 *encBufp = (u32 *)&sec->blowfishFlashTable; - u32 *encDestp = (u32 *)rh->l.arm9.ramAddr; - s32 size = sec->secureSize; - s32 restSize; - BOOL exist = TRUE; - int i; - - sec->enableReadSecure = 1; // SECURE領域リード・イネーブル - - encDestp = GCDi_SecureAreaBuf[slot]; - encBufp = encDestBuf; - - if (size > ENCRYPT_DEF_SIZE) { - size = ENCRYPT_DEF_SIZE; - } - restSize = size; - - if (sec->enableReadSecure) { - MI_CpuCopy32(encDestp, encBufp, (u32)size); - DBG_PRINTF("%s %d\n",__FUNCTION__,__LINE__); - DecryptByBlowfish(tableBufp, &(encBufp)[1], &(encBufp)[0]); - } - - GCDi_ChangeObjectTableDS( slot, 8 ); - - if (sec->enableReadSecure) { - DecryptByBlowfish(tableBufp, &(encBufp)[1], &(encBufp)[0]); - DBG_PRINTF("%s %d\n",__FUNCTION__,__LINE__); - -#if 1 - for ( i=0; i<8; i++ ) - { - if ( encrypt_object_key[i] != ((char*)encBufp)[i] ) - { - exist = FALSE; - break; - } - } - - // 暗号化オブジェクト有効時 - if ( exist ) - { -#else - if ((encBufp[0] == encrypt_object_key[0]) // 暗号化オブジェクト有効時 - && (encBufp[1] == encrypt_object_key[1])) { -#endif - u32 *bufp = encBufp; - - bufp[0] = UNDEF_CODE; - bufp[1] = UNDEF_CODE; - while ((restSize -= 8) > 0) { - bufp += 2; // 復号処理 - DecryptByBlowfish(tableBufp, &(bufp)[1], &(bufp)[0]); - } - DBG_PRINTF("SUCCESS %s %d\n",__FUNCTION__,__LINE__); - } - else { - DBG_PRINTF("ERROR %s %d\n",__FUNCTION__,__LINE__); - // CpuClearFast32(UNDEF_CODE, encBufp, size); // 未定義コードでクリア - sh->disableEncryptedCardData = 1; // 暗号化オブジェクト無効 通知 - } - MI_CpuCopy32(encBufp, encDestp, (u32)size); - DBG_PRINTF("%s %d\n",__FUNCTION__,__LINE__); - } -} - - -/*************************************************** - - utility functions - - ***************************************************/ -static void my_memcopy(void *src, void *dst, int size) -{ - u8 *s,*d; - int i; - s = (u8 *)src; - d = (u8 *)dst; - for( i = 0 ; i < size ; i++ ) { - *d++ = *s++; - } -} - diff --git a/build/libraries/gcd/common/ds_blowfish_table.c b/build/libraries/gcd/common/ds_blowfish_table.c deleted file mode 100644 index 2ab70da3..00000000 --- a/build/libraries/gcd/common/ds_blowfish_table.c +++ /dev/null @@ -1,286 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlBrom - libraries - GCD - File: ds_blowfish_table.c - - Copyright 2007 Nintendo. All rights reserved. - - These coded instructions, statements, and computer programs contain - proprietary information of Nintendo of America Inc. and/or Nintendo - Company Ltd., and are protected by Federal copyright law. They may - not be disclosed to third parties or copied or duplicated in any form, - in whole or in part, without the prior written consent of Nintendo. - - $Log: $ - $NoKeywords: $ - *---------------------------------------------------------------------------*/ -#include - - -const BLOWFISH_CTX GCDi_BlowfishInitTableDS = { - 0x5f20d599, 0xb9f54457, 0xd9a4196e, 0x945a6a9e, - 0xebf1aed8, 0x3ae27541, 0x32d08293, 0xd531ee33, - 0x9a6157cc, 0x1ba20637, 0xf5723979, 0xbef6ae55, - 0xfb691b5f, 0xe9f19de5, 0xa1d92cce, 0xe605325e, - 0xcffed3fe, 0x0d0462d4 , - - 0xb7ecf58b, 0xbb79602b, 0x0d319512, 0x2bda3f6e, - 0xf1f08488, 0x257e123d, 0xbbf12245, 0x061a0624, - 0x28dfad11, 0x3481648b, 0x2933eb2b, 0xbdf2aa99, - 0x9d95149c, 0x8cf5f79f, 0x29a19772, 0xcf5fd19d, - 0x1a074d66, 0x4b4ad3de, 0xa3a7c985, 0x3a059517, - 0xbf0a493d, 0xa28b890a, 0xdd49824a, 0x0bf19027, - 0x6a1cebe9, 0x05457683, 0x617081ba, 0xde4b3f17, - 0x39abcfae, 0x563af257, 0x8aad1148, 0x3f45e140, - 0x54029bfa, 0xfb93a6ca, 0x6ffe4def, 0x9c87d8a3, - 0x48d5ba08, 0xfd2d8d6a, 0x74f8156e, 0x8b52bebd, - 0x9e8a2218, 0x073774fb, 0x4a6c361b, 0x6242ba19, - 0x109179b9, 0x9665677b, 0xe82302fe, 0x778c99ee, - 0x64865c3e, 0x86786d4d, 0xe2654fa5, 0x5adfb21e, - 0x087ed00a, 0xac71b014, 0x1c83dbbd, 0x62a1d7b9, - 0x7c63c6cd, 0xe6c36952, 0x12ce75bf, 0x04215d44, - 0x3cd3fbfa, 0xd4631138, 0x49418595, 0x08f20946, - 0x1fdc1143, 0x6d15c076, 0x70633c1f, 0x6c8087ea, - 0x8b63bdc3, 0x372137c2, 0x2309eedc, 0x4d6a372e, - 0x50f79073, 0x921cac30, 0x91231004, 0xaa07d24f, - 0x9a4f3e68, 0x6a6064c9, 0xf32114c8, 0x124122d6, - 0xe6cf2444, 0x0ddd568a, 0x85e14d53, 0x5a528c1e, - 0xc284199c, 0x6ff15703, 0x58be00e3, 0xd5ed4cf6, - 0x1f9c6421, 0x3c0355be, 0xaaffdc4a, 0x5de0dac9, - 0xdee6bf5e, 0xf8b1d8f5, 0xb9b336ff, 0xdb956762, - 0xed375f31, 0x9967704c, 0x3118b590, 0x99993d6c, - 0xd3da42e4, 0xa0134225, 0x6c70d7ae, 0xc7cf55b1, - 0x43d546d7, 0x443d1761, 0x8533e928, 0x93a2d0d5, - 0x1f1225aa, 0x460bc5fb, 0x567697f5, 0x87bea645, - 0xe86b94b1, 0x9933feb1, 0x6c3e1fae, 0x091d7139, - 0xe4379000, 0x74753e10, 0x3b838cff, 0xf9b0f1b0, - 0x42470501, 0xacd6f195, 0x9ee6387e, 0x3f267495, - 0x185068b4, 0xb43043d0, 0x68e34b4c, 0xb64de5bf, - 0xa00a8b95, 0x77322574, 0x2cf7a1cf, 0x5a1371d8, - 0x51c9eaab, 0xefee0de8, 0x197e93e9, 0x38431ea7, - 0xa12c1681, 0xcc73e348, 0xd36c2129, 0xd9a0ce5d, - 0xa0437161, 0x64b51315, 0x192acf92, 0xa5b7addc, - 0xf865869f, 0xfbe79f1a, 0x13b8fdf7, 0x6fdb276c, - 0xf71c35df, 0x9b5b2c8d, 0x6438ab12, 0x31decc06, - 0x11754ee8, 0xeafae364, 0xc25434eb, 0xeb343fad, - 0x267d2c93, 0xf3569d36, 0xb3f6e15a, 0x9e4a6398, - 0x9ae48332, 0x907d6084, 0xee0e132e, 0xa2364b93, - 0x3816ec85, 0x020688e8, 0x3aa0f0bf, 0x9a6ad7ed, - 0xcf57e173, 0xdcb844f8, 0xd159232e, 0x715295df, - 0x4ba06199, 0x786e7fd5, 0x30c5a9ba, 0x328640d3, - 0x9c0c329d, 0x2f02b737, 0xa99854ba, 0xc90413c4, - 0xe7c8be8d, 0x2e50975d, 0x5922d693, 0x22bc270c, - 0x20a7e092, 0x7f6f930f, 0xb5d39f4c, 0x740b2aa6, - 0x107d4967, 0xc5d1cb26, 0x8ce77186, 0x5be99ca0, - 0x01f61ab2, 0x5e9e8cee, 0xdb1af283, 0x84eae5e6, - 0x7cd27659, 0x49a58df6, 0x16c24836, 0xa383bb52, - 0x0c07b974, 0x2861ff3b, 0xe4e961e1, 0xaa156eef, - 0x5de8ba4e, 0x32bb9605, 0x72fbb056, 0xc80e0f52, - 0x76652542, 0xdef2af89, 0x01f02710, 0x97a7744b, - 0x5426d507, 0x821f0954, 0x307d860a, 0x26b30e39, - 0xbb570b9b, 0xaf310636, 0xd9fc79fd, 0x0c2b1030, - 0xd79be1b3, 0xef5fdc7b, 0x4513f8d2, 0xbd75474d, - 0x7e3c9646, 0xb53ef375, 0x3b9ac567, 0x6b295bb0, - 0xc85b80de, 0x31b10515, 0xdd49ceb6, 0xaeb584ad, - 0x3167dc60, 0x4efe3034, 0xa62f80bd, 0x213963bf, - 0x7f35d986, 0x05226816, 0x2690e954, 0x516c078c, - 0xd75531a4, 0x3ea80709, 0xc166532e, 0xc47bf2f8, - 0xf1cf58f2, 0xe7a2c587, 0x87308f27, 0x6264a058, - 0x88b91823, 0xc4cefa7c, 0x17adae98, 0xf35b4acc, - 0x56d548e9, 0xc8f20dd3, 0xdb8c7392, 0xac562fd7, - - 0x6992f981, 0xf632c64d, 0x218dc0e6, 0x618076e2, - 0x6cdcbc11, 0x6919af93, 0xb9bfd09b, 0x67029f31, - 0x83ee51a3, 0x0c7b2206, 0x404249ab, 0x7d01d5b8, - 0x55f75ece, 0x99c53953, 0x9f87d846, 0xb464f7ba, - 0xa1fa9ae3, 0x1068906d, 0x548aca30, 0xc3609fa7, - 0x0d6bf519, 0xe698517a, 0xb4514398, 0x4fe935d6, - 0x7b0fdfc3, 0xbd5c2fd6, 0x1961153a, 0xaacb4bf1, - 0xc9646ddc, 0x561ec6d3, 0x504c38ef, 0xcc758671, - 0xe94e0d0d, 0x5d06f628, 0xd3aa1b70, 0x39a8cf45, - 0x2ea695ac, 0xd422e4b4, 0x5f37a874, 0xcc047a48, - 0xd8404ca5, 0x0828b428, 0x52721c0d, 0x477df041, - 0x4e533a19, 0x6b628458, 0x818ab593, 0xdc0d4e21, - 0xc6a23fb4, 0x402bc9fc, 0xe90438da, 0x6b865a5e, - 0x8525220c, 0x7c8d1168, 0x55951d92, 0xbb8eab4d, - 0xb7e6a6da, 0x5a32b651, 0x05dd4105, 0x50560a2a, - 0xcc471791, 0xb57ee6c9, 0x73db4a61, 0x33c85167, - 0x746edaf5, 0x37c3542e, 0x08af6d0d, 0x5f8a15e8, - 0xcd2159e2, 0x060cdea8, 0x5f6b775a, 0x3e6518db, - 0x78de50c8, 0xb382b8e0, 0x32724e5d, 0x34c14f07, - 0xb796ba23, 0x28a44e67, 0xeb62341e, 0xe9706a2d, - 0x70c4422f, 0x9c315a4e, 0x28475bf9, 0x6f71daaa, - 0x78b31f38, 0x1c6b92c4, 0x9a35f69e, 0xbf0e4db7, - 0x412918cc, 0x5d354803, 0xc62bd055, 0x605caf29, - 0x5e8e6974, 0xbdd47c9b, 0x7d64447b, 0x695d923f, - 0x4b001fb6, 0xcf3583d4, 0x174e647e, 0x2ed58dae, - 0x4e12289a, 0x08492b2e, 0x46c6ae5c, 0x6141ae85, - 0xd2826f1e, 0x1f163751, 0xa459f60b, 0xaf5aca9a, - 0x8b33d40d, 0x84f16320, 0xcfcb5c80, 0xd3b9b408, - 0x62bd0516, 0x569b3183, 0xba9f9851, 0xb2aa5bb2, - 0xb52c6b22, 0x63fa48d4, 0xfa585f2b, 0x0964fa61, - 0xb8e038bb, 0xa860929d, 0x0e6f670d, 0x010df537, - 0xd477c29f, 0x73f1ecfe, 0x7de03930, 0xe49861f5, - 0x0455282c, 0x2fdb5556, 0x58e5ec6b, 0x8064b606, - 0x4e1a2a6a, 0xc4d80f5b, 0x19522e0a, 0x30f562d9, - 0x7b8cbe48, 0xa29b384f, 0xd3c9afc3, 0x4162c1c7, - 0x2161b986, 0x4f996f57, 0x7bcebac1, 0x5e4d3bb5, - 0x57448b8a, 0x705f135f, 0x47295b6d, 0xece238dc, - 0x12655504, 0x4317e82a, 0x2add8ee1, 0xf794e2b3, - 0xe65c6e09, 0x6df88aeb, 0x48544989, 0xbfad2ff5, - 0xca4b94ea, 0x828739fc, 0xf2018a5f, 0x71e6f275, - 0xde42d8d6, 0x281d2df1, 0xa37e88a6, 0x301d47a0, - 0xdf71a3d9, 0x01cb1c49, 0xf2b136f8, 0x5d5822f0, - 0xa0bd6b45, 0x4288b2bb, 0xce288cc7, 0x6390e893, - 0x897c9008, 0xb77df53c, 0x554f2d04, 0x7efd1651, - 0xc1bee879, 0xf8d412f2, 0x230584b4, 0x2bd2cca0, - 0xadabe1fd, 0x6c55d10d, 0x4d944123, 0x054f3777, - 0x17bf0c28, 0x6c6712b3, 0xf75ac38c, 0x6d2a8441, - 0x271294d0, 0x9cedb42c, 0x8247ec4d, 0xb967d597, - 0x55c09d1b, 0x8ee57e07, 0x3ee7a8e2, 0x3a0ee412, - 0x3455452a, 0x5a2df9a2, 0x7c52ab1b, 0x555f1083, - 0x435af1d2, 0xa4a7c62b, 0xe8951589, 0xf89d4bb4, - 0x609fe375, 0xe6d65b78, 0x21e6440d, 0x2247bd06, - 0xad00a453, 0x8513438d, 0xfcaaf739, 0xed7baf38, - 0x542be4fc, 0xfc4c9850, 0xdff78085, 0xe122803c, - 0x24deda94, 0x397ab0c6, 0xa10fdc38, 0x6ff9f4a7, - 0x8b571863, 0x2e2a4184, 0xd9f253d4, 0xddd00f00, - 0xa6196e99, 0x5becd00a, 0xc0ab2458, 0xec6506cb, - 0x9438131a, 0x2f03670a, 0x77e3f73f, 0xc6337744, - 0xe3d03914, 0x7908a2c0, 0x579940bb, 0x90010b41, - 0x48cce1cd, 0xafb3db67, 0x4cf37488, 0xb1728f82, - 0xc42923b5, 0xfc196c12, 0x9ca4468e, 0x876525c4, - 0x8abe6dd3, 0x38031193, 0xf32b83ed, 0xea93a446, - 0x1d85533b, 0x08f1d4ce, 0xfced2783, 0xbc181a9b, - 0xdcae8bf9, 0x3850ab24, 0x104b72e9, 0x467b1722, - - 0x6459ab5d, 0xf8ae40f3, 0xf9c8e5bb, 0x554e0326, - 0xfeebeb7d, 0xe0e639f7, 0x2ebe110a, 0xed98ff28, - 0x5642c9c0, 0x00fdc342, 0xa287aff6, 0x323f015b, - 0x9a954792, 0x3d32a572, 0x9bd06bae, 0x9249d207, - 0xfa4a78e3, 0xf27d06a1, 0x7477cf41, 0x0cb21404, - 0x16648486, 0xa151bbd5, 0xd1f16fe5, 0x5ff7e2f2, - 0xb84d2058, 0xddcfc757, 0x76bed8c5, 0x7e5ff63d, - 0x888b2ae7, 0x3f381b24, 0x7723410e, 0xd44bf0f5, - 0xa4fa1f0c, 0xcf5f800b, 0xdae0f645, 0x5359342f, - 0x523c20fb, 0xb5355e62, 0x608bfe62, 0x5a86e363, - 0xd16e1a15, 0x32bc4547, 0x3867ebb4, 0x336ee4ab, - 0xa3edb53a, 0x4ee067ad, 0x62ee9541, 0x1d267162, - 0x3062ef31, 0xac82d7af, 0x0405dcc2, 0xbf0797f5, - 0x07235911, 0xe80264c0, 0xaf3ee597, 0xa659ac18, - 0x90334a8b, 0x9c7c6e1c, 0x3c4c7e20, 0xbb64613e, - 0x7e7c6bc5, 0x4cc59f3e, 0xf573ea9f, 0x4cc089d7, - 0x2df4fbf4, 0x511b14ec, 0xc812c1d5, 0x4a0bdf10, - 0x93bc9c8b, 0x3e3e6a45, 0xbaa9c17d, 0x07b4c1cd, - 0x8668e1e4, 0x386db243, 0x5c0cfbf3, 0xde713766, - 0xa06eef56, 0xa7654010, 0xbed0f798, 0x3637c80e, - 0x7cca10ec, 0x1e84ab9c, 0x02761705, 0xaa524f1c, - 0xa0c6c15f, 0x04d8b956, 0xa74d4484, 0x60ded859, - 0x050e38e6, 0x3be1038f, 0x3304816d, 0xce0b306f, - 0x33210569, 0x89bb26fb, 0x87aeb67d, 0xe007517e, - 0x0a96f7ac, 0x5cc4f96b, 0x4744e41d, 0xe3fa5eb8, - 0x42558478, 0xf75e484b, 0x8635477d, 0x05432b1d, - 0xb88aec03, 0x763c061e, 0x431a480c, 0xed8ab7a7, - 0x43c6131e, 0xdbef10ee, 0x833cfbec, 0xef4495b2, - 0x4e5154d8, 0x1d44112d, 0x1e5936fb, 0xc3c1347a, - 0x610057ca, 0x16a567ea, 0x55d0559b, 0x36d97fe1, - 0xae7640d2, 0xb0ce01dc, 0xcbd5837a, 0x6bec9820, - 0x349272c1, 0x375782f3, 0x36328a62, 0xae43900c, - 0x789b5cae, 0x0265138e, 0xc17168fd, 0xa031b0fe, - 0xc3b08224, 0xa76979b1, 0xd0ebd2f5, 0xdc32c082, - 0x3c26c79e, 0xc1988d6d, 0xd0d422bb, 0x3eec330f, - 0xdce1ccb9, 0x36774c6a, 0xbff91c14, 0x5f289f81, - 0x29328571, 0xc4487590, 0xd8ce4ab3, 0x2f148f44, - 0xef5740fd, 0xd97508aa, 0x6ed6d146, 0xc31f5532, - 0x1f84fe18, 0xffd584fc, 0x481b5e71, 0x0e9586c3, - 0xd3270828, 0x7b718338, 0x5463804c, 0xacb0569a, - 0x31ca80cf, 0xf3feef09, 0x7e24afbe, 0x3f53fea6, - 0x334a8dc2, 0xa622d168, 0xea7bad66, 0xb043b6de, - 0x009525a1, 0x46753fa3, 0xec441114, 0x92bc95d7, - 0x16a94ff0, 0x60976253, 0xf1410f2a, 0xeebe2471, - 0xcd087f94, 0x85b39360, 0x3f00075b, 0x83280fd8, - 0x9f69d19a, 0xc32edad1, 0xb9a20190, 0x662a4e6b, - 0xa6aeda9d, 0x68d32aea, 0x9c0c0c2f, 0xed4a8cd2, - 0x65579ee2, 0xa387099d, 0x5d32c4b4, 0x2b32d4c9, - 0x1e71e0b1, 0x90e64d64, 0x401ee371, 0x84f37ded, - 0x78c8ed0e, 0x71c0ae76, 0x05bb7227, 0xfb6402ea, - 0xb56b48f3, 0xed3f9342, 0xd253139f, 0xec2afef7, - 0xdb25471d, 0xc686913c, 0xfd11f08e, 0xf7367423, - 0x7a9ef5a4, 0x4450537e, 0xd3ca47d4, 0xe66d38eb, - 0x7f9471d9, 0x4b69c64a, 0xea52f411, 0xb08afe22, - 0x598b6736, 0x2a80e6e8, 0x130465eb, 0x9edcecee, - 0x05ecb15f, 0x9fe6596a, 0x896b595e, 0xca1af7bf, - 0x6a5bf944, 0xe4038571, 0x70e06229, 0xcfc4416f, - 0xe3ccb1b2, 0xa807a67e, 0x847fe787, 0x4b52db93, - 0xdd7eec6c, 0x104824d4, 0x60049f69, 0x1848e674, - 0xb92ce4f3, 0x7a502e4f, 0x6954d4df, 0xf3a78b2b, - 0xf31fffce, 0x3901263e, 0x89849517, 0x4b4cf0b0, - 0xc49f9182, 0xa59dac4b, 0x2517af74, 0xd332cac9, - 0x848a89bc, 0xae0dcc89, 0x9cdba27c, 0xee91786a, - 0x4e5d76ea, 0x69f56087, 0x02d46715, 0x3648afcf, - - 0x6fbfea07, 0x8f062d66, 0xf9fe9ac4, 0x758790f6, - 0x0fadf7b8, 0x3d5a1076, 0xb32eb059, 0xcc2c35c7, - 0xcb2b5670, 0xc59637e3, 0x8a1b462f, 0x88c74622, - 0x983226a7, 0x2286df61, 0x2f1cf48a, 0xaa09a187, - 0xd3aea9cc, 0x1c4500bd, 0x8687549a, 0xffef8752, - 0x8fa18f1e, 0x355c89c1, 0x3a2dda1b, 0xc2b2162c, - 0x78e256f1, 0x97636bc1, 0xc98f56c5, 0xaa2c7f32, - 0xaca8a6af, 0x88229120, 0x8b60e4de, 0x25424bf9, - 0x9c7fe31a, 0x3a89192c, 0x36d4057e, 0xc25869cc, - 0x2f8b32c1, 0x7aeb8590, 0xa1a55039, 0x66c59227, - 0x584f20b0, 0x4383557e, 0x9ce2452b, 0x9012d8e4, - 0x5683162c, 0xb3037916, 0x18612dad, 0x371f131a, - 0x739ce1e2, 0xfdd5807b, 0xfc87512d, 0x1fd7aa7b, - 0xaf8e7a2c, 0xcdbb8df4, 0x727c1195, 0xe26fee0b, - 0x37deafb9, 0x8d8cde83, 0xb7670562, 0x568dc696, - 0x62d70db6, 0x3646d6ba, 0xe6c88ebd, 0x106c2aea, - 0x5b6bff14, 0x463c82fa, 0x464330b1, 0x9b7d8a51, - 0x79833e92, 0xb25d555b, 0x90ce5e6c, 0x98538e62, - 0xe56d0dc9, 0xc5cd572d, 0xe1ba5781, 0x728fb8e8, - 0xdc134fe5, 0x15719dea, 0x8811b210, 0x7fd409d5, - 0x2c7f655b, 0x114c383b, 0xfb8d5068, 0xbf59b09e, - 0x4a898094, 0x12181ac5, 0x4ad15389, 0x8ce82910, - 0xeab6ec1c, 0x8b17c746, 0xa8311525, 0xb1436ba2, - 0x0bdbe29d, 0x11b09b87, 0xd2710e04, 0x82897729, - 0x7f41660a, 0xff480b1d, 0xfd24bb72, 0x9ba148c2, - 0xce7f7bfe, 0xd986db88, 0xb01c3b85, 0x0733a8dc, - 0xe32e51bf, 0x97009a0e, 0x97c0061e, 0xb6d89d43, - 0x6786c445, 0x88f8005f, 0x9e52a49a, 0x838aaac7, - 0x18c5ec75, 0x2fc3ceae, 0x18f92b1a, 0xf51aaeff, - 0x33b50b53, 0xe8fda751, 0x64a2e1a8, 0x431722b6, - 0xd80acc80, 0x40ba3bae, 0x4a92d9d7, 0x1004df89, - 0x2b189bee, 0x8a69776a, 0xb9f9f468, 0x6e1521a2, - 0x033b1ee6, 0x609b3062, 0x9b257e41, 0x52c58f9e, - 0xc2f80810, 0x1121a169, 0x795e3788, 0x10ff6635, - 0xed6e1842, 0x1c6bb697, 0x6de5364e, 0xbfe4b47d, - 0x05e0b920, 0xb8d5693a, 0xe0dcd5e3, 0x3e53acb9, - 0xad57a407, 0x1848ff77, 0x49ac2a76, 0x75478e2a, - 0x63679f6d, 0x398c3530, 0x6fd53905, 0xad5b3a64, - 0x82bb0bca, 0xb1459952, 0x99363693, 0x442013af, - 0x4402d836, 0x85923909, 0x974a4aff, 0xd763a687, - 0x24b5b5c7, 0x6fb40fed, 0x1452580c, 0xd37ba6d9, - 0x5838bc79, 0x843bbda1, 0x061ad806, 0xeaa86bfd, - 0x0428694b, 0x9982ad37, 0x851b0efb, 0x735da8bd, - 0x7558dccd, 0x6c63be0a, 0xe44ce748, 0x60042b30, - 0xdad815b9, 0x8f758186, 0x1c8dd496, 0x7c85705d, - 0xd57b671c, 0xcea66708, 0x70660a4b, 0xd463e5b7, - 0xea828a5b, 0xe2ca6710, 0x8517eff4, 0x8a5f2a2f, - 0x6af88297, 0xea1034d6, 0x3c5cc9eb, 0x46f849e1, - 0xf6bddeeb, 0xaaf192a9, 0xb018a0a6, 0x1f0fd33a, - 0x31ff6ff3, 0xd3444345, 0x88f79a50, 0xcec19609, - 0x2cf2cc76, 0x82adba2c, 0x84188f77, 0x9c07d2c0, - 0x4e839036, 0x434fa50b, 0x78ab043e, 0x09fbd64f, - 0xda902401, 0x613a3c6f, 0x4a697f0d, 0x02302beb, - 0x84e0dbb4, 0x35d7eca9, 0x857d37bf, 0x4ea9ce58, - 0xa8c780e4, 0x486730d3, 0x2faf29eb, 0xa7b46a74, - 0x923f0f3f, 0xaccaf3af, 0x94d94baf, 0x81ca43c0, - 0xa1482f0d, 0xd2d527b0, 0x85054bef, 0x934ddea3, - 0xbbf03c30, 0x27308f4a, 0x3ee3eb4c, 0x2f9aed64, - 0xf082f13b, 0x7fcff4ba, 0xe1b0cb40, 0x57aabc7f, - 0xf274c9d3, 0x220d43fa, 0x4e77f4d0, 0x7085d793, - 0xb6bf991f, 0x30f135de, 0xf0715ea7, 0x7b2d016b, - 0x5333f064, 0xf388390a, 0x6ba63a6b, 0x432fd235, - 0xb5fd02cd, 0xaa5bbce9, 0x7e19a4d8, 0x81945d0e, - 0xad776f9e, 0x93740ed6, 0x18c4e796, 0x19f5ad5f -}; - diff --git a/build/libraries/gcd/common/gcd.c b/build/libraries/gcd/common/gcd.c deleted file mode 100644 index 0f277b13..00000000 --- a/build/libraries/gcd/common/gcd.c +++ /dev/null @@ -1,1215 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlBrom - GCD - libraries - File: gcd.c - - Copyright 2007 Nintendo. All rights reserved. - - These coded instructions, statements, and computer programs contain - proprietary information of Nintendo of America Inc. and/or Nintendo - Company Ltd., and are protected by Federal copyright law. They may - not be disclosed to third parties or copied or duplicated in any form, - in whole or in part, without the prior written consent of Nintendo. - - $Log: $ - $NoKeywords: $ - *---------------------------------------------------------------------------*/ - -#include -#include - -// use this functions for DS mode only - -//#define PRINT_DEBUG - -#ifdef PRINT_DEBUG -#define DBG_PRINTF vlink_dos_printf -#define DBG_CHAR vlink_dos_put_console -#else -#define DBG_PRINTF( ... ) ((void)0) -#define DBG_CHAR( c ) ((void)0) -#endif - - -static BOOL GCDi_ReadRomPreCore( GCDSlot slot, u32 romp, void *ramp, s32 size ); -static void GCDi_ReadGameModeRomCore( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ); -static void GCDi_WriteGameModeRomCore( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ); - -static void GCD_DmaRecvRomAsync( GCDSlot slot, u32 dmaNo, void *dest ); -static void GCD_DmaSendRomAsync( GCDSlot slot, u32 dmaNo, void *src ); - - -u32 GCDi_HeaderBuf[2][ GCD_ROM_HEADER_SIZE/sizeof(u32) ]; -u32 GCDi_SecureAreaBuf[2][ GCD_SECURE_AREA_SIZE/sizeof(u32) ]; -u32 GCDi_Secure2AreaBuf[2][ GCD_SECURE_AREA_SIZE/sizeof(u32) ]; - -GCDSharedWork GCDi_SharedWork[2]; -GCDSecureWork GCDi_SecureWork[2]; - - -/*---------------------------------------------------------------------------* - Name: GCDi_Enable - - Description: enable game card master control - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_Enable( GCDSlot slot ) -{ - REGType16v* cnt0 = GCDi_SelectRegAddr( slot, REG_MCCNT0_ADDR ); - - OSIntrMode enabled = OS_DisableInterrupts(); - - GCDi_WaitCtrl( slot ); - - *cnt0 |= REG_MI_MCCNT0_A_E_MASK | REG_MI_MCCNT0_A_I_MASK; - - (void)OS_RestoreInterrupts(enabled); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_Disable - - Description: disable game card master control - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_Disable( GCDSlot slot ) -{ - REGType16v* cnt0 = GCDi_SelectRegAddr( slot, REG_MCCNT0_ADDR ); - - OSIntrMode enabled = OS_DisableInterrupts(); - - GCDi_WaitCtrl( slot ); - - *cnt0 &= ~(REG_MI_MCCNT0_A_E_MASK | REG_MI_MCCNT0_A_I_MASK); - - (void)OS_RestoreInterrupts(enabled); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_SelectRom - - Description: select game card rom - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_SelectRom( GCDSlot slot ) -{ - REGType16v* cnt0 = GCDi_SelectRegAddr( slot, REG_MCCNT0_ADDR ); - - OSIntrMode enabled = OS_DisableInterrupts(); - - *cnt0 &= ~REG_MI_MCCNT0_A_SEL_MASK; - - (void)OS_RestoreInterrupts(enabled); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_SelectSpi - - Description: select game card spi - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_SelectSpi( GCDSlot slot ) -{ - REGType16v* cnt0 = GCDi_SelectRegAddr( slot, REG_MCCNT0_ADDR ); - - OSIntrMode enabled = OS_DisableInterrupts(); - - *cnt0 |= REG_MI_MCCNT0_A_SEL_MASK; - - (void)OS_RestoreInterrupts(enabled); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_GenCtrl - - Description: generate game card control - - Arguments: op : command - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_GenCtrl( GCDCtrlRegs* regs, - GCDRw rw, - GCDPageCount pcount, - GCDClockType ckt, u32 lt1, u32 lt2, - BOOL cpn, BOOL dpn, BOOL csc, BOOL dsc ) -{ - regs->latency = ((lt1 << REG_MI_MCCNT1_A_L1_SHIFT) & REG_MI_MCCNT1_A_L1_MASK) - | ((lt2 << REG_MI_MCCNT1_A_L2_SHIFT) & REG_MI_MCCNT1_A_L2_MASK); - - regs->ctrl = REG_MI_MCCNT1_A_START_MASK | REG_MI_MCCNT1_A_RESB_MASK - | rw - | pcount - | ckt - | ((lt1 << REG_MI_MCCNT1_A_L1_SHIFT) & REG_MI_MCCNT1_A_L1_MASK) - | ((lt2 << REG_MI_MCCNT1_A_L2_SHIFT) & REG_MI_MCCNT1_A_L2_MASK) - | ((cpn || dpn) ? (u32)REG_MI_MCCNT1_A_SE_MASK : 0) - | (csc ? REG_MI_MCCNT1_A_CSC_MASK : 0) - | (dsc ? REG_MI_MCCNT1_A_DS_MASK : 0); - -#if 1 - regs->scramble = (cpn || dpn) ? (u32)REG_MI_MCCNT1_A_SE_MASK : 0 - | csc ? REG_MI_MCCNT1_A_CSC_MASK : 0 - | dsc ? REG_MI_MCCNT1_A_DS_MASK : 0; -#endif -} - -/*---------------------------------------------------------------------------* - Name: GCDi_SetCtrl - - Description: set game card control - - Arguments: op : command - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_SetCtrl( GCDSlot slot, GCDCtrlRegs* regs ) -{ - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - - *cnt1 = regs->ctrl | regs->latency | regs->scramble; -} - -/*---------------------------------------------------------------------------* - Name: GCDi_SetOp - - Description: set game card command - - Arguments: op : command - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_SetOp( GCDSlot slot, GCDCmd64* op ) -{ - GCDi_SelectRom( slot ); - - { - REGType8v* cmd = GCDi_SelectRegAddr( slot, REG_MCCMD0_ADDR ); - - cmd[0] = op->b[7]; - cmd[1] = op->b[6]; - cmd[2] = op->b[5]; - cmd[3] = op->b[4]; - cmd[4] = op->b[3]; - cmd[5] = op->b[2]; - cmd[6] = op->b[1]; - cmd[7] = op->b[0]; - } -} - -/*---------------------------------------------------------------------------* - Name: GCD_SendOnlyCardOpCore - - Description: send only rom command - sync version - - Arguments: ctrls : rom control - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_SendOnlyCardOpCore( GCDSlot slot, GCDRomCtrls *ctrls ) -{ - GCDi_WaitCtrl( slot ); - - GCDi_SetOp( slot, &ctrls->gcdOp ); - - GCDi_SetCtrl( slot, ctrls->gcdRegs ); -} - -/*---------------------------------------------------------------------------* - Name: GCD_ReadRomID - - Description: read rom ID - sync version - - Arguments: None - - Returns: rom ID - *---------------------------------------------------------------------------*/ -u32 GCD_ReadRomID( GCDSlot slot ) -{ - return GCD_ReadGameModeID( slot ); -} - -/*---------------------------------------------------------------------------* - Name: GCD_ReadGameModeID - - Description: read rom ID on game mode - sync version - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -u32 GCD_ReadGameModeID( GCDSlot slot ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - u32 romID = 0; - u16 id = (u16)OS_GetLockID(); - - if ( !GCD_IsExisting( slot ) ) - { - return romID; - } - - if ( slot == GCD_PRIMARY_SLOT ) - { - OS_LockCard( id ); - } - else - { - OS_LockExCard( id ); - } - - ctrls->gcdRegs = &ctrls->gIDRegs; - ctrls->gcdOp.dw = GCDOP_G_OP_RD_ROM_ID; - - romID = GCDi_ReadRomIDCore( slot, ctrls ); - - if ( slot == GCD_PRIMARY_SLOT ) - { - OS_UnlockCard( id ); - } - else - { - OS_UnlockExCard( id ); - } - OS_ReleaseLockID( id ); - - return romID; -} - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadRomIDCore - - Description: read rom ID - sync version - - Arguments: ctrls : rom control - - Returns: None - *---------------------------------------------------------------------------*/ -u32 GCDi_ReadRomIDCore( GCDSlot slot, GCDRomCtrls *ctrls ) -{ - REGType32v* data1 = GCDi_SelectRegAddr( slot, REG_MCD1_ADDR ); - - GCDi_WaitCtrl( slot ); - - GCDi_SetOp( slot, &ctrls->gcdOp ); - - GCDi_SetCtrl( slot, ctrls->gcdRegs ); - GCDi_WaitData( slot ); - - return *data1; -} - - -/*---------------------------------------------------------------------------* - Name: GCD_ReadRom - - Description: read rom data - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadRom( GCDSlot slot, u32 romp, void *ramp, s32 size ) -{ - GCDWork *gw = &GCDi_Work[slot]; - u16 id; - - if ( !GCD_IsExisting( slot ) ) - { - return; - } - - id = (u16)OS_GetLockID(); - if ( slot == GCD_PRIMARY_SLOT ) - { - OS_LockCard( id ); - } - else - { - OS_LockExCard( id ); - } - - if ( GCDi_ReadRomPreCore( slot, romp, ramp, size ) ) - { - GCD_ReadGameModeRom( slot, gw->romp, gw->ramp, gw->restSize ); - } - - if ( slot == GCD_PRIMARY_SLOT ) - { - OS_UnlockCard( id ); - } - else - { - OS_UnlockExCard( id ); - } - OS_ReleaseLockID( id ); -} - -/*---------------------------------------------------------------------------* - Name: GCD_ReadRomAsync - - Description: read rom data - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ) -{ - GCDWork *gw = &GCDi_Work[slot]; - - if ( GCDi_ReadRomPreCore( slot, romp, ramp, size ) ) - { - GCD_ReadGameModeRomAsync( slot, gw->romp, gw->ramp, gw->restSize ); - } -} - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadRomPreCore - - Description: read rom data - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -static BOOL GCDi_ReadRomPreCore( GCDSlot slot, u32 romp, void *ramp, s32 size ) -{ - BOOL game_area = GCDi_ReadRomCommonPreCore( slot, romp, ramp, size ); - { - GCDWork *gw = &GCDi_Work[slot]; - romp = gw->romp; - ramp = gw->ramp; - size = gw->restSize; - } - - return game_area; -} - -BOOL GCDi_ReadRomCommonPreCore( GCDSlot slot, u32 romp, void *ram, s32 size ) -{ - GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); - u32 romEndp = romp + size; - u32 secure2 = (u32)rh->l.twlAreaOffset * GCD_TWL_AREA_ALIGN + GCD_SECURE2_AREA_OFFSET; - u32 game2 = secure2 + GCD_SECURE2_AREA_SIZE; - u8 *ramp = ram; - - // header - if ( romp < GCD_ROM_HEADER_SIZE - && size > 0 ) - { - s32 otherSize = (s32)romEndp - GCD_ROM_HEADER_SIZE; - s32 hdrSize = size; - if ( otherSize > 0 ) - { - hdrSize -= otherSize; - } - MI_CpuCopyFast( &GCDi_HeaderBuf[slot][romp/4], ramp, (u32)hdrSize ); - romp += hdrSize; - ramp += hdrSize; - size -= hdrSize; - } - - // pad - if ( romp >= GCD_ROM_HEADER_SIZE && romp < GCD_SECURE_AREA_OFFSET - && size > 0 ) - { - s32 otherSize = (s32)romEndp - (GCD_SECURE_AREA_OFFSET - GCD_ROM_HEADER_SIZE); - s32 padSize = size; - if ( otherSize > 0 ) - { - padSize -= otherSize; - } - MI_CpuClearFast( ramp, (u32)padSize ); - romp += padSize; - ramp += padSize; - size -= padSize; - } - - //secure - if ( romp >= GCD_SECURE_AREA_OFFSET && romp < GCD_GAME_AREA_OFFSET - && size > 0 ) - { - s32 gameSize = (s32)romEndp - GCD_GAME_AREA_OFFSET; - s32 secureSize = size; - if ( gameSize > 0 ) - { - secureSize -= gameSize; - } - MI_CpuCopyFast( &GCDi_SecureAreaBuf[slot][(romp - GCD_SECURE_AREA_OFFSET)/4], ramp, (u32)secureSize ); - romp += secureSize; - ramp += secureSize; - size -= secureSize; - } - - //secure2 - if ( rh->l.twlAreaOffset - && romp >= secure2 && romp < game2 - && size > 0 ) - { - s32 game2Size = (s32)(romEndp - game2); - s32 secure2Size = size; - if ( game2Size > 0 ) - { - secure2Size -= game2Size; - } - MI_CpuCopyFast( &GCDi_Secure2AreaBuf[slot][(romp - secure2)/4], ramp, (u32)secure2Size ); - romp += secure2Size; - ramp += secure2Size; - size -= secure2Size; - } - - GCD_WaitRomAsync( slot ); - - { - GCDWork *gw = &GCDi_Work[slot]; - gw->romp = romp; - gw->ramp = ramp; - gw->restSize = size; - } - - // game - if ( romp >= GCD_GAME_AREA_OFFSET - && size > 0 ) - { - return TRUE; - } - - return FALSE; -} - -/*---------------------------------------------------------------------------* - Name: GCD_ReadNormalModeRom - - Description: read rom data on normal mode - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadNormalModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - s32 restSize = size; - s32 oneShotSize; - - ctrls->gcdRegs = &ctrls->nReadRomRegs; - oneShotSize = GCDi_GetOneShotSizeFromCtrl( ctrls->gcdRegs->ctrl ); - - if ( GCDi_SharedWork[slot].nCardID & GCD_ROMID_1TROM_MASK ) - { - // 3Dメモリ専用設定 - { - ctrls->gcdRegs->ctrl &= ~REG_MI_MCCNT1_A_PC_MASK; - ctrls->gcdRegs->ctrl |= GCD_PAGE_1; - } - } - - while ( restSize > 0 ) // ブロック分割読み込み - { - GCDi_ReadNormalModeRomCore( slot, romp, ramp, oneShotSize, ctrls ); - - romp += oneShotSize; - *(u8 **)&ramp += oneShotSize; - restSize -= oneShotSize; - } - - GCDi_WaitDma( slot, ctrls->dmaNo ); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadNormalModeRomCore - - Description: read rom data on game mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_ReadNormalModeRomCore( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ) -{ - ctrls->gcdOp.dw = GCDOP_N_OP_RD_PAGE - | ((u64 )(romp/GCD_ROM_PAGE_SIZE) << GCDOP_N_RD_PAGE_ADDR_SHIFT); - - GCDi_ReadRomCore( slot, ramp, size, ctrls ); -} - -/*---------------------------------------------------------------------------* - Name: GCD_ReadGameModeRom - - Description: read rom data on game mode - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadGameModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - s32 restSize = size; - s32 oneShotSize; - - ctrls->gcdRegs = &ctrls->gReadRomRegs; - oneShotSize = GCDi_GetOneShotSizeFromCtrl( ctrls->gcdRegs->ctrl ); - - while ( restSize > 0 ) // ブロック分割読み込み - { - GCDi_ReadGameModeRomCore( slot, romp, ramp, oneShotSize, ctrls ); - - romp += oneShotSize; - *(u8 **)&ramp += oneShotSize; - restSize -= oneShotSize; - } - - GCDi_WaitDma( slot, ctrls->dmaNo ); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadGameModeRomCore - - Description: read rom data on game mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCDi_ReadGameModeRomCore( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ) -{ - ctrls->gcdOp.dw = GCDOP_G_OP_RD_PAGE - | ((u64 )(romp/GCD_ROM_PAGE_SIZE) << GCDOP_G_RD_PAGE_ADDR_SHIFT); - - GCDi_ReadRomCore( slot, ramp, size, ctrls ); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadRomCore - - Description: read rom data on game mode - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_ReadRomCore( GCDSlot slot, void *ramp, s32 size, GCDRomCtrls *ctrls ) -{ - u32 dmaNo = ctrls->dmaNo; - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - REGType32v* data1 = GCDi_SelectRegAddr( slot, REG_MCD1_ADDR ); - - if ( !GCD_IsExisting( slot ) ) - { - return; - } - - GCDi_WaitDma( slot, dmaNo ); - - GCDi_SetOp( slot, &ctrls->gcdOp ); // コマンド設定 - - if ( MI_EXDMA_CH_MIN <= dmaNo && dmaNo <= MI_EXDMA_CH_MAX ) - { - GCD_DmaRecvRomAsync( slot, dmaNo, ramp ); - GCDi_SetCtrl( slot, ctrls->gcdRegs ); // コントロール設定 & DMAスタート - } - else - { - void *ramEndp; - u32 ctrlTmp; - - GCDi_SetCtrl( slot, ctrls->gcdRegs ); // コントロール設定 - - ramEndp = (u8 *)ramp + size; // 格納終了アドレス算出 - - do { // CPU読み込み - ctrlTmp = *cnt1; - - if (ctrlTmp & REG_MI_MCCNT1_A_RDY_MASK) { - u32 dataTmp = *data1; - - if (ramp < ramEndp) - { - *((vu32 *)ramp) = dataTmp; // 指定サイズまで格納(後続データは読み捨て) - (*(vu32 **)&ramp)++; - } - } - } - while (ctrlTmp & REG_MI_MCCNT1_A_START_MASK); - } -} - - -/*---------------------------------------------------------------------------* - Name: GCD_WriteGameModeRom - - Description: write rom data on game mode - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_WriteGameModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - s32 restSize = size; - s32 oneShotSize; - - ctrls->gcdRegs = &ctrls->gWriteRomRegs; - - oneShotSize = GCDi_GetOneShotSizeFromCtrl( ctrls->gcdRegs->ctrl ); - - while ( restSize > 0 ) // ブロック分割読み込み - { - GCDi_WriteGameModeRomCore( slot, romp, ramp, oneShotSize, ctrls ); - - romp += oneShotSize; - *(u8 **)&ramp += oneShotSize; - restSize -= oneShotSize; - } - - GCDi_WaitDma( slot, ctrls->dmaNo ); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_WriteGameModeRomCore - - Description: write rom data on game mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCDi_WriteGameModeRomCore( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ) -{ - ctrls->gcdOp.dw = GCDOP_G_OP_WR_PAGE - | ((u64 )(romp/GCD_ROM_PAGE_SIZE) << GCDOP_G_RD_PAGE_ADDR_SHIFT); - - GCDi_WriteRomCore( slot, ramp, size, ctrls ); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_WriteRomCore - - Description: write rom data on game mode - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WriteRomCore( GCDSlot slot, void *ramp, s32 size, GCDRomCtrls *ctrls ) -{ - u32 dmaNo = ctrls->dmaNo; - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - REGType32v* data1 = GCDi_SelectRegAddr( slot, REG_MCD1_ADDR ); - -// OS_TPrintf( "\nwrite size = %#x\n\n", size ); - - GCDi_WaitDma( slot, dmaNo ); - - GCDi_SetOp( slot, &ctrls->gcdOp ); // コマンド設定 - - if ( MI_EXDMA_CH_MIN <= dmaNo && dmaNo <= MI_EXDMA_CH_MAX ) - { - GCD_DmaSendRomAsync( slot, dmaNo, ramp ); - GCDi_SetCtrl( slot, ctrls->gcdRegs ); // コントロール設定 & DMAスタート - } - else - { - void *ramEndp; - u32 ctrlTmp; - - GCDi_SetCtrl( slot, ctrls->gcdRegs ); // コントロール設定 - - ramEndp = (u8 *)ramp + size; // 格納終了アドレス算出 - - do { // CPU読み込み - ctrlTmp = *cnt1; - - if (ctrlTmp & REG_MI_MCCNT1_A_RDY_MASK) { - u32 dataTmp = 0; - - if (ramp < ramEndp) - { - dataTmp = *((vu32 *)ramp); - (*(vu32 **)&ramp)++; - } - *data1 = dataTmp; - } - } - while (ctrlTmp & REG_MI_MCCNT1_A_START_MASK); - } -} - -/*---------------------------------------------------------------------------* - Name: GCD_DmaRecvRomAsync - - Description: receive data with DMA - async version - - Arguments: dmaNo : DMA channel No. - dest : destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCD_DmaRecvRomAsync( GCDSlot slot, u32 dmaNo, void *dest ) -{ - const void* data1 = GCDi_SelectRegAddr( slot, REG_MCD1_ADDR ); - u32 timing = MI_NDMA_TIMING_CARD_A; - u32 blockSize = MI_NDMA_BWORD_1; - u32 interval = 1; - u32 prescale = MI_NDMA_INTERVAL_PS_1; - - if ( slot == GCD_SECONDARY_SLOT ) - { - timing = MI_NDMA_TIMING_CARD_B; - } - - MIi_ExDmaRecvAsyncCore(dmaNo, data1, dest, 4, 4, - blockSize, interval, prescale, - MI_NDMA_CONTINUOUS_ON, MI_NDMA_SRC_RELOAD_ENABLE, MI_NDMA_DEST_RELOAD_DISABLE, - timing); -} - -/*---------------------------------------------------------------------------* - Name: GCD_DmaSendRomAsync - - Description: receive data with DMA - async version - - Arguments: dmaNo : DMA channel No. - dest : destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCD_DmaSendRomAsync( GCDSlot slot, u32 dmaNo, void *src ) -{ - const void* data1 = GCDi_SelectRegAddr( slot, REG_MCD1_ADDR ); - u32 timing = MI_NDMA_TIMING_CARD_A; - u32 blockSize = MI_NDMA_BWORD_1; - u32 interval = 1; - u32 prescale = MI_NDMA_INTERVAL_PS_1; - - if ( slot == GCD_SECONDARY_SLOT ) - { - timing = MI_NDMA_TIMING_CARD_B; - } - - MIi_ExDmaSendAsyncCore(dmaNo, src, (void*)REG_MCD1_ADDR, 4, 4, - blockSize, interval, prescale, - MI_NDMA_CONTINUOUS_ON, MI_NDMA_SRC_RELOAD_DISABLE, MI_NDMA_DEST_RELOAD_ENABLE, - timing); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_GetOneShotSizeFromCtrl - - Description: get block size - - Arguments: ctrl : rom control - - Returns: None - *---------------------------------------------------------------------------*/ -s32 GCDi_GetOneShotSizeFromCtrl( u32 ctrl ) -{ - s32 oneShotSize = 0; - u32 pages = (ctrl & REG_MI_MCCNT1_A_PC_MASK) >> REG_MI_MCCNT1_A_PC_SHIFT; - s32 pageSize = 512; - - oneShotSize = pageSize << (pages - 1); - - return oneShotSize; -} - - -/*---------------------------------------------------------------------------* - Name: GCD_ReadNormalModeRomAsync - - Description: read rom data on normal mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadNormalModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ) -{ - GCDWork *gw = &GCDi_Work[slot]; - GCDRomCtrls *ctrls = &gw->ctrls; - - ctrls->gcdRegs = &ctrls->nReadRomRegs; - - gw->funcp = GCDi_ReadNormalModeRomCore; - - GCD_SetInterrupt( slot, romp, ramp, size, gw ); - - gw->funcp( slot, gw->romp, gw->ramp, gw->oneShotSize, ctrls ); -} - - -/*---------------------------------------------------------------------------* - Name: GCD_ReadGameModeRomAsync - - Description: read rom data on game mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadGameModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ) -{ - GCDWork *gw = &GCDi_Work[slot]; - GCDRomCtrls *ctrls = &gw->ctrls; - - ctrls->gcdRegs = &ctrls->gReadRomRegs; - - gw->funcp = GCDi_ReadGameModeRomCore; - - GCD_SetInterrupt( slot, romp, ramp, size, gw ); - - gw->funcp( slot, gw->romp, gw->ramp, gw->oneShotSize, ctrls ); -} - - -/*---------------------------------------------------------------------------* - Name: GCD_WriteGameModeRomAsync - - Description: write rom data on game mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_WriteGameModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ) -{ - GCDWork *gw = &GCDi_Work[slot]; - GCDRomCtrls *ctrls = &gw->ctrls; - - ctrls->gcdRegs = &ctrls->gWriteRomRegs; - - gw->funcp = GCDi_WriteGameModeRomCore; - - GCD_SetInterrupt( slot, romp, ramp, size, gw ); - - gw->funcp( slot, gw->romp, gw->ramp, gw->oneShotSize, ctrls ); -} - - -/*---------------------------------------------------------------------------* - Name: GCD_SetInterrupt - - Description: set interrupt - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_SetInterrupt( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDWork *gw ) -{ - GCDRomCtrls *ctrls = &gw->ctrls; - u32 dmaNo = ctrls->dmaNo; - u32 mask = GCDi_SelectIrqMask( slot, OS_IE_CARD_DATA ); - OSIrqFunction intr = GCDi_InterruptHandlerPRIME; - - gw->romp = romp; - gw->ramp = ramp; - gw->restSize = size; - gw->oneShotSize = GCDi_GetOneShotSizeFromCtrl( ctrls->gcdRegs->ctrl ); - - if ( dmaNo < MI_EXDMA_CH_MIN || MI_EXDMA_CH_MAX < dmaNo ) - { - ctrls->lastDmaNo = ctrls->dmaNo; - ctrls->dmaNo = GCD_DEFAULT_DMA_A_NO; - if ( slot == GCD_SECONDARY_SLOT ) - { - ctrls->dmaNo = GCD_DEFAULT_DMA_B_NO; - } - } - - GCDi_WaitDma( slot, dmaNo ); - - (void)OS_DisableInterrupts(); - - if ( slot ) - { - intr = GCDi_InterruptHandlerSECOND; - } - - OS_SetIrqFunction( mask, intr ); - - gw->isAsync = TRUE; - - gw->intrDone = FALSE; - - reg_OS_IF = mask; - reg_OS_IE |= mask; - - (void)OS_EnableInterrupts(); - (void)OS_EnableIrq(); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_InterruptHandler - - Description: interrupt handler - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_InterruptHandlerCommon( GCDSlot slot ) -{ - GCDWork *gw = &GCDi_Work[slot]; - s32 oneShotSize = gw->oneShotSize; - - // read block - - gw->romp += oneShotSize; - gw->ramp += oneShotSize; - gw->restSize -= oneShotSize; - - if (gw->restSize > 0) { - GCDRomCtrls *ctrls = &gw->ctrls; - gw->oneShotSize = GCDi_GetOneShotSizeFromCtrl( ctrls->gcdRegs->ctrl ); - gw->funcp( slot, gw->romp, gw->ramp, oneShotSize, &gw->ctrls ); - } else { - gw->intrDone = TRUE; // カード割込処理完了の通知 - } -} - -void GCDi_InterruptHandlerPRIME( void ) -{ - GCDi_InterruptHandlerCommon( GCD_PRIMARY_SLOT ); -} - -void GCDi_InterruptHandlerSECOND( void ) -{ - GCDi_InterruptHandlerCommon( GCD_SECONDARY_SLOT ); -} - - -//================================================================================ -// WAIT/STOP -//================================================================================ -/*---------------------------------------------------------------------------* - Name: GCD_IsBusy - - Description: check whether game card is busy or not - - Arguments: None - - Returns: TRUE if game card is busy, FALSE if not - *---------------------------------------------------------------------------*/ -BOOL GCD_IsBusy( GCDSlot slot ) -{ - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - - return (BOOL)((*cnt1 & REG_MI_MCCNT1_A_START_MASK) >> REG_MI_MCCNT1_A_START_SHIFT); -} - -/*---------------------------------------------------------------------------* - Name: GCD_IsDataReady - - Description: check whether data is ready or not - - Arguments: None - - Returns: TRUE if game card is busy, FALSE if not - *---------------------------------------------------------------------------*/ -BOOL GCD_IsDataReady( GCDSlot slot ) -{ - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - - return (BOOL)((*cnt1 & REG_MI_MCCNT1_A_RDY_MASK) >> REG_MI_MCCNT1_A_RDY_SHIFT); -} - -/*---------------------------------------------------------------------------* - Name: GCD_Stop - - Description: stop game card access - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_Stop( GCDSlot slot ) -{ - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - - OSIntrMode enabled = OS_DisableInterrupts(); - - *cnt1 &= ~REG_MI_MCCNT1_A_START_MASK; - - (void)OS_RestoreInterrupts(enabled); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_WaitCtrl - - Description: wait while game card is busy - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WaitCtrl( GCDSlot slot ) -{ - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - - while (*cnt1 & REG_MI_MCCNT1_A_START_MASK) - { - } -} - -/*---------------------------------------------------------------------------* - Name: GCDi_WaitData - - Description: wait until data is ready - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WaitData( GCDSlot slot ) -{ - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - - while ( !(*cnt1 & REG_MI_MCCNT1_A_RDY_MASK) ) - { - } -} - -/*---------------------------------------------------------------------------* - Name: GCDi_WaitDma - - Description: wait for stopping game card DMA - - Arguments: dmaNo : DMA channel No. - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WaitDma( GCDSlot slot, u32 dmaNo ) -{ - GCDi_WaitCtrl( slot ); - - if ( MI_EXDMA_CH_MIN <= dmaNo && dmaNo <= MI_EXDMA_CH_MAX ) - { - MIi_StopExDma( dmaNo ); - } -} - - -/*---------------------------------------------------------------------------* - Name: GCDi_WaitInterrupt - - Description: wait for game card interrupt - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WaitInterrupt( GCDSlot slot ) -{ - GCDWork *gw = &GCDi_Work[slot]; - - if ( gw->isAsync ) - { - while ( !gw->intrDone ) - { - } - } - gw->intrDone = FALSE; - gw->isAsync = FALSE; - - GCDi_WaitDma( slot, gw->ctrls.dmaNo ); -} - -/*---------------------------------------------------------------------------* - Name: GCD_WaitRomAsync - - Description: wait for game card async access - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_WaitRomAsync( GCDSlot slot ) -{ - GCDi_WaitInterrupt( slot ); - - { - GCDWork *gw = &GCDi_Work[slot]; - GCDRomCtrls *ctrls = &gw->ctrls; - u32 mask = GCDi_SelectIrqMask( slot, OS_IE_CARD_DATA ); - - OSIntrMode enabled = OS_DisableInterrupts(); - - ctrls->dmaNo = ctrls->lastDmaNo; - -#define IOP_DISABLE_OS_TIMER -#ifdef IOP_DISABLE_OS_TIMER - reg_OS_IE &= ~REG_OS_IE_T1_MASK; -#endif // IOP_DISABLE_OS_TIMER - - reg_OS_IE &= ~mask; // disable card interrupt - - (void)OS_RestoreInterrupts( enabled ); - } -} - - diff --git a/build/libraries/gcd/common/gcd_init.c b/build/libraries/gcd/common/gcd_init.c deleted file mode 100644 index 43d5c83e..00000000 --- a/build/libraries/gcd/common/gcd_init.c +++ /dev/null @@ -1,1696 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlBrom - GCD - libraries - File: gcd_init.c - - Copyright 2007 Nintendo. All rights reserved. - - These coded instructions, statements, and computer programs contain - proprietary information of Nintendo of America Inc. and/or Nintendo - Company Ltd., and are protected by Federal copyright law. They may - not be disclosed to third parties or copied or duplicated in any form, - in whole or in part, without the prior written consent of Nintendo. - - $Log: $ - $NoKeywords: $ - *---------------------------------------------------------------------------*/ - -#include -#include -#include -#include - -//#define PRINT_DEBUG - -#ifdef PRINT_DEBUG -#define DBG_PRINTF vlink_dos_printf -#define DBG_CHAR vlink_dos_put_console -#else -#define DBG_PRINTF( ... ) ((void)0) -#define DBG_CHAR( c ) ((void)0) -#endif - - -//#define FIRM_FORCE_DEBUGGER -#define FIRM_FORCE_FIRMBLOWFISH - -#ifndef FIRM_FORCE_DEBUGGER -#define GCD_ENABLE_SCRAMBLE -#endif // FIRM_FORCE_DEBUGGER - -static void GCDi_GetExistingSlots( GCDSlot* start, GCDSlot* end ); -void GCDi_CallbackForReset(PXIFifoTag tag, u32 data, BOOL err); -void GCDi_CallbackForResetAll(PXIFifoTag tag, u32 data, BOOL err); - -static void GCDi_SetPngIntf( GCDSlot slot, u32 pnA_l, u8 pnA_h, u32 pnB_l, u8 pnB_h ); -static void GCDi_SendOnlyCardSecureOpCore( GCDSlot slot, GCDRomCtrls *ctrls ); -static void GCDi_ReadSecureModeRomCore( GCDSlot slot, void *ramp, s32 size, GCDRomCtrls *ctrls ); -static void Encrypt2SetTimer4Secure( GCDSlot slot, GCDRomCtrls *ctrls ); - -static BOOL IsCtrApp( GCDSlot slot ); -static BOOL IsDsApp( GCDSlot slot ); - -static BOOL GCDi_SecureInitialized[2]; - - -static void GCDi_LoadHeader( GCDSlot slot ); -static void GCDi_LoadHeaderAll( void ); -static void GCDi_LoadTable( GCDSlot slot ); -static void GCDi_LoadTableAsync( GCDSlot slot ); -static void GCDi_ReadShortHeader( GCDSlot slot, void *ramp ); -static void GCDi_ReadShortHeaderAsync( GCDSlot slot, void *ramp ); -static void GCDi_LoadSecure( GCDSlot slot ); -static void GCDi_LoadSecure2( GCDSlot slot ); -static void GCDi_LoadSecureAll( void ); -static void GCDi_LoadSecure2All( void ); - -static BOOL GCD_Initialized[2]; -extern GCDSharedWork GCDi_SharedWork[2]; -extern GCDSecureWork GCDi_SecureWork[2]; - -GCDWork GCDi_Work[2]; - - - -void* GCDi_GetRomHeaderAddr( GCDSlot slot ) -{ - return ((void*)GCDi_HeaderBuf[slot]); -} - - -// ※SDKにSecondarySlotのカードプロセッサ設定が用意されていないので、とりあえずローカルで用意。 -#ifdef SDK_ARM9 -static inline void MIi_SetExCardProcessor(MIProcessor proc) -{ - MI_PROCESSOR_ASSERT(proc); - reg_MI_EXMEMCNT = - (u16)((reg_MI_EXMEMCNT & ~REG_MI_EXMEMCNT_MPB_MASK) | (proc << REG_MI_EXMEMCNT_MPB_SHIFT)); -} -#endif -#ifdef SDK_ARM7 -#define REG_MI_EXMEMCNT_MPB_MASK 0x0400 -#define REG_MI_EXMEMCNT_MPB_SHIFT 10 -#endif -static inline MIProcessor MI_GetExCardProcessor(void) -{ - return (MIProcessor)((reg_MI_EXMEMCNT & REG_MI_EXMEMCNT_MPB_MASK) >> REG_MI_EXMEMCNT_MPB_SHIFT); -} - -// ※SDKにSecondarySlotのカードロックが用意されていないので、とりあえずPrimarySlotと共用で。 -#ifdef SDK_ARM9 -#define OSi_ASSERT_ID( id ) SDK_ASSERTMSG( id >= OS_MAINP_LOCK_ID_START && id <= OS_MAINP_SYSTEM_LOCK_ID, \ - "lock ID %d is out of bounds", id ) -#else -#define OSi_ASSERT_ID( id ) SDK_ASSERTMSG( id >= OS_SUBP_LOCK_ID_START && id <= OS_SUBP_SYSTEM_LOCK_ID, \ - "lock ID %d is out of bounds", id ) -#endif - -static void OSi_AllocateExCardBus(void) -{ -#ifdef SDK_ARM9 - MIi_SetExCardProcessor(MI_PROCESSOR_ARM9); // Card for MAIN -#endif -} - -static void OSi_FreeExCardBus(void) -{ -#ifdef SDK_ARM9 - MIi_SetExCardProcessor(MI_PROCESSOR_ARM7); // Card for SUB -#endif -} - -#define HW_CARD_B_LOCK_BUF HW_CTRDG_LOCK_BUF - -s32 OS_LockExCard(u16 lockID) -{ - OSi_ASSERT_ID(lockID); - - return OS_LockByWord(lockID, (OSLockWord *)HW_CARD_B_LOCK_BUF, OSi_AllocateExCardBus); -} - -s32 OS_UnlockExCard(u16 lockID) -{ - OSi_ASSERT_ID(lockID); - - return OS_UnlockByWord(lockID, (OSLockWord *)HW_CARD_B_LOCK_BUF, OSi_FreeExCardBus); -} - - -/*---------------------------------------------------------------------------* - Name: GCD_Init - - Description: initialize for game card access - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_Init( void ) -{ - GCDSlot slot; - MIProcessor lastProc = MI_GetCardProcessor(); - MIProcessor lastProcB = MI_GetExCardProcessor(); - u16 id = (u16)OS_GetLockID(); - - OS_LockCard( id ); - OS_LockExCard( id ); - -#ifdef SDK_ARM9 - MIi_SetCardProcessor( MI_PROCESSOR_ARM9 ); - MIi_SetExCardProcessor( MI_PROCESSOR_ARM9 ); -#else // SDK_ARM9 - while ( MI_GetCardProcessor() != MI_PROCESSOR_ARM7 ) - { - } - while ( MI_GetExCardProcessor() != MI_PROCESSOR_ARM7 ) - { - } -#endif // SDK_ARM7 - - if ( GCD_Initialized[GCD_PRIMARY_SLOT] == FALSE || - GCD_Initialized[GCD_SECONDARY_SLOT] == FALSE ) - { - GCDi_Init( TRUE ); - GCDi_LoadHeaderAll(); - GCDi_LoadSecureAll(); - } - - for (slot=GCD_PRIMARY_SLOT; slot<=GCD_SECONDARY_SLOT; slot++) - { - if ( GCD_Initialized[slot] == FALSE ) - { - if ( GCD_IsExisting( slot ) ) - { - if ( GCDi_IsDsApp( slot ) ) - { - GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); - - if ( rh->l.twlAreaOffset ) // && (sh->nCardID & GCD_ROMID_TWLROM_MASK) ) - { - u32 chat_cycles = OS_MSEC_TO_CPUCYC( 25 ) / GCD_CHATTERING_CYCLES; -#ifdef SDK_ARM9 - chat_cycles /= 2; -#endif // SDK_ARM9 - GCD_Reset( slot, chat_cycles ); - GCDi_LoadHeader( slot ); - GCDi_LoadSecure2( slot ); - } - - GCD_Initialized[slot] = TRUE; - } - } - } - } - -#ifdef SDK_ARM9 - MIi_SetCardProcessor( lastProc ); - MIi_SetExCardProcessor( lastProcB ); -#endif // SDK_ARM9 - - OS_UnlockExCard( id ); - OS_UnlockCard( id ); - - OS_ReleaseLockID( id ); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_Init - - Description: initialize for game card access - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_Init( BOOL reset ) -{ - static BOOL initialized; - - if ( initialized == FALSE ) - { - GCDSlot slot; - - if ( reset ) - { -#ifdef SDK_ARM7 - - OSIntrMode enabled; - OSIrqMask lastIE; - BOOL lastIME; - - lastIE = OS_EnableIrqMask(OS_IE_SPFIFO_RECV); - lastIME = OS_EnableIrq(); - enabled = OS_EnableInterrupts(); - - //---- setting PXI - PXI_Init(); - PXI_SetFifoRecvCallback(PXI_FIFO_TAG_GCD, GCDi_CallbackForResetAll); - - while ( !( GCDi_Work[GCD_PRIMARY_SLOT].isPxiDone == TRUE && - GCDi_Work[GCD_SECONDARY_SLOT].isPxiDone == TRUE ) ) - { - } - - (void)OS_RestoreIrq(lastIME); - (void)OS_SetIrqMask(lastIE); - (void)OS_RestoreInterrupts(enabled); - -#else // SDK_ARM9 - - u32 chat_cycles = OS_MSEC_TO_CPUCYC( 25 ) / GCD_CHATTERING_CYCLES; - chat_cycles /= 2; - GCD_ResetAll( chat_cycles ); - -#endif // SDK_ARM9 - } - - for (slot=GCD_PRIMARY_SLOT; slot<=GCD_SECONDARY_SLOT; slot++) - { - GCDWork *gw = &GCDi_Work[slot]; - GCDRomCtrls *ctrls = &gw->ctrls; - - GCDi_GenCtrl( &ctrls->nLoadTableRegs, GCD_RW_READ, - GCD_PAGE_16, - GCD_CKT_240NS, 0, 0x18, - FALSE, FALSE, FALSE, FALSE ); - - GCDi_GenCtrl( &ctrls->nSendOnlyOpRegs, GCD_RW_READ, - GCD_PAGE_0, - GCD_CKT_240NS, 0x18, 0, - FALSE, FALSE, FALSE, FALSE ); - - GCDi_GenCtrl( &ctrls->nIDRegs, GCD_RW_READ, - GCD_PAGE_STAT, - GCD_CKT_240NS, 0x18, 0, - FALSE, FALSE, FALSE, FALSE ); - - GCDi_GenCtrl( &ctrls->nReadShortHeaderRegs, GCD_RW_READ, - GCD_PAGE_1, - GCD_CKT_240NS, REG_MI_MCCNT1_L1_MASK, REG_MI_MCCNT1_L2_MASK >> REG_MI_MCCNT1_L2_SHIFT, - FALSE, FALSE, FALSE, FALSE ); - - GCDi_GenCtrl( &ctrls->nReadRomRegs, GCD_RW_READ, - GCD_PAGE_8, - GCD_CKT_240NS, 0x657, 0x1, - FALSE, FALSE, FALSE, FALSE ); - - GCDi_GenCtrl( &ctrls->sSendOnlyOpRegs, GCD_RW_READ, - GCD_PAGE_0, - GCD_CKT_240NS, 0x8f8+0x18, 0, - FALSE, FALSE, FALSE, FALSE ); // enable after PNG ON - - GCDi_GenCtrl( &ctrls->sIDRegs, GCD_RW_READ, - GCD_PAGE_STAT, - GCD_CKT_240NS, 0x8f8+0x18, 0, - FALSE, TRUE, FALSE, TRUE ); - - GCDi_GenCtrl( &ctrls->sReadRomRegs, GCD_RW_READ, - GCD_PAGE_8, - GCD_CKT_240NS, 0x8f8, 0x18, - FALSE, TRUE, FALSE, TRUE ); - - GCDi_GenCtrl( &ctrls->gIDRegs, GCD_RW_READ, - GCD_PAGE_STAT, - GCD_CKT_150NS, 0, 0x1, -#ifdef GCD_ENABLE_SCRAMBLE - TRUE, TRUE, TRUE, TRUE ); -#else // GCD_ENABLE_SCRAMBLE - FALSE, FALSE, FALSE, FALSE ); -#endif // GCD_ENABLE_SCRAMBLE - - GCDi_GenCtrl( &ctrls->gReadRomRegs, GCD_RW_READ, - GCD_PAGE_1, - GCD_CKT_150NS, 0x657, 0x1, -#ifdef GCD_ENABLE_SCRAMBLE - TRUE, TRUE, TRUE, TRUE ); -#else // GCD_ENABLE_SCRAMBLE - FALSE, FALSE, FALSE, FALSE ); -#endif // GCD_ENABLE_SCRAMBLE - - GCDi_GenCtrl( &ctrls->gWriteRomRegs, GCD_RW_WRITE, - GCD_PAGE_1, - GCD_CKT_150NS, 0x21, 0x1, -#ifdef GCD_ENABLE_SCRAMBLE - TRUE, TRUE, TRUE, TRUE ); -#else // GCD_ENABLE_SCRAMBLE - FALSE, FALSE, FALSE, FALSE ); -#endif // GCD_ENABLE_SCRAMBLE - } - - initialized = TRUE; - } -} - - -/*---------------------------------------------------------------------------* - Name: GCD_SetPrimarySlot - - Description: set primary game card slot - - Arguments: primary slot - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_SetPrimarySlot( u8 slot ) -{ - if ( slot <= 1 ) - { - reg_MI_MC_SWP = (u8)(slot * REG_MI_MC_SWP_E_MASK); - } -} - -/*---------------------------------------------------------------------------* - Name: GCD_GetPrimarySlot - - Description: get primary game card slot - - Arguments: None - - Returns: primary slot - *---------------------------------------------------------------------------*/ -u8 GCD_GetPrimarySlot( void ) -{ - return (u8)((reg_MI_MC_SWP & REG_MI_MC_SWP_E_MASK) >> REG_MI_MC_SWP_E_SHIFT); -} - - -/*---------------------------------------------------------------------------* - Name: GCDi_SendtoPxi - - Description: send data via PXI - - Arguments: data : data to send - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_SendtoPxi(u32 data) -{ - while (PXI_SendWordByFifo(PXI_FIFO_TAG_GCD, data, FALSE) != PXI_FIFO_SUCCESS) - { - SVC_WaitByLoop(1); - } -} - -/*---------------------------------------------------------------------------* - Name: GCDi_CallbackForReset - - Description: callback to receive data from PXI - - Arguments: tag : tag from PXI (unused) - data : data from PXI - err : error bit (unused) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_CallbackForReset(PXIFifoTag tag, u32 data, BOOL err) -{ -#pragma unused( tag, err ) - GCDPxiCmd pxi; - pxi.raw = data; - - if (pxi.e.cmd == GCD_PXI_COMMAND_RESET) - { -#ifdef SDK_ARM7 - GCD_Reset( (GCDSlot)pxi.e.slot, pxi.e.param ); - //---- send message to ARM9 - GCDi_SendtoPxi( GCD_PXI_COMMAND_RESET ); -#endif // SDK_ARM7 - - GCDi_Work[pxi.e.slot].isPxiDone = TRUE; - } - else - { -#ifndef SDK_FINALROM - OS_Panic("illegal GCD pxi command."); -#else - OS_Panic(""); -#endif - } -} - -/*---------------------------------------------------------------------------* - Name: GCDi_CallbackForResetAll - - Description: callback to receive data from PXI - - Arguments: tag : tag from PXI (unused) - data : data from PXI - err : error bit (unused) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_CallbackForResetAll(PXIFifoTag tag, u32 data, BOOL err) -{ -#pragma unused( tag, err ) - GCDPxiCmd pxi; - pxi.raw = data; - - if (pxi.e.cmd == GCD_PXI_COMMAND_RESET) - { -#ifdef SDK_ARM7 - GCD_ResetAll( pxi.e.param ); - //---- send message to ARM9 - GCDi_SendtoPxi( GCD_PXI_COMMAND_RESET ); -#endif // SDK_ARM7 - - GCDi_Work[GCD_PRIMARY_SLOT].isPxiDone = TRUE; - GCDi_Work[GCD_SECONDARY_SLOT].isPxiDone = TRUE; - } - else - { -#ifndef SDK_FINALROM - OS_Panic("illegal GCD pxi command."); -#else - OS_Panic(""); -#endif - } -} - - -/*---------------------------------------------------------------------------* - Name: GCDi_GetExistingSlots - - Description: get enabled slots - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCDi_GetExistingSlots( GCDSlot* start, GCDSlot* end ) -{ - if ( GCD_IsExisting( GCD_PRIMARY_SLOT ) ) - { - *start = GCD_PRIMARY_SLOT; - if ( GCD_IsExisting( GCD_SECONDARY_SLOT ) ) - { - *end = GCD_SECONDARY_SLOT; - } - else - { - *end = GCD_PRIMARY_SLOT; - } - } - else - { - *start = GCD_SECONDARY_SLOT; - if ( GCD_IsExisting( GCD_SECONDARY_SLOT ) ) - { - *end = GCD_SECONDARY_SLOT; - } - else - { - *end = GCD_NO_SLOT; - } - } -} - - -/*---------------------------------------------------------------------------* - Name: GCD_Reset - - Description: reset game card - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_Reset( GCDSlot slot, u32 chat_cycles ) -{ -#ifdef SDK_ARM9 -#pragma unused( chat_cycles, slot ) - - OSIntrMode enabled; - OSIrqMask lastIE; - BOOL lastIME; - - GCDPxiCmd pxi; - GCDi_Work[GCD_PRIMARY_SLOT].isPxiDone = FALSE; - GCDi_Work[GCD_SECONDARY_SLOT].isPxiDone = FALSE; - - lastIE = OS_EnableIrqMask(OS_IE_SPFIFO_RECV); - lastIME = OS_EnableIrq(); - enabled = OS_EnableInterrupts(); - - //---- setting PXI - PXI_Init(); - while (!PXI_IsCallbackReady(PXI_FIFO_TAG_GCD, PXI_PROC_ARM7)) - { - } - PXI_SetFifoRecvCallback(PXI_FIFO_TAG_GCD, GCDi_CallbackForReset); - - pxi.e.cmd = GCD_PXI_COMMAND_RESET; - pxi.e.param = chat_cycles; - pxi.e.slot = (u32)slot; - - //---- send message to ARM7 - GCDi_SendtoPxi( pxi.raw ); - - while ( !( GCDi_Work[GCD_PRIMARY_SLOT].isPxiDone == TRUE && - GCDi_Work[GCD_SECONDARY_SLOT].isPxiDone == TRUE ) ) - { - } - - (void)OS_RestoreIrq(lastIME); - (void)OS_SetIrqMask(lastIE); - (void)OS_RestoreInterrupts(enabled); - - PXI_SetFifoRecvCallback(PXI_FIFO_TAG_GCD, NULL); - - GCDi_Enable( slot ); - -#else // SDK_ARM7 - - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - - reg_MI_MCCHAT = (u16)chat_cycles; - - OS_SpinWait( chat_cycles * GCD_CHATTERING_CYCLES ); - - if ( !GCD_IsExisting( slot ) ) - { - return; - } - - GCDi_Enable( slot ); - - if ( GCD_GetDetectMode( slot ) != 0 ) - { - GCD_SetDetectMode( slot, 3 ); - - while ( GCD_GetDetectMode( slot ) != 0 ) - { - } - } - - OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); - - GCD_SetDetectMode( slot, 1 ); - - OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); - - GCD_SetDetectMode( slot, 2 ); - - OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); - - *cnt1 = REG_MI_MCCNT1_RESB_MASK; // preset - - OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); - -#endif // SDK_ARM7 -} - -/*---------------------------------------------------------------------------* - Name: GCD_ResetAll - - Description: reset game cards - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ResetAll( u32 chat_cycles ) -{ -#ifdef SDK_ARM9 -#pragma unused( chat_cycles ) - - GCDWork *gw = &GCDi_Work[GCD_PRIMARY_SLOT]; - OSIntrMode enabled; - OSIrqMask lastIE; - BOOL lastIME; - - GCDSlot slot; - GCDPxiCmd pxi; - gw->isPxiDone = FALSE; - - lastIE = OS_EnableIrqMask(OS_IE_SPFIFO_RECV); - lastIME = OS_EnableIrq(); - enabled = OS_EnableInterrupts(); - - //---- setting PXI - PXI_Init(); - while (!PXI_IsCallbackReady(PXI_FIFO_TAG_GCD, PXI_PROC_ARM7)) - { - } - PXI_SetFifoRecvCallback(PXI_FIFO_TAG_GCD, GCDi_CallbackForResetAll); - - pxi.e.cmd = GCD_PXI_COMMAND_RESET; - pxi.e.param = chat_cycles; - pxi.e.slot = (u32)NULL; - - //---- send message to ARM7 - GCDi_SendtoPxi( pxi.raw ); - - while (gw->isPxiDone == FALSE) - { - } - - (void)OS_RestoreIrq(lastIME); - (void)OS_SetIrqMask(lastIE); - (void)OS_RestoreInterrupts(enabled); - - PXI_SetFifoRecvCallback(PXI_FIFO_TAG_GCD, NULL); - - for (slot=GCD_PRIMARY_SLOT; slot<=GCD_SECONDARY_SLOT; slot++) - { - GCDi_Enable( slot ); - } - -#else // SDK_ARM7 - - GCDSlot slot, start, end; - - reg_MI_MCCHAT = (u16)chat_cycles; - - OS_SpinWait( chat_cycles * GCD_CHATTERING_CYCLES ); - - GCDi_GetExistingSlots( &start, &end ); - - for (slot=start; slot<=end; slot++) - { - GCDi_Enable( slot ); - - if ( GCD_GetDetectMode( slot ) != 0 ) - { - GCD_SetDetectMode( slot, 3 ); - - while ( GCD_GetDetectMode( slot ) != 0 ) - { - } - } - } - - if ( end != GCD_NO_SLOT ) - { - OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); - } - - for (slot=start; slot<=end; slot++) - { - GCD_SetDetectMode( slot, 1 ); - } - - if ( end != GCD_NO_SLOT ) - { - OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); - } - - for (slot=start; slot<=end; slot++) - { - GCD_SetDetectMode( slot, 2 ); - } - - if ( end != GCD_NO_SLOT ) - { - OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); - } - - for (slot=start; slot<=end; slot++) - { - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - *cnt1 = REG_MI_MCCNT1_RESB_MASK; // preset - } - - if ( end != GCD_NO_SLOT ) - { - OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); - } - -#endif // SDK_ARM7 -} - -/*---------------------------------------------------------------------------* - Name: GCDi_LoadSecure - - Description: load secure area - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ - -static BOOL isCtrApp[2]; -static BOOL isDsApp[2]; - - -/*************************************************** - - ***************************************************/ - -BOOL GCDi_IsDsApp( GCDSlot slot ) -{ - return isDsApp[slot]; -} - -static const u8 dsNinLogo[] = { -0x24,0xff,0xae,0x51,0x69,0x9a,0xa2,0x21,0x3d,0x84,0x82,0x0a,0x84,0xe4,0x09,0xad, -0x11,0x24,0x8b,0x98,0xc0,0x81,0x7f,0x21,0xa3,0x52,0xbe,0x19,0x93,0x09,0xce,0x20, -0x10,0x46,0x4a,0x4a,0xf8,0x27,0x31,0xec,0x58,0xc7,0xe8,0x33,0x82,0xe3,0xce,0xbf, -0x85,0xf4,0xdf,0x94,0xce,0x4b,0x09,0xc1,0x94,0x56,0x8a,0xc0,0x13,0x72,0xa7,0xfc, -0x9f,0x84,0x4d,0x73,0xa3,0xca,0x9a,0x61,0x58,0x97,0xa3,0x27,0xfc,0x03,0x98,0x76, -0x23,0x1d,0xc7,0x61,0x03,0x04,0xae,0x56,0xbf,0x38,0x84,0x00,0x40,0xa7,0x0e,0xfd, -0xff,0x52,0xfe,0x03,0x6f,0x95,0x30,0xf1,0x97,0xfb,0xc0,0x85,0x60,0xd6,0x80,0x25, -0xa9,0x63,0xbe,0x03,0x01,0x4e,0x38,0xe2,0xf9,0xa2,0x34,0xff,0xbb,0x3e,0x03,0x44, -0x78,0x00,0x90,0xcb,0x88,0x11,0x3a,0x94,0x65,0xc0,0x7c,0x63,0x87,0xf0,0x3c,0xaf, -0xd6,0x25,0xe4,0x8b,0x38,0x0a,0xac,0x72,0x21,0xd4,0xf8,0x07,0x56,0xcf -}; - -static BOOL IsDsApp( GCDSlot slot ) -{ - GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); - BOOL isDsNinLogo = TRUE; - int i; - - isDsApp[slot] = FALSE; - - for ( i=0; il.nintendoLogo)[i] ) - { - isDsNinLogo = FALSE; - break; - } - } - if ( isDsNinLogo ) - { - isDsApp[slot] = TRUE; - } - - return isDsApp[slot]; -} - -/*************************************************** - - ***************************************************/ -static void SetVAE( GCDSlot slot, GCDCmd64* op ) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - op->dw |= ((u64)(sec->va) << GCDOP_N_VAE_SHIFT) & GCDOP_N_VAE_MASK; -} - -static void SetVBI( GCDSlot slot, GCDCmd64* op ) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - op->dw |= sec->vb; - sec->vb >>= GCDOP_N_VBI_SHIFT; -} - -static void SetVA( GCDSlot slot, GCDCmd64* op ) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - op->dw |= ((u64)(sec->va) << GCDOP_S_VA_SHIFT) & GCDOP_S_VA_MASK; -} - -static void SetVB( GCDSlot slot, GCDCmd64* op ) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - op->dw |= sec->vb & GCDOP_S_VB_MASK; - sec->vb++; -} - -static void SetDummyVC( GCDSlot slot, GCDCmd64* op ) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - op->dw |= ((u64)(sec->vc_dummy) << GCDOP_S_VC_SHIFT) & GCDOP_S_VC_MASK; -} - -static void SetVD( GCDSlot slot, GCDCmd64* op ) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - op->dw |= ((u64)(sec->vd) << GCDOP_S_VD_SHIFT) & GCDOP_S_VD_MASK; -} - -static void GCDi_GenVA_VB_VD( GCDSlot slot ) -{ - GCDHeader* fh = GCDi_GetRomHeaderAddr( slot ); - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - - sec->va = fh->sign.raw[0]; - sec->vb = fh->sign.raw[1]; - sec->vd = fh->sign.raw[2]; - sec->vc_dummy = fh->sign.raw[3]; - - EncryptByBlowfish(&sec->blowfishCardTable, &sec->va, &sec->vb); - EncryptByBlowfish(&sec->blowfishCardTable, &sec->vd, &sec->vc_dummy); -} - -// TWLFIRM_DSCARD_DEV - -#ifndef FIRM_FORCE_DEBUGGER - -void GCDi_InitCardOpBlowfish( GCDSlot slot ) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - const BLOWFISH_CTX *blowfishInitTablep = &GCDi_BlowfishInitTableGCDFIRM; - BLOWFISH_CTX *tableBufp = &sec->blowfishCardTable; - - MI_CpuCopyFast( (void*)blowfishInitTablep, (void *)tableBufp, sizeof(BLOWFISH_CTX) ); - InitBlowfish( tableBufp, &((u8*)GCDi_HeaderBuf[slot])[0xc], 4 ); -} - -void GCDi_InitSecureParam( GCDSlot slot, BOOL twl_ex ) -{ - GCDRomHeaderDS *rh = GCDi_GetRomHeaderAddr( slot ); - u32 code = rh->initialCode; - - if ( twl_ex ) - { - rh->initialCode = 'ALWT'; - } - -#ifdef FIRM_FORCE_FIRMBLOWFISH - GCDi_InitCardOpBlowfish( slot ); -#else // FIRM_FORCE_FIRMBLOWFISH - GCDi_InitCardOpBlowfishDS( slot ); -#endif // FIRM_FORCE_FIRMBLOWFISH - - rh->initialCode = code; - - GCDi_GenVA_VB_VD( slot ); // VA & VB & VD 初期化 -} - -void GCDi_InitPngIntf( GCDSlot slot ) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - -#define PNA_INDEX (((u32)GCDi_GetRomHeaderAddr( slot )) + 0x12) // PNAテーブル・インデックス -static u32 default_pnB_l = 0x879b9b05; -static u8 default_pnB_h = 0x5c; -static u8 default_pnA_l_1 = 0x60; -static u8 default_pnA_l_0_table[8] = { 0xe8, 0x4d, 0x5a, 0xb1, 0x17, 0x8f }; - - u32 pnA_l; - u8 pnA_h; - - pnA_l = sec->vd <<15 - | default_pnA_l_0_table[(*(vu16 *)PNA_INDEX & 0x0700) >>8] | default_pnA_l_1 <<8; - pnA_h = (u8)((sec->vd >>(32-15)) & 0x7f); - - GCDi_SetPngIntf( slot, pnA_l, pnA_h, default_pnB_l, default_pnB_h ); -} - -#endif // FIRM_FORCE_DEBUGGER - -/*************************************************** - - ***************************************************/ -static void GCDi_SetPngIntf( GCDSlot slot, u32 pnA_l, u8 pnA_h, u32 pnB_l, u8 pnB_h ) -{ - REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); - REGType32v* scra_l = GCDi_SelectRegAddr( slot, REG_MCSCRA_L_ADDR ); - REGType8v* scra_h = GCDi_SelectRegAddr( slot, REG_MCSCRA_H_ADDR ); - REGType32v* scrb_l = GCDi_SelectRegAddr( slot, REG_MCSCRB_L_ADDR ); - REGType8v* scrb_h = GCDi_SelectRegAddr( slot, REG_MCSCRB_H_ADDR ); - - // PN初期値設定 - - GCDi_WaitCtrl( slot ); - - *scra_l = pnA_l; - *scra_h = pnA_h; - - *scrb_l = pnB_l; - *scrb_h = pnB_h; - - *cnt1 = REG_MI_MCCNT1_A_SCR_MASK | REG_MI_MCCNT1_A_SE_MASK | REG_MI_MCCNT1_A_DS_MASK | REG_MI_MCCNT1_A_RESB_MASK; - - GCDi_WaitCtrl( slot ); - - // データスクランブル設定 - GCDi_Work[slot].ctrls.sSendOnlyOpRegs.scramble |= REG_MI_MCCNT1_A_SE_MASK | REG_MI_MCCNT1_A_DS_MASK; -} - - -void GCDi_DecryptObjectFile( GCDSlot slot ) -{ - if ( GCDi_IsDsApp( slot ) ) - { - } -} - -/*************************************************** - - ***************************************************/ -static void ReadCardAsync4Secure_1( GCDSlot slot, void *romp ) -{ - GCDWork *gw = &GCDi_Work[slot]; - GCDRomCtrls *ctrls = &gw->ctrls; - - if ( GCDi_SharedWork[slot].nCardID & GCD_ROMID_1TROM_MASK ) - { - // 3Dメモリ専用設定 - { - ctrls->gcdRegs->ctrl &= ~REG_MI_MCCNT1_PC_MASK; - ctrls->gcdRegs->ctrl |= GCD_PAGE_1; - } - } - ctrls->gcdOp.dw = GCDOP_S_OP_RD_SEGMENT // コマンド設定 - | (((u64)romp/GCD_SECURE_SEGMENT_SIZE) << GCDOP_S_VC_SHIFT); - - gw->oneShotSize = GCDi_GetOneShotSizeFromCtrl( ctrls->gcdRegs->ctrl ); - SetVA( slot, &ctrls->gcdOp ); - Encrypt2SetTimer4Secure( slot, ctrls ); - - if ( (GCDi_SharedWork[slot].nCardID & GCD_ROMID_1TROM_MASK) == 0 ) - { - ctrls->ltckReq = TRUE; - } -} - -/*************************************************** - - ***************************************************/ -static void ReadCardAsync4Secure_2( GCDSlot slot ) -{ - GCDWork *gw = &GCDi_Work[slot]; - GCDRomCtrls *ctrls = &gw->ctrls; - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - - /* CardTimerIntr4Secure(void)のかわり */ - s32 oneShotSize; - s32 offset; - - // セグメント境界にて - // 3Dメモリは1セグメントを8ページに分割して読む - do { - oneShotSize = gw->oneShotSize; - offset = sec->segmentOffset + sec->blockOffset; - - GCDi_ReadSecureModeRomCore( slot, gw->ramp + offset, oneShotSize, ctrls ); - - gw->restSize -= oneShotSize; - sec->blockOffset += oneShotSize; - } - while( gw->restSize % GCD_SECURE_SEGMENT_SIZE ); -} - -/*************************************************** - - ***************************************************/ -u8 GCDi_SegmentIndexTable4Secure[] = -{ - (0<<6)|(1<<4)|(3<<2)|(2<<0), (0<<6)|(2<<4)|(1<<2)|(3<<0), (0<<6)|(2<<4)|(3<<2)|(1<<0), (0<<6)|(3<<4)|(1<<2)|(2<<0), - (1<<6)|(0<<4)|(2<<2)|(3<<0), (1<<6)|(2<<4)|(0<<2)|(3<<0), (1<<6)|(3<<4)|(0<<2)|(2<<0), (1<<6)|(3<<4)|(2<<2)|(0<<0), - (2<<6)|(1<<4)|(0<<2)|(3<<0), (2<<6)|(1<<4)|(3<<2)|(0<<0), (2<<6)|(3<<4)|(0<<2)|(1<<0), (2<<6)|(3<<4)|(1<<2)|(0<<0), - (3<<6)|(0<<4)|(1<<2)|(2<<0), (3<<6)|(0<<4)|(2<<2)|(1<<0), (3<<6)|(1<<4)|(2<<2)|(0<<0), (3<<6)|(2<<4)|(0<<2)|(1<<0), -}; - -/* - DCB 4_0132, 4_0213, 4_0231, 4_0312 ; - 4_0123, 4_0321 - DCB 4_1023, 4_1203, 4_1302, 4_1320 ; - 4_1032, 4_1230 - DCB 4_2103, 4_2130, 4_2301, 4_2310 ; - 4_2013, 4_2031 - DCB 4_3012, 4_3021, 4_3120, 4_3201 ; - 4_3102, 4_3210 -*/ - -void GCDi_ReadCardSegmentAsync4Secure( GCDSlot slot, BOOL twl_ex ) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - s16 *blockOffsetp = &sec->blockOffset; - s16 *segmentOffsetp = &sec->segmentOffset; - s16 *tblShiftp = &sec->segmentTblShift; - s32 diffSegmentNo; - s32 offset; - - GCDWork *gw = &GCDi_Work[slot]; - GCDRomCtrls *ctrls = &gw->ctrls; - -// GCDi_WaitCtrl(); - - GCDi_SecureWork[slot].segmentTblp = &(((u8 *)GCDi_SegmentIndexTable4Secure)[GCDi_SecureWork[slot].vd >>28]); // セグメントテーブル設定 - GCDi_SecureWork[slot].numSecureSegment = GCD_SECURE_AREA_SIZE / GCD_SECURE_SEGMENT_SIZE; // SECUREセグメント数 1segment 4096 - - ctrls->gcdRegs = &ctrls->sReadRomRegs; - gw->romp = GCD_SECURE_AREA_OFFSET; - if ( !twl_ex ) - { - gw->ramp = (void*)GCDi_SecureAreaBuf[slot]; - } - else - { - gw->ramp = (void*)GCDi_Secure2AreaBuf[slot]; - } - gw->restSize = sizeof( GCDi_SecureAreaBuf[slot] ); - gw->oneShotSize = GCDi_GetOneShotSizeFromCtrl( ctrls->gcdRegs->ctrl ); - - sec->secureSize = gw->restSize; - - do { - // SECURE領域を超えないように調整 - while ((diffSegmentNo = ((*sec->segmentTblp) >>*tblShiftp) & 0x3) >= sec->numSecureSegment) - *tblShiftp += 2; - - *segmentOffsetp = (s16)(GCD_SECURE_SEGMENT_SIZE * diffSegmentNo); // セグメントオフセット セット - *blockOffsetp = 0; // ブロックオフセット クリア - - offset = *segmentOffsetp + *blockOffsetp; - - ReadCardAsync4Secure_1( slot, (u8*)gw->romp + offset ); - ReadCardAsync4Secure_2( slot ); - - *tblShiftp += 2; - *tblShiftp &= 0x7; - } - while( gw->restSize > 0 ); -} - - -/*---------------------------------------------------------------------------* - Name: GCD_SendOnlyCardOpCore - - Description: send only rom command - sync version - - Arguments: ctrls : rom control - - Returns: None - *---------------------------------------------------------------------------*/ - -#define AddLatency2ToLatency1(param) \ - ( (((param) & CARD_LATENCY2_CYCLES_MASK) \ - >> CARD_LATENCY2_CYCLES_SHIFT) \ - + ((param) & ~CARD_LATENCY2_CYCLES_MASK) \ - ) - - -static void Encrypt2SetTimer4Secure( GCDSlot slot, GCDRomCtrls *ctrls ) -{ - GCDSecureWork* sec = &GCDi_SecureWork[slot]; - GCDSharedWork* sh = &GCDi_SharedWork[slot]; - - SetVB( slot, &ctrls->gcdOp ); // VB セット - - //GCDi_SecureWork.paramBak = *paramp; // 暗号化前のバップアップ - // my_memcopy((void *)paramp, (void *)&(GCDi_SecureWork.paramBak),sizeof(CardCtrlParam)); // 暗号化前のバップアップ - - // コマンド暗号 - EncryptByBlowfish( &sec->blowfishCardTable, &((u32*)&ctrls->gcdOp)[1], (u32*)&ctrls->gcdOp ); - - // 3Dメモリ専用プリコマンド発行 - if ( sh->nCardID & GCD_ROMID_1TROM_MASK ) { - GCDCtrlRegs *preRegs = ctrls->gcdRegs; - ctrls->gcdRegs = &ctrls->sSendOnlyOpRegs; - GCD_SendOnlyCardOpCore( slot, ctrls ); - ctrls->gcdRegs = preRegs; - - OS_SpinWait( OS_MSEC_TO_CPUCYC(30) ); /* wait 27 milli sec. for 3D-MEMROY? */ - } -} - - -static void GCDi_SendOnlyCardSecureOpCore( GCDSlot slot, GCDRomCtrls *ctrls ) -{ - GCDCtrlRegs *regs = ctrls->gcdRegs; - - // レイテンシ2をレイテンシ1へ加算 -#if 0 - paramp->cardCnt = AddLatency2ToLatency1(GetCardCnt4Secure()) - | CARD_READ_MODE | CARD_0_PAGE - | CARD_START | CARD_RESET_HI; -#endif - - SetDummyVC( slot, &ctrls->gcdOp ); - Encrypt2SetTimer4Secure( slot, ctrls ); - - if ( (GCDi_SharedWork[slot].nCardID & GCD_ROMID_1TROM_MASK) == 0 ) { - ctrls->gcdRegs->ctrl |= GCD_LTCK_ENABLE; // マスクROM専用設定: レイテンシ期間にクロック供給 -// ctrls->ltckReq = TRUE; - } - GCD_SendOnlyCardOpCore( slot, ctrls ); -} - - -/*************************************************** - - ***************************************************/ -void GCDi_ChangeIntoSecureMode( GCDSlot slot ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - - ctrls->gcdRegs = &ctrls->nSendOnlyOpRegs; - ctrls->gcdOp.dw = GCDOP_N_OP_CHG_MODE; // コマンド設定 - SetVAE( slot, &ctrls->gcdOp ); - SetVBI( slot, &ctrls->gcdOp ); - - GCD_SendOnlyCardOpCore( slot, ctrls ); -} - -void GCDi_ChangeIntoSecure2Mode( GCDSlot slot ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - - ctrls->gcdRegs = &ctrls->nSendOnlyOpRegs; - ctrls->gcdOp.dw = GCDOP_N_OP_CHG2_MODE; // コマンド設定 - SetVAE( slot, &ctrls->gcdOp ); - SetVBI( slot, &ctrls->gcdOp ); - - GCD_SendOnlyCardOpCore( slot, ctrls ); -} - - -void GCDi_SendPngON( GCDSlot slot ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - - ctrls->gcdRegs = &ctrls->sSendOnlyOpRegs; - ctrls->gcdOp.dw = GCDOP_S_OP_PNG_ON; // コマンド設定 - SetVD( slot, &ctrls->gcdOp ); - - GCDi_SendOnlyCardSecureOpCore( slot, ctrls ); -} - -void GCDi_SendPngOFF( GCDSlot slot ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - - ctrls->gcdRegs = &ctrls->sSendOnlyOpRegs; - ctrls->gcdOp.dw = GCDOP_S_OP_PNG_OFF; // コマンド設定 - SetVA( slot, &ctrls->gcdOp ); - - GCDi_SendOnlyCardSecureOpCore( slot, ctrls ); -} - -void GCDi_ChangeIntoGameMode( GCDSlot slot ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - - ctrls->gcdRegs = &ctrls->sSendOnlyOpRegs; - ctrls->gcdOp.dw = GCDOP_S_OP_CHG_MODE; // コマンド設定 - SetVA( slot, &ctrls->gcdOp ); - - GCDi_SendOnlyCardSecureOpCore( slot, ctrls ); -} - -/*---------------------------------------------------------------------------* - Name: GCD_SendOnlyCardNormalOpCore - - Description: send only rom command - sync version - - Arguments: ctrls : rom control - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCD_SendOnlyCardNormalOpCore( GCDSlot slot, GCDRomCtrls *ctrls ) -{ - ctrls->gcdRegs = &ctrls->nSendOnlyOpRegs; - - GCD_SendOnlyCardOpCore( slot, ctrls ); -} - -/*---------------------------------------------------------------------------* - Name: GCD_SendOnlyCardSecureOpCore - - Description: send only rom command - sync version - - Arguments: ctrls : rom control - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCD_SendOnlyCardSecureOpCore( GCDSlot slot, GCDRomCtrls *ctrls ) -{ - ctrls->gcdRegs = &ctrls->sSendOnlyOpRegs; - - if ( ctrls->ltckReq ) - { - ctrls->gcdRegs->ctrl |= GCD_LTCK_ENABLE; // マスクROM専用設定: レイテンシ期間にクロック供給 - ctrls->ltckReq = FALSE; - } - - GCD_SendOnlyCardOpCore( slot, ctrls ); -} - -/*************************************************** - - ***************************************************/ -static u32 GCDi_ReadSecureModeIDCore( GCDSlot slot, GCDRomCtrls *ctrls ) -{ - ctrls->gcdRegs = &ctrls->sIDRegs; - - if ( ctrls->ltckReq ) - { - ctrls->gcdRegs->ctrl |= GCD_LTCK_ENABLE; // マスクROM専用設定: レイテンシ期間にクロック供給 - ctrls->ltckReq = FALSE; - } - - return GCDi_ReadRomIDCore( slot, ctrls ); -} - -static void GCDi_ReadSecureModeRomCore( GCDSlot slot, void *ramp, s32 size, GCDRomCtrls *ctrls ) -{ - ctrls->gcdRegs = &ctrls->sReadRomRegs; - - if ( ctrls->ltckReq ) - { - ctrls->gcdRegs->ctrl |= GCD_LTCK_ENABLE; // マスクROM専用設定: レイテンシ期間にクロック供給 - ctrls->ltckReq = FALSE; - } - - GCDi_ReadRomCore( slot, ramp, size, ctrls ); -} - - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadSecureModeID - - Description: read rom ID on secure mode - sync version - - Arguments: None - - Returns: rom ID - *---------------------------------------------------------------------------*/ -u32 GCDi_ReadSecureModeID( GCDSlot slot ) -{ - GCDSharedWork* sh = &GCDi_SharedWork[slot]; - - if ( GCDi_IsSecureInitialized( slot ) == FALSE ) - { - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - - ctrls->gcdRegs = &ctrls->sIDRegs; - ctrls->gcdOp.dw = GCDOP_S_OP_RD_ROM_ID; // コマンド設定 - SetVA( slot, &ctrls->gcdOp ); - SetDummyVC( slot, &ctrls->gcdOp ); - Encrypt2SetTimer4Secure( slot, ctrls ); - - if ( (sh->nCardID & GCD_ROMID_1TROM_MASK) == 0 ) { - ctrls->ltckReq = TRUE; - } - sh->sCardID = GCDi_ReadSecureModeIDCore( slot, ctrls ); - DBG_PRINTF("%s %d CardID Secure 0x%08x\n",__FUNCTION__,__LINE__, sh->sCardID); - } - - return sh->sCardID; -} - -/*---------------------------------------------------------------------------* - Name: GCD_ReadNormalModeID - - Description: read rom ID on normal mode - sync version - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -u32 GCD_ReadNormalModeID( GCDSlot slot ) -{ - GCDSharedWork* sh = &GCDi_SharedWork[slot]; - - if ( GCDi_IsSecureInitialized( slot ) == FALSE ) - { - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - - ctrls->gcdRegs = &ctrls->nIDRegs; - ctrls->gcdOp.dw = GCDOP_N_OP_RD_ROM_ID; // コマンド設定 - - return GCDi_ReadRomIDCore( slot, ctrls ); - } else { - return sh->nCardID; - } -} - - -/*---------------------------------------------------------------------------* - Name: GCDi_LoadHeader - - Description: load header - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCDi_LoadHeader( GCDSlot slot ) -{ - if ( GCDi_IsSecureInitialized( slot ) == FALSE ) - { - GCDSharedWork* sh = &GCDi_SharedWork[slot]; - - // load table from dev flash into ASIC - GCDi_LoadTable( slot ); - - // read ROM header - GCD_ReadNormalModeRom( slot, 0, GCDi_HeaderBuf[slot], sizeof( GCDi_HeaderBuf[slot] ) ); - - if ( ! IsDsApp( slot ) ) - { - MI_CpuFillFast( GCDi_HeaderBuf[slot], 0, sizeof( GCDi_HeaderBuf[slot] ) ); - } - - // read ROM-ID - sh->nCardID = GCD_ReadNormalModeID( slot ); - DBG_PRINTF("%s %d CardID Normal 0x%08x\n",__FUNCTION__,__LINE__, sh->nCardID); - } -} - -/*---------------------------------------------------------------------------* - Name: GCDi_LoadHeaderAll - - Description: load header - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCDi_LoadHeaderAll( void ) -{ - GCDSlot slot, start, end; - - GCDi_GetExistingSlots( &start, &end ); - - if ( GCDi_IsSecureInitialized( GCD_PRIMARY_SLOT ) == FALSE ) - { - for (slot=start; slot<=end; slot++) - { - // load table from dev flash into ASIC - GCDi_LoadTableAsync( slot ); - } - - for (slot=start; slot<=end; slot++) - { - GCD_WaitRomAsync( slot ); - - // read short ROM header - GCDi_ReadShortHeaderAsync( slot, GCDi_HeaderBuf[slot] ); - } - - for (slot=start; slot<=end; slot++) - { - GCD_WaitRomAsync( slot ); - - if ( ! IsDsApp( slot ) ) - { - MI_CpuFillFast( GCDi_HeaderBuf[slot], 0, sizeof( GCDi_HeaderBuf[slot] ) ); - } - } - - for (slot=start; slot<=end; slot++) - { - // read ROM-ID - GCDSharedWork* sh = &GCDi_SharedWork[slot]; - sh->nCardID = GCD_ReadNormalModeID( slot ); - DBG_PRINTF("%s %d CardID Normal 0x%08x\n",__FUNCTION__,__LINE__, sh->nCardID); - - // read ROM header - GCD_ReadNormalModeRomAsync( slot, 0, GCDi_HeaderBuf[slot], sizeof( GCDi_HeaderBuf[slot] ) ); - } - - for (slot=start; slot<=end; slot++) - { - GCD_WaitRomAsync( slot ); - } - } -} - -/*---------------------------------------------------------------------------* - Name: GCDi_LoadTable - - Description: load table from dev flash into ASIC - sync version - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCDi_LoadTable( GCDSlot slot ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - - ctrls->gcdRegs = &ctrls->nLoadTableRegs; - ctrls->gcdOp.dw = GCDOP_N_OP_LD_TABLE; - - GCDi_ReadRomCore( slot, NULL, 0, ctrls ); -} - -static void GCDi_LoadTableCore( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ) -{ -#pragma unused( romp ) - - GCDi_ReadRomCore( slot, ramp, size, ctrls ); -} - -static void GCDi_LoadTableAsync( GCDSlot slot ) -{ - GCDWork *gw = &GCDi_Work[slot]; - GCDRomCtrls *ctrls = &gw->ctrls; - - ctrls->gcdRegs = &ctrls->nLoadTableRegs; - ctrls->gcdOp.dw = GCDOP_N_OP_LD_TABLE; - - gw->funcp = GCDi_LoadTableCore; - - GCD_SetInterrupt( slot, 0, GCDi_Secure2AreaBuf[slot], GCD_LOAD_TABLE_SIZE, gw ); - - gw->funcp( slot, gw->romp, gw->ramp, gw->oneShotSize, ctrls ); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadShortHeader - - Description: load table from dev flash into ASIC - sync version - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCDi_ReadShortHeader( GCDSlot slot, void *ramp ) -{ - GCDRomCtrls *ctrls = &GCDi_Work[slot].ctrls; - - ctrls->gcdRegs = &ctrls->nReadShortHeaderRegs; - - GCDi_ReadNormalModeRomCore( slot, 0, ramp, GCD_ROM_PAGE_SIZE, ctrls ); -} - -static void GCDi_ReadShortHeaderAsync( GCDSlot slot, void *ramp ) -{ - GCDWork *gw = &GCDi_Work[slot]; - GCDRomCtrls *ctrls = &gw->ctrls; - - ctrls->gcdRegs = &ctrls->nReadShortHeaderRegs; - - gw->funcp = GCDi_ReadNormalModeRomCore; - - GCD_SetInterrupt( slot, 0, ramp, GCD_ROM_PAGE_SIZE, gw ); - - gw->funcp( slot, gw->romp, gw->ramp, gw->oneShotSize, ctrls ); -} - -/*---------------------------------------------------------------------------* - Name: GCDi_LoadSecure - - Description: load secure area - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static void GCDi_LoadSecureCore( GCDSlot slot, BOOL twl_ex ) -{ - if ( GCDi_IsSecureInitialized( slot ) == FALSE ) - { - GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); - -#ifndef FIRM_FORCE_DEBUGGER - - GCDi_InitSecureParam( slot, twl_ex ); - -#endif // FIRM_FORCE_DEBUGGER - - if ( !twl_ex ) - { - GCDi_ChangeIntoSecureMode( slot ); - } - else - { - GCDi_ChangeIntoSecure2Mode( slot ); - } - -#ifdef FIRM_FORCE_DEBUGGER - - if ( !twl_ex ) - { - GCD_ReadNormalModeRom( slot, GCD_SECURE_AREA_OFFSET, GCDi_SecureAreaBuf[slot], sizeof( GCDi_SecureAreaBuf[slot] ) ); - } - else if ( rh->l.twlAreaOffset ) - { - GCD_ReadNormalModeRom( slot, (u32)rh->l.twlAreaOffset * GCD_TWL_AREA_ALIGN + GCD_SECURE2_AREA_OFFSET, - GCDi_Secure2AreaBuf[slot], sizeof( GCDi_Secure2AreaBuf[slot] ) ); - } - -#else // FIRM_FORCE_DEBUGGER - - GCDi_SendPngON( slot ); - GCDi_InitPngIntf( slot ); - - GCDi_ReadSecureModeID( slot ); - - GCDi_ReadCardSegmentAsync4Secure( slot, twl_ex ); - -#ifndef GCD_ENABLE_SCRAMBLE - GCDi_SendPngOFF( slot ); -#endif // GCD_ENABLE_SCRAMBLE - -#endif // FIRM_FORCE_DEBUGGER - - GCDi_ChangeIntoGameMode( slot ); - - // 暗号化オブジェクトの復号 - if ( !twl_ex ) - { -#ifndef FIRM_FORCE_FIRMBLOWFISH - GCDi_DecryptObjectFileDS( slot ); -#endif // FIRM_FORCE_FIRMBLOWFISH - } - - if ( twl_ex || !rh->l.twlAreaOffset ) - { - GCDi_SecureInitialized[slot] = TRUE; - } - } -} - -static void GCDi_LoadSecure( GCDSlot slot ) -{ - GCDi_LoadSecureCore( slot, FALSE ); - -} - -static void GCDi_LoadSecure2( GCDSlot slot ) -{ - GCDi_LoadSecureCore( slot, TRUE ); - -} - -static void GCDi_LoadSecureAllCore( BOOL twl_ex ) -{ - GCDSlot slot, start, end; - - GCDi_GetExistingSlots( &start, &end ); - - if ( GCDi_IsSecureInitialized( GCD_PRIMARY_SLOT ) == FALSE ) - { - -#ifndef FIRM_FORCE_DEBUGGER - - for (slot=start; slot<=end; slot++) - { - GCDi_InitSecureParam( slot, twl_ex ); - } - -#endif // FIRM_FORCE_DEBUGGER - - if ( !twl_ex ) - { - for (slot=start; slot<=end; slot++) - { - GCDi_ChangeIntoSecureMode( slot ); - } - } - else - { - for (slot=start; slot<=end; slot++) - { - GCDi_ChangeIntoSecure2Mode( slot ); - } - } - -#ifdef FIRM_FORCE_DEBUGGER - - for (slot=start; slot<=end; slot++) - { - GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); - GCD_ReadNormalModeRomAsync( slot, GCD_SECURE_AREA_OFFSET, GCDi_SecureAreaBuf[slot], sizeof( GCDi_SecureAreaBuf[slot] ) ); - } - - for (slot=start; slot<=end; slot++) - { - GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); - GCD_WaitRomAsync( slot ); - - if ( rh->l.twlAreaOffset ) - { - GCD_ReadNormalModeRomAsync( slot, (u32)rh->l.twlAreaOffset * GCD_TWL_AREA_ALIGN + GCD_SECURE2_AREA_OFFSET, - GCDi_Secure2AreaBuf[slot], sizeof( GCDi_Secure2AreaBuf[slot] ) ); - } - } - - for (slot=start; slot<=end; slot++) - { - GCD_WaitRomAsync( slot ); - } - -#else // FIRM_FORCE_DEBUGGER - - for (slot=start; slot<=end; slot++) - { - GCDi_SendPngON( slot ); - } - - for (slot=start; slot<=end; slot++) - { - GCDi_InitPngIntf( slot ); - } - - for (slot=start; slot<=end; slot++) - { - GCDi_ReadSecureModeID( slot ); - } - - for (slot=start; slot<=end; slot++) - { - GCDi_ReadCardSegmentAsync4Secure( slot, twl_ex ); - } - -#ifndef GCD_ENABLE_SCRAMBLE - for (slot=start; slot<=end; slot++) - { - GCDi_SendPngOFF( slot ); - } -#endif // GCD_ENABLE_SCRAMBLE - -#endif // FIRM_FORCE_DEBUGGER - - for (slot=start; slot<=end; slot++) - { - GCDi_ChangeIntoGameMode( slot ); - } - - // 暗号化オブジェクトの復号 - for (slot=start; slot<=end; slot++) - { - GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); - - if ( !twl_ex ) - { -#ifndef FIRM_FORCE_FIRMBLOWFISH - GCDi_DecryptObjectFileDS( slot ); -#endif // FIRM_FORCE_FIRMBLOWFISH - } - - if ( twl_ex || !rh->l.twlAreaOffset ) - { - GCDi_SecureInitialized[slot] = TRUE; - } - } - } -} - -static void GCDi_LoadSecureAll( void ) -{ - GCDi_LoadSecureAllCore( FALSE ); - -} - -static void GCDi_LoadSecure2All( void ) -{ - GCDi_LoadSecureAllCore( TRUE ); - -} - -// -BOOL GCDi_IsSecureInitialized( GCDSlot slot ) -{ - return GCDi_SecureInitialized[slot]; -} - diff --git a/build/libraries/gcd/ARM7/Makefile b/build/libraries/nvram/ARM7/Makefile similarity index 81% rename from build/libraries/gcd/ARM7/Makefile rename to build/libraries/nvram/ARM7/Makefile index fc529123..0677f004 100644 --- a/build/libraries/gcd/ARM7/Makefile +++ b/build/libraries/nvram/ARM7/Makefile @@ -1,9 +1,9 @@ #! make -f #---------------------------------------------------------------------------- -# Project: TwlIPL +# Project: TwlSDK - libraries - spi # File: Makefile # -# Copyright 2007 Nintendo. All rights reserved. +# Copyright 2003 Nintendo. All rights reserved. # # These coded instructions, statements, and computer programs contain # proprietary information of Nintendo of America Inc. and/or Nintendo @@ -27,14 +27,11 @@ TWL_PROC = ARM7 SRCDIR = . ../common SRCS = \ - gcd.c \ - gcd_init.c \ - blowfish.c \ - ds_blowfish.c \ - ds_blowfish_table.c \ + nvram_misc.c \ -TARGET_LIB = libgcd_sp$(FIRM_LIBSUFFIX).a +TARGET_LIB = libnvram_sp$(FIRM_LIBSUFFIX).a INCDIR = ../include +LINCLUDES = $(ROOT)/build/libraries/spi/ARM7/include ../common/include #---------------------------------------------------------------------------- diff --git a/build/libraries/nvram/ARM7/nvram_misc.c b/build/libraries/nvram/ARM7/nvram_misc.c new file mode 100644 index 00000000..2141bc63 --- /dev/null +++ b/build/libraries/nvram/ARM7/nvram_misc.c @@ -0,0 +1,180 @@ +/*---------------------------------------------------------------------------* + Project: TwlBromSDK - libraries - + File: nvram_misc.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#include +#include "spi_sp.h" +#include "nvram_sp.h" + +/*---------------------------------------------------------------------------* + Name: NvramCheckReadyToRead + + Description: NVRAMを読み出し可能な状態かどうか確認する。 + + Arguments: None. + + Returns: BOOL - 読み出し可能な状態の場合にTRUEを返す。 + FALSEの場合は読み出し禁止の状態。 + *---------------------------------------------------------------------------*/ +static BOOL NvramCheckReadyToRead(void) +{ + u16 tempStatus; + + // ステータスレジスタ読み出し + NVRAM_ReadStatusRegister((u8 *)(&tempStatus)); + // 書き込みもしくは消去操作中かを確認 + if (tempStatus & NVRAM_STATUS_REGISTER_WIP) + { + return FALSE; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: NvramCheckReadyToWrite + + Description: NVRAMを書き込み可能な状態かどうか確認する。 + + Arguments: None. + + Returns: BOOL - 書き込み可能な状態の場合にTRUEを返す。 + FALSEの場合は書き込み禁止の状態。 + *---------------------------------------------------------------------------*/ +static BOOL NvramCheckReadyToWrite(void) +{ + u16 tempStatus; + + // ステータスレジスタ読み出し + NVRAM_ReadStatusRegister((u8 *)(&tempStatus)); + // 書き込みもしくは消去操作中かを確認 + if (tempStatus & NVRAM_STATUS_REGISTER_WIP) + { + return FALSE; + } + // 書き込み許可されているかを確認 + if (!(tempStatus & NVRAM_STATUS_REGISTER_WEL)) + { + return FALSE; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: NVRAM_WaitOperation + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void NVRAM_WaitOperation(void) +{ + while( NvramCheckReadyToRead() == FALSE ) { + } +} + +/*---------------------------------------------------------------------------* + Name: NVRAM_WaitWriteEnable + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void NVRAM_WaitWriteEnable(void) +{ + while( NvramCheckReadyToWrite() == FALSE ) { + } +} + + +/*---------------------------------------------------------------------------* + Name: NVRAMi_Read + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void NVRAMi_Read(u32 address, void *buf, u32 size) +{ + NVRAM_WaitOperation(); + NVRAM_ReadDataBytes(address, size, buf); + return; +} + + +/*---------------------------------------------------------------------------* + Name: NVRAMi_Write + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void NVRAMi_Write(u32 address, void *buf, u32 size) +{ + u32 i; + u32 page_start; + u32 page_end; + u32 offset_start; + u32 offset_end; + u8 *src_ptr; + u8 temp_buffer[SPI_NVRAM_PAGE_SIZE]; + + src_ptr = (u8 *)buf; + page_start = (address / SPI_NVRAM_PAGE_SIZE) * SPI_NVRAM_PAGE_SIZE; + page_end = ((address+size-1) / SPI_NVRAM_PAGE_SIZE ) * SPI_NVRAM_PAGE_SIZE; + offset_start = address % SPI_NVRAM_PAGE_SIZE; + offset_end = (address+size-1) % SPI_NVRAM_PAGE_SIZE; + + while( page_start <= page_end ) { + if( offset_start != 0 ) { + NVRAMi_Read(page_start, temp_buffer, offset_start); + } + if( page_start != page_end ) { + for( i = offset_start ; i < SPI_NVRAM_PAGE_SIZE ; i++ ) { + temp_buffer[i] = *src_ptr++; + } + } + else { + for( i = offset_start ; i <= offset_end ; i++ ) { + temp_buffer[i] = *src_ptr++; + } + if( offset_end != (SPI_NVRAM_PAGE_SIZE-1) ) { + NVRAMi_Read(page_start+offset_end+1, &(temp_buffer[offset_end+1]), SPI_NVRAM_PAGE_SIZE - (offset_end+1) ); + } + } + + NVRAM_WriteEnable(); + NVRAM_WaitWriteEnable(); + + NVRAM_PageErase((u32)page_start); + + NVRAM_WaitOperation(); + + NVRAM_WriteEnable(); + + NVRAM_PageWrite((u32)page_start, (u16)SPI_NVRAM_PAGE_SIZE, temp_buffer); + NVRAM_WaitOperation(); + + page_start += SPI_NVRAM_PAGE_SIZE; + offset_start = 0; + } +} diff --git a/build/libraries/gcd/Makefile b/build/libraries/nvram/Makefile similarity index 80% rename from build/libraries/gcd/Makefile rename to build/libraries/nvram/Makefile index bae95ea7..f7829b79 100644 --- a/build/libraries/gcd/Makefile +++ b/build/libraries/nvram/Makefile @@ -1,9 +1,9 @@ #! make -f #---------------------------------------------------------------------------- -# Project: TwlFirm - libraries - gcd +# Project: TwlIPL - libraries - nvram # File: Makefile # -# Copyright 2007 Nintendo. All rights reserved. +# Copyright 2008 Nintendo. All rights reserved. # # These coded instructions, statements, and computer programs contain # proprietary information of Nintendo of America Inc. and/or Nintendo @@ -11,8 +11,9 @@ # not be disclosed to third parties or copied or duplicated in any form, # in whole or in part, without the prior written consent of Nintendo. # -# $Log: $ -# $NoKeywords: $ +# $Date:: $ +# $Rev$ +# $Author$ #---------------------------------------------------------------------------- include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs @@ -20,11 +21,7 @@ include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs #---------------------------------------------------------------------------- -SUBDIRS = ARM9 - -#ifdef TWL_WITH_ARM7 -SUBDIRS += ARM7 -#endif +SUBDIRS = ARM7 #---------------------------------------------------------------------------- diff --git a/include/firm.h b/include/firm.h index c2005e7a..ee845021 100644 --- a/include/firm.h +++ b/include/firm.h @@ -27,6 +27,7 @@ #include #include #include +#include /* FIRM_H_ */ #endif diff --git a/include/firm/gcd.h b/include/firm/gcd.h deleted file mode 100644 index 26593c55..00000000 --- a/include/firm/gcd.h +++ /dev/null @@ -1,26 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlFirm - GCD - File: gcd.h - - Copyright 2007 Nintendo. All rights reserved. - - These coded instructions, statements, and computer programs contain - proprietary information of Nintendo of America Inc. and/or Nintendo - Company Ltd., and are protected by Federal copyright law. They may - not be disclosed to third parties or copied or duplicated in any form, - in whole or in part, without the prior written consent of Nintendo. - - $Date:: 2007-09-06$ - $Rev$ - $Author$ - *---------------------------------------------------------------------------*/ - -#ifndef FIRM_GCD_H_ -#define FIRM_GCD_H_ - -//#include -#include -#include - -/* FIRM_GCD_H_ */ -#endif diff --git a/include/firm/gcd/gcd.h b/include/firm/gcd/gcd.h deleted file mode 100644 index c9106759..00000000 --- a/include/firm/gcd/gcd.h +++ /dev/null @@ -1,779 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlFirm - GCD - include - File: gcd.h - - Copyright 2007 Nintendo. All rights reserved. - - These coded instructions, statements, and computer programs contain - proprietary information of Nintendo of America Inc. and/or Nintendo - Company Ltd., and are protected by Federal copyright law. They may - not be disclosed to third parties or copied or duplicated in any form, - in whole or in part, without the prior written consent of Nintendo. - - $Date:: 2007-09-06$ - $Rev$ - $Author$ - *---------------------------------------------------------------------------*/ - -#ifndef FIRM_GCD_GCD_H_ -#define FIRM_GCD_GCD_H_ - -#include -#include -#include -#include -#include -#include - - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum -{ - GCD_PRIMARY_SLOT = 0, - GCD_SECONDARY_SLOT = 1, - - GCD_NO_SLOT = -1 -} -GCDSlot; - - -/*****************/ - -/* ROMヘッダ・ブートパラメータ構造体 */ -typedef struct { - u8 *romAddr; // ROMアドレス - u8 *entryAddr; // エントリアドレス - u8 *ramAddr; // RAMアドレス - s32 romSize; // ROMサイズ -} GCDBootUsrParam; - -// カードアクセス・コントロールレジスタ構造体 -typedef struct { - u16 latency1:13; // レイテンシ1のサイクル数 - u16 dataScramble_on:1; // データスクランブル ON - u16 scrambleUnit_on:1; // スクランブル回路 ON - u16 initScramblePN:1; // スクランブルPNデータ初期化 - u16 latency2:6; // レイテンシ2のサイクル数 - u16 cmdScramble_on:1; // コマンドスクランブル ON - u16 dataReady:1; // データ レディ - u16 pages:3; // ページ数 - u16 clockType:1; // クロックタイプ(150ns/240ns) - u16 clockInLatency:1; // レイテンシ期間にクロック供給 - u16 reset:1; // リセット信号 - u16 accessMode:1; // アクセスモード - u16 start:1; // スタート -} GCDCardCnt; - -// カードコントロール・パラメータ構造体 -typedef struct { - // u32 dmaNo; // DMA番号 - u32 cardCnt; // カードコントロール - u32 op[2]; // コマンド -} GCDCardCtrlParam; - - -/* ROMヘッダ構造体 */ -typedef struct { - s8 titleName[12]; // ソフトタイトル名 - u32 initialCode; // イニシャルコード - - u16 makerCode; // メーカーコード - u8 machineCode; // 本体コード - u8 deviceType; // デバイスタイプ - - u8 nonVerReserved[4]; // 予約(4バイト) - u8 verDepReserved[4]; // 予約(バージョン依存、4バイト) - u16 wirelessSerialNo; - u16 softVersion:8; // ソフトバージョン - u16 compArm9BootArea:1; // ARM9ブートエリア圧縮フラグ - u16 compArm7BootArea:1; // ARM7ブートエリア圧縮フラグ - u16 :0; - - GCDBootUsrParam arm9; // ARM9ブート領域パラメータ - GCDBootUsrParam arm7; // ARM7ブート領域パラメータ - - u32 fileSysReserved[8]; // ファイルシステム予約(32バイト) - - GCDCardCnt romCtrl4Game; // ROMコントロール情報(NORMAL & GAMEモード) - GCDCardCnt romCtrl4Secure; // (SECUREモード) - u8 romCtrlReserved_l[4]; // 予約 - u16 secureCRC16; // セキュア領域CRC16bit - u16 romTimerLatency; // タイマーレイテンシ((サイクル数/256) - 2、3Dメモリ用) - u8 romReserved_h[8]; // 予約 - u32 romNormalModeKey[2]; // NORMALモード判定キー - - u8 reserved_80h[0x10]; // 予約領域(16バイト) - - u16 normalAreaOffset; // NORMAL領域 - u16 twlAreaOffset; // TWL専用領域 - - u8 reserved_94h[0x2c]; // 予約領域(44バイト) - - u16 nintendoLogo[0x9c/2]; // NINTENDOロゴ(156バイト) - u16 ninLogoCRC16; // NINTENDOロゴCRC16 - u16 headerCRC16; // ヘッダCRC16 - - u8 *dbgRomAddr; // デバッガモニタROMアドレス - s32 dbgRomSize; // デバッガモニタROMサイズ - u8 *dbgArm9RamAddr; // デバッガモニタARM9-RAMアドレス - u8 *dbgArm7RamAddr; // デバッガモニタARM7-RAMアドレス - - u8 reserved_170h[0x10]; // 予約領域(16バイト) -} -GCDRomHeaderDS; - -typedef struct { - // DS互換 - GCDRomHeaderDS l; - - // TWL拡張 - MIHeader_WramRegs w; - - u8 reserved_1b0h[0x10]; // 予約領域(16バイト) - - GCDBootUsrParam arm9ex; // ARM9拡張ブート領域パラメータ - GCDBootUsrParam arm7ex; // ARM7拡張ブート領域パラメータ - - u8 reserved_1e0h[0x1000 - 0x1e0 - 0x200]; // 予約領域 - - u8 acsign_contents[0x180]; // コンテンツ証明書 - - u8 acsign_header[0x80]; // ROMヘッダ電子署名 -} -GCDRomHeader; - - -/* セキュアワーク構造体 */ -typedef struct { - u8 recvRtcBuf[8]; // RTCデータ受信バッファ(要4バイト境界) -#if 0 - u16 flashCrc16; // フラッシュメモリCRC16 - u16 flashCount; // フラッシュメモリ 8バイトカウント - u32 flashBuf[2]; // フラッシュメモリ受信バッファ(要4バイト境界) - u32 flashKeyBuf[3]; // フラッシュメモリキー・テンポラリバッファ -#endif - u32 unScrambleKey[2]; // スクランブル解除キー(8バイト、MakeBlowfishTable() で算出) - s16 isGenUnScrambleKey; // スクランブル解除キー生成完了(MakeBlowfishTable() で設定) - - u32 va; // 下位24bit(24bit送信) - u32 vb; // 中間20bit(+未定義4bit、VBI: 32bit送信) - u32 vc_dummy; // 下位16bit(16bit送信) - u32 vd; // 下位24bit(24bit送信) - - GCDCardCnt cardCntBak4Secure; // SECUREコマンドパラメータ・バックアップ - s16 enableReadSecure; // SECURE領域リード・イネーブル(LoadSecure4Card() で設定) - u32 cardNormalModeKey[2]; // NORMALモード判定キー(MakeBlowfishTable() で算出) - u32 cardKeyBuf[3]; // カードキー・テンポラリバッファ - s32 secureSize; // SECURE領域サイズ - s16 sequenceNo4Secure; // シーケンス番号(SECURE用) - s16 segmentTblShift; // セグメント番号テーブルシフト値(SECURE用) - u8 *segmentTblp; // セグメントテーブルポインタ(SECURE用) - s16 numSecureSegment; // SECUREセグメント数(SECURE用) - s16 segmentOffset; // セグメントオフセット(SECURE用) - s16 blockOffset; // ブロックオフセット(SECURE用) - - // CardCtrlParam paramBak; // カードパラメータ 暗号化前バックアップ(SECURE用) - - BLOWFISH_CTX blowfishCardTable; // カード用Blowfishテーブル - BLOWFISH_CTX blowfishFlashTable; - - u8 bufEnd[4]; // セキュアワーク最終データ -} GCDSecureWork; - - -/* 共有ワーク構造体 */ -typedef struct { - u32 nCardID; // NORMALカードID(LoadCardHeader() で取得) - u32 sCardID; // SECUREカードID(CardTimerIntr4Secure() で取得) - u16 cardHeaderCrc16; // カードヘッダCRC16(LoadCardHeader() で算出) - u16 cardSecureCrc16; // カードSECURE領域CRC16(LoadSecure4Card() で算出) - s16 cardHeaderError; // カードヘッダエラー(CheckCardHeader() で設定) - s16 disableEncryptedCardData;// カードSECURE領域暗号化データ無効(DecryptObjectFile() で設定) - s16 cardSequenceNo; // カード読み込みシーケンス番号 - s16 enableCardNormalOnly; // カードNORMALモードのみ有効(LoadFlashDemo() で設定) - - // s16 isOnDebugger; // デバッガ上で動作中か - // s16 rtcError; // RTCエラー - - u32 recvRtc[2]; // RTCステータス1&タイマーデータ(要4バイト境界) - -} GCDSharedWork; - - -typedef union -{ - u64 dw; - u8 b[8]; -} -GCDCmd64; - -typedef struct -{ - u32 ctrl; - s32 cmdcount; - u32 latency; - u32 scramble; - u8 master; - u8 spi; - GCDSlot slot; -} -GCDCtrlRegs; - -typedef struct -{ - GCDCmd64 gcdOp; - u32 dmaNo; - u32 lastDmaNo; - BOOL ltckReq; - GCDCtrlRegs *gcdRegs; - GCDCtrlRegs nLoadTableRegs; - GCDCtrlRegs nSendOnlyOpRegs; - GCDCtrlRegs sSendOnlyOpRegs; - GCDCtrlRegs nIDRegs; - GCDCtrlRegs sIDRegs; - GCDCtrlRegs gIDRegs; - GCDCtrlRegs nReadShortHeaderRegs; - GCDCtrlRegs nReadRomRegs; - GCDCtrlRegs sReadRomRegs; - GCDCtrlRegs gReadRomRegs; - GCDCtrlRegs gWriteRomRegs; -} -GCDRomCtrls; - -typedef void (* GCDRomFuncp)( u32 romp, void *ramp, s32 size ); -typedef void (* GCDAsyncCoreFuncp)( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ); - - -typedef struct -{ - u32 romp; // ROM offset - u8 *ramp; // RAM address - s32 restSize; // rest size - s32 oneShotSize; // one shot size - vs8 intrDone; - s8 isAsync; - volatile BOOL isPxiDone; - GCDRomCtrls ctrls; - GCDAsyncCoreFuncp funcp; -} -GCDWork; - - -#define GCD_DEFAULT_DMA_A_NO 7 -#define GCD_DEFAULT_DMA_B_NO 6 - -#define GCD_CHATTERING_CYCLES 0x200U - -#define GCD_ROM_PAGE_SIZE 0x200 // 512B -#define GCD_SECURE_SEGMENT_SIZE 0x1000 // 4KB -#define GCD_LOAD_TABLE_SIZE 0x2000 // 8KB - -#define GCD_NML_AREA_ALIGN 0x80000 // 512KB -#define GCD_TWL_AREA_ALIGN 0x80000 // 512KB -#define GCD_SECURE2_AREA_SIZE 0x4000 // 16KB -#define GCD_SECURE2_AREA_OFFSET 0x3000 // 12KB -#define GCD_GAME2_AREA_OFFSET 0x7000 // 28KB - - -// ROM area - -#define GCD_LOAD_TABLE_SIZE 0x2000 // 8KB -#define GCD_DS_ROM_HEADER_SIZE 0x200 // 512B -#define GCD_ROM_HEADER_SIZE 0x1000 // 4KB -#define GCD_SECURE_AREA_SIZE 0x4000 // 16KB - -#define GCD_SECURE_AREA_OFFSET 0x4000 -#define GCD_GAME_AREA_OFFSET 0x8000 - - -// ROM command - -#define GCDOP_BIT_NUM 64 - -// NORMAL mode - -#define GCDOP_N_OP_MASK 0xff00000000000000ULL -#define GCDOP_N_OP_SIZE 8 - -#define GCDOP_N_OP_RD_ROM_ID 0x9000000000000000ULL -#define GCDOP_N_OP_RD_PAGE 0x0000000000000000ULL -#define GCDOP_N_OP_WR_PAGE 0x8000000000000000ULL -#define GCDOP_N_OP_LD_TABLE 0x9f00000000000000ULL -#define GCDOP_N_OP_CHG_MODE 0x3c00000000000000ULL -#define GCDOP_N_OP_CHG2_MODE 0x3d00000000000000ULL - -#define GCDOP_N_RD_ROM_ID_PAD 0x00ffffffffffffffULL -#define GCDOP_N_RD_PAGE_PAD 0x00fffffeff00ffffULL -#define GCDOP_N_CHG_MODE_PAD 0x00000000f00000ffULL -#define GCDOP_N_CHG2_MODE_PAD GCDOP_N_CHG_MODE_PAD - -#define GCDOP_N_RD_PAGE_ADDR_SHIFT 33 -#define GCDOP_N_RD_PAGE_ADDR_SIZE 23 -#define GCDOP_N_RD_PAGE_ADDR_MASK 0x00fffffe00000000ULL - -#define GCDOP_N_VAE_SHIFT 32 -#define GCDOP_N_VAE_SIZE 24 -#define GCDOP_N_VAE_MASK 0x00ffffff00000000ULL - -#define GCDOP_N_VBI_SHIFT 8 -#define GCDOP_N_VBI_SIZE 20 -#define GCDOP_N_VBI_MASK 0x000000000fffff00ULL - - -// SECURE mode - -#define GCDOP_S_OP_MASK 0xf000000000000000ULL -#define GCDOP_S_OP_SIZE 4 - -#define GCDOP_S_OP_RD_ROM_ID 0x1000000000000000ULL -#define GCDOP_S_OP_RD_SEGMENT 0x2000000000000000ULL -#define GCDOP_S_OP_PNG_ON 0x4000000000000000ULL -#define GCDOP_S_OP_PNG_OFF 0x6000000000000000ULL -#define GCDOP_S_OP_CHG_MODE 0xa000000000000000ULL - -#define GCDOP_S_VA_SHIFT GCDOP_S_VB_SIZE -#define GCDOP_S_VA_SIZE 24 -#define GCDOP_S_VA_MASK 0x00000ffffff00000ULL - -#define GCDOP_S_VB_SHIFT 0 -#define GCDOP_S_VB_SIZE 20 -#define GCDOP_S_VB_MASK 0x00000000000fffffULL - -#define GCDOP_S_VC_SHIFT (GCDOP_S_VA_SIZE + GCDOP_S_VB_SIZE) -#define GCDOP_S_VC_SIZE 16 -#define GCDOP_S_VC_MASK 0x0ffff00000000000ULL - -#define GCDOP_S_VD_SHIFT GCDOP_S_VA_SHIFT -#define GCDOP_S_VD_SIZE GCDOP_S_VA_SIZE -#define GCDOP_S_VD_MASK GCDOP_S_VA_MASK - - -// GAME mode - -#define GCDOP_G_OP_MASK 0xff00000000000000ULL -#define GCDOP_G_OP_SIZE 8 - -#define GCDOP_G_OP_RD_ROM_ID 0xb800000000000000ULL -#define GCDOP_G_OP_RD_ROM_UID 0xb900000000000000ULL -#define GCDOP_G_OP_RD_PAGE 0xb700000000000000ULL -#define GCDOP_G_OP_RD_CACHE_START 0x5800000000000000ULL -#define GCDOP_G_OP_RD_CACHE 0x6000000000000000ULL -#define GCDOP_G_OP_RD_CACHE_LAST 0x6800000000000000ULL -#define GCDOP_G_OP_WR_PAGE 0x8000000000000000ULL - -#define GCDOP_G_RD_ROM_ID_PAD 0x00ffffffffffffffULL -#define GCDOP_G_RD_ROM_UID_PAD 0x00ffffffffffffffULL -#define GCDOP_G_RD_PAGE_PAD 0x00f0000000ffffffULL - -#define GCDOP_G_RD_PAGE_ADDR_SHIFT 33 -#define GCDOP_G_RD_PAGE_ADDR_SIZE 23 -#define GCDOP_G_RD_PAGE_ADDR_MASK 0x000ffffe00000000ULL - - -// ROM ID - -#define GCD_ROMID_1TROM_MASK 0x80000000UL -#define GCD_ROMID_TWLROM_MASK 0x40000000UL -#define GCD_ROMID_BADBLK_MASK 0x20000000UL -#define GCD_ROMID_SIZE_MASK 0x0000ff00UL - - - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadRomID - - Description: read rom ID - sync version - - Arguments: None - - Returns: rom ID - *---------------------------------------------------------------------------*/ -u32 GCDi_ReadRomID( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadRom - - Description: read rom data - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_ReadRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadRomAsync - - Description: read rom data - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_ReadRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadNormalModeRom - - Description: read rom data on normal mode - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_ReadNormalModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCD_ReadNormalModeRomAsync - - Description: read rom data on normal mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadNormalModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadGameModeRom - - Description: read rom data on game mode - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_ReadGameModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCDi_ReadGameModeRomAsync - - Description: read rom data on game mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_ReadGameModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCDi_WriteGameModeRom - - Description: write rom data on game mode - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WriteGameModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCDi_WriteGameModeRomAsync - - Description: write rom data on game mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WriteGameModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCDi_Enable - - Description: Enable game card master control - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_Enable( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_Disable - - Description: disable game card master control - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_Disable( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCD_SetPrimarySlot - - Description: set primary game card slot - - Arguments: primary slot - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_SetPrimarySlot( u8 slot ); - -/*---------------------------------------------------------------------------* - Name: GCD_GetPrimarySlot - - Description: get primary game card slot - - Arguments: None - - Returns: primary slot - *---------------------------------------------------------------------------*/ -u8 GCD_GetPrimarySlot(void ); - -/*---------------------------------------------------------------------------* - Name: GCD_Reset - - Description: reset game card - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_Reset( GCDSlot slot, u32 chat_cycles ); - -/*---------------------------------------------------------------------------* - Name: GCD_Reset - - Description: reset game card - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ResetAll( u32 chat_cycles ); - -/*---------------------------------------------------------------------------* - Name: GCDi_SelectRom - - Description: select game card spi - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_SelectRom( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_SelectSpi - - Description: select game card spi - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_SelectSpi( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_SetDmaNo - - Description: set card dma number - - Arguments: dmaNo : dma channel number - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_SetDmaNo( GCDSlot slot, u32 dmaNo ); - -/*---------------------------------------------------------------------------* - Name: GCDi_GetDmaNo - - Description: get card dma number - - Arguments: None - - Returns: dmaNo : dma channel number - *---------------------------------------------------------------------------*/ -u32 GCDi_GetDmaNo( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_InterruptHandler - - Description: interrupt handler - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_InterruptHandlerPRIME( void ); -void GCDi_InterruptHandlerSECOND( void ); -void GCDi_InterruptHandlerCommon( GCDSlot slot ); - -//================================================================================ -// WAIT/STOP -//================================================================================ -/*---------------------------------------------------------------------------* - Name: GCDi_IsBusy - - Description: check whether game card is busy or not - - Arguments: None - - Returns: TRUE if game card is busy, FALSE if not - *---------------------------------------------------------------------------*/ -BOOL GCDi_IsBusy( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_IsDataReady - - Description: check whether data is ready or not - - Arguments: None - - Returns: TRUE if game card is busy, FALSE if not - *---------------------------------------------------------------------------*/ -BOOL GCDi_IsDataReady( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_Stop - - Description: stop game card access - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_Stop( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_WaitCtrl - - Description: wait while game card is busy - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WaitCtrl( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_WaitData - - Description: wait until data is ready - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WaitData( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_WaitDma - - Description: wait for stopping game card DMA - - Arguments: dmaNo : DMA channel No. - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WaitDma( GCDSlot slot, u32 dmaNo ); - -/*---------------------------------------------------------------------------* - Name: GCDi_WaitInterrupt - - Description: wait for game card interrupt - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_WaitInterrupt( GCDSlot slot ); - - -// internal - -BOOL GCDi_IsSecureInitialized( GCDSlot slot ); -BOOL GCDi_IsCtrApp( GCDSlot slot ); -BOOL GCDi_IsDsApp( GCDSlot slot ); - -u32 GCDi_ReadNormalModeID( GCDSlot slot ); -u32 GCDi_ReadSecureModeID( GCDSlot slot ); -u32 GCDi_ReadGameModeID( GCDSlot slot ); - -u32 GCDi_ReadRomIDCore( GCDSlot slot, GCDRomCtrls *ctrls ); -void GCDi_ReadRomCore( GCDSlot slot, void *ramp, s32 size, GCDRomCtrls *ctrls ); -BOOL GCDi_ReadRomCommonPreCore( GCDSlot slot, u32 romp, void *ram, s32 size ); -void GCDi_WriteRomCore( GCDSlot slot, void *ramp, s32 size, GCDRomCtrls *ctrls ); - -void GCDi_ReadNormalModeRomCore( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ); - -void GCDi_InitSecureParam( GCDSlot slot, BOOL twl_ex ); -void GCDi_InitPngIntf( GCDSlot slot ); -void GCDi_SetInitCardOpBlowfish( void (*p)( void ) ); -void GCDi_SetDecryptObjectFilep( void (*p)( void ) ); -void GCDi_SetSetPngIntf( void (*p)( u32 pnA_l, u8 pnA_h, u32 pnB_l, u8 pnB_h ) ); -void GCDi_SetReadSecureModeIDCorep( u32 (p)( GCDRomCtrls *ctrls ) ); -void GCDi_SetReadSecureModeRomCorep( void (p)( u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ) ); -void GCDi_SetGetOneShotSizeFromCtrlp( s32 (p)( u32 ctrl ) ); - -void GCDi_SetSendOnlyCardOpCorep( void (*p)( GCDRomCtrls *ctrls ) ); -void GCDi_ChangeIntoSecureMode( GCDSlot slot ); -void GCDi_ChangeIntoSecure2Mode( GCDSlot slot ); -void GCDi_SendPngON( GCDSlot slot ); -void GCDi_SendPngOFF( GCDSlot slot ); -void GCDi_ChangeIntoGameMode( GCDSlot slot ); -void GCDi_ReadCardSegmentAsync4Secure( GCDSlot slot, BOOL twl_ex ); - -void GCDi_InitCardOpBlowfish( GCDSlot slot ); -void GCDi_InitCardOpBlowfishDS( GCDSlot slot ); -void GCDi_DecryptObjectFile( GCDSlot slot ); -void GCDi_DecryptObjectFileDS( GCDSlot slot ); - -void GCD_SetInterrupt( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDWork *wp ); - -void* GCDi_GetRomHeaderAddr( GCDSlot slot ); - - -extern u32 GCDi_HeaderBuf[2][ GCD_ROM_HEADER_SIZE/sizeof(u32) ]; -extern u32 GCDi_SecureAreaBuf[2][ GCD_SECURE_AREA_SIZE/sizeof(u32) ]; -extern u32 GCDi_Secure2AreaBuf[2][ GCD_SECURE_AREA_SIZE/sizeof(u32) ]; - -extern GCDSharedWork GCDi_SharedWork[2]; -extern GCDWork GCDi_Work[2]; - -// 初期化テーブル -extern const BLOWFISH_CTX GCDi_BlowfishInitTableDS; -extern const BLOWFISH_CTX GCDi_BlowfishInitTableGCDFIRM; - - -// ※SecondarySlotのカードロックが用意されていないので、とりあえずPrimarySlotと共用で。 -s32 OS_LockExCard( u16 lockID ); -s32 OS_UnlockExCard( u16 lockID ); - -#ifdef __cplusplus -} /* extern "C" */ - -#endif - -/* FIRM_GCD_GCD_H_ */ -#endif diff --git a/include/firm/gcd/gcd_misc.h b/include/firm/gcd/gcd_misc.h deleted file mode 100644 index 4b3da84f..00000000 --- a/include/firm/gcd/gcd_misc.h +++ /dev/null @@ -1,516 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlFirm - GCD - include - File: ngcd.h - - Copyright 2007 Nintendo. All rights reserved. - - These coded instructions, statements, and computer programs contain - proprietary information of Nintendo of America Inc. and/or Nintendo - Company Ltd., and are protected by Federal copyright law. They may - not be disclosed to third parties or copied or duplicated in any form, - in whole or in part, without the prior written consent of Nintendo. - - $Date:: 2007-09-06$ - $Rev$ - $Author$ - *---------------------------------------------------------------------------*/ - -#ifndef FIRM_GCD_GCD_MISC_H_ -#define FIRM_GCD_GCD_MISC_H_ - -#include -#include "./gcd.h" - - -#ifdef __cplusplus -extern "C" { -#endif - -#define PXI_FIFO_TAG_GCD PXI_FIFO_TAG_USER_1 - -#define reg_MI_MC_DET (*(REGType8v *) REG_MC_OFFSET) -#define reg_MI_MC_SWP (*(REGType8v *) ( REG_MC_OFFSET + 1 ) ) - -#define REG_MCCHAT_OFFSET 0x4012 -#define REG_MCCHAT_ADDR (HW_REG_BASE + REG_MCCHAT_OFFSET) -#define reg_MI_MCCHAT (*( REGType16v *) REG_MCCHAT_ADDR) - -/* MCSCRA_L */ - -#define REG_MCSCRA_L_OFFSET 0x1b0 -#define REG_MCSCRA_L_ADDR (HW_REG_BASE + REG_MCSCRA_L_OFFSET) -#define reg_MI_MCSCRA_L (*( REGType32v *) REG_MCSCRA_L_ADDR) - -/* MCSCRB_L */ - -#define REG_MCSCRB_L_OFFSET 0x1b4 -#define REG_MCSCRB_L_ADDR (HW_REG_BASE + REG_MCSCRB_L_OFFSET) -#define reg_MI_MCSCRB_L (*( REGType32v *) REG_MCSCRB_L_ADDR) - -/* MCSCRA_H */ - -#define REG_MCSCRA_H_OFFSET 0x1b8 -#define REG_MCSCRA_H_ADDR (HW_REG_BASE + REG_MCSCRA_H_OFFSET) -#define reg_MI_MCSCRA_H (*( REGType8v *) REG_MCSCRA_H_ADDR) - -/* MCSCRB_H */ - -#define REG_MCSCRB_H_OFFSET 0x1ba -#define REG_MCSCRB_H_ADDR (HW_REG_BASE + REG_MCSCRB_H_OFFSET) -#define reg_MI_MCSCRB_H (*( REGType8v *) REG_MCSCRB_H_ADDR) - - -#define REG_MI_MCCNT1_A_CSC_SHIFT 22 -#define REG_MI_MCCNT1_A_CSC_SIZE 1 -#define REG_MI_MCCNT1_A_CSC_MASK 0x00400000 - -#define REG_MI_MC_SWP_E_SHIFT 7 -#define REG_MI_MC_SWP_E_SIZE 1 -#define REG_MI_MC_SWP_E_MASK 0x80 - - - -typedef enum -{ - GCD_PAGE_0 = 0x0UL << REG_MI_MCCNT1_A_PC_SHIFT, - GCD_PAGE_1 = 0x1UL << REG_MI_MCCNT1_A_PC_SHIFT, - GCD_PAGE_2 = 0x2UL << REG_MI_MCCNT1_A_PC_SHIFT, - GCD_PAGE_4 = 0x3UL << REG_MI_MCCNT1_A_PC_SHIFT, - GCD_PAGE_8 = 0x4UL << REG_MI_MCCNT1_A_PC_SHIFT, - GCD_PAGE_16 = 0x5UL << REG_MI_MCCNT1_A_PC_SHIFT, - GCD_PAGE_32 = 0x6UL << REG_MI_MCCNT1_A_PC_SHIFT, - GCD_PAGE_STAT = 0x7UL << REG_MI_MCCNT1_A_PC_SHIFT -} -GCDPageCount; - -typedef enum -{ - GCD_CKT_150NS = 0x0UL << REG_MI_MCCNT1_A_CT_SHIFT, - GCD_CKT_240NS = 0x1UL << REG_MI_MCCNT1_A_CT_SHIFT -} -GCDClockType; - -typedef enum -{ - GCD_RW_READ = 0x0UL << REG_MI_MCCNT1_WR_SHIFT, - GCD_RW_WRITE = 0x1UL << REG_MI_MCCNT1_WR_SHIFT -} -GCDRw; - -typedef enum -{ - GCD_RESET_LO = 0x0UL << REG_MI_MCCNT1_A_RESB_SHIFT, - GCD_RESET_HI = 0x1UL << REG_MI_MCCNT1_A_RESB_SHIFT -} -GCDReset; - -typedef enum -{ -#ifdef SDK_ARM9 - GCD_LTCK_DISABLE = 0x0UL << REG_MI_MCCNT1_A_TRM_SHIFT, - GCD_LTCK_ENABLE = 0x1UL << REG_MI_MCCNT1_A_TRM_SHIFT -#else - GCD_LTCK_DISABLE = 0x0UL << REG_MI_MCCNT1_A_RTM_SHIFT, - GCD_LTCK_ENABLE = 0x1UL << REG_MI_MCCNT1_A_RTM_SHIFT -#endif -} -GCDLtClkEnable; - -typedef struct -{ - u32 ctrl; - u8 master; - u8 spi; -} -NGCDCtrlRegs; - -// PXIでの通信プロトコル関連定義 -#define GCD_PXI_COMMAND_MASK 0x0000003f // 開始ワードのコマンド部 -#define GCD_PXI_COMMAND_SHIFT 0 -#define GCD_PXI_COMMAND_SIZE 6 -#define GCD_PXI_COMMAND_PARAM_MASK 0x03ffffc0 // 開始ワードのパラメータ部 -#define GCD_PXI_COMMAND_PARAM_SHIFT 6 -#define GCD_PXI_COMMAND_PARAM_SIZE 20 - -typedef union -{ - struct - { - u32 cmd:GCD_PXI_COMMAND_SIZE; - u32 param:GCD_PXI_COMMAND_PARAM_SIZE-1; - u32 slot:1; - } - e; - u32 raw; -} -GCDPxiCmd; - -// PXI経由で発行される命令 -#define GCD_PXI_COMMAND_RESET 0x01 -#define GCD_PXI_COMMAND_LOADED 0x02 - - -/*---------------------------------------------------------------------------* - Name: GCD_Init - - Description: initialize for game card access - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_Init( void ); - -/*---------------------------------------------------------------------------* - Name: GCDi_Init - - Description: initialize for game card access - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_Init( BOOL reset ); - -/*---------------------------------------------------------------------------* - Name: GCD_ReadRomID - - Description: read rom ID - sync version - - Arguments: None - - Returns: rom ID - *---------------------------------------------------------------------------*/ -u32 GCD_ReadRomID( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCD_ReadRom - - Description: read rom data - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCD_ReadRomAsync - - Description: read rom data - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCD_ReadNormalModeRom - - Description: read rom data on normal mode - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadNormalModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCD_ReadGameModeRom - - Description: read rom data on game mode - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadGameModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCD_ReadRomPreCore - - Description: read rom data - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -BOOL GCD_ReadRomPreCore( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCD_ReadGameModeRomAsync - - Description: read rom data on game mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_ReadGameModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCD_WriteGameModeRom - - Description: write rom data on game mode - sync version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_WriteGameModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCD_WriteGameModeRomAsync - - Description: write rom data on game mode - async version - - Arguments: romp : rom offset - ramp : ram destination address - size : size (byte) - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_WriteGameModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); - -/*---------------------------------------------------------------------------* - Name: GCDi_Enable - - Description: Enable game card master control - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_Enable( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_Disable - - Description: disable game card master control - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCDi_Disable( GCDSlot slot ); - -//================================================================================ -// WAIT/STOP -//================================================================================ -/*---------------------------------------------------------------------------* - Name: GCD_IsExisting - - Description: get whether cartridge exists - - Arguments: None - - Returns: TRUE if game card is busy, FALSE if not - *---------------------------------------------------------------------------*/ -static inline BOOL GCD_IsExisting( GCDSlot slot ) -{ - s32 ofs = (GCD_GetPrimarySlot() ^ slot) * 4; - s32 r = ~reg_MI_MC_DET & (REG_MI_MC_SL1_CDET_MASK << ofs); - return r >> (REG_MI_MC_SL1_CDET_SHIFT + ofs); -} - -/*---------------------------------------------------------------------------* - Name: GCD_SetDetectMode - - Description: - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static inline void GCD_SetDetectMode( GCDSlot slot, u32 mode ) -{ - s32 ofs = (GCD_GetPrimarySlot() ^ slot) * 4; - s32 others = reg_MI_MC_DET & ~(REG_MI_MC_SL1_MODE_MASK << ofs); - reg_MI_MC_DET = (u8)((mode << (REG_MI_MC_SL1_MODE_SHIFT + ofs)) | others); -} - -/*---------------------------------------------------------------------------* - Name: GCD_GetDetectMode - - Description: - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static inline u8 GCD_GetDetectMode( GCDSlot slot ) -{ - s32 ofs = (GCD_GetPrimarySlot() ^ slot) * 4; - return (u8)((reg_MI_MC_DET & (REG_MI_MC_SL1_MODE_MASK << ofs)) - >> (REG_MI_MC_SL1_MODE_SHIFT + ofs)); -} - -/*---------------------------------------------------------------------------* - Name: GCD_SetChatCounter - - Description: - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static inline void GCD_SetChatCounter( u16 value ) -{ - reg_MI_MCCHAT = value; -} - -/*---------------------------------------------------------------------------* - Name: GCD_IsBusy - - Description: check whether game card is busy or not - - Arguments: None - - Returns: TRUE if game card is busy, FALSE if not - *---------------------------------------------------------------------------*/ -BOOL GCD_IsBusy( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCD_IsDataReady - - Description: check whether data is ready or not - - Arguments: None - - Returns: TRUE if game card is busy, FALSE if not - *---------------------------------------------------------------------------*/ -BOOL GCD_IsDataReady( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCD_Stop - - Description: stop game card access - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_Stop( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCD_WaitRomAsync - - Description: wait for game card async access - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void GCD_WaitRomAsync( GCDSlot slot ); - -/*---------------------------------------------------------------------------* - Name: GCDi_SelectRegAddr - - Description: - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static inline void* GCDi_SelectRegAddr( GCDSlot slot, u32 base ) -{ - u32 addr = base; - - if ( slot == GCD_SECONDARY_SLOT ) - { - addr += REG_MCCNT0_B_ADDR - REG_MCCNT0_ADDR; - } - - return (void*)addr; -} - -/*---------------------------------------------------------------------------* - Name: GCDi_SelectIrqMask - - Description: - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -static inline u32 GCDi_SelectIrqMask( GCDSlot slot, u32 base_mask ) -{ - u32 mask = base_mask; - - if ( slot == GCD_SECONDARY_SLOT ) - { - switch ( mask ) - { - case OS_IE_CARD_DATA: - mask = OS_IE_CARD_B_DATA; - break; - case OS_IE_CARD_IREQ: - mask = OS_IE_CARD_B_IREQ; - break; - case OS_IE_CARD_A_DET: - mask = OS_IE_CARD_B_DET; - break; - } - } - - return mask; -} - - -// internal - -u32 GCD_ReadNormalModeID( GCDSlot slot ); -u32 GCD_ReadSecureModeID( GCDSlot slot ); -u32 GCD_ReadGameModeID( GCDSlot slot ); - -void GCDi_SetOp( GCDSlot slot, GCDCmd64* op ); -void GCDi_SetCtrl( GCDSlot slot, GCDCtrlRegs* regs ); -void GCDi_GenCtrl( GCDCtrlRegs* regs, - GCDRw rw, - GCDPageCount pcount, - GCDClockType ckt, u32 lt1, u32 lt2, - BOOL cpn, BOOL dpn, BOOL csc, BOOL dsc ); -s32 GCDi_GetOneShotSizeFromCtrl( u32 ctrl ); -void GCD_SendOnlyCardOpCore( GCDSlot slot, GCDRomCtrls *ctrls ); -u32 GCDi_ReadRomIDCore( GCDSlot slot, GCDRomCtrls *ctrls ); -void GCD_ReadRomCore( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ); -void GCD_WaitRomAsyncCore( GCDSlot slot ); - -void GCDi_WaitCtrl( GCDSlot slot ); -void GCDi_WaitData( GCDSlot slot ); -void GCDi_WaitDma( GCDSlot slot, u32 dmaNo ); -void GCDi_WaitInterrupt( GCDSlot slot ); - -void GCDi_SendtoPxi(u32 data); - -#ifdef __cplusplus -} /* extern "C" */ - -#endif - -/* FIRM_GCD_GCD_MISC_H_ */ -#endif