diff --git a/build/libraries/Makefile b/build/libraries/Makefile index 727e589c..17fe8ac4 100644 --- a/build/libraries/Makefile +++ b/build/libraries/Makefile @@ -23,6 +23,7 @@ include $(TWLFIRM_ROOT)/build/buildtools/commondefs SUBDIRS = \ os \ + gcd \ mi \ init \ pxi \ @@ -31,7 +32,6 @@ SUBDIRS = \ pm \ # syscall \ # nvram \ -# gcd \ # acsign \ # acsign_ecc \ # devices \ diff --git a/build/libraries/gcd/ARM7/Makefile b/build/libraries/gcd/ARM7/Makefile new file mode 100644 index 00000000..c8ddf7f6 --- /dev/null +++ b/build/libraries/gcd/ARM7/Makefile @@ -0,0 +1,60 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL +# 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:: 2007-10-03#$ +# $Rev: 1319 $ +# $Author: kitase_hirotake $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +# build ARM & THUMB libraries +FIRM_CODEGEN_ALL ?= True + +FIRM_PROC = ARM7 + +SRCDIR = . ../common +SRCS = \ + gcd.c \ + gcd_init.c \ + blowfish.c \ + ds_blowfish.c \ + ds_blowfish_table.c \ + gcdfirm_blowfish_table.c \ + +TARGET_LIB = libgcd_sp$(FIRM_LIBSUFFIX).a +INCDIR = ../include + +#---------------------------------------------------------------------------- + +# DEBUG版ビルドの場合、RELEASE版でビルドして +# DEBUG版のライブラリを装います。 + +ifdef NITRO_DEBUG +NITRO_BUILD_TYPE = RELEASE +endif + +include $(TWLFIRM_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWLFIRM_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries/gcd/ARM9/Makefile b/build/libraries/gcd/ARM9/Makefile new file mode 100644 index 00000000..b5ff3faa --- /dev/null +++ b/build/libraries/gcd/ARM9/Makefile @@ -0,0 +1,65 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL +# 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:: 2007-10-03#$ +# $Rev: 1319 $ +# $Author: kitase_hirotake $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +# build ARM & THUMB libraries +FIRM_CODEGEN_ALL ?= True + + + +SRCDIR = . ../common +SRCS = \ + gcd.c \ + gcd_init.c \ + blowfish.c \ + ds_blowfish.c \ + ds_blowfish_table.c \ + gcdfirm_blowfish_table.c \ + +TARGET_LIB = libgcd$(FIRM_LIBSUFFIX).a +INCDIR = ../include + +#---------------------------------------------------------------------------- + +# DEBUG版ビルドの場合、RELEASE版でビルドして +# DEBUG版のライブラリを装います。 + +ifdef NITRO_DEBUG +NITRO_BUILD_TYPE = RELEASE +endif + +include $(TWLFIRM_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWLFIRM_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/libraries/gcd/Makefile b/build/libraries/gcd/Makefile new file mode 100644 index 00000000..b762dc2b --- /dev/null +++ b/build/libraries/gcd/Makefile @@ -0,0 +1,34 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - init +# 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. +# +# $Log: $ +# $NoKeywords: $ +#---------------------------------------------------------------------------- + +include $(TWLFIRM_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 + +#ifdef TWL_WITH_ARM7 +SUBDIRS += ARM7 +#endif + +#---------------------------------------------------------------------------- + +include $(TWLFIRM_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/gcd/common/blowfish.c b/build/libraries/gcd/common/blowfish.c new file mode 100644 index 00000000..60f8fb2d --- /dev/null +++ b/build/libraries/gcd/common/blowfish.c @@ -0,0 +1,149 @@ +/*---------------------------------------------------------------------------* + 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 new file mode 100644 index 00000000..1a6b3bd1 --- /dev/null +++ b/build/libraries/gcd/common/ds_blowfish.c @@ -0,0 +1,186 @@ +/*---------------------------------------------------------------------------* + 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 new file mode 100644 index 00000000..2ab70da3 --- /dev/null +++ b/build/libraries/gcd/common/ds_blowfish_table.c @@ -0,0 +1,286 @@ +/*---------------------------------------------------------------------------* + 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 new file mode 100644 index 00000000..0f277b13 --- /dev/null +++ b/build/libraries/gcd/common/gcd.c @@ -0,0 +1,1215 @@ +/*---------------------------------------------------------------------------* + 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 new file mode 100644 index 00000000..e97e8d2c --- /dev/null +++ b/build/libraries/gcd/common/gcd_init.c @@ -0,0 +1,1668 @@ +/*---------------------------------------------------------------------------* + 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と共用で。 +s32 OS_LockExCard( u16 lockID ) +{ + return OS_LockCard( lockID ); +} + +s32 OS_UnlockExCard( u16 lockID ) +{ + return OS_UnlockCard( lockID ); +} + + +/*---------------------------------------------------------------------------* + 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/common/gcdfirm_blowfish_table.c b/build/libraries/gcd/common/gcdfirm_blowfish_table.c new file mode 100644 index 00000000..ec61d6d1 --- /dev/null +++ b/build/libraries/gcd/common/gcdfirm_blowfish_table.c @@ -0,0 +1,288 @@ +/*---------------------------------------------------------------------------* + Project: TwlBrom - libraries - GCD + File: gcdfirm_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_BlowfishInitTableGCDFIRM = { + + 0x7595a8ee, 0x84fff32d, 0x58f8aec6, 0x6f6444c2, + 0x10a6cfbc, 0xbee1b813, 0x88efabc3, 0xc72026cd, + 0xc00b913a, 0x9fb074c0, 0x56d4830f, 0x69abdee5, + 0xcf6e5ff2, 0xd7febe2f, 0x84f5d5e2, 0x73a1ccda, + 0x44205999, 0x74278f63, + + 0xf0907253, 0x1c95d48f, 0x7cdbce99, 0xa8b9508a, + 0x79379f9e, 0x129144fe, 0xd2b3554d, 0x72d702c6, + 0xce058143, 0x72b411b8, 0x9acf2ae7, 0x62c0d195, + 0x7d0861e5, 0x333ac8f6, 0xafc17b59, 0x7fabab12, + 0x5a20b8df, 0x43c908e1, 0xdf057b54, 0x65237d17, + 0x8988581c, 0x1d02cad9, 0xdde63c8a, 0x302fee12, + 0x0abedd9d, 0x586fb574, 0x10130aad, 0x0a1ead35, + 0xfe6f0870, 0x8cac4f02, 0x9c56ef2c, 0xc0ab9bcd, + 0x7faf9a52, 0xef822dcd, 0x2bc0fdc2, 0xde22a557, + 0xccf82867, 0x582a9d19, 0xd2790715, 0xdc8df689, + 0x250ca6e2, 0xfe35236d, 0x8648e2d6, 0xaa0bf6e7, + 0xd1240620, 0x413a5ea7, 0x4cf59143, 0x4f4f5472, + 0xa5f29a08, 0x1fff4e8f, 0x14f0ec2d, 0x47d6f42a, + 0x85b021f0, 0x7836f20a, 0xd908d0d7, 0xbdcc9dd5, + 0xa6ac0bfb, 0x96fb7daf, 0xb65476ff, 0xbde99b51, + 0xe8c84b8e, 0x72c88630, 0x3f8d0979, 0x5c1e45dc, + 0x7555b1db, 0x3edb5a90, 0xb07fac66, 0xf7316aba, + 0x84a088bd, 0xf0b2fb9d, 0x014b48e1, 0x6d0967e3, + 0xa38d60e4, 0x148eedf2, 0x81898864, 0xfe0d73aa, + 0x58c37bd5, 0x8ce2c345, 0x82951de7, 0x17be1aa6, + 0xbfe8ad1b, 0x4d6b4176, 0x3a0da43d, 0x50a4dcac, + 0x69f1282e, 0x16b49576, 0x6b521ffe, 0x67588174, + 0xb3de1d28, 0x06198cbd, 0xeea240ea, 0xd13e358e, + 0x3664b06c, 0x59f4e227, 0xb54122d3, 0x94bb71e3, + 0x0315fb94, 0x647301d6, 0x943f1f0d, 0x7a2aaec4, + 0x51bf88f7, 0x712c091a, 0x6d3b6e3e, 0x6eb24d52, + 0x9fc82ca4, 0x8ffc188e, 0xbe31140a, 0x1d3e5756, + 0xc574e16e, 0xb105a793, 0x94f658ec, 0x6ed4864c, + 0xb2bae3cf, 0xe342cf15, 0xf2bc4d27, 0x090334b1, + 0xc2632a42, 0x884f0092, 0xa59abd51, 0xe9d203f9, + 0x7d122257, 0x02a709aa, 0xac9fc39b, 0x4840beed, + 0x74be37a4, 0x24b9a4d3, 0x8178bca7, 0x606b85e5, + 0x1dcb46b2, 0xe6112060, 0xbd44008a, 0xd1be2964, + 0xcfcc5032, 0x74e10e43, 0x53fac5ab, 0x84a6e0a4, + 0x9080997a, 0xa31a0100, 0xcee21c1c, 0xebcee973, + 0x77e9a4c7, 0x3a261b9b, 0xce49ca16, 0xec3a432d, + 0x1410c1bf, 0x8d22c824, 0xb0018266, 0x7964e2e2, + 0xfcc6eb14, 0x12e6e035, 0xca689d0a, 0x5f9f39fc, + 0xbf14f7e9, 0x5d7813f2, 0x87347401, 0x1a107660, + 0xfeaa1bb7, 0x53ebb1a2, 0xfc47a457, 0xf71cde17, + 0x25379a36, 0xb2ed205d, 0x1225bf36, 0x14536bd4, + 0x31138cdf, 0xeeecb7f4, 0xbb6e5b19, 0x39877d0f, + 0x4366ac24, 0xfb13893c, 0x3a7039b2, 0x3a1b8037, + 0xfc668634, 0x0a3fb783, 0x50380526, 0x9c0e4b1a, + 0x462b9398, 0x0e6c7d2d, 0x689a929e, 0x715701e6, + 0x2e61d17d, 0x09da9145, 0xfb143ba1, 0x5b199259, + 0xc4e3a5ee, 0x0b4bda9a, 0xe18c526c, 0x73171c1a, + 0x1572a94b, 0x6d15b729, 0x71509e91, 0x571bc76e, + 0x8c721018, 0x1fcc1742, 0xa6602c75, 0x787f88a9, + 0x0598f9c4, 0x5addc61b, 0x8e9b7b41, 0x2f4daf72, + 0xd9f09e2a, 0xe76054ca, 0x28bc0b4e, 0x4a320c32, + 0xdf2b687e, 0x2cdffbcc, 0x77f16b69, 0x5d425665, + 0xcf207fd9, 0x2e4d166d, 0x46e57957, 0x37f50f39, + 0x6742b74a, 0xbb21df47, 0xe2df0964, 0x0dd6d989, + 0x6f635a6e, 0x8f05a457, 0x6e5dc010, 0xeae76f43, + 0x135c206a, 0x876bd938, 0x1ccbc607, 0xaf600e28, + 0x0daa4fe0, 0x95e0fe33, 0x093e44b1, 0x1d16b2ad, + 0x8d710ba2, 0x3ca3c1d9, 0x8f54a8e1, 0x7eb11ec8, + 0xcdb82a0e, 0xde1aff6d, 0x68ae2ce2, 0x80e1ca3e, + 0x67d60c2c, 0xac6ad1da, 0x5330c802, 0x5f67a04d, + 0x5d6f3c9d, 0x1f4725b0, 0x094a4c69, 0x4c1dea21, + 0xfd09ced5, 0x270fc341, 0xf16081f5, 0x54dcbdb4, + 0x72a36bf5, 0xbeabc16a, 0xdd82bb02, 0xf0e75d20, + 0xea6a64b0, 0x85cb5c2c, 0xd53a5aaa, 0x400f91d1, + + 0xc020695e, 0xa3d05c76, 0x8ac00446, 0xe0ebe1ce, + 0x7ed2ca13, 0x7f41bbca, 0x09daffc0, 0x16d39c09, + 0xd417fe9e, 0x11fc4b36, 0x87b92111, 0x581cea89, + 0x6a51516d, 0xa691f994, 0x06e5c6ab, 0x81200780, + 0xe6ea60b7, 0x8d0967af, 0x32f81d79, 0x1bf63b78, + 0xeefe70bb, 0x74123b42, 0xf7345b16, 0x7aaa1388, + 0x0152a394, 0xb5463ea1, 0xe7968633, 0xf6b00f17, + 0xfee65926, 0xfac95f88, 0xf7788838, 0x404d27c8, + 0x0a40725a, 0xac948618, 0xb2fb966f, 0x730b40c3, + 0x3fa5b3a0, 0x2a4a7b57, 0xe2ee0994, 0xe2662b03, + 0xa517c253, 0x5fcd9ac2, 0x7cf1861a, 0xfb9c6d92, + 0x726cfcf6, 0x6bc20855, 0xe03c7757, 0x15f7aefc, + 0x0490f4b2, 0xc5c49d9e, 0xd91bc403, 0x84799016, + 0x5e8b5d2f, 0xdd8aef68, 0x4225b87a, 0xd3912770, + 0x56f84df2, 0xe191d469, 0xb6306514, 0xf66b7461, + 0xaa528b42, 0xd7d8d211, 0x0409e809, 0x3e995489, + 0x984e2cd0, 0x21da8726, 0xa901dcce, 0xc59ed627, + 0xa508a395, 0xe67e1c10, 0x7786c594, 0x7db49c12, + 0xf3a048fa, 0x6c03c939, 0x5fe538b2, 0xe68d94f1, + 0x74116818, 0xbc041b38, 0x37e9f59f, 0xd5f0d6b4, + 0x3abedc09, 0xf2277fcf, 0xb1c090ca, 0x179fbeaf, + 0x6799f269, 0x4ef2e1ba, 0x9a8530fe, 0xe629bad3, + 0xef2d1806, 0xefe0d41a, 0x8fbd8038, 0xae93b3b8, + 0xb96af69a, 0xe976f30a, 0x3735edf2, 0xa10aab80, + 0x572bc346, 0xd9d352e5, 0xa88382fb, 0xc36d9a6a, + 0x622169f5, 0x2b668147, 0xc68d8e94, 0xd83725df, + 0x75ca8dc0, 0xe0fef07d, 0x3020348f, 0xd7e941c5, + 0x0f18da00, 0x9909caca, 0x1b5f4c03, 0x611ba66e, + 0xe3c25c8d, 0x87fe1654, 0x20ed099e, 0x2eef6251, + 0xf8b62747, 0xa8863716, 0x2e654e0a, 0x17985515, + 0xd121a7f0, 0xf0545a5b, 0xed9f9da3, 0xfe607b10, + 0x3afc599b, 0xa3c13305, 0x9667a20a, 0xbd639f0c, + 0xe647e3a0, 0x0e1304b2, 0x26a31cec, 0xd1435273, + 0x33845341, 0xbe3383f5, 0x22e5e07f, 0xb516aed2, + 0xe7dad3c1, 0x7e0b2eec, 0x7709d235, 0x48923397, + 0x086b62a6, 0x05270843, 0x48073d32, 0x3e22db8e, + 0x7b0fd2eb, 0x9199531d, 0xa47e9efc, 0x76b1bf31, + 0xee7b6f31, 0xdc6de2c0, 0x120d4d2c, 0x1c7d1a8b, + 0xd9192142, 0x5251ce66, 0x26dd0acf, 0x18073f04, + 0x5901f0a3, 0xfc24fea0, 0xe9d4474b, 0xbbda7bdd, + 0x66cb45f6, 0x66137a90, 0xa010a036, 0xa3fff96c, + 0x61c8194f, 0x553e0b2b, 0x72b54de2, 0x59aeefe9, + 0xda01dab4, 0xdac48b91, 0xbba66e7a, 0xa3819de2, + 0x1f950fce, 0xa3c4d697, 0xc4e28dce, 0x530179ee, + 0xaa7cc068, 0x1b44146a, 0xb267d209, 0x984ff1be, + 0x90fd796b, 0xe0e42a5f, 0x36d033fb, 0x13c2f482, + 0x3b19a86d, 0xff0ad256, 0xf06acb47, 0x0d4fbfa0, + 0x53246fd3, 0xf9296dd5, 0x42bb5d4a, 0xd4d86e75, + 0x96442650, 0x0bdebc51, 0xb3cee98d, 0x188c83e2, + 0xbe632850, 0x9a0ce659, 0xc51250cd, 0x141b9f77, + 0x292844d4, 0xa8ce50d4, 0xe6f471a3, 0xe51b7ef9, + 0xece33b79, 0x1ec17a6a, 0x01a0125e, 0x09071e04, + 0xbfe72df4, 0x170ed1cf, 0x2fa259ac, 0x4821704f, + 0x95b82704, 0xcd1e0c6a, 0xb57a33ce, 0x057204fe, + 0x7617de6b, 0xaa72f1d5, 0x4b46d61a, 0xac797378, + 0x4984d9cf, 0x40726022, 0x2b425b5c, 0x4ca25dab, + 0xa0e23aa3, 0x4fe1527a, 0x6fd3b7ac, 0xeb47ba60, + 0xcde7c8b7, 0x9aef5d0f, 0x821674cd, 0xc258ea7d, + 0xa6a813a5, 0x93e88a84, 0x8f32d2e3, 0x58ae440d, + 0xc5799715, 0x425284d0, 0x1b696e64, 0x7d3ce93a, + 0xdad0f25c, 0xc4b0dd14, 0x7079e2e5, 0xa9e8e61d, + 0xfaf686b7, 0x1cf1b87b, 0x31ab43c7, 0xdc45d1bb, + 0x386cb6ec, 0xcad283f2, 0x4dccbfaf, 0x4934f28b, + 0x2fbc3dd4, 0x789b64f7, 0xb2e8918f, 0x506acbf7, + + 0x50a13360, 0xd128d4d3, 0xba687526, 0xc5474940, + 0x6bb5dfc7, 0xef9bdf1f, 0x92cc643b, 0xfb2ad4f0, + 0x4ff9410b, 0xb013c81e, 0x9fe69574, 0x5fed0d88, + 0xcfe87720, 0x09cddf06, 0x9e57696f, 0xc429dfb9, + 0x460c5dd2, 0x9b9e505b, 0xc012bcf6, 0xd955bdda, + 0x7310ed31, 0xcdaaebe2, 0xc9761ff6, 0x5de00f45, + 0x66a5e949, 0x45c5df1d, 0x96a38fab, 0x18939d5b, + 0x94015083, 0xd27b1379, 0xe10107e7, 0xdaef6ef8, + 0xaf8f83b3, 0xafd37029, 0x7d6803e0, 0x3a545055, + 0xfd419925, 0xb49fa25f, 0x533ad3f4, 0xc49f3fe4, + 0x9b9eb196, 0x2015408e, 0xd6f46485, 0xa8e66479, + 0x5b8866e1, 0xc97d478d, 0xb7fcb30a, 0xddefdff0, + 0x34afb94c, 0xa155d92f, 0xf53979b1, 0xf0cdd075, + 0xf25accae, 0xe4208afd, 0x5b11bb77, 0x37b337e4, + 0xa69da8be, 0x28a9ee86, 0xb284b30e, 0xc3527598, + 0xf423936e, 0x7e2e1d51, 0xcaf2613d, 0x7505391e, + 0x252d3dd5, 0x00d18203, 0x7ef4577e, 0x244e98a9, + 0xb73b5840, 0xb0f9c9ed, 0xa8d4bc23, 0xb7228243, + 0x241418d3, 0x39fd4429, 0xe8ab9b37, 0x3a74ecdf, + 0xbf99499c, 0x70c3eb26, 0xc6ac5d10, 0x7085410a, + 0x9bc5ca24, 0x37cf4d32, 0x5a407af1, 0x7f38c2af, + 0x6cf95726, 0x2934cce9, 0x478e4a5e, 0x86bccd71, + 0x46673804, 0x5cd7e9da, 0x601c0e47, 0x32f3c95c, + 0x98f3b207, 0x2a9f09f2, 0xa68e3b9b, 0xe0a67f44, + 0x8d4801eb, 0x0d650900, 0x2dbd9d8f, 0x9113fe47, + 0x5a317b0e, 0x3d5a8d71, 0xfbd60e45, 0x86f6eedc, + 0x3f77fec6, 0xe56a0bb2, 0x32ab5ef7, 0x2262c429, + 0x7ed387c6, 0x0087c87e, 0x6570e4b7, 0x648d80e1, + 0xc3bd761a, 0x5c3c0c47, 0x9ac5b07c, 0x6ecb158f, + 0x73e2d323, 0x5095435e, 0x21a97ee4, 0x0c599519, + 0x1f6c6441, 0xee52efd7, 0xbd886ee2, 0x66ec3c66, + 0x0e42820c, 0xb4f244cb, 0xa56f2efc, 0xc0302f16, + 0xf9b795aa, 0x60a00f3f, 0xa83fb0a9, 0xe9b2f724, + 0xa3c3b44f, 0x8151cc80, 0x2ae0e99c, 0x0cb0ff00, + 0x2e9a646d, 0x991d2cd6, 0xef2bf16b, 0x0a610ad2, + 0x1674ea07, 0x567fcfe7, 0xf05ef5af, 0xdfdf47cb, + 0x6c3ebb59, 0x2f052cad, 0x4701ca04, 0x0c65164a, + 0xa285ecb3, 0x348fd20a, 0x7915f8ff, 0xdc269d33, + 0x74578f72, 0x763ced80, 0x53275951, 0x8c51eebd, + 0x6d8b4452, 0x5267c34e, 0xe9b7197b, 0x912800ab, + 0x10d207a4, 0x4238eaf7, 0x2171bd12, 0x9c7eff0b, + 0x251b79ff, 0x41bb7753, 0xecea6583, 0x031393e5, + 0x49a58fe9, 0x83bb7587, 0x4a2a3156, 0xa3ab8da7, + 0x38f774aa, 0xd3844d4e, 0x7cc81418, 0x894ca09d, + 0x341ade56, 0x9574d6a5, 0xd2299751, 0xdbd43293, + 0x253d53e8, 0x64005cc4, 0x813de56f, 0x631c3cda, + 0x931681bd, 0x77dd0ab8, 0x15d6b56f, 0x2a3106b1, + 0x603102bf, 0xfef29a3d, 0x648baa38, 0x470ae791, + 0x02e625ab, 0x04904d5d, 0x3b31cea4, 0xa9a2126d, + 0x76814575, 0x4c6a5511, 0xe2d7c619, 0x840d8ca5, + 0x4d15e8f8, 0x59256a95, 0xf1ed6a56, 0xb996efab, + 0x5da9c913, 0x7652bed8, 0xedbda0be, 0x59f81908, + 0xd1d45ed7, 0x00b5f876, 0x986b97e4, 0x0bf99862, + 0xf3a448c6, 0x05f92573, 0x9ab2c7c4, 0xbf92bbf2, + 0xa8e5e036, 0x3030a02b, 0xab1e833b, 0x5190d039, + 0x3d31eec2, 0x4eadf427, 0xea65d217, 0xafac4dd3, + 0xdf5ef6fe, 0xe88cdd6c, 0xab55d1df, 0x77689e8b, + 0x3ba6b081, 0x9ed37908, 0x42383678, 0xf9f221a6, + 0xb6cf355d, 0x1c10aa09, 0x38645486, 0xab46320e, + 0x6c01bdce, 0xaa9b77bf, 0xdc8a7085, 0x843c40c0, + 0x35218b12, 0x57c15a35, 0x37a879d4, 0x41fa8671, + 0xe9bae4f3, 0x9521c923, 0x2a32bab3, 0x5415b46b, + 0xcb7245dd, 0x6e6407bd, 0x88477782, 0x18424ea6, + 0x48214427, 0xd266b8b8, 0x70b796d4, 0xe4e48223, + + 0xf6a5bf45, 0xa34cc400, 0x0b62f21c, 0xf0eb6ca7, + 0x4f8566a3, 0xd23e5904, 0x86eac0fd, 0x95080a7d, + 0xe2926a24, 0x9983c4a1, 0x7e398b84, 0x9fccb2f1, + 0xff70696b, 0xccb47af7, 0x61d3bf96, 0xf4170385, + 0x0bc86fef, 0x06fb5c90, 0xce92d9fe, 0x120ca3cf, + 0xdcde2f59, 0xd6fd2b38, 0x4258d974, 0x4b2c0a3c, + 0x1f0967ec, 0x25987e51, 0x4e7acfc7, 0x1f7f9694, + 0x18de3230, 0x85d9095d, 0x54737616, 0x6ec26956, + 0x9eb3637b, 0x908a5192, 0x839fb43e, 0xefe70f2a, + 0x42e168a5, 0x776e5c22, 0x736be3a9, 0xb72d66ed, + 0xa4f94794, 0xb414bd55, 0x5de623d3, 0x9cd1e1a9, + 0x42957f7e, 0x381cf593, 0x678a7d07, 0x158bb604, + 0xe64926bd, 0x5a047438, 0x360d68cb, 0xab487a8e, + 0x0d769a0b, 0xde3fc939, 0xf33ea9c0, 0x28b87455, + 0xd5f6c00c, 0x853f8ffe, 0xc8d238c3, 0x3bb5473e, + 0xc9779097, 0xc4af3a0c, 0x899098c0, 0x3c51c0e4, + 0x7e02214e, 0xe65f85a4, 0xe7c4a857, 0x6096179e, + 0x9c9eb559, 0x709a5f7d, 0x548f6fd5, 0xf1ad58cb, + 0xe4bce783, 0x43ca2b6c, 0x6f43de8f, 0xa60a02f9, + 0xbcdd0f35, 0x58f582b3, 0x30633b0d, 0xf17c7d49, + 0x35f809f7, 0x9ee90417, 0x6360674f, 0x44375b7b, + 0x72949c97, 0xff78dcd2, 0x08bff59a, 0x00b14d4e, + 0xf37ef8c1, 0x6760a010, 0x87dd4dee, 0x31f5208a, + 0x721c3add, 0x6eb9ab46, 0x29250341, 0x2fdcc721, + 0x9d812ebb, 0x60a078a0, 0x20fcdc2d, 0xe8c594f9, + 0x4956e488, 0x81873803, 0xf51a953d, 0x9b43c7e1, + 0xdfd95440, 0x8dbdb07e, 0x1ecaf22f, 0xb14dceca, + 0xc4c8003d, 0xdc26051b, 0x8bdc1011, 0x6df204db, + 0xc72491cf, 0x9fd74623, 0xa663c57f, 0xd0f6f96d, + 0x60f5d249, 0x10b66b81, 0xeeb26437, 0xe739332c, + 0xeb94bdfd, 0xbfc4e0e3, 0x5d8ee7a8, 0xf676c5c3, + 0x38357061, 0x8d3e4d68, 0xd560280b, 0x7a85b438, + 0x00e7da19, 0x44e3021b, 0xb22bee73, 0x7af11114, + 0x9a4aacd3, 0xbb5ea97a, 0x7993ac0b, 0x3dc12ed7, + 0x7ac7eda8, 0x26528e57, 0xb15b78c9, 0xeae2b177, + 0xa9bd7a3c, 0x03812180, 0x0ed1451f, 0x9ab1c57d, + 0xa0acc3c5, 0xbf0b533d, 0x017f8413, 0x3228452a, + 0x86eb48e1, 0x379cbcff, 0x3b200f75, 0x0cbbb62b, + 0x7467627f, 0xc782b5e3, 0xd402c537, 0x026be842, + 0x41a32d7a, 0x5910b6ff, 0x909926b4, 0x05bd811e, + 0x92fd98c8, 0xcf66e980, 0x1f5eb79c, 0x4e2c31e4, + 0x5f9b7f0c, 0x91972e91, 0xf70f2e5a, 0xd5b6b627, + 0x3b1f243a, 0xf404cb7b, 0xe6232ec3, 0x22da8906, + 0x0cb348ff, 0x0da6349d, 0x7c858b98, 0xd9b258f1, + 0x623c9dd4, 0x8493c626, 0x91551f3b, 0x6ed97a53, + 0xb5a10c32, 0x23d39f3e, 0x57e7da04, 0x8f0b2689, + 0xebb54529, 0x0f015572, 0x2f4db833, 0x407e1d2b, + 0xfd815f1a, 0xdeacbb64, 0xe8c38859, 0xde04110b, + 0xb6c901ab, 0x153aee1a, 0x6b5af720, 0xc3bfe796, + 0x8b412bc7, 0xe8cbe167, 0x60d83df2, 0x35506981, + 0x2b8f1fc7, 0x311029cf, 0xf46fad6e, 0x7440056b, + 0x61df9779, 0x693d02da, 0xe7d93ccc, 0x861bd3d3, + 0xad0b85a0, 0x8bcd277a, 0xb72fceb7, 0x8ca5d84f, + 0xc0847150, 0x1bd88428, 0x4673ca0d, 0xb030dbe5, + 0xb51c06c1, 0x642baffb, 0xccb5043b, 0xb84aebcb, + 0xbcd80352, 0x385520d6, 0x3b4518aa, 0xfed91bbe, + 0x95f68932, 0x3a10ae0e, 0xd733aeaf, 0xf9f85ba7, + 0x978ac3d1, 0x6a64540c, 0xc5a1575c, 0xc2adcd2b, + 0xc3d45465, 0x47671f05, 0x8542fff3, 0x0f528f92, + 0x3da8b9cd, 0x13e96928, 0x0ae5cb86, 0x55602423, + 0x1acfb022, 0x68c9f16b, 0xbebc28a5, 0xb1d1d15e, + 0xa9f54130, 0x0ebb0b93, 0xaf3ffdb9, 0x52078aad, + 0xb3bf2160, 0xfb4d9d05, 0xe32785a3, 0xd05a87e5, + 0x688e68a5, 0x38840376, 0x9b46ac8d, 0x23f286fd, + +}; + diff --git a/build/libraries/mi/ARM9/Makefile b/build/libraries/mi/ARM9/Makefile index 23dc414c..f9f594c1 100644 --- a/build/libraries/mi/ARM9/Makefile +++ b/build/libraries/mi/ARM9/Makefile @@ -16,38 +16,39 @@ # $Author:$ #---------------------------------------------------------------------------- -SUBDIRS = -SUBMAKES = +SUBDIRS = +SUBMAKES = #---------------------------------------------------------------------------- # build ARM & THUMB libraries -FIRM_CODEGEN_ALL ?= TRUE +FIRM_CODEGEN_ALL ?= TRUE -SRCDIR = . +SRCDIR = . ../common -SRCS = \ - mi_init_mainMemory.c \ - mi_loader.c \ +SRCS = \ + mi_init_mainMemory.c \ + mi_loader.c \ + mi_exDma.c \ -TARGET_LIB = libmi$(FIRM_LIBSUFFIX).a +TARGET_LIB = libfirm_mi$(FIRM_LIBSUFFIX).a include $(TWLFIRM_ROOT)/build/buildtools/commondefs -INSTALL_TARGETS = $(TARGETS) -INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) ifdef NITRO_CALLTRACE -CCFLAGS += -DOS_PROFILE_AVAILABLE -DOS_PROFILE_CALL_TRACE +CCFLAGS += -DOS_PROFILE_AVAILABLE -DOS_PROFILE_CALL_TRACE endif ifdef NITRO_FUNCTIONCOST -CCFLAGS += -DOS_PROFILE_AVAILABLE -DOS_PROFILE_FUNCTION_COST +CCFLAGS += -DOS_PROFILE_AVAILABLE -DOS_PROFILE_FUNCTION_COST endif ifdef NITRO_TCM_APPLY -CCFLAGS += -DSDK_TCM_APPLY +CCFLAGS += -DSDK_TCM_APPLY endif #---------------------------------------------------------------------------- diff --git a/build/libraries/mi/common/mi_exDma.c b/build/libraries/mi/common/mi_exDma.c new file mode 100644 index 00000000..5fab0b03 --- /dev/null +++ b/build/libraries/mi/common/mi_exDma.c @@ -0,0 +1,286 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - mi + File: mi_init_mainMemory.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 + +static u16 intervalTable[] = +{ + 1, 1, 1, 1, +}; + +static u32 prescaleTable[] = +{ + MI_NDMA_INTERVAL_PS_1, + MI_NDMA_INTERVAL_PS_1, + MI_NDMA_INTERVAL_PS_1, + MI_NDMA_INTERVAL_PS_1, +}; + +//================================================================================ +// memory oparation using DMA (sync) +//================================================================================ + +/*---------------------------------------------------------------------------* + Name: MIi_ExDmaSendAsync + + Description: send data with DMA + async version + + Arguments: dmaNo : DMA channel No. + dest : destination address + src : source address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_ExDmaSendAsync( u32 dmaNo, const void *src, void *dest, u32 size ) +{ + u32 idx = dmaNo - MI_EXDMA_CH_MIN; + + { + u32 blockSize = MI_NDMA_BWORD_8; + u32 interval = intervalTable[idx]; + u32 prescale = prescaleTable[idx]; + + MIi_ExDmaSendAsyncCore( dmaNo, src, dest, size, size, + blockSize, interval, prescale, + MI_NDMA_CONTINUOUS_OFF, MI_NDMA_SRC_RELOAD_DISABLE, MI_NDMA_DEST_RELOAD_DISABLE, + MI_NDMA_IMM_MODE_ON ); + } +} + +/*---------------------------------------------------------------------------* + Name: MIi_ExDmaRecvAsync + + Description: receive data with DMA + async version + + Arguments: dmaNo : DMA channel No. + dest : destination address + src : source address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_ExDmaRecvAsync( u32 dmaNo, const void *src, void *dest, u32 size ) +{ + u32 idx = dmaNo - MI_EXDMA_CH_MIN; + + { + u32 blockSize = MI_NDMA_BWORD_8; + u32 interval = intervalTable[idx]; + u32 prescale = prescaleTable[idx]; + + MIi_ExDmaRecvAsyncCore( dmaNo, src, dest, size, size, + blockSize, interval, prescale, + MI_NDMA_CONTINUOUS_OFF, MI_NDMA_SRC_RELOAD_DISABLE, MI_NDMA_DEST_RELOAD_DISABLE, + MI_NDMA_IMM_MODE_ON ); + } +} + +//----------------- internel functions ------------------- + +/*---------------------------------------------------------------------------* + Name: MIi_ExDmaSendAsyncCore + + Description: send data with DMA + async version + + Arguments: dmaNo : DMA channel No. + dest : destination address + src : source address + size : size (byte) + blockSize : block size + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_ExDmaSendAsyncCore( u32 dmaNo, const void *src, void *dest, u32 size, u32 oneShotSize, + u32 blockSize, u32 interval, u32 prescale, + u32 continuous, u32 srcRld, u32 destRld, + u32 timing ) +{ + MIi_WaitExDma( dmaNo ); + + MIi_SetExDmaParams( dmaNo, src, dest, size, oneShotSize, + blockSize, interval, prescale, + continuous, srcRld, destRld, + timing, + 0, MI_NDMA_SRC_INC, MI_NDMA_DEST_FIX ); +} + +/*---------------------------------------------------------------------------* + Name: MIi_ExDmaRecvAsyncCore + + Description: receive data with DMA + async version + + Arguments: dmaNo : DMA channel No. + dest : destination address + src : source address + size : size (byte) + blockSize : block size + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_ExDmaRecvAsyncCore( u32 dmaNo, const void *src, void *dest, u32 size, u32 oneShotSize, + u32 blockSize, u32 interval, u32 prescale, + u32 continuous, u32 srcRld, u32 destRld, + u32 timing ) +{ + MIi_WaitExDma( dmaNo ); + + MIi_SetExDmaParams( dmaNo, src, dest, size, oneShotSize, + blockSize, interval, prescale, + continuous, srcRld, destRld, + timing, + 0, MI_NDMA_SRC_FIX, MI_NDMA_DEST_INC ); +} + +/*---------------------------------------------------------------------------* + Name: MIi_SetExDmaParams + + Description: set DMA + + Arguments: dmaNo : DMA channel No. + dest : destination address + src : source address + size : size (byte) + blockSize : block size + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_SetExDmaParams( u32 dmaNo, const void *src, void *dest, u32 size, u32 oneShotSize, + u32 blockSize, u32 interval, u32 prescale, + u32 continuous, u32 srcRld, u32 destRld, + u32 timing, + u32 fillData, u32 srcDir, u32 destDir ) +{ + u32 idx = dmaNo - MI_EXDMA_CH_MIN; + + if ( idx < MI_EXDMA_CH_NUM ) + { + OSIntrMode enabled = OS_DisableInterrupts(); + + MIExDmaChanRegs *reg = &((MIExDmaChanRegs*)REG_NDMA0SAD_ADDR)[idx]; + + reg->src = src; + reg->dest = dest; + reg->fillData = fillData; + reg->totalCount = size / 4; + reg->wordCount = oneShotSize / 4; + reg->blockInterval = (interval << REG_MI_NDMA0BCNT_ICNT_SHIFT) | prescale; + reg->ctrl = blockSize + | srcDir | destDir + | srcRld | destRld + | continuous + | timing + | MI_NDMA_ENABLE | MI_NDMA_IF_ENABLE; + + (void)OS_RestoreInterrupts(enabled); + } +} + +//================================================================================ +// DMA WAIT/STOP +//================================================================================ +/*---------------------------------------------------------------------------* + Name: MIi_IsExDmaBusy + + Description: check whether extended DMA is busy or not + + Arguments: dmaNo : DMA channel No. + + Returns: TRUE if extended DMA is busy, FALSE if not + *---------------------------------------------------------------------------*/ +BOOL MIi_IsExDmaBusy( u32 dmaNo ) +{ + u32 idx = dmaNo - MI_EXDMA_CH_MIN; + + if ( idx < MI_EXDMA_CH_NUM ) + { + MIExDmaChanRegs *reg = &((MIExDmaChanRegs*)REG_NDMA0SAD_ADDR)[idx]; + + return (BOOL)((reg->ctrl & REG_MI_NDMA0CNT_E_MASK) >> REG_MI_NDMA0CNT_E_SHIFT); + } + + return FALSE; +} + +/*---------------------------------------------------------------------------* + Name: MIi_WaitExDma + + Description: wait while extended DMA is busy + + Arguments: dmaNo : DMA channel No. + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_WaitExDma( u32 dmaNo ) +{ + u32 idx = dmaNo - MI_EXDMA_CH_MIN; + + if ( idx < MI_EXDMA_CH_NUM ) + { + MIExDmaChanRegs *reg = &((MIExDmaChanRegs*)REG_NDMA0SAD_ADDR)[idx]; + + while (reg->ctrl & REG_MI_NDMA0CNT_E_MASK) + { + } + } +} + +/*---------------------------------------------------------------------------* + Name: MIi_StopDma + + Description: stop extended DMA + + Arguments: dmaNo : DMA channel No. + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_StopExDma( u32 dmaNo ) +{ + MIi_StopExDmaAsync( dmaNo ); + MIi_WaitExDma( dmaNo ); +} + +/*---------------------------------------------------------------------------* + Name: MIi_StopDmaAsync + + Description: stop extended DMA + async version + + Arguments: dmaNo : DMA channel No. + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_StopExDmaAsync( u32 dmaNo ) +{ + OSIntrMode enabled = OS_DisableInterrupts(); + + u32 idx = dmaNo - MI_EXDMA_CH_MIN; + + if ( idx < MI_EXDMA_CH_NUM ) + { + MIExDmaChanRegs *reg = &((MIExDmaChanRegs*)REG_NDMA0SAD_ADDR)[idx]; + + reg->ctrl &= ~MI_NDMA_ENABLE; + } + + (void)OS_RestoreInterrupts(enabled); +} + diff --git a/build/libraries/os/ARM9/os_cache_tag.c b/build/libraries/os/ARM9/os_cache_tag.c index 3ea8a89d..cb16308a 100644 --- a/build/libraries/os/ARM9/os_cache_tag.c +++ b/build/libraries/os/ARM9/os_cache_tag.c @@ -11,10 +11,10 @@ in whole or in part, without the prior written consent of Nintendo. $Date:: $ - $Rev:$ - $Author:$ + $Rev$ + $Author$ *---------------------------------------------------------------------------*/ -#include +#include #include diff --git a/build/libraries/os/common/os_boot.c b/build/libraries/os/common/os_boot.c index c8282322..103efb1a 100644 --- a/build/libraries/os/common/os_boot.c +++ b/build/libraries/os/common/os_boot.c @@ -18,7 +18,7 @@ #include #include #ifdef SDK_ARM9 -#include +#include #else #include #endif diff --git a/include/firm/gcd/gcd.h b/include/firm/gcd/gcd.h index 1a83e781..c9106759 100644 --- a/include/firm/gcd/gcd.h +++ b/include/firm/gcd/gcd.h @@ -765,6 +765,11 @@ 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" */ diff --git a/include/firm/gcd/gcd_misc.h b/include/firm/gcd/gcd_misc.h index 3401eab0..4b3da84f 100644 --- a/include/firm/gcd/gcd_misc.h +++ b/include/firm/gcd/gcd_misc.h @@ -26,24 +26,67 @@ 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_PC_SHIFT, - GCD_PAGE_1 = 0x1UL << REG_MI_MCCNT1_PC_SHIFT, - GCD_PAGE_2 = 0x2UL << REG_MI_MCCNT1_PC_SHIFT, - GCD_PAGE_4 = 0x3UL << REG_MI_MCCNT1_PC_SHIFT, - GCD_PAGE_8 = 0x4UL << REG_MI_MCCNT1_PC_SHIFT, - GCD_PAGE_16 = 0x5UL << REG_MI_MCCNT1_PC_SHIFT, - GCD_PAGE_32 = 0x6UL << REG_MI_MCCNT1_PC_SHIFT, - GCD_PAGE_STAT = 0x7UL << REG_MI_MCCNT1_PC_SHIFT + 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_CT_SHIFT, - GCD_CKT_240NS = 0x1UL << REG_MI_MCCNT1_CT_SHIFT + GCD_CKT_150NS = 0x0UL << REG_MI_MCCNT1_A_CT_SHIFT, + GCD_CKT_240NS = 0x1UL << REG_MI_MCCNT1_A_CT_SHIFT } GCDClockType; @@ -56,15 +99,20 @@ GCDRw; typedef enum { - GCD_RESET_LO = 0x0UL << REG_MI_MCCNT1_RESB_SHIFT, - GCD_RESET_HI = 0x1UL << REG_MI_MCCNT1_RESB_SHIFT + GCD_RESET_LO = 0x0UL << REG_MI_MCCNT1_A_RESB_SHIFT, + GCD_RESET_HI = 0x1UL << REG_MI_MCCNT1_A_RESB_SHIFT } GCDReset; typedef enum { - GCD_LTCK_DISABLE = 0x0UL << REG_MI_MCCNT1_TRM_SHIFT, - GCD_LTCK_ENABLE = 0x1UL << REG_MI_MCCNT1_TRM_SHIFT +#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; @@ -76,7 +124,6 @@ typedef struct } NGCDCtrlRegs; - // PXIでの通信プロトコル関連定義 #define GCD_PXI_COMMAND_MASK 0x0000003f // 開始ワードのコマンド部 #define GCD_PXI_COMMAND_SHIFT 0 @@ -286,8 +333,8 @@ void GCDi_Disable( GCDSlot slot ); static inline BOOL GCD_IsExisting( GCDSlot slot ) { s32 ofs = (GCD_GetPrimarySlot() ^ slot) * 4; - s32 r = ~reg_MI_MC_DET & (REG_MI_MC_DET_DET1_MASK << ofs); - return r >> (REG_MI_MC_DET_DET1_SHIFT + ofs); + s32 r = ~reg_MI_MC_DET & (REG_MI_MC_SL1_CDET_MASK << ofs); + return r >> (REG_MI_MC_SL1_CDET_SHIFT + ofs); } /*---------------------------------------------------------------------------* @@ -302,8 +349,8 @@ static inline BOOL GCD_IsExisting( GCDSlot slot ) static inline void GCD_SetDetectMode( GCDSlot slot, u32 mode ) { s32 ofs = (GCD_GetPrimarySlot() ^ slot) * 4; - s32 others = reg_MI_MC_DET & ~(REG_MI_MC_DET_MODE1_MASK << ofs); - reg_MI_MC_DET = (u8)((mode << (REG_MI_MC_DET_MODE1_SHIFT + ofs)) | others); + 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); } /*---------------------------------------------------------------------------* @@ -318,8 +365,8 @@ static inline void GCD_SetDetectMode( GCDSlot slot, u32 mode ) static inline u8 GCD_GetDetectMode( GCDSlot slot ) { s32 ofs = (GCD_GetPrimarySlot() ^ slot) * 4; - return (u8)((reg_MI_MC_DET & (REG_MI_MC_DET_MODE1_MASK << ofs)) - >> (REG_MI_MC_DET_MODE1_SHIFT + ofs)); + return (u8)((reg_MI_MC_DET & (REG_MI_MC_SL1_MODE_MASK << ofs)) + >> (REG_MI_MC_SL1_MODE_SHIFT + ofs)); } /*---------------------------------------------------------------------------* @@ -333,7 +380,7 @@ static inline u8 GCD_GetDetectMode( GCDSlot slot ) *---------------------------------------------------------------------------*/ static inline void GCD_SetChatCounter( u16 value ) { - reg_MI_MC_CHT = value; + reg_MI_MCCHAT = value; } /*---------------------------------------------------------------------------* @@ -424,7 +471,7 @@ static inline u32 GCDi_SelectIrqMask( GCDSlot slot, u32 base_mask ) case OS_IE_CARD_IREQ: mask = OS_IE_CARD_B_IREQ; break; - case OS_IE_CARD_DET: + case OS_IE_CARD_A_DET: mask = OS_IE_CARD_B_DET; break; } diff --git a/include/firm/mi.h b/include/firm/mi.h index 427e7927..475c4c18 100644 --- a/include/firm/mi.h +++ b/include/firm/mi.h @@ -20,6 +20,7 @@ #include +#include #include #ifdef SDK_ARM9 #include diff --git a/include/firm/mi/exDma.h b/include/firm/mi/exDma.h new file mode 100644 index 00000000..38d8ec16 --- /dev/null +++ b/include/firm/mi/exDma.h @@ -0,0 +1,203 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - mi + File: exDma.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:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef TWL_MI_EXDMA_H_ +#define TWL_MI_EXDMA_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +//---------------------------------------------------------------------- + +//---- registers +typedef struct +{ + const void * src; + void * dest; + u32 totalCount; + u32 wordCount; + u32 blockInterval; + u32 fillData; + u32 ctrl; +} +t_MIExDmaChanRegs; + +typedef volatile t_MIExDmaChanRegs MIExDmaChanRegs; + + +//================================================================================ +// DMA control definition +//================================================================================ +//---- DMA channel No. +#define MI_EXDMA_CH_MIN 4 +#define MI_EXDMA_CH_MAX 7 + +#define MI_EXDMA_CH_NUM 4 + + +//================================================================================ +// DMA WAIT +//================================================================================ +/*---------------------------------------------------------------------------* + Name: MIi_IsExDmaBusy + + Description: check whether extended DMA is busy or not + + Arguments: dmaNo : DMA channel No. + + Returns: TRUE if extended DMA is busy, FALSE if not + *---------------------------------------------------------------------------*/ +BOOL MIi_IsExDmaBusy( u32 dmaNo ); + +/*---------------------------------------------------------------------------* + Name: MIi_WaitExDma + + Description: wait while extended DMA is busy + + Arguments: dmaNo : DMA channel No. + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_WaitExDma( u32 dmaNo ); + +/*---------------------------------------------------------------------------* + Name: MIi_StopExDma + + Description: stop extended DMA + + Arguments: dmaNo : DMA channel No. + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_StopExDma( u32 dmaNo ); + +/*---------------------------------------------------------------------------* + Name: MIi_StopDmaAsync + + Description: stop extended DMA + async version + + Arguments: dmaNo : DMA channel No. + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_StopExDmaAsync( u32 dmaNo ); + +//================================================================================ +// memory operation using DMA +//================================================================================ +/*---------------------------------------------------------------------------* + Name: MIi_ExDmaSendAsync + + Description: send data with DMA + sync version + + Arguments: dmaNo : DMA channel No. + dest : destination address + src : source address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_ExDmaSendAsync( u32 dmaNo, const void *src, void *dest, u32 size ); + +/*---------------------------------------------------------------------------* + Name: MIi_ExDmaRecvAsync + + Description: receive data with DMA + sync version + + Arguments: dmaNo : DMA channel No. + dest : destination address + src : source address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_ExDmaRecvAsync( u32 dmaNo, const void *src, void *dest, u32 size ); + +//----------------- internel functions ------------------- +/*---------------------------------------------------------------------------* + Name: MIi_ExDmaSendAsyncCore + + Description: send data with DMA + async version + + Arguments: dmaNo : DMA channel No. + dest : destination address + src : source address + size : size (byte) + blockSize : block size + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_ExDmaSendAsyncCore( u32 dmaNo, const void *src, void *dest, u32 size, u32 oneShotSize, + u32 blockSize, u32 interval, u32 prescale, + u32 continuous, u32 srcRld, u32 destRld, + u32 timing ); + +/*---------------------------------------------------------------------------* + Name: MIi_ExDmaRecvAsyncCore + + Description: receive data with DMA + async version + + Arguments: dmaNo : DMA channel No. + dest : destination address + src : source address + size : size (byte) + blockSize : block size + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_ExDmaRecvAsyncCore( u32 dmaNo, const void *src, void *dest, u32 size, u32 oneShotSize, + u32 blockSize, u32 interval, u32 prescale, + u32 continuous, u32 srcRld, u32 destRld, + u32 timing ); + +/*---------------------------------------------------------------------------* + Name: MIi_SetExDmaParams + + Description: set DMA + + Arguments: dmaNo : DMA channel No. + dest : destination address + src : source address + size : size (byte) + blockSize : block size + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_SetExDmaParams( u32 dmaNo, const void *src, void *dest, u32 size, u32 oneShotSize, + u32 blockSize, u32 interval, u32 prescale, + u32 continuous, u32 srcRld, u32 destRld, + u32 timing, + u32 fillData, u32 srcDir, u32 destDir); + + +#ifdef __cplusplus +} /* extern "C" */ + +#endif + +/* TWL_MI_EXDMA_H_ */ +#endif diff --git a/include/firm/os.h b/include/firm/os.h index 9ae3c6bb..83cf04b1 100644 --- a/include/firm/os.h +++ b/include/firm/os.h @@ -18,13 +18,12 @@ #ifndef FIRM_OS_H_ #define FIRM_OS_H_ -#include - #include #include #include #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/include/firm/os/common/systemCall.h b/include/firm/os/common/systemCall.h index 5525240a..37c693d7 100644 --- a/include/firm/os/common/systemCall.h +++ b/include/firm/os/common/systemCall.h @@ -18,8 +18,6 @@ #ifndef FIRM_OS_SYSTEMCALL_H_ #define FIRM_OS_SYSTEMCALL_H_ -#include - #ifdef __cplusplus extern "C" { #endif @@ -86,6 +84,67 @@ typedef enum } OSSvcID; +int SVC_InitSignHeap( + int acmemory_pool[3], + void* heap, + unsigned int length + ); + +int SVC_DecryptoRSA( + const void* acmemory_pool, + const void* pData, + unsigned int* len // 出力サイズ + ); + +int SVC_DecryptoSign( + const void* acmemory_pool, + void* buffer, // 出力領域 + const void* sgn_ptr, // データへのポインタ + const void* key_ptr // キーへのポインタ + ); + +int SVC_DecryptoSignDER( + const void* acmemory_pool, + void* buffer, // 出力領域 + const void* sgn_ptr, // データへのポインタ + const void* key_ptr // キーへのポインタ + ); + +void SVC_SHA1Init( void *c ); +void SVC_SHA1Update( void *c, const unsigned char *data, unsigned long len ); +void SVC_SHA1GetHash( unsigned char *md, void *c ); + +int SVC_CalcSHA1( + void* buffer, // 出力領域 + const void* buf, // データへのポインタ + unsigned int len // データの長さ + ); + +int SVC_CompareSHA1( + const void* decedHash, // SVC_Decrypto*の出力 + const void* digest // SVC_GetDigestの出力 + ); + +int SVC_RandomSHA1( + void* dest_ptr, // 出力データへのポインタ + unsigned int dest_len, // 出力データの長さ + const void* src_ptr, // 入力データへのポインタ + unsigned int src_len // 入力データの長さ + ); + +int SVC_UncompressLZ8FromDevice( const void* srcp, + void* destp, + const void* paramp, + const MIReadStreamCallbacks *callbacks + ); + +int SVC_UncompressLZ16FromDeviceIMG( const void* srcp, + void* destp, + const void* paramp, + const MIReadStreamCallbacks *callbacks + ); + + #ifdef __cplusplus } /* extern "C" */ diff --git a/include/twl/os/ARM9/os_cache_tag.h b/include/twl/os/ARM9/os_cache_tag.h deleted file mode 100644 index 4d877566..00000000 --- a/include/twl/os/ARM9/os_cache_tag.h +++ /dev/null @@ -1,151 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlFirm - OS - include - File: os_cache_tag.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:: $ - $Rev:$ - $Author:$ - *---------------------------------------------------------------------------*/ - -#ifndef TWL_OS_CACHE_TAG_H_ -#define TWL_OS_CACHE_TAG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -//=========================================================================== -// DATA CACHE (for specified range) -//=========================================================================== -/*---------------------------------------------------------------------------* - Name: DC_ClearTagAll - - Description: clear tag in data cache - - Arguments: None - - Returns: None. - *---------------------------------------------------------------------------*/ -void DC_ClearTagAll( void ); - -/*---------------------------------------------------------------------------* - Name: DC_ClearDataAll - - Description: clear data in data cache - - Arguments: None - - Returns: None. - *---------------------------------------------------------------------------*/ -void DC_ClearDataAll( void ); - -/*---------------------------------------------------------------------------* - Name: DC_FillTagAll - - Description: clear tag in data cache - - Arguments: data : fill data - - Returns: None. - *---------------------------------------------------------------------------*/ -void DC_FillTagAll( u32 data ); - -/*---------------------------------------------------------------------------* - Name: DC_FillDataAll - - Description: fill data in data cache - - Arguments: data : fill data - - Returns: None. - *---------------------------------------------------------------------------*/ -void DC_FillDataAll( u32 data ); - -/*---------------------------------------------------------------------------* - Name: DC_GetTagAndDataAll - - Description: get tag and data in data cache - - Arguments: tag tag address - data data address - - Returns: None. - *---------------------------------------------------------------------------*/ -void DC_GetTagAndDataAll( void* tag, void* data ); - -//=========================================================================== -// INSTRUCTION CACHE -//=========================================================================== -/*---------------------------------------------------------------------------* - Name: IC_ClearTagAll - - Description: clear tag in instruction cache - - Arguments: None - - Returns: None. - *---------------------------------------------------------------------------*/ -void IC_ClearTagAll( void ); - -/*---------------------------------------------------------------------------* - Name: IC_ClearInstructionAll - - Description: clear instruction in instruction cache - - Arguments: None - - Returns: None. - *---------------------------------------------------------------------------*/ -void IC_ClearInstructionAll( void ); - -/*---------------------------------------------------------------------------* - Name: IC_FillTagAll - - Description: fill tag in instruction cache - - Arguments: None - - Returns: None. - *---------------------------------------------------------------------------*/ -void IC_FillTagAll( u32 data ); - -/*---------------------------------------------------------------------------* - Name: IC_FillInstructionAll - - Description: fill instruction in instruction cache - - Arguments: data : fill data - - Returns: None. - *---------------------------------------------------------------------------*/ -void IC_FillInstructionAll( u32 data ); - -/*---------------------------------------------------------------------------* - Name: IC_GetTagAndInstructionAll - - Description: get tag and instruction in instruction cache - - Arguments: tag tag address - inst instruction address - - Returns: None. - *---------------------------------------------------------------------------*/ -void IC_GetTagAndInstructionAll( void* tag, void* inst ); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -/* TWL_OS_CACHE_TAG_H_ */ -#endif diff --git a/include/twl/os/common/systemCall.h b/include/twl/os/common/systemCall.h deleted file mode 100644 index be7d156a..00000000 --- a/include/twl/os/common/systemCall.h +++ /dev/null @@ -1,93 +0,0 @@ -/*---------------------------------------------------------------------------* - Project: TwlSDK - OS - include - File: systemCall.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 TWL_OS_SYSTEMCALL_H_ -#define TWL_OS_SYSTEMCALL_H_ - - -#ifdef __cplusplus -extern "C" { -#endif - -int SVC_InitSignHeap( - int acmemory_pool[3], - void* heap, - unsigned int length - ); - -int SVC_DecryptoRSA( - const void* acmemory_pool, - const void* pData, - unsigned int* len // 出力サイズ - ); - -int SVC_DecryptoSign( - const void* acmemory_pool, - void* buffer, // 出力領域 - const void* sgn_ptr, // データへのポインタ - const void* key_ptr // キーへのポインタ - ); - -int SVC_DecryptoSignDER( - const void* acmemory_pool, - void* buffer, // 出力領域 - const void* sgn_ptr, // データへのポインタ - const void* key_ptr // キーへのポインタ - ); - -void SVC_SHA1Init( void *c ); -void SVC_SHA1Update( void *c, const unsigned char *data, unsigned long len ); -void SVC_SHA1GetHash( unsigned char *md, void *c ); - -int SVC_CalcSHA1( - void* buffer, // 出力領域 - const void* buf, // データへのポインタ - unsigned int len // データの長さ - ); - -int SVC_CompareSHA1( - const void* decedHash, // SVC_Decrypto*の出力 - const void* digest // SVC_GetDigestの出力 - ); - -int SVC_RandomSHA1( - void* dest_ptr, // 出力データへのポインタ - unsigned int dest_len, // 出力データの長さ - const void* src_ptr, // 入力データへのポインタ - unsigned int src_len // 入力データの長さ - ); - -int SVC_UncompressLZ8FromDevice( const void* srcp, - void* destp, - const void* paramp, - const MIReadStreamCallbacks *callbacks - ); - -int SVC_UncompressLZ16FromDeviceIMG( const void* srcp, - void* destp, - const void* paramp, - const MIReadStreamCallbacks *callbacks - ); - - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -/* TWL_OS_SYSTEMCALL_H_ */ -#endif