diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..2248c351 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - build +# 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-11-21#$ +# $Rev: 237 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- +export TWL_ARCHGEN = ALL + +SUBDIRS = \ + build + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/Makefile.full b/Makefile.full new file mode 100644 index 00000000..b586c89b --- /dev/null +++ b/Makefile.full @@ -0,0 +1,37 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - build +# File: Makefile.full +# +# 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 $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- +export TWL_ARCHGEN = ALL + +SUBDIRS = \ + $(ROOT)/build/libraries/reboot \ + $(ROOT)/build/demos/gx/UnitTours/DEMOLib \ + $(TWLSYSTEM_ROOT) \ + build + + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/Makefile.sysmenu b/Makefile.sysmenu new file mode 100644 index 00000000..e4a6f97e --- /dev/null +++ b/Makefile.sysmenu @@ -0,0 +1,35 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - build +# File: Makefile.sysmenu +# +# 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 $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- +export TWL_ARCHGEN = ALL + +SUBDIRS = \ + build/libraries_sysmenu\ + build/components \ + build/systemmenu_RED + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/add-ins/TwlSystem/NitroSystem_patch.zip b/add-ins/TwlSystem/NitroSystem_patch.zip new file mode 100644 index 00000000..4eb1525b Binary files /dev/null and b/add-ins/TwlSystem/NitroSystem_patch.zip differ diff --git a/add-ins/TwlSystem/使用方法.txt b/add-ins/TwlSystem/使用方法.txt new file mode 100644 index 00000000..2572dc4d --- /dev/null +++ b/add-ins/TwlSystem/使用方法.txt @@ -0,0 +1,25 @@ +--------------- +̃pb`͎bIȂ NitroSystem +TWL-SDK Ńrh/gpł悤ɂ̂łB +Yt zip t@CWJ NitroSystem ɏ㏑ĂB + + +ETWLSYSTEM_ROOT ‹ϐ NITROSYSTEM_ROOT ‹ϐ +@lݒ肷Kv܂B +ENitroSystem ̓rhȂKv܂B +Esnd, mcs Cu͎gpł܂B +Edemo ͂̂܂܂ł̓rhł܂B +@TWL-SDK ł nef tef ֕ύXꂽ +@TARGET_NEF ݒ肳Ă͍̂폜Kv܂B +---- + + +demõrhʂ@ + +LLIBRARY_DIRS = $(G2D_DEMOLIB)/lib/$(NITRO_BUILDTYPE) + +LLIBRARY_DIRS = $(G2D_DEMOLIB)/$(LIBDIR) + + +TARGET_NEF = main.nef@폜B + diff --git a/build/Makefile b/build/Makefile new file mode 100644 index 00000000..fc4cb349 --- /dev/null +++ b/build/Makefile @@ -0,0 +1,42 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - build +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + tools \ + libraries \ + nandfirm \ + libraries_sysmenu\ + components \ + systemmenu_RED \ + gcdfirm \ + +ifdef TWL_IPL_WITH_TESTS +SUBDIRS += tests +endif + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/buildtools/commondefs b/build/buildtools/commondefs new file mode 100644 index 00000000..98c45b61 --- /dev/null +++ b/build/buildtools/commondefs @@ -0,0 +1,35 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - commondefs - common definitions for build system +# File: commondefs +# +# 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_IPL_COMMONDEFS_ +TWL_IPL_COMMONDEFS_ = TRUE + +FIRM_USE_TWLSDK_KEYS = TRUE + +ifeq ($(TARGET_FIRM),SYSTEMMENU) +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs.sysmenu +else +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs.firm +endif + +ifdef FIRM_USE_TWLSDK_KEYS +MACRO_FLAGS += -DFIRM_USE_TWLSDK_KEYS=$(FIRM_USE_TWLSDK_KEYS) +endif + +#---------------------------------------------------------------------------- +endif # TWL_IPL_COMMONDEFS_ +#----- End of commondefs ----- diff --git a/build/buildtools/commondefs.firm b/build/buildtools/commondefs.firm new file mode 100644 index 00000000..7ca5d5d5 --- /dev/null +++ b/build/buildtools/commondefs.firm @@ -0,0 +1,144 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - commondefs - common definitions for build system +# File: commondefs +# +# 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 TWLFIRM_COMMONDEFS_ +TWLFIRM_COMMONDEFS_ = TRUE + +EMPTY ?= +SPACE ?= $(EMPTY) $(EMPTY) + +ifndef TWL_KEYSDIR +DUMMY_KEYS_SUFFIX = .dummykey +endif +TWL_KEYSDIR ?= $(FIRM_ROOT)/keys/dummy + +TARGET_BIN ?= $(subst .,$(DUMMY_KEYS_SUFFIX).,$(TARGET_FIRM_BIN)) + +# +# change default variables for product +# +override TARGET_PLATFORM := TWL +override TWL_ARCHGEN := LIMITED +override TWL_MEMSIZE := 16M + +#---------------------------------------------------------------------------- +### TWL-commondefs +# +include $(TWLSDK_ROOT)/build/buildtools/commondefs +include $(TWLSDK_ROOT)/build/libraries/reboot/commondefs.reboot + +#---------------------------------------------------------------------------- +# TWL-FIRM path settings +# + +FIRM_ROOT := $(call eupath,$(TWL_IPL_RED_ROOT)) +FIRM_BUILDTOOLSDIR := $(FIRM_ROOT)/build/buildtools +FIRM_BUILDSETUPDIR := $(FIRM_ROOT)/build/buildsetup +FIRM_INCDIR := $(FIRM_ROOT)/include +FIRM_TOOLSDIR := $(FIRM_ROOT)/tools +FIRM_COMPONENTSDIR := $(FIRM_ROOT)/components +FIRM_ADDINS ?= $(FIRM_ROOT)/add-ins + +FIRM_LIBDIR = $(FIRM_ROOT)/lib/$(TWL_LIBTYPE) +FIRM_LIBSUFFIX = .firm$(ARCHGEN_TYPE)$(CODEGEN_ARCH) + +FIRM_SPECDIR := $(FIRM_INCDIR)/firm/specfiles +FIRM_LSFARCH = $(TWL_LIBARCH)-FIRM +FIRM_LCFARCH = $(FIRM_LSFARCH) +DEFAULT_FIRM_LCFILE = $(FIRM_SPECDIR)/$(FIRM_LCFARCH).lcf +DEFAULT_FIRM_LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(FIRM_LCFARCH).lcf.template +DEFAULT_FIRM_LCFILE_SPEC = $(FIRM_SPECDIR)/$(FIRM_LSFARCH).lsf +DEFAULT_FIRM_ROM_SPEC = $(FIRM_SPECDIR)/ROM-$(TWL_PLATFORM)-FIRM.rsf + +### Compiler & Linker settings + +# replace NitroSDK +DEFAULT_LCFILE_TEMPLATE = $(DEFAULT_FIRM_LCFILE_TEMPLATE) +DEFAULT_LCFILE_SPEC = $(DEFAULT_FIRM_LCFILE_SPEC) +DEFAULT_ROM_SPEC = $(DEFAULT_FIRM_ROM_SPEC) + +LDEPENDS_LCF += $(FIRM_BUILDTOOLSDIR)/commondefs +LDEPENDS_RES += $(FIRM_BUILDTOOLSDIR)/commondefs + +### SDK Library settings + +ifeq ($(CODEGEN_PROC),ARM9) + +FIRM_LIBS_BASE ?= \ + libos \ + libpxi \ + libfs \ + libfatfs \ + libmi \ + +else # ($(CODEGEN_PROC),ARM7) + +FIRM_LIBS_BASE ?= \ + libos_sp \ + libpxi_sp \ + libfs_sp \ + libaes_sp \ + libpm_sp \ + +endif + +FIRM_LIBS ?= $(addsuffix $(FIRM_LIBSUFFIX).a,$(FIRM_LIBS_BASE)) + +#---------------------------------------------------------------------------- +# MY BUILD TOOLS +# +MAKENORFIRM := $(FIRM_TOOLSDIR)/bin/makenorfirm.exe +MAKENANDFIRM := $(FIRM_TOOLSDIR)/bin/makenandfirm.exe +MAKEGCDFIRM := $(FIRM_TOOLSDIR)/bin/makegcdfirm.exe +OPENSSL := $(FIRM_TOOLSDIR)/openssl/openssl.exe +NTEXCONV := $(ROOT)/tools/bin/ntexconv.exe +MAKEBANNER := $(FIRM_TOOLSDIR)/bin/makebanner.exe + +MAKEFIRM_RSA_PRVKEY ?= $(FIRM_TOOLSDIR)/openssl/rsa_private.der +MAKEFIRM_RSA_PUBKEY ?= $(FIRM_TOOLSDIR)/openssl/rsa_public.der + +MAKEFIRM_FLAGS ?= + +#---------------------------------------------------------------------------- + +### Global Library resettings + +GINCLUDES := $(FIRM_INCDIR) $(GINCLUDES) +GLIBRARY_DIRS := $(FIRM_LIBDIR) $(GLIBRARY_DIRS) +GLIBRARIES := $(FIRM_LIBS) $(GLIBRARIES) + +#---------------------------------------------------------------------------- +# TWLFIRM_INSTALL_ROOT +# + +ifdef TWLFIRM_INSTALL_ROOT +TWLFIRM_INSTALL_ROOT_ := $(TWLFIRM_INSTALL_ROOT) +else +TWLFIRM_INSTALL_ROOT_ := $(TWL_IPL_RED_ROOT) +endif + +FIRM_INSTALL_ROOT := $(subst $(SPACE),\ ,$(subst \,/,$(TWLFIRM_INSTALL_ROOT_))) +FIRM_INSTALL_INCDIR := $(FIRM_INSTALL_ROOT)/include +FIRM_INSTALL_TOOLSDIR := $(FIRM_INSTALL_ROOT)/tools +FIRM_INSTALL_LIBDIR = $(FIRM_INSTALL_ROOT)/lib/$(TWL_LIBTYPE) +FIRM_INSTALL_PROMDIR := $(FIRM_INSTALL_TOOLSDIR)/prom +FIRM_INSTALL_COMPONENTSDIR := $(FIRM_INSTALL_ROOT)/components +FIRM_INSTALL_ADDINS := $(FIRM_INSTALL_ROOT)/add-ins + +#---------------------------------------------------------------------------- +endif # TWLFIRM_COMMONDEFS_ +#----- End of commondefs ----- diff --git a/build/buildtools/commondefs.sysmenu b/build/buildtools/commondefs.sysmenu new file mode 100644 index 00000000..b838c2fc --- /dev/null +++ b/build/buildtools/commondefs.sysmenu @@ -0,0 +1,129 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - commondefs - common definitions for build system +# File: commondefs +# +# 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_SYSMENU_COMMONDEFS_ +TWL_SYSMENU_COMMONDEFS_ = TRUE + +#SYSMENU_DISABLE_TWL_BOOT = TRUE +#SYSMENU_DISABLE_RETAIL_BOOT = TRUE + +NITRO_NO_STD_PCHDR = TRUE # vRpCwb_}~ + +EMPTY ?= +SPACE ?= $(EMPTY) $(EMPTY) + +TWL_KEYSDIR ?= $(SYSMENU_ROOT)/keys/dummy + +#---------------------------------------------------------------------------- +### TWL-commondefs +# +#include $(TWLSDK_ROOT)/build/buildtools/commondefs +include $(NITROSYSTEM_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- +# TWL-SYSTEM-MENU path settings +# + +#SYSMENU_ROOT := $(subst $(SPACE),\ ,$(subst \,/,$(TWL_IPL_RED_ROOT))) +SYSMENU_ROOT := $(call eupath,$(TWL_IPL_RED_ROOT)) + +SYSMENU_BUILDTOOLSDIR := $(SYSMENU_ROOT)/build/buildtools +SYSMENU_INCDIR := $(SYSMENU_ROOT)/include \ + $(ROOT)/build/libraries/spi/ARM9/include \ + $(ROOT)/build/libraries/mb/common/include +SYSMENU_TOOLSDIR := $(SYSMENU_ROOT)/tools +SYSMENU_COMPONENTSDIR := $(SYSMENU_ROOT)/components + +LDEPENDS_LCF += $(SYSMENU_BUILDTOOLSDIR)/commondefs.sysmenu +LDEPENDS_RES += $(SYSMENU_BUILDTOOLSDIR)/commondefs.sysmenu + + +ifneq ($(TARGET_TAD),) +TARGETS += $(TARGET_TAD) +endif + +#---------------------------------------------------------------------------- +### SYSTEM_MENU Library settings + +SYSMENU_LIBDIR := $(SYSMENU_ROOT)/lib/$(TWL_LIBTYPE) + +ifeq ($(CODEGEN_PROC),ARM9) + +SYSMENU_LIBS ?= \ + liblcfg$(TWL_LIBSUFFIX).a \ + libsysmenu$(TWL_LIBSUFFIX).a \ + libmbloader$(TWL_LIBSUFFIX).a \ + libacsign$(TWL_LIBSUFFIX).a \ + libboot$(TWL_LIBSUFFIX).a \ + +else # ($(CODEGEN_PROC),ARM7) + +SYSMENU_LIBS ?= \ + libsysmenu_sp$(TWL_LIBSUFFIX).a \ + libmbloader_sp$(TWL_LIBSUFFIX).a \ + libboot_sp$(TWL_LIBSUFFIX).a \ + libhotsw_sp$(TWL_LIBSUFFIX).a + +endif + + +#---------------------------------------------------------------------------- +# MY BUILD TOOLS +# +OPENSSL := $(SYSMENU_TOOLSDIR)/openssl/openssl.exe +NTEXCONV := $(ROOT)/tools/bin/ntexconv.exe +MAKEBANNER := $(SYSMENU_TOOLSDIR)/bin/makebanner.exe + +MAKESYSMENU_RSA_PRVKEY ?= $(SYSMENU_TOOLSDIR)/openssl/rsa_private.der +MAKESYSMENU_RSA_PUBKEY ?= $(SYSMENU_TOOLSDIR)/openssl/rsa_public.der + +MAKETAD ?= $(ROOT)/tools/bin/makeTad.pl + +#---------------------------------------------------------------------------- + +### Global Library resettings + +GINCLUDES := $(SYSMENU_INCDIR) $(GINCLUDES) +ifneq ($(ES_ROOT),) +GINCLUDES += $(ES_ROOT)/twl/include +endif +GLIBRARY_DIRS := $(SYSMENU_LIBDIR) $(GLIBRARY_DIRS) +GLIBRARIES := $(SYSMENU_LIBS) $(GLIBRARIES) + +#---------------------------------------------------------------------------- +# TWLSYSMENU_INSTALL_ROOT +# +SYSMENU_INSTALL_ROOT := $(subst $(SPACE),\ ,$(subst \,/,$(TWL_IPL_RED_ROOT))) +SYSMENU_INSTALL_INCDIR := $(SYSMENU_INSTALL_ROOT)/include +SYSMENU_INSTALL_TOOLSDIR := $(SYSMENU_INSTALL_ROOT)/tools +SYSMENU_INSTALL_LIBDIR := $(SYSMENU_INSTALL_ROOT)/lib/$(TWL_LIBTYPE) +SYSMENU_INSTALL_COMPONENTSDIR := $(SYSMENU_INSTALL_ROOT)/components +SDK_NMENU_DATADIR = $(ROOT)/build/tools/TwlNMenu/data + +#---------------------------------------------------------------------------- + +ifdef SYSMENU_DISABLE_TWL_BOOT +MACRO_FLAGS += -DSYSMENU_DISABLE_TWL_BOOT=$(SYSMENU_DISABLE_TWL_BOOT) +endif + +ifdef SYSMENU_DISABLE_RETAIL_BOOT +MACRO_FLAGS += -DSYSMENU_DISABLE_RETAIL_BOOT=$(SYSMENU_DISABLE_RETAIL_BOOT) +endif + +#---------------------------------------------------------------------------- +endif # TWL_SYSMENU_COMMONDEFS_ +#----- End of commondefs ----- diff --git a/build/buildtools/modulerules b/build/buildtools/modulerules new file mode 100644 index 00000000..3d246a4a --- /dev/null +++ b/build/buildtools/modulerules @@ -0,0 +1,34 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - modulerules - common rules for build system +# File: modulerules +# +# 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_IPL_MODULERULES_ + +#---------------------------------------------------------------------------- +### TWL-modulerules +# + +ifeq ($(TARGET_FIRM),SYSTEMMENU) +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules.sysmenu +else +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules.firm +endif + + +#---------------------------------------------------------------------------- +TWL_IPL_MODULERULES_ = TRUE +endif # TWL_IPL_MODULERULES_ +#----- End of modulerules ----- diff --git a/build/buildtools/modulerules.firm b/build/buildtools/modulerules.firm new file mode 100644 index 00000000..8aa7e534 --- /dev/null +++ b/build/buildtools/modulerules.firm @@ -0,0 +1,88 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - modulerules - common rules for build system +# File: modulerules +# +# 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 TWLFIRM_MODULERULES_ + +#---------------------------------------------------------------------------- +### TWL-modulerules +# +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +# +# MAKEROM for IS-TWL-DEBUGGER +# +ifeq ($(filter $(MAKEROM_FLAGS),-F),) +MAKEROM_FLAGS += -F +endif + +# +# MAKENORFIRM / MAKENANDFIRM / MAKEGCDFIRM +# +MAKEFIRM_ARM7 ?= ARM7/bin/$(TWL_BUILDTYPE_ARM7)/main.tef +MAKEFIRM_ARM9 ?= ARM9/bin/$(TWL_BUILDTYPE_ARM9)/main.tef +MAKEFIRM_RSA_PRVKEY ?= $(TWL_KEYSDIR)/rsa/pubkey_nor.der + +MAKEFIRM_ARM7_M := $(call empath,$(MAKEFIRM_ARM7)) +MAKEFIRM_ARM9_M := $(call empath,$(MAKEFIRM_ARM9)) +MAKEFIRM_RSA_PRVKEY_M := $(call empath,$(MAKEFIRM_RSA_PRVKEY)) + +MAKEFIRM_DEFS += -DFIRM_ROOT='$(FIRM_ROOT)' \ + -DMAKEFIRM_ARM9='$(basename $(MAKEFIRM_ARM9_M))' \ + -DMAKEFIRM_ARM7='$(basename $(MAKEFIRM_ARM7_M))' \ + -DMAKEFIRM_RSA_PRVKEY='$(MAKEFIRM_RSA_PRVKEY_M)' \ + +ifdef TWL_KEYSDIR +MAKEGCDFIRM_FLAGS += -t'$(TWL_KEYSDIR)/blowfish/gcdfirm_header_twlj.template.sbin' +else +MAKEGCDFIRM_FLAGS += -t'$(FIRM_ROOT)/build/tools/makegcdfirm/gcdfirm_header_twlj.template.sbin' +endif + +FIRM_SDEPENDS_BIN := $(call eupath,$(MAKEFIRM_RSA_PRVKEY)) \ + $(call eupath,$(MAKEFIRM_ARM9)) \ + $(call eupath,$(MAKEFIRM_ARM7)) + + +.PHONY: firmtop firmlib + +firmtop: + @$(MAKE) -C $(TWL_IPL_RED_ROOT)/build + +firmlib: + @$(MAKE) -C $(TWL_IPL_RED_ROOT)/build/libraries + +# .nor +$(BINDIR)/%.nor: $(FIRM_SDEPENDS_BIN) $(FIRM_SPEC) $(LDEPENDS_BIN) $(EDEPENDS_BIN) $(MAKEFILE) + $(MAKENORFIRM) $(MAKEFIRM_FLAGS) $(MAKEFIRM_DEFS) $(FIRM_SPEC) $@ + +# .nand +$(BINDIR)/%.nand: $(FIRM_SDEPENDS_BIN) $(FIRM_SPEC) $(LDEPENDS_BIN) $(EDEPENDS_BIN) $(MAKEFILE) + $(MAKENANDFIRM) $(MAKEFIRM_FLAGS) $(MAKEFIRM_DEFS) $(FIRM_SPEC) $@ + +# .gcd +$(BINDIR)/%.gcd: $(FIRM_SDEPENDS_BIN) $(FIRM_SPEC) $(LDEPENDS_BIN) $(EDEPENDS_BIN) $(MAKEFILE) + $(MAKEGCDFIRM) $(MAKEFIRM_FLAGS) $(MAKEGCDFIRM_FLAGS) $(MAKEFIRM_DEFS) $(FIRM_SPEC) $@ + +# .rbin +$(BINDIR)/$(TARGET_BIN_BASENAME).rbin: $(OBJS) + objcopy -I elf32-little -O binary $< $@ + +#---------------------------------------------------------------------------- +TWLFIRM_MODULERULES_ = TRUE +endif # TWLFIRM_MODULERULES_ +#----- End of modulerules ----- diff --git a/build/buildtools/modulerules.sysmenu b/build/buildtools/modulerules.sysmenu new file mode 100644 index 00000000..973fac58 --- /dev/null +++ b/build/buildtools/modulerules.sysmenu @@ -0,0 +1,37 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - modulerules - common rules for build system +# File: modulerules +# +# 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_SYSMENU_MODULERULES_ + +#---------------------------------------------------------------------------- +### TWL-modulerules +# +#include $(TWLSDK_ROOT)/build/buildtools/modulerules +include $(NITROSYSTEM_ROOT)/build/buildtools/modulerules + + +%.tad: $(BINDIR)/$(TARGET_BIN) + $(MAKETAD) $< $(MAKETAD_FLAGS) -o $@ + +# .rbin +$(BINDIR)/$(TARGET_BIN_BASENAME).rbin: $(OBJS) + objcopy -I elf32-little -O binary $< $@ + +#---------------------------------------------------------------------------- +TWL_SYSMENU_MODULERULES_ = TRUE +endif # TWL_SYSMENU_MODULERULES_ +#----- End of modulerules ----- diff --git a/build/components/Makefile b/build/components/Makefile new file mode 100644 index 00000000..466e4fce --- /dev/null +++ b/build/components/Makefile @@ -0,0 +1,32 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - build +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + hyena.TWL + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/components/hyena.TWL/Makefile b/build/components/hyena.TWL/Makefile new file mode 100644 index 00000000..357ca49d --- /dev/null +++ b/build/components/hyena.TWL/Makefile @@ -0,0 +1,86 @@ +#! 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-09#$ +# $Rev: 1499 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +override TARGET_PLATFORM = TWL +override TWL_PROC = ARM7 +override TWL_ARCHGEN = LIMITED +TWL_NO_STD_PCHDR = True +TWL_CODEGEN ?= ARM + +#---------------------------------------------------------------------------- + +SUBDIRS = wram_regs + +SRCS = main.c + +TARGET_NAME = hyena + +TARGET_NEF = $(TARGET_NAME).tef +LCFILE_SPEC = $(TARGET_NAME).lsf +LCFILE_TEMPLATE = $(TARGET_NAME).lcf.template +LDRES_TEMPLATE = $(ROOT)/build/components/racoon.TWL/racoon.response.template + +CRT0_O = crt0.LTD.TWL.o + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs +include $(TWLSDK_ROOT)/build/libraries/reboot/commondefs.reboot + +ifdef TWLSDK_NOCRYPTO +CCFLAGS += -DSDK_NOCRYPTO +endif + +ifndef TWLSDK_NOCRYPTO +MAKELCF_FLAGS += -DUSE_CRYPTO_LIBS='libaes_sp$(TWL_LIBSUFFIX).a' +endif + +#MACRO_FLAGS += -DSDK_ARM7COMP_LTD + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037b8000' \ + -DADDRESS_FLXMAIN='0x02280000' \ + -DADDRESS_BOOTCORE='0x0380f000' \ + -DCRT0_O='$(CRT0_O)' + +MAKELCF_FLAGS += -DISDBG_LIBS_TWL='$(if $(ISDBG_LIBS_TWL),$(ISDBG_LIBS_TWL),libstubsistd_sp$(TWL_LIBSUFFIX).a)' \ + -DISDBG_LIBS_NITRO='libstubsisd_sp$(TWL_LIBSUFFIX).a' + + +#-------------------------------- +# install target +#-------------------------------- +INSTALL_TARGETS = $(BINDIR)/$(TARGET_NAME).tef \ + $(BINDIR)/$(TARGET_NAME).TWL.FLX.sbin \ + $(BINDIR)/$(TARGET_NAME)_defs.TWL.FLX.sbin \ + $(BINDIR)/$(TARGET_NAME).TWL.LTD.sbin \ + $(BINDIR)/$(TARGET_NAME)_defs.TWL.LTD.sbin + +INSTALL_DIR = $(TWL_INSTALL_COMPONENTSDIR)/$(TARGET_NAME)/$(TWL_BUILDTYPE) + +LINCLUDES = $(ROOT)/build/libraries/spi/ARM7/include \ + $(ROOT)/build/libraries/spi/ARM7/pm/include \ + $(SYSMENU_ROOT)/build/libraries_sysmenu/sysmenu/common/include +LLIBRARIES += libwl_sp.TWL.LTD.a +LDEPENDS_NEF = $(TWL_LIBS) $(LLIBRARIES) + +do-build: $(TARGETS) + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/components/hyena.TWL/hyena.lcf.template b/build/components/hyena.TWL/hyena.lcf.template new file mode 100644 index 00000000..010e70bd --- /dev/null +++ b/build/components/hyena.TWL/hyena.lcf.template @@ -0,0 +1,915 @@ +#--------------------------------------------------------------------------- +# Project: TwlIPL +# File: hyena.lcf.template +# +# 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$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.WORKRAM (RWX) : ORIGIN = 0x037b8000, LENGTH = 0x58000 > workram.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDMAIN (RWX) : ORIGIN = 0x02280000, LENGTH = 0x74000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.WRAM.START = 0x037c0000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = . + SDK_AUTOLOAD.WRAM.BSS_END - SDK_AUTOLOAD.WRAM.START + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02e80000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + .check.LTDMAIN: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.LTDMAIN + +} diff --git a/build/components/hyena.TWL/hyena.lsf b/build/components/hyena.TWL/hyena.lsf new file mode 100644 index 00000000..d161ef36 --- /dev/null +++ b/build/components/hyena.TWL/hyena.lsf @@ -0,0 +1,192 @@ +#---------------------------------------------------------------------------- +# Project: TwlIPL +# File: hyena.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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$ +#---------------------------------------------------------------------------- +# +# Nitro LCF SPEC FILE +# +#-------- +Static $(TARGET_NAME) +{ + Address $(ADDRESS_FLXMAIN) + Library $(CRT0_O) + StackSize 1024 1024 +} + +#-------- +Autoload WRAM +{ + Address $(ADDRESS_LTDWRAM) + + Library libsubpsyscall.a \ + libsyscall_sp.twl.a \ + $(CW_LIBS) \ + libos_sp$(LIBSUFFIX).a \ + libmi_sp$(LIBSUFFIX).a \ + libpad_sp$(LIBSUFFIX).a \ + libpxi_sp$(LIBSUFFIX).a \ + libstd_sp$(LIBSUFFIX).a \ + libexi_sp$(LIBSUFFIX).a \ + libsnd_sp$(LIBSUFFIX).a \ + libspi_sp$(LIBSUFFIX).a \ + libpm_sp$(LIBSUFFIX).a \ + libmath_sp$(LIBSUFFIX).a \ + libscfg_sp$(LIBSUFFIX).a \ + libtp_sp$(LIBSUFFIX).a \ + libmic_sp$(LIBSUFFIX).a \ + libfs_sp$(LIBSUFFIX).a \ + libcard_sp$(LIBSUFFIX).a \ + libi2c_sp$(LIBSUFFIX).a \ + libcamera_sp$(LIBSUFFIX).a \ + libcdc_sp$(LIBSUFFIX).a \ + libsndex_sp$(LIBSUFFIX).a \ + libtpex_sp$(LIBSUFFIX).a \ + libmicex_sp$(LIBSUFFIX).a \ + libmcu_sp$(LIBSUFFIX).a \ + libboot_sp$(LIBSUFFIX).a \ + libreboot_sp$(LIBSUFFIX).a \ + libhotsw_sp$(LIBSUFFIX).a \ + libreloc_info_sp$(LIBSUFFIX).a \ + libsysmenu_sp$(LIBSUFFIX).a + + Library libsdio_sp$(LIBSUFFIX).a + + Library libnvram_sp$(LIBSUFFIX).a + Library librtc_sp$(LIBSUFFIX).a + + + Object * (.etable) + Object * (.wram) + Object * (.ltdwram) + Object $(OBJDIR)/main.o + + # caches in fatfs library, that should be on WRAM. + # 2007/12/11 OBJECT() ɂ .bss V{̃N܂Ȃ̂ŁA + # ϐ`ӏ pragma .ltdwram ZNVɊ܂܂悤Ɏb΍􂵂܂B +# Object OBJECT( FATFSi___mem_drives_structures , libfatfs_sp$(LIBSUFFIX).a) (.bss) + + ##### + # Sub-routines in WL library , that should be on WRAM. + # in TaskMan.o + Object OBJECT( MainTaskRoutine , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AddTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( DeleteTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( LowestIdleTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ExecuteMessage , libwl_sp$(LIBSUFFIX).a ) (.text) + # in BufMan.o + Object OBJECT( NewHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( DeleteHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AllocateHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ReleaseHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( MoveHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AddHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( GetHeapBufNextAdrs , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlCmdIf.o + Object OBJECT( RequestCmdTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SendMessageToWmDirect , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlNic.o + Object OBJECT( WStart , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WStop , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WSetStaState , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlIntr.o + Object OBJECT( WlIntr , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrPreTbtt , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTbtt , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrActEnd , libwl_sp$(LIBSUFFIX).a ) (.text) +# Object OBJECT( WlIntrAckCntOvf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrCntOvf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxErr , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxCntup , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrMpEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrStartTx , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrStartRx , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SetParentTbttTxq , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( MacBugTxMp , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AdjustRingPointer , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( CheckKeyTxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlIntrTask.o + Object OBJECT( WlIntrTxBeaconTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrMpEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SetParentTbttTxqTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( TakeoutRxFrame , libwl_sp$(LIBSUFFIX).a ) (.text) + # in TxCtrl.o + Object OBJECT( InitTxCtrl , libwl_sp$(LIBSUFFIX).a ) (.text) + # in RxCtrl.o + Object OBJECT( InitRxCtrl , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WaitLoop.o + Object OBJECT( WaitLoop_Rxpe , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_Waitus , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_ClrAid , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_BbpAccess , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_RfAccess , libwl_sp$(LIBSUFFIX).a ) (.text) + +# Object OBJECT( s_ar_cookie_mem , libathdrv_sp$(LIBSUFFIX).a ) (.bss) +# Object OBJECT( nin_ar , libathdrv_sp$(LIBSUFFIX).a ) (.bss) + + Object OBJECT( a_netbuf_alloc_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( a_netbuf_register_rx_callback , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_driver_tx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_tx_queue_full , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_tx_complete , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_bitrate_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_channelList_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_txPwr_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_gpio_intr_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_gpio_data_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_gpio_ack_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_drv_BmiWriteSocReg , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_control_tx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_drv_BmiReadMemory , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_drv_BmiWriteMemory , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( BMI_read_reg , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( BMI_write_reg , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( BMI_read_mem , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( BMI_write_mem , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( wmi_dix_2_dot3 , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( wmi_control_rx_xtnd , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( wmi_control_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( wmi_cmd_send , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( wmi_cmd_send_xtnd , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( HIFReadWrite , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ath_ioctl , libathdrv_sp$(LIBSUFFIX).a ) (.text) + + Object OBJECT( wpa_sm_rx_eapol , libwpa_sp$(LIBSUFFIX).a ) (.text) + +} + +#-------- +Ltdautoload LTDMAIN +{ + After $(TARGET_NAME) + + Object * (.ltdmain) + Library libwm_sp$(LIBSUFFIX).a \ + libnwm_sp$(LIBSUFFIX).a \ + libwvr_sp$(LIBSUFFIX).a \ + libwl_sp$(LIBSUFFIX).a + + Library libwpa_sp$(LIBSUFFIX).a + Library libathdrv_sp$(LIBSUFFIX).a + + Library libfatfs_sp$(LIBSUFFIX).a \ + $(USE_CRYPTO_LIBS) + Library $(ISDBG_LIBS_TWL) + Library $(ISDBG_LIBS_NITRO) +} diff --git a/build/components/hyena.TWL/src/main.c b/build/components/hyena.TWL/src/main.c new file mode 100644 index 00000000..98ad5bcf --- /dev/null +++ b/build/components/hyena.TWL/src/main.c @@ -0,0 +1,692 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - components - mongoose.TWL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "nvram_sp.h" +#include "pm_pmic.h" +#include "internal_api.h" + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ +/* [TODO] Work around. Should be defined in wm_sp.h */ +#define WM_WL_HEAP_SIZE 0x2100 + +/* Priorities of each threads */ +#define THREAD_PRIO_SPI 2 +#define THREAD_PRIO_MCU 4 // b +#define THREAD_PRIO_SND 6 +#define THREAD_PRIO_FATFS 8 +#define THREAD_PRIO_RTC 12 +#define THREAD_PRIO_FS 15 +/* OS_THREAD_LAUNCHER_PRIORITY 16 */ + +/* [TODO] ȉ New WM ɈڍsقD܂? */ +#define NWM_DMANO 3 +#define THREAD_PRIO_NWM_COMMMAND 9 +#define THREAD_PRIO_NWM_EVENT 7 +#define THREAD_PRIO_NWM_SDIO 8 +#define THREAD_PRIO_NWM_WPA 10 + +// ROM o^GÅgR[h +#define ROMHEADER_FOR_CHINA_BIT 0x80 +#define ROMHEADER_FOR_KOREA_BIT 0x40 + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +static void SetSCFGWork( void ); +static void ResetRTC( void ); +static void ReadLauncherParameter( void ); +static void PrintDebugInfo(void); +static OSHeapHandle InitializeAllocateSystem(void); +static void InitializeFatfs(void); +static void InitializeNwm(void); +static void InitializeCdc(void); +static void DummyThread(void* arg); +static void ReadUserInfo(void); +static void VBlankIntr(void); + +/*---------------------------------------------------------------------------* + OV{Q + *---------------------------------------------------------------------------*/ +#ifdef SDK_TWLHYB +extern void SDK_LTDAUTOLOAD_LTDWRAM_BSS_END(void); +extern void SDK_LTDAUTOLOAD_LTDMAIN_BSS_END(void); +#endif + +/*---------------------------------------------------------------------------* + Name: TwlSpMain + Description: NxN^B + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +void +TwlSpMain(void) +{ + OSHeapHandle heapHandle; + + // SYSM[ÑNA + MI_CpuClear32( SYSMi_GetWork(), sizeof(SYSM_work) ); + + // MMEMTCY`FbŃAARM7_startłĂ̂ŁAm[PAOK. + // SCFGWX^HWi_WSYS04 etc.system shared̈ւ̒lZbǵA`[N_ł͍sĂȂ̂ŁA + // `[g̒lgɂ́Agł̒lZbgĂKvB + // `[AvNۂɂ́Areboot.clăZbgĂB + SetSCFGWork(); // [TODO]fobO + + // obNCgON + while ( (reg_GX_DISPSTAT & REG_GX_DISPSTAT_INI_MASK) == FALSE ) + { + } + PMi_SetControl( PMIC_CTL_BKLT1 | PMIC_CTL_BKLT2 ); + + // OS + OS_Init(); + OS_InitTick(); + PrintDebugInfo(); + + // PXIR[obN̐ݒ +// PXI_SetFifoRecvCallback( SYSMENU_PXI_FIFO_TAG, SYSMi_PXIFifoRecvCallback ); + + // `[p^[擾iCold/HotX^[g܂ށj + ReadLauncherParameter(); + + // RTCZbg + ResetRTC(); // 330us炢 + + // NVRAM 烆[U[ǂݏo + ReadUserInfo(); + + // [TODO:] J[hdONāAROMwb_̂݃[h`FbN炢͂Ă + + SYSMi_GetWork()->flags.common.isARM9Start = TRUE; // [TODO:] HW_RED_RESERVEDNANDt@[ŃNAĂė~ + + // q[v̈ݒ + { + void *wram = OS_GetWramSubPrivArenaHi(); + void *mmem = OS_GetSubPrivArenaHi(); + OS_SetSubPrivArenaHi( (void*)SYSM_OWN_ARM7_MMEM_ADDR_END ); // zuĂ̂ŁAA[iHiύXȂƃ_II + OS_SetWramSubPrivArenaHi( (void*)SYSM_OWN_ARM7_WRAM_ADDR_END ); + OS_TPrintf( "MMEM SUBPRV ARENA HI : %08x -> %08x\n", mmem, OS_GetSubPrivArenaHi() ); + OS_TPrintf( "WRAM SUBPRV ARENA HI : %08x -> %08x\n", wram, OS_GetWramSubPrivArenaHi() ); + } + heapHandle = InitializeAllocateSystem(); + + // {^̓T[` + (void)PAD_InitXYButton(); + + // 荞݋ + (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + // t@CVXe + FS_Init(FS_DMA_NOT_USE); + FS_CreateReadServerThread(THREAD_PRIO_FS); + + if (OS_IsRunOnTwl() == TRUE) + { + OSTick start = OS_GetTick(); + InitializeFatfs(); // FATFS + OS_TPrintf( "FATFS init time = %dms\n", OS_TicksToMilliSeconds( OS_GetTick() - start ) ); + InitializeNwm(); // NWM +#ifndef SDK_NOCRYPTO + AES_Init(); // AES +#endif + MCU_InitIrq(THREAD_PRIO_MCU); // MCU + } + + if (OSi_IsCodecTwlMode() == TRUE) + { + // CODEC + InitializeCdc(); + // J + CAMERA_Init(); + /* CODEC TWL [hłȂƃVb^[Iɖ‚炷 + @\gpł܂Bׁ̈ACODEC TWL [h̏ꍇ + ɂ̂݃JCugp”\ȏԂɂ܂B */ + } + + // TEh + SND_Init(THREAD_PRIO_SND); + + // RTC + RTC_Init(THREAD_PRIO_RTC); + + // + WVR_Begin(heapHandle); + + // SPI + SPI_Init(THREAD_PRIO_SPI); + + BOOT_Init(); + + // }@\ + if( ( SYSM_GetLauncherParamBody()->v1.flags.isValid ) && + ( SYSM_GetLauncherParamBody()->v1.flags.bootType != LAUNCHER_BOOTTYPE_ROM ) && + ( SYSM_GetLauncherParamBody()->v1.bootTitleID ) + ) { + // `[p[^Ń_CNgJ[hu[gȊO̎w肪鎞́A}OFFɂB + SYSMi_GetWork()->flags.common.isEnableHotSW = 0; + }else { + // ȊO̎͊}ON + SYSMi_GetWork()->flags.common.isEnableHotSW = 1; + } + + HOTSW_Init(); + + while (TRUE) + { + OS_Halt(); + //---- check reset + if (OS_IsResetOccurred()) + { + OS_ResetSystem(); + } + BOOT_WaitStart(); + } +} + + +// VXë(WRAM & MMEM)SCFGZbg [TODO:]ŏIINANDt@[u[gꂽ炢Ȃ +static void SetSCFGWork( void ) +{ + // SCFGWX^Lȏꍇ̂݃Zbg + if( reg_SCFG_EXT & REG_SCFG_EXT_CFG_MASK ) { + // WRAM̃VXëɃZbg + u32 *wsys4 = (void*)HWi_WSYS04_ADDR; + u8 *wsys8 = (void*)HWi_WSYS08_ADDR; + u8 *wsys9 = (void*)HWi_WSYS09_ADDR; + // copy scfg registers + *wsys4 = reg_SCFG_EXT; + *wsys8 = (u8)(((reg_SCFG_OP & REG_SCFG_OP_OPT_MASK)) | + ((reg_SCFG_A9ROM & (REG_SCFG_A9ROM_RSEL_MASK | REG_SCFG_A9ROM_SEC_MASK)) << (HWi_WSYS08_ROM_ARM9RSEL_SHIFT - REG_SCFG_A9ROM_RSEL_SHIFT)) | + ((reg_SCFG_A7ROM & (REG_SCFG_A7ROM_RSEL_MASK | REG_SCFG_A7ROM_FUSE_MASK)) << (HWi_WSYS08_ROM_ARM7RSEL_SHIFT - REG_SCFG_A7ROM_RSEL_SHIFT)) | + ((reg_SCFG_WL & REG_SCFG_WL_OFFB_MASK) << (HWi_WSYS08_WL_OFFB_SHIFT - REG_SCFG_WL_OFFB_SHIFT)) + ); + *wsys9 = (u8)((*wsys9 & (HWi_WSYS09_JTAG_DSPJE_MASK | HWi_WSYS09_JTAG_CPUJE_MASK | HWi_WSYS09_JTAG_ARM7SEL_MASK)) | + ((reg_SCFG_JTAG & (REG_SCFG_JTAG_CPUJE_MASK | REG_SCFG_JTAG_ARM7SEL_MASK))) | + ((reg_SCFG_JTAG & REG_SCFG_JTAG_DSPJE_MASK) >> (REG_SCFG_JTAG_DSPJE_SHIFT - HWi_WSYS09_JTAG_DSPJE_SHIFT)) | + ((reg_SCFG_CLK & (REG_SCFG_CLK_AESHCLK_MASK | REG_SCFG_CLK_SD2HCLK_MASK | REG_SCFG_CLK_SD1HCLK_MASK)) << (HWi_WSYS09_CLK_SD1HCLK_SHIFT - REG_SCFG_CLK_SD1HCLK_SHIFT)) | + ((reg_SCFG_CLK & (REG_SCFG_CLK_SNDMCLK_MASK | REG_SCFG_CLK_WRAMHCLK_MASK)) >> (REG_SCFG_CLK_WRAMHCLK_SHIFT - HWi_WSYS09_CLK_WRAMHCLK_SHIFT)) + ); + + // MMEM̃VXëɃRs[ + MI_CpuCopy8( (void*)HWi_WSYS04_ADDR, (void *)HW_SYS_CONF_BUF, 6 ); + } +} + + +// RTC̃Zbg`FbN +static void ResetRTC( void ) +{ + // `[ŃZbgo邽߂ɂ̏Ă邪ARTC_InitłƂĂ̂ŁAƖʁB + RTCRawStatus1 stat1; + RTCRawStatus2 stat2; + RTC_ReadStatus1( &stat1 ); + RTC_ReadStatus2( &stat2 ); + // ZbgAdAddቺAICeXg̊etOmF + if ( stat1.reset || stat1.poc || stat1.bld || stat2.test ) + { + // Zbgs + stat1.reset = 1; + RTC_WriteStatus1( &stat1 ); + SYSMi_GetWork()->flags.common.isResetRTC = TRUE; + } +} + + +// `[p[^̃[hHot/ColdX^[g +void ReadLauncherParameter( void ) +{ + BOOL hot; + SYSMi_GetWork()->flags.common.isValidLauncherParam = OS_ReadLauncherParameter( (LauncherParam *)&(SYSMi_GetWork()->launcherParam), &hot ); + SYSMi_GetWork()->flags.common.isHotStart = hot; + // C̃Zbgp[^NAĂ + MI_CpuClear32( SYSMi_GetLauncherParamAddr(), 0x100 ); +} + + +/*---------------------------------------------------------------------------* + Name: PrintDebugInfo + Description: ARM7 R|[lg̏fobOo͂B + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +PrintDebugInfo(void) +{ + if(OS_IsRunOnTwl()) + { + OS_TPrintf("ARM7: This component is running on TWL.\n"); + } + else + { + OS_TPrintf("ARM7: This component is running on NITRO.\n"); + } + OS_TPrintf("ARM7: This component is \"hyena.TWL\"\n"); +} + +#include +/*---------------------------------------------------------------------------* + Name: InitializeFatfs + Description: FATFSCuBFATFS֐ŃXbhx~ + ׁAx~삷_~[̃Xbh𗧂ĂB + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeFatfs(void) +{ + OSThread thread; + u32 stack[18]; + + // _~[Xbh쐬 + OS_CreateThread(&thread, DummyThread, NULL, + (void*)((u32)stack + (sizeof(u32) * 18)), sizeof(u32) * 18, OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&thread); + + // FATFSCȕ +#ifndef SDK_NOCRYPTO +#ifdef FATFS_AES_MOUNT_FOR_NAND + if(!FATFS_Init( FATFS_DMA_4, FATFS_DMA_NOT_USE, THREAD_PRIO_FATFS)) +#else + if (FATFS_Init(FATFS_DMA_NOT_USE, FATFS_DMA_NOT_USE, THREAD_PRIO_FATFS)) +#endif +#else + if (FATFS_Init(FATFS_DMA_NOT_USE, FATFS_DMA_NOT_USE, THREAD_PRIO_FATFS)) +#endif + { + // do nothing + } + + // _~[Xbhj + OS_KillThread(&thread, NULL); +} +#include + +#include +/*---------------------------------------------------------------------------* + Name: InitializeNwm + Description: NWMCuB + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeNwm(void) +{ + NwmspInit nwmInit; + + OSHeapHandle heapHandle; + void* Lo = (void*)OS_GetSubPrivArenaLo(); + void* Hi = (void*)OS_GetSubPrivArenaHi(); + heapHandle = OS_CreateHeap(OS_ARENA_MAIN_SUBPRIV, Lo, Hi); + + /* [TODO] mۂq[v̈悪VꎮKvƂĂ郁ʈȏォ̃`FbNKv */ + + nwmInit.dmaNo = NWM_DMANO; + nwmInit.cmdPrio = THREAD_PRIO_NWM_COMMMAND; + nwmInit.evtPrio = THREAD_PRIO_NWM_EVENT; + nwmInit.sdioPrio = THREAD_PRIO_NWM_SDIO; + nwmInit.drvHeap.id = OS_ARENA_MAIN_SUBPRIV; /* [TODO] */ + nwmInit.drvHeap.handle = heapHandle; +#ifdef WPA_BUILT_IN /* WPA gݍ܂ꍇAȉ̃olj */ + nwmInit.wpaPrio = THREAD_PRIO_NWM_WPA; + nwmInit.wpaHeap.id = OS_ARENA_MAIN_SUBPRIV; /* [TODO] */ + nwmInit.wpaHeap.handle = heapHandle; +#endif + NWMSP_Init(&nwmInit); + +} +#include + +#include +/*---------------------------------------------------------------------------* + Name: InitializeCdc + Description: CDCCuBCDC֐ŃXbhx~ + ׁAx~삷_~[̃Xbh𗧂ĂB + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeCdc(void) +{ + OSThread thread; + u32 stack[18]; + + // _~[Xbh쐬 + OS_CreateThread(&thread, DummyThread, NULL, + (void*)((u32)stack + (sizeof(u32) * 18)), sizeof(u32) * 18, OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&thread); + +#if 1 + // CODEC + CDC_Init(); + CDC_InitMic(); +// CDCi_DumpRegisters(); +#else + /* [Debug] CODEC DS [hŏ */ + *((u8*)(HW_TWL_ROM_HEADER_BUF + 0x01bf)) &= ~(0x01); + CDC_Init(); + CDC_GoDsMode(); + OS_TPrintf("Codec mode changed to DS mode for debug.\n"); +#endif + + // _~[Xbhj + OS_KillThread(&thread, NULL); +} + +/*---------------------------------------------------------------------------* + Name: DummyThread + Description: FATFSCuACDCCuۂɗĂ_~[ + XbhB + Arguments: arg - gpȂB + Returns: None. + *---------------------------------------------------------------------------*/ +static void +DummyThread(void* arg) +{ +#pragma unused(arg) + while (TRUE) + { + } +} +#include + +/*---------------------------------------------------------------------------* + Name: InitializeAllocateSystem + Description: ăVXeB + Arguments: None. + Returns: OSHeapHandle - WRAM A[iɊmۂꂽq[ṽnhԂB + *---------------------------------------------------------------------------*/ +static OSHeapHandle +InitializeAllocateSystem(void) +{ + OSHeapHandle hh; + +#ifdef SDK_TWLHYB + if (OS_IsRunOnTwl() == TRUE) + { + void* basicLo = (void*)OS_GetSubPrivArenaLo(); + void* basicHi = (void*)OS_GetSubPrivArenaHi(); + void* extraLo = (void*)MATH_ROUNDUP((u32)SDK_LTDAUTOLOAD_LTDMAIN_BSS_END, 32); + void* extraHi = (void*)MATH_ROUNDDOWN(HW_MAIN_MEM_SUB, 32); + +#if SDK_DEBUG + // debug information + OS_TPrintf("ARM7: MAIN arena basicLo = %p\n", basicLo); + OS_TPrintf("ARM7: MAIN arena basicHi = %p\n", basicHi); + OS_TPrintf("ARM7: MAIN arena extraLo = %p\n", extraLo); + OS_TPrintf("ARM7: MAIN arena extraHi = %p\n", extraHi); +#endif + + // A[i 0 NA + MI_CpuClear8(basicLo, (u32)basicHi - (u32)basicLo); + MI_CpuClear8(extraLo, (u32)extraHi - (u32)extraLo); + + // 蓖ď + if ((u32)basicLo < (u32)extraLo) + { + basicLo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, basicLo, extraHi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_MAIN_SUBPRIV, basicLo); + } + else + { + extraLo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, extraLo, basicHi, 1); + } + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_MAIN_SUBPRIV, basicLo, basicHi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to create MAIN heap.\n"); + } + + // q[vTCY̊mF + { + u32 heapSize; + + heapSize = (u32)OS_CheckHeap(OS_ARENA_MAIN_SUBPRIV, hh); + if (ATH_DRV_HEAP_SIZE > heapSize) + { + OS_Panic("Insufficient heap size. (0x%x < 0x%x)\n", heapSize, ATH_DRV_HEAP_SIZE); + } + OS_TPrintf("ARM7: MAIN heap size is %d (before AddToHead)\n", heapSize); + } + + // q[vɊgubNlj + OS_AddToHeap(OS_ARENA_MAIN_SUBPRIV, hh, extraLo, extraHi); + } + else +#endif + { + void* lo = (void*)OS_GetSubPrivArenaLo(); + void* hi = (void*)OS_GetSubPrivArenaHi(); + + // A[i 0 NA + MI_CpuClear8(lo, (u32)hi - (u32)lo); + + // 蓖ď + lo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, lo, hi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_MAIN_SUBPRIV, lo); + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_MAIN_SUBPRIV, lo, hi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to MAIN create heap.\n"); + } + } + // Jgq[vɐݒ + (void)OS_SetCurrentHeap(OS_ARENA_MAIN_SUBPRIV, hh); + // q[vTCY̊mF + { + u32 heapSize; + + heapSize = (u32)OS_CheckHeap(OS_ARENA_MAIN_SUBPRIV, hh); + OS_TPrintf("ARM7: MAIN heap size is %d\n", heapSize); + } +#ifdef SDK_TWLHYB + if (OS_IsRunOnTwl() == TRUE) + { + void* basicLo = (void*)OS_GetWramSubPrivArenaLo(); + void* basicHi = (void*)OS_GetWramSubPrivArenaHi(); + void* extraLo = (void*)MATH_ROUNDUP((u32)SDK_LTDAUTOLOAD_LTDWRAM_BSS_END, 32); + void* extraHi = (void*)MATH_ROUNDDOWN(HW_WRAM_A_HYB_END, 32); + +#if SDK_DEBUG + // debug information + OS_TPrintf("ARM7: WRAM arena basicLo = %p\n", basicLo); + OS_TPrintf("ARM7: WRAM arena basicHi = %p\n", basicHi); + OS_TPrintf("ARM7: WRAM arena extraLo = %p\n", extraLo); + OS_TPrintf("ARM7: WRAM arena extraHi = %p\n", extraHi); +#endif + + // A[i 0 NA + MI_CpuClear8(basicLo, (u32)basicHi - (u32)basicLo); + MI_CpuClear8(extraLo, (u32)extraHi - (u32)extraLo); + + // 蓖ď + if ((u32)basicLo < (u32)extraLo) + { + basicLo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV, basicLo, extraHi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_WRAM_SUBPRIV, basicLo); + } + else + { + extraLo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV, extraLo, basicHi, 1); + } + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_WRAM_SUBPRIV, basicLo, basicHi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to WRAM create heap.\n"); + } + + // q[vTCY̊mF + { + u32 heapSize; + + heapSize = (u32)OS_CheckHeap(OS_ARENA_WRAM_SUBPRIV, hh); + if (WM_WL_HEAP_SIZE > heapSize) + { + OS_Panic("Insufficient heap size. (0x%x < 0x%x)\n", heapSize, WM_WL_HEAP_SIZE); + } + OS_TPrintf("ARM7: WRAM heap size is %d (before AddToHeap)\n", heapSize); + } + + // q[vɊgubNlj + OS_AddToHeap(OS_ARENA_WRAM_SUBPRIV, hh, extraLo, extraHi); + } + else +#endif + { + void* lo = (void*)OS_GetWramSubPrivArenaLo(); + void* hi = (void*)OS_GetWramSubPrivArenaHi(); + + // A[i 0 NA + MI_CpuClear8(lo, (u32)hi - (u32)lo); + + // 蓖ď + lo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV, lo, hi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_WRAM_SUBPRIV, lo); + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_WRAM_SUBPRIV, lo, hi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to WRAM create heap.\n"); + } + } + + // Jgq[vɐݒ + (void)OS_SetCurrentHeap(OS_ARENA_WRAM_SUBPRIV, hh); + + // q[vTCY̊mF + { + u32 heapSize; + + heapSize = (u32)OS_CheckHeap(OS_ARENA_WRAM_SUBPRIV, hh); + if (WM_WL_HEAP_SIZE > heapSize) + { + OS_Panic("Insufficient heap size. (0x%x < 0x%x)\n", heapSize, WM_WL_HEAP_SIZE); + } + OS_TPrintf("ARM7: WRAM heap size is %d\n", heapSize); + } + + return hh; +} + +#ifdef WM_PRECALC_ALLOWEDCHANNEL +extern u16 WMSP_GetAllowedChannel(u16 bitField); +#endif +/*---------------------------------------------------------------------------* + Name: ReadUserInfo + + Description: NVRAM烆[U[ǂݏoAL̈ɓWJB + ~[OĂobt@Ăꍇ́A + L̈̃[U[i[ꏊNAB + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void ReadUserInfo(void) +{ + u8 *p = OS_GetSystemWork()->nvramUserInfo; + + // MACAhX[U[̌ɓWJ + { + u8 wMac[6]; + + // NVRAMMACAhXǂݏo + NVRAM_ReadDataBytes(NVRAM_CONFIG_MACADDRESS_ADDRESS, 6, wMac); + // WJAhXvZ + p = (u8 *)((u32)p + ((sizeof(NVRAMConfig) + 3) & ~0x00000003)); + // L̈ɓWJ + MI_CpuCopy8(wMac, p, 6); + } + +#ifdef WM_PRECALC_ALLOWEDCHANNEL + // gp”\`lgpƒ`lvZ + { + u16 enableChannel; + u16 allowedChannel; + + // gp”\`lǂݏo + NVRAM_ReadDataBytes(NVRAM_CONFIG_ENABLECHANNEL_ADDRESS, 2, (u8 *)(&enableChannel)); + // gpƒ`lvZ + allowedChannel = WMSP_GetAllowedChannel((u16)(enableChannel >> 1)); + // WJAhXvZ(MACAhX̌2oCg) + p = (u8 *)((u32)p + 6); + // L̈ɓWJ + *((u16 *)p) = allowedChannel; + } +#endif +} + + +/*---------------------------------------------------------------------------* + Name: VBlankIntr + Description: V uN荞݃xN^B + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +extern BOOL PMi_Initialized; +void PM_SelfBlinkProc(void); + +static void +VBlankIntr(void) +{ + if (PMi_Initialized) + { + PM_SelfBlinkProc(); + } +} + diff --git a/build/components/hyena.TWL/wram_regs/Makefile b/build/components/hyena.TWL/wram_regs/Makefile new file mode 100644 index 00000000..d8f67eab --- /dev/null +++ b/build/components/hyena.TWL/wram_regs/Makefile @@ -0,0 +1,49 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - nandfirm-ds-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Log: $ +# $NoKeywords: $ +#---------------------------------------------------------------------------- + +TWL_PROC = ARM7 + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/components/hyena.TWL/wram_regs/wram_regs.c b/build/components/hyena.TWL/wram_regs/wram_regs.c new file mode 100644 index 00000000..0d93fa87 --- /dev/null +++ b/build/components/hyena.TWL/wram_regs/wram_regs.c @@ -0,0 +1,121 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - wram_regs + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-12-11#$ + $Rev: 2990 $ + $Author: nakasima $ + *---------------------------------------------------------------------------*/ +#include + +#define HW_HYENA_WRAM_A_OFS (HW_WRAM_A_LTD - HW_WRAM_BASE) +#define HW_HYENA_WRAM_A_OFS_END (HW_WRAM_A_LTD_END - HW_WRAM_BASE) +#define HW_HYENA_WRAM_B_OFS (HW_HYENA_WRAM_A_OFS - HW_WRAM_B_SIZE) +#define HW_HYENA_WRAM_B_OFS_END (HW_HYENA_WRAM_A_OFS) +#define HW_HYENA_WRAM_C_OFS (HW_HYENA_WRAM_B_OFS - HW_WRAM_C_SIZE) +#define HW_HYENA_WRAM_C_OFS_END (HW_HYENA_WRAM_B_OFS) + +// MAP_TS_LTD for hyena +// WRAM-A Lock:ON, Master:ARM7, Enable:Slot0-3(256Kbytes), Address(7):0x037c0000-0x037fffff, Address(9):None +// WRAM-B Lock:ON, Master:ARM7, Enable:Slot7 (32Kbytes), Address(7):0x037b8000-0x037bffff, Address(9):None +// WRAM-B Lock:OFF, Master:ARM9, Enable:Slot0-6(224Kbytes), Address(7):0x03780000-0x037b7fff, Address(9):0x03780000-0x037bffff +// WRAM-C Lock:OFF, Msster:ARM9, Enable:Slot0-7(256Kbytes), Address(7):0x03740000-0x0377ffff, Address(9):0x03740000-0x0377ffff +// WRAM-0 Master:ARM9, (16Kbytes), Address(7):0x03040000-0x03043fff, Address(9):0x03040000-0x03043fff +// WRAM-1 Master:ARM9, (16Kbytes), Address(7):0x03044000-0x03047fff, Address(9):0x03044000-0x03047fff + +// MAP_TS_LTD original +// WRAM-A Lock:ON, Master:ARM7, Enable:Slot0-3(256Kbytes), Address(7):0x037c0000-0x037fffff, Address(9):None +// WRAM-B Lock:OFF, Master:ARM9, Enable:Slot0-7(256Kbytes), Address(7):0x03900000-0x0393ffff, Address(9):0x03900000-0x0393ffff +// WRAM-C Lock:OFF, Msster:ARM9, Enable:Slot0-7(256Kbytes), Address(7):0x03940000-0x0397ffff, Address(9):0x03940000-0x0397ffff +// WRAM-0 Master:ARM9, (16Kbytes), Address(7):0x03040000-0x03043fff, Address(9):0x03040000-0x03043fff +// WRAM-1 Master:ARM9, (16Kbytes), Address(7):0x03044000-0x03047fff, Address(9):0x03044000-0x03047fff + +u32 HYENA_WramReg[0x30/sizeof(u32)] = +{ + // ARM9 + + // WRAM-A + REG_MI_MBK1_FIELD( + TRUE, MI_WRAM_OFFSET_192KB/2, MI_WRAM_ARM7, + TRUE, MI_WRAM_OFFSET_128KB/2, MI_WRAM_ARM7, + TRUE, MI_WRAM_OFFSET_64KB/2, MI_WRAM_ARM7, + TRUE, MI_WRAM_OFFSET_0KB/2, MI_WRAM_ARM7 + ), + // WRAM-B + REG_MI_MBK2_FIELD( + TRUE, MI_WRAM_OFFSET_96KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_64KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_32KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_0KB, MI_WRAM_ARM9 + ), + REG_MI_MBK3_FIELD( + TRUE, MI_WRAM_OFFSET_224KB, MI_WRAM_ARM7, + TRUE, MI_WRAM_OFFSET_192KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_160KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_128KB, MI_WRAM_ARM9 + ), + // WRAM-C + REG_MI_MBK4_FIELD( + TRUE, MI_WRAM_OFFSET_96KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_64KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_32KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_0KB, MI_WRAM_ARM9 + ), + REG_MI_MBK5_FIELD( + TRUE, MI_WRAM_OFFSET_224KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_192KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_160KB, MI_WRAM_ARM9, + TRUE, MI_WRAM_OFFSET_128KB, MI_WRAM_ARM9 + ), + + REG_MI_MBK6_FIELD( NULL >> 16, + MI_WRAM_IMAGE_256KB, + NULL >> 16 + ), + REG_MI_MBK7_FIELD( HW_HYENA_WRAM_B_OFS_END >> 15, + MI_WRAM_IMAGE_256KB, + HW_HYENA_WRAM_B_OFS >> 15 + ), + REG_MI_MBK8_FIELD( HW_HYENA_WRAM_C_OFS_END >> 15, + MI_WRAM_IMAGE_256KB, + HW_HYENA_WRAM_C_OFS >> 15 + ), + + // ARM7 + REG_MI_MBK6_FIELD( HW_HYENA_WRAM_A_OFS_END >> 16, + MI_WRAM_IMAGE_256KB, + HW_HYENA_WRAM_A_OFS >> 16 + ), + REG_MI_MBK7_FIELD( HW_HYENA_WRAM_B_OFS_END >> 15, + MI_WRAM_IMAGE_256KB, + HW_HYENA_WRAM_B_OFS >> 15 + ), + REG_MI_MBK8_FIELD( HW_HYENA_WRAM_C_OFS_END >> 15, + MI_WRAM_IMAGE_256KB, + HW_HYENA_WRAM_C_OFS >> 15 + ), + + // WRAM Lock + (u32)( + (0x0F << 0) | + (0x80 << 8) | + (0x00 << 16) | + + // WRAM-0/1 + (0 << 24) | + + // VRAM-C + (7 << 26) | + // VRAM-D + (7 << 29) + ), +}; + diff --git a/build/gcdfirm/Makefile b/build/gcdfirm/Makefile new file mode 100644 index 00000000..d6d1b53b --- /dev/null +++ b/build/gcdfirm/Makefile @@ -0,0 +1,34 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - firmware +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + gcdfirm-disp \ + gcdfirm-print \ + sdmc-launcher \ + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/gcdfirm/gcdfirm-disp/ARM7/Makefile b/build/gcdfirm/gcdfirm-disp/ARM7/Makefile new file mode 100644 index 00000000..ac07e3ac --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/ARM7/Makefile @@ -0,0 +1,51 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - menu-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +TWL_PROC = ARM7 + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = gcdfirm_disp7.tef + +SRCS = main.c + +CRT0_O = crt0_firm.o + +ADDRESS_STATIC = 0x037b8000 + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/gcdfirm/gcdfirm-disp/ARM7/main.c b/build/gcdfirm/gcdfirm-disp/ARM7/main.c new file mode 100644 index 00000000..d9d563b4 --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/ARM7/main.c @@ -0,0 +1,66 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - firm_writer_gcd + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include + +//#define PRINT_DEBUG + +#ifndef PRINT_DEBUG +#undef OS_TPrintf +#undef OS_PutChar +#define OS_TPrintf(...) ((void)0) +#define OS_PutChar(...) ((void)0) +#endif // PRINT_DEBUG + +void TwlSpMain( void ) +{ +#ifdef PRINT_DEBUG + reg_SCFG_JTAG = REG_SCFG_JTAG_CPUJE_MASK | REG_SCFG_JTAG_ARM7SEL_MASK; +#endif // PRINT_DEBUG + + MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) ); + + OS_InitFIRM(); + + OS_TPrintf( "\nARM7 starts.\n" ); + + OS_EnableInterrupts(); + OS_EnableIrq(); + + PM_InitFIRM(); + PMi_SetParams( REG_PMIC_BL_BRT_A_ADDR, PMIC_BACKLIGHT_BRIGHT_DEFAULT, PMIC_BL_BRT_A_MASK ); + PMi_SetParams( REG_PMIC_BL_BRT_B_ADDR, PMIC_BACKLIGHT_BRIGHT_DEFAULT, PMIC_BL_BRT_B_MASK ); + PM_BackLightOn( TRUE ); + + // {^܂ő҂ + OS_TPrintf( "\nPress A button.\n"); + while ( !(PAD_Read() & PAD_BUTTON_A) ) + { + } + + OS_TPrintf( "\nARM7 ends.\n" ); + (void)OS_DisableIrq(); +// OSi_Finalize(); +#ifdef PRINT_DEBUG + reg_SCFG_JTAG = REG_SCFG_JTAG_CPUJE_MASK | REG_SCFG_JTAG_ARM7SEL_MASK; +#endif // PRINT_DEBUG + while (1) + { + } +// OS_Terminate(); +} + + diff --git a/build/gcdfirm/gcdfirm-disp/ARM9/Makefile b/build/gcdfirm/gcdfirm-disp/ARM9/Makefile new file mode 100644 index 00000000..c357b701 --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/ARM9/Makefile @@ -0,0 +1,54 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - menu-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = gcdfirm_disp9.srl + +SRCS = main.c \ + screen.c \ + font.c \ + +CRT0_O = crt0_firm.o + +ADDRESS_STATIC = 0x037c0000 + +MAKEROM_ARM7 = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/gcdfirm_disp7.tef +MAKEROM_ARM7_BASE = $(basename $(MAKEROM_ARM7)) + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/gcdfirm/gcdfirm-disp/ARM9/font.c b/build/gcdfirm/gcdfirm-disp/ARM9/font.c new file mode 100644 index 00000000..ee49f50b --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/ARM9/font.c @@ -0,0 +1,588 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - SPI - demos - pm-1 + File: font.c + + Copyright 2003-2005 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: font.c,v $ + Revision 1.3 2005/02/28 05:26:11 yosizaki + do-indent. + + Revision 1.2 2004/11/02 07:19:52 terui + RgXy~XCB + + Revision 1.1 2004/08/07 01:59:51 yada + modified much + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#include "font.h" + + +/*---------------------------------------------------------------------------* + Character data + *---------------------------------------------------------------------------*/ +const u32 d_CharData[8 * 256] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 0000h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01010010, 0x01010010, 0x00000110, // 0001h + 0x00011010, 0x01100010, 0x00000010, 0x00000010, + 0x00000000, 0x01011010, 0x01010010, 0x00010010, // 0002h + 0x00100010, 0x00100010, 0x00100001, 0x00100001, + 0x00000000, 0x01010001, 0x01010001, 0x01111111, // 0003h + 0x00000001, 0x00000001, 0x00000001, 0x01111110, + 0x00000000, 0x01010000, 0x01111111, 0x00100000, // 0004h + 0x00100000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x01010000, 0x01010100, 0x00001010, // 0005h + 0x00010001, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01011000, 0x01011000, 0x01111111, // 0006h + 0x00001000, 0x00101010, 0x01001010, 0x01001001, + 0x00000000, 0x01010010, 0x01101111, 0x01010010, // 0007h + 0x00010010, 0x00010010, 0x00010010, 0x00001001, + 0x00000000, 0x01010010, 0x01011111, 0x00000100, // 0008h + 0x00011111, 0x00001000, 0x00000001, 0x00011110, + 0x00000000, 0x01010000, 0x01011000, 0x00000110, // 0009h + 0x00000001, 0x00000110, 0x00011000, 0x00100000, + 0x00000000, 0x01010000, 0x01111101, 0x00010001, // 000ah + 0x00010001, 0x00010001, 0x00010001, 0x00001010, + 0x00000000, 0x01010000, 0x01011110, 0x00100000, // 000bh + 0x00000000, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x01010100, 0x01011111, 0x00001000, // 000ch + 0x00010000, 0x00000001, 0x00000001, 0x00011110, + 0x00000000, 0x01010001, 0x01010001, 0x00000001, // 000dh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01010000, 0x01111111, 0x00011000, // 000eh + 0x00010100, 0x00010100, 0x00011000, 0x00001100, + 0x00000000, 0x01010010, 0x01111111, 0x00010010, // 000fh + 0x00010010, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x00001110, 0x01010100, 0x01010010, // 0010h + 0x00111111, 0x00000100, 0x00000100, 0x00011000, + 0x00000000, 0x01010100, 0x01011111, 0x00000100, // 0011h + 0x01110100, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x01010100, 0x01011111, 0x00000010, // 0012h + 0x00011110, 0x00100001, 0x00100000, 0x00011110, + 0x00000000, 0x01010000, 0x01011100, 0x00100011, // 0013h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01010000, 0x01111111, 0x00010000, // 0014h + 0x00001000, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x01010010, 0x01010010, 0x00001100, // 0015h + 0x00000010, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x01010001, 0x01111101, 0x00010001, // 0016h + 0x00010001, 0x00111001, 0x01010101, 0x00011001, + 0x00000000, 0x01010100, 0x01010011, 0x01110010, // 0017h + 0x00010001, 0x00010001, 0x00001010, 0x00000100, + 0x00000000, 0x01011110, 0x01011000, 0x00000100, // 0018h + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x01010000, 0x01011100, 0x00010010, // 0019h + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01011101, 0x01010001, 0x00111101, // 001ah + 0x00010001, 0x00011001, 0x00110101, 0x00001001, + 0x00000000, 0x01110001, 0x01011101, 0x00110001, // 001bh + 0x00010001, 0x00111001, 0x01010101, 0x00011001, + 0x00000000, 0x01110100, 0x01010011, 0x00110010, // 001ch + 0x00010001, 0x00010001, 0x00001010, 0x00000100, + 0x00000000, 0x01101110, 0x01011000, 0x00100100, // 001dh + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x01110000, 0x01011100, 0x00110010, // 001eh + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01111101, 0x01010001, 0x00111101, // 001fh + 0x00010001, 0x00011001, 0x00110101, 0x00001001, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 0020h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 0021h + 0x00001000, 0x00001000, 0x00000000, 0x00001000, + 0x00000000, 0x01101100, 0x01001000, 0x00100100, // 0022h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00100100, 0x01111111, 0x00100100, // 0023h + 0x00100100, 0x01111111, 0x00010010, 0x00010010, + 0x00000000, 0x00001000, 0x01111110, 0x00001001, // 0024h + 0x00111110, 0x01001000, 0x00111111, 0x00001000, + 0x00000000, 0x01000010, 0x00100101, 0x00010010, // 0025h + 0x00001000, 0x00100100, 0x01010010, 0x00100001, + 0x00000000, 0x00001110, 0x00010001, 0x00001001, // 0026h + 0x01000110, 0x00101001, 0x00110001, 0x01001110, + 0x00000000, 0x00011000, 0x00010000, 0x00001000, // 0027h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01110000, 0x00001000, 0x00000100, // 0028h + 0x00000100, 0x00000100, 0x00001000, 0x01110000, + 0x00000000, 0x00000111, 0x00001000, 0x00010000, // 0029h + 0x00010000, 0x00010000, 0x00001000, 0x00000111, + 0x00000000, 0x00001000, 0x01001001, 0x00101010, // 002ah + 0x00011100, 0x00101010, 0x01001001, 0x00001000, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 002bh + 0x01111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002ch + 0x00000000, 0x00001100, 0x00001000, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002dh + 0x01111111, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002eh + 0x00000000, 0x00000000, 0x00000000, 0x00001100, + 0x00000000, 0x01000000, 0x00100000, 0x00010000, // 002fh + 0x00001000, 0x00000100, 0x00000010, 0x00000001, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0030h + 0x01000001, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x00011100, 0x00010000, 0x00010000, // 0031h + 0x00010000, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x00111110, 0x01000001, 0x01000000, // 0032h + 0x00111110, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x00111110, 0x01000001, 0x01000000, // 0033h + 0x00111110, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x00100000, 0x00110000, 0x00101000, // 0034h + 0x00100100, 0x00100010, 0x01111111, 0x00100000, + 0x00000000, 0x01111111, 0x00000001, 0x00111111, // 0035h + 0x01000000, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x00111110, 0x00000001, 0x00111111, // 0036h + 0x01000001, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x01111111, 0x00100000, 0x00100000, // 0037h + 0x00010000, 0x00010000, 0x00001000, 0x00001000, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0038h + 0x00111110, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0039h + 0x01000001, 0x01111110, 0x01000000, 0x00111110, + 0x00000000, 0x00000000, 0x00001100, 0x00000000, // 003ah + 0x00000000, 0x00000000, 0x00001100, 0x00000000, + 0x00000000, 0x00000000, 0x00001100, 0x00000000, // 003bh + 0x00000000, 0x00001100, 0x00001000, 0x00000100, + 0x00000000, 0x01100000, 0x00011000, 0x00000110, // 003ch + 0x00000001, 0x00000110, 0x00011000, 0x01100000, + 0x00000000, 0x00000000, 0x01111111, 0x00000000, // 003dh + 0x00000000, 0x00000000, 0x01111111, 0x00000000, + 0x00000000, 0x00000011, 0x00001100, 0x00110000, // 003eh + 0x01000000, 0x00110000, 0x00001100, 0x00000011, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 003fh + 0x00110000, 0x00001000, 0x00000000, 0x00001000, + 0x00000000, 0x00011100, 0x00100010, 0x01001001, // 0040h + 0x01010101, 0x01010101, 0x01010101, 0x00111010, + 0x00000000, 0x00001000, 0x00010100, 0x00010100, // 0041h + 0x00100010, 0x00111110, 0x01000001, 0x01000001, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0042h + 0x00111111, 0x01000001, 0x01000001, 0x00111111, + 0x00000000, 0x00111100, 0x01000010, 0x00000001, // 0043h + 0x00000001, 0x00000001, 0x01000010, 0x00111100, + 0x00000000, 0x00011111, 0x00100001, 0x01000001, // 0044h + 0x01000001, 0x01000001, 0x00100001, 0x00011111, + 0x00000000, 0x01111111, 0x00000001, 0x00000001, // 0045h + 0x01111111, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x01111111, 0x00000001, 0x00000001, // 0046h + 0x00111111, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00111100, 0x01000010, 0x00000001, // 0047h + 0x01111001, 0x01000001, 0x01000010, 0x00111100, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0048h + 0x01111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00111110, 0x00001000, 0x00001000, // 0049h + 0x00001000, 0x00001000, 0x00001000, 0x00111110, + 0x00000000, 0x01000000, 0x01000000, 0x01000000, // 004ah + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01100001, 0x00011001, 0x00000101, // 004bh + 0x00000011, 0x00000101, 0x00011001, 0x01100001, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 004ch + 0x00000001, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x01000001, 0x01100011, 0x01010101, // 004dh + 0x01001001, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x01000001, 0x01000011, 0x01000101, // 004eh + 0x01001001, 0x01010001, 0x01100001, 0x01000001, + 0x00000000, 0x00011100, 0x00100010, 0x01000001, // 004fh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0050h + 0x00111111, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00011100, 0x00100010, 0x01000001, // 0051h + 0x01000001, 0x01011001, 0x00100010, 0x01011100, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0052h + 0x00111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00111110, 0x01000001, 0x00000001, // 0053h + 0x00111110, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x01111111, 0x00001000, 0x00001000, // 0054h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0055h + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01000001, 0x01000001, 0x00100010, // 0056h + 0x00100010, 0x00010100, 0x00010100, 0x00001000, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0057h + 0x01001001, 0x01010101, 0x01100011, 0x01000001, + 0x00000000, 0x01000001, 0x00100010, 0x00010100, // 0058h + 0x00001000, 0x00010100, 0x00100010, 0x01000001, + 0x00000000, 0x01000001, 0x00100010, 0x00010100, // 0059h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01111111, 0x00100000, 0x00010000, // 005ah + 0x00001000, 0x00000100, 0x00000010, 0x01111111, + 0x00000000, 0x01111100, 0x00000100, 0x00000100, // 005bh + 0x00000100, 0x00000100, 0x00000100, 0x01111100, + 0x00000000, 0x00100010, 0x00010100, 0x00111110, // 005ch + 0x00001000, 0x00111110, 0x00001000, 0x00001000, + 0x00000000, 0x00011111, 0x00010000, 0x00010000, // 005dh + 0x00010000, 0x00010000, 0x00010000, 0x00011111, + 0x00000000, 0x00001000, 0x00010100, 0x00100010, // 005eh + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 005fh + 0x00000000, 0x00000000, 0x00000000, 0x01111111, + 0x00000000, 0x00010000, 0x00001000, 0x00011000, // 0060h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00011110, 0x00100001, // 0061h + 0x00111110, 0x00100001, 0x00100001, 0x01011110, + 0x00000000, 0x00000001, 0x00000001, 0x00111111, // 0062h + 0x01000001, 0x01000001, 0x01000001, 0x00111111, + 0x00000000, 0x00000000, 0x00111100, 0x01000010, // 0063h + 0x00000001, 0x00000001, 0x01000010, 0x00111100, + 0x00000000, 0x01000000, 0x01000000, 0x01111110, // 0064h + 0x01000001, 0x01000001, 0x01000001, 0x01111110, + 0x00000000, 0x00000000, 0x00111110, 0x01000001, // 0065h + 0x01111111, 0x00000001, 0x01000001, 0x00111110, + 0x00000000, 0x00110000, 0x00001000, 0x00001000, // 0066h + 0x01111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x01111110, 0x01000001, // 0067h + 0x01000001, 0x01111110, 0x01000000, 0x00111110, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 0068h + 0x00111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00001000, 0x00000000, 0x00001000, // 0069h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00100000, 0x00000000, 0x00100000, // 006ah + 0x00100000, 0x00100001, 0x00100001, 0x00011110, + 0x00000000, 0x00000001, 0x00000001, 0x01100001, // 006bh + 0x00011001, 0x00000111, 0x00011001, 0x01100001, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 006ch + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00110111, 0x01001001, // 006dh + 0x01001001, 0x01001001, 0x01001001, 0x01001001, + 0x00000000, 0x00000000, 0x00111111, 0x01000001, // 006eh + 0x01000001, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00000000, 0x00011100, 0x00100010, // 006fh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00000000, 0x00111101, 0x01000011, // 0070h + 0x01000001, 0x01000011, 0x00111101, 0x00000001, + 0x00000000, 0x00000000, 0x01011110, 0x01100001, // 0071h + 0x01000001, 0x01100001, 0x01011110, 0x01000000, + 0x00000000, 0x00000000, 0x00110001, 0x00001101, // 0072h + 0x00000011, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00000000, 0x00111110, 0x01000001, // 0073h + 0x00001110, 0x00110000, 0x01000001, 0x00111110, + 0x00000000, 0x00000100, 0x00000100, 0x01111111, // 0074h + 0x00000100, 0x00000100, 0x00000100, 0x01111000, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0075h + 0x01000001, 0x01000001, 0x01000001, 0x01111110, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0076h + 0x00100010, 0x00100010, 0x00010100, 0x00001000, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0077h + 0x01001001, 0x00101010, 0x00101010, 0x00010100, + 0x00000000, 0x00000000, 0x00100001, 0x00010010, // 0078h + 0x00001100, 0x00001100, 0x00010010, 0x00100001, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0079h + 0x00100010, 0x00011100, 0x00001000, 0x00000110, + 0x00000000, 0x00000000, 0x00111111, 0x00010000, // 007ah + 0x00001000, 0x00000100, 0x00000010, 0x00111111, + 0x00000000, 0x00001000, 0x00011110, 0x01100100, // 007bh + 0x00011000, 0x00100100, 0x00000100, 0x01111000, + 0x00000000, 0x00000000, 0x00011110, 0x00000100, // 007ch + 0x00011110, 0x00110101, 0x00101101, 0x00010010, + 0x00000000, 0x00000000, 0x00000000, 0x00010001, // 007dh + 0x00100001, 0x00100001, 0x00000001, 0x00000010, + 0x00000000, 0x00000000, 0x00011100, 0x00000000, // 007eh + 0x00011110, 0x00100000, 0x00100000, 0x00011100, + 0x00000000, 0x00000000, 0x00011100, 0x00000000, // 007fh + 0x00111110, 0x00010000, 0x00001100, 0x00110010, + 0x00000000, 0x00000000, 0x00000100, 0x00101111, // 0080h + 0x01000100, 0x00011110, 0x00100101, 0x00010110, + 0x00000000, 0x00000000, 0x00001010, 0x00011110, // 0081h + 0x00101011, 0x00100010, 0x00010100, 0x00000100, + 0x00000000, 0x00000000, 0x00001000, 0x00011101, // 0082h + 0x00101011, 0x00101001, 0x00011001, 0x00000100, + 0x00000000, 0x00000000, 0x00001000, 0x00111000, // 0083h + 0x00001000, 0x00011110, 0x00101001, 0x00000110, + 0x00000000, 0x00000000, 0x00000000, 0x00011100, // 0084h + 0x00100011, 0x00100000, 0x00100000, 0x00011100, + 0x00000000, 0x00000110, 0x01001001, 0x00110000, // 0085h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000100, 0x00111111, 0x00000100, // 0086h + 0x00111110, 0x01010101, 0x01001101, 0x00100110, + 0x00000000, 0x00000000, 0x00100001, 0x01000001, // 0087h + 0x01000001, 0x01000001, 0x00000001, 0x00000010, + 0x00000000, 0x00111100, 0x00000000, 0x00111110, // 0088h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x00011100, 0x00000000, 0x00111110, // 0089h + 0x00010000, 0x00001000, 0x00010100, 0x01100010, + 0x00000000, 0x00100100, 0x01011111, 0x00000100, // 008ah + 0x00111110, 0x01000101, 0x01000101, 0x00100010, + 0x00000000, 0x00100010, 0x01001111, 0x01010010, // 008bh + 0x01010010, 0x00010010, 0x00010010, 0x00001001, + 0x00000000, 0x00000100, 0x00111110, 0x00001000, // 008ch + 0x00111110, 0x00010000, 0x00000010, 0x00111100, + 0x00000000, 0x00100000, 0x00011000, 0x00000110, // 008dh + 0x00000001, 0x00000110, 0x00011000, 0x00100000, + 0x00000000, 0x00100000, 0x01111101, 0x00100001, // 008eh + 0x00100001, 0x00100001, 0x00100001, 0x00010010, + 0x00000000, 0x00011110, 0x00100000, 0x00000000, // 008fh + 0x00000000, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x00001000, 0x01111111, 0x00010000, // 0090h + 0x00100000, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 0091h + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00010000, 0x01111111, 0x00011000, // 0092h + 0x00010100, 0x00010100, 0x00011000, 0x00001100, + 0x00000000, 0x00100010, 0x01111111, 0x00100010, // 0093h + 0x00100010, 0x00000010, 0x00000010, 0x01111100, + 0x00000000, 0x00111100, 0x00010000, 0x00001100, // 0094h + 0x01111111, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x00000100, 0x00011111, 0x00000100, // 0095h + 0x01110100, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x00001000, 0x01111111, 0x00000100, // 0096h + 0x00111100, 0x01000010, 0x01000000, 0x00111100, + 0x00000000, 0x00000000, 0x00011100, 0x00100011, // 0097h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01111111, 0x00010000, 0x00001000, // 0098h + 0x00001000, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x00000010, 0x00110010, 0x00001100, // 0099h + 0x00000010, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x00100100, 0x01001111, 0x01000010, // 009ah + 0x00010001, 0x00111100, 0x00010010, 0x00001100, + 0x00000000, 0x00000010, 0x01111010, 0x01000010, // 009bh + 0x00000010, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x00100010, 0x00111110, 0x01010010, // 009ch + 0x01001011, 0x01101101, 0x01010101, 0x00110010, + 0x00000000, 0x00110010, 0x01001011, 0x01000110, // 009dh + 0x01000110, 0x01110010, 0x01001011, 0x00110010, + 0x00000000, 0x00011100, 0x00101010, 0x01001001, // 009eh + 0x01001001, 0x01000101, 0x01000101, 0x00110010, + 0x00000000, 0x00100001, 0x01111101, 0x00100001, // 009fh + 0x00100001, 0x00111001, 0x01100101, 0x00011001, + 0x00000000, 0x00000100, 0x00100011, 0x01100010, // 00a0h + 0x00100001, 0x00100001, 0x00010010, 0x00001100, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a1h + 0x00000000, 0x00000100, 0x00001010, 0x00000100, + 0x00000000, 0x01110000, 0x00010000, 0x00010000, // 00a2h + 0x00010000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a3h + 0x00001000, 0x00001000, 0x00001000, 0x00001110, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a4h + 0x00000000, 0x00000010, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00011000, // 00a5h + 0x00011000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01111111, 0x01000000, 0x01111111, // 00a6h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x00000000, 0x00111111, 0x00100000, // 00a7h + 0x00010100, 0x00001100, 0x00000100, 0x00000010, + 0x00000000, 0x00000000, 0x00100000, 0x00100000, // 00a8h + 0x00010000, 0x00001111, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00000100, 0x00111111, // 00a9h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x00000000, 0x00000000, 0x00111110, // 00aah + 0x00001000, 0x00001000, 0x00001000, 0x01111111, + 0x00000000, 0x00000000, 0x00010000, 0x00111111, // 00abh + 0x00011000, 0x00010100, 0x00010010, 0x00011001, + 0x00000000, 0x00000000, 0x00000010, 0x00111111, // 00ach + 0x00100010, 0x00010010, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00111110, // 00adh + 0x00100000, 0x00100000, 0x00100000, 0x01111111, + 0x00000000, 0x00000000, 0x00111110, 0x00100000, // 00aeh + 0x00111110, 0x00100000, 0x00100000, 0x00111110, + 0x00000000, 0x00000000, 0x00100101, 0x00101010, // 00afh + 0x00101010, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00b0h + 0x01111111, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01111111, 0x01000000, 0x00101000, // 00b1h + 0x00011000, 0x00001000, 0x00001000, 0x00000100, + 0x00000000, 0x01000000, 0x00100000, 0x00011000, // 00b2h + 0x00010111, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x00001000, 0x01111111, 0x01000001, // 00b3h + 0x01000001, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00000000, 0x00111110, 0x00001000, // 00b4h + 0x00001000, 0x00001000, 0x00001000, 0x01111111, + 0x00000000, 0x00100000, 0x01111111, 0x00110000, // 00b5h + 0x00101000, 0x00100100, 0x00100010, 0x00110001, + 0x00000000, 0x00000100, 0x01111111, 0x01000100, // 00b6h + 0x01000100, 0x01000100, 0x01000010, 0x00100001, + 0x00000000, 0x00000100, 0x00111111, 0x00001000, // 00b7h + 0x01111111, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x01111100, 0x01000100, 0x01000100, // 00b8h + 0x01000010, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00000010, 0x01111110, 0x00100010, // 00b9h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01111110, 0x01000000, 0x01000000, // 00bah + 0x01000000, 0x01000000, 0x01000000, 0x01111110, + 0x00000000, 0x00100010, 0x01111111, 0x00100010, // 00bbh + 0x00100010, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x00000011, 0x00000100, 0x01000011, // 00bch + 0x01000100, 0x00100000, 0x00011000, 0x00000111, + 0x00000000, 0x01111111, 0x01000000, 0x00100000, // 00bdh + 0x00010000, 0x00011000, 0x00100100, 0x01000011, + 0x00000000, 0x00000010, 0x01111111, 0x01000010, // 00beh + 0x00100010, 0x00000010, 0x00000010, 0x01111100, + 0x00000000, 0x01000001, 0x01000010, 0x01000000, // 00bfh + 0x00100000, 0x00100000, 0x00011000, 0x00000110, + 0x00000000, 0x01111110, 0x01000010, 0x01001110, // 00c0h + 0x01110001, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x01100000, 0x00011110, 0x00010000, // 00c1h + 0x01111111, 0x00010000, 0x00010000, 0x00001100, + 0x00000000, 0x01000101, 0x01001010, 0x01001010, // 00c2h + 0x01000000, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00111110, 0x00000000, 0x01111111, // 00c3h + 0x00010000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x00000010, 0x00000010, 0x00000110, // 00c4h + 0x00011010, 0x01100010, 0x00000010, 0x00000010, + 0x00000000, 0x00010000, 0x00010000, 0x01111111, // 00c5h + 0x00010000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x00000000, 0x00111110, 0x00000000, // 00c6h + 0x00000000, 0x00000000, 0x00000000, 0x01111111, + 0x00000000, 0x01111110, 0x01000000, 0x01000100, // 00c7h + 0x00101000, 0x00010000, 0x00101000, 0x01000110, + 0x00000000, 0x00001000, 0x01111111, 0x00100000, // 00c8h + 0x00010000, 0x00011100, 0x01101011, 0x00001000, + 0x00000000, 0x01000000, 0x01000000, 0x01000000, // 00c9h + 0x00100000, 0x00100000, 0x00011000, 0x00000111, + 0x00000000, 0x00010010, 0x00100010, 0x00100010, // 00cah + 0x01000010, 0x01000010, 0x01000001, 0x01000001, + 0x00000000, 0x00000001, 0x00000001, 0x01111111, // 00cbh + 0x00000001, 0x00000001, 0x00000001, 0x01111110, + 0x00000000, 0x01111111, 0x01000000, 0x01000000, // 00cch + 0x01000000, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00000000, 0x00000100, 0x00001010, // 00cdh + 0x00010001, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x00001000, 0x00001000, 0x01111111, // 00ceh + 0x00001000, 0x00101010, 0x01001010, 0x01001001, + 0x00000000, 0x01111111, 0x01000000, 0x01000000, // 00cfh + 0x00100010, 0x00010100, 0x00001000, 0x00010000, + 0x00000000, 0x00001110, 0x01110000, 0x00001110, // 00d0h + 0x01110000, 0x00000110, 0x00011000, 0x01100000, + 0x00000000, 0x00001000, 0x00001000, 0x00000100, // 00d1h + 0x00000100, 0x00100010, 0x01000010, 0x01111111, + 0x00000000, 0x01000000, 0x01000000, 0x00100100, // 00d2h + 0x00101000, 0x00010000, 0x00101100, 0x01000011, + 0x00000000, 0x01111111, 0x00000100, 0x01111111, // 00d3h + 0x00000100, 0x00000100, 0x00000100, 0x01111000, + 0x00000000, 0x00000010, 0x01111111, 0x01000010, // 00d4h + 0x00100010, 0x00010100, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00111110, 0x00100000, // 00d5h + 0x00100000, 0x00100000, 0x00100000, 0x01111111, + 0x00000000, 0x01111110, 0x01000000, 0x01000000, // 00d6h + 0x01111110, 0x01000000, 0x01000000, 0x01111110, + 0x00000000, 0x00111110, 0x00000000, 0x01111111, // 00d7h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01000010, 0x01000010, 0x01000010, // 00d8h + 0x01000010, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00001010, 0x00001010, 0x00001010, // 00d9h + 0x01001010, 0x01001010, 0x00101010, 0x00011001, + 0x00000000, 0x00000010, 0x00000010, 0x01000010, // 00dah + 0x01000010, 0x00100010, 0x00010010, 0x00001110, + 0x00000000, 0x01111111, 0x01000001, 0x01000001, // 00dbh + 0x01000001, 0x01000001, 0x01000001, 0x01111111, + 0x00000000, 0x01111111, 0x01000001, 0x01000001, // 00dch + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01000011, 0x01000100, 0x01000000, // 00ddh + 0x01000000, 0x00100000, 0x00010000, 0x00001111, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00deh + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00dfh + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00011110, 0x00001000, 0x00000100, // 00e0h + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x00000000, 0x00001100, 0x00010010, // 00e1h + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01111101, 0x00100001, 0x01111101, // 00e2h + 0x00100001, 0x00111001, 0x01100101, 0x00011001, + 0x00000000, 0x00111100, 0x00010000, 0x00111100, // 00e3h + 0x00010000, 0x00011100, 0x00110010, 0x00001100, + 0x00000000, 0x00001110, 0x00101000, 0x00101000, // 00e4h + 0x00111110, 0x01100101, 0x00100101, 0x00010010, + 0x00000000, 0x00000100, 0x00101111, 0x01000100, // 00e5h + 0x00000110, 0x01000101, 0x01000101, 0x00111110, + 0x00000000, 0x00100010, 0x00100010, 0x00111110, // 00e6h + 0x01010010, 0x01010101, 0x01001101, 0x00100110, + 0x00000000, 0x00000100, 0x00011111, 0x00000010, // 00e7h + 0x00011111, 0x01000010, 0x01000010, 0x00111100, + 0x00000000, 0x00010010, 0x00111110, 0x01010011, // 00e8h + 0x01000010, 0x00100100, 0x00000100, 0x00000100, + 0x00000000, 0x00001000, 0x00111101, 0x01001011, // 00e9h + 0x01001001, 0x01001001, 0x00111000, 0x00000100, + 0x00000000, 0x00001000, 0x00111000, 0x00001000, // 00eah + 0x00001000, 0x00011110, 0x00101001, 0x00000110, + 0x00000000, 0x00011000, 0x00100000, 0x00000100, // 00ebh + 0x00111010, 0x01000110, 0x01000000, 0x00111000, + 0x00000000, 0x01000010, 0x01000010, 0x01000010, // 00ech + 0x01000110, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00111110, 0x00010000, 0x00111100, // 00edh + 0x01000011, 0x01001100, 0x01010010, 0x00111100, + 0x00000000, 0x00100010, 0x00110011, 0x00101010, // 00eeh + 0x00100110, 0x00100010, 0x00100011, 0x01000010, + 0x00000000, 0x00111110, 0x00010000, 0x00111100, // 00efh + 0x01000011, 0x01000000, 0x01000010, 0x00111100, + 0x00000000, 0x00000010, 0x00111011, 0x01000110, // 00f0h + 0x01000010, 0x01000011, 0x01000010, 0x00110010, + 0x00000000, 0x00000100, 0x00000100, 0x00000010, // 00f1h + 0x01000110, 0x01000101, 0x01000101, 0x00111001, + 0x00000000, 0x01010100, 0x01111111, 0x00100100, // 00f2h + 0x00100100, 0x00100100, 0x00100010, 0x00010001, + 0x00000000, 0x01010100, 0x01011111, 0x00000100, // 00f3h + 0x00111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01011110, 0x01100010, 0x00100010, // 00f4h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01010010, 0x01111110, 0x00100010, // 00f5h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01010000, 0x01111111, 0x00100000, // 00f6h + 0x00100000, 0x00100000, 0x00100000, 0x00111111, + 0x00000000, 0x01010010, 0x01010010, 0x00111111, // 00f7h + 0x00010010, 0x00010000, 0x00010000, 0x00001100, + 0x00000000, 0x01010011, 0x01010100, 0x00100011, // 00f8h + 0x00100100, 0x00010000, 0x00001000, 0x00000111, + 0x00000000, 0x01010000, 0x01011111, 0x00010000, // 00f9h + 0x00001000, 0x00001100, 0x00010010, 0x00100001, + 0x00000000, 0x01010010, 0x01111111, 0x00100010, // 00fah + 0x00010010, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x01010001, 0x01010010, 0x00100000, // 00fbh + 0x00100000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x01011110, 0x01010010, 0x00100110, // 00fch + 0x00111001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01010000, 0x01011110, 0x00010000, // 00fdh + 0x01111111, 0x00010000, 0x00010000, 0x00001100, + 0x00000000, 0x00100101, 0x01001010, 0x00101010, // 00feh + 0x00100000, 0x00010000, 0x00001000, 0x00000111, + 0x00000000, 0x01011110, 0x01010000, 0x00111111, // 00ffh + 0x00001000, 0x00001000, 0x00001000, 0x00000110 +}; + + +/*---------------------------------------------------------------------------* + Palette data + *---------------------------------------------------------------------------*/ +const u32 d_PaletteData[8 * 16] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // black + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x001f0000, 0x00000000, 0x00000000, 0x00000000, // red + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03e00000, 0x00000000, 0x00000000, 0x00000000, // green + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7c000000, 0x00000000, 0x00000000, 0x00000000, // blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03ff0000, 0x00000000, 0x00000000, 0x00000000, // yellow + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7c1f0000, 0x00000000, 0x00000000, 0x00000000, // purple + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7fe00000, 0x00000000, 0x00000000, 0x00000000, // light blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00180000, 0x00000000, 0x00000000, 0x00000000, // dark red + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03000000, 0x00000000, 0x00000000, 0x00000000, // dark green + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x60000000, 0x00000000, 0x00000000, 0x00000000, // dark blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03180000, 0x00000000, 0x00000000, 0x00000000, // dark yellow + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x60180000, 0x00000000, 0x00000000, 0x00000000, // dark purple + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x63000000, 0x00000000, 0x00000000, 0x00000000, // dark light blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x56b50000, 0x00000000, 0x00000000, 0x00000000, // gray + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x2d6b0000, 0x00000000, 0x00000000, 0x00000000, // dark gray + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7fff0000, 0x00000000, 0x00000000, 0x00000000, // white + 0x00000000, 0x00000000, 0x00000000, 0x00000000 +}; + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/gcdfirm/gcdfirm-disp/ARM9/include/font.h b/build/gcdfirm/gcdfirm-disp/ARM9/include/font.h new file mode 100644 index 00000000..30d49e95 --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/ARM9/include/font.h @@ -0,0 +1,60 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - SPI - demos - pm-1 + File: font.h + + Copyright 2003-2005 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: font.h,v $ + Revision 1.2 2005/02/28 05:26:12 yosizaki + do-indent. + + Revision 1.1 2004/08/07 01:59:51 yada + modified much + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#ifndef FONT_H_ +#define FONT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +typedef enum +{ + FONT_BLOCK = 0, + FONT_RED = 1, + FONT_GREEN = 2, + FONT_BLUE = 3, + FONT_YELLOW = 4, + FONT_PURPLE = 5, + FONT_CYAAN = 6, + FONT_WHITE = 15 +} +MYFontColor; + +extern const u32 d_CharData[8 * 256]; +extern const u32 d_PaletteData[8 * 16]; + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* FONT_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/gcdfirm/gcdfirm-disp/ARM9/include/screen.h b/build/gcdfirm/gcdfirm-disp/ARM9/include/screen.h new file mode 100644 index 00000000..81ed6790 --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/ARM9/include/screen.h @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - SPI - demos - pm-1 + File: screen.h + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: screen.h,v $ + Revision 1.3 2006/01/18 02:12:28 kitase_hirotake + do-indent + + Revision 1.2 2005/02/28 05:26:12 yosizaki + do-indent. + + Revision 1.1 2004/08/07 01:59:51 yada + modified much + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#ifndef SCREEN_H_ +#define SCREEN_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ +#include + +extern u16 gScreen[32 * 32]; + +void ClearScreen(void); +void PrintString(s16 x, s16 y, u8 palette, char *text, ...); +void ColorString(s16 x, s16 y, s16 length, u8 palette); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* SCREEN_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/gcdfirm/gcdfirm-disp/ARM9/main.c b/build/gcdfirm/gcdfirm-disp/ARM9/main.c new file mode 100644 index 00000000..fb48c3d9 --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/ARM9/main.c @@ -0,0 +1,150 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - ts_dev9 + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include "font.h" +#include "screen.h" +//#include + +//#define PRINT_DEBUG + +#ifndef PRINT_DEBUG +#undef OS_TPrintf +#define OS_TPrintf(...) ((void)0) +#endif // PRINT_DEBUG + +static void myInit(void); +static void myVBlankIntr(void); + +void TwlMain( void ) +{ + s16 x = 2, y = 2; + + OS_TPrintf( "\nGCD Boot time is %d msec.\n", OS_TicksToMilliSecondsBROM32(OS_GetTick())); + + MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) ); + + myInit(); + + OS_TPrintf( "\nARM9 starts.\n" ); + + //---- clear screen buffer + ClearScreen(); + + PrintString( x, y, FONT_CYAAN, "Gcdfirm-Disp" ); + PrintString( (s16)(x+17), y++, FONT_WHITE, "%s", __DATE__ ); + PrintString( (s16)(x+20), y++, FONT_WHITE, "%s", __TIME__ ); + y++; + + PrintString( x, y++, FONT_YELLOW, "Hello!"); + + OS_TPrintf( "\nARM9 ends.\n" ); + + OS_WaitVBlankIntr(); + + OS_Terminate(); +} + +//---------------------------------------------------------------- +// myInit +// +void myInit(void) +{ + //---- init + OS_InitFIRM(); + OS_InitTick(); + OS_InitAlarm(); + FX_Init(); + GX_Init(); + GX_DispOff(); + GXS_DispOff(); + + //---- init displaying + GX_SetBankForLCDC(GX_VRAM_LCDC_ALL); + MI_CpuClearFast((void *)HW_LCDC_VRAM, HW_LCDC_VRAM_SIZE); + (void)GX_DisableBankForLCDC(); + + MI_CpuFillFast((void *)HW_OAM, 192, HW_OAM_SIZE); + MI_CpuClearFast((void *)HW_PLTT, HW_PLTT_SIZE); + MI_CpuFillFast((void *)HW_DB_OAM, 192, HW_DB_OAM_SIZE); + MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE); + + //---- setting 2D for top screen + GX_SetBankForBG(GX_VRAM_BG_128_A); + + G2_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256, + GX_BG_COLORMODE_16, + GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01); + G2_SetBG0Priority(0); + G2_BG0Mosaic(FALSE); + GX_SetGraphicsMode(GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BG0_AS_2D); + GX_SetVisiblePlane(GX_PLANEMASK_BG0); + + GX_LoadBG0Char(d_CharData, 0, sizeof(d_CharData)); + GX_LoadBGPltt(d_PaletteData, 0, sizeof(d_PaletteData)); + + + + //---- setting 2D for bottom screen + GX_SetBankForSubBG(GX_VRAM_SUB_BG_128_C); + + G2S_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256, + GX_BG_COLORMODE_16, + GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01); + G2S_SetBG0Priority(0); + G2S_BG0Mosaic(FALSE); + GXS_SetGraphicsMode(GX_BGMODE_0); + GXS_SetVisiblePlane(GX_PLANEMASK_BG0); + + GXS_LoadBG0Char(d_CharData, 0, sizeof(d_CharData)); + GXS_LoadBGPltt(d_PaletteData, 0, sizeof(d_PaletteData)); + + + //---- screen + MI_CpuFillFast((void *)gScreen, 0, sizeof(gScreen)); + DC_FlushRange(gScreen, sizeof(gScreen)); + /* DMAIOWX^փANZX̂ŃLbV Wait ͕sv */ + // DC_WaitWriteBufferEmpty(); + GX_LoadBG0Scr(gScreen, 0, sizeof(gScreen)); + GXS_LoadBG0Scr(gScreen, 0, sizeof(gScreen)); + + //---- init interrupt + OS_SetIrqFunction(OS_IE_V_BLANK, myVBlankIntr); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + //---- start displaying + GX_DispOn(); + GXS_DispOn(); +} + +//---------------------------------------------------------------- +// myVBlankIntr +// vblank interrupt handler +// +static void myVBlankIntr(void) +{ + //---- upload pseudo screen to VRAM + DC_FlushRange(gScreen, sizeof(gScreen)); + /* DMAIOWX^փANZX̂ŃLbV Wait ͕sv */ + // DC_WaitWriteBufferEmpty(); + GX_LoadBG0Scr(gScreen, 0, sizeof(gScreen)); + GXS_LoadBG0Scr(gScreen, 0, sizeof(gScreen)); + + OS_SetIrqCheckFlag(OS_IE_V_BLANK); +} + diff --git a/build/gcdfirm/gcdfirm-disp/ARM9/screen.c b/build/gcdfirm/gcdfirm-disp/ARM9/screen.c new file mode 100644 index 00000000..8e20145a --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/ARM9/screen.c @@ -0,0 +1,120 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - SPI - demos - pm-1 + File: screen.c + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: screen.c,v $ + Revision 1.3 2006/01/18 02:12:28 kitase_hirotake + do-indent + + Revision 1.2 2005/02/28 05:26:12 yosizaki + do-indent. + + Revision 1.1 2004/08/07 01:59:51 yada + modified much + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include "screen.h" + +u16 gScreen[32 * 32]; +//u16 gScreen2[ 32 * 32 ]; + +// ** these code are refer to rtc sample. thanks. +/*---------------------------------------------------------------------------* + Name: ClearScreen + + Description: clear screen buffer + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void ClearScreen(void) +{ + MI_CpuClearFast((void *)gScreen, sizeof(gScreen)); +} + +/*---------------------------------------------------------------------------* + Name: PrintString + + Description: enter string into screen buffer + string must be within 32 chars + + Arguments: x : x + y : y + palette : color (0-15) + text : string. end mark is NULL + + Returns: None. + *---------------------------------------------------------------------------*/ +void PrintString(s16 x, s16 y, u8 palette, char *text, ...) +{ + va_list vlist; + char temp[32 + 2], *tempPtr; + s32 i; + u16 *p, *pLimit; + + va_start(vlist, text); + (void)vsnprintf(temp, 33, text, vlist); + va_end(vlist); + + *(u16 *)(&temp[32]) = 0; + p = &gScreen[((y * 32) + x) % (32 * 32)]; + pLimit = &gScreen[32 * 32]; + tempPtr = &temp[0]; + + for (i = 0; *tempPtr; i++, tempPtr++) + { + *p = (u16)((palette << 12) | *tempPtr); + if (++p >= pLimit) + { + p = &gScreen[0]; + } + } +} + +/*---------------------------------------------------------------------------* + Name: ColorString + + Description: change string color which is put in screen buffer + + Arguments: x : x + y : y + length : number of characters to change color + palette : color (0-15) + + Returns: None. + *---------------------------------------------------------------------------*/ +void ColorString(s16 x, s16 y, s16 length, u8 palette) +{ + s32 i; + u16 *p, *pLimit; + + if (length < 0) + return; + + p = &gScreen[((y * 32) + x) % (32 * 32)]; + pLimit = &gScreen[32 * 32]; + + for (i = 0; i < length; i++) + { + u16 temp = *p; + temp &= 0x0fff; + temp |= (palette << 12); + *p = temp; + + if (++p >= pLimit) + { + p = &gScreen[0]; + } + } +} diff --git a/build/gcdfirm/gcdfirm-disp/Makefile b/build/gcdfirm/gcdfirm-disp/Makefile new file mode 100644 index 00000000..e541274c --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/Makefile @@ -0,0 +1,52 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - gcdfirm-disp +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + + +# if you have valid keys, set environment value like below +#export TWL_KEYSDIR='$(FIRM_ROOT)/../twl_firmware/bootrom/build/keys' + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + wram_regs \ + ARM7 \ + ARM9 \ + +TARGET_FIRM_BIN = gcdfirm_disp-$(TWL_BUILD_TYPE)$(CODEGEN_ARCH).gcd +BINDIR = . +MAKEFIRM_ARM9 = ARM9/bin/$(TWL_BUILDTYPE_ARM9)/gcdfirm_disp9.tef +MAKEFIRM_ARM7 = ARM7/bin/$(TWL_BUILDTYPE_ARM7)/gcdfirm_disp7.tef +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_gcd.der +LDEPENDS_BIN += wram_regs/wram_regs.rbin + +MAKEFIRM_FLAGS += -p +FIRM_SPEC = gcdfirm.gcdsf + +LDIRT_CLEAN += $(wildcard *.gcd) \ + rsa_public.sbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/gcdfirm/gcdfirm-disp/gcdfirm.gcdsf b/build/gcdfirm/gcdfirm-disp/gcdfirm.gcdsf new file mode 100644 index 00000000..b5a9fa74 --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/gcdfirm.gcdsf @@ -0,0 +1,21 @@ +#GCDSF --- Gcdfirm Spec File + +VERSION : 0x0 # GENERATE + +RSA_KEY : $(MAKEFIRM_RSA_PRVKEY) +OUT_KEY : rsa_public.sbin + +WRAM_RBIN : ./wram_regs/wram_regs.rbin + +ARM9_COMP : FALSE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).TWL.FLX.sbin +ARM9_ELF : $(MAKEFIRM_ARM9).tef + +ARM7_COMP : FALSE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).TWL.FLX.sbin +ARM7_ELF : $(MAKEFIRM_ARM7).tef + +ARM9_X2 : TRUE # TRUE or FALSE + +#NORFIRM : $(NORFIRM_BIN) +#NANDFIRM : $(NANDFIRM_BIN) diff --git a/build/gcdfirm/gcdfirm-disp/wram_regs/Makefile b/build/gcdfirm/gcdfirm-disp/wram_regs/Makefile new file mode 100644 index 00000000..66504d9a --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/wram_regs/Makefile @@ -0,0 +1,57 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - menu-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM := TWL +override TARGET_CODEGEN := ARM +override TWL_ARCHGEN := LIMITED + +override TARGET_FINALROM := TRUE +override TARGET_RELEASE := +override TARGET_DEBUG := + +SUBDIRS = + +LINCLUDES = ../include + + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/gcdfirm/gcdfirm-disp/wram_regs/wram_regs.c b/build/gcdfirm/gcdfirm-disp/wram_regs/wram_regs.c new file mode 100644 index 00000000..f03e0e14 --- /dev/null +++ b/build/gcdfirm/gcdfirm-disp/wram_regs/wram_regs.c @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - nandfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-11-12#$ + $Rev: 149 $ + $Author: yutaka $ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM9 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_A_SIZE ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE - HW_WRAM_C_SIZE ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/gcdfirm/gcdfirm-print/Makefile b/build/gcdfirm/gcdfirm-print/Makefile new file mode 100644 index 00000000..592a90bb --- /dev/null +++ b/build/gcdfirm/gcdfirm-print/Makefile @@ -0,0 +1,46 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - build +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + + +#---------------------------------------------------------------------------- + +SUBDIRS = ../../norfirm/norfirm-print + +TARGET_FIRM_BIN = gcdfirm_print-$(TWL_BUILD_TYPE).gcd +BINDIR = . +MAKEFIRM_ARM9 = ../../norfirm/norfirm-print/ARM9/bin/$(TWL_BUILDTYPE_ARM9)/twl_norfirm9_print.tef +MAKEFIRM_ARM7 = ../../norfirm/norfirm-print/ARM7/bin/$(TWL_BUILDTYPE_ARM7)/twl_norfirm7_print.tef +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_gcd.der +LDEPENDS_BIN += ../../norfirm/norfirm-print/wram_regs/wram_regs.rbin + +MAKEFIRM_FLAGS += -p +FIRM_SPEC = gcdfirm.gcdsf + +LDIRT_CLEAN += $(wildcard *.gcd) \ + rsa_public.sbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/gcdfirm/gcdfirm-print/gcdfirm.gcdsf b/build/gcdfirm/gcdfirm-print/gcdfirm.gcdsf new file mode 100644 index 00000000..1a0a93a2 --- /dev/null +++ b/build/gcdfirm/gcdfirm-print/gcdfirm.gcdsf @@ -0,0 +1,22 @@ +#GCDSF --- Gcdfirm Spec File + +VERSION : GENERATE + +RSA_KEY : $(MAKEFIRM_RSA_PRVKEY) +OUT_KEY : rsa_public.sbin + +WRAM_RBIN: ../../norfirm/norfirm-print/wram_regs/wram_regs.rbin + +DECOMP_PROC : ARM9 # ARM9 or ARM7 + +ARM9_COMP : FALSE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).TWL.FLX.sbin +ARM9_ELF : $(MAKEFIRM_ARM9).tef + +ARM7_COMP : FALSE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).TWL.FLX.sbin +ARM7_ELF : $(MAKEFIRM_ARM7).tef + +ARM9_X2 : TRUE # TRUE or FALSE + +NCD_ROMOFS : 0x07fe00 diff --git a/build/gcdfirm/sdmc-launcher/ARM7/Makefile b/build/gcdfirm/sdmc-launcher/ARM7/Makefile new file mode 100644 index 00000000..2c85da75 --- /dev/null +++ b/build/gcdfirm/sdmc-launcher/ARM7/Makefile @@ -0,0 +1,49 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - sdmc-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +TWL_PROC = ARM7 + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = sdmc_launcher7.tef + +SRCS = main.c + +CRT0_O = crt0_firm.o + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/gcdfirm/sdmc-launcher/ARM7/main.c b/build/gcdfirm/sdmc-launcher/ARM7/main.c new file mode 100644 index 00000000..f5936b8c --- /dev/null +++ b/build/gcdfirm/sdmc-launcher/ARM7/main.c @@ -0,0 +1,314 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - gcdfirm - sdmc-launcher + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +/* + PROFILE_ENABLE `Ƃx̃ptH[}X`FbNł܂B + p邽߂ɂ́Amain.cǂɁAu32 profile[256]; u32 pf_cnt = 0; + `Kv܂B +*/ +#define PROFILE_ENABLE + +/* + fobOLEDFINALROMƂ͕ʂOn/Offł܂B +*/ +#define USE_DEBUG_LED + +/* + PRINT_MEMORY_ADDR `ƁÃAhXSPrintfs܂(̃t@Ĉ) + FINALROMłłR[hĉŒӂĂB +*/ +//#define PRINT_MEMORY_ADDR 0x02FFC800 + + +#ifdef PROFILE_ENABLE +#define PROFILE_MAX 16 +u32 profile[PROFILE_MAX]; +u32 pf_cnt = 0; +#define PUSH_PROFILE() (profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick())) +#else +#define PUSH_PROFILE() ((void)0) +#endif + +#ifdef USE_DEBUG_LED +static u8 step = 0x80; +#define InitDebugLED() I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x03, 0x00) +#define SetDebugLED(pattern) I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, (pattern)); +#else +#define InitDebugLED() ((void)0) +#define SetDebugLED(pattern) ((void)0) +#endif + +#ifdef PRINT_MEMORY_ADDR +static char* debugPtr = (char*)PRINT_MEMORY_ADDR; +#undef OS_TPrintf +//#define OS_TPrintf(...) (debugPtr = (char*)((u32)(debugPtr + STD_TSPrintf(debugPtr, __VA_ARGS__) + 0xf) & ~0xf)) +#define OS_TPrintf(...) (debugPtr += STD_TSPrintf(debugPtr, __VA_ARGS__)) +#endif + +#define THREAD_PRIO_FATFS 8 +#define DMA_FATFS_1 3 +#define DMA_FATFS_2 2 + +extern void* SDNandContext; /* NANDp[^ */ + +static ROM_Header* const rh= (ROM_Header*)HW_TWL_ROM_HEADER_BUF; + +static OSThread idleThread; +static u64 idleStack[32]; +static void IdleThread(void* arg) +{ +#pragma unused(arg) + OS_EnableInterrupts(); + while (1) + { + OS_Halt(); + } +} +static void CreateIdleThread(void) +{ + OS_CreateThread(&idleThread, IdleThread, NULL, &idleStack[32], sizeof(idleStack), OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&idleThread); +} + +/*************************************************************** + PreInit + + FromBoot̑ΉC̏ + OS_InitOȂ̂Œ (ARM9ɂ郁CŏȂ悤ɒ) +***************************************************************/ +static void PreInit(void) +{ + /* + obe[cʃ`FbN + */ + if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) + { + OS_TPrintf("Battery is empty.\n"); + OS_Terminate(); + } + /* + FromBrom֘A + */ + if ( !OSi_FromBromToMenu() ) + { + OS_Terminate(); + } + /* + Zbgp[^(1oCg)L̈(1oCg)ɃRs[ + */ +#define HOTSTART_FLAG_ENABLE 0x80 + *(u8 *)HW_NAND_FIRM_HOTSTART_FLAG = (u8)(MCU_GetFreeRegister( OS_MCU_RESET_VALUE_OFS ) | HOTSTART_FLAG_ENABLE); +} + +/*************************************************************** + PostInit + + e평 +***************************************************************/ +static void PostInit(void) +{ + // PMIC̐ݒ for old version + PM_InitFIRM(); + // AES̏ + AES_Init(); // for encrypted NAND + // AChXbh̍쐬 + CreateIdleThread(); + /* + obe[cʃ`FbN + */ + if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) + { + OS_TPrintf("Battery is empty.\n"); + OS_Terminate(); + } +} + +/*************************************************************** + EraseAll + + sI܂ + 낢Ă + DS[hɂďÎ悢H +***************************************************************/ +static void EraseAll(void) +{ + MI_CpuClearFast( OSi_GetFromFirmAddr(), sizeof(OSFromFirmBuf) ); +#ifdef SDK_FINALROM + MI_CpuClearFast( (void*)HW_TWL_ROM_HEADER_BUF, HW_TWL_ROM_HEADER_BUF_SIZE ); + OS_BootFromFIRM(); +#endif +} + +void TwlSpMain( void ) +{ + int fd; // menu file descriptor + +#ifdef PROFILE_ENABLE + // 0: bootrom + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + InitDebugLED(); + SetDebugLED(++step); // 0x81 + + PreInit(); +#ifdef PROFILE_ENABLE + // 1: after PreInit + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + SetDebugLED(++step); // 0x82 + + OS_InitFIRM(); + OS_EnableIrq(); + OS_EnableInterrupts(); + // 2: after OS_InitFIRM + PUSH_PROFILE(); + SetDebugLED(++step); // 0x83 + + PostInit(); + // 3: after PostInit + PUSH_PROFILE(); + SetDebugLED(++step); // 0x84 + + PM_BackLightOn( FALSE ); + + SDNandContext = &OSi_GetFromFirmAddr()->SDNandContext; + if ( !FATFS_Init( DMA_FATFS_1, DMA_FATFS_2, THREAD_PRIO_FATFS ) ) + { + OS_TPrintf("Failed to call FATFS_Init().\n"); + goto end; + } + // 4: after FATFS_Init + PUSH_PROFILE(); + SetDebugLED(++step); // 0x85 + + PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_SET_PATH ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_SET_PATH).\n"); + goto end; + } + // 5: after PXI + PUSH_PROFILE(); + SetDebugLED(++step); // 0x86 + + PM_BackLightOn( FALSE ); + + if ( (fd = FS_OpenSrl()) < 0 ) + { + OS_TPrintf("Failed to call FS_OpenSrl().\n"); + goto end; + } + // 6: after FS_OpenSrl + PUSH_PROFILE(); + SetDebugLED(++step); // 0x87 + + PM_BackLightOn( FALSE ); + + if ( !FS_LoadHeader( fd ) ) + { + OS_TPrintf("Failed to call FS_LoadHeader().\n"); + goto end; + } + // 7: after FS_LoadHeader + PUSH_PROFILE(); + SetDebugLED(++step); // 0x88 + + PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_DONE_HEADER ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_DONE_HEADER).\n"); + goto end; + } + // 8: after PXI + PUSH_PROFILE(); + SetDebugLED(++step); // 0x89 + + PM_BackLightOn( FALSE ); + + AESi_InitKeysFIRM(); + AESi_RecvSeed( rh->s.developer_encrypt ); + // 9: after AESi_RecvSeed + PUSH_PROFILE(); + SetDebugLED(++step); // 0x8a + + PM_BackLightOn( FALSE ); + + if ( !FS_LoadStatic( fd ) ) + { + OS_TPrintf("Failed to call FS_LoadStatic().\n"); + goto end; + } + // 10: after FS_LoadStatic + PUSH_PROFILE(); + SetDebugLED(++step); // 0x8b + + PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_DONE_STATIC ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_DONE_STATIC).\n"); + goto end; + } + // 11: after PXI + PUSH_PROFILE(); + +#ifdef PROFILE_ENABLE + { + int i; + PXI_RecvID(); + OS_TPrintf("\n[ARM7] Begin\n"); + for (i = 0; i < PROFILE_MAX; i++) + { +// OS_TPrintf("0x%08X\n", profile[i]); + if ( !profile[i] ) break; + OS_TPrintf("%2d: %7d usec", i, profile[i]); + if (i) + { + OS_TPrintf(" ( %7d usec )\n", profile[i]-profile[i-1]); + } + else + { + OS_TPrintf("\n"); + } + } + OS_TPrintf("\n[ARM7] End\n"); + } +#endif + SetDebugLED( 0 ); + + PM_BackLightOn( TRUE ); // last chance + + PMi_SetParams( REG_PMIC_BL_BRT_B_ADDR, 22, PMIC_BL_BRT_B_MASK ); + OS_BootFromFIRM(); + +end: + SetDebugLED( (u8)(0xF0 | step)); + + EraseAll(); + + // failed + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + OS_Terminate(); +} + diff --git a/build/gcdfirm/sdmc-launcher/ARM9/Makefile b/build/gcdfirm/sdmc-launcher/ARM9/Makefile new file mode 100644 index 00000000..1c0bbd29 --- /dev/null +++ b/build/gcdfirm/sdmc-launcher/ARM9/Makefile @@ -0,0 +1,51 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - sdmc-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = sdmc_launcher9.srl + +SRCS = main.c + +CRT0_O = crt0_firm.o + +MAKEROM_ARM7 = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/sdmc_launcher7.tef +MAKEROM_ARM7_BASE = $(basename $(MAKEROM_ARM7)) + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/gcdfirm/sdmc-launcher/ARM9/main.c b/build/gcdfirm/sdmc-launcher/ARM9/main.c new file mode 100644 index 00000000..b7ef81b7 --- /dev/null +++ b/build/gcdfirm/sdmc-launcher/ARM9/main.c @@ -0,0 +1,327 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - gcdfirm - sdmc-launcher + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include + +#define RSA_KEY_ADDR rsa_key + +#ifndef FIRM_USE_TWLSDK_KEYS +static const u8 rsa_key[128] = +{ + 0xC7, 0x94, 0x50, 0x00, 0x3A, 0xE1, 0x0E, 0x6C, 0xA8, 0xD1, 0xC0, 0x2D, 0x77, 0xB7, 0x6D, 0xBC, + 0x31, 0xDB, 0x12, 0x08, 0x09, 0x0D, 0x2A, 0xE8, 0xC9, 0x1A, 0x2B, 0x6E, 0x6C, 0x85, 0x78, 0xD7, + 0x46, 0x50, 0x05, 0xB5, 0xCC, 0x3B, 0xEC, 0xBA, 0xF4, 0xDE, 0xC2, 0x13, 0x13, 0xBE, 0x67, 0xEE, + 0x85, 0x19, 0xEB, 0x62, 0xB3, 0x5C, 0x09, 0xA8, 0x54, 0x44, 0x26, 0x85, 0x25, 0xEA, 0xE5, 0x85, + 0xD1, 0xB5, 0xCE, 0xA0, 0xFF, 0x6B, 0x61, 0xCA, 0x94, 0xC1, 0x67, 0xBE, 0xC0, 0x7E, 0x3B, 0xFF, + 0x12, 0x9B, 0x79, 0xDB, 0xAC, 0xD3, 0x5A, 0x3F, 0x14, 0x37, 0x49, 0xA8, 0x7C, 0x2F, 0x07, 0xF4, + 0x8B, 0xA9, 0x8B, 0x8D, 0xB2, 0x60, 0xA5, 0xD5, 0x64, 0xEE, 0xCF, 0x3F, 0x32, 0xEE, 0x77, 0xAC, + 0x27, 0x75, 0x2B, 0x04, 0xD7, 0x26, 0xA8, 0x8A, 0x55, 0x2A, 0x76, 0xE5, 0x68, 0x80, 0x57, 0x85 +}; +#else +static const u8 rsa_key[128] = +{ + 0xAC, 0x93, 0xBB, + 0x3C, 0x15, 0x5C, 0x5F, 0x25, 0xB0, 0x4C, 0x37, 0xA4, 0x2D, 0x85, 0x29, 0x1D, 0x7A, 0x9D, 0x2D, + 0xD5, 0x79, 0xB5, 0x5D, 0xB1, 0x08, 0x20, 0x9C, 0xF0, 0x4C, 0x56, 0x27, 0x97, 0xF8, 0x7E, 0x3E, + 0xCB, 0x94, 0x06, 0x05, 0x94, 0x00, 0x92, 0x9B, 0xB0, 0x5B, 0x06, 0xF6, 0xAF, 0xAA, 0x9C, 0xA5, + 0xF0, 0x11, 0xA7, 0x8A, 0xCB, 0x0C, 0x11, 0xD6, 0x0C, 0x3D, 0x30, 0xAC, 0x51, 0x79, 0x5A, 0xB5, + 0x7F, 0x11, 0x92, 0x74, 0x48, 0x82, 0x81, 0xBF, 0x3B, 0xFA, 0x93, 0xBF, 0x6B, 0x5B, 0x3F, 0x86, + 0x96, 0x4F, 0xCC, 0x90, 0x12, 0xB2, 0x39, 0x8D, 0x68, 0x16, 0x7B, 0xC6, 0x87, 0xF1, 0xF5, 0x60, + 0x62, 0x39, 0xFB, 0x10, 0x7E, 0x48, 0x7F, 0xDD, 0x82, 0x38, 0x38, 0x76, 0xB5, 0xCE, 0x21, 0x4B, + 0xC9, 0x6F, 0x31, 0x8D, 0x23, 0x57, 0x3D, 0xB6, 0x6C, 0xEE, 0xC2, 0x0D, 0x11 +}; +#endif + +#define RSA_HEAP_SIZE (4*1024) // RSApq[vTCY (TCYKv) + +static u8 acHeap[RSA_HEAP_SIZE] __attribute__ ((aligned (32))); +static SVCSignHeapContext acPool; + +#define MENU_FILE "sdmc:/menu.srl" + +/* + PROFILE_ENABLE `Ƃx̃ptH[}X`FbNł܂B + p邽߂ɂ́Amain.cǂɁAu32 profile[256]; u32 pf_cnt = 0; + `Kv܂B +*/ +#define PROFILE_ENABLE + +/* + PRINT_MEMORY_ADDR `ƁÃAhXSPrintfs܂(̃t@Ĉ) + FINALROMłłR[hĉŒӂĂB +*/ +//#define PRINT_MEMORY_ADDR 0x02FFC000 + +//#ifdef SDK_FINALROM // FINALROMŖ +//#undef PROFILE_ENABLE +//#endif + +#ifdef PROFILE_ENABLE +#define PROFILE_MAX 16 +u32 profile[PROFILE_MAX]; +u32 pf_cnt = 0; +#define PUSH_PROFILE() (profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick())) +#else +#define PUSH_PROFILE() ((void)0) +#endif + +#ifdef PRINT_MEMORY_ADDR +static char* debugPtr = (char*)PRINT_MEMORY_ADDR; +#undef OS_TPrintf +//#define OS_TPrintf(...) (debugPtr = (char*)((u32)(debugPtr + STD_TSPrintf(debugPtr, __VA_ARGS__) + 0xf) & ~0xf)) +#define OS_TPrintf(...) (debugPtr += STD_TSPrintf(debugPtr, __VA_ARGS__)) +#endif + +/*************************************************************** + PreInit + + FromBoot̑ΉOS_InitOɕKvȃC̏ +***************************************************************/ +static void PreInit(void) +{ + static const OSMountInfo firmSettings[] = + { + // drive device target pertitionIdx resource userPermission rsvA B archive path + { 'A', OS_MOUNT_DEVICE_SD, OS_MOUNT_TGT_ROOT, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "sdmc", "/" }, + { 'B', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_ROOT, 0, OS_MOUNT_RSC_WRAM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "nand", "/" }, // [U[Av͂̃A[JCułWrites + { 'C', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_ROOT, 1, OS_MOUNT_RSC_WRAM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "nand2", "/" }, // [U[Av͂̃A[JCułWrites + { 'D', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_DIR, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "shared2", "nand2:/shared2" }, + { 'E', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_DIR, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "photo", "nand2:/photo" }, + { 0 } + }; + /* + C֘A + */ + // SHARED̈NA + MI_CpuClearFast((void *)HW_WRAM_EX_LOCK_BUF, (HW_WRAM_EX_LOCK_BUF_END - HW_WRAM_EX_LOCK_BUF)); + MI_CpuClearFast((void *)HW_BIOS_EXCP_STACK_MAIN, (HW_REAL_TIME_CLOCK_BUF - HW_BIOS_EXCP_STACK_MAIN)); + MI_CpuClearFast((void *)HW_PXI_SIGNAL_PARAM_ARM9, (HW_MMEMCHECKER_MAIN - HW_PXI_SIGNAL_PARAM_ARM9)); + MI_CpuClearFast((void*)HW_ROM_HEADER_BUF, (HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF)); + + // FS_MOUNT̈̏ + MI_CpuCopy8(firmSettings, (char*)HW_TWL_FS_MOUNT_INFO_BUF, sizeof(firmSettings)); + + /* + FromBrom֘A + */ + if ( !OSi_FromBromToMenu() ) + { + OS_Terminate(); + } + + // u[g^Cv̕ύX + ( (OSBootInfo *)OS_GetBootInfo() )->boot_type = OS_BOOTTYPE_NAND; +} + +/*************************************************************** + PostInit + + e평 +***************************************************************/ +static void PostInit(void) +{ + // RSApq[vݒ + SVC_InitSignHeap( &acPool, acHeap, sizeof(acHeap) ); + // HMACp + FS_SetDigestKey( NULL ); + // FS/FATFS + FS_InitFIRM(); +} + +/*************************************************************** + CheckHeader + + wb_VXej[ƂĖȂ`FbN +***************************************************************/ +static BOOL CheckHeader(void) +{ + static ROM_Header_Short* const rhs = (ROM_Header_Short*)HW_TWL_ROM_HEADER_BUF; + // CjVR[hȂ + OS_TPrintf("Initial Code : %08X (%.4s)\n", *(u32*)rhs->game_code, rhs->game_code); + OS_TPrintf("Platform Code : %02X\n", rhs->platform_code); + OS_TPrintf("Codec Mode : %s\n", rhs->codec_mode ? "TWL" : "NITRO"); + OS_TPrintf("Sigunature : %s\n", rhs->enable_signature ? "AVAILABLE" : "NOT AVAILABLE"); + OS_TPrintf("AES Encryption : %s\n", rhs->enable_aes ? "AVAILABLE" : "NOT AVAILABLE"); + if ( rhs->enable_aes ) + { + OS_TPrintf("AES Key Type : %s\n", rhs->developer_encrypt ? "FOR DEVELOPMENT" : "FOR PRODUCT"); + } + // Gg|Cg + OS_TPrintf("ARM9 Entry point : %08X\n", rhs->main_entry_address); + OS_TPrintf("ARM7 Entry point : %08X\n", rhs->sub_entry_address); + // [h͈ + OS_TPrintf("ARM9 ROM address : %08X\n", rhs->main_rom_offset); + OS_TPrintf("ARM9 RAM address : %08X\n", rhs->main_ram_address); + OS_TPrintf("ARM9 size : %08X\n", rhs->main_size); + OS_TPrintf("ARM7 ROM address : %08X\n", rhs->sub_rom_offset); + OS_TPrintf("ARM7 RAM address : %08X\n", rhs->sub_ram_address); + OS_TPrintf("ARM7 size : %08X\n", rhs->sub_size); + OS_TPrintf("ARM9 LTD ROM address: %08X\n", rhs->main_ltd_rom_offset); + OS_TPrintf("ARM9 LTD RAM address: %08X\n", rhs->main_ltd_ram_address); + OS_TPrintf("ARM9 LTD size : %08X\n", rhs->main_ltd_size); + OS_TPrintf("ARM7 LTD ROM address: %08X\n", rhs->sub_ltd_rom_offset); + OS_TPrintf("ARM7 LTD RAM address: %08X\n", rhs->sub_ltd_ram_address); + OS_TPrintf("ARM7 LTD size : %08X\n", rhs->sub_ltd_size); + // قڍœKς +#ifndef FIRM_USE_TWLSDK_KEYS + if ( rhs->platform_code != PLATFORM_CODE_TWL_LIMITED || // TWL Limited only + !rhs->enable_signature || // Should be use ROM header signature +#else + if ( // no check +#endif + !rhs->codec_mode || // TWL mode only + // should be in main memory + HW_TWL_MAIN_MEM > (u32)rhs->main_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->sub_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->main_ltd_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->sub_ltd_ram_address || + // should be in static area without Limited region + (u32)rhs->main_ram_address > (u32)rhs->main_entry_address || + (u32)rhs->sub_ram_address > (u32)rhs->sub_entry_address || + // should be in main memory (end address) + HW_TWL_MAIN_MEM_END <= (u32)rhs->main_ram_address + rhs->main_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->sub_ram_address + rhs->sub_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->main_ltd_ram_address + rhs->main_ltd_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->sub_ltd_ram_address + rhs->sub_ltd_size || + // should be in static area without Limited region (end address) + (u32)rhs->main_ram_address + rhs->main_size <= (u32)rhs->main_entry_address || + (u32)rhs->sub_ram_address + rhs->sub_size <= (u32)rhs->sub_entry_address || + 0 ) + { + OS_TPrintf("Invalid ROM header for SDMC Launcher!\n"); + return FALSE; + } + return TRUE; +} + +/*************************************************************** + EraseAll + + sI܂ + 낢Ă + DS[hɂďÎ悢H +***************************************************************/ +static void EraseAll(void) +{ + MI_CpuClearFast( OSi_GetFromFirmAddr(), sizeof(OSFromFirmBuf) ); +#ifdef SDK_FINALROM + MI_CpuClearFast( (void*)HW_TWL_ROM_HEADER_BUF, HW_TWL_ROM_HEADER_BUF_SIZE ); + MI_CpuClearFast( (void*)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF ); + OS_BootFromFIRM(); +#endif +} + +void TwlMain( void ) +{ +#ifdef PROFILE_ENABLE + // 0: bootrom + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + + PreInit(); +#ifdef PROFILE_ENABLE + // 1: before OS_InitFIRM + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + + OS_InitFIRM(); + OS_EnableIrq(); + OS_EnableInterrupts(); +#ifdef PROFILE_ENABLE + // 2: before OS_InitTick + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); + + OS_InitTick(); +#endif + + PostInit(); + // 3: after PostInit + PUSH_PROFILE(); + + STD_CopyString((char*)HW_TWL_FS_BOOT_SRL_PATH_BUF, MENU_FILE); + // 4: after STD_CopyString + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_SET_PATH ); + // 5: after PXI + PUSH_PROFILE(); + + if ( !FS_LoadHeader(&acPool, RSA_KEY_ADDR ) || !CheckHeader() ) + { + OS_TPrintf("Failed to call FS_LoadHeader() and/or CheckHeader().\n"); + goto end; + } + // 6: after FS_LoadHeader + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_DONE_HEADER ); + // 7: after PXI + PUSH_PROFILE(); + + AESi_SendSeed( FS_GetAesKeySeed() ); + FS_DeleteAesKeySeed(); + // 8: after AESi_SendSeed + PUSH_PROFILE(); + + if ( !FS_LoadStatic() ) + { + OS_TPrintf("Failed to call FS_LoadStatic().\n"); + goto end; + } + // 9: after FS_LoadStatic + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); + // 10: after PXI + PUSH_PROFILE(); + +#ifdef PROFILE_ENABLE + { + int i; + OS_TPrintf("\n[ARM9] Begin\n"); + for (i = 0; i < PROFILE_MAX; i++) + { +// OS_TPrintf("0x%08X\n", profile[i]); + if ( !profile[i] ) break; + OS_TPrintf("%2d: %7d usec", i, profile[i]); + if (i) + { + OS_TPrintf(" ( %7d usec )\n", profile[i]-profile[i-1]); + } + else + { + OS_TPrintf("\n"); + } + } + OS_TPrintf("\n[ARM9] End\n"); + PXI_NotifyID( FIRM_PXI_ID_NULL ); + } +#endif + + MI_CpuClearFast( OSi_GetFromFirmAddr(), sizeof(OSFromFirmBuf) ); + OS_BootFromFIRM(); + +end: + EraseAll(); + + // failed + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + OS_Terminate(); +} + diff --git a/build/gcdfirm/sdmc-launcher/Makefile b/build/gcdfirm/sdmc-launcher/Makefile new file mode 100644 index 00000000..3fc5086b --- /dev/null +++ b/build/gcdfirm/sdmc-launcher/Makefile @@ -0,0 +1,52 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - gcdfirm-disp +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + + +# if you have valid keys, set environment value like below +#export TWL_KEYSDIR='$(TWL_IPL_RED_ROOT)/../twl_firmware/bootrom/build/keys' + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + wram_regs \ + ARM7 \ + ARM9 \ + +TARGET_FIRM_BIN = sdmc_launcher-$(TWL_BUILD_TYPE)$(CODEGEN_ARCH).gcd +BINDIR = . +MAKEFIRM_ARM9 = ARM9/bin/$(TWL_BUILDTYPE_ARM9)/sdmc_launcher9.tef +MAKEFIRM_ARM7 = ARM7/bin/$(TWL_BUILDTYPE_ARM7)/sdmc_launcher7.tef +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_gcd.der +LDEPENDS_BIN += wram_regs/wram_regs.rbin + +MAKEFIRM_FLAGS += -p +FIRM_SPEC = gcdfirm.gcdsf + +LDIRT_CLEAN += $(wildcard *.gcd) \ + rsa_public.sbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/gcdfirm/sdmc-launcher/gcdfirm.gcdsf b/build/gcdfirm/sdmc-launcher/gcdfirm.gcdsf new file mode 100644 index 00000000..b5a9fa74 --- /dev/null +++ b/build/gcdfirm/sdmc-launcher/gcdfirm.gcdsf @@ -0,0 +1,21 @@ +#GCDSF --- Gcdfirm Spec File + +VERSION : 0x0 # GENERATE + +RSA_KEY : $(MAKEFIRM_RSA_PRVKEY) +OUT_KEY : rsa_public.sbin + +WRAM_RBIN : ./wram_regs/wram_regs.rbin + +ARM9_COMP : FALSE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).TWL.FLX.sbin +ARM9_ELF : $(MAKEFIRM_ARM9).tef + +ARM7_COMP : FALSE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).TWL.FLX.sbin +ARM7_ELF : $(MAKEFIRM_ARM7).tef + +ARM9_X2 : TRUE # TRUE or FALSE + +#NORFIRM : $(NORFIRM_BIN) +#NANDFIRM : $(NANDFIRM_BIN) diff --git a/build/gcdfirm/sdmc-launcher/wram_regs/Makefile b/build/gcdfirm/sdmc-launcher/wram_regs/Makefile new file mode 100644 index 00000000..66504d9a --- /dev/null +++ b/build/gcdfirm/sdmc-launcher/wram_regs/Makefile @@ -0,0 +1,57 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - menu-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM := TWL +override TARGET_CODEGEN := ARM +override TWL_ARCHGEN := LIMITED + +override TARGET_FINALROM := TRUE +override TARGET_RELEASE := +override TARGET_DEBUG := + +SUBDIRS = + +LINCLUDES = ../include + + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/gcdfirm/sdmc-launcher/wram_regs/wram_regs.c b/build/gcdfirm/sdmc-launcher/wram_regs/wram_regs.c new file mode 100644 index 00000000..2454b302 --- /dev/null +++ b/build/gcdfirm/sdmc-launcher/wram_regs/wram_regs.c @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - nandfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM9 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_A_SIZE ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE - HW_WRAM_C_SIZE ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/libraries/Makefile b/build/libraries/Makefile new file mode 100644 index 00000000..2c3fb71b --- /dev/null +++ b/build/libraries/Makefile @@ -0,0 +1,40 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS_P = \ + init \ + os \ + pxi \ + fs \ + mi \ + fatfs \ + aes \ + pm \ + gcd \ + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/aes/ARM7/Makefile b/build/libraries/aes/ARM7/Makefile new file mode 100644 index 00000000..810b504f --- /dev/null +++ b/build/libraries/aes/ARM7/Makefile @@ -0,0 +1,52 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - aes +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = + + +#---------------------------------------------------------------------------- + +# build ARM & THUMB libraries +TWL_CODEGEN_ALL ?= TRUE + +# Codegen for sub processer +TWL_PROC = ARM7 + +SRCDIR = . + +SRCS = \ + aes_init.c \ + +TARGET_LIB = libaes_sp$(FIRM_LIBSUFFIX).a + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries/aes/ARM7/aes_init.c b/build/libraries/aes/ARM7/aes_init.c new file mode 100644 index 00000000..b8e6b3d5 --- /dev/null +++ b/build/libraries/aes/ARM7/aes_init.c @@ -0,0 +1,137 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - aes + File: aes_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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include + +/*---------------------------------------------------------------------------* + Name: AESi_InitKeysForApp + + Description: set IDs depending on the application. + you SHOULD NOT touch any ID registers after this call. + + Arguments: game_code game code + + Returns: None + *---------------------------------------------------------------------------*/ +void AESi_InitKeysForApp( u8 game_code[4] ) +{ + AES_Lock(); + AES_WaitKey(); + + reg_AES_AES_ID_A2 = AES_IDS_ID0_C(game_code); + reg_AES_AES_ID_A3 = AES_IDS_ID0_D(game_code); + reg_AES_AES_ID_B0 = AES_IDS_ID1_A(game_code); + reg_AES_AES_ID_B1 = AES_IDS_ID1_B(game_code); + AES_Unlock(); +} + +/*---------------------------------------------------------------------------* + Name: AESi_InitKeysForHard + + Description: set IDs depending on the system hardware. + you SHOULD NOT use this for standard applications. + + Arguments: fuse camouflaged fuse id + + Returns: None + *---------------------------------------------------------------------------*/ +void AESi_InitKeysForHard( u8 fuse[8] ) +{ + AES_Lock(); + AES_WaitKey(); + + reg_AES_AES_ID_B2 = *(u32*)&fuse[4]; + reg_AES_AES_ID_B3 = *(u32*)&fuse[0]; + reg_AES_AES_ID_D0 = *(u32*)&fuse[0]; + reg_AES_AES_ID_D3 = *(u32*)&fuse[4]; + AES_Unlock(); +} + +/*---------------------------------------------------------------------------* + Name: AESi_ResetAesKey + + Description: set SEED/KEYs filler data without seed[3] + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void AESi_ResetAesKey( void ) +{ + AES_Lock(); + AES_WaitKey(); + + // set dummy without seed[3] + reg_AES_AES_SEED_A0 = 1; + reg_AES_AES_SEED_A1 = 2; + reg_AES_AES_SEED_A2 = 3; + reg_AES_AES_SEED_B0 = 4; + reg_AES_AES_SEED_B1 = 5; + reg_AES_AES_SEED_B2 = 6; + reg_AES_AES_SEED_C0 = 7; + reg_AES_AES_SEED_C1 = 8; + reg_AES_AES_SEED_C2 = 9; + reg_AES_AES_SEED_D0 = 10; + reg_AES_AES_SEED_D1 = 11; + reg_AES_AES_SEED_D2 = 12; + + reg_AES_AES_KEY_A0 = 1; + reg_AES_AES_KEY_A1 = 2; + reg_AES_AES_KEY_A2 = 3; + reg_AES_AES_KEY_A3 = 3; + reg_AES_AES_KEY_B0 = 4; + reg_AES_AES_KEY_B1 = 5; + reg_AES_AES_KEY_B2 = 6; + reg_AES_AES_KEY_B3 = 6; + reg_AES_AES_KEY_C0 = 7; + reg_AES_AES_KEY_C1 = 8; + reg_AES_AES_KEY_C2 = 9; + reg_AES_AES_KEY_C3 = 9; + reg_AES_AES_KEY_D0 = 10; + reg_AES_AES_KEY_D1 = 11; + reg_AES_AES_KEY_D2 = 12; + reg_AES_AES_KEY_D3 = 12; + AES_Unlock(); +} + +/*---------------------------------------------------------------------------* + Name: AESi_RecvSeed + + Description: set SEED/KEY from ARM9 via PXI. + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void AESi_RecvSeed( BOOL developer_encrypt ) +{ + AESKey seed; +// PXI_RecvDataByFifo( PXI_FIFO_TAG_DATA, &seed, AES_BLOCK_SIZE ); + PXI_RecvStream( &seed, AES_BLOCK_SIZE ); + AES_Lock(); + AES_WaitKey(); + if ( developer_encrypt ) + { + AES_SetKeyA(&seed); // Direct + } + else + { + AES_SetKeySeedA((AESKeySeed*)&seed); // APP + } + AES_Unlock(); +} diff --git a/build/libraries/aes/Makefile b/build/libraries/aes/Makefile new file mode 100644 index 00000000..a9cca493 --- /dev/null +++ b/build/libraries/aes/Makefile @@ -0,0 +1,31 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - libraries - aes +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM7 + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/fatfs/ARM9/Makefile b/build/libraries/fatfs/ARM9/Makefile new file mode 100644 index 00000000..c1c9e673 --- /dev/null +++ b/build/libraries/fatfs/ARM9/Makefile @@ -0,0 +1,42 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - fatfs +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = + + +#---------------------------------------------------------------------------- + +SRCS = fatfs_firm.c + +TARGET_LIB = libfatfs$(FIRM_LIBSUFFIX).a + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries/fatfs/ARM9/src/fatfs_firm.c b/build/libraries/fatfs/ARM9/src/fatfs_firm.c new file mode 100644 index 00000000..71fca82f --- /dev/null +++ b/build/libraries/fatfs/ARM9/src/fatfs_firm.c @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - fatfs + File: fatfs_firm.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include + +void FATFS_InitFIRM( void ) +{ + MI_CpuClearFast( (void*)HW_FIRM_FATFS_COMMAND_BUFFER, HW_FIRM_FATFS_COMMAND_BUFFER_SIZE ); + FATFSiCommandBuffer = (void*)HW_FIRM_FATFS_COMMAND_BUFFER; + FATFS_Init(); +} + +void FATFSi_GetUnicodeConversionTable(const u8 **u2s, const u16 **s2u) +{ + *u2s = NULL; + *s2u = NULL; +} diff --git a/build/libraries/fatfs/Makefile b/build/libraries/fatfs/Makefile new file mode 100644 index 00000000..8ec2c27c --- /dev/null +++ b/build/libraries/fatfs/Makefile @@ -0,0 +1,31 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - libraries - fatfs +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/fs/ARM7/Makefile b/build/libraries/fs/ARM7/Makefile new file mode 100644 index 00000000..a4bec5b3 --- /dev/null +++ b/build/libraries/fs/ARM7/Makefile @@ -0,0 +1,54 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - fs +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = + + +#---------------------------------------------------------------------------- + +# build ARM & THUMB libraries +TWL_CODEGEN_ALL ?= TRUE + +# Codegen for sub processer +TWL_PROC = ARM7 + +LINCLUDES = \ + $(ROOT)/build/libraries/fatfs/ARM7.TWL/include \ + $(ROOT)/build/libraries/fatfs/ARM7.TWL/include/twl/fatfs/ARM7 + +SRCS = fs_firm.c fs_loader.c + + +TARGET_LIB = libfs_sp$(FIRM_LIBSUFFIX).a + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries/fs/ARM7/src/fs_firm.c b/build/libraries/fs/ARM7/src/fs_firm.c new file mode 100644 index 00000000..261ff699 --- /dev/null +++ b/build/libraries/fs/ARM7/src/fs_firm.c @@ -0,0 +1,117 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - fs + File: fs_firm.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include + +//#define WORKAROUND_NAND_2KB_BUG + +#define FS_HEADER_AUTH_SIZE 0xe00 + +#define MODULE_ALIGNMENT 0x10 // 16oCgPʂœǂݍ +//#define MODULE_ALIGNMENT 0x200 // 512oCgPʂœǂݍ +#define RoundUpModuleSize(value) (((value) + MODULE_ALIGNMENT - 1) & -MODULE_ALIGNMENT) + +static ROM_Header* const rh= (ROM_Header*)HW_TWL_ROM_HEADER_BUF; + +static BOOL aesFlag; +static AESCounter aesCounter; +static u8 aesBuffer[HW_FIRM_LOAD_BUFFER_UNIT_SIZE] ATTRIBUTE_ALIGN(32); + +static void ConvertPath( u16* dest, const char* src, u32 max) +{ + dest[0] = 0; + { + const OSMountInfo *info; + int len; + // foCX擾 + for (len = 0; src[len] && src[len] != ':'; len++) + { + if (len >= max) // ƎOŎ~߂ĂǂH + { + OS_TPrintf("%s: Cannot detect ':' in %d charactors.\n", __func__, len); + return; + } + } + + // hCủ + for (info = OS_GetMountInfo(); *info->drive; ++info) + { + if ((STD_CompareNString(src, info->archiveName, len) == 0) && + (info->archiveName[len] == 0)) + { + if (info->target != OS_MOUNT_TGT_ROOT) // d}EgΉ + { + return; + } + dest[0] = (u16)*info->drive; + break; + } + } + max --; + dest++; + src += len; + } + { + int len; + // cunicode (ASCIÎ) + for (len = 0; len < max && src[len]; len++) + { + if (src[len] == '/') + { + dest[len] = L'\\'; + } +#ifndef SDK_FINALROM + else if (src[len] & 0x80) + { + OS_TPrintf("%s: Multi-byte charactor was detected (0x%02X).\n", __func__, src[len]); + dest[len] = (u16)src[len]; // ignore but maybe broken + } +#endif + else + { + dest[len] = (u16)src[len]; + } + } + if (len < max) + { + dest[len] = 0; + } + else // l type (ensure to terminate zero) + { + dest[max-1] = 0; + } + } +} + +/*---------------------------------------------------------------------------* + Name: FS_OpenSrl + + Description: open srl file named in HW_TWL_FS_BOOT_SRL_PATH_BUF + + Arguments: None + + Returns: file discriptor + *---------------------------------------------------------------------------*/ +int FS_OpenSrl( void ) +{ + const char *fspath = (char*)HW_TWL_FS_BOOT_SRL_PATH_BUF; + u16 fatpath[OS_MOUNT_PATH_LEN]; + ConvertPath(fatpath, fspath, OS_MOUNT_PATH_LEN); + return FATFSi_rtfs_po_open((u8*)fatpath, 0, 0); +} diff --git a/build/libraries/fs/ARM7/src/fs_loader.c b/build/libraries/fs/ARM7/src/fs_loader.c new file mode 100644 index 00000000..803384c3 --- /dev/null +++ b/build/libraries/fs/ARM7/src/fs_loader.c @@ -0,0 +1,259 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - fs + File: fs_loader.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include + +//#define WORKAROUND_NAND_2KB_BUG + +#define FS_HEADER_AUTH_SIZE 0xe00 + +#define MODULE_ALIGNMENT 0x10 // 16oCgPʂœǂݍ +//#define MODULE_ALIGNMENT 0x200 // 512oCgPʂœǂݍ +#define RoundUpModuleSize(value) (((value) + MODULE_ALIGNMENT - 1) & -MODULE_ALIGNMENT) + +static ROM_Header* const rh= (ROM_Header*)HW_TWL_ROM_HEADER_BUF; + +static BOOL aesFlag; +static AESCounter aesCounter; +static u8 aesBuffer[HW_FIRM_LOAD_BUFFER_UNIT_SIZE] ATTRIBUTE_ALIGN(32); + +#define DMA_SEND 2 +#define DMA_RECV 3 +static void CopyWithAes( const void* src, void* dest, u32 size ) +{ + AES_Lock(); + AES_Reset(); + AES_Reset(); + AES_WaitKey(); + AES_LoadKey( AES_KEY_SLOT_A ); + AES_WaitKey(); + AES_DmaSend( DMA_SEND, src, size, NULL, NULL ); + AES_DmaRecv( DMA_RECV, dest, size, NULL, NULL ); + AES_SetCounter( &aesCounter ); + AES_Run( AES_MODE_CTR, 0, size / AES_BLOCK_SIZE, NULL, NULL ); + AES_AddToCounter( &aesCounter, size / AES_BLOCK_SIZE ); + MI_WaitNDma( DMA_RECV ); + AES_Unlock(); +} + +static void EnableAes( u32 offset ) +{ + aesFlag = TRUE; + MI_CpuCopy8( rh->s.main_static_digest, &aesCounter, AES_BLOCK_SIZE ); + AES_AddToCounter( &aesCounter, (offset - rh->s.aes_target_rom_offset) / AES_BLOCK_SIZE ); +} +static void DisableAes( void ) +{ + aesFlag = FALSE; +} + +static u32 GetTransferSize( u32 offset, u32 size ) +{ + u32 aes_offset = rh->s.aes_target_rom_offset; + u32 aes_end = aes_offset + RoundUpModuleSize(rh->s.aes_target_size); + u32 end = offset + RoundUpModuleSize(size); + if ( rh->s.enable_aes ) + { + if ( offset >= aes_offset && offset < aes_end ) + { + if ( end > aes_end ) + { + size = aes_end - offset; + } + EnableAes( offset ); + } + else + { + if ( offset < aes_offset && offset + size > aes_offset ) + { + size = aes_offset - offset; + } + DisableAes(); + } + } + else + { + DisableAes(); + } + return size; +} + +/*---------------------------------------------------------------------------* + Name: FS_LoadBuffer + + Description: load data in file and pass to ARM9 via WRAM-B + + Arguments: fd file discriptor to read + offset offset to start to read in bytes + size total length to read in bytes + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadBuffer( int fd, u32 offset, u32 size ) +{ + static int count = 0; + + if ( fd < 0 ) + { + return FALSE; + } + // seek + if ( FATFSi_rtfs_po_lseek( fd, (long)offset, PSEEK_SET ) != (long)offset ) + { + OS_TPrintf("Failed to seek file. (offset=0x%X)\n", offset); + return FALSE; + } + while ( size > 0 ) + { + u8* dest = aesFlag ? aesBuffer : + (u8*)HW_FIRM_LOAD_BUFFER_BASE + count * HW_FIRM_LOAD_BUFFER_UNIT_SIZE; + u32 unit = size < HW_FIRM_LOAD_BUFFER_UNIT_SIZE ? size : HW_FIRM_LOAD_BUFFER_UNIT_SIZE; + PXI_AcquireLoadBufferSemaphore(); // wait to be ready + if ( MI_GetWramBankMaster_B( count ) != MI_WRAM_ARM7 ) + { + OS_TPanic("PROGRAM ERROR!"); + } +#ifdef WORKAROUND_NAND_2KB_BUG + { + u32 done; + for ( done = 0; done < unit; done += 2048 ) + { + u8* d = dest + done; + u32 u = unit - done < 2048 ? unit - done : 2048; + if ( FATFSi_rtfs_po_read( fd, (u8*)d, (int)u ) != (int)u ) + { + OS_TPrintf("Failed to read file. (dest=%p, size=0x%X)\n", d, u); + return FALSE; + } + } + } +#else + if ( FATFSi_rtfs_po_read( fd, (u8*)dest, (int)unit ) != (int)unit ) + { + OS_TPrintf("Failed to read file. (dest=%p, size=0x%X)\n", dest, unit); + return FALSE; + } +#endif + if ( aesFlag ) + { + CopyWithAes( dest, (u8*)HW_FIRM_LOAD_BUFFER_BASE + count * HW_FIRM_LOAD_BUFFER_UNIT_SIZE, unit ); + } + PXI_ReleaseLoadBufferSemaphore(); + count = ( count + 1 ) % HW_FIRM_LOAD_BUFFER_UNIT_NUMS; + size -= unit; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: FS_LoadModule + + Description: load data in file and pass to ARM9 via WRAM-B in view of AES + settings in the ROM header in HW_TWL_ROM_HEADER_BUF + + Arguments: fd file discriptor to read + offset offset to start to read in bytes + length total length to read in bytes + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadModule( int fd, u32 offset, u32 size ) +{ + size = RoundUpModuleSize( size ); + while ( size > 0 ) + { + u32 unit = GetTransferSize( offset, size ); + if ( !FS_LoadBuffer( fd, offset, unit ) ) + { + return FALSE; + } + offset += unit; + size -= unit; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: FS_LoadHeader + + Description: load ROM header in the head of file and pass to ARM9 via WRAM-B + + Arguments: fd file discriptor to read + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadHeader( int fd ) +{ + if (fd < 0) + { + return FALSE; + } + DisableAes(); + if ( !FS_LoadBuffer(fd, 0, FS_HEADER_AUTH_SIZE) || + !FS_LoadBuffer(fd, FS_HEADER_AUTH_SIZE, HW_TWL_ROM_HEADER_BUF_SIZE - FS_HEADER_AUTH_SIZE) ) + { + return FALSE; + } + + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: FS_LoadStatic + + Description: load static regions in file and pass to ARM9 via WRAM-B + specified by ROM header at HW_TWL_ROM_HEADER_BUF + + Arguments: fd file discriptor to read + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadStatic( int fd ) +{ + if ( rh->s.main_size > 0 ) + { + if ( !FS_LoadModule( fd, rh->s.main_rom_offset, rh->s.main_size ) ) + { + return FALSE; + } + } + if ( rh->s.sub_size > 0 ) + { + if ( !FS_LoadModule( fd, rh->s.sub_rom_offset, rh->s.sub_size ) ) + { + return FALSE; + } + } + if ( rh->s.main_ltd_size > 0 ) + { + if ( !FS_LoadModule( fd, rh->s.main_ltd_rom_offset, rh->s.main_ltd_size ) ) + { + return FALSE; + } + } + if ( rh->s.sub_ltd_size > 0 ) + { + if ( !FS_LoadModule( fd, rh->s.sub_ltd_rom_offset, rh->s.sub_ltd_size ) ) + { + return FALSE; + } + } + return TRUE; +} + diff --git a/build/libraries/fs/ARM9/Makefile b/build/libraries/fs/ARM9/Makefile new file mode 100644 index 00000000..4f7cd66a --- /dev/null +++ b/build/libraries/fs/ARM9/Makefile @@ -0,0 +1,47 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - fs +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = + + +#---------------------------------------------------------------------------- + +LINCLUDES = $(ES_ROOT)/twl/include + +SRCS = fs_firm.c fs_loader.c fs_loader2.c + + +TARGET_LIB = libfs$(FIRM_LIBSUFFIX).a + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs +include $(TWLSDK_ROOT)/add-ins/es/commondefs.es + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries/fs/ARM9/src/fs_firm.c b/build/libraries/fs/ARM9/src/fs_firm.c new file mode 100644 index 00000000..c4828584 --- /dev/null +++ b/build/libraries/fs/ARM9/src/fs_firm.c @@ -0,0 +1,214 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - fs + File: fs_firm.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +// bootContent \ contentIndex +#define CONTENT_INDEX_BOOT 0xFFFF + +#define PATH_FORMAT_TMD "nand:/title/%08x/%08x/content/title.tmd" +#define PATH_FORMAT_CONTENT "nand:/title/%08x/%08x/content/%08x.app" + +/*---------------------------------------------------------------------------* + Name: FS_InitFIRM + + Description: initialize FS/FATFS for firm + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void FS_InitFIRM( void ) +{ + MI_CpuClearFast( (void*)HW_FIRM_FS_TEMP_BUFFER, HW_FIRM_FS_TEMP_BUFFER_SIZE ); + FSiTemporaryBuffer = (void*)HW_FIRM_FS_TEMP_BUFFER; + FATFS_InitFIRM(); + FS_Init( FS_DMA_NOT_USE ); +} + +/*---------------------------------------------------------------------------* + Name: LoadTMD + + Description: Ώۂ̃^Cg TMD t@Cɓǂݍ݂܂B + ɍsꂽꍇɓobt@ւ̃|C^ + svɂȂ NAMi_Free ʼnKv܂B + + Arguments: titleId: Ώۂ̃^Cg TitleIDB + + Returns: ɍsꂽȂ TRUEԂ܂B + łȂ FALSE Ԃ܂B + *---------------------------------------------------------------------------*/ +static BOOL LoadTMD(ESTitleMeta* pTmd, u64 titleId) +{ + char path[64]; + FSFile f; + BOOL bSuccess; + u32 fileSize; + s32 readSize; + s32 readResult; + + // TMD ̃pX𐶐 + STD_TSPrintf(path, PATH_FORMAT_TMD, (u32)(titleId >> 32), (u32)titleId); + + FS_InitFile(&f); + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R); + + if( ! bSuccess ) + { + // t@CJȂ + return FALSE; + } + + fileSize = FS_GetFileLength(&f); + + // t@CTCY`FbN 1 + // Œ蕔TCY <= fileSize <= Œ蕔TCY + •ϒőTCY + if( (fileSize < sizeof(IOSCSigRsa2048) + sizeof(ESTitleMetaHeader)) + || (sizeof(ESTitleMeta) < fileSize) ) + { + // t@CTCYُ + FS_CloseFile(&f); + return FALSE; + } + + readSize = (s32)fileSize; + readResult = FS_ReadFile(&f, pTmd, readSize); + FS_CloseFile(&f); + + if( readResult != readSize ) + { + // t@C̓ǂݍ݂Ɏs + return FALSE; + } + + // t@CTCY`FbN 2 + // •ϒ𐳂l + if( fileSize != sizeof(IOSCSigRsa2048) + + sizeof(ESTitleMetaHeader) + + sizeof(ESContentMeta) * MI_SwapEndian16(pTmd->head.numContents) ) + { + // t@CTCYُ + return FALSE; + } + + // ^Cg ID ̈v`FbN + if( titleId != MI_SwapEndian64(pTmd->head.titleId) ) + { + // ^Cg ID vȂ + return FALSE; + } + + return TRUE; +} +/*---------------------------------------------------------------------------* + Name: FS_GetTitleBootContentPathFast + + Description: NAND ɃCXg[ĂAv̎st@C̃pX + 擾܂B + 擾̐؂ȂߍłA + 񂪉₂Ô\邱ƂɒӂȂ΂Ȃ܂B + + Arguments: buf: pXi[obt@ւ̃|C^B + FS_ENTRY_LONGNAME_MAX ȏ̃TCYKvłB + titleId: pX擾Av Title IDB + + Returns: ɏsꂽȂ TRUE Ԃ܂B + *---------------------------------------------------------------------------*/ +BOOL FS_GetTitleBootContentPathFast(char* buf, u64 titleId) +{ + ESTitleMeta tmd; + u32 bootContentId; + int bootContentIndex; + int numContents; + int i; + + SDK_POINTER_ASSERT(buf); + + + + if( !LoadTMD(&tmd, titleId) ) + { + return FALSE; + } + + // TMD BigEndian + bootContentIndex = MI_SwapEndian16(tmd.head.bootIndex); + numContents = MI_SwapEndian16(tmd.head.numContents); + + // bootContentIndex ɈvRecT + for( i = 0; i < numContents; ++i ) + { + const ESContentMeta* pContent = &tmd.contents[i]; + + if( MI_SwapEndian16(pContent->index) == bootContentIndex ) + { + bootContentId = MI_SwapEndian32(pContent->cid); + break; + } + } + + if( i >= numContents ) + { + return FALSE; + } + + // Rec̃pX𐶐 + STD_TSPrintf(buf, PATH_FORMAT_CONTENT, (u32)(titleId >> 32), (u32)titleId, bootContentId); + + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: FS_ResolveSrl + + Description: resolve srl filename and store to HW_TWL_FS_BOOT_SRL_PATH_BUF + + Arguments: titleId title id for srl file + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_ResolveSrl( u64 titleId ) +{ + if ( ES_ERR_OK != ES_InitLib() || + ES_ERR_OK != ES_GetContentPath(titleId, CONTENT_INDEX_BOOT, (char*)HW_TWL_FS_BOOT_SRL_PATH_BUF) || + ES_ERR_OK != ES_CloseLib() ) + { + return FALSE; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: FS_ResolveSrlUnsecured + + Description: resolve srl filename and store to HW_TWL_FS_BOOT_SRL_PATH_BUF + without almost security check + + Arguments: titleId title id for srl file + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_ResolveSrlUnsecured( u64 titleId ) +{ + if ( !FS_GetTitleBootContentPathFast((char*)HW_TWL_FS_BOOT_SRL_PATH_BUF, titleId) ) + { + return FALSE; + } + return TRUE; +} + + diff --git a/build/libraries/fs/ARM9/src/fs_loader.c b/build/libraries/fs/ARM9/src/fs_loader.c new file mode 100644 index 00000000..f5d623bc --- /dev/null +++ b/build/libraries/fs/ARM9/src/fs_loader.c @@ -0,0 +1,386 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - fs + File: fs_loader.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include + +#define FS_HEADER_AUTH_SIZE 0xe00 + +#define MODULE_ALIGNMENT 0x10 // 16oCgPʂœǂݍ +//#define MODULE_ALIGNMENT 0x200 // 512oCgPʂœǂݍ +#define RoundUpModuleSize(value) (((value) + MODULE_ALIGNMENT - 1) & -MODULE_ALIGNMENT) + +#define HASH_UNIT 0x1000 + +static ROM_Header* const rh = (ROM_Header*)HW_TWL_ROM_HEADER_BUF; + +static u8 currentKey[ SVC_SHA1_BLOCK_SIZE ]; + +static const u8 defaultKey[ SVC_SHA1_BLOCK_SIZE ] = +{ + 0x21, 0x06, 0xc0, 0xde, + 0xba, 0x98, 0xce, 0x3f, + 0xa6, 0x92, 0xe3, 0x9d, + 0x46, 0xf2, 0xed, 0x01, + + 0x76, 0xe3, 0xcc, 0x08, + 0x56, 0x23, 0x63, 0xfa, + 0xca, 0xd4, 0xec, 0xdf, + 0x9a, 0x62, 0x78, 0x34, + + 0x8f, 0x6d, 0x63, 0x3c, + 0xfe, 0x22, 0xca, 0x92, + 0x20, 0x88, 0x97, 0x23, + 0xd2, 0xcf, 0xae, 0xc2, + + 0x32, 0x67, 0x8d, 0xfe, + 0xca, 0x83, 0x64, 0x98, + 0xac, 0xfd, 0x3e, 0x37, + 0x87, 0x46, 0x58, 0x24, +}; + +static AESKey FSiAesKeySeed; + +/*---------------------------------------------------------------------------* + Name: FS_GetAesKeySeed + + Description: retreive aes key seed in the signature + + Arguments: None + + Returns: pointer to seed + *---------------------------------------------------------------------------*/ +AESKey* const FS_GetAesKeySeed( void ) +{ + return &FSiAesKeySeed; +} + +/*---------------------------------------------------------------------------* + Name: FS_DeleteAesKeySeed + + Description: delete aes key seed in the signature + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void FS_DeleteAesKeySeed( void ) +{ + MI_CpuClear8( &FSiAesKeySeed, sizeof(FSiAesKeySeed) ); +} + +/*---------------------------------------------------------------------------* + Name: FS_SetDigestKey + + Description: set specified key or default key for HMAC-SHA-1 + + Arguments: digestKey pointer to key + if NULL, use default key + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +void FS_SetDigestKey( const u8* digestKey ) +{ + if ( digestKey ) + { + MI_CpuCopy8(digestKey, currentKey, SVC_SHA1_BLOCK_SIZE); + } + else + { + MI_CpuCopy8(defaultKey, currentKey, SVC_SHA1_BLOCK_SIZE); + } +} + +static inline BOOL CheckDigest( u8* a, u8* b, BOOL aClr, BOOL bClr ) +{ + BOOL result = TRUE; + int i; + for ( i = 0; i < SVC_SHA1_DIGEST_SIZE; i++ ) + { + if ( a[i] != b[i] ) + { + result = FALSE; + } + } + if ( aClr ) MI_CpuClear8(a, SVC_SHA1_DIGEST_SIZE); + if ( bClr ) MI_CpuClear8(b, SVC_SHA1_DIGEST_SIZE); + return result; +} + +/*---------------------------------------------------------------------------* + Name: CheckRomCertificate + + Description: check the certification in the ROM + + ROMwb_ɕtꂽؖ̃`FbNs܂B + makerom.TWL̃R[hɈˑ܂B + + Arguments: pool pointer to the SVCSignHeapContext + pCert pointer to the certification + pCAPubKey pointer to the public key for the certification + gameCode initial code + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +static BOOL CheckRomCertificate( SVCSignHeapContext* pool, const RomCertificate *pCert, const void* pCAPubKey, u32 gameCode ) +{ + u8 digest[SVC_SHA1_DIGEST_SIZE]; + u8 md[SVC_SHA1_DIGEST_SIZE]; + + // ؖwb_̃}WbNio[`FbN + if( pCert->header.magicNumber != TWL_ROM_CERT_MAGIC_NUMBER || + // ؖwb_ROMwb_̃Q[R[hv`FbN + pCert->header.gameCode != gameCode ) + { + return FALSE; + } + // ؖ`FbN + SVC_DecryptSign( pool, &digest, pCert->sign, pCAPubKey ); + + // _CWFXǧvZ + SVC_CalcSHA1( md, pCert, ROM_CERT_SIGN_OFFSET ); + + // r + return CheckDigest(md, digest, TRUE, TRUE); +} + +/*---------------------------------------------------------------------------* + Name: FS_LoadBuffer + + Description: receive data from ARM7 via WRAM-B and store in destination address, + calculate SHA1 in parallel if ctx is specified + + Arguments: dest destination address to read + size total length to read in bytes + ctx pointer to SHA1 context or NULL + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadBuffer( u8* dest, u32 size, SVCSHA1Context *ctx ) +{ + static int count = 0; + + while ( size > 0 ) + { + u8* src = (u8*)HW_FIRM_LOAD_BUFFER_BASE + count * HW_FIRM_LOAD_BUFFER_UNIT_SIZE; + u32 unit = size < HW_FIRM_LOAD_BUFFER_UNIT_SIZE ? size : HW_FIRM_LOAD_BUFFER_UNIT_SIZE; + PXI_AcquireLoadBufferSemaphore(); // wait to be ready + MIi_SetWramBankMaster_B( count, MI_WRAM_ARM9 ); + if (ctx) + { + int done; + for ( done = 0; done < unit; done += HASH_UNIT ) + { + u8* s = src + done; + u8* d = dest + done; + u32 u = unit - done < HASH_UNIT ? unit - done : HASH_UNIT; + SVC_SHA1Update( ctx, s, u ); + MI_CpuCopyFast( s, d, u ); + } + } + else + { + MI_CpuCopyFast( src, dest, unit ); + } + DC_FlushRange( src, unit ); + size -= unit; + dest += unit; + MIi_SetWramBankMaster_B( count, MI_WRAM_ARM7 ); + PXI_ReleaseLoadBufferSemaphore(); + count = ( count + 1 ) % HW_FIRM_LOAD_BUFFER_UNIT_NUMS; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: GetTransferSize + + Description: get size to transfer once + + xɎMTCYԂ܂B + + ]͈͂AES̈܂ꍇ́AE܂ł̃TCY ( + ȃTCY) Ԃ܂B + makerom.TWL܂IPL̎gpɈˑ܂B + + Arguments: offset offset of region from head of ROM_Header + size size of region + + Returns: size to transfer once + *---------------------------------------------------------------------------*/ +static u32 GetTransferSize( u32 offset, u32 size ) +{ + u32 aes_offset = rh->s.aes_target_rom_offset; + u32 aes_end = aes_offset + rh->s.aes_target_size; + u32 end = offset + size; + if ( rh->s.enable_aes ) + { + if ( offset >= aes_offset && offset < aes_end ) + { + if ( end > aes_end ) + { + size = aes_end - offset; + } + } + else + { + if ( offset < aes_offset && offset + size > aes_offset ) + { + size = aes_offset - offset; + } + } + } + return size; +} + +/*---------------------------------------------------------------------------* + Name: FS_LoadModule + + Description: receive data from ARM7 via WRAM-B and store in destination address + in view of AES settings in the ROM header at HW_TWL_ROM_HEADER_BUF, + then verify the digest + + Arguments: dest destination address to read + offset file offset to start to read in bytes + size total length to read in bytes + digest digest to verify + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadModule( u8* dest, u32 offset, u32 size, const u8 digest[SVC_SHA1_DIGEST_SIZE] ) +{ + SVCHMACSHA1Context ctx; + u8 md[SVC_SHA1_DIGEST_SIZE]; + + SVC_HMACSHA1Init(&ctx, currentKey, SVC_SHA1_BLOCK_SIZE ); + while ( size > 0 ) + { + u32 unit = GetTransferSize( offset, size ); + if ( !FS_LoadBuffer( dest, unit, &ctx.sha1_ctx ) ) + { + return FALSE; + } + dest += unit; + offset += unit; + size -= unit; + } + SVC_HMACSHA1GetHash(&ctx, md); + return CheckDigest(md, (u8*)digest, TRUE, FALSE); +} + +/*---------------------------------------------------------------------------* + Name: FS_LoadHeader + + Description: receive ROM header, store to HW_TWL_ROM_HEADER_BUF, + and verify signature + + Arguments: pool heap context to call SVC_DecryptSign + rsa_key public key to verify the signature + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadHeader( SVCSignHeapContext* pool, const void* rsa_key ) +{ + SVCSHA1Context ctx; + u8 md[SVC_SHA1_DIGEST_SIZE]; + SignatureData sd; + + SVC_SHA1Init( &ctx ); + if ( !FS_LoadBuffer( (u8*)rh, FS_HEADER_AUTH_SIZE, &ctx ) ) + { + return FALSE; + } + SVC_SHA1GetHash( &ctx, md ); + if ( !FS_LoadBuffer( (u8*)rh + FS_HEADER_AUTH_SIZE, HW_TWL_ROM_HEADER_BUF_SIZE - FS_HEADER_AUTH_SIZE, NULL ) ) + { + return FALSE; + } + + // Recؖ + if ( CheckRomCertificate( pool, &rh->certificate, rsa_key, *(u32*)rh->s.game_code ) ) + { + rsa_key = rh->certificate.pubKeyMod; // wb_p̌̎o + } + else + { + // Ƃ肠Recؖp̌̂܂܎gƉ + } + + // wb_`FbN + SVC_DecryptSign( pool, &sd, rh->signature, rsa_key ); + + if ( !CheckDigest( md, sd.digest, TRUE, FALSE ) ) + { + MI_CpuClear8( &sd, sizeof(sd) ); // c폜 (ɕKvȂ̂͂ȂH) + return FALSE; + } + + // _CWFXgȊÕf[^̃`FbNKvII + + // ̕ۑ + MI_CpuCopy8( (AESKey*)sd.aes_key_seed, &FSiAesKeySeed, sizeof(FSiAesKeySeed) ); + + MI_CpuClear8( &sd, sizeof(sd) ); // c폜 (ɕKvȂ̂͂ȂH) + + // ROMwb_̃Rs[ + MI_CpuCopyFast( rh, (void*)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF ); + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: FS_LoadStatic + + Description: receive static regions from ARM6 via WRAM-B and store them + specified by ROM header at HW_TWL_ROM_HEADER_BUF + + Arguments: None + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadStatic( void ) +{ + if ( rh->s.main_size > 0 ) + { + if ( !FS_LoadModule( rh->s.main_ram_address, rh->s.main_rom_offset, rh->s.main_size, rh->s.main_static_digest ) ) + { + return FALSE; + } + } + if ( rh->s.sub_size > 0 ) + { + if ( !FS_LoadModule( rh->s.sub_ram_address, rh->s.sub_rom_offset, rh->s.sub_size, rh->s.sub_static_digest ) ) + { + return FALSE; + } + } + if ( rh->s.main_ltd_size > 0 ) + { + if ( !FS_LoadModule( rh->s.main_ltd_ram_address, rh->s.main_ltd_rom_offset, rh->s.main_ltd_size, rh->s.main_ltd_static_digest ) ) + { + return FALSE; + } + } + if ( rh->s.sub_ltd_size > 0 ) + { + if ( !FS_LoadModule( rh->s.sub_ltd_ram_address, rh->s.sub_ltd_rom_offset, rh->s.sub_ltd_size, rh->s.sub_ltd_static_digest ) ) + { + return FALSE; + } + } + return TRUE; +} diff --git a/build/libraries/fs/ARM9/src/fs_loader2.c b/build/libraries/fs/ARM9/src/fs_loader2.c new file mode 100644 index 00000000..43efe415 --- /dev/null +++ b/build/libraries/fs/ARM9/src/fs_loader2.c @@ -0,0 +1,422 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - fs + File: fs_loader.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include + +#define FS_HEADER_AUTH_SIZE 0xe00 + +#define MODULE_ALIGNMENT 0x10 // 16oCgPʂœǂݍ +//#define MODULE_ALIGNMENT 0x200 // 512oCgPʂœǂݍ +#define RoundUpModuleSize(value) (((value) + MODULE_ALIGNMENT - 1) & -MODULE_ALIGNMENT) + +#define HASH_UNIT 0x1000 + +static ROM_Header* const rh = (ROM_Header*)HW_TWL_ROM_HEADER_BUF; + +static u8 currentKey[ SVC_SHA1_BLOCK_SIZE ]; + +static const u8 defaultKey[ SVC_SHA1_BLOCK_SIZE ] = +{ + 0x21, 0x06, 0xc0, 0xde, + 0xba, 0x98, 0xce, 0x3f, + 0xa6, 0x92, 0xe3, 0x9d, + 0x46, 0xf2, 0xed, 0x01, + + 0x76, 0xe3, 0xcc, 0x08, + 0x56, 0x23, 0x63, 0xfa, + 0xca, 0xd4, 0xec, 0xdf, + 0x9a, 0x62, 0x78, 0x34, + + 0x8f, 0x6d, 0x63, 0x3c, + 0xfe, 0x22, 0xca, 0x92, + 0x20, 0x88, 0x97, 0x23, + 0xd2, 0xcf, 0xae, 0xc2, + + 0x32, 0x67, 0x8d, 0xfe, + 0xca, 0x83, 0x64, 0x98, + 0xac, 0xfd, 0x3e, 0x37, + 0x87, 0x46, 0x58, 0x24, +}; + +static AESKey FSiAesKeySeed; + +static BOOL aesFlag; +static AESCounter aesCounter; +static u8* const aesBuffer = (u8*)HW_FIRM_FS_AES_BUFFER; // 0x2ff3800 + + +/*---------------------------------------------------------------------------* + Name: FS2_GetAesKeySeed + + Description: retreive aes key seed in the signature + + Arguments: None + + Returns: pointer to seed + *---------------------------------------------------------------------------*/ +AESKey* const FS2_GetAesKeySeed( void ) +{ + return &FSiAesKeySeed; +} + +/*---------------------------------------------------------------------------* + Name: FS2_DeleteAesKeySeed + + Description: delete aes key seed in the signature + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void FS2_DeleteAesKeySeed( void ) +{ + MI_CpuClear8( &FSiAesKeySeed, sizeof(FSiAesKeySeed) ); +} + +/*---------------------------------------------------------------------------* + Name: FS2_SetDigestKey + + Description: set specified key or default key for HMAC-SHA-1 + + Arguments: digestKey pointer to key + if NULL, use default key + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +void FS2_SetDigestKey( const u8* digestKey ) +{ + if ( digestKey ) + { + MI_CpuCopy8(digestKey, currentKey, SVC_SHA1_BLOCK_SIZE); + } + else + { + MI_CpuCopy8(defaultKey, currentKey, SVC_SHA1_BLOCK_SIZE); + } +} + +static inline BOOL CheckDigest( u8* a, u8* b, BOOL aClr, BOOL bClr ) +{ + BOOL result = TRUE; + int i; + for ( i = 0; i < SVC_SHA1_DIGEST_SIZE; i++ ) + { + if ( a[i] != b[i] ) + { + result = FALSE; + } + } + if ( aClr ) MI_CpuClear8(a, SVC_SHA1_DIGEST_SIZE); + if ( bClr ) MI_CpuClear8(b, SVC_SHA1_DIGEST_SIZE); + return result; +} + +/*---------------------------------------------------------------------------* + Name: CheckRomCertificate + + Description: check the certification in the ROM + + ROMwb_ɕtꂽؖ̃`FbNs܂B + makerom.TWL̃R[hɈˑ܂B + + Arguments: pool pointer to the SVCSignHeapContext + pCert pointer to the certification + pCAPubKey pointer to the public key for the certification + gameCode initial code + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +static BOOL CheckRomCertificate( SVCSignHeapContext* pool, const RomCertificate *pCert, const void* pCAPubKey, u32 gameCode ) +{ + u8 digest[SVC_SHA1_DIGEST_SIZE]; + u8 md[SVC_SHA1_DIGEST_SIZE]; + + // ؖwb_̃}WbNio[`FbN + if( pCert->header.magicNumber != TWL_ROM_CERT_MAGIC_NUMBER || + // ؖwb_ROMwb_̃Q[R[hv`FbN + pCert->header.gameCode != gameCode ) + { + return FALSE; + } + // ؖ`FbN + SVC_DecryptSign( pool, &digest, pCert->sign, pCAPubKey ); + + // _CWFXǧvZ + SVC_CalcSHA1( md, pCert, ROM_CERT_SIGN_OFFSET ); + + // r + return CheckDigest(md, digest, TRUE, TRUE); +} + +static void AesCallback(AESResult result, void* arg) +{ + volatile BOOL *pBusy = (BOOL*)arg; + *pBusy = FALSE; + if (result != AES_RESULT_SUCCESS) + { + OS_TPrintf("Failed to decrypt by AES (%d)\n", result); + } +} + +static void CopyWithAes( const void* src, void* dest, u32 size ) +{ + volatile BOOL aesBusy = TRUE; + + AES_SetKeySlot( AES_KEY_SLOT_A ); + aesBusy = TRUE; + if ( AES_RESULT_SUCCESS == AES_Ctr( &aesCounter, src, size, dest, AesCallback, (void*)&aesBusy ) ) + { + while ( aesBusy ) + { + } + } + AES_AddToCounter( &aesCounter, size / AES_BLOCK_SIZE ); +} + +static void EnableAes( u32 offset ) +{ + aesFlag = TRUE; + MI_CpuCopy8( rh->s.main_static_digest, &aesCounter, AES_BLOCK_SIZE ); + AES_AddToCounter( &aesCounter, (offset - rh->s.aes_target_rom_offset) / AES_BLOCK_SIZE ); +} +static void DisableAes( void ) +{ + aesFlag = FALSE; +} + +/*---------------------------------------------------------------------------* + Name: GetTransferSize + + Description: get size to transfer once + + xɎMTCYԂ܂B + + ]͈͂AES̈܂ꍇ́AE܂ł̃TCY ( + ȃTCY) Ԃ܂B + makerom.TWL܂IPL̎gpɈˑ܂B + + Arguments: offset offset of region from head of ROM_Header + size size of region + + Returns: size to transfer once + *---------------------------------------------------------------------------*/ +static u32 GetTransferSize( u32 offset, u32 size ) +{ + u32 aes_offset = rh->s.aes_target_rom_offset; + u32 aes_end = aes_offset + RoundUpModuleSize(rh->s.aes_target_size); + u32 end = offset + RoundUpModuleSize(size); + if ( rh->s.enable_aes ) + { + if ( offset >= aes_offset && offset < aes_end ) + { + if ( end > aes_end ) + { + size = aes_end - offset; + } + if ( size > HW_FIRM_FS_AES_BUFFER_SIZE ) + { + size = HW_FIRM_FS_AES_BUFFER_SIZE; + } + EnableAes( offset ); + } + else + { + if ( offset < aes_offset && offset + size > aes_offset ) + { + size = aes_offset - offset; + } + DisableAes(); + } + } + else + { + DisableAes(); + } + return size; +} + +/*---------------------------------------------------------------------------* + Name: FS2_LoadModule + + Description: receive data from ARM7 via WRAM-B and store in destination address + in view of AES settings in the ROM header at HW_TWL_ROM_HEADER_BUF, + then verify the digest + + Arguments: pFile pointer to FSFile streucture + dest destination address to read + offset file offset to start to read in bytes + size total length to read in bytes + digest digest to verify + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS2_LoadModule( FSFile *pFile, u8* dest, u32 offset, u32 size, const u8 digest[SVC_SHA1_DIGEST_SIZE] ) +{ + u8 md[SVC_SHA1_DIGEST_SIZE]; + u8* hmacDest = dest; + u32 hmacSize = size; + + if ( !FS_SeekFile( pFile, (s32)offset, FS_SEEK_SET ) ) + { + return FALSE; + } + size = RoundUpModuleSize( size ); + while ( size > 0 ) + { + u32 unit = GetTransferSize( offset, size ); + if ( aesFlag ) + { + if ( !FS_ReadFile( pFile, aesBuffer, (s32)unit ) ) + { + return FALSE; + } + DC_FlushRange( aesBuffer, unit ); + CopyWithAes( aesBuffer, dest, unit ); + } + else + { + if ( !FS_ReadFile( pFile, dest, (s32)unit ) ) + { + return FALSE; + } + } + dest += unit; + offset += unit; + size -= unit; + } + SVC_CalcHMACSHA1( md, hmacDest, hmacSize, currentKey, SVC_SHA1_BLOCK_SIZE ); + return CheckDigest(md, (u8*)digest, TRUE, FALSE); +} + +/*---------------------------------------------------------------------------* + Name: FS2_OpenSrl + + Description: open srl file named at HW_TWL_FS_BOOT_SRL_PATH_BUF + + Arguments: pFile pointer to FSFile streucture + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS2_OpenSrl( FSFile *pFile ) +{ + return FS_OpenFileEx( pFile, (char*)HW_TWL_FS_BOOT_SRL_PATH_BUF, FS_FILEMODE_R ); +} + +/*---------------------------------------------------------------------------* + Name: FS2_LoadHeader + + Description: load ROM header to HW_TWL_ROM_HEADER_BUF using normal FS, + and verify signature + + Arguments: pFile pointer to FSFile streucture + pool heap context to call SVC_DecryptSign + rsa_key public key to verify the signature + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS2_LoadHeader( FSFile *pFile, SVCSignHeapContext* pool, const void* rsa_key ) +{ + u8 md[SVC_SHA1_DIGEST_SIZE]; + SignatureData sd; + + if ( !FS_SeekFile( pFile, 0, FS_SEEK_SET ) ) + { + return FALSE; + } + if ( !FS_ReadFile( pFile, rh, HW_TWL_ROM_HEADER_BUF_SIZE ) ) + { + return FALSE; + } + SVC_CalcSHA1( md, rh, FS_HEADER_AUTH_SIZE ); + + // Recؖ + if ( CheckRomCertificate( pool, &rh->certificate, rsa_key, *(u32*)rh->s.game_code ) ) + { + rsa_key = rh->certificate.pubKeyMod; // wb_p̌̎o + } + else + { + // Ƃ肠Recؖp̌̂܂܎gƉ + } + + // wb_`FbN + SVC_DecryptSign( pool, &sd, rh->signature, rsa_key ); + + if ( !CheckDigest( md, sd.digest, TRUE, FALSE ) ) + { + MI_CpuClear8( &sd, sizeof(sd) ); // c폜 (ɕKvȂ̂͂ȂH) + return FALSE; + } + + // _CWFXgȊÕf[^̃`FbNKvII + + // ̕ۑ + MI_CpuCopy8( (AESKey*)sd.aes_key_seed, &FSiAesKeySeed, sizeof(FSiAesKeySeed) ); + + MI_CpuClear8( &sd, sizeof(sd) ); // c폜 (ɕKvȂ̂͂ȂH) + + // ROMwb_̃Rs[ + MI_CpuCopyFast( rh, (void*)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF ); + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: FS2_LoadStatic + + Description: receive static regions from ARM6 via WRAM-B and store them + specified by ROM header at HW_TWL_ROM_HEADER_BUF + + Arguments: pFile pointer to FSFile streucture + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS2_LoadStatic( FSFile *pFile ) +{ + if ( rh->s.main_size > 0 ) + { + if ( !FS2_LoadModule( pFile, rh->s.main_ram_address, rh->s.main_rom_offset, rh->s.main_size, rh->s.main_static_digest ) ) + { + return FALSE; + } + } + if ( rh->s.sub_size > 0 ) + { + if ( !FS2_LoadModule( pFile, rh->s.sub_ram_address, rh->s.sub_rom_offset, rh->s.sub_size, rh->s.sub_static_digest ) ) + { + return FALSE; + } + } + if ( rh->s.main_ltd_size > 0 ) + { + if ( !FS2_LoadModule( pFile, rh->s.main_ltd_ram_address, rh->s.main_ltd_rom_offset, rh->s.main_ltd_size, rh->s.main_ltd_static_digest ) ) + { + return FALSE; + } + } + if ( rh->s.sub_ltd_size > 0 ) + { + if ( !FS2_LoadModule( pFile, rh->s.sub_ltd_ram_address, rh->s.sub_ltd_rom_offset, rh->s.sub_ltd_size, rh->s.sub_ltd_static_digest ) ) + { + return FALSE; + } + } + return TRUE; +} diff --git a/build/libraries/fs/Makefile b/build/libraries/fs/Makefile new file mode 100644 index 00000000..94c7f98c --- /dev/null +++ b/build/libraries/fs/Makefile @@ -0,0 +1,31 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - libraries - fatfs +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 ARM7 + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/gcd/ARM7/Makefile b/build/libraries/gcd/ARM7/Makefile new file mode 100644 index 00000000..a9879b0e --- /dev/null +++ b/build/libraries/gcd/ARM7/Makefile @@ -0,0 +1,52 @@ +#! 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 +TWL_CODEGEN_ALL ?= True + +TWL_PROC = ARM7 + +SRCDIR = . ../common +SRCS = \ + gcd.c \ + gcd_init.c \ + blowfish.c \ + ds_blowfish.c \ + ds_blowfish_table.c \ + +TARGET_LIB = libgcd_sp$(FIRM_LIBSUFFIX).a +INCDIR = ../include + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries/gcd/ARM9/Makefile b/build/libraries/gcd/ARM9/Makefile new file mode 100644 index 00000000..d1d747c1 --- /dev/null +++ b/build/libraries/gcd/ARM9/Makefile @@ -0,0 +1,57 @@ +#! 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 +TWL_CODEGEN_ALL ?= True + + + +SRCDIR = . ../common +SRCS = \ + gcd.c \ + gcd_init.c \ + blowfish.c \ + ds_blowfish.c \ + ds_blowfish_table.c \ + +TARGET_LIB = libgcd$(FIRM_LIBSUFFIX).a +INCDIR = ../include + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +LDEPENDS_OBJ := $(MAKEFIRM_RSA_PUBKEY) \ + +gcd_acsign.c : $(LDEPENDS_OBJ) + touch gcd_acsign.c + +#===== End of Makefile ===== diff --git a/build/libraries/gcd/Makefile b/build/libraries/gcd/Makefile new file mode 100644 index 00000000..bae95ea7 --- /dev/null +++ b/build/libraries/gcd/Makefile @@ -0,0 +1,34 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - gcd +# 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 $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 + +#ifdef TWL_WITH_ARM7 +SUBDIRS += ARM7 +#endif + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_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 +/* ƂŖOς */ +#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; // SECURË惊[hECl[u + + 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; + } + } + + // ÍIuWFNgL + if ( exist ) + { +#else + if ((encBufp[0] == encrypt_object_key[0]) // ÍIuWFNgL + && (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); // `R[hŃNA + sh->disableEncryptedCardData = 1; // ÍIuWFNg ʒm + } + 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 ) + { + // 3Dpݒ + { + ctrls->gcdRegs->ctrl &= ~REG_MI_MCCNT1_A_PC_MASK; + ctrls->gcdRegs->ctrl |= GCD_PAGE_1; + } + } + + while ( restSize > 0 ) // ubNǂݍ + { + 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 ) // ubNǂݍ + { + 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 ); // R}hݒ + + if ( MI_EXDMA_CH_MIN <= dmaNo && dmaNo <= MI_EXDMA_CH_MAX ) + { + GCD_DmaRecvRomAsync( slot, dmaNo, ramp ); + GCDi_SetCtrl( slot, ctrls->gcdRegs ); // Rg[ݒ & DMAX^[g + } + else + { + void *ramEndp; + u32 ctrlTmp; + + GCDi_SetCtrl( slot, ctrls->gcdRegs ); // Rg[ݒ + + ramEndp = (u8 *)ramp + size; // i[IAhXZo + + do { // CPUǂݍ + ctrlTmp = *cnt1; + + if (ctrlTmp & REG_MI_MCCNT1_A_RDY_MASK) { + u32 dataTmp = *data1; + + if (ramp < ramEndp) + { + *((vu32 *)ramp) = dataTmp; // wTCY܂Ŋi[i㑱f[^͓ǂݎ̂āj + (*(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 ) // ubNǂݍ + { + 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 ); // R}hݒ + + if ( MI_EXDMA_CH_MIN <= dmaNo && dmaNo <= MI_EXDMA_CH_MAX ) + { + GCD_DmaSendRomAsync( slot, dmaNo, ramp ); + GCDi_SetCtrl( slot, ctrls->gcdRegs ); // Rg[ݒ & DMAX^[g + } + else + { + void *ramEndp; + u32 ctrlTmp; + + GCDi_SetCtrl( slot, ctrls->gcdRegs ); // Rg[ݒ + + ramEndp = (u8 *)ramp + size; // i[IAhXZo + + 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; // J[h̒ʒm + } +} + +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..43d5c83e --- /dev/null +++ b/build/libraries/gcd/common/gcd_init.c @@ -0,0 +1,1696 @@ +/*---------------------------------------------------------------------------* + 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]); +} + + +// SDKSecondarySlot̃J[hvZbTݒ肪pӂĂȂ̂ŁAƂ肠[JŗpӁB +#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); +} + +// SDKSecondarySlot̃J[hbNpӂĂȂ̂ŁAƂ肠PrimarySlotƋpŁB +#ifdef SDK_ARM9 +#define OSi_ASSERT_ID( id ) SDK_ASSERTMSG( id >= OS_MAINP_LOCK_ID_START && id <= OS_MAINP_SYSTEM_LOCK_ID, \ + "lock ID %d is out of bounds", id ) +#else +#define OSi_ASSERT_ID( id ) SDK_ASSERTMSG( id >= OS_SUBP_LOCK_ID_START && id <= OS_SUBP_SYSTEM_LOCK_ID, \ + "lock ID %d is out of bounds", id ) +#endif + +static void OSi_AllocateExCardBus(void) +{ +#ifdef SDK_ARM9 + MIi_SetExCardProcessor(MI_PROCESSOR_ARM9); // Card for MAIN +#endif +} + +static void OSi_FreeExCardBus(void) +{ +#ifdef SDK_ARM9 + MIi_SetExCardProcessor(MI_PROCESSOR_ARM7); // Card for SUB +#endif +} + +#define HW_CARD_B_LOCK_BUF HW_CTRDG_LOCK_BUF + +s32 OS_LockExCard(u16 lockID) +{ + OSi_ASSERT_ID(lockID); + + return OS_LockByWord(lockID, (OSLockWord *)HW_CARD_B_LOCK_BUF, OSi_AllocateExCardBus); +} + +s32 OS_UnlockExCard(u16 lockID) +{ + OSi_ASSERT_ID(lockID); + + return OS_UnlockByWord(lockID, (OSLockWord *)HW_CARD_B_LOCK_BUF, OSi_FreeExCardBus); +} + + +/*---------------------------------------------------------------------------* + Name: GCD_Init + + Description: initialize for game card access + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_Init( void ) +{ + GCDSlot slot; + MIProcessor lastProc = MI_GetCardProcessor(); + MIProcessor lastProcB = MI_GetExCardProcessor(); + u16 id = (u16)OS_GetLockID(); + + OS_LockCard( id ); + OS_LockExCard( id ); + +#ifdef SDK_ARM9 + MIi_SetCardProcessor( MI_PROCESSOR_ARM9 ); + MIi_SetExCardProcessor( MI_PROCESSOR_ARM9 ); +#else // SDK_ARM9 + while ( MI_GetCardProcessor() != MI_PROCESSOR_ARM7 ) + { + } + while ( MI_GetExCardProcessor() != MI_PROCESSOR_ARM7 ) + { + } +#endif // SDK_ARM7 + + if ( GCD_Initialized[GCD_PRIMARY_SLOT] == FALSE || + GCD_Initialized[GCD_SECONDARY_SLOT] == FALSE ) + { + GCDi_Init( TRUE ); + GCDi_LoadHeaderAll(); + GCDi_LoadSecureAll(); + } + + for (slot=GCD_PRIMARY_SLOT; slot<=GCD_SECONDARY_SLOT; slot++) + { + if ( GCD_Initialized[slot] == FALSE ) + { + if ( GCD_IsExisting( slot ) ) + { + if ( GCDi_IsDsApp( slot ) ) + { + GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); + + if ( rh->l.twlAreaOffset ) // && (sh->nCardID & GCD_ROMID_TWLROM_MASK) ) + { + u32 chat_cycles = OS_MSEC_TO_CPUCYC( 25 ) / GCD_CHATTERING_CYCLES; +#ifdef SDK_ARM9 + chat_cycles /= 2; +#endif // SDK_ARM9 + GCD_Reset( slot, chat_cycles ); + GCDi_LoadHeader( slot ); + GCDi_LoadSecure2( slot ); + } + + GCD_Initialized[slot] = TRUE; + } + } + } + } + +#ifdef SDK_ARM9 + MIi_SetCardProcessor( lastProc ); + MIi_SetExCardProcessor( lastProcB ); +#endif // SDK_ARM9 + + OS_UnlockExCard( id ); + OS_UnlockCard( id ); + + OS_ReleaseLockID( id ); +} + +/*---------------------------------------------------------------------------* + Name: GCDi_Init + + Description: initialize for game card access + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_Init( BOOL reset ) +{ + static BOOL initialized; + + if ( initialized == FALSE ) + { + GCDSlot slot; + + if ( reset ) + { +#ifdef SDK_ARM7 + + OSIntrMode enabled; + OSIrqMask lastIE; + BOOL lastIME; + + lastIE = OS_EnableIrqMask(OS_IE_SPFIFO_RECV); + lastIME = OS_EnableIrq(); + enabled = OS_EnableInterrupts(); + + //---- setting PXI + PXI_Init(); + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_GCD, GCDi_CallbackForResetAll); + + while ( !( GCDi_Work[GCD_PRIMARY_SLOT].isPxiDone == TRUE && + GCDi_Work[GCD_SECONDARY_SLOT].isPxiDone == TRUE ) ) + { + } + + (void)OS_RestoreIrq(lastIME); + (void)OS_SetIrqMask(lastIE); + (void)OS_RestoreInterrupts(enabled); + +#else // SDK_ARM9 + + u32 chat_cycles = OS_MSEC_TO_CPUCYC( 25 ) / GCD_CHATTERING_CYCLES; + chat_cycles /= 2; + GCD_ResetAll( chat_cycles ); + +#endif // SDK_ARM9 + } + + for (slot=GCD_PRIMARY_SLOT; slot<=GCD_SECONDARY_SLOT; slot++) + { + GCDWork *gw = &GCDi_Work[slot]; + GCDRomCtrls *ctrls = &gw->ctrls; + + GCDi_GenCtrl( &ctrls->nLoadTableRegs, GCD_RW_READ, + GCD_PAGE_16, + GCD_CKT_240NS, 0, 0x18, + FALSE, FALSE, FALSE, FALSE ); + + GCDi_GenCtrl( &ctrls->nSendOnlyOpRegs, GCD_RW_READ, + GCD_PAGE_0, + GCD_CKT_240NS, 0x18, 0, + FALSE, FALSE, FALSE, FALSE ); + + GCDi_GenCtrl( &ctrls->nIDRegs, GCD_RW_READ, + GCD_PAGE_STAT, + GCD_CKT_240NS, 0x18, 0, + FALSE, FALSE, FALSE, FALSE ); + + GCDi_GenCtrl( &ctrls->nReadShortHeaderRegs, GCD_RW_READ, + GCD_PAGE_1, + GCD_CKT_240NS, REG_MI_MCCNT1_L1_MASK, REG_MI_MCCNT1_L2_MASK >> REG_MI_MCCNT1_L2_SHIFT, + FALSE, FALSE, FALSE, FALSE ); + + GCDi_GenCtrl( &ctrls->nReadRomRegs, GCD_RW_READ, + GCD_PAGE_8, + GCD_CKT_240NS, 0x657, 0x1, + FALSE, FALSE, FALSE, FALSE ); + + GCDi_GenCtrl( &ctrls->sSendOnlyOpRegs, GCD_RW_READ, + GCD_PAGE_0, + GCD_CKT_240NS, 0x8f8+0x18, 0, + FALSE, FALSE, FALSE, FALSE ); // enable after PNG ON + + GCDi_GenCtrl( &ctrls->sIDRegs, GCD_RW_READ, + GCD_PAGE_STAT, + GCD_CKT_240NS, 0x8f8+0x18, 0, + FALSE, TRUE, FALSE, TRUE ); + + GCDi_GenCtrl( &ctrls->sReadRomRegs, GCD_RW_READ, + GCD_PAGE_8, + GCD_CKT_240NS, 0x8f8, 0x18, + FALSE, TRUE, FALSE, TRUE ); + + GCDi_GenCtrl( &ctrls->gIDRegs, GCD_RW_READ, + GCD_PAGE_STAT, + GCD_CKT_150NS, 0, 0x1, +#ifdef GCD_ENABLE_SCRAMBLE + TRUE, TRUE, TRUE, TRUE ); +#else // GCD_ENABLE_SCRAMBLE + FALSE, FALSE, FALSE, FALSE ); +#endif // GCD_ENABLE_SCRAMBLE + + GCDi_GenCtrl( &ctrls->gReadRomRegs, GCD_RW_READ, + GCD_PAGE_1, + GCD_CKT_150NS, 0x657, 0x1, +#ifdef GCD_ENABLE_SCRAMBLE + TRUE, TRUE, TRUE, TRUE ); +#else // GCD_ENABLE_SCRAMBLE + FALSE, FALSE, FALSE, FALSE ); +#endif // GCD_ENABLE_SCRAMBLE + + GCDi_GenCtrl( &ctrls->gWriteRomRegs, GCD_RW_WRITE, + GCD_PAGE_1, + GCD_CKT_150NS, 0x21, 0x1, +#ifdef GCD_ENABLE_SCRAMBLE + TRUE, TRUE, TRUE, TRUE ); +#else // GCD_ENABLE_SCRAMBLE + FALSE, FALSE, FALSE, FALSE ); +#endif // GCD_ENABLE_SCRAMBLE + } + + initialized = TRUE; + } +} + + +/*---------------------------------------------------------------------------* + Name: GCD_SetPrimarySlot + + Description: set primary game card slot + + Arguments: primary slot + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_SetPrimarySlot( u8 slot ) +{ + if ( slot <= 1 ) + { + reg_MI_MC_SWP = (u8)(slot * REG_MI_MC_SWP_E_MASK); + } +} + +/*---------------------------------------------------------------------------* + Name: GCD_GetPrimarySlot + + Description: get primary game card slot + + Arguments: None + + Returns: primary slot + *---------------------------------------------------------------------------*/ +u8 GCD_GetPrimarySlot( void ) +{ + return (u8)((reg_MI_MC_SWP & REG_MI_MC_SWP_E_MASK) >> REG_MI_MC_SWP_E_SHIFT); +} + + +/*---------------------------------------------------------------------------* + Name: GCDi_SendtoPxi + + Description: send data via PXI + + Arguments: data : data to send + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_SendtoPxi(u32 data) +{ + while (PXI_SendWordByFifo(PXI_FIFO_TAG_GCD, data, FALSE) != PXI_FIFO_SUCCESS) + { + SVC_WaitByLoop(1); + } +} + +/*---------------------------------------------------------------------------* + Name: GCDi_CallbackForReset + + Description: callback to receive data from PXI + + Arguments: tag : tag from PXI (unused) + data : data from PXI + err : error bit (unused) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_CallbackForReset(PXIFifoTag tag, u32 data, BOOL err) +{ +#pragma unused( tag, err ) + GCDPxiCmd pxi; + pxi.raw = data; + + if (pxi.e.cmd == GCD_PXI_COMMAND_RESET) + { +#ifdef SDK_ARM7 + GCD_Reset( (GCDSlot)pxi.e.slot, pxi.e.param ); + //---- send message to ARM9 + GCDi_SendtoPxi( GCD_PXI_COMMAND_RESET ); +#endif // SDK_ARM7 + + GCDi_Work[pxi.e.slot].isPxiDone = TRUE; + } + else + { +#ifndef SDK_FINALROM + OS_Panic("illegal GCD pxi command."); +#else + OS_Panic(""); +#endif + } +} + +/*---------------------------------------------------------------------------* + Name: GCDi_CallbackForResetAll + + Description: callback to receive data from PXI + + Arguments: tag : tag from PXI (unused) + data : data from PXI + err : error bit (unused) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_CallbackForResetAll(PXIFifoTag tag, u32 data, BOOL err) +{ +#pragma unused( tag, err ) + GCDPxiCmd pxi; + pxi.raw = data; + + if (pxi.e.cmd == GCD_PXI_COMMAND_RESET) + { +#ifdef SDK_ARM7 + GCD_ResetAll( pxi.e.param ); + //---- send message to ARM9 + GCDi_SendtoPxi( GCD_PXI_COMMAND_RESET ); +#endif // SDK_ARM7 + + GCDi_Work[GCD_PRIMARY_SLOT].isPxiDone = TRUE; + GCDi_Work[GCD_SECONDARY_SLOT].isPxiDone = TRUE; + } + else + { +#ifndef SDK_FINALROM + OS_Panic("illegal GCD pxi command."); +#else + OS_Panic(""); +#endif + } +} + + +/*---------------------------------------------------------------------------* + Name: GCDi_GetExistingSlots + + Description: get enabled slots + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +static void GCDi_GetExistingSlots( GCDSlot* start, GCDSlot* end ) +{ + if ( GCD_IsExisting( GCD_PRIMARY_SLOT ) ) + { + *start = GCD_PRIMARY_SLOT; + if ( GCD_IsExisting( GCD_SECONDARY_SLOT ) ) + { + *end = GCD_SECONDARY_SLOT; + } + else + { + *end = GCD_PRIMARY_SLOT; + } + } + else + { + *start = GCD_SECONDARY_SLOT; + if ( GCD_IsExisting( GCD_SECONDARY_SLOT ) ) + { + *end = GCD_SECONDARY_SLOT; + } + else + { + *end = GCD_NO_SLOT; + } + } +} + + +/*---------------------------------------------------------------------------* + Name: GCD_Reset + + Description: reset game card + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_Reset( GCDSlot slot, u32 chat_cycles ) +{ +#ifdef SDK_ARM9 +#pragma unused( chat_cycles, slot ) + + OSIntrMode enabled; + OSIrqMask lastIE; + BOOL lastIME; + + GCDPxiCmd pxi; + GCDi_Work[GCD_PRIMARY_SLOT].isPxiDone = FALSE; + GCDi_Work[GCD_SECONDARY_SLOT].isPxiDone = FALSE; + + lastIE = OS_EnableIrqMask(OS_IE_SPFIFO_RECV); + lastIME = OS_EnableIrq(); + enabled = OS_EnableInterrupts(); + + //---- setting PXI + PXI_Init(); + while (!PXI_IsCallbackReady(PXI_FIFO_TAG_GCD, PXI_PROC_ARM7)) + { + } + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_GCD, GCDi_CallbackForReset); + + pxi.e.cmd = GCD_PXI_COMMAND_RESET; + pxi.e.param = chat_cycles; + pxi.e.slot = (u32)slot; + + //---- send message to ARM7 + GCDi_SendtoPxi( pxi.raw ); + + while ( !( GCDi_Work[GCD_PRIMARY_SLOT].isPxiDone == TRUE && + GCDi_Work[GCD_SECONDARY_SLOT].isPxiDone == TRUE ) ) + { + } + + (void)OS_RestoreIrq(lastIME); + (void)OS_SetIrqMask(lastIE); + (void)OS_RestoreInterrupts(enabled); + + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_GCD, NULL); + + GCDi_Enable( slot ); + +#else // SDK_ARM7 + + REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); + + reg_MI_MCCHAT = (u16)chat_cycles; + + OS_SpinWait( chat_cycles * GCD_CHATTERING_CYCLES ); + + if ( !GCD_IsExisting( slot ) ) + { + return; + } + + GCDi_Enable( slot ); + + if ( GCD_GetDetectMode( slot ) != 0 ) + { + GCD_SetDetectMode( slot, 3 ); + + while ( GCD_GetDetectMode( slot ) != 0 ) + { + } + } + + OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); + + GCD_SetDetectMode( slot, 1 ); + + OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); + + GCD_SetDetectMode( slot, 2 ); + + OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); + + *cnt1 = REG_MI_MCCNT1_RESB_MASK; // preset + + OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); + +#endif // SDK_ARM7 +} + +/*---------------------------------------------------------------------------* + Name: GCD_ResetAll + + Description: reset game cards + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_ResetAll( u32 chat_cycles ) +{ +#ifdef SDK_ARM9 +#pragma unused( chat_cycles ) + + GCDWork *gw = &GCDi_Work[GCD_PRIMARY_SLOT]; + OSIntrMode enabled; + OSIrqMask lastIE; + BOOL lastIME; + + GCDSlot slot; + GCDPxiCmd pxi; + gw->isPxiDone = FALSE; + + lastIE = OS_EnableIrqMask(OS_IE_SPFIFO_RECV); + lastIME = OS_EnableIrq(); + enabled = OS_EnableInterrupts(); + + //---- setting PXI + PXI_Init(); + while (!PXI_IsCallbackReady(PXI_FIFO_TAG_GCD, PXI_PROC_ARM7)) + { + } + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_GCD, GCDi_CallbackForResetAll); + + pxi.e.cmd = GCD_PXI_COMMAND_RESET; + pxi.e.param = chat_cycles; + pxi.e.slot = (u32)NULL; + + //---- send message to ARM7 + GCDi_SendtoPxi( pxi.raw ); + + while (gw->isPxiDone == FALSE) + { + } + + (void)OS_RestoreIrq(lastIME); + (void)OS_SetIrqMask(lastIE); + (void)OS_RestoreInterrupts(enabled); + + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_GCD, NULL); + + for (slot=GCD_PRIMARY_SLOT; slot<=GCD_SECONDARY_SLOT; slot++) + { + GCDi_Enable( slot ); + } + +#else // SDK_ARM7 + + GCDSlot slot, start, end; + + reg_MI_MCCHAT = (u16)chat_cycles; + + OS_SpinWait( chat_cycles * GCD_CHATTERING_CYCLES ); + + GCDi_GetExistingSlots( &start, &end ); + + for (slot=start; slot<=end; slot++) + { + GCDi_Enable( slot ); + + if ( GCD_GetDetectMode( slot ) != 0 ) + { + GCD_SetDetectMode( slot, 3 ); + + while ( GCD_GetDetectMode( slot ) != 0 ) + { + } + } + } + + if ( end != GCD_NO_SLOT ) + { + OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); + } + + for (slot=start; slot<=end; slot++) + { + GCD_SetDetectMode( slot, 1 ); + } + + if ( end != GCD_NO_SLOT ) + { + OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); + } + + for (slot=start; slot<=end; slot++) + { + GCD_SetDetectMode( slot, 2 ); + } + + if ( end != GCD_NO_SLOT ) + { + OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); + } + + for (slot=start; slot<=end; slot++) + { + REGType32v* cnt1 = GCDi_SelectRegAddr( slot, REG_MCCNT1_ADDR ); + *cnt1 = REG_MI_MCCNT1_RESB_MASK; // preset + } + + if ( end != GCD_NO_SLOT ) + { + OS_SpinWait( OS_MSEC_TO_CPUCYC( 50 ) ); + } + +#endif // SDK_ARM7 +} + +/*---------------------------------------------------------------------------* + Name: GCDi_LoadSecure + + Description: load secure area + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ + +static BOOL isCtrApp[2]; +static BOOL isDsApp[2]; + + +/*************************************************** + + ***************************************************/ + +BOOL GCDi_IsDsApp( GCDSlot slot ) +{ + return isDsApp[slot]; +} + +static const u8 dsNinLogo[] = { +0x24,0xff,0xae,0x51,0x69,0x9a,0xa2,0x21,0x3d,0x84,0x82,0x0a,0x84,0xe4,0x09,0xad, +0x11,0x24,0x8b,0x98,0xc0,0x81,0x7f,0x21,0xa3,0x52,0xbe,0x19,0x93,0x09,0xce,0x20, +0x10,0x46,0x4a,0x4a,0xf8,0x27,0x31,0xec,0x58,0xc7,0xe8,0x33,0x82,0xe3,0xce,0xbf, +0x85,0xf4,0xdf,0x94,0xce,0x4b,0x09,0xc1,0x94,0x56,0x8a,0xc0,0x13,0x72,0xa7,0xfc, +0x9f,0x84,0x4d,0x73,0xa3,0xca,0x9a,0x61,0x58,0x97,0xa3,0x27,0xfc,0x03,0x98,0x76, +0x23,0x1d,0xc7,0x61,0x03,0x04,0xae,0x56,0xbf,0x38,0x84,0x00,0x40,0xa7,0x0e,0xfd, +0xff,0x52,0xfe,0x03,0x6f,0x95,0x30,0xf1,0x97,0xfb,0xc0,0x85,0x60,0xd6,0x80,0x25, +0xa9,0x63,0xbe,0x03,0x01,0x4e,0x38,0xe2,0xf9,0xa2,0x34,0xff,0xbb,0x3e,0x03,0x44, +0x78,0x00,0x90,0xcb,0x88,0x11,0x3a,0x94,0x65,0xc0,0x7c,0x63,0x87,0xf0,0x3c,0xaf, +0xd6,0x25,0xe4,0x8b,0x38,0x0a,0xac,0x72,0x21,0xd4,0xf8,0x07,0x56,0xcf +}; + +static BOOL IsDsApp( GCDSlot slot ) +{ + GCDRomHeader *rh = GCDi_GetRomHeaderAddr( slot ); + BOOL isDsNinLogo = TRUE; + int i; + + isDsApp[slot] = FALSE; + + for ( i=0; il.nintendoLogo)[i] ) + { + isDsNinLogo = FALSE; + break; + } + } + if ( isDsNinLogo ) + { + isDsApp[slot] = TRUE; + } + + return isDsApp[slot]; +} + +/*************************************************** + + ***************************************************/ +static void SetVAE( GCDSlot slot, GCDCmd64* op ) +{ + GCDSecureWork* sec = &GCDi_SecureWork[slot]; + op->dw |= ((u64)(sec->va) << GCDOP_N_VAE_SHIFT) & GCDOP_N_VAE_MASK; +} + +static void SetVBI( GCDSlot slot, GCDCmd64* op ) +{ + GCDSecureWork* sec = &GCDi_SecureWork[slot]; + op->dw |= sec->vb; + sec->vb >>= GCDOP_N_VBI_SHIFT; +} + +static void SetVA( GCDSlot slot, GCDCmd64* op ) +{ + GCDSecureWork* sec = &GCDi_SecureWork[slot]; + op->dw |= ((u64)(sec->va) << GCDOP_S_VA_SHIFT) & GCDOP_S_VA_MASK; +} + +static void SetVB( GCDSlot slot, GCDCmd64* op ) +{ + GCDSecureWork* sec = &GCDi_SecureWork[slot]; + op->dw |= sec->vb & GCDOP_S_VB_MASK; + sec->vb++; +} + +static void SetDummyVC( GCDSlot slot, GCDCmd64* op ) +{ + GCDSecureWork* sec = &GCDi_SecureWork[slot]; + op->dw |= ((u64)(sec->vc_dummy) << GCDOP_S_VC_SHIFT) & GCDOP_S_VC_MASK; +} + +static void SetVD( GCDSlot slot, GCDCmd64* op ) +{ + GCDSecureWork* sec = &GCDi_SecureWork[slot]; + op->dw |= ((u64)(sec->vd) << GCDOP_S_VD_SHIFT) & GCDOP_S_VD_MASK; +} + +static void GCDi_GenVA_VB_VD( GCDSlot slot ) +{ + GCDHeader* fh = GCDi_GetRomHeaderAddr( slot ); + GCDSecureWork* sec = &GCDi_SecureWork[slot]; + + sec->va = fh->sign.raw[0]; + sec->vb = fh->sign.raw[1]; + sec->vd = fh->sign.raw[2]; + sec->vc_dummy = fh->sign.raw[3]; + + EncryptByBlowfish(&sec->blowfishCardTable, &sec->va, &sec->vb); + EncryptByBlowfish(&sec->blowfishCardTable, &sec->vd, &sec->vc_dummy); +} + +// TWLFIRM_DSCARD_DEV + +#ifndef FIRM_FORCE_DEBUGGER + +void GCDi_InitCardOpBlowfish( GCDSlot slot ) +{ + GCDSecureWork* sec = &GCDi_SecureWork[slot]; + const BLOWFISH_CTX *blowfishInitTablep = &GCDi_BlowfishInitTableGCDFIRM; + BLOWFISH_CTX *tableBufp = &sec->blowfishCardTable; + + MI_CpuCopyFast( (void*)blowfishInitTablep, (void *)tableBufp, sizeof(BLOWFISH_CTX) ); + InitBlowfish( tableBufp, &((u8*)GCDi_HeaderBuf[slot])[0xc], 4 ); +} + +void GCDi_InitSecureParam( GCDSlot slot, BOOL twl_ex ) +{ + GCDRomHeaderDS *rh = GCDi_GetRomHeaderAddr( slot ); + u32 code = rh->initialCode; + + if ( twl_ex ) + { + rh->initialCode = 'ALWT'; + } + +#ifdef FIRM_FORCE_FIRMBLOWFISH + GCDi_InitCardOpBlowfish( slot ); +#else // FIRM_FORCE_FIRMBLOWFISH + GCDi_InitCardOpBlowfishDS( slot ); +#endif // FIRM_FORCE_FIRMBLOWFISH + + rh->initialCode = code; + + GCDi_GenVA_VB_VD( slot ); // VA & VB & VD +} + +void GCDi_InitPngIntf( GCDSlot slot ) +{ + GCDSecureWork* sec = &GCDi_SecureWork[slot]; + +#define PNA_INDEX (((u32)GCDi_GetRomHeaderAddr( slot )) + 0x12) // PNAe[uECfbNX +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 ); + + // omlݒ + + 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 ); + + // f[^XNuݒ + 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 ) + { + // 3Dpݒ + { + ctrls->gcdRegs->ctrl &= ~REG_MI_MCCNT1_PC_MASK; + ctrls->gcdRegs->ctrl |= GCD_PAGE_1; + } + } + ctrls->gcdOp.dw = GCDOP_S_OP_RD_SEGMENT // R}hݒ + | (((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; + + // ZOgEɂ + // 3D1ZOg8y[Wɕēǂ + 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]); // ZOge[uݒ + GCDi_SecureWork[slot].numSecureSegment = GCD_SECURE_AREA_SIZE / GCD_SECURE_SEGMENT_SIZE; // SECUREZOg 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 { + // SECURË𒴂Ȃ悤ɒ + while ((diffSegmentNo = ((*sec->segmentTblp) >>*tblShiftp) & 0x3) >= sec->numSecureSegment) + *tblShiftp += 2; + + *segmentOffsetp = (s16)(GCD_SECURE_SEGMENT_SIZE * diffSegmentNo); // ZOgItZbg Zbg + *blockOffsetp = 0; // ubNItZbg NA + + 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 Zbg + + //GCDi_SecureWork.paramBak = *paramp; // ÍÕobvAbv + // my_memcopy((void *)paramp, (void *)&(GCDi_SecureWork.paramBak),sizeof(CardCtrlParam)); // ÍÕobvAbv + + // R}hÍ + EncryptByBlowfish( &sec->blowfishCardTable, &((u32*)&ctrls->gcdOp)[1], (u32*)&ctrls->gcdOp ); + + // 3DpvR}hs + 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; + + // CeVQCeVP։Z +#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; // }XNROMpݒF CeVԂɃNbN +// 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; // R}hݒ + 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; // R}hݒ + 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; // R}hݒ + 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; // R}hݒ + 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; // R}hݒ + 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; // }XNROMpݒF CeVԂɃNbN + 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; // }XNROMpݒF CeVԂɃNbN + 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; // }XNROMpݒF CeVԂɃNbN + 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; // R}hݒ + 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; // R}hݒ + + 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 ); + + // ÍIuWFNg̕ + 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 ); + } + + // ÍIuWFNg̕ + 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/init/ARM7/Makefile b/build/libraries/init/ARM7/Makefile new file mode 100644 index 00000000..2db293a0 --- /dev/null +++ b/build/libraries/init/ARM7/Makefile @@ -0,0 +1,53 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - 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. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +# Codegen for sub processer +override TWL_PROC = ARM7 + +# Avoid to use pre-compile-header of "nitro.h" +TWL_NO_STD_PCHDR = True + +# Avoid to build THUMB version object +override TWL_CODEGEN = ARM + +SRCS = crt0_firm.c + +TARGET_OBJ = crt0_firm.o + +MACRO_FLAGS += -DSDK_NOINIT + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/init/ARM7/crt0_firm.c b/build/libraries/init/ARM7/crt0_firm.c new file mode 100644 index 00000000..e93d2521 --- /dev/null +++ b/build/libraries/init/ARM7/crt0_firm.c @@ -0,0 +1,650 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - init + File: crt0_firm.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +#include + +void _start(void); +void _start_AutoloadDoneCallback(void *argv[]); + +#define SDK_NITROCODE_LE 0x2106c0de +#define SDK_NITROCODE_BE 0xdec00621 + +#define SDK_TWLCODE_LE 0x6314c0de +#define SDK_TWLCODE_BE 0xdec01463 + +/* O֐Qƒ` */ +extern void OS_IrqHandler(void); +extern void _fp_init(void); +extern void __call_static_initializers(void); + +static void INITi_CpuClear32(register u32 data, register void *destp, register u32 size); +static void INITi_CpuClearFast(register u32 data, register void* destp, register u32 size); +static void INITi_DoAutoload(void); +static void INITi_ShelterLtdBinary(void); +static void INITi_CopySysConfig( void ); +static void INITi_DetectMainMemorySize(void); +#ifndef SDK_NOINIT +static void INITi_ShelterStaticInitializer(u32* ptr); +static void INITi_CallStaticInitializers(void); +#endif + +/* JXNvgɂ`V{Q */ +extern void SDK_AUTOLOAD_LIST(void); +extern void SDK_AUTOLOAD_LIST_END(void); +extern void SDK_AUTOLOAD_START(void); +extern void SDK_STATIC_BSS_START(void); +extern void SDK_STATIC_BSS_END(void); + +void *const _start_ModuleParams[] = +{ + (void *)SDK_AUTOLOAD_LIST, + (void *)SDK_AUTOLOAD_LIST_END, + (void *)SDK_AUTOLOAD_START, + (void *)SDK_STATIC_BSS_START, + (void *)SDK_STATIC_BSS_END, + (void*)0, // CompressedStaticEnd. This fixed number will be updated by compstatic tool. + (void*)0, // SDK_VERSION_ID // SDK version info /* [TODO] rhʂ */ + (void*)SDK_NITROCODE_BE, + (void*)SDK_NITROCODE_LE, +}; + +extern void SDK_LTDAUTOLOAD_LIST(void); +extern void SDK_LTDAUTOLOAD_LIST_END(void); +extern void SDK_LTDAUTOLOAD_START(void); + +void* const _start_LtdModuleParams[] = +{ + (void*)SDK_LTDAUTOLOAD_LIST, + (void*)SDK_LTDAUTOLOAD_LIST_END, + (void*)SDK_LTDAUTOLOAD_START, + (void*)0, // CompressedLtdautoloadEnd. This fixed number will be updated by compstatic tool. + (void*)SDK_TWLCODE_BE, + (void*)SDK_TWLCODE_LE, +}; + +/*---------------------------------------------------------------------------* + Name: _start + + Description: Start up + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL asm void _start( void ) +{ + //---- set IME = 0 + // ( use that LSB of HW_REG_BASE equal to 0 ) + mov r12, #HW_REG_BASE + str r12, [r12, #REG_IME_OFFSET] + + //---- initialize stack pointer + // SVC mode + mov r0, #HW_PSR_SVC_MODE + msr cpsr_c, r0 + ldr sp, =HW_FIRM_SVC_STACK_END + + // IRQ mode + mov r0, #HW_PSR_IRQ_MODE + msr cpsr_c, r0 + ldr r0, =HW_FIRM_IRQ_STACK_END + mov sp, r0 + + // System mode + ldr r1, =HW_FIRM_IRQ_STACK_SIZE + sub r1, r0, r1 + mov r0, #HW_PSR_SYS_MODE + msr cpsr_csfx, r0 + sub sp, r1, #4 // 4byte for stack check code + +#ifdef FIRM_DISABLE_CR_AT_WARMBOOT + //---- read reset flag from mcu +#ifdef SDK_TS +#if 0 + mov r0, #REG_PMIC_SW_FLAGS_ADDR + bl PMi_GetRegister + ands r0, r0, #PMIC_SW_FLAGS_WARMBOOT +#else + mov r0, #I2C_SLAVE_MICRO_CONTROLLER + mov r1, #MCU_REG_TEMP_ADDR + bl I2Ci_ReadRegister + ldr r2, =HW_RESET_PARAMETER_BUF + str r0, [r2] // store 4 bytes + cmp r0, #0 +#endif + movne r0, #FIRM_PXI_ID_WARMBOOT + moveq r0, #FIRM_PXI_ID_COLDBOOT + bl PXIi_SendByIntf +#endif // SDK_TS +#endif // FIRM_DISABLE_CR_AT_WARMBOOT + + //---- wait for main memory mode into burst mode + ldr r3, =REG_EXMEMCNT_L_ADDR + mov r1, #REG_MI_EXMEMCNT_L_EMODE_MASK +@1: + ldrh r2, [r3] + tst r2, r1 + beq @1 + + mov r0, #FIRM_PXI_ID_INIT_MMEM + bl PXIi_WaitIDByIntf + + //---- clear HW_TWL_MAIN_MEM_SHARED + mov r0, #0 + ldr r1, =HW_TWL_MAIN_MEM_SHARED + mov r2, #HW_TWL_MAIN_MEM_SHARED_SIZE + bl INITi_CpuClearFast + + //---- notify to clear HW_MAIN_MEM_SHARED + mov r0, #FIRM_PXI_ID_INIT_MMEM + bl PXIi_SendIDByIntf + + /* SCFG HW_SYS_CONF_BUF փRs[ */ + bl INITi_CopySysConfig + + //---- load autoload block and initialize bss + //bl INITi_DoAutoload +#ifndef SDK_FINALROM // for IS-TWL-DEBUGGER + bl _start_AutoloadDoneCallback +#endif + + //---- fill static bss with 0 + ldr r0, =_start_ModuleParams + ldr r1, [r0, #12] // BSS segment start + ldr r2, [r0, #16] // BSS segment end + mov r0, #0 + sub r2, r2, r1 + bl INITi_CpuClearFast + + //---- detect main memory size + bl INITi_DetectMainMemorySize + +#ifndef SDK_FINALROM + //---- set debug print window + ldr r1, =HW_PRINT_OUTPUT_ARM9 + mov r0, #OS_PRINT_OUTPUT_DEFAULT_ARM9 + orr r0, r0, #(OS_PRINT_OUTPUT_DEFAULT_ARM7<<8) + strh r0, [r1] + mov r0, #OS_PRINT_OUTPUT_DEFAULT_ARM9ERR + orr r0, r0, #(OS_PRINT_OUTPUT_DEFAULT_ARM7ERR<<8) + strh r0, [r1, #2] +#endif + + //---- set interrupt vector + ldr r1, =HW_INTR_VECTOR_BUF + ldr r0, =OS_IrqHandler + str r0, [r1, #0] + +#ifndef SDK_NOINIT + //---- for C++ + bl _fp_init + bl TwlSpStartUp + bl __call_static_initializers +// bl INITi_CallStaticInitializers +#endif + + //---- start (to 16bit code) + ldr r1, =TwlSpMain + ldr lr, =HW_RESET_VECTOR + + bx r1 +} + +/*---------------------------------------------------------------------------* + Name: INITi_CpuClearFast + Description: 32 Byte PʂŃobt@̃NAsB + Arguments: r0 - NAlB + r1 - NAւ̃|C^B + r2 - AăNAobt@B + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_CpuClearFast(register u32 data, register void* destp, register u32 size) +{ + stmfd sp!, {r4-r9} + + add r9, r1, r2 // r9: destEndp = destp + size + mov r12, r2, lsr #5 // r12: destBlockEndp = destp + size/32*32 + add r12, r1, r12, lsl #5 + + mov r2, r0 + mov r3, r2 + mov r4, r2 + mov r5, r2 + mov r6, r2 + mov r7, r2 + mov r8, r2 + +@40: + cmp r1, r12 // while (destp < destBlockEndp) + stmltia r1!, {r0, r2-r8} // *((vu32 *)(destp++)) = data + blt @40 +@41: + cmp r1, r9 // while (destp < destEndp) + stmltia r1!, {r0} // *((vu32 *)(destp++)) = data + blt @41 + + ldmfd sp!, {r4-r9} + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_CpuClear32 + Description: 32 bit PʂŃobt@̃NAsB + Arguments: r0 - NAlB + r1 - NAւ̃|C^B + r2 - AăNAobt@B + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_CpuClear32(register u32 data, register void* destp, register u32 size) +{ + add r12, r1, r2 +@001: cmp r1, r12 + strlt r0, [r1], #4 + blt @001 + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_DoAutoload + Description: NɉāAeI[g[hubŇŒf[^̓WJ + yѕϐ 0 NAsB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +/* + * < iKI[g[h > + * 0x02f88000 crt0 yшiڃ[hoCizuĂB + * NITRO ƋL”\ WRAM ɔzuׂoCif[^ 0x037c0000 Ƀ[hB + * TWL ł삵Ȃ WRAM ɔzuׂoCif[^𑱂̃AhXɃ[hB + * 0x02e80000 ɓiڃ[hoCizuĂB + * 0x04000 oCg̓J[h ROM ēǂݏos‚Ȃ̂ŁA0x02f84000 - 0x02f88000 ɑޔB + * NITRO ƋL”\ MAIN ɔzuׂoCif[^ 0x02f88000 + sizeof(crt0) Ƀ[hB + * TWL ł삵Ȃ MAIN ɔzuׂoCif[^𑱂̃AhXɃ[hB + */ +static asm void +INITi_DoAutoload(void) +{ +@000: + stmdb sp!, {lr} + /* WRAM pubNI[g[h */ + ldr r1, =_start_ModuleParams + ldr r12, [r1] // r12 = SDK_AUTOLOAD_LIST + ldr r0, [r1, #4] // r0 = SDK_AUTOLOAD_LIST_END + ldr r1, [r1, #8] // r1 = SDK_AUTOLOAD_START +@001: cmp r12, r0 + bge @010 + /* ŒZNV[h */ + stmdb sp!, {r0} + ldr r2, [r12], #4 // r2 = start address of destination range + ldr r3, [r12], #4 // r3 = size of fixed section + add r3, r3, r2 // r3 = end address of destination range of fixed section +@002: cmp r2, r3 + ldrlt r0, [r1], #4 + strlt r0, [r2], #4 + blt @002 + /* static initializer e[uǂݏo */ + ldr r0, [r12], #4 // r0 = address of the table managing pointers of static initializers +#ifndef SDK_NOINIT + stmdb sp!, {r0-r3, r12} + bl INITi_ShelterStaticInitializer + ldmia sp!, {r0-r3, r12} +#endif + /* .bss ZNV 0 NA */ + mov r0, #0 + ldr r3, [r12], #4 // r3 = size of .bss section + add r3, r3, r2 // r3 = end address of destination range of .bss section +@003: cmp r2, r3 + strlt r0, [r2], #4 + blt @003 +@004: ldmia sp!, {r0} + b @001 + +@010: /* CpubN݂̑mF */ + ldr r1, =HW_TWL_ROM_HEADER_BUF + 0x1dc /* ARM7 pg풓W[ ROM TCY */ + ldr r0, [r1] + cmp r0, #0 + beq @020 + + /* ēǂݏos•ޔ */ + bl INITi_ShelterLtdBinary + + /* CpubNI[g[h */ + ldr r1, =_start_LtdModuleParams + ldr r12, [r1] // r12 = SDK_LTDAUTOLOAD_LIST + ldr r0, [r1, #4] // r0 = SDK_LTDAUTOLOAD_LIST_END + ldr r1, [r1, #8] // r1 = SDK_LTDAUTOLOAD_START +@011: cmp r12, r0 + bge @020 + /* ŒZNV[h */ + stmdb sp!, {r0} + ldr r2, [r12], #4 // r2 = start address of destination range + ldr r3, [r12], #4 // r3 = size of fixed section + add r3, r3, r2 // r3 = end address of destination range of fixed section +@012: cmp r2, r3 + ldrlt r0, [r1], #4 + strlt r0, [r2], #4 + blt @012 + /* static initializer e[uǂݏo */ + ldr r0, [r12], #4 // r0 = address of the table managing pointers of static initializers +#ifndef SDK_NOINIT + stmdb sp!, {r0-r3, r12} + bl INITi_ShelterStaticInitializer + ldmia sp!, {r0-r3, r12} +#endif + /* .bss ZNV 0 NA */ + mov r0, #0 + ldr r3, [r12], #4 // r3 = size of .bss section + add r3, r3, r2 // r3 = end address of destination range of .bss section +@013: cmp r2, r3 + strlt r0, [r2], #4 + blt @013 +@014: ldmia sp!, {r0} + b @011 + +@020: /* I[g[hR[obN֐Ăяo */ + ldr r0, =_start_ModuleParams + ldr r1, =_start_LtdModuleParams + ldmia sp!, {lr} + b _start_AutoloadDoneCallback +} + +/*---------------------------------------------------------------------------* + Name: INITi_ShelterLtdBinary + Description: TWL p̃I[g[hoCif[^̓AJ[h ROM + ēǂݏołȂ̈̃f[^ޔGAɑޔB + ēǂݏołȂ̈̃f[^ ARM7 p ARM9 p̊g풓 + W[̂Q‚ɕÔ\̂ŁA璷ł͂邪 + ̐擪 0x4000 ꂼޔB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_ShelterLtdBinary(void) +{ + /* ޔEAhX𒲍 */ + ldr r1, =HW_TWL_ROM_HEADER_BUF + 0x1d8 /* ARM7 pg풓W[ RAM AhX */ + ldr r1, [r1] + ldr r3, =HW_TWL_ROM_HEADER_BUF + 0x038 /* ARM7 p풓W[ RAM AhX */ + ldr r3, [r3] + sub r2, r3, #0x4000 /* ēǂݏos—̈TCY */ /* ARM7 pޔGA */ + + /* Rs[ */ +@loop: ldr r0, [r1], #4 + str r0, [r2], #4 + cmp r2, r3 + blt @loop + + bx lr +} + +#ifndef SDK_NOINIT +/*---------------------------------------------------------------------------* + Name: INITi_ShelterStaticInitializer + Description: eI[g[hZOg static initializer ւ̃|C^ + e[u IRQ X^bN̍ŏ㕔ɑޔB + Arguments: ptr - ZOg̃|C^e[uւ̃|C^B + e[u NULL ŏI[ĂKvB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_ShelterStaticInitializer(u32* ptr) +{ + /* mF */ + cmp r0, #0 + bxeq lr + + /* ޔꏊ擪AhXvZ */ + ldr r1, =HW_FIRM_IRQ_STACK_END + ldr r2, =HW_FIRM_IRQ_STACK_SIZE + sub r1, r1, r2 + add r1, r1, #4 + + /* ޔꏊ擪󂫏ꏊ𒲍 */ +@001: ldr r2, [r1] + cmp r2, #0 + addne r1, r1, #4 + bne @001 + + /* 󂫏ꏊɃe[uRs[ */ +@002: ldr r2, [r0], #4 + str r2, [r1], #4 + cmp r2, #0 + bne @002 + + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_CallStaticInitializers + Description: eI[g[hZOg static initializer ĂяoB + I[g[hɂ IRQ X^bN̍ŏ㕔ɑޔĂ + ֐|C^e[u‚ŒĂяoB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_CallStaticInitializers(void) +{ + stmdb sp!, {lr} + + /* e[uޔꏊ擪AhXvZ */ + ldr r1, =HW_FIRM_IRQ_STACK_END + ldr r2, =HW_FIRM_IRQ_STACK_SIZE + sub r1, r1, r2 + add r1, r1, #4 + + /* e[uɊǗĂ|C^‚ŒĂяo */ +@001: ldr r0, [r1] + cmp r0, #0 + beq @002 + stmdb sp!, {r1} + mov lr, pc + bx r0 + ldmia sp!, {r1} + /* UĂяo|C^̓[NA (IRQX^bNԎ؂肵Ă) */ + mov r0, #0 + str r0, [r1], #4 + b @001 + +@002: ldmia sp!, {lr} + bx lr +} +#endif + +/*---------------------------------------------------------------------------* + Name: _start_AutoloadDoneCallback + Description: I[g[hR[obNB + Arguments: argv - I[g[hp[^ێĂzB + argv[0] = SDK_AUTOLOAD_LIST + argv[1] = SDK_AUTOLOAD_LIST_END + argv[2] = SDK_AUTOLOAD_START + argv[3] = SDK_STATIC_BSS_START + argv[4] = SDK_STATIC_BSS_END + Returns: ȂB + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL asm void +_start_AutoloadDoneCallback(void* argv[]) +{ + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_CopySysConfig + + Description: copy SCFG registers to HW_SYS_CONF_BUF and HW_PRV_WRAM_SYSRV + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static asm void INITi_CopySysConfig( void ) +{ +//################ temp: this process will be done in IPL + // SCFG enable? + ldr r2, =REG_EXT_ADDR + ldr r0, [r2] + tst r0, #0x80000000 + beq @9 + + ldr r2, =HW_PRV_WRAM_SYSRV + //EXT(extentions) + ldr r3, =REG_EXT_ADDR + ldr r0, [r3] + str r0, [r2, #HWi_WSYS04_WRAMOFFSET] + //OPT(bonding option) + ldr r3, =REG_OP_ADDR + ldrb r0, [r3] + //A9ROM(ARM9 ROM) + ldr r3, =REG_A9ROM_ADDR + ldrb r1, [r3] + and r12,r1, #(REG_SCFG_A9ROM_RSEL_MASK | REG_SCFG_A9ROM_SEC_MASK) + orr r0, r0, r12, LSL #(HWi_WSYS08_ROM_ARM9RSEL_SHIFT - REG_SCFG_A9ROM_RSEL_SHIFT) + //A7ROM(ARM7 ROM) + ldr r3, =REG_A7ROM_ADDR + ldrb r1, [r3] + and r12,r1, #(REG_SCFG_A7ROM_RSEL_MASK | REG_SCFG_A7ROM_FUSE_MASK) + orr r0, r0, r12, LSL #(HWi_WSYS08_ROM_ARM7RSEL_SHIFT - REG_SCFG_A7ROM_RSEL_SHIFT) + //DS-WL(DS wireless) + ldr r3, =REG_A7ROM_ADDR + ldrb r1, [r3] + and r12,r1, #REG_SCFG_WL_OFFB_MASK + orr r0, r0, r12, LSL #(HWi_WSYS08_WL_OFFB_SHIFT - REG_SCFG_WL_OFFB_SHIFT) + strb r0, [r2, #HWi_WSYS08_WRAMOFFSET] + //OPT(JTAG info) + ldr r3, =REG_JTAG_ADDR + ldrh r0, [r3] + and r12,r0, #REG_SCFG_JTAG_DSPJE_MASK + orr r0, r0, r12, LSR #(REG_SCFG_JTAG_DSPJE_SHIFT - HWi_WSYS09_JTAG_DSPJE_SHIFT) + //CLK(only wram clock) + ldr r3, =REG_CLK_ADDR + ldrh r1, [r3] + and r12,r1, #(REG_SCFG_CLK_AESHCLK_MASK | REG_SCFG_CLK_SD2HCLK_MASK | REG_SCFG_CLK_SD1HCLK_MASK) + orr r0, r0, r12, LSL #(HWi_WSYS09_CLK_SD1HCLK_SHIFT - REG_SCFG_CLK_SD1HCLK_SHIFT) + and r12,r1, #(REG_SCFG_CLK_SNDMCLK_MASK | REG_SCFG_CLK_WRAMHCLK_MASK) + orr r0, r0, r12, LSR #(REG_SCFG_CLK_WRAMHCLK_SHIFT - HWi_WSYS09_CLK_WRAMHCLK_SHIFT) + strb r0, [r2, #HWi_WSYS09_WRAMOFFSET] +@9: +//################ + + //---- copy scfg setting + ldr r2, =HW_PRV_WRAM_SYSRV + ldr r3, =HW_SYS_CONF_BUF + ldr r0, [r2, #HWi_WSYS04_WRAMOFFSET] + str r0, [r3, #HWi_WSYS04_OFFSET] + ldrh r0, [r2, #HWi_WSYS08_WRAMOFFSET] + strh r0, [r3, #HWi_WSYS08_OFFSET] + + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_DetectMainMemorySize + + Description: detect main memory size. + result is written into (u32*)HW_MMEMCHECKER_SUB. + value is [OS_CONSOLE_SIZE_4MB|OS_CONSOLE_SIZE_8MB| + OS_CONSOLE_SIZE_16MB|OS_CONSOLE_SIZE_32MB] + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +#define OSi_IMAGE_DIFFERENCE 0x400000 +#define OSi_IMAGE_DIFFERENCE2 0xb000000 +#define OSi_DETECT_NITRO_MASK (REG_SND_SMX_CNT_E_MASK | REG_SND_SMX_CNT_FSEL_MASK) +#define OSi_DETECT_NITRO_VAL (REG_SND_SMX_CNT_E_MASK) + +static asm void INITi_DetectMainMemorySize( void ) +{ + stmfd sp!, {r4,lr} + + //---- detect memory size +#if 0 + mov r4, #OS_CONSOLE_SIZE_4MB + mov r1, #0 + + ldr r2, =HW_MMEMCHECKER_SUB + sub r3, r2, #OSi_IMAGE_DIFFERENCE +@1: + strh r1, [r2] + ldrh r12, [r3] + cmp r1, r12 + bne @2 + + add r1, r1, #1 + cmp r1, #2 // check 2 loop + bne @1 + + //---- 4MB + b @4 + + //---- 8MB or 16MB or 32MB +@2: + // check if running on twl/nitro + bl INITi_IsRunOnTwl + movne r4, #OS_CONSOLE_SIZE_8MB + bne @4 +#else + ldr r2, =HW_MMEMCHECKER_SUB +#endif + //---- 16MB or 32MB + mov r1, #0 + add r3, r2, #OSi_IMAGE_DIFFERENCE2 +@3: + strh r1, [r2] + ldrh r12, [r3] + cmp r1, r12 + + movne r4, #OS_CONSOLE_SIZE_32MB + bne @4 + + add r1, r1, #1 + cmp r1, #2 // check 2 loop + bne @3 + mov r4, #OS_CONSOLE_SIZE_16MB +@4: + //---- check SMX_CNT + ldr r3, =REG_SMX_CNT_ADDR + ldrh r1, [r3] + and r1, r1, #OSi_DETECT_NITRO_MASK + cmp r1, #OSi_DETECT_NITRO_VAL + orreq r4, r4, #OS_CHIPTYPE_SMX_MASK + + strb r4, [r2] + + ldmfd sp!, {r4,lr} + bx lr +} + +/*---------------------------------------------------------------------------* + Name: TwlSpStartUp + + Description: hook for user start up + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL void TwlSpStartUp(void) +{ +} + +#include diff --git a/build/libraries/init/ARM9/Makefile b/build/libraries/init/ARM9/Makefile new file mode 100644 index 00000000..7b3753e9 --- /dev/null +++ b/build/libraries/init/ARM9/Makefile @@ -0,0 +1,50 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - 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. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +# Avoid to use pre-compile-header of "nitro.h" +TWL_NO_STD_PCHDR = True + +# Avoid to build THUMB version object +override TWL_CODEGEN = ARM + +SRCS = crt0_firm.c + +TARGET_OBJ = crt0_firm.o + +MACRO_FLAGS += -DSDK_NOINIT + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/init/ARM9/crt0_firm.c b/build/libraries/init/ARM9/crt0_firm.c new file mode 100644 index 00000000..ac6bbda4 --- /dev/null +++ b/build/libraries/init/ARM9/crt0_firm.c @@ -0,0 +1,946 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - init + File: crt0_firm.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include + +#include + +void _start(void); +void _start_AutoloadDoneCallback(void *argv[]); + +#define SDK_NITROCODE_LE 0x2106c0de +#define SDK_NITROCODE_BE 0xdec00621 + +#define SDK_TWLCODE_LE 0x6314c0de +#define SDK_TWLCODE_BE 0xdec01463 + +/* O֐Qƒ` */ +extern void OS_IrqHandler(void); +extern void _fp_init(void); +extern void __call_static_initializers(void); + +/* ֐vg^Cv` */ +static void INITi_CpuClear32(register u32 data, register void *destp, register u32 size); +static void INITi_CpuClearFast(register u32 data, register void* destp, register u32 size); +static void INITi_InitCoprocessor(void); +static void INITi_InitRegion(void); +static void INITi_DoAutoload(void); +static void INITi_ShelterLtdBinary(void); +#ifndef SDK_NOINIT +static void INITi_ShelterStaticInitializer(u32* ptr); +static void INITi_CallStaticInitializers(void); +#endif + +/* JXbNvgɂ`V{Q */ +extern void SDK_AUTOLOAD_LIST(void); +extern void SDK_AUTOLOAD_LIST_END(void); +extern void SDK_AUTOLOAD_START(void); +extern void SDK_STATIC_BSS_START(void); +extern void SDK_STATIC_BSS_END(void); + +//#include +#define SDK_VERSION_ID ((u32)SDK_VERSION_MAJOR<<24|\ + (u32)SDK_VERSION_MINOR<<16|\ + (u32)SDK_VERSION_RELSTEP) + +void* const _start_ModuleParams[] = +{ + (void*)SDK_AUTOLOAD_LIST, + (void*)SDK_AUTOLOAD_LIST_END, + (void*)SDK_AUTOLOAD_START, + (void*)SDK_STATIC_BSS_START, + (void*)SDK_STATIC_BSS_END, + (void*)0, // CompressedStaticEnd. This fixed number will be updated by compstatic tool. + (void*)SDK_VERSION_ID, // SDK version info /* [TODO] rhʂ */ + (void*)SDK_NITROCODE_BE, + (void*)SDK_NITROCODE_LE, +}; + +extern void SDK_LTDAUTOLOAD_LIST(void); +extern void SDK_LTDAUTOLOAD_LIST_END(void); +extern void SDK_LTDAUTOLOAD_START(void); + +void* const _start_LtdModuleParams[] = +{ + (void*)SDK_LTDAUTOLOAD_LIST, + (void*)SDK_LTDAUTOLOAD_LIST_END, + (void*)SDK_LTDAUTOLOAD_START, + (void*)0, // CompressedLtdautoloadEnd. This fixed number will be updated by compstatic tool. + (void*)SDK_TWLCODE_BE, + (void*)SDK_TWLCODE_LE, +}; + +/*---------------------------------------------------------------------------* + Name: _start + Description: NxN^B + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +#define INITi_HW_DTCM SDK_AUTOLOAD_DTCM_START + +SDK_WEAK_SYMBOL asm void _start( void ) +{ + //---- set IME = 0 + // ( use that LSB of HW_REG_BASE equal to 0 ) + mov r12, #HW_REG_BASE + str r12, [r12, #REG_IME_OFFSET] + + //---- initialize stack pointer + // SVC mode + mov r0, #HW_PSR_SVC_MODE + msr cpsr_c, r0 + ldr r0, =INITi_HW_DTCM + add r0, r0, #0x3fc0 + mov sp, r0 + + // IRQ mode + mov r0, #HW_PSR_IRQ_MODE + msr cpsr_c, r0 + ldr r0, =INITi_HW_DTCM + add r0, r0, #0x3fc0 + sub r0, r0, #HW_SVC_STACK_SIZE + sub sp, r0, #4 // 4byte for stack check code + tst sp, #4 + subeq sp, sp, #4 // for 8byte-alignment + + // System mode + ldr r1, =SDK_IRQ_STACKSIZE + sub r1, r0, r1 + mov r0, #HW_PSR_SYS_MODE + msr cpsr_csfx, r0 + sub sp, r1, #4 // 4byte for stack check code + tst sp, #4 + subeq sp, sp, #4 // for 8byte-alignment + + //---- read reset flag from pmic +#ifdef SDK_TS +#ifdef FIRM_DISABLE_CR_AT_WARMBOOT +@0: bl PXIi_RecvIDByIntf + cmp r0, #FIRM_PXI_ID_COLDBOOT + cmpne r0, #FIRM_PXI_ID_WARMBOOT + bne @0 + + //---- initialize Main Memory + cmp r0, #FIRM_PXI_ID_COLDBOOT + moveq r0, #TRUE + movne r0, #FALSE + bl MIi_InitMainMemCR + +#else // !FIRM_DISABLE_CR_AT_WARMBOOT + //---- initialize Main Memory + bl MIi_InitMainMemCR + +#endif // !FIRM_DISABLE_CR_AT_WARMBOOT +#endif // SDK_TS + + //---- notify main memory mode into burst mode + mov r0, #FIRM_PXI_ID_INIT_MMEM + bl PXIi_SendIDByIntf + + //---- wait to clear HW_MAIN_MEM_SHARED + mov r0, #FIRM_PXI_ID_INIT_MMEM + bl PXIi_WaitIDByIntf + + /* VXeRvZbT */ + bl INITi_InitCoprocessor + + /* [Wݒ */ + bl INITi_InitRegion + + //---- clear memory + // DTCM (16KB) + mov r0, #0 + ldr r1, =INITi_HW_DTCM + mov r2, #HW_DTCM_SIZE + bl INITi_CpuClear32 + + //---- load autoload block and initialize bss +// bl INITi_DoAutoload +#ifndef SDK_FINALROM // for IS-TWL-DEBUGGER + bl _start_AutoloadDoneCallback +#endif + + //---- fill static static bss with 0 + mov r0, #0 + ldr r3, =_start_ModuleParams + ldr r1, [r3, #12] // SDK_STATIC_BSS_START + ldr r2, [r3, #16] // SDK_STATIC_BSS_END + sub r2, r2, r1 + bl INITi_CpuClearFast + + //---- flush static bss region + // (r0 == #0, r3 == _start_ModuleParams::BSS_segment_start) + bic r1, r3, #HW_CACHE_LINE_SIZE - 1 +@cacheflush: + mcr p15, 0, r0, c7, c10, 4 // wait writebuffer empty + mcr p15, 0, r1, c7, c5, 1 // ICache + mcr p15, 0, r1, c7, c14, 1 // DCache + add r1, r1, #HW_CACHE_LINE_SIZE + cmp r1, r2 + blt @cacheflush + + // print buffer (used for ARM7's printing) + ldr r1, =HW_COMPONENT_PARAM + str r0, [r1, #0] + + //---- set interrupt vector + ldr r1, =INITi_HW_DTCM + add r1, r1, #0x3fc0 + add r1, r1, #HW_DTCM_SYSRV_OFS_INTR_VECTOR + ldr r0, =OS_IrqHandler + str r0, [r1, #0] + +#ifndef SDK_NOINIT + //---- for C++ + bl _fp_init + bl TwlStartUp + bl __call_static_initializers +// bl INITi_CallStaticInitializers +#endif + //---- start (to 16bit code) + ldr r1, =TwlMain + ldr lr, =HW_RESET_VECTOR + bx r1 +} + +/*---------------------------------------------------------------------------* + Name: INITi_CpuClearFast + Description: 32 Byte PʂŃobt@̃NAsB + Arguments: r0 - NAlB + r1 - NAւ̃|C^B + r2 - AăNAobt@B + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_CpuClearFast(register u32 data, register void* destp, register u32 size) +{ + stmfd sp!, {r4-r9} + + add r9, r1, r2 // r9: destEndp = destp + size + mov r12, r2, lsr #5 // r12: destBlockEndp = destp + size/32*32 + add r12, r1, r12, lsl #5 + + mov r2, r0 + mov r3, r2 + mov r4, r2 + mov r5, r2 + mov r6, r2 + mov r7, r2 + mov r8, r2 + +@40: + cmp r1, r12 // while (destp < destBlockEndp) + stmltia r1!, {r0, r2-r8} // *((vu32 *)(destp++)) = data + blt @40 +@41: + cmp r1, r9 // while (destp < destEndp) + stmltia r1!, {r0} // *((vu32 *)(destp++)) = data + blt @41 + + ldmfd sp!, {r4-r9} + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_CpuClear32 + Description: 32 bit PʂŃobt@̃NAsB + Arguments: r0 - NAlB + r1 - NAւ̃|C^B + r2 - AăNAobt@B + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_CpuClear32(register u32 data, register void* destp, register u32 size) +{ + add r12, r1, r2 +@001: cmp r1, r12 + strlt r0, [r1], #4 + blt @001 + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_InitCoprocessor + Description: VXeRvZbTB + ɁAI-TCM y D-TCM gp”\ȏԂɂB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_InitCoprocessor(void) +{ + /* RvZbT̏Ԏ擾 */ + mrc p15, 0, r0, c1, c0, 0 + + tst r0, #HW_C1_PROTECT_UNIT_ENABLE + beq @010 + tst r0, #HW_C1_DCACHE_ENABLE + beq @003 + + /* D-Cache eɃCgobN */ + mov r1, #0 +@001: mov r2, #0 +@002: orr r3, r1, r2 + mcr p15, 0, r3, c7, c10, 2 + add r2, r2, #HW_CACHE_LINE_SIZE + cmp r2, #HW_DCACHE_SIZE / 4 + blt @002 + adds r1, r1, #1 << HW_C7_CACHE_SET_NO_SHIFT + bne @001 + +@003: /* Cgobt@ɂȂ̂҂ */ + mov r1, #0 + mcr p15, 0, r1, c7, c10, 4 + +@010: /* RvZbT̏Ԃ */ + ldr r1, = HW_C1_ITCM_LOAD_MODE \ + | HW_C1_DTCM_LOAD_MODE \ + | HW_C1_ITCM_ENABLE \ + | HW_C1_DTCM_ENABLE \ + | HW_C1_LD_INTERWORK_DISABLE \ + | HW_C1_ICACHE_ENABLE \ + | HW_C1_DCACHE_ENABLE \ + | HW_C1_PROTECT_UNIT_ENABLE + bic r0, r0, r1 + ldr r1, = HW_C1_SB1_BITSET \ + | HW_C1_EXCEPT_VEC_UPPER + orr r0, r0, r1 + mcr p15, 0, r0, c1, c0, 0 + + /* I-TCM ̃TCYݒ */ + mov r1, #HW_C9_TCMR_32MB + mcr p15, 0, r1, c9, c1, 1 + /* D-TCM ̃TCYyї̈x[XAhXݒ */ + ldr r1, =SDK_AUTOLOAD_DTCM_START + orr r1, r1, #HW_C9_TCMR_16KB + mcr p15, 0, r1, c9, c1, 0 + + /* I-TCM / D-TCM gpݒ */ + mov r1, #HW_C1_ITCM_ENABLE | HW_C1_DTCM_ENABLE + orr r0, r0, r1 + mcr p15, 0, r0, c1, c0, 0 + + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_InitRegion + Description: [WݒsB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +/* When hardware is TWL +; Region G: BACK_GROUND: Base = 0x0, Size = 4GB, I:NC NB / D:NC NB, I:NA / D:NA +; Region 0: IO_VRAM: Base = 0x04000000, Size = 64MB, I:NC NB / D:NC NB, I:RW / D:RW +; Region 1: MAINMEM_WRAM: Base = 0x02000000, Size = 32MB, I:Cach Buf / D:Cach Buf, I:RW / D:RW +; Region 2: ARM7_RESERVE: Base = 0x02f80000, Size = 512KB, I:NC NB / D:NC NB, I:NA / D:NA +; Region 3: EX_MAINMEM: Base = 0x0d000000, Size = 16MB, I:Cach Buf / D:Cach Buf, I:RW / D:RW +; Region 4: DTCM: Base = 0x02fe0000, Size = 16KB, I:NC NB / D:NC NB, I:NA / D:RW +; Region 5: ITCM: Base = 0x01000000, Size = 16MB, I:NC NB / D:NC NB, I:RW / D:RW +; Region 6: BIOS: Base = 0xffff0000, Size = 32KB, I:Cach NB / D:Cach NB, I:RO / D:RO +; Region 7: SHARED_WORK: Base = 0x02ffc000, Size = 16KB, I:NC NB / D:NC NB, I:NA / D:RW +*/ +/* When hardware is NITRO +; Region G: BACK_GROUND: Base = 0x0, Size = 4GB, I:NC NB / D:NC NB, I:NA / D:NA +; Region 0: IO_VRAM: Base = 0x04000000, Size = 64MB, I:NC NB / D:NC NB, I:RW / D:RW +; Region 1: MAIN_MEM: Base = 0x02000000, Size = 8MB*, I:Cach Buf / D:Cach Buf, I:RW / D:RW +; (* When hardware is not debugger, size will be reduced to 4MB in OS_InitArena() ) +;// Region 2: ARM7_RESERVE: Base = 0x027e0000, Size = 128KB, I:NC NB / D:NC NB, I:NA / D:NA +;// (* When hardware is not debugger, base will be moved to 0x023e0000 in OS_InitArena() ) +; Region 2: SHARED_WORK: Base = 0x027ff000, Size = 4KB, I:NC NB / D:NC NB, I:NA / D:RW +; Region 3: CARTRIDGE: Base = 0x08000000, Size = 128MB, I:NC NB / D:NC NB, I:NA / D:RW +; Region 4: DTCM: Base = 0x02fe0000, Size = 16KB, I:NC NB / D:NC NB, I:NA / D:RW +; Region 5: ITCM: Base = 0x01000000, Size = 16MB, I:NC NB / D:NC NB, I:RW / D:RW +; Region 6: BIOS: Base = 0xffff0000, Size = 32KB, I:Cach NB / D:Cach NB, I:RO / D:RO +; Region 7: SHARED_WORK: Base = 0x02fff000, Size = 4KB, I:NC NB / D:NC NB, I:NA / D:RW +*/ + +static asm void +INITi_InitRegion(void) +{ + mov r12, lr + +#define SET_PROTECTION_A(id, adr, siz) ldr r0, =(adr|HW_C6_PR_##siz|HW_C6_PR_ENABLE) +#define SET_PROTECTION_B(id, adr, siz) mcr p15, 0, r0, c6, id, 0 +#define REGION_BIT(a, b, c, d, e, f, g, h) (((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7)) +#define REGION_ACC(a, b, c, d, e, f, g, h) (((a) << 0) | ((b) << 4) | ((c) << 8) | ((d) << 12) | ((e) << 16) | ((f) << 20) | ((g) << 24) | ((h) << 28)) +#define NA 0 +#define RW 1 +#define RO 5 + + /* (0) I/O WX^y VRAM */ + SET_PROTECTION_A(c0, HW_IOREG, 64MB) + SET_PROTECTION_B(c0, HW_IOREG, 64MB) + + /* (4) D-TCM */ + ldr r0, =SDK_AUTOLOAD_DTCM_START + orr r0, r0, #HW_C6_PR_16KB | HW_C6_PR_ENABLE + SET_PROTECTION_B(c4, SDK_AUTOLOAD_DTCM_START, 16KB) + + /* (5) I-TCM */ + SET_PROTECTION_A(c5, HW_ITCM_IMAGE, 16MB) + SET_PROTECTION_B(c5, HW_ITCM_IMAGE, 16MB) + + /* (6) VXeR[ ROM */ + SET_PROTECTION_A(c6, HW_BIOS, 32KB) + SET_PROTECTION_B(c6, HW_BIOS, 32KB) + + /* TWL n[hEFAœ삵Ă邩ǂ𒲍 */ +#if 0 + bl INITi_IsRunOnTwl + bne @002 +#endif + +@001: /* n[hEFA TWL ̏ꍇ */ + /* (1) Cy WRAM */ + SET_PROTECTION_A(c1, HW_TWL_MAIN_MEM_MAIN, 32MB) + SET_PROTECTION_B(c1, HW_TWL_MAIN_MEM_MAIN, 32MB) + + /* (2) ARM7 pC */ + SET_PROTECTION_A(c2, HW_TWL_MAIN_MEM_SUB, 512KB) + SET_PROTECTION_B(c2, HW_TWL_MAIN_MEM_SUB, 512KB) + + /* (3) gC */ + SET_PROTECTION_A(c3, HW_TWL_MAIN_MEM_EX, 16MB) + SET_PROTECTION_B(c3, HW_TWL_MAIN_MEM_EX, 16MB) + + /* (7) ARM9/ARM7 LC */ + SET_PROTECTION_A(c7, HW_TWL_MAIN_MEM_SHARED, 16KB) + SET_PROTECTION_B(c7, HW_TWL_MAIN_MEM_SHARED, 16KB) + + /* ߃LbV */ + mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 1, 0) + mcr p15, 0, r0, c2, c0, 1 + + /* f[^LbV */ +// mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 1, 0) + mov r0, #REGION_BIT(0, 1, 1, 1, 0, 0, 1, 0) + mcr p15, 0, r0, c2, c0, 0 + + /* Cgobt@ */ +// mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 0, 0) + mov r0, #REGION_BIT(0, 1, 1, 1, 0, 0, 0, 0) + mcr p15, 0, r0, c3, c0, 0 + + /* ߃ANZX */ + ldr r0, =REGION_ACC(RW, RW, NA, RW, NA, RW, RO, NA) + mcr p15, 0, r0, c5, c0, 3 + + /* f[^ANZX */ +// ldr r0, =REGION_ACC(RW, RW, NA, RW, RW, RW, RO, RW) + ldr r0, =REGION_ACC(RW, RW, RW, RW, RW, RW, RO, RW) + mcr p15, 0, r0, c5, c0, 2 +#if 0 + b @003 + +@002: /* n[hEFA NITRO ̏ꍇ */ + /* (1) C */ + //SET_PROTECTION_A(c1, HW_MAIN_MEM_MAIN, 8MB) + //SET_PROTECTION_B(c1, HW_MAIN_MEM_MAIN, 8MB) + SET_PROTECTION_A(c1, HW_MAIN_MEM_MAIN, 32MB) + SET_PROTECTION_B(c1, HW_MAIN_MEM_MAIN, 32MB) + /* Size will be arranged in OS_InitArena(). */ + + /* (2) ARM7 pC */ + SET_PROTECTION_A(c2, (HW_MAIN_MEM_EX_END - HW_MAIN_MEM_SHARED_SIZE - HW_MAIN_MEM_SUB_SIZE), 128KB) + SET_PROTECTION_B(c2, (HW_MAIN_MEM_EX_END - HW_MAIN_MEM_SHARED_SIZE - HW_MAIN_MEM_SUB_SIZE), 128KB) + /* Base address will be moved in OS_InitArena(). */ + + /* (3) J[gbW */ + //SET_PROTECTION_A(c3, HW_CTRDG_ROM, 128MB) + //SET_PROTECTION_B(c3, HW_CTRDG_ROM, 128MB) + SET_PROTECTION_A(c3, HW_CTRDG_ROM, 32MB) + SET_PROTECTION_B(c3, HW_CTRDG_ROM, 32MB) + + /* (7) ARM9/ARM7 LC */ + SET_PROTECTION_A(c7, HW_MAIN_MEM_SHARED, 4KB) + SET_PROTECTION_B(c7, HW_MAIN_MEM_SHARED, 4KB) + + /* ߃LbV */ + mov r0, #REGION_BIT(0, 1, 0, 0, 0, 0, 1, 0) + mcr p15, 0, r0, c2, c0, 1 + + /* f[^LbV */ + //mov r0, #REGION_BIT(0, 1, 0, 0, 0, 0, 1, 0) + mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 1, 0) + mcr p15, 0, r0, c2, c0, 0 + + /* Cgobt@ */ + //mov r0, #REGION_BIT(0, 1, 0, 0, 0, 0, 0, 0) + mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 0, 0) + mcr p15, 0, r0, c3, c0, 0 + + /* ߃ANZX */ + //ldr r0, =REGION_ACC(RW, RW, NA, NA, NA, RW, RO, NA) + ldr r0, =REGION_ACC(RW, RW, NA, RW, NA, RW, RO, NA) + mcr p15, 0, r0, c5, c0, 3 + + /* f[^ANZX */ + ldr r0, =REGION_ACC(RW, RW, NA, RW, RW, RW, RO, RW) + mcr p15, 0, r0, c5, c0, 2 +#endif +@003: /* veNVjbgyуLbVgpݒ */ + mrc p15, 0, r0, c1, c0, 0 + ldr r1, = HW_C1_ICACHE_ENABLE \ + | HW_C1_DCACHE_ENABLE \ + | HW_C1_CACHE_ROUND_ROBIN \ + | HW_C1_PROTECT_UNIT_ENABLE + orr r0, r0, r1 + mcr p15, 0, r0, c1, c0, 0 + + /* LbV̓ej */ + mov r1, #0 + mcr p15, 0, r1, c7, c6, 0 + mcr p15, 0, r1, c7, c5, 0 + + bx r12 +} + +/*---------------------------------------------------------------------------* + Name: INITi_DoAutoload + Description: NɉāAeI[g[hubŇŒf[^̓WJ + yѕϐ 0 NAsB4M bytes z PSRAM + ɔzuI[g[hubN̓WJ́An[hEFA TWL + ꍇɂsBI[g[hf[^ƃI[g[h悪ꕔ + dȂꍇ̂ŁAWJsB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +/* + * < iKI[g[h > + * 0x02000000 Static ZOgyшiڃ[hoCi(KvɉČ㔼k)zuĂB + * kĂꍇ́A܂ 0x02000000 Ɍ㏑‚‰𓀂B + * NITRO ƋL”\ ITCM ɔzuׂoCif[^ 0x01ff8000 Ƀ[hB + * NITRO ƋL”\ DTCM ɔzuׂoCif[^ 0x02fe0000 Ƀ[hB + * 0x02400000 ɓiڃ[hoCi(KvɉđSĈk)zuĂB + * 0x04000 oCg̓J[h ROM ēǂݏos‚Ȃ̂ŁA0x02f80000 - 0x02f84000 ɑޔB + * kĂꍇ́A܂ 0x02400000 Ɍ㏑‚‰𓀂B + * TWL ł삵Ȃ WRAM ɔzuׂoCif[^ꂼwAhXɃ[hB + * TWL ł삵ȂCɔzuׂoCif[^ORs[邱ƂŃ[hB + * ́ANITRO ƋL”\ȃCɔzuf[^ 0x02400000 zȂ͂ł邽߁A + * zuׂAhX 0x02400000 菬AhXɂȂ͂łׁB + * ܂AI[g[h񃊃Xg̎̂Cւ̃I[g[hubN .bss ZNṼNẢߒ + * j󂳂”\邪AÃI[g[h̍Ō̒iKȂ̂ŁAj󂳂ĂȂB + */ +static asm void +INITi_DoAutoload(void) +{ +@000: + stmdb sp!, {lr} + /* NITRO pubN̉ */ + ldr r1, =_start_ModuleParams + ldr r0, [r1, #20] // r0 = bottom of compressed data + bl MIi_UncompressBackward + +@010: + /* NITRO pubNI[g[h */ + ldr r1, =_start_ModuleParams + ldr r12, [r1] // r12 = SDK_AUTOLOAD_LIST + ldr r0, [r1, #4] // r0 = SDK_AUTOLOAD_LIST_END + ldr r1, [r1, #8] // r1 = SDK_AUTOLOAD_START +@011: cmp r12, r0 + bge @020 + /* ŒZNV[h */ + stmdb sp!, {r0} + ldr r2, [r12], #4 // r2 = start address of destination range + stmdb sp!, {r2} + ldr r3, [r12], #4 // r3 = size of fixed section + add r3, r3, r2 // r3 = end address of destination range of fixed section +@012: cmp r2, r3 + ldrlt r0, [r1], #4 + strlt r0, [r2], #4 + blt @012 + /* static initializer e[uǂݏo */ + ldr r0, [r12], #4 // r0 = address of the table managing pointers of static initializers +#ifndef SDK_NOINIT + stmdb sp!, {r0-r3, r12} + bl INITi_ShelterStaticInitializer + ldmia sp!, {r0-r3, r12} +#endif + /* .bss ZNV 0 NA */ + mov r0, #0 // r0 = number to fill .bss section + ldr r3, [r12], #4 // r3 = size of .bss section + add r3, r3, r2 // r3 = end address of destination range of .bss section +@013: cmp r2, r3 + strlt r0, [r2], #4 + blt @013 + /* LbV𒲐 */ + ldmia sp!, {r2} // r2 = start address of destination range + mov r0, #HW_ITCM_IMAGE + cmp r2, r0 + movge r0, #HW_ITCM_END + cmpge r0, r2 + bgt @015 // If I-TCM autoload block, skip cache control logic. + ldr r0, =SDK_AUTOLOAD_DTCM_START + cmp r2, r0 + addge r0, r0, #HW_DTCM_SIZE + cmpge r0, r2 + bgt @015 // If D-TCM autoload block, skip cache control logic. + bic r2, r2, #HW_CACHE_LINE_SIZE - 1 // RoundDown32 +@014: cmp r2, r3 + bge @015 + mcr p15, 0, r2, c7, c14, 1 // Store and Invalidate D-Cache + mcr p15, 0, r2, c7, c5, 1 // Invalidate I-Cache + add r2, r2, #HW_CACHE_LINE_SIZE + b @014 +@015: ldmia sp!, {r0} + b @011 + +@020: + /* TWL n[hEFAœ삵Ă邩ǂ𒲍 */ +#if 0 + bl INITi_IsRunOnTwl + bne @030 +#endif + + /* TWL pubN݂̑mF */ + ldr r1, =HW_TWL_ROM_HEADER_BUF + 0x1cc /* ARM9 pg풓W[ ROM TCY */ + ldr r0, [r1] + cmp r0, #0 + beq @030 + + /* ēǂݏos•ޔ */ + bl INITi_ShelterLtdBinary + + /* TWL pubN̉ */ + ldr r1, =_start_LtdModuleParams + ldr r0, [r1, #12] + bl MIi_UncompressBackward + + /* TWL pubNI[g[h */ + ldr r1, =_start_LtdModuleParams + ldr r12, [r1] // r12 = SDK_LTDAUTOLOAD_LIST + ldr r0, [r1, #4] // r0 = SDK_LTDAUTOLOAD_LIST_END + ldr r1, [r1, #8] // r1 = SDK_LTDAUTOLOAD_START +@021: cmp r12, r0 + bge @030 + /* ŒZNV[h */ + stmdb sp!, {r0} + ldr r2, [r12], #4 // r2 = start address of destination range + stmdb sp!, {r2} + ldr r3, [r12], #4 // r3 = size of fixed section + add r3, r3, r2 // r3 = end address of destination range of fixed section +@022: cmp r2, r3 + ldrlt r0, [r1], #4 + strlt r0, [r2], #4 + blt @022 + /* static initializer e[uǂݏo */ + ldr r0, [r12], #4 // r0 = address of the table managing pointers of static initializers +#ifndef SDK_NOINIT + stmdb sp!, {r0-r3, r12} + bl INITi_ShelterStaticInitializer + ldmia sp!, {r0-r3, r12} +#endif + /* .bss ZNV 0 NA */ + mov r0, #0 // r0 = number to fill .bss section + ldr r3, [r12], #4 // r3 = size of .bss section + add r3, r3, r2 // r3 = end address of destination range of .bss section +@023: cmp r2, r3 + strlt r0, [r2], #4 + blt @023 + /* LbV𒲐 */ + ldmia sp!, {r2} // r2 = start address of destination range + mov r0, #HW_ITCM_IMAGE + cmp r2, r0 + movge r0, #HW_ITCM_END + cmpge r0, r2 + bgt @025 // If I-TCM autoload block, skip cache control logic. + ldr r0, =SDK_AUTOLOAD_DTCM_START + cmp r2, r0 + addge r0, r0, #HW_DTCM_SIZE + cmpge r0, r2 + bgt @025 // If D-TCM autoload block, skip cache control logic. + bic r2, r2, #HW_CACHE_LINE_SIZE - 1 // RoundDown32 +@024: cmp r2, r3 + bge @025 + mcr p15, 0, r2, c7, c14, 1 // Store and Invalidate D-Cache + mcr p15, 0, r2, c7, c5, 1 // Invalidate I-Cache + add r2, r2, #HW_CACHE_LINE_SIZE + b @024 +@025: ldmia sp!, {r0} + b @021 + +@030: /* Cgobt@ɂȂ̂҂ */ + mov r0, #0 + mcr p15, 0, r0, c7, c10, 4 + + /* I[g[hR[obN֐Ăяo */ + ldr r0, =_start_ModuleParams + ldr r1, =_start_LtdModuleParams + ldmia sp!, {lr} + b _start_AutoloadDoneCallback +} + +/*---------------------------------------------------------------------------* + Name: INITi_ShelterLtdBinary + Description: TWL p̃I[g[hoCif[^̓AJ[h ROM + ēǂݏołȂ̈̃f[^ޔGAɑޔB + ēǂݏołȂ̈̃f[^ ARM7 p ARM9 p̊g풓 + W[̂Q‚ɕÔ\̂ŁA璷ł͂邪 + ̐擪 0x4000 ꂼޔB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_ShelterLtdBinary(void) +{ + /* ARM7 pCԕی샊[WUANZX”\ɕύX */ + mrc p15, 0, r0, c5, c0, 3 + mrc p15, 0, r1, c5, c0, 2 + stmdb sp!, {r0, r1} + bic r0, r0, #(0xf << 8) + orr r0, r0, #(0x1 << 8) + bic r1, r1, #(0xf << 8) + orr r1, r1, #(0x1 << 8) + mcr p15, 0, r0, c5, c0, 3 + mcr p15, 0, r1, c5, c0, 2 + + /* ޔEAhX𒲍 */ + ldr r1, =HW_TWL_ROM_HEADER_BUF + 0x1c8 /* ARM9 pg풓W[ RAM AhX */ + ldr r1, [r1] + ldr r3, =HW_TWL_ROM_HEADER_BUF + 0x038 /* ARM7 p풓W[ RAM AhX */ + ldr r3, [r3] + sub r3, r3, #0x4000 /* ēǂݏos—̈TCY */ /* ARM7 pޔGA */ + sub r2, r3, #0x4000 /* ēǂݏos—̈TCY */ /* ARM9 pޔGA */ + + /* Rs[ */ +@loop: ldr r0, [r1], #4 + str r0, [r2], #4 + cmp r2, r3 + blt @loop + + /* ARM7 pCԕی샊[Wݒɖ߂ */ + ldmia sp!, {r0, r1} + mcr p15, 0, r0, c5, c0, 3 + mcr p15, 0, r1, c5, c0, 2 + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_ShelterStaticInitializer + Description: eI[g[hZOg static initializer ւ̃|C^ + e[u IRQ X^bN̍ŏ㕔 ( 4 oCg炵ʒu) + ɑޔB + Arguments: ptr - ZOg̃|C^e[uւ̃|C^B + e[u NULL ŏI[ĂKvB + Returns: ȂB + *---------------------------------------------------------------------------*/ +#ifndef SDK_NOINIT +static asm void +INITi_ShelterStaticInitializer(u32* ptr) +{ + /* mF */ + cmp r0, #0 + bxeq lr + + /* ޔꏊ擪AhXvZ */ + ldr r1, =SDK_AUTOLOAD_DTCM_START + add r1, r1, #HW_DTCM_SIZE + sub r1, r1, #HW_DTCM_SYSRV_SIZE + sub r1, r1, #HW_SVC_STACK_SIZE + ldr r2, =SDK_IRQ_STACKSIZE + sub r1, r1, r2 + add r1, r1, #4 + + /* ޔꏊ擪󂫏ꏊ𒲍 */ +@001: ldr r2, [r1] + cmp r2, #0 + addne r1, r1, #4 + bne @001 + + /* 󂫏ꏊɃe[uRs[ */ +@002: ldr r2, [r0], #4 + str r2, [r1], #4 + cmp r2, #0 + bne @002 + + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_CallStaticInitializers + Description: eI[g[hZOg static initializer ĂяoB + I[g[hɂ IRQ X^bN̍ŏ㕔 ( 4 oCg + 炵ʒu) ɑޔĂ֐|C^e[u‚ + ĂяoB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_CallStaticInitializers(void) +{ + stmdb sp!, {lr} + + /* e[uޔꏊ擪AhXvZ */ + ldr r1, =SDK_AUTOLOAD_DTCM_START + add r1, r1, #HW_DTCM_SIZE + sub r1, r1, #HW_DTCM_SYSRV_SIZE + sub r1, r1, #HW_SVC_STACK_SIZE + ldr r2, =SDK_IRQ_STACKSIZE + sub r1, r1, r2 + add r1, r1, #4 + + /* e[uɊǗĂ|C^‚ŒĂяo */ +@001: ldr r0, [r1] + cmp r0, #0 + beq @002 + stmdb sp!, {r1} + blx r0 + ldmia sp!, {r1} + /* UĂяo|C^̓[NA (IRQX^bNԎ؂肵Ă) */ + mov r0, #0 + str r0, [r1], #4 + b @001 + +@002: + ldmia sp!, {lr} + bx lr +} +#endif + +/*---------------------------------------------------------------------------* + Name: MIi_UncompressBackward + Description: Uncompress special archive for module compression. + Arguments: bottom = Bottom adrs of packed archive + 1 + bottom[-8..-6] = offset for top of compressed data + inp_top = bottom - bottom[-8..-6] + bottom[-5] = offset for bottom of compressed data + inp = bottom - bottom[-5] + bottom[-4..-1] = offset for bottom of original data + outp = bottom + bottom[-4..-1] + typedef struct + { + u32 bufferTop:24; + u32 compressBottom:8; + u32 originalBottom; + } CompFooter; + Returns: None. + *---------------------------------------------------------------------------*/ +asm void +MIi_UncompressBackward(register void* bottom) +{ +#define data r0 +#define inp_top r1 +#define outp r2 +#define inp r3 +#define outp_save r4 +#define flag r5 +#define count8 r6 +#define index r7 +#define len r12 + + cmp bottom, #0 + beq @exit + stmfd sp!, {r4-r7} + ldmdb bottom, {r1-r2} + add outp, bottom, outp + sub inp, bottom, inp_top, LSR #24 + bic inp_top, inp_top, #0xff000000 + sub inp_top, bottom, inp_top + mov outp_save, outp +@loop: + cmp inp, inp_top // exit if inp==inp_top + ble @end_loop + ldrb flag, [inp, #-1]! // r4 = compress_flag = *--inp + mov count8, #8 +@loop8: + subs count8, count8, #1 + blt @loop + tst flag, #0x80 + bne @blockcopy +@bytecopy: + ldrb data, [inp, #-1]! + strb data, [outp, #-1]! // Copy 1 byte + b @joinhere +@blockcopy: + ldrb len, [inp, #-1]! + ldrb index, [inp, #-1]! + orr index, index, len, LSL #8 + bic index, index, #0xf000 + add index, index, #0x0002 + add len, len, #0x0020 +@patterncopy: + ldrb data, [outp, index] + strb data, [outp, #-1]! + subs len, len, #0x0010 + bge @patterncopy + +@joinhere: + cmp inp, inp_top + mov flag, flag, LSL #1 + bgt @loop8 +@end_loop: + + // DC_FlushRange & IC_InvalidateRange + mov r0, #0 + bic inp, inp_top, #HW_CACHE_LINE_SIZE - 1 +@cacheflush: + mcr p15, 0, r0, c7, c10, 4 // wait writebuffer empty + mcr p15, 0, inp, c7, c5, 1 // ICache + mcr p15, 0, inp, c7, c14, 1 // DCache + add inp, inp, #HW_CACHE_LINE_SIZE + cmp inp, outp_save + blt @cacheflush + + ldmfd sp!, {r4-r7} +@exit bx lr +} + +/*---------------------------------------------------------------------------* + Name: _start_AutoloadDoneCallback + Description: I[g[hR[obNB + Arguments: argv - I[g[hp[^ێĂzB + argv[0] = SDK_AUTOLOAD_LIST + argv[1] = SDK_AUTOLOAD_LIST_END + argv[2] = SDK_AUTOLOAD_START + argv[3] = SDK_STATIC_BSS_START + argv[4] = SDK_STATIC_BSS_END + Returns: ȂB + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL asm void +_start_AutoloadDoneCallback(void* argv[]) +{ + bx lr +} + +/*---------------------------------------------------------------------------* + Name: TwlStartUp + + Description: hook for user start up + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL void TwlStartUp(void) +{ +} + +/*---------------------------------------------------------------------------* + Name: OSi_ReferSymbol + + Description: used by SDK_REFER_SYMBOL macro to avoid dead-strip. + + Arguments: symbol unused + + Returns: None. + *---------------------------------------------------------------------------*/ +void OSi_ReferSymbol(void *symbol) +{ +#pragma unused(symbol) +} + +#include diff --git a/build/libraries/init/Makefile b/build/libraries/init/Makefile new file mode 100644 index 00000000..18137ffb --- /dev/null +++ b/build/libraries/init/Makefile @@ -0,0 +1,32 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - 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. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 \ + ARM7 \ + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/mi/ARM9/Makefile b/build/libraries/mi/ARM9/Makefile new file mode 100644 index 00000000..eb187cf6 --- /dev/null +++ b/build/libraries/mi/ARM9/Makefile @@ -0,0 +1,46 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - mi +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = + + +#---------------------------------------------------------------------------- + +# build ARM & THUMB libraries +TWL_CODEGEN_ALL ?= TRUE + +SRCDIR = . ../common + +SRCS = \ + mi_init_mainMemory.c \ + +TARGET_LIB = libmi$(FIRM_LIBSUFFIX).a + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries/mi/ARM9/mi_init_mainMemory.c b/build/libraries/mi/ARM9/mi_init_mainMemory.c new file mode 100644 index 00000000..083ce2b8 --- /dev/null +++ b/build/libraries/mi/ARM9/mi_init_mainMemory.c @@ -0,0 +1,169 @@ +/*---------------------------------------------------------------------------* + 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 + +void MIi_InitMainMemCRCore( void ); + +/*---------------------------------------------------------------------------* + Name: MIi_IsMainMemoryInitialized + + Description: + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL MIi_IsMainMemoryInitialized( void ) +{ + return (BOOL)((reg_MI_EXMEMCNT & REG_MI_EXMEMCNT_CE2_MASK) >> REG_MI_EXMEMCNT_CE2_SHIFT); +} + +/*---------------------------------------------------------------------------* + Name: MIi_WaitMainMemoryInitialize + + Description: + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_WaitMainMemoryInitialize( void ) +{ + while( MIi_IsMainMemoryInitialized() == FALSE ) + { + } +} + + +/*---------------------------------------------------------------------------* + Name: MIi_InitMainMemCR + + Description: change mainmem into the burst mode + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +#include + +asm void MIi_InitMainMemCR( BOOL setCR ) +{ + mov r12, lr + + mov r2, r0 + + mov r0, #0x8000 // low period 0.97ms + bl OS_SpinWaitCpuCycles + + ldr r3, =REG_EXMEMCNT_ADDR + mov r1, #REG_MI_EXMEMCNT_CE2_MASK + ldrh r0, [r3] + tst r0, r1 + bxne r12 + + strh r1, [r3] + + mov r0, #0x8000 // high period 0.97ms + bl OS_SpinWaitCpuCycles + + cmp r2, #FALSE + beq @10 + + // C[hin[hZbgj + // 񓯊[hiCLKŒjŃR}hsĂv + ldr r3, =HW_WRAM_AREA - 2 + bl MIi_InitMainMemCRCore +#ifdef SDK_TS + ldr r3, =HW_MAIN_MEM + HW_MAIN_MEM_EX_SIZE - 2 + bl MIi_InitMainMemCRCore +#endif // SDK_TS + +@10: + ldr r3, =REG_EXMEMCNT_ADDR + ldr r1, = (1 << REG_MI_EXMEMCNT_IFM_SHIFT) | \ + (1 << REG_MI_EXMEMCNT_CE2_SHIFT) | \ + (MI_PROCESSOR_ARM7 << REG_MI_EXMEMCNT_EP_SHIFT) | \ + (MI_PROCESSOR_ARM7 << REG_MI_EXMEMCNT_MPA_SHIFT) | \ + (MI_PROCESSOR_ARM7 << REG_MI_EXMEMCNT_MPB_SHIFT) | \ + (MI_PROCESSOR_ARM7 << REG_MI_EXMEMCNT_CP_SHIFT) | \ + (MIi_PHI_CLOCK_LOW << REG_MI_EXMEMCNT_PHI_SHIFT) | \ + (MI_CTRDG_ROMCYCLE1_18 << REG_MI_EXMEMCNT_ROM1st_SHIFT) | \ + (MI_CTRDG_ROMCYCLE2_6 << REG_MI_EXMEMCNT_ROM2nd_SHIFT) | \ + (MI_CTRDG_RAMCYCLE_10 << REG_MI_EXMEMCNT_RAM_SHIFT) + strh r1, [r3] + + bx r12 +} + +asm void MIi_InitMainMemCRCore( void ) +{ +// stmfd sp!, { lr } + +#ifdef TWL_PLATFORM_BB + mov r2, lr + ldr r0, =MMEM_DCR0_BURST_MODE | MMEM_DCR0_BURST_CONTINUOUS \ + | MMEM_DCR0_PARTIAL_REFRESH_NONE | MMEM_DCR0_SB1 + ldr r1, =MMEM_DCR1_1ST_R4_W3 | MMEM_DCR1_BURST_WRITE | MMEM_DCR1_BURST_LINER \ + | MMEM_DCR1_CLOCK_TRIGGER_UP | MMEM_DCR1_SB1 + ldrh lr, [r3] + strh lr, [r3] + strh lr, [r3] + mov lr, r2 + ldr r2, =HW_MAIN_MEM | MMEM_DCR2_CLOCK_TRIGGER_UP \ + | MMEM_DCR2_BURST_MODE | MMEM_DCR2_BURST_CONTINUOUS \ + | MMEM_DCR2_1ST_R4_W3 | MMEM_DCR2_BURST_WRITE | MMEM_DCR2_BURST_LINER \ + | MMEM_DCR2_PARTIAL_REFRESH_NONE | MMEM_DCR2_SB1 + strh r0, [r3] + strh r1, [r3] + ldrh r3, [r2] +#else // SDK_TS + mov r2, lr + ldr r0, =MMEM_TCR0 + ldr r1, =MMEM_TCR1 + ldrh lr, [r3] + strh lr, [r3] + strh lr, [r3] + mov lr, r2 + ldr r2, =MMEM_TCR2 + strh r0, [r3] + strh r1, [r3] + strh r2, [r3] +#endif // SDK_TS + +// ldmfd sp!, { lr } + bx lr +} + +asm void MIi_GetMainMemCR( MIMmemCR* dest ) +{ +#ifdef SDK_TS + ldr r3, =HW_WRAM_AREA - 2 + ldr r1, =MMEM_TCR0_R + ldrh r2, [r3] + strh r2, [r3] + strh r2, [r3] + strh r1, [r3] + ldrh r1, [r3] + ldrh r2, [r3] + strh r2, [r0, #4] + strh r1, [r0, #2] + ldr r1, =MMEM_TCR0_R + strh r1, [r0, #0] +#endif // SDK_TS + + bx lr +} \ No newline at end of file diff --git a/build/libraries/mi/Makefile b/build/libraries/mi/Makefile new file mode 100644 index 00000000..a439cbf6 --- /dev/null +++ b/build/libraries/mi/Makefile @@ -0,0 +1,31 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - libraries - mi +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/os/ARM7/Makefile b/build/libraries/os/ARM7/Makefile new file mode 100644 index 00000000..06d51210 --- /dev/null +++ b/build/libraries/os/ARM7/Makefile @@ -0,0 +1,56 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries_sp - os +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +# build ARM & THUMB libraries +TWL_CODEGEN_ALL ?= TRUE + +# Codegen for sub processer +TWL_PROC = ARM7 + +SRCDIR = ../common . +INCDIR = ./include ../common/include \ + $(ROOT)/build/libraries/fatfs/ARM7.TWL/include \ + $(ROOT)/build/libraries/fatfs/ARM7.TWL/include/twl/fatfs/ARM7 \ + +SRCS = \ + os_init_firm.c \ + os_boot.c \ + +TARGET_LIB = libos_sp$(FIRM_LIBSUFFIX).a + + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/os/ARM9/Makefile b/build/libraries/os/ARM9/Makefile new file mode 100644 index 00000000..eeb8c37c --- /dev/null +++ b/build/libraries/os/ARM9/Makefile @@ -0,0 +1,47 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - os +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = + + +#---------------------------------------------------------------------------- + +# build ARM & THUMB libraries +TWL_CODEGEN_ALL ?= TRUE + +SRCDIR = ../common . + +SRCS = \ + os_init_firm.c \ + os_boot.c \ + +TARGET_LIB = libos$(FIRM_LIBSUFFIX).a + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries/os/ARM9/os_cache_tag.c b/build/libraries/os/ARM9/os_cache_tag.c new file mode 100644 index 00000000..cb16308a --- /dev/null +++ b/build/libraries/os/ARM9/os_cache_tag.c @@ -0,0 +1,269 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - OS + File: os_cache_tag.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + + +//=========================================================================== +// DATA CACHE (for specified range) +//=========================================================================== +/*---------------------------------------------------------------------------* + Name: DC_ClearTagAll + + Description: clear tag in data cache + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +void DC_ClearTagAll( void ) +{ + DC_FillTagAll( 0 ); +} + +/*---------------------------------------------------------------------------* + Name: DC_FillTagAll + + Description: clear tag in data cache + + Arguments: data : fill data + + Returns: None. + *---------------------------------------------------------------------------*/ +asm void DC_FillTagAll( u32 data ) +{ + mov r12, #0 +@1: + mov r2, #0 +@2: + orr r3, r2, r12 + mcr p15, 3, r3, c15, c0, 0 // set index + mcr p15, 3, r0, c15, c2, 0 // clear tag + add r2, r2, #HW_CACHE_LINE_SIZE + cmp r2, #HW_DCACHE_SIZE/4 + blt @2 + + add r12, r12, #1< diff --git a/build/libraries/os/Makefile b/build/libraries/os/Makefile new file mode 100644 index 00000000..a2045b3d --- /dev/null +++ b/build/libraries/os/Makefile @@ -0,0 +1,32 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - os +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 \ + ARM7 \ + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/os/common/os_boot.c b/build/libraries/os/common/os_boot.c new file mode 100644 index 00000000..09617c7d --- /dev/null +++ b/build/libraries/os/common/os_boot.c @@ -0,0 +1,134 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - OS + File: os_boot.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "reboot.h" + +extern void SDK_STATIC_START(void); // static and bss start address +extern void SDK_STATIC_BSS_END(void); // static and bss end address + +/*---------------------------------------------------------------------------* + Name: OS_BootWithRomHeaderFromFIRM + + Description: boot with ROM header + + Arguments: rom_header : ROM header + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_BootWithRomHeaderFromFIRM( ROM_Header* rom_header ) +{ +#ifdef SDK_ARM9 + void *entry = rom_header->s.main_entry_address; + void *code_buf = (void*)OS_BOOT_CODE_BUF; // 0x023fee00 + void *stack_top = (void*)OS_BOOT_STACK_TOP; // (HW_DTCM_END - HW_DTCM_SYSRV_SIZE - HW_SVC_STACK_SIZE) +#else + void *entry = rom_header->s.sub_entry_address; + void *code_buf = (void*)OS_BOOT_CODE_BUF; // 0x03fff600 + void *stack_top = (void*)OS_BOOT_STACK_TOP; // (HW_WRAM_AREA_END - HW_PRV_WRAM_SYSRV_SIZE - HW_SVC_STACK_SIZE) +#endif + void *wram_reg = rom_header->s.main_wram_config_data; + REBOOTTarget target = REBOOT_TARGET_TWL_SECURE_SYSTEM; + BOOL scfg = TRUE; // no touch + BOOL jtag = FALSE; // no touch + static u32 mem_list[32]; + int i = 0; + + // pre clear + /* g static & bss ̃NA */ + mem_list[i++] = (u32)SDK_STATIC_START; + mem_list[i++] = (u32)SDK_STATIC_BSS_END-(u32)SDK_STATIC_START; +#ifdef SDK_ARM9 + /* ITCMSNA (FromFrim) */ + mem_list[i++] = HW_ITCM; + mem_list[i++] = HW_FIRM_FROM_FIRM_BUF - HW_ITCM; + mem_list[i++] = HW_FIRM_FROM_FIRM_BUF_END; + mem_list[i++] = HW_ITCM_END - HW_FIRM_FROM_FIRM_BUF_END; + /* FS/FATFSobt@̃NA */ + mem_list[i++] = (u32)HW_FIRM_FATFS_COMMAND_BUFFER; // 0x02ff7800 - 0x02ffbfff + mem_list[i++] = (u32)HW_FIRM_FS_TEMP_BUFFER_END - (u32)HW_FIRM_FATFS_COMMAND_BUFFER; + /* ꕔobt@̃NA (Ǘ.xlsQ) */ + mem_list[i++] = (u32)OSi_GetFromFirmAddr()->rsa_pubkey[0]; + mem_list[i++] = ACS_PUBKEY_LEN; +#else // SDK_ARM7 + /* FS_Loaderpobt@̃NA */ + mem_list[i++] = HW_FIRM_LOAD_BUFFER_BASE; + mem_list[i++] = HW_FIRM_LOAD_BUFFER_UNIT_SIZE * HW_FIRM_LOAD_BUFFER_UNIT_NUMS; + { /* REBOOT_ExecuteCODESTACǨԂNA */ + u32 stack_bottom = (u32)stack_top - OS_BOOT_STACK_SIZE_MIN - sizeof(mem_list); + u32 code_buf_end = OS_BOOT_CODE_BUF + OS_BOOT_CODE_SIZE; + SDK_ASSERT( stack_bottom > code_buf_end ); + mem_list[i++] = code_buf_end; + mem_list[i++] = stack_bottom - code_buf_end; + } + /* ꕔobt@̃NA (Ǘ.xlsQ) */ + // Y +#endif // SDK_ARM7 + mem_list[i++] = NULL; + // copy forward + mem_list[i++] = NULL; + // copy backward + mem_list[i++] = NULL; + // post clear + mem_list[i++] = NULL; + SDK_ASSERT(i <= sizeof(mem_list)/sizeof(mem_list[0])); +#ifdef FIRM_USE_TWLSDK_KEYS + // TwlSDǨgĂ鎞͗ʎYpCPUł̓u[gȂ +#ifdef SDK_ARM9 + if ( ! ((*(u8*)OS_CHIPTYPE_DEBUGGER_ADDR & OS_CHIPTYPE_DEBUGGER_MASK)) ) +#else // SDK_ARM7 + if ( ! ((*(u8*)HWi_WSYS08_ADDR & HWi_WSYS08_OP_OPT_MASK)) ) +#endif // SDK_ARM7 + { + OS_Terminate(); + } +#endif // FIRM_USE_SDK_KEYS + REBOOT_Execute(entry, wram_reg, mem_list, code_buf, stack_top, target, scfg, jtag); + OS_Terminate(); +} + +/*---------------------------------------------------------------------------* + Name: OSi_FromBromToMenu + + Description: convert OSFromBromBuf to OSFromFirmBuf + + Arguments: None + + Returns: FALSE if FromBrom is broken + *---------------------------------------------------------------------------*/ +BOOL OSi_FromBromToMenu( void ) +{ + OSFromBromBuf* const fromBromBuf = OSi_GetFromBromAddr(); + BOOL result = TRUE; + int i; + // check offset (why not to omit by compiler?) + if ( OSi_GetFromFirmAddr()->rsa_pubkey != fromBromBuf->rsa_pubkey ) // same area without header + { + result = FALSE; + } + // check unused signature area + for (i = 0; i < sizeof(fromBromBuf->hash_table_hash); i++) // check all values are same + { + if (fromBromBuf->hash_table_hash[i] != 0x00) + { + result = FALSE; + } + } + // clear out of OSFromFirmBuf area + MI_CpuClearFast( fromBromBuf->header.max, sizeof(fromBromBuf->header.max) ); + return result; +} diff --git a/build/libraries/os/common/os_init_firm.c b/build/libraries/os/common/os_init_firm.c new file mode 100644 index 00000000..26aa0c0c --- /dev/null +++ b/build/libraries/os/common/os_init_firm.c @@ -0,0 +1,166 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - OS + File: os_init_firm.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 + +/*---------------------------------------------------------------------------* + Name: OS_InitNOR + + Description: initialize sdk os for firm + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +#pragma profile off +void OS_InitFIRM(void) +{ +#ifdef SDK_ARM9 + //---- system shared area check +// SDK_ASSERT((u32)&(OS_GetSystemWork()->command_area) == HW_CMD_AREA); + + //---------------------------------------------------------------- + // for ARM9 + +#ifdef SDK_ENABLE_ARM7_PRINT + // Init PrintServer for ARM7 (if specified) +// OS_InitPrintServer(); +#endif + + //---- Init interProcessor I/F + // Sync with ARM7 to enable OS_GetConsoleType() + // PXI_Init() must be called before OS_InitArenaEx() + //PXI_Init(); + //PXI_InitFifoFIRM(); + PXI_InitFIRM(); + + //---- Init Arena (arenas except SUBPRIV-WRAM) + OS_InitArena(); + + //---- Init Spinlock + OS_InitLock(); + + //---- Init Arena (extended main) + OS_InitArenaEx(); + + //---- Init IRQ Table + OS_InitIrqTable(); + + //---- Init IRQ Stack checker + OS_SetIrqStackChecker(); + + //---- Init Exception System +// OS_InitException(); + + //---- Init MI (Wram bank and DMA0 arranged) + MI_Init(); + + //---- Init VCountAlarm + OS_InitVAlarm(); + + //---- Init VRAM exclusive System + OSi_InitVramExclusive(); + + //---- Init Thread System +#ifndef SDK_NO_THREAD + OS_InitThread(); +#endif + //---- Init Reset System +#ifndef SDK_SMALL_BUILD +// OS_InitReset(); +#endif + + //---- Init Cartridge +#ifndef SDK_TEG +// CTRDG_Init(); +#endif + + //---- Init Card +#ifndef SDK_SMALL_BUILD +// CARD_Init(); +#endif + + //---- init System config +#ifdef SDK_TWL +// if (OS_IsRunOnTwl() == TRUE) +// { + SCFG_Init(); +// } +#endif + + //---- Init Power Manager +#ifndef SDK_TEG +// PM_Init(); +#endif + + //---- adjust VCOUNT +// OSi_WaitVCount0(); + +#else // SDK_ARM9 + //---------------------------------------------------------------- + // for ARM7 + + //---- Init interProcessor I/F + //PXI_Init(); + //PXI_InitFifoFIRM(); + PXI_InitFIRM(); + + //---- Init Arena (SUBPRIV-WRAM arena) + OS_InitArena(); + + //---- Init Spinlock + OS_InitLock(); + + //---- Init IRQ Table + OS_InitIrqTable(); + +#define SDK_EXCEPTION_BUG +#ifndef SDK_EXCEPTION_BUG + //---- Init Exception System + OS_InitException(); +#endif + + //---- Init Tick + OS_InitTick(); + + //---- Init Alarm System + OS_InitAlarm(); + + //---- Init Thread System + OS_InitThread(); + + //---- Init Reset System +#ifndef SDK_SMALL_BUILD +// OS_InitReset(); +#endif + + //---- Init Cartridge +#ifndef SDK_TEG +// CTRDG_Init(); +#endif + + //---- init System config +#ifdef SDK_TWL +// if (OS_IsRunOnTwl() == TRUE) +// { + SCFG_Init(); +// } +#endif + +#endif // SDK_ARM9 +} + +#pragma profile reset diff --git a/build/libraries/pm/ARM7/Makefile b/build/libraries/pm/ARM7/Makefile new file mode 100644 index 00000000..d258ebe5 --- /dev/null +++ b/build/libraries/pm/ARM7/Makefile @@ -0,0 +1,55 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - pm +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = + + +#---------------------------------------------------------------------------- + +# build ARM & THUMB libraries +TWL_CODEGEN_ALL ?= TRUE + +# Codegen for sub processer +TWL_PROC = ARM7 + +INCDIR = $(ROOT)/build/libraries/spi/ARM7/pm/include \ + +SRCDIR = . + +SRCS = \ + pm_init.c \ + pm_pmic_ex.c \ + +TARGET_LIB = libpm_sp$(FIRM_LIBSUFFIX).a + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries/pm/ARM7/pm_init.c b/build/libraries/pm/ARM7/pm_init.c new file mode 100644 index 00000000..86976e7d --- /dev/null +++ b/build/libraries/pm/ARM7/pm_init.c @@ -0,0 +1,93 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - pm + File: pm_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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include + +static BOOL doneBackLight = FALSE; + +/*---------------------------------------------------------------------------* + Name: PM_InitFIRM + + Description: set default parameters + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void PM_InitFIRM( void ) +{ + // LED + PMi_ResetFlags( REG_PMIC_LED_CTL_ADDR, PMIC_LED_CTL_AUTO_BLINK | PMIC_LED_CTL_BLINK_BY_SLEEP ); + PMi_SetParams( REG_PMIC_LVL4_BRT_ADDR, + PMIC_LED_1_BRT_LEVEL_4_OFF | PMIC_LED_2_BRT_LEVEL_4_OFF, + PMIC_LVL4_BRT_LED_1_MASK | PMIC_LVL4_BRT_LED_2_MASK + ); + PMi_SetParams( REG_PMIC_LVL3_BRT_ADDR, + PMIC_LED_1_BRT_LEVEL_3_100 | PMIC_LED_2_BRT_LEVEL_3_OFF, + PMIC_LVL3_BRT_LED_1_MASK | PMIC_LVL3_BRT_LED_2_MASK + ); + PMi_SetParams( REG_PMIC_LVL2_BRT_ADDR, + PMIC_LED_1_BRT_LEVEL_2_OFF | PMIC_LED_1_BRT_LEVEL_2_100, + PMIC_LVL2_BRT_LED_1_MASK | PMIC_LVL2_BRT_LED_2_MASK + ); + PMi_SetParams( REG_PMIC_LVL1_BRT_ADDR, + PMIC_LED_1_BRT_LEVEL_1_100 | PMIC_LED_2_BRT_LEVEL_1_100, + PMIC_LVL1_BRT_LED_1_MASK | PMIC_LVL1_BRT_LED_2_MASK + ); + + // correct battery LED curve + PMi_SetFlags( REG_PMIC_VLBAT_CTL_ADDR, PMIC_VLBAT_CTL_VLBAT_2_ACTIVE | PMIC_VLBAT_CTL_VLBAT_3_ACTIVE ); + + // LCD ON + PMi_SetFlags( REG_PMIC_CTL2_ADDR, PMIC_CTL2_VDD50 ); + + // back light + //PMi_SetParams( REG_PMIC_BL_BRT_A_ADDR, PMIC_BACKLIGHT_BRIGHT_MAX, PMIC_BL_BRT_A_MASK ); // TODO: less brightness + //PMi_SetParams( REG_PMIC_BL_BRT_B_ADDR, PMIC_BACKLIGHT_BRIGHT_MAX, PMIC_BL_BRT_B_MASK ); // TODO: less brightness + PMi_SetParams( REG_PMIC_BL_BRT_A_ADDR, 0, PMIC_BL_BRT_A_MASK ); + PMi_SetParams( REG_PMIC_BL_BRT_B_ADDR, 0, PMIC_BL_BRT_B_MASK ); +} + +/*---------------------------------------------------------------------------* + Name: PM_BackLightOn + + Description: power B/L on if not set yet + + Arguments: force TRUE: wait until valid condition + FALSE not set unless valid condition + + Returns: None + *---------------------------------------------------------------------------*/ +void PM_BackLightOn( BOOL force ) +{ + if ( doneBackLight ) + { + return; // have already set + } + if ( force ) + { + while ( (reg_GX_DISPSTAT & REG_GX_DISPSTAT_INI_MASK) == FALSE ) + { + } + } + if ( reg_GX_DISPSTAT & REG_GX_DISPSTAT_INI_MASK ) + { + PMi_SetFlags( REG_PMIC_CTL2_ADDR, PMIC_CTL2_BACK_LIGHT_1 | PMIC_CTL2_BACK_LIGHT_2 ); + doneBackLight = TRUE; + } +} diff --git a/build/libraries/pm/ARM7/pm_pmic_ex.c b/build/libraries/pm/ARM7/pm_pmic_ex.c new file mode 100644 index 00000000..5932fa03 --- /dev/null +++ b/build/libraries/pm/ARM7/pm_pmic_ex.c @@ -0,0 +1,72 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - libraries - pm + File: pm_pmic_ex.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 + +//================================================================================ +// PMIC BIT CONTROL +//================================================================================ +/*---------------------------------------------------------------------------* + Name: PMi_SetParams + + Description: set control bit to device register + + Arguments: reg : device register + setBits : bits to set + maskBits : bits to mask + + Returns: None + *---------------------------------------------------------------------------*/ +void PMi_SetParams( u8 reg, u8 setBits, u8 maskBits ) +{ + u8 tmp; + tmp = PMi_GetRegister( reg ); + tmp &= ~maskBits; + setBits &= maskBits; + tmp |= setBits; + PMi_SetRegister( reg, tmp ); +} + +/*---------------------------------------------------------------------------* + Name: PMi_SetFlags + + Description: set control bit to device register + + Arguments: reg : device register + setBits : bits to set + + Returns: None + *---------------------------------------------------------------------------*/ +void PMi_SetFlags( u8 reg, u8 setBits ) +{ + PMi_SetParams( reg, setBits, setBits ); +} + +/*---------------------------------------------------------------------------* + Name: PMi_ResetFlags + + Description: clear control bit to device register + + Arguments: reg : device register + clrBits : bits to set + + Returns: None + *---------------------------------------------------------------------------*/ +void PMi_ResetFlags( u8 reg, u8 clrBits ) +{ + PMi_SetParams( reg, 0, clrBits ); +} + diff --git a/build/libraries/pm/Makefile b/build/libraries/pm/Makefile new file mode 100644 index 00000000..f9636f04 --- /dev/null +++ b/build/libraries/pm/Makefile @@ -0,0 +1,31 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - libraries - pm +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM7 + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/pxi/ARM7/Makefile b/build/libraries/pxi/ARM7/Makefile new file mode 100644 index 00000000..09a3c37a --- /dev/null +++ b/build/libraries/pxi/ARM7/Makefile @@ -0,0 +1,53 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries_sp - pxi +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +# build ARM & THUMB libraries +TWL_CODEGEN_ALL ?= TRUE + +# Codegen for sub processer +TWL_PROC = ARM7 + +SRCDIR = ../common . + +SRCS = \ + pxi_firm.c +# pxi_misc.c \ + +TARGET_LIB = libpxi_sp$(FIRM_LIBSUFFIX).a + + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/pxi/ARM9/Makefile b/build/libraries/pxi/ARM9/Makefile new file mode 100644 index 00000000..d7d5361f --- /dev/null +++ b/build/libraries/pxi/ARM9/Makefile @@ -0,0 +1,47 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - pxi +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = + + +#---------------------------------------------------------------------------- + +# build ARM & THUMB libraries +TWL_CODEGEN_ALL ?= TRUE + +SRCDIR = ../common . + +SRCS = \ + pxi_firm.c +# pxi_misc.c \ + +TARGET_LIB = libpxi$(FIRM_LIBSUFFIX).a + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(FIRM_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries/pxi/Makefile b/build/libraries/pxi/Makefile new file mode 100644 index 00000000..2dbcba07 --- /dev/null +++ b/build/libraries/pxi/Makefile @@ -0,0 +1,32 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - libraries - pxi +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 \ + ARM7 \ + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries/pxi/common/pxi_firm.c b/build/libraries/pxi/common/pxi_firm.c new file mode 100644 index 00000000..a3d06780 --- /dev/null +++ b/build/libraries/pxi/common/pxi_firm.c @@ -0,0 +1,325 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - library - pxi + File: pxi_firm.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 + +#define PXI_FIRM_ID_MAX 8 +#define PXI_FIRM_STREAM_MAX 16 + +typedef struct +{ + u32 wp; + u32 rp; + + u8 id[PXI_FIRM_ID_MAX]; + + u32 semaphore; // for fs_loader.c + + u32 length; + u32 current; + u8 data[PXI_FIRM_STREAM_MAX]; +} +PxiWork; +static PxiWork work; + +static void PxiFirmStreamCallback( PXIFifoTag tag, u32 data, BOOL err ) +{ + (void)tag; + (void)err; + if ( !work.length ) // stream is starting + { + if ( data > PXI_FIRM_STREAM_MAX ) + { + OS_TPrintf("Receiving stream has too large size (%d > %d).\n", data, PXI_FIRM_STREAM_MAX); + } + work.length = data; + work.current = 0; + } + else if ( work.current < work.length ) // stream is cotinuous + { + int i; + u8* ptr = (u8*)&data; + for ( i = 0; i < 3 && work.current < work.length; i++ ) + { + work.data[ work.current++ ] = *ptr++; + } + } + else + { + OS_TPrintf("Stream buffer was overflow because of multiple usage.\n"); + } +} + +static void PxiFirmIDCallback( PXIFifoTag tag, u32 data, BOOL err ) +{ + u32 next_wp = ( work.wp + 1 ) % PXI_FIRM_ID_MAX; + (void)tag; + (void)err; + + // special ID + if ( data == FIRM_PXI_ID_LOAD_BUFFER_SEMAPHORE ) + { + work.semaphore++; + if ( work.semaphore > HW_FIRM_LOAD_BUFFER_UNIT_NUMS ) + { + OS_TPanic("PROGRAM ERROR: Semaphore counter was overlow."); + } + return; + } + + if ( next_wp != work.rp ) + { + work.wp = next_wp; + work.id[work.wp] = (u8)data; + } + else + { + OS_TPrintf("ID buffer was overflow (%d is ignored).\n", (u8)data); + } +} + +/*---------------------------------------------------------------------------* + Name: PXI_InitFIRM + + Description: initialize PXI for firm + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_InitFIRM(void) +{ +#ifdef SDK_ARM9 + work.semaphore = 0; +#else + work.semaphore = HW_FIRM_LOAD_BUFFER_UNIT_NUMS; +#endif + work.rp = work.wp = work.length = 0; + + PXI_Init(); +#ifdef SDK_ARM9 + while (!PXI_IsCallbackReady(PXI_FIFO_TAG_USER_0, PXI_PROC_ARM7)) + { + } +#endif + PXI_SetFifoRecvCallback( PXI_FIFO_TAG_USER_0, PxiFirmStreamCallback ); + PXI_SetFifoRecvCallback( PXI_FIFO_TAG_USER_1, PxiFirmIDCallback ); +#ifdef SDK_ARM7 + while (!PXI_IsCallbackReady(PXI_FIFO_TAG_USER_1, PXI_PROC_ARM9)) + { + } +#endif +} + +/*---------------------------------------------------------------------------* + Name: PXI_SendStream + + Description: Send data stream + + Arguments: buf pointer to data buffer + size transfer size + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_SendStream( const void* buf, int size ) +{ + u8* ptr = (u8*)buf; + while ( 0 > PXI_SendWordByFifo( PXI_FIFO_TAG_USER_0, (u32)size, 0 ) ) + { + } + while ( size > 0 ) + { + u32 data = (u32)(ptr[0] << 0 | ptr[1] << 8 | ptr[2] << 16); + while ( 0 > PXI_SendWordByFifo( PXI_FIFO_TAG_USER_0, data, 0 ) ) + { + } + size -= 3; + ptr += 3; + } +} + +/*---------------------------------------------------------------------------* + Name: PXI_RecvStream + + Description: Receive data stream + + Arguments: buf pointer to data buffer + size transfer size + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_RecvStream( void* buf, int size ) +{ + while ( 1 ) + { + OSIntrMode enabled = OS_DisableInterrupts(); + if ( work.length && work.current >= work.length ) + { + if ( size != work.length ) + { + OS_TPrintf("Stream data size was not expected."); + } + else + { + MI_CpuCopy8( work.data, buf, (u32)size ); + work.length = work.current = 0; + } + OS_RestoreInterrupts( enabled ); + return; + } + OS_RestoreInterrupts( enabled ); + } +} + +/*---------------------------------------------------------------------------* + Name: PXI_NotifyID + + Description: Send ID + + Arguments: id id to send + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_NotifyID( FIRMPxiID id ) +{ + while ( 0 > PXI_SendWordByFifo( PXI_FIFO_TAG_USER_1, id, 0 ) ) + { + } +#if 0 +#ifdef SDK_ARM9 + OS_TPrintf("[ARM9] Notify: %d\n", (u8)id); +#else + OS_TPrintf("[ARM7] Notify: %d\n", (u8)id); +#endif +#endif +} + +/*---------------------------------------------------------------------------* + Name: PXI_RecvID + + Description: Receive ID + + Arguments: None + + Returns: Received ID + *---------------------------------------------------------------------------*/ +FIRMPxiID PXI_RecvID( void ) +{ + while ( 1 ) + { + OSIntrMode enabled = OS_DisableInterrupts(); + if ( work.rp != work.wp ) + { + FIRMPxiID id; + work.rp = ( work.rp + 1 ) % PXI_FIRM_ID_MAX; + id = (FIRMPxiID)work.id[work.rp]; + OS_RestoreInterrupts( enabled ); +#if 0 +#ifdef SDK_ARM9 + OS_TPrintf("[ARM9] Received: %d\n", id); +#else + OS_TPrintf("[ARM7] Received: %d\n", id); +#endif +#endif + return id; + } + OS_RestoreInterrupts( enabled ); + } +} + +/*---------------------------------------------------------------------------* + Name: PXI_ReleaseLoadBufferSemaphore + + Description: Release semaphore for *_LoadBuffer + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_ReleaseLoadBufferSemaphore( void ) +{ + PXI_NotifyID( FIRM_PXI_ID_LOAD_BUFFER_SEMAPHORE ); +} + +/*---------------------------------------------------------------------------* + Name: PXI_AcquireLoadBufferSemaphore + + Description: Acquire semaphore for *_LoadBuffer + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_AcquireLoadBufferSemaphore( void ) +{ + while ( 1 ) + { + OSIntrMode enabled = OS_DisableInterrupts(); + if ( work.semaphore > 0 ) + { + work.semaphore--; + OS_RestoreInterrupts( enabled ); + return; + } + OS_RestoreInterrupts( enabled ); + } +} + +/*---------------------------------------------------------------------------* + Name: PXIi_SendIDByIntf + + Description: Send 4bit id to the other processor + + Arguments: id sending id + + Returns: None + *---------------------------------------------------------------------------*/ +void PXIi_SendIDByIntf( u32 id ) +{ + reg_PXI_INTF = (u16)(id << REG_PXI_INTF_SEND_SHIFT); +} + +/*---------------------------------------------------------------------------* + Name: PXIi_RecvIDByIntf + + Description: Receive 4bit id from the other processor + + Arguments: None + + Returns: received id + *---------------------------------------------------------------------------*/ +u32 PXIi_RecvIDByIntf( void ) +{ + return (u32)((reg_PXI_INTF & REG_PXI_INTF_RECV_MASK) >> REG_PXI_INTF_RECV_SHIFT); +} + +/*---------------------------------------------------------------------------* + Name: PXIi_WaitIDByIntf + + Description: Wait 4bit id from the other processor + + Arguments: id waiting id + + Returns: None + *---------------------------------------------------------------------------*/ +void PXIi_WaitIDByIntf( u32 id ) +{ + while (PXIi_RecvIDByIntf() != id) + { + } +} + diff --git a/build/libraries_sysmenu/Makefile b/build/libraries_sysmenu/Makefile new file mode 100644 index 00000000..d5db837c --- /dev/null +++ b/build/libraries_sysmenu/Makefile @@ -0,0 +1,32 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS_P = reloc_info sysmenu mb_loader acsign boot hotsw + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries_sysmenu/acsign/ARM9/Makefile b/build/libraries_sysmenu/acsign/ARM9/Makefile new file mode 100644 index 00000000..f9c8bc66 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/Makefile @@ -0,0 +1,58 @@ +#! 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 = +SUBMAKES = Makefile.encrypt + + +#---------------------------------------------------------------------------- +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED +TWL_PROC = ARM9 + +INCDIR = include \ + $(ROOT)/build/libraries/mb/common/include + +SRCS = acsign.c acmemory.c acsign_util.c \ + +TARGET_LIB = libacsign$(TWL_LIBSUFFIX).a + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(SYSMENU_INSTALL_LIBDIR) + +CCFLAGS += -DSMALL_CODE_SIZE \ + -DSTANDALONE \ + -DOPT_32_BIT \ + -DNO_SPLIT \ + -DNO_FP_API \ + -DNO_R_DIAG \ + -DNO_STDIO_H \ + -DNO_STDLIB_H + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries_sysmenu/acsign/ARM9/Makefile.encrypt b/build/libraries_sysmenu/acsign/ARM9/Makefile.encrypt new file mode 100644 index 00000000..2640e983 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/Makefile.encrypt @@ -0,0 +1,57 @@ +#! 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:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- + +SUBDIRS = + + +#---------------------------------------------------------------------------- +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED +TWL_PROC = ARM9 + +INCDIR = include + +SRCS = acsign_encrypt.c \ + ber_lib.c ber_isk.c ber_par.c + +TARGET_LIB = libacsign_enc$(TWL_LIBSUFFIX).a + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(SYSMENU_INSTALL_LIBDIR) + +CCFLAGS += -DSMALL_CODE_SIZE \ + -DSTANDALONE \ + -DOPT_32_BIT \ + -DNO_SPLIT \ + -DNO_FP_API \ + -DNO_R_DIAG \ + -DNO_STDIO_H \ + -DNO_STDLIB_H + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries_sysmenu/acsign/ARM9/include/acmemory.h b/build/libraries_sysmenu/acsign/ARM9/include/acmemory.h new file mode 100644 index 00000000..1a3e206e --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/acmemory.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: acmemory.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 _ACMEMORY_H_ +#define _ACMEMORY_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// +void ACMemory_Clear( ); +void* ACMemory_Alloc( u32 size ); +void* ACMemory_Realloc( void *adrs, u32 nowsize, u32 newsize ); +void ACMemory_Free( void* adrs ); +void* ACMemory_Memset( void* adrs, u32 val, u32 cnt ); +void* ACMemory_Memcpy( void* dst, void* src, u32 cnt ); + +#ifdef __cplusplus +} +#endif + +#endif //_ACMEMORY_H_ diff --git a/build/libraries_sysmenu/acsign/ARM9/include/ber.h b/build/libraries_sysmenu/acsign/ARM9/include/ber.h new file mode 100644 index 00000000..c0821a1c --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/ber.h @@ -0,0 +1,667 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - makerom.TWL + File: ber.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$ + *---------------------------------------------------------------------------*/ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#ifndef HEADER_COMMON_BER_H +#define HEADER_COMMON_BER_H + +#ifdef __cplusplus +extern "C" { +#endif + +//#include "r_com.h" // local modified. +#include +#include +#include +#include + +/* The ASN.1 types are in this file */ +#include "ber_type.h" + +#if defined(VXWORKS) && defined(m_len) +#undef m_len +#endif + +/* In the info field */ +/** + * The name-space of the object is universal or global. + */ +#define BER_UNIVERSAL 0x00 +/** + * The name-space of the object is application specific. + */ +#define BER_APPLICATION 0x40 +/** + * The name-space of the object is context specific. + * Context-specific items are constructed types of a value (cont [1]). + */ +#define BER_CONTEXT_SPECIFIC 0x80 +/** + * The name-space of the object is private. + */ +#define BER_PRIVATE 0xc0 +/** + * Masks the class part of the type of the BER item. + */ +#define BER_CLASS_MASK 0xc0 + +/** + * The items has no explicit data. All following items that fit in the length + * of the constructed item are part of the data. If the constructed item is + * indefinite encoded, the data finishes with an EOC of 0 length. + * The items that make up the data of this item are said to have a greater + * depth than the constructed item. + */ +#define BER_CONSTRUCTED 0x20 +/** + * This mask is used to determine the type of the item. + */ +#define BER_PRIMITIVE_TAG_MASK 0x1f + +/* Set in the flags */ +/** + * Flag indicates that the stack of items was dynamically allocated and needs + * to be freed. + */ +#define BER_FLAG_DYNAMIC 0x01 +/** + * Flag indicates that the items in the #BER_ITEMS_SK were dynamically allocated + * and need to be freed. + */ +#define BER_FLAG_DYNAMIC_ITEMS 0x02 +/** + * A prefix byte has been set. A bit string requires a byte to precede the data + * in order to provide information about the number of valid bits. + */ +#define BER_FLAG_PREFIX_BYTE 0x04 +/** + * The item has an invalid length value associated with it. This may be because + * the length is greater than the parent's length or because the item has a + * that is required more than five bytes to represent. + */ +#define BER_FLAG_INVALID_LENGTH 0x08 +/** + * The header bytes have been seen for this item and any parents will not have + * these bytes available. + */ +#define BER_FLAG_SEEN_HEADER 0x10 +/** + * No data for this item has been made available. + */ +#define BER_FLAG_NO_DATA_SEEN 0x20 +/** + * Set if the header of the BER_ITEM has already been encoded. + */ +#define BER_FLAG_HEADER_ENCODED 0x40 +/** + * @fn int BER_prefix_byte(BER_ITEMS *i) + * + * Returns whether the prefix byte flag has been set for this item. + * + * @param i [In] BER item. + * @return Bit is set. + *
  • 0 = False, the bit is not set.
  • + *
  • 1 = True, the bit is set.
  • + * + * @note This flag is used for the bit string type as it requires an extra + * byte to indicate a number of valid bits. + * + * @see BER_ITEM_set_prefix_byte(). + */ + +#define BER_prefix_byte(i) ((i)->flags & BER_FLAG_PREFIX_BYTE) +/** + * @fn int BER_invalid_length(BER_ITEMS *i) + * + * Returns whether the invalid length flag has been set for this item. + * + * @param i [In] BER item. + * @return Bit is set. + *
  • 0 = False, the bit is not set.
  • + *
  • 1 = True, the bit is set.
  • + */ +#define BER_invalid_length(i) ((i)->flags & BER_FLAG_INVALID_LENGTH) + +/* In the info field */ +/** + * Mask off the flags of the information field. + */ +#define BER_INFO_MASK 0x0f +/** + * The encoding is BER rather than DER. + */ +#define BER_BER 0x01 +/** + * The item is indefinite length encoded. This means that there is no length + * value that can be used to determine the length of the data for this item. + */ +#define BER_ILEN 0x02 +/** + * The contents of this item are to be hidden. + */ +#define BER_HIDE_CONTENTS 0x04 +/** + * The header of this item has not been set yet. + */ +#define BER_NO_HEADER 0x08 + + +/** + * @fn int BER_hide_contents(BER_ITEMS *i) + * + * Returns whether the hide contents flag has been set for this item. + * + * @param i [In] BER item. + * @return Bit is set. + *
  • 0 = False, the bit is not set.
  • + *
  • 1 = True, the bit is set.
  • + */ +#define BER_hide_contents(i) ((i)->info & BER_HIDE_CONTENTS) + +/** + * @fn int BER_no_header(BER_ITEMS *i) + * + * Returns whether the no header flag has been set for this item. + * + * @param i [In] BER item. + * @return Bit is set. + *
  • 0 = False, the bit is not set.
  • + *
  • 1 = True, the bit is set.
  • + * + * @note This could be set when the data has been placed in the item but the + * header has not been setup. + */ +#define BER_no_header(i) ((i)->info & BER_NO_HEADER) + +/** + * @fn unsigned long BER_MASK(int a) + * + * Returns the BER type as a bit mask. + * + * @param a [In] Type of the item. + * @return Each ASN.1 type maps to a bit in a 32 bit value. + * + * @note There are less than 32 primative ASN.1 types. This + * means a 32bit word can be used to specify acceptable 'types'. + */ +#define BER_MASK(a) (1UL << (a)) + +/** + * @fn int BER_constructed(BER_ITEMS *a) + * + * Returns a value to indicate that the item is constructed. + * + * @param a [In] BER item. + * @return Constructed bit set. + *
  • 0 = False, the bit is not set.
  • + *
  • #BER_CONSTRUCTED = True, the bit is set.
  • + */ +#define BER_constructed(a) (((a)->info) & BER_CONSTRUCTED) + +/** + * @fn int BER_class(BER_ITEMS *a) + * + * Returns a value to indicate the name-space of the item. + * + * @param a [In] BER item. + * @return Application and/or context specific bit set. + *
  • #BER_UNIVERSAL = Universal.
  • + *
  • #BER_APPLICATION = application specific item.
  • + *
  • #BER_CONTEXT_SPECIFIC = context specific item.
  • + *
  • #BER_PRIVATE = private item.
  • + * + * @note The top two bits of the type are used to specify the name-space of + * the item and these are pulled out and put in the info field. + */ +#define BER_class(a) (((a)->info) & BER_CLASS_MASK) + +/** + * @fn int BER_indefinite_encoding(BER_ITEMS *a) + * + * Returns a value to indicate if the item is indefinite encoded. That is, + * the number of bytes to the data is not known. + * + * @param a [In] BER item. + * @return Indefinite length bit set. + *
  • 0 = False, the bit is not set.
  • + *
  • #BER_ILEN = True, the bit is set.
  • + */ +#define BER_indefinite_encoding(a) (((a)->info) & BER_ILEN) + +/** + * @fn void BER_ITEMS_SK_clear(BER_ITEMS_SK *sk) + * + * Clears the items out of the stack. + * + * @param sk [In] Stack of BER items. + * + * @note The items in the stack are not freed by this call. + */ +#define BER_ITEMS_SK_clear(sk) ((sk)->num=0) + +/** + * Maximum length of the tag/type of an item. + */ +#define BER_MAX_TAG_LEN_IN_BITS (sizeof(int) * 8) +/** + * Minumum length of the data for a header of an item that streaming can use + * when decoding. + */ +#define BER_MIN_HEADER_LEN 2 +/** + * Maximum length of the header of an item. + */ +#define BER_MAX_HEADER_LEN (1 + (BER_MAX_TAG_LEN_IN_BITS / 8) + \ + 1 + sizeof(unsigned long)) + +#ifndef NO_STREAM +/** + * The initial state in which a new item is created. + */ +#define BER_STATE_READ_NEXT_ITEM 1 +/** + * The state in which the item header is read in and processed. + */ +#define BER_STATE_READ_NEXT_ITEM_HEADER 2 +/** + * The state in which the data of the item is read in and processed. + */ +#define BER_STATE_READ_NEXT_ITEM_DATA 3 +/** + * The state in which the current item is the last for the constructed item + * above. + */ +#define BER_STATE_GO_UP 4 +#endif /* !NO_STREAM */ + +/** + * This structure holds the information about the data part of the BER item. + */ +typedef struct ber_bytes_st +{ + /** + * Length of the data for this item. + */ + unsigned long len; + /** + * A pointer to the start of the valid data of this item. + */ + unsigned char *bytes; +} BER_BYTES; + +/** + * This structure holds the information about the data part of the BER item. + */ +typedef struct ber_item_st +{ + /** + * The data of the item. + */ + BER_BYTES data; +#ifndef NO_STREAM + /** + * The depth of this item. The depth is the number of constructed items this + * item is under. + */ + unsigned char depth; + /** + * The header bytes of the item. They are kept as the buffer it comes from + * may no longer be valid when the header data is needed. + */ + unsigned char header[BER_MAX_HEADER_LEN]; + /** + * Number of data bytes seen of this item. When streaming the number of + * bytes seen depends on the number of bytes in the buffer that is being + * parsed. + */ + unsigned long seen; + /** + * Number of data bytes left to get out. When streaming the number of + * valid bytes available depends on the number of bytes in the buffer that + * is being parsed. + */ + unsigned long part_len; + /** + * Number of data bytes already encoded of the BER_ITEM. When + * streaming the number of bytes encoded depends on how much space + * is in the output buffer and how many bytes are available to encode. + */ + unsigned int encoded; +#endif /* !NO_STREAM */ + /** + * The tag number that indicates the type of the item. + */ + unsigned int type; + /** + * Information about the item. Includes the name-space, constructed bit + * and whether it is indefinite encoded. + */ + unsigned char info; + /** + * The length of the header bytes. Varies depending on name-space and the + * number of bytes needed to represent data length. + */ + unsigned char hlen; + /** + * The extra flags of the item. Includes flags to indicate what parts of the + * item are dynamic. + */ + unsigned char flags; + /** + * Holds an 'extra' prefix byte. Needed for the bit string type as it + * requires an extra byte to indicate the number of valid bits in the data. + */ + unsigned char prefix_byte; +} BER_ITEM; + +/** + * An item and pointer to other items linked to it. + */ +typedef struct ber_items_st +{ + /** + * The current item data. + */ + BER_ITEM item; + /** + * The constructed item that this item is the data for. + */ + struct ber_items_st *parent; + /** + * The next item that is also in this constructed item. + */ + struct ber_items_st *next; + /** + * When the item is constructed, this points to the first item that is + * part of the data for this item. + */ + struct ber_items_st *down; +} BER_ITEMS; + +/** + * Stack of BER items. The stack is the context of the BER items. + */ +typedef struct ber_items_sk_st +{ + /** + * The number of items stored in the stack. + */ + unsigned int num; + /** + * The maximum number of items that can be stored in the stack. + */ + unsigned int max; + /** + * The array of items. + */ + BER_ITEMS *items; + /** + * Flags of the structure. Includes dynamic allocation of data. + * If the data is dynamic, this means that it can grow. + */ + unsigned int flags; +#ifndef NO_STREAM + /** + * Current streaming parsing state. + */ + int state; + /** + * Current item is indefinite encoded. + */ + int inf; + /** + * The parent or the constructed item this item belongs to is indefinite + * encoded. + */ + int pinf; + /** + * The current item is a constructed item. + */ + int con; + /** + * The next item needs to be placed under the current item. + * Alternatively, the previous item was a constructed item. + */ + int down; + /** + * The index into the array of items of the current item. + * Due to the fact that the items may be reallocated an index needs to be + * kept rather than a pointer. + */ + int this_idx; + /** + * The index into the array of items of the next/new item. + * Due to the fact that the items may be reallocated an index needs to be + * kept rather than a pointer. + */ + int next_idx; + /** + * Holds a pointer to the next/new item for the next call to the streaming + * parsing function. + */ + BER_ITEMS *next; +#endif /* !NO_STREAM */ +} BER_ITEMS_SK; + +/** + * @fn unsigned int BER_ITEMS_SK_num(BER_ITEMS_SK *sk) + * + * Returns the number of items in the stack. + * + * @param sk [In] Stack of BER items. + * @return Number of items in the stack. + * + * @note Useful in calculating the index of the next new item. + */ +#define BER_ITEMS_SK_num(sk) ((sk)->num) +/** + * @fn unsigned BER_ITEMS *BER_ITEMS_SK_items(BER_ITEMS_SK *sk, unsigned int n) + * + * Returns a pointer to a data item in the stack. + * + * @param sk [In] Stack of BER items. + * @param n [In] Array position of the item to obtain. + * @return Pointer to a BER item. + */ +#define BER_ITEMS_SK_items(sk,n) (&((sk)->items[n])) + + +/** + * Return value indicating no error occurred. + */ +#define BER_OK 0 +/** + * Return value indicating no error occurred. + */ +#define BER_ERR_OK 0 +/** + * Error indicating that the type/tag of the item was too long. + * This normally indicates that the encoding is invalid. + * Some valid private name-space items may cause this error. + */ +#define BER_ERR_TAG_TOO_LONG 1 +/** + * Error indicating that there are not enough bytes in the buffer to complete + * the message. This is not a fatal error when streaming. + */ +#define BER_ERR_NOT_ENOUGH_BYTES 2 +/** + * Error indicating that the value of the length of data is too long. + * A length value can be infinitely long but only lengths that can fit in an + * unsigned long are supported. + */ +#define BER_ERR_LENGTH_TOO_LARGE 3 +/** + * Error indicating that the item is not constructed as expected or required. + */ +#define BER_ERR_NOT_CONSTRUCTED 4 +/** + * Error indicating that the function was unable to allocate the memory + * required. + */ +#define BER_ERR_OUT_OF_MEMORY 5 +/** + * Error indicating that the function needed space for more items but was + * unable to grow the stack. This is mostly likely to occur when the array + * of items is static and more items than allocated are required. + */ +#define BER_ERR_OUT_OF_ITEMS_STORAGE 6 +/** + * Error indicating that the comparison of the tag/type failed. + */ +#define BER_ERR_CMP_TAG 7 +/** + * Error indicating that the item is not an integer as expected or required. + */ +#define BER_ERR_NOT_AN_INTEGER 8 +/** + * Error indicating that the length of the data is too large to return in an + * unsigned long. + */ +#define BER_ERR_NUMBER_TOO_LARGE 9 +/** + * Error indicating that the bytes of data did not match in the comparison. + */ +#define BER_ERR_CMP_BYTES 10 +/** + * Error indicating an end of content item is present when not in an indefinite + * encoded item. Normally occurs when buffer is not filled properly. + */ +#define BER_ERR_UNEXPECTED_EOC 11 +/** + * Error indicating that the value of the length is invalid. This occurs when + * the length is an indefinite length value and the item is not constructed. + */ +#define BER_ERR_INVALID_LENGTH_ENCODING 12 +/** + * Error indicating that the partial length of the value is not zero. This + * means that there is data in the items that has not been used yet that will + * be invalidated by parsing the new data. Streaming only. + */ +#define BER_ERR_PARTIAL 13 +/** + * Error indicating that the various length fields of a BER_ITEM do + * not make sense and therefore processing cannot continue. In this + * case an unidentified logic error earlier in the code has occured. + */ +#define BER_ERR_PAR_ENC_LENGTH 14 +/** + * Invalid state in parsing or encoding. + */ +#define BER_ERR_INVALID_STATE 15 + + +/* A description of the BER item header: + * First byte definition + * 5 1 - search for a class + * 0 - search for a number + * for class + * 7-6 - for class, it class field + * 4-0 - tag, normal taging convention + * for number + * 7-6 - 0 - do next operation + * - 0x40 - finished + * - 0x80 - operate on the contents of this item + * - 0xc0 - operate on the contents and return at end + * 4-0 - num to scan, can only do 31 at a time, extend with subsequent calls + * Number counts skip explicit and implicit tags, they only count on + * universal types. + * If bit 5 is set, and 6-7 are 0, then we have 'special' comands + * which we can use WRT class elements. + * These two are needed when we are 'sitting' on a non-primative tag + * item since the normal 'counting' commands will skip the element before + * they perform their command. + * 0x20 return + * 0x21 operate on the contents + */ +/* To get a public key and the algorithm the following strings would work + * 0x80|0,0x40|5 - this will return the pubkey structure + * 0x80,0xc0 - Return the pubkey algorithm (from the pubkey) + * 0x80,0xc1 - Return the pubkey parameters + * 0x81 - Return the pubkey bitstring + * 0x80,0x20|0x80|3,0xc0 - return the first extension + */ + +int BER_read_item(BER_ITEM *item,unsigned char *p,unsigned long max); +int BER_find(BER_ITEM *ret,BER_ITEM *in,unsigned char *find); +int BER_ITEMS_SK_get(BER_ITEMS_SK *sk,int *items_idx); +void BER_ITEMS_append(BER_ITEMS *a,BER_ITEMS *b); +int BER_ITEMS_under(BER_ITEMS *a,BER_ITEMS *b); +int BER_ITEMS_SK_grow(BER_ITEMS_SK *ks,unsigned int num); +int BER_parse(BER_ITEMS_SK *ks,unsigned char *in,unsigned long max, + unsigned long *num_used); +int BER_parse_stream(BER_ITEMS_SK *ks,unsigned char **in,long mlen, + long *num_used); + +#ifdef HEADER_COMMON_BIO_H +int BER_print(BIO *bio,BER_ITEMS *items); +int BER_out(BIO *out,BER_ITEMS *start); +#else /* !HEADER_COMMON_BIO_H */ +int BER_print(char *,BER_ITEMS *items); +int BER_out(char *out,BER_ITEMS *start); +#endif /* !HEADER_COMMON_BIO_H */ + +void BER_ITEM_init(BER_ITEM *item); +void BER_ITEMS_init(BER_ITEMS *item); +void BER_ITEM_set_all(BER_ITEM *item,unsigned int sclass,unsigned int tag, + unsigned char *data,unsigned int len,unsigned int info, unsigned int flags); +void BER_ITEM_set_header(BER_ITEM *item, unsigned int sclass,unsigned int tag, + unsigned int flags); +void BER_ITEM_set_data(BER_ITEM *item, unsigned char *data, unsigned int len); +int BER_ITEM_cmp_tag(BER_ITEM *a,unsigned int tag); +int BER_ITEM_get_long(BER_ITEM *a,long *l); +int BER_ITEM_set_long(BER_ITEM *a, long lret, unsigned char *buf); + +size_t BER_ITEM_header_len(BER_ITEM *item); +unsigned int BER_ITEM_header_write(BER_ITEM *item, unsigned char *out); +unsigned int BER_ITEM_header_swrite(BER_ITEM *item, unsigned char *out); + +int BER_ITEM_cmp_bytes(BER_ITEM *a,unsigned char *d, unsigned int l); +void BER_ITEMS_SK_init(BER_ITEMS_SK *sk,BER_ITEMS *items,unsigned int num, + unsigned int max); +void BER_ITEMS_SK_free(BER_ITEMS_SK *sk); +unsigned long BER_ITEMS_recalc_length(BER_ITEMS *a); +int BER_ITEMS_encode(BER_ITEMS *a, unsigned char *out, unsigned long *olen, + unsigned long max); +int BER_ITEMS_encode_stream(BER_ITEMS **a, unsigned char *out, + unsigned long *olen, unsigned long max); +int BER_load_level(BER_ITEMS_SK *sk, unsigned char *ino, unsigned long m_len); + +/* We have to make the second parameter 'unsigned int' instead of + * 'unsigned char' because both the Sun and HP compilers complain + * when using a mix of ANSI prototypes and K&R function implementations + */ +void BER_ITEM_set_prefix_byte(BER_ITEM *item, unsigned int byte); + +/* Used to count bits in an array of chars, strip leading 0, counts bits */ +int R_num_bits(unsigned char *buf, int len, int bigendian); + +#ifdef __cplusplus +} +#endif + +#endif /* !HEADER_COMMON_BER_H */ + diff --git a/build/libraries_sysmenu/acsign/ARM9/include/ber_lcl.h b/build/libraries_sysmenu/acsign/ARM9/include/ber_lcl.h new file mode 100644 index 00000000..d1d3a787 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/ber_lcl.h @@ -0,0 +1,62 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - makerom.TWL + File: ber_lcl.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$ + *---------------------------------------------------------------------------*/ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#ifndef HEADER_COMMON_BER_LCL_H +#define HEADER_COMMON_BER_LCL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef STANDALONE +#include "r_com.h" +#else +#include +#include +#define NO_STDLIB_MAPPING +#include "acmemory.h" +#define Malloc(a) ACMemory_Alloc(a) +#define Free(a) ACMemory_Free(a) +#define Memset(a,b,c) ACMemory_Memset(a,b,c) +#define Memcpy(a,b,c) ACMemory_Memcpy(a,b,c) +#define Realloc(a,b,c) ACMemory_Realloc(a,b,c) +#define Memcmp(a,b,c) memcmp(a,b,c) +#define Bsearch(a,b,c,d,e) bsearch(a,b,c,d,e) +#endif + +#include "ber.h" + +#ifdef UNDER_CE +#include "wcestdlb.h" /* include for bsearch */ +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* !HEADER_COMMON_BER_H */ + diff --git a/build/libraries_sysmenu/acsign/ARM9/include/ber_type.h b/build/libraries_sysmenu/acsign/ARM9/include/ber_type.h new file mode 100644 index 00000000..92fe40de --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/ber_type.h @@ -0,0 +1,221 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - makerom.TWL + File: ber_type.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$ + *---------------------------------------------------------------------------*/ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/** + * @file + * This file contains information on the ASN.1 types used to perform + * Basic Encoding Rules (BER) encoding and decoding operations. + */ + +#ifndef HEADER_COMMON_BER_TYPE_H +#define HEADER_COMMON_BER_TYPE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Indicates the end of content for encoded items with an unspecified length. + */ +#define BER_EOC 0 + +/** + * Indicates either "true" or "false" as per the ASN.1 boolean values + * #BER_TRUE and #BER_FALSE. + */ +#define BER_BOOLEAN 1 + +/** + * Effectively unbounded but commonly used to hold values + * that will fit into a long. + */ +#define BER_INTEGER 2 + +/** + * An array of Bytes in which the first Byte is the number of bits to + * discard from the end. + */ +#define BER_BIT_STRING 3 + +/** + * An 8-bit (hexadecimal Byte) array or Byte array. + */ +#define BER_OCTET_STRING 4 + +/** + * A Basic Encoding Rules (BER) object that has no data. It is used when data + * is specified for a general case but not a specific case. + */ +#define BER_NULL 5 + +/** + * A Basic Encoding Rules (BER) object used to hold an ASN.1 identifier that + * describes the make-up of the rest of the constructed elements. + */ +#define BER_OBJECT 6 + +/** + * An indefinitely long string of characters (plus space) used to describe an + * object. + */ +#define BER_OBJECT_DESCRIPTOR 7 + +/** + * Embedded material that is not defined using ASN.1, such as a GIF file. This + * type is deprecated in favour of #BER_EMBEDDED_PDV. + */ +#define BER_EXTERNAL 8 + +/** + * A comma-separated list of three integers for the mantissa, the base + * (2 or 10), and the exponent. (Also PLUS-INFINITY and + * MINUS-INFINITY.)
    + * Hence, {x, y, z} is (x times (y to the power z)), + * where y is allowed to take only the values 2 and 10. + */ +#define BER_REAL 9 + +/** + * A comma-separated list of names. + */ +#define BER_ENUMERATED 10 + +/** + * Embedded material that is not defined using ASN.1, such as a GIF file. This + * type supercedes #BER_EXTERNAL. + */ +#define BER_EMBEDDED_PDV 11 + +/** + * A character string which may contain characters from any language. + */ +#define BER_UTF8STRING 12 + +/** + * A constructed type that is used to hold an ordered list of elements. + */ +#define BER_SEQUENCE 16 + +/** + * A constructed type that is used to hold a list of repeating elements. + */ +#define BER_SET 17 + +/** + * A string of characters containing the digits zero to 9 and space. + */ +#define BER_NUMERICSTRING 18 + +/** + * A character array that only allows a small subset of values, namely + * [A-Z] [a-z] [0-9] and [ '()+,-./:=?]. + */ +#define BER_PRINTABLESTRING 19 + +/** + * A deprecated synonym for #BER_TELETEXSTRING. + */ +#define BER_T61STRING 20 + +/** + * A character string that allows register entries 6, 87, 102, 103, 106, 107, + * 126, 144, 150, 153, 156, 164, 165 and 168 (plus space and delete) + * of the International Register of Coded Character Sets. + */ +#define BER_TELETEXSTRING 20 + +/** + * A character string that enables access to the "characters" used to + * build crude pictures on videotext systems. + */ +#define BER_VIDEOTEXSTRING 21 + +/** + * A character string that allows the register entries 1 and 6 (plus space and + * delete) of the International Register of Coded Character Sets to be used + * with escape sequences. + */ +#define BER_IA5STRING 22 + +/** + * A character string representing the date and time in the format:
    + * ddmmyyhhmmssZ. + */ +#define BER_UTCTIME 23 + +/** + * A character string representing the date and time in the format:
    + * ddmmyyyyhhmmssZ. + */ +#define BER_GENERALIZEDTIME 24 + +/** + * A character string that allows any of the register entries in the + * International Register for printable characters other than + * the control character entries. + */ +#define BER_GRAPHICSTRING 25 + +/** + * A deprecated synonym for #BER_VISIBLESTRING. + */ +#define BER_ISO64STRING 26 + +/** + * A character string that allows register entry 6 of the International + * Register of Coded Character Sets to be used with escape sequences. + */ +#define BER_VISIBLESTRING 26 + +/** + * A character string that allows any of the register entries in the + * International Register for printable characters. + */ +#define BER_GENERALSTRING 27 + +/** + * A character string which may contain characters from any language + * without using combining characters. + */ +#define BER_UNIVERSALSTRING 28 + +/** + * A character string which may contain characters from any living + * language. + */ +#define BER_BMPSTRING 30 + +/** The boolean value "false" for the #BER_BOOLEAN ASN.1 type. */ +#define BER_FALSE 0 +/** The boolean value "true" for the #BER_BOOLEAN ASN.1 type. */ +#define BER_TRUE 255 + +#ifdef __cplusplus +} +#endif + +#endif /* !HEADER_COMMON_BER_TYPE_H */ + diff --git a/build/libraries_sysmenu/acsign/ARM9/include/bn.h b/build/libraries_sysmenu/acsign/ARM9/include/bn.h new file mode 100644 index 00000000..ed99275e --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/bn.h @@ -0,0 +1,1136 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#ifndef HEADER_COMMON_BN_H +#define HEADER_COMMON_BN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef FLAT_INC +#include "r_types.h" +#else +#include "../include/r_types.h" +#endif + +#if !defined(CCONV) +#define CCONV +#endif + +#ifndef PRE_CCONV +#define PRE_CCONV +#endif + +/* convert from the new to the old option names */ +#if defined(OPT_BN_LLONG) +#define BN_LLONG /* comment to make sure Configure leaves this alone */ +#endif + +#if defined(OPT_BN_MUL_LATENCY) +#define BN_MUL_LATENCY +#endif + +/* by default we have the following switched on - unless we have an option + * that switched them off for a specific platform + */ +#ifdef OPT_NO_COMBA +#define OPT_NO_BN_MUL_COMBA +#define OPT_NO_BN_SQR_COMBA +#endif + +#ifdef OPT_NO_REC +#define OPT_NO_BN_RECURSION_MUL +#define OPT_NO_BN_RECURSION_SQR +#endif + +#ifndef OPT_NO_BN_MUL_COMBA +#define BN_MUL_COMBA +#endif +#ifndef OPT_NO_BN_SQR_COMBA +#define BN_SQR_COMBA +#endif +#ifndef OPT_NO_BN_RECURSION_MUL +#define BN_RECURSION_MUL +#endif +#ifndef OPT_NO_BN_RECURSION_SQR +#define BN_RECURSION_SQR +#endif +#ifndef OPT_NO_BN_RECURSION_MONT +#undef BN_RECURSION_MONT /* DO NOT TURN THIS ON, IT IS BROKEN */ +#endif + +#if (!defined(OPT_NO_BN_MUL_COMBA) && !defined(OPT_NO_BN_SQR_COMBA)) +#if OPT_MONT_REDUCE_COMBA /* TEMP UNTIL C IS IMPLEMENTED-DEF'd ON PLATFORMS W/ ASM */ +#define BN_REDUCE_COMBA +#endif +#endif + +#define RECP_MUL_MOD +#define MONT_MUL_MOD + +#ifndef OPT_NO_BN_SURRENDER +#define BN_SURRENDER +#else +#undef BN_SURRENDER +#endif + +#ifdef SMALL_CODE_SIZE +#undef BN_MUL_COMBA /* stop modification */ +#undef BN_SQR_COMBA /* stop modification */ +#undef BN_REDUCE_COMBA /* stop modification */ +#undef BN_RECURSION_MUL /* stop modification */ +#undef BN_RECURSION_SQR /* stop modification */ +#undef BN_RECURSION_MONT /* stop modification */ +#endif + + + +/* This next option uses the C libraries (2 word)/(1 word) function. + * If it is not defined, I use my C version (which is slower). + * The reason for this flag is that when the particular C compiler + * library routine is used, and the library is linked with a different + * compiler, the library is missing. This mostly happens when the + * library is built with gcc and then linked using nornal cc. This would + * be a common occurance because gcc normally produces code that is + * 2 times faster than system compilers for the big number stuff. + * For machines with only one compiler (or shared libraries), this should + * be on. Again this in only really a problem on machines + * using "long long's", are 32bit, and are not using my assember code. */ +#if defined(MSDOS) || defined(WINDOWS) || defined(linux) +#define BN_DIV2W +#endif + +/* Only one for the following should be defined */ +/* The prime number generation stuff may not work when + * EIGHT_BIT but I don't care since I've only used this mode + * for debuging the bignum libraries */ +#undef SIXTY_FOUR_BIT_LONG +#undef SIXTY_FOUR_BIT +#undef SIXTY_BIT +#undef THIRTY_TWO_BIT +#undef THIRTY_BIT +#undef SIXTEEN_BIT +#undef EIGHT_BIT +#undef TEST_EIGHT_BIT + +#if defined(OPT_64_BIT_LONG) +#define SIXTY_FOUR_BIT_LONG +#endif +#if defined(OPT_64_BIT) +#define SIXTY_FOUR_BIT +#endif +#if defined(OPT_60_BIT) +#define SIXTY_BIT +#endif +#if defined(OPT_32_BIT) +#define THIRTY_TWO_BIT +#endif +#if defined(OPT_32_BIT_INT) +#define THIRTY_TWO_BIT +#endif +#if defined(OPT_30_BIT) +#define THIRTY_BIT +#endif +#if defined(OPT_16_BIT) +#define SIXTEEN_BIT +#endif +#if defined(OPT_8_BIT) +#define EIGHT_BIT +#endif +#if defined(OPT_8_BIT_TEST) +#define TEST_EIGHT_BIT +#endif + +/* This define is used for those few functions that 'break' when + * things are compiled for 8 bit words. Basically the size of an + * integer. + */ +#define BN_ILONG BN_ULONG + +/* assuming long is 64bit - this is the DEC Alpha + * unsigned long long is only 64 bits, don't define + * BN_LLONG for the DEC Alpha */ +#ifdef SIXTY_FOUR_BIT_LONG +#undef BN_LLONG +#define BN_ULLONG unsigned long long +#define BN_ULONG unsigned long +#define BN_LONG long +#define BN_BITS 128 +#define BN_BYTES 8 +#define BN_BITS2 64 +#define BN_BITS4 32 +#define BN_MASK (0xffffffffffffffffffffffffffffffffLL) +#define BN_MASK2 (0xffffffffffffffffL) +#define BN_MASK2l (0xffffffffL) +#define BN_MASK2lh (0xffffffffL) +#define BN_MASK2h (0xffffffff00000000L) +#define BN_MASK2h1 (0xffffffff80000000L) +#define BN_TBIT (0x8000000000000000L) +#define BN_DEC_CONV (10000000000000000000UL) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%019lu" +#define BN_DEC_NUM 19 +#define BN_HEX_FMT "%016lX" +#endif + +/* This is where the long long data type is 64 bits, but long is 32. + * For machines where there are 64bit registers, this is the mode to use. + * IRIX, on R4000 and above should use this mode, along with the relevent + * assember code. Do NOT define BN_LLONG. + */ +#ifdef SIXTY_FOUR_BIT +#undef BN_LLONG /* Protect against config */ +/* #define BN_ULLONG unsigned long long */ +#ifdef WIN64 +#define BN_ULONG unsigned _int64 +#define BN_LONG _int64 +#else +#define BN_ULONG unsigned long long +#define BN_LONG long long +#endif +#define BN_BITS 128 +#define BN_BYTES 8 +#define BN_BITS2 64 +#define BN_BITS4 32 +#define BN_MASK2 (0xffffffffffffffffLL) +#define BN_MASK2l (0xffffffffL) +#define BN_MASK2lh (0xffffffffL) +#define BN_MASK2h (0xffffffff00000000LL) +#define BN_MASK2h1 (0xffffffff80000000LL) +#define BN_TBIT (0x8000000000000000LL) +#define BN_DEC_CONV (10000000000000000000ULL) +#ifdef WIN64 +#define BN_DEC_FMT1 "%I64u" +#define BN_DEC_FMT2 "%019I64u" +#define BN_DEC_NUM 19 +#define BN_HEX_FMT "%016I64X" +#else +#define BN_DEC_FMT1 "%llu" +#define BN_DEC_FMT2 "%019llu" +#define BN_DEC_NUM 19 +#define BN_HEX_FMT "%016llX" +#endif +#endif + +#ifdef SIXTY_BIT +#undef SIXTY_FOUR_BIT +#undef BN_LLONG /* Protect against config */ +/* #define BN_ULLONG unsigned long long */ +#define BN_ULONG unsigned long long +#define BN_LONG long long +#define BN_BITS 120 +#define BN_BITS2 60 +#define BN_BITS4 30 +#define BN_MASK2 (0x0fffffffffffffffLL) +#define BN_MASK2l ( 0x3fffffffL) +#define BN_MASK2lh ( 0x3fffffffL) +#define BN_MASK2h (0x0fffffffc0000000LL) +#define BN_MASK2h1 (0x0fffffffe0000000LL) +#define BN_TBIT (0x0800000000000000LL) +#define BN_DEC_CONV (100000000000000000LL) +#define BN_DEC_FMT1 "%9u" +#define BN_DEC_FMT2 "%017llu" +#define BN_DEC_NUM 17 +#define BN_HEX_FMT "%016llX" +#endif + +#ifdef THIRTY_TWO_BIT +#ifdef WIN32 +#if defined(__BORLANDC__) +#define BN_ULLONG unsigned __int64 +#else /* !__BORLANDC__ */ +#if defined(__MINGW32__) || defined(__DJGPP__) +#define BN_ULLONG unsigned long long +#else +#define BN_ULLONG unsigned _int64 +#endif /* __MINGW32__ || __DJGPP__ */ +#endif /* __BORLANDC__ */ +#else /* !WIN32 */ +#define BN_ULLONG unsigned long long +#endif /* WIN32 */ +#ifdef OPT_32_BIT_INT +#define BN_ULONG unsigned int +#define BN_LONG int +#else +#define BN_ULONG unsigned long +#define BN_LONG long +#endif +#define BN_BITS 64 +#define BN_BYTES 4 +#define BN_BITS2 32 +#define BN_BITS4 16 +/* This is needed because the Watcom compiler pre-processor + * under QNX tries to parses the 'LL' part even though it is + * never used. + */ +#ifdef BN_LLONG +#ifndef WIN32 +#define BN_MASK (0xffffffffffffffffLL) +#else +#define BN_MASK (0xffffffffffffffffL) +#endif +#endif +#define BN_MASK2 (0xffffffffL) +#define BN_MASK2l (0xffff) +#define BN_MASK2lh (0xffff) +#define BN_MASK2h1 (0xffff8000L) +#define BN_MASK2h (0xffff0000L) +#define BN_TBIT (0x80000000L) +#define BN_DEC_CONV (1000000000L) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%09lu" +#define BN_DEC_NUM 9 +#define BN_HEX_FMT "%08lX" +#endif + +#ifdef THIRTY_BIT +#ifdef WIN32 +#if defined(__MINGW32__) || defined(__DJGPP__) +#define BN_ULLONG unsigned long long +#else /* ! (__MINGW32__ || __DJGPP__) */ +#define BN_ULLONG unsigned _int64 +#endif /* __MINGW32__ || __DJGPP__ */ +#else /* !WIN32 */ +#define BN_ULLONG unsigned long long +#endif /* WIN32 */ +#define BN_ULONG unsigned long +#define BN_LONG long +#define BN_BITS 60 +#define BN_BITS2 30 +#define BN_BITS4 15 +/* This is needed because the Watcom compiler pre-processor + * under QNX tries to parses the 'LL' part even though it is + * never used. + */ +#ifdef BN_LLONG +#ifndef WIN32 +#define BN_MASK (0x0fffffffffffffffLL) +#else +#define BN_MASK (0x0fffffffffffffffL) +#endif +#endif +#define BN_MASK2 (0x3fffffffL) +#define BN_MASK2l (0x7fff) +#define BN_MASK2lh (0x7fff) +#define BN_MASK2h1 (0x3fffc000L) +#define BN_MASK2h (0x3fff8000L) +#define BN_TBIT (0x20000000L) +#define BN_DEC_CONV (1000000000L) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%09lu" +#define BN_DEC_NUM 9 +#define BN_HEX_FMT "%08lX" +#endif + +#ifdef SIXTEEN_BIT +#ifndef BN_DIV2W +#define BN_DIV2W +#endif +#define BN_ULLONG unsigned long +#define BN_ULONG unsigned short +#define BN_LONG short +#define BN_BITS 32 +#define BN_BYTES 2 +#define BN_BITS2 16 +#define BN_BITS4 8 +#define BN_MASK (0xffffffff) +#define BN_MASK2 (0xffff) +#define BN_MASK2l (0xff) +#define BN_MASK2lh (0xff) +#define BN_MASK2h1 (0xff80) +#define BN_MASK2h (0xff00) +#define BN_TBIT (0x8000) +#define BN_DEC_CONV (10000) +#define BN_DEC_FMT1 "%u" +#define BN_DEC_FMT2 "%04u" +#define BN_DEC_NUM 4 +#define BN_HEX_FMT "%04X" +#endif + +#ifdef TEST_EIGHT_BIT +#define EIGHT_BIT /* comment to stop editing */ +#endif + +#ifdef EIGHT_BIT +#undef BN_ILONG +#define BN_ILONG unsigned int +#ifndef BN_DIV2W +#define BN_DIV2W +#endif +#ifdef TEST_EIGHT_BIT +#define BN_ULLONG unsigned int +#define BN_ULONG unsigned int +#define BN_LONG int +#else +#define BN_ULLONG unsigned short +#define BN_ULONG unsigned char +#define BN_LONG char +#endif +#define BN_BITS 16 +#define BN_BYTES 1 +#define BN_BITS2 8 +#define BN_BITS4 4 +#define BN_MASK (0xffff) +#define BN_MASK2 (0xff) +#define BN_MASK2lh (0xf) +#define BN_MASK2l (0xf) +#define BN_MASK2h1 (0xf8) +#define BN_MASK2h (0xf0) +#define BN_TBIT (0x80) +#define BN_DEC_CONV (100) +#define BN_DEC_FMT1 "%u" +#define BN_DEC_FMT2 "%02u" +#define BN_DEC_NUM 2 +#define BN_HEX_FMT "%02X" +#endif + +#ifdef BIGNUM +#undef BIGNUM +#endif + +#define BN_FLG_MALLOCED 0x01 +#define BN_FLG_STATIC_DATA 0x02 +#define BN_FLG_FREE 0x8000 /* used for debuging */ +#define BN_CTX_FLG_ABORT 0x4000 /* used for aborting RSA operations*/ +#define BN_set_flags(b,n) ((b)->flags|=(n)) +#define BN_get_flags(b,n) ((b)->flags&(n)) +#define BN_CTX_set_flags(b,n) ((b)->flags|=(n)) +#define BN_CTX_get_flags(b,n) ((b)->flags&(n)) + +#ifndef HEADER_COMMON_BN_H_TYPEDEF_DEF +#define HEADER_COMMON_BN_H_TYPEDEF_DEF +typedef struct bignum_st BIGNUM; +typedef struct bignum_ctx BN_CTX; +typedef struct bn_mont_ctx_st BN_MONT_CTX; +typedef struct bn_recp_ctx_st BN_RECP_CTX; +typedef struct bn_prime_ctx_st BN_PRIME_CTX; +typedef struct bn_blind_ctx_st BN_BLIND_CTX; +typedef struct bn_blind_meth_st BN_BLIND_METH; +#endif + +typedef struct bn_mod_exp_meth_st BN_ME_METH; +typedef struct bn_mod_exp_ctx_st BN_ME_CTX; + + +/* The data array d must always have an extra 'valid' word in location + * bn->d[bn->max]. It must be ok for reading. This is needed if + * BN_MUL_LATENCY is defined. + */ +struct bignum_st + { + BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ + int top; /* Index of last used d +1. */ + /* The next are internal book keeping for bn_expand. */ + int max; /* Size of the d array. */ + int neg; /* one if the number is negative */ + int flags; + }; + +/* Used for temp variables */ +#define BN_CTX_NUM 12 +struct bignum_ctx + { + int tos; + BIGNUM bn[BN_CTX_NUM+1]; + int flags; + R_SURRENDER *surrender; + }; + +#if defined(WIN64) || defined(__ia64__) || defined(CPU_IA64) +#define BN_USHORT unsigned int +#else +#define BN_USHORT unsigned short +#endif + +/* Used for prime number generation */ +struct bn_prime_ctx_st + { + BN_USHORT *primes; + BN_USHORT *mods; + int num_primes; + int prime_checks; + R_SURRENDER *surrender; + R_RANDOM *random; + int flags; + }; + +struct bn_blind_ctx_st + { + int init; + BN_BLIND_METH *meth; + BIGNUM B; + BIGNUM Bi; + BIGNUM mod; + }; + +struct bn_blind_meth_st + { + void (*init) (BN_BLIND_CTX *); + void (*ctx_free)(BN_BLIND_CTX *); + int (*set) (BN_BLIND_CTX *,R_RANDOM *,BIGNUM *,BIGNUM *, BN_ME_CTX *,BN_CTX *); + int (*convert) (BN_BLIND_CTX *,BIGNUM *,BN_CTX *); + int (*invert) (BN_BLIND_CTX *,BIGNUM *,BN_CTX *); + int (*update) (BN_BLIND_CTX *,BN_CTX *); + int (*copy) (BN_BLIND_CTX *,BN_BLIND_CTX *); + }; + +/* Used for montgomery multiplication */ +struct bn_mont_ctx_st + { + int use_word; /* 0 for word form, 1 for long form */ + int ri; /* number of bits in R */ + int riw; /* number of words in R */ + BIGNUM RR; /* used to convert to montgomery form */ + BIGNUM N; /* The modulus */ + BIGNUM Ni; /* The inverse of N */ + BN_ULONG n0; /* word form of inverse, normally only one of + * Ni or n0 is defined */ + int flags; + }; + +/* Used by the recursive exponentiation implementations */ +typedef struct bn_mod_exp_rec_meth_st + { +#ifndef NOPROTO + void (PRE_CCONV CCONV *mul)(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b); + void (PRE_CCONV CCONV *sqr)(BN_ULONG *r, BN_ULONG *a); + void (PRE_CCONV CCONV *low_mul)(); +#else + void (PRE_CCONV CCONV *mul)(); + void (PRE_CCONV CCONV *sqr)(); + void (PRE_CCONV CCONV *low_mul)(); +#endif + } BN_MOD_EXP_REC_METH; + +/* If this flag is set, if there is a custom method for a modulus + * two times larger, use it. This is mostly mean for use on the + * itanium where a 512*512 routine is 10 times faster than the C + * code version, so we need to detect that we can turn of CRT + * for RSA if there is an native IA64 512*512 present. + */ +#define BN_ME_FLG_FAST_ASM 0x0001 + +struct bn_mod_exp_meth_st + { + int num; /* Word size we target */ + char *name; /* Identify the method */ +#ifndef NOPROTO + int (*useit)(const BN_ME_METH *meth); + /* If 'power' is null, reuse the old one */ + int (*mod_exp)(BN_ME_CTX *mctx,BIGNUM *r,BIGNUM *a,BIGNUM *p, + BN_CTX *ctx); + /* Create the BN_ME_CTX */ + int (*init_ctx)(const BN_ME_METH *meth,BN_ME_CTX **mctx); + /* Get rid of it */ + int (*free_ctx)(BN_ME_CTX *mctx); + /* Assign the modulus */ + int (*set)(BN_ME_CTX *mctx,BIGNUM *n,int cmd,int flags,BN_CTX *ctx); +#else + int (*useit)(); + int (*mod_exp)(); + int (*init_ctx)(); + int (*free_ctx)(); + int (*set)(); +#endif + int argi; + char *argp; /* 'Extra stuff' */ + }; + +#define BN_ME_METH_TABLE_MAX 32 +/* Used in BN_library_init */ +#define BN_INIT_LAST 0x00 +#define BN_INIT_BN_ME_METH 0x01 + +#define BN_BNME_F_DEFAULT 0x01 +/* Used only when loading, kept as bits internally, normally loaded as + * words */ +#define BN_BNME_F_BITS 0x02 +typedef struct bn_me_meth_info_st + { +#ifndef NOPROTO + const BN_ME_METH *(*meth)(void); +#else + const BN_ME_METH *(*meth)(); +#endif + int min; + int max; + int flags; + } BN_ME_METH_INFO; + +#define BN_ME_SET_MOD 0x01 +#define BN_ME_SET_BASE 0x02 +#define BN_ME_SET_EXP 0x03 +#define BN_ME_SET_FLG_NO_LOOKUP 0x01 /* Passed to BN_ME_CTX_set() */ + +#define BN_FLG_CACHE 0x10 /* Cache values */ +#define BN_ME_FLG_BASE 0x40 /* base has been cached */ +#define BN_ME_FLG_EXP 0x80 /* power has been cached */ +/* When one of these structures is setup, it is intended that the + * base or power, if not null, will be used for the current calculation. + * If the base and/or power are cached, they will only be used if the input + * value is null. + * For RSA, the power would normally be set. + * For DH, the base and power would be set. The initial value generated + * would be the public key, which is exchanged. The phase2 part would + * change the base but not the power. + * For DSA signing, a fixed base is used, but a random power. + * For DSA verification, there are two bases and two powers, + * a^p%m * b^q%m + * One way to implement this is to use a special function to + * generate a composite power value, and or a special base form. + * The other option is to have a special function to generate + * the 'base' array. The problem is that we are exponentiating with + * a 3 value power value, instead of the normal two. It should be possible + * to use the standard a^b%m function. + */ +struct bn_mod_exp_ctx_st + { + const BN_ME_METH *meth; + char *callback; + char *cb_arg; + int flags; + /* Evil hack for storage of data values, it should really be here + * other than the first value */ + char *modulus; /* eg BN_MONT_CTX */ + char *power; /* eg power representation */ + char *base; /* eg base representation */ + char *arg; + }; + +/* Used for reciprocal division/mod functions + * It cannot be shared between threads + */ +struct bn_recp_ctx_st + { + BIGNUM N; /* the divisor */ + BIGNUM Nr; /* the reciprocal */ + int num_bits; + int shift; + int flags; + }; + +typedef struct bn_rec_st + { + int depth; + int n; +#ifndef NOPROTO + void (PRE_CCONV CCONV *mul)(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b); + void (PRE_CCONV CCONV *sqr)(BN_ULONG *r, BN_ULONG *a); + void (PRE_CCONV CCONV *low_mul)(); +#else + void (PRE_CCONV CCONV *mul)(); + void (PRE_CCONV CCONV *sqr)(); + void (PRE_CCONV CCONV *low_mul)(); +#endif + } BN_REC; + +#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ + r,a,&((mont)->RR),(mont),ctx) + +#define BN_prime_checks (5) + +#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) +#define BN_length(a) ((a)->top * BN_BYTES) +#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) +#define BN_is_zero(a) (((a)->top == 0) || BN_is_word(a,0)) +#define BN_is_one(a) (BN_is_word((a),1)) +#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) +#define BN_one(a) (BN_set_word((a),(BN_ULONG)1)) +#define BN_zero(a) (BN_set_word((a),(BN_ULONG)0)) + +/*#define BN_ascii2bn(a) BN_hex2bn(a) */ +/*#define BN_bn2ascii(a) BN_bn2hex(a) */ + +#define bn_expand(n,b) ((((((b+BN_BITS2-1))/BN_BITS2)) <= (n)->max)?\ + (n):bn_expand2((n),(b)/BN_BITS2+1)) +#define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b))) + +#ifdef SMALL_CODE_SIZE +void bn_zexpand(BIGNUM *a,int n); +void bn_fix_top(BIGNUM *a); +#else +#define bn_zexpand(a,n) \ + if ((a)->top < n) \ + { \ + int i; \ + bn_wexpand((a),n); \ + if ((a)->d!=NULL) \ + { \ + for (i=(a)->top; id[i]=0; \ + } \ + } + +#define bn_fix_top(a) \ + { \ + BN_ULONG *ftl; \ + if ((a)->top > 0) \ + { \ + for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ + if (*(ftl--)) break; \ + } \ + } +#endif + +#define BN_MONT_CTX_set(a,b,c) BN_MONT_CTX_set_word((a),(b),(c)) + +#ifndef NOPROTO + + +const BN_ME_METH *BN_ME_METH_word(void); +const BN_ME_METH *BN_ME_METH_full(void); + +#if (defined(BN_MUL_COMBA) || defined(BN_SQR_COMBA)) + +/* word4 - used for 64bit multiprime*/ +const BN_ME_METH *BN_ME_METH_word4(void); +const BN_ME_METH *BN_ME_METH_rec4_word8(void); +const BN_ME_METH *BN_ME_METH_rec4_word16(void); +const BN_ME_METH *BN_ME_METH_rec4_word32(void); +const BN_ME_METH *BN_ME_METH_rec4_word64(void); +const BN_ME_METH *BN_ME_METH_rec4_word128(void); + +/* word6 - used for 64bit multiprime*/ +const BN_ME_METH *BN_ME_METH_word6(void); +const BN_ME_METH *BN_ME_METH_rec6_word12(void); +const BN_ME_METH *BN_ME_METH_rec6_word24(void); +const BN_ME_METH *BN_ME_METH_rec6_word48(void); +const BN_ME_METH *BN_ME_METH_rec6_word96(void); + +const BN_ME_METH *BN_ME_METH_word8(void); +const BN_ME_METH *BN_ME_METH_rec8_word16(void); +const BN_ME_METH *BN_ME_METH_rec8_word32(void); +const BN_ME_METH *BN_ME_METH_rec8_word64(void); +const BN_ME_METH *BN_ME_METH_rec8_word128(void); +const BN_ME_METH *BN_ME_METH_rec8_word256(void); + +const BN_ME_METH *BN_ME_METH_word11(void); +const BN_ME_METH *BN_ME_METH_rec11_word22(void); +const BN_ME_METH *BN_ME_METH_rec11_word44(void); +const BN_ME_METH *BN_ME_METH_rec11_word88(void); + +const BN_ME_METH *BN_ME_METH_word16(void); +const BN_ME_METH *BN_ME_METH_rec16_word32(void); +const BN_ME_METH *BN_ME_METH_rec16_word64(void); +const BN_ME_METH *BN_ME_METH_rec16_word128(void); +const BN_ME_METH *BN_ME_METH_rec16_word256(void); + +#endif + +#ifdef CPU_IA64 +const BN_ME_METH *BN_ME_METH_ia64_384(void); +const BN_ME_METH *BN_ME_METH_ia64_512(void); +const BN_ME_METH *BN_ME_METH_ia64_1024(void); +#endif + +#if (defined(CPU_SPARC_V8PLUS) || defined (CPU_SPARC_V9)) +const BN_ME_METH *BN_ME_METH_usparc(void); +const BN_ME_METH *BN_ME_METH_usparc_352(void); +const BN_ME_METH *BN_ME_METH_usparc_512(void); +#endif + +#if 1 || defined(CPU_X86) +const BN_ME_METH *BN_ME_METH_pentium4_29(void); +const BN_ME_METH *BN_ME_METH_pentium4_28(void); +#endif + +/* NCipher Nfast hardware accelerator method prototype */ +const BN_ME_METH *BN_ME_METH_nfast(void); + + +BIGNUM *BN_value_one(void); +const char * BN_options(void); +BN_CTX *BN_CTX_new(void); +void BN_CTX_init(BN_CTX *c); +void BN_CTX_free(BN_CTX *c); +#ifndef NO_BN_RAND +int BN_rand(BIGNUM *rnd, R_RANDOM *rand, int bits, int top,int bottom); +#endif +int BN_num_bits(BIGNUM *a); +int BN_num_bits_word(BN_ILONG); +BIGNUM *BN_new(void); +void BN_init(BIGNUM *); +void BN_clear_free(BIGNUM *a); +BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b); +BIGNUM *BN_bin2bn(unsigned char *s,int len,BIGNUM *ret); +int BN_bn2bin(BIGNUM *a, unsigned char *to); +BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret); +int BN_bn2mpi(BIGNUM *a, unsigned char *to); +int BN_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b); +int BN_usub(BIGNUM *r, BIGNUM *a, BIGNUM *b); +int BN_uadd(BIGNUM *r, BIGNUM *a, BIGNUM *b); +int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b); +int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx); +int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx); +int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b,BN_CTX *ctx); +int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx); +BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w); +BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); +int BN_mul_word(BIGNUM *a, BN_ULONG w); +int BN_add_word(BIGNUM *a, BN_ULONG w); +int BN_sub_word(BIGNUM *a, BN_ULONG w); +int BN_set_word(BIGNUM *a, BN_ULONG w); +BN_ULONG BN_get_word(BIGNUM *a); +int BN_cmp(BIGNUM *a, BIGNUM *b); +void BN_free(BIGNUM *a); +int BN_is_bit_set(BIGNUM *a, int n); +int BN_lshift(BIGNUM *r, BIGNUM *a, int n); +int BN_lshift1(BIGNUM *r, BIGNUM *a); +int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx); +int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx); +int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx, + BN_MONT_CTX *m_ctx); +int BN_mod_exp2_mont(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2, + BIGNUM *p2,BIGNUM *m,BN_CTX *ctx,BN_MONT_CTX *m_ctx); +int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, + BIGNUM *m,BN_CTX *ctx); +int BN_mask_bits(BIGNUM *a,int n); +int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, BIGNUM *m, + BN_CTX *ctx); +#if !defined(WIN16) && !defined(NO_FP_API) +int BN_print_fp(FILE *fp, BIGNUM *a); +#endif +#ifdef HEADER_COMMON_BIO_H +int BN_print(BIO *fp, BIGNUM *a); +#else +/* int BN_print(char *fp, BIGNUM *a); */ +#endif +int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx); +int BN_rshift(BIGNUM *r, BIGNUM *a, int n); +int BN_rshift1(BIGNUM *r, BIGNUM *a); +void BN_clear(BIGNUM *a); +BIGNUM *bn_expand2(BIGNUM *b, int bits); +BIGNUM *BN_dup(BIGNUM *a); +int BN_ucmp(BIGNUM *a, BIGNUM *b); +int BN_set_bit(BIGNUM *a, int n); +int BN_clear_bit(BIGNUM *a, int n); +char * BN_bn2hex(BIGNUM *a); +char * BN_bn2dec(BIGNUM *a); +int BN_hex2bn(BIGNUM **a,char *str); +int BN_dec2bn(BIGNUM **a,char *str); +int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx); +BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, BIGNUM *n,BN_CTX *ctx); +/* Return R, where it is R*(1< +#include +#include "r_error.h" +#include "err.h" +#include +#else //NITRO +#include "r_error.h" +#ifndef NULL +#define NULL 0 +#endif +#endif + +#ifndef STANDALONE +#include "r_com.h" +#else +#if 0 //RSA +#define NO_STDLIB_MAPPING +#define Malloc(a) malloc(a) +#define Free(a) free(a) +#define Memset(a,b,c) memset(a,b,c) +#define Memcpy(a,b,c) memcpy(a,b,c) +#else // Nitro +#define NO_STDLIB_MAPPING +#include "acmemory.h" +#define Malloc(a) ACMemory_Alloc(a) +#define Free(a) ACMemory_Free(a) +#define Memset(a,b,c) ACMemory_Memset(a,b,c) +#define Memcpy(a,b,c) ACMemory_Memcpy(a,b,c) +#endif +#endif + +/* TEMP FIX */ +#undef BNerr +#define BNerr(a,b) +#include "bn.h" + +#define BN_EXP_TABLE_SIZE 16 + +/* see the bn_limit_ fields which are the start of a runtime + * tunable set of values to match these fixed compile-time constants + */ +/* Pentium pro 16,16,16,32,64 */ +/* Alpha 16,16,16,16.64 */ +/* StrongARM */ +#define BN_MULL_SIZE_NORMAL (16) /* 32 */ +#define BN_MUL_RECURSIVE_SIZE_NORMAL (16) /* 32 */ /* less than */ +#define BN_SQR_RECURSIVE_SIZE_NORMAL (16) /* 32 */ +#define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32) /* 32 */ +#define BN_MONT_CTX_SET_SIZE_WORD (64) /* 32 */ + +/************************************************************* + * Using the long long type + */ +#define Lw(t) (((BN_ULONG)(t))&BN_MASK2) +#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) + +/* These are used for internal error checking and are not normally used */ +#ifdef BN_DEBUG +#define bn_check_top(a) \ + { if ( ((a)->top < 0) || \ + ((a)->top > (a)->max) || \ + (((a)->top == 0) && (a)->neg) || \ + (((a)->top == 1) && (a->d[0] == 0))) \ + { char *nullp=NULL; *nullp='z'; } } +#define bn_check_num(a) if ((a) < 0) { char *nullp=NULL; *nullp='z'; } +#define bn_assert(a) if (!(a)) { char *nullp=NULL; *nullp='z'; } +#define bn_set_used_check(l,size,num) bn_su_check(l,size,num) +#ifdef BN_DEBUG2 +#define bn_do_used_check(fp,str,l,size,num) bn_du_check(fp,str,l,size,num) +#else +#define bn_do_used_check(fp,str,l,size,num) +#endif +#else +#define bn_assert(a) +#define bn_check_top(a) +#define bn_check_num(a) +#define bn_set_used_check(l,size,num) +#define bn_do_used_check(fp,str,l,size,num) +#endif + + +/*********************************************** +* IA64 32 bit build SWIZZLE code +* This essentially casts our points which are +* 32bits under abi32 to 64bit unsigned long +* longs and then grabs the top two bits of the +* pointer and places it in the 2nd and 3rd bits +* of the unsigned long long. +**********************************************/ +#ifdef HPUX_IA64_32 +#define SWIZLLE(VALUE) ((((unsigned long long)(VALUE) & 0xc0000000LL) <<31)\ +|((unsigned long long)(VALUE))) +#else +#define SWIZZLE(VALUE) (VALUE) +#endif + +#define bn_neg_words(a,n) \ + { \ + int iii; \ + \ + for (iii=0; iiimax=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA)) +#else +#define bn_set_max(r) +#endif + +/* These macros are used to 'take' a section of a bignum for read only use */ +#define bn_set_low(r,a,n) \ + { \ + (r)->top=((a)->top > (n))?(n):(a)->top; \ + (r)->d=(a)->d; \ + (r)->neg=(a)->neg; \ + (r)->flags|=BN_FLG_STATIC_DATA; \ + bn_set_max(r); \ + } + +#define bn_set_high(r,a,n) \ + { \ + if ((a)->top > (n)) \ + { \ + (r)->top=(a)->top-n; \ + (r)->d= &((a)->d[n]); \ + } \ + else \ + (r)->top=0; \ + (r)->neg=(a)->neg; \ + (r)->flags|=BN_FLG_STATIC_DATA; \ + bn_set_max(r); \ + } + +/* #define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?(n):bn_expand2((n),(b))) */ + +#ifdef BN_LLONG +#define mul_add(r,a,w,c) { \ + BN_ULLONG t; \ + t=(BN_ULLONG)w * (a) + (r) + (c); \ + (r)= Lw(t); \ + (c)= Hw(t); \ + } + +#define mul(r,a,w,c) { \ + BN_ULLONG t; \ + t=(BN_ULLONG)w * (a) + (c); \ + (r)= Lw(t); \ + (c)= Hw(t); \ + } + +#else +/************************************************************* + * No long long type + */ + +#define LBITS(a) ((a)&BN_MASK2l) +#define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2lh) +#define L2HBITS(a) ((BN_ULONG)((a)&BN_MASK2lh)<>(BN_BITS4-1); \ + m =((m&BN_MASK2l)<<(BN_BITS4+1))&BN_MASK2; \ + l=(l+m)&BN_MASK2; if (l < m) h++; \ + (lo)=l; \ + (ho)=h; \ + } + +#if 0 +#define mul_add(r,a,bl,bh,b_hl,c) { \ + BN_ULONG l,h; \ + BN_ULONG lt,mt; \ + \ + h= (a); \ + l=LBITS(h); \ + h=HBITS(h); \ + mt=bl*l; \ + lt=mt+c+(r); \ + c=bh*h; \ + mt+=c+(l-h)*b_hl; \ + mt+=(lt>>BN_BITS4); \ + (r)=(lt&BN_MASK2l)|((mt&BN_MASK2l)<>BN_BITS4); \ + } +#else /* Normal version */ +#define mul_add(r,a,bl,bh,b_hl,c) { \ + BN_ULONG l,h; \ + \ + h= (a); \ + l=LBITS(h); \ + h=HBITS(h); \ + mul64(l,h,(bl),(bh)); \ + \ + /* non-multiply part */ \ + l=(l+(c))&BN_MASK2; if (l < (c)) h++; \ + (c)=(r); \ + l=(l+(c))&BN_MASK2; if (l < (c)) h++; \ + (c)=h&BN_MASK2; \ + (r)=l; \ + } +#endif + +#define mul(r,a,bl,bh,c) { \ + BN_ULONG l,h; \ + \ + h= (a); \ + l=LBITS(h); \ + h=HBITS(h); \ + mul64(l,h,(bl),(bh)); \ + \ + /* non-multiply part */ \ + l+=(c); if ((l&BN_MASK2) < (c)) h++; \ + (c)=h&BN_MASK2; \ + (r)=l&BN_MASK2; \ + } + +#endif + +#ifndef BN_MUL_COMBA +#define bn_mul_comba4(r,a,b) bn_mul_normal(r,a,4,b,4) +#define bn_mul_comba5(r,a,b) bn_mul_normal(r,a,5,b,5) +#define bn_mul_comba6(r,a,b) bn_mul_normal(r,a,6,b,6) +#define bn_mul_comba8(r,a,b) bn_mul_normal(r,a,8,b,8) +#define bn_mul_comba11(r,a,b) bn_mul_normal(r,a,11,b,11) +#define bn_mul_comba12(r,a,b) bn_mul_normal(r,a,12,b,12) +#define bn_mul_comba16(r,a,b) bn_mul_normal(r,a,16,b,16) +#endif +#if 1 +#ifndef BN_SQR_COMBA +#define bn_sqr_comba4(r,a) bn_mul_normal(r,a,4,a,4) +#define bn_sqr_comba5(r,a) bn_mul_normal(r,a,5,a,5) +#define bn_sqr_comba6(r,a) bn_mul_normal(r,a,6,a,6) +#define bn_sqr_comba8(r,a) bn_mul_normal(r,a,8,a,8) +#define bn_sqr_comba11(r,a) bn_mul_normal(r,a,11,a,11) +#define bn_sqr_comba12(r,a) bn_mul_normal(r,a,12,a,12) +#define bn_sqr_comba16(r,a) bn_mul_normal(r,a,16,a,16) +#endif +#else +#ifndef BN_SQR_COMBA +#define bn_sqr_comba4(r,a) bn_mul_comba4(r,a,a) +#define bn_sqr_comba5(r,a) bn_mul_comba5(r,a,a) +#define bn_sqr_comba6(r,a) bn_mul_comba6(r,a,a) +#define bn_sqr_comba8(r,a) bn_mul_comba8(r,a,a) +#define bn_sqr_comba11(r,a) bn_mul_comba11(r,a,a) +#define bn_sqr_comba12(r,a) bn_mul_comba12(r,a,a) +#define bn_sqr_comba16(r,a) bn_mul_comba16(r,a,a) +#endif +#endif +#ifndef BN_REDUCE_COMBA +#define r0_bn_mont_comba4(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba5(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba6(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba8(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba11(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba12(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba16(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#endif + +#ifndef NOPROTO + +BIGNUM *bn_expand2(BIGNUM *b, int bits); + +#ifdef X86_ASM +void bn_add_words(BN_ULONG *r,BN_ULONG *a,int num); +#endif + +#else + +BIGNUM *bn_expand2(); +#ifdef X86_ASM +BN_ULONG bn_add_words(); +#endif + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_COMMON_BN_LCL_H */ + +void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,BN_ULONG *t); +void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2, BN_ULONG *t); +int BN_gen_exp_string(unsigned char *str, BIGNUM *p, int bits); +void bn_from_montgomery_rec_full(BN_ULONG *rp, BN_ULONG *ap, + BN_ULONG *np, BN_ULONG *nip, BN_ULONG *tmp,BN_REC *rec); + +int bn_mont_ctx_new_word(const BN_ME_METH *meth, BN_ME_CTX **retp); + diff --git a/build/libraries_sysmenu/acsign/ARM9/include/bn_thx.h b/build/libraries_sysmenu/acsign/ARM9/include/bn_thx.h new file mode 100644 index 00000000..451b3e4d --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/bn_thx.h @@ -0,0 +1,317 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/***************************************************************************** + * Copyright (c). 2001 RSA Security Inc. All rights reserved. + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + ****************************************************************************/ +/** + * @file bn_thx.h + * @brief header file created for used as interface defines for systems + * containing hetergeneous environments where some bn operations + * will be performed in isolation from the rest of the library + */ +#ifndef HEADER_COMMON_BN_THX_H +#define HEADER_COMMON_BN_THX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* These defines are required on systems so that the mod_exp code + * to be used in isolation from the bn operation with library will work, + * if these are not available, the header files with equivalent functionality + * should be added inside a CPU or Operating system define + */ +#ifndef NO_STDIO_H +#include +#endif + +#ifndef NO_STDLIB_H +#include +#endif + +#ifndef NO_STRING_H +#include +#endif + +/* Interface for ARM/DSP systems, this interface requires only + * the standard defines and includes at the moment + */ +#ifdef CPU_TMS320 +#define THX_RECIPIENT +#define CPU_DSP +#endif + +#ifdef THX_RECIPIENT + +#ifndef restrict +#define restrict +#endif + +#ifndef Malloc +#define Malloc malloc +#endif + +#ifndef Memcpy +#define Memcpy memcpy +#endif + +#ifndef Memmove +#define Memmove memmove +#endif + +#ifndef Memset +#define Memset memset +#endif + +#ifndef Free +#define Free free +#endif + +#endif /* THX_RECIPIENT */ + +#ifndef THX_RECIPIENT /* not the recipient, we must be the caller */ + +#include "bn_lcl.h" + +#endif /* ! THX_RECIPIENT */ + +/* The follow define protected inclusions are excerpts from the + * header file bn.h, this has been done, so that code written for the + * THX systems can be used in isolation from the library + * This code may need to be updated in line with changes to the bn.h + * header file. + */ +#ifndef HEADER_COMMON_BN_H +#define HEADER_COMMON_BN_H + +#if !defined(CCONV) +#define CCONV +#endif + +#ifndef PRE_CCONV +#define PRE_CCONV +#endif + +/* convert from the new to the old option names */ +#if defined(OPT_BN_LLONG) +#define BN_LLONG /* comment to make sure Configure leaves this alone */ +#endif + +#if defined(OPT_32_BIT_INT) || defined(OPT_32_BIT) +#define THIRTY_TWO_BIT +#endif + +#define BN_ILONG BN_ULONG + +#ifdef THIRTY_TWO_BIT +#define BN_ULLONG unsigned long long +#ifdef OPT_32_BIT_INT +#define BN_ULONG unsigned int +#define BN_LONG int +#else +#define BN_ULONG unsigned long +#define BN_LONG long +#endif +#define BN_BITS 64 +#define BN_BYTES 4 +#define BN_BITS2 32 +#define BN_BITS4 16 +/* This is needed because the Watcom compiler pre-processor + * under QNX is perverted and tries to parses the 'LL' + * part even though it is never used. + */ +#ifdef BN_LLONG +#define BN_MASK (0xffffffffffffffffL) +#endif +#define BN_MASK2 (0xffffffffL) +#define BN_MASK2l (0xffff) +#define BN_MASK2lh (0xffff) +#define BN_MASK2h1 (0xffff8000L) +#define BN_MASK2h (0xffff0000L) +#define BN_TBIT (0x80000000L) +#define BN_DEC_CONV (1000000000L) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%09lu" +#define BN_DEC_NUM 9 +#define BN_HEX_FMT "%08lX" +#endif + +#define BN_EXP_TABLE_SIZE 16 + +typedef struct bignum_st BIGNUM; + +struct bignum_st + { + BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ + int top; /* Index of last used d +1. */ + /* The next are internal book keeping for bn_expand. */ + int max; /* Size of the d array. */ + int neg; /* one if the number is negative */ + int flags; + }; + +PRE_CCONV BN_ULONG CCONV bn_mul_add_words(BN_ULONG *rp,BN_ULONG *ap, + int num, BN_ULONG w); +PRE_CCONV BN_ULONG CCONV bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, + int num, BN_ULONG w); +PRE_CCONV void CCONV bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num); +BN_ULONG CCONV bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d); +PRE_CCONV BN_ULONG CCONV bn_add_words(BN_ULONG *rp, BN_ULONG *ap, + BN_ULONG *bp,int num); +PRE_CCONV BN_ULONG CCONV bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, + BN_ULONG *bp,int num); + +#ifndef BN_ME_METH +#define BN_ME_METH void +#endif + +#endif /* ! HEADER_COMMON_BN_H */ + +/* The follow define protected inclusions are excerpts from the + * header file r_error.h, this has been done, so that code written for the + * THX systems can be used in isolation from the library + * This code may need to be updated in line with changes to the r_error.h + * header file. + */ +#ifndef HEADER_COMMON_R_ERROR_H +#define HEADER_COMMON_R_ERROR_H + +/* The FATAL_INTERNAL_ERROR is a flag that is set with the following + * error codes: + * R_ERROR_INVALID_STATE + * R_ERROR_INIT_NOT_CALLED + * R_ERROR_SHOULD_NOT_HAVE_BEEN_CALLED + */ +#define R_ERROR_FATAL_INTERNAL_ERROR 64 + +/* The BAD_PARAMETER is a flag that is set with the following error + * codes: + * R_ERROR_NULL_ARG + * R_ERROR_BUFFER_TOO_SMALL + * R_ERROR_BAD_VALUE + * R_ERROR_BAD_RANGE + * R_ERROR_BAD_FORMAT + * R_ERROR_BAD_TYPE + * R_ERROR_BAD_DATA + * R_ERROR_BAD_LENGTH + */ +#define R_ERROR_BAD_PARAMETER 32 + +/* Base value for all general errors used through all products */ +#define R_ERROR_BASE 10000 + +#define R_ERROR_NONE 0 + +#define R_ERROR_FAILED (R_ERROR_BASE+1) +#define R_ERROR_IO (R_ERROR_BASE+2) +#define R_ERROR_PROTOCOL (R_ERROR_BASE+3) +#define R_ERROR_EOF (R_ERROR_BASE+4) +#define R_ERROR_ALLOC_FAILURE (R_ERROR_BASE+5) +#define R_ERROR_EVAL_RESTRICTION (R_ERROR_BASE+6) +#define R_ERROR_EVAL_EXPIRED (R_ERROR_BASE+7) +#define R_ERROR_NOT_FOUND (R_ERROR_BASE+8) +#define R_ERROR_NOT_AVAILABLE (R_ERROR_BASE+9) +#define R_ERROR_NOT_IMPLEMENTED (R_ERROR_BASE+10) +#define R_ERROR_NOT_SUPPORTED (R_ERROR_BASE+11) +#define R_ERROR_INVALID_STATE \ + ((R_ERROR_BASE+12) | R_ERROR_FATAL_INTERNAL_ERROR) +#define R_ERROR_INIT_NOT_CALLED \ + ((R_ERROR_BASE+13) | R_ERROR_FATAL_INTERNAL_ERROR) +#define R_ERROR_SHOULD_NOT_HAVE_BEEN_CALLED \ + ((R_ERROR_BASE+14) | R_ERROR_FATAL_INTERNAL_ERROR) +#define R_ERROR_METHOD_UNDEFINED \ + ((R_ERROR_BASE+15) | R_ERROR_FATAL_INTERNAL_ERROR) +#define R_ERROR_BUFFER_TOO_SMALL \ + ((R_ERROR_BASE+16) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_NULL_ARG ((R_ERROR_BASE+17) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_VALUE ((R_ERROR_BASE+18) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_RANGE ((R_ERROR_BASE+19) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_FORMAT ((R_ERROR_BASE+20) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_TYPE ((R_ERROR_BASE+21) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_DATA ((R_ERROR_BASE+22) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_LENGTH ((R_ERROR_BASE+23) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_RCOM_LIBRARY_NOT_SUPPORTED (R_ERROR_BASE+24) + +/* Resource Manager base for errors */ +#define R_COM_ERR_LIB_CTX_BASE 10100 + +#endif /* HEADER_COMMON_R_ERROR_H */ + + +const BN_ME_METH *BN_ME_METH_thxc(void); +/** + * @note THX code only needs to store rr, n0, str + * + */ +typedef struct thxc_mont_ctx_st + { + BIGNUM *rr; + unsigned char *str; + unsigned int str_len; + BN_ULONG n0; + } THXC_MONT_CTX; + + +int Rx_thxr_mod_exp_mont( BN_ULONG *result, BN_ULONG *ap, BN_ULONG *np, + BN_ULONG *rrp, BN_ULONG n0, int top, int tmp_len, unsigned char *str); + +int Ri_thxr_mod_exp_mont( BN_ULONG *result, BN_ULONG *ap, BN_ULONG *np, + BN_ULONG *rrp, BN_ULONG *dp, BN_ULONG *aap, BN_ULONG *rp, BN_ULONG *tmp, + BN_ULONG n0, int top, unsigned char *str); + +void Ri_thxr_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb); +void Ri_thxr_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp); + +void Ri_thxr_from_montgomery_words(BN_ULONG *ret,BN_ULONG *ap,BN_ULONG *np, + int w, BN_ULONG n0); + +BN_ULONG Ri_thxr_from_mont_words(BN_ULONG *ap,BN_ULONG *wap, + BN_ULONG *np, int w, BN_ULONG n0); + +#ifdef CPU_TMS320 + +/* Method and functions required for the ARM/DSP interface */ + +const BN_ME_METH *BN_ME_METH_dspc(void); + +int Rx_dsp_mod_exp_mont( BN_ULONG *result, BN_ULONG *ap, BN_ULONG *np, + BN_ULONG *rrp, BN_ULONG n0, int top, int tmp_len, unsigned char *str); + +int Ri_dsp_mod_exp_mont( BN_ULONG *result, BN_ULONG *ap, BN_ULONG *np, + BN_ULONG *rrp, BN_ULONG *dp, BN_ULONG *aap, BN_ULONG *rp, BN_ULONG *tmp, + BN_ULONG n0, int top, unsigned char *str); + +#endif + +#ifdef __cplusplus +} +#endif +#endif /* HEADER_COMMON_BN_THX_H */ diff --git a/build/libraries_sysmenu/acsign/ARM9/include/md5.h b/build/libraries_sysmenu/acsign/ARM9/include/md5.h new file mode 100644 index 00000000..7a5ca73a --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/md5.h @@ -0,0 +1,73 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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 _MD5_H_ +#define _MD5_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* MD5.H - header file for MD5C.C + */ + +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All +rights reserved. + +License to copy and use this software is granted provided that it +is identified as the "RSA Data Security, Inc. MD5 Message-Digest +Algorithm" in all material mentioning or referencing this software +or this function. + +License is also granted to make and use derivative works provided +that such works are identified as "derived from the RSA Data +Security, Inc. MD5 Message-Digest Algorithm" in all material +mentioning or referencing the derived work. + +RSA Data Security, Inc. makes no representations concerning either +the merchantability of this software or the suitability of this +software for any particular purpose. It is provided "as is" +without express or implied warranty of any kind. + +These notices must be retained in any copies of any part of this +documentation and/or software. + */ + +typedef struct MD5_CTX MD5_CTX; +typedef struct MD5_CTX MD5Context; + +/* MD5 context. */ +struct MD5_CTX{ + unsigned long state[4]; /* state (ABCD) */ + unsigned long count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} ; + +void MD5Init(MD5_CTX *); +void MD5Update(MD5_CTX *, unsigned char *, unsigned int); +void MD5Final(unsigned char digest[16], MD5_CTX *); + + +#if defined( MD5_TEST ) +int MD5Test( ); +#endif // MD5_TEST + +#ifdef __cplusplus +} +#endif + +#endif // _MD5_H_ diff --git a/build/libraries_sysmenu/acsign/ARM9/include/r_error.h b/build/libraries_sysmenu/acsign/ARM9/include/r_error.h new file mode 100644 index 00000000..16ffb55a --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/r_error.h @@ -0,0 +1,226 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/** + * @file r_error.h + * This file contains the error definitions for the toolkit. + */ +#ifndef HEADER_COMMON_R_ERROR_H +#define HEADER_COMMON_R_ERROR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup R_ERROR_IDS Error Identifiers + * This section outlines the error codes returned, enabling identification of + * specific errors. For more information, see the + * Developer's Guide. + * + * @{ + */ +/** + * Indicates that a fatal error has occurred in the operation performed. + * This flag is set with the following error codes:
    + *
      + *
    • #R_ERROR_INVALID_STATE.
    • + *
    • #R_ERROR_INIT_NOT_CALLED.
    • + *
    • #R_ERROR_SHOULD_NOT_HAVE_BEEN_CALLED.
    • + *
    + */ +#define R_ERROR_FATAL_INTERNAL_ERROR 64 + +/** + * Indicates that the specified parameter is incorrect or contains invalid + * information. This flag is set with the following error codes:
    + *
      + *
    • #R_ERROR_NULL_ARG.
    • + *
    • #R_ERROR_BUFFER_TOO_SMALL.
    • + *
    • #R_ERROR_BAD_VALUE.
    • + *
    • #R_ERROR_BAD_RANGE.
    • + *
    • #R_ERROR_BAD_FORMAT.
    • + *
    • #R_ERROR_BAD_TYPE.
    • + *
    • #R_ERROR_BAD_DATA.
    • + *
    • #R_ERROR_BAD_LENGTH.
    • + *
    + */ +#define R_ERROR_BAD_PARAMETER 32 + +/* Indicates the base value for all general errors used through all products */ +#define R_ERROR_BASE 10000 + +/** + * Indicates that no errors were detected in the requested operation. + */ +#define R_ERROR_NONE 0 + +/** + * Indicates that the requested operation failed. + */ +#define R_ERROR_FAILED (R_ERROR_BASE+1) +/** + * Indicates that the requested operation detected an Input/Output error. + */ +#define R_ERROR_IO (R_ERROR_BASE+2) +/** + * Indicates that the requested operation detected a protocol error. + */ +#define R_ERROR_PROTOCOL (R_ERROR_BASE+3) +/** + * Indicates that the requested operation detected an End-of-File (EOF) error. + */ +#define R_ERROR_EOF (R_ERROR_BASE+4) +/** + * Indicates that the requested operation failed in a memory allocation + * operation. + */ +#define R_ERROR_ALLOC_FAILURE (R_ERROR_BASE+5) +/** + * Indicates that the requested operation is restricted in an evaluation + * version of the library. + */ +#define R_ERROR_EVAL_RESTRICTION (R_ERROR_BASE+6) +/** + * Indicates that the evaluation period of the library has expired. + */ +#define R_ERROR_EVAL_EXPIRED (R_ERROR_BASE+7) +/** + * Indicates that the requested operation detected that a pre-requirement was + * not found. + */ +#define R_ERROR_NOT_FOUND (R_ERROR_BASE+8) +/** + * Indicates that the requested operation detected that a pre-requirement was + * unavailable. + */ +#define R_ERROR_NOT_AVAILABLE (R_ERROR_BASE+9) +/** + * Indicates that the requested operation is not implemented in the current + * instantiation of the library. + */ +#define R_ERROR_NOT_IMPLEMENTED (R_ERROR_BASE+10) +/** + * Indicates that the requested operation is not supported in the current + * instantiation of the library. + */ +#define R_ERROR_NOT_SUPPORTED (R_ERROR_BASE+11) +/** + * Indicates that the requested operation entered an invalid state. + */ +#define R_ERROR_INVALID_STATE \ + ((R_ERROR_BASE+12) | R_ERROR_FATAL_INTERNAL_ERROR) +/** + * Indicates that the requested operation detected that an initialization + * operation has not been performed. + */ +#define R_ERROR_INIT_NOT_CALLED \ + ((R_ERROR_BASE+13) | R_ERROR_FATAL_INTERNAL_ERROR) +/** + * Indicates that the requested operation should not have been called. + */ +#define R_ERROR_SHOULD_NOT_HAVE_BEEN_CALLED \ + ((R_ERROR_BASE+14) | R_ERROR_FATAL_INTERNAL_ERROR) +/** + * Indicates that the requested method is not defined. + */ +#define R_ERROR_METHOD_UNDEFINED \ + ((R_ERROR_BASE+15) | R_ERROR_FATAL_INTERNAL_ERROR) +/** + * Indicates that the requested operation detected an inadequately sized + * buffer. + */ +#define R_ERROR_BUFFER_TOO_SMALL \ + ((R_ERROR_BASE+16) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * was passed as NULL. + */ +#define R_ERROR_NULL_ARG ((R_ERROR_BASE+17) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed contained a bad or incorrect value. + */ +#define R_ERROR_BAD_VALUE ((R_ERROR_BASE+18) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed was out of the allowed range. + */ +#define R_ERROR_BAD_RANGE ((R_ERROR_BASE+19) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed used a format that is not supported or incorrect. + */ +#define R_ERROR_BAD_FORMAT ((R_ERROR_BASE+20) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed used a type that is not supported or incorrect. + */ +#define R_ERROR_BAD_TYPE ((R_ERROR_BASE+21) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed contained incorrect or invalid data. + */ +#define R_ERROR_BAD_DATA ((R_ERROR_BASE+22) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed contained an incorrect length value. + */ +#define R_ERROR_BAD_LENGTH ((R_ERROR_BASE+23) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the library instantiation requested is not supported. + */ +#define R_ERROR_RCOM_LIBRARY_NOT_SUPPORTED (R_ERROR_BASE+24) +/** + * Indicates that the request operation was denied. + */ +#define R_ERROR_DENIED (R_ERROR_BASE+25) +/** + * Indicates that authentication is required before the operation + * can succeed. + */ +#define R_ERROR_AUTHENTICATION_REQUIRED (R_ERROR_BASE+26) + +/** + * Indicates that a required module was unable to be loaded. + */ +#define R_ERROR_MODULE_LOAD_FAILED \ + ((R_ERROR_BASE+27)|R_ERROR_FATAL_INTERNAL_ERROR) + +/* Resource Manager base for errors */ +#define R_COM_ERR_LIB_CTX_BASE 10100 + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif /* HEADER_COMMON_R_ERROR_H */ + + + diff --git a/build/libraries_sysmenu/acsign/ARM9/include/r_stdiag.h b/build/libraries_sysmenu/acsign/ARM9/include/r_stdiag.h new file mode 100644 index 00000000..fbe3d3ca --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/r_stdiag.h @@ -0,0 +1,98 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +/* + * *************************************************************************** + * + * Purpose: + * + * This file defines an API for performing stack diagnostics. + * + * It provides: + * Peek Stack Usage statistics + * To use it: + * 1. Build the library without "NO_R_DIAG" defined + * 2. Make a call to R_DIAG_set_stack_datum() prior to + * calling the first library function. + * 3. Add calls to the macro R_DIAG_CHECK_STACK where potential + * high stack usage points are. + * 4. Call R_DIAG_get_stack_low_water_mark() at then end of the + * library calls to return the maximum stack usage OR + * 5. Call R_DIAG_print_stack_depth() to display the peek stack + * usage + * + * + * + * History: + * 3-Aug-00 mjs development + * + * ************************************************************************** + */ + + +#ifndef HEADER_COMMON_R_STDIAG_H +#define HEADER_COMMON_R_STDIAG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NO_R_DIAG + +#ifdef NOPROTO +int R_DIAG_set_stack_datum(char *ptr); +int R_DIAG_check_stack(char *ptr, char *file, int line, int hit); +int R_DIAG_get_stack_low_water_mark(int *depth, char **file, int *line, + int *hit); +int R_DIAG_print_stack_depth(BIO *bio); + +#else + +int R_DIAG_set_stack_datum(); +int R_DIAG_check_stack(); +int R_DIAG_get_stack_low_water_mark(); +int R_DIAG_print_stack_depth(); + +#endif + +#define R_DIAG_CHECK_STACK {\ + char r_diag_stack_check_var = 0;\ + static int r_diag_stack_check_cnt = 0;\ +\ + R_DIAG_check_stack(&r_diag_stack_check_var, __FILE__,\ + __LINE__,++r_diag_stack_check_cnt);\ + } +#else +#define R_DIAG_CHECK_STACK +#endif + + +#ifdef __cplusplus +} +#endif +#endif /* HEADER_COMMON_R_STDIAG_H */ + diff --git a/build/libraries_sysmenu/acsign/ARM9/include/r_types.h b/build/libraries_sysmenu/acsign/ARM9/include/r_types.h new file mode 100644 index 00000000..f6514b13 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/r_types.h @@ -0,0 +1,257 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/** + * @file r_types.h + * This file contains the library structure and type definitions. + */ +#ifndef HEADER_COMMON_R_TYPES_H +#define HEADER_COMMON_R_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup DATA_MNG_FLAGS Data Management Flags + * This section lists the data management flags. + * @{ + */ + +/** + * @} + */ + +/* This gets set if the flags field if the we need to 'free' the + * R_RANDOM when we call R_rand_free(). If it is not set, the + * rand_ctrl will only be called to clean things up. + */ +#define R_RANDOM_FLG_MALLOCED 0x01 + +/* portable form of a random callback function */ +/** + * @typedef R_RANDOM + * The random object type. + */ +typedef struct r_random_st R_RANDOM; +/** + * This structure is used by the random object type. + */ +struct r_random_st +{ + /** + * A method function for generation of random data. + * + * @see R_rand_bytes(). + */ + int (*rand_bytes)(R_RANDOM *ctx,unsigned char *bytes,int len); + /** + * A method function for seeding of the random generator. + * @see R_rand_seed(). + */ + int (*rand_seed)(R_RANDOM *ctx,unsigned char *bytes,int len); + /** + * A method function for control of the random generator used by + * other functions as a single interface. + * + * @see R_rand_entropy_count(), R_rand_set_entropy_func(), + * R_rand_get_entropy_func(), R_rand_load_file(), R_rand_write_file() + * and R_rand_file_name(). + */ + int (*rand_ctrl)(R_RANDOM *ctx,int op,char *arg); + /** + * The data used by the random implementation. + */ + char *arg; + /** + * A method flag for used for keeping the state of the #R_RANDOM. + */ + int flags; /* normally set to zero */ +}; +/** + * @typedef R_SURRENDER + * The surrender function and argument. + */ +typedef struct r_surrender_st R_SURRENDER; +/** + * This structure provides a status update of a time intensive operation. It + * also allows you to abort the operation if required. + */ +struct r_surrender_st +{ + /* Return 0 to continue, non-zero to 'cancel' function */ + /** + * The surrender function pointer used as a generic method of + * passing user-defined callback or information collection functions. + */ + int (*callback)(R_SURRENDER *ctx,int function,int num); + /** + * The argument data used by the callback operation. + */ + char *arg; +}; + +typedef struct r_fixed_point_number_st R_FIXED_POINT_NUMBER; +struct r_fixed_point_number_st +{ + unsigned long hi; + unsigned long lo; +}; + +/** + * @typedef R_INDEXED_INFO + * This structure details the index containing information for get and set + * functions. + */ +typedef struct r_indexed_info_st R_INDEXED_INFO; +/** This structure details the index containing information for get and set + * functions. + */ +struct r_indexed_info_st +{ + /** The index into the list of the item to work with. */ + int index; + /** The data of the item in the list. */ + void *data; + /** The length of the data. */ + unsigned int len; + /** The data value as an integer. */ + int value; +}; + +/** + * @typedef R_ID_INFO + * The information to work with requires a second identity value to find it. + */ +typedef struct r_id_info_st R_ID_INFO; +/** The information to get or set requires a second information identifier. + * This type is used when calling set_info and get_info to get a number of + * information items in one call. + */ +struct r_id_info_st +{ + /** The information identifier. */ + int info_id; + /** The information data associated with the identifier. */ + void *value; +}; + +/** @defgroup R_FLAG_COPY_IDS Copy Flag Identifiers + * + * This section provides information on the copy mode. When data is passed + * to/from the library you can specify whether or not the copy should be done + * by value, by reference or by direct assignment. + * @ingroup DATA_MNG_FLAGS + * @{ + */ + +/** + * The copy flag. When data is passed to/from the library you can specify + * whether or not the copy should be done by value, by reference or + * by direct assignment. + */ +typedef int R_FLAG_COPY; + +/* + * action flag app lib + * obj_get BY_VAL F X + * BY_REF X F [app will not free "obj" until it is + * BY_ASSIGN F X finished with the returned reference] + * obj_set BY_VAL F X + * BY_REF F X [app will not free passed reference + * BY_ASSIGN X F until after it has freed "obj"] + * + * BY_REF makes the lifetime of the two objects linked and it is up to + * the application to manage the objects in a manner that preserves this + * relationship. + */ + +/** + * Indicates to copy by value. A complete clone of the object is made. + * The lifecycles of the two objects are independent. + */ +#define R_FLAG_COPY_BY_VALUE 0x0000 + +/** + * Indicates to copy by reference. A reference to the object is made. + * The lifecycles of objects sharing references are linked. + */ +#define R_FLAG_COPY_BY_REFERENCE 0x0001 + +/** + * Indicates to copy by assignment. The object is assigned to the required + * party. The caller does not keep a reference to the passed object. + */ +#define R_FLAG_COPY_BY_ASSIGN 0x0002 + +/** + * Indicates to copy using the default flag settings. + */ +#define R_FLAG_COPY_DEFAULT R_FLAG_COPY_BY_VALUE + +/** + * @} + */ + +/** @defgroup R_FLAG_SHARE_IDS Shared Flag Identifiers + * + * This section provides information on the shared flags available. + * @ingroup DATA_MNG_FLAGS + * @{ + */ + +/** + * The constructor flag. Indicates whether or not it is permissible to share + * the internal state between objects. + */ +typedef int R_FLAG_SHARE; + +/** + * Indicates to share nothing. The states of the two objects are completely + * separate. + */ +#define R_FLAG_SHARE_NONE 0x0000 + +/** + * Indicates to share data. Constructed objects may reference the state of + * the object from which it was constructed. The lifecycles of the two objects + * are linked. + */ +#define R_FLAG_SHARE_DATA 0x0001 + +/** Indicates the share default in which nothing is shared. */ +#define R_FLAG_SHARE_DEFAULT R_FLAG_SHARE_NONE + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/build/libraries_sysmenu/acsign/ARM9/include/sha.h b/build/libraries_sysmenu/acsign/ARM9/include/sha.h new file mode 100644 index 00000000..e1543a75 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/sha.h @@ -0,0 +1,105 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#ifndef HEADER_COMMON_SHA_H +#define HEADER_COMMON_SHA_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(CCONV) +#define CCONV +#endif + +#ifndef PRE_CCONV +#define PRE_CCONV +#endif + +#define SHA_CBLOCK 64 +#define SHA_LBLOCK 16 +#define SHA_BLOCK 16 +#define SHA_LAST_BLOCK 56 +#define SHA_LENGTH_BLOCK 8 +#define SHA_DIGEST_LENGTH 20 + +/* the default is to use unsigned long */ +#if !defined(OPT_SHA_INT) && !defined(OPT_SHA_LONG) +#define OPT_SHA_LONG +#endif + +#ifdef OPT_SHA_LONG +#define SHA_LONG unsigned long +#endif + +#ifdef OPT_SHA_INT +#define SHA_LONG unsigned int +#endif + +typedef struct sha_ctx_st SHA_CTX; + +struct sha_ctx_st + { + SHA_LONG h0,h1,h2,h3,h4; + SHA_LONG Nl,Nh; + SHA_LONG data[SHA_LBLOCK]; + int num; + void (PRE_CCONV CCONV *sha_block)(SHA_CTX *c, const unsigned char *W, + int num); + }; + +#ifndef NOPROTO +int SHA1_Setup(SHA_CTX *c, void (PRE_CCONV CCONV *sha_block)(SHA_CTX *c, + const unsigned char *W, int num)); +void SHA_Init(SHA_CTX *c); +void SHA_Update(SHA_CTX *c, const unsigned char *data, unsigned long len); +void SHA_Final(unsigned char *md, SHA_CTX *c); +unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md); +void SHA_Transform(SHA_CTX *c, const unsigned char *data); +void SHA1_Init(SHA_CTX *c); +void SHA1_Update(SHA_CTX *c, const unsigned char *data, unsigned long len); +void SHA1_Final(unsigned char *md, SHA_CTX *c); +unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md); +void SHA1_Transform(SHA_CTX *c, const unsigned char *data); +#else +void SHA_Init(); +void SHA_Update(); +void SHA_Final(); +unsigned char *SHA(); +void SHA_Transform(); +void SHA1_Init(); +void SHA1_Update(); +void SHA1_Final(); +unsigned char *SHA1(); +void SHA1_Transform(); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_COMMON_SHA_H */ diff --git a/build/libraries_sysmenu/acsign/ARM9/include/sha1.h b/build/libraries_sysmenu/acsign/ARM9/include/sha1.h new file mode 100644 index 00000000..692f2e9b --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/sha1.h @@ -0,0 +1,90 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * sha1.h + * + * Description: + * This is the header file for code which implements the Secure + * Hashing Algorithm 1 as defined in FIPS PUB 180-1 published + * April 17, 1995. + * + * Many of the variable names in this code, especially the + * single character names, were used because those were the names + * used in the publication. + * + * Please read the file sha1.c for more information. + * + */ + +#ifndef _SHA1_H_ +#define _SHA1_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _SHA_enum_ +#define _SHA_enum_ +enum +{ + shaSuccess = 0, + shaNull, /* Null pointer parameter */ + shaInputTooLong, /* input data too long */ + shaStateError /* called Input after Result */ +}; +#endif + +/* + * This structure will hold context information for the SHA-1 + * hashing operation + */ +typedef struct SHA1Context +{ + unsigned long Intermediate_Hash[20/4]; /* Message Digest */ + + unsigned long Length_Low; /* Message length in bits */ + unsigned long Length_High; /* Message length in bits */ + + int Message_Block_Index; /* Index into message block array */ + unsigned char Message_Block[64]; /* 512-bit message blocks */ + + int Computed; /* Is the digest computed? */ + int Corrupted; /* Is the message digest corrupted? */ +} SHA1Context; + +/* + * Function Prototypes + */ + +int SHA1Reset( SHA1Context *); +int SHA1Input( SHA1Context *, + const unsigned char *, + unsigned int); +int SHA1Result( SHA1Context *, + unsigned char Message_Digest[20]); + +#if defined( SHA1_TEST ) +int SHA1Test( ); +#endif // SHA1_TEST + + +#ifdef __cplusplus +} +#endif + +#endif // _SHA1_H_ diff --git a/build/libraries_sysmenu/acsign/ARM9/include/sha_locl.h b/build/libraries_sysmenu/acsign/ARM9/include/sha_locl.h new file mode 100644 index 00000000..10553ab4 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/include/sha_locl.h @@ -0,0 +1,290 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#ifndef HEADER_COMMON_SHA_LOCL_H +#define HEADER_COMMON_SHA_LOCL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef STANDALONE +#include "r_com.h" +#else +#if 0 //RSA +#include +#include +#include +#define Memcpy memcpy +#define Memset memset +#define Strcpy strcpy +#else //NITRO +#include "acmemory.h" +#define Malloc(a) ACMemory_Alloc(a) +#define Free(a) ACMemory_Free(a) +#define Memset(a,b,c) ACMemory_Memset(a,b,c) +#define Memcpy(a,b,c) ACMemory_Memcpy(a,b,c) +#endif +#endif + +#ifdef undef +/* one or the other must be defined */ +#ifndef SHA_1 /* FIPE 180-1 */ +#define SHA_0 /* FIPS 180 */ +#endif +#endif + +#define ULONG unsigned long +#define UCHAR unsigned char +#define UINT unsigned int + +#ifdef NOCONST +#define const +#endif + +#undef c2nl +#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ + l|=(((unsigned long)(*((c)++)))<<16), \ + l|=(((unsigned long)(*((c)++)))<< 8), \ + l|=(((unsigned long)(*((c)++))) )) + +#undef p_c2nl +#define p_c2nl(c,l,n) { \ + switch (n) { \ + case 0: l =((unsigned long)(*((c)++)))<<24; \ + case 1: l|=((unsigned long)(*((c)++)))<<16; \ + case 2: l|=((unsigned long)(*((c)++)))<< 8; \ + case 3: l|=((unsigned long)(*((c)++))); \ + } \ + } + +#undef c2nl_p +/* NOTE the pointer is not incremented at the end of this */ +#define c2nl_p(c,l,n) { \ + l=0; \ + (c)+=n; \ + switch (n) { \ + case 3: l =((unsigned long)(*(--(c))))<< 8; \ + case 2: l|=((unsigned long)(*(--(c))))<<16; \ + case 1: l|=((unsigned long)(*(--(c))))<<24; \ + } \ + } + +#undef p_c2nl_p +#define p_c2nl_p(c,l,sc,len) { \ + switch (sc) \ + { \ + case 0: l =((unsigned long)(*((c)++)))<<24; \ + if (--len == 0) break; \ + case 1: l|=((unsigned long)(*((c)++)))<<16; \ + if (--len == 0) break; \ + case 2: l|=((unsigned long)(*((c)++)))<< 8; \ + } \ + } + +#undef nl2c +#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16)&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ + *((c)++)=(unsigned char)(((l) )&0xff)) + +#undef c2l +#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ + l|=(((unsigned long)(*((c)++)))<< 8), \ + l|=(((unsigned long)(*((c)++)))<<16), \ + l|=(((unsigned long)(*((c)++)))<<24)) + +#undef p_c2l +#define p_c2l(c,l,n) { \ + switch (n) { \ + case 0: l =((unsigned long)(*((c)++))); \ + case 1: l|=((unsigned long)(*((c)++)))<< 8; \ + case 2: l|=((unsigned long)(*((c)++)))<<16; \ + case 3: l|=((unsigned long)(*((c)++)))<<24; \ + } \ + } + +#undef c2l_p +/* NOTE the pointer is not incremented at the end of this */ +#define c2l_p(c,l,n) { \ + l=0; \ + (c)+=n; \ + switch (n) { \ + case 3: l =((unsigned long)(*(--(c))))<<16; \ + case 2: l|=((unsigned long)(*(--(c))))<< 8; \ + case 1: l|=((unsigned long)(*(--(c)))); \ + } \ + } + +#undef p_c2l_p +#define p_c2l_p(c,l,sc,len) { \ + switch (sc) \ + { \ + case 0: l =((unsigned long)(*((c)++))); \ + if (--len == 0) break; \ + case 1: l|=((unsigned long)(*((c)++)))<< 8; \ + if (--len == 0) break; \ + case 2: l|=((unsigned long)(*((c)++)))<<16; \ + } \ + } + +#undef l2c +#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16)&0xff), \ + *((c)++)=(unsigned char)(((l)>>24)&0xff)) + +#ifdef OPT_SHA_B_ENDIAN +#define B_ENDIAN +#endif +#ifdef OPT_SHA_L_ENDIAN +#define L_ENDIAN +#endif + +#undef ROTATE +#if defined(WIN32) +#define ROTATE(a,n) _lrotl(a,n) +#else +#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) +#endif + +/* byte order reversal */ +#if defined(WIN32) +/* 5 instructions with rotate instruction, else 9 */ +#define Endian_Reverse32(a) \ + { \ + unsigned long l=(a); \ + (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ + } +#else +/* 6 instructions with rotate instruction, else 8 */ +#define Endian_Reverse32(a) \ + { \ + unsigned long l=(a); \ + l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ + (a)=ROTATE(l,16L); \ + } +#endif + +/* F() below can be + * simplified to the code in F_00_19. + * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) + * another tweak to be made + * in F_40_59, (x&a)|(y&a) -> (x|y)&a + */ +#define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) +#define F_20_39(b,c,d) ((b) ^ (c) ^ (d)) +#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) +#define F_60_79(b,c,d) F_20_39(b,c,d) + +#ifdef SHA_0 +#undef Xupdate +#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\ + (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]); +#endif +#ifdef SHA_1 +#undef Xupdate +#define Xupdate(a,i,ia,ib,ic,id) (a)=\ + (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\ + X[(i)&0x0f]=(a)=ROTATE((a),1); +#endif + +#define BODY_00_15(i,a,b,c,d,e,f,xa) \ + (f)=xa[i]+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_60_79(i,a,b,c,d,e,f,xa) \ + Xupdate(f,i,xa,xa,xa,xa); \ + (f)=X[(i)&0x0f]+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \ + (b)=ROTATE((b),30); + +/* + * The CodeWarrior compiler has a problem correctly expanding things like + * + * (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); + * + * so we separate this to 3 explicit adds, just for PalmOS. + */ +#ifndef UNDER_PALMOS + +#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \ + Xupdate(f,i,xa,xb,xc,xd); \ + (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \ + Xupdate(f,i,xa,xb,xc,xd); \ + (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_32_39(i,a,b,c,d,e,f,xa) \ + Xupdate(f,i,xa,xa,xa,xa); \ + (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_40_59(i,a,b,c,d,e,f,xa) \ + Xupdate(f,i,xa,xa,xa,xa); \ + (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#else /* UNDER_PALMOS */ + +#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \ + Xupdate(f,i,xa,xb,xc,xd); \ + (f)+=(e); \ + (f)+=K_00_19; \ + (f)+=ROTATE((a),5)+F_00_19((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \ + Xupdate(f,i,xa,xb,xc,xd); \ + (f)+=(e); \ + (f)+=K_20_39; \ + (f)+=ROTATE((a),5)+F_20_39((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_32_39(i,a,b,c,d,e,f,xa) \ + Xupdate(f,i,xa,xa,xa,xa); \ + (f)+=(e); \ + (f)+=K_20_39; \ + (f)+=ROTATE((a),5)+F_20_39((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_40_59(i,a,b,c,d,e,f,xa) \ + Xupdate(f,i,xa,xa,xa,xa); \ + (f)+=(e); \ + (f)+=K_40_59; \ + (f)+=ROTATE((a),5)+F_40_59((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#endif /* UNDER_PALMOS */ + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_COMMON_SHA_LOCL_H */ diff --git a/build/libraries_sysmenu/acsign/ARM9/src/acmemory.c b/build/libraries_sysmenu/acsign/ARM9/src/acmemory.c new file mode 100644 index 00000000..d97bac91 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/acmemory.c @@ -0,0 +1,335 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +// +// BNn֐p̃֘Au +// +#include +#include "acmemory.h" + +/* + head tail + | | | | + +--------+---------+----....----+---------+--------+ + |block |check |buffer |check |block | + +--------+---------+----....----+---------+--------+ + |4byte |4byte |Upper4(size)|4byte |4byte | + <------------------ 4 * n -------------------> + + block = n = (4 * 4 + Upper4(size)) / 4 + check = 0x0F5555F0Fgp^0x0FAAAAF0Fgp +*/ + +unsigned long aACMemoryPoolA[ 16 ]; +unsigned long aACMemoryPool[ 1024 * 32 / sizeof (unsigned long) ]; // 32K +unsigned long aACMemoryPoolB[ 16 ]; + +#define ACMEMORYPOOL_HEAD (aACMemoryPool) +#define ACMEMORYPOOL_TAIL (aACMemoryPool + sizeof aACMemoryPool / sizeof (unsigned long)) +#define ACMEMORYPOOL_SIZE ((unsigned long)ACMEMORYPOOL_TAIL - (unsigned long)ACMEMORYPOOL_HEAD) + +#define ACMEMORY_CHECK_BASE 0xF000000F +#define ACMEMORY_CHECK_FREE (0x00555500 | ACMEMORY_CHECK_BASE) +#define ACMEMORY_CHECK_USED (0x00AAAA00 | ACMEMORY_CHECK_BASE) + +#define ACMemory_Lower4( _size ) (((_size) ) & 0xFFFFFFFC) +#define ACMemory_Upper4( _size ) (((_size) + 3) & 0xFFFFFFFC) + +#define pACMemory_FromHeadToBody( _head ) ((unsigned long*)(((volatile unsigned long*)(_head)) + 2)) +#define pACMemory_FromBodyToHead( _body ) ((unsigned long*)(((volatile unsigned long*)(_body)) - 2)) +#define pACMemory_FromHeadToTail( _head ) ((unsigned long*)(((volatile unsigned long*)(_head)) + nACMemory_HeadBlock( _head ))) +#define pACMemory_FromTailToHead( _tail ) ((unsigned long*)(((volatile unsigned long*)(_tail)) - nACMemory_TailBlock( _tail ))) +#define nACMemory_HeadBlock( _head ) (((volatile unsigned long*)(_head))[+0]) +#define nACMemory_HeadCheck( _head ) (((volatile unsigned long*)(_head))[+1]) +#define nACMemory_TailBlock( _tail ) (((volatile unsigned long*)(_tail))[-1]) +#define nACMemory_TailCheck( _tail ) (((volatile unsigned long*)(_tail))[-2]) + + +static void *(*s_acsignAlloc)( u32 length ); +static void (*s_acsignFree)( void *ptr ); + +void ACSign_SetAllocFunc( void *(*pAlloc)( u32 ), void (*pFree)( void * ) ); +void ACSign_SetAllocFunc( void *(*pAlloc)( u32 ), void (*pFree)( void * ) ) +{ + s_acsignAlloc = pAlloc; + s_acsignFree = pFree; +} + + +//#define USE_OSALLOC +//#define USE_ACMEMORY_DEBUGDUMP +//#define USE_ACMEMORY_DEBUGFILL + +// +#if defined( USE_ACMEMORY_DEBUGDUMP ) +static +void acMemory_DebugDump( ) +{ + unsigned long* ptr = ACMEMORYPOOL_HEAD; + + // + OS_Printf( "----ACMemory_Dump [0x%.8x - 0x%.8x : 0x%.8x ]----\n", ACMEMORYPOOL_HEAD, ACMEMORYPOOL_TAIL, ACMEMORYPOOL_SIZE ); + + for ( ; (unsigned long)ptr < (unsigned long)ACMEMORYPOOL_TAIL; ) + { + OS_Printf( " [0x%.8x - 0x%.8x] (0x%.8x) <%c> ", + ptr, + pACMemory_FromHeadToTail( ptr ), + nACMemory_HeadBlock( ptr ), + nACMemory_HeadCheck( ptr ) == ACMEMORY_CHECK_USED ? '*' : '-' ); + + //OS_Printf( "0x%.8x 0x%.8x", nACMemory_HeadBlock( ptr ), nACMemory_HeadCheck( ptr ) ); + + //OS_Printf( " .... " ); + + ptr += nACMemory_HeadBlock( ptr ); + + //OS_Printf( "0x%.8x 0x%.8x", nACMemory_TailCheck( ptr ), nACMemory_TailBlock( ptr ) ); + + OS_Printf( "\n" ); + OS_PrintServer(); + } + ptr = 0; +} + +#define ACMemory_DebugDump( ) acMemory_DebugDump( ) + +#else + +#define ACMemory_DebugDump( ) + +#endif //USE_ACMEMORY_DEBUGDUMP + +// +#if defined( USE_ACMEMORY_DEBUGFILL ) +static +void acMemory_DebugFill( void* ptr, int cnt, int val ) +{ + (void)ACMemory_Memset( ptr, val, cnt ); +} + +#define ACMemory_DebugFill( _ptr, _cnt, _val ) acMemory_DebugFill( _ptr, _cnt, _val ) + +#else + +#define ACMemory_DebugFill( _ptr, _cnt, _val ) + +#endif //USE_ACMEMORY_DEBUGFILL + +// +void ACMemory_Clear( ) +{ + unsigned long* head = ACMEMORYPOOL_HEAD; + unsigned long* tail = ACMEMORYPOOL_TAIL; + unsigned long block; + unsigned long check; + + + block = ACMEMORYPOOL_SIZE / 4; + check = ACMEMORY_CHECK_FREE; + + nACMemory_HeadBlock( head ) = block; + nACMemory_HeadCheck( head ) = check; + nACMemory_TailBlock( tail ) = block; + nACMemory_TailCheck( tail ) = check; + + ACMemory_DebugFill( pACMemory_FromHeadToBody( head ), (block - 4) * 4, 0xFF ); + ACMemory_DebugDump( ); +} + +// +void* ACMemory_Alloc( u32 size ) +{ + if( s_acsignAlloc ) { + return s_acsignAlloc( size ); + } + return NULL; + + /* + #if defined( USE_OSALLOC ) + OSIntrMode nOSIntrMode; + void* alloc = NULL; + + nOSIntrMode = OS_DisableInterrupts( ); + alloc = OS_Alloc( size ); + (void)OS_RestoreInterrupts( nOSIntrMode ); + return alloc; + + #else + + unsigned long* head = ACMEMORYPOOL_HEAD; + unsigned long* tail = ACMEMORYPOOL_TAIL; + unsigned long block, oldblock, newblock; + unsigned long check, oldcheck, newcheck; + + if ( !size ) return 0; + + // + if ( size < 16 ) size = 16; + block = 4 + ACMemory_Upper4( size ) / 4; + check = ACMEMORY_CHECK_USED; + + // + for ( ; ; ) + { + if ( (unsigned long)head >= (unsigned long)tail ) + { + head = 0; + break; + } + + newblock = nACMemory_HeadBlock( head ); + newcheck = nACMemory_HeadCheck( head ); + if ( newcheck == check ) + { + head += newblock; + continue ; + } + if ( newblock < block + 4 + 4 ) + { + head += newblock; + continue ; + } + + break; + } + + if ( !head ) return 0; + + // + oldblock = nACMemory_HeadBlock( head ); + oldcheck = nACMemory_HeadCheck( head ); + + nACMemory_HeadBlock( head ) = block; + nACMemory_HeadCheck( head ) = check; + + tail = pACMemory_FromHeadToTail( head ); + nACMemory_TailBlock( tail ) = block; + nACMemory_TailCheck( tail ) = check; + + if ( (unsigned long)tail < (unsigned long)ACMEMORYPOOL_TAIL ) + { + nACMemory_HeadBlock( tail ) = oldblock - block; + nACMemory_HeadCheck( tail ) = oldcheck; + tail = pACMemory_FromHeadToTail( tail ); + nACMemory_TailBlock( tail ) = oldblock - block; + nACMemory_TailCheck( tail ) = oldcheck; + } + + // + (void)ACMemory_Memset( pACMemory_FromHeadToBody( head ), 0x00, (block - 4) * 4 ); + + ACMemory_DebugFill( pACMemory_FromHeadToBody( head ), (block - 4) * 4, 0x00 ); + ACMemory_DebugDump( ); + + return (void*)pACMemory_FromHeadToBody( head ); + #endif + */ +} + +// +void ACMemory_Free( void* adrs ) +{ + if( s_acsignFree ) { + s_acsignFree( adrs ); + } + /* + #if defined( USE_OSALLOC ) + OSIntrMode nOSIntrMode; + + nOSIntrMode = OS_DisableInterrupts( ); + OS_Free( adrs ); + (void)OS_RestoreInterrupts( nOSIntrMode ); + #else + + unsigned long* work; + unsigned long* head; + unsigned long* tail; + unsigned long block; + unsigned long check; + + + if ( !adrs ) return ; + + // + head = pACMemory_FromBodyToHead( adrs ); + tail = pACMemory_FromHeadToTail( head ); + block = nACMemory_HeadBlock( head ); + check = ACMEMORY_CHECK_FREE; + + // + if ( nACMemory_HeadBlock( head ) != nACMemory_TailBlock( tail ) ) + return ; + if ( nACMemory_HeadCheck( head ) != nACMemory_TailCheck( tail ) ) + return ; + + + // + if ( (unsigned long)head != (unsigned long)ACMEMORYPOOL_HEAD ) + { + work = pACMemory_FromTailToHead( head ); + if ( nACMemory_HeadCheck( work ) == check ) + { + block += nACMemory_HeadBlock( work ); + head = work; + } + } + // + if ( (unsigned long)tail != (unsigned long)ACMEMORYPOOL_TAIL ) + { + work = pACMemory_FromHeadToTail( tail ); + if ( nACMemory_TailCheck( work ) == check ) + { + block += nACMemory_TailBlock( work ); + tail = work; + } + } + + // + nACMemory_HeadBlock( head ) = nACMemory_TailBlock( tail ) = block; + nACMemory_HeadCheck( head ) = nACMemory_TailCheck( tail ) = check; + + ACMemory_DebugFill( pACMemory_FromHeadToBody( head ), (block - 4) * 4, 0xFF ); + ACMemory_DebugDump( ); + + #endif + */ +} + + +// +void* ACMemory_Memset( void* adrs, u32 val, u32 cnt ) +{ + if ( !adrs ) return 0; + MI_CpuFill8( (void*)adrs, (u8)val, (u32)cnt ); + return adrs; +} + +// +void* ACMemory_Memcpy( void* dst, void* src, u32 cnt ) +{ + if ( !dst || !src ) return 0; + MI_CpuCopy8( (const void*)src, (void*)dst, (u32)cnt ); + return dst; +} + + +void* ACMemory_Realloc( void *adrs, u32 nowsize, u32 newsize ) +{ +#pragma unused( adrs, nowsize, newsize ) + return NULL; +} diff --git a/build/libraries_sysmenu/acsign/ARM9/src/acsign.c b/build/libraries_sysmenu/acsign/ARM9/src/acsign.c new file mode 100644 index 00000000..89a528cd --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/acsign.c @@ -0,0 +1,453 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "acmemory.h" + +// SHA1 +#include "sha.h" +#include "sha1dgst.c" + +#define _DLENGTH_ (160/8) +#define _BLENGTH_ (512/8) + +#define HASHContext SHA_CTX + +#define HASHReset( _context ) (void)SHA1_Init( _context ) +#define HASHSetSource( _context, _ptr, _len ) (void)SHA1_Update( _context, _ptr, _len ) +#define HASHGetDigest( _context, _ptr ) (void)SHA1_Final( _ptr, _context ) + +// BN +#include "bn.h" + +#include "bn_lib.c" +#include "bn_asm.c" +#include "bn_comba.c" +#include "bn_lsh.c" +#include "bn_rsh.c" +#include "bn_word.c" +#include "bn_add.c" +#include "bn_mul.c" +#include "bn_div.c" +#include "bn_exp.c" +#include "bn_sqr.c" +#include "bn_fm_w.c" +#include "bn_gcd.c" +#include "bn_ex_str.c" +#include "bn_ms_w.c" +//#include "bn_me.c" +#include "bn_rec.c" +#include "bn_mont.c" +#include "bn_recp.c" +#include "bn_wdiv.c" +#include "bn_r_exp.c" +#include "bn_m_exp.c" + + +#if !defined( RSA_ENC_DEC ) + +#define BER_NULL 5 +#define BER_OBJECT 6 +#define BER_SEQUENCE 16 +#define BER_OCTET_STRING 4 +#define BER_CONSTRUCTED 0x20 + + +// +// rsa_padding_check_pkcs1_type_1֐ +// +static +int decode_padding( unsigned char* pdst_adrs, unsigned int* pdst_size, + unsigned char* psrc_adrs, unsigned int nsrc_size, + int length ) +{ + unsigned char* p; + unsigned char* q; + unsigned char* pe; + int i; + + if (nsrc_size >= length ) + return 0; + + /* The leading 0 was removed by the bignum->bin conversion */ + if (nsrc_size < 10) + return 0; + + p = psrc_adrs; + pe = &(psrc_adrs[nsrc_size]); + /* if (p[0] != 0) goto err; */ + if ( p[0] != 1 ) + return 0; + p++; + + for ( i = 0; i < 8; i++ ) + { + if ( *(p++) != 0xFF ) + return 0; + } + for ( ; p != pe; p++ ) + { + if ( *p != 0xFF ) + break; + } + if ( p == pe ) + return 0; + + if ( *(p++) != 0 ) + return 0; + + *pdst_size = (unsigned int)((int)pe - (int)p); + q = pdst_adrs; + while ( p != pe ) + *(q++)= *(p++); + + return 1; +} + +// +// +// +static +int pk_skip( unsigned char **datap, unsigned int *dlenp, + unsigned char type, unsigned int *lenp) +{ + unsigned char *data = *datap; + unsigned int dlen = *dlenp; + unsigned int len = 0; + unsigned char l; + + if (*(data++) != type) + return 0; + + if (dlen < 1) + return 0; + dlen--; + + if ( (*data & 0x80) != 0 ) + { + l = (unsigned char)( *data & 0x7F ); + if (dlen < (unsigned int)l + 1) + return 0; + dlen -= l; + if (lenp != NULL) + { + data++; + do + { + len <<= 7; + len += (*data & 0x7f); + l--; + } + while (l > 0); + } + else + { + data += l; + } + } + else + { + len = *data; + data++; + if (dlen < 1) + return 0; + dlen--; + } + + *datap = data; + *dlenp = dlen; + if (lenp != NULL) + { + *lenp = len; + } + + return 1; +} + +// +// PK_decode_sighash֐ +// +static +int decode_sighash( unsigned char* data, unsigned int dlen, + unsigned char** ppdgst_adrs, unsigned int* pdgst_size, + unsigned char** pphash_adrs, unsigned int* phash_size ) +{ + #if 0 + /* 01 */ OB_cmpu(BER_SEQUENCE, 0, 0), + /* 02 */ OB_down(0, 1), + /* 03 */ OB_cmpu(BER_SEQUENCE, 0, 0), + /* 04 */ OB_down(0, 1), + /* 05 */ OB_cmpu(BER_OBJECT, 0, 0), + /* 06 */ OB_call(OB_F_SET, PK_TYPE_SIG, PK_SIG_DIGEST_OID), + + /* go up a level - we got all we need out of the + * sequence that contains the parameters + * - we could OB_next(0,1) and check that we have BER_NULL + * as then next item but there is no real need to do that + */ + + /* 07 */ OB_up(0, 1), + /* 08 */ OB_next(0, 1), + /* 09 */ OB_cmpu(BER_OCTET_STRING, 0, 0), + /* 10 */ OB_call(OB_F_SET, PK_TYPE_SIG, PK_SIG_HASH), + + /* 11 */ OB_exit(0), + /* 12 */ OB_FINISH, + #endif + + unsigned int len; + + if ( !pk_skip(&data, &dlen, (BER_SEQUENCE|BER_CONSTRUCTED), NULL) ) + return 0; + + if ( !pk_skip(&data, &dlen, (BER_SEQUENCE|BER_CONSTRUCTED), NULL) ) + return 0; + + if ( !pk_skip(&data, &dlen, (BER_OBJECT), &len) ) + return 0; + + /* + if (digest != NULL) + { + digest->adrs = data; + digest->size = len; + } + */ + if ( ppdgst_adrs ) *ppdgst_adrs = data; + if ( pdgst_size ) *pdgst_size = len; + + data += len; + if (dlen < len) + return 0; + dlen -= len; + + if ( !pk_skip(&data, &dlen, BER_NULL, &len) ) + return 0; + data += len; + if (dlen < len) + return 0; + dlen -= len; + + if ( !pk_skip(&data, &dlen, (BER_OCTET_STRING), &len) ) + return 0; + + /* + if (hash != NULL) + { + hash->adrs = data; + hash->size = len; + } + */ + if ( pphash_adrs ) *pphash_adrs = data; + if ( phash_size ) *phash_size = len; + + return 1; +} + +#endif + + + + +// +#define SGN_LEN 128 +#define MOD_LEN 128 +#define EXP_LEN 3 + +int ACSign_Decrypto( + void* buffer, // o͗̈ + void* sgn_ptr, // f[^ւ̃|C^ + void* key_ptr // L[ւ̃|C^ + ) +{ + BN_CTX* ctx; + BIGNUM src, dst, exp, mod; + void* exp_ptr; + void* mod_ptr; + int nTmp, nWrk; + unsigned char* pAdrs = 0; + unsigned int nSize = 0; + unsigned long nDummyExp = 0x00010001; // 65537Œ + unsigned long aBufferA[ 256 / sizeof (unsigned long) ]; + unsigned long aBufferB[ 256 / sizeof (unsigned long) ]; + + + if ( !buffer ) return 0; + if ( !sgn_ptr ) return 0; + if ( !key_ptr ) return 0; + + // +// ACMemory_Clear( ); + + // + exp_ptr = &nDummyExp; + mod_ptr = key_ptr; + + (void)ACMemory_Memset( aBufferA, 0, sizeof aBufferA ); + (void)ACMemory_Memset( aBufferB, 0, sizeof aBufferB ); + + ctx=BN_CTX_new(); + + BN_init( &src ); + BN_init( &dst ); + BN_init( &exp ); + BN_init( &mod ); + + (void)BN_bin2bn( sgn_ptr, SGN_LEN, &src ); + (void)BN_bin2bn( exp_ptr, EXP_LEN, &exp ); + (void)BN_bin2bn( mod_ptr, MOD_LEN, &mod ); + + nTmp = BN_mod_exp( &dst, &src, &exp, &mod, ctx ); + + nTmp = BN_bn2bin( &dst, (unsigned char*)aBufferA ); + + BN_free( &src ); + BN_free( &dst ); + BN_free( &exp ); + BN_free( &mod ); + + if (ctx != NULL) + BN_CTX_free(ctx); + + #if defined( RSA_ENC_DEC ) + + pAdrs = (unsigned char*)aBufferA + 4; //_~[SoCg͓ǂݔ΂ + nSize = nTmp; + + (void)ACMemory_Memcpy( buffer, pAdrs, _DLENGTH_ * 4 ); + + #else + + if ( !decode_padding( (unsigned char*)aBufferB, (unsigned int*)&nWrk, (unsigned char*)aBufferA, (unsigned int )nTmp, SGN_LEN ) ) + return 0; + if ( !decode_sighash( (unsigned char*)aBufferB, (unsigned int)nWrk, NULL, NULL, (unsigned char**)&pAdrs, (unsigned int*)&nSize ) ) + return 0; + if ( nSize != _DLENGTH_ ) + return 0; + + (void)ACMemory_Memcpy( buffer, pAdrs, _DLENGTH_ * 1 ); + + #endif + + return 1; +} + + +// +#define ROMH_SIZE 0x0160 +int ACSign_Digest( + void* buffer, // o͗̈ + void* romh_ptr, // f[^ւ̃|C^ + void* mbin_ptr, // f[^ւ̃|C^ + int mbin_len, // f[^̒ + void* sbin_ptr, // f[^ւ̃|C^ + int sbin_len, // f[^̒ + u32 serial_num // VAio[ + ) +{ + #if defined( RSA_ENC_DEC ) + HASHContext context; + + + if ( !buffer ) return 0; + if ( !romh_ptr ) return 0; + if ( !mbin_ptr || !mbin_len ) return 0; + if ( !sbin_ptr || !sbin_len ) return 0; + + + HASHReset( &context ); + HASHSetSource( &context, romh_ptr, ROMH_SIZE ); + HASHGetDigest( &context, (unsigned char*)buffer + _DLENGTH_ * 0 ); + + HASHReset( &context ); + HASHSetSource( &context, mbin_ptr, mbin_len ); + HASHGetDigest( &context, (unsigned char*)buffer + _DLENGTH_ * 1 ); + + HASHReset( &context ); + HASHSetSource( &context, sbin_ptr, sbin_len ); + HASHGetDigest( &context, (unsigned char*)buffer + _DLENGTH_ * 2 ); + + HASHReset( &context ); + HASHSetSource( &context, buffer, _DLENGTH_ * 3 ); + HASHGetDigest( &context, (unsigned char*)buffer + _DLENGTH_ * 3 ); + + #else + + HASHContext context; + unsigned char aBuffer[ (_DLENGTH_ * 3 + sizeof (unsigned long)) ]; + + if ( !buffer ) return 0; + if ( !romh_ptr ) return 0; + if ( !mbin_ptr || !mbin_len ) return 0; + if ( !sbin_ptr || !sbin_len ) return 0; + + HASHReset( &context ); + HASHSetSource( &context, romh_ptr, ROMH_SIZE ); + HASHGetDigest( &context, (unsigned char*)aBuffer + _DLENGTH_ * 0 ); + + HASHReset( &context ); + HASHSetSource( &context, mbin_ptr, mbin_len ); + HASHGetDigest( &context, (unsigned char*)aBuffer + _DLENGTH_ * 1 ); + + HASHReset( &context ); + HASHSetSource( &context, sbin_ptr, sbin_len ); + HASHGetDigest( &context, (unsigned char*)aBuffer + _DLENGTH_ * 2 ); + + // VAԍ ͂OŒ + aBuffer[ (_DLENGTH_ * 3) + 0 ] = (unsigned char)((serial_num >> 0) & 0xFF); + aBuffer[ (_DLENGTH_ * 3) + 1 ] = (unsigned char)((serial_num >> 8) & 0xFF); + aBuffer[ (_DLENGTH_ * 3) + 2 ] = (unsigned char)((serial_num >> 16) & 0xFF); + aBuffer[ (_DLENGTH_ * 3) + 3 ] = (unsigned char)((serial_num >> 24) & 0xFF); + + HASHReset( &context ); + HASHSetSource( &context, (unsigned char*)aBuffer, _DLENGTH_ * 3 + sizeof (unsigned long) ); + HASHGetDigest( &context, (unsigned char*)buffer ); + #endif + return 1; +} + + +// +int ACSign_Compare( + void* decrypto, // ACSign_Decryptȍo + void* digest // ACSign_Digest̏o + ) +{ + unsigned char* ptrA = (unsigned char*)decrypto; + unsigned char* ptrB = (unsigned char*)digest; + int loop; + int test = 1; + + if ( !decrypto ) return 0; + if ( !digest ) return 0; + + #if defined( RSA_ENC_DEC ) + for ( loop = 0; loop < _DLENGTH_ * 4; loop++ ) + #else + for ( loop = 0; loop < _DLENGTH_ * 1; loop++ ) + #endif + { + if ( *ptrA++ != *ptrB++ ) + { + test = 0; + break; + } + } + return test; +} + + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/acsign_encrypt.c b/build/libraries_sysmenu/acsign/ARM9/src/acsign_encrypt.c new file mode 100644 index 00000000..5d524254 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/acsign_encrypt.c @@ -0,0 +1,187 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "acmemory.h" +#include "ber.h" + +// SHA1 +#include "sha.h" + +#define _DLENGTH_ (160/8) +#define _BLENGTH_ (512/8) + +#define HASHContext SHA_CTX + +#define HASHReset( _context ) (void)SHA1_Init( _context ) +#define HASHSetSource( _context, _ptr, _len ) (void)SHA1_Update( _context, _ptr, _len ) +#define HASHGetDigest( _context, _ptr ) (void)SHA1_Final( _ptr, _context ) + +// BN +#include "bn.h" +#include "bn_lcl.h" + +#define BER_NULL 5 +#define BER_OBJECT 6 +#define BER_SEQUENCE 16 +#define BER_OCTET_STRING 4 +#define BER_CONSTRUCTED 0x20 + + +// RSAL[\vf̃p[^ +typedef struct KeyParam { + u8 *pData; + int length; +}KeyParam; + +static BOOL GetRSAPrivateKeyParam( const u8 *pKeyDER, KeyParam *pMod, KeyParam *pPrvExp ); + + +// +// rsa_padding_add_pkcs1_type_1֐ +// +static int add_padding(unsigned char *out, + int out_len, const unsigned char *in, int in_len) +{ + unsigned char *p; + int j,i; + + if ((in_len+11) > out_len) + return(1); + + /* First we copy data bytes to the output buffer, this + * way the input and output buffers can be the same + * and things will still work */ + p=out+out_len-in_len; + for (i=in_len-1; i>=0; i--) + p[i]=in[i]; + p=out; + *(p++)=0; + *(p++)=1; /* Private Key BT (Block Type) */ + + /* pad with 0xff data */ + j=out_len-3-in_len; + Memset(p,0xff,(u32)j); + p[j]='\0'; + return(0); +} + + +// +// RSA +// +#define ACS_ENCRYPTED_SIGN_LEN 128 +BOOL ACSign_Encrypto(void *sign, const void *key, const void *data, int length) +{ + BN_CTX *ctx; + BIGNUM src, dst, exp, mod; + u8 buf[ACS_ENCRYPTED_SIGN_LEN]; + int len = length; + BOOL result = TRUE; + KeyParam key_mod; + KeyParam key_prvExp; + + if (NULL == sign || NULL == key || NULL == data || 0 > length) { + return FALSE; + } + + if( !GetRSAPrivateKeyParam( key, &key_mod, &key_prvExp ) ) { + OS_TPrintf( "RSA PrivKey Param get failed.\n" ); + return FALSE; + } + + + if ( add_padding( buf, ACS_ENCRYPTED_SIGN_LEN, data, length ) ) { + OS_TPrintf("encode_padding was failed.\n"); + result = FALSE; + goto end; + } + + + ctx = BN_CTX_new(); + + BN_init(&src); + BN_init(&dst); + BN_init(&exp); + BN_init(&mod); + + BN_bin2bn((u8*)buf, ACS_ENCRYPTED_SIGN_LEN, &src); + BN_bin2bn(key_prvExp.pData, key_prvExp.length, &exp); + BN_bin2bn(key_mod.pData, key_mod.length, &mod); + + BN_mod_exp( &dst, &src, &exp, &mod, ctx ); + + { // BIGNUM͍ŏʂ"0"̎A炳̂ŁA炩ߒĂ + u8 *pSign = sign; + int padLen = ACS_ENCRYPTED_SIGN_LEN - BN_num_bytes( &dst ); + while( ( padLen > 0 ) && ( padLen < ACS_ENCRYPTED_SIGN_LEN ) ) { + *pSign++ = 0; + padLen--; + } + + len = BN_bn2bin( &dst, pSign ); + } + + BN_free(&src); + BN_free(&dst); + BN_free(&exp); + BN_free(&mod); + + if (ctx) { + BN_CTX_free(ctx); + } + + if ( len > ACS_ENCRYPTED_SIGN_LEN ) { // TCY`FbNB + OS_TPrintf( "len = %d\n", len ); + result = FALSE; + goto end; + } +end: + return result; +} + + +// DERtH[}bgRSA PublicKeyp[^擾 +static BOOL GetRSAPrivateKeyParam( const u8 *pKeyDER, KeyParam *pMod, KeyParam *pPrvExp ) +{ + BOOL retval = FALSE; + BER_ITEMS_SK sk; + BER_ITEMS *bi; + BER_ITEM item; + + // 擪ACeAt@CŜ̃TCYZo + if( BER_read_item( &item, (unsigned char *)pKeyDER, 16 ) ) { + return FALSE; + } + + BER_ITEMS_SK_init( &sk, NULL, 0, 0 ); + if( BER_parse( &sk, (unsigned char *)pKeyDER, item.data.len + item.hlen, NULL ) == BER_OK ) { + bi = BER_ITEMS_SK_items( &sk, 2 ); // mod + pMod->pData = bi->item.data.bytes; + pMod->length = (int)bi->item.data.len; + + bi = BER_ITEMS_SK_items( &sk, 4 ); // private exp + pPrvExp->pData = bi->item.data.bytes; + pPrvExp->length = (int)bi->item.data.len; + + retval = TRUE; + } + BER_ITEMS_SK_free( &sk ); + + return retval; +} + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/acsign_util.c b/build/libraries_sysmenu/acsign/ARM9/src/acsign_util.c new file mode 100644 index 00000000..0dd8ee07 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/acsign_util.c @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include + +#define AUTH_KEY_BUFFER_LEN 128 +#define MB_AUTH_SIGN_SIZE (128) /* digital sign size */ + + +typedef struct MbAuthCode +{ + char magic_code[2]; // }WbNio[ + u16 version; // o[W + u8 sign[MB_AUTH_SIGN_SIZE]; // + u32 serial_number; // VAԍ +} MbAuthCode; // 16byte + + + +static u8 key_buffer[AUTH_KEY_BUFFER_LEN] = { + 0x9E,0xC1,0xCC,0xC0,0x4A,0x6B,0xD0,0xA0,0x6D,0x62,0xED,0x5F,0x15,0x67,0x87,0x12, + 0xE6,0xF4,0x77,0x1F,0xD8,0x5C,0x81,0xCE,0x0C,0xD0,0x22,0x31,0xF5,0x89,0x08,0xF5, + 0xBE,0x04,0xCB,0xC1,0x4F,0x63,0xD9,0x5A,0x98,0xFF,0xEB,0x36,0x0F,0x9C,0x5D,0xAD, + 0x15,0xB9,0x99,0xFB,0xC6,0x86,0x2C,0x0A,0x0C,0xFC,0xE6,0x86,0x03,0x60,0xD4,0x87, + 0x28,0xD5,0x66,0x42,0x9C,0xF7,0x04,0x14,0x4E,0x6F,0x73,0x20,0xC3,0x3E,0x3F,0xF5, + 0x82,0x2E,0x78,0x18,0xD6,0xCD,0xD5,0xC2,0xDC,0xAA,0x1D,0x34,0x91,0xEC,0x99,0xC9, + 0xF7,0xBF,0xBF,0xA0,0x0E,0x1E,0xF0,0x25,0xF8,0x66,0x17,0x54,0x34,0x28,0x2D,0x28, + 0xA3,0xAE,0xF0,0xA9,0xFA,0x3A,0x70,0x56,0xD2,0x34,0xA9,0xC5,0x9E,0x5D,0xF5,0xE1 +}; + + +int ACSignDecrpto(void *output_buffer, MBDownloadFileInfo *download_file_info_buf) +{ + return ACSign_Decrypto(output_buffer, + ((MbAuthCode *)(download_file_info_buf->auth_code))->sign, + key_buffer); +} + + +int ACSignDigest(void *input_buffer, MBDownloadFileInfo *download_file_info_buf) +{ + int ret_code; + u8 digest_output_buffer[AUTH_BUFFER_LEN]; + + ret_code = ACSign_Digest((void *)digest_output_buffer, // o͗̈ 20 Bytes + (void *)(download_file_info_buf->seg[0].recv_addr), + (void *)(download_file_info_buf->seg[1].recv_addr), + (int)(download_file_info_buf->seg[1].size), + (void *)(download_file_info_buf->seg[2].recv_addr), + (int)(download_file_info_buf->seg[2].size), + ((MbAuthCode *)(download_file_info_buf)->auth_code)->serial_number // serial_number + ); + if( ret_code == 0 ) + { + return ret_code; // failure + } + + return ACSign_Compare( + input_buffer, // ACSign_Decryptȍo + (void*)digest_output_buffer // ACSign_Digest̏o + ); +} + +#if 0 +void* doAlloc( int size ) +{ + OSIntrMode nOSIntrMode; + void* alloc = NULL; + + nOSIntrMode = OS_DisableInterrupts( ); + alloc = OS_Alloc( size ); + (void)OS_RestoreInterrupts( nOSIntrMode ); + return alloc; +} + +void doFree( void* adrs ) +{ + OSIntrMode nOSIntrMode; + + nOSIntrMode = OS_DisableInterrupts( ); + OS_Free( adrs ); + (void)OS_RestoreInterrupts( nOSIntrMode ); +} + +void* doMemset( void* adrs, int val, int cnt ) +{ + return memset( adrs, val, cnt ); +} + +void* doMemcpy( void* dst, void* src, int cnt ) +{ + return memcpy( dst, src, cnt ); +} + +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/ber_isk.c b/build/libraries_sysmenu/acsign/ARM9/src/ber_isk.c new file mode 100644 index 00000000..77137220 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/ber_isk.c @@ -0,0 +1,295 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - makerom.TWL + File: ber_isk.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$ + *---------------------------------------------------------------------------*/ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "ber_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BER_ITEMS_SK_INIT +#define SPLIT_BER_ITEMS_SK_GET +#define SPLIT_BER_ITEMS_APPEND +#define SPLIT_BER_ITEMS_UNDER +#define SPLIT_BER_ITEMS_SK_GROW +#define SPLIT_BER_ITEMS_SK_FREE +#endif /* NO_SPLIT */ + +/* BER_ITEMS_SK_EXPAND_COUNT - number of items to expand to given that + * there are "X" items currently. + * + * note: each item typically costs 28 bytes so 20 is around .5k which + * is a reasonable growth size + */ +#define BER_ITEMS_SK_EXPAND_COUNT(X) ((X)+20) + +#ifdef SPLIT_BER_ITEMS_SK_INIT +/** + * Initialises the stack of BER items. The array of items, the current number + * of items and the maximum number of items allocated may be set. + * + * @param sk [In] A stack of BER items. + * @param items [In] An array of BER items. + * @param num [In] The number of BER items in the array. + * @param max [In] The number of BER items allocated in the array. + */ +void BER_ITEMS_SK_init(BER_ITEMS_SK *sk, BER_ITEMS *items, unsigned int num, + unsigned int max) +{ + sk->num=num; + sk->max=max; + if (items == NULL) + { + sk->flags=BER_FLAG_DYNAMIC_ITEMS; + } + else + { + sk->flags=0; + } + sk->items=items; + +#ifndef NO_STREAM + sk->state=BER_STATE_READ_NEXT_ITEM; + sk->inf=0; + sk->pinf=0; + sk->con=0; + sk->down=1; + sk->this_idx=-1; + sk->next=NULL; +#endif /* !NO_STREAM */ +} +#endif /* SPLIT_BER_ITEMS_SK_INIT */ + +#ifdef SPLIT_BER_ITEMS_SK_GET +/** + * Obtains the next available BER item in the stack. + * + * @param sk [In] Stack of BER items. + * @param index [Out] Index into array of new item. + * @return Indication of successful completion of function. + * Values are: + *
  • 0 indicates the function succeeded.
  • + *
  • >0 indicates the function failed.
  • + * + * @note If there is no item available in the array then the array is grown. + * This means that an existing external pointer to an item may not be + * valid after a call to this function. + */ +int BER_ITEMS_SK_get(BER_ITEMS_SK *sk, int *index) +{ + int ret; /* return value */ + BER_ITEMS *it; /* next item */ + + /* Ensure there are enough spare items. */ + if (sk->num >= sk->max) + { + /* Reallocate the array. */ + ret = BER_ITEMS_SK_grow(sk, BER_ITEMS_SK_EXPAND_COUNT(sk->num)); + if (ret != 0) + { + return(ret); + } + } + + /* Set the new item index for return. */ + *index = (int)sk->num; + + /* Initialize the new item. */ + it = &(sk->items[sk->num++]); + Memset((char *)it, 0, sizeof(BER_ITEMS)); + + /* return success */ + return(0); +} + +#endif /* SPLIT_BER_ITEMS_SK_GET */ + +#ifdef SPLIT_BER_ITEMS_APPEND +/** + * Places the BER item b next to the BER item a in the tree + * structure. + * + * @param a [In] A BER item. + * @param b [In] A BER item. + */ +void BER_ITEMS_append(a,b) +BER_ITEMS *a,*b; +{ + b->parent=a->parent; + if (b->parent != NULL) + { + b->parent->item.flags|=BER_FLAG_INVALID_LENGTH; + } + b->next=a->next; + a->next=b; +} +#endif /* SPLIT_BER_ITEMS_APPEND */ + +#ifdef SPLIT_BER_ITEMS_UNDER +/** + * Places the BER item b below the BER item a in the tree + * structure. + * + * @param a [In] A BER item. + * @param b [In] A BER item. + * + * @return An indication of success:
    + *
  • 0 indicates success
  • + *
  • >0 indicates failure
  • + */ +int BER_ITEMS_under(BER_ITEMS *a, BER_ITEMS *b) +{ + if (!(BER_constructed(&a->item) || BER_hide_contents(&a->item))) + { + return(BER_ERR_NOT_CONSTRUCTED); + } + b->parent=a; + b->next=a->down; + a->down=b; + + a->item.flags|=BER_FLAG_INVALID_LENGTH; + return(0); +} +#endif /* SPLIT_BER_ITEMS_UNDER */ + +#ifdef SPLIT_BER_ITEMS_SK_GROW +/** + * Grows the number of allocated BER items. + * + * @param sk [In] A stack of BER items. + * @param num [In] The number of BER items to allocate. + * + * @return An indication of success:
    + *
  • 0 indicates success
  • + *
  • >0 indicates failure
  • + */ +int BER_ITEMS_SK_grow(BER_ITEMS_SK *sk, unsigned int num) +{ + int ptr_fix; + unsigned int i; + unsigned int j; + BER_ITEMS *nai; + BER_ITEMS *oai; + BER_ITEMS *oend; + + if (num <= sk->num) + { + return(0); + } + + if (sk->flags & BER_FLAG_DYNAMIC_ITEMS) + { + if (sk->items == NULL) + { + ptr_fix=0; + nai=(BER_ITEMS *)Malloc(sizeof(BER_ITEMS)*num); + if (nai == NULL) + { + return(BER_ERR_OUT_OF_MEMORY); + } + Memset(nai,0,sizeof(BER_ITEMS)*num); + } + else + { + ptr_fix=1; + nai=(BER_ITEMS *)Realloc(sk->items, sizeof(BER_ITEMS)*num, + sizeof(BER_ITEMS)*sk->max); + if (nai == NULL) + { + return(BER_ERR_OUT_OF_MEMORY); + } + Memset(&(nai[sk->max]),0, sizeof(BER_ITEMS)*(num-sk->max)); + } + if (nai == NULL) + { + return(BER_ERR_OUT_OF_MEMORY); + } + + /* If we have realloced, and the Memory has moved, we + * need to fix the pointers */ + if ((sk->items != nai) && ptr_fix) + { + oai=sk->items; + oend= &(sk->items[sk->num]); + for (i=0; inum; i++) + { + if ((nai[i].parent >= oai) && + (nai[i].parent <= oend)) + { + j=(unsigned int)( nai[i].parent-oai ); + nai[i].parent= &(nai[j]); + } + if ((nai[i].next >= oai) && + (nai[i].next <= oend)) + { + j=(unsigned int)( nai[i].next-oai ); + nai[i].next= &(nai[j]); + } + if ((nai[i].down >= oai) && + (nai[i].down <= oend)) + { + j=(unsigned int)( nai[i].down-oai ); + nai[i].down= &(nai[j]); + } + } + } + + sk->max=num; + sk->items=nai; + return(0); + } + + return(BER_ERR_OUT_OF_ITEMS_STORAGE); +} +#endif /* SPLIT_BER_ITEMS_SK_GROW */ + +#ifdef SPLIT_BER_ITEMS_SK_FREE +void BER_ITEMS_SK_free(sk) +BER_ITEMS_SK *sk; + { + unsigned int i; + + for (i=0; imax; i++) + { + if ((sk->items[i].item.data.bytes != NULL) && + (sk->items[i].item.flags & BER_FLAG_DYNAMIC)) + { + Free(sk->items[i].item.data.bytes); + sk->items[i].item.data.bytes=NULL; + } + } + if ((sk->flags & BER_FLAG_DYNAMIC_ITEMS) && (sk->items != NULL)) + { + Free(sk->items); + sk->items=NULL; + } + sk->num=0; + if (sk->flags & BER_FLAG_DYNAMIC) + Free(sk); + } +#endif /* SPLIT_BER_ITEMS_SK_FREE */ + +#endif /* !(defined(NO_SPLIT) && defined(SPLIT_FILE)) */ diff --git a/build/libraries_sysmenu/acsign/ARM9/src/ber_lib.c b/build/libraries_sysmenu/acsign/ARM9/src/ber_lib.c new file mode 100644 index 00000000..6bd4ed0a --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/ber_lib.c @@ -0,0 +1,437 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - makerom.TWL + File: ber_lib.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$ + *---------------------------------------------------------------------------*/ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "ber_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BER_NUM_BITS +#define SPLIT_BER_ITEM_CMP_BYTES +#define SPLIT_BER_ITEM_CMP_TAG +#define SPLIT_BER_ITEM_INIT +#define SPLIT_BER_ITEMS_INIT +#define SPLIT_BER_ITEM_SET_ALL +#define SPLIT_BER_ITEM_SET_HEADER +#define SPLIT_BER_ITEM_SET_PREFIX_BYTE +#define SPLIT_BER_ITEM_SET_DATA +#define SPLIT_BER_READ_ITEM +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BER_NUM_BITS +/** + * Calculates the number of used bits in a buffer bytes. This function is + * useful when dealing with a BER item that is a bit string. + * + * @param buf [In] The buffer of data. + * @param len [In] The length of the buffer in bytes. + * @param bigendian [In] Indicates that the bits in the data is order in + * big endian order. + * + * @return The number of bits. + */ +int R_num_bits(unsigned char *buf, int len, int bigendian) +{ + int ret; + int i; + int j; + int inc; + int c; + + if (len == 0) + { + return(0); + } + if (bigendian) + { + inc = 1; + j = 0; + } + else + { + j = len - 1; + inc = -1; + } + + ret = (len-1)*8; + for (i = 0; i < len; i++) + { + c = buf[j]; + if (c == 0) + { + ret -= 8; + j += inc; + } + else + { + if (c & 0x80) + { + return(ret+8); + } + if (c & 0x40) + { + return(ret+7); + } + if (c & 0x20) + { + return(ret+6); + } + if (c & 0x10) + { + return(ret+5); + } + if (c & 0x08) + { + return(ret+4); + } + if (c & 0x04) + { + return(ret+3); + } + if (c & 0x02) + { + return(ret+2); + } + /* if (c & 0x01) */ + { + return(ret+1); + } + } + } + return(0); +} +#endif /* SPLIT_BER_NUM_BITS */ + + +#ifdef SPLIT_BER_ITEM_CMP_BYTES +/** + * Compares the data bytes of the BER item with the data of the buffer. + * + * @param a [In] A BER item. + * @param d [In] A buffer of data. + * @param l [In] The length of the data. + * + * @return Indication of a match:
    + *
  • 0 indicates a match
  • + *
  • BER_ERR_CMP_BYTES indicates no match
  • + */ +int BER_ITEM_cmp_bytes(BER_ITEM *a, unsigned char *d, unsigned int l) +{ + unsigned char *b; + + if (l != a->data.len) + { + return(BER_ERR_CMP_BYTES); + } + + if (l == 0) + { + return(0); + } + + b = a->data.bytes; + if (BER_prefix_byte(a)) + { + if (a->prefix_byte != *(d++)) + { + return(BER_ERR_CMP_BYTES); + } + + l--; + } + + if (Memcmp(d,b,l) != 0) + { + return(BER_ERR_CMP_BYTES); + } + + return(0); +} +#endif /* SPLIT_BER_ITEM_CMP_BYTES */ + +#ifdef SPLIT_BER_ITEM_CMP_TAG +/** + * Compares the tag of a BER item with a BER type value for a match. + * + * @param a [In] A BER item. + * @param type [In] A type of BER item. + * + * @return Indication of a match:
    + *
  • 0 indicares a match
  • + *
  • BER_ERR_CMP_TAG indicates no match
  • + */ +int BER_ITEM_cmp_tag(BER_ITEM *a, unsigned int type) +{ + int i; + int j; + + if (a->type != type) + { + return(BER_ERR_CMP_TAG); + } + + if ((a->info & BER_PRIVATE) != 0) + { + return(BER_ERR_CMP_TAG); + } + + i = ((a->type == BER_SEQUENCE) || (a->type == BER_SET)); + j = (a->info&BER_CONSTRUCTED) ? 1 : 0; + + return((i == j) ? 0: BER_ERR_CMP_TAG); +} +#endif /* SPLIT_BER_ITEM_CMP_TAG */ + +#ifdef SPLIT_BER_ITEM_INIT +/** + * Initializes a BER item. + * + * @param item [In] A BER item. + * + * @pre The BER item is not a NULL pointer. + */ +void BER_ITEM_init(BER_ITEM *item) +{ + Memset(item, 0, sizeof(BER_ITEM)); +} +#endif /* SPLIT_BER_ITEM_INIT */ + +#ifdef SPLIT_BER_ITEMS_INIT +/** + * Initializes a BER items. + * + * @param items [In] A BER items. + * + * @pre The BER item is not a NULL pointer. + */ +void BER_ITEMS_init(BER_ITEMS *items) +{ + Memset(items, 0, sizeof(BER_ITEMS)); +} +#endif /* SPLIT_BER_ITEMS_INIT */ + +#ifdef SPLIT_BER_ITEM_SET_ALL +/** + * Sets the data against a BER item. + * + * @param item [In] A BER item. + * @param sclass [In] The class of a BER item. + * @param tag [In] The tag of a BER item. + * @param data [In] The data of a BER item. + * @param len [In] The length of the data of a BER item. + * @param info [In] The info of a BER item. + * @param flags [In] The flags of a BER item. + */ +void BER_ITEM_set_all(BER_ITEM *item, unsigned int sclass, unsigned int tag, + unsigned char *data, unsigned int len, unsigned int info, + unsigned int flags) +{ + BER_ITEM_set_header(item, sclass, tag, info); + BER_ITEM_set_data(item, data, len); + item->flags |= flags; +} +#endif /* SPLIT_BER_ITEM_SET_ALL */ + +#ifdef SPLIT_BER_ITEM_SET_HEADER +/** + * Sets the header data against a BER item. + * + * @param item [In] A BER item. + * @param sclass [In] The class of a BER item. + * @param tag [In] The tag of a BER item. + * @param info [In] The info of a BER item. + */ +void BER_ITEM_set_header(BER_ITEM *item, unsigned int sclass, unsigned int tag, + unsigned int info) +{ + item->info = (unsigned char)( (sclass & BER_PRIVATE) | + (info & (BER_INFO_MASK | BER_CONSTRUCTED)) ); + item->flags |= BER_FLAG_INVALID_LENGTH; + + if (((sclass & BER_PRIVATE) == 0) && + ((tag == BER_SEQUENCE) || (tag == BER_SET))) + { + item->info |= BER_CONSTRUCTED; + } + + item->type = tag; +} +#endif /* SPLIT_BER_ITEM_SET_HEADER */ + +#ifdef SPLIT_BER_ITEM_SET_PREFIX_BYTE +/** + * Places a byte at the front of the data of a BER item. This is useful for + * handling bit strings that require a bytes to be placed before the actual + * data. + * + * @param item [In] A BER item. + * @param abyte [In] A byte. + */ +void BER_ITEM_set_prefix_byte(BER_ITEM *item, unsigned int abyte) +{ + if ((item->flags & BER_FLAG_PREFIX_BYTE) == 0) + { + item->flags |= BER_FLAG_PREFIX_BYTE; + item->data.len++; + } + + item->prefix_byte = (unsigned char)( abyte & 0xff ); +} +#endif /* SPLIT_BER_ITEM_SET_PREFIX_BYTE */ + +#ifdef SPLIT_BER_ITEM_SET_DATA +/** + * Sets data against a BER item. + * + * @param item [In] A BER item. + * @param data [In] The data of a BER item. + * @param len [In] The length of the data of a BER item. + */ +void BER_ITEM_set_data(BER_ITEM *item, unsigned char *data, unsigned int len) +{ + item->flags |= BER_FLAG_INVALID_LENGTH; + item->data.bytes = data; + item->data.len = len; +} +#endif /* SPLIT_BER_ITEM_SET_DATA */ + +#ifdef SPLIT_BER_READ_ITEM +/** + * Reads the data from the buffer as a BER item and stores the header + * information into item. + * + * @param item [In] A BER item. + * @param p [In] A buffer of data. + * @param max [In] The number of bytes in buffer. + */ +int BER_read_item(BER_ITEM *item, unsigned char *p, unsigned long max) +{ + unsigned int i=0; + unsigned int tag; + unsigned int j; + unsigned int x; + unsigned int tclass; + unsigned long len; + + if (2 > max) + { + return(BER_ERR_NOT_ENOUGH_BYTES); + } + + tclass = p[i++]; + + /* First get the class and constructed flags */ + item->info = (unsigned char)( tclass & (BER_PRIVATE | BER_CONSTRUCTED) ); + + /* Get the tag */ + tag = tclass & BER_PRIMITIVE_TAG_MASK; + if (tag == BER_PRIMITIVE_TAG_MASK) + { + /* This code handles tags greater than 30 */ + tag = 0; + j =0; + for (;;) + { + if ((unsigned long)i >= max) + { + return(BER_ERR_NOT_ENOUGH_BYTES); + } + + x = p[i++]; + tag |= x & 0x7f; + if (x & 0x80) + { + break; + } + j += 7; + if (j > BER_MAX_TAG_LEN_IN_BITS) + { + return(BER_ERR_TAG_TOO_LONG); + } + tag<<=7; + } + } + item->type = tag; + + /* Now get the length */ + if ((unsigned long)i >= max) + { + return(BER_ERR_NOT_ENOUGH_BYTES); + } + + len = p[i++]; + if (len & 0x80) + { /* Long or extended */ + len &= 0x7f; + if (len == 0) + { + item->info |= BER_ILEN; + /* Don't set this flag if indefinite length encoding. + * Assume if the Constructed bit is set that it is indef encoding. + */ + if (!(tclass & BER_CONSTRUCTED)) + item->flags |= BER_FLAG_INVALID_LENGTH; + } + else + { + if (len > sizeof(unsigned long)) + { + return(BER_ERR_LENGTH_TOO_LARGE); + } + if ((unsigned long)i+len >= max) + { + return(BER_ERR_NOT_ENOUGH_BYTES); + } + + j = len; + len = 0; + for (;;) + { + len |= p[i++]; + if (--j <= 0) + { + break; + } + len <<= 8; + } + } + } + item->data.len = len; + item->data.bytes = &(p[i]); + item->hlen = (unsigned char)i; + +#ifndef NO_STREAM + /* Keep a copy of the header for an outer sequence. */ + Memcpy(item->header, p, i); +#endif /* !NO_STREAM */ + + return(BER_OK); +} +#endif /* SPLIT_BER_READ_ITEM */ + +#endif /* !(defined(NO_SPLIT) && defined(SPLIT_FILE)) */ + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/ber_par.c b/build/libraries_sysmenu/acsign/ARM9/src/ber_par.c new file mode 100644 index 00000000..5098acb6 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/ber_par.c @@ -0,0 +1,251 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - makerom.TWL + File: ber_par.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$ + *---------------------------------------------------------------------------*/ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "ber_lcl.h" + +/* We need to 'parse' the input data into an BER_ITEMS_SK, which is composed of + * BER_ITEMS. + * For definite length encoding, we read a full 'level' at a time, and then + * process the sub-elements. + * For indefinite encoding, we go as 'deep' as we can, updating the + * length info of the indefinite encodings as we go. + * This is easy to do because when we go back up to our parent, + * just compare it's start data byte with the current pointer. + */ + +#define READ_NEXT_ITEM 1 +#define GO_UP 2 + +int BER_parse(BER_ITEMS_SK *sk, unsigned char *ino, unsigned long m_len, + unsigned long *n_used) +{ + int this_idx; + int next_idx; + BER_ITEMS *this = NULL; + BER_ITEMS *next = NULL; + int ret=999; + int state; + unsigned char *in = ino; + unsigned char *max = in + m_len; + unsigned char *end = max; + int inf = 0; + int pinf = 0; + int con = 0; + int down; + + state = READ_NEXT_ITEM; + down = 1; + this_idx = -1; + pinf = 0; + for (;;) + { + switch (state) + { + case READ_NEXT_ITEM: + /* Read the item into 'next' */ + if ((ret=BER_ITEMS_SK_get(sk,&next_idx)) != 0) + { + goto err; + } + next=BER_ITEMS_SK_items(sk,next_idx); + ret = BER_read_item(&(next->item), in, (unsigned long)(end - in)); + if (ret != 0) + { + goto err; + } + /* Check the length of the data against what is available */ + if (next->item.data.len > (unsigned long)(end - in)) + { + ret = BER_ERR_NOT_ENOUGH_BYTES; + goto err; + } + inf = BER_indefinite_encoding(&(next->item)); + con = BER_constructed(&(next->item)); + in += next->item.hlen; + + if (this_idx == -1) + { + this = NULL; + } + else + { + this = BER_ITEMS_SK_items(sk, this_idx); + } + + /* If we are pushing it under, do so */ + if (down) + { + next->parent = this; + if (this != NULL) + { + this->down = next; + if (!pinf) + { + end = this->item.data.bytes+ this->item.data.len; + } + pinf = BER_indefinite_encoding(&this->item); + } + else + { + pinf = 0; + } + next->next = NULL; + } + else + { + next->parent = this->parent; + next->next = NULL; + this->next = next; + } +#ifndef NO_STREAM + next->item.seen = next->item.data.len; + next->item.part_len = next->item.data.len; +#endif /* !NO_STREAM */ + down = 0; + this = next; + this_idx = next_idx; + if ((this->item.type == BER_EOC) && (this->item.data.len == 0) && + (BER_class(&(this->item)) == BER_UNIVERSAL)) + { + if (pinf) + { + this->parent->item.data.len=(unsigned long) + (in - this->parent->item.data.bytes); +#ifndef NO_STREAM + this->parent->item.seen = this->parent->item.data.len; + this->parent->item.part_len = this->parent->item.data.len; +#endif /* !NO_STREAM */ + state = GO_UP; + break; + } + else + { + ret = BER_ERR_UNEXPECTED_EOC; + goto err; + } + } + + if (con && (inf || (this->item.data.len > 0))) + { + pinf = inf; + down = 1; + } + else + { + in += this->item.data.len; + } + + if (in > end) + { + ret = BER_ERR_NOT_ENOUGH_BYTES; + goto err; + } + + if (in == end) + { + state = GO_UP; + } + else + { + state = READ_NEXT_ITEM; + } + + if (inf && !con) + { + ret = BER_ERR_INVALID_LENGTH_ENCODING; + goto err; + } + + break; + case GO_UP: + /* this is valid and is the 'end'. We need to + * go back up one and then see if we contiune or + * go_up again. */ + this_idx +=(int)(this->parent-this); + this = this->parent; + down = 0; + if (this == NULL) + { + ret = 0; + goto end; /* we have finished */ + } + + /* Must have finished this one */ + /* inf = BER_indefinite_encoding(&this->item); */ + + if (this->parent != NULL) + { + pinf = BER_indefinite_encoding(&this->parent->item); + if (pinf) + { + end = max; + } + else + { + end = this->parent->item.data.bytes + + this->parent->item.data.len; + } + } + else + { + if (BER_indefinite_encoding(&this->item)) + { + ret = 0; + goto end; + } + pinf = 0; + end = max; + } + + if (end < in) + { + ret = BER_ERR_NOT_ENOUGH_BYTES; + goto err; + } + if (end == in) + { + state = GO_UP; + } + else + { + state = READ_NEXT_ITEM; + } + break; + default: + break; + } + } +end: + /* if there were no errors we set the length of data we consumed + * if the user wants to know that information. + */ + if (n_used != NULL) + *n_used = (unsigned long)( in - ino ); +err: + return(ret); +} + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_add.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_add.c new file mode 100644 index 00000000..7b36c8b6 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_add.c @@ -0,0 +1,320 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +/** + * @file bn_add.c + * @brief BIGNUM addition and subtraction functions + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_ADD +#define SPLIT_BN_UADD +#define SPLIT_BN_USUB +#define SPLIT_BN_SUB +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BN_ADD +/* r can == a or b */ +int BN_add(r, a, b) +BIGNUM *r; +BIGNUM *a; +BIGNUM *b; + { + BIGNUM *tmp; + + bn_check_top(a); + bn_check_top(b); + + /* a + b a+b + * a + -b a-b + * -a + b b-a + * -a + -b -(a+b) + */ + if (a->neg ^ b->neg) + { + /* only one is negative */ + if (a->neg) + { tmp=a; a=b; b=tmp; } + + /* we are now a - b */ + + if (BN_ucmp(a,b) < 0) + { + if (!BN_usub(r,b,a)) return(0); + r->neg=1; + } + else + { + if (!BN_usub(r,a,b)) return(0); + r->neg=0; + } + return(1); + } + + if (a->neg) /* both are neg */ + r->neg=1; + else + r->neg=0; + + if (!BN_uadd(r,a,b)) return(0); + return(1); + } +#endif + +#ifdef SPLIT_BN_UADD +/* unsigned add of b to a, r must be large enough */ +int BN_uadd(r,a,b) +BIGNUM *r; +BIGNUM *a; +BIGNUM *b; + { + register int i; + int max,min; + BN_ULONG *ap,*bp,*rp,carry,t1; + BIGNUM *tmp; + + bn_check_top(a); + bn_check_top(b); + + if (a->top < b->top) + { tmp=a; a=b; b=tmp; } + max=a->top; + min=b->top; + + if (bn_wexpand(r,max+1) == NULL) + return(0); + + r->top=max; + + + ap=a->d; + bp=b->d; + rp=r->d; + carry=0; + + carry=bn_add_words(rp,ap,bp,min); + rp+=min; + ap+=min; + bp+=min; + i=min; + + if (carry) + { + while (i < max) + { + i++; + t1= *(ap++); + if ((*(rp++)=(t1+1)&BN_MASK2) >= t1) + { + carry=0; + break; + } + } + if ((i >= max) && carry) + { + *(rp++)=1; + r->top++; + } + } + if (rp != ap) + { + for (; ib from a + * @param r result of subtraction + * @param a pointer to a BIGNUM + * @param b pointer to a BIGNUM + * @pre a must be larger than b + * @return 1 on success, 0 on failure + * @todo On next IRIX port check the validity of IRIX_CC_BUG. + */ +#ifdef SPLIT_BN_USUB +int BN_usub(r, a, b) +BIGNUM *r; +BIGNUM *a; +BIGNUM *b; + { + int max,min; + register BN_ULONG t1,t2,*ap,*bp,*rp; + int i,carry; +#if defined(IRIX_CC_BUG) && !defined(LINT) + int dummy; +#endif + + bn_check_top(a); + bn_check_top(b); + + /* + * check for pre-condition violation + */ + if (a->top < b->top) + { +#ifndef NO_ERR + BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3); +#endif + return(0); + } + + max=a->top; + min=b->top; + if (bn_wexpand(r,max) == NULL) return(0); + + ap=a->d; + bp=b->d; + rp=r->d; + + /* + * perform the subtraction and see if we + * have a (final) carry + */ + carry=0; + for (i=0; i t2) break; + } + } + + if (rp != ap) + { +#ifdef BN_LIBRARY_SMALL + Memcpy(rp,ap,sizeof(*rp)*(max-i)); +#else /* BN_LIBRARY_SMALL */ + for (;;) + { + if (i++ >= max) break; + rp[0]=ap[0]; + if (i++ >= max) break; + rp[1]=ap[1]; + if (i++ >= max) break; + rp[2]=ap[2]; + if (i++ >= max) break; + rp[3]=ap[3]; + rp+=4; + ap+=4; + } +#endif /* BN_LIBRARY_SMALL */ + } + + r->top=max; + bn_fix_top(r); + return(1); + } +#endif + +#ifdef SPLIT_BN_SUB +int BN_sub(r, a, b) +BIGNUM *r; +BIGNUM *a; +BIGNUM *b; + { + int max; + int add=0,neg=0; + BIGNUM *tmp; + + bn_check_top(a); + bn_check_top(b); + + /* a - b a-b + * a - -b a+b + * -a - b -(a+b) + * -a - -b b-a + */ + if (a->neg) + { + if (b->neg) + { tmp=a; a=b; b=tmp; } + else + { add=1; neg=1; } + } + else + { + if (b->neg) { add=1; neg=0; } + } + + if (add) + { + if (!BN_uadd(r,a,b)) return(0); + r->neg=neg; + return(1); + } + + /* We are actually doing a - b */ + + max=(a->top > b->top)?a->top:b->top; + if (bn_wexpand(r,max) == NULL) return(0); + if (BN_ucmp(a,b) < 0) + { + if (!BN_usub(r,b,a)) return(0); + r->neg=1; + } + else + { + if (!BN_usub(r,a,b)) return(0); + r->neg=0; + } + return(1); + } +#endif + +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_asm.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_asm.c new file mode 100644 index 00000000..64efa61f --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_asm.c @@ -0,0 +1,525 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#ifndef OPT_BN_ASM + +#define BN_MUL_ADD_WORDS + +#ifndef BN_MUL_WORDS +#define BN_MUL_WORDS +#endif + +#ifndef BN_SQR_WORDS +#define BN_SQR_WORDS +#endif + +#ifndef BN_ADD_WORDS +#define BN_ADD_WORDS +#endif + +#ifndef BN_SUB_WORDS +#define BN_SUB_WORDS +#endif + +#endif + + +#include "bn_lcl.h" + +#ifdef BN_LLONG + +/* + * bn_mul_add_words + * + * for(i=0;i=0; i--) + fprintf(stderr,BN_HEX_FMT,ap[i]); + fprintf(stderr,"*"); + fprintf(stderr,BN_HEX_FMT,w); + fprintf(stderr,"+"); + for (i=num-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,rp[i]); +#endif + + for (;;) + { + mul_add(rp[0],ap[0],w,c1); + if (--num == 0) break; + mul_add(rp[1],ap[1],w,c1); + if (--num == 0) break; + mul_add(rp[2],ap[2],w,c1); + if (--num == 0) break; + mul_add(rp[3],ap[3],w,c1); + if (--num == 0) break; + ap+=4; + rp+=4; + } + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + fprintf(stderr,"-"); + fprintf(stderr,BN_HEX_FMT,c1); + for (i=nn-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,rp[i]); + fprintf(stderr,"\n"); + } +#endif + return(c1); + } +#endif + +#ifdef BN_MUL_WORDS +BN_ULONG bn_mul_words(rp,ap,num,w) +BN_ULONG *rp,*ap; +int num; +BN_ULONG w; + { + BN_ULONG c1=0; + + bn_check_num(num); + if (num <= 0) return(c1); + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + { + int i,nn=num; + + for (i=num-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,ap[i]); + fprintf(stderr,"*"); + fprintf(stderr,BN_HEX_FMT,w); +#endif + + for (;;) + { + mul(rp[0],ap[0],w,c1); + if (--num == 0) break; + mul(rp[1],ap[1],w,c1); + if (--num == 0) break; + mul(rp[2],ap[2],w,c1); + if (--num == 0) break; + mul(rp[3],ap[3],w,c1); + if (--num == 0) break; + ap+=4; + rp+=4; + } + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + fprintf(stderr,"-"); + fprintf(stderr,BN_HEX_FMT,c1); + for (i=nn-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,rp[i]); + fprintf(stderr,"\n"); + } +#endif + return(c1); + } +#endif + +#ifdef BN_SQR_WORDS +void bn_sqr_words(r,a,n) +BN_ULONG *r,*a; +int n; + { + bn_check_num(n); + if (n <= 0) return; + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + { + int i,nn=n; + + for (i=n-1; i>=0; i--) + { + fprintf(stderr,BN_HEX_FMT,a[i]); + if (i != 0) + fprintf(stderr,"^2*2^%X+",i*2*BN_BITS2); + else + fprintf(stderr,"^2"); + } +#endif + + for (;;) + { + BN_ULLONG t; + + t=(BN_ULLONG)(a[0])*(a[0]); + r[0]=Lw(t); r[1]=Hw(t); + if (--n == 0) break; + + t=(BN_ULLONG)(a[1])*(a[1]); + r[2]=Lw(t); r[3]=Hw(t); + if (--n == 0) break; + + t=(BN_ULLONG)(a[2])*(a[2]); + r[4]=Lw(t); r[5]=Hw(t); + if (--n == 0) break; + + t=(BN_ULLONG)(a[3])*(a[3]); + r[6]=Lw(t); r[7]=Hw(t); + if (--n == 0) break; + + a+=4; + r+=8; + } +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + + fprintf(stderr,"-"); + for (i=nn+nn-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,r[i]); + fprintf(stderr,"\n"); + } +#endif + } +#endif + +#else + +#ifdef BN_MUL_ADD_WORDS + +BN_ULONG bn_mul_add_words(rp,ap,num,w) +BN_ULONG *rp,*ap; +int num; +BN_ULONG w; + { + BN_ULONG c=0; + BN_ULONG bl,bh,b_hl; + + bn_check_num(num); + if (num <= 0) return((BN_ULONG)0); + + bl=LBITS(w); + bh=HBITS(w); + b_hl=bh-bl; +/* +{ int i,nnum=num; +BN_ULONG *rrp=rp; +for (i=num-1; i>=0; i--) printf("%02X",rp[i]); +printf("+"); +for (i=num-1; i>=0; i--) printf("%02X",ap[i]); +printf("*%02X - ",w); +*/ + for (;;) + { + mul_add(rp[0],ap[0],bl,bh,b_hl,c); + if (--num == 0) break; + mul_add(rp[1],ap[1],bl,bh,b_hl,c); + if (--num == 0) break; + mul_add(rp[2],ap[2],bl,bh,b_hl,c); + if (--num == 0) break; + mul_add(rp[3],ap[3],bl,bh,b_hl,c); + if (--num == 0) break; + ap+=4; + rp+=4; + } + +/* +printf("%02X",c); +for (i=nnum-1; i>=0; i--) printf("%02X",rrp[i]); +printf("\n"); +} +*/ + return(c); + } + +#endif + +#ifdef BN_MUL_WORDS +BN_ULONG bn_mul_words(rp,ap,num,w) +BN_ULONG *rp,*ap; +int num; +BN_ULONG w; + { + BN_ULONG carry=0; + BN_ULONG bl,bh; + + bn_check_num(num); + if (num <= 0) return((BN_ULONG)0); + + bl=LBITS(w); + bh=HBITS(w); + + for (;;) + { + mul(rp[0],ap[0],bl,bh,carry); + if (--num == 0) break; + mul(rp[1],ap[1],bl,bh,carry); + if (--num == 0) break; + mul(rp[2],ap[2],bl,bh,carry); + if (--num == 0) break; + mul(rp[3],ap[3],bl,bh,carry); + if (--num == 0) break; + ap+=4; + rp+=4; + } + return(carry); + } +#endif + +#ifdef BN_SQR_WORDS +void bn_sqr_words(r,a,n) +BN_ULONG *r,*a; +int n; + { + bn_check_num(n); + if (n <= 0) return; + for (;;) + { + sqr64(r[0],r[1],a[0]); + if (--n == 0) break; + + sqr64(r[2],r[3],a[1]); + if (--n == 0) break; + + sqr64(r[4],r[5],a[2]); + if (--n == 0) break; + + sqr64(r[6],r[7],a[3]); + if (--n == 0) break; + + a+=4; + r+=8; + } + } +#endif + +#endif + +#ifdef BN_ADD_WORDS +#ifdef BN_LLONG +BN_ULONG bn_add_words(r,a,b,n) +BN_ULONG *r,*a,*b; +int n; + { + BN_ULLONG ll=0; + + bn_check_num(n); + if (n <= 0) return((BN_ULONG)0); + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + { + int i,nn=n; + + for (i=n-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,a[i]); + fprintf(stderr,"+"); + for (i=n-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,b[i]); +#endif + + for (;;) + { + ll+=(BN_ULLONG)a[0]+b[0]; + r[0]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + ll+=(BN_ULLONG)a[1]+b[1]; + r[1]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + ll+=(BN_ULLONG)a[2]+b[2]; + r[2]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + ll+=(BN_ULLONG)a[3]+b[3]; + r[3]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + a+=4; + b+=4; + r+=4; + } +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + fprintf(stderr,"-"); + fprintf(stderr,BN_HEX_FMT,(BN_ULONG)ll); + for (i=nn-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,r[i]); + fprintf(stderr,"\n"); + } +#endif + return((BN_ULONG)ll); + } +#else +BN_ULONG bn_add_words(r,a,b,n) +BN_ULONG *r,*a,*b; +int n; + { + BN_ULONG c,l,t; + + bn_check_num(n); + if (n <= 0) return((BN_ULONG)0); + + c=0; + for (;;) + { + t=a[0]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[0])&BN_MASK2; + c+=(l < t); + r[0]=l; + if (--n <= 0) break; + + t=a[1]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[1])&BN_MASK2; + c+=(l < t); + r[1]=l; + if (--n <= 0) break; + + t=a[2]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[2])&BN_MASK2; + c+=(l < t); + r[2]=l; + if (--n <= 0) break; + + t=a[3]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[3])&BN_MASK2; + c+=(l < t); + r[3]=l; + if (--n <= 0) break; + + a+=4; + b+=4; + r+=4; + } + + return((BN_ULONG)c); + } +#endif +#endif + +#ifdef BN_SUB_WORDS +BN_ULONG bn_sub_words(r,a,b,n) +BN_ULONG *r,*a,*b; +int n; + { + BN_ULONG c,t1,t2; + + bn_check_num(n); + if (n <= 0) return((BN_ULONG)0); + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + { + int i,nn=n; + + for (i=n-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,a[i]); + fprintf(stderr,"-"); + for (i=n-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,b[i]); +#endif + + c=0; + for (;;) + { + t1=a[0]; t2=b[0]; + r[0]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + t1=a[1]; t2=b[1]; + r[1]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + t1=a[2]; t2=b[2]; + r[2]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + t1=a[3]; t2=b[3]; + r[3]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + a+=4; + b+=4; + r+=4; + } + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + fprintf(stderr,"- "); + if (c) fprintf(stderr,"-"); + for (i=nn-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,r[i]); + fprintf(stderr,"\n"); + } +#endif + return(c); + } +#endif + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_comba.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_comba.c new file mode 100644 index 00000000..462c8f4d --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_comba.c @@ -0,0 +1,450 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_MUL_COMBA8 +#define SPLIT_BN_MUL_COMBA4 +#define SPLIT_BN_SQR_COMBA8 +#define SPLIT_BN_SQR_COMBA4 +#endif /* NO_SPLIT */ + +#ifndef OPT_BN_ASM +/* #if 1 */ + +#ifdef BN_LLONG +#define mul_add_c(a,b,c0,c1,c2) \ + t=(BN_ULLONG)a*b; \ + t1=(BN_ULONG)Lw(t); \ + t2=(BN_ULONG)Hw(t); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define mul_add_c2(a,b,c0,c1,c2) \ + t=(BN_ULLONG)a*b; \ + tt=(t+t)&BN_MASK; \ + if (tt < t) c2++; \ + t1=(BN_ULONG)Lw(tt); \ + t2=(BN_ULONG)Hw(tt); \ + c0=(c0+t1)&BN_MASK2; \ + if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c(a,i,c0,c1,c2) \ + t=(BN_ULLONG)a[i]*a[i]; \ + t1=(BN_ULONG)Lw(t); \ + t2=(BN_ULONG)Hw(t); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c2(a,i,j,c0,c1,c2) \ + mul_add_c2((a)[i],(a)[j],c0,c1,c2) +#else +#define mul_add_c(a,b,c0,c1,c2) \ + t1=LBITS(a); t2=HBITS(a); \ + bl=LBITS(b); bh=HBITS(b); \ + mul64(t1,t2,bl,bh); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define mul_add_c2(a,b,c0,c1,c2) \ + t1=LBITS(a); t2=HBITS(a); \ + bl=LBITS(b); bh=HBITS(b); \ + mul64(t1,t2,bl,bh); \ + if (t2 & BN_TBIT) c2++; \ + t2=(t2+t2)&BN_MASK2; \ + if (t1 & BN_TBIT) t2++; \ + t1=(t1+t1)&BN_MASK2; \ + c0=(c0+t1)&BN_MASK2; \ + if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c(a,i,c0,c1,c2) \ + sqr64(t1,t2,(a)[i]); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c2(a,i,j,c0,c1,c2) \ + mul_add_c2((a)[i],(a)[j],c0,c1,c2) +#endif + +#if defined(BN_MUL_COMBA) + +#ifdef SPLIT_BN_MUL_COMBA8 +#undef bn_mul_comba8 +void bn_mul_comba8(r,a,b) +BN_ULONG *r,*a,*b; + { +#ifdef BN_LLONG + BN_ULLONG t; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + mul_add_c(a[0],b[0],c1,c2,c3); + r[0]=c1; + c1=0; + mul_add_c(a[0],b[1],c2,c3,c1); + mul_add_c(a[1],b[0],c2,c3,c1); + r[1]=c2; + c2=0; + mul_add_c(a[2],b[0],c3,c1,c2); + mul_add_c(a[1],b[1],c3,c1,c2); + mul_add_c(a[0],b[2],c3,c1,c2); + r[2]=c3; + c3=0; + mul_add_c(a[0],b[3],c1,c2,c3); + mul_add_c(a[1],b[2],c1,c2,c3); + mul_add_c(a[2],b[1],c1,c2,c3); + mul_add_c(a[3],b[0],c1,c2,c3); + r[3]=c1; + c1=0; + mul_add_c(a[4],b[0],c2,c3,c1); + mul_add_c(a[3],b[1],c2,c3,c1); + mul_add_c(a[2],b[2],c2,c3,c1); + mul_add_c(a[1],b[3],c2,c3,c1); + mul_add_c(a[0],b[4],c2,c3,c1); + r[4]=c2; + c2=0; + mul_add_c(a[0],b[5],c3,c1,c2); + mul_add_c(a[1],b[4],c3,c1,c2); + mul_add_c(a[2],b[3],c3,c1,c2); + mul_add_c(a[3],b[2],c3,c1,c2); + mul_add_c(a[4],b[1],c3,c1,c2); + mul_add_c(a[5],b[0],c3,c1,c2); + r[5]=c3; + c3=0; + mul_add_c(a[6],b[0],c1,c2,c3); + mul_add_c(a[5],b[1],c1,c2,c3); + mul_add_c(a[4],b[2],c1,c2,c3); + mul_add_c(a[3],b[3],c1,c2,c3); + mul_add_c(a[2],b[4],c1,c2,c3); + mul_add_c(a[1],b[5],c1,c2,c3); + mul_add_c(a[0],b[6],c1,c2,c3); + r[6]=c1; + c1=0; + mul_add_c(a[0],b[7],c2,c3,c1); + mul_add_c(a[1],b[6],c2,c3,c1); + mul_add_c(a[2],b[5],c2,c3,c1); + mul_add_c(a[3],b[4],c2,c3,c1); + mul_add_c(a[4],b[3],c2,c3,c1); + mul_add_c(a[5],b[2],c2,c3,c1); + mul_add_c(a[6],b[1],c2,c3,c1); + mul_add_c(a[7],b[0],c2,c3,c1); + r[7]=c2; + c2=0; + mul_add_c(a[7],b[1],c3,c1,c2); + mul_add_c(a[6],b[2],c3,c1,c2); + mul_add_c(a[5],b[3],c3,c1,c2); + mul_add_c(a[4],b[4],c3,c1,c2); + mul_add_c(a[3],b[5],c3,c1,c2); + mul_add_c(a[2],b[6],c3,c1,c2); + mul_add_c(a[1],b[7],c3,c1,c2); + r[8]=c3; + c3=0; + mul_add_c(a[2],b[7],c1,c2,c3); + mul_add_c(a[3],b[6],c1,c2,c3); + mul_add_c(a[4],b[5],c1,c2,c3); + mul_add_c(a[5],b[4],c1,c2,c3); + mul_add_c(a[6],b[3],c1,c2,c3); + mul_add_c(a[7],b[2],c1,c2,c3); + r[9]=c1; + c1=0; + mul_add_c(a[7],b[3],c2,c3,c1); + mul_add_c(a[6],b[4],c2,c3,c1); + mul_add_c(a[5],b[5],c2,c3,c1); + mul_add_c(a[4],b[6],c2,c3,c1); + mul_add_c(a[3],b[7],c2,c3,c1); + r[10]=c2; + c2=0; + mul_add_c(a[4],b[7],c3,c1,c2); + mul_add_c(a[5],b[6],c3,c1,c2); + mul_add_c(a[6],b[5],c3,c1,c2); + mul_add_c(a[7],b[4],c3,c1,c2); + r[11]=c3; + c3=0; + mul_add_c(a[7],b[5],c1,c2,c3); + mul_add_c(a[6],b[6],c1,c2,c3); + mul_add_c(a[5],b[7],c1,c2,c3); + r[12]=c1; + c1=0; + mul_add_c(a[6],b[7],c2,c3,c1); + mul_add_c(a[7],b[6],c2,c3,c1); + r[13]=c2; + c2=0; + mul_add_c(a[7],b[7],c3,c1,c2); + r[14]=c3; + r[15]=c1; + } +#endif + +#ifdef SPLIT_BN_MUL_COMBA4 +#undef bn_mul_comba4 +void bn_mul_comba4(r,a,b) +BN_ULONG *r,*a,*b; + { +#ifdef BN_LLONG + BN_ULLONG t; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + mul_add_c(a[0],b[0],c1,c2,c3); + r[0]=c1; + c1=0; + mul_add_c(a[0],b[1],c2,c3,c1); + mul_add_c(a[1],b[0],c2,c3,c1); + r[1]=c2; + c2=0; + mul_add_c(a[2],b[0],c3,c1,c2); + mul_add_c(a[1],b[1],c3,c1,c2); + mul_add_c(a[0],b[2],c3,c1,c2); + r[2]=c3; + c3=0; + mul_add_c(a[0],b[3],c1,c2,c3); + mul_add_c(a[1],b[2],c1,c2,c3); + mul_add_c(a[2],b[1],c1,c2,c3); + mul_add_c(a[3],b[0],c1,c2,c3); + r[3]=c1; + c1=0; + mul_add_c(a[3],b[1],c2,c3,c1); + mul_add_c(a[2],b[2],c2,c3,c1); + mul_add_c(a[1],b[3],c2,c3,c1); + r[4]=c2; + c2=0; + mul_add_c(a[2],b[3],c3,c1,c2); + mul_add_c(a[3],b[2],c3,c1,c2); + r[5]=c3; + c3=0; + mul_add_c(a[3],b[3],c1,c2,c3); + r[6]=c1; + r[7]=c2; + } +#endif + +#else + +#ifdef SPLIT_BN_MUL_COMBA4 +#undef bn_mul_comba4 +void bn_mul_comba4(r,a,b) +BN_ULONG *r,*a,*b; + { + r[4]=bn_mul_words( &(r[0]),a,4,b[0]); + r[5]=bn_mul_add_words(&(r[1]),a,4,b[1]); + r[6]=bn_mul_add_words(&(r[2]),a,4,b[2]); + r[7]=bn_mul_add_words(&(r[3]),a,4,b[3]); + } +#endif + +#ifdef SPLIT_BN_MUL_COMBA8 +#undef bn_mul_comba8 +void bn_mul_comba8(r,a,b) +BN_ULONG *r,*a,*b; + { + r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]); + r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]); + r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]); + r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]); + r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]); + r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]); + r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]); + r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]); + } +#endif + +#endif /* BN_MUL_COMBA */ + +#ifdef BN_SQR_COMBA + +#ifdef SPLIT_BN_SQR_COMBA8 +#undef bn_sqr_comba8 +void bn_sqr_comba8(r,a) +BN_ULONG *r,*a; + { +#ifdef BN_LLONG + BN_ULLONG t,tt; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + sqr_add_c(a,0,c1,c2,c3); + r[0]=c1; + c1=0; + sqr_add_c2(a,1,0,c2,c3,c1); + r[1]=c2; + c2=0; + sqr_add_c(a,1,c3,c1,c2); + sqr_add_c2(a,2,0,c3,c1,c2); + r[2]=c3; + c3=0; + sqr_add_c2(a,3,0,c1,c2,c3); + sqr_add_c2(a,2,1,c1,c2,c3); + r[3]=c1; + c1=0; + sqr_add_c(a,2,c2,c3,c1); + sqr_add_c2(a,3,1,c2,c3,c1); + sqr_add_c2(a,4,0,c2,c3,c1); + r[4]=c2; + c2=0; + sqr_add_c2(a,5,0,c3,c1,c2); + sqr_add_c2(a,4,1,c3,c1,c2); + sqr_add_c2(a,3,2,c3,c1,c2); + r[5]=c3; + c3=0; + sqr_add_c(a,3,c1,c2,c3); + sqr_add_c2(a,4,2,c1,c2,c3); + sqr_add_c2(a,5,1,c1,c2,c3); + sqr_add_c2(a,6,0,c1,c2,c3); + r[6]=c1; + c1=0; + sqr_add_c2(a,7,0,c2,c3,c1); + sqr_add_c2(a,6,1,c2,c3,c1); + sqr_add_c2(a,5,2,c2,c3,c1); + sqr_add_c2(a,4,3,c2,c3,c1); + r[7]=c2; + c2=0; + sqr_add_c(a,4,c3,c1,c2); + sqr_add_c2(a,5,3,c3,c1,c2); + sqr_add_c2(a,6,2,c3,c1,c2); + sqr_add_c2(a,7,1,c3,c1,c2); + r[8]=c3; + c3=0; + sqr_add_c2(a,7,2,c1,c2,c3); + sqr_add_c2(a,6,3,c1,c2,c3); + sqr_add_c2(a,5,4,c1,c2,c3); + r[9]=c1; + c1=0; + sqr_add_c(a,5,c2,c3,c1); + sqr_add_c2(a,6,4,c2,c3,c1); + sqr_add_c2(a,7,3,c2,c3,c1); + r[10]=c2; + c2=0; + sqr_add_c2(a,7,4,c3,c1,c2); + sqr_add_c2(a,6,5,c3,c1,c2); + r[11]=c3; + c3=0; + sqr_add_c(a,6,c1,c2,c3); + sqr_add_c2(a,7,5,c1,c2,c3); + r[12]=c1; + c1=0; + sqr_add_c2(a,7,6,c2,c3,c1); + r[13]=c2; + c2=0; + sqr_add_c(a,7,c3,c1,c2); + r[14]=c3; + r[15]=c1; + } +#endif + +#ifdef SPLIT_BN_SQR_COMBA4 +#undef bn_sqr_comba4 +void bn_sqr_comba4(r,a) +BN_ULONG *r,*a; + { +#ifdef BN_LLONG + BN_ULLONG t,tt; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + sqr_add_c(a,0,c1,c2,c3); + r[0]=c1; + c1=0; + sqr_add_c2(a,1,0,c2,c3,c1); + r[1]=c2; + c2=0; + sqr_add_c(a,1,c3,c1,c2); + sqr_add_c2(a,2,0,c3,c1,c2); + r[2]=c3; + c3=0; + sqr_add_c2(a,3,0,c1,c2,c3); + sqr_add_c2(a,2,1,c1,c2,c3); + r[3]=c1; + c1=0; + sqr_add_c(a,2,c2,c3,c1); + sqr_add_c2(a,3,1,c2,c3,c1); + r[4]=c2; + c2=0; + sqr_add_c2(a,3,2,c3,c1,c2); + r[5]=c3; + c3=0; + sqr_add_c(a,3,c1,c2,c3); + r[6]=c1; + r[7]=c2; + } +#endif +#else + +#ifdef SPLIT_BN_SQR_COMBA4 +/* hmm... is it faster just to do a multiply? */ +#undef bn_sqr_comba4 +void bn_sqr_comba4(r,a) +BN_ULONG *r,*a; + { + BN_ULONG t[8]; + bn_sqr_normal(r,a,4,t); + } +#endif + +#ifdef SPLIT_BN_SQR_COMBA8 +#undef bn_sqr_comba8 +void bn_sqr_comba8(r,a) +BN_ULONG *r,*a; + { + BN_ULONG t[16]; + bn_sqr_normal(r,a,8,t); + } +#endif + +#endif + +#endif /* OPT_BN_ASM */ + +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_div.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_div.c new file mode 100644 index 00000000..7036d196 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_div.c @@ -0,0 +1,381 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/** + * @file bn_div.c + * @brief Division and modulus functions + */ +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_DIV +#define SPLIT_BN_MOD +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BN_DIV +/* The old slow way */ +#ifdef OLD_BN_DIVISION +int BN_div(dv, rem, m, d,ctx) +BIGNUM *dv; +BIGNUM *rem; +BIGNUM *m; +BIGNUM *d; +BN_CTX *ctx; + { + int i,nm,nd; + BIGNUM *D; + + bn_check_top(m); + bn_check_top(d); + if (BN_is_zero(d)) + { +#ifndef NO_ERR + BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); +#endif + return(0); + } + + if (BN_ucmp(m,d) < 0) + { + if (rem != NULL) + { if (BN_copy(rem,m) == NULL) return(0); } + if (dv != NULL) BN_zero(dv); + return(1); + } + + D= &(ctx->bn[ctx->tos]); + if (dv == NULL) dv= &(ctx->bn[ctx->tos+1]); + if (rem == NULL) rem= &(ctx->bn[ctx->tos+2]); + + nd=BN_num_bits(d); + nm=BN_num_bits(m); + if (BN_copy(D,d) == NULL) return(0); + if (BN_copy(rem,m) == NULL) return(0); + + /* The next 2 are needed so we can do a dv->d[0]|=1 later + * since BN_lshift1 will only work once there is a value + */ + BN_zero(dv); + bn_wexpand(dv,1); + dv->top=1; + + if (!BN_lshift(D,D,nm-nd)) return(0); + for (i=nm-nd; i>=0; i--) + { + if (!BN_lshift1(dv,dv)) return(0); + if (BN_ucmp(rem,D) >= 0) + { + dv->d[0]|=1; + if (!BN_usub(rem,rem,D)) return(0); + } +/* CAN IMPROVE (and have now :=) */ + if (!BN_rshift1(D,D)) return(0); + } + rem->neg=BN_is_zero(rem)?0:m->neg; + dv->neg=m->neg^d->neg; + return(1); + } + +#else +/** + * Performs Big number division + * + * @param dv [In] division + * @param rm [Out] remainder + * @param num [In] number + * @param divisor [In] divisor + * @param ctx [In] Temporary data storage + * + * @todo add more comments to this function + */ +int BN_div(BIGNUM *dv, BIGNUM *rm, BIGNUM *num, BIGNUM *divisor, BN_CTX *ctx) + { + int norm_shift,i,j,loop; + BIGNUM *tmp,wnum,*snum,*sdiv,*res; + BN_ULONG *resp,*wnump; + BN_ULONG d0,d1; + int num_n,div_n; + + bn_check_top(num); + bn_check_top(divisor); + + if (BN_is_zero(divisor)) + { +#ifndef NO_ERR + BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); +#endif + return(0); + } + + if (BN_ucmp(num,divisor) < 0) + { + if (rm != NULL) + { if (BN_copy(rm,num) == NULL) return(0); } + if (dv != NULL) (void)BN_zero(dv); + return(1); + } + + tmp= &(ctx->bn[ctx->tos]); + tmp->neg=0; + snum= &(ctx->bn[ctx->tos+1]); + sdiv= &(ctx->bn[ctx->tos+2]); + if (dv == NULL) + res= &(ctx->bn[ctx->tos+3]); + else res=dv; + + /* First we normalise the numbers */ + norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2); + if (!BN_lshift(sdiv,divisor,norm_shift)) return(0); + sdiv->neg=0; + norm_shift+=BN_BITS2; + if (!BN_lshift(snum,num,norm_shift)) return(0); + snum->neg=0; + div_n=sdiv->top; + num_n=snum->top; + loop=num_n-div_n; + + /* Lets setup a 'window' into snum + * This is the part that corresponds to the current + * 'area' being divided */ + BN_init(&wnum); + wnum.d= &(snum->d[loop]); + wnum.top= div_n; + wnum.max= snum->max+1; /* a bit of a lie */ + + /* Get the top 2 words of sdiv */ + /* i=sdiv->top; */ + d0=sdiv->d[div_n-1]; + d1=(div_n == 1)?0:sdiv->d[div_n-2]; + + /* pointer to the 'top' of snum */ + wnump= &(snum->d[num_n-1]); + + /* Setup to 'res' */ + if (!bn_wexpand(res,(loop+1))) goto err; + res->neg= (num->neg^divisor->neg); + res->top=loop; + resp= &(res->d[loop-1]); + + /* space for temp */ + if (!bn_wexpand(tmp,(div_n+1))) goto err; + + if (BN_ucmp(&wnum,sdiv) >= 0) + { + if (!BN_usub(&wnum,&wnum,sdiv)) goto err; + *resp=1; + res->d[res->top-1]=1; + } + else + res->top--; + resp--; + + for (i=0; i>BN_BITS2) || + (t2 <= ((BN_ULLONG)(rem< t1l) t3h++; + t3h=(t1h-t3h)&BN_MASK2; + + /*if ((t3>>BN_BITS2) || + (t2 <= ((t3<d,sdiv->d,div_n,q); + tmp->d[div_n]=l0; + for (j=div_n+1; j>0; j--) + if (tmp->d[j-1]) break; + tmp->top=j; + + j=wnum.top; +#ifdef BN_DEBUG + /* Sometimes this is 0 now (wnum.top is not). + * We need to look at this some time, I am quite + * sure it has no affect. + */ + bn_fix_top(&wnum); +#endif + (void)BN_sub(&wnum,&wnum,tmp); + + snum->top=snum->top+wnum.top-j; + + if (wnum.neg) + { + q--; + j=wnum.top; + (void)BN_add(&wnum,&wnum,sdiv); + snum->top+=wnum.top-j; + } + *(resp--)=q; + wnump--; + } + bn_fix_top(snum); + if (rm != NULL) + { + i=num->neg; /* just in case num == rm */ + if (BN_rshift(rm,snum,norm_shift) == 0) + return(0); + rm->neg=i; + } + return(1); +err: + return(0); + } +#endif +#endif + +#ifdef SPLIT_BN_MOD +/** + * Calculate the remainder where rem = m mod d + * + * @param rem [Out] Modulus result + * @param m [In] Base value + * @param d [In] Divisor + * @param ctx [In] BN_CTX for data space + * + * @pre variables are initialised and valid + * @post rem contained modulus + * + * @retval 1 success + * @retval 0 failure + * + * @note when BN_LIBRARY_SMALL define uses following algorithm + * otherwise calls through to BN_div + * + * @note m < d rem = m + * (length m = length of d) and (m > d) , rem = m - d + * alg otherwise + * let rem = m + * loop while rem > d + * let dv = shift left d, n bits to = length rem + * if dv > rem + * let dv = shift left d, n - 1 bits ( = length rem - 1) + * end if + * let rem = rem - dv; + * end loop + * + * @relates BN_div + */ +int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx) +{ +#ifdef BN_LIBRARY_SMALL + int nm,nd; + BIGNUM *dv, *dv2; + + /* if m < d , mod = m */ + if (BN_ucmp(m,d) < 0) + return((BN_copy(rem,m) == NULL)?0:1); + + dv= &(ctx->bn[ctx->tos]); + dv2 = &(ctx->bn[ctx->tos+1]); + + nm=BN_num_bits(m); + nd=BN_num_bits(d); + + /* if bits m = bits d and m >= d (from above) + * rem = m - d + */ + if(nm == nd) + { + BN_usub(rem, m, d); + goto end; + } + + if (BN_copy(rem, m) == NULL) + { + return 0; + } + + /* while the rem > d */ + while(BN_ucmp(rem,d) > 0) + { + nm=BN_num_bits(rem); + if(!BN_lshift(dv2,d,nm-nd)) + { + return(0); + } + + if(BN_ucmp(dv2, rem) >0) + { + if(!BN_lshift(dv2,d,nm-nd-1)) + { + return(0); + } + } + + BN_usub(rem,rem,dv2); + } +end: + return(1); +#else + return(BN_div(NULL,rem,m,d,ctx)); +#endif +} +#endif + +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_ex_str.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_ex_str.c new file mode 100644 index 00000000..02e31d1c --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_ex_str.c @@ -0,0 +1,453 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +#include "bn_lcl.h" + +const static unsigned char p2 []={0,8,1,1,1,1,1,0,0,0}; +const static unsigned char p4 []={0,8,1,1,1,4,1,0,0,0}; +const static unsigned char p16[]={0,8,1,1,1,16,1,0,0,0}; + +/* The following defines allow for redefinition of the window size + * of the exponent string at compile time, this affects the size + * of temporary data required in montgomery operations. + * Larger window sizes have more memory and are slightly faster + */ +#ifndef MAX_WIN_SIZE +#define MAX_WIN_SIZE 5 +#endif + +#if (MAX_WIN_SIZE == 6) +#define MAX_NUM_SIZE 16 +#endif + +#if (MAX_WIN_SIZE == 5) +#define MAX_NUM_SIZE 16 +#endif + +#if (MAX_WIN_SIZE == 4) +#define MAX_NUM_SIZE 8 +#endif + +#if (MAX_WIN_SIZE == 3) +#define MAX_NUM_SIZE 4 +#endif + +#ifndef MAX_NUM_SIZE +#define MAX_NUM_SIZE 16 +#endif + +/* This table is used to calculate how far to shift a window to find + * the next 1 bit within the window, for a given window size + * Comment next to each value represents window size, value of the window + * and the number of shifts to find the next 1 bit. + * where the value of the window is 0, the shift is the size of the window + * and thus may not necessary yield a 1 bit, but refreshes the window + */ +const static unsigned char shift[64]= + {6, /* window 6, bits 000000, shift 6 */ + 0, /* 6, bits 000001, shift 0 */ + 1, /* 6, bits 000010, shift 1 */ + 0, /* 6, bits 000011, shift 0 */ + 2, /* 6, bits 000100, shift 2 */ + 0, /* 6, bits 000101, shift 0 */ + 1, /* 6, bits 000110, shift 1 */ + 0, /* 6, bits 000111, shift 0 */ + 3, /* 6, bits 001000, shift 3 */ + 0, /* 6, bits 001001, shift 0 */ + 1, /* 6, bits 001010, shift 1 */ + 0, /* 6, bits 001011, shift 0 */ + 2, /* 6, bits 001100, shift 2 */ + 0, /* 6, bits 001101, shift 0 */ + 1, /* 6, bits 001110, shift 1 */ + 0, /* 6, bits 001111, shift 0 */ + 4, /* 6, bits 010000, shift 4 */ + 0, /* 6, bits 010001, shift 0 */ + 1, /* 6, bits 010010, shift 1 */ + 0, /* 6, bits 010011, shift 0 */ + 2, /* 6, bits 010100, shift 2 */ + 0, /* 6, bits 010101, shift 0 */ + 1, /* 6, bits 010110, shift 1 */ + 0, /* 6, bits 010111, shift 0 */ + 3, /* 6, bits 011000, shift 3 */ + 0, /* 6, bits 011001, shift 0 */ + 1, /* 6, bits 011010, shift 1 */ + 0, /* 6, bits 011011, shift 0 */ + 2, /* 6, bits 011100, shift 2 */ + 0, /* 6, bits 011101, shift 0 */ + 1, /* 6, bits 011110, shift 1 */ + 0, /* 6, bits 011111, shift 0 */ + 5, /* 6, bits 100000, shift 5 */ + /* also window 5, bits 00000, shift 5 */ + 0, /* 5 ,bits 00001, shift 0 */ + 1, /* 5 ,bits 00010, shift 1 */ + 0, /* 5 ,bits 00011, shift 0 */ + 2, /* 5 ,bits 00100, shift 2 */ + 0, /* 5 ,bits 00101, shift 0 */ + 1, /* 5 ,bits 00110, shift 1 */ + 0, /* 5 ,bits 00111, shift 0 */ + 3, /* 5 ,bits 01000, shift 3 */ + 0, /* 5 ,bits 01001, shift 0 */ + 1, /* 5 ,bits 01010, shift 1 */ + 0, /* 5 ,bits 01011, shift 0 */ + 2, /* 5 ,bits 01100, shift 2 */ + 0, /* 5 ,bits 01101, shift 0 */ + 1, /* 5 ,bits 01110, shift 1 */ + 0, /* 5 ,bits 01111, shift 0 */ + 4, /* 5 ,bits 10000, shift 1 */ + /* also window 4, bits 0000, shift 4 */ + 0, /* 4 ,bits 0001, shift 0 */ + 1, /* 4 ,bits 0010, shift 1 */ + 0, /* 4 ,bits 0011, shift 0 */ + 2, /* 4 ,bits 0100, shift 2 */ + 0, /* 4 ,bits 0101, shift 0 */ + 1, /* 4 ,bits 0110, shift 1 */ + 0, /* 4 ,bits 0111, shift 0 */ + 3, /* 4 ,bits 1000, shift 3 */ + /* also window 3, bits 000, shift 3 */ + 0, /* 3 ,bits 001, shift 0 */ + 1, /* 3 ,bits 010, shift 1 */ + 0, /* 3 ,bits 011, shift 0 */ + 2, /* 3 ,bits 100, shift 2 */ + 0, /* 3 ,bits 101, shift 0 */ + 1, /* 3 ,bits 110, shift 1 */ + 0 /* 3 ,bits 111, shift 0 */ + }; + +/* This table defines the starting point in the shift table for + * a particular window size + */ +const static unsigned char *shift_val[7]= + { + &(shift[63]), /* window 0 - unused */ + &(shift[62]), /* window 1 */ + &(shift[60]), /* window 2 - unused */ + &(shift[56]), /* window 3 */ + &(shift[48]), /* window 4 */ + &(shift[32]), /* window 5 */ + &(shift[ 0]), /* window 6 - unused */ + }; + +/** + * Calculates a Montgomery exponent string. + * + * For a supplied exponent p, generate an exponent string strp, which + * defines in pairs the number of multiplies and square operations + * required by a particular bit pattern, commonly used exponents + * 3, 11 and F4 have predefined constant string values, the rest + * are calculated into a cast unsigned char * array via the data + * pointer of a BIGNUM taken from the BN_CTX stack of BIGNUMs + * + * @param p [In] Exponent + * @param strp [Out] Exponent string result + * @param flags [In] Unused + * @param ctx [In] Temporary data storage + * + * @pre p, and ctx are initialised and valid + * @post strp points to required exponent string + * + * @notes String length value in strp[2] is invalid for strings + * greater than length 255 + * string terminates with pattern, 0, 0 this should be + * used in accurately determining the length of a returned + * string strp. + * + * @note strings with value sqr = 255, mul = 0, sqr value should be + * treated as value 256, and added to the next sqr value, this + * is used by exponent strings where more then 256 contiguous + * zero bits are in the exponent bit representation. + * + * @note code contains conditional compilation of code dependent on + * the OS int/long sizes + */ +int BN_gen_exp_bits(p,strp,flags,ctx) +BIGNUM *p; +unsigned char **strp; +int flags; +BN_CTX *ctx; + { + int bits,i,j,window,num; + unsigned char *str=NULL; + BIGNUM *tmp; + + flags=flags; + bits=p->top*BN_BITS2; + tmp=&(ctx->bn[ctx->tos]); + if (p->top == 0) + return(0); + +#if (BN_BITS2 > 17) + if (p->top == 1) +#else + if (bits <= 32) +#endif + { +#if (BN_BITS2 > 17) + if ((p->top == 1) && (p->d[0] == 0x10001)) + str=(unsigned char *)p16; +#endif +#if (16 >= BN_BITS2) && (BN_BITS > 8) + if ( (p->top == 2) && + (p->d[0] == 0x0001) && + (p->d[1] == 0x0001)) + str=(unsigned char *)p16; +#endif +#if (8 >= BN_BITS) + if ( (p->top == 3) && + (p->d[0] == 0x01) && + (p->d[1] == 0x00) && + (p->d[2] == 0x01)) + str=(unsigned char *)p16; +#endif + else if ((p->d[0] == 0x11) && (p->top == 1)) + str=(unsigned char *)p4; + else if ((p->d[0] == 0x3) && (p->top == 1)) + str=(unsigned char *)p2; + window=1; + num=1; + i=BN_BITS2; + } + else if (bits >= 256) + { + window=MAX_WIN_SIZE; /* max size of window */ + num=MAX_NUM_SIZE; + i=(BN_BITS2+(MAX_WIN_SIZE -1))/MAX_WIN_SIZE; + } + else if (bits >= 128) + { + window=4; + num=8; + i=(BN_BITS2+3)/4; + } + else /* 128 to 33 */ + { + window=3; + num=4; + i=(BN_BITS2+2)/3; + } + + /* Number of tmp words */ + j=(p->top*i*2+BN_BYTES-1+4)/BN_BYTES; + + if (str == NULL) + { + if (!bn_wexpand(tmp,j)) + return(0); + str=(unsigned char *)tmp->d; + i=BN_gen_exp_string(&(str[4]),p,window); + i+=2; + str[0]=(unsigned char)((i>>8)&0xff); + str[1]=(unsigned char)((i )&0xff); + str[2]=(unsigned char)window; + str[3]=(unsigned char)num; + } + else + { + i=8; + } + *strp=str; + return(i+2); + } + + +/** + * Generates the Montgomery exponent string. + * + * This function is used to generate an 'exponent string' + * which is an array of bytes that encode how to perform the steps in + * the a^p%m operation. + * + * @param str [Out] Containing the generated string + * @param p [In] Exponent to generate the string for + * @param bits [In] Size of the window for shifting the values of the BIGNUM + * + * @pre p is initialised and value BIGNUM, bits is not 0 + * @post str points to generated exponent string + * + * @note str is cast assigned the data of a BIGNUM allocated and + * expanded from the BN_CTX of the calling function BN_gen_exp_bits + * it does not need to be de-allocated + * + * @note string consisted of unsigned char pairs and 4 byte init + * pairs are sqr count and multiply, where strings are greater + * than 256 bit, length in position str[2] is invalid + * + * @note strings with value sqr = 255, mul = 0, sqr value should be + * treated as value 256, and added to the next sqr value, this + * is used by exponent strings where more then 256 contiguous + * zero bits are in the exponent bit representation. + * + */ +int BN_gen_exp_string(str,p,bits) +unsigned char *str; +BIGNUM *p; +int bits; + { + unsigned char *sp; + unsigned int mask; + const unsigned char *shift; + BN_ULONG w,wh,wl,*d; + unsigned int i,mul,sqr,t,s,ss; + int top; + + if (bits > 6) bits=6; + shift= shift_val[bits]; + + /* This is the mask for the bits we wish to operate on */ + mask=(unsigned int)( (1<top*BN_BITS2+bits-1)/bits)*2+2]); + *sp-- = 0; + *sp-- = 0; + top=p->top; /* Total words we will shift in */ + d=p->d; + w=wl= *d++; + if (top <= 1) + wh=0; + else + wh= *d++; + sqr=0; + i=0; + + for (;;) + { + /* t will contain how far we need to shift to set a 1 + * in the bottom bit. */ + for (;;) + { + t=w&mask; /* retrieve our window */ + s=shift[t]; /* get the shift value for the window */ + if (s == 0) break; /* no shift write out the vals */ + sqr+=s; /* add the shifted zero count to sqr */ + ss+=s; /* ss is total shift for wl */ + if (ss >= BN_BITS2) /* we have shifted > word len */ + { + if (top <= 1) break; /* no more to do */ + top--; /* dec the count */ + + wl=wh; /* copy the next word */ + /* load the word after or 0 if no more */ + wh=(top <= 1)?0:(*d++); + /* adjust our shift by len of word */ + ss-=BN_BITS2; + } + /* reset our window word w */ + if (ss == 0) + w=wl; + else + w=(wl>>ss)|(wh<<(BN_BITS2-ss)); + } + + /* At this point we have the 0th bit set */ + mul=t; + if (t == 0) break; /* we have reached the end of p */ + /* write out sqr/mul pair */ + *sp-- = (unsigned char)(sqr & 0xff); + *sp-- = (unsigned char)(mul & 0xff); + if(sqr >= 256) /* check whether sqr exceeds max uchar */ + { + /* output the expanded list of to allow for this + * and numbers will require to be added together + * at interpret time + */ + while(sqr >= 256) + { + *sp-- = 255; + *sp-- = 0; /* mul is never zero normally */ + sqr-= 256; + } + } + sqr=(unsigned int)bits; /* set sqr to be the window size */ + + ss+=bits; /* ss is total shift for wl */ + if (ss >= BN_BITS2) /* adjust window words w,wl, wh again */ + { + if (top <= 1) break; + top--; + + wl=wh; + wh=(top <= 1)?0:(*(d++)); + ss-=BN_BITS2; + } + + if (ss == 0) + w=wl; + else + w=(wl>>ss)|(wh<<(BN_BITS2-ss)); + } + sp++; + i=2; + /* reverse the string from the top of the exponent string + * and copy to the bottom, allocated exponent string is 2 * max length + * expected for exponent string + */ + while (sp[0] != 0 || sp[1] != 0) + { + str[0]=sp[0]; + str[1]=sp[1]; + str+=2; + sp+=2; + i+=2; + } + str[0]=0; + str[1]=0; + + return( (int)i ); + } + +#ifdef MAIN +main() + { + BIGNUM p; + unsigned char buf[512],*pp; + int i; + + BN_init(&p); + BN_rand(&p,33,1,0); +#ifndef NO_FP_API + BN_print_fp(stdout,&p); fprintf(stdout,"\n"); +#endif + + BN_rand(&p,512,1,1); +#ifndef NO_FP_API + BN_print_fp(stdout,&p); fprintf(stdout,"\n"); +#endif + for (i=0; i<10000; i++) + BN_gen_exp_string(buf,&p,5); + +#if 0 + BN_gen_exp_string(buf,&p,3); + + pp=buf; + for (;;) + { + printf("mul %d sqr %d\n",pp[0],pp[1]); + if (pp[1] == 0) break; + pp+=2; + } +#endif + } +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_exp.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_exp.c new file mode 100644 index 00000000..723b62f5 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_exp.c @@ -0,0 +1,172 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_MOD_EXP_ORIG +#define SPLIT_BN_MOD_EXP +#endif /* NO_SPLIT */ + +#define TABLE_SIZE 16 + +#ifdef SPLIT_BN_MOD_EXP_ORIG +#if 0 +/* this one works - simple but works */ +int BN_mod_exp_orig(r,a,p,m,ctx) +BIGNUM *r,*a,*p,*m; +BN_CTX *ctx; + { + int i,bits,ret=0; + BIGNUM *v,*tmp; + + v= &(ctx->bn[ctx->tos++]); + tmp= &(ctx->bn[ctx->tos++]); + + if (BN_copy(v,a) == NULL) goto err; + bits=BN_num_bits(p); + + if (BN_is_odd(p)) + { if (BN_copy(r,a) == NULL) goto err; } + else { if (!BN_one(r)) goto err; } + + for (i=1; itos-=2; + return(ret); + } + +#endif + +/* this one works - simple but works */ +int BN_exp(r,a,p,ctx) +BIGNUM *r,*a,*p; +BN_CTX *ctx; + { + int i,bits,ret=0,tos; + BIGNUM *v,*rr; + + bn_check_top(a); + bn_check_top(p); + + tos=ctx->tos; + v= &(ctx->bn[ctx->tos++]); + if ((r == a) || (r == p)) + rr= &(ctx->bn[ctx->tos++]); + else + rr=r; + + if (BN_copy(v,a) == NULL) goto err; + bits=BN_num_bits(p); + + if (BN_is_odd(p)) + { if (BN_copy(rr,a) == NULL) goto err; } + else { if (!BN_one(rr)) goto err; } + + for (i=1; itos=tos; + if (r != rr) (void)BN_copy(r,rr); + return(ret); + } +#endif + +#ifdef SPLIT_BN_MOD_EXP +/** + * Perform mod exp on BIGNUM + * @param r Pointer to return value BIGNUM + * @param a Pointer to data value BIGNUM + * @param p Pointer to Public exponent BIGNUM + * @param m Pointer to modulus BIGNUM + * @param ctx Pointer to BN_CTX + * @return 0 success + * @pre BIGNUMs a, p, m and BN_CTX ctx exist and are valid + * @post BIGNUM r points to evaluated mod_exp + * @note BN_mod_exp_mont is only available if library compiled + * with define BN_MONT_MUL, and will only be used to compute + * mod_exp operation where the modulus m is odd. + * BN_mod_exp_recp is only available if library is compiled + * with define RECP_MUL_MOD. + * BN_mod_exp_simple is the default method, not available if + * library is compiled with define RECP_MUL_MOD. + * if BN_mod_exp_mont is available, which ever of BN_mod_exp_simple + * or BN_mod_exp_recp is available will only be used for even + * modulus m values. + * @relates BN_mod_exp_mont + * @relates BN_mod_exp_recp + * @relates BN_mod_exp_simple + */ +int BN_mod_exp(r,a,p,m,ctx) +BIGNUM *r; +BIGNUM *a; +BIGNUM *p; +BIGNUM *m; +BN_CTX *ctx; + { + int ret; + + bn_check_top(a); + bn_check_top(p); + bn_check_top(m); + +#ifdef MONT_MUL_MOD + + if (BN_is_odd(m)) + { ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); } + else +#endif +#ifdef RECP_MUL_MOD + { ret=BN_mod_exp_recp(r,a,p,m,ctx); } +#else + { ret=BN_mod_exp_simple(r,a,p,m,ctx); } +#endif + + return(ret); + } +#endif + +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_fm_w.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_fm_w.c new file mode 100644 index 00000000..54c67abb --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_fm_w.c @@ -0,0 +1,79 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +#include "bn_lcl.h" + +/* rp has w words, the top w words are 0 */ +void bn_from_montgomery_words(ret,a,np,w,n0) +BN_ULONG *ret; +BN_ULONG *a; +BN_ULONG *np; +int w; +BN_ULONG n0; + { + BN_ULONG v0,v1,*ap,*wap; + int i; + + v1=0; + + ap=a; + wap= &(a[w]); + /* Consider putting this loop in ASM */ + for (i=0; i0; i--) + if (ap[i] != np[i]) break; + } + v1=(ap[i] >= np[i]); + } + if (v1) + (void)bn_sub_words(ret,ap,np,w); + else + { +#if 0 /* Alpha does not like Memcpy */ + Memcpy(ret,ap,sizeof(BN_ULONG)*w); +#else + for (i=0; ibn[ctx->tos]); + b= &(ctx->bn[ctx->tos+1]); + + if (BN_copy(a,in_a) == NULL) goto err; + if (BN_copy(b,in_b) == NULL) goto err; + + if (BN_cmp(a,b) < 0) { t=a; a=b; b=t; } + t=bn_euclid(a,b); + if (t == NULL) goto err; + + if (BN_copy(r,t) == NULL) goto err; + ret=1; +err: + return(ret); + } + +BIGNUM *bn_euclid(a,b) +BIGNUM *a,*b; + { + BIGNUM *t; + int shifts=0; + + bn_check_top(a); + bn_check_top(b); + + for (;;) + { + if (BN_is_zero(b)) + break; + + if (BN_is_odd(a)) + { + if (BN_is_odd(b)) + { + if (!BN_sub(a,a,b)) goto err; + if (!BN_rshift1(a,a)) goto err; + if (BN_cmp(a,b) < 0) + { t=a; a=b; b=t; } + } + else /* a odd - b even */ + { + if (!BN_rshift1(b,b)) goto err; + if (BN_cmp(a,b) < 0) + { t=a; a=b; b=t; } + } + } + else /* a is even */ + { + if (BN_is_odd(b)) + { + if (!BN_rshift1(a,a)) goto err; + if (BN_cmp(a,b) < 0) + { t=a; a=b; b=t; } + } + else /* a even - b even */ + { + if (!BN_rshift1(a,a)) goto err; + if (!BN_rshift1(b,b)) goto err; + shifts++; + } + } + } + if (shifts) + { + if (!BN_lshift(a,a,shifts)) goto err; + } + return(a); +err: + return(NULL); + } +#endif + +#ifdef SPLIT_BN_MOD_INVERSE +/* solves ax == 1 (mod n) */ +BIGNUM *BN_mod_inverse(in, a, n, ctx) +BIGNUM *in; +BIGNUM *a; +BIGNUM *n; +BN_CTX *ctx; + { + BIGNUM *A,*B,*X,*Y,*M,*D,*R; + BIGNUM *T,*ret=NULL; + int sign; + + bn_check_top(a); + bn_check_top(n); + + A= &(ctx->bn[ctx->tos]); + B= &(ctx->bn[ctx->tos+1]); + X= &(ctx->bn[ctx->tos+2]); + D= &(ctx->bn[ctx->tos+3]); + M= &(ctx->bn[ctx->tos+4]); + Y= &(ctx->bn[ctx->tos+5]); + ctx->tos+=6; + if (in == NULL) + R=BN_new(); + else + R=in; + if (R == NULL) goto err; + + (void)BN_zero(X); + (void)BN_one(Y); + if (BN_copy(A,a) == NULL) goto err; + if (BN_copy(B,n) == NULL) goto err; + sign=1; + + while (!BN_is_zero(B)) + { + if (!BN_div(D,M,A,B,ctx)) goto err; + T=A; + A=B; + B=M; + /* T has a struct, M does not */ + + if (!BN_mul(T,D,X,ctx)) goto err; + if (!BN_add(T,T,Y)) goto err; + M=Y; + Y=X; + X=T; + sign= -sign; + } + if (sign < 0) + { + if (!BN_sub(Y,n,Y)) goto err; + } + + if (BN_is_one(A)) + { if (!BN_mod(R,Y,n,ctx)) goto err; } + else + { +#ifndef NO_ERR + BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE); +#endif + goto err; + } + ret=R; +err: + if ((ret == NULL) && (in == NULL)) BN_free(R); + ctx->tos-=6; + return(ret); + } +#endif + +#ifdef SPLIT_BN_MOD_INVERSE_WORD +/* solves 1 == (ret*(1<l + * @param l [In] a word (size of word depends on machine) + * @returns number of bits in parameter l + */ +#ifdef SPLIT_BN_NUM_BITS_WORD +int BN_num_bits_word(l) +BN_ILONG l; + { + int i; + + /* + * This table represents the number of bits required to + * represent a "number", where "number" is indexed from + * 0 into the table. So: + * number 0 = # bits req'd to represent 0 = bits[0] = 0 + * number 1 = # bits req'd to represent 1 = bits[1] = 1 + * number 2 = # bits req'd to represent 2 = bits[2] = 2 + * number 3 = # bits req'd to represent 3 = bits[3] = 2 + * number 4 = # bits req'd to represent 4 = bits[4] = 3 + * etc. + * + * The small code size table exists to save some space, + * but requires (at most) an extra shift, an extra AND, + * and an extra add. + */ +#ifdef SMALL_CODE_SIZE + const static char bits[16]={ + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4 + }; +#else + const static char bits[256]={ + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4, + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + }; +#endif + +#if defined(SIXTY_FOUR_BIT_LONG) + if (l & 0xffffffff00000000L) + { + if (l & 0xffff000000000000L) + { + if (l & 0xff00000000000000L) + i=56; + else i=48; + } + else + { + if (l & 0x0000ff0000000000L) + i=40; + else i=32; + } + } + else +#else +#ifdef SIXTY_FOUR_BIT + if (l & 0xffffffff00000000LL) + { + if (l & 0xffff000000000000LL) + { + if (l & 0xff00000000000000LL) + i=56; + else i=48; + } + else + { + if (l & 0x0000ff0000000000LL) + i=40; + else i=32; + } + } + else +#endif +#endif + { +#if defined(THIRTY_BIT) || defined(THIRTY_ONE_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) + if (l & 0xffff0000L) + { + if (l & 0xff000000L) + i=24; + else i=16; + } + else +#endif + { + if (l & 0xff00L) + i=8; + else + i=0; + } + } +#ifndef SMALL_CODE_SIZE + return(i+bits[l>>i]); +#else + l>>=i; + if (l & 0xf0) + return(bits[l>>4]+i+4); + else + return(bits[l]+i); +#endif + } +#endif + +#ifdef SPLIT_BN_NUM_BITS +int BN_num_bits(a) +BIGNUM *a; + { + BN_ULONG l; + int i; + + bn_check_top(a); + + if (a->top == 0) return(0); + l=a->d[a->top-1]; + i=(a->top-1)*BN_BITS2; +#ifdef BN_DEBUG + if (l == 0) + { +#if !defined(NO_FP_API) && !defined(WIN16) + fprintf(stderr,"BAD TOP VALUE\n"); +#endif + abort(); /* BN_DEBUG */ + /* TODO: need to understand what sort of error can + * be reported for this error + */ + return(0); + } +#endif + return(i+BN_num_bits_word(l)); + } +#endif + +/** + * Clears and free a BIGNUM + * + * @param a [In] BIGNUM to clear then free + */ +#ifdef SPLIT_BN_CLEAR_FREE +void BN_clear_free(BIGNUM *a) +{ + if (a == NULL) + { + return; + } + + BN_clear(a); + BN_free(a); +} +#endif + +#ifdef SPLIT_BN_FREE +/** + * Frees a BIGNUM + * + * @param a [In] BIGNUM to free + */ +void BN_free(a) +BIGNUM *a; + { + if (a == NULL) return; + if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA))) + Free(a->d); + a->flags|=BN_FLG_FREE; /* REMOVE? */ + if (a->flags & BN_FLG_MALLOCED) + Free(a); + } +#endif + +#ifdef SPLIT_BN_INIT + +#ifdef SMALL_CODE_SIZE +/** + * Zero expands a bignum + * + * @param a [In] BIGNUM to expand + * @param n [In] number of bits to expand to + * + * @pre a is a valid BIGNUM. + */ +void bn_zexpand(a,n) +BIGNUM *a; +int n; + { + if ((a)->top < n) + { + int i; + bn_wexpand((a),n); + if (a->d!=NULL) + { + for (i=(a)->top; id[i]=0; + } + } + } + +/** + * Fixes the top value in the BIGNUM to be the count of BN_ULONGs with data. + * + * @param a [In] BIGNUM to free + * + * @pre a is a valid BIGNUM. + */ +void bn_fix_top(a) +BIGNUM *a; + { + BN_ULONG *ftl; + if ((a)->top > 0) + { + for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) + if (*(ftl--)) break; + } + } +#endif + +/** + * Initializes a BIGNUM + * + * @param a [In] BIGNUM reference + * + * @pre a is a valid BIGNUM. + */ +void BN_init(a) +BIGNUM *a; + { + (void)Memset(a,0,sizeof(BIGNUM)); + } +#endif + +#ifdef SPLIT_BN_NEW +/** + * Allocates a BIGNUM + * + * @return pointer to allocated BIGNUM + */ +BIGNUM *BN_new() + { + BIGNUM *ret; + + if ((ret=(BIGNUM *)Malloc(sizeof(BIGNUM))) == NULL) + { +#ifndef NO_ERR + BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE); +#endif + return(NULL); + } + ret->flags=BN_FLG_MALLOCED; + ret->top=0; + ret->neg=0; + ret->max=0; + ret->d=NULL; + return(ret); + } +#endif + +#ifdef SPLIT_BN_CTX_NEW +/** + * Allocates a BIGNUM context + * + * @return pointer to allocated BIGNUM context + */ +BN_CTX *BN_CTX_new() + { + BN_CTX *ret; + + ret=(BN_CTX *)Malloc(sizeof(BN_CTX)); + if (ret == NULL) + { +#ifndef NO_ERR + BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE); +#endif + return(NULL); + } + + BN_CTX_init(ret); + ret->flags=BN_FLG_MALLOCED; + return(ret); + } +#endif + +#ifdef SPLIT_CTX_INIT +/** + * Initializes a BIGNUM context + * + * @param a [In] BIGNUM context reference + * + * @pre a is a valid BIGNUM context. + */ +void BN_CTX_init(ctx) +BN_CTX *ctx; + { + (void)Memset(ctx,0,sizeof(BN_CTX)); + ctx->tos=0; + ctx->flags=0; + } +#endif + +#ifdef SPLIT_BN_CTX_FREE +/** + * Frees a BIGNUM context + * + * @param a [In] BIGNUM context reference + * + * @pre a is a valid BIGNUM context. + */ +void BN_CTX_free(c) +BN_CTX *c; + { + int i; + + for (i=0; ibn[i])); + if (c->flags & BN_FLG_MALLOCED) + Free(c); + } +#endif + +#ifdef SPLIT_BN_EXPAND2 +BIGNUM *bn_expand2(b, words) +BIGNUM *b; +int words; + { + BN_ULONG *A,*B,*a; + + R_DIAG_CHECK_STACK; + + bn_check_top(b); + + if (words > b->max) + { + bn_check_top(b); + if (BN_get_flags(b,BN_FLG_STATIC_DATA)) + { +#ifndef NO_ERR + BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); +#endif + return(NULL); + } + a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1)); + if (A == NULL) + { +#ifndef NO_ERR + BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); +#endif + return(NULL); + } + /* during development this is a nice way of making sure + * that we are not relying on the top byte being 0 or + * other such things + */ +#ifdef BN_DEBUG + (void)Memset(A,0x5c,sizeof(BN_ULONG)*(words+1)); +#endif + + B=b->d; + if (B != NULL) + { +#ifndef SMALL_CODE_SIZE + int i; + + /* for (i=b->top&(~7); i>0; i-=8) */ + /* The above line can induce a SunC compiler bug */ + for (i=(b->top>>3); i>0; i--) + { + BN_ULONG T0,T1,T2,T3; + + T0=B[0]; + T1=B[1]; + T2=B[2]; + T3=B[3]; + A[0]=T0; + A[1]=T1; + A[2]=T2; + A[3]=T3; + T0=B[4]; + T1=B[5]; + T2=B[6]; + T3=B[7]; + A[4]=T0; + A[5]=T1; + A[6]=T2; + A[7]=T3; + A+=8; + B+=8; + } + switch (b->top&7) + { + case 7: + A[6]=B[6]; + case 6: + A[5]=B[5]; + case 5: + A[4]=B[4]; + case 4: + A[3]=B[3]; + case 3: + A[2]=B[2]; + case 2: + A[1]=B[1]; + case 1: + A[0]=B[0]; + case 0: + /* I need the 'case 0' entry for utrix cc. + * If the optimiser is turned on, it does the + * switch table by doing + * a=top&7 + * a--; + * goto jump_table[a]; + * If top is 0, this makes us jump to 0xffffffc + * which is rather bad. + * eric 23-Apr-1998 + */ + ; + } +#if 0 /* Not needed */ + B= &(b->d[b->top]); + j=b->max-8; + for (i=b->top; itop); +#endif + Free(b->d); + } + + b->d=a; + b->max=words; + } + return(b); + } +#endif + +#ifdef SPLIT_BN_DUP +/** + * Duplicates a BIGNUM + * + * @param a [In] BIGNUM reference + * + * @returns pointer to duplicate BIGNUM of a + */ +BIGNUM *BN_dup(a) +BIGNUM *a; + { + BIGNUM *r; + BIGNUM *ret; + + bn_check_top(a); + + r=BN_new(); + if (r == NULL) return(NULL); + ret = (BIGNUM *)BN_copy(r,a); + if (ret == NULL) + { + BN_free(r); + } + return(ret); + } +#endif + +#ifdef SPLIT_BN_COPY +/** + * Copies a BIGNUM to an existing BIGNUM + * + * @param a [In] To BIGNUM reference + * @param b [Out] From BIGNUM reference + * + * @pre Both a and b are valid BIGNUMs + * + * @returns pointer to duplicate BIGNUM of a + */ +BIGNUM *BN_copy(a, b) +BIGNUM *a; +BIGNUM *b; + { +#ifndef SMALL_CODE_SIZE + int i; + BN_ULONG *A,*B; +#endif + + bn_check_top(b); + + if (a == b) return(a); + if (bn_wexpand(a,b->top) == NULL) return(NULL); +#ifndef SMALL_CODE_SIZE + A=a->d; + B=b->d; + +/* for (i=b->top&~0x07; i>0; i-=8) */ +/* The above version of this loop has been removed. It appeared + to generate a compiler bug in SunC 4.x and 5.x. I do not believe + that the code was to blame. Compiling with -fast was the problem + since this would loop unroll the loop below another 3 times. + The compiler would generate generate + andcc %o0,-8,%o1 # load ~0x07 + ld [%i2],%o3 # load *B + ble .L77000125 # exit loop unless 8 or more + ld [%i1],%o2 # load *A + sub %o1,-7,%o0 # + sdivcc %o0,8,%o0 # when do we clear %y? + bvs,a .L900001510 + sethi %hi(0x80000000),%o0 +.L900001510: + cmp %o0,3 + bl .L77000114 # one loop + ld [%o2],%o0 + # three loop code + + The loop would then be unrolled 3 times. The problem I believe + I was seeing was that the sdivcc operates is %y:%o0 / 8. + %y is not being cleared, and so occasionally this would + cause problems. The replacement code sequence stops + the compiler generating the sdiv instruction. + */ + for (i=(b->top>>3); i>0; i--) + { + BN_ULONG T0,T1,T2,T3; + T0=B[0]; + T1=B[1]; + T2=B[2]; + T3=B[3]; + A[0]=T0; + A[1]=T1; + A[2]=T2; + A[3]=T3; + T0=B[4]; + T1=B[5]; + T2=B[6]; + T3=B[7]; + A[4]=T0; + A[5]=T1; + A[6]=T2; + A[7]=T3; + A+=8; + B+=8; + } + switch (b->top&0x07) + { + case 7: + A[6]=B[6]; + case 6: + A[5]=B[5]; + case 5: + A[4]=B[4]; + case 4: + A[3]=B[3]; + case 3: + A[2]=B[2]; + case 2: + A[1]=B[1]; + case 1: + A[0]=B[0]; + case 0: + /* I need the 'case 0' entry for utrix cc. + * If the optimiser is turned on, it does the + * switch table by doing + * a=top&7 + * a--; + * goto jump_table[a]; + * If top is 0, this makes us jump to 0xffffffc which is + * rather bad. + * eric 23-Apr-1998 + */ + ; + } +#else + (void)Memcpy(a->d,b->d,sizeof(b->d[0])*b->top); +#endif + +/* (void)Memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/ + a->top=b->top; + if ((a->top == 0) && (a->d != NULL)) + a->d[0]=0; + a->neg=b->neg; + return(a); + } +#endif + +#ifdef SPLIT_BN_CLEAR +/** + * Clears a BIGNUM + * + * @param a [In] BIGNUM to clear + * + * @pre a is valid + */ +void BN_clear(a) +BIGNUM *a; + { + if (a->d != NULL) + (void)Memset(a->d,0,a->max*sizeof(a->d[0])); + a->top=0; + a->neg=0; + } +#endif + +#ifdef SPLIT_BN_GET_WORD +BN_ULONG BN_get_word(a) +BIGNUM *a; + { + int i,n; + BN_ULONG ret=0; + + n=BN_num_bytes(a); + if (n > ((int) sizeof(BN_ULONG))) + return(BN_MASK2); + for (i=a->top-1; i>=0; i--) + { +#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ + ret<<=BN_BITS4; /* stops the compiler complaining */ + ret<<=BN_BITS4; +#else + ret=0; +#endif + ret|=a->d[i]; + } + return(ret); + } +#endif + +#ifdef SPLIT_BN_SET_WORD +/** + * Set the BIGNUM to the supplied BN_ULONG value. + * + * @param a [In/Out] BIGNUM to be updated + * @param w [In] Value to be set in a + * + * @notes Function will expand a to be an + * array of 8 BN_ULONGs in size. + * @todo Review behaviour of expansion without checking + * of size first. + */ +int BN_set_word(a,w) +BIGNUM *a; +BN_ULONG w; + { + int i,n; + + if (bn_expand(a,(int)(sizeof(BN_ULONG)*8)) == NULL) return(0); + +#ifdef BN_BYTES + /* This is used when a BN_ULONG is greater in size + * than the BN_BYTES of the array, eg BN_ULONG 64 bits + * and actual a->d array of 32 bits. + */ + n=sizeof(BN_ULONG)/BN_BYTES; +#else + n=1; +#endif + a->neg=0; + a->top=0; + a->d[0]=(BN_ULONG)w&BN_MASK2; + if (a->d[0] != 0) a->top=1; + for (i=1; i>=BN_BITS2 so compilers don't complain + * on builds where sizeof(long) == BN_TYPES */ +#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ + w>>=BN_BITS4; + w>>=BN_BITS4; +#else + w=0; +#endif + a->d[i]=(BN_ULONG)w&BN_MASK2; + if (a->d[i] != 0) a->top=i+1; + } + return(1); + } +#endif + +#ifdef BN_BYTES +#ifdef SPLIT_BN_BIN2BN +/* ignore negative */ +BIGNUM *BN_bin2bn(s, len, ret) +unsigned char *s; +int len; +BIGNUM *ret; + { + int i,m; + int n; + BN_ULONG l; + + if (ret == NULL) ret=BN_new(); + if (ret == NULL) return(NULL); + l=0; + n=len; + if (n == 0) + { + ret->top=0; + return(ret); + } + if (bn_expand(ret,(int)(n+2)*8) == NULL) + return(NULL); + i=((n-1)/BN_BYTES)+1; + m=((n-1)%(BN_BYTES)); + ret->top=i; + while (n-- > 0) + { + l=(l<<8L)| *(s++); + if (m-- == 0) + { + ret->d[--i]=l; + l=0; + m=BN_BYTES-1; + } + } + /* need to call this due to clear byte at top if avoiding + * having the top bit set (-ve number) */ + bn_fix_top(ret); + return(ret); + } +#endif + +#ifdef SPLIT_BN_BN2BIN +/* ignore negative */ +int BN_bn2bin(a, to) +BIGNUM *a; +unsigned char *to; + { + int n,i; + BN_ULONG l; + + bn_check_top(a); + + n=i=BN_num_bytes(a); + while (i-- > 0) + { + l=a->d[i/BN_BYTES]; + *(to++)=(unsigned char)((l>>(8*(i%BN_BYTES)))&0xff); + } + return(n); + } +#endif +#else +#ifdef SPLIT_BN_BIN2BN +/* ignore negative */ +BIGNUM *BN_bin2bn(s, len, ret) +unsigned char *s; +int len; +BIGNUM *ret; + { + int i,w,r,b,j,v; + int n; + BN_ULONG l; + + if (ret == NULL) ret=BN_new(); + if (ret == NULL) return(NULL); + while (len > 0) + { + if (*s != 0) break; + s++; + len--; + } + n=len*8; + if (bn_expand(ret,n) == NULL) + return(NULL); + for (i=0; imax; i++) + ret->d[i]=0; + j=0; + for (i=len-1; i>=0; i--) + { + v=((int)s[i])&0xff; + w=j/BN_BITS2; + b=j%BN_BITS2; + r=BN_BITS2-b; + j+=8; + if (r >= 8) + { + ret->d[w]|=(((BN_ULONG)v)<d[w] =(ret->d[w]|(((BN_ULONG)v)<d[w+1]=(ret->d[w+1]|(((BN_ULONG)v)>>r)); + } + } + + ret->top=((n-1)/BN_BITS2)+1; + bn_fix_top(ret); + return(ret); + } +#endif + +#ifdef SPLIT_BN_BN2BIN +int BN_bn2bin(a, to) +BIGNUM *a; +unsigned char *to; + { + int num,i,bi,w,b,r,max; + BN_ULONG l,*lp; + + bn_check_top(a); + + num=bi=BN_num_bytes(a); + lp=a->d; + for (i=0; i= 8) + to[bi]=(lp[w]>>b)&0xff; + else + { + to[bi]=(lp[w]>>b); + if (w+1 < a->top) + to[bi]|=lp[w+1]<top-b->top; + if (i != 0) return(i); + ap=a->d; + bp=b->d; + for (i=a->top-1; i>=0; i--) + { + t1= ap[i]; + t2= bp[i]; + if (t1 != t2) + return(t1 > t2?1:-1); + } + return(0); + } +#endif + +#ifdef SPLIT_BN_CMP +int BN_cmp(a, b) +BIGNUM *a; +BIGNUM *b; + { + int i; + int gt,lt; + BN_ULONG t1,t2; + + if ((a == NULL) || (b == NULL)) + { + if (a != NULL) + return(-1); + else if (b != NULL) + return(1); + else + return(0); + } + + bn_check_top(a); + bn_check_top(b); + + if (a->neg != b->neg) + { + if (a->neg) + return(-1); + else return(1); + } + if (a->neg == 0) + { gt=1; lt= -1; } + else { gt= -1; lt=1; } + + if (a->top > b->top) return(gt); + if (a->top < b->top) return(lt); + for (i=a->top-1; i>=0; i--) + { + t1=a->d[i]; + t2=b->d[i]; + if (t1 > t2) return(gt); + if (t1 < t2) return(lt); + } + return(0); + } +#endif + +#ifdef SPLIT_BN_SET_BIT +int BN_set_bit(a, n) +BIGNUM *a; +int n; + { + int i,j,k; + + bn_check_top(a); + + i=n/BN_BITS2; + j=n%BN_BITS2; + if (a->top <= i) + { + if (bn_wexpand(a,i+1) == NULL) return(0); + for(k=a->top; kd[k]=0; + a->top=i+1; + } + + a->d[i]|=(((BN_ULONG)1)<top <= i) return(0); + + a->d[i]&=(~(((BN_ULONG)1)<top <= i) return(0); + return((a->d[i]&(((BN_ULONG)1)<= a->top) return(0); + if (b == 0) + a->top=w; + else + { + a->top=w+1; + a->d[w]&= ~(((BN_ULONG)BN_MASK2)< bb)?1:-1); + for (i=n-2; i>=0; i--) + { + aa=a[i]; + bb=b[i]; + if (aa != bb) return((aa > bb)?1:-1); + } + return(0); + } +#endif +#endif + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_lsh.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_lsh.c new file mode 100644 index 00000000..21508b16 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_lsh.c @@ -0,0 +1,128 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_LSHIFT1 +#define SPLIT_BN_LSHIFT +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BN_LSHIFT1 +#ifdef SMALL_CODE_SIZE + +int BN_lshift1(r, a) +BIGNUM *r,*a; + { + return(BN_lshift(r, a, 1)); + } + +#else + +int BN_lshift1(r, a) +BIGNUM *r; +BIGNUM *a; + { + register BN_ULONG *ap,*rp,t,c; + int i; + + bn_check_top(a); + + if (r != a) + { + if (bn_wexpand(r,a->top+1) == NULL) return(0); + r->neg=a->neg; + r->top=a->top; + } + else + { + if (bn_wexpand(r,a->top+1) == NULL) return(0); + } + ap=a->d; + rp=r->d; + c=0; + for (i=0; itop; i++) + { + t= *(ap++); + *(rp++)=((t<<1L)|c)&BN_MASK2; + c=(t & BN_TBIT)?1:0; + } + if (c) + { + *rp=1; + r->top++; + } + return(1); + } +#endif +#endif + +#ifdef SPLIT_BN_LSHIFT +int BN_lshift(r, a, n) +BIGNUM *r; +BIGNUM *a; +int n; + { + int i,nw,lb,rb; + BN_ULONG *t,*f; + BN_ULONG l; + + bn_check_top(a); + +#ifndef SMALL_CODE_SIZE + if (n == 1) return(BN_lshift1(r,a)); +#endif + if (bn_wexpand(r,a->top+(n/BN_BITS2)+1) == NULL) return(0); + r->neg=a->neg; + nw=n/BN_BITS2; + lb=n%BN_BITS2; + rb=BN_BITS2-lb; + f=a->d; + t=r->d; + t[a->top+nw]=0; + if (lb == 0) + for (i=a->top-1; i>=0; i--) + t[nw+i]=f[i]; + else + for (i=a->top-1; i>=0; i--) + { + l=f[i]; + t[nw+i+1]|=(l>>rb)&BN_MASK2; + t[nw+i]=(l<top=a->top+nw+1; + bn_fix_top(r); + return(1); + } +#endif + +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_m_exp.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_m_exp.c new file mode 100644 index 00000000..480bb599 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_m_exp.c @@ -0,0 +1,299 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#if 0 //RSA +#include +#endif +#include "bn_lcl.h" + +/* #ifdef MONT_MUL_MOD */ +/** + * Generic form of Montgomery Exponentiation, can be called directly + * out side of a BN_ME_METH + * + * @param rr_in BIGNUM pointer for result + * @param a_in BIGNUM pointer for base + * @param p BIGNUM pointer to the exponent + * @param m BIGNUM pointer to the modulus + * @param ctx BN_CTX pointer for temp values are argument storage + * @param in_mont BN_MONT_CTX pointer to structure of montgomery values + * + * @pre arguments are all initialised and not NULL or zero + * @post rr_in contains evaluated result + * + * @note + */ +int BN_mod_exp_mont(rr_in,a_in,p,m,ctx,in_mont) +BIGNUM *rr_in; +BIGNUM *a_in; +BIGNUM *p; +BIGNUM *m; +BN_CTX *ctx; +BN_MONT_CTX *in_mont; + { + int i,j,k,ret=0,tos,top; + int mul,sqr,num; + BIGNUM *d,*aa,*r,*a,*t; + BN_ULONG *vall[BN_EXP_TABLE_SIZE],*dp,*rp,n0,*rr,*tmp,*np; + BN_MONT_CTX *mont=NULL; + unsigned char *str=NULL; +#ifdef BN_SURRENDER + R_SURRENDER *surrender=NULL; + int count=0; +#endif + + bn_check_top(a_in); + bn_check_top(p); + bn_check_top(m); + + if (!(m->d[0] & 1)) + { +#ifndef NO_ERR + BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); +#endif + return(0); + } + + tos=ctx->tos; + + if (BN_is_zero(a_in)) + { (void)BN_zero(rr_in); return(1); } + if (BN_is_zero(p)) + { (void)BN_one(rr_in); return(1); } + if (BN_is_one(p)) + { (void)BN_copy(rr_in,a_in); return(1); } + + /* If this is not done, things will break in the montgomery + * part */ + +#if 1 + if (in_mont != NULL) + mont=in_mont; + else +#endif + { + if ((mont=BN_MONT_CTX_new()) == NULL) goto err; + if (!BN_MONT_CTX_set(mont,m,ctx)) goto err; + } + +#ifdef BN_SURRENDER + surrender=ctx->surrender; +#endif + + if (!BN_gen_exp_bits(p,&str,0,ctx)) goto err; + /* Remember this function uses another element from the passed ctx */ + ctx->tos++; + num=str[3]; + i=(BN_BITS+str[2]-1)/str[2]; + str+=4; + + + top=mont->N.top; + if ((a_in->top == top) && (a_in->d[top-1] < m->d[top-1])) + { + a=a_in; + } + else if (a_in->top < top) + { + a= &(ctx->bn[ctx->tos++]); + a->top=a_in->top; + bn_zexpand(a,top); + for (j=0; jtop; j++) + a->d[j]=a_in->d[j]; + } + else /* if (a_in->top > i) */ + { + a= &(ctx->bn[ctx->tos++]); + if (!BN_mod(a,a_in,m,ctx)) goto err; + bn_zexpand(a,top); + } + + /* At this point a is the size of the modulus and is 0 padded + * out to its size if needed. + */ + + /* Number of tmp words */ + k=num*top; + j=k+(p->top*i*2+BN_BYTES-1+4)/BN_BYTES; + + aa=&(ctx->bn[ctx->tos++]); + d= &(ctx->bn[ctx->tos++]); + r= &(ctx->bn[ctx->tos++]); + t= &(ctx->bn[ctx->tos++]); + + if (bn_wexpand(rr_in,top) == NULL) goto err; + if (bn_wexpand(d,top*4) == NULL) goto err; /* *2? */ + if (bn_wexpand(r,top*2) == NULL) goto err; + if (bn_wexpand(aa,j) == NULL) goto err; + if (bn_wexpand(t,top*2) == NULL) goto err; + dp=d->d; + rp=r->d; + tmp=t->d; + rr=mont->RR.d; + + n0=mont->n0; + np=mont->N.d; + + vall[0]=aa->d; + + bn_mul_normal(tmp,a->d,top,rr,top); + bn_from_montgomery_words(vall[0],tmp,np,top,n0); + + if (num > 1) + { + bn_sqr_normal(tmp,vall[0],top,dp); + bn_from_montgomery_words(dp,tmp,np,top,n0); + + for (i=1; i>1],sizeof(BN_ULONG)*top); + while (sqr != 0) + { +#ifdef BN_SURRENDER + /* + * Check this at the start of the loop rather than the + * end so we avoid as many of the bn operations as possible + */ + if (surrender != NULL) + { + if (surrender->callback(surrender,0xff, count++) != 0) + { + goto err; + } + } +#endif /* BN_SURRENDER */ + + /* + * check the abort flag at the start of the loop so we avoid + * as many of the bn operations as possible + */ + if (BN_CTX_get_flags(ctx, BN_CTX_FLG_ABORT)) + { + goto err; + } + + for (i=0; i>1],top); + bn_from_montgomery_words(rp,tmp,np,top,n0); + } + else + { + bn_mul_normal(tmp,rp,top,a->d,top); + bn_from_montgomery_words(rr_in->d,tmp,np,top,n0); + goto end; + } + } + + /* if (mul != 1) */ + { + for (i=top; id,rp,np,top,n0); + } +end: /* Use this to avoid an if */ + + /* + * Even if the operation has completed successfully, if the + * abort flag is set we want to abort so that anything + * calling this function will know not to continue. + */ + if (BN_CTX_get_flags(ctx, BN_CTX_FLG_ABORT)) + { + goto err; + } + + rr_in->top=top; + bn_fix_top(rr_in); + ret=1; +err: +#ifdef BN_SURRENDER + /* + * Even if the operation completed successfully we want to abort + * if the abort flag has been is set, so that subsequent operations + * do not continue. Allow the caller change to return value and + * cause the function to fail. + */ + if (surrender != NULL) + { + if (surrender->callback(surrender, 0xff, -1) != 0) + { + ret = 0; + } + } +#endif + if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); + ctx->tos=tos; + return(ret); + } +/* #endif */ + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_me.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_me.c new file mode 100644 index 00000000..fae07491 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_me.c @@ -0,0 +1,267 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/** + * @file bn_me.c + * @brief BN method functions and utilities + */ +#include "bn_lcl.h" +#include "bn_thx.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_MOD_EXP_METH_DEFAULT +#define SPLIT_BN_MONT_CTX_USEIT +#define SPLIT_BN_ME_CTX_NAME +#define SPLIT_BN_ME_CTX_NEW +#define SPLIT_BN_ME_CTX_FREE +#define SPLIT_BN_ME_CTX_SET +#define SPLIT_BN_ME_CTX_MOD_EXP +#endif /* NO_SPLIT */ + +#ifndef NOPROTO +BN_ME_METH *bn_mod_exp_meth_default(int fallback); +#else +BN_ME_METH *bn_mod_exp_meth_default(); +#endif + +#ifdef SPLIT_BN_MOD_EXP_METH_DEFAULT + +/** + * Returns the default mod_exp method, choose first available in the + * method table or a hardwired default + * + * @param fallback [In] Flag for choice of method + * - 0 use the first value in the method table + * - 1 use the all encompassing default method + * + * @pre BN_default_init() has been run setting up library + * + * @post + * + * @internal uses global table bnme[] and counter me_num + * + * @internal only read the BN_ME_METH_INFO table no need for locking + * + * @relates BN_library_init + * @relates BN_default_init + * @relates BN_ME_CTX_new + * @relates BN_ME_CTX_free + * + */ +BN_ME_METH *bn_mod_exp_meth_default(int fallback) +{ + const BN_ME_METH *tmp; + +#ifndef BN_LIBRARY_SMALL + BN_ME_METH_INFO *meth_info; + + if(!fallback && ((meth_info = BN_bnme_get_info(0)) != NULL)) + { + tmp = meth_info->meth(); + } + else +#endif + { + /* set in bn.h or override bn_thx.h */ + tmp = BN_ME_METH_DEFAULT(); + } + return((BN_ME_METH *)tmp); +} +#endif + +#ifdef SPLIT_BN_MONT_CTX_USEIT + +#ifndef NOPROTO +int bn_mont_ctx_useit(int argi); +#else +int bn_mont_ctx_useit(); +#endif + +/** + * Montgomery method default useit function + * + * @param argi [In] reserved for future use + * + * @return 0 success + */ +int bn_mont_ctx_useit(int argi) + { + return(0); + } +#endif + +#ifdef SPLIT_BN_ME_CTX_NAME +/** + * Retrieve the BN method name string + * + * @param ctx [In] Method + * + * @pre ctx is valid and not NULL + * + * @return string pointer + */ +char *BN_ME_CTX_name(BN_ME_CTX *ctx) + { + return(ctx->meth->name); + } +#endif + +#ifdef SPLIT_BN_ME_CTX_NEW +/** + * Allocate a new BN_ME_CTX structure and assign method + * + * @param meth [In] Method to assign + * @param in [Out] Result BN_ME_CTX + * + * @note if meth is NULL system method default is used + * + * @retval pointer to BN_ME_CTX success + * @retval NULL failure + */ +BN_ME_CTX *BN_ME_CTX_new(BN_ME_METH *meth, BN_ME_CTX **in) + { + int i; + BN_ME_CTX *ret; + + if (in == NULL) + in= &ret; + + if (meth == NULL) + meth=bn_mod_exp_meth_default(0); + i=meth->init_ctx(meth,in); + if (i) + return(NULL); + else + return(*in); + } +#endif + +#ifdef SPLIT_BN_ME_CTX_FREE +/** + * Free context method + * + * @param mctx [In] Context object to be deallocated + * + * @note it is the callers responsibility to set mctx to NULL after free + * + * @pre mctx is not NULL and is valide BN_ME_CTX + */ +void BN_ME_CTX_free(BN_ME_CTX *mctx) + { + mctx->meth->free_ctx(mctx); + } +#endif + +#ifdef SPLIT_BN_ME_CTX_SET +/** + * Set value to BN_ME_CTX by identifier + * + * @param mctx [In] Method context object + * @param b [In] Big number + * @param cmd [In] Command identifier + * @param flags [In] Mask operation directives + * @param ctx [In] BN data store + * + * @note cmd values: + * @li BN_ME_SET_MOD will cause a method lookup is method not set + * + * @note passes control to set method in mctx + * + * @return result of mctx method set operation + */ +int BN_ME_CTX_set(BN_ME_CTX *mctx, BIGNUM *b, int cmd, int flags, BN_CTX *ctx) + { +#ifndef BN_LIBRARY_SMALL +#ifndef NOPROTO + const BN_ME_METH *(*meth)(void); +#else + const BN_ME_METH *(*meth)(); +#endif +#endif /* BN_LIBRARY_SMALL */ + + /* If we are loading the modulus, and we do not have the + * no_lookup flag (without a null method) + */ + if ((cmd == BN_ME_SET_MOD) && + ((mctx->meth != NULL) && !(flags & BN_ME_SET_FLG_NO_LOOKUP))) + { +#ifndef BN_LIBRARY_SMALL + meth=(const BN_ME_METH*(*)(void)) + BN_bnme_get(BN_num_bits(b),BN_BNME_F_BITS); + if (meth != NULL) + mctx->meth=meth(); + else +#endif + mctx->meth=bn_mod_exp_meth_default(1); + } + return(mctx->meth->set(mctx,b,cmd,flags,ctx)); + } +#endif + +#ifdef SPLIT_BN_ME_CTX_MOD_EXP +/** + * Call method mod_exp operation + * + * @param mctx [In] Method context object + * @param ret [Out] Result + * @param a [In] Base value + * @param p [In] Exponent + * @param m [In] Modulus + * @param ctx [In] Data storage + * + * @pre a must be expandable + * + * @return 0 success + */ +int BN_ME_CTX_mod_exp(BN_ME_CTX *mctx, BIGNUM *ret, BIGNUM *a, BIGNUM *p, + BIGNUM *m, BN_CTX *ctx) + { + int wtop; + + /* Before we call the method, make sure we are not doing 0^p, + * and p is not 0 or 1 */ + if (BN_is_zero(a)) + { BN_zero(ret); return(0); } + if (p != NULL) + { + if (BN_is_zero(p)) + { BN_one(ret); return(0); } + else if (BN_is_one(p)) + { BN_copy(ret,a); return(0); } + } + + /* wtop is the size 'a' needs to be for the method */ + wtop=mctx->meth->num; + bn_zexpand(a,wtop); + + return(mctx->meth->mod_exp(mctx,ret,a,p,ctx)); + } +#endif + +#endif + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_mont.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_mont.c new file mode 100644 index 00000000..d6a45def --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_mont.c @@ -0,0 +1,247 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#undef BN_DEBUG +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_MOD_MUL_MONTGOMERY +#define SPLIT_BN_FROM_MONTGOMERY +#define SPLIT_BN_MONT_CTX_NEW +#define SPLIT_BN_MONT_CTX_INIT +#define SPLIT_BN_MONT_CTX_FREE +#define SPLIT_BN_MONT_CTX_COPY +#endif /* NO_SPLIT */ + +/* #define DEBUG */ + +#ifdef SPLIT_BN_MOD_MUL_MONTGOMERY +/* We multiply a by b, generating a number 2n words long. + * This is then reduced by the montogmery number, which is + * n words. */ +int BN_mod_mul_montgomery(r,a,b,mont,ctx) +BIGNUM *r,*a,*b; +BN_MONT_CTX *mont; +BN_CTX *ctx; + { + BIGNUM *tmp,*tmp2; + int ret=0,w; + int i; + + bn_check_top(a); + bn_check_top(b); + + w=mont->riw; + + tmp= &(ctx->bn[ctx->tos++]); + tmp2= &(ctx->bn[ctx->tos++]); + bn_check_top(tmp); + bn_check_top(tmp2); + if (bn_wexpand(tmp,w+w) == NULL) goto err; + if (bn_wexpand(r,w+w) == NULL) goto err; + + if (a == b) + { + if (bn_wexpand(tmp2,w+w) == NULL) goto err; +#ifdef BN_SQR_COMBA + if ((a->top == 8) && (a->top == b->top)) + bn_sqr_comba8(tmp->d,a->d); + else +#endif + { + bn_sqr_normal(tmp->d,a->d,a->top,tmp2->d); + } + } + else + { +#ifdef BN_MUL_COMBA + if (a->top == 8) + bn_mul_comba8(tmp->d,a->d,b->d); + else +#endif + { + bn_mul_normal(tmp->d,a->d,a->top,b->d,b->top); + } + } + + i=a->top+b->top; + while (i<(w+w)) + { + tmp->d[i]=0; + i++; + } + tmp->top=w+w; + tmp->neg=0; + + /* reduce from aRR to aR */ + /* tmp->d is 2w words */ +#if 0 + bn_fix_top(tmp); + BN_from_montgomery_words(r,tmp,mont,ctx); +#else + bn_from_montgomery_words(r->d,tmp->d,mont->N.d,w,mont->n0); +#endif + r->top=w; + r->neg=0; + bn_fix_top(r); + + ret=1; +err: + ctx->tos-=2; + return(ret); + } +#endif + +#ifdef SPLIT_BN_FROM_MONTGOMERY +int BN_from_montgomery(ret,a,mont,ctx) +BIGNUM *ret; +BIGNUM *a; +BN_MONT_CTX *mont; +BN_CTX *ctx; + { + BIGNUM *n,*r; + BN_ULONG *np,*rp,n0,v0,v1,*nrp; + int al,nl,max,i; + int retn=0; + + bn_check_top(a); + + r= &(ctx->bn[ctx->tos]); + + if (!BN_copy(r,a)) goto err1; + n= &(mont->N); + + /* mont->riw is the size of mont->N in bits/words */ + al=mont->riw; + + nl=n->top; + if ((al == 0) || (nl == 0)) { r->top=0; return(1); } + + max=(nl+al+1); /* allow for overflow (no?) XXX */ + if (bn_wexpand(r,max) == NULL) goto err1; + if (bn_wexpand(ret,max) == NULL) goto err1; + + r->neg=a->neg^n->neg; + np=n->d; + rp=r->d; + nrp= &(r->d[nl]); + + /* clear the top words of T */ + for (i=r->top; id[i]=0; + + r->top=max; + n0=mont->n0; + + v1=0; + for (i=0; iriw will be a multiple of the word size */ + (void)BN_rshift(ret,r,mont->riw*BN_BITS2); + + if (BN_ucmp(ret, &(mont->N)) >= 0) + { + (void)BN_usub(ret,ret,&(mont->N)); /* XXX */ + } + retn=1; + +err1: + return(retn); + } +#endif + +#ifdef SPLIT_BN_MONT_CTX_NEW +BN_MONT_CTX *BN_MONT_CTX_new() + { + BN_MONT_CTX *ret; + + if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL) + return(NULL); + + BN_MONT_CTX_init(ret); + ret->flags=BN_FLG_MALLOCED; + return(ret); + } +#endif + +#ifdef SPLIT_BN_MONT_CTX_INIT +void BN_MONT_CTX_init(ctx) +BN_MONT_CTX *ctx; + { + ctx->use_word=0; + ctx->riw=0; + BN_init(&(ctx->RR)); + BN_init(&(ctx->N)); + BN_init(&(ctx->Ni)); + ctx->flags=0; + } +#endif + +#ifdef SPLIT_BN_MONT_CTX_FREE +void BN_MONT_CTX_free(mont) +BN_MONT_CTX *mont; + { + BN_free(&(mont->RR)); + BN_free(&(mont->N)); + BN_free(&(mont->Ni)); + if (mont->flags & BN_FLG_MALLOCED) + Free(mont); + } +#endif + +#ifdef SPLIT_BN_MONT_CTX_COPY +BN_MONT_CTX *BN_MONT_CTX_copy(to, from) +BN_MONT_CTX *to, *from; + { + if (to == from) return(to); + + (void)BN_copy(&(to->RR),&(from->RR)); + (void)BN_copy(&(to->N),&(from->N)); + (void)BN_copy(&(to->Ni),&(from->Ni)); + bn_zexpand(&(to->RR),from->riw); + bn_zexpand(&(to->Ni),from->riw); + to->use_word=from->use_word; + to->riw=from->riw; + to->n0=from->n0; + return(to); + } +#endif + +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_ms_w.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_ms_w.c new file mode 100644 index 00000000..86a6510d --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_ms_w.c @@ -0,0 +1,137 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +int BN_MONT_CTX_set_word(mont,mod,ctx) +BN_MONT_CTX *mont; +BIGNUM *mod; +BN_CTX *ctx; + { + BIGNUM Ri,*R; +#if 1 + BN_ULONG tmod,rr; +#else + BN_ULONG buf[2]; + BIGNUM tmod; +#endif + + + bn_check_top(mod); + if (mod->top == 0) return(0); + + R= &(mont->RR); /* grab RR as a temp */ + if (BN_copy(&(mont->N),mod) == NULL) /* Set N */ + return(0); + + BN_init(&Ri); + + mont->use_word=1; + +/* EAY is this number of words to shift, or the number to shift to end up + * with a '1' in the next word? + * for 8 bit words, is 0x01ab == 1 or 2 + */ + mont->riw=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2; + if (!BN_zero(R)) return(0); + + /* We are now setting a number which is larger than our current + * one after we do the shift + */ + if (!BN_set_bit(R,BN_BITS2)) + goto err; + +#if 0 + tmod.d=buf; + tmod.top=1; + tmod.max=mod->max; + tmod.neg=mod->neg; + buf[0]=mod->d[0]&BN_MASK2; + buf[1]=0; + + if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL) + goto err; +#else + tmod=mod->d[0]; + rr=BN_mod_inverse_word(tmod); + if (!BN_set_word(&Ri,rr)) + goto err; +#endif + + /* R*Ri */ + if (!BN_lshift(&Ri,&Ri,BN_BITS2)) + goto err; + + if (!BN_is_zero(&Ri)) + (void)BN_sub_word(&Ri,1); + else + { + /* This is not common..., 1 in BN_MASK2, + * It happens when buf[0] was == 1. So for 8 bit, + * this is 1/256, 16bit, 1 in 2^16 etc. + */ + if (!BN_set_word(&Ri,BN_MASK2)) + goto err; + } +#if 0 + BN_div(&Ri,NULL,&Ri,&tmod,ctx); + //BN_div_word(&Ri,tmod); + mont->n0=Ri.d[0]; +#else +#if 0 + { + BN_ULONG h,l; + + h=l=0; + if (Ri.top >= 2) h=Ri.d[1]; + if (Ri.top >= 1) l=Ri.d[0]; + mont->n0=bn_div_words(h,l,tmod); + } +#endif + mont->n0=bn_div_words( + (Ri.top >= 2)?Ri.d[1]:0, + (Ri.top >= 1)?Ri.d[0]:0, + tmod); +#endif + /* mod->top=z; */ + + /* setup RR for conversions */ + (void)BN_zero(&(mont->RR)); + if (!BN_set_bit(&(mont->RR),mont->riw*2*BN_BITS2)) + goto err; + (void)BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx); + bn_zexpand(&(mont->RR),mont->riw); +#if 0 + bn_zexpand(&(mont->Ni),mont->riw); /*This is not used? */ +#endif + +err: + BN_free(&Ri); + return(1); + } + + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_mul.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_mul.c new file mode 100644 index 00000000..76e83e74 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_mul.c @@ -0,0 +1,795 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_MUL_RECURSIVE +#define SPLIT_BN_MUL_PART_RECURSIVE +#define SPLIT_BN_MUL_LOW_RECURSIVE +#define SPLIT_BN_MUL_HIGH +#define SPLIT_BN_MUL +#define SPLIT_BN_MUL_NORMAL +#define SPLIT_BN_MUL_LOW_NORMAL +#endif /* NO_SPLIT */ + +#ifdef SMALL_CODE_SIZE +#undef BN_RECURSION_MUL +#endif + +#ifdef BN_RECURSION_MUL +#if 0 /* Replaced by bn_mul_rec_words() */ +/* r is 2*n2 words in size, + * a and b are both n2 words in size. + * n2 must be a power of 2. + * We multiply and return the result. + * t must be 2*n2 words in size + * We calulate + * a[0]*b[0] + * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) + * a[1]*b[1] + */ +#ifdef SPLIT_BN_MUL_RECURSIVE +void bn_mul_recursive(r,a,b,n2,t) +BN_ULONG *r,*a,*b; +int n2; +BN_ULONG *t; + { + int n=n2/2,c1,c2; + unsigned int neg,zero; + BN_ULONG ln,lo,*p; + +#ifdef BN_COUNT +printf(" bn_mul_recursive %d * %d\n",n2,n2); +#endif +#ifdef BN_MUL_COMBA +/* if (n2 == 4) + { + bn_mul_comba4(r,a,b); + return; + } + else */ if (n2 == 8) + { + bn_mul_comba8(r,a,b); + return; + } +#endif + if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) + { + /* This should not happen */ + bn_mul_normal(r,a,n2,b,n2); + return; + } + /* r=(a[0]-a[1])*(b[1]-b[0]) */ + c1=bn_cmp_words(a,&(a[n]),n); + c2=bn_cmp_words(&(b[n]),b,n); + zero=neg=0; + switch (c1*3+c2) + { + case -4: + bn_sub_words(t, &(a[n]),a, n); /* - */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + break; + case -3: + zero=1; + break; + case -2: + bn_sub_words(t, &(a[n]),a, n); /* - */ + bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */ + neg=1; + break; + case -1: + case 0: + case 1: + zero=1; + break; + case 2: + bn_sub_words(t, a, &(a[n]),n); /* + */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + neg=1; + break; + case 3: + zero=1; + break; + case 4: + bn_sub_words(t, a, &(a[n]),n); + bn_sub_words(&(t[n]),&(b[n]),b, n); + break; + } + +#ifdef BN_MUL_COMBA + if (n == 4) + { + if (!zero) + bn_mul_comba4(&(t[n2]),t,&(t[n])); + else + Memset(&(t[n2]),0,8*sizeof(BN_ULONG)); + + bn_mul_comba4(r,a,b); + bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n])); + } + else if (n == 8) + { + if (!zero) + bn_mul_comba8(&(t[n2]),t,&(t[n])); + else + Memset(&(t[n2]),0,16*sizeof(BN_ULONG)); + + bn_mul_comba8(r,a,b); + bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n])); + } + else +#endif + { + p= &(t[n2*2]); + if (!zero) + bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); + else + Memset(&(t[n2]),0,n2*sizeof(BN_ULONG)); + bn_mul_recursive(r,a,b,n,p); + bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p); + } + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=(int)bn_add_words(t,r,&(r[n2]),n2); + + if (neg) /* if t[32] is negative */ + { + c1-=(int)bn_sub_words(&(t[n2]),t,&(t[n2]),n2); + } + else + { + /* Might have a carry */ + c1+=(int)bn_add_words(&(t[n2]),&(t[n2]),t,n2); + } + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + * c1 holds the carry bits + */ + c1+=(int)bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < (BN_ULONG)c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } +#endif +#endif + +#if 0 +#ifdef SPLIT_BN_MUL_PART_RECURSIVE +/* n+tn is the word length + * t must be n*4 is size, as does r */ +void bn_mul_part_recursive(r,a,b,tn,n,t) +BN_ULONG *r,*a,*b; +int tn,n; +BN_ULONG *t; + { + int i,j,n2=n*2; + int c1; + BN_ULONG ln,lo,*p; + +#ifdef BN_COUNT +printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n); +#endif + if (n < 8) + { + i=tn+n; + bn_mul_normal(r,a,i,b,i); + return; + } + + /* r=(a[0]-a[1])*(b[1]-b[0]) */ + bn_sub_words(t, a, &(a[n]),n); /* + */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + +#ifdef BN_MUL_COMBA +/* if (n == 4) + { + bn_mul_comba4(&(t[n2]),t,&(t[n])); + bn_mul_comba4(r,a,b); + bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); + Memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); + } + else */ if (n == 8) + { + bn_mul_comba8(&(t[n2]),t,&(t[n])); + bn_mul_comba8(r,a,b); + bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); + Memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); + } + else +#endif + { + p= &(t[n2*2]); + bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); + bn_mul_recursive(r,a,b,n,p); + i=n/2; + /* If there is only a bottom half to the number, + * just do it */ + j=tn-i; + if (j == 0) + { + bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p); + Memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2)); + } + else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */ + { + bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]), + j,i,p); + Memset(&(r[n2+tn*2]),0, + sizeof(BN_ULONG)*(n2-tn*2)); + } + else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */ + { + Memset(&(r[n2]),0,sizeof(BN_ULONG)*n2); + if (tn < BN_MUL_RECURSIVE_SIZE_NORMAL) + { + bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); + } + else + { + for (;;) + { + i/=2; + if (i < tn) + { + bn_mul_part_recursive(&(r[n2]), + &(a[n]),&(b[n]), + tn-i,i,p); + break; + } + else if (i == tn) + { + bn_mul_recursive(&(r[n2]), + &(a[n]),&(b[n]), + i,p); + break; + } + } + } + } + } + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=(int)bn_add_words(t,r,&(r[n2]),n2); + c1-=(int)bn_sub_words(&(t[n2]),t,&(t[n2]),n2); + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + * c1 holds the carry bits + */ + c1+=(int)bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < (BN_ULONG)c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } +#endif +#endif + +#if 0 +#ifdef SPLIT_BN_MUL_LOW_RECURSIVE +/* a and b must be the same size, which is n2. + * r must be n2 words and t must be n2*2 + */ +void bn_mul_low_recursive(r,a,b,n2,t) +BN_ULONG *r,*a,*b; +int n2; +BN_ULONG *t; + { + int n=n2/2; + +#ifdef BN_COUNT +printf(" bn_mul_low_recursive %d * %d\n",n2,n2); +#endif + + bn_mul_recursive(r,a,b,n,&(t[0])); + if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL) + { + bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2])); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + bn_mul_low_recursive(&(t[0]),&(a[n]),&(b[0]),n,&(t[n2])); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + } + else + { + bn_mul_low_normal(&(t[0]),&(a[0]),&(b[n]),n); + bn_mul_low_normal(&(t[n]),&(a[n]),&(b[0]),n); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + bn_add_words(&(r[n]),&(r[n]),&(t[n]),n); + } + } +#endif +#endif + +#ifdef SPLIT_BN_MUL_HIGH +#if 0 +/* a and b must be the same size, which is n2. + * r must be n2 words and t must be n2*2 + * l is the low words of the output. + * t must be n2*3 + */ +void bn_mul_high(r,a,b,l,n2,t) +BN_ULONG *r,*a,*b,*l; +int n2; +BN_ULONG *t; + { + int i,n; + int c1,c2; + int neg,oneg,zero; + BN_ULONG ll,lc,*lp,*mp; + +#ifdef BN_COUNT +printf(" bn_mul_high %d * %d\n",n2,n2); +#endif + n=n2/2; + + /* Calculate (al-ah)*(bh-bl) */ + neg=zero=0; + c1=bn_cmp_words(&(a[0]),&(a[n]),n); + c2=bn_cmp_words(&(b[n]),&(b[0]),n); + switch (c1*3+c2) + { + case -4: + bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n); + bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n); + break; + case -3: + zero=1; + break; + case -2: + bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n); + bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n); + neg=1; + break; + case -1: + case 0: + case 1: + zero=1; + break; + case 2: + bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n); + bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n); + neg=1; + break; + case 3: + zero=1; + break; + case 4: + bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n); + bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n); + break; + } + + oneg=neg; + /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */ + /* r[10] = (a[1]*b[1]) */ +#ifdef BN_MUL_COMBA + if (n == 8) + { + bn_mul_comba8(&(t[0]),&(r[0]),&(r[n])); + bn_mul_comba8(r,&(a[n]),&(b[n])); + } + else +#endif + { +#ifdef BN_MUL_RECURSION + bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2])); + bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2])); +#else + bn_mul_normal(&(t[0]),&(r[0]),n,&(r[n]),n); + bn_mul_normal(r,&(a[n]),n,&(b[n]),n); +#endif + } + + /* s0 == low(al*bl) + * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl) + * We know s0 and s1 so the only unknown is high(al*bl) + * high(al*bl) == s1 - low(ah*bh+s0+(al-ah)*(bh-bl)) + * high(al*bl) == s1 - (r[0]+l[0]+t[0]) + */ + if (l != NULL) + { + lp= &(t[n2+n]); + c1=(int)bn_add_words(lp,&(r[0]),&(l[0]),n); + } + else + { + c1=0; + lp= &(r[0]); + } + + if (neg) + neg=(int)bn_sub_words(&(t[n2]),lp,&(t[0]),n); + else + { + bn_add_words(&(t[n2]),lp,&(t[0]),n); + neg=0; + } + + if (l != NULL) + { + bn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n); + } + else + { + lp= &(t[n2+n]); + mp= &(t[n2]); + for (i=0; i 0) + { + lc=c1; + do { + ll=(r[i]+lc)&BN_MASK2; + r[i++]=ll; + lc=(lc > ll); + } while (lc); + } + else + { + lc= -c1; + do { + ll=r[i]; + r[i++]=(ll-lc)&BN_MASK2; + lc=(lc > ll); + } while (lc); + } + } + if (c2 != 0) /* Add starting at r[1] */ + { + i=n; + if (c2 > 0) + { + lc=c2; + do { + ll=(r[i]+lc)&BN_MASK2; + r[i++]=ll; + lc=(lc > ll); + } while (lc); + } + else + { + lc= -c2; + do { + ll=r[i]; + r[i++]=(ll-lc)&BN_MASK2; + lc=(lc > ll); + } while (lc); + } + } + } +#endif +#endif +#endif + +#ifdef SPLIT_BN_MUL +int BN_mul(r,a,b,ctx) +BIGNUM *r,*a,*b; +BN_CTX *ctx; + { + int top,al,bl,neg; + BIGNUM *rr; +#ifdef BN_RECURSION_MUL + BIGNUM *t; + int i,j,k,l; +#endif + +#ifdef BN_COUNT +printf("BN_mul %d * %d\n",a->top,b->top); +#endif + + bn_check_top(a); + bn_check_top(b); + bn_check_top(r); + + al=a->top; + bl=b->top; + + if ((al == 0) || (bl == 0)) + { + (void)BN_zero(r); + return(1); + } + top=al+bl; + neg=a->neg^b->neg; + + if ((r == a) || (r == b)) + rr= &(ctx->bn[ctx->tos+1]); + else + rr=r; + + if (bn_wexpand(rr,top) == NULL) return(0); + rr->top=top; + +#if defined(BN_MUL_COMBA) || defined(BN_RECURSION_MUL) + if (al == bl) + { +# ifdef BN_MUL_COMBA +/* if (al == 4) + { + bn_mul_comba4(rr->d,a->d,b->d); + goto end; + } + else */ if (al == 8) + { + bn_mul_comba8(rr->d,a->d,b->d); + goto end; + } + else +# endif +#ifdef BN_RECURSION_MUL + if (al < BN_MULL_SIZE_NORMAL) +#endif + { + bn_mul_normal(rr->d,a->d,al,b->d,bl); + goto end; + } +# ifdef BN_RECURSION_MUL + goto symetric; +# endif + } +#endif +#ifdef BN_RECURSION_MUL + else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL)) + { + bn_mul_normal(rr->d,a->d,al,b->d,bl); + goto end; + } + else + { + i=(al-bl); + if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA)) + { + bn_wexpand(b,al); + b->d[bl]=0; + bl++; + goto symetric; + } + else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) + { + bn_wexpand(a,bl); + a->d[al]=0; + al++; + goto symetric; + } + } +#endif + +#ifdef BN_RECURSION_MUL +normal_mul: +#endif + bn_mul_normal(rr->d,a->d,al,b->d,bl); + +#ifdef BN_RECURSION_MUL + if (0) + { +symetric: + /* symetric and > 4 */ + /* 16 or larger */ + l=BN_num_bits_word((BN_ULONG)al); + j=1<<(l-1); + k=j+j; + t= &(ctx->bn[ctx->tos]); + if (al == j) /* exact multiple */ + { + BN_REC rec; + rec.depth=l-5; + rec.n=j; + rec.mul=bn_mul_comba8; + rec.sqr=bn_sqr_comba8; + if (bn_wexpand(t,k+k) == NULL) + return(0); + if (bn_wexpand(rr,k) == NULL) + return(0); + bn_mul_rec_words(rr->d,a->d,b->d,t->d,&rec); + } + else + goto normal_mul; +#if 0 + { + bn_zexpand(a,k); + bn_zexpand(b,k); + bn_wexpand(t,k); + bn_wexpand(rr,k); + bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d); + } +#endif + } +#endif +#if defined(BN_MUL_COMBA) || defined(BN_RECURSION_MUL) +end: +#endif + + r->neg=neg; + bn_fix_top(rr); + if (r != rr) (void)BN_copy(r,rr); + return(1); + } +#endif + + +#ifdef SPLIT_BN_MUL_NORMAL +void bn_mul_normal(r,a,na,b,nb) +BN_ULONG *r,*a; +int na; +BN_ULONG *b; +int nb; + { + BN_ULONG *rr; + +#ifdef BN_COUNT +printf(" bn_mul_normal %d * %d\n",na,nb); +#endif + /* asymetric and >= 4 */ +#if 0 + if ((na == nb) && (na == 8)) + { + bn_mul_normal(r,a,na,b,nb); + return; + } +#endif + + if (na < nb) + { + int itmp; + BN_ULONG *ltmp; + + itmp=na; na=nb; nb=itmp; + ltmp=a; a=b; b=ltmp; + + } + rr= &(r[na]); + rr[0]=bn_mul_words(r,a,na,b[0]); + + for (;;) + { + if (--nb <= 0) return; + rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]); + if (--nb <= 0) return; + rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]); + if (--nb <= 0) return; + rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]); + if (--nb <= 0) return; + rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]); + rr+=4; + r+=4; + b+=4; + } + } +#endif + +#ifdef SPLIT_BN_MUL_LOW_NORMAL +void bn_mul_low_normal(r,a,b,n) +BN_ULONG *r,*a,*b; +int n; + { +#ifdef BN_COUNT +printf(" bn_mul_low_normal %d * %d\n",n,n); +#endif + (void)bn_mul_words(r,a,n,b[0]); + + for (;;) + { + if (--n <= 0) return; + (void)bn_mul_add_words(&(r[1]),a,n,b[1]); + if (--n <= 0) return; + (void)bn_mul_add_words(&(r[2]),a,n,b[2]); + if (--n <= 0) return; + (void)bn_mul_add_words(&(r[3]),a,n,b[3]); + if (--n <= 0) return; + (void)bn_mul_add_words(&(r[4]),a,n,b[4]); + r+=4; + b+=4; + } + } +#endif +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_r_exp.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_r_exp.c new file mode 100644 index 00000000..ef056efd --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_r_exp.c @@ -0,0 +1,150 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +/* #ifdef RECP_MUL_MOD */ +int BN_mod_exp_recp(r,a,p,m,ctx) +BIGNUM *r; +BIGNUM *a; +BIGNUM *p; +BIGNUM *m; +BN_CTX *ctx; + { + int i,j,bits,ret=0,wstart,wend,window,wvalue; + int start=1,ts=0; + BIGNUM *aa; + BIGNUM val[BN_EXP_TABLE_SIZE]; + BN_RECP_CTX recp; + + bits=BN_num_bits(p); + + if (BN_is_zero(a)) + { (void)BN_zero(r); return(1); } + if (BN_is_zero(p)) + { (void)BN_one(r); return(1); } + if (BN_is_one(p)) + { (void)BN_copy(r,a); return(1); } + + BN_RECP_CTX_init(&recp); + if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err; + + BN_init(&(val[0])); + ts=1; + + aa= &(ctx->bn[ctx->tos++]); + + if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */ + if (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx)) + goto err; /* 2 */ + + if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */ + window=1; + else if (bits >= 256) + window=5; /* max size of window */ + else if (bits >= 128) + window=4; + else + window=3; + + j=1<<(window-1); + for (i=1; i>1]),&recp,ctx)) + goto err; + + /* move the 'window' down further */ + wstart-=wend+1; + wvalue=0; + start=0; + if (wstart < 0) break; + } + ret=1; +err: + ctx->tos--; + for (i=0; in; + int n2=n/2; + int neg=0; + BN_ULONG c1; + + + if (rec->depth == 0) + { + /* t needs to have space for 4*n words + * The multiply needs to be a n2*n2 -> n + */ +#ifndef NOPROTO + void (PRE_CCONV CCONV *rmul)(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b); +#else + void (PRE_CCONV CCONV *rmul)(); +#endif + rmul=rec->mul; + +#ifdef _EXTRA_ARG_ + /* THIS IS WRONG - there is no extra int arg on the end */ + rmul(&(r[0]),&(a[0]),&(b[0]),n2); + rmul(&(r[n]),&(a[n2]),&(b[n2]),n2); +#else + rmul(&(r[0]),&(a[0]),&(b[0])); + rmul(&(r[n]),&(a[n2]),&(b[n2])); +#endif + + if (bn_sub_words(&(tt[n+0]), &(a[0]),&(a[n2]),n2)) + { + bn_2s_comp(&(tt[n+ 0]),&(tt[n+ 0]),n2); + neg=1; + } + else + neg=0; + if (bn_sub_words(&(tt[n+n2]),&(b[n2]),&(b[0]),n2)) + { + neg^=1; + bn_2s_comp(&(tt[n+n2]),&(tt[n+n2]),n2); + } + +#ifdef _EXTRA_ARG_ + rmul(&(tt[0]),&(tt[n+0]),&(tt[n+n2]),n2); +#else + rmul(&(tt[0]),&(tt[n+0]),&(tt[n+n2])); +#endif + } + else /* Leaf node */ + { + /* t has 4*n words taken per call. + * Since n is half the size per call, we need + * 6*n words for our current level and all sub levels + * The multiply needs to be a n2*n2 -> n + */ + rec->depth--; + rec->n=n2; + bn_mul_rec_words(&(r[0]), &(a[0]), &(b[0]), &(tt[n+n]),rec); + bn_mul_rec_words(&(r[n]), &(a[n2]),&(b[n2]), &(tt[n+n]),rec); + + neg=0; + if (bn_sub_words(&(tt[n+0]), &(a[0]),&(a[n2]),n2)) + { + bn_2s_comp(&(tt[n+ 0]),&(tt[n+ 0]),n2); + neg=1; + } + else + neg=0; + if (bn_sub_words(&(tt[n+n2]),&(b[n2]),&(b[0]),n2)) + { + neg^=1; + bn_2s_comp(&(tt[n+n2]),&(tt[n+n2]),n2); + } + + bn_mul_rec_words(&(tt[0]),&(tt[n]),&(tt[n+n2]),&(tt[n+n]),rec); + rec->n=n; + rec->depth++; + } + + c1=bn_add_words(&(tt[n]),&(r[0]),&(r[n]),n); + + if (neg) + c1-=bn_sub_words(&(tt[0]),&(tt[n]),&(tt[0]),n); + else + c1+=bn_add_words(&(tt[0]),&(tt[n]),&(tt[0]),n); + tt[n]=c1; + c1=bn_add_words(&(r[n2]),&(r[n2]),&(tt[0]),n+1); + if (c1) + { + tt= &(r[n+n2+1]); + do { + } while (++(*(tt++)) == 0); + } + } +#endif + +#ifdef SPLIT_BN_SQR_REC_WORDS +/* tt needs to be 3*n words */ +void bn_sqr_rec_words(r,a,tt,rec) +BN_ULONG *r,*a,*tt; +BN_REC *rec; + { + int n=rec->n; + int n2=n/2; + BN_ULONG c1; + + if (rec->depth == 0) + { + /* t needs to have space for 4*n words + * The multiply needs to be a n2*n2 -> n + */ +#ifndef NOPROTO + void (PRE_CCONV CCONV *rsqr)(BN_ULONG *r, BN_ULONG *a); +#else + void (PRE_CCONV CCONV *rsqr)(); +#endif + + rsqr=rec->sqr; + +#ifdef _EXTRA_ARG_ + /* THIS IS WRONG - there is no extra int arg on the end */ + rsqr(&(r[0]), &(a[0]), n2); + rsqr(&(r[n]), &(a[n2]),n2); +#else + rsqr(&(r[0]), &(a[0])); + rsqr(&(r[n]), &(a[n2])); +#endif + + if (bn_sub_words(&(tt[n+0]), &(a[0]),&(a[n2]),n2)) + bn_2s_comp(&(tt[n+0]),&tt[n+0], n2); + +#ifdef _EXTRA_ARG_ + rsqr(&(tt[0]),&(tt[n]), n2); +#else + rsqr(&(tt[0]),&(tt[n])); +#endif + + } + else /* Leaf node */ + { + /* t has 4*n words taken per call. + * Since n is half the size per call, we need + * 6*n words for our current level and all sub levels + * The multiply needs to be a n2*n2 -> n + */ + rec->depth--; + rec->n=n2; + bn_sqr_rec_words(&(r[0]), &(a[0]), &(tt[n+n]),rec); + bn_sqr_rec_words(&(r[n]), &(a[n2]),&(tt[n+n]),rec); + + if (bn_sub_words(&(tt[n+0]), &(a[0]),&(a[n2]),n2)) + bn_2s_comp(&(tt[n+0]),&tt[n+0], n2); + bn_sqr_rec_words(&(tt[0]),&(tt[n]),&(tt[n+n]),rec); + + rec->n=n; + rec->depth++; + } + + c1=bn_add_words(&(tt[n]),&(r[0]),&(r[n]),n); + c1-=bn_sub_words(&(tt[0]),&(tt[n]),&(tt[0]),n); + + tt[n]=c1; + c1=bn_add_words(&(r[n2]),&(r[n2]),&(tt[0]),n+1); + if (c1) + { + tt= &(r[n+n2+1]); + do { + } while (++(*(tt++)) == 0); + } + } +#endif + +#endif /* !NO_SPLIT || !SPLIT_FILE */ diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_recp.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_recp.c new file mode 100644 index 00000000..6830f59d --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_recp.c @@ -0,0 +1,218 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +void BN_RECP_CTX_init(recp) +BN_RECP_CTX *recp; + { + BN_init(&(recp->N)); + BN_init(&(recp->Nr)); + recp->num_bits=0; + recp->flags=0; + } + +BN_RECP_CTX *BN_RECP_CTX_new() + { + BN_RECP_CTX *ret; + + if ((ret=(BN_RECP_CTX *)Malloc(sizeof(BN_RECP_CTX))) == NULL) + return(NULL); + + BN_RECP_CTX_init(ret); + ret->flags=BN_FLG_MALLOCED; + return(ret); + } + +void BN_RECP_CTX_free(recp) +BN_RECP_CTX *recp; + { + BN_free(&(recp->N)); + BN_free(&(recp->Nr)); + if (recp->flags & BN_FLG_MALLOCED) + Free(recp); + } + +int BN_RECP_CTX_set(recp,d,ctx) +BN_RECP_CTX *recp; +BIGNUM *d; +BN_CTX *ctx; + { + (void)BN_copy(&(recp->N),d); + (void)BN_zero(&(recp->Nr)); + recp->num_bits=BN_num_bits(d); + recp->shift=0; + ctx=ctx; /* Stop warning */ + return(1); + } + +int BN_mod_mul_reciprocal(r, x, y, recp, ctx) +BIGNUM *r; +BIGNUM *x; +BIGNUM *y; +BN_RECP_CTX *recp; +BN_CTX *ctx; + { + int ret=0; + BIGNUM *a; + + bn_check_top(x); + bn_check_top(y); + + a= &(ctx->bn[ctx->tos++]); + if (y != NULL) + { + if (x == y) + { if (!BN_sqr(a,x,ctx)) goto err; } + else + { if (!BN_mul(a,x,y,ctx)) goto err; } + } + else + a=x; /* Just do the mod */ + + (void)BN_div_recp(NULL,r,a,recp,ctx); + ret=1; +err: + ctx->tos--; + return(ret); + } + +int BN_div_recp(dv,rem,m,recp,ctx) +BIGNUM *dv; +BIGNUM *rem; +BIGNUM *m; +BN_RECP_CTX *recp; +BN_CTX *ctx; + { + int i,j,tos,ret=0,ex; + BIGNUM *a,*b,*d,*r; + + bn_check_top(m); + + tos=ctx->tos; + a= &(ctx->bn[ctx->tos++]); + b= &(ctx->bn[ctx->tos++]); + if (dv != NULL) + d=dv; + else + d= &(ctx->bn[ctx->tos++]); + if (rem != NULL) + r=rem; + else + r= &(ctx->bn[ctx->tos++]); + + if (BN_ucmp(m,&(recp->N)) < 0) + { + (void)BN_zero(d); + (void)BN_copy(r,m); + ctx->tos=tos; + return(1); + } + + /* We want the remainder + * Given input of ABCDEF / ab + * we need multiply ABCDEF by 3 digests of the reciprocal of ab + * + */ + i=BN_num_bits(m); + + j=recp->num_bits*2; + if (j > i) + { + i=j; + ex=0; + } + else + { + ex=(i-j)/2; + } + + j=i/2; + + if (i != recp->shift) + recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N), + i,ctx); + + if (!BN_rshift(a,m,j-ex)) goto err; + if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err; + if (!BN_rshift(d,b,j+ex)) goto err; + d->neg=0; + if (!BN_mul(b,&(recp->N),d,ctx)) goto err; + if (!BN_usub(r,m,b)) goto err; + r->neg=0; + + j=0; +#if 1 + while (BN_ucmp(r,&(recp->N)) >= 0) + { + if (j++ > 2) + { +#ifndef NO_ERR + BNerr(BN_F_BN_DIV_RECP,BN_R_BAD_RECIPROCAL); +#endif + goto err; + } + if (!BN_usub(r,r,&(recp->N))) goto err; + if (!BN_add_word(d,1)) goto err; + } +#endif + + r->neg=BN_is_zero(r)?0:m->neg; + d->neg=m->neg^recp->N.neg; + ret=1; +err: + ctx->tos=tos; + return(ret); + } + +/* len is the expected size of the result + * We actually calculate with an extra word of precision, so + * we can do faster division if the remainder is not required. + */ +int BN_reciprocal(r,m,len,ctx) +BIGNUM *r; +BIGNUM *m; +int len; +BN_CTX *ctx; + { + int ret= -1; + BIGNUM t; + + bn_check_top(m); + + BN_init(&t); + + (void)BN_zero(&t); + if (!BN_set_bit(&t,len)) goto err; + + if (!BN_div(r,NULL,&t,m,ctx)) goto err; + ret=len; +err: + BN_free(&t); + return(ret); + } + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_rsh.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_rsh.c new file mode 100644 index 00000000..0f0d5c60 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_rsh.c @@ -0,0 +1,139 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_RSHIFT1 +#define SPLIT_BN_RSHIFT +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BN_RSHIFT1 +#ifdef SMALL_CODE_SIZE +int BN_rshift1(r, a) +BIGNUM *r; +BIGNUM *a; + { + return(BN_rshift(r,a,1)); + } + +#else + +int BN_rshift1(r, a) +BIGNUM *r; +BIGNUM *a; + { + BN_ULONG *ap,*rp,t,c; + int i; + + bn_check_top(a); + + if (BN_is_zero(a)) + { + BN_zero(r); + return(1); + } + if (a != r) + { + if (bn_wexpand(r,a->top) == NULL) return(0); + r->top=a->top; + r->neg=a->neg; + } + ap=a->d; + rp=r->d; + c=0; + for (i=a->top-1; i>=0; i--) + { + t=ap[i]; + rp[i]=((t>>1)&BN_MASK2)|c; + c=(t&1)?BN_TBIT:0; + } + bn_fix_top(r); + return(1); + } +#endif +#endif + +#ifdef SPLIT_BN_RSHIFT +int BN_rshift(r, a, n) +BIGNUM *r; +BIGNUM *a; +int n; + { + int i,j,nw,lb,rb; + BN_ULONG *t,*f; + BN_ULONG l,tmp; + + bn_check_top(a); + +#ifndef SMALL_CODE_SIZE + if (n == 1) return(BN_rshift1(r,a)); +#endif + nw=n/BN_BITS2; + rb=n%BN_BITS2; + lb=BN_BITS2-rb; + if (nw > a->top) + { + (void)BN_zero(r); + return(1); + } + if (r != a) + { + if (bn_wexpand(r,a->top-nw+1+1/*???*/) == NULL) return(0); + r->neg=a->neg; + } + + f= &(a->d[nw]); + t=r->d; + j=a->top-nw; + r->top=j; + + if (rb == 0) + { + for (i=j+1; i > 0; i--) + *(t++)= *(f++); + } + else + { + l= *(f++); + for (i=1; i>rb)&BN_MASK2; + l= *(f++); + *(t++) =(tmp|(l<>rb)&BN_MASK2; + *t=0; + } + bn_fix_top(r); + return(1); + } +#endif + +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_sqr.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_sqr.c new file mode 100644 index 00000000..24b5c4cb --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_sqr.c @@ -0,0 +1,289 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#ifdef SMALL_CODE_SIZE +#undef BN_RECURSION_SQR +#endif + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_SQR +#define SPLIT_BN_SQR_NORMAL +#define SPLIT_BN_RECURSION_SQR +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BN_SQR +/* r must not be a */ +int BN_sqr(r, a, ctx) +BIGNUM *r; +BIGNUM *a; +BN_CTX *ctx; + { + int max,al; + BIGNUM *tmp,*rr; + +#ifdef BN_COUNT +printf("BN_sqr %d * %d\n",a->top,a->top); +#endif + bn_check_top(a); + tmp= &(ctx->bn[ctx->tos]); + rr=(a != r)?r: (&ctx->bn[ctx->tos+1]); + + al=a->top; + if (al <= 0) + { + r->top=0; + return(1); + } + + max=(al+al); + if (bn_wexpand(rr,max) == NULL) return(0); + + rr->top=max; + rr->neg=0; + + if (al == 4) + { +#ifndef BN_SQR_COMBA + BN_ULONG t[8]; + bn_sqr_normal(rr->d,a->d,4,t); +#else + bn_sqr_comba4(rr->d,a->d); +#endif + } + else if (al == 8) + { +#ifndef BN_SQR_COMBA + BN_ULONG t[16]; + bn_sqr_normal(rr->d,a->d,8,t); +#else + bn_sqr_comba8(rr->d,a->d); +#endif + } + else + { +#if 1 && defined(BN_RECURSION_SQR) + if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) + { + BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2]; + bn_sqr_normal(rr->d,a->d,al,t); + } + else + { + int j,l,k; + + l=BN_num_bits_word((BN_ULONG)al); + j=1<<(l-1); + k=j+j; + if ((al == j) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) + { + BN_REC rec; + if (bn_wexpand(tmp,k*2) == NULL) return(0); + rec.depth=l-5; + rec.n=j; + rec.mul=bn_mul_comba8; + rec.sqr=bn_sqr_comba8; + + bn_sqr_rec_words(rr->d,a->d,tmp->d,&rec); + } + else + { + if (bn_wexpand(tmp,max) == NULL) return(0); + bn_assert(al*2 <= max); + bn_sqr_normal(rr->d,a->d,al,tmp->d); + } + } +#else + if (bn_wexpand(tmp,max) == NULL) return(0); + bn_assert(al*2 <= max); + bn_sqr_normal(rr->d,a->d,al,tmp->d); +#endif +#ifdef BN_DEBUG + tmp->top=0; +#endif + } + + if ((max > 0) && (rr->d[max-1] == 0)) rr->top--; + if (rr != r) (void)BN_copy(r,rr); + return(1); + } +#endif + +#ifdef SPLIT_BN_SQR_NORMAL +/* tmp must have 2*n words */ +void bn_sqr_normal(r, a, n, tmp) +BN_ULONG *r; +BN_ULONG *a; +int n; +BN_ULONG *tmp; + { + int i,j,max; + BN_ULONG *ap,*rp,m; + + max=n*2; + ap=a; + rp=r; + rp[0]=rp[max-1]=0; + rp++; + j=n; + + if (--j > 0) + { + m= (*ap++); + rp[j]=bn_mul_words(rp,ap,j,m); + rp+=2; + } + + for (i=n-2; i>0; i--) + { + j--; + m= *(ap++); + rp[j]=bn_mul_add_words(rp,ap,j,m); + rp+=2; + } + + (void)bn_add_words(r,r,r,max); + + /* There will not be a carry */ + + bn_sqr_words(tmp,a,n); + + (void)bn_add_words(r,r,tmp,max); + } +#endif + +#if 0 /* replaced by bn_sqr_rec_words() AND this has bugs */ +#ifdef SPLIT_BN_RECURSION_SQR +#ifdef BN_RECURSION_SQR +/* r is 2*n words in size, + * a and b are both n words in size. + * n must be a power of 2. + * We multiply and return the result. + * t must be 2*n words in size + * We calulate + * a[0]*b[0] + * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) + * a[1]*b[1] + */ +void bn_sqr_recursive(r,a,n2,t) +BN_ULONG *r,*a; +int n2; +BN_ULONG *t; + { + int n=n2/2; + int zero,c1; + BN_ULONG ln,lo,*p; + +#ifdef BN_COUNT +printf(" bn_sqr_recursive %d * %d\n",n2,n2); +#endif + if (n2 == 4) + { +#ifndef BN_SQR_COMBA + bn_sqr_normal(r,a,4,t); +#else + bn_sqr_comba4(r,a); +#endif + return; + } + else if (n2 == 8) + { +#ifndef BN_SQR_COMBA + bn_sqr_normal(r,a,8,t); +#else + bn_sqr_comba8(r,a); +#endif + return; + } + if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL) + { + bn_sqr_normal(r,a,n2,t); + return; + } + /* r=(a[0]-a[1])*(a[1]-a[0]) */ + c1=bn_cmp_words(a,&(a[n]),n); + zero=0; + if (c1 > 0) + bn_sub_words(t,a,&(a[n]),n); + else if (c1 < 0) + bn_sub_words(t,&(a[n]),a,n); + else + zero=1; + + /* The result will always be negative unless it is zero */ + p= &(t[n2*2]); + + if (!zero) + bn_sqr_recursive(&(t[n2]),t,n,p); + else + Memset(&(t[n2]),0,n*sizeof(BN_ULONG)); + bn_sqr_recursive(r,a,n,p); + bn_sqr_recursive(&(r[n2]),&(a[n]),n,p); + + /* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=(int)(bn_add_words(t,r,&(r[n2]),n2)); + + /* t[32] is negative */ + c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2)); + + /* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1]) + * r[10] holds (a[0]*a[0]) + * r[32] holds (a[1]*a[1]) + * c1 holds the carry bits + */ + c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2)); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < (BN_ULONG)c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } +#endif +#endif +#endif +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/bn_wdiv.c b/build/libraries_sysmenu/acsign/ARM9/src/bn_wdiv.c new file mode 100644 index 00000000..97c21860 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/bn_wdiv.c @@ -0,0 +1,116 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#ifndef OPT_BN_ASM + +#ifndef BN_DIV_WORDS +#define BN_DIV_WORDS +#endif + +#endif + +#ifdef BN_DIV_WORDS +#if defined(BN_LLONG) +BN_ULONG bn_div_words(h,l,d) +BN_ULONG h,l,d; + { + return((BN_ULONG)(((((BN_ULLONG)h)< ((BN_ULONG)1)<= d) h-=d; + + if (i) + { + d=(d<>(BN_BITS2-i)))&BN_MASK2; + l=(l<>BN_BITS4)&BN_MASK2lh; + dl=(d&BN_MASK2l); + for (;;) + { + if ((h>>BN_BITS4) == dh) + q=BN_MASK2l; + else + q=h/dh; + + for (;;) + { + t=(h-q*dh)&BN_MASK2; + if ((t&BN_MASK2h) || + (((dl*q)&BN_MASK2) <= (( + (t<>BN_BITS4)&BN_MASK2lh))&BN_MASK2))) + break; + q--; + } + th=(q*dh)&BN_MASK2; + tl=(q*dl)&BN_MASK2; + t=(tl>>BN_BITS4); + tl=(tl&BN_MASK2lh)<>BN_BITS4))&BN_MASK2; + l=(l&BN_MASK2l)<top-1; i>=0; i--) + { +#ifndef BN_LLONG + ret=((ret<d[i]>>BN_BITS4)&BN_MASK2l))%w; + ret=((ret<d[i]&BN_MASK2l))%w; +#else + ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])% + (BN_ULLONG)w); +#endif + } + return((BN_ULONG)ret); + } +#endif + +#ifdef SPLIT_BN_DIV_WORD +BN_ULONG BN_div_word(a, w) +BIGNUM *a; +BN_ULONG w; + { + BN_ULONG ret; + int i; + + if (a->top == 0) return(0); + ret=0; + w=w&BN_MASK2;//w&=BN_MASK2; + for (i=a->top-1; i>=0; i--) + { + BN_ULONG l,d; + + l=a->d[i]; + d=bn_div_words(ret,l,w); + ret=(l-((d*w)&BN_MASK2))&BN_MASK2; + a->d[i]=d; + } + if ((a->top > 0) && (a->d[a->top-1] == 0)) + a->top--; + return(ret); + } +#endif + +#ifdef SPLIT_BN_ADD_WORD +int BN_add_word(a, w) +BIGNUM *a; +BN_ULONG w; + { + BN_ULONG l; + int i; + + if (w == 0) return(1); + bn_check_top(a); + + w=w&BN_MASK2;//w&=BN_MASK2; + if (a->neg) + { + if(a->top > 1) + { + a->neg=0; + i=BN_sub_word(a,w); + a->neg=1; + return(i); + } + else + { /* a->top == 1, it cannot be 0 */ + l=a->d[0]; + if (l > w) + a->d[0]=l-w; + else if (l < w) + { + a->neg=0; + a->d[0]=w-l; + } + else + { + a->neg=0; + a->top=0; + } + return(1); + } + } + w=w&BN_MASK2;//w&=BN_MASK2; + if (bn_wexpand(a,a->top+1) == NULL) return(0); + a->d[a->top]=0; + i=0; + for (;;) + { + l=(a->d[i]+(BN_ULONG)w)&BN_MASK2; + a->d[i]=l; + if (w > l) + w=1; + else + break; + i++; + } + if (i >= a->top) + a->top++; + return(1); + } +#endif + +#ifdef SPLIT_BN_SUB_WORD +int BN_sub_word(a, w) +BIGNUM *a; +BN_ULONG w; + { + int i; + + bn_check_top(a); + if (w == 0) return(1); + + w=w&BN_MASK2;//w&=BN_MASK2; + if (a->neg) + { + a->neg=0; + i=BN_add_word(a,w); + a->neg=1; + return(i); + } + + w=w&BN_MASK2;//w&=BN_MASK2; + if (a->top <= 1) + { + BN_ULONG l; + + if (a->top == 0) + { + if (bn_wexpand(a,1) == NULL) return(0); + a->d[0]=w; + a->neg = 1; + a->top = 1; + return(1); + } + l=a->d[0]; + if (l == w) + a->top=0; + else if (l > w) + a->d[0]=l-w; + else + { + a->neg=1; + a->d[0]=w-l; + } + return(1); + } + i=0; + for (;;) + { + if (a->d[i] >= w) + { + a->d[i]-=w; + break; + } + else + { + a->d[i]=(a->d[i]-w)&BN_MASK2; + i++; + w=1; + } + } + if ((a->d[i] == 0) && (i == (a->top-1))) + a->top--; + return(1); + } +#endif + +#ifdef SPLIT_BN_MUL_WORD +int BN_mul_word(a,w) +BIGNUM *a; +BN_ULONG w; + { + BN_ULONG ll; + + w=w&BN_MASK2;//w&=BN_MASK2; + if (a->top) + { + ll=bn_mul_words(a->d,a->d,a->top,w); + if (ll) + { + if (bn_wexpand(a,a->top+1) == NULL) return(0); + a->d[a->top++]=ll; + } + } + return(1); + } +#endif + +#endif diff --git a/build/libraries_sysmenu/acsign/ARM9/src/main.c b/build/libraries_sysmenu/acsign/ARM9/src/main.c new file mode 100644 index 00000000..d0d591b8 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/main.c @@ -0,0 +1,320 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------*/ +#include +#include + +#include "acsign.h" +#include "acmemory.h" + +/*---------------------------------------------------------------------------*/ +unsigned long binarray[ 1024 * 1024 * 2 / sizeof (unsigned long) ]; +unsigned long keyarray[ 1024 / sizeof (unsigned long) ]; +unsigned long sgnarray[ 1024 / sizeof (unsigned long) ]; +unsigned long bufferA[ ACSIGN_BUFFER / sizeof (unsigned long) ]; +unsigned long bufferB[ ACSIGN_BUFFER / sizeof (unsigned long) ]; + + + +/*--------------------------------------------------------------------------*/ +// ROMwb_ +//---------------------------------------------------------------------- +typedef struct { + // + // 0x000 System Reserved + // + char title_name[12]; // Soft title name + u32 game_code; // Game code + + u16 maker_code; // Maker code + u8 machine_code; // Machine code + u8 rom_type; // Rom type + u8 rom_size; // Rom size + + u8 reserved_A[9]; // System Reserved A ( Set ALL 0 ) + u8 soft_version; // Soft version + + u8 comp_arm9_boot_area:1; // Compress arm9 boot area + u8 comp_arm7_boot_area:1; // Compress arm7 boot area + u8 inspectCard:1; // J[htO + u8 disableClearMemoryPad:1; // IPL2pbhNAEfBZ[utO + u8 :0; + + + // + // 0x020 for Static modules (Section:B) + // + // ARM9 + u32 main_rom_offset; // ROM offset + void* main_entry_address; // Entry point + void* main_ram_address; // RAM address + u32 main_size; // Module size + + // ARM7 + u32 sub_rom_offset; // ROM offset + void* sub_entry_address; // Entry point + void* sub_ram_address; // RAM address + u32 sub_size; // Module size + + // + // 0x040 for File Name Table[FNT] (Section:C) + // + u32 fnt_offset; // ROM offset + u32 fnt_size; // Table size + + // + // 0x048 for File Allocation Table[FAT] (Section:E) + // + u32 fat_offset; // ROM offset + u32 fat_size; // Table size + + // + // 0x050 for Overlay Tables[OVT] (Section:D) + // + // ARM9 + u32 main_ovt_offset; // ROM offset + u32 main_ovt_size; // Table size + + // ARM7 + u32 sub_ovt_offset; // ROM offset + u32 sub_ovt_size; // Table size + + // 0x060 for ROM control parameter + u8 reserved_A2[32]; + + // 0x080 - 0x0C0 System Reserved + u8 reserved_B[64]; // System Reserved B (Set 0) + + // 0x0C0 for NINTENDO logo data + u8 nintendo_logo[0x9c]; // NINTENDO logo data + u16 nintendo_logo_crc16; // CRC-16 + + // 0x15E ROM header CRC-16 + u16 header_crc16; // ROM header CRC-16 +} RomHeader; + + +/* V-blank callback */ +static void VBlankIntr(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); +} + + + + + +/*---------------------------------------------------------------------------* + Name: InitializeAllocateSystem + + Description: C̃A[iɂăăVXeB + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void InitializeAllocateSystem(void) +{ + void* tempLo; + OSHeapHandle hh; + + // OS_Init͌Ă΂ĂƂO + tempLo = OS_InitAlloc( + OS_ARENA_MAIN , + OS_GetMainArenaLo() , + OS_GetMainArenaHi() , + 1 + ); + OS_SetArenaLo( + OS_ARENA_MAIN , + tempLo + ); + hh = OS_CreateHeap( + OS_ARENA_MAIN , + OS_GetMainArenaLo() , + OS_GetMainArenaHi() + ); + if( hh < 0 ) + { + OS_Panic("ARM9: Fail to create heap...\n"); + } + hh = OS_SetCurrentHeap( + OS_ARENA_MAIN , + hh + ); +} + + +// +static +void TestAC(char* iplfile, char* srlfile, char* sgnfile, FSFile* pfile ) +{ + RomHeader* pHeader; + const char* path; + BOOL fresult; + void* srl_ptr = 0; + long srl_len = 0; + void* key_ptr = 0; + long key_len = 0; + void* sgn_ptr = 0; + long sgn_len = 0; + + + if ( !pfile ) return ; + if ( !iplfile ) return ; + if ( !srlfile ) return ; + if ( !sgnfile ) return ; + + path = iplfile; + if ( (fresult = FS_OpenFile(pfile, path)) ) + { + key_len = FS_ReadFile( pfile, keyarray, sizeof keyarray ); + key_ptr = keyarray; + fresult = FS_CloseFile( pfile ); + } + if ( !fresult ) + OS_Printf("file read error! %s\n", path ); + + path = srlfile; + if ( (fresult = FS_OpenFile(pfile, path)) ) + { + srl_len = FS_ReadFile( pfile, binarray, sizeof binarray ); + srl_ptr = binarray; + fresult = FS_CloseFile( pfile ); + } + if ( !fresult ) + OS_Printf("file read error! %s\n", path ); + + path = sgnfile; //"/data/sgn0.bin"; // sgn + if ( (fresult = FS_OpenFile(pfile, path)) ) + { + sgn_len = FS_ReadFile( pfile, sgnarray, sizeof sgnarray ); + sgn_ptr = sgnarray; + fresult = FS_CloseFile( pfile ); + } + if ( !fresult ) + OS_Printf("file read error! %s\n", path ); + + // F + if ( srl_ptr && srl_len && key_ptr && key_len && sgn_ptr && sgn_len ) + { + long nSerial = 0; + pHeader = (RomHeader*)binarray; + + MI_CpuFill8( bufferA, 0, sizeof bufferA ); + MI_CpuFill8( bufferB, 0, sizeof bufferB ); + #if 0 + HMAC/Digtal Signature + >char seg_id[2]; //->"ac"ɌŒ + >u16 version; //-> 1ɌŒ + >u8 auth_code[20]/digital_sign[128] + >long serial_number + >char title_name[12]; // RomHeader.title_name + >u32 game_code; // RomHeader.game_code + >u16 maker_code; // RomHeader.make_code + >u8 machine_code; // RomHeader.machine_code + #endif + ((unsigned char*)&nSerial)[0] = ((unsigned char*)sgn_ptr + 4 + 128)[0]; + ((unsigned char*)&nSerial)[1] = ((unsigned char*)sgn_ptr + 4 + 128)[1]; + ((unsigned char*)&nSerial)[2] = ((unsigned char*)sgn_ptr + 4 + 128)[2]; + ((unsigned char*)&nSerial)[3] = ((unsigned char*)sgn_ptr + 4 + 128)[3]; + + (void)ACSign_Decrypto( bufferA, + (char*)sgn_ptr + 4, // t@C̈Í͂ւ̃ItZbgvX + (char*)key_ptr + 16 ); // PCMOD݂̂̃t@CɑΉ+16sv + + (void)ACSign_Digest( bufferB, + srl_ptr, + (char*)srl_ptr + pHeader->main_rom_offset, + pHeader->main_size, + (char*)srl_ptr + pHeader->sub_rom_offset, + pHeader->sub_size, + nSerial ); + + if ( ACSign_Compare( bufferA, bufferB ) ) + { + OS_Printf( "Authentication_Code test : success! [%12s %12s] \n", srlfile, sgnfile ); + } + else + { + OS_Printf( "Authentication_Code test : failure! [%12s %12s]\n", srlfile, sgnfile ); + } + + } + else + { + OS_Printf( "no test\n" ); + } + + OS_PrintServer(); +} + + +void NitroMain(void) +{ + FSFile file; + + + OS_InitPrintServer(); + OS_Init(); + OS_InitThread(); + InitializeAllocateSystem(); + + OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)OS_EnableIrqMask(OS_IE_FIFO_RECV); + (void)OS_EnableIrq(); + + if ( sizeof (int ) < sizeof ( long ) ) + OS_Printf( "sizeof (int ) != sizeof ( long )\n" ); + if ( sizeof ( RomHeader ) != 0x0160 ) + OS_Printf( "sizeof ( RomHeader ) != 0x0160\n" ); + + /* initialize file-system */ + FS_Init( (u32)MI_DMA_MAX_NUM ); /* use DMA-3 for FS */ + + /* always preload FS table for faster directory access. */ + { + u32 need_size = FS_GetTableSize(); + void *p_table = OS_Alloc(need_size); + SDK_ASSERT(p_table != NULL); + (void)FS_LoadTable(p_table, need_size); + } + + // t@Cǂݍ + FS_InitFile(&file); + //TestAC( "/data/iplpub.bin", "/data/main.srl", "/data/sgn.bin", &file ); + + TestAC( "/data/iplpub.bin", "/data/main0.srl", "/data/sgn0.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main1.srl", "/data/sgn1.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main2.srl", "/data/sgn2.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main3.srl", "/data/sgn3.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main4.srl", "/data/sgn4.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main5.srl", "/data/sgn5.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main6.srl", "/data/sgn6.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main7.srl", "/data/sgn7.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main0.srl", "/data/sgn7.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main3.srl", "/data/sgn1.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main5.srl", "/data/sgn5.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main1.srl", "/data/sgn0.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main0.srl", "/data/sgn1.bin", &file ); + TestAC( "/data/iplpub.bin", "/data/main0.srl", "/data/sgn0.bin", &file ); + + OS_Terminate(); +} + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/md5.c b/build/libraries_sysmenu/acsign/ARM9/src/md5.c new file mode 100644 index 00000000..9b89e568 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/md5.c @@ -0,0 +1,412 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm + */ + +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All +rights reserved. + +License to copy and use this software is granted provided that it +is identified as the "RSA Data Security, Inc. MD5 Message-Digest +Algorithm" in all material mentioning or referencing this software +or this function. + +License is also granted to make and use derivative works provided +that such works are identified as "derived from the RSA Data +Security, Inc. MD5 Message-Digest Algorithm" in all material +mentioning or referencing the derived work. + +RSA Data Security, Inc. makes no representations concerning either +the merchantability of this software or the suitability of this +software for any particular purpose. It is provided "as is" +without express or implied warranty of any kind. + +These notices must be retained in any copies of any part of this +documentation and/or software. + */ + +#include "md5.h" + +/* Constants for MD5Transform routine. */ + +#define S11 7 +#define S12 12 +#define S13 17 +#define S14 22 +#define S21 5 +#define S22 9 +#define S23 14 +#define S24 20 +#define S31 4 +#define S32 11 +#define S33 16 +#define S34 23 +#define S41 6 +#define S42 10 +#define S43 15 +#define S44 21 + +static void MD5Transform(unsigned long [4], unsigned char [64]); +static void Encode(unsigned char *, unsigned long *, unsigned int); +static void Decode(unsigned long *, unsigned char *, unsigned int); +static void MD5_memcpy(unsigned char*, unsigned char*, unsigned int); +static void MD5_memset(unsigned char*, int, unsigned int); + +static unsigned char PADDING[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* F, G, H and I are basic MD5 functions. + */ +#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) +#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define I(x, y, z) ((y) ^ ((x) | (~z))) + +/* ROTATE_LEFT rotates x left n bits. + */ +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. + Rotation is separate from addition to prevent recomputation. + */ +#define FF(a, b, c, d, x, s, ac) { \ + (a) += F ((b), (c), (d)) + (x) + (unsigned long)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define GG(a, b, c, d, x, s, ac) { \ + (a) += G ((b), (c), (d)) + (x) + (unsigned long)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define HH(a, b, c, d, x, s, ac) { \ + (a) += H ((b), (c), (d)) + (x) + (unsigned long)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } +#define II(a, b, c, d, x, s, ac) { \ + (a) += I ((b), (c), (d)) + (x) + (unsigned long)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ + } + +/* MD5 initialization. Begins an MD5 operation, writing a new context. + */ +void MD5Init(context) +MD5_CTX *context; /* context */ +{ + context->count[0] = context->count[1] = 0; + /* Load magic initialization constants. */ + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; +} + +/* MD5 block update operation. Continues an MD5 message-digest + operation, processing another message block, and updating the + context. + */ +void MD5Update(context, input, inputLen) +MD5_CTX *context; /* context */ +unsigned char *input; /* input block */ +unsigned int inputLen; /* length of input block */ +{ + unsigned int i, index, partLen; + + /* Compute number of bytes mod 64 */ + index = (unsigned int)((context->count[0] >> 3) & 0x3F); + + /* Update number of bits */ + if ((context->count[0] += ((unsigned long)inputLen << 3)) < ((unsigned long)inputLen << 3)) + context->count[1]++; + context->count[1] += ((unsigned long)inputLen >> 29); + + partLen = 64 - index; + + /* Transform as many times as possible. */ + if (inputLen >= partLen) { + MD5_memcpy((unsigned char*)&context->buffer[index], (unsigned char*)input, partLen); + MD5Transform (context->state, context->buffer); + + for (i = partLen; i + 63 < inputLen; i += 64) + MD5Transform (context->state, &input[i]); + + index = 0; + } + else + i = 0; + + /* Buffer remaining input */ + MD5_memcpy((unsigned char*)&context->buffer[index], (unsigned char*)&input[i], inputLen-i); +} + +/* MD5 finalization. Ends an MD5 message-digest operation, writing the + the message digest and zeroizing the context. + */ +void MD5Final(digest, context) +unsigned char digest[16]; /* message digest */ +MD5_CTX *context; /* context */ +{ + unsigned char bits[8]; + unsigned int index, padLen; + + /* Save number of bits */ + Encode (bits, context->count, 8); + + /* Pad out to 56 mod 64. */ + index = (unsigned int)((context->count[0] >> 3) & 0x3f); + padLen = (index < 56) ? (56 - index) : (120 - index); + MD5Update (context, PADDING, padLen); + + /* Append length (before padding) */ + MD5Update (context, bits, 8); + + /* Store state in digest */ + Encode (digest, context->state, 16); + + /* Zeroize sensitive information. */ + MD5_memset ((unsigned char*)context, 0, sizeof (*context)); +} + +/* MD5 basic transformation. Transforms state based on block. + */ +static void MD5Transform (state, block) +unsigned long state[4]; +unsigned char block[64]; +{ + unsigned long a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + + Decode (x, block, 64); + + /* Round 1 */ + FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ + FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ + FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ + FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ + FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ + FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ + FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ + FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ + FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ + FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ + FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ + FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ + FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ + FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ + FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ + FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ + + /* Round 2 */ + GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ + GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ + GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ + GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ + GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ + GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ + GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ + GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ + GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ + GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ + GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ + GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ + GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ + GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ + GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ + GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ + + /* Round 3 */ + HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ + HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ + HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ + HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ + HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ + HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ + HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ + HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ + HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ + HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ + HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ + HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ + HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ + HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ + HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ + HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ + + /* Round 4 */ + II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ + II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ + II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ + II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ + II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ + II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ + II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ + II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ + II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ + II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ + II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ + II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ + II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ + II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ + II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ + II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + + /* Zeroize sensitive information. */ + MD5_memset ((unsigned char*)x, 0, sizeof (x)); +} + +/* Encodes input (unsigned long) into output (unsigned char). Assumes len is + a multiple of 4. + */ +static void Encode(output, input, len) +unsigned char *output; +unsigned long *input; +unsigned int len; +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) { + output[j ] = (unsigned char)( input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + } +} + +/* Decodes input (unsigned char) into output (unsigned long). Assumes len is + a multiple of 4. + */ +static void Decode(output, input, len) +unsigned long *output; +unsigned char *input; +unsigned int len; +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((unsigned long)input[j]) | (((unsigned long)input[j+1]) << 8) | + (((unsigned long)input[j+2]) << 16) | (((unsigned long)input[j+3]) << 24); +} + +/* Note: Replace "for loop" with standard memcpy if possible. + */ + +static void MD5_memcpy(output, input, len) +unsigned char* output; +unsigned char* input; +unsigned int len; +{ + unsigned int i; + + for (i = 0; i < len; i++) + output[i] = input[i]; +} + +/* Note: Replace "for loop" with standard memset if possible. + */ +static void MD5_memset(output, value, len) +unsigned char* output; +int value; +unsigned int len; +{ + unsigned int i; + + for (i = 0; i < len; i++) + ((char *)output)[i] = (char)value; +} + + + + +////////////////////////////////////////////////////////////////////////////// +#if defined( MD5_TEST ) + +#include + +char* samplearray[ 7 ] = +{ + "", + "a", + "abc", + "message digest", + "abcdefghijklmnopqrstuvwxyz", + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "1234567890" // x8 +}; + +char* resultarray[ 7 ] = +{ + "\xD4\x1D\x8C\xD9\x8F\x00\xB2\x04\xE9\x80\x09\x98\xEC\xF8\x42\x7E", + "\x0C\xC1\x75\xB9\xC0\xF1\xB6\xA8\x31\xC3\x99\xE2\x69\x77\x26\x61", + "\x90\x01\x50\x98\x3C\xD2\x4F\xB0\xD6\x96\x3F\x7D\x28\xE1\x7F\x72", + "\xF9\x6B\x69\x7D\x7C\xB7\x93\x8D\x52\x5A\x2F\x31\xAA\xF1\x61\xD0", + "\xC3\xFC\xD3\xD7\x61\x92\xE4\x00\x7D\xFB\x49\x6C\xCA\x67\xE1\x3B", + "\xD1\x74\xAB\x98\xD2\x77\xD9\xF5\xA5\x61\x1C\x2C\x9F\x41\x9D\x9F", + "\x57\xED\xF4\xA2\x2B\xE3\xC9\x55\xAC\x49\xDA\x2E\x21\x07\xB6\x7A" +}; + +int repeatarray[ 7 ] = +{ + 1, + 1, + 1, + 1, + 1, + 1, + 8 +}; + +int MD5Test( ) +{ + MD5_CTX context; + unsigned char digest[16]; + int i, j, error; + + error = 0; + for ( j = 0; j < 7; j++ ) + { + MD5Init(&context); + + for ( i = 0; i < repeatarray[j]; i++ ) + { + MD5Update (&context, + (unsigned char*)samplearray[j], + (unsigned int)strlen( samplearray[j]) ); + } + + MD5Final(digest, &context); + + error = memcmp( digest, resultarray[j], 16 ); + + if ( error ) + break; + } + + return error ? 0 : 1; +} + +#endif // MD5_TEST +////////////////////////////////////////////////////////////////////////////// diff --git a/build/libraries_sysmenu/acsign/ARM9/src/sha1.c b/build/libraries_sysmenu/acsign/ARM9/src/sha1.c new file mode 100644 index 00000000..e7f2a653 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/sha1.c @@ -0,0 +1,470 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * sha1.c + * + * Description: + * This file implements the Secure Hashing Algorithm 1 as + * defined in FIPS PUB 180-1 published April 17, 1995. + * + * The SHA-1, produces a 160-bit message digest for a given + * data stream. It should take about 2**n steps to find a + * message with the same digest as a given message and + * 2**(n/2) to find any two messages with the same digest, + * when n is the digest size in bits. Therefore, this + * algorithm can serve as a means of providing a + * "fingerprint" for a message. + * + * Portability Issues: + * SHA-1 is defined in terms of 32-bit "words". This code + * uses (included via "sha1.h" to define 32 and 8 + * bit unsigned integer types. If your C compiler does not + * support 32 bit unsigned integers, this code is not + * appropriate. + * + * Caveats: + * SHA-1 is designed to work with messages less than 2^64 bits + * long. Although SHA-1 allows a message digest to be generated + * for messages of any number of bits less than 2^64, this + * implementation only works with messages with a length that is + * a multiple of the size of an 8-bit character. + * + */ + +#include "sha1.h" + +/* + * Define the SHA1 circular left shift macro + */ +#define SHA1CircularShift(bits,word) \ + (((word) << (bits)) | ((word) >> (32-(bits)))) + +/* Local Function Prototyptes */ +void SHA1PadMessage(SHA1Context *); +void SHA1ProcessMessageBlock(SHA1Context *); + +/* + * SHA1Reset + * + * Description: + * This function will initialize the SHA1Context in preparation + * for computing a new SHA1 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * + * Returns: + * sha Error Code. + * + */ +int SHA1Reset(SHA1Context *context) +{ + if (!context) + { + return shaNull; + } + + context->Length_Low = 0; + context->Length_High = 0; + context->Message_Block_Index = 0; + + context->Intermediate_Hash[0] = 0x67452301; + context->Intermediate_Hash[1] = 0xEFCDAB89; + context->Intermediate_Hash[2] = 0x98BADCFE; + context->Intermediate_Hash[3] = 0x10325476; + context->Intermediate_Hash[4] = 0xC3D2E1F0; + + context->Computed = 0; + context->Corrupted = 0; + + return shaSuccess; +} + +/* + * SHA1Result + * + * Description: + * This function will return the 160-bit message digest into the + * Message_Digest array provided by the caller. + * NOTE: The first octet of hash is stored in the 0th element, + * the last octet of hash in the 19th element. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA-1 hash. + * Message_Digest: [out] + * Where the digest is returned. + * + * Returns: + * sha Error Code. + * + */ +int SHA1Result( SHA1Context *context, + unsigned char Message_Digest[20]) +{ + int i; + + if (!context || !Message_Digest) + { + return shaNull; + } + + if (context->Corrupted) + { + return context->Corrupted; + } + + if (!context->Computed) + { + SHA1PadMessage(context); + for(i=0; i<64; ++i) + { + /* message may be sensitive, clear it out */ + context->Message_Block[i] = 0; + } + context->Length_Low = 0; /* and clear length */ + context->Length_High = 0; + context->Computed = 1; + + } + + for(i = 0; i < 20; ++i) + { + Message_Digest[i] = (unsigned char) + (context->Intermediate_Hash[i>>2] + >> 8 * ( 3 - ( i & 0x03 ) )); + } + + return shaSuccess; +} + +/* + * SHA1Input + * + * Description: + * This function accepts an array of octets as the next portion + * of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update + * message_array: [in] + * An array of characters representing the next portion of + * the message. + * length: [in] + * The length of the message in message_array + * + * Returns: + * sha Error Code. + * + */ +int SHA1Input( SHA1Context *context, + const unsigned char *message_array, + unsigned int length) +{ + if (!length) + { + return shaSuccess; + } + + if (!context || !message_array) + { + return shaNull; + } + + if (context->Computed) + { + context->Corrupted = shaStateError; + + return shaStateError; + } + + if (context->Corrupted) + { + return context->Corrupted; + } + while(length-- && !context->Corrupted) + { + context->Message_Block[context->Message_Block_Index++] = + (unsigned char)(*message_array & 0xFF); + + context->Length_Low += 8; + if (context->Length_Low == 0) + { + context->Length_High++; + if (context->Length_High == 0) + { + /* Message is too long */ + context->Corrupted = 1; + } + } + + if (context->Message_Block_Index == 64) + { + SHA1ProcessMessageBlock(context); + } + + message_array++; + } + + return shaSuccess; +} + +/* + * SHA1ProcessMessageBlock + * + * Description: + * This function will process the next 512 bits of the message + * stored in the Message_Block array. + * + * Parameters: + * None. + * + * Returns: + * Nothing. + * + * Comments: + * + * Many of the variable names in this code, especially the + * single character names, were used because those were the + * names used in the publication. + * + * + */ +void SHA1ProcessMessageBlock(SHA1Context *context) +{ + const unsigned long K[] = { /* Constants defined in SHA-1 */ + 0x5A827999, + 0x6ED9EBA1, + 0x8F1BBCDC, + 0xCA62C1D6 + }; + int t; /* Loop counter */ + unsigned long temp; /* Temporary word value */ + unsigned long W[80]; /* Word sequence */ + unsigned long A, B, C, D, E; /* Word buffers */ + + /* + * Initialize the first 16 words in the array W + */ + for(t = 0; t < 16; t++) + { + W[t] = context->Message_Block[t * 4 ] << 24; + W[t] |= context->Message_Block[t * 4 + 1] << 16; + W[t] |= context->Message_Block[t * 4 + 2] << 8; + W[t] |= context->Message_Block[t * 4 + 3]; + } + + for(t = 16; t < 80; t++) + { + W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]); + } + + A = context->Intermediate_Hash[0]; + B = context->Intermediate_Hash[1]; + C = context->Intermediate_Hash[2]; + D = context->Intermediate_Hash[3]; + E = context->Intermediate_Hash[4]; + + for(t = 0; t < 20; t++) + { + temp = SHA1CircularShift(5,A) + + ((B & C) | ((~B) & D)) + E + W[t] + K[0]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + + B = A; + A = temp; + } + + for(t = 20; t < 40; t++) + { + temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + for(t = 40; t < 60; t++) + { + temp = SHA1CircularShift(5,A) + + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + for(t = 60; t < 80; t++) + { + temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + context->Intermediate_Hash[0] += A; + context->Intermediate_Hash[1] += B; + context->Intermediate_Hash[2] += C; + context->Intermediate_Hash[3] += D; + context->Intermediate_Hash[4] += E; + + context->Message_Block_Index = 0; +} + +/* + * SHA1PadMessage + * + + * Description: + * According to the standard, the message must be padded to an even + * 512 bits. The first padding bit must be a '1'. The last 64 + * bits represent the length of the original message. All bits in + * between should be 0. This function will pad the message + * according to those rules by filling the Message_Block array + * accordingly. It will also call the ProcessMessageBlock function + * provided appropriately. When it returns, it can be assumed that + * the message digest has been computed. + * + * Parameters: + * context: [in/out] + * The context to pad + * ProcessMessageBlock: [in] + * The appropriate SHA*ProcessMessageBlock function + * Returns: + * Nothing. + * + */ + +void SHA1PadMessage(SHA1Context *context) +{ + /* + * Check to see if the current message block is too small to hold + * the initial padding bits and length. If so, we will pad the + * block, process it, and then continue padding into a second + * block. + */ + if (context->Message_Block_Index > 55) + { + context->Message_Block[context->Message_Block_Index++] = 0x80; + while(context->Message_Block_Index < 64) + { + context->Message_Block[context->Message_Block_Index++] = 0; + } + + SHA1ProcessMessageBlock(context); + + while(context->Message_Block_Index < 56) + { + context->Message_Block[context->Message_Block_Index++] = 0; + } + } + else + { + context->Message_Block[context->Message_Block_Index++] = 0x80; + while(context->Message_Block_Index < 56) + { + + context->Message_Block[context->Message_Block_Index++] = 0; + } + } + + /* + * Store the message length as the last 8 octets + */ + context->Message_Block[56] = (unsigned char)(context->Length_High >> 24); + context->Message_Block[57] = (unsigned char)(context->Length_High >> 16); + context->Message_Block[58] = (unsigned char)(context->Length_High >> 8); + context->Message_Block[59] = (unsigned char)(context->Length_High ); + context->Message_Block[60] = (unsigned char)(context->Length_Low >> 24); + context->Message_Block[61] = (unsigned char)(context->Length_Low >> 16); + context->Message_Block[62] = (unsigned char)(context->Length_Low >> 8); + context->Message_Block[63] = (unsigned char)(context->Length_Low ); + + SHA1ProcessMessageBlock(context); +} + + + + +////////////////////////////////////////////////////////////////////////////// +#if defined( SHA1_TEST ) + +#include "string.h" + +char* samplearray[4] = +{ + "abc", + "abcdbcdecdefdefgefghfghighijhi" "jkijkljklmklmnlmnomnopnopq", + "a", + "01234567012345670123456701234567" "01234567012345670123456701234567" +}; + +char* resultarray[ 4 ] = +{ + "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D", + "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1", + "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F", + "\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52" +}; + +long int repeatcount[4] = { 1, 1, 1000000, 10 }; + +int SHA1Test( ) +{ + SHA1Context sha; + unsigned char digest[20]; + int i, j, error; + + error = 0; + for ( j = 0; j < 4; ++j ) + { + if ( !error ) + error = SHA1Reset(&sha); + + for(i = 0; i < repeatcount[j]; ++i) + { + if ( !error ) + error = SHA1Input(&sha, + (const unsigned char *)samplearray[j], + (unsigned int)strlen(samplearray[j])); + } + + if ( !error ) + error = SHA1Result(&sha, digest); + + if ( !error ) + error = memcmp( digest, resultarray[j], 20 ); + + if (error) + break; + } + + return error ? 0 : 1; +} + +#endif // SHA1_TEST +////////////////////////////////////////////////////////////////////////////// + diff --git a/build/libraries_sysmenu/acsign/ARM9/src/sha1dgst.c b/build/libraries_sysmenu/acsign/ARM9/src/sha1dgst.c new file mode 100644 index 00000000..4742b605 --- /dev/null +++ b/build/libraries_sysmenu/acsign/ARM9/src/sha1dgst.c @@ -0,0 +1,786 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: + + 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$ + *---------------------------------------------------------------------------*/ + +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +////!!!!#include "r_com.h" + +#ifndef NO_SHA1 +#undef SHA_0 +#define SHA_1 +#include "sha.h" +#include "sha_locl.h" +#ifdef CPU_X86 +#include "r_cpuid.h" +#endif /* NO_SHA1 */ + +const char *SHA1_version="SHA1 part of RCOM 2.3.0 11-Jun-2002"; + +/* Implemented from SHA-1 document - The Secure Hash Algorithm + */ + +#define INIT_DATA_h0 (SHA_LONG)0x67452301L +#define INIT_DATA_h1 (SHA_LONG)0xefcdab89L +#define INIT_DATA_h2 (SHA_LONG)0x98badcfeL +#define INIT_DATA_h3 (SHA_LONG)0x10325476L +#define INIT_DATA_h4 (SHA_LONG)0xc3d2e1f0L + +#define K_00_19 (SHA_LONG)0x5a827999L +#define K_20_39 (SHA_LONG)0x6ed9eba1L +#define K_40_59 (SHA_LONG)0x8f1bbcdcL +#define K_60_79 (SHA_LONG)0xca62c1d6L + +#ifndef CCONV +#define CCONV +#endif + +#ifndef PRE_CCONV +#define PRE_CCONV +#endif + +/* Endian flags are only used for the assembler code */ +#ifndef OPT_SHA1_ASM +#undef L_ENDIAN +#undef B_ENDIAN +#endif + + +#ifdef OPT_SHA1_ASM + +#ifdef CPU_X86 +void CCONV sha1_block_586(SHA_CTX *c,const unsigned char *p, int num); +void CCONV sha1_block_686(SHA_CTX *c,const unsigned char *p, int num); +void CCONV sha1_block_786(SHA_CTX *c,const unsigned char *p, int num); +unsigned long r_cpuid(unsigned long *,char **name); + +#elif OPT_SHA1_ARM +PRE_CCONV void CCONV sha1_arm4_fast(SHA_CTX *c, const unsigned char *p, + int num); +PRE_CCONV void CCONV sha1_arm4_small(SHA_CTX *c, const unsigned char *p, + int num); +#else +void CCONV sha1_block_asm(SHA_CTX *c, const unsigned char *p, int num); +#endif /* CPU_X86 */ + +#else /* OPT_SHA1_ASM */ + +void sha1_block(SHA_CTX *c, SHA_LONG *p, int num); + +#endif /* OPT_SHA1_ASM */ + +#undef M_c2nl +#undef M_p_c2nl +#undef M_c2nl_p +#undef M_p_c2nl_p +#undef M_nl2c + +#if defined(L_ENDIAN) && !defined(OPT_SHA1_ASM) +# define M_c2nl c2l +# define M_p_c2nl p_c2l +# define M_c2nl_p c2l_p +# define M_p_c2nl_p p_c2l_p +# define M_nl2c l2c +#else +# define M_c2nl c2nl +# define M_p_c2nl p_c2nl +# define M_c2nl_p c2nl_p +# define M_p_c2nl_p p_c2nl_p +# define M_nl2c nl2c +#endif /* defined(L_ENDIAN) && !defined(OPT_SHA1_ASM) */ + +int SHA1_Setup(c,sha_block) +SHA_CTX *c; +void (PRE_CCONV CCONV *sha_block)(SHA_CTX *c, const unsigned char *W, int num); + { + c->sha_block=sha_block; + return(0); + } + +void SHA1_Init(c) +SHA_CTX *c; + { + c->h0=INIT_DATA_h0; + c->h1=INIT_DATA_h1; + c->h2=INIT_DATA_h2; + c->h3=INIT_DATA_h3; + c->h4=INIT_DATA_h4; + c->Nl=0; + c->Nh=0; + c->num=0; + +#ifdef OPT_SHA1_ASM +#ifdef CPU_X86 + if (c->sha_block == NULL) + { + unsigned long cpu,attrib; + + /* We should make the methods loadable */ + cpu=r_cpuid(&attrib,NULL); + if (attrib & R_CPU_X86_HAS_PENTIUM_IV) + c->sha_block=sha1_block_786; + else if (attrib & R_CPU_X86_HAS_PENTIUM_PRO) + c->sha_block=sha1_block_686; + else + c->sha_block=sha1_block_586; + } +#else /* CPU_X86 */ + +#ifndef OPT_SHA1_ARM + c->sha_block=sha1_block_asm; +#else /* OPT_SHA1_ARM */ + if (c->sha_block == NULL) + { +#ifdef SMALL_CODE_SIZE + c->sha_block = sha1_arm4_small; +#else /* SMALL_CODE_SIZE */ + c->sha_block = sha1_arm4_fast; +#endif /* SMALL_CODE_SIZE */ + } +#endif /* OPT_SHA1_ARM */ +#endif /* CPU_X86 */ + +#else /* OPT_SHA1_ASM */ + c->sha_block=(void (PRE_CCONV CCONV *)(SHA_CTX *, const unsigned char *, int))sha1_block; +#endif /* OPT_SHA1_ASM */ + } + +#ifdef OPT_SHA1_ASM + +void SHA1_Update(c, data, len) +SHA_CTX *c; +const register unsigned char *data; +unsigned long len; + { + int i; + unsigned int alignment; + unsigned long l; + unsigned char *cp=(unsigned char *)c->data; + + if (len == 0) return; + + l=(c->Nl+(len<<3))&0xffffffffL; + if (l < c->Nl) /* overflow */ + c->Nh++; + c->Nh+=(len>>29); + c->Nl=l; + + if (c->num != 0) + { + if (c->num+len >= SHA_CBLOCK) + { + i=SHA_CBLOCK-c->num; + Memcpy(&(cp[c->num]),data,i); + len-=i; + data+=i; + + c->sha_block(c,cp,64); + c->num=0; + /* drop through and do the rest */ + } + else + { + Memcpy(&(cp[c->num]),data,len); + c->num+=(int)len; + return; + } + } + /* we now can process the input data in blocks of SHA_CBLOCK + * chars and save the leftovers to c->data. */ + if (len >= SHA_CBLOCK) + { + i=(int)(len& ~63); + len-=i; + + /* + * Check to see if the input data lies on a word boundary. + * Do this as the ASM relies on input data being word aligned. + */ + alignment = (((unsigned int)data) & (sizeof(unsigned int)-1)) + & 0x03; + if (alignment == 0) + { + c->sha_block(c,data,i); + data+=i; + } + else + { + do { + Memcpy(cp, data, SHA_CBLOCK); + data += SHA_CBLOCK; + c->sha_block(c, cp, SHA_CBLOCK); + i -= SHA_CBLOCK; + } while (i > 0); + } + } + c->num=len; + if (len) + { + Memcpy(cp,data,(int)len); + } + } + +void SHA1_Transform(c,b) +SHA_CTX *c; +const unsigned char *b; + { + c->sha_block(c,b,64); + } + +void SHA1_Final(md, c) +unsigned char *md; +SHA_CTX *c; + { + register int i,j; + register SHA_LONG l; + register SHA_LONG *p; + const static unsigned char end[4]={0x80,0x00,0x00,0x00}; + unsigned char *cp= (unsigned char *)end; + unsigned char *pc; + + /* c->num should definitly have room for at least one more byte. */ + p=c->data; + j=c->num; + i=j>>2; + +#ifdef PURIFY + /* PURIFY */ + /* we reference uninitialised data but don't keep the result + * which purify complains about ... and we don't want to have + * to come back here to find a non-existant problem later + */ + + /* purify often complains about the following line as an + * Uninitialized Memory Read. While this can be true, the + * following p_c2l macro will reset l when that case is true. + * This is because j&0x03 contains the number of 'valid' bytes + * already in p[i]. If and only if j&0x03 == 0, the UMR will + * occur but this is also the only time p_c2l will do + * l= *(cp++) instead of l|= *(cp++) + */ + if ((j&0x03) == 0) p[i]=0; +#endif + + pc=(unsigned char *)c->data; + pc[j]=0x80; + for (j++; j & 0x03; j++) + pc[j]=0; + i++; + /* i is the next 'undefined word' */ + if (c->num >= SHA_LAST_BLOCK) + { + for (; isha_block(c,(unsigned char *)p,64); + i=0; + } + for (; i<(SHA_LBLOCK-2); i++) + p[i]=0; + + l=c->Nl; + pc[63]=(unsigned char)((l )&0xff); + pc[62]=(unsigned char)((l>> 8)&0xff); + pc[61]=(unsigned char)((l>>16)&0xff); + pc[60]=(unsigned char)((l>>24)&0xff); + l=c->Nh; + pc[59]=(unsigned char)((l )&0xff); + pc[58]=(unsigned char)((l>> 8)&0xff); + pc[57]=(unsigned char)((l>>16)&0xff); + pc[56]=(unsigned char)((l>>24)&0xff); + + c->sha_block(c,(unsigned char *)p,64); + cp=md; + l=c->h0; nl2c(l,cp); + l=c->h1; nl2c(l,cp); + l=c->h2; nl2c(l,cp); + l=c->h3; nl2c(l,cp); + l=c->h4; nl2c(l,cp); + + /* clear stuff, sha1_block_asm may be leaving some stuff on the stack + * but I'm not worried :-) */ + c->num=0; +/* Memset((char *)&c,0,sizeof(c));*/ + } + +#else /* !OPT_SHA1_ASM */ + +void SHA1_Update(c, data, len) +SHA_CTX *c; +const register unsigned char *data; +unsigned long len; + { + register SHA_LONG *p; + int ew,ec,sw,sc; + SHA_LONG l; + + if (len == 0) return; + + l=(c->Nl+(len<<3))&0xffffffffL; + if (l < c->Nl) /* overflow */ + c->Nh++; + c->Nh+=(len>>29); + c->Nl=l; + + if (c->num != 0) + { + p=c->data; + sw=c->num>>2; + sc=c->num&0x03; + + if ((c->num+len) >= SHA_CBLOCK) + { + l= p[sw]; + M_p_c2nl(data,l,sc); + p[sw++]=l; + for (; swnum); + + c->sha_block(c,(unsigned char *)p,64); + c->num=0; + /* drop through and do the rest */ + } + else + { + c->num+=(int)len; + if ((sc+len) < 4) /* ugly, add char's to a word */ + { + l= p[sw]; + M_p_c2nl_p(data,l,sc,len); + p[sw]=l; + } + else + { + ew=(c->num>>2); + ec=(c->num&0x03); + l= p[sw]; + M_p_c2nl(data,l,sc); + p[sw++]=l; + for (; sw < ew; sw++) + { M_c2nl(data,l); p[sw]=l; } + if (ec) + { + M_c2nl_p(data,l,ec); + p[sw]=l; + } + } + return; + } + } + /* We can only do the following code for assember, the reason + * being that the sha1_block 'C' version changes the values + * in the 'data' array. The assember code avoids this and + * copies it to a local array. I should be able to do this for + * the C version as well.... + */ +#if defined(B_ENDIAN) || defined(OPT_SHA1_ASM) + if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0) + { + sw=len/SHA_CBLOCK; + if (sw) + { + sw*=SHA_CBLOCK; + c->sha_block(c,(SHA_LONG *)data,sw); + data+=sw; + len-=sw; + } + } +#endif + /* we now can process the input data in blocks of SHA_CBLOCK + * chars and save the leftovers to c->data. */ + p=c->data; + while (len >= SHA_CBLOCK) + { +#if defined(B_ENDIAN) || defined(L_ENDIAN) + if (p != (SHA_LONG *)data) + Memcpy(p,data,SHA_CBLOCK); + data+=SHA_CBLOCK; +# ifdef L_ENDIAN +# ifndef OPT_SHA1_ASM /* Will not happen */ + for (sw=(SHA_LBLOCK/4); sw; sw--) + { + Endian_Reverse32(p[0]); + Endian_Reverse32(p[1]); + Endian_Reverse32(p[2]); + Endian_Reverse32(p[3]); + p+=4; + } + p=c->data; +# endif +# endif +#else + for (sw=(SHA_BLOCK/4); sw; sw--) + { + M_c2nl(data,l); *(p++)=l; + M_c2nl(data,l); *(p++)=l; + M_c2nl(data,l); *(p++)=l; + M_c2nl(data,l); *(p++)=l; + } + p=c->data; +#endif + c->sha_block(c,(unsigned char *)p,64); + len-=SHA_CBLOCK; + } + ec=(int)len; + c->num=ec; + ew=(ec>>2); + ec&=0x03; + + for (sw=0; sw < ew; sw++) + { M_c2nl(data,l); p[sw]=l; } + M_c2nl_p(data,l,ec); + p[sw]=l; + } + +void SHA1_Transform(c,b) +SHA_CTX *c; +const unsigned char *b; + { + SHA_LONG p[16]; +#ifndef B_ENDIAN + SHA_LONG *q; + int i; +#endif + +#if defined(B_ENDIAN) || defined(L_ENDIAN) + Memcpy(p,b,64); +#ifdef L_ENDIAN + q=p; + for (i=(SHA_LBLOCK/4); i; i--) + { + Endian_Reverse32(q[0]); + Endian_Reverse32(q[1]); + Endian_Reverse32(q[2]); + Endian_Reverse32(q[3]); + q+=4; + } +#endif +#else + q=p; + for (i=(SHA_LBLOCK/4); i; i--) + { + SHA_LONG l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + } +#endif + c->sha_block(c,(unsigned char *)p,64); + } + + +void sha1_block(c, W, num) +SHA_CTX *c; +SHA_LONG *W; +int num; + { +#ifndef SMALL_CODE_SIZE + register SHA_LONG A,B,C,D,E,T; + SHA_LONG X[16]; + + A=c->h0; + B=c->h1; + C=c->h2; + D=c->h3; + E=c->h4; + + for (;;) + { + BODY_00_15( 0,A,B,C,D,E,T,W); + BODY_00_15( 1,T,A,B,C,D,E,W); + BODY_00_15( 2,E,T,A,B,C,D,W); + BODY_00_15( 3,D,E,T,A,B,C,W); + BODY_00_15( 4,C,D,E,T,A,B,W); + BODY_00_15( 5,B,C,D,E,T,A,W); + BODY_00_15( 6,A,B,C,D,E,T,W); + BODY_00_15( 7,T,A,B,C,D,E,W); + BODY_00_15( 8,E,T,A,B,C,D,W); + BODY_00_15( 9,D,E,T,A,B,C,W); + BODY_00_15(10,C,D,E,T,A,B,W); + BODY_00_15(11,B,C,D,E,T,A,W); + BODY_00_15(12,A,B,C,D,E,T,W); + BODY_00_15(13,T,A,B,C,D,E,W); + BODY_00_15(14,E,T,A,B,C,D,W); + BODY_00_15(15,D,E,T,A,B,C,W); + BODY_16_19(16,C,D,E,T,A,B,W,W,W,W); + BODY_16_19(17,B,C,D,E,T,A,W,W,W,W); + BODY_16_19(18,A,B,C,D,E,T,W,W,W,W); + BODY_16_19(19,T,A,B,C,D,E,W,W,W,X); + + BODY_20_31(20,E,T,A,B,C,D,W,W,W,X); + BODY_20_31(21,D,E,T,A,B,C,W,W,W,X); + BODY_20_31(22,C,D,E,T,A,B,W,W,W,X); + BODY_20_31(23,B,C,D,E,T,A,W,W,W,X); + BODY_20_31(24,A,B,C,D,E,T,W,W,X,X); + BODY_20_31(25,T,A,B,C,D,E,W,W,X,X); + BODY_20_31(26,E,T,A,B,C,D,W,W,X,X); + BODY_20_31(27,D,E,T,A,B,C,W,W,X,X); + BODY_20_31(28,C,D,E,T,A,B,W,W,X,X); + BODY_20_31(29,B,C,D,E,T,A,W,W,X,X); + BODY_20_31(30,A,B,C,D,E,T,W,X,X,X); + BODY_20_31(31,T,A,B,C,D,E,W,X,X,X); + BODY_32_39(32,E,T,A,B,C,D,X); + BODY_32_39(33,D,E,T,A,B,C,X); + BODY_32_39(34,C,D,E,T,A,B,X); + BODY_32_39(35,B,C,D,E,T,A,X); + BODY_32_39(36,A,B,C,D,E,T,X); + BODY_32_39(37,T,A,B,C,D,E,X); + BODY_32_39(38,E,T,A,B,C,D,X); + BODY_32_39(39,D,E,T,A,B,C,X); + + BODY_40_59(40,C,D,E,T,A,B,X); + BODY_40_59(41,B,C,D,E,T,A,X); + BODY_40_59(42,A,B,C,D,E,T,X); + BODY_40_59(43,T,A,B,C,D,E,X); + BODY_40_59(44,E,T,A,B,C,D,X); + BODY_40_59(45,D,E,T,A,B,C,X); + BODY_40_59(46,C,D,E,T,A,B,X); + BODY_40_59(47,B,C,D,E,T,A,X); + BODY_40_59(48,A,B,C,D,E,T,X); + BODY_40_59(49,T,A,B,C,D,E,X); + BODY_40_59(50,E,T,A,B,C,D,X); + BODY_40_59(51,D,E,T,A,B,C,X); + BODY_40_59(52,C,D,E,T,A,B,X); + BODY_40_59(53,B,C,D,E,T,A,X); + BODY_40_59(54,A,B,C,D,E,T,X); + BODY_40_59(55,T,A,B,C,D,E,X); + BODY_40_59(56,E,T,A,B,C,D,X); + BODY_40_59(57,D,E,T,A,B,C,X); + BODY_40_59(58,C,D,E,T,A,B,X); + BODY_40_59(59,B,C,D,E,T,A,X); + + BODY_60_79(60,A,B,C,D,E,T,X); + BODY_60_79(61,T,A,B,C,D,E,X); + BODY_60_79(62,E,T,A,B,C,D,X); + BODY_60_79(63,D,E,T,A,B,C,X); + BODY_60_79(64,C,D,E,T,A,B,X); + BODY_60_79(65,B,C,D,E,T,A,X); + BODY_60_79(66,A,B,C,D,E,T,X); + BODY_60_79(67,T,A,B,C,D,E,X); + BODY_60_79(68,E,T,A,B,C,D,X); + BODY_60_79(69,D,E,T,A,B,C,X); + BODY_60_79(70,C,D,E,T,A,B,X); + BODY_60_79(71,B,C,D,E,T,A,X); + BODY_60_79(72,A,B,C,D,E,T,X); + BODY_60_79(73,T,A,B,C,D,E,X); + BODY_60_79(74,E,T,A,B,C,D,X); + BODY_60_79(75,D,E,T,A,B,C,X); + BODY_60_79(76,C,D,E,T,A,B,X); + BODY_60_79(77,B,C,D,E,T,A,X); + BODY_60_79(78,A,B,C,D,E,T,X); + BODY_60_79(79,T,A,B,C,D,E,X); + + c->h0=(c->h0+E)&0xffffffffL; + c->h1=(c->h1+T)&0xffffffffL; + c->h2=(c->h2+A)&0xffffffffL; + c->h3=(c->h3+B)&0xffffffffL; + c->h4=(c->h4+C)&0xffffffffL; + + num-=64; + if (num <= 0) break; + + A=c->h0; + B=c->h1; + C=c->h2; + D=c->h3; + E=c->h4; + + W+=16; + } +#else /* SMALL_CODE_SIZE */ + SHA_LONG A,B,C,D,E,T; + SHA_LONG X[16]; + SHA_LONG *a1,*a2,*a3; + + A=c->h0; + B=c->h1; + C=c->h2; + D=c->h3; + E=c->h4; + + for (;;) + { + int i; + + for (i=0; i<16; i++) + { + BODY_00_15(i,A,B,C,D,E,T,W); + E=D; D=C; C=B; B=A; A=T; + } + + a1=W; + for (i=16; i<20; i++) + { + if (i == 19) a1=X; + BODY_16_19(i,A,B,C,D,E,T,W,W,W,a1); + E=D; D=C; C=B; B=A; A=T; + } + + a1=a2=a3=W; + for (i=20; i<40; i++) + { + if (i == 24) a3=X; + if (i == 30) a2=X; + if (i == 32) a1=X; + BODY_20_31(i,A,B,C,D,E,T,a1,a2,a3,X); + E=D; D=C; C=B; B=A; A=T; + } + + for (i=40; i<60; i++) + { + BODY_40_59(i,A,B,C,D,E,T,X); + E=D; D=C; C=B; B=A; A=T; + } + + for (i=60; i<80; i++) + { + BODY_60_79(i,A,B,C,D,E,T,X); + E=D; D=C; C=B; B=A; A=T; + } + + c->h0=(c->h0+A)&0xffffffffL; + c->h1=(c->h1+B)&0xffffffffL; + c->h2=(c->h2+C)&0xffffffffL; + c->h3=(c->h3+D)&0xffffffffL; + c->h4=(c->h4+E)&0xffffffffL; + + num-=64; + if (num <= 0) break; + + A=c->h0; + B=c->h1; + C=c->h2; + D=c->h3; + E=c->h4; + + W+=16; + } +#endif /* SMALL_CODE_SIZE */ + } + +void SHA1_Final(md, c) +unsigned char *md; +SHA_CTX *c; + { + register int i,j; + register SHA_LONG l; + register SHA_LONG *p; + const static unsigned char end[4]={0x80,0x00,0x00,0x00}; + unsigned char *cp= (unsigned char *)end; + + /* c->num should definitly have room for at least one more byte. */ + p=c->data; + j=c->num; + i=j>>2; + +#ifdef PURIFY + /* PURIFY */ + /* we reference uninitialised data but don't keep the result + * which purify complains about ... and we don't want to have + * to come back here to find a non-existant problem later + */ + + /* purify often complains about the following line as an + * Uninitialized Memory Read. While this can be true, the + * following p_c2l macro will reset l when that case is true. + * This is because j&0x03 contains the number of 'valid' bytes + * already in p[i]. If and only if j&0x03 == 0, the UMR will + * occur but this is also the only time p_c2l will do + * l= *(cp++) instead of l|= *(cp++) + */ + if ((j&0x03) == 0) p[i]=0; +#endif + + l=p[i]; + M_p_c2nl(cp,l,j&0x03); + p[i]=l; + i++; + /* i is the next 'undefined word' */ + if (c->num >= SHA_LAST_BLOCK) + { + for (; isha_block(c,(unsigned char *)p,64); + i=0; + } + for (; i<(SHA_LBLOCK-2); i++) + p[i]=0; + p[SHA_LBLOCK-2]=c->Nh; + p[SHA_LBLOCK-1]=c->Nl; +#if defined(L_ENDIAN) + Endian_Reverse32(p[SHA_LBLOCK-2]); + Endian_Reverse32(p[SHA_LBLOCK-1]); +#endif + c->sha_block(c,(unsigned char *)p,64); + cp=md; + l=c->h0; nl2c(l,cp); + l=c->h1; nl2c(l,cp); + l=c->h2; nl2c(l,cp); + l=c->h3; nl2c(l,cp); + l=c->h4; nl2c(l,cp); + + /* clear stuff, sha1_block may be leaving some stuff on the stack + * but I'm not worried :-) */ + c->num=0; +/* Memset((char *)&c,0,sizeof(c));*/ + } +#endif + +#if 0 +int pr(ctx) +SHA_CTX *ctx; + { + int i,j; + unsigned char *p=(unsigned char *)(ctx->data); + + fprintf(stderr,"num = %08X%08X\n",ctx->Nh,ctx->Nl); + fprintf(stderr," %08X %08X %08X %08X %08X\n", + ctx->h0,ctx->h1,ctx->h2,ctx->h3,ctx->h4); + fprintf(stderr,"bufnum = %d\n",ctx->num); + fprintf(stderr," "); + for (j=0; j<64; j+=16) + { + for (i=0; i<16; i++) + { +/* + if ((i+j) >= ctx->num) + fprintf(stderr,"--"); + else +*/ + fprintf(stderr,"%02X",p[i+j]); + } + if ((j+16) >=64) + fprintf(stderr,"\n"); + else + fprintf(stderr,"\n "); + } + } + +#endif + +#endif /* NO_SHA1 */ diff --git a/build/libraries_sysmenu/acsign/Makefile b/build/libraries_sysmenu/acsign/Makefile new file mode 100644 index 00000000..66c26aae --- /dev/null +++ b/build/libraries_sysmenu/acsign/Makefile @@ -0,0 +1,31 @@ +#! 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-09-27#$ +# $Rev: 1203 $ +# $Author: yada $ +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 + +TARGET_FIRM = SYSTEMMENU + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries_sysmenu/boot/ARM7/Makefile b/build/libraries_sysmenu/boot/ARM7/Makefile new file mode 100644 index 00000000..628d3b30 --- /dev/null +++ b/build/libraries_sysmenu/boot/ARM7/Makefile @@ -0,0 +1,54 @@ +#! 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-09-27#$ +# $Rev: 1203 $ +# $Author: yada $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED +TWL_PROC = ARM7 + +#---------------------------------------------------------------------------- + +SRCDIR = ./src + +INCDIR = ../common/include \ + $(ROOT)/build/libraries/fatfs/ARM7.TWL/include \ + $(ROOT)/build/libraries/fatfs/ARM7.TWL/include/twl/fatfs/ARM7 \ + +SRCS = bootAPI.c + +TARGET_LIB = libboot_sp$(TWL_LIBSUFFIX).a + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs +include $(TWLSDK_ROOT)/build/libraries/reboot/commondefs.reboot + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(SYSMENU_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== + diff --git a/build/libraries_sysmenu/boot/ARM7/src/bootAPI.c b/build/libraries_sysmenu/boot/ARM7/src/bootAPI.c new file mode 100644 index 00000000..bdc028a6 --- /dev/null +++ b/build/libraries_sysmenu/boot/ARM7/src/bootAPI.c @@ -0,0 +1,309 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: boot.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include "reboot.h" + + +// define data------------------------------------------------------- +#define MAINP_SEND_IF 0x2000 +#define reg_MI_MC_SWP (*(REGType8v *) ( REG_MC1_ADDR + 1 ) ) + +#ifdef ISDBG_MB_CHILD_ +#define PRE_CLEAR_NUM_MAX (6*2) +#else +#define PRE_CLEAR_NUM_MAX (4*2) +#endif + +#define COPY_NUM_MAX (4*3) +#define POST_CLEAR_NUM_MAX (12 + 4*2) + +#define SYSMi_ARM9_BOOT_CODE_BUF 0x023fee00 + +// extern data------------------------------------------------------- + +// function's prototype---------------------------------------------- + +static void BOOTi_ClearREG_RAM( void ); +static void BOOTi_CutAwayRegionList( u32 *regionlist, u32 start, u32 end ); + +// global variables-------------------------------------------------- + +// static variables-------------------------------------------------- + +static u32 twl_post_clear_list[POST_CLEAR_NUM_MAX + 1] = +{ + HW_PARAM_RESERVED_END, SYSM_OWN_ARM7_MMEM_ADDR, + SYSM_OWN_ARM7_MMEM_ADDR_END, SYSMi_ARM9_BOOT_CODE_BUF, + SYSMi_ARM9_BOOT_CODE_BUF + OS_BOOT_CODE_SIZE, SYSM_OWN_ARM9_MMEM_ADDR, + SYSM_OWN_ARM9_MMEM_ADDR_END, HW_TWL_MAIN_MEM_SHARED, + NULL, +}; + +static u32 nitro_post_clear_list[POST_CLEAR_NUM_MAX + 1] = +{ + HW_PARAM_DELIVER_ARG, HW_PARAM_DELIVER_ARG_END, + HW_PARAM_RESERVED_END, SYSM_OWN_ARM7_MMEM_ADDR, + SYSM_OWN_ARM7_MMEM_ADDR_END, SYSMi_ARM9_BOOT_CODE_BUF, + SYSM_TWL_ARM9_LTD_LOAD_MMEM, SYSM_DBG_NTR_SYSTEM_BUF, + SYSM_OWN_ARM9_MMEM_ADDR_END, HW_TWL_MAIN_MEM_SHARED, + NULL, +}; + +// const data-------------------------------------------------------- + +void BOOT_Init( void ) +{ + reg_PXI_MAINPINTF = 0x0000; +} + +BOOL BOOT_WaitStart( void ) +{ + if( (reg_PXI_MAINPINTF & 0x000f ) == 0x000f ) { + + (void)OS_DisableIrq(); // Ŋ荞݋֎~ɂȂƃ_B + (void)OS_SetIrqMask(0); // SDKo[W̃T[`ɎԂƁAARM9HALTɂĂ܂AARM7̃TEhXbhARM9FIFOŃf[^M悤ƂĂFIFOtőMłȂԂŖ[vɓĂ܂B + (void)OS_SetIrqMaskEx(0); +/* +#ifdef ISDBG_MB_CHILD_ + if( ( GetIpl2WorkAddr()->ipl2_type != 0xff ) && ( GetIpl2WorkAddr()->ipl2_type & 0x28 ) ) +#endif // ISDBG_MB_CHILD_ // USG or NATȂ疳pb`𓖂Ă + { + InsertWLPatch(); + } +*/ + + BOOTi_ClearREG_RAM(); // ARM7̃WX^NAB + reg_MI_MBK9 = 0; // SWRAM̃bN + reg_PXI_MAINPINTF = MAINP_SEND_IF | 0x0100; // ARM9ɑ΂ău[g悤IRQŗv{ARM7̃Xe[gPɂB + + // SDKʃu[g + { + REBOOTTarget target = REBOOT_TARGET_TWL_SYSTEM; + BOOL ds = FALSE; + ROM_Header *th = (ROM_Header *)HW_TWL_ROM_HEADER_BUF; // TWLgROMwb_iDSAvɂ͖j + ROM_Header *dh = (ROM_Header *)HW_ROM_HEADER_BUF; // DS݊ROMwb_ + int list_count = PRE_CLEAR_NUM_MAX + 1; + int l; + u32 *post_clear_list; + // Xg̐ݒ + static u32 mem_list[PRE_CLEAR_NUM_MAX + 1 + COPY_NUM_MAX + 2 + POST_CLEAR_NUM_MAX + 1] = + { + // pre clear + SYSM_OWN_ARM7_WRAM_ADDR, NULL, // SYSM_OWN_ARM7_WRAM_ADDRiSDK_AUTOLOAD_WRAM_STARTj̓J^ + SYSM_OWN_ARM7_MMEM_ADDR, SYSM_OWN_ARM7_MMEM_ADDR_END - SYSM_OWN_ARM7_MMEM_ADDR, + SYSM_OWN_ARM9_MMEM_ADDR, SYSM_OWN_ARM9_MMEM_ADDR_END - SYSM_OWN_ARM9_MMEM_ADDR, +#ifdef ISDBG_MB_CHILD_ + HW_PRV_WRAM_END - 0x600, (HW_PRV_WRAM_END - HW_PRV_WRAM_SYSRV_SIZE) - (HW_PRV_WRAM_END - 0x600), + HW_PRV_WRAM_END - 0x600 + 0x20, HW_PRV_WRAM_END - (HW_PRV_WRAM_END - 0x600 + 0x20), +#endif + HW_MAIN_MEM_SHARED, HW_RED_RESERVED - HW_MAIN_MEM_SHARED, + NULL, + // copy forward + NULL, + // copy backward + NULL, + // post clear + NULL, + }; + mem_list[1] = SYSM_OWN_ARM7_WRAM_ADDR_END - SYSM_OWN_ARM7_WRAM_ADDR; + + // copy forwardXgݒ + for( l=0; lromRelocateInfo[l].src != NULL && !SYSMi_GetWork()->romRelocateInfo[l].rev ) + { + mem_list[list_count++] = SYSMi_GetWork()->romRelocateInfo[l].src; + mem_list[list_count++] = SYSMi_GetWork()->romRelocateInfo[l].dest; + mem_list[list_count++] = SYSMi_GetWork()->romRelocateInfo[l].length; + } + } + mem_list[list_count++] = NULL; + + // copy backwardXgݒ + for( l=0; lromRelocateInfo[l].src != NULL && SYSMi_GetWork()->romRelocateInfo[l].rev ) + { + mem_list[list_count++] = SYSMi_GetWork()->romRelocateInfo[l].src; + mem_list[list_count++] = SYSMi_GetWork()->romRelocateInfo[l].dest; + mem_list[list_count++] = SYSMi_GetWork()->romRelocateInfo[l].length; + } + } + mem_list[list_count++] = NULL; + + // post clearXgݒ + if ( dh->s.platform_code ) + { + post_clear_list = twl_post_clear_list; + BOOTi_CutAwayRegionList( post_clear_list, (u32)th->s.main_ltd_ram_address, (u32)th->s.main_ltd_ram_address + th->s.main_ltd_size); + BOOTi_CutAwayRegionList( post_clear_list, (u32)th->s.sub_ltd_ram_address, (u32)th->s.sub_ltd_ram_address + th->s.sub_ltd_size); + }else + { + post_clear_list = nitro_post_clear_list; + } + BOOTi_CutAwayRegionList( post_clear_list, (u32)dh->s.main_ram_address, (u32)dh->s.main_ram_address + dh->s.main_size); + BOOTi_CutAwayRegionList( post_clear_list, (u32)dh->s.sub_ram_address, (u32)dh->s.sub_ram_address + dh->s.sub_size); + for( l=0; post_clear_list[l]!=NULL ; l+=2 ) + { + mem_list[list_count++] = post_clear_list[l]; + mem_list[list_count++] = post_clear_list[l+1] - post_clear_list[l]; + } + mem_list[list_count] = NULL; + + // TEh~ + SND_Disable(); + + // AvP[VI + if ( dh->s.platform_code ) + { +// target = REBOOT_TARGET_TWL_APP; +#ifdef SYSMENU_DISABLE_TWL_BOOT + while (1) + { + } +#endif // SYSMENU_DISABLE_TWL_BOOT + } + else + { + target = REBOOT_TARGET_DS_APP; + } + + if ( target == REBOOT_TARGET_DS_APP || target == REBOOT_TARGET_DS_WIFI ) + { + ds = TRUE; + } + + if ( ds || th->s.codec_mode == OS_CODECMODE_NITRO ) + { + // I2S~iMCLK͓pj + reg_SND_SMX_CNT &= ~REG_SND_SMX_CNT_E_MASK; + CDC_GoDsMode(); + // DSTEhFDSP = 8:0 + // 32KHz + reg_SND_SMX_CNT = REG_SND_SMX_CNT_MIX_RATE_MASK | + REG_SND_SMX_CNT_E_MASK; + } + +#if defined(FIRM_USE_TWLSDK_KEYS) || defined(SYSMENU_DISABLE_RETAIL_BOOT) + // TwlSDǨgĂ鎞͐ipCPUłTWLAv̓u[gȂ + if ( ! (*(u8*)HWi_WSYS08_ADDR & HWi_WSYS08_OP_OPT_MASK) && !ds ) + { + OS_Terminate(); + } +#endif // FIRM_USE_SDK_KEYS || SYSMENU_DISABLE_RETAIL_BOOT + + // u[g + OS_Boot( dh->s.sub_entry_address, mem_list, target ); + } + } + return FALSE; +} + +static void BOOTi_ClearREG_RAM( void ) +{ + if( SYSMi_GetWork()->flags.common.isCardBoot ) { +#ifdef DEBUG_USED_CARD_SLOT_B_ + reg_MI_MC_SWP = 0x80; // J[hXbg̃Xbv +#endif + *(u32 *)HW_BOOT_CHECK_INFO_BUF = SYSMi_GetWork()->nCardID; // J[h`FbNobt@ɃJ[hIDZbg + } + + *(vu32 *)HW_RESET_PARAMETER_BUF = 0; // Zbgobt@NA + + // WX^NA͊{I OS_Boot ōs + + // NAĂȂWX^́AVCOUNT, JOY, PIFCNT, MC-, EXMEMCNT, IME, PAUSE, POWLCDCNT, ZLeBnłB + (void)OS_ResetRequestIrqMask((u32)~0); + (void)OS_ResetRequestIrqMaskEx((u32)~0); +} + +// PXgvf폜 +static void BOOTi_DeliteElementFromList( u32 *list, u32 index ) +{ + int l; + for( l=(int)index; list[l]!=NULL; l++ ) + { + list[l] = list[l+1]; + } +} + +// PXgvflj +static void BOOTi_InsertElementToList( u32 *list, u32 index, u32 value ) +{ + int l = (int)index; + while(list[l]!=NULL) + { + l++; + } + list[l+1] = NULL; + for( ; index= start ) + { + break; + } + } + for( m=l; regionlist[m]!=NULL; m++ ) + { + if( regionlist[m] > end ) + { + break; + } + } + // ̎_regionlist[l]regionlist[m]́Astart <= regionlist[l], end < regionlist[m]ŁAłȒl + + if( m % 2 == 1 ) + { + BOOTi_InsertElementToList( regionlist, (u32)m, end ); + // endXgɒljꍇAm͒ljvfw悤 + } + if( l % 2 == 1 ) + { + BOOTi_InsertElementToList( regionlist, (u32)l, start ); + m++; + // startXgɒljꍇAm1 + l++; + // startXgɒljꍇAl͒ljvf̗̎vfw悤 + } + + // regionlist[l]regionlist[m-1]܂ł̗vf + for( n=l; l +#include +#include +#include +#include +#include "reboot.h" + + +// define data------------------------------------------------------- +#define SUBP_RECV_IF_ENABLE 0x4000 + +#define C1_DTCM_ENABLE 0x00010000 // f[^sbl Cl[u +#define C1_EXCEPT_VEC_UPPER 0x00002000 // OxN^ ʃAhXiɐݒ肵ĉj +#define C1_SB1_BITSET 0x00000078 // WX^PpPŒrbgiA{[gfADATA32\VOiAPROG32\VOiACgobt@Cl[uj + +// extern data------------------------------------------------------- + +// function's prototype---------------------------------------------- +static void BOOTi_ClearREG_RAM( void ); +static void BOOTi_StartBOOT( void ); + +// global variables-------------------------------------------------- + +// static variables-------------------------------------------------- + +// const data-------------------------------------------------------- +void BOOT_Init( void ) +{ + reg_PXI_SUBPINTF = 0x0000; +} + +static void ie_subphandler( void ) +{ + OS_TPrintf( "INTR SUBP!!\n" ); + OS_SetIrqCheckFlag( OS_IE_SUBP ); +} + +// u[gāAARM7̒ʒm҂B +void BOOT_Ready( void ) +{ + int i; + + // GgAhX̐`FbNAȏꍇ͖[vɓB +// SYSMi_CheckEntryAddress(); + +// FinalizeCardPulledOut(); // J[hoI + BOOTi_ClearREG_RAM(); // WX^RAMNA + (void)GX_VBlankIntr( FALSE ); + + for( i = 0; i <= MI_DMA_MAX_NUM; i++ ) { // 荞݋֎~ԂDMA~ + MI_StopDma( (u16)i ); + MI_StopNDma( (u16)i ); + } + + (void)OS_SetIrqFunction( OS_IE_SUBP, ie_subphandler ); + OS_EnableInterrupts(); + (void)OS_SetIrqMask( OS_IE_SUBP ); // TuvZbT荞݂݂̂B + reg_PXI_SUBPINTF = SUBP_RECV_IF_ENABLE | 0x0f00; // ARM9Xe[g "0x0f" + // FIFO̓NAς݂Ȃ̂ŁAgȂB + // ARM7̒ʒm҂ + OS_WaitIrq( 1, OS_IE_SUBP ); + + OS_TPrintf( "INTR SUBP passed!!\n" ); + // 荞݂NAčŏIu[gV[PXցB + reg_PXI_SUBPINTF &= 0x0f00; // TuvZbT荞݋ƒtONA + (void)OS_DisableIrq(); + (void)OS_SetIrqMask( 0 ); + (void)OS_ResetRequestIrqMask( (u32)~0 ); + + // WRAM̔zu + { + ROM_Header_Short *pROMH = (ROM_Header_Short *)HW_TWL_ROM_HEADER_BUF; + MIHeader_WramRegs *pWRAMREGS = (MIHeader_WramRegs *)pROMH->main_wram_config_data; + reg_GX_VRAMCNT_C = pWRAMREGS->main_vrambnk_c; + reg_GX_VRAMCNT_D = pWRAMREGS->main_vrambnk_d; + reg_GX_VRAMCNT_WRAM = pWRAMREGS->main_wrambnk_01; + } + + // ROMwb_obt@Rs[ + MI_CpuCopy32( (void *)HW_TWL_ROM_HEADER_BUF, (void *)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END - HW_ROM_HEADER_BUF ); + + // SDKʃu[g + { + // Xg̐ݒ + static u32 mem_list[] = + { + // pre clear + HW_ITCM, HW_ITCM_SIZE, + //HW_DTCM, HW_DTCM_SIZE, + NULL, + // copy forward + NULL, + // copy backward + NULL, + // post clear + NULL, + }; + + // [TODO]ĔzuXg̍쐬ƐݒiقARM7ł̂ł͋j + static u32 relocate_list[] = + { + NULL + }; + + REBOOTTarget target = REBOOT_TARGET_TWL_SYSTEM; + BOOL ds = FALSE; + ROM_Header *dh = (ROM_Header *)HW_ROM_HEADER_BUF; // DS݊ROMwb_ + + // AvP[VI + if ( dh->s.platform_code ) + { +// target = REBOOT_TARGET_TWL_APP; +#ifdef SYSMENU_DISABLE_TWL_BOOT + OS_Terminate(); +#endif // SYSMENU_DISABLE_TWL_BOOT + } + else + { + target = REBOOT_TARGET_DS_APP; + } + + if ( target == REBOOT_TARGET_DS_APP || target == REBOOT_TARGET_DS_WIFI ) + { + ds = TRUE; + } + +#if defined(FIRM_USE_TWLSDK_KEYS) || defined(SYSMENU_DISABLE_RETAIL_BOOT) + // TwlSDǨgĂ鎞͐ipCPUłTWLAv̓u[gȂ + if ( ! (*(u8*)OS_CHIPTYPE_DEBUGGER_ADDR & OS_CHIPTYPE_DEBUGGER_MASK) && !ds ) + { + OS_Terminate(); + } +#endif // FIRM_USE_SDK_KEYS || SYSMENU_DISABLE_RETAIL_BOOT + + // N^[Qbg̎ނw肷Kv + OS_Boot( dh->s.main_entry_address, mem_list, target ); + } +} + + +// gpWX^̃NA +static void BOOTi_ClearREG_RAM( void ) +{ + // ŌオTuvZbT荞ݑ҂Ȃ̂ŁAIME̓NAȂB + (void)OS_SetIrqMask( 0 ); + (void)OS_ResetRequestIrqMask( (u32)~0 ); + + // WX^NA͊{I OS_Boot ōs +} + diff --git a/build/libraries_sysmenu/boot/Makefile b/build/libraries_sysmenu/boot/Makefile new file mode 100644 index 00000000..1e0ca3f0 --- /dev/null +++ b/build/libraries_sysmenu/boot/Makefile @@ -0,0 +1,30 @@ +#! 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-09-27#$ +# $Rev: 1203 $ +# $Author: yada $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +SUBDIRS = ARM7 ARM9 + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries_sysmenu/hotsw/ARM7/Makefile b/build/libraries_sysmenu/hotsw/ARM7/Makefile new file mode 100644 index 00000000..cd874b52 --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/Makefile @@ -0,0 +1,50 @@ +#! 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:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED +TWL_PROC = ARM7 + +#---------------------------------------------------------------------------- + +SRCDIR = ./src +INCDIR = ./include + +SRCS = blowfish.c hotsw.c ds_blowfish_table.c dsCardType1.c dsCardType2.c romEmulation.c customNDma.c + +TARGET_LIB = libhotsw_sp$(TWL_LIBSUFFIX).a + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(SYSMENU_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== + diff --git a/build/libraries_sysmenu/hotsw/ARM7/include/blowfish.h b/build/libraries_sysmenu/hotsw/ARM7/include/blowfish.h new file mode 100644 index 00000000..c1ed8701 --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/include/blowfish.h @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - GCD - include + File: blowfish.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. + *---------------------------------------------------------------------------*/ +#ifndef FIRM_GCD_BLOWFISH_H +#define FIRM_GCD_BLOWFISH_H + + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*************************************************************************/ + +// e[u +extern const BLOWFISH_CTX GCDi_BlowfishInitTableDS; + +// Function Prototype ------------------------------------------------------------------------ +// Blowfish +void InitBlowfish(BLOWFISH_CTX *ctx, const unsigned char *key, int keyLen); + +// Blowfish KeyTablȅ +void InitBlowfishKeyAndTableDS(BLOWFISH_CTX *ctx, u32 *keyBufp, s32 keyLen); + +// Blowfish +void EncryptByBlowfish(const BLOWFISH_CTX *ctx, u32 *xl, u32 *xr); + +// Blowfish Í +void DecryptByBlowfish(const BLOWFISH_CTX *ctx, u32 *xl, u32 *xr); + +// Key Table ̐ +void GCDm_MakeBlowfishTableDS(BLOWFISH_CTX *tableBufp, ROM_Header_Short *rhs, u32 *keyBufp, s32 keyLen); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // FIRM_GCD_BLOWFISH_H diff --git a/build/libraries_sysmenu/hotsw/ARM7/include/customNDma.h b/build/libraries_sysmenu/hotsw/ARM7/include/customNDma.h new file mode 100644 index 00000000..e2fdefaa --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/include/customNDma.h @@ -0,0 +1,20 @@ +#ifndef __CUSTOM_NDMA_H__ +#define __CUSTOM_NDMA_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// =========================================================================== +// Function Describe +// =========================================================================== +// J[h +void HOTSW_NDmaCopy_Card(u32 ndmaNo, const void *src, void *dest, u32 size); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // __CUSTOM_NDMA_H__ \ No newline at end of file diff --git a/build/libraries_sysmenu/hotsw/ARM7/include/dsCardType1.h b/build/libraries_sysmenu/hotsw/ARM7/include/dsCardType1.h new file mode 100644 index 00000000..b3bab430 --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/include/dsCardType1.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK + File: + *---------------------------------------------------------------------------*/ +#ifndef __DSCARD_TYPE1_H__ +#define __DSCARD_TYPE1_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// =========================================================================== +// Function Describe +// =========================================================================== + +// m[}[h̃R}h +// DSJ[hType1̃m[}[hBoot Segment(4Kbyte)ǂݍ +void ReadBootSegNormal_DSType1(CardBootData *cbd); + +// DSJ[hType1̃m[}[h̃[hύX +void ChangeModeNormal_DSType1(CardBootData *cbd); + + +// ZLA[h̃R}h +// DSJ[hType1̃ZLA[hIDǂݍ +void ReadIDSecure_DSType1(CardBootData *cbd); + +// DSJ[hType1̃ZLA[hSecure Segment(16Kbyte)ǂݍ +void ReadSegSecure_DSType1(CardBootData *cbd); + +// DSJ[hType1̃ZLA[hPNWFl[^ON +void SwitchONPNGSecure_DSType1(CardBootData *cbd); + +// DSJ[hType1̃ZLA[hPNWFl[^OFF +void SwitchOFFPNGSecure_DSType1(CardBootData *cbd); + +// DSJ[hType1̃ZLA[h̃[hύX +void ChangeModeSecure_DSType1(CardBootData *cbd); + + +// Q[[h̃R}h +// DSJ[hType1̃Q[[hIDǂݍ +void ReadIDGame_DSType1(CardBootData *cbd); + +// DSJ[hType1̃Q[[h̎wy[Wǂݍ +void ReadPageGame_DSType1(CardBootData *cbd, u32 start_addr, void* buf, u32 size); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // __DSCARD_TYPE1_H__ diff --git a/build/libraries_sysmenu/hotsw/ARM7/include/dsCardType2.h b/build/libraries_sysmenu/hotsw/ARM7/include/dsCardType2.h new file mode 100644 index 00000000..89e6bed7 --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/include/dsCardType2.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK + File: + *---------------------------------------------------------------------------*/ +#ifndef __DSCARD_TYPE2_H__ +#define __DSCARD_TYPE2_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// =========================================================================== +// Function Describe +// =========================================================================== +// m[}[h̃R}h +// DSJ[hType2̃m[}[hBoot Segment(4Kbyte)ǂݍ +void ReadBootSegNormal_DSType2(CardBootData *cbd); + +// DSJ[hType2̃m[}[h̃[hύX (Type1Ɠ) +#define ChangeModeNormal_DSType2 ChangeModeNormal_DSType1 + + +// ZLA[h̃R}h +// DSJ[hType2̃ZLA[hIDǂݍ +void ReadIDSecure_DSType2(CardBootData *cbd); + +// DSJ[hType2̃ZLA[hSecure Segment(16Kbyte)ǂݍ +void ReadSegSecure_DSType2(CardBootData *cbd); + +// DSJ[hType2̃ZLA[hPNWFl[^ON +void SwitchONPNGSecure_DSType2(CardBootData *cbd); + +// DSJ[hType2̃ZLA[hPNWFl[^OFF +void SwitchOFFPNGSecure_DSType2(CardBootData *cbd); + +// DSJ[hType2̃ZLA[h̃[hύX +void ChangeModeSecure_DSType2(CardBootData *cbd); + + +// Q[[h̃R}h +// DSJ[hType2̃Q[[hIDǂݍ (Type1Ɠ) +#define ReadIDGame_DSType2 ReadIDGame_DSType1 + +// DSJ[hType2̃Q[[h̎wy[Wǂݍ +void ReadPageGame_DSType2(CardBootData *cbd, u32 start_addr, void* buf, u32 size); +//#define ReadPageGame_DSType2 ReadPageGame_DSType1 + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // __DSCARD_TYPE2_H__ diff --git a/build/libraries_sysmenu/hotsw/ARM7/include/hotswTypes.h b/build/libraries_sysmenu/hotsw/ARM7/include/hotswTypes.h new file mode 100644 index 00000000..8acf3306 --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/include/hotswTypes.h @@ -0,0 +1,272 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - GCD - include + File: type.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. + *---------------------------------------------------------------------------*/ +#ifndef __HOTSW_TYPES_H__ +#define __HOTSW_TYPES_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +// Define ------------------------------------------------------------------- +//#define HOTSW_NO_MESSAGE // Printf}XCb` + +#ifdef HOTSW_NO_MESSAGE +#ifndef SDK_FINALROM +#define OS_TPrintf( ... ) ((void)0) +#define OS_PutString( ... ) ((void)0) +#endif +#endif + + +#define KEY_BUF_SIZE 3 // BlowfishL[̃obt@TCY +#define HOTSW_DMA_NO 2 // +#define BOOT_SEGMENT_SIZE 0x1000 // Boot Segmenẗ̃TCY + +#define PAGE_SIZE 0x200 // 1y[W̃TCY(oCgP) +#define PAGE_WORD_SIZE 0x80 // 1y[W̃TCY([hP) + +#define ONE_SEGMENT_SIZE 0x1000 // 1Segment̃TCY(oCgP) +#define ONE_SEGMENT_WORD_SIZE 0x400 // 1Segment̃TCY([hP) + +#define SECURE_SEGMENT_SIZE 0x4000 // Securë̃TCY + +#define ROM_EMULATION_DATA_SIZE 0x20 // ROMG~[Vf[^TCY + +#define PNA_BASE_VALUE 0x60e8 // +#define PNB_L_VALUE 0x879b9b05 // +#define PNB_H_VALUE 0x5c // + +// Rg[WX^P bit֘A +#define START_FLG_MASK 0x80000000 +#define READY_FLG_MASK 0x00800000 + +#define LATENCY1_SHIFT 0 +#define LATENCY1_MASK 0x00001fff + +#define DS_SHIFT 13 +#define DS_MASK 0x00002000 + +#define SE_SHIFT 14 +#define SE_MASK 0x00004000 + +#define SCR_SHIFT 15 +#define SCR_MASK 0x00008000 + +#define LATENCY2_SHIFT 16 +#define LATENCY2_MASK 0x003f0000 + +#define CS_SHIFT 22 +#define CS_MASK 0x00400000 + +#define RDY_SHIFT 23 +#define RDY_MASK 0x00800000 + +#define PC_SHIFT 24 +#define PC_MASK 0x07000000 + +#define CT_SHIFT 27 +#define CT_MASK 0x08000000 + +#define TRM_SHIFT 28 +#define TRM_MASK 0x10000000 + +#define RESB_SHIFT 29 +#define RESB_MASK 0x20000000 + +#define WR_SHIFT 30 +#define WR_MASK 0x40000000 + +#define START_SHIFT 31 +#define START_MASK 0x80000000 + +#define SCRAMBLE_MASK 0x406000 // CS SE DS̃}XN + +#define AddLatency2ToLatency1(param)\ + ( (((param) & LATENCY2_MASK) \ + >> LATENCY2_SHIFT) \ + + ((param) & LATENCY1_MASK) \ + ) + +//#define USE_SLOT_A + +#ifdef USE_SLOT_A +// Slot A +#define SLOT_STATUS_MODE_SELECT_MSK 0x0c +#define SLOT_STATUS_CDET_MSK 0x01 +#define SLOT_STATUS_MODE_00 0x00 +#define SLOT_STATUS_MODE_01 0x04 +#define SLOT_STATUS_MODE_10 0x08 +#define SLOT_STATUS_MODE_11 0x0c + +#define reg_HOTSW_MCCMD0 reg_MI_MCCMD0_A +#define reg_HOTSW_MCCMD1 reg_MI_MCCMD1_A + +#define reg_HOTSW_MCCNT0 reg_MI_MCCNT0_A +#define reg_HOTSW_MCCNT1 reg_MI_MCCNT1_A + +#define HOTSW_MCD1 REG_MCD1_A_ADDR +#define reg_HOTSW_MCD1 reg_MI_MCD1_A + +#define reg_HOTSW_MCSCR0 reg_MI_MCSCR0_A +#define reg_HOTSW_MCSCR1 reg_MI_MCSCR1_A +#define reg_HOTSW_MCSCR2 reg_MI_MCSCR2_A + +#define HOTSW_IF_CARD_DET OS_IE_CARD_A_DET + +#else +// Slot B +#define SLOT_STATUS_MODE_SELECT_MSK 0xc0 +#define SLOT_STATUS_CDET_MSK 0x10 +#define SLOT_STATUS_MODE_00 0x00 +#define SLOT_STATUS_MODE_01 0x40 +#define SLOT_STATUS_MODE_10 0x80 +#define SLOT_STATUS_MODE_11 0xc0 + +#define reg_HOTSW_MCCMD0 reg_MI_MCCMD0_B +#define reg_HOTSW_MCCMD1 reg_MI_MCCMD1_B + +#define reg_HOTSW_MCCNT0 reg_MI_MCCNT0_B +#define reg_HOTSW_MCCNT1 reg_MI_MCCNT1_B + +#define HOTSW_MCD1 REG_MCD1_B_ADDR +#define reg_HOTSW_MCD1 reg_MI_MCD1_B + +#define reg_HOTSW_MCSCR0 reg_MI_MCSCR0_B +#define reg_HOTSW_MCSCR1 reg_MI_MCSCR1_B +#define reg_HOTSW_MCSCR2 reg_MI_MCSCR2_B + +#define HOTSW_IF_CARD_DET OS_IE_CARD_B_DET + +#endif + +// Enum --------------------------------------------------------------------- +typedef enum CardTypeEx{ + DS_CARD_TYPE_1 = 0, + DS_CARD_TYPE_2, + TWL_CARD, + ROM_EMULATION +}CardTypeEx; + +typedef enum NormalCommandType{ + RD_ID = 0, + RD_BSEG, + CHG_MODE +}NormalCommandType; + +typedef enum SecureCommandType{ + S_RD_ID = 0, + S_RD_SEG, + S_PNG_ON, + S_PNG_OFF, + S_CHG_MODE +}SecureCommandType; + +typedef enum GameCommandType{ + G_RD_ID = 0, + G_RD_PAGE +}GameCommandType; + +typedef enum CardType{ + CARD_DS_TYPE1 = 0, + CARD_DS_TYPE2, + CARD_TWL +}CardType; + +// union --------------------------------------------------------------------- +typedef union +{ + u64 dw; + u8 b[8]; +} +GCDCmd64; + +// u[gZOgf[^ +typedef union BootSegmentData +{ + ROM_Header rh; + u32 word[BOOT_SEGMENT_SIZE / sizeof(u32)]; +} +BootSegmentData; + +// struct ------------------------------------------------------------------- +typedef struct BLOWFISH_CTX{ + u32 P[16 + 2]; + u32 S[4][256]; +} BLOWFISH_CTX; + +// J[hu[gɕKvȕϐꎮ܂Ƃ߂\ +typedef struct CardBootData{ + u16 lockID; + + u32 vae; + u32 vbi; + u32 vd; + + u32 id_nml; + u32 id_scr; + u32 id_gam; + + u32 arm9StcSize; + u32 arm7StcSize; + u32 arm9LtdSize; + u32 arm7LtdSize; + + u32 arm9Stc; + u32 arm7Stc; + u32 arm9Ltd; + u32 arm7Ltd; + + u32 secureLatency; + + BOOL twlFlg; + BOOL debuggerFlg; + + u32 romEmuBuf[ROM_EMULATION_DATA_SIZE/sizeof(u32)]; + u32 keyBuf[KEY_BUF_SIZE]; + + CardTypeEx cardType; + + BootSegmentData *pBootSegBuf; + u32 *pSecureSegBuf; + + BLOWFISH_CTX keyTable; +} +CardBootData; + +// J[hNp֐ +typedef struct CardBootFunction { + void (*ReadBootSegment_N)(CardBootData *cbd); + void (*ChangeMode_N)(CardBootData *cbd); + + void (*ReadID_S)(CardBootData *cbd); + void (*ReadSegment_S)(CardBootData *cbd); + void (*SetPNG_S)(CardBootData *cbd); + void (*ChangeMode_S)(CardBootData *cbd); + + void (*ReadID_G)(CardBootData *cbd); + void (*ReadPage_G)(CardBootData *cbd, u32 addr, void* buf, u32 size); +} +CardBootFunction; + + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // __HOTSW_TYPES_H__ \ No newline at end of file diff --git a/build/libraries_sysmenu/hotsw/ARM7/include/romEmulation.h b/build/libraries_sysmenu/hotsw/ARM7/include/romEmulation.h new file mode 100644 index 00000000..f534ccae --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/include/romEmulation.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK + File: romEmulation.h + *---------------------------------------------------------------------------*/ +#ifndef __ROM_EMULATION_H__ +#define __ROM_EMULATION_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// =========================================================================== +// Function Describe +// =========================================================================== + +// m[}[h̃R}h +// Rom Emulatioñm[}[hBoot Segment(4Kbyte)ǂݍ +void ReadBootSegNormal_ROMEMU(CardBootData *cbd); + +// Rom Emulatioñm[}[h̃[hύX +void ChangeModeNormal_ROMEMU(CardBootData *cbd); + + +// ZLA[h̃R}h +// Rom EmulatioñZLA[hIDǂݍ +void ReadIDSecure_ROMEMU(CardBootData *cbd); + +// Rom EmulatioñZLA[hSecure Segment(16Kbyte)ǂݍ +void ReadSegSecure_ROMEMU(CardBootData *cbd); + +// Rom EmulatioñZLA[hPNWFl[^ON +void SwitchONPNGSecure_ROMEMU(CardBootData *cbd); + +// Rom EmulatioñZLA[hPNWFl[^OFF +void SwitchOFFPNGSecure_ROMEMU(CardBootData *cbd); + +// Rom EmulatioñZLA[h̃[hύX +void ChangeModeSecure_ROMEMU(CardBootData *cbd); + + +// Q[[h̃R}h +// DSJ[hType1̃Q[[hIDǂݍ +void ReadIDGame_ROMEMU(CardBootData *cbd); + +// DSJ[hType1̃Q[[h̎wy[Wǂݍ +void ReadPageGame_ROMEMU(CardBootData *cbd, u32 start_addr, void* buf, u32 size); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // __ROM_EMULATION_H__ diff --git a/build/libraries_sysmenu/hotsw/ARM7/src/blowfish.c b/build/libraries_sysmenu/hotsw/ARM7/src/blowfish.c new file mode 100644 index 00000000..6f71e741 --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/src/blowfish.c @@ -0,0 +1,206 @@ +/*---------------------------------------------------------------------------* + 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. + *---------------------------------------------------------------------------*/ +#include +#include + +#define MAXKEYBYTES 56 /* 448 bits */ +#define N 16 + +// Function Prototype ------------------------------------------------------- +static u32 F(const BLOWFISH_CTX *ctx, u32 x); +//static void GCDi_InitBlowfishKeyAndTableDS(BLOWFISH_CTX *ctx, u32 *keyBufp, s32 keyLen); + +//***************************************** +// +// GCDm_MakeBlowfishTableDS֐ +// +//***************************************** +void GCDm_MakeBlowfishTableDS(BLOWFISH_CTX *tableBufp, ROM_Header_Short *rhs, u32 *keyBufp, s32 keyLen) +{ + const BLOWFISH_CTX *blowfishInitTablep = &GCDi_BlowfishInitTableDS; + u32 blowfishedKey[2]; + + MI_CpuCopy32((void *)blowfishInitTablep, (void *)tableBufp, sizeof(BLOWFISH_CTX)); + + keyBufp[0] = *(u32 *)rhs->game_code; + keyBufp[1] = *(u32 *)rhs->game_code >> 1; + keyBufp[2] = *(u32 *)rhs->game_code << 1; + + InitBlowfishKeyAndTableDS(tableBufp, keyBufp, keyLen); + + blowfishedKey[0] = (u32)rhs->ctrl_reserved_B[0]; + blowfishedKey[1] = *(u32 *)&rhs->ctrl_reserved_B[4]; + +// OS_TPrintf("Blowfish - key[0]:%d key[1]:%d\n",blowfishedKey[0],blowfishedKey[1]); + + DecryptByBlowfish(tableBufp, &(blowfishedKey)[1], &(blowfishedKey)[0]); + + InitBlowfishKeyAndTableDS(tableBufp, keyBufp, keyLen); +} + +//***************************************** +// +// InitBlowfishKeyAndTableDS֐ +// +//***************************************** +void 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); +} + +//***************************************** +// +// InitBlowfish֐ +// +//***************************************** +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; + } + } + +} + +//***************************************** +// +// EncryptByBlowfish֐ +// +//***************************************** +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; +} + +//***************************************** +// +// DecryptByBlowfish֐ +// +//***************************************** +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; +} + +//***************************************** +// +// F֐ +// +//***************************************** +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_sysmenu/hotsw/ARM7/src/customNDma.c b/build/libraries_sysmenu/hotsw/ARM7/src/customNDma.c new file mode 100644 index 00000000..49bca406 --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/src/customNDma.c @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK + File: + *---------------------------------------------------------------------------*/ +#include +#include + + +// Define data -------------------------------------------------------------- +#define NDMA_BLOCK_WORD_COUNT_1 0x0 +#define NDMA_NO_INTERVAL_NORMAL_SCALE 0x0 +#define NDMA_TOTAL_WORD_COUNT_1 0x1 +#define NDMA_WORD_COUNT_1 0x1 +#define ASSERT_DMANO( ndmaNo ) SDK_ASSERTMSG( (ndmaNo) <= MI_NDMA_MAX_NUM, "illegal NDMA No." ); + + +// =========================================================================== +// Function Describe +// =========================================================================== + +// custom CARD DMA +void HOTSW_NDmaCopy_Card(u32 ndmaNo, const void *src, void *dest, u32 size) +{ + u32 contData; + OSIntrMode enabled = OS_DisableInterrupts(); + + //--- Assert + ASSERT_DMANO( ndmaNo ); + + //---- confirm DMA free + while( MI_IsNDmaBusy(ndmaNo) == TRUE ){} + + //---- set up registers + MI_NDMA_REG( ndmaNo, MI_NDMA_REG_SAD_WOFFSET ) = (u32)src; + MI_NDMA_REG( ndmaNo, MI_NDMA_REG_DAD_WOFFSET ) = (u32)dest; + MI_NDMA_REG( ndmaNo, MI_NDMA_REG_BCNT_WOFFSET ) = NDMA_NO_INTERVAL_NORMAL_SCALE; + MI_NDMA_REG( ndmaNo, MI_NDMA_REG_TCNT_WOFFSET ) = (u32)(size/4); + MI_NDMA_REG( ndmaNo, MI_NDMA_REG_WCNT_WOFFSET ) = NDMA_WORD_COUNT_1; + + //---- decide control register + contData = NDMA_BLOCK_WORD_COUNT_1 | MI_NDMA_ENABLE; + contData |= (MI_NDMA_SRC_FIX | MI_NDMA_DEST_INC | MI_NDMA_DEST_RELOAD_DISABLE); + contData |= MI_NDMA_TIMING_CARD_B; + + //---- set interrupt enable + contData |= MI_NDMA_IF_ENABLE; + + //---- start + MI_NDMA_REG( ndmaNo, MI_NDMA_REG_CNT_WOFFSET ) = contData; + + (void)OS_RestoreInterrupts( enabled ); +} diff --git a/build/libraries_sysmenu/hotsw/ARM7/src/dsCardType1.c b/build/libraries_sysmenu/hotsw/ARM7/src/dsCardType1.c new file mode 100644 index 00000000..7809a50c --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/src/dsCardType1.c @@ -0,0 +1,382 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK + File: dsCardType1.c + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include + +// Function prototype ------------------------------------------------------- +static void SetSecureCommand(SecureCommandType type, CardBootData *cbd); +static void SetMCSCR(void); + + +// =========================================================================== +// Function Describe +// =========================================================================== + +// -------------------------------------- +// m[}[h̃R}h +// -------------------------------------- +/*---------------------------------------------------------------------------* + Name: ReadIDNormal_DSType1 + + Description: DSJ[hType1̃m[}[hIDǂݍ + *---------------------------------------------------------------------------*/ +// + +/*---------------------------------------------------------------------------* + * Name: ReadBootSegNormal_DSType1 + * + * Description: DSJ[hType1̃m[}[hBoot Segmentǂݍ + * + * CT=240ns Latency1=0x1fff Latency2=0x3f Pagecount=8page + *---------------------------------------------------------------------------*/ +void ReadBootSegNormal_DSType1(CardBootData *cbd) +{ + // NewDMA]̏ + HOTSW_NDmaCopy_Card( HOTSW_DMA_NO, (u32 *)HOTSW_MCD1, &cbd->pBootSegBuf->word, BOOT_SEGMENT_SIZE ); + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x00000000; + reg_HOTSW_MCCMD1 = 0x00000000; + + // MCCNT0 WX^ݒ (E = 1 I = 1 SEL = 0) + reg_HOTSW_MCCNT0 = (u16)((reg_HOTSW_MCCNT0 & 0x0fff) | 0xc000); + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = START_MASK | CT_MASK | PC_MASK & (0x4 << PC_SHIFT) | LATENCY2_MASK | LATENCY1_MASK; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); +} + +/*---------------------------------------------------------------------------* + * Name: ChangeModeNormal_DSType1 + * + * Description: DSJ[hType1̃m[}[h̃[hύX + * + * CT=240ns Latency1=0x18 Latency2=0 Pagecount=0page + *---------------------------------------------------------------------------*/ +void ChangeModeNormal_DSType1(CardBootData *cbd) +{ + GCDCmd64 tempCnd, cnd; + u64 vae64 = cbd->vae; + + // [NA + MI_CpuClear8(&tempCnd, sizeof(GCDCmd64)); + + // gGfBAō + tempCnd.dw = cbd->vbi << 8; + tempCnd.dw |= vae64 << 32; + tempCnd.dw |= 0x3c00000000000000; + + // rbNGfBAɂ + cnd.b[0] = tempCnd.b[7]; + cnd.b[1] = tempCnd.b[6]; + cnd.b[2] = tempCnd.b[5]; + cnd.b[3] = tempCnd.b[4]; + cnd.b[4] = tempCnd.b[3]; + cnd.b[5] = tempCnd.b[2]; + cnd.b[6] = tempCnd.b[1]; + cnd.b[7] = tempCnd.b[0]; + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = *(u32 *)cnd.b; + reg_HOTSW_MCCMD1 = *(u32 *)&cnd.b[4]; + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = START_MASK | CT_MASK | LATENCY2_MASK & (0x18 << LATENCY2_SHIFT); + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); +} + + +// -------------------------------------- +// ZLA[h̃R}h +// -------------------------------------- +/*---------------------------------------------------------------------------* + Name: SetSecureCommand + + Description: + *---------------------------------------------------------------------------*/ +static void SetSecureCommand(SecureCommandType type, CardBootData *cbd) +{ + GCDCmd64 cndLE, cndBE; + u64 data; + + // [NA + MI_CpuClear8(&cndLE, sizeof(GCDCmd64)); + data = (type == S_PNG_ON) ? (u64)cbd->vd : (u64)cbd->vae; + + cndLE.dw = cbd->vbi; + cndLE.dw |= data << 20; + + // comannd0 + switch(type){ + case S_RD_ID: + cndLE.dw |= 0x1000000000000000; + break; + + case S_PNG_ON: + cndLE.dw |= 0x4000000000000000; + break; + + case S_PNG_OFF: + cndLE.dw |= 0x6000000000000000; + break; + + case S_CHG_MODE: + cndLE.dw |= 0xa000000000000000; + break; + } + + if(!cbd->debuggerFlg){ + // R}ḧÍ + EncryptByBlowfish( &cbd->keyTable, (u32*)&cndLE.b[4], (u32*)cndLE.b ); + } + + // rbOGfBAɒ(Í) + cndBE.b[7] = cndLE.b[0]; + cndBE.b[6] = cndLE.b[1]; + cndBE.b[5] = cndLE.b[2]; + cndBE.b[4] = cndLE.b[3]; + cndBE.b[3] = cndLE.b[4]; + cndBE.b[2] = cndLE.b[5]; + cndBE.b[1] = cndLE.b[6]; + cndBE.b[0] = cndLE.b[7]; + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = *(u32*)cndBE.b; + reg_HOTSW_MCCMD1 = *(u32*)&cndBE.b[4]; +} + + +/*---------------------------------------------------------------------------* + * Name: ReadIDSecure_DSType1 + * + * Description: + * + * CT=240ns Latency1=0x8f8+0x18 Latency2=0 Pagecount=Status + *---------------------------------------------------------------------------*/ +void ReadIDSecure_DSType1(CardBootData *cbd) +{ + // NewDMA]̏ + HOTSW_NDmaCopy_Card( HOTSW_DMA_NO, (u32 *)HOTSW_MCD1, &cbd->id_scr, sizeof(cbd->id_scr) ); + + // R}h쐬Eݒ + SetSecureCommand(S_RD_ID, cbd); + + // MCCNT1 WX^ݒ + // (START = 1 TRM = 1 PC = 111(Xe[^X[h) Romwb_ɂC) + reg_HOTSW_MCCNT1 = cbd->pBootSegBuf->rh.s.secure_cmd_param + | START_MASK | TRM_MASK | PC_MASK & (0x7 << PC_SHIFT) | SE_MASK | DS_MASK ; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + // R}hJE^CNg + cbd->vbi++; +} + +/*---------------------------------------------------------------------------* + * Name: ReadSegSecure_DSType1 + * + * Description: + *---------------------------------------------------------------------------*/ +void ReadSegSecure_DSType1(CardBootData *cbd) +{ + u32 i,j=0; + u64 segNum = 4; + u64 vae = cbd->vae; + GCDCmd64 cndLE, cndBE; + + for(i=0; i<4; i++){ + // NewDMA]̏ + HOTSW_NDmaCopy_Card( HOTSW_DMA_NO, (u32 *)HOTSW_MCD1, (cbd->pSecureSegBuf + ONE_SEGMENT_WORD_SIZE*i), ONE_SEGMENT_SIZE ); + + MI_CpuClear8(&cndLE, sizeof(GCDCmd64)); + + cndLE.dw = cbd->vbi; + cndLE.dw |= vae << 20; + cndLE.dw |= segNum << 44; + cndLE.dw |= 0x2000000000000000; + + // R}ḧÍ + EncryptByBlowfish( &cbd->keyTable, (u32*)&cndLE.b[4], (u32*)cndLE.b ); + + // rbOGfBAɒ(Í) + cndBE.b[7] = cndLE.b[0]; + cndBE.b[6] = cndLE.b[1]; + cndBE.b[5] = cndLE.b[2]; + cndBE.b[4] = cndLE.b[3]; + cndBE.b[3] = cndLE.b[4]; + cndBE.b[2] = cndLE.b[5]; + cndBE.b[1] = cndLE.b[6]; + cndBE.b[0] = cndLE.b[7]; + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = *(u32*)cndBE.b; + reg_HOTSW_MCCMD1 = *(u32*)&cndBE.b[4]; + + // MCCNT1 WX^ݒ + // (START = 1 TRM = 1 PC = 100(8y[W[h) Romwb_ɂC) + reg_HOTSW_MCCNT1 = cbd->pBootSegBuf->rh.s.secure_cmd_param + | START_MASK | TRM_MASK | PC_MASK & (0x4 << PC_SHIFT) | SE_MASK | DS_MASK; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + // ǂݍ݃ZOgԍCNg + segNum++; + + // R}hJE^CNg + cbd->vbi++; + } +} + +/*---------------------------------------------------------------------------* + * Name: SwitchONPNGSecure_DSType1 + * + * Description: + *---------------------------------------------------------------------------*/ +void SwitchONPNGSecure_DSType1(CardBootData *cbd) +{ + // R}h쐬Eݒ + SetSecureCommand(S_PNG_ON, cbd); + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = (cbd->pBootSegBuf->rh.s.secure_cmd_param & CT_MASK) | + START_MASK | TRM_MASK | SE_MASK | DS_MASK | (cbd->secureLatency & LATENCY1_MASK); + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + // R}hJE^CNg + cbd->vbi++; +} + +/*---------------------------------------------------------------------------* + * Name: SwitchOFFPNGSecure_DSType1 + * + * Description: + *---------------------------------------------------------------------------*/ +void SwitchOFFPNGSecure_DSType1(CardBootData *cbd) +{ + // R}h쐬Eݒ + SetSecureCommand(S_PNG_OFF, cbd); + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = (cbd->pBootSegBuf->rh.s.secure_cmd_param & CT_MASK) | + START_MASK | TRM_MASK | SE_MASK | DS_MASK | (cbd->secureLatency & LATENCY1_MASK); + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + // R}hJE^CNg + cbd->vbi++; +} + +/*---------------------------------------------------------------------------* + * Name: ChangeModeSecure_DSType1 + * + * Description: + * + * CT=240ns Latency1=0x8f8+0x18 Latency2=0 Pagecount=0page + *---------------------------------------------------------------------------*/ +void ChangeModeSecure_DSType1(CardBootData *cbd) +{ + // R}h쐬Eݒ + SetSecureCommand(S_CHG_MODE, cbd); + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = (cbd->pBootSegBuf->rh.s.secure_cmd_param & CT_MASK) | + START_MASK | TRM_MASK | SE_MASK | DS_MASK | (cbd->secureLatency & LATENCY1_MASK); + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + // R}hJE^CNg + cbd->vbi++; +} + + +// ------------------------------------ +// Q[[h̃R}h +// ------------------------------------ +/*---------------------------------------------------------------------------* + * Name: ReadIDGame_DSType1 + * + * Description: Q[[hIDǂݍ + *---------------------------------------------------------------------------*/ +void ReadIDGame_DSType1(CardBootData *cbd) +{ + // NewDMA]̏ + HOTSW_NDmaCopy_Card( HOTSW_DMA_NO, (u32 *)HOTSW_MCD1, &cbd->id_gam, sizeof(cbd->id_gam) ); + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x000000B8; + reg_HOTSW_MCCMD1 = 0x00000000; + + // MCCNT1 WX^ݒ (START = 1 W/R = 0 PC = 111(Xe[^X[h) ̑Romwb_̏ɂ܂) + reg_HOTSW_MCCNT1 = cbd->pBootSegBuf->rh.s.game_cmd_param | + START_MASK | (PC_MASK & (0x7 << PC_SHIFT)); + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); +} + +/*---------------------------------------------------------------------------* + Name: ReadPageGame_DSType1 + + Description: Q[[hŁAw肳ꂽy[Wwobt@ɎwTCYǂݍ + *---------------------------------------------------------------------------*/ +void ReadPageGame_DSType1(CardBootData *cbd, u32 start_addr, void* buf, u32 size) +{ + u32 loop, counter=0; + u64 i, page; + GCDCmd64 cndLE, cndBE; + + page = (u32)(start_addr / PAGE_SIZE); + loop = (u32)(size / PAGE_SIZE); + loop = (size % PAGE_SIZE) ? loop + 1 : loop; + +// OS_TPrintf("Src Addr : 0x%08x Dst Addr : 0x%08x\n", start_addr, buf); +// OS_TPrintf("Read Game Segment Page Count : %d size : %x\n", loop, size); + + for(i=0; ipBootSegBuf->rh.s.game_cmd_param | + START_MASK | (PC_MASK & (0x1 << PC_SHIFT)); + + // MCCNTWX^RDYtO|[OāAtOf[^MCD1WX^ɍēxZbgBX^[gtO0ɂȂ܂Ń[vB + while(reg_HOTSW_MCCNT1 & START_FLG_MASK){ + while(!(reg_HOTSW_MCCNT1 & READY_FLG_MASK)){} + *((u32 *)buf + counter++) = reg_HOTSW_MCD1; + } + } +} diff --git a/build/libraries_sysmenu/hotsw/ARM7/src/dsCardType2.c b/build/libraries_sysmenu/hotsw/ARM7/src/dsCardType2.c new file mode 100644 index 00000000..fc708bc2 --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/src/dsCardType2.c @@ -0,0 +1,436 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK + File: dsCardType2.c + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include + +// Define Data -------------------------------------------------------------- +#define SECURE_SEGMENT_NUM 4 +#define ONE_SEGMENT_PAGE_NUM 8 +#define COMMAND_DECRYPTION_WAIT 25 // 25ms + +// Function prototype ------------------------------------------------------- +static void SetSecureCommand(SecureCommandType type, CardBootData *cbd); +static void SetMCSCR(void); + + +// =========================================================================== +// Function Describe +// =========================================================================== + +// -------------------------------------- +// m[}[h̃R}h +// -------------------------------------- +/*---------------------------------------------------------------------------* + Name: ReadIDNormal_DSType2 + + Description: DSJ[hType1̃m[}[hIDǂݍ + *---------------------------------------------------------------------------*/ +// + +/*---------------------------------------------------------------------------* + * Name: ReadBootSegNormal_DSType2 + * + * Description: DSJ[hType2̃m[}[hBoot Segmentǂݍ + * + * CT=240ns Latency1=0x1fff Latency2=0x3f Pagecount=8page + *---------------------------------------------------------------------------*/ +void ReadBootSegNormal_DSType2(CardBootData *cbd) +{ + u32 i = 0; + u32 *dst = cbd->pBootSegBuf->word; + u64 page = 0; + GCDCmd64 cndLE, cndBE; + + for(i=0; ipBootSegBuf->word + (u32)(PAGE_WORD_SIZE*i), PAGE_SIZE ); + + // [NA + MI_CpuClear8(&cndLE, sizeof(GCDCmd64)); + + // gGfBAō + cndLE.dw = 0x0 << 24; + cndLE.dw |= page << 33; + + // rbNGfBAɂ + cndBE.b[0] = cndLE.b[7]; + cndBE.b[1] = cndLE.b[6]; + cndBE.b[2] = cndLE.b[5]; + cndBE.b[3] = cndLE.b[4]; + cndBE.b[4] = cndLE.b[3]; + cndBE.b[5] = cndLE.b[2]; + cndBE.b[6] = cndLE.b[1]; + cndBE.b[7] = cndLE.b[0]; + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = *(u32 *)cndBE.b; + reg_HOTSW_MCCMD1 = *(u32 *)&cndBE.b[4]; + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = START_MASK | CT_MASK | PC_MASK & (0x1 << PC_SHIFT) | LATENCY2_MASK | LATENCY1_MASK; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + page++; + } +} + +/*---------------------------------------------------------------------------* + * Name: ChangeModeNormal_DSType2 + * + * Description: DSJ[hType2̃m[}[h̃[hύX + * + * CT=240ns Latency1=0x18 Latency2=0 Pagecount=0page + *---------------------------------------------------------------------------*/ +// Type1Ɠ + + +// -------------------------------------- +// ZLA[h̃R}h +// -------------------------------------- +/*---------------------------------------------------------------------------* + Name: SetSecureCommand + + Description: + *---------------------------------------------------------------------------*/ +static void SetSecureCommand(SecureCommandType type, CardBootData *cbd) +{ + GCDCmd64 cndLE, cndBE; + u64 data; + + // [NA + MI_CpuClear8(&cndLE, sizeof(GCDCmd64)); + data = (type == S_PNG_ON) ? (u64)cbd->vd : (u64)cbd->vae; + + cndLE.dw = cbd->vbi; + cndLE.dw |= data << 20; + + // comannd0 + switch(type){ + case S_RD_ID: + cndLE.dw |= 0x1000000000000000; + break; + + case S_PNG_ON: + cndLE.dw |= 0x4000000000000000; + break; + + case S_PNG_OFF: + cndLE.dw |= 0x6000000000000000; + break; + + case S_CHG_MODE: + cndLE.dw |= 0xa000000000000000; + break; + } + + if(!cbd->debuggerFlg){ + // R}ḧÍ + EncryptByBlowfish( &cbd->keyTable, (u32*)&cndLE.b[4], (u32*)cndLE.b ); + } + + // rbOGfBAɒ(Í) + cndBE.b[7] = cndLE.b[0]; + cndBE.b[6] = cndLE.b[1]; + cndBE.b[5] = cndLE.b[2]; + cndBE.b[4] = cndLE.b[3]; + cndBE.b[3] = cndLE.b[4]; + cndBE.b[2] = cndLE.b[5]; + cndBE.b[1] = cndLE.b[6]; + cndBE.b[0] = cndLE.b[7]; + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = *(u32*)cndBE.b; + reg_HOTSW_MCCMD1 = *(u32*)&cndBE.b[4]; +} + + +/*---------------------------------------------------------------------------* + * Name: ReadIDSecure_DSType2 + * + * Description: fobKǂݍ񂾏ꍇSCRAMBLE_MASK -> CS SE DS }XN + * + * CT=240ns Latency1=0x8f8+0x18 Latency2=0 Pagecount=Status + *---------------------------------------------------------------------------*/ +void ReadIDSecure_DSType2(CardBootData *cbd) +{ + // XNu̐ݒ + u32 scrambleMask = cbd->debuggerFlg ? 0 : (u32)(SCRAMBLE_MASK & ~CS_MASK); + + // NewDMA]̏ + HOTSW_NDmaCopy_Card( HOTSW_DMA_NO, (u32 *)HOTSW_MCD1, &cbd->id_scr, sizeof(cbd->id_scr) ); + + // R}h쐬Eݒ + SetSecureCommand(S_RD_ID, cbd); + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = START_MASK | scrambleMask | cbd->pBootSegBuf->rh.s.secure_cmd_param; + + // 25ms҂ + OS_Sleep(COMMAND_DECRYPTION_WAIT); + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x0; + reg_HOTSW_MCCMD1 = 0x0; + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = START_MASK | PC_MASK & (0x7 << PC_SHIFT) | scrambleMask | cbd->pBootSegBuf->rh.s.secure_cmd_param; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + // R}hJE^CNg + cbd->vbi++; +} + +/*---------------------------------------------------------------------------* + * Name: ReadSegSecure_DSType2 + * + * Description: Securëǂݍފ֐ + * + * CT=240ns Latency1=0x8f8+0x18 Latency2=0 Pagecount=1page + *---------------------------------------------------------------------------*/ +void ReadSegSecure_DSType2(CardBootData *cbd) +{ + u32 i,j=0,k; + u64 segNum = 4; + u64 vae = cbd->vae; + GCDCmd64 cndLE, cndBE; + + // XNu̐ݒ + u32 scrambleMask = cbd->debuggerFlg ? 0 : (u32)(SCRAMBLE_MASK & ~CS_MASK); + + for(i=0; ivbi; + cndLE.dw |= vae << 20; + cndLE.dw |= segNum << 44; + cndLE.dw |= 0x2000000000000000; + + // R}ḧÍ + EncryptByBlowfish( &cbd->keyTable, (u32*)&cndLE.b[4], (u32*)cndLE.b ); + + // rbOGfBAɒ(Í) + cndBE.b[7] = cndLE.b[0]; + cndBE.b[6] = cndLE.b[1]; + cndBE.b[5] = cndLE.b[2]; + cndBE.b[4] = cndLE.b[3]; + cndBE.b[3] = cndLE.b[4]; + cndBE.b[2] = cndLE.b[5]; + cndBE.b[1] = cndLE.b[6]; + cndBE.b[0] = cndLE.b[7]; + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = *(u32*)cndBE.b; + reg_HOTSW_MCCMD1 = *(u32*)&cndBE.b[4]; + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = START_MASK | scrambleMask | cbd->pBootSegBuf->rh.s.secure_cmd_param; + + // 25ms҂ + OS_Sleep(COMMAND_DECRYPTION_WAIT); + + for(k=0; kpSecureSegBuf + (PAGE_WORD_SIZE * j), PAGE_SIZE ); + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x0; + reg_HOTSW_MCCMD1 = 0x0; + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = START_MASK | PC_MASK & (0x1 << PC_SHIFT) | scrambleMask | cbd->pBootSegBuf->rh.s.secure_cmd_param; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + // ]ς݃y[W + j++; + } + + // ǂݍ݃ZOgԍCNg + segNum++; + + // R}hJE^CNg + cbd->vbi++; + } +} + +/*---------------------------------------------------------------------------* + * Name: SwitchONPNGSecure_DSType2 + * + * Description: PNWFl[^ONɂ + * + * CT=240ns Latency1=0x8f8+0x18 Latency2=0 Pagecount=0page + *---------------------------------------------------------------------------*/ +void SwitchONPNGSecure_DSType2(CardBootData *cbd) +{ + // XNu̐ݒ + u32 scrambleMask = cbd->debuggerFlg ? 0 : (u32)(SCRAMBLE_MASK & ~CS_MASK); + + // R}h쐬Eݒ + SetSecureCommand(S_PNG_ON, cbd); + + // MCCNT1 WX^ݒ (START = 1 SE = 1 DS = 1 Latency1 = 0 ) + reg_HOTSW_MCCNT1 = START_MASK | scrambleMask | cbd->pBootSegBuf->rh.s.secure_cmd_param; + + // 25ms҂ + OS_Sleep(COMMAND_DECRYPTION_WAIT); + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x0; + reg_HOTSW_MCCMD1 = 0x0; + + // MCCNT1 WX^ݒ (START = 1 SE = 1 DS = 1 Latency1 = 0 ) + reg_HOTSW_MCCNT1 = START_MASK | scrambleMask | cbd->pBootSegBuf->rh.s.secure_cmd_param; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + // R}hJE^CNg + cbd->vbi++; +} + +/*---------------------------------------------------------------------------* + * Name: SwitchOFFPNGSecure_DSType2 + * + * Description: PNWFl[^OFF + * + * CT=240ns Latency1=0x8f8+0x18 Latency2=0 Pagecount=0page + *---------------------------------------------------------------------------*/ +void SwitchOFFPNGSecure_DSType2(CardBootData *cbd) +{ + // XNu̐ݒ + u32 scrambleMask = cbd->debuggerFlg ? 0 : (u32)(SCRAMBLE_MASK & ~CS_MASK); + + // R}h쐬Eݒ + SetSecureCommand(S_PNG_OFF, cbd); + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = START_MASK | scrambleMask | cbd->pBootSegBuf->rh.s.secure_cmd_param; + + // 25ms҂ + OS_Sleep(COMMAND_DECRYPTION_WAIT); + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x0; + reg_HOTSW_MCCMD1 = 0x0; + + // MCCNT1 WX^ݒ + reg_HOTSW_MCCNT1 = START_MASK | scrambleMask | cbd->pBootSegBuf->rh.s.secure_cmd_param; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + // R}hJE^CNg + cbd->vbi++; +} + +/*---------------------------------------------------------------------------* + * Name: ChangeModeSecure_DSType2 + * + * Description: Game[hɈڍs + * + * CT=240ns Latency1=0x8f8+0x18 Latency2=0 Pagecount=0page + *---------------------------------------------------------------------------*/ +void ChangeModeSecure_DSType2(CardBootData *cbd) +{ + // XNu̐ݒ + u32 scrambleMask = cbd->debuggerFlg ? 0 : (u32)(SCRAMBLE_MASK & ~CS_MASK); + + // R}h쐬Eݒ + SetSecureCommand(S_CHG_MODE, cbd); + + // MCCNT1 WX^ݒ (START = 1 SE = 1 DS = 1 Latency1 = 0 ) + reg_HOTSW_MCCNT1 = START_MASK | scrambleMask | cbd->pBootSegBuf->rh.s.secure_cmd_param; + + // 25ms҂ + OS_Sleep(COMMAND_DECRYPTION_WAIT); + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x0; + reg_HOTSW_MCCMD1 = 0x0; + + // MCCNT1 WX^ݒ (START = 1 SE = 1 DS = 1 Latency1 = 0 ) + reg_HOTSW_MCCNT1 = START_MASK | scrambleMask | cbd->pBootSegBuf->rh.s.secure_cmd_param; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + + // R}hJE^CNg + cbd->vbi++; +} + + +// ------------------------------------ +// Q[[h̃R}h +// ------------------------------------ +/*---------------------------------------------------------------------------* + Name: ReadIDGame_DSType2 + + Description: Q[[hIDǂݍ + *---------------------------------------------------------------------------*/ +// Type1Ɠ + + +/*---------------------------------------------------------------------------* + * Name: ReadPageGame_DSType1 + * + * Description: Q[[hŁAw肳ꂽy[Wwobt@ɎwTCYǂݍ + * + * CT=150ns Latency1=0x657 Latency2=0x1 Pagecount=1page + *---------------------------------------------------------------------------*/ +void ReadPageGame_DSType2(CardBootData *cbd, u32 start_addr, void* buf, u32 size) +{ + u32 loop, counter=0; + u64 i, page; + GCDCmd64 cndLE, cndBE; + + page = (u32)(start_addr / PAGE_SIZE); + loop = (u32)(size / PAGE_SIZE); + loop = (size % PAGE_SIZE) ? loop + 1 : loop; + +// OS_TPrintf("Src Addr : 0x%08x Dst Addr : 0x%08x\n", start_addr, buf); +// OS_TPrintf("Read Game Segment Page Count : %d size : %x\n", loop, size); + + for(i=0; ipBootSegBuf->rh.s.game_cmd_param | + START_MASK | (PC_MASK & (0x1 << PC_SHIFT)); + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); + } +} \ No newline at end of file diff --git a/build/libraries_sysmenu/hotsw/ARM7/src/ds_blowfish_table.c b/build/libraries_sysmenu/hotsw/ARM7/src/ds_blowfish_table.c new file mode 100644 index 00000000..0c402ad0 --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/src/ds_blowfish_table.c @@ -0,0 +1,283 @@ +/*---------------------------------------------------------------------------* + 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. + *---------------------------------------------------------------------------*/ +#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_sysmenu/hotsw/ARM7/src/hotsw.c b/build/libraries_sysmenu/hotsw/ARM7/src/hotsw.c new file mode 100644 index 00000000..1087f4ea --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/src/hotsw.c @@ -0,0 +1,1243 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK + File: hotsw.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. + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// define ------------------------------------------------------------------- +#define UNDEF_CODE 0xe7ffdeff // `R[h +#define ENCRYPT_DEF_SIZE 0x800 // 2KB ARM9풓W[擪2KB + +#define DIGEST_HASH_BLOCK_SIZE_SHA1 (512/8) + +#define ROM_EMULATION_START_OFS 0x160 +#define ROM_EMULATION_END_OFS 0x180 + +#define HOTSW_THREAD_STACK_SIZE 1024 // X^bNTCY +#define HOTSW_THREAD_PRIO 11 // J[hdON Q[[h̃XbhDx +#define HOTSW_MSG_BUFFER_NUM 32 // Mobt@̐ + +// enum --------------------------------------------------------------------- +typedef enum IntrType{ + HOTSW_INSERT = 0, + HOTSW_PULLEDOUT = 1 +} +IntrType; + +// struct ------------------------------------------------------------------- +typedef struct HotSwMessage{ + IntrType type; + u32 hotswCount; +} +HotSwMessage; + +// XbhEbZ[W֌W܂Ƃ߂\ +typedef struct CardThreadData{ + u64 stack[HOTSW_THREAD_STACK_SIZE / sizeof(u64)]; + OSThread thread; + + HotSwMessage hotswInsertMsg; + HotSwMessage hotswPulledOutMsg; + OSMessageQueue hotswQueue; + OSMessage hotswMsgBuffer[HOTSW_MSG_BUFFER_NUM]; +} +CardThreadData; + +// Function prototype ------------------------------------------------------- +static BOOL IsCardExist(void); + +static void SetInterruptCallback( OSIrqMask intr_bit, OSIrqFunction func ); +static void SetInterruptCallbackEx( OSIrqMask intr_bit, void *func ); +static void SetInterrupt(void); + +static void InterruptCallbackCard(void); +static void InterruptCallbackCardDet(void); +static void InterruptCallbackCardData(void); + +static void McThread(void *arg); +static void McPowerOn(void); +static void McPowerOff(void); +static void SetMCSCR(void); + +static void GenVA_VB_VD(void); +static void LoadTable(void); +static void ReadRomEmulationData(void); +static void ReadIDNormal(void); +static void DecryptObjectFile(void); + +static void SetHotSwState(BOOL busy); + +static BOOL CheckArm7HashValue(void); +static BOOL CheckArm9HashValue(void); +static BOOL CheckExtArm7HashValue(void); +static BOOL CheckExtArm9HashValue(void); + +static void ShowRegisterData(void); +static void ShowRomHeaderData(void); + +// Static Values ------------------------------------------------------------ +static char *encrypt_object_key ATTRIBUTE_ALIGN(4) = "encryObj"; +static char *rom_emu_info ATTRIBUTE_ALIGN(4) = "TWLD"; + +static u32 s_SecureSegBufSize, s_BootSegBufSize; + +static u32 *s_pSecureSegBuffer; // J[hĂobt@̏ꏊoƂ +static BootSegmentData *s_pBootSegBuffer; // J[hĂobt@̏ꏊoƂ + +static CardBootData s_cbData; +static CardThreadData s_ctData; + +// HMACSHA1̌ +static u8 s_digestDefaultKey[ DIGEST_HASH_BLOCK_SIZE_SHA1 ] = { + 0x21, 0x06, 0xc0, 0xde, + 0xba, 0x98, 0xce, 0x3f, + 0xa6, 0x92, 0xe3, 0x9d, + 0x46, 0xf2, 0xed, 0x01, + + 0x76, 0xe3, 0xcc, 0x08, + 0x56, 0x23, 0x63, 0xfa, + 0xca, 0xd4, 0xec, 0xdf, + 0x9a, 0x62, 0x78, 0x34, + + 0x8f, 0x6d, 0x63, 0x3c, + 0xfe, 0x22, 0xca, 0x92, + 0x20, 0x88, 0x97, 0x23, + 0xd2, 0xcf, 0xae, 0xc2, + + 0x32, 0x67, 0x8d, 0xfe, + 0xca, 0x83, 0x64, 0x98, + 0xac, 0xfd, 0x3e, 0x37, + 0x87, 0x46, 0x58, 0x24 +}; + +static CardBootFunction s_funcTable[] = { + // DS Card Type 1 + { ReadBootSegNormal_DSType1, ChangeModeNormal_DSType1, // Normal[h֐ + ReadIDSecure_DSType1, ReadSegSecure_DSType1, SwitchONPNGSecure_DSType1, ChangeModeSecure_DSType1, // Secure[h֐ + ReadIDGame_DSType1, ReadPageGame_DSType1}, // Game [h֐ + // DS Card Type 2 + { ReadBootSegNormal_DSType2, ChangeModeNormal_DSType2, // Normal[h֐ + ReadIDSecure_DSType2, ReadSegSecure_DSType2, SwitchONPNGSecure_DSType2, ChangeModeSecure_DSType2, // Secure[h֐ + ReadIDGame_DSType2, ReadPageGame_DSType2}, // Game [h֐ + // TWL Card Type 1 + { ReadBootSegNormal_DSType2, ChangeModeNormal_DSType2, // Normal[h֐ + ReadIDSecure_DSType2, ReadSegSecure_DSType2, SwitchONPNGSecure_DSType2, ChangeModeSecure_DSType2, // Secure[h֐ + ReadIDGame_DSType2, ReadPageGame_DSType2}, // Game [h֐ + // RomEmulation + { ReadBootSegNormal_ROMEMU, ChangeModeNormal_ROMEMU, // Normal[h֐ + ReadIDSecure_ROMEMU, ReadSegSecure_ROMEMU, SwitchONPNGSecure_ROMEMU, ChangeModeSecure_ROMEMU, // Secure[h֐ + ReadIDGame_ROMEMU, ReadPageGame_ROMEMU} // Game [h֐ +}; + + +// =========================================================================== +// Function Describe +// =========================================================================== +/*---------------------------------------------------------------------------* + Name: HOTSW_Init + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +void HOTSW_Init(void) +{ + OS_InitTick(); + OS_InitThread(); + + // 荞݃}XN̐ݒ + SetInterrupt(); + + // 荞݂̗L + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + +#ifdef SDK_ARM7 + // `b^OJE^̒lݒ + reg_MI_MC1 = (u32)((reg_MI_MC1 & 0xffff) | 0xe00000); + + // Counter-A̒lݒ + reg_MI_MC2 = 0xe0; +#else + // PXIoRARM7Ƀ`b^OJE^EJE^A̒lݒ肵Ă炤Bݒ肳܂ő҂B + +#endif + + // J[hu[gp\̂̏ + MI_CpuClear8(&s_cbData, sizeof(CardBootData)); + + // J[hXbhp\̂̏ + MI_CpuClear8(&s_ctData, sizeof(CardThreadData)); + + // J[hu[gpXbh̐ + OS_CreateThread(&s_ctData.thread, + McThread, + NULL, + s_ctData.stack + HOTSW_THREAD_STACK_SIZE / sizeof(u64), + HOTSW_THREAD_STACK_SIZE, + HOTSW_THREAD_PRIO + ); + + // bZ[WL[̏ + OS_InitMessageQueue( &s_ctData.hotswQueue, &s_ctData.hotswMsgBuffer[0], HOTSW_MSG_BUFFER_NUM ); + + // XbhN + OS_WakeupThreadDirect(&s_ctData.thread); + + // Boot Segment obt@̐ݒ + HOTSW_SetBootSegmentBuffer((void *)SYSM_CARD_ROM_HEADER_BAK, SYSM_CARD_ROM_HEADER_SIZE ); + + // Secure Segment obt@̐ݒ + HOTSW_SetSecureSegmentBuffer((void *)SYSM_CARD_NTR_SECURE_BUF, SECURE_AREA_SIZE ); + + // CDETtOĂJ[hu[gXbhN + if(!(reg_MI_MC1 & SLOT_STATUS_CDET_MSK)){ + OS_PutString("Card Boot Start\n"); + + // MbZ[W쐬 (}񐔂擾EJ[h}) + s_ctData.hotswInsertMsg.hotswCount = CARDi_GetSlotResetCount(); + s_ctData.hotswInsertMsg.type = HOTSW_INSERT; + + // bZ[WM + OS_SendMessage(&s_ctData.hotswQueue, (OSMessage)&s_ctData.hotswInsertMsg, OS_MESSAGE_NOBLOCK); + } + else{ + OS_PutString("No Card...\n"); +#ifdef DEBUG_USED_CARD_SLOT_B_ + SYSMi_GetWork()->flags.common.is1stCardChecked = TRUE; +#endif + } +} + +/* ----------------------------------------------------------------- + * HOTSW_LoadCardData֐ + * + * J[hf[^[h + * + * BootSegmentBuffer SecureSegmentBuffer̐ݒsĂ + * ̊֐ĂłB + * ----------------------------------------------------------------- */ +BOOL HOTSW_LoadCardData(void) +{ + OSTick start; + s32 tempLockID; + BOOL retval = TRUE; + + start = OS_GetTick(); + + // XbgXbvĂ猳ɖ߂B + if(reg_MI_MC1 & 0x8000){ + reg_MI_MC1 = reg_MI_MC1 & 0xff; + } + + OS_TPrintf("---------------- Card Boot Start ---------------\n"); +#ifdef SDK_ARM7 + // J[hdZbg + McPowerOff(); + McPowerOn(); +#else // SDK_ARM9 + // ARM7PXIoRŃJ[hdON肢BONɂȂ܂ő҂B + +#endif + + // obt@ݒ + s_cbData.pBootSegBuf = s_pBootSegBuffer; + s_cbData.pSecureSegBuf = s_pSecureSegBuffer; + + // J[h̃bNID擾 + tempLockID = OS_GetLockID(); + if(tempLockID == OS_LOCK_ID_ERROR){ + retval = FALSE; + } + else{ + s_cbData.lockID = (u16)tempLockID; + } + + // u[gJn + if(IsCardExist() && retval){ + // J[h̃bN + + + // J[hKey Table[h + LoadTable(); + + // ---------------------- Normal Mode ---------------------- + // J[hIDǂݍ + ReadIDNormal(); + + // J[h^Cv𔻕ʂāAg֐ؑւ ID̍ŏʃrbg1Ȃ3DM + if(s_cbData.id_nml & 0x80000000){ + s_cbData.cardType = DS_CARD_TYPE_2; + OS_TPrintf("Card Type2\n"); + } + else{ + s_cbData.cardType = DS_CARD_TYPE_1; + OS_TPrintf("Card Type1\n"); + } + + { + u8 i; + u8 *romEmuInf = (u8 *)s_cbData.romEmuBuf; + + // ŒARM9Ɣr䂵ȂƂȂ͈͂͂ꂾ + u16 id = (u16)OS_GetLockID(); + (void)OS_LockByWord( id, &SYSMi_GetWork()->lockCardRsc, NULL ); // ARM9Ɣr䂷 + + // Boot Segmentǂݍ + s_funcTable[s_cbData.cardType].ReadBootSegment_N(&s_cbData); + + // RomG~[V擾 + ReadRomEmulationData(); + + // 擾RomG~[Vr + s_cbData.debuggerFlg = TRUE; + for(i=0; i<4; i++){ + if ( rom_emu_info[i] != romEmuInf[i] ){ + s_cbData.debuggerFlg = FALSE; + break; + } + } + if(s_cbData.debuggerFlg){ + OS_PutString("Read Debugger\n"); + s_cbData.cardType = ROM_EMULATION; + SYSMi_GetWork()->gameCommondParam = s_cbData.pBootSegBuf->rh.s.game_cmd_param & ~SCRAMBLE_MASK; + } + else{ + SYSMi_GetWork()->gameCommondParam = s_cbData.pBootSegBuf->rh.s.game_cmd_param; + } + + // ROMwb_CRCZoă`FbNBNintendoSCRCmFB + SYSMi_GetWork()->cardHeaderCrc16_bak = SVC_GetCRC16( 65535, s_cbData.pBootSegBuf, 0x015e ); + OS_TPrintf( "RomHeaderCRC16 : calc = %04x romh = %04x\n", + SYSMi_GetWork()->cardHeaderCrc16_bak, s_cbData.pBootSegBuf->rh.s.header_crc16 ); + + if( ( SYSMi_GetWork()->cardHeaderCrc16_bak != s_cbData.pBootSegBuf->rh.s.header_crc16 ) || + ( 0xcf56 != s_cbData.pBootSegBuf->rh.s.nintendo_logo_crc16 ) ){ + retval = FALSE; + } + + (void)OS_UnlockByWord( id, &SYSMi_GetWork()->lockCardRsc, NULL ); // ARM9Ɣr䂷 + OS_ReleaseLockID( id ); + } + + if( retval ) { + // NTRJ[hTWLJ[h + if(s_cbData.pBootSegBuf->rh.s.platform_code & 0x02){ + OS_TPrintf("TWL Card.\n"); + s_cbData.twlFlg = TRUE; + } + else{ + // NTRJ[h̏ꍇRomHeaderobt@1y[Wڈȍ~NAĂB + MI_CpuClearFast((void *)(SYSM_CARD_ROM_HEADER_BAK + PAGE_SIZE), SYSM_CARD_ROM_HEADER_SIZE - PAGE_SIZE); + } + + // SecureR}hPNG_ONR}hetcp̃CeV߂(Latency1Latency2𑫂) + s_cbData.secureLatency = AddLatency2ToLatency1(s_cbData.pBootSegBuf->rh.s.secure_cmd_param); + + // Key Table + GCDm_MakeBlowfishTableDS(&s_cbData.keyTable, &s_pBootSegBuffer->rh.s, s_cbData.keyBuf, 8); + + // R}hFؒlER}hJE^lEPNWFl[^l̐ + GenVA_VB_VD(); + + // ZLA[hɈڍs + s_funcTable[s_cbData.cardType].ChangeMode_N(&s_cbData); + + // ---------------------- Secure Mode ---------------------- + // PNGݒ + s_funcTable[s_cbData.cardType].SetPNG_S(&s_cbData); + + // DSHlݒ (WX^ݒ) + SetMCSCR(); + + // IDǂݍ + s_funcTable[s_cbData.cardType].ReadID_S(&s_cbData); + + // J[hID̔rāAvȂFALSEԂ + if(s_cbData.id_nml != s_cbData.id_scr){ + return FALSE; + } + + // SecurëSegmentǂݍ + s_funcTable[s_cbData.cardType].ReadSegment_S(&s_cbData); + + // Q[[hɈڍs + s_funcTable[s_cbData.cardType].ChangeMode_S(&s_cbData); + + // ---------------------- Game Mode ---------------------- + // IDǂݍ + s_funcTable[s_cbData.cardType].ReadID_G(&s_cbData); + + // J[hID̔rāAvȂFALSEԂ + if(s_cbData.id_scr != s_cbData.id_gam){ + return FALSE; + } + + // 풓W[cwɓ] + HOTSW_LoadStaticModule(); + + // ARM9풓W[̐擪2KB̈Í̈𕡍 + DecryptObjectFile(); + + // fobOo +// ShowRomHeaderData(); + } + OS_TPrintf("-----------------------------------------------\n\n"); + } + else{ + OS_TPrintf("Card Not Found\n"); + retval = FALSE; + } + + // J[hbNID̊J + OS_ReleaseLockID( s_cbData.lockID ); + + OS_TPrintf( "Load Card Time : %dms\n", OS_TicksToMilliSeconds( OS_GetTick() - start ) ); + + return retval; +} + +/* ----------------------------------------------------------------- + * HOTSW_GetRomEmulationBuffer֐ + * + * RomG~[Vi[Ăobt@ւ̃|C^Ԃ + * ----------------------------------------------------------------- */ +void* HOTSW_GetRomEmulationBuffer(void) +{ + return s_cbData.romEmuBuf; +} + +/* ----------------------------------------------------------------- + * HOTSW_LoadStaticModule֐ + * + * ARM7,9̏풓W[WJ֐ + * + * FxJ[hu[găQ[[hɂȂĂĂяoĂ + * ----------------------------------------------------------------- */ +void HOTSW_LoadStaticModule(void) +{ +#ifdef DEBUG_USED_CARD_SLOT_B_ + // oi[[h + if( s_cbData.pBootSegBuf->rh.s.banner_offset ) { +// OS_TPrintf(" - Banner Loading...\n"); + s_funcTable[s_cbData.cardType].ReadPage_G(&s_cbData, + s_cbData.pBootSegBuf->rh.s.banner_offset, + (u32 *)SYSM_CARD_BANNER_BUF, + sizeof(TWLBannerFile) ); + + SYSMi_GetWork()->flags.common.isValidCardBanner = TRUE; + SYSMi_GetWork()->flags.common.isCardStateChanged = TRUE; + SYSMi_GetWork()->flags.common.isExistCard = TRUE; + } +#endif + +// OS_TPrintf(" - Arm9 Static Module Loading...\n"); + s_cbData.arm9Stc = (u32)s_cbData.pBootSegBuf->rh.s.main_ram_address; + // zuƍĔzu擾 & Arm9̏풓W[cwɓ] + SYSM_CheckLoadRegionAndSetRelocateInfo( ARM9_STATIC, &s_cbData.arm9Stc, s_cbData.pBootSegBuf->rh.s.main_size, &SYSMi_GetWork()->romRelocateInfo[ARM9_STATIC] , s_cbData.twlFlg); + s_funcTable[s_cbData.cardType].ReadPage_G(&s_cbData, + s_cbData.pBootSegBuf->rh.s.main_rom_offset + SECURE_SEGMENT_SIZE, + (u32 *)(s_cbData.arm9Stc + SECURE_SEGMENT_SIZE), + s_cbData.pBootSegBuf->rh.s.main_size - SECURE_SEGMENT_SIZE); + +// OS_TPrintf(" - Arm7 Static Module Loading...\n"); + s_cbData.arm7Stc = (u32)s_cbData.pBootSegBuf->rh.s.sub_ram_address; + // zuƍĔzu擾 & Arm7̏풓W[wɓ] + SYSM_CheckLoadRegionAndSetRelocateInfo( ARM7_STATIC, &s_cbData.arm7Stc, s_cbData.pBootSegBuf->rh.s.sub_size, &SYSMi_GetWork()->romRelocateInfo[ARM7_STATIC] , s_cbData.twlFlg); + s_funcTable[s_cbData.cardType].ReadPage_G(&s_cbData, + s_cbData.pBootSegBuf->rh.s.sub_rom_offset, + (u32 *)s_cbData.arm7Stc, + s_cbData.pBootSegBuf->rh.s.sub_size); + + // TWLł̂݃[h + if( s_cbData.pBootSegBuf->rh.s.platform_code & PLATFORM_CODE_FLAG_TWL ) { + u32 size = ( s_cbData.pBootSegBuf->rh.s.main_ltd_size < SECURE_SEGMENT_SIZE ) ? + s_cbData.pBootSegBuf->rh.s.main_ltd_size : SECURE_SEGMENT_SIZE; +// OS_TPrintf(" - Arm9 Ltd. Static Module Loading...\n"); + s_cbData.arm9Ltd = (u32)s_cbData.pBootSegBuf->rh.s.main_ltd_ram_address; + // zuƍĔzu擾 & Arm9̏풓W[wɓ]iTWLJ[hΉĂȂ̂ŁAӁIIj + SYSM_CheckLoadRegionAndSetRelocateInfo( ARM9_LTD_STATIC, &s_cbData.arm9Ltd, s_cbData.pBootSegBuf->rh.s.main_ltd_size, &SYSMi_GetWork()->romRelocateInfo[ARM9_LTD_STATIC] , TRUE); + s_funcTable[s_cbData.cardType].ReadPage_G(&s_cbData, + s_cbData.pBootSegBuf->rh.s.main_ltd_rom_offset, + (u32 *)SYSM_CARD_TWL_SECURE_BUF, + size); + if( s_cbData.pBootSegBuf->rh.s.main_ltd_size > SECURE_SEGMENT_SIZE ) { + s_funcTable[s_cbData.cardType].ReadPage_G(&s_cbData, + s_cbData.pBootSegBuf->rh.s.main_ltd_rom_offset + SECURE_SEGMENT_SIZE, + (u32 *)(s_cbData.arm9Ltd + SECURE_SEGMENT_SIZE), + s_cbData.pBootSegBuf->rh.s.main_ltd_size - size); + } + +// OS_TPrintf(" - Arm7 Ltd. Static Module Loading...\n"); + s_cbData.arm7Ltd = (u32)s_cbData.pBootSegBuf->rh.s.sub_ltd_ram_address; + // zuƍĔzu擾 & Arm7̏풓W[wɓ] + SYSM_CheckLoadRegionAndSetRelocateInfo( ARM7_LTD_STATIC, &s_cbData.arm7Ltd, s_cbData.pBootSegBuf->rh.s.sub_ltd_size, &SYSMi_GetWork()->romRelocateInfo[ARM7_LTD_STATIC], TRUE); + s_funcTable[s_cbData.cardType].ReadPage_G(&s_cbData, + s_cbData.pBootSegBuf->rh.s.sub_ltd_rom_offset, + (u32 *)s_cbData.arm7Ltd, + s_cbData.pBootSegBuf->rh.s.sub_ltd_size); + + // Arm9풓W[ Hashl̃`FbN + if(!CheckArm9HashValue()){ + OS_PutString("~Arm9 Static Module Hash Check Error...\n"); + } + + // Arm7풓W[ Hashl̃`FbN + if(!CheckArm7HashValue()){ + OS_PutString("~Arm7 Static Module Hash Check Error...\n"); + } + + // Arm9g풓W[ Hashl̃`FbN + if(!CheckExtArm9HashValue()){ + OS_PutString("~Arm9 Ltd Static Module Hash Check Error...\n"); + } + + // Arm7g풓W[ Hashl̃`FbN + if(!CheckExtArm7HashValue()){ + OS_PutString("~Arm7 Ltd Static Module Hash Check Error...\n"); + } + } +} + + +/* ----------------------------------------------------------------- + * HOTSW_SetBootSegmentBuffer֐ + * + * Boot Segment obt@̎w + * + * FJ[hu[g͌ĂяoȂ悤ɂ + * ----------------------------------------------------------------- */ +void HOTSW_SetBootSegmentBuffer(void* buf, u32 size) +{ + SDK_ASSERT(size > BOOT_SEGMENT_SIZE); + + s_pBootSegBuffer = (BootSegmentData *)buf; + s_BootSegBufSize = size; + + s_cbData.pBootSegBuf = s_pBootSegBuffer; + + // obt@̏ + MI_CpuClear8(s_pBootSegBuffer, size); + + OS_TPrintf("*** Boot Segm Address : 0x%08x\n", s_pBootSegBuffer); +} + +/* ----------------------------------------------------------------- + * HOTSW_SetSecureSegmentBuffer֐ + * + * Secure Segment obt@̎w + * + * FJ[hu[g͌ĂяoȂ悤ɂ + * ----------------------------------------------------------------- */ +void HOTSW_SetSecureSegmentBuffer(void* buf, u32 size) +{ + SDK_ASSERT(size > SECURE_SEGMENT_SIZE); + + s_pSecureSegBuffer = (u32 *)buf; + s_SecureSegBufSize = size; + + s_cbData.pSecureSegBuf = s_pSecureSegBuffer; + + // obt@̏ + MI_CpuClear8(s_pSecureSegBuffer, size); + + OS_TPrintf("*** Scr Seg Buf Address : 0x%08x\n", s_pSecureSegBuffer); +} + + +/* ----------------------------------------------------------------- + * GenVA_VB_VD֐ + * + * R}hFؒlER}hJE^EPNWFl[^l̐ + * ----------------------------------------------------------------- */ +static void GenVA_VB_VD(void) +{ + u32 dummy = 0; + MATHRandContext32 rnd; + + // VBlankJE^lƂB + MATH_InitRand32(&rnd, (u64)OS_GetVBlankCount()); + + s_cbData.vae = MATH_Rand32(&rnd, 0); + s_cbData.vbi = MATH_Rand32(&rnd, 0); + s_cbData.vd = MATH_Rand32(&rnd, 0); + dummy = MATH_Rand32(&rnd, 0); + + EncryptByBlowfish(&s_cbData.keyTable, &s_cbData.vae, &s_cbData.vbi); + EncryptByBlowfish(&s_cbData.keyTable, &s_cbData.vd , &dummy); + + s_cbData.vae &= 0xffffff; + s_cbData.vbi &= 0xfffff; + s_cbData.vd &= 0xffffff; +} + +/* ----------------------------------------------------------------- + * LoadTable֐ + * + * J[h Key Table [h֐B + * + * ̊֐͊JJ[hpɔsȂƂȂB + * iŃJ[h̏ꍇÃR}h͖݌v + * ----------------------------------------------------------------- */ +static void LoadTable(void) +{ + u32 temp; + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x0000009f; + reg_HOTSW_MCCMD1 = 0x00000000; + + // MCCNT0 WX^ݒ (E = 1 I = 1 SEL = 0) + reg_HOTSW_MCCNT0 = (u16)((reg_HOTSW_MCCNT0 & 0x0fff) | 0xc000); + + // MCCNT1 WX^ݒ (START = 1 W/R = 0 PC = 101(16y[W) latency1 = 0(KvȂ) ) + reg_HOTSW_MCCNT1 = START_MASK | PC_MASK & (0x5 << PC_SHIFT); + + // MCCNTWX^RDYtO|[OāAtOf[^MCD1WX^ɍēxZbgBX^[gtO0ɂȂ܂Ń[vB + while(reg_HOTSW_MCCNT1 & START_FLG_MASK){ + while(!(reg_HOTSW_MCCNT1 & READY_FLG_MASK)){} + temp = reg_HOTSW_MCD1; + } +} + +/*---------------------------------------------------------------------------* + Name: ReadRomEmulationData + + Description: RomG~[Vf[^̓ǂݍ + *---------------------------------------------------------------------------*/ +static void ReadRomEmulationData(void) +{ + u32 count=0; + u32 temp; + u32 *dst = s_cbData.romEmuBuf; + + // ʎYpCPUł͕ANZXh~̂߃[hȂ + if ( ! (*(u8*)(OS_CHIPTYPE_DEBUGGER_ADDR) & OS_CHIPTYPE_DEBUGGER_MASK) ) + { + return; + } + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x3e000000; + reg_HOTSW_MCCMD1 = 0x0; + + // MCCNT1 WX^ݒ (START = 1 PC = 001(1y[W[h) latency1 = 0x5fe) + reg_HOTSW_MCCNT1 = START_MASK | PC_MASK & (0x1 << PC_SHIFT) | (0x5fe & LATENCY1_MASK); + + // MCCNTWX^RDYtO|[OāAtOf[^MCD1WX^ɍēxZbgBX^[gtO0ɂȂ܂Ń[vB + while(reg_HOTSW_MCCNT1 & START_FLG_MASK){ + while(!(reg_HOTSW_MCCNT1 & READY_FLG_MASK)){} + if(count >= ROM_EMULATION_START_OFS && count < ROM_EMULATION_END_OFS){ + *dst++ = reg_HOTSW_MCD1; + } + else{ + temp = reg_HOTSW_MCD1; + } + count+=4; + } + + MI_CpuCopyFast(s_cbData.romEmuBuf, (void*)HW_ISD_RESERVED, 32); +} + +/* ----------------------------------------------------------------- + * ReadIDNormal֐ + * + * m[}[h̃J[hIDǂݍފ֐ + * ----------------------------------------------------------------- */ +void ReadIDNormal(void) +{ + // J[h荞݂ɂDMARs[ + HOTSW_NDmaCopy_Card( HOTSW_DMA_NO, (u32 *)HOTSW_MCD1, &s_cbData.id_nml, sizeof(s_cbData.id_nml) ); + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x00000090; + reg_HOTSW_MCCMD1 = 0x00000000; + + // MCCNT0 WX^ݒ (E = 1 I = 1 SEL = 0) + reg_HOTSW_MCCNT0 = (u16)((reg_HOTSW_MCCNT0 & 0x0fff) | 0xc000); + + // MCCNT1 WX^ݒ (START = 1 PC = 111(Xe[^X[h) latency1 = 1 ) + reg_HOTSW_MCCNT1 = START_MASK | PC_MASK & (0x7 << PC_SHIFT) | (0x1 & LATENCY1_MASK); + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); +} + +/* ----------------------------------------------------------------- + * DecryptObjectFile֐ + * + * ZLÄ擪2KB̈Í̈𕜍 + * + * FZLA[hA܂̓ZLA[hOɂ̊֐ĂԂƁA + * @@ɃR}ḧÍsȂȂ܂B + * ----------------------------------------------------------------- */ +static u32 encDestBuf[ENCRYPT_DEF_SIZE/sizeof(u32)]; + +static void DecryptObjectFile(void) +{ + u8 i; + s32 restSize; + s32 size = (s32)s_cbData.pBootSegBuf->rh.s.main_size; + u32 *pEncBuf = encDestBuf; + u32 *pEncDes = s_cbData.pSecureSegBuf; + BLOWFISH_CTX *tableBufp = &s_cbData.keyTable; + BOOL exist = TRUE; + + if (size > ENCRYPT_DEF_SIZE) { + size = ENCRYPT_DEF_SIZE; + } + restSize = size; + + // ǂݍ񂾃ZLÄobt@ꎞobt@ɃRs[ + MI_CpuCopy32(s_cbData.pSecureSegBuf, pEncBuf, (u32)size); + + // ZLÄ擪8oCgBlowfishŕ + DecryptByBlowfish(&s_cbData.keyTable, &(pEncBuf)[1], &(pEncBuf)[0]); + + // Key Tableϊ + s_cbData.keyBuf[1] = (s_cbData.keyBuf[1] << 1); + s_cbData.keyBuf[2] = (s_cbData.keyBuf[2] >> 1); + InitBlowfishKeyAndTableDS(&s_cbData.keyTable, s_cbData.keyBuf, 8); + + // xZLÄ擪8oCgBlowfishŕ + DecryptByBlowfish(&s_cbData.keyTable, &(pEncBuf)[1], &(pEncBuf)[0]); + for ( i=0; i<8; i++ ){ + // 擪8oCǧ "encryObj" ƂȂĂ畡 + if ( encrypt_object_key[i] != ((char*)pEncBuf)[i] ){ + exist = FALSE; + break; + } + } + + // ÍIuWFNgL + if ( exist ){ + u32 *bufp = pEncBuf; + + bufp[0] = UNDEF_CODE; + bufp[1] = UNDEF_CODE; + while ((restSize -= 8) > 0) { + bufp += 2; // + DecryptByBlowfish(tableBufp, &(bufp)[1], &(bufp)[0]); + } + } + else{ + OS_PutString(" DecryptObjectFile : Error...\n"); + + MI_NDmaFill( HOTSW_DMA_NO, pEncBuf, UNDEF_CODE, (u32)size ); // `R[hŃNA + } + MI_CpuCopy32(pEncBuf, pEncDes, (u32)size); +} + +/* ----------------------------------------------------------------- + * IsCardExist֐ + * + * J[h̑ݔ + * + * SCFG_MC1CDETtOĂ + * ----------------------------------------------------------------- */ +static BOOL IsCardExist(void) +{ + if(!(reg_MI_MC1 & SLOT_STATUS_CDET_MSK)){ + return TRUE; + } + else{ + return FALSE; + } +} + +/*---------------------------------------------------------------------------* + Name: McPowerOn + + Description: XbgB dON֐ + *---------------------------------------------------------------------------*/ +static void McPowerOn(void) +{ + if((reg_MI_MC1 & SLOT_STATUS_MODE_SELECT_MSK) == SLOT_STATUS_MODE_00){ + // SCFG_MC1 Slot Status M1,M0 01 ɂ + reg_MI_MC1 = (u32)((reg_MI_MC1 & (~SLOT_STATUS_MODE_SELECT_MSK)) | SLOT_STATUS_MODE_01); + // 1ms҂ + OS_Sleep(1); + + // SCFG_MC1 Slot Status M1,M0 10 ɂ + reg_MI_MC1 = (u32)((reg_MI_MC1 & (~SLOT_STATUS_MODE_SELECT_MSK)) | SLOT_STATUS_MODE_10); + // 1ms҂ + OS_Sleep(1); + + // Zbghigh (RESB = 1ɂ) + reg_HOTSW_MCCNT1 = RESB_MASK; + + // 27ms҂ + OS_Sleep(27); + } +} + +/*---------------------------------------------------------------------------* + Name: McPowerOff + + Description: XbgB dOFF֐ + *---------------------------------------------------------------------------*/ +static void McPowerOff(void) +{ + if((reg_MI_MC1 & SLOT_STATUS_MODE_SELECT_MSK) == SLOT_STATUS_MODE_10){ + // SCFG_MC1 Slot Status M1,M0 11 ɂ + reg_MI_MC1 = (u32)((reg_MI_MC1 & (~SLOT_STATUS_MODE_SELECT_MSK)) | SLOT_STATUS_MODE_11); + + // SCFG_MC1 Slot Status M1,M0 00 ɂȂ܂Ń|[O + while((reg_MI_MC1 & SLOT_STATUS_MODE_SELECT_MSK) != SLOT_STATUS_MODE_00){} + + // 100ms҂ [TODO:]҂Ԃ͎blBqɐl𑪒肵Ă炤B + OS_Sleep(100); + } +} + +/*---------------------------------------------------------------------------* + Name: SetMCSCR + + Description: Hlݒ背WX^ݒ肷 + + F̊֐̓ZLA[hŁA + sPNG_ONR}hsĂĂяoĂB + *---------------------------------------------------------------------------*/ +static void SetMCSCR(void) +{ + u32 pna_l = (u32)(PNA_BASE_VALUE | (s_cbData.vd << 15)); + u32 pna_h = (u32)(s_cbData.vd >> 17); + + // SCR A + reg_HOTSW_MCSCR0 = pna_l; + + // SCR B + reg_HOTSW_MCSCR1 = PNB_L_VALUE; + + // [d0 -d6 ] -> SCR A + // [d16-d22] -> SCR B + reg_HOTSW_MCSCR2 = (u32)(pna_h | PNB_H_VALUE << 16); + + // MCCNT1 WX^ݒ (SCR = 1) + reg_HOTSW_MCCNT1 = SCR_MASK; +} + +/*---------------------------------------------------------------------------* + Name: McThread + + Description: J[hE}Xbh + *---------------------------------------------------------------------------*/ +static void McThread(void *arg) +{ + #pragma unused( arg ) + + static BOOL insert = FALSE; + + BOOL retval; + HotSwMessage *msg; + + while(1){ + OS_ReceiveMessage(&s_ctData.hotswQueue, (OSMessage *)&msg, OS_MESSAGE_BLOCK); + + // }񐔂r + if(CARDi_IsPulledOutEx(msg->hotswCount)){ + // J[h}荞݂ɂXbhN ÕXbhN J[h}Ă + if(msg->type == HOTSW_INSERT && !insert && IsCardExist()){ + OS_PutString("--- Insert\n"); + + // }tO𗧂Ă + insert = TRUE; + + if( !SYSMi_GetWork()->flags.common.isEnableHotSW ) { +#ifdef DEBUG_USED_CARD_SLOT_B_ + SYSMi_GetWork()->flags.common.is1stCardChecked = TRUE; +#endif + continue; + } + // HotSwbusyԂɂ + SetHotSwState(TRUE); + // J[hǂݍ݊Jn + retval = HOTSW_LoadCardData(); + // HotSwfreeԂɂ + SetHotSwState(FALSE); + + // J[hǂݍ݂ɎsĂꍇ or }񐔕sv or J[hĂ + if(!retval || !CARDi_IsPulledOutEx(msg->hotswCount) || !IsCardExist()){ + // tO + SYSMi_GetWork()->flags.common.isValidCardBanner = FALSE; + SYSMi_GetWork()->flags.common.isCardStateChanged = FALSE; + SYSMi_GetWork()->flags.common.isExistCard = FALSE; + + // bN̊J + + // J[hbNID̊J + OS_ReleaseLockID( s_cbData.lockID ); + + OS_PutString("### Card Read Error\n"); + } + // J[hǂݍ݁EԂɖ肪Ȃꍇ + else{ + u16 id = (u16)OS_GetLockID(); + (void)OS_LockByWord( id, &SYSMi_GetWork()->lockHotSW, NULL ); + if( SYSMi_GetWork()->flags.arm9.reqChangeHotSW ) { + SYSMi_GetWork()->flags.common.isEnableHotSW = SYSMi_GetWork()->flags.arm9.nextHotSWStatus; + SYSMi_GetWork()->flags.arm9.reqChangeHotSW = 0; + SYSMi_GetWork()->flags.arm9.nextHotSWStatus = 0; +// HOTSW_Finalize(); + } + (void)OS_UnlockByWord( id, &SYSMi_GetWork()->lockHotSW, NULL ); + OS_ReleaseLockID( id ); + + // VJ[hID + SYSMi_GetWork()->nCardID = s_cbData.id_gam; + + // fobK + MI_CpuCopy8( HOTSW_GetRomEmulationBuffer(), &SYSMi_GetWork()->romEmuInfo, ROM_EMULATION_DATA_SIZE ); + SYSMi_GetWork()->flags.common.isOnDebugger = s_cbData.debuggerFlg; + } +#ifdef DEBUG_USED_CARD_SLOT_B_ + SYSMi_GetWork()->flags.common.is1stCardChecked = TRUE; +#endif + } + + // J[h荞݂ɂXbhN ÕXbhN} J[hĂ + else if(msg->type == HOTSW_PULLEDOUT && insert && !IsCardExist()){ + OS_PutString("--- Init\n"); + + // }tO낷B + insert = FALSE; + + // HOTSW}tOĂAȂ + if( !SYSMi_GetWork()->flags.common.isEnableHotSW ) { + continue; + } + + // obt@̏ + MI_CpuClearFast(s_pBootSegBuffer, s_BootSegBufSize); + MI_CpuClearFast(s_pSecureSegBuffer, s_SecureSegBufSize); + + // tOPA + { + u16 id = (u16)OS_GetLockID(); + (void)OS_LockByWord( id, &SYSMi_GetWork()->lockHotSW, NULL ); + SYSMi_GetWork()->flags.common.isExistCard = FALSE; + SYSMi_GetWork()->flags.common.isValidCardBanner = FALSE; + SYSMi_GetWork()->flags.common.isCardStateChanged = TRUE; + (void)OS_UnlockByWord( id, &SYSMi_GetWork()->lockHotSW, NULL ); + OS_ReleaseLockID( id ); + } + // bN̊J + + + // J[hbNID̊J + OS_ReleaseLockID( s_cbData.lockID ); + + // J[hu[gp\̂̏ + MI_CpuClear32(&s_cbData, sizeof(CardBootData)); + } + } + } +} + +/*---------------------------------------------------------------------------* + Name: InterruptCallbackCard + + Description: J[hB荞݃nh + *---------------------------------------------------------------------------*/ +static void InterruptCallbackCard(void) +{ +// OS_TPrintf("*** Pulled Out\n"); + + // MbZ[W쐬 (}񐔂擾EJ[h}) + s_ctData.hotswPulledOutMsg.hotswCount = CARDi_GetSlotResetCount(); + s_ctData.hotswPulledOutMsg.type = HOTSW_PULLEDOUT; + + // bZ[WM + OS_SendMessage(&s_ctData.hotswQueue, (OSMessage *)&s_ctData.hotswPulledOutMsg, OS_MESSAGE_NOBLOCK); + +#ifdef USE_SLOT_A + OS_SetIrqCheckFlagEx(OS_IE_CARD_A_IREQ); +#else + OS_SetIrqCheckFlagEx(OS_IE_CARD_B_IREQ); +#endif +} + +/*---------------------------------------------------------------------------* + Name: InterruptCallbackCardDet + + Description: J[hB}荞݃nh + *---------------------------------------------------------------------------*/ +static void InterruptCallbackCardDet(void) +{ +// OS_TPrintf("*** Insert\n"); + + // SDK̃J[hԂZbg + CARDi_ResetSlotStatus(); + + // MbZ[W쐬 (}񐔂擾EJ[h}) + s_ctData.hotswInsertMsg.hotswCount = CARDi_GetSlotResetCount(); + s_ctData.hotswInsertMsg.type = HOTSW_INSERT; + + // bZ[WM + OS_SendMessage(&s_ctData.hotswQueue, (OSMessage *)&s_ctData.hotswInsertMsg, OS_MESSAGE_NOBLOCK); + +#ifdef USE_SLOT_A + OS_SetIrqCheckFlagEx(OS_IE_CARD_A_DET); +#else + OS_SetIrqCheckFlagEx(OS_IE_CARD_B_DET); +#endif +} + +/*---------------------------------------------------------------------------* + Name: InterruptCallbackCardData + + Description: J[hB f[^]I荞݃nh + *---------------------------------------------------------------------------*/ +static void InterruptCallbackCardData(void) +{ + // f[^]I҂܂ŐQĂ̂N + OS_WakeupThreadDirect(&s_ctData.thread); + +#ifdef USE_SLOT_A + OS_SetIrqCheckFlagEx(OS_IE_CARD_A_DATA); +#else + OS_SetIrqCheckFlagEx(OS_IE_CARD_B_DATA); +#endif +} + +/*---------------------------------------------------------------------------* + Name: SetHotSwState + + Description: HotSw̏Ԃݒ肷 + *---------------------------------------------------------------------------*/ +static void SetHotSwState(BOOL busy) +{ + u16 id = (u16)OS_GetLockID(); + (void)OS_LockByWord( id, &SYSMi_GetWork()->lockHotSW, NULL ); + + SYSMi_GetWork()->flags.common.isBusyHotSW = busy ? 1 : 0; + + (void)OS_UnlockByWord( id, &SYSMi_GetWork()->lockHotSW, NULL ); + OS_ReleaseLockID( id ); +} + +/*---------------------------------------------------------------------------* + Name: SetInterruptCallback + SetInterruptCallbackEx + + Description: 荞݃R[obN֐Ɗ荞݋‚̐ݒs + *---------------------------------------------------------------------------*/ +static void SetInterruptCallback( OSIrqMask intr_bit, OSIrqFunction func ) +{ + (void)OS_SetIrqFunction(intr_bit, func); + (void)OS_EnableIrqMask(intr_bit); +} + +static void SetInterruptCallbackEx( OSIrqMask intr_bit, void *func ) +{ + (void)OS_SetIrqFunctionEx(intr_bit, func); + (void)OS_EnableIrqMaskEx(intr_bit); +} + +/*---------------------------------------------------------------------------* + Name: SetInterrupt + + Description: 荞݃R[obN֐xɐݒ肷֐ + *---------------------------------------------------------------------------*/ +static void SetInterrupt(void) +{ +#ifdef USE_SLOT_A + SetInterruptCallback( OS_IE_CARD_A_IREQ , InterruptCallbackCard ); + SetInterruptCallback( OS_IE_CARD_A_DET , InterruptCallbackCardDet ); + SetInterruptCallback( OS_IE_CARD_A_DATA , InterruptCallbackCardData ); +#else + SetInterruptCallback( OS_IE_CARD_B_IREQ , InterruptCallbackCard ); + SetInterruptCallback( OS_IE_CARD_B_DET , InterruptCallbackCardDet ); + SetInterruptCallback( OS_IE_CARD_B_DATA , InterruptCallbackCardData ); +#endif +} + +/* ----------------------------------------------------------------- + * CheckHashValue֐ + * + * 풓W[Eg풓W[̃nbVvZāA + * J[h̃nbVlƔׂB + * ----------------------------------------------------------------- */ +#include + +// ---------------------------------------------------------------------- +// Arm7풓W[̃nbV`FbN +// ---------------------------------------------------------------------- +static BOOL CheckArm7HashValue(void) +{ + u8 sha1data[DIGEST_SIZE_SHA1]; + BOOL retval = TRUE; + + // NA + MI_CpuClear8(sha1data, sizeof(sha1data)); + + // ARM7풓W[Hashlƍ + SVC_CalcHMACSHA1( sha1data, + (u32 *)(s_cbData.arm7Stc), + s_cbData.pBootSegBuf->rh.s.sub_size, + s_digestDefaultKey, + sizeof(s_digestDefaultKey) ); + + return SVC_CompareSHA1( sha1data, s_cbData.pBootSegBuf->rh.s.sub_static_digest ); +} + +// ---------------------------------------------------------------------- +// Arm9풓W[̃nbV`FbN +// +// 擪2K̕sÕf[^̃nbVׂ +// ---------------------------------------------------------------------- +static BOOL CheckArm9HashValue(void) +{ + u8 sha1data[DIGEST_SIZE_SHA1]; + BOOL retval = TRUE; + SVCHMACSHA1Context hash; + + // NA + MI_CpuClear8(sha1data, sizeof(sha1data)); + + // nbV + SVC_HMACSHA1Init( &hash, s_digestDefaultKey, sizeof(s_digestDefaultKey) ); + + // ZLÄ敪UpDate + SVC_HMACSHA1Update( &hash, s_cbData.pSecureSegBuf, SECURE_SEGMENT_SIZE ); + + // Q[̈敪UpDate + SVC_HMACSHA1Update( &hash, (u32 *)(s_cbData.arm9Stc + SECURE_SEGMENT_SIZE), s_cbData.pBootSegBuf->rh.s.main_size - SECURE_SEGMENT_SIZE ); + + // Hashl擾 + SVC_HMACSHA1GetHash( &hash, sha1data ); + + return SVC_CompareSHA1( sha1data, s_cbData.pBootSegBuf->rh.s.main_static_digest ); +} + +// ---------------------------------------------------------------------- +// Arm7g풓W[̃nbV`FbN +// ---------------------------------------------------------------------- +static BOOL CheckExtArm7HashValue(void) +{ + u8 sha1data[DIGEST_SIZE_SHA1]; + BOOL retval = TRUE; + + // NA + MI_CpuClear8(sha1data, sizeof(sha1data)); + + // ARM7풓W[Hashlƍ + SVC_CalcHMACSHA1( sha1data, + (u32 *)s_cbData.arm7Ltd, + s_cbData.pBootSegBuf->rh.s.sub_ltd_size, + s_digestDefaultKey, + sizeof(s_digestDefaultKey) ); + + return SVC_CompareSHA1( sha1data, s_cbData.pBootSegBuf->rh.s.sub_ltd_static_digest ); +} + +// ---------------------------------------------------------------------- +// Arm9g풓W[̃nbV`FbN +// ---------------------------------------------------------------------- +static BOOL CheckExtArm9HashValue(void) +{ + u8 sha1data[DIGEST_SIZE_SHA1]; + u32 size; + BOOL retval = TRUE; + SVCHMACSHA1Context hash; + + // Arm9g풓W[̃ZLÄ敪̃TCY擾 + size = ( s_cbData.pBootSegBuf->rh.s.main_ltd_size < SECURE_SEGMENT_SIZE ) ? + s_cbData.pBootSegBuf->rh.s.main_ltd_size : SECURE_SEGMENT_SIZE; + + // NA + MI_CpuClear8(sha1data, sizeof(sha1data)); + + // nbV + SVC_HMACSHA1Init( &hash, s_digestDefaultKey, sizeof(s_digestDefaultKey) ); + + // ZLÄ敪UpDate + SVC_HMACSHA1Update( &hash, (u32 *)SYSM_CARD_TWL_SECURE_BUF, size ); + + // Q[̈敪UpDate (Arm9g풓W[SecurëŎ܂Ă炱͔΂) + if( s_cbData.pBootSegBuf->rh.s.main_ltd_size > SECURE_SEGMENT_SIZE ){ + SVC_HMACSHA1Update( &hash, (u32 *)(s_cbData.arm9Ltd + SECURE_SEGMENT_SIZE), s_cbData.pBootSegBuf->rh.s.main_ltd_size - size ); + } + + // Hashl擾 + SVC_HMACSHA1GetHash( &hash, sha1data ); + + return SVC_CompareSHA1( sha1data, s_cbData.pBootSegBuf->rh.s.main_ltd_static_digest ); +} + +// ************************************************************************** +// +// Debugp\֐ +// +// ************************************************************************** +/*---------------------------------------------------------------------------* + Name: ShowRomHeaderData + + Description: + *---------------------------------------------------------------------------*/ +static void ShowRomHeaderData(void) +{ + OS_TPrintf("\nDebug Data -------------------------------\n"); + OS_TPrintf("1. Normal Mode ID : 0x%08x\n" , s_cbData.id_nml); + OS_TPrintf("2. Secure Mode ID : 0x%08x\n" , s_cbData.id_scr); + OS_TPrintf("3. Game Mode ID : 0x%08x\n" , s_cbData.id_gam); + + OS_TPrintf("title Name : %s\n", s_pBootSegBuffer->rh.s.title_name); + OS_TPrintf("initial Code : %x\n\n", *(u32 *)s_pBootSegBuffer->rh.s.game_code); + + OS_TPrintf("platform Code : 0x%02x\n\n", s_cbData.pBootSegBuf->rh.s.platform_code); + + OS_TPrintf("main rom offset : 0x%08x\n" , s_cbData.pBootSegBuf->rh.s.main_rom_offset); + OS_TPrintf("main entry addr : 0x%08x\n" , s_cbData.pBootSegBuf->rh.s.main_entry_address); + OS_TPrintf("main ram addr : 0x%08x\n" , s_cbData.pBootSegBuf->rh.s.main_ram_address); + OS_TPrintf("main size : 0x%08x\n\n", s_cbData.pBootSegBuf->rh.s.main_size); + + OS_TPrintf("sub rom offset : 0x%08x\n", s_cbData.pBootSegBuf->rh.s.sub_rom_offset); + OS_TPrintf("sub entry addr : 0x%08x\n", s_cbData.pBootSegBuf->rh.s.sub_entry_address); + OS_TPrintf("sub ram addr : 0x%08x\n", s_cbData.pBootSegBuf->rh.s.sub_ram_address); + OS_TPrintf("sub size : 0x%08x\n", s_cbData.pBootSegBuf->rh.s.sub_size); + + if(s_cbData.twlFlg){ + OS_TPrintf("\nLtd main rom offset: 0x%08x\n" , s_cbData.pBootSegBuf->rh.s.main_ltd_rom_offset); + OS_TPrintf("Ltd main ram addr: 0x%08x\n" , s_cbData.pBootSegBuf->rh.s.main_ltd_ram_address); + OS_TPrintf("Ltd main size : 0x%08x\n\n", s_cbData.pBootSegBuf->rh.s.main_ltd_size); + + OS_TPrintf("Ltd Sub rom offset : 0x%08x\n" , s_cbData.pBootSegBuf->rh.s.sub_ltd_rom_offset); + OS_TPrintf("Ltd Sub ram addr : 0x%08x\n" , s_cbData.pBootSegBuf->rh.s.sub_ltd_ram_address); + OS_TPrintf("Ltd Sub size : 0x%08x\n", s_cbData.pBootSegBuf->rh.s.sub_ltd_size); + } + + OS_TPrintf("------------------------------------------\n\n"); +} + +/*---------------------------------------------------------------------------* + Name: ShowRegisterData + + Description: + *---------------------------------------------------------------------------*/ +static void ShowRegisterData(void) +{ + OS_TPrintf("----------------------------------------------------------\n"); + OS_TPrintf("g@\䃌WX^ (MC_B(d24)) : %08x\n", reg_SCFG_EXT); + OS_TPrintf("MC I/F䃌WX^P (slot status) : %08x\n", reg_MI_MC1); + OS_TPrintf("MC I/F䃌WX^Q (Counter-A) : %04x\n", reg_MI_MC2); + OS_TPrintf("MC Rg[WX^0 (SEL etc) : %04x\n", reg_HOTSW_MCCNT0); + OS_TPrintf("MC Rg[WX^1 (START etc) : %08x\n", reg_HOTSW_MCCNT1); + OS_TPrintf("----------------------------------------------------------\n"); +} diff --git a/build/libraries_sysmenu/hotsw/ARM7/src/romEmulation.c b/build/libraries_sysmenu/hotsw/ARM7/src/romEmulation.c new file mode 100644 index 00000000..b40ce962 --- /dev/null +++ b/build/libraries_sysmenu/hotsw/ARM7/src/romEmulation.c @@ -0,0 +1,333 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK + File: romEmulation.c + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include + +// Define Data -------------------------------------------------------------- +#define BOOT_PAGE_NUM 8 +#define SECURE_PAGE_NUM 32 + + + +// =========================================================================== +// Function Describe +// =========================================================================== + +// -------------------------------------- +// m[}[h̃R}h +// -------------------------------------- +/*---------------------------------------------------------------------------* + Name: ReadIDNormal_ROMEMU + + Description: DSJ[hType1̃m[}[hIDǂݍ + *---------------------------------------------------------------------------*/ +// + +/*---------------------------------------------------------------------------* + Name: ReadBootSegNormal_ROMEMU + + Description: DSJ[hType1̃m[}[hBoot Segmentǂݍ + *---------------------------------------------------------------------------*/ +void ReadBootSegNormal_ROMEMU(CardBootData *cbd) +{ + u32 i,j=0; + u64 page = 0; + GCDCmd64 tempCnd, cnd; +// u32 n = 0; + + for(i=0; ipBootSegBuf->word + j++) = reg_HOTSW_MCD1; + } + + page++; + } +} + +/*---------------------------------------------------------------------------* + Name: ChangeModeNormal_ROMEMU + + Description: DSJ[hType1̃m[}[h̃[hύX + *---------------------------------------------------------------------------*/ +void ChangeModeNormal_ROMEMU(CardBootData *cbd) +{ + #pragma unused( cbd ) + + GCDCmd64 tempCnd, cnd; + + // [NA + MI_CpuClear8(&tempCnd, sizeof(GCDCmd64)); + + // gGfBAō + tempCnd.dw = 0x3c00000000000000; + + // rbNGfBAɂ + cnd.b[0] = tempCnd.b[7]; + cnd.b[1] = tempCnd.b[6]; + cnd.b[2] = tempCnd.b[5]; + cnd.b[3] = tempCnd.b[4]; + cnd.b[4] = tempCnd.b[3]; + cnd.b[5] = tempCnd.b[2]; + cnd.b[6] = tempCnd.b[1]; + cnd.b[7] = tempCnd.b[0]; + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = *(u32 *)cnd.b; + reg_HOTSW_MCCMD1 = *(u32 *)&cnd.b[4]; + + // MCCNT1 WX^ݒ (START = 1 ) + reg_HOTSW_MCCNT1 = START_MASK; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); +} + + +// -------------------------------------- +// ZLA[h̃R}h +// -------------------------------------- +/*---------------------------------------------------------------------------* + Name: ReadIDSecure_ROMEMU + + Description: + *---------------------------------------------------------------------------*/ +void ReadIDSecure_ROMEMU(CardBootData *cbd) +{ + // J[h荞݂ɂDMARs[ + HOTSW_NDmaCopy_Card( HOTSW_DMA_NO, (u32 *)HOTSW_MCD1, &cbd->id_scr, sizeof(cbd->id_scr) ); + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x00000090; + reg_HOTSW_MCCMD1 = 0x00000000; + + // MCCNT0 WX^ݒ (E = 1 I = 1 SEL = 0) + reg_HOTSW_MCCNT0 = (u16)((reg_HOTSW_MCCNT0 & 0x0fff) | 0xc000); + + // MCCNT1 WX^ݒ (START = 1 PC = 111(Xe[^X[h) latency1 = 1 ) + reg_HOTSW_MCCNT1 = START_MASK | PC_MASK & (0x7 << PC_SHIFT) | (0x1 & LATENCY1_MASK); + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); +} + +/*---------------------------------------------------------------------------* + Name: ReadSegSecure_ROMEMU + + Description: + *---------------------------------------------------------------------------*/ +void ReadSegSecure_ROMEMU(CardBootData *cbd) +{ + u32 i,j=0; + u64 page = 0x20; + GCDCmd64 tempCnd, cnd; + u32 n = 0; + + for(i=0; ipSecureSegBuf + j++) = reg_HOTSW_MCD1; + } + page++; + } +} + +/*---------------------------------------------------------------------------* + Name: SwitchONPNGSecure_ROMEMU + + Description: + *---------------------------------------------------------------------------*/ +void SwitchONPNGSecure_ROMEMU(CardBootData *cbd) +{ + #pragma unused( cbd ) +} + +/*---------------------------------------------------------------------------* + Name: SwitchOFFPNGSecure_ROMEMU + + Description: + *---------------------------------------------------------------------------*/ +void SwitchOFFPNGSecure_ROMEMU(CardBootData *cbd) +{ + #pragma unused( cbd ) +} + +/*---------------------------------------------------------------------------* + Name: ChangeModeSecure_ROMEMU + + Description: + *---------------------------------------------------------------------------*/ +void ChangeModeSecure_ROMEMU(CardBootData *cbd) +{ + #pragma unused( cbd ) + + GCDCmd64 tempCnd, cnd; + + // [NA + MI_CpuClear8(&tempCnd, sizeof(GCDCmd64)); + + // gGfBAō + tempCnd.dw = 0xa000000000000000; + + // rbNGfBAɂ + cnd.b[0] = tempCnd.b[7]; + cnd.b[1] = tempCnd.b[6]; + cnd.b[2] = tempCnd.b[5]; + cnd.b[3] = tempCnd.b[4]; + cnd.b[4] = tempCnd.b[3]; + cnd.b[5] = tempCnd.b[2]; + cnd.b[6] = tempCnd.b[1]; + cnd.b[7] = tempCnd.b[0]; + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = *(u32 *)cnd.b; + reg_HOTSW_MCCMD1 = *(u32 *)&cnd.b[4]; + + // MCCNT1 WX^ݒ (START = 1 ) + reg_HOTSW_MCCNT1 = START_MASK; + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); +} + + +// ------------------------------------ +// Q[[h̃R}h +// ------------------------------------ +/*---------------------------------------------------------------------------* + Name: ReadIDGame_ROMEMU + + Description: Q[[hIDǂݍ + *---------------------------------------------------------------------------*/ +void ReadIDGame_ROMEMU(CardBootData *cbd) +{ + #pragma unused( cbd ) + + // J[h荞݂ɂDMARs[ + HOTSW_NDmaCopy_Card( HOTSW_DMA_NO, (u32 *)HOTSW_MCD1, &cbd->id_gam, sizeof(cbd->id_gam) ); + + // MCCMD WX^ݒ + reg_HOTSW_MCCMD0 = 0x000000B8; + reg_HOTSW_MCCMD1 = 0x00000000; + + // MCCNT0 WX^ݒ (E = 1 I = 1 SEL = 0) + reg_HOTSW_MCCNT0 = (u16)((reg_HOTSW_MCCNT0 & 0x0fff) | 0xc000); + + // MCCNT1 WX^ݒ (START = 1 PC = 111(Xe[^X[h) latency1 = 1 ) + reg_HOTSW_MCCNT1 = START_MASK | PC_MASK & (0x7 << PC_SHIFT) | (0x1 & LATENCY1_MASK); + + // J[hf[^]I荞݂N܂ŐQ(荞݃nh̒ŋN) + OS_SleepThread(NULL); +} + +/*---------------------------------------------------------------------------* + Name: ReadPageGame_ROMEMU + + Description: Q[[hŁAw肳ꂽy[Wwobt@ɎwTCYǂݍ + *---------------------------------------------------------------------------*/ +void ReadPageGame_ROMEMU(CardBootData *cbd, u32 start_addr, void* buf, u32 size) +{ + #pragma unused( cbd ) + + u32 loop, counter=0; + u64 i, page; + GCDCmd64 cndLE, cndBE; + + page = (u32)(start_addr / PAGE_SIZE); + loop = (u32)(size / PAGE_SIZE); + loop = (size % PAGE_SIZE) ? loop + 1 : loop; + + OS_TPrintf("Src Addr : 0x%08x Dst Addr : 0x%08x\n", start_addr, buf); + OS_TPrintf("Read Game Segment Page Count : %d size : %x\n", loop, size); + + for(i=0; i + +#if defined(SDK_ARM7) +#include +#else +#ifdef SDK_SMALL_BUILD +#include "SYSM_work.h" +#endif +#endif + + +#include // twl/mb.hȂB +#include +#include + +// -------------------------------------------------------------------------- + +// Download̃TCY + +#define MB_OVT_MAX_SIZE MB_COMM_BLOCK_SIZE // OVT̍őTCYiBlockTCYőTCYƂj + +/*----------------------------------------------------------------------------*/ +#define MB_TRIGGER_SIGNAL_TO_ARM7 (0x00000001) + +/*----------------------------------------------------------------------------*/ +static void MIm_CpuClear32( register u32 data, register void *destp, register u32 size ); +static void MIm_CpuClear32( register u32 data, register void *destp, register u32 size ); +static void LOADERi_LocateAllSegments( MBDownloadFileInfo *mdfi ); +static void MBi_SearchAndLocateSegmentInfo( MBDownloadFileInfo *mdfi, u16 processor ); +static void LOADERi_Jump(void); +static void MBi_fifo_callback_arm7(PXIFifoTag tag, u32 msg_adr, BOOL err); + +/*----------------------------------------------------------------------------*/ +static MB_LoaderCallback loader_precallback = NULL; + +/*----------------------------------------------------------------------------*/ + + +#if defined(SDK_ARM7) + +/*---------------------------------------------------------------------------* + Name: MIm_CpuCopy32 + + Description: [_[pCpuCopy + + Arguments: srcp, destp, size + + Returns: void + *---------------------------------------------------------------------------*/ + +#include + +asm void MIm_CpuCopy32( register const void *srcp, register void *destp, register u32 size ) +{ + add r12, r1, r2 // r12: destEndp = destp + size + +@30: + cmp r1, r12 // while (destp < destEndp) + ldmltia r0!, {r2} // *((vu32 *)(destp)++) = *((vu32 *)(srcp)++) + stmltia r1!, {r2} + blt @30 + + bx lr +} + +#ifndef SDK_SMALL_BUILD +static asm void MIm_CpuClear32( register u32 data, register void *destp, register u32 size ) +{ + add r12, r1, r2 // r12: destEndp = destp + size + +@20: + cmp r1, r12 // while (destp < destEndp) + stmltia r1!, {r0} // *((vu32 *)(destp++)) = data + blt @20 + + bx lr +} +#endif + +#include + + +/*---------------------------------------------------------------------------* + Name: LOADERi_LocateAllSegments + + Description: ARM9,ARM7̊eZOgKvɉčĔzuB + + Arguments: mdfi + + Returns: void + *---------------------------------------------------------------------------*/ + +static void LOADERi_LocateAllSegments( MBDownloadFileInfo *mdfi ) +{ + MBi_SearchAndLocateSegmentInfo(mdfi, MI_PROCESSOR_ARM9); // ARM9ZOgɂ‚Ă̔zu + MBi_SearchAndLocateSegmentInfo(mdfi, MI_PROCESSOR_ARM7); // ARM7ZOgɂ‚Ă̔zu +} + + +/* w̃ZOg, Ĕzu */ +static void MBi_SearchAndLocateSegmentInfo( MBDownloadFileInfo *mdfi, u16 processor ) +{ + int i; + MbSegmentInfo *seg_info; + + if( mdfi ) { + for( i = 0 ; i < MB_DL_SEGMENT_NUM ; ++i ) { + seg_info = &mdfi->seg[i]; + if ( seg_info->target == processor ) { + if ( seg_info->recv_addr != seg_info->load_addr ) { + MIm_CpuCopy32( (void*)seg_info->recv_addr, (void*)seg_info->load_addr, seg_info->size ); +#ifndef SDK_SMALL_BUILD // IPL2̏ꍇ́ÃNAIPL2ōsB + MIm_CpuClear32( 0, (void*)seg_info->recv_addr, seg_info->size ); +#endif + } + } + } + } +} + + +/*---------------------------------------------------------------------------* + Name: LOADERi_Jump + + Description: [_[N (ARM7/9 ) + + Arguments: + + Returns: void + *---------------------------------------------------------------------------*/ + +static void LOADERi_Jump(void) +{ +#if defined(SDK_ARM7) + + MBDownloadFileInfo *mdfi = (MBDownloadFileInfo*)MB_DOWNLOAD_FILEINFO_ADDRESS; + MBParam *p_param = (MBParam*)HW_WM_BOOT_BUF; + + if( p_param->boot_type != MB_TYPE_MULTIBOOT ) { // u[g^Cv}`u[głȂꍇ́ATRUE^[B + return; + } + + LOADERi_LocateAllSegments( mdfi ); // u[gvO̍ĔzusB + +#endif +} + + +/*---------------------------------------------------------------------------* + Name: MBi_fifo_callback_arm7 + + Description: p PXI ^OoRŃ[_[N + + Arguments: + + Returns: None. + *---------------------------------------------------------------------------*/ + +static void MBi_fifo_callback_arm7(PXIFifoTag tag, u32 msg_adr, BOOL err) +{ +#pragma unused( err ) + + if (tag == PXI_FIFO_TAG_MB && msg_adr == (u32)MB_TRIGGER_SIGNAL_TO_ARM7) + { + if ( loader_precallback ) { + (*loader_precallback)(); + } + } +} + +#endif /* defined(SDK_ARM7) */ + + +/*---------------------------------------------------------------------------* + Name: LOADER_Start + + Description: [_[̃X^[g + + Arguments: None. + + Returns: TRUE - success FALSE - failed + *---------------------------------------------------------------------------*/ + + +void LOADER_Start(void) +{ + +#if defined(SDK_ARM9) + int result; + MBDownloadFileInfo *mdfi = (MBDownloadFileInfo*)MB_DOWNLOAD_FILEINFO_ADDRESS; + MBParam *p_param = (MBParam*)HW_WM_BOOT_BUF; + + // }`u[g̎̓fobKGgɔ΂Ȃ悤NAB +#ifdef SDK_SMALL_BUILD + GetMovedInfoFromIPL1Addr()->isOnDebugger = 0; // USG-WW-3rd & USG-China-2ndł́AGetSharedWorkAddr()->isOnDebugger̓pb`̈ƃobeBOĂ邪Ã[`ARM9̃}`u[g[`ŌĂ΂ꂽŁAARM7Ńpb`}[`Ă΂̂ŁAvB + // AfobKŃrhɂ́AQƂ鑤isOnDebuggertONAĂȂ̂ŁACB +#endif // SDK_SMALL_BUILD + + // VXëփ}`u[gtO + p_param->boot_type = MB_TYPE_MULTIBOOT; + // e@VXë֏ + MI_CpuCopy8((void*)MB_BSSDESC_ADDRESS, &p_param->parent_bss_desc, MB_BSSDESC_SIZE); + + // ARM7փ[_[Nʒm + result = PXI_SendWordByFifo( PXI_FIFO_TAG_MB, (u32)MB_TRIGGER_SIGNAL_TO_ARM7, FALSE ); + SDK_ASSERTMSG((result >= 0), "ARM9:FIFO SEND ERROR!\n"); + + return; + +#else /* defined(SDK_ARM9) */ + + // [_[R[ + LOADERi_Jump(); + +#endif +} + + +/*---------------------------------------------------------------------------* + Name: LOADER_Init + + Description: [_[̏ + + Arguments: callback - u[g̏oƂɕԂR[obN + + Returns: None. + *---------------------------------------------------------------------------*/ + +void LOADER_Init(MB_LoaderCallback callback) +{ + MBParam *p_param = (MBParam*)HW_WM_BOOT_BUF; + + PXI_Init(); // ĂȂAs + +#if defined(SDK_ARM7) + + loader_precallback = callback; + + /* u[gtO̕␳(}`u[gtOw肳ĂȂꍇROMƂ݂ȂB) */ + if (p_param->boot_type != MB_TYPE_MULTIBOOT) { + p_param->boot_type = MB_TYPE_NORMAL; + } + /* ̏, K MB_TYPE_MULTIBOOT MB_TYPE_NORMAL ɂȂ */ + + // }`u[gĎFIFOR[obNZbg + PXI_SetFifoRecvCallback( PXI_FIFO_TAG_MB, MBi_fifo_callback_arm7 ); + +#else /* defined(SDK_ARM7) */ + + #pragma unused(callback) + +#endif +} + + + +/*----------------------------------------------------------------------------* +/* sgp + *----------------------------------------------------------------------------*/ + +#if defined(LOADER_USE_OVT_BUF) + +//---------------------------------------------------------------------- +// I[o[Ce[u +//---------------------------------------------------------------------- +typedef struct { + u32 id; // I[o[C ID + void *ram_address; // [h擪ʒu + u32 ram_size; // [hTCY + u32 bss_size; // bss ̈TCY + void *sinit_init; // static initializer 擪AhX + void *sinit_init_end; // static initializer ŏIAhX + u32 file_id; // I[o[Ct@CID + u32 rsv; // \B +} ROM_OVT; + + +// OVT̍őTCYiɂ‚Ă͍čl̗]nj +#define MB_OVT_MAX_SIZE MB_COMM_BLOCKSIZE + +// Overlay Table Buffer +// }`u[gvOŁAX^eBbNCjVCUN̂ɕKv +// I[o[Ce[uŗeʂςĂB +// IPL2ɂdlł܂܂ŁAɒuĂ +static u32 mb_ovt_buf[MB_OVT_MAX_SIZE/sizeof(u32)]; + +static void MB_SetOverlayTable(ROM_OVT *srcp, u16 sec_num) +{ + if (srcp && sec_num) + { + MI_CpuCopy8((void*)srcp, (void*)mb_ovt_buf, sec_num*sizeof(ROM_OVT)); + } +} + +#endif diff --git a/build/libraries_sysmenu/reloc_info/ARM7/Makefile b/build/libraries_sysmenu/reloc_info/ARM7/Makefile new file mode 100644 index 00000000..f32176ea --- /dev/null +++ b/build/libraries_sysmenu/reloc_info/ARM7/Makefile @@ -0,0 +1,49 @@ +#! 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-09-27#$ +# $Rev: 1203 $ +# $Author: yada $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED +TWL_PROC = ARM7 + +#---------------------------------------------------------------------------- + +SRCDIR = ../common/src + +SRCS = reloc_info.c + +TARGET_LIB = libreloc_info_sp$(TWL_LIBSUFFIX).a + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(SYSMENU_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== + diff --git a/build/libraries_sysmenu/reloc_info/ARM9/Makefile b/build/libraries_sysmenu/reloc_info/ARM9/Makefile new file mode 100644 index 00000000..b106cb11 --- /dev/null +++ b/build/libraries_sysmenu/reloc_info/ARM9/Makefile @@ -0,0 +1,49 @@ +#! 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-09-27#$ +# $Rev: 1203 $ +# $Author: yada $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED +TWL_PROC = ARM9 + +#---------------------------------------------------------------------------- + +SRCDIR = ../common/src + +SRCS = reloc_info.c + +TARGET_LIB = libreloc_info$(TWL_LIBSUFFIX).a + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(SYSMENU_INSTALL_LIBDIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== + diff --git a/build/libraries_sysmenu/reloc_info/Makefile b/build/libraries_sysmenu/reloc_info/Makefile new file mode 100644 index 00000000..1e0ca3f0 --- /dev/null +++ b/build/libraries_sysmenu/reloc_info/Makefile @@ -0,0 +1,30 @@ +#! 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-09-27#$ +# $Rev: 1203 $ +# $Author: yada $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +SUBDIRS = ARM7 ARM9 + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries_sysmenu/reloc_info/common/src/reloc_info.c b/build/libraries_sysmenu/reloc_info/common/src/reloc_info.c new file mode 100644 index 00000000..f9456674 --- /dev/null +++ b/build/libraries_sysmenu/reloc_info/common/src/reloc_info.c @@ -0,0 +1,138 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: reloc_info.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:: 2007-12-12#$ + $Rev: 355 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include + +// const data------------------------------------------------------------------ + +typedef struct RomSegmentRange { + u32 start; + u32 end; +}RomSegmentRange; + +static RomSegmentRange romSegmentRange[RELOCATE_INFO_NUM] = { + { SYSM_TWL_ARM9_LOAD_MMEM, SYSM_TWL_ARM9_LOAD_MMEM_END }, + { SYSM_TWL_ARM7_LOAD_MMEM, SYSM_TWL_ARM7_LOAD_MMEM_END }, + { SYSM_TWL_ARM9_LTD_LOAD_MMEM, SYSM_TWL_ARM9_LTD_LOAD_MMEM_END }, + { SYSM_TWL_ARM7_LTD_LOAD_MMEM, SYSM_TWL_ARM7_LTD_LOAD_MMEM_END }, +}; + +static RomSegmentRange romSegmentRangeNitro[RELOCATE_INFO_NUM] = { + { SYSM_NTR_ARM9_LOAD_MMEM, SYSM_NTR_ARM9_LOAD_MMEM_END }, + { SYSM_NTR_ARM7_LOAD_MMEM, SYSM_NTR_ARM7_LOAD_MMEM_END }, + { SYSM_TWL_ARM9_LTD_LOAD_MMEM, SYSM_TWL_ARM9_LTD_LOAD_MMEM_END }, + { SYSM_TWL_ARM7_LTD_LOAD_MMEM, SYSM_TWL_ARM7_LTD_LOAD_MMEM_END }, +}; + +static u32 load_region_check_list[RELOCATE_INFO_NUM][RELOCATE_INFO_NUM * 2 - 1] = +{ + {SYSM_NTR_ARM7_LOAD_MMEM, SYSM_NTR_ARM7_LOAD_MMEM_END, + SYSM_TWL_ARM9_LTD_LOAD_MMEM, SYSM_TWL_ARM9_LTD_LOAD_MMEM_END, + SYSM_TWL_ARM7_LTD_LOAD_MMEM, SYSM_TWL_ARM7_LTD_LOAD_MMEM_END, + NULL }, + {SYSM_NTR_ARM9_LOAD_MMEM, SYSM_NTR_ARM9_LOAD_MMEM_END, + SYSM_TWL_ARM9_LTD_LOAD_MMEM, SYSM_TWL_ARM9_LTD_LOAD_MMEM_END, + SYSM_TWL_ARM7_LTD_LOAD_MMEM, SYSM_TWL_ARM7_LTD_LOAD_MMEM_END, + NULL }, + {SYSM_NTR_ARM9_LOAD_MMEM, SYSM_NTR_ARM9_LOAD_MMEM_END, + SYSM_NTR_ARM7_LOAD_MMEM, SYSM_NTR_ARM7_LOAD_MMEM_END, + SYSM_TWL_ARM7_LTD_LOAD_MMEM, SYSM_TWL_ARM7_LTD_LOAD_MMEM_END, + NULL }, + {SYSM_NTR_ARM9_LOAD_MMEM, SYSM_NTR_ARM9_LOAD_MMEM_END, + SYSM_NTR_ARM7_LOAD_MMEM, SYSM_NTR_ARM7_LOAD_MMEM_END, + SYSM_TWL_ARM9_LTD_LOAD_MMEM, SYSM_TWL_ARM9_LTD_LOAD_MMEM_END, + NULL }, +}; + +// ============================================================================ +// +// Ĕzu񐶐 +// +// ============================================================================ + +// ROM̃[ḧ`FbNAĔzu̕Kv΃[hAhXύXAĔzu*infoɃZbgB +// [ḧ悪Ă͂Ȃ̈̃Xgcheck_dest{Jn, I, JnQ, IQ, cc, NULL}̌`B +// Ĕzu̗L薳Ɋւ炸[h”\ȂTRUEA[hs”\ȂFALSEԂ +// ĔzuKvȂꍇAĔzusrc,dest,lengthɂ͂ꂼNULLB +static BOOL SYSMi_CheckLoadRegionAndSetRelocateInfoEx +( u32 *dest, u32 length, RomSegmentRange default_region, u32 *check_dest, Relocate_Info *info ) +{ + MI_CpuClearFast( info, sizeof(Relocate_Info) ); + if( default_region.end - default_region.start < length ) return FALSE;// TCYI[o[ + if( !( default_region.start <= *dest && *dest + length <= default_region.end ) ) + { + // Ĕzu̕Kv + while( *check_dest != NULL ) + { + if( check_dest[0] < *dest + length && *dest < check_dest[1] ) return FALSE;// `FbN̈ɔNG + check_dest += 2; + } + + // ܂ŗĂ΍Ĕzu + // Rs[tOOFF + info->rev = FALSE; + if( default_region.start < *dest + length && *dest + length <= default_region.end ) + { + // ftHgzü̐擪ɁAĔzǔ㕔Ă + // |XgNA + info->post_clear_addr = *dest + length; + info->post_clear_length = default_region.end - (*dest + length); + } + else if( default_region.start <= *dest && *dest < default_region.end ) + { + // ftHgzǚ㕔ɁAĔzu̐擪Ă + // |XgNA + info->post_clear_addr = default_region.start; + info->post_clear_length = *dest - default_region.start; + if( *dest < default_region.start + length ) + { + // XɁAftHgzüɃ[hf[^̍ŌƍĔzu̐擪Ă + // Rs[tOON + info->rev = TRUE; + } + }else + { + // ܂ĂȂ + // |XgNA + info->post_clear_addr = default_region.start; + info->post_clear_length = default_region.end - default_region.start; + } + info->src = default_region.start; + info->dest = *dest; + info->length = length; + *dest = default_region.start; + }else + { + // Ĕzu̕KvȂ + } + return TRUE; +} + +// SYSMi_CheckLoadRegionAndSetRelocateInfoEx̃bp[֐ +BOOL SYSM_CheckLoadRegionAndSetRelocateInfo( RomSegmentName seg, u32 *dest, u32 length, Relocate_Info *info, BOOL isTwlApp) +{ + RomSegmentRange *rsr; + if( isTwlApp ) + { + rsr = romSegmentRange; + }else + { + //NTRp + rsr = romSegmentRangeNitro; + } + return SYSMi_CheckLoadRegionAndSetRelocateInfoEx(dest, length, rsr[seg], load_region_check_list[seg], info); +} diff --git a/build/libraries_sysmenu/sysmenu/ARM7/Makefile b/build/libraries_sysmenu/sysmenu/ARM7/Makefile new file mode 100644 index 00000000..078021b6 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/ARM7/Makefile @@ -0,0 +1,47 @@ +#! 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:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED +TWL_PROC = ARM7 + +SRCDIR = ../common/src +SRCS = status.c \ + pxi.c + +TARGET_LIB = libsysmenu_sp$(TWL_LIBSUFFIX).a + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(SYSMENU_INSTALL_LIBDIR) + +LINCLUDES = $(SYSMENU_ROOT)/build/libraries_sysmenu/sysmenu/common/include + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/libraries_sysmenu/sysmenu/ARM9/Makefile b/build/libraries_sysmenu/sysmenu/ARM9/Makefile new file mode 100644 index 00000000..c7053e78 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/ARM9/Makefile @@ -0,0 +1,62 @@ +#! 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 = + +MYSUBDIRS = ./ + +#---------------------------------------------------------------------------- +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED +TWL_PROC = ARM9 + +SRCS = sysmenu_lib.c \ + util.c \ + ninLogoFunc.c \ + mountInfo.c \ + device.c \ + title.c \ + banner.c \ + ../common/src/status.c \ + ../common/src/pxi.c + + +TARGET_LIB = libsysmenu$(TWL_LIBSUFFIX).a + +include $(TWLSDK_ROOT)/add-ins/es/commondefs.es +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(SYSMENU_INSTALL_LIBDIR) + +LINCLUDES = $(ROOT)/build/libraries/mb/common/include \ + $(ROOT)/build/libraries/spi/ARM9/include \ + $(SYSMENU_ROOT)/build/libraries_sysmenu/sysmenu/common/include + +#---------------------------------------------------------------------------- + +do-build: $(MYSUBDIRS) $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +$(MYSUBDIRS):: +# $(MAKE) -C $@ -f MakeCrt0 + +#===== End of Makefile ===== diff --git a/build/libraries_sysmenu/sysmenu/ARM9/src/banner.c b/build/libraries_sysmenu/sysmenu/ARM9/src/banner.c new file mode 100644 index 00000000..a32b138d --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/ARM9/src/banner.c @@ -0,0 +1,107 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: SYSM_lib.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "internal_api.h" + +// define data----------------------------------------------------------------- +typedef struct BannerCheckParam { + u8 *pSrc; + u32 size; +}BannerCheckParam; + +// extern data----------------------------------------------------------------- +// function's prototype------------------------------------------------------- +static BOOL SYSMi_CheckBannerFile( NTRBannerFile *pBanner ); + +// global variable------------------------------------------------------------- +// static variable------------------------------------------------------------- + +// const data------------------------------------------------------------------ + +// ============================================================================ +// +// oi[ +// +// ============================================================================ + +// J[hoi[[hiNTR-IPL2dlj +BOOL SYSMi_ReadCardBannerFile( u32 bannerOffset, TWLBannerFile *pBanner ) +{ +#ifndef DEBUG_USED_CARD_SLOT_B_ + // XbgÃ[hȂȂAXbgB͒ړǂ߂Ȃ̂ + BOOL isRead; + u16 id = (u16)OS_GetLockID(); + + // ROMJ[h̃oi[f[^̃[h + DC_FlushRange( pBanner, sizeof(TWLBannerFile) ); + CARD_LockRom( id ); + CARD_ReadRom( 4, (void *)bannerOffset, pBanner, sizeof(TWLBannerFile) ); + CARD_UnlockRom( id ); + OS_ReleaseLockID( id ); + + isRead = SYSMi_CheckBannerFile( (NTRBannerFile *)pBanner ); + + if( !isRead ) { + MI_CpuClearFast( pBanner, sizeof(TWLBannerFile) ); + } + return isRead; +#else +#pragma unused(bannerOffset) + if( SYSMi_GetWork()->flags.common.isValidCardBanner ) { + DC_InvalidateRange( (void *)SYSM_CARD_BANNER_BUF, 0x3000 ); + MI_CpuCopyFast( (void *)SYSM_CARD_BANNER_BUF, pBanner, sizeof(TWLBannerFile) ); + } + return (BOOL)SYSMi_GetWork()->flags.common.isValidCardBanner; +#endif +} + + + // oi[f[^̐`FbN +static BOOL SYSMi_CheckBannerFile( NTRBannerFile *pBanner ) +{ + int i; + BOOL retval = TRUE; + u16 calc_crc = 0xffff; + u16 *pHeaderCRC = (u16 *)&pBanner->h.crc16_v1; + BannerCheckParam bannerCheckList[ BANNER_VER_NTR_MAX ]; + BannerCheckParam *pChk = &bannerCheckList[ 0 ]; + + bannerCheckList[ 0 ].pSrc = (u8 *)&( pBanner->v1 ); + bannerCheckList[ 0 ].size = sizeof( BannerFileV1 ); + bannerCheckList[ 1 ].pSrc = (u8 *)&( pBanner->v2 ); + bannerCheckList[ 1 ].size = sizeof( BannerFileV2 ); + bannerCheckList[ 2 ].pSrc = (u8 *)&( pBanner->v3 ); + bannerCheckList[ 2 ].size = sizeof( BannerFileV3 ); + + for( i = 0; i < BANNER_VER_NTR_MAX; i++ ) { + if( i < pBanner->h.version ) { + calc_crc = SVC_GetCRC16( calc_crc, pChk->pSrc, pChk->size ); + if( calc_crc != *pHeaderCRC++ ) { + retval = FALSE; + break; + } + }else { + MI_CpuClear16( pChk->pSrc, pChk->size ); + } + pChk++; + } + + return retval; +} + diff --git a/build/libraries_sysmenu/sysmenu/ARM9/src/device.c b/build/libraries_sysmenu/sysmenu/ARM9/src/device.c new file mode 100644 index 00000000..04de3aa9 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/ARM9/src/device.c @@ -0,0 +1,134 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: SYSM_lib.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include "internal_api.h" + +// define data----------------------------------------------------------------- +// extern data----------------------------------------------------------------- +// function's prototype------------------------------------------------------- +#ifdef SDK_FINALROM +u32 PM_SendUtilityCommandAsync(u32 number, u16 parameter, u16* retValue, PMCallback callback, void *arg); +u32 PM_SendUtilityCommand(u32 number, u16 parameter, u16* retValue); +u32 PMi_WriteRegister(u16 registerAddr, u16 data); +u32 PMi_WriteRegisterAsync(u16 registerAddr, u16 data, PMCallback callback, void *arg); +#endif // SDK_FINALROM + +// global variable------------------------------------------------------------- +// static variable------------------------------------------------------------- +// const data------------------------------------------------------------------ + +// ============================================================================ +// +// foCX +// +// ============================================================================ + +// obNCgPx +void SYSM_SetBackLightBrightness( u8 brightness ) +{ + if( brightness > LCFG_TWL_BACKLIGHT_LEVEL_MAX ) { + OS_Panic( "Backlight brightness over : %d\n", brightness ); + } + ( void )PMi_WriteRegister( 0x20, (u16)brightness ); + LCFG_TSD_SetBacklightBrightness( brightness ); + + // [TODO:] obNCgPx͖Z[uɁAAvN⃊ZbgAdOFFɒlςĂZ[u悤ɂB + LCFG_WriteTWLSettings(); +} + + +// ^b`plLu[V +void SYSM_CaribrateTP( void ) +{ + LCFGTWLTPCalibData store; + TPCalibrateParam calibParam; + + // {̐ݒf[^Lu[V擾 + LCFG_TSD_GetTPCalibration( &store ); + + // TPLu[V + ( void )TP_CalcCalibrateParam( &calibParam, // ^b`pl + store.data.raw_x1, store.data.raw_y1, (u16)store.data.dx1, (u16)store.data.dy1, + store.data.raw_x2, store.data.raw_y2, (u16)store.data.dx2, (u16)store.data.dy2 ); + TP_SetCalibrateParam( &calibParam ); + OS_TPrintf("TP_calib: %4d %4d %4d %4d %4d %4d\n", + store.data.raw_x1, store.data.raw_y1, (u16)store.data.dx1, (u16)store.data.dy1, + store.data.raw_x2, store.data.raw_y2, (u16)store.data.dx2, (u16)store.data.dy2 ); +} + + +// RTCNbN␳lZbg +void SYSMi_WriteAdjustRTC( void ) +{ + RTCRawAdjust raw; + raw.adjust = LCFG_THW_GetRTCAdjust(); + ( void )RTCi_SetRegAdjust( &raw ); +} + + +// NRTC`FbN +void SYSMi_CheckRTC( void ) +{ + RTCDate date; + RTCTime time; + + // RTC̃Zbg or loꍇ͏NV[PXցB + ( void )RTC_GetDateTime( &date, &time ); + if( !SYSM_CheckRTCDate( &date ) || + !SYSM_CheckRTCTime( &time ) +#ifndef __IS_DEBUGGER_BUILD // ƒfobKłRTC̓drȂ̂ŁA񂱂ɂЂĐݒf[^ЕNAĂ܂BhXCb`B + || + SYSMi_GetWork()->flags.common.isResetRTC +#endif + ) { // RTCُ̈oArtc̓tOrtcOffset0ɂNVRAMɏ݁B + OS_TPrintf("\"RTC reset\" or \"Illegal RTC data\" detect!\n"); + LCFG_TSD_SetFlagDateTime( FALSE ); + LCFG_TSD_SetRTCOffset( 0 ); + LCFG_TSD_SetRTCLastSetYear( 0 ); + LCFG_WriteTWLSettings(); + } +} + + +#ifdef SDK_FINALROM +/*---------------------------------------------------------------------------* + Name: PMi_WriteRegisterAsync + + Description: send write register command to ARM7 + + Arguments: registerAddr : PMIC register number (0-3) + data : data written to PMIC register + callback : callback function + arg : callback argument + + Returns: result of issueing command + PM_RESULT_BUSY : busy + PM_RESULT_SUCCESS : success + *---------------------------------------------------------------------------*/ +u32 PMi_WriteRegisterAsync(u16 registerAddr, u16 data, PMCallback callback, void *arg) +{ + return PM_SendUtilityCommandAsync(PMi_UTIL_WRITEREG, (u16)((registerAddr<<16) | (data&0xff)), NULL, callback, arg); +} + +u32 PMi_WriteRegister(u16 registerAddr, u16 data) +{ + return PM_SendUtilityCommand(PMi_UTIL_WRITEREG, (u16)((registerAddr<<16) | (data&0xff)), NULL); +} +#endif // SDK_FINALROM diff --git a/build/libraries_sysmenu/sysmenu/ARM9/src/mountInfo.c b/build/libraries_sysmenu/sysmenu/ARM9/src/mountInfo.c new file mode 100644 index 00000000..af0699c8 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/ARM9/src/mountInfo.c @@ -0,0 +1,272 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: SYSM_lib.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include "internal_api.h" + +// define data----------------------------------------------------------------- +#define DEFAULT_MOUNT_LIST_NUM 7 +#define PRV_SAVE_DATA_MOUNT_INDEX 5 // vCx[gZ[uf[^ s_defaultMountInfo XgCfbNX +#define PUB_SAVE_DATA_MOUNT_INDEX 6 // pubN@Z[uf[^ s_defaultMountInfo XgCfbNX + +#define TITLEID_APP_SYS_FLAG_SHIFT ( 32 + 0 ) +#define TITLEID_NOT_LAUNCH_FLAG_SHIFT ( 32 + 1 ) +#define TITLEID_MEDIA_NAND_FLAG_SHIFT ( 32 + 2 ) +#define TITLEID_APP_SYS_FLAG ( 1ULL << TITLEID_APP_SYS_FLAG_SHIFT ) +#define TITLEID_NOT_LAUNCH_FLAG ( 1ULL << TITLEID_NOT_LAUNCH_FLAG_SHIFT ) +#define TITLEID_MEDIA_NAND_FLAG ( 1ULL << TITLEID_MEDIA_NAND_FLAG_SHIFT ) + + +// extern data----------------------------------------------------------------- +// function's prototype-------------------------------------------------------- +static void SYSMi_SetBootSRLPath( LauncherBootType bootType, NAMTitleId titleID ); +static void SYSMi_SetMountInfoCore( LauncherBootType bootType, NAMTitleId titleID, OSMountInfo *pSrc ); +static void SYSMi_ModifySaveDataMount( LauncherBootType bootType, NAMTitleId titleID, OSMountInfo *pMountTgt ); +static void SYSMi_ModifySaveDataMountForLauncher( LauncherBootType bootType, NAMTitleId titleID, OSMountInfo *pMountTgt ); + +// global variable------------------------------------------------------------- +// static variable------------------------------------------------------------- +// const data------------------------------------------------------------------ + +// ftHg}Eg񃊃Xg +OSMountInfo s_defaultMountList[ DEFAULT_MOUNT_LIST_NUM ] ATTRIBUTE_ALIGN(4) = { +// drive device target pertitionIdx resource userPermission rsvA B archive path + { 'A', OS_MOUNT_DEVICE_SD, OS_MOUNT_TGT_ROOT, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "sdmc", "/" }, + { 'B', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_ROOT, 0, OS_MOUNT_RSC_WRAM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "nand", "/" }, // [U[Av͂̃A[JCułWrites + { 'C', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_ROOT, 1, OS_MOUNT_RSC_WRAM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "nand2", "/" }, // [U[Av͂̃A[JCułWrites + { 'D', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_DIR, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "shared2", "nand2:/shared2" }, + { 'E', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_DIR, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "photo", "nand2:/photo" }, + { 'F', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_FILE, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "dataPrv", NULL }, // NANDɃZ[uf[^ȂAv̏ꍇ́A}EgȂB + { 'G', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_FILE, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "dataPub", NULL }, // NANDɃZ[uf[^ȂAv̏ꍇ́A}EgȂB +}; + + +// ============================================================================ +// +// }EgZbg +// +// ============================================================================ + +/* + vmF + J[hu[gBootSRLPath́A"rom:"ł͂ȂA""łB + "nand:" "nand1:"userPermission"OS_MOUNT_USR_R"ŗǂ̂H +*/ +// `[̃}EgZbg +void SYSMi_SetLauncherMountInfo( void ) +{ + NAMTitleId titleID = TITLE_ID_LAUNCHER; + + // Ƃ肠gROMu[gŁB[TODO:]ŏC +// SYSMi_SetBootSRLPath( LAUNCHER_BOOTTYPE_NAND, titleID ); // SDK2623ł́ABootSRLPath"rom:"ƂFSi_InitRomArchiveNANDAvăANZXOŗB + + // Z[uf[^Lɂ}Eg̕ҏW + // ̃^C~OłFS͓Ȃ̂ŁAFSgȂʔłőΉB + SYSMi_ModifySaveDataMountForLauncher( LAUNCHER_BOOTTYPE_NAND, + titleID, + &s_defaultMountList[ PRV_SAVE_DATA_MOUNT_INDEX ] ); + + // }Eg̃Zbg + SYSMi_SetMountInfoCore( LAUNCHER_BOOTTYPE_NAND, + titleID, + &s_defaultMountList[0] ); +} + + +// VXëɁAu[gAṽ}Ego^ +void SYSMi_SetBootAppMountInfo( TitleProperty *pBootTitle ) +{ + // AvTWLΉłȂꍇ́AZbgɃ^[ + if( ( (( ROM_Header_Short *)HW_TWL_ROM_HEADER_BUF)->platform_code ) == 0 ) { + return; + } + + // NAvSRLpXZbg + SYSMi_SetBootSRLPath( (LauncherBootType)pBootTitle->flags.bootType, + pBootTitle->titleID ); + + // Z[uf[^Lɂ}Eg̕ҏW + SYSMi_ModifySaveDataMount( (LauncherBootType)pBootTitle->flags.bootType, + pBootTitle->titleID, + &s_defaultMountList[ PRV_SAVE_DATA_MOUNT_INDEX ] ); + + // }Eg̃Zbg + SYSMi_SetMountInfoCore( (LauncherBootType)pBootTitle->flags.bootType, + pBootTitle->titleID, + &s_defaultMountList[0] ); + + /* + @Ӂ@ + MountInfóAFSŒڎQƂăANZXԂ𔻒肵Ă邽߁AɃAvp̃f[^ZbgƁA + ̌̓p[~bV̓sFSCuFSgpESNAMCuSgpłȂȂBip[~bVdlɂ‚Ă͕ύX”\j + āAFSCugp鏈́A{̑OɊĂKvB + */ +} + + +// NSRLpXVXëɃZbg +static void SYSMi_SetBootSRLPath( LauncherBootType bootType, NAMTitleId titleID ) +{ + static char path[ FS_ENTRY_LONGNAME_MAX ]; + + switch( bootType ) + { + case LAUNCHER_BOOTTYPE_NAND: + if( NAM_GetTitleBootContentPathFast( path, titleID ) != NAM_OK ) { + OS_TPrintf( "ERROR: BootContentPath Get failed.\n" ); + } + break; + case LAUNCHER_BOOTTYPE_TEMP: + STD_TSNPrintf( path, 31, "nand:/tmp/%.16llx.srl", titleID ); + break; + default: + path[ 0 ] = 0; +// STD_StrCpy( path, (const char*)"rom:" ); // SDK2623ł́ABootSRLPath"rom:"ƂFSi_InitRomArchiveNANDAvăANZXOŗB + break; + } + + if( path[ 0 ] ) { + STD_CopyLStringZeroFill( (char *)HW_TWL_FS_BOOT_SRL_PATH_BUF, path, OS_MOUNT_PATH_LEN ); + }else { + MI_CpuClearFast( (void *)HW_TWL_FS_BOOT_SRL_PATH_BUF, OS_MOUNT_PATH_LEN ); + } + OS_TPrintf( "boot SRL path : %s\n", (char *)HW_TWL_FS_BOOT_SRL_PATH_BUF ); // OS_InitOŌĂԂPrintfłȂ̂ŒӁB +} + + +// }EgVXëɏ +static void SYSMi_SetMountInfoCore( LauncherBootType bootType, NAMTitleId titleID, OSMountInfo *pSrc ) +{ +#pragma unused(bootType) + + int i; + OSMountInfo *pDst = (OSMountInfo *)HW_TWL_FS_MOUNT_INFO_BUF; + + MI_CpuClearFast( (void *)HW_TWL_FS_MOUNT_INFO_BUF, HW_TWL_FS_BOOT_SRL_PATH_BUF - HW_TWL_FS_MOUNT_INFO_BUF ); + + // [U[Av̏ꍇA"nand:", "nand2:"A[JCuύXB + if( ( titleID & TITLEID_APP_SYS_FLAG ) == 0 ) { + pSrc[ 1 ].userPermission = 0; // "nand:" + pSrc[ 2 ].userPermission = 0; // "nand2:" + } + + // Zbg + for( i = 0; i < DEFAULT_MOUNT_LIST_NUM; i++ ) { + if( pSrc->drive[ 0 ] ) { + MI_CpuCopyFast( pSrc, pDst, sizeof(OSMountInfo) ); + pDst++; + } + pSrc++; + } +#if 0 + pDst = (OSMountInfo *)HW_TWL_FS_MOUNT_INFO_BUF; + for( i = 0; i < DEFAULT_MOUNT_LIST_NUM; i++ ) { + OS_TPrintf( "mount path : %s\n", pDst->path ); + pDst++; + } +#endif +} + + +// ^CgIDƂɃZ[uf[^L𔻒肵āA}EgҏWB +static void SYSMi_ModifySaveDataMount( LauncherBootType bootType, NAMTitleId titleID, OSMountInfo *pMountTgt ) +{ + int i; + + // J[hu[gꂽꍇłAtitleID"NANDAv"̏ꍇ́AZ[uf[^}Eg悤ɂĂB + + // Z[uf[^L𔻒肵āApXZbg + if( ( ( bootType == LAUNCHER_BOOTTYPE_NAND ) && // NANDAvNANDu[gꂽ + ( titleID & TITLEID_MEDIA_NAND_FLAG ) ) || + ( ( bootType == LAUNCHER_BOOTTYPE_ROM ) && // ISfobKŁANANDAvROM u[gꂽ + ( titleID & TITLEID_MEDIA_NAND_FLAG ) && + ( SYSMi_GetWork()->flags.common.isOnDebugger ) ) + ) { + char saveFilePath[ 2 ][ FS_ENTRY_LONGNAME_MAX ]; + u32 saveDataSize[ 2 ]; + saveDataSize[ 0 ] = (( ROM_Header_Short *)HW_TWL_ROM_HEADER_BUF)->private_save_data_size; + saveDataSize[ 1 ] = (( ROM_Header_Short *)HW_TWL_ROM_HEADER_BUF)->public_save_data_size; + + // Z[uf[^̃t@CpX擾 + NAM_GetTitleSaveFilePath( saveFilePath[ 1 ], saveFilePath[ 0 ], titleID ); + + // "ROMwb_NANDZ[ut@CTCY > 0" ̃t@CJꍇ̂݃}Ego^ + for( i = 0; i < 2; i++ ) { + FSFile file[1]; + FS_InitFile( file ); + if( saveDataSize[ i ] && + FS_OpenFileEx( file, saveFilePath[ i ], FS_FILEMODE_R) ) { + FS_CloseFile( file ); + STD_CopyLStringZeroFill( pMountTgt->path, saveFilePath[ i ], OS_MOUNT_PATH_LEN ); + }else { + pMountTgt->drive[ 0 ] = 0; + } + pMountTgt++; + } + }else { + // ^CgIDwȂ̃J[hAv̏ꍇ́AZ[uf[^ + for( i = 0; i < 2; i++ ) { + pMountTgt->drive[ 0 ] = 0; + } + } +} + + +// ^CgIDƂɃZ[uf[^L𔻒肵āA}EgҏWB +static void SYSMi_ModifySaveDataMountForLauncher( LauncherBootType bootType, NAMTitleId titleID, OSMountInfo *pMountTgt ) +{ + int i; + + // J[hu[gꂽꍇłAtitleID"NANDAv"̏ꍇ́AZ[uf[^}Eg悤ɂĂB + + // Z[uf[^L𔻒肵āApXZbg + if( ( ( bootType == LAUNCHER_BOOTTYPE_NAND ) && // NANDAvNANDu[gꂽ + ( titleID & TITLEID_MEDIA_NAND_FLAG ) ) || + ( ( bootType == LAUNCHER_BOOTTYPE_ROM ) && // ISfobKŁANANDAvROM u[gꂽ + ( titleID & TITLEID_MEDIA_NAND_FLAG ) && + ( SYSMi_GetWork()->flags.common.isOnDebugger ) ) + ) { + char saveFilePath[ 2 ][ FS_ENTRY_LONGNAME_MAX ]; + u32 saveDataSize[ 2 ]; + saveDataSize[ 0 ] = (( ROM_Header_Short *)HW_TWL_ROM_HEADER_BUF)->private_save_data_size; + saveDataSize[ 1 ] = (( ROM_Header_Short *)HW_TWL_ROM_HEADER_BUF)->public_save_data_size; + + // Z[uf[^̃t@CpX擾 + STD_TSNPrintf( saveFilePath[ 0 ], FS_ENTRY_LONGNAME_MAX, + "nand:/title/%08x/%08x/data/private.sav", (u32)( titleID >> 32 ), titleID ); + STD_TSNPrintf( saveFilePath[ 1 ], FS_ENTRY_LONGNAME_MAX, + "nand:/title/%08x/%08x/data/public.sav", (u32)( titleID >> 32 ), titleID ); + + // "ROMwb_NANDZ[ut@CTCY > 0" ̃t@CJꍇ̂݃}Ego^ + for( i = 0; i < 2; i++ ) { + if( saveDataSize[ i ] ) { + STD_CopyLStringZeroFill( pMountTgt->path, saveFilePath[ i ], OS_MOUNT_PATH_LEN ); + }else { + pMountTgt->drive[ 0 ] = 0; + } + pMountTgt++; + } + }else { + // ^CgIDwȂ̃J[hAv̏ꍇ́AZ[uf[^ + for( i = 0; i < 2; i++ ) { + pMountTgt->drive[ 0 ] = 0; + } + } +} + diff --git a/build/libraries_sysmenu/sysmenu/ARM9/src/ninLogoFunc.c b/build/libraries_sysmenu/sysmenu/ARM9/src/ninLogoFunc.c new file mode 100644 index 00000000..135feaf7 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/ARM9/src/ninLogoFunc.c @@ -0,0 +1,195 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: ninLogoFunc.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include + +// define data----------------------------------------------------------- + +// extern data----------------------------------------------------------- + +// function's prototype-------------------------------------------------- +static void UnCompNintendoLogo2(u16 *pLogoData, u16 *pDst, u32 *pTemp ); +static void SVC_DiffUnFilter16_16_2( u16 *pSrc, u16 *pDst ); +static s32 MEMBm_InitFunc( const u8 *pDevice, void *pRAM, const void *pParam ); +static s32 MEMBm_TerminateFunc( const u8 *pDevice ); +static u8 MEMBm_ByteStreamFunc( const u8 *pDevice ); +static u32 MEMBm_WordStreamFunc( const u8 *pDevice ); + + +// global variable------------------------------------------------------- + +// static variable------------------------------------------------------- +static MIUnpackBitsParam Nin_UnPackBitsParam2 = { (8 * 8 / 2) * ( 7 * 2 ), + 1, + 4, // J[bit(4=4bit=16F, 8=8bit=256F) + 0, + 0 }; + +// const data------------------------------------------------------------ +static const u8 Nin_Char_Diff_Huff_Table2[]={ + 0x24,0xd4,0x00,0x00, + 0x0f,0x40,0x00,0x00,0x00,0x01,0x81,0x82,0x82,0x83,0x0f,0x83,0x0c,0xc3,0x03,0x83, + 0x01,0x83,0x04,0xc3,0x08,0x0e,0x02,0xc2,0x0d,0xc2,0x07,0x0b,0x06,0x0a,0x05,0x09, +}; + + +const MIReadStreamCallbacks memb_ifp2={ + MEMBm_InitFunc, + MEMBm_TerminateFunc, + MEMBm_ByteStreamFunc, + NULL, + MEMBm_WordStreamFunc, +}; + + +// function's description-------------------------------------------- + +// NintendoS`FbN u^[@1:NintendoSF@0Fsv +BOOL SYSM_CheckNintendoLogo( u16 *pLogoData ) +{ + u16 *pLogoOrg = (u16 *)SYSROM9_NINLOGO_ADR; // ARM9̃VXeROM̃Sf[^ƃJ[gbŴ̂r + u16 length = NINTENDO_LOGO_DATA_LENGTH >> 1; + + while( length-- ) { + if( *pLogoOrg++ != *pLogoData++ ) { + return FALSE; + } + } + return TRUE; +} + + +// NintendoSf[^̓WJ[`iOBJ2D}bv[hœWJj +// tempBuffpɂ́A0x700byteKvłB +void SYSM_LoadNintendoLogo2D( u16 *pLogoData, u16 *pDst, int paletteColorIndex ) +{ + u32 work[ 0x100 / sizeof(u32) ]; + u16 *pBuffer = SYSM_Alloc( 0x700 ); + if( pBuffer == NULL ) { + OS_Panic( "memory allocation failed.\n" ); + } + Nin_UnPackBitsParam2.destOffset = paletteColorIndex - 1; + UnCompNintendoLogo2( pLogoData, (u16 *)pBuffer, work ); + MI_CpuCopy16( (u16 *)( (u32)pBuffer + 0 ), pDst + 0x0000 / sizeof(u16), 0x1a0 ); + MI_CpuCopy16( (u16 *)( (u32)pBuffer + 0x1a0), pDst + 0x0400 / sizeof(u16), 0x1a0 ); + SYSM_Free( pBuffer ); +} + + +void SYSM_LoadNintendoLogo1D( u16 *pLogoData, u16 *pDst, int paletteColorIndex ) +{ + u32 work[ 0x100 / sizeof(u32) ]; + u16 *pBuffer = SYSM_Alloc( 0x700 ); + if( pBuffer == NULL ) { + OS_Panic( "memory allocation failed.\n" ); + } + Nin_UnPackBitsParam2.destOffset = paletteColorIndex - 1; + UnCompNintendoLogo2( pLogoData, (u16 *)pBuffer, work ); + MI_CpuCopy16( (u16 *)pBuffer, pDst, 0x340 ); + SYSM_Free( pBuffer ); +} + +/* UnCompNintendoLogo2[N + + zu恄 dstp(0x700) temp(0x100) + + NintendoS{wb_ 0x0c0 + nt}WJobt@ 0x200 + nt}WJ̃obt@ 0x0d0 + diff̃f[^ 0x0d0 + UnpackBits̃f[^ 0x700 + +*/ + +//@NintendoSWJ[`@(r0=Skf[^ r1=WJAhX) +#include +static asm void UnCompNintendoLogo2( u16 *pLogoData, u16 *pDst, u32 *pTemp ) +{ + push {r0-r2,r4, lr} + + ldr r0, =Nin_Char_Diff_Huff_Table2 + mov r1, r2 // r1 <- temp + mov r4, r1 // r4 <- temp + mov r2, #36 + bl MIi_CpuCopy16 // NintendoS̈ke[û݂Rs[Ă + + ldr r0, [sp, #0] // r0 <- NintendoLogoDatap + mov r2, #36 + add r1, r4, r2 // r1 <- temp + 36 + mov r2, #NINTENDO_LOGO_DATA_LENGTH + bl MIi_CpuCopy16 // NintendoLogoDatapNintendoSf[^{̂Rs[Ă + + mov r0, r4 // r0 <- temp + ldr r1, [sp, #4] // r1 <- dstp + mov r2, #1 + lsl r2, r2, #8 + add r2, r2, r1 // r2 <- dstp + 0x100 + ldr r3, =memb_ifp2 // r3 <- memb_ifp2 + bl SVC_UncompressHuffmanFromDevice // nt}WJ + + ldr r0, [sp, #4] + ldr r2, =0x0000d082 + str r2, [r0,#0] + + mov r1, r4 // temp + bl SVC_DiffUnFilter16_16_2 // DiffWJ + + mov r0, r4 // temp + ldr r1, [sp, #4] // dstp + ldr r2, =Nin_UnPackBitsParam2 + bl SVC_UnpackBits // rbgWJ + + pop {r0-r2,r4, pc} +} + + +// tB^WJVXeR[i16Bit16Bitj (r0=Srcp, r1=Destp) +static asm void SVC_DiffUnFilter16_16_2( u16 *pSrc, u16 *pDst ) +{ + swi 24 + bx lr +} +#include + + +// ============================================================================ +// oCgANZX”\pANZX[`Q +// ============================================================================ +static s32 MEMBm_InitFunc( const u8 *pDevice, void *pRAM, const void *pParam ) +{ + #pragma unused(pRAM) + if(pParam) return (s32)MEMBm_WordStreamFunc(pDevice); + else return 0; +} + +static s32 MEMBm_TerminateFunc( const u8 *pDevice ) +{ + #pragma unused(pDevice) + return 0; +} + +static u8 MEMBm_ByteStreamFunc( const u8 *pDevice ) +{ + return *pDevice; +} + +static u32 MEMBm_WordStreamFunc( const u8 *pDevice ) +{ + return *(u32 *)pDevice; +} diff --git a/build/libraries_sysmenu/sysmenu/ARM9/src/sysmenu_lib.c b/build/libraries_sysmenu/sysmenu/ARM9/src/sysmenu_lib.c new file mode 100644 index 00000000..1d4b0384 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/ARM9/src/sysmenu_lib.c @@ -0,0 +1,272 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: SYSM_lib.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "internal_api.h" + +// define data----------------------------------------------------------------- +// extern data----------------------------------------------------------------- +extern void LCFG_VerifyAndRecoveryNTRSettings( void ); + +// function's prototype------------------------------------------------------- +static TitleProperty *SYSMi_CheckShortcutBoot( void ); +static void SYSMi_CheckCardCloneBoot( void ); + +// global variable------------------------------------------------------------- +void *(*SYSMi_Alloc)( u32 size ); +void (*SYSMi_Free )( void *ptr ); + +#define SYSM_DEBUG_ +#ifdef SYSM_DEBUG_ +SYSM_work *pSysm; // fobKłSYSM[ÑEHb`p +ROM_Header_Short *pRomHeader; +#endif +// static variable------------------------------------------------------------- + +static TitleProperty s_bootTitleBuf; + +// const data------------------------------------------------------------------ + +// ============================================================================ +// +// +// +// ============================================================================ + +// SystemMenȕ +void SYSM_Init( void *(*pAlloc)(u32), void (*pFree)(void*) ) +{ +#ifdef SYSM_DEBUG_ + pSysm = SYSMi_GetWork(); + pRomHeader = (ROM_Header_Short *)0x027fc000; +#endif /* SYSM_DEBUG_ */ + + // `[̃}EgZbg + SYSMi_SetLauncherMountInfo(); + + // ARM7R|[lgpveNVjbg̈ύX + OS_SetProtectionRegion( 2, SYSM_OWN_ARM7_MMEM_ADDR, 512KB ); + + SYSM_SetAllocFunc( pAlloc, pFree ); + + // PXI_SetFifoRecvCallback( SYSMENU_PXI_FIFO_TAG, SYSMi_PXIFifoRecvCallback ); + + reg_OS_PAUSE |= REG_OS_PAUSE_CHK_MASK; // PAUSEWX^̃`FbNtÕZbg +} + + +// A[iĐݒ +void SYSM_SetArena( void ) +{ + // ARM9pu[gR[hzû߁AA[iHiʒu + OS_SetMainArenaHi( (void *)SYSM_OWN_ARM9_MMEM_ADDR_END ); +} + + +// VXej[CupAP[^̐ݒ +void SYSM_SetAllocFunc( void *(*pAlloc)(u32), void (*pFree)(void*) ) +{ + SYSMi_Alloc = pAlloc; + SYSMi_Free = pFree; +} + + +// Alloc +void *SYSM_Alloc( u32 size ) +{ + void *p = SYSMi_Alloc( size ); + OS_TPrintf( "SYSM_Alloc : %08x %xbytes\n", p, size ); + return p; +} + + +// Free +void SYSM_Free( void *ptr ) +{ + OS_TPrintf( "SYSM_Free : %08x\n", ptr ); + SYSMi_Free( ptr ); +} + + +// ============================================================================ +// +// 擾 +// +// ============================================================================ + +// p[^[h +TitleProperty *SYSM_ReadParameters( void ) +{ + TitleProperty *pBootTitle = NULL; + u8 brightness = LCFG_TWL_BACKLIGHT_LEVEL_MAX; + + // ARM7̃Zbgp[^擾̂҂ + while( !SYSMi_GetWork()->flags.common.isARM9Start ) { + SVC_WaitByLoop( 0x1000 ); + } +#ifdef DEBUG_USED_CARD_SLOT_B_ + // ARM7̃J[h`FbN҂ + while( !SYSMi_GetWork()->flags.common.is1stCardChecked ) { + SVC_WaitByLoop( 0x1000 ); + } +#endif + + //----------------------------------------------------- + // Zbgp[^̔iZbgp[^Lǂ́AARM7łĂĂj + //----------------------------------------------------- + { + if( SYSM_GetLauncherParamBody()->v1.flags.isLogoSkip || // SfXLbvH + SYSMi_IsDebuggerBannerViewMode() ) { + SYSM_SetLogoDemoSkip( TRUE ); + } + + if( SYSM_GetLauncherParamBody()->v1.bootTitleID ) { // AvڋN̎w肪烍Sf΂ĎwAvN + s_bootTitleBuf.titleID = SYSM_GetLauncherParamBody()->v1.bootTitleID; + s_bootTitleBuf.flags = SYSM_GetLauncherParamBody()->v1.flags; + s_bootTitleBuf.pBanner = (TWLBannerFile *)(*(TWLBannerFile **)(SYSM_GetLauncherParamBody()->v1.rsv)); + pBootTitle = &s_bootTitleBuf; + } + } + + //----------------------------------------------------- + // ʎYHpV[gJbgL[ or + // J[hN + //----------------------------------------------------- + if( pBootTitle == NULL ) { + pBootTitle = SYSMi_CheckShortcutBoot(); + } + + //----------------------------------------------------- + // HW̃[h + //----------------------------------------------------- + // m[}񃊁[h + if( !LCFG_ReadHWNormalInfo() ) { + OS_TPrintf( "HW Normal Info Broken!\n" ); + SYSMi_GetWork()->flags.common.isBrokenHWNormalInfo = TRUE; + } + // ZLA񃊁[h + if( !LCFG_ReadHWSecureInfo() ) { + OS_TPrintf( "HW Secure Info Broken!\n" ); + SYSMi_GetWork()->flags.common.isBrokenHWSecureInfo = TRUE; + SYSMi_GetWork()->flags.common.isFatalError = TRUE; + } + + //----------------------------------------------------- + // {̐ݒf[^̃[h + //----------------------------------------------------- + if( LCFG_ReadTWLSettings() ) { // NANDTWL{̐ݒf[^[h + SYSM_CaribrateTP(); // ǂݏoTWL{̐ݒf[^ƂTPLu[VB + brightness = (u8)LCFG_TSD_GetBacklightBrightness(); + } + + //----------------------------------------------------- + // efoCXݒ + //----------------------------------------------------- + // obNCgPxݒ + SYSM_SetBackLightBrightness( brightness ); + // RTC␳ + SYSMi_WriteAdjustRTC(); + // RTCl̃`FbN + SYSMi_CheckRTC(); + + LCFG_VerifyAndRecoveryNTRSettings(); // NTRݒf[^ǂݏoāATWLݒf[^ƃxt@CAKvȂ烊Jo + + //NAM̏ + NAM_Init( SYSM_Alloc, SYSM_Free ); + + return pBootTitle; +} + + +// V[gJbgÑ`FbN +static TitleProperty *SYSMi_CheckShortcutBoot( void ) +{ + static TitleProperty s_bootTitle; + + MI_CpuClear8( &s_bootTitle, sizeof(TitleProperty) ); + + //----------------------------------------------------- + // ISfobKN or + // ʎYHpV[gJbgL[ or + // J[hN + //----------------------------------------------------- + if( SYSM_IsExistCard() ) { + if( ( SYSMi_GetWork()->flags.common.isOnDebugger && // ISfobKLJTAG܂LłȂ + !( *(u8 *)( HW_SYS_CONF_BUF + HWi_WSYS09_OFFSET ) & HWi_WSYS09_JTAG_CPUJE_MASK ) ) || + SYSM_IsInspectCard() || + ( ( PAD_Read() & PAD_PRODUCTION_SHORTCUT_CARD_BOOT ) == + PAD_PRODUCTION_SHORTCUT_CARD_BOOT ) + ) { + s_bootTitle.flags.isAppRelocate = TRUE; + s_bootTitle.flags.isAppLoadCompleted = TRUE; + s_bootTitle.flags.isInitialShortcutSkip = TRUE; // NV[PX΂ + s_bootTitle.flags.isLogoSkip = TRUE; // Sf΂ + s_bootTitle.flags.bootType = LAUNCHER_BOOTTYPE_ROM; + s_bootTitle.flags.isValid = TRUE; + s_bootTitle.titleID = *(u64 *)( &SYSM_GetCardRomHeader()->titleID_Lo ); + SYSM_SetLogoDemoSkip( s_bootTitle.flags.isLogoSkip ); + return &s_bootTitle; + } + } + + //----------------------------------------------------- + // TWLݒf[^͎̏NV[PXN + //----------------------------------------------------- +#if 0 +#ifdef ENABLE_INITIAL_SETTINGS_ + if( !LCFG_TSD_IsSetTP() || + !LCFG_TSD_IsSetLanguage() || + !LCFG_TSD_IsSetDateTime() || + !LCFG_TSD_IsSetUserColor() || + !LCFG_TSD_IsSetNickname() ) { + s_bootTitle.titleID = TITLE_ID_MACHINE_SETTINGS; + s_bootTitle.flags.bootType = LAUNCHER_BOOTTYPE_NAND; + s_bootTitle.flags.isValid = TRUE; + return &s_bootTitle; + } +#endif // ENABLE_INITIAL_SETTINGS_ +#endif + + return NULL; // uu[gevŃ^[ +} + + +// N[u[g +static void SYSMi_CheckCardCloneBoot( void ) +{ +#if 0 + u8 *buffp = (u8 *)&pTempBuffer; + u32 total_rom_size = SYSM_GetCardRomHeader()->rom_valid_size ? SYSM_GetCardRomHeader()->rom_valid_size : 0x01000000; + u32 file_offset = total_rom_size & 0xFFFFFE00; + + DC_FlushRange( buffp, BNR_IMAGE_SIZE ); + CARD_ReadRom( 4, (void *)file_offset, buffp, BNR_IMAGE_SIZE ); + + buffp += total_rom_size & 0x000001FF; + if( *buffp++ == 'a' && *buffp == 'c' ) { + SYSMi_GetWork()->flags.common.cloneBootMode = CLONE_BOOT_MODE; + }else { + SYSMi_GetWork()->flags.common.cloneBootMode = OTHER_BOOT_MODE; + } +#endif +} + + +//====================================================================== +// fobO +//====================================================================== diff --git a/build/libraries_sysmenu/sysmenu/ARM9/src/title.c b/build/libraries_sysmenu/sysmenu/ARM9/src/title.c new file mode 100644 index 00000000..2e8c8875 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/ARM9/src/title.c @@ -0,0 +1,671 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: SYSM_lib.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include "internal_api.h" + +// define data----------------------------------------------------------------- +#define CARD_BANNER_INDEX ( LAUNCHER_TITLE_LIST_NUM - 1 ) +#define GAME_COMMAND_PARAM_INDEX 0x60 + +// extern data----------------------------------------------------------------- +// function's prototype------------------------------------------------------- +static BOOL SYSMi_ReadBanner_NAND( NAMTitleId titleID, u8 *pDst ); +static s32 ReadFile( FSFile* pf, void* buffer, s32 size ); +static void SYSMi_EnableHotSW( BOOL enable ); +static void SYSMi_LoadTitleThreadFunc( TitleProperty *pBootTitle ); +static void SYSMi_Relocate( void ); +static BOOL SYSMi_CheckTitlePointer( TitleProperty *pBootTitle ); + +// global variable------------------------------------------------------------- +// static variable------------------------------------------------------------- +static OSThread s_thread; +static TWLBannerFile s_bannerBuf[ LAUNCHER_TITLE_LIST_NUM ] ATTRIBUTE_ALIGN(32); + +// const data------------------------------------------------------------------ +static const OSBootType s_launcherToOSBootType[ LAUNCHER_BOOTTYPE_MAX ] = { + OS_BOOTTYPE_ILLEGAL, // ILLEGAL + OS_BOOTTYPE_ROM, // ROM + OS_BOOTTYPE_NAND, // TEMP + OS_BOOTTYPE_NAND, // NAND + OS_BOOTTYPE_MEMORY, // MEMORY +}; + +// ============================================================================ +// +// 擾 +// +// ============================================================================ + +// J[h^Cg̎擾 +BOOL SYSM_GetCardTitleList( TitleProperty *pTitleList_Card ) +{ + BOOL retval = FALSE; + + if( SYSMi_GetWork()->flags.common.isCardStateChanged ) { + + MI_CpuClear32( pTitleList_Card, sizeof(TitleProperty) ); + + // ROMwb_obt@̃Rs[ + if( SYSM_IsExistCard() ) { + u16 id = (u16)OS_GetLockID(); + (void)OS_LockByWord( id, &SYSMi_GetWork()->lockCardRsc, NULL ); // ARM7Ɣr䂷 + DC_InvalidateRange( (void *)SYSM_CARD_ROM_HEADER_BAK, SYSM_CARD_ROM_HEADER_SIZE ); // LbVPA + MI_CpuCopyFast( (void *)SYSM_CARD_ROM_HEADER_BAK, (void *)SYSM_CARD_ROM_HEADER_BUF, SYSM_CARD_ROM_HEADER_SIZE ); // ROMwb_Rs[ + SYSMi_GetWork()->cardHeaderCrc16 = SYSMi_GetWork()->cardHeaderCrc16; // ROMwb_CRCRs[ + SYSMi_GetWork()->flags.common.isCardStateChanged = FALSE; // J[hXVtO𗎂Ƃ + (void)OS_UnlockByWord( id, &SYSMi_GetWork()->lockCardRsc, NULL ); // ARM7Ɣr䂷 + OS_ReleaseLockID( id ); + + pTitleList_Card->flags.isValid = TRUE; + pTitleList_Card->flags.isAppLoadCompleted = TRUE; + pTitleList_Card->flags.isAppRelocate = TRUE; + pTitleList_Card->pBanner = NULL; + + // oi[f[^̃[h + if( SYSM_GetCardRomHeader()->banner_offset && + SYSMi_ReadCardBannerFile( SYSM_GetCardRomHeader()->banner_offset, &s_bannerBuf[ CARD_BANNER_INDEX ] ) ) { + pTitleList_Card->pBanner = &s_bannerBuf[ CARD_BANNER_INDEX ]; + }else { + MI_CpuClearFast( &s_bannerBuf[ CARD_BANNER_INDEX ], sizeof(TWLBannerFile) ); + } + } + + retval = TRUE; + } + + // ^CgtÕZbg + pTitleList_Card->flags.bootType = LAUNCHER_BOOTTYPE_ROM; + pTitleList_Card->titleID = *(u64 *)( &SYSM_GetCardRomHeader()->titleID_Lo ); + + return retval; +} + + +// NAND^CgXg̎擾 +int SYSM_GetNandTitleList( TitleProperty *pTitleList_Nand, int listNum ) +{ + // filter_flag : ALL, ALL_APP, SYS_APP, USER_APP, Data only, ̏w肵ă^CgXg擾B + // Ƃ肠ALL + OSTick start; + int l; + int getNum; + int validNum = 0; + NAMTitleId titleIDArray[ LAUNCHER_TITLE_LIST_NUM ]; + NAMTitleId *pTitleIDList = NULL; + + + if( listNum > LAUNCHER_TITLE_LIST_NUM ) { + OS_TPrintf( "Warning: TitleList_Nand num over LAUNCHER_TITLE_LIST_NUM(%d)\n", LAUNCHER_TITLE_LIST_NUM ); + } + + // CXg[Ă^Cg̎擾 + start = OS_GetTick(); + getNum = NAM_GetNumTitles(); + OS_TPrintf( "NAM_GetNumTitles : %dus\n", OS_TicksToMicroSeconds( OS_GetTick() - start ) ); + pTitleIDList = SYSM_Alloc( sizeof(NAMTitleId) * getNum ); + if( pTitleIDList == NULL ) { + OS_TPrintf( "%s: alloc error.\n", __FUNCTION__ ); + return 0; + } + start = OS_GetTick(); + (void)NAM_GetTitleList( pTitleIDList, (u32)getNum ); + OS_TPrintf( "NAM_GetTitleList : %dus\n", OS_TicksToMicroSeconds( OS_GetTick() - start ) ); + + // 擾^Cg[`Ώۂǂ`FbN + for( l = 0; l < getNum; l++ ) { + // "Not Launch"łȂ@@"Data Only"łȂ@ȂLȃ^CgƂăXgɒlj + if( ( pTitleIDList[ l ] & ( TITLE_ID_NOT_LAUNCH_FLAG_MASK | TITLE_ID_DATA_ONLY_FLAG_MASK ) ) == 0 ) { + titleIDArray[ validNum ] = pTitleIDList[ l ]; + SYSMi_ReadBanner_NAND( pTitleIDList[ l ], (u8 *)&s_bannerBuf[ validNum ] ); + validNum++; + } + } + SYSM_Free( pTitleIDList ); + + // Ôߎc̈0NA + for( l = validNum; l < LAUNCHER_TITLE_LIST_NUM; l++ ) { + titleIDArray[ l ] = 0; + } + + // ŏIXgɑ΂āAJ[hAvNA + MI_CpuClearFast( &pTitleList_Nand[ 1 ], sizeof(TitleProperty) * ( listNum - 1 ) ); + + listNum = ( validNum < listNum ) ? validNum : listNum; + + for(l=0;l 0 ) + { + const s32 len = MATH_IMin(1024, remain); + const s32 readLen = FS_ReadFile(pf, p, len); + + if( readLen < 0 ) + { + return readLen; + } + if( readLen != len ) + { + return size - remain + readLen; + } + + remain -= readLen; + p += readLen; + } + + return size; +} + + +// ============================================================================ +// +// AvN +// +// ============================================================================ + +static void SYSMi_LoadTitleThreadFunc( TitleProperty *pBootTitle ) +{ + enum + { + region_header = 0, + region_arm9_ntr, + region_arm7_ntr, + region_arm9_twl, + region_arm7_twl, + region_max + }; + // C̃NA + // DS_E[hvC̎́AROMwb_ޔ + // Av[h + // AvF + + + // [h + char path[256]; + FSFile file[1]; + BOOL bSuccess; + BOOL isTwlApp = TRUE; + + switch( pBootTitle->flags.bootType ) + { + case LAUNCHER_BOOTTYPE_NAND: + // NAND + NAM_GetTitleBootContentPathFast(path, pBootTitle->titleID); + break; + case LAUNCHER_BOOTTYPE_ROM: + // TODO:CARDǂ̏ꍇ̏ + break; + case LAUNCHER_BOOTTYPE_TEMP: + // tmptH_ + STD_TSNPrintf( path, 31, "nand:/tmp/%.16llx.srl", pBootTitle->titleID ); + break; + default: + // unknown + return; + } + + bSuccess = FS_OpenFileEx(file, path, FS_FILEMODE_R); + + if( ! bSuccess ) + { +OS_TPrintf("RebootSystem failed: cant open file\n"); + return; + } + + { + int i; + u32 source[region_max]; + u32 length[region_max]; + u32 destaddr[region_max]; + static u8 header[HW_TWL_ROM_HEADER_BUF_SIZE] ATTRIBUTE_ALIGN(32); + s32 readLen; + + // ܂ROMwb_ǂݍ + // ({Ȃ炱SRL̐) + bSuccess = FS_SeekFile(file, 0x00000000, FS_SEEK_SET); + + if( ! bSuccess ) + { +OS_TPrintf("RebootSystem failed: cant seek file(0)\n"); + FS_CloseFile(file); + return; + } + + readLen = ReadFile(file, header, (s32)sizeof(header)); + + if( readLen != (s32)sizeof(header) ) + { +OS_TPrintf("RebootSystem failed: cant read file(%p, %d, %d, %d)\n", header, 0, sizeof(header), readLen); + FS_CloseFile(file); + return; + } + + if( header[0x15C] != 0x56 || header[0x15D] != 0xCF ) + { +int i, j; +for( i = 0; i < 0x20; ++i ) +{ +for( j = 0; j < 0x10; ++j ) +{ +OS_TPrintf("%02X ", header[i * 0x10 + j]); +} +OS_TPrintf("\n"); +} +OS_TPrintf("RebootSystem failed: logo CRC error\n"); + FS_CloseFile(file); + return; + } + + + if( header[0x12] && 0x03 == 0 ) + { + //NTRpROM + isTwlApp = FALSE; + } + /* + else if( pBootTitle->titleID != *((NAMTitleId *)(&header[0x230])) ) + { + //TWLΉROMŁAwb_titleIDNw肳ꂽIDƈႤ +OS_TPrintf("RebootSystem failed: header TitleID error\n"); +OS_TPrintf("RebootSystem failed: selectedTitleID=%.16llx\n",pBootTitle->titleID); +OS_TPrintf("RebootSystem failed: headerTitleID=%.16llx\n",*((NAMTitleId *)(&header[0x230]))); + FS_CloseFile(file); + return; + } + */ + + // ëǂݍ + source [region_header ] = 0x00000000; + length [region_header ] = HW_TWL_ROM_HEADER_BUF_SIZE; + destaddr[region_header ] = HW_TWL_ROM_HEADER_BUF; + + source [region_arm9_ntr] = *(const u32*)&header[0x020]; + length [region_arm9_ntr] = *(const u32*)&header[0x02C]; + destaddr[region_arm9_ntr] = *(const u32*)&header[0x028]; + + source [region_arm7_ntr] = *(const u32*)&header[0x030]; + length [region_arm7_ntr] = *(const u32*)&header[0x03C]; + destaddr[region_arm7_ntr] = *(const u32*)&header[0x038]; + + if( isTwlApp ) + { + source [region_arm9_twl] = *(const u32*)&header[0x1C0]; + length [region_arm9_twl] = *(const u32*)&header[0x1CC]; + destaddr[region_arm9_twl] = *(const u32*)&header[0x1C8]; + + source [region_arm7_twl] = *(const u32*)&header[0x1D0]; + length [region_arm7_twl] = *(const u32*)&header[0x1DC]; + destaddr[region_arm7_twl] = *(const u32*)&header[0x1D8]; + } + + // ̈ǂݍݐ̃`FbNyэĔzuf[^̍쐬 + // Q[J[h̍Ĕzu񂪏܂Ă̂ŁAnandAv[hOɈUNA + MI_CpuClearFast(SYSMi_GetWork()->romRelocateInfo, sizeof(Relocate_Info) * RELOCATE_INFO_NUM); + for( i=0; i= ARM9_LTD_STATIC ) continue;// nitroł͓ǂݍ܂Ȃ̈ + if ( !SYSM_CheckLoadRegionAndSetRelocateInfo( (RomSegmentName)i, &(destaddr[i+region_arm9_ntr]), length[i+region_arm9_ntr], + &(SYSMi_GetWork()->romRelocateInfo[i]), isTwlApp ) ) + { + OS_TPrintf("RebootSystem failed: ROM Load Region error\n"); + FS_CloseFile(file); + return; + } + } + + for (i = region_header; i < region_max; ++i) + { + u32 len = length[i]; + + if ( !isTwlApp && i >= region_arm9_twl ) continue;// nitroł͓ǂݍ܂Ȃ̈ + + bSuccess = FS_SeekFile(file, (s32)source[i], FS_SEEK_SET); + + if( ! bSuccess ) + { +OS_TPrintf("RebootSystem failed: cant seek file(%d)\n", source[i]); + FS_CloseFile(file); + return; + } + + readLen = ReadFile(file, (void *)destaddr[i], (s32)len); + + if( readLen != (s32)len ) + { +OS_TPrintf("RebootSystem failed: cant read file(%d, %d)\n", source[i], len); + FS_CloseFile(file); + return; + } + } + + (void)FS_CloseFile(file); + + } + + // ROMwb_obt@Rs[ + MI_CpuCopy32( (void *)HW_TWL_ROM_HEADER_BUF, (void *)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END - HW_ROM_HEADER_BUF ); + + SYSMi_GetWork()->flags.common.isLoadSucceeded = TRUE; +} + + +// w^CgʃXbhŃ[hJn +void SYSM_StartLoadTitle( TitleProperty *pBootTitle ) +{ +#define THREAD_PRIO 17 +#define STACK_SIZE 0xc00 + static u64 stack[ STACK_SIZE / sizeof(u64) ]; + + SYSMi_EnableHotSW( FALSE ); + + // Av[hԂȂA[hJn + if( !pBootTitle->flags.isAppLoadCompleted ) { + SYSMi_GetWork()->flags.common.isLoadSucceeded = FALSE; + OS_InitThread(); + OS_CreateThread( &s_thread, (void (*)(void *))SYSMi_LoadTitleThreadFunc, (void*)pBootTitle, stack+STACK_SIZE/sizeof(u64), STACK_SIZE,THREAD_PRIO ); + OS_WakeupThreadDirect( &s_thread ); + }else if( pBootTitle->flags.isAppRelocate ) { + // Av[hς݂ŁAĔzuvȂAĔzuiJ[ĥݑΉj + SYSMi_Relocate(); + SYSMi_GetWork()->flags.common.isLoadSucceeded = TRUE; + }else + { + // Av[hς݂ŁAĔzuvȂ + SYSMi_GetWork()->flags.common.isLoadSucceeded = TRUE; + } + + if( pBootTitle->flags.bootType == LAUNCHER_BOOTTYPE_ROM ) { + SYSMi_GetWork()->flags.common.isCardBoot = TRUE; + }else if(pBootTitle->flags.isAppLoadCompleted) + { + // J[hu[głȂA[hς݂̏ꍇAĔzu`[p^ǂݍ + MI_CpuCopy8( SYSM_GetLauncherParamBody()->v1.relocInfo, SYSMi_GetWork()->romRelocateInfo, sizeof(Relocate_Info)*RELOCATE_INFO_NUM ); + // XɃwb_Ĕzu + if( ((ROM_Header_Short *)(OS_TWL_HEADER_PRELOAD_MMEM))->platform_code & PLATFORM_CODE_FLAG_TWL ) { + // TWL[h + // TWL-ROMwb_̍Ĕzu + MI_CpuCopyFast( (void *)(OS_TWL_HEADER_PRELOAD_MMEM), (void *)HW_TWL_ROM_HEADER_BUF, SYSM_CARD_ROM_HEADER_SIZE ); + MI_CpuCopyFast( (void *)(OS_TWL_HEADER_PRELOAD_MMEM), (void *)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END - HW_ROM_HEADER_BUF ); + }else { + // NTR[h + // TWL-ROMwb_̍Ĕzu + // `[ROMwb_cĂRs[̈NA + MI_CpuClearFast( (void *)HW_TWL_ROM_HEADER_BUF, SYSM_CARD_ROM_HEADER_SIZE ); + MI_CpuCopyFast( (void *)(OS_TWL_HEADER_PRELOAD_MMEM), (void *)HW_TWL_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END - HW_ROM_HEADER_BUF ); + MI_CpuCopyFast( (void *)(OS_TWL_HEADER_PRELOAD_MMEM), (void *)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END - HW_ROM_HEADER_BUF ); + // NTR-ROMwb_̍ĔzúArebootCuōsB + } + } +} + + +// J[hAvP[V̍Ĕzu +static void SYSMi_Relocate( void ) +{ + u32 size; + u32 *dest = SYSM_GetCardRomHeader()->main_ram_address; + // NTRZLÄ̍Ĕzu + DC_InvalidateRange( (void *)SYSM_CARD_NTR_SECURE_BUF, SECURE_AREA_SIZE ); // LbVPA + size = ( SYSM_GetCardRomHeader()->main_size < SECURE_AREA_SIZE ) ? + SYSM_GetCardRomHeader()->main_size : SECURE_AREA_SIZE; + // rom̍ĔzuQƂāAZLÄ̍ĔzuύXKvׂ + if( SYSMi_GetWork()->romRelocateInfo[ARM9_STATIC].src != NULL ) + { + dest = (u32 *)SYSMi_GetWork()->romRelocateInfo[ARM9_STATIC].src; + } + MI_CpuCopyFast( (void *)SYSM_CARD_NTR_SECURE_BUF, dest, size ); + + if( SYSM_GetCardRomHeader()->platform_code & PLATFORM_CODE_FLAG_TWL ) { + // TWL[h + // TWLZLÄ̍Ĕzu + dest = SYSM_GetCardRomHeader()->main_ltd_ram_address; + DC_InvalidateRange( (void *)SYSM_CARD_TWL_SECURE_BUF, SECURE_AREA_SIZE ); // LbVPA + size = ( SYSM_GetCardRomHeader()->main_ltd_size < SECURE_AREA_SIZE ) ? + SYSM_GetCardRomHeader()->main_ltd_size : SECURE_AREA_SIZE; + // rom̍ĔzuQƂāAZLÄ̍ĔzuύXKvׂ + if( SYSMi_GetWork()->romRelocateInfo[ARM9_LTD_STATIC].src != NULL ) + { + dest = (u32 *)SYSMi_GetWork()->romRelocateInfo[ARM9_LTD_STATIC].src; + } + MI_CpuCopyFast( (void *)SYSM_CARD_TWL_SECURE_BUF, dest, size ); + // TWL-ROMwb_̍Ĕzu + MI_CpuCopyFast( (void *)SYSM_CARD_ROM_HEADER_BUF, (void *)HW_TWL_ROM_HEADER_BUF, SYSM_CARD_ROM_HEADER_SIZE ); + MI_CpuCopyFast( (void *)SYSM_CARD_ROM_HEADER_BUF, (void *)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END - HW_ROM_HEADER_BUF ); + }else { + // NTR[h + // TWL-ROMwb_̍Ĕzu + // `[ROMwb_cĂRs[̈NA + MI_CpuClearFast( (void *)HW_TWL_ROM_HEADER_BUF, SYSM_CARD_ROM_HEADER_SIZE ); + MI_CpuCopyFast( (void *)SYSM_CARD_ROM_HEADER_BUF, (void *)HW_TWL_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END - HW_ROM_HEADER_BUF ); + MI_CpuCopyFast( (void *)SYSM_CARD_ROM_HEADER_BUF, (void *)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END - HW_ROM_HEADER_BUF ); + } + // NTR-ROMwb_obt@̃Q[R}hp[^㏑ + *(vu32 *)(HW_ROM_HEADER_BUF + GAME_COMMAND_PARAM_INDEX) = SYSMi_GetWork()->gameCommondParam; +} + + +// Av[hς݁H +BOOL SYSM_IsLoadTitleFinished( TitleProperty *pBootTitle ) +{ + if( pBootTitle->flags.isAppLoadCompleted ) { + return TRUE; + } + return OS_IsThreadTerminated( &s_thread ); +} + + +// [hς݂̎w^Cg̔F؂ƃu[gs +AuthResult SYSM_AuthenticateTitle( TitleProperty *pBootTitle ) +{ + // [h + if( !SYSM_IsLoadTitleFinished( pBootTitle ) ) { + return AUTH_RESULT_PROCESSING; + } + // [hH + if( SYSMi_GetWork()->flags.common.isLoadSucceeded == FALSE ) + { + return AUTH_RESULT_TITLE_LOAD_FAILED; + } + // p[^`FbN + if( !SYSMi_CheckTitlePointer( pBootTitle ) ) { + return AUTH_RESULT_TITLE_POINTER_ERROR; + } +#if 0 + // GgAhX̐`FbN + if( !SYSMi_CheckEntryAddress() ) { + return AUTH_RESULT_ENTRY_ADDRESS_ERROR; + } +#endif + + // BOOTTYPE_MEMORYNTR[hFSŃu[gƁANitroSDKŃrhꂽAv̏ꍇA + // ROMA[JCuɃJ[h蓖ĂāAFSŊ֌WȂJ[hɃANZXɂĂ܂̂ŁAh~B + if( ( pBootTitle->flags.bootType == LAUNCHER_BOOTTYPE_MEMORY ) && + ( ( (( ROM_Header_Short *)HW_TWL_ROM_HEADER_BUF)->platform_code ) == 0 ) && + ( ( (( ROM_Header_Short *)HW_TWL_ROM_HEADER_BUF)->fat_size ) > 0 ) + ) { + return AUTH_RESULT_TITLE_BOOTTYPE_ERROR; + } + + // ROMwb_F + + + // }Eg̓o^ + SYSMi_SetBootAppMountInfo( pBootTitle ); + + // HW_WM_BOOT_BUFւ̃u[gZbg + ( (OSBootInfo *)OS_GetBootInfo() )->boot_type = s_launcherToOSBootType[ pBootTitle->flags.bootType ]; + + BOOT_Ready(); // never return. + + return AUTH_RESULT_SUCCEEDED; +} + + +#if 0 +// w^Cg̔F؁[h@Pt[IB +// ƎgȂ +void SYSM_LoadAndAuthenticateTitleThread( TitleProperty *pBootTitle ) +{ + SYSMi_LoadTitleThreadFunc( pBootTitle ); + OS_JoinThread(&s_thread); + + // F + return SYSM_AuthenticateTitle( pBootTitle ); +} +#endif + + +// w^Cgu[g”\ȃ|C^`FbN +static BOOL SYSMi_CheckTitlePointer( TitleProperty *pBootTitle ) +{ +#pragma unused( pBootTitle ) + + return TRUE; +} + +#if 0 +void CheckDigest( void ) +{ + int i; + for( i = 0; i < 4; i++ ) { + if( SYSMi_GetWork()->reloc_info[ i ].src ) { + + }else { + } + } +} +#endif + + +// }L^Zbg +void SYSMi_EnableHotSW( BOOL enable ) +{ + enable = enable ? 1 : 0; + + // ݂̒lƓȂ牽^[ + if( SYSMi_GetWork()->flags.common.isEnableHotSW == enable ) { + return; + } + + { + u16 id = (u16)OS_GetLockID(); + (void)OS_LockByWord( id, &SYSMi_GetWork()->lockHotSW, NULL ); + if( !SYSMi_GetWork()->flags.common.isBusyHotSW ) { + // ARM7rW[łȂ΁Aڏ + SYSMi_GetWork()->flags.common.isEnableHotSW = enable; + }else { + // ARM7rW[ȂAύXvARM7lĂ̂҂B + SYSMi_GetWork()->flags.arm9.reqChangeHotSW = 1; + SYSMi_GetWork()->flags.arm9.nextHotSWStatus = enable; + } + (void)OS_UnlockByWord( id, &SYSMi_GetWork()->lockHotSW, NULL ); + OS_ReleaseLockID( id ); + } + + // lω܂ŃX[vđ҂B + while( SYSMi_GetWork()->flags.common.isEnableHotSW != enable ) { + OS_Sleep( 2 ); + } +} diff --git a/build/libraries_sysmenu/sysmenu/ARM9/src/util.c b/build/libraries_sysmenu/sysmenu/ARM9/src/util.c new file mode 100644 index 00000000..ac51c715 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/ARM9/src/util.c @@ -0,0 +1,167 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: SYSM_util.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include + +// define data------------------------------------------ + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- +static s64 SYSMi_CalcRTCSecOffset( RTCDate *datep, RTCTime *timep ); + +// global variable ------------------------------------- + +// static variable ------------------------------------- + +// const data ----------------------------------------- + +// function's description------------------------------- + +//====================================================================== +// RTCItZbg +//====================================================================== + +// RTCɐVݒlZbgāA̒lƂrtcOffsetlZoB +s64 SYSM_CalcRTCOffset( RTCDate *newDatep, RTCTime *newTimep ) +{ + RTCDate oldDate; + RTCTime oldTime; + s64 offset0; + s64 offset1; + s64 offset; + + // RTCւ̐Vl̐ݒ + (void)RTC_GetDateTime( &oldDate, &oldTime ); // CgOɌ݂RTCl擾B + oldTime.second = 0; + + // RTCݒ莞́A̐ݒłǂꂾRTClωibItZbgPʁjZoB + if( ( oldDate.year < LCFG_TSD_GetRTCLastSetYear() ) && ( LCFG_TSD_IsSetDateTime() ) ) { + oldDate.year += 100; // O̐ݒ`̐ݒ̊ԂRTCĂ܂Ayear100ZoffsetvZB + } + LCFG_TSD_SetRTCLastSetYear( (u8)newDatep->year ); + + offset0 = SYSMi_CalcRTCSecOffset( &oldDate, &oldTime ); // ݒ蒼ORTCl̃ItZbgZo + offset1 = SYSMi_CalcRTCSecOffset( newDatep, newTimep ); // VZbgꂽRTCl̃ItZbgZo + offset = LCFG_TSD_GetRTCOffset() + offset1 - offset0; // VRTC_ofs ݂RTC_ofs ̍̒lZă^[B + + OS_Printf ("Now Date = year:%3d month:%3d date:%3d hour:%3d minute:%3d second:%3d\n", + oldDate.year, oldDate.month, oldDate.day, + oldTime.hour, oldTime.minute, oldTime.second); + OS_Printf ("Set Date = year:%3d month:%3d date:%3d hour:%3d minute:%3d second:%3d\n", + newDatep->year, newDatep->month, newDatep->day, + newTimep->hour, newTimep->minute, newTimep->second); + OS_Printf ("offset[0] = %x\n", offset0 ); + OS_Printf ("offset[1] = %x\n", offset1 ); + OS_Printf ("rtcOffset = %x\n", offset ); + + return offset; +} + + +// RTCItZbgl̎Zo +#define SECOND_OFFSET +static s64 SYSMi_CalcRTCSecOffset( RTCDate *datep, RTCTime *timep ) +{ + u32 i; + int uruu = 0; + int dayNum = 0; + s64 offset; + + // AAb@b or ItZbg +#ifdef SECOND_OFFSET + offset = ( timep->hour * 60 + timep->minute ) * 60 + timep->second; // LXgɃoO +#else + offset = timep->hour * 60 + timep->minute; +#endif + + // A@ɊZĂA@b or ItZbg + dayNum = (int)datep->day - 1; + for( i = 1; i < datep->month; i++ ) { + dayNum += SYSM_GetDayNum( datep->year, i ); + } + + // N@ɊZ + if( datep->year > 0 ) { + uruu = ( ( (int)datep->year - 1 ) >> 2 ) + 1; // wN-1܂ł̂邤ҐZoāA̓ZB + } + dayNum += uruu + (u32)( datep->year * 365 ); + + // NEEɊZl@b or ItZbg +#ifdef SECOND_OFFSET + offset += (s64)( dayNum * 24 * 3600 ); // LXgɃoO +#else + offset += (s64)( dayNum * 24 * 60 ); +#endif + + return offset; +} + + +// w肳ꂽNE̓ԂB +u32 SYSM_GetDayNum( u32 year, u32 month ) +{ + u32 dayNum = 31; + if( month == 2 ) { + if( SYSM_IsLeapYear100( year ) ) { + dayNum -= 2; + }else { + dayNum -= 3; + } + }else if( ( month == 4 ) || ( month == 6 ) || ( month == 9 ) || ( month == 11 ) ) { + dayNum--; + } + return dayNum; +} + + +// ȈՂ邤N̔ (邤NF1Aʏ̔NF0jRTĈƂ肤2000`2100NɌ肷B +BOOL SYSM_IsLeapYear100( u32 year ) +{ + if( ( year & 0x03 ) || ( year == 100 ) ) { // 邤ŃAu4Ŋ؂@@100Ŋ؂ȂNv܂́u400Ŋ؂Nv + return FALSE; + }else { + return TRUE; + } +} + + +// RTC̓t`FbN +BOOL SYSM_CheckRTCDate( RTCDate *datep ) +{ + if( ( datep->year >= 100 ) + || ( datep->month < 1 ) || ( datep->month > 12 ) + || ( datep->day < 1 ) || ( datep->day > 31 ) + || ( datep->week >= RTC_WEEK_MAX ) ) { + return FALSE; + } + return TRUE; +} + + +// RTC̎`FbN +BOOL SYSM_CheckRTCTime( RTCTime *timep ) +{ + if( ( timep->hour > 23 ) + || ( timep->minute > 59 ) + || ( timep->second > 59 ) ) { + return FALSE; + } + return TRUE; +} + diff --git a/build/libraries_sysmenu/sysmenu/Makefile b/build/libraries_sysmenu/sysmenu/Makefile new file mode 100644 index 00000000..be4cc462 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/Makefile @@ -0,0 +1,33 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 ARM7 + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries_sysmenu/sysmenu/common/include/internal_api.h b/build/libraries_sysmenu/sysmenu/common/include/internal_api.h new file mode 100644 index 00000000..a95c7734 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/common/include/internal_api.h @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: internal_api.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 SYSM_INTERNAL_API_H_ +#define SYSM_INTERNAL_API_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +//#define SYSM_LIB_NO_MESSAGE // Printf}XCb` + +#ifdef SYSM_LIB_NO_MESSAGE +#define OS_Printf( ... ) ((void)0) +#define OS_TPrintf( ... ) ((void)0) +#define OS_PutString( ... ) ((void)0) +#endif + +#ifdef SDK_ARM9 +//------------------------------------------------------- +// }EgZbg +//------------------------------------------------------- + +// `[p +void SYSMi_SetLauncherMountInfo( void ); + +// NAvp +void SYSMi_SetBootAppMountInfo( TitleProperty *pBootTitle ); + + +//------------------------------------------------------- +// foCX +//------------------------------------------------------- + +// RTC␳ +void SYSMi_WriteAdjustRTC( void ); + +// RTC`FbN +void SYSMi_CheckRTC( void ); + + +//------------------------------------------------------- +// oi[ +//------------------------------------------------------- + +// J[hoi[[hiNTR-IPL2dlj +BOOL SYSMi_ReadCardBannerFile( u32 bannerOffset, TWLBannerFile *pBanner ); + +//------------------------------------------------------- +// } +//------------------------------------------------------- +void SYSMi_EnableHotSW( BOOL enable ); + + +#endif + + +//======================================================= +// +// ARM9/ARM7API +// +//======================================================= +BOOL SYSMi_IsDebuggerBannerViewMode( void ); +BOOL SYSMi_CheckEntryAddress( void ); +BOOL SYSMi_SendPXICommand( SYSMPXICommand command ); +void SYSMi_PXIFifoRecvCallback( PXIFifoTag tag, u32 data, BOOL err ); + + +#ifdef __cplusplus +} +#endif + +#endif // SYSM_INTERNAL_API_H_ diff --git a/build/libraries_sysmenu/sysmenu/common/src/pxi.c b/build/libraries_sysmenu/sysmenu/common/src/pxi.c new file mode 100644 index 00000000..d14b2192 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/common/src/pxi.c @@ -0,0 +1,118 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: pxi.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "internal_api.h" + +// define data----------------------------------------------------------------- +#define SYSM_PXI_COMM_STAT_REQ 0 +#define SYSM_PXI_COMM_STAT_ACK 1 + +// PXIR}h +typedef union SYSMPXIPacket { + struct { + u16 data; + u16 command : 14; + u16 stat : 2; + }; + u32 raw; +}SYSMPXIPacket; + + +// extern data----------------------------------------------------------------- +// function's prototype------------------------------------------------------- +// global variable------------------------------------------------------------- +// static variable------------------------------------------------------------- +static volatile BOOL s_sending = FALSE; +// const data------------------------------------------------------------------ + +// PXIR}hM +BOOL SYSMi_SendPXICommand( SYSMPXICommand command ) +{ + SYSMPXIPacket packet; + + OSIntrMode saved = OS_DisableInterrupts(); + if( s_sending ) { + OS_RestoreInterrupts( saved ); + return FALSE; + } + s_sending = TRUE; + OS_RestoreInterrupts( saved ); + + packet.stat = SYSM_PXI_COMM_STAT_REQ; + packet.command = (u16)command; + packet.data = 0; + + while( PXI_SendWordByFifo( SYSMENU_PXI_FIFO_TAG, packet.raw, 0 ) < 0 ) {} + + while( s_sending ) { + OS_WaitAnyIrq(); + } + return TRUE; +} + +void SYSMi_PXIFifoRecvCallback( PXIFifoTag tag, u32 data, BOOL err ) +{ +#pragma unused( tag, err ) + SYSMPXIPacket packet; + packet.raw = data; +#if 0 + +#ifdef SDK_ARM9 + + s_sending = FALSE; + + if( packet.stat == SYSM_PXI_COMM_STAT_ACK ) { + switch( data ) { + case SYSM_PXI_COMM_DISABLE_HOTSW: + SYSMi_GetWork()->flags.arm9.isEnableHotSW = 0; + break; + default: + break; + } + }else { // SYSM_PXI_COMM_STAT_REQ + switch( data ) { + default: + break; + } + } +#else // !SDK_ARM9 + + if( packet.stat == SYSM_PXI_COMM_STAT_REQ ) { + switch( data ) { + case SYSM_PXI_COMM_DISABLE_HOTSW: + if( SYSMi_GetWork()->flags.arm7.isBusyHotSW ) { + SYSMi_GetWork()->flags.arm7.disableHotSW_REQ = 1; + }else { + SYSMi_GetWork()->flags.arm7.isEnableHotSW = 0; + // PXIŕԐM + } + break; + default: + break; + } + }else { // SYSM_PXI_COMM_STAT_ACK + switch( data ) { + default: + break; + } + } +#endif // SDK_ARM9 +#endif +} + diff --git a/build/libraries_sysmenu/sysmenu/common/src/status.c b/build/libraries_sysmenu/sysmenu/common/src/status.c new file mode 100644 index 00000000..dcc97297 --- /dev/null +++ b/build/libraries_sysmenu/sysmenu/common/src/status.c @@ -0,0 +1,147 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: status.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "internal_api.h" + +// define data----------------------------------------------------------------- +// extern data----------------------------------------------------------------- +// function's prototype------------------------------------------------------- +static int SYSMi_IsValidCard( void ); +// global variable------------------------------------------------------------- +// static variable------------------------------------------------------------- +// const data------------------------------------------------------------------ + + +// `[p[^̎擾 +const LauncherParamBody *SYSM_GetLauncherParamBody( void ) +{ + return (const LauncherParamBody *)&SYSMi_GetWork()->launcherParam.body; +} + + +// SfXLbvǂZbg +void SYSM_SetLogoDemoSkip( BOOL skip ) +{ + SYSMi_GetWork()->flags.common.isLogoSkip = skip; +} + + +// SfXLbvH +BOOL SYSM_IsLogoDemoSkip( void ) +{ + return (BOOL)SYSMi_GetWork()->flags.common.isLogoSkip; +} + + +// ISfobK̃oi[r[[hNǂH +BOOL SYSMi_IsDebuggerBannerViewMode( void ) +{ +#ifdef __IS_DEBUGGER_BUILD + return ( SYSMi_GetWork()->flags.common.isOnDebugger && + SYSMi_IsValidCard() && + SYSM_GetCardRomHeader()->dbgRomSize == 0 ) ? TRUE : FALSE; +#else + return FALSE; +#endif // __IS_DEBUGGER_BUILD +} + + +// TP[h”\ԂH +BOOL SYSM_IsTPReadable( void ) +{ + return TRUE; +} + + +// TSDL/Zbg +void SYSM_SetValidTSD( BOOL valid ) +{ + SYSMi_GetWork()->flags.common.isValidTSD = valid; +} + + +// TSDLH +BOOL SYSM_IsValidTSD( void ) +{ + return (BOOL)SYSMi_GetWork()->flags.common.isValidTSD; +} + + +// LTWL/NTRJ[hĂ邩H +BOOL SYSM_IsExistCard( void ) +{ + return (BOOL)SYSMi_GetWork()->flags.common.isExistCard; +} + + +// pJ[hĂ邩H +BOOL SYSM_IsInspectCard( void ) +{ + return ( SYSM_IsExistCard() && SYSM_GetCardRomHeader()->inspect_card ); +} + + +// LTWLJ[hĂ邩H +BOOL SYSM_IsTWLCard( void ); +BOOL SYSM_IsTWLCard( void ) +{ + return ( SYSM_IsExistCard() && ( SYSM_GetCardRomHeader()->platform_code & PLATFORM_CODE_FLAG_TWL ) ); +} + + +// LNTRJ[hĂ邩H +BOOL SYSM_IsNTRCard( void ); +BOOL SYSM_IsNTRCard( void ) +{ + return ( SYSM_IsExistCard() && ( SYSM_GetCardRomHeader()->platform_code == PLATFORM_CODE_NTR ) ); +} + + +// NTR,TWLJ[h݃`FbN u^[@1FJ[hF@0FJ[hȂv +static int SYSMi_IsValidCard( void ) +{ + if( ( SYSM_GetCardRomHeader()->nintendo_logo_crc16 == 0xcf56 ) && + ( SYSM_GetCardRomHeader()->header_crc16 == SYSMi_GetWork()->cardHeaderCrc16 ) ) { + return TRUE; // NTR,TWLJ[hiNintendoSCRCAJ[hwb_CRCꍇj + // NintendoSf[^̃`FbŃA̓sAS\[`Nɍs܂B + }else { + return FALSE; // NTR,TWLJ[hȂ + } +} + + +// GgAhX̐`FbN +BOOL SYSMi_CheckEntryAddress( void ) +{ + // GgAhXROMo^GAAGBJ[gbWGAȂA[vɓB + if( !( ( (u32)SYSM_GetCardRomHeader()->main_entry_address >= HW_MAIN_MEM ) && + ( (u32)SYSM_GetCardRomHeader()->main_entry_address < SYSM_ARM9_MMEM_ENTRY_ADDR_LIMIT ) + ) || + !( ( ( (u32)SYSM_GetCardRomHeader()->sub_entry_address >= HW_MAIN_MEM ) && + ( (u32)SYSM_GetCardRomHeader()->sub_entry_address < SYSM_ARM7_LOAD_MMEM_LAST_ADDR ) ) || + ( ( (u32)SYSM_GetCardRomHeader()->sub_entry_address >= HW_WRAM ) && + ( (u32)SYSM_GetCardRomHeader()->sub_entry_address < SYSM_ARM7_LOAD_WRAM_LAST_ADDR ) ) + ) + ) { + OS_TPrintf("entry address invalid.\n"); + return FALSE; + } + OS_TPrintf("entry address valid.\n"); + return TRUE; +} diff --git a/build/nandfirm/Makefile b/build/nandfirm/Makefile new file mode 100644 index 00000000..c7621800 --- /dev/null +++ b/build/nandfirm/Makefile @@ -0,0 +1,35 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - firmware +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS_P = \ + nandfirm-print \ + sdmc-launcher \ + menu-launcher \ + menu-launcher2 \ + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/nandfirm/menu-launcher/ARM7/Makefile b/build/nandfirm/menu-launcher/ARM7/Makefile new file mode 100644 index 00000000..0bab582d --- /dev/null +++ b/build/nandfirm/menu-launcher/ARM7/Makefile @@ -0,0 +1,51 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - menu-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +TWL_PROC = ARM7 + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = menu_launcher7.tef + +SRCS = main.c + +CRT0_O = crt0_firm.o + +ADDRESS_STATIC = 0x037b8000 + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/nandfirm/menu-launcher/ARM7/main.c b/build/nandfirm/menu-launcher/ARM7/main.c new file mode 100644 index 00000000..abc34f8c --- /dev/null +++ b/build/nandfirm/menu-launcher/ARM7/main.c @@ -0,0 +1,315 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - nandfirm - menu-launcher + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +/* + PROFILE_ENABLE `Ƃx̃ptH[}X`FbNł܂B + p邽߂ɂ́Amain.cǂɁAu32 profile[256]; u32 pf_cnt = 0; + `Kv܂B +*/ +#define PROFILE_ENABLE + +/* + fobOLEDFINALROMƂ͕ʂOn/Offł܂B +*/ +#define USE_DEBUG_LED + +/* + PRINT_MEMORY_ADDR `ƁÃAhXSPrintfs܂(̃t@Ĉ) + FINALROMłłR[hĉŒӂĂB +*/ +#define PRINT_MEMORY_ADDR 0x02FFC800 + + +#ifdef PROFILE_ENABLE +#define PROFILE_MAX 16 +u32 profile[PROFILE_MAX]; +u32 pf_cnt = 0; +#define PUSH_PROFILE() (profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick())) +#else +#define PUSH_PROFILE() ((void)0) +#endif + +#ifdef USE_DEBUG_LED +static u8 step = 0x80; +#define InitDebugLED() I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x03, 0x00) +#define SetDebugLED(pattern) I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, (pattern)); +#else +#define InitDebugLED() ((void)0) +#define SetDebugLED(pattern) ((void)0) +#endif + +#ifdef PRINT_MEMORY_ADDR +static char* debugPtr = (char*)PRINT_MEMORY_ADDR; +#undef OS_TPrintf +//#define OS_TPrintf(...) (debugPtr = (char*)((u32)(debugPtr + STD_TSPrintf(debugPtr, __VA_ARGS__) + 0xf) & ~0xf)) +#define OS_TPrintf(...) (debugPtr += STD_TSPrintf(debugPtr, __VA_ARGS__)) +#endif + +#define THREAD_PRIO_FATFS 8 +#define DMA_FATFS_1 3 +#define DMA_FATFS_2 2 + +extern void* SDNandContext; /* NANDp[^ */ + +static ROM_Header* const rh= (ROM_Header*)HW_TWL_ROM_HEADER_BUF; + +static OSThread idleThread; +static u64 idleStack[32]; +static void IdleThread(void* arg) +{ +#pragma unused(arg) + OS_EnableInterrupts(); + while (1) + { + OS_Halt(); + } +} +static void CreateIdleThread(void) +{ + OS_CreateThread(&idleThread, IdleThread, NULL, &idleStack[32], sizeof(idleStack), OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&idleThread); +} + +/*************************************************************** + PreInit + + FromBoot̑ΉC̏ + OS_InitOȂ̂Œ (ARM9ɂ郁CŏȂ悤ɒ) +***************************************************************/ +static void PreInit(void) +{ + /* + obe[cʃ`FbN + */ + if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCUo[W΍ + if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) + { + OS_TPrintf("Battery is empty.\n"); + OS_Terminate(); + } + /* + FromBrom֘A + */ + if ( !OSi_FromBromToMenu() ) + { + OS_Terminate(); + } + /* + Zbgp[^(1oCg)L̈(1oCg)ɃRs[ + */ +#define HOTSTART_FLAG_ENABLE 0x80 + *(u8 *)HW_NAND_FIRM_HOTSTART_FLAG = (u8)(MCU_GetFreeRegister( OS_MCU_RESET_VALUE_OFS ) | HOTSTART_FLAG_ENABLE); +} + +/*************************************************************** + PostInit + + e평 +***************************************************************/ +static void PostInit(void) +{ + // PMIC̐ݒ for old version + PM_InitFIRM(); + // AES̏ + AES_Init(); // for encrypted NAND + // AChXbh̍쐬 + CreateIdleThread(); + /* + obe[cʃ`FbN + */ + if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCUo[W΍ + if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) + { + OS_TPrintf("Battery is empty.\n"); + OS_Terminate(); + } +} + +/*************************************************************** + EraseAll + + sI܂ + 낢Ă + DS[hɂďÎ悢H +***************************************************************/ +static void EraseAll(void) +{ + MI_CpuClearFast( OSi_GetFromFirmAddr(), sizeof(OSFromFirmBuf) ); +#ifdef SDK_FINALROM + MI_CpuClearFast( (void*)HW_TWL_ROM_HEADER_BUF, HW_TWL_ROM_HEADER_BUF_SIZE ); + OS_BootFromFIRM(); +#endif +} + +void TwlSpMain( void ) +{ + int fd; // menu file descriptor + +#ifdef PROFILE_ENABLE + // 0: bootrom + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + InitDebugLED(); + SetDebugLED(++step); // 0x81 + + PreInit(); +#ifdef PROFILE_ENABLE + // 1: after PreInit + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + SetDebugLED(++step); // 0x82 + + OS_InitFIRM(); + OS_EnableIrq(); + OS_EnableInterrupts(); + // 2: after OS_InitFIRM + PUSH_PROFILE(); + SetDebugLED(++step); // 0x83 + + PostInit(); + // 3: after PostInit + PUSH_PROFILE(); + SetDebugLED(++step); // 0x84 + +// PM_BackLightOn( FALSE ); + + SDNandContext = &OSi_GetFromFirmAddr()->SDNandContext; + if ( !FATFS_Init( DMA_FATFS_1, DMA_FATFS_2, THREAD_PRIO_FATFS ) ) + { + OS_TPrintf("Failed to call FATFS_Init().\n"); + goto end; + } + // 4: after FATFS_Init + PUSH_PROFILE(); + SetDebugLED(++step); // 0x85 + +// PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_SET_PATH ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_SET_PATH).\n"); + goto end; + } + // 5: after PXI + PUSH_PROFILE(); + SetDebugLED(++step); // 0x86 + +// PM_BackLightOn( FALSE ); + + if ( (fd = FS_OpenSrl()) < 0 ) + { + OS_TPrintf("Failed to call FS_OpenSrl().\n"); + goto end; + } + // 6: after FS_OpenSrl + PUSH_PROFILE(); + SetDebugLED(++step); // 0x87 + +// PM_BackLightOn( FALSE ); + + if ( !FS_LoadHeader( fd ) ) + { + OS_TPrintf("Failed to call FS_LoadHeader().\n"); + goto end; + } + // 7: after FS_LoadHeader + PUSH_PROFILE(); + SetDebugLED(++step); // 0x88 + +// PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_DONE_HEADER ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_DONE_HEADER).\n"); + goto end; + } + // 8: after PXI + PUSH_PROFILE(); + SetDebugLED(++step); // 0x89 + +// PM_BackLightOn( FALSE ); + + AESi_InitKeysFIRM(); + AESi_RecvSeed( rh->s.developer_encrypt ); + // 9: after AESi_RecvSeed + PUSH_PROFILE(); + SetDebugLED(++step); // 0x8a + +// PM_BackLightOn( FALSE ); + + if ( !FS_LoadStatic( fd ) ) + { + OS_TPrintf("Failed to call FS_LoadStatic().\n"); + goto end; + } + // 10: after FS_LoadStatic + PUSH_PROFILE(); + SetDebugLED(++step); // 0x8b + +// PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_DONE_STATIC ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_DONE_STATIC).\n"); + goto end; + } + // 11: after PXI + PUSH_PROFILE(); + +#ifdef PROFILE_ENABLE + { + int i; + PXI_RecvID(); + OS_TPrintf("\n[ARM7] Begin\n"); + for (i = 0; i < PROFILE_MAX; i++) + { +// OS_TPrintf("0x%08X\n", profile[i]); + if ( !profile[i] ) break; + OS_TPrintf("%2d: %7d usec", i, profile[i]); + if (i) + { + OS_TPrintf(" ( %7d usec )\n", profile[i]-profile[i-1]); + } + else + { + OS_TPrintf("\n"); + } + } + OS_TPrintf("\n[ARM7] End\n"); + } +#endif + SetDebugLED( 0 ); + +// PM_BackLightOn( TRUE ); // last chance + + OS_BootFromFIRM(); + +end: + SetDebugLED( (u8)(0xF0 | step)); + + EraseAll(); + + // failed + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + OS_Terminate(); +} + diff --git a/build/nandfirm/menu-launcher/ARM9/Makefile b/build/nandfirm/menu-launcher/ARM9/Makefile new file mode 100644 index 00000000..a66ae301 --- /dev/null +++ b/build/nandfirm/menu-launcher/ARM9/Makefile @@ -0,0 +1,60 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - menu-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = menu_launcher9.srl + +SRCS = main.c + +CRT0_O = crt0_firm.o + +ADDRESS_STATIC = 0x037c0000 + +MAKEROM_ARM7 = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/menu_launcher7.tef +MAKEROM_ARM7_BASE = $(basename $(MAKEROM_ARM7)) + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +# no thumb version, no final rom version +ifeq ($(TARGET_FINALROM),) +LLIBRARIES += libes.TWL$(ARCHGEN_TYPE).a libboc.TWL$(ARCHGEN_TYPE).a +else +LLIBRARIES += ../Release/libes.TWL$(ARCHGEN_TYPE).a ../Release/libboc.TWL$(ARCHGEN_TYPE).a +endif +LLIBRARIES += liblcfg$(TWL_LIBSUFFIX).a + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/nandfirm/menu-launcher/ARM9/main.c b/build/nandfirm/menu-launcher/ARM9/main.c new file mode 100644 index 00000000..7c5c7eea --- /dev/null +++ b/build/nandfirm/menu-launcher/ARM9/main.c @@ -0,0 +1,350 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - nandfirm - menu-launcher + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +#ifndef FIRM_USE_TWLSDK_KEYS +#define RSA_KEY_ADDR OSi_GetFromFirmAddr()->rsa_pubkey[0] // Ǘ.xlsQ +#else +#define RSA_KEY_ADDR rsa_key +static const u8 rsa_key[128] = +{ + 0xAC, 0x93, 0xBB, + 0x3C, 0x15, 0x5C, 0x5F, 0x25, 0xB0, 0x4C, 0x37, 0xA4, 0x2D, 0x85, 0x29, 0x1D, 0x7A, 0x9D, 0x2D, + 0xD5, 0x79, 0xB5, 0x5D, 0xB1, 0x08, 0x20, 0x9C, 0xF0, 0x4C, 0x56, 0x27, 0x97, 0xF8, 0x7E, 0x3E, + 0xCB, 0x94, 0x06, 0x05, 0x94, 0x00, 0x92, 0x9B, 0xB0, 0x5B, 0x06, 0xF6, 0xAF, 0xAA, 0x9C, 0xA5, + 0xF0, 0x11, 0xA7, 0x8A, 0xCB, 0x0C, 0x11, 0xD6, 0x0C, 0x3D, 0x30, 0xAC, 0x51, 0x79, 0x5A, 0xB5, + 0x7F, 0x11, 0x92, 0x74, 0x48, 0x82, 0x81, 0xBF, 0x3B, 0xFA, 0x93, 0xBF, 0x6B, 0x5B, 0x3F, 0x86, + 0x96, 0x4F, 0xCC, 0x90, 0x12, 0xB2, 0x39, 0x8D, 0x68, 0x16, 0x7B, 0xC6, 0x87, 0xF1, 0xF5, 0x60, + 0x62, 0x39, 0xFB, 0x10, 0x7E, 0x48, 0x7F, 0xDD, 0x82, 0x38, 0x38, 0x76, 0xB5, 0xCE, 0x21, 0x4B, + 0xC9, 0x6F, 0x31, 0x8D, 0x23, 0x57, 0x3D, 0xB6, 0x6C, 0xEE, 0xC2, 0x0D, 0x11 +}; +#endif + +#define RSA_HEAP_SIZE (4*1024) // RSApq[vTCY (TCYKv) + +static u8 acHeap[RSA_HEAP_SIZE] __attribute__ ((aligned (32))); +static SVCSignHeapContext acPool; + +#define MENU_TITLE_ID_HI 0x00030007ULL +#define MENU_TITLE_ID_LO 0x4c4e4352ULL +#define MENU_TITLE_ID (MENU_TITLE_ID_HI << 32 | MENU_TITLE_ID_LO) + +/* + PROFILE_ENABLE `Ƃx̃ptH[}X`FbNł܂B + p邽߂ɂ́Amain.cǂɁAu32 profile[256]; u32 pf_cnt = 0; + `Kv܂B +*/ +#define PROFILE_ENABLE + +/* + PRINT_MEMORY_ADDR `ƁÃAhXSPrintfs܂(̃t@Ĉ) + FINALROMłłR[hĉŒӂĂB +*/ +#define PRINT_MEMORY_ADDR 0x02FFC000 + +//#ifdef SDK_FINALROM // FINALROMŖ +//#undef PROFILE_ENABLE +//#endif + +#ifdef PROFILE_ENABLE +#define PROFILE_MAX 16 +u32 profile[PROFILE_MAX]; +u32 pf_cnt = 0; +#define PUSH_PROFILE() (profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick())) +#else +#define PUSH_PROFILE() ((void)0) +#endif + +#ifdef PRINT_MEMORY_ADDR +static char* debugPtr = (char*)PRINT_MEMORY_ADDR; +#undef OS_TPrintf +//#define OS_TPrintf(...) (debugPtr = (char*)((u32)(debugPtr + STD_TSPrintf(debugPtr, __VA_ARGS__) + 0xf) & ~0xf)) +#define OS_TPrintf(...) (debugPtr += STD_TSPrintf(debugPtr, __VA_ARGS__)) +#endif + +/*************************************************************** + PreInit + + FromBoot̑ΉOS_InitOɕKvȃC̏ +***************************************************************/ +static void PreInit(void) +{ + static const OSMountInfo firmSettings[] = + { + { 'F', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_ROOT, 0, OS_MOUNT_RSC_WRAM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "nand", "/" }, + { 0 } + }; + /* + C֘A + */ + // SHARED̈̓X^[gAbvŃNA + + // FS_MOUNT̈̏ + MI_CpuCopy8(firmSettings, (char*)HW_TWL_FS_MOUNT_INFO_BUF, sizeof(firmSettings)); + + /* + FromBrom֘A + */ + if ( !OSi_FromBromToMenu() ) + { + OS_Terminate(); + } + + // u[g^Cv̕ύX + ( (OSBootInfo *)OS_GetBootInfo() )->boot_type = OS_BOOTTYPE_NAND; +} + +/*************************************************************** + PostInit + + e평 +***************************************************************/ +static void PostInit(void) +{ + // RSApq[vݒ + SVC_InitSignHeap( &acPool, acHeap, sizeof(acHeap) ); + // HMACp + FS_SetDigestKey( NULL ); + // FS/FATFS + FS_InitFIRM(); +} + +/*************************************************************** + TryResolveSrl + + NANDɊi[ꂽ񂩂烉`[SRL +***************************************************************/ +static BOOL TryResolveSrl(void) +{ + u64 titleId = MENU_TITLE_ID_HI << 32; + if ( !LCFG_ReadHWSecureInfo() ) + { + OS_TPrintf("Failed to load HWSecureInfo.\n"); + return FALSE; + } + LCFG_THW_GetLauncherTitleID_Lo( (u8*)&titleId ); + // 4: after LCFG_ReadHWSecureInfo + PUSH_PROFILE(); + + if ( !FS_ResolveSrl( titleId ) ) + { + OS_TPrintf("Failed to call FS_ResolveSrl( 0x%016llx ).\n", titleId); + return FALSE; + } + OS_TPrintf("Launcher Title ID: 0x%016llx\n", titleId); + return TRUE; +} +/*************************************************************** + RetryResolveSrl + + ftHgݒ肩烉`[SRL +***************************************************************/ +static BOOL RetryResolveSrl(void) +{ + if ( !FS_ResolveSrl( MENU_TITLE_ID ) ) + { + OS_TPrintf("Failed to call FS_ResolveSrl( 0x%016llx ).\n", MENU_TITLE_ID); + return FALSE; + } + OS_TPrintf("Launcher Title ID: 0x%016llx\n", MENU_TITLE_ID); + return TRUE; +} + +/*************************************************************** + CheckHeader + + wb_VXej[ƂĖȂ`FbN +***************************************************************/ +static BOOL CheckHeader(void) +{ + static ROM_Header_Short* const rhs = (ROM_Header_Short*)HW_TWL_ROM_HEADER_BUF; + // CjVR[hȂ + OS_TPrintf("Initial Code : %08X (%.4s)\n", *(u32*)rhs->game_code, rhs->game_code); + OS_TPrintf("Platform Code : %02X\n", rhs->platform_code); + OS_TPrintf("Codec Mode : %s\n", rhs->codec_mode ? "TWL" : "NITRO"); + OS_TPrintf("Sigunature : %s\n", rhs->enable_signature ? "AVAILABLE" : "NOT AVAILABLE"); + OS_TPrintf("AES Encryption : %s\n", rhs->enable_aes ? "AVAILABLE" : "NOT AVAILABLE"); + if ( rhs->enable_aes ) + { + OS_TPrintf("AES Key Type : %s\n", rhs->developer_encrypt ? "FOR DEVELOPMENT" : "FOR PRODUCT"); + } + // Gg|Cg + OS_TPrintf("ARM9 Entry point : %08X\n", rhs->main_entry_address); + OS_TPrintf("ARM7 Entry point : %08X\n", rhs->sub_entry_address); + // [h͈ + OS_TPrintf("ARM9 ROM address : %08X\n", rhs->main_rom_offset); + OS_TPrintf("ARM9 RAM address : %08X\n", rhs->main_ram_address); + OS_TPrintf("ARM9 size : %08X\n", rhs->main_size); + OS_TPrintf("ARM7 ROM address : %08X\n", rhs->sub_rom_offset); + OS_TPrintf("ARM7 RAM address : %08X\n", rhs->sub_ram_address); + OS_TPrintf("ARM7 size : %08X\n", rhs->sub_size); + OS_TPrintf("ARM9 LTD ROM address: %08X\n", rhs->main_ltd_rom_offset); + OS_TPrintf("ARM9 LTD RAM address: %08X\n", rhs->main_ltd_ram_address); + OS_TPrintf("ARM9 LTD size : %08X\n", rhs->main_ltd_size); + OS_TPrintf("ARM7 LTD ROM address: %08X\n", rhs->sub_ltd_rom_offset); + OS_TPrintf("ARM7 LTD RAM address: %08X\n", rhs->sub_ltd_ram_address); + OS_TPrintf("ARM7 LTD size : %08X\n", rhs->sub_ltd_size); + // قڍœKς + if ( rhs->platform_code != PLATFORM_CODE_TWL_LIMITED || // TWL Limited only + !rhs->codec_mode || // TWL mode only + !rhs->enable_signature || // Should be use ROM header signature + (rhs->titleID_Hi & 0x0005) != 0x0005 || // check only NAND/SYSTEM bits (need?) + // should be in main memory + HW_TWL_MAIN_MEM > (u32)rhs->main_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->sub_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->main_ltd_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->sub_ltd_ram_address || + // should be in static area without Limited region + (u32)rhs->main_ram_address > (u32)rhs->main_entry_address || + (u32)rhs->sub_ram_address > (u32)rhs->sub_entry_address || + // should be in main memory (end address) + HW_TWL_MAIN_MEM_END <= (u32)rhs->main_ram_address + rhs->main_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->sub_ram_address + rhs->sub_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->main_ltd_ram_address + rhs->main_ltd_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->sub_ltd_ram_address + rhs->sub_ltd_size || + // should be in static area without Limited region (end address) + (u32)rhs->main_ram_address + rhs->main_size <= (u32)rhs->main_entry_address || + (u32)rhs->sub_ram_address + rhs->sub_size <= (u32)rhs->sub_entry_address || + 0 ) + { + OS_TPrintf("Invalid ROM header for MENU Launcher!\n"); + return FALSE; + } + return TRUE; +} + +/*************************************************************** + EraseAll + + sI܂ + 낢Ă + DS[hɂďÎ悢H +***************************************************************/ +static void EraseAll(void) +{ + MI_CpuClearFast( OSi_GetFromFirmAddr(), sizeof(OSFromFirmBuf) ); +#ifdef SDK_FINALROM + MI_CpuClearFast( (void*)HW_TWL_ROM_HEADER_BUF, HW_TWL_ROM_HEADER_BUF_SIZE ); + MI_CpuClearFast( (void*)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF ); + OS_BootFromFIRM(); +#endif +} + +void TwlMain( void ) +{ +#ifdef PROFILE_ENABLE + // 0: bootrom + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + + PreInit(); +#ifdef PROFILE_ENABLE + // 1: before OS_InitFIRM + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + OS_InitFIRM(); + OS_EnableIrq(); + OS_EnableInterrupts(); +#ifdef PROFILE_ENABLE + // 2: before OS_InitTick + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); + + OS_InitTick(); +#endif + + PostInit(); + // 3: after PostInit + PUSH_PROFILE(); + + if ( !TryResolveSrl() && !RetryResolveSrl() ) + { + goto end; + } + // 5: after FS_ResolveSrl + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_SET_PATH ); + // 6: after PXI + PUSH_PROFILE(); + + if ( !FS_LoadHeader(&acPool, RSA_KEY_ADDR ) || !CheckHeader() ) + { + OS_TPrintf("Failed to call FS_LoadHeader() and/or CheckHeader().\n"); + goto end; + } + // 7: after FS_LoadHeader + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_DONE_HEADER ); + // 8: after PXI + PUSH_PROFILE(); + + AESi_SendSeed( FS_GetAesKeySeed() ); + FS_DeleteAesKeySeed(); + // 9: after AESi_SendSeed + PUSH_PROFILE(); + + if ( !FS_LoadStatic() ) + { + OS_TPrintf("Failed to call FS_LoadStatic().\n"); + goto end; + } + // 10: after FS_LoadStatic + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); + // 11: after PXI + PUSH_PROFILE(); + +#ifdef PROFILE_ENABLE + { + int i; + OS_TPrintf("\n[ARM9] Begin\n"); + for (i = 0; i < PROFILE_MAX; i++) + { +// OS_TPrintf("0x%08X\n", profile[i]); + if ( !profile[i] ) break; + OS_TPrintf("%2d: %7d usec", i, profile[i]); + if (i) + { + OS_TPrintf(" ( %7d usec )\n", profile[i]-profile[i-1]); + } + else + { + OS_TPrintf("\n"); + } + } + OS_TPrintf("\n[ARM9] End\n"); + PXI_NotifyID( FIRM_PXI_ID_NULL ); + OS_SetTick(0); + } +#endif + + OS_BootFromFIRM(); + +end: + EraseAll(); + + // failed + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + OS_Terminate(); +} + diff --git a/build/nandfirm/menu-launcher/Makefile b/build/nandfirm/menu-launcher/Makefile new file mode 100644 index 00000000..232ee475 --- /dev/null +++ b/build/nandfirm/menu-launcher/Makefile @@ -0,0 +1,52 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - menu-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + + +# if you have valid keys, set environment value like below +#export TWL_KEYSDIR='$(TWL_IPL_RED_ROOT)/../twl_firmware/bootrom/build/keys' + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + wram_regs \ + ARM7 \ + ARM9 \ + +TARGET_FIRM_BIN = menu_launcher-$(TWL_BUILD_TYPE)$(CODEGEN_ARCH).nand +BINDIR = . +MAKEFIRM_ARM9 = ARM9/bin/$(TWL_BUILDTYPE_ARM9)/menu_launcher9.tef +MAKEFIRM_ARM7 = ARM7/bin/$(TWL_BUILDTYPE_ARM7)/menu_launcher7.tef +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_nand.der +LDEPENDS_BIN += wram_regs/wram_regs.rbin + +MAKEFIRM_FLAGS += -p +FIRM_SPEC = nandfirm.nandsf + +LDIRT_CLEAN += $(wildcard *.nand) \ + rsa_public.sbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/nandfirm/menu-launcher/nandfirm.nandsf b/build/nandfirm/menu-launcher/nandfirm.nandsf new file mode 100644 index 00000000..cdea8b16 --- /dev/null +++ b/build/nandfirm/menu-launcher/nandfirm.nandsf @@ -0,0 +1,24 @@ +#NANDSF --- Nandfirm Spec File + +VERSION : GENERATE + +RSA_KEY : $(MAKEFIRM_RSA_PRVKEY) +OUT_KEY : rsa_public.sbin + +WRAM_RBIN: ./wram_regs/wram_regs.rbin + +MIRROR_OFS: 0x100000 + +DECOMP_PROC : ARM9 # ARM9 or ARM7 + +ARM9_COMP : FALSE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).TWL.FLX.sbin +ARM9_ELF : $(MAKEFIRM_ARM9).tef + +ARM7_COMP : FALSE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).TWL.FLX.sbin +ARM7_ELF : $(MAKEFIRM_ARM7).tef + +ARM9_X2 : TRUE # TRUE or FALSE + +NCD_ROMOFS : 0x0f00 diff --git a/build/nandfirm/menu-launcher/wram_regs/Makefile b/build/nandfirm/menu-launcher/wram_regs/Makefile new file mode 100644 index 00000000..66504d9a --- /dev/null +++ b/build/nandfirm/menu-launcher/wram_regs/Makefile @@ -0,0 +1,57 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - menu-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM := TWL +override TARGET_CODEGEN := ARM +override TWL_ARCHGEN := LIMITED + +override TARGET_FINALROM := TRUE +override TARGET_RELEASE := +override TARGET_DEBUG := + +SUBDIRS = + +LINCLUDES = ../include + + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/nandfirm/menu-launcher/wram_regs/wram_regs.c b/build/nandfirm/menu-launcher/wram_regs/wram_regs.c new file mode 100644 index 00000000..2454b302 --- /dev/null +++ b/build/nandfirm/menu-launcher/wram_regs/wram_regs.c @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - nandfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM9 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_A_SIZE ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE - HW_WRAM_C_SIZE ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/nandfirm/menu-launcher2/ARM7/Makefile b/build/nandfirm/menu-launcher2/ARM7/Makefile new file mode 100644 index 00000000..f662cc89 --- /dev/null +++ b/build/nandfirm/menu-launcher2/ARM7/Makefile @@ -0,0 +1,49 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - menu-launcher2 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +TWL_PROC = ARM7 + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = menu_launcher2_7.tef + +SRCS = main.c + +CRT0_O = crt0_firm.o + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/nandfirm/menu-launcher2/ARM7/main.c b/build/nandfirm/menu-launcher2/ARM7/main.c new file mode 100644 index 00000000..b5659ca4 --- /dev/null +++ b/build/nandfirm/menu-launcher2/ARM7/main.c @@ -0,0 +1,290 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - nandfirm - menu-launcher2 + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include +#include + +/* + PROFILE_ENABLE `Ƃx̃ptH[}X`FbNł܂B + p邽߂ɂ́Amain.cǂɁAu32 profile[256]; u32 pf_cnt = 0; + `Kv܂B +*/ +#define PROFILE_ENABLE + +/* + fobOLEDFINALROMƂ͕ʂOn/Offł܂B +*/ +#define USE_DEBUG_LED + +/* + PRINT_MEMORY_ADDR `ƁÃAhXSPrintfs܂(̃t@Ĉ) + FINALROMłłR[hĉŒӂĂB +*/ +#define PRINT_MEMORY_ADDR 0x02FFC800 + + +#ifdef PROFILE_ENABLE +#define PROFILE_MAX 16 +u32 profile[PROFILE_MAX]; +u32 pf_cnt = 0; +#define PUSH_PROFILE() (profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick())) +#else +#define PUSH_PROFILE() ((void)0) +#endif + +#ifdef USE_DEBUG_LED +static u8 step = 0x80; +#define InitDebugLED() I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x03, 0x00) +#define SetDebugLED(pattern) I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, (pattern)); +#else +#define InitDebugLED() ((void)0) +#define SetDebugLED(pattern) ((void)0) +#endif + +#ifdef PRINT_MEMORY_ADDR +static char* debugPtr = (char*)PRINT_MEMORY_ADDR; +#undef OS_TPrintf +//#define OS_TPrintf(...) (debugPtr = (char*)((u32)(debugPtr + STD_TSPrintf(debugPtr, __VA_ARGS__) + 0xf) & ~0xf)) +#define OS_TPrintf(...) (debugPtr += STD_TSPrintf(debugPtr, __VA_ARGS__)) +#endif + +#define THREAD_PRIO_FATFS 8 +#define DMA_FATFS_1 3 +#define DMA_FATFS_2 2 + +extern void* SDNandContext; /* NANDp[^ */ + +static ROM_Header* const rh= (ROM_Header*)HW_TWL_ROM_HEADER_BUF; + +static OSThread idleThread; +static u64 idleStack[32]; +static void IdleThread(void* arg) +{ +#pragma unused(arg) + OS_EnableInterrupts(); + while (1) + { + OS_Halt(); + } +} +static void CreateIdleThread(void) +{ + OS_CreateThread(&idleThread, IdleThread, NULL, &idleStack[32], sizeof(idleStack), OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&idleThread); +} + +/*************************************************************** + PreInit + + FromBoot̑ΉC̏ + OS_InitOȂ̂Œ (ARM9ɂ郁CŏȂ悤ɒ) +***************************************************************/ +static void PreInit(void) +{ + /* + obe[cʃ`FbN + */ + if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCUo[W΍ + if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) + { + OS_TPrintf("Battery is empty.\n"); + OS_Terminate(); + } + /* + FromBrom֘A + */ + if ( !OSi_FromBromToMenu() ) + { + OS_Terminate(); + } + /* + Zbgp[^(1oCg)L̈(1oCg)ɃRs[ + */ +#define HOTSTART_FLAG_ENABLE 0x80 + *(u8 *)HW_NAND_FIRM_HOTSTART_FLAG = (u8)(MCU_GetFreeRegister( OS_MCU_RESET_VALUE_OFS ) | HOTSTART_FLAG_ENABLE); +} + +/*************************************************************** + PostInit + + e평 +***************************************************************/ +static void PostInit(void) +{ + // PMIC̐ݒ for old version + PM_InitFIRM(); + // AES̏ + AES_Init(); // for encrypted NAND + // AChXbh̍쐬 + CreateIdleThread(); + /* + obe[cʃ`FbN + */ + if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCUo[W΍ + if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) + { + OS_TPrintf("Battery is empty.\n"); + OS_Terminate(); + } +} + +/*************************************************************** + EraseAll + + sI܂ + 낢Ă + DS[hɂďÎ悢H +***************************************************************/ +static void EraseAll(void) +{ + MI_CpuClearFast( OSi_GetFromFirmAddr(), sizeof(OSFromFirmBuf) ); +#ifdef SDK_FINALROM + MI_CpuClearFast( (void*)HW_TWL_ROM_HEADER_BUF, HW_TWL_ROM_HEADER_BUF_SIZE ); + OS_BootFromFIRM(); +#endif +} + +void TwlSpMain( void ) +{ +#ifdef PROFILE_ENABLE + // 0: bootrom + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + InitDebugLED(); + SetDebugLED(++step); // 0x81 + + PreInit(); +#ifdef PROFILE_ENABLE + // 1: after PreInit + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + SetDebugLED(++step); // 0x82 + + OS_InitFIRM(); + OS_EnableIrq(); + OS_EnableInterrupts(); + // 2: after PXI + PUSH_PROFILE(); + SetDebugLED(++step); // 0x83 + + PostInit(); + // 3: after PostInit + PUSH_PROFILE(); + SetDebugLED(++step); // 0x84 + +// PM_BackLightOn( FALSE ); + + SDNandContext = &OSi_GetFromFirmAddr()->SDNandContext; + if ( !FATFS_Init( DMA_FATFS_1, DMA_FATFS_2, THREAD_PRIO_FATFS ) ) + { + OS_TPrintf("Failed to call FATFS_Init().\n"); + goto end; + } + // 4: after FATFS_Init + PUSH_PROFILE(); + SetDebugLED(++step); // 0x85 + +// PM_BackLightOn( FALSE ); + // 5: + PUSH_PROFILE(); + SetDebugLED(++step); // 0x86 + + //PM_BackLightOn( FALSE ); + // 6: + PUSH_PROFILE(); + SetDebugLED(++step); // 0x87 + + //PM_BackLightOn( FALSE ); + // 7: + PUSH_PROFILE(); + SetDebugLED(++step); // 0x88 + + //PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_DONE_HEADER ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_DONE_HEADER).\n"); + goto end; + } + // 8: after PXI + PUSH_PROFILE(); + SetDebugLED(++step); // 0x89 + +// PM_BackLightOn( FALSE ); + + AESi_InitKeysFIRM(); + AESi_RecvSeed( rh->s.developer_encrypt ); + // 9: after AESi_RecvSeed + PUSH_PROFILE(); + SetDebugLED(++step); // 0x8a + +// PM_BackLightOn( FALSE ); + // 10: + PUSH_PROFILE(); + SetDebugLED(++step); // 0x8b + + //PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_DONE_STATIC ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_DONE_STATIC).\n"); + goto end; + } + // 11: after PXI + PUSH_PROFILE(); + +#ifdef PROFILE_ENABLE + { + int i; + PXI_RecvID(); + OS_TPrintf("\n[ARM7] Begin\n"); + for (i = 0; i < PROFILE_MAX; i++) + { +// OS_TPrintf("0x%08X\n", profile[i]); + if ( !profile[i] ) break; + OS_TPrintf("%2d: %7d usec", i, profile[i]); + if (i) + { + OS_TPrintf(" ( %7d usec )\n", profile[i]-profile[i-1]); + } + else + { + OS_TPrintf("\n"); + } + } + OS_TPrintf("\n[ARM7] End\n"); + } +#endif + SetDebugLED( 0 ); + +// PM_BackLightOn( TRUE ); // last chance + + OS_BootFromFIRM(); + +end: + SetDebugLED( (u8)(0xF0 | step)); + + EraseAll(); + + // failed + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + OS_Terminate(); +} + diff --git a/build/nandfirm/menu-launcher2/ARM9/Makefile b/build/nandfirm/menu-launcher2/ARM9/Makefile new file mode 100644 index 00000000..0870f698 --- /dev/null +++ b/build/nandfirm/menu-launcher2/ARM9/Makefile @@ -0,0 +1,59 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - menu-launcher2 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = menu_launcher2_9.srl + +SRCS = main.c + +CRT0_O = crt0_firm.o + +MAKEROM_ARM7 = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/menu_launcher2_7.tef +MAKEROM_ARM7_BASE = $(basename $(MAKEROM_ARM7)) + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +# no thumb version, no final rom version +ifeq ($(TARGET_FINALROM),) +LLIBRARIES += libes.TWL$(ARCHGEN_TYPE).a libboc.TWL$(ARCHGEN_TYPE).a +else +LLIBRARIES += ../Release/libes.TWL$(ARCHGEN_TYPE).a ../Release/libboc.TWL$(ARCHGEN_TYPE).a +endif +LLIBRARIES += liblcfg$(TWL_LIBSUFFIX).a \ + libaes_private$(TWL_LIBSUFFIX).a + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/nandfirm/menu-launcher2/ARM9/main.c b/build/nandfirm/menu-launcher2/ARM9/main.c new file mode 100644 index 00000000..20421863 --- /dev/null +++ b/build/nandfirm/menu-launcher2/ARM9/main.c @@ -0,0 +1,358 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - nandfirm - menu-launcher2 + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include +#include + +#ifndef FIRM_USE_TWLSDK_KEYS +#define RSA_KEY_ADDR OSi_GetFromFirmAddr()->rsa_pubkey[0] // Ǘ.xlsQ +#else +#define RSA_KEY_ADDR rsa_key +static const u8 rsa_key[128] = +{ + 0xAC, 0x93, 0xBB, + 0x3C, 0x15, 0x5C, 0x5F, 0x25, 0xB0, 0x4C, 0x37, 0xA4, 0x2D, 0x85, 0x29, 0x1D, 0x7A, 0x9D, 0x2D, + 0xD5, 0x79, 0xB5, 0x5D, 0xB1, 0x08, 0x20, 0x9C, 0xF0, 0x4C, 0x56, 0x27, 0x97, 0xF8, 0x7E, 0x3E, + 0xCB, 0x94, 0x06, 0x05, 0x94, 0x00, 0x92, 0x9B, 0xB0, 0x5B, 0x06, 0xF6, 0xAF, 0xAA, 0x9C, 0xA5, + 0xF0, 0x11, 0xA7, 0x8A, 0xCB, 0x0C, 0x11, 0xD6, 0x0C, 0x3D, 0x30, 0xAC, 0x51, 0x79, 0x5A, 0xB5, + 0x7F, 0x11, 0x92, 0x74, 0x48, 0x82, 0x81, 0xBF, 0x3B, 0xFA, 0x93, 0xBF, 0x6B, 0x5B, 0x3F, 0x86, + 0x96, 0x4F, 0xCC, 0x90, 0x12, 0xB2, 0x39, 0x8D, 0x68, 0x16, 0x7B, 0xC6, 0x87, 0xF1, 0xF5, 0x60, + 0x62, 0x39, 0xFB, 0x10, 0x7E, 0x48, 0x7F, 0xDD, 0x82, 0x38, 0x38, 0x76, 0xB5, 0xCE, 0x21, 0x4B, + 0xC9, 0x6F, 0x31, 0x8D, 0x23, 0x57, 0x3D, 0xB6, 0x6C, 0xEE, 0xC2, 0x0D, 0x11 +}; +#endif + +#define RSA_HEAP_SIZE (4*1024) // RSApq[vTCY (TCYKv) + +static u8 acHeap[RSA_HEAP_SIZE] __attribute__ ((aligned (32))); +static SVCSignHeapContext acPool; + +#define MENU_TITLE_ID_HI 0x00030007ULL +#define MENU_TITLE_ID_LO 0x4c4e4352ULL +#define MENU_TITLE_ID (MENU_TITLE_ID_HI << 32 | MENU_TITLE_ID_LO) + +/* + PROFILE_ENABLE `Ƃx̃ptH[}X`FbNł܂B + p邽߂ɂ́Amain.cǂɁAu32 profile[256]; u32 pf_cnt = 0; + `Kv܂B +*/ +#define PROFILE_ENABLE + +/* + PRINT_MEMORY_ADDR `ƁÃAhXSPrintfs܂(̃t@Ĉ) + FINALROMłłR[hĉŒӂĂB +*/ +#define PRINT_MEMORY_ADDR 0x02FFC000 + +//#ifdef SDK_FINALROM // FINALROMŖ +//#undef PROFILE_ENABLE +//#endif + +#ifdef PROFILE_ENABLE +#define PROFILE_MAX 16 +u32 profile[PROFILE_MAX]; +u32 pf_cnt = 0; +#define PUSH_PROFILE() (profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick())) +#else +#define PUSH_PROFILE() ((void)0) +#endif + +#ifdef PRINT_MEMORY_ADDR +static char* debugPtr = (char*)PRINT_MEMORY_ADDR; +#undef OS_TPrintf +//#define OS_TPrintf(...) (debugPtr = (char*)((u32)(debugPtr + STD_TSPrintf(debugPtr, __VA_ARGS__) + 0xf) & ~0xf)) +#define OS_TPrintf(...) (debugPtr += STD_TSPrintf(debugPtr, __VA_ARGS__)) +#endif + +/*************************************************************** + PreInit + + FromBoot̑ΉOS_InitOɕKvȃC̏ +***************************************************************/ +static void PreInit(void) +{ + static const OSMountInfo firmSettings[] = + { + { 'F', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_ROOT, 0, OS_MOUNT_RSC_WRAM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "nand", "/" }, + { 0 } + }; + /* + C֘A + */ + // SHARED̈̓X^[gAbvŃNA + + // FS_MOUNT̈̏ + MI_CpuCopy8(firmSettings, (char*)HW_TWL_FS_MOUNT_INFO_BUF, sizeof(firmSettings)); + + /* + FromBrom֘A + */ + if ( !OSi_FromBromToMenu() ) + { + OS_Terminate(); + } + + // u[g^Cv̕ύX + ( (OSBootInfo *)OS_GetBootInfo() )->boot_type = OS_BOOTTYPE_NAND; +} + +/*************************************************************** + PostInit + + e평 +***************************************************************/ +static void PostInit(void) +{ + AES_Init(); + // RSApq[vݒ + SVC_InitSignHeap( &acPool, acHeap, sizeof(acHeap) ); + // HMACp + FS2_SetDigestKey( NULL ); + // FS/FATFS + FS_InitFIRM(); +} + +/*************************************************************** + TryResolveSrl + + NANDɊi[ꂽ񂩂烉`[SRL +***************************************************************/ +static BOOL TryResolveSrl(void) +{ + u64 titleId = MENU_TITLE_ID_HI << 32; + if ( !LCFG_ReadHWSecureInfo() ) + { + OS_TPrintf("Failed to load HWSecureInfo.\n"); + return FALSE; + } + LCFG_THW_GetLauncherTitleID_Lo( (u8*)&titleId ); + // 4: after LCFG_ReadHWSecureInfo + PUSH_PROFILE(); + + if ( !FS_ResolveSrl( titleId ) ) + { + OS_TPrintf("Failed to call FS_ResolveSrl( 0x%016llx ).\n", titleId); + return FALSE; + } + OS_TPrintf("Launcher Title ID: 0x%016llx\n", titleId); + return TRUE; +} +/*************************************************************** + RetryResolveSrl + + ftHgݒ肩烉`[SRL +***************************************************************/ +static BOOL RetryResolveSrl(void) +{ + if ( !FS_ResolveSrl( MENU_TITLE_ID ) ) + { + OS_TPrintf("Failed to call FS_ResolveSrl( 0x%016llx ).\n", MENU_TITLE_ID); + return FALSE; + } + OS_TPrintf("Launcher Title ID: 0x%016llx\n", MENU_TITLE_ID); + return TRUE; +} + +/*************************************************************** + CheckHeader + + wb_VXej[ƂĖȂ`FbN +***************************************************************/ +static BOOL CheckHeader(void) +{ + static ROM_Header_Short* const rhs = (ROM_Header_Short*)HW_TWL_ROM_HEADER_BUF; + // CjVR[hȂ + OS_TPrintf("Initial Code : %08X (%.4s)\n", *(u32*)rhs->game_code, rhs->game_code); + OS_TPrintf("Platform Code : %02X\n", rhs->platform_code); + OS_TPrintf("Codec Mode : %s\n", rhs->codec_mode ? "TWL" : "NITRO"); + OS_TPrintf("Sigunature : %s\n", rhs->enable_signature ? "AVAILABLE" : "NOT AVAILABLE"); + OS_TPrintf("AES Encryption : %s\n", rhs->enable_aes ? "AVAILABLE" : "NOT AVAILABLE"); + if ( rhs->enable_aes ) + { + OS_TPrintf("AES Key Type : %s\n", rhs->developer_encrypt ? "FOR DEVELOPMENT" : "FOR PRODUCT"); + } + // Gg|Cg + OS_TPrintf("ARM9 Entry point : %08X\n", rhs->main_entry_address); + OS_TPrintf("ARM7 Entry point : %08X\n", rhs->sub_entry_address); + // [h͈ + OS_TPrintf("ARM9 ROM address : %08X\n", rhs->main_rom_offset); + OS_TPrintf("ARM9 RAM address : %08X\n", rhs->main_ram_address); + OS_TPrintf("ARM9 size : %08X\n", rhs->main_size); + OS_TPrintf("ARM7 ROM address : %08X\n", rhs->sub_rom_offset); + OS_TPrintf("ARM7 RAM address : %08X\n", rhs->sub_ram_address); + OS_TPrintf("ARM7 size : %08X\n", rhs->sub_size); + OS_TPrintf("ARM9 LTD ROM address: %08X\n", rhs->main_ltd_rom_offset); + OS_TPrintf("ARM9 LTD RAM address: %08X\n", rhs->main_ltd_ram_address); + OS_TPrintf("ARM9 LTD size : %08X\n", rhs->main_ltd_size); + OS_TPrintf("ARM7 LTD ROM address: %08X\n", rhs->sub_ltd_rom_offset); + OS_TPrintf("ARM7 LTD RAM address: %08X\n", rhs->sub_ltd_ram_address); + OS_TPrintf("ARM7 LTD size : %08X\n", rhs->sub_ltd_size); + // قڍœKς + if ( rhs->platform_code != PLATFORM_CODE_TWL_LIMITED || // TWL Limited only + !rhs->codec_mode || // TWL mode only + !rhs->enable_signature || // Should be use ROM header signature + (rhs->titleID_Hi & 0x0005) != 0x0005 || // check only NAND/SYSTEM bits (need?) + // should be in main memory + HW_TWL_MAIN_MEM > (u32)rhs->main_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->sub_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->main_ltd_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->sub_ltd_ram_address || + // should be in static area without Limited region + (u32)rhs->main_ram_address > (u32)rhs->main_entry_address || + (u32)rhs->sub_ram_address > (u32)rhs->sub_entry_address || + // should be in main memory (end address) + HW_TWL_MAIN_MEM_END <= (u32)rhs->main_ram_address + rhs->main_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->sub_ram_address + rhs->sub_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->main_ltd_ram_address + rhs->main_ltd_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->sub_ltd_ram_address + rhs->sub_ltd_size || + // should be in static area without Limited region (end address) + (u32)rhs->main_ram_address + rhs->main_size <= (u32)rhs->main_entry_address || + (u32)rhs->sub_ram_address + rhs->sub_size <= (u32)rhs->sub_entry_address || + 0 ) + { + OS_TPrintf("Invalid ROM header for MENU Launcher!\n"); + return FALSE; + } + return TRUE; +} + +/*************************************************************** + EraseAll + + sI܂ + 낢Ă + DS[hɂďÎ悢H +***************************************************************/ +static void EraseAll(void) +{ + MI_CpuClearFast( OSi_GetFromFirmAddr(), sizeof(OSFromFirmBuf) ); +#ifdef SDK_FINALROM + MI_CpuClearFast( (void*)HW_TWL_ROM_HEADER_BUF, HW_TWL_ROM_HEADER_BUF_SIZE ); + MI_CpuClearFast( (void*)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF ); + OS_BootFromFIRM(); +#endif +} + +void TwlMain( void ) +{ + FSFile file; + +#ifdef PROFILE_ENABLE + // 0: bootrom + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + + PreInit(); +#ifdef PROFILE_ENABLE + // 1: before OS_InitFIRM + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + + OS_InitFIRM(); + OS_EnableIrq(); + OS_EnableInterrupts(); +#ifdef PROFILE_ENABLE + // 2: before OS_InitTick + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); + + OS_InitTick(); +#endif + + PostInit(); + // 3: after PostInit + PUSH_PROFILE(); + + if ( !TryResolveSrl() && !RetryResolveSrl() ) + { + goto end; + } + // 5: after FS_ResolveSrl + PUSH_PROFILE(); + + if ( !FS2_OpenSrl( &file ) ) + { + OS_TPrintf("Failed to call FS_OpenSrl().\n"); + goto end; + } + // 6: after FS_OpenSrl + PUSH_PROFILE(); + + if ( !FS2_LoadHeader( &file, &acPool, RSA_KEY_ADDR ) || !CheckHeader() ) + { + OS_TPrintf("Failed to call FS2_LoadHeader() and/or CheckHeader().\n"); + goto end; + } + // 7: after FS2_LoadHeader + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_DONE_HEADER ); + // 8: after PXI + PUSH_PROFILE(); + + AESi_SendSeed( FS2_GetAesKeySeed() ); + // 9: after AESi_SendSeed + PUSH_PROFILE(); + + if ( !FS2_LoadStatic( &file ) ) + { + OS_TPrintf("Failed to call FS2_LoadStatic().\n"); + goto end; + } + // 10: after FS2_LoadStatic + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); + // 11: after PXI + PUSH_PROFILE(); + +#ifdef PROFILE_ENABLE + { + int i; + OS_TPrintf("\n[ARM9] Begin\n"); + for (i = 0; i < PROFILE_MAX; i++) + { +// OS_TPrintf("0x%08X\n", profile[i]); + if ( !profile[i] ) break; + OS_TPrintf("%2d: %7d usec", i, profile[i]); + if (i) + { + OS_TPrintf(" ( %7d usec )\n", profile[i]-profile[i-1]); + } + else + { + OS_TPrintf("\n"); + } + } + OS_TPrintf("\n[ARM9] End\n"); + PXI_NotifyID( FIRM_PXI_ID_NULL ); + OS_SetTick(0); + } +#endif + + OS_BootFromFIRM(); + +end: + EraseAll(); + + // failed + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + OS_Terminate(); +} + diff --git a/build/nandfirm/menu-launcher2/Makefile b/build/nandfirm/menu-launcher2/Makefile new file mode 100644 index 00000000..beab20d3 --- /dev/null +++ b/build/nandfirm/menu-launcher2/Makefile @@ -0,0 +1,52 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - menu-launcher2 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + + +# if you have valid keys, set environment value like below +#export TWL_KEYSDIR='$(TWL_IPL_RED_ROOT)/../twl_firmware/bootrom/build/keys' + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + wram_regs \ + ARM7 \ + ARM9 \ + +TARGET_FIRM_BIN = menu_launcher2-$(TWL_BUILD_TYPE)$(CODEGEN_ARCH).nand +BINDIR = . +MAKEFIRM_ARM9 = ARM9/bin/$(TWL_BUILDTYPE_ARM9)/menu_launcher2_9.tef +MAKEFIRM_ARM7 = ARM7/bin/$(TWL_BUILDTYPE_ARM7)/menu_launcher2_7.tef +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_nand.der +LDEPENDS_BIN += wram_regs/wram_regs.rbin + +MAKEFIRM_FLAGS += -p +FIRM_SPEC = nandfirm.nandsf + +LDIRT_CLEAN += $(wildcard *.nand) \ + rsa_public.sbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/nandfirm/menu-launcher2/nandfirm.nandsf b/build/nandfirm/menu-launcher2/nandfirm.nandsf new file mode 100644 index 00000000..cdea8b16 --- /dev/null +++ b/build/nandfirm/menu-launcher2/nandfirm.nandsf @@ -0,0 +1,24 @@ +#NANDSF --- Nandfirm Spec File + +VERSION : GENERATE + +RSA_KEY : $(MAKEFIRM_RSA_PRVKEY) +OUT_KEY : rsa_public.sbin + +WRAM_RBIN: ./wram_regs/wram_regs.rbin + +MIRROR_OFS: 0x100000 + +DECOMP_PROC : ARM9 # ARM9 or ARM7 + +ARM9_COMP : FALSE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).TWL.FLX.sbin +ARM9_ELF : $(MAKEFIRM_ARM9).tef + +ARM7_COMP : FALSE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).TWL.FLX.sbin +ARM7_ELF : $(MAKEFIRM_ARM7).tef + +ARM9_X2 : TRUE # TRUE or FALSE + +NCD_ROMOFS : 0x0f00 diff --git a/build/nandfirm/menu-launcher2/wram_regs/Makefile b/build/nandfirm/menu-launcher2/wram_regs/Makefile new file mode 100644 index 00000000..cdd48383 --- /dev/null +++ b/build/nandfirm/menu-launcher2/wram_regs/Makefile @@ -0,0 +1,57 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - menu-launcher2 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM := TWL +override TARGET_CODEGEN := ARM +override TWL_ARCHGEN := LIMITED + +override TARGET_FINALROM := TRUE +override TARGET_RELEASE := +override TARGET_DEBUG := + +SUBDIRS = + +LINCLUDES = ../include + + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/nandfirm/menu-launcher2/wram_regs/wram_regs.c b/build/nandfirm/menu-launcher2/wram_regs/wram_regs.c new file mode 100644 index 00000000..2454b302 --- /dev/null +++ b/build/nandfirm/menu-launcher2/wram_regs/wram_regs.c @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - nandfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM9 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_A_SIZE ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE - HW_WRAM_C_SIZE ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/nandfirm/nandfirm-print/Makefile b/build/nandfirm/nandfirm-print/Makefile new file mode 100644 index 00000000..ecd52984 --- /dev/null +++ b/build/nandfirm/nandfirm-print/Makefile @@ -0,0 +1,46 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - build +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + + +#---------------------------------------------------------------------------- + +SUBDIRS = ../../norfirm/norfirm-print + +TARGET_FIRM_BIN = nandfirm_print-$(TWL_BUILD_TYPE).nand +BINDIR = . +MAKEFIRM_ARM9 = ../../norfirm/norfirm-print/ARM9/bin/$(TWL_BUILDTYPE_ARM9)/twl_norfirm9_print.tef +MAKEFIRM_ARM7 = ../../norfirm/norfirm-print/ARM7/bin/$(TWL_BUILDTYPE_ARM7)/twl_norfirm7_print.tef +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_nand.der +LDEPENDS_BIN += ../../norfirm/norfirm-print/wram_regs/wram_regs.rbin + +MAKEFIRM_FLAGS += -p +FIRM_SPEC = nandfirm-BB.nandsf + +LDIRT_CLEAN += $(wildcard *.nand) \ + rsa_public.sbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/nandfirm/nandfirm-print/nandfirm-BB.nandsf b/build/nandfirm/nandfirm-print/nandfirm-BB.nandsf new file mode 100644 index 00000000..30e9a3f8 --- /dev/null +++ b/build/nandfirm/nandfirm-print/nandfirm-BB.nandsf @@ -0,0 +1,24 @@ +#NANDSF --- Nandfirm Spec File + +VERSION : GENERATE + +RSA_KEY : $(MAKEFIRM_RSA_PRVKEY) +OUT_KEY : rsa_public.sbin + +WRAM_RBIN: ../../norfirm/norfirm-print/wram_regs/wram_regs.rbin + +MIRROR_OFS: 0x100000 + +DECOMP_PROC : ARM9 # ARM9 or ARM7 + +ARM9_COMP : FALSE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).TWL.FLX.sbin +ARM9_ELF : $(MAKEFIRM_ARM9).tef + +ARM7_COMP : FALSE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).TWL.FLX.sbin +ARM7_ELF : $(MAKEFIRM_ARM7).tef + +ARM9_X2 : TRUE # TRUE or FALSE + +NCD_ROMOFS : 0x07fe00 diff --git a/build/nandfirm/sdmc-launcher/ARM7/Makefile b/build/nandfirm/sdmc-launcher/ARM7/Makefile new file mode 100644 index 00000000..2c85da75 --- /dev/null +++ b/build/nandfirm/sdmc-launcher/ARM7/Makefile @@ -0,0 +1,49 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - sdmc-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +TWL_PROC = ARM7 + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = sdmc_launcher7.tef + +SRCS = main.c + +CRT0_O = crt0_firm.o + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/nandfirm/sdmc-launcher/ARM7/main.c b/build/nandfirm/sdmc-launcher/ARM7/main.c new file mode 100644 index 00000000..ca8bae55 --- /dev/null +++ b/build/nandfirm/sdmc-launcher/ARM7/main.c @@ -0,0 +1,314 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - nandfirm - sdmc-launcher + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +/* + PROFILE_ENABLE `Ƃx̃ptH[}X`FbNł܂B + p邽߂ɂ́Amain.cǂɁAu32 profile[256]; u32 pf_cnt = 0; + `Kv܂B +*/ +#define PROFILE_ENABLE + +/* + fobOLEDFINALROMƂ͕ʂOn/Offł܂B +*/ +#define USE_DEBUG_LED + +/* + PRINT_MEMORY_ADDR `ƁÃAhXSPrintfs܂(̃t@Ĉ) + FINALROMłłR[hĉŒӂĂB +*/ +//#define PRINT_MEMORY_ADDR 0x02FFC800 + + +#ifdef PROFILE_ENABLE +#define PROFILE_MAX 16 +u32 profile[PROFILE_MAX]; +u32 pf_cnt = 0; +#define PUSH_PROFILE() (profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick())) +#else +#define PUSH_PROFILE() ((void)0) +#endif + +#ifdef USE_DEBUG_LED +static u8 step = 0x80; +#define InitDebugLED() I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x03, 0x00) +#define SetDebugLED(pattern) I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, (pattern)); +#else +#define InitDebugLED() ((void)0) +#define SetDebugLED(pattern) ((void)0) +#endif + +#ifdef PRINT_MEMORY_ADDR +static char* debugPtr = (char*)PRINT_MEMORY_ADDR; +#undef OS_TPrintf +//#define OS_TPrintf(...) (debugPtr = (char*)((u32)(debugPtr + STD_TSPrintf(debugPtr, __VA_ARGS__) + 0xf) & ~0xf)) +#define OS_TPrintf(...) (debugPtr += STD_TSPrintf(debugPtr, __VA_ARGS__)) +#endif + +#define THREAD_PRIO_FATFS 8 +#define DMA_FATFS_1 3 +#define DMA_FATFS_2 2 + +extern void* SDNandContext; /* NANDp[^ */ + +static ROM_Header* const rh= (ROM_Header*)HW_TWL_ROM_HEADER_BUF; + +static OSThread idleThread; +static u64 idleStack[32]; +static void IdleThread(void* arg) +{ +#pragma unused(arg) + OS_EnableInterrupts(); + while (1) + { + OS_Halt(); + } +} +static void CreateIdleThread(void) +{ + OS_CreateThread(&idleThread, IdleThread, NULL, &idleStack[32], sizeof(idleStack), OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&idleThread); +} + +/*************************************************************** + PreInit + + FromBoot̑ΉC̏ + OS_InitOȂ̂Œ (ARM9ɂ郁CŏȂ悤ɒ) +***************************************************************/ +static void PreInit(void) +{ + /* + obe[cʃ`FbN + */ + if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) + { + OS_TPrintf("Battery is empty.\n"); + OS_Terminate(); + } + /* + FromBrom֘A + */ + if ( !OSi_FromBromToMenu() ) + { + OS_Terminate(); + } + /* + Zbgp[^(1oCg)L̈(1oCg)ɃRs[ + */ +#define HOTSTART_FLAG_ENABLE 0x80 + *(u8 *)HW_NAND_FIRM_HOTSTART_FLAG = (u8)(MCU_GetFreeRegister( OS_MCU_RESET_VALUE_OFS ) | HOTSTART_FLAG_ENABLE); +} + +/*************************************************************** + PostInit + + e평 +***************************************************************/ +static void PostInit(void) +{ + // PMIC̐ݒ for old version + PM_InitFIRM(); + // AES̏ + AES_Init(); // for encrypted NAND + // AChXbh̍쐬 + CreateIdleThread(); + /* + obe[cʃ`FbN + */ + if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) + { + OS_TPrintf("Battery is empty.\n"); + OS_Terminate(); + } +} + +/*************************************************************** + EraseAll + + sI܂ + 낢Ă + DS[hɂďÎ悢H +***************************************************************/ +static void EraseAll(void) +{ + MI_CpuClearFast( OSi_GetFromFirmAddr(), sizeof(OSFromFirmBuf) ); +#ifdef SDK_FINALROM + MI_CpuClearFast( (void*)HW_TWL_ROM_HEADER_BUF, HW_TWL_ROM_HEADER_BUF_SIZE ); + OS_BootFromFIRM(); +#endif +} + +void TwlSpMain( void ) +{ + int fd; // menu file descriptor + +#ifdef PROFILE_ENABLE + // 0: bootrom + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + InitDebugLED(); + SetDebugLED(++step); // 0x81 + + PreInit(); +#ifdef PROFILE_ENABLE + // 1: after PreInit + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + SetDebugLED(++step); // 0x82 + + OS_InitFIRM(); + OS_EnableIrq(); + OS_EnableInterrupts(); + // 2: after OS_InitFIRM + PUSH_PROFILE(); + SetDebugLED(++step); // 0x83 + + PostInit(); + // 3: after PostInit + PUSH_PROFILE(); + SetDebugLED(++step); // 0x84 + + PM_BackLightOn( FALSE ); + + SDNandContext = &OSi_GetFromFirmAddr()->SDNandContext; + if ( !FATFS_Init( DMA_FATFS_1, DMA_FATFS_2, THREAD_PRIO_FATFS ) ) + { + OS_TPrintf("Failed to call FATFS_Init().\n"); + goto end; + } + // 4: after FATFS_Init + PUSH_PROFILE(); + SetDebugLED(++step); // 0x85 + + PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_SET_PATH ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_SET_PATH).\n"); + goto end; + } + // 5: after PXI + PUSH_PROFILE(); + SetDebugLED(++step); // 0x86 + + PM_BackLightOn( FALSE ); + + if ( (fd = FS_OpenSrl()) < 0 ) + { + OS_TPrintf("Failed to call FS_OpenSrl().\n"); + goto end; + } + // 6: after FS_OpenSrl + PUSH_PROFILE(); + SetDebugLED(++step); // 0x87 + + PM_BackLightOn( FALSE ); + + if ( !FS_LoadHeader( fd ) ) + { + OS_TPrintf("Failed to call FS_LoadHeader().\n"); + goto end; + } + // 7: after FS_LoadHeader + PUSH_PROFILE(); + SetDebugLED(++step); // 0x88 + + PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_DONE_HEADER ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_DONE_HEADER).\n"); + goto end; + } + // 8: after PXI + PUSH_PROFILE(); + SetDebugLED(++step); // 0x89 + + PM_BackLightOn( FALSE ); + + AESi_InitKeysFIRM(); + AESi_RecvSeed( rh->s.developer_encrypt ); + // 9: after AESi_RecvSeed + PUSH_PROFILE(); + SetDebugLED(++step); // 0x8a + + PM_BackLightOn( FALSE ); + + if ( !FS_LoadStatic( fd ) ) + { + OS_TPrintf("Failed to call FS_LoadStatic().\n"); + goto end; + } + // 10: after FS_LoadStatic + PUSH_PROFILE(); + SetDebugLED(++step); // 0x8b + + PM_BackLightOn( FALSE ); + + if ( PXI_RecvID() != FIRM_PXI_ID_DONE_STATIC ) + { + OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_DONE_STATIC).\n"); + goto end; + } + // 11: after PXI + PUSH_PROFILE(); + +#ifdef PROFILE_ENABLE + { + int i; + PXI_RecvID(); + OS_TPrintf("\n[ARM7] Begin\n"); + for (i = 0; i < PROFILE_MAX; i++) + { +// OS_TPrintf("0x%08X\n", profile[i]); + if ( !profile[i] ) break; + OS_TPrintf("%2d: %7d usec", i, profile[i]); + if (i) + { + OS_TPrintf(" ( %7d usec )\n", profile[i]-profile[i-1]); + } + else + { + OS_TPrintf("\n"); + } + } + OS_TPrintf("\n[ARM7] End\n"); + } +#endif + SetDebugLED( 0 ); + + PM_BackLightOn( TRUE ); // last chance + + PMi_SetParams( REG_PMIC_BL_BRT_B_ADDR, 22, PMIC_BL_BRT_B_MASK ); + OS_BootFromFIRM(); + +end: + SetDebugLED( (u8)(0xF0 | step)); + + EraseAll(); + + // failed + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + OS_Terminate(); +} + diff --git a/build/nandfirm/sdmc-launcher/ARM9/Makefile b/build/nandfirm/sdmc-launcher/ARM9/Makefile new file mode 100644 index 00000000..1c0bbd29 --- /dev/null +++ b/build/nandfirm/sdmc-launcher/ARM9/Makefile @@ -0,0 +1,51 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - sdmc-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = sdmc_launcher9.srl + +SRCS = main.c + +CRT0_O = crt0_firm.o + +MAKEROM_ARM7 = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/sdmc_launcher7.tef +MAKEROM_ARM7_BASE = $(basename $(MAKEROM_ARM7)) + +#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/nandfirm/sdmc-launcher/ARM9/main.c b/build/nandfirm/sdmc-launcher/ARM9/main.c new file mode 100644 index 00000000..fdca66e0 --- /dev/null +++ b/build/nandfirm/sdmc-launcher/ARM9/main.c @@ -0,0 +1,351 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - nandfirm - sdmc-launcher + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include + +#define RSA_KEY_ADDR rsa_key + +#ifndef FIRM_USE_TWLSDK_KEYS +static const u8 rsa_key[128] = +{ + 0xC7, 0x94, 0x50, 0x00, 0x3A, 0xE1, 0x0E, 0x6C, 0xA8, 0xD1, 0xC0, 0x2D, 0x77, 0xB7, 0x6D, 0xBC, + 0x31, 0xDB, 0x12, 0x08, 0x09, 0x0D, 0x2A, 0xE8, 0xC9, 0x1A, 0x2B, 0x6E, 0x6C, 0x85, 0x78, 0xD7, + 0x46, 0x50, 0x05, 0xB5, 0xCC, 0x3B, 0xEC, 0xBA, 0xF4, 0xDE, 0xC2, 0x13, 0x13, 0xBE, 0x67, 0xEE, + 0x85, 0x19, 0xEB, 0x62, 0xB3, 0x5C, 0x09, 0xA8, 0x54, 0x44, 0x26, 0x85, 0x25, 0xEA, 0xE5, 0x85, + 0xD1, 0xB5, 0xCE, 0xA0, 0xFF, 0x6B, 0x61, 0xCA, 0x94, 0xC1, 0x67, 0xBE, 0xC0, 0x7E, 0x3B, 0xFF, + 0x12, 0x9B, 0x79, 0xDB, 0xAC, 0xD3, 0x5A, 0x3F, 0x14, 0x37, 0x49, 0xA8, 0x7C, 0x2F, 0x07, 0xF4, + 0x8B, 0xA9, 0x8B, 0x8D, 0xB2, 0x60, 0xA5, 0xD5, 0x64, 0xEE, 0xCF, 0x3F, 0x32, 0xEE, 0x77, 0xAC, + 0x27, 0x75, 0x2B, 0x04, 0xD7, 0x26, 0xA8, 0x8A, 0x55, 0x2A, 0x76, 0xE5, 0x68, 0x80, 0x57, 0x85 +}; +#else +static const u8 rsa_key[128] = +{ + 0xAC, 0x93, 0xBB, + 0x3C, 0x15, 0x5C, 0x5F, 0x25, 0xB0, 0x4C, 0x37, 0xA4, 0x2D, 0x85, 0x29, 0x1D, 0x7A, 0x9D, 0x2D, + 0xD5, 0x79, 0xB5, 0x5D, 0xB1, 0x08, 0x20, 0x9C, 0xF0, 0x4C, 0x56, 0x27, 0x97, 0xF8, 0x7E, 0x3E, + 0xCB, 0x94, 0x06, 0x05, 0x94, 0x00, 0x92, 0x9B, 0xB0, 0x5B, 0x06, 0xF6, 0xAF, 0xAA, 0x9C, 0xA5, + 0xF0, 0x11, 0xA7, 0x8A, 0xCB, 0x0C, 0x11, 0xD6, 0x0C, 0x3D, 0x30, 0xAC, 0x51, 0x79, 0x5A, 0xB5, + 0x7F, 0x11, 0x92, 0x74, 0x48, 0x82, 0x81, 0xBF, 0x3B, 0xFA, 0x93, 0xBF, 0x6B, 0x5B, 0x3F, 0x86, + 0x96, 0x4F, 0xCC, 0x90, 0x12, 0xB2, 0x39, 0x8D, 0x68, 0x16, 0x7B, 0xC6, 0x87, 0xF1, 0xF5, 0x60, + 0x62, 0x39, 0xFB, 0x10, 0x7E, 0x48, 0x7F, 0xDD, 0x82, 0x38, 0x38, 0x76, 0xB5, 0xCE, 0x21, 0x4B, + 0xC9, 0x6F, 0x31, 0x8D, 0x23, 0x57, 0x3D, 0xB6, 0x6C, 0xEE, 0xC2, 0x0D, 0x11 +}; +#endif + +#define RSA_HEAP_SIZE (4*1024) // RSApq[vTCY (TCYKv) + +static u8 acHeap[RSA_HEAP_SIZE] __attribute__ ((aligned (32))); +static SVCSignHeapContext acPool; + +#define MENU_FILE "sdmc:/menu.srl" +#define MENU_FILE_A "sdmc:/menu_a.srl" +#define MENU_FILE_B "sdmc:/menu_b.srl" +#define MENU_FILE_L "sdmc:/menu_l.srl" +#define MENU_FILE_R "sdmc:/menu_r.srl" + +/* + PROFILE_ENABLE `Ƃx̃ptH[}X`FbNł܂B + p邽߂ɂ́Amain.cǂɁAu32 profile[256]; u32 pf_cnt = 0; + `Kv܂B +*/ +#define PROFILE_ENABLE + +/* + PRINT_MEMORY_ADDR `ƁÃAhXSPrintfs܂(̃t@Ĉ) + FINALROMłłR[hĉŒӂĂB +*/ +//#define PRINT_MEMORY_ADDR 0x02FFC000 + +//#ifdef SDK_FINALROM // FINALROMŖ +//#undef PROFILE_ENABLE +//#endif + +#ifdef PROFILE_ENABLE +#define PROFILE_MAX 16 +u32 profile[PROFILE_MAX]; +u32 pf_cnt = 0; +#define PUSH_PROFILE() (profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick())) +#else +#define PUSH_PROFILE() ((void)0) +#endif + +#ifdef PRINT_MEMORY_ADDR +static char* debugPtr = (char*)PRINT_MEMORY_ADDR; +#undef OS_TPrintf +//#define OS_TPrintf(...) (debugPtr = (char*)((u32)(debugPtr + STD_TSPrintf(debugPtr, __VA_ARGS__) + 0xf) & ~0xf)) +#define OS_TPrintf(...) (debugPtr += STD_TSPrintf(debugPtr, __VA_ARGS__)) +#endif + +/*************************************************************** + PreInit + + FromBoot̑ΉOS_InitOɕKvȃC̏ +***************************************************************/ +static void PreInit(void) +{ + static const OSMountInfo firmSettings[] = + { + // drive device target pertitionIdx resource userPermission rsvA B archive path + { 'A', OS_MOUNT_DEVICE_SD, OS_MOUNT_TGT_ROOT, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "sdmc", "/" }, + { 'B', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_ROOT, 0, OS_MOUNT_RSC_WRAM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "nand", "/" }, // [U[Av͂̃A[JCułWrites + { 'C', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_ROOT, 1, OS_MOUNT_RSC_WRAM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "nand2", "/" }, // [U[Av͂̃A[JCułWrites + { 'D', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_DIR, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "shared2", "nand2:/shared2" }, + { 'E', OS_MOUNT_DEVICE_NAND, OS_MOUNT_TGT_DIR, 0, OS_MOUNT_RSC_MMEM, (OS_MOUNT_USR_R|OS_MOUNT_USR_W), 0, 0, "photo", "nand2:/photo" }, + { 0 } + }; + /* + C֘A + */ + // SHARED̈NA + MI_CpuClearFast((void *)HW_WRAM_EX_LOCK_BUF, (HW_WRAM_EX_LOCK_BUF_END - HW_WRAM_EX_LOCK_BUF)); + MI_CpuClearFast((void *)HW_BIOS_EXCP_STACK_MAIN, (HW_REAL_TIME_CLOCK_BUF - HW_BIOS_EXCP_STACK_MAIN)); + MI_CpuClearFast((void *)HW_PXI_SIGNAL_PARAM_ARM9, (HW_MMEMCHECKER_MAIN - HW_PXI_SIGNAL_PARAM_ARM9)); + MI_CpuClearFast((void*)HW_ROM_HEADER_BUF, (HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF)); + + // FS_MOUNT̈̏ + MI_CpuCopy8(firmSettings, (char*)HW_TWL_FS_MOUNT_INFO_BUF, sizeof(firmSettings)); + + /* + FromBrom֘A + */ + if ( !OSi_FromBromToMenu() ) + { + OS_Terminate(); + } + + // u[g^Cv̕ύX + ( (OSBootInfo *)OS_GetBootInfo() )->boot_type = OS_BOOTTYPE_NAND; +} + +/*************************************************************** + PostInit + + e평 +***************************************************************/ +static void PostInit(void) +{ + // RSApq[vݒ + SVC_InitSignHeap( &acPool, acHeap, sizeof(acHeap) ); + // HMACp + FS_SetDigestKey( NULL ); + // FS/FATFS + FS_InitFIRM(); +} + +/*************************************************************** + CheckHeader + + wb_VXej[ƂĖȂ`FbN +***************************************************************/ +static BOOL CheckHeader(void) +{ + static ROM_Header_Short* const rhs = (ROM_Header_Short*)HW_TWL_ROM_HEADER_BUF; + // CjVR[hȂ + OS_TPrintf("Initial Code : %08X (%.4s)\n", *(u32*)rhs->game_code, rhs->game_code); + OS_TPrintf("Platform Code : %02X\n", rhs->platform_code); + OS_TPrintf("Codec Mode : %s\n", rhs->codec_mode ? "TWL" : "NITRO"); + OS_TPrintf("Sigunature : %s\n", rhs->enable_signature ? "AVAILABLE" : "NOT AVAILABLE"); + OS_TPrintf("AES Encryption : %s\n", rhs->enable_aes ? "AVAILABLE" : "NOT AVAILABLE"); + if ( rhs->enable_aes ) + { + OS_TPrintf("AES Key Type : %s\n", rhs->developer_encrypt ? "FOR DEVELOPMENT" : "FOR PRODUCT"); + } + // Gg|Cg + OS_TPrintf("ARM9 Entry point : %08X\n", rhs->main_entry_address); + OS_TPrintf("ARM7 Entry point : %08X\n", rhs->sub_entry_address); + // [h͈ + OS_TPrintf("ARM9 ROM address : %08X\n", rhs->main_rom_offset); + OS_TPrintf("ARM9 RAM address : %08X\n", rhs->main_ram_address); + OS_TPrintf("ARM9 size : %08X\n", rhs->main_size); + OS_TPrintf("ARM7 ROM address : %08X\n", rhs->sub_rom_offset); + OS_TPrintf("ARM7 RAM address : %08X\n", rhs->sub_ram_address); + OS_TPrintf("ARM7 size : %08X\n", rhs->sub_size); + OS_TPrintf("ARM9 LTD ROM address: %08X\n", rhs->main_ltd_rom_offset); + OS_TPrintf("ARM9 LTD RAM address: %08X\n", rhs->main_ltd_ram_address); + OS_TPrintf("ARM9 LTD size : %08X\n", rhs->main_ltd_size); + OS_TPrintf("ARM7 LTD ROM address: %08X\n", rhs->sub_ltd_rom_offset); + OS_TPrintf("ARM7 LTD RAM address: %08X\n", rhs->sub_ltd_ram_address); + OS_TPrintf("ARM7 LTD size : %08X\n", rhs->sub_ltd_size); + // قڍœKς +#ifndef FIRM_USE_TWLSDK_KEYS + if ( rhs->platform_code != PLATFORM_CODE_TWL_LIMITED || // TWL Limited only + !rhs->enable_signature || // Should be use ROM header signature +#else + if ( // no check +#endif + !rhs->codec_mode || // TWL mode only + // should be in main memory + HW_TWL_MAIN_MEM > (u32)rhs->main_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->sub_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->main_ltd_ram_address || + HW_TWL_MAIN_MEM > (u32)rhs->sub_ltd_ram_address || + // should be in static area without Limited region + (u32)rhs->main_ram_address > (u32)rhs->main_entry_address || + (u32)rhs->sub_ram_address > (u32)rhs->sub_entry_address || + // should be in main memory (end address) + HW_TWL_MAIN_MEM_END <= (u32)rhs->main_ram_address + rhs->main_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->sub_ram_address + rhs->sub_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->main_ltd_ram_address + rhs->main_ltd_size || + HW_TWL_MAIN_MEM_END <= (u32)rhs->sub_ltd_ram_address + rhs->sub_ltd_size || + // should be in static area without Limited region (end address) + (u32)rhs->main_ram_address + rhs->main_size <= (u32)rhs->main_entry_address || + (u32)rhs->sub_ram_address + rhs->sub_size <= (u32)rhs->sub_entry_address || + 0 ) + { + OS_TPrintf("Invalid ROM header for SDMC Launcher!\n"); + return FALSE; + } + return TRUE; +} + +/*************************************************************** + EraseAll + + sI܂ + 낢Ă + DS[hɂďÎ悢H +***************************************************************/ +static void EraseAll(void) +{ + MI_CpuClearFast( OSi_GetFromFirmAddr(), sizeof(OSFromFirmBuf) ); +#ifdef SDK_FINALROM + MI_CpuClearFast( (void*)HW_TWL_ROM_HEADER_BUF, HW_TWL_ROM_HEADER_BUF_SIZE ); + MI_CpuClearFast( (void*)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF ); + OS_BootFromFIRM(); +#endif +} + +void TwlMain( void ) +{ +#ifdef PROFILE_ENABLE + // 0: bootrom + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + + PreInit(); +#ifdef PROFILE_ENABLE + // 1: before Init + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); +#endif + + OS_InitFIRM(); + OS_EnableIrq(); + OS_EnableInterrupts(); +#ifdef PROFILE_ENABLE + // 2: before OS_InitTick + profile[pf_cnt++] = OS_TicksToMicroSecondsBROM32(OS_GetTick()); + + OS_InitTick(); +#endif + + PostInit(); + // 3: after PostInit + PUSH_PROFILE(); + + switch ( PAD_Read() & PAD_KEYPORT_MASK ) + { + case 0: + STD_CopyString((char*)HW_TWL_FS_BOOT_SRL_PATH_BUF, MENU_FILE); + break; + case PAD_BUTTON_A: + STD_CopyString((char*)HW_TWL_FS_BOOT_SRL_PATH_BUF, MENU_FILE_A); + break; + case PAD_BUTTON_B: + STD_CopyString((char*)HW_TWL_FS_BOOT_SRL_PATH_BUF, MENU_FILE_B); + break; + case PAD_BUTTON_L: + STD_CopyString((char*)HW_TWL_FS_BOOT_SRL_PATH_BUF, MENU_FILE_L); + break; + case PAD_BUTTON_R: + STD_CopyString((char*)HW_TWL_FS_BOOT_SRL_PATH_BUF, MENU_FILE_R); + break; + default: + OS_TPrintf("Unknown pad pattern (%X).\n", PAD_Read() & PAD_KEYPORT_MASK); + goto end; + } + // 4: after FS_ResolveSrl + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_SET_PATH ); + // 5: after PXI + PUSH_PROFILE(); + + if ( !FS_LoadHeader(&acPool, RSA_KEY_ADDR ) || !CheckHeader() ) + { + OS_TPrintf("Failed to call FS_LoadHeader() and/or CheckHeader().\n"); + goto end; + } + // 6: after FS_LoadHeader + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_DONE_HEADER ); + // 7: after PXI + PUSH_PROFILE(); + + AESi_SendSeed( FS_GetAesKeySeed() ); + FS_DeleteAesKeySeed(); + // 8: after AESi_SendSeed + PUSH_PROFILE(); + + if ( !FS_LoadStatic() ) + { + OS_TPrintf("Failed to call FS_LoadStatic().\n"); + goto end; + } + // 9: after FS_LoadStatic + PUSH_PROFILE(); + + PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); + // 10: after PXI + PUSH_PROFILE(); + +#ifdef PROFILE_ENABLE + { + int i; + OS_TPrintf("\n[ARM9] Begin\n"); + for (i = 0; i < PROFILE_MAX; i++) + { +// OS_TPrintf("0x%08X\n", profile[i]); + if ( !profile[i] ) break; + OS_TPrintf("%2d: %7d usec", i, profile[i]); + if (i) + { + OS_TPrintf(" ( %7d usec )\n", profile[i]-profile[i-1]); + } + else + { + OS_TPrintf("\n"); + } + } + OS_TPrintf("\n[ARM9] End\n"); + PXI_NotifyID( FIRM_PXI_ID_NULL ); + } +#endif + + MI_CpuClearFast( OSi_GetFromFirmAddr(), sizeof(OSFromFirmBuf) ); + OS_BootFromFIRM(); + +end: + EraseAll(); + + // failed + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + PXI_NotifyID( FIRM_PXI_ID_ERR ); + OS_Terminate(); +} + diff --git a/build/nandfirm/sdmc-launcher/Makefile b/build/nandfirm/sdmc-launcher/Makefile new file mode 100644 index 00000000..3e3117e5 --- /dev/null +++ b/build/nandfirm/sdmc-launcher/Makefile @@ -0,0 +1,52 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - sdmc-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + + +# if you have valid keys, set environment value like below +#export TWL_KEYSDIR='$(TWL_IPL_RED_ROOT)/../twl_firmware/bootrom/build/keys' + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + wram_regs \ + ARM7 \ + ARM9 \ + +TARGET_FIRM_BIN = sdmc_launcher-$(TWL_BUILD_TYPE)$(CODEGEN_ARCH).nand +BINDIR = . +MAKEFIRM_ARM9 = ARM9/bin/$(TWL_BUILDTYPE_ARM9)/sdmc_launcher9.tef +MAKEFIRM_ARM7 = ARM7/bin/$(TWL_BUILDTYPE_ARM7)/sdmc_launcher7.tef +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_nand.der +LDEPENDS_BIN += wram_regs/wram_regs.rbin + +MAKEFIRM_FLAGS += -p +FIRM_SPEC = nandfirm.nandsf + +LDIRT_CLEAN += $(wildcard *.nand) \ + rsa_public.sbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/nandfirm/sdmc-launcher/nandfirm.nandsf b/build/nandfirm/sdmc-launcher/nandfirm.nandsf new file mode 100644 index 00000000..29cd4bf6 --- /dev/null +++ b/build/nandfirm/sdmc-launcher/nandfirm.nandsf @@ -0,0 +1,24 @@ +#NANDSF --- Nandfirm Spec File + +VERSION : GENERATE + +RSA_KEY : $(MAKEFIRM_RSA_PRVKEY) +OUT_KEY : rsa_public.sbin + +WRAM_RBIN: ./wram_regs/wram_regs.rbin + +MIRROR_OFS: 0x100000 + +DECOMP_PROC : ARM9 # ARM9 or ARM7 + +ARM9_COMP : FALSE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).TWL.FLX.sbin +ARM9_ELF : $(MAKEFIRM_ARM9).tef + +ARM7_COMP : FALSE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).TWL.FLX.sbin +ARM7_ELF : $(MAKEFIRM_ARM7).tef + +ARM9_X2 : TRUE # TRUE or FALSE + +NCD_ROMOFS : 0x07fe00 diff --git a/build/nandfirm/sdmc-launcher/wram_regs/Makefile b/build/nandfirm/sdmc-launcher/wram_regs/Makefile new file mode 100644 index 00000000..a9bc2f39 --- /dev/null +++ b/build/nandfirm/sdmc-launcher/wram_regs/Makefile @@ -0,0 +1,57 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - nandfirm - sdmc-launcher +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM := TWL +override TARGET_CODEGEN := ARM +override TWL_ARCHGEN := LIMITED + +override TARGET_FINALROM := TRUE +override TARGET_RELEASE := +override TARGET_DEBUG := + +SUBDIRS = + +LINCLUDES = ../include + + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/nandfirm/sdmc-launcher/wram_regs/wram_regs.c b/build/nandfirm/sdmc-launcher/wram_regs/wram_regs.c new file mode 100644 index 00000000..2454b302 --- /dev/null +++ b/build/nandfirm/sdmc-launcher/wram_regs/wram_regs.c @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - nandfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM9 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_A_SIZE ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE - HW_WRAM_C_SIZE ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/norfirm/Makefile b/build/norfirm/Makefile new file mode 100644 index 00000000..e49922b3 --- /dev/null +++ b/build/norfirm/Makefile @@ -0,0 +1,35 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - firmware +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + firm-dev \ + norfirm-print \ + norfirm-empty \ + + +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/norfirm/firm-dev/ARM7/Makefile b/build/norfirm/firm-dev/ARM7/Makefile new file mode 100644 index 00000000..97c1de2a --- /dev/null +++ b/build/norfirm/firm-dev/ARM7/Makefile @@ -0,0 +1,49 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - firm-dev +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +TWL_PROC = ARM7 + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = firm_dev7.tef + +CRT0_O = crt0_firm.o + +SRCS = \ + main.c \ + +#SRCDIR = # using default +#LCFILE = # using default + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/norfirm/firm-dev/ARM7/main.c b/build/norfirm/firm-dev/ARM7/main.c new file mode 100644 index 00000000..f004af8d --- /dev/null +++ b/build/norfirm/firm-dev/ARM7/main.c @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - norfirm-print + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-11#$ + $Rev: 22 $ + $Author: yutaka $ + *---------------------------------------------------------------------------*/ +#include +#include "reboot.h" + +//#define PRINT_DEBUG + +#ifndef PRINT_DEBUG +#undef OS_TPrintf +#define OS_TPrintf(...) ((void)0) +#endif // PRINT_DEBUG + +void TwlSpMain( void ) +{ + OS_TPrintf( "\nNOR Boot time is %d msec.\n", OS_TicksToMilliSecondsBROM32(OS_GetTick())); + +// MIi_CpuClearFast( 0, (void*)HW_TWL_ROM_HEADER_BUF, HW_MAIN_MEM_SYSTEM_END - HW_TWL_ROM_HEADER_BUF ); // include HW_MAIN_MEM_SHARED + MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) ); + + OS_InitFIRM(); + + OS_TPrintf( "\nARM7 starts.\n" ); + + OS_EnableInterrupts(); + OS_EnableIrq(); + + PM_InitFIRM(); + PMi_SetParams( REG_PMIC_BL_BRT_A_ADDR, PMIC_BACKLIGHT_BRIGHT_MAX, PMIC_BL_BRT_A_MASK ); + PMi_SetParams( REG_PMIC_BL_BRT_B_ADDR, PMIC_BACKLIGHT_BRIGHT_MAX, PMIC_BL_BRT_B_MASK ); + PM_BackLightOn( TRUE ); + + OS_TPrintf( "\nARM7 ends.\n" ); + + REBOOT_DisableInterruptsAndProtectionUnit(); + reg_SCFG_JTAG = REG_SCFG_JTAG_CPUJE_MASK | REG_SCFG_JTAG_ARM7SEL_MASK | REG_SCFG_JTAG_DSPJE_MASK; + while (1) + { + } +// OS_Terminate(); +} + diff --git a/build/norfirm/firm-dev/ARM9/Makefile b/build/norfirm/firm-dev/ARM9/Makefile new file mode 100644 index 00000000..6b2904e5 --- /dev/null +++ b/build/norfirm/firm-dev/ARM9/Makefile @@ -0,0 +1,48 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - firm-dev +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = firm_dev9.srl + +SRCS = main.c + +CRT0_O = crt0_firm.o + +MAKEROM_ARM7 = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/firm_dev7.tef +MAKEROM_ARM7_BASE = $(basename $(MAKEROM_ARM7)) + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/norfirm/firm-dev/ARM9/main.c b/build/norfirm/firm-dev/ARM9/main.c new file mode 100644 index 00000000..13b33851 --- /dev/null +++ b/build/norfirm/firm-dev/ARM9/main.c @@ -0,0 +1,41 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - norfirm-print + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-11#$ + $Rev: 22 $ + $Author: yutaka $ + *---------------------------------------------------------------------------*/ +#include +#include "reboot.h" + +//#define PRINT_DEBUG + +#ifndef PRINT_DEBUG +#undef OS_TPrintf +#define OS_TPrintf(...) ((void)0) +#endif // PRINT_DEBUG + +void TwlMain( void ) +{ + OS_TPrintf( "\nNOR Boot time is %d msec.\n", OS_TicksToMilliSecondsBROM32(OS_GetTick())); + + MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) ); + + OS_InitFIRM(); + + OS_TPrintf( "\nARM9 starts.\n" ); + OS_TPrintf( "\nARM9 ends.\n" ); + + REBOOT_DisableInterruptsAndProtectionUnit(); + OS_Terminate(); +} + diff --git a/build/norfirm/firm-dev/Makefile b/build/norfirm/firm-dev/Makefile new file mode 100644 index 00000000..0777144a --- /dev/null +++ b/build/norfirm/firm-dev/Makefile @@ -0,0 +1,53 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - build +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + + +# if you have no valid key, comment out next line +#TWL_KEYSDIR = $(FIRM_ROOT)/../twl_firmware/bootrom/build/keys + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + wram_regs \ + ARM7 \ + ARM9 \ + +TARGET_FIRM_BIN = firm_dev-$(TWL_BUILD_TYPE)$(CODEGEN_ARCH).nor +BINDIR = . +MAKEFIRM_ARM9 = ARM9/bin/$(TWL_BUILDTYPE_ARM9)/firm_dev9.tef +MAKEFIRM_ARM7 = ARM7/bin/$(TWL_BUILDTYPE_ARM7)/firm_dev7.tef +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_nor.der +LDEPENDS_BIN += wram_regs/wram_regs.rbin + +MAKEFIRM_FLAGS += -p +FIRM_SPEC = norfirm.norsf + +LDIRT_CLEAN += $(wildcard *.nor) \ + rsa_public.sbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/norfirm/firm-dev/norfirm.norsf b/build/norfirm/firm-dev/norfirm.norsf new file mode 100644 index 00000000..42f93272 --- /dev/null +++ b/build/norfirm/firm-dev/norfirm.norsf @@ -0,0 +1,25 @@ +#NORSF --- Norfirm Spec File + +VERSION : GENERATE + +BOOT_NAND : TRUE # TRUE or FALSE + +RSA_KEY : $(MAKEFIRM_RSA_PRVKEY) +OUT_KEY : rsa_public.sbin + +WRAM_RBIN: ./wram_regs/wram_regs.rbin + +DECOMP_PROC : ARM9 # ARM9 or ARM7 + +ARM9_COMP : TRUE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).TWL.FLX.sbin +ARM9_ELF : $(MAKEFIRM_ARM9).tef + +ARM7_COMP : TRUE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).TWL.FLX.sbin +ARM7_ELF : $(MAKEFIRM_ARM7).tef + +NCD_ROMOFS : 0x07fe00 + +BAUDRATE : 8M # 4M or 8M +ARM9_X2 : TRUE # TRUE or FALSE diff --git a/build/norfirm/firm-dev/wram_regs/Makefile b/build/norfirm/firm-dev/wram_regs/Makefile new file mode 100644 index 00000000..427c35a2 --- /dev/null +++ b/build/norfirm/firm-dev/wram_regs/Makefile @@ -0,0 +1,57 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - norfirm-print +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM := TWL +override TARGET_CODEGEN := ARM +override TWL_ARCHGEN := LIMITED + +override TARGET_FINALROM := TRUE +override TARGET_RELEASE := +override TARGET_DEBUG := + +SUBDIRS = + +LINCLUDES = ../include + + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/norfirm/firm-dev/wram_regs/wram_regs.c b/build/norfirm/firm-dev/wram_regs/wram_regs.c new file mode 100644 index 00000000..f03e0e14 --- /dev/null +++ b/build/norfirm/firm-dev/wram_regs/wram_regs.c @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - nandfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-11-12#$ + $Rev: 149 $ + $Author: yutaka $ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM9 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_A_SIZE ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA + HW_WRAM_B_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE ), + MI_WRAM_IMAGE_256KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF - HW_WRAM_SIZE - HW_WRAM_C_SIZE ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/norfirm/norfirm-empty/Makefile b/build/norfirm/norfirm-empty/Makefile new file mode 100644 index 00000000..c518dda7 --- /dev/null +++ b/build/norfirm/norfirm-empty/Makefile @@ -0,0 +1,50 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - build +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM := TWL +override TARGET_CODEGEN := ARM +override TWL_ARCHGEN := LIMITED + +override TARGET_FINALROM := TRUE +override TARGET_RELEASE := +override TARGET_DEBUG := + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + +TARGET_FIRM_BIN = norfirm_empty.nor +BINDIR = . +MAKEFIRM_ARM9 = +MAKEFIRM_ARM7 = +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_nor.der +MAKEFIRM_FLAGS += -p +FIRM_SPEC = norfirm-BB.norsf + +LDIRT_CLEAN += $(TARGETS) \ + rsa_public.sbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/norfirm/norfirm-empty/norfirm-BB.norsf b/build/norfirm/norfirm-empty/norfirm-BB.norsf new file mode 100644 index 00000000..319e6851 --- /dev/null +++ b/build/norfirm/norfirm-empty/norfirm-BB.norsf @@ -0,0 +1,8 @@ +#NORSF --- Norfirm Spec File + +VERSION : GENERATE + +BOOT_NAND : TRUE # TRUE or FALSE + +NCD_ROMOFS : 0x07fe00 + diff --git a/build/norfirm/norfirm-print/ARM7/Makefile b/build/norfirm/norfirm-print/ARM7/Makefile new file mode 100644 index 00000000..53b0578c --- /dev/null +++ b/build/norfirm/norfirm-print/ARM7/Makefile @@ -0,0 +1,49 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - norfirm-print +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +TWL_PROC = ARM7 + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = twl_norfirm7_print.tef + +CRT0_O = crt0_firm.o + +SRCS = \ + main.c \ + +#SRCDIR = # using default +#LCFILE = # using default + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/norfirm/norfirm-print/ARM7/main.c b/build/norfirm/norfirm-print/ARM7/main.c new file mode 100644 index 00000000..13134a0f --- /dev/null +++ b/build/norfirm/norfirm-print/ARM7/main.c @@ -0,0 +1,31 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - norfirm-print + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include + + +void TwlSpMain( void ) +{ + OS_TPrintf( "\nNOR Boot time is %d msec.\n", OS_TicksToMilliSecondsBROM32(OS_GetTick())); + + OS_InitFIRM(); + + OS_TPrintf( "\nARM7 starts.\n" ); + OS_TPrintf( "\nARM7 ends.\n" ); + + OS_Terminate(); +} + diff --git a/build/norfirm/norfirm-print/ARM9/Makefile b/build/norfirm/norfirm-print/ARM9/Makefile new file mode 100644 index 00000000..6f5d8a9f --- /dev/null +++ b/build/norfirm/norfirm-print/ARM9/Makefile @@ -0,0 +1,48 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - norfirm-print +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = twl_norfirm9_print.srl + +SRCS = main.c + +CRT0_O = crt0_firm.o + +MAKEROM_ARM7 = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/twl_norfirm7_print.tef +MAKEROM_ARM7_BASE = $(basename $(MAKEROM_ARM7)) + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/norfirm/norfirm-print/ARM9/main.c b/build/norfirm/norfirm-print/ARM9/main.c new file mode 100644 index 00000000..08f1fdb1 --- /dev/null +++ b/build/norfirm/norfirm-print/ARM9/main.c @@ -0,0 +1,31 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - norfirm-print + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include + + +void TwlMain( void ) +{ + OS_TPrintf( "\nNOR Boot time is %d msec.\n", OS_TicksToMilliSecondsBROM32(OS_GetTick())); + + OS_InitFIRM(); + + OS_TPrintf( "\nARM9 starts.\n" ); + OS_TPrintf( "\nARM9 ends.\n" ); + + OS_Terminate(); +} + diff --git a/build/norfirm/norfirm-print/Makefile b/build/norfirm/norfirm-print/Makefile new file mode 100644 index 00000000..3e9e4ff6 --- /dev/null +++ b/build/norfirm/norfirm-print/Makefile @@ -0,0 +1,53 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - build +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + + +# if you have no valid key, comment out next line +#TWL_KEYSDIR = $(FIRM_ROOT)/../twl_firmware/bootrom/build/keys + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + wram_regs \ + ARM7 \ + ARM9 \ + +TARGET_FIRM_BIN = norfirm_print-$(TWL_BUILD_TYPE)$(CODEGEN_ARCH).nor +BINDIR = . +MAKEFIRM_ARM9 = ARM9/bin/$(TWL_BUILDTYPE_ARM9)/twl_norfirm9_print.tef +MAKEFIRM_ARM7 = ARM7/bin/$(TWL_BUILDTYPE_ARM7)/twl_norfirm7_print.tef +MAKEFIRM_RSA_PRVKEY = $(TWL_KEYSDIR)/rsa/private_nor.der +LDEPENDS_BIN += wram_regs/wram_regs.rbin + +MAKEFIRM_FLAGS += -p +FIRM_SPEC = norfirm-BB.norsf + +LDIRT_CLEAN += $(wildcard *.nor) \ + rsa_public.sbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build: $(TARGET_BIN) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/norfirm/norfirm-print/norfirm-BB.norsf b/build/norfirm/norfirm-print/norfirm-BB.norsf new file mode 100644 index 00000000..42f93272 --- /dev/null +++ b/build/norfirm/norfirm-print/norfirm-BB.norsf @@ -0,0 +1,25 @@ +#NORSF --- Norfirm Spec File + +VERSION : GENERATE + +BOOT_NAND : TRUE # TRUE or FALSE + +RSA_KEY : $(MAKEFIRM_RSA_PRVKEY) +OUT_KEY : rsa_public.sbin + +WRAM_RBIN: ./wram_regs/wram_regs.rbin + +DECOMP_PROC : ARM9 # ARM9 or ARM7 + +ARM9_COMP : TRUE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).TWL.FLX.sbin +ARM9_ELF : $(MAKEFIRM_ARM9).tef + +ARM7_COMP : TRUE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).TWL.FLX.sbin +ARM7_ELF : $(MAKEFIRM_ARM7).tef + +NCD_ROMOFS : 0x07fe00 + +BAUDRATE : 8M # 4M or 8M +ARM9_X2 : TRUE # TRUE or FALSE diff --git a/build/norfirm/norfirm-print/wram_regs/Makefile b/build/norfirm/norfirm-print/wram_regs/Makefile new file mode 100644 index 00000000..427c35a2 --- /dev/null +++ b/build/norfirm/norfirm-print/wram_regs/Makefile @@ -0,0 +1,57 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - norfirm-print +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM := TWL +override TARGET_CODEGEN := ARM +override TWL_ARCHGEN := LIMITED + +override TARGET_FINALROM := TRUE +override TARGET_RELEASE := +override TARGET_DEBUG := + +SUBDIRS = + +LINCLUDES = ../include + + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/norfirm/norfirm-print/wram_regs/wram_regs.c b/build/norfirm/norfirm-print/wram_regs/wram_regs.c new file mode 100644 index 00000000..ea59c659 --- /dev/null +++ b/build/norfirm/norfirm-print/wram_regs/wram_regs.c @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM9 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF + 0x00020000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF + 0x00020000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA_HALF + 0x00040000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA_HALF + 0x00020000 ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/systemMenu_RED/DS_DownloadPlay/ARM9/ARM9-TS.lsf b/build/systemMenu_RED/DS_DownloadPlay/ARM9/ARM9-TS.lsf new file mode 100644 index 00000000..1b0a503a --- /dev/null +++ b/build/systemMenu_RED/DS_DownloadPlay/ARM9/ARM9-TS.lsf @@ -0,0 +1,70 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-BB.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- +# +# TWL LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x02800000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) +} + +Overlay bm_mainp +{ + After $(TARGET_NAME) + Object $(OBJDIR)/DS_Setting.o $(OBJDIR)/settingMenu.o $(OBJDIR)/rtcSet.o $(OBJDIR)/langSelect.o \ + $(OBJDIR)/tpCalib.o $(OBJDIR)/ownerInfo.o $(OBJDIR)/AgbLcdSel.o $(OBJDIR)/autoBoot.o \ + $(OBJDIR)/unicode.o $(OBJDIR)/misc.o \ + $(OBJDIR)/DS_DownloadPlay.o \ + $(OBJDIR)/DS_Chat.o +} + +Overlay ipl2_data +{ + After bm_mainp + Object ./font/f12han.o +} + + +Autoload ITCM +{ + Address 0x01ff8000 + Object * (.itcm) + Object $(OBJS_AUTOLOAD) (.text) + Object $(OBJS_AUTOLOAD) (.rodata) +} + +Autoload DTCM +{ + Address $(ADDRESS_DTCM) + Object * (.dtcm) + Object $(OBJS_AUTOLOAD) (.data) + Object $(OBJS_AUTOLOAD) (.sdata) + Object $(OBJS_AUTOLOAD) (.bss) + Object $(OBJS_AUTOLOAD) (.sbss) +} + +Ltdautoload LTDMAIN +{ + # NITRO/TWL L̃I[o[C݂ꍇ́Aɂ̌ɔzuKv܂B + After ipl2_data + Object * (.ltdmain) + Object $(OBJS_LTDAUTOLOAD) + Library $(LLIBS_EX) $(GLIBS_EX) +} diff --git a/build/systemMenu_RED/DS_DownloadPlay/ARM9/Makefile b/build/systemMenu_RED/DS_DownloadPlay/ARM9/Makefile new file mode 100644 index 00000000..6a019cc1 --- /dev/null +++ b/build/systemMenu_RED/DS_DownloadPlay/ARM9/Makefile @@ -0,0 +1,52 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +TARGET_BIN = dlplay.srl + +LCFILE_SPEC = ARM9-TS.lsf +ROM_SPEC = main.rsf + +SRCS = main.c mainFunc.c DS_DownloadPlay.c + +LINCLUDES = $(ROOT)/build/libraries/spi/arm9/include \ + $(ROOT)/build/libraries/mb/common/include \ + +LLIBRARY_DIRS = +LLIBRARIES = +LDEPENDS_NEF = + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/DS_DownloadPlay/ARM9/main.rsf b/build/systemMenu_RED/DS_DownloadPlay/ARM9/main.rsf new file mode 100644 index 00000000..df21378b --- /dev/null +++ b/build/systemMenu_RED/DS_DownloadPlay/ARM9/main.rsf @@ -0,0 +1,135 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot data + Root /data + File NTR_IPL_font_m.NFTR +} diff --git a/build/systemMenu_RED/DS_DownloadPlay/ARM9/src/DS_DownloadPlay.c b/build/systemMenu_RED/DS_DownloadPlay/ARM9/src/DS_DownloadPlay.c new file mode 100644 index 00000000..87d6276d --- /dev/null +++ b/build/systemMenu_RED/DS_DownloadPlay/ARM9/src/DS_DownloadPlay.c @@ -0,0 +1,1618 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: DS_DownloadPlay.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$ + *---------------------------------------------------------------------------*/ + +// mb_private.hPRINT_DEBUG"1"ɂĂƁA_E[hɐɃu[głȂȂĂ̂ŁAӁB + +#include +#include // Ƃ̂OK? +#include +#include "mb_child.h" +#include "mb_private.h" + + +#include "misc.h" +#include "DS_Setting.h" +#include "DS_DownloadPlay.h" + +// define data------------------------------------------ +#define PARENT_VIEW_NUM 4 // e@񃊃Xg̈ʕ\ +#define PLIST_X 1 // e@񃊃Xg̕\Xʒu +#define PLIST_Y 4 // e@񃊃Xg̕\Yʒu +#define MB_DMA_NO 2 // }`u[gpDMAԍ +#define PRG_NEXT_SEQ_QUE_NUM 4 // ̃vOV[PXi[L[̐ +#define MY_GGID 0x00000000 // }`u[gpGGID +#define G_INTRO_X 1 // Q[e\Xʒu +#define G_INTRO_Y 4 // Q[e\Yʒu +#define G_MEMBER_X 1 // ʐMo[\Xʒu +#define G_MEMBER_Y 10 // ʐMo[\Yʒu +#define MSG_VIEW_COUNT 75 // bZ[W\VJEg +#define MSG_BLINK_COUNT 12 // bZ[W_ŃJEg + +#define NINLOGO_LOAD_1D_CHAR // NintendoSf[^1D}bsOLN^Ń[hB + + // vOV[PX +typedef enum PrgSeq { + PSEQ_READY = 0, + PSEQ_INIT, + PSEQ_INITIALIZING, + PSEQ_ENDING, + PSEQ_END, + PSEQ_CANCELLED, + PSEQ_DISCONNECTED_BY_PARENT, + PSEQ_SCANNING, + PSEQ_CONNECTING, + PSEQ_CONNECT_SUCCEEDED, + PSEQ_CONNECT_FAILED, + PSEQ_REQ_REFUSED, + PSEQ_MEMBER_FULL, + PSEQ_DOWNLOAD_READY, + PSEQ_DOWNLOADING, + PSEQ_DOWNLOAD_COMPLETED, + PSEQ_DOWNLOAD_FAILED, + PSEQ_BOOT_REQ_WAIT, + PSEQ_BOOT_READY, + PSEQ_BOOT_START, + PSEQ_BOOT_FAILED +}PrgSeq; + +static char *str_prgSeq[] = { + "PSEQ_READY", + "PSEQ_INIT", + "PSEQ_INITIALIZING", + "PSEQ_ENDING", + "PSEQ_END", + "PSEQ_CANCELLED", + "PSEQ_DISCONNECTED_BY_PARENT", + "PSEQ_SCANNING", + "PSEQ_CONNECTING", + "PSEQ_CONNECT_SUCCEEDED", + "PSEQ_CONNECT_FAILED", + "PSEQ_REQ_REFUSED", + "PSEQ_MEMBER_FULL", + "PSEQ_DOWNLOAD_READY", + "PSEQ_DOWNLOADING", + "PSEQ_DOWNLOAD_COMPLETED", + "PSEQ_DOWNLOAD_FAILED", + "PSEQ_BOOT_REQ_WAIT", + "PSEQ_BOOT_READY", + "PSEQ_BOOT_START", + "PSEQ_BOOT_FAILED", +}; + + + // e@񔭌ԃf[^ +typedef struct FindTime { + BOOL find; // ǂ + int vcount; // +}FindTime; + + // bZ[W\Xe[^X +typedef struct MsgViewStatus { + u16 handle; + u16 vcount; + u16 flag; + u16 color; + const u8 *str; + int (*nextProcessp)(void); +}MsgViewStatus; + + // vOV[PXi[pL[ +typedef struct PrgNextSeqQue { + BOOL lock; + u8 pad; + u8 num; + u8 top; + u8 bottom; + PrgSeq seq[ PRG_NEXT_SEQ_QUE_NUM ]; +}PrgNextSeqQue; + + +// extern data------------------------------------------ +extern void MBw_SetMaxScanTime( u16 time ); +extern int MBw_GetScanChannel( void ); +extern void UnCompNintendoLogo( u16 *NintendoLogoDatap, u16 *dstp, u32 *temp ); + +// function's prototype declaration--------------------- + // CV[PX +static void SEQ_DSDL_init( void ); +static int SEQ_DSDL_Connect( void ); +static int SEQ_DSDL_Download( void ); +static BOOL CheckNextSeq_Connect( void ); +static BOOL CheckNextSeq_Download( void ); + // R[obN +static void CallbackChild_MB( u32 status, void *arg ); // }`u[gpR[obN֐ + // \n +static void DispTopScreen( void ); +static void DispScanStatus( void ); +static void DispParentNum( void ); +static void DispParentList( void ); +static void DispGameIntroduction( void ); +static void DispPlayMember( void ); +static void DispParentGameInfo( u32 view_no, u32 listNo, BOOL drawFixedDataFlag ); +static void ClearDispParentGameInfo( u32 view_no, u32 listNo ); +static void DispGameIntroduction_Core( u32 listNo ); +static void DispPlayMember_Core( u32 listNo ); +static void ClearDispGameIntroduction( void ); +static void ClearDispPlayMember( void ); +static void DecimalToString( u8 *dstp, const void *valuep, u8 drawLength, u8 size ); +static void InitParentFindTime( void ); +static void CountParentFindTime( void ); +static BOOL CheckParentFindTime( u32 index ); +static void CountAndDispTotalTime( void ); +static void SetIconOBJ( u32 index ); +static void ClearIconOBJ( u32 index ); +static void SetDispMessage( u16 color, const u8 *str ); +static BOOL DispMessage( void ); +static void SetBlinkMessage( u16 color, const u8 *str ); +static void DispBlinkMessage( void ); + // NintendoS\ +static void InitDispNintendoLogo( void ); +static BOOL DispNintendoLogo( void ); + // ̑ +static void SetMyUserInfo( MBUserInfo *my ); +static BOOL IsScanLock( void ); + // 荞 +static void VBlankIntr_WDL( void ); + // V[PXL[ +static void InitPrgNextSeqQue( void ); +static BOOL SetPrgNextSeqQue( PrgSeq seq ); +static BOOL GetPrgNextSeqQue( PrgSeq *seqp ); +static void LockPrgNextSeqQue( void ); +static void UnlockPrgNextSeqQue( void ); +static BOOL IsEmptyPrgNextSeqQue( void ); + +void SearchPatchAddress( void ); + +// global variable ------------------------------------- + +// static variable ------------------------------------- +static int (*wdProcess)( void ); // ݎs̃vZXւ̃|C^ +static int csrC; // j[̃J[\ʒu +static int csrC_old; // j[̑OJ[\ʒu +static PrgSeq prgSeq; // vOV[PX +static PrgNextSeqQue nextSeq; // ̃vOV[PXi[L[ +static BOOL end_flag; // ItO +static MsgViewStatus msgStat; // bZ[W\Xe[^X +static MBUserInfo myUser; // ̃[U[ +static u16 tgid = 0; +static u16 tp_touch_count = 0; +static u32 gameInfoLostCount = 0; +// e@Xg̕\Ɏgp +static int unrenewalFlag; +static int total_vcount; +static int time_ms; // e@ms +static int time_sec; // e@sec +static u16 msgHandle; // bZ[W\nh +static u16 dispGameInfoFlag; // ɕ\Q[rbgŎB +static u16 dispIntroFlag; // Q[̏ڍ׃f[^`tO +static u16 dispMemberFlag; // Q[̏ڍ׃f[^`tO +static u16 gameName[ MB_GAME_NAME_LENGTH + 1 ]; // e@Q[l[ +static u16 userName[ MB_USER_NAME_LENGTH + 1 ]; // e@[U[l[ +static u16 gameIntroduction[2][ MB_GAME_INTRO_LENGTH / 2 + 1 ]; + // e@Q[e +static u16 playMember[ MB_MEMBER_MAX_NUM ][ MB_USER_NAME_LENGTH + 1]; + // ʐMo[Xg +static u8 parentListNo[ PARENT_VIEW_NUM ][ 4 ] ATTRIBUTE_ALIGN(2); + // e@Xgԍ +static u32 objVramBuff[ (MB_ICON_DATA_SIZE * PARENT_VIEW_NUM + 0x20) / sizeof(u32) ] ATTRIBUTE_ALIGN(32); +static FindTime findTime[ MB_GAME_INFO_RECV_LIST_NUM ]; // e@ԃf[^ +static GXOamAttr oamBakM[ 128 ] ATTRIBUTE_ALIGN(32); // OAM obNAbv + +static const MbBeaconRecvStatus *mbrsp; + +// MBCup[N +static u32 mbwork[ MB_CHILD_SYSTEM_BUF_SIZE / sizeof(u32) ]; + +// NintendoS\ +static int loop_count; +static u32 ninLogoBuff[ 0x700 / sizeof(u32) ]; + +static MBDownloadFileInfo dlfileinfo; +static u8 output_buffer[ AUTH_BUFFER_LEN ]; + +// const data ----------------------------------------- + // \p +static const u8 str_sura[] ATTRIBUTE_ALIGN(2) = "/"; +static const u8 str_period[] ATTRIBUTE_ALIGN(2) = "."; +static const u8 str_sec[] ATTRIBUTE_ALIGN(2) = "sec"; +static const u8 str_disconnected[] ATTRIBUTE_ALIGN(2) = "disconnected by parent."; +static const u8 str_connect_succeeded[] ATTRIBUTE_ALIGN(2) = "connect succeeded."; +static const u8 str_connect_failed[] ATTRIBUTE_ALIGN(2) = "connect failed."; +static const u8 str_req_refused[] ATTRIBUTE_ALIGN(2) = "req refused."; +static const u8 str_member_full[] ATTRIBUTE_ALIGN(2) = "member full."; +static const u8 str_downloading[] ATTRIBUTE_ALIGN(2) = "DOWNLOADING...."; +static const u8 str_download_completed[] ATTRIBUTE_ALIGN(2) = "download completed."; +static const u8 str_download_cancelled[] ATTRIBUTE_ALIGN(2) = "download cancelled."; + + // j[֐p@e@Xg񃊃Xg +static u8 *str_parentListNo[] ATTRIBUTE_ALIGN(2) = { + parentListNo[0], + parentListNo[1], + parentListNo[2], + parentListNo[3], +}; + + // j[֐p@j[\f[^ +static const MenuComponent childModeSel = { + PARENT_VIEW_NUM, // ڐ + PLIST_X, // XʒuiLj + PLIST_Y, // Yʒui@V@@j + 0, // ̍ڂւXʒuL + 4, // ̍ڂւYʒuL + 3, + WHITE, // IF + HIGHLIGHT_Y, // IF + (const u8 **)&str_parentListNo, // j[ڕ񃊃Xg +}; + + +//====================================================== +// C[v +//====================================================== + +// }`u[g̃C[v +int DS_DownloadPlayMain(void) +{ + SEQ_DSDL_init(); + + wdProcess = SEQ_DSDL_Connect; + + OS_TPrintf("MbBeaconRecvStatus:%d\n", sizeof(MbBeaconRecvStatus) ); + + while(1) { + OS_WaitIrq(1, OS_IE_V_BLANK); + ReadKeyPad(); + mf_KEYPAD_rapid(); + + mbrsp = MB_GetBeaconRecvStatus(); + + if( wdProcess != NULL ) { + if(wdProcess()) { + return 0; + } + } + + //// //// + { + static int touch = 0; + TPData tmp1 ATTRIBUTE_ALIGN(32); + TPData tmp2 ATTRIBUTE_ALIGN(32); + + while (TP_RequestRawSampling(&tmp1) != 0) {} + TP_GetCalibratedPoint(&tmp2, &tmp1); + + if (tmp2.touch != touch) + { + tp_touch_count++; + (void)DrawDecimalSJIS( 16, 0, RED, &tp_touch_count, 4, 2 ); + OS_Printf("touch change %d validity = %d\n", tmp2.touch, tmp2.validity); + touch = tmp2.touch; + } + } + //// ܂ //// + +// if (SYSM_IsCardPulledOut()) { // J[ho + if ( 0 ) { + OS_Printf("Card is pulled out.\n"); +#ifdef __DEBUG + OS_Terminate(); +#endif + } + + if (PAD_DetectFold() == TRUE) { // X[v[hւ̑J +// SYSM_GoSleepMode(); + } + + OS_PrintServer(); // ARM7̃vgfobO + } + return 0; +} + + +//====================================================== +// }`u[gij +//====================================================== + +// }`u[g̏ +static void SEQ_DSDL_init(void) +{ + GXS_SetVisiblePlane( GX_PLANEMASK_NONE ); + GX_SetVisiblePlane ( GX_PLANEMASK_NONE ); + + (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr_WDL); + GXS_SetOBJVRamModeChar(GX_OBJVRAMMODE_CHAR_1D_32K); + + // NITROJ[hROMo^f[^̃NA + MI_CpuClearFast( (void *)HW_ROM_HEADER_BUF, 0x160 ); + + // TuXN[̃NA + MI_CpuClearFast( bgBakS, sizeof(bgBakS) ); + MI_CpuFillFast ( (void *)HW_OAM, 192 , HW_OAM_SIZE ); + MI_CpuFillFast ( (void *)oamBakS, 192 , sizeof(oamBakS) ); // 192ŃtBȂƁAgpOBJ(0, 0)ɃLNo.0őS\Ă܂B + + // CXN[̃NA + MI_CpuClearFast( (void *)HW_BG_VRAM, 0x10000 ); + MI_CpuClearFast( (void *)HW_OBJ_VRAM, 0x8000 ); + MI_CpuClearFast( bgBakM, sizeof(bgBakM) ); + MI_CpuFillFast ( (void *)oamBakM, 192 , sizeof(oamBakM) ); // 192ŃtBȂƁAgpOBJ(0, 0)ɃLNo.0őS\Ă܂B + MI_CpuFillFast ( (void *)HW_OAM, 192 , HW_OAM_SIZE ); + MI_CpuCopyFast ( myPlttData, (void *)HW_BG_PLTT, sizeof(myPlttData) ); // BGpbg Zbg + + ClearAllStringSJIS(); + + (void)DrawStringSJIS ( 1, 0, WHITE, (const u8 *)"NICKNAME="); + (void)DrawStringSJIS ( 1, 2, LIGHTGREEN, (const u8 *)"PARENT NUM ="); +// (void)DrawStringSJIS ( 1, 22, LIGHTGREEN, (const u8 *)"GINFO LOST COUNT ="); + (void)DrawStringSJISEx( 26, 2, CYAN, str_period, PARENT_VIEW_NUM); + (void)DrawStringSJISEx( 29, 2, CYAN, str_sec, PARENT_VIEW_NUM); + + InitPrgNextSeqQue(); + unrenewalFlag = 0; + end_flag = FALSE; + prgSeq = PSEQ_INIT; + msgHandle = 0x8000; + dispGameInfoFlag = 0; + dispIntroFlag = 0; + dispMemberFlag = 0; + csrC_old = 2; // ŏ͂킴ƈႤlɂĂ + csrC = 0; + { + int i; + for( i = 0; i < PARENT_VIEW_NUM; i++ ) { + parentListNo[i][2] = '.'; + parentListNo[i][3] = 0x00; + } + } + SetMyUserInfo( &myUser ); // MBUserInfoNITROݒf[^ǂݏoăZbg + { + // jbNl[\ + u16 nickname[ MB_USER_NAME_LENGTH + 1 ]; + ExUTF16_LEtoSJIS_BE( (u8 *)nickname, (u16 *)myUser.name, myUser.nameLength ); + nickname[ myUser.nameLength ] = 0; + (void)DrawStringSJIS( 8, 0, WHITE, (const u8 *)nickname ); + } + + InitParentFindTime(); // e@ԕϐ̃NA + + while( (SYSM_GetBootFlag() & BFLG_WM_INITIALIZED) == 0 ) {} + + LOADER_Init( NULL ); + + GXS_SetVisiblePlane( GX_PLANEMASK_OBJ | GX_PLANEMASK_BG1 ); + GX_SetVisiblePlane ( GX_PLANEMASK_OBJ | GX_PLANEMASK_BG1 ); +} + + +// TOPXN[ւ̕\ +static void DispTopScreen( void ) +{ + SetTargetScreenSJIS( TOP_SCREEN ); + ClearAllStringSJIS(); + (void)DrawStringSJIS( 1, 0, YELLOW, (const u8 *)"WIRELESS DOWNLOAD"); + (void)DrawStringSJIS( G_INTRO_X, G_INTRO_Y, LIGHTGREEN, (const u8 *)"GAME INTRODUCTION"); + (void)DrawStringSJIS( G_MEMBER_X, G_MEMBER_Y, LIGHTGREEN, (const u8 *)"MEMBER LIST"); + SetTargetScreenSJIS( BOTTOM_SCREEN ); +} + + +//====================================================== +// }`u[gie@T[` ` ڑj +//====================================================== + +// }`u[g̐ڑV[PX +static int SEQ_DSDL_Connect(void) +{ + // ݂prgSeqɉ + BOOL getSeqFlag = CheckNextSeq_Connect(); + + switch ( prgSeq ) { + case PSEQ_INIT: // q@[h̊JniCȕ`StartScan܂ł̗sj + if ( MB_Init( mbwork, &myUser, MY_GGID, tgid, MB_DMA_NO ) != WM_ERRCODE_SUCCESS ) { + OS_Printf("MB init failed.\n"); + break; + } + MB_CommSetChildStateCallback( CallbackChild_MB ); + if ( MB_StartChild() != WM_ERRCODE_SUCCESS ) { + OS_Printf("MB start failed.\n"); + break; + } + tgid++; + DispTopScreen(); + prgSeq = PSEQ_INITIALIZING; + break; + + case PSEQ_INITIALIZING: + break; + + case PSEQ_SCANNING: // XL͐AV[PX`FbNsB + case PSEQ_ENDING: + if( !getSeqFlag ) { + return 0; + } + break; + + case PSEQ_CONNECTING: // ڑ̓L[͂󂯕tɃ^[BiV[PX`FbN͍sj + return 0; + + case PSEQ_CONNECT_SUCCEEDED: // bZ[W\A_E[hV[PXɈڍsB + if( DispMessage() ) { + UnlockPrgNextSeqQue(); // V[PXbN + wdProcess = SEQ_DSDL_Download; + } + return 0; + + case PSEQ_CONNECT_FAILED: // bZ[W\AXLĊJBiXLĊĴ̂́ACuōsBj + if( DispMessage() ) { + UnlockPrgNextSeqQue(); // V[PXbN + prgSeq = PSEQ_SCANNING; + } + break; + + case PSEQ_DISCONNECTED_BY_PARENT: // ؒfobZ[W\ݒB + if( DispMessage() ) { + UnlockPrgNextSeqQue(); // V[PXbN + prgSeq = PSEQ_INIT; + } + break; + + case PSEQ_CANCELLED: // I + return 0; + + default: + break; + } + + + // J[\ړ + if(pad.trg & PAD_KEY_DOWN){ // J[\̈ړ + if( ++csrC == MB_GAME_INFO_RECV_LIST_NUM ){ + csrC = 0; + } + } + if(pad.trg & PAD_KEY_UP){ + if( --csrC & 0x80 ){ + csrC = MB_GAME_INFO_RECV_LIST_NUM - 1; + } + } + DrawMenu((u16)(csrC & (PARENT_VIEW_NUM - 1)), &childModeSel); // XgԍiJ[\j̕\ + DispParentNum(); // e@̕\ + DispParentList(); // e@Xg̕\ + DispScanStatus(); // WMXLԂ̕\ + CountAndDispTotalTime(); // g[^Ԃ̃JEg\ + CountParentFindTime(); // e@Ԃ̃JEg + + + // e@ւ̐ڑ + if(pad.trg & PAD_BUTTON_A) { + if( mbrsp->usefulGameInfoFlag & (0x0001 << csrC) ) { + if( MB_CommDownloadRequest( csrC ) == WM_ERRCODE_SUCCESS ) { // ڑJn + OS_Printf("start conntct to parent.\n"); + prgSeq = PSEQ_CONNECTING; + }else { + OS_Printf("this parent info is invalid.\n"); + } + } + }else if(pad.trg & PAD_BUTTON_B) { // IJn + if( prgSeq == PSEQ_SCANNING ) { + OS_Printf("MB End start\n"); + prgSeq = PSEQ_ENDING; +// end_flag = TRUE; + MB_End(); + } + }else if( pad.trg & PAD_BUTTON_R ) { + unrenewalFlag ^= 0x01; +// MB_SetUnrenewalGameInfoFlag( (BOOL)unrenewalFlag ); + } + + csrC_old = csrC; // J[\ʒȗޔ + return 0; +} + + +// V[PX̃`FbNiR[obNŃC[vƂ͔񓯊ɕԂ鎟V[PXւ̈ڍsC[ṽvOisɍ킹Bj +static BOOL CheckNextSeq_Connect(void) +{ + PrgSeq seq; + // MBR[obNɂāAV[PXڍsĂꍇ̏ + if( GetPrgNextSeqQue( &seq) ) { // MBR[obNɂāAV[PXڍsĂꍇ̏ + prgSeq = seq; + OS_Printf("prgSeq = %s\n", str_prgSeq[ prgSeq ]); + + switch( seq ) { + case PSEQ_SCANNING: + { +/* + u8 *ver = MBw_GetWLVersion(); + (void)DrawStringSJIS( 21, 0, WHITE, (const u8 *)"WL ver=" ); + (void)DrawStringSJIS( 26, 0, WHITE, (const u8 *)ver ); +*/ + } + break; + + case PSEQ_CONNECT_SUCCEEDED: // ڑbZ[W\ݒB + SetDispMessage( YELLOW, str_connect_succeeded ); + LockPrgNextSeqQue(); // prgSeqbNB + return FALSE; + + case PSEQ_CONNECT_FAILED: // ڑsbZ[W\ݒB + SetDispMessage( RED, str_connect_failed); + LockPrgNextSeqQue(); // prgSeqbNB + return FALSE; + + case PSEQ_DISCONNECTED_BY_PARENT: // ؒfobZ[W\ݒB + SetDispMessage( RED, str_disconnected); + LockPrgNextSeqQue(); // prgSeqbNB + return FALSE; + + case PSEQ_CANCELLED: // I + { + u32 i; + for( i = 0; i < PARENT_VIEW_NUM; i++ ) { + ClearIconOBJ( i ); // SACȐ + } +// if( end_flag ) { +// ClearAllStringSJIS(); +// SetTargetScreenSJIS( TOP_SCREEN ); +// ClearAllStringSJIS(); +// SetTargetScreenSJIS( BOTTOM_SCREEN ); +// (void)DrawStringSJIS( 11, 11, WHITE, (const u8 *)"イ傤܂B"); +// }else { + prgSeq = PSEQ_INIT; +// } + } + return FALSE; + } + } + return TRUE; // V[PXڍsȂꍇFALSE^[̃V[PXłȂꍇTRUE^[B +} + + +//====================================================== +// }`u[gi_E[hj +//====================================================== + +// }`u[g̃t@C_E[hV[PX +static int SEQ_DSDL_Download(void) +{ + static int count_old = 0; + // ݂prgSeqɉ + BOOL getSeqFlag = CheckNextSeq_Download(); + + switch(prgSeq) { + + case PSEQ_REQ_REFUSED: + case PSEQ_MEMBER_FULL: // bZ[W\AUIď蒼B + if( DispMessage() ) { + UnlockPrgNextSeqQue(); // V[PXbN + prgSeq = PSEQ_ENDING; + wdProcess = SEQ_DSDL_Connect; + MB_End(); + } + break; + + // _E[ht@CMA_E[hł + case PSEQ_DOWNLOAD_READY: +// if (pad.trg & PAD_BUTTON_A) { // _E[hJn + OS_Printf("Start download.\n"); + ClearStringSJIS_handle(msgHandle); + (void)MB_CommStartDownload(); + SetBlinkMessage( YELLOW, str_downloading ); +// } + break; + + // _E[h + case PSEQ_DOWNLOADING: + if( getSeqFlag ) { + DispBlinkMessage(); + msgHandle = msgStat.handle; + + if( 1 ) { + u16 percent = MB_GetChildProgressPercentage(); + msgHandle = DrawDecimalSJIS( 16, 21, WHITE, &percent ,3, 2 ); + } + } + break; + + // _E[h + case PSEQ_DOWNLOAD_COMPLETED: + if( DispMessage() ) { + { + msgHandle = DrawStringSJIS( 4, 21, LIGHTGREEN, "Sign Digest...."); + if ( ACSignDigest ( output_buffer, &dlfileinfo ) ) { + ClearStringSJIS_handle( msgHandle ); + msgHandle = DrawStringSJIS( 4, 21, LIGHTGREEN, "Digest SUCCEEDED."); + }else { + ClearStringSJIS_handle( msgHandle ); + msgHandle = DrawStringSJIS( 4, 21, RED, "Digest FAILED."); + } + { + int i; + for ( i = 0; i < 120; i++ ) { + SVC_WaitVBlankIntr(); + } + } + ClearStringSJIS_handle( msgHandle ); + } + UnlockPrgNextSeqQue(); // V[PXbN + prgSeq = PSEQ_BOOT_REQ_WAIT; + msgHandle = DrawStringSJIS( 4, 21, WHITE, "Waiting BOOT-REQ from parent."); + } + break; + + // e@̃u[g‘҂ + case PSEQ_BOOT_REQ_WAIT: + break; + + // _E[hAu[gł +// case PSEQ_BOOT_READY: +// (void)LOADER_Start(); // ARM7ɂāA_E[hvO̍ĔzusB +// return 1; // "1"Ń^[邱ƂŁA}`u[g̃C[v甲IPL2ɏ߂B + + // e@̃u[gvMɂAN”ۃ`FbNsBiNintendoS\`FbNj + case PSEQ_BOOT_READY: + if( DispNintendoLogo() ) { + if( SYSM_CheckNinLogo( (u16 *)SYSM_GetCardRomHeader()->nintendo_logo ) ) { + prgSeq = PSEQ_BOOT_START; + }else { + SetDispMessage( RED, (const u8 *)"Illegal game data."); + prgSeq = PSEQ_BOOT_FAILED; + } + } + break; + + // u[gJn + case PSEQ_BOOT_START: + ClearStringSJIS_handle(msgHandle); + + SearchPatchAddress(); + + (void)LOADER_Start(); // ARM7ɂāA_E[hvO̍ĔzusB + return 1; // "1"Ń^[邱ƂŁA}`u[g̃C[v甲IPL2ɏ߂B + + // u[gs + // e@ɂāAڑؒfꂽ + // LZꍇ + case PSEQ_BOOT_FAILED: + case PSEQ_DISCONNECTED_BY_PARENT: + case PSEQ_CANCELLED: + if( DispMessage() ) { // w胁bZ[Wԕ\ + UnlockPrgNextSeqQue(); // V[PXbN + ClearStringSJIS_handle( msgHandle ); + prgSeq = PSEQ_INIT; + wdProcess = SEQ_DSDL_Connect; + } + break; + + default: + break; + } + + // B{^ŏIs + if( pad.trg & PAD_BUTTON_B ) { + MB_End(); // LŹAe@T[`Ԃ蒼B + } + + DrawMenu((u16)(csrC & (PARENT_VIEW_NUM - 1)), &childModeSel); // XgԍiJ[\j̕\ + DispParentNum(); // e@̕\ + DispParentList(); // e@Xg̕\ + DispScanStatus(); // WMXLԂ̕\ + CountAndDispTotalTime(); // g[^Ԃ̃JEg\ + CountParentFindTime(); // e@Ԃ̃JEg + return 0; +} + + +// V[PX̃`FbNiR[obNŃC[vƂ͔񓯊ɕԂ鎟V[PXւ̈ڍsC[ṽvOisɍ킹Bj +static BOOL CheckNextSeq_Download(void) +{ + PrgSeq seq; + + // MBR[obNɂāAV[PXڍsĂꍇ̏ + if( GetPrgNextSeqQue( &seq) ) { + prgSeq = seq; + OS_Printf("prgSeq = %s\n", str_prgSeq[ prgSeq ]); + + switch( seq ) { + + case PSEQ_REQ_REFUSED: // ڑۃbZ[W\ݒ + SetDispMessage( RED, str_req_refused); + LockPrgNextSeqQue(); // prgSeqbNB + return FALSE; + + case PSEQ_MEMBER_FULL: // o[FULLbZ[W\ݒB + SetDispMessage( RED, str_member_full); + LockPrgNextSeqQue(); // prgSeqbNB + return FALSE; + + case PSEQ_DOWNLOAD_READY: // _E[h + ClearStringSJIS_handle( msgHandle ); + { + msgHandle = DrawStringSJIS( 4, 21, WHITE, "Sign Decript...."); + if ( ACSignDecrpto( output_buffer, &dlfileinfo ) ) { + ClearStringSJIS_handle( msgHandle ); + msgHandle = DrawStringSJIS( 4, 21, LIGHTGREEN, "Decript SUCCEEDED."); + }else { + ClearStringSJIS_handle( msgHandle ); + msgHandle = DrawStringSJIS( 4, 21, RED, "Decript FAILED."); + } + { + int i; + for ( i = 0; i < 120; i++ ) { + SVC_WaitVBlankIntr(); + } + } + ClearStringSJIS_handle( msgHandle ); + } + + msgHandle = DrawStringSJIS( 4, 21, WHITE, "PUSH [A] TO DOWNLOAD."); + break; + + case PSEQ_DOWNLOAD_COMPLETED: // _E[h + ClearStringSJIS_handle( msgHandle ); + SetDispMessage( YELLOW, str_download_completed ); + LockPrgNextSeqQue(); // V[PXbN + return FALSE; + +// case PSEQ_BOOT_READY: // u[g +// ClearStringSJIS_handle( msgHandle ); +// break; + + case PSEQ_BOOT_READY: // u[g + ClearStringSJIS_handle( msgHandle ); + InitDispNintendoLogo(); + break; + + case PSEQ_CANCELLED: + ClearStringSJIS_handle( msgHandle ); + SetDispMessage( RED, str_download_cancelled ); + LockPrgNextSeqQue(); // V[PXbN + return FALSE; + + case PSEQ_DISCONNECTED_BY_PARENT: // ؒfobZ[W\ݒB + ClearStringSJIS_handle( msgHandle ); + SetDispMessage( RED, str_disconnected ); + LockPrgNextSeqQue(); // prgSeqbNB + return FALSE; + + default: + break; + } + } + return TRUE; +} + + +//====================================================== +// R[obN +//====================================================== + +// q@[hł̃R[obN +static void CallbackChild_MB( u32 status, void *arg ) +{ + switch (status) + { + case MB_COMM_CSTATE_INIT_COMPLETE: // + OS_Printf("CB: init completed.\n"); + (void)SetPrgNextSeqQue( PSEQ_SCANNING ); + break; + +// case MB_COMM_CSTATE_END_COMPLETE: // }`u[gI +// OS_Printf("CB: end completed.\n"); +// (void)SetPrgNextSeqQue( PSEQ_END ); +// break; + + case MB_COMM_CSTATE_REQ_REFUSED: // e@̃Gg[ + OS_Printf("CB: request refused.\n"); + (void)SetPrgNextSeqQue( PSEQ_REQ_REFUSED ); + break; + + case MB_COMM_CSTATE_MEMBER_FULL: // Q[ɒB + OS_Printf("CB: member full.\n"); + (void)SetPrgNextSeqQue( PSEQ_MEMBER_FULL ); + break; + + case MB_COMM_CSTATE_CONNECT: // e@ւ̐ڑ + OS_Printf("CB: connected.\n"); + (void)SetPrgNextSeqQue( PSEQ_CONNECT_SUCCEEDED ); + break; + + case MB_COMM_CSTATE_CONNECT_FAILED: // e@ւ̐ڑs + OS_Printf("CB: connect failed!\n"); + (void)SetPrgNextSeqQue( PSEQ_CONNECT_FAILED ); + break; + + case MB_COMM_CSTATE_DLINFO_ACCEPTED: // e@_E[hM + OS_Printf("CB: dlinfo accepted.\n"); + (void)SetPrgNextSeqQue( PSEQ_DOWNLOAD_READY ); + MI_CpuCopy16( (void *)arg, (void *)&dlfileinfo, sizeof( MBDownloadFileInfo ) ) ; + break; + + case MB_COMM_CSTATE_RECV_PROCEED: // MJn + OS_Printf("CB: recv proceed.\n"); + (void)SetPrgNextSeqQue( PSEQ_DOWNLOADING ); + break; + + case MB_COMM_CSTATE_RECV_COMPLETE: // M + OS_Printf("CB: recv completed.\n"); + (void)SetPrgNextSeqQue( PSEQ_DOWNLOAD_COMPLETED ); + break; + + case MB_COMM_CSTATE_BOOT_READY: // u[g + OS_Printf("CB: boot ready.\n"); +// SYSMi_GetWork()->mb_flag = 1; +// SYSMi_GetWork()->mb_ggid = *(u32 *)( MB_GetBeaconRecvStatus()->list[ pCwork->connectTargetNo ].bssDesc.gameInfo.ggid ); +// SYSMi_GetWork()->mb_ggid = MB_GetBeaconRecvStatus()->list[ pCwork->connectTargetNo ].gameInfo.ggid; + (void)SetPrgNextSeqQue( PSEQ_BOOT_READY ); + break; + + case MB_COMM_CSTATE_CANCELLED: // _E[hLZ + OS_Printf("CB: download cancel.\n"); + (void)SetPrgNextSeqQue( PSEQ_CANCELLED ); + break; + + case MB_COMM_CSTATE_DISCONNECTED_BY_PARENT: // e@̐ؒfʒm + OS_Printf("CB: disconnected by parent!\n"); + (void)SetPrgNextSeqQue( PSEQ_DISCONNECTED_BY_PARENT ); + break; + + case MB_COMM_CSTATE_GAMEINFO_LOST: + gameInfoLostCount++; + break; + } +} + + +//====================================================== +// \nTu[` +//====================================================== + +// XLԂ̕\ +static void DispScanStatus(void) +{ +#if 0 + int channel = MBw_GetScanChannel(); + + (void)DrawHexSJIS( 13, 2, WHITE, &channel, 2); + if( IsScanLock() ) { // XLbNȂA̎Ԃ\ + (void)DrawStringSJIS( 15, 2, RED, (const u8 *)"LOCK"); + (void)DrawHexSJIS ( 19, 2, WHITE, &mbrsp->nowLockTimeCount, 4); + }else { + (void)DrawStringSJIS( 15, 2, RED, (const u8 *)" "); + } +#endif +} + + +// e@̕\ +static void DispParentNum(void) +{ + int i; + int num = 0; + + for (i = 0; i < MB_GAME_INFO_RECV_LIST_NUM; i++) { // e@̃JEg + if( mbrsp->usefulGameInfoFlag & (0x0001 << i) ) num++; + } + (void)DrawDecimalSJIS( 10, 2, LIGHTGREEN, &num, 2, 4); +} + + +// e@񃊃Xg̕\ +static void DispParentList(void) +{ + u32 i; + u32 listNo = (u32)( csrC & ~(PARENT_VIEW_NUM - 1) ); // ݕ\̃Xg̐擪Zoi~\Ń}XNj + u32 listNo_old = (u32)( csrC_old & ~(PARENT_VIEW_NUM - 1) ); // O\Xg̐擪Zo + +// (void)DrawDecimalSJISEx( 15, 22, WHITE, &gameInfoLostCount, 8, 4, 0); + + // Q[e̕\ + DispGameIntroduction(); + + // ʐMo[̕\ + DispPlayMember(); + + // e@Xg̕\ + for( i = 0; i < PARENT_VIEW_NUM; i++ ) { + if( (listNo != listNo_old) || !(mbrsp->usefulGameInfoFlag & (0x0001 << listNo)) ){ + if( dispGameInfoFlag & (0x0001 << listNo_old) ) { // \XgʒuύX or Ye@LłȂȂꍇAO\f[^ɕ\ς݂ȂNAB + ClearDispParentGameInfo( i, listNo_old); + dispGameInfoFlag ^= 0x0001 << listNo_old; + } + } + + if( mbrsp->usefulGameInfoFlag & (0x0001 << listNo) ) { // YXg̃f[^LŁA–\Ȃ\B + DispParentGameInfo( i, listNo , !(dispGameInfoFlag & (0x0001 << listNo)) ); + dispGameInfoFlag |= 0x0001 << listNo; + } + if( csrC != csrC_old ) { + DecimalToString( parentListNo[i], &listNo, 2, 2); // r[ʂ̐擪Xgio[𕶎obt@ɓB + } + listNo++; + listNo_old++; + } +} + + +// Q[e̕\ +static void DispGameIntroduction( void ) +{ + BOOL clear = FALSE; + + if( ( ( csrC != csrC_old ) && ( dispIntroFlag & (0x0001 << csrC_old) ) ) + || ( !(mbrsp->usefulGameInfoFlag & (0x0001 << csrC)) && ( dispIntroFlag & (0x0001 << csrC) ) ) ) { + ClearDispGameIntroduction(); // J[\āAOJ[\ʒȕڍו\sĂA + dispIntroFlag = 0; + clear = TRUE; + } + + if( (mbrsp->usefulGameInfoFlag & (0x0001 << csrC)) && !( dispIntroFlag & (0x0001 << csrC) ) ) { + if ( !clear ){ // ݃J[\ʒũQ[񂪗LŁA܂ڍו\sĂȂ\B + ClearDispGameIntroduction(); + } + DispGameIntroduction_Core( (u32)csrC ); + dispIntroFlag = (u16)( 0x0001 << csrC ); // J[\ړꂽA݈ʒũQ[񂪖\̎ɂ̂ݕ\ or NAsB + } +} + + +// ʐMo[̃NA\ +static void DispPlayMember( void ) +{ + BOOL clear = FALSE; + + if( ( ( csrC != csrC_old ) && ( dispMemberFlag & (0x0001 << csrC_old) ) ) + || ( !(mbrsp->validGameInfoFlag & (0x0001 << csrC)) && ( dispMemberFlag & (0x0001 << csrC) ) ) ) { + ClearDispPlayMember(); // J[\ʒũQ[ڍ׏\ĂāÃQ[񂪖ɂȂNAB + dispMemberFlag = 0; + clear = TRUE; + } + + if( (mbrsp->validGameInfoFlag & (0x0001 << csrC)) && !( dispMemberFlag & (0x0001 << csrC) ) ) { + if ( !clear ){ // ݃J[\ʒũQ[񂪗LŁA܂ڍו\sĂȂ\B + ClearDispPlayMember(); + } + DispPlayMember_Core( (u32)csrC ); + dispMemberFlag = (u16)( 0x0001 << csrC ); // J[\ړꂽA݈ʒũQ[񂪖\̎ɂ̂ݕ\ or NAsB + } +} + + +// w肳ꂽe@̕\ +static void DispParentGameInfo( u32 view_no, u32 listNo, BOOL drawFixedDataFlag) +{ + if(drawFixedDataFlag) { // ωȂ̕\ + + MI_CpuClear16( gameName, MB_GAME_NAME_LENGTH * 2 ); + MI_CpuClear16( userName, MB_USER_NAME_LENGTH * 2 ); + ExUTF16_LEtoSJIS_BE( (u8 *)gameName, (u16 *)mbrsp->list[ listNo ].gameInfo.fixed.gameName, MB_GAME_NAME_LENGTH * 2 ); + ExUTF16_LEtoSJIS_BE( (u8 *)userName, (u16 *)mbrsp->list[ listNo ].gameInfo.fixed.parent.name, (u16)( mbrsp->list[ listNo ].gameInfo.fixed.parent.nameLength * 2)); +// MI_CpuCopy16( mbrsp->list[ listNo ].gameInfo.fixed.gameName, gameName, MB_GAME_NAME_LENGTH * 2); +// MI_CpuCopy16( mbrsp->list[ listNo ].gameInfo.fixed.parent.name, userName, mbrsp->list[ listNo ].gameInfo.fixed.parent.nameLength * 2); + gameName[ MB_GAME_NAME_LENGTH ] = 0; + userName[ mbrsp->list[ listNo ].gameInfo.fixed.parent.nameLength ] = 0; + + (void)ClearStringSJISEx( gameName, view_no); + (void)ClearStringSJISEx( userName, view_no); + (void)DrawStringSJISEx( 9, (PLIST_Y + (int)view_no*4), WHITE, gameName, view_no); + (void)DrawStringSJISEx( 9, (PLIST_Y + (int)view_no*4 + 2), WHITE, userName, view_no); + + (void)DrawStringSJISEx( 26, (PLIST_Y + (int)view_no*4), YELLOW, str_sura, view_no); + (void)DrawDecimalSJIS ( 27, (PLIST_Y + (int)view_no*4), YELLOW, &mbrsp->list[ listNo ].gameInfo.fixed.maxPlayerNum, 2, 1); + + // e@Ԃ̕\ + (void)CheckParentFindTime( listNo ); // Őe@𔭌Ă邩ĊmFĂB + time_ms = (int)findTime[listNo].vcount * 17; + time_sec = time_ms / 1000; + time_ms = (time_ms % 1000) / 10; + (void)DrawDecimalSJISEx( 23, (PLIST_Y + (int)view_no*4 + 2), CYAN, &time_sec, 4, 4, view_no); + (void)DrawDecimalSJISEx( 27, (PLIST_Y + (int)view_no*4 + 2), CYAN, &time_ms, 2, 4, view_no); + (void)DrawStringSJISEx ( 26, (PLIST_Y + (int)view_no*4 + 2), CYAN, str_period, view_no); + (void)DrawStringSJISEx ( 29, (PLIST_Y + (int)view_no*4 + 2), CYAN, str_sec, view_no); + + SetIconOBJ( listNo ); // ACR̕\ + } + { // ωio[Ee@JEg̕\j + (void)DrawDecimalSJIS( 24, (PLIST_Y + (int)view_no*4), YELLOW, &mbrsp->list[ listNo ].gameInfo.volat.nowPlayerNum, 2, 1); + (void)DrawHexSJIS ( 19, (PLIST_Y + (int)view_no*4 + 2), CYAN, &mbrsp->list[ listNo ].lifetimeCount, 4); + { + u16 color = RED; + if ( mbrsp->validGameInfoFlag & ( 0x0001 << listNo ) ) { + color = CYAN; + } + (void)DrawHexSJIS ( 19, (PLIST_Y + (int)view_no*4), color, &mbrsp->list[ listNo ].gameInfo.seqNoVolat, 2); + } + } +} + + +// w肳ꂽe@̕\NA +static void ClearDispParentGameInfo( u32 view_no, u32 listNo) +{ + // ̕ϐ̃AhX́ADispParentGameInfô̂ƈvĂȂƁA\NA邱ƂłȂ̂ŒӁBiϐŕ\Ƃ̓AhXςĂ܂j + // iDrawStringSJIS֐̎dlj + ClearStringSJISEx( gameName, view_no ); // Q[ + ClearStringSJISEx( userName, view_no ); // [U[ + ClearStringSJISEx( &time_sec, view_no ); // e@sec + ClearStringSJISEx( &time_ms, view_no ); // e@ms + ClearStringSJISEx( (void *)str_sura, view_no ); // "/" + ClearStringSJISEx( (void *)str_period, view_no ); // "." + ClearStringSJISEx( (void *)str_sec, view_no ); // "sec" + ClearStringSJIS ( (void *)&mbrsp->list[ listNo ].lifetimeCount ); // e@JEg + ClearStringSJIS ( (void *)&mbrsp->list[ listNo ].gameInfo.volat.nowPlayerNum ); // vCl + ClearStringSJIS ( (void *)&mbrsp->list[ listNo ].gameInfo.fixed.maxPlayerNum ); // ővCl + ClearStringSJIS ( (void *)&mbrsp->list[ listNo ].gameInfo.seqNoVolat ); // ővCl + + ClearIconOBJ( listNo ); // ACȐ +} + + +// Q[e̕\i) +static void DispGameIntroduction_Core( u32 listNo ) +{ + int i; + const u16 *strp = mbrsp->list[ listNo ].gameInfo.fixed.gameIntroduction; + u16 *dstp; + u16 gameIntroTmp[ MB_GAME_INTRO_LENGTH / 2 + 1 ]; + + MI_CpuClear16( gameIntroduction[0], (MB_GAME_INTRO_LENGTH / 2 + 1) * sizeof(u16) ); + MI_CpuClear16( gameIntroduction[1], (MB_GAME_INTRO_LENGTH / 2 + 1) * sizeof(u16) ); + + dstp = gameIntroTmp; + for ( i = 0; i < MB_GAME_INTRO_LENGTH / 2; i++ ) { // oCgPʂł̃Rs[Ȃ̂ŁA1śAMB_GAME_INTRO_LENGTH/2*2B + if( ( *strp == NULL) || ( *strp == 0x000a ) ) { + *dstp++ = 0x0000; + }else { + *dstp++ = *strp++; + } + } + ExUTF16_LEtoSJIS_BE( (u8 *)gameIntroduction[ 0 ], gameIntroTmp, MB_GAME_INTRO_LENGTH / 2 ); + + if( *strp == 0x000a ) { + strp++; + } + + dstp = gameIntroTmp; + for ( i = 0; i < MB_GAME_INTRO_LENGTH / 2; i++ ) { + if( ( *strp == NULL) || ( *strp == 0x000a ) ) { + *dstp++ = 0x00; + }else { + *dstp++ = *strp++; + } + } + ExUTF16_LEtoSJIS_BE( (u8 *)gameIntroduction[ 1 ], gameIntroTmp, MB_GAME_INTRO_LENGTH / 2 + 1 ); + + ClearDispGameIntroduction(); + + SetTargetScreenSJIS( TOP_SCREEN ); + (void)DrawStringSJIS( ( G_INTRO_X + 1 ), ( G_INTRO_Y + 2 ), WHITE, (const u8 *)gameIntroduction[0] ); + (void)DrawStringSJIS( ( G_INTRO_X + 1 ), ( G_INTRO_Y + 4 ), WHITE, (const u8 *)gameIntroduction[1] ); + SetTargetScreenSJIS( BOTTOM_SCREEN ); +} + + +// Q[e\̃NA +static void ClearDispGameIntroduction( void ) +{ + SetTargetScreenSJIS( TOP_SCREEN ); + ClearStringSJIS( (void *)gameIntroduction[0] ); + ClearStringSJIS( (void *)gameIntroduction[1] ); + SetTargetScreenSJIS( BOTTOM_SCREEN ); +} + + +// ʐMo[̕\ij +static void DispPlayMember_Core( u32 listNo ) +{ + int n, count_x; + u16 nameLength; + int pos_x, pos_y; + const MBUserInfo *memberp = &mbrsp->list[ listNo ].gameInfo.volat.member[ 0 ]; + u16 *dstp; + + SetTargetScreenSJIS( TOP_SCREEN ); + + MI_CpuClear16( playMember, sizeof(playMember) ); + count_x = 0; + pos_x = G_MEMBER_X + 1; + pos_y = G_MEMBER_Y + 2; + for ( n = 0; n < MB_MEMBER_MAX_NUM; n++ ) { + + if( memberp->nameLength > MB_USER_NAME_LENGTH ) { // Õ`FbN + nameLength = MB_USER_NAME_LENGTH; + }else { + nameLength = memberp->nameLength; + } + dstp = playMember[ n ]; + if( mbrsp->list[ listNo ].gameInfo.volat.nowPlayerFlag & (0x0002 << n ) ) { + + ExUTF16_LEtoSJIS_BE( (u8 *)dstp, (u16 *)memberp->name, nameLength ); + playMember[ n ][ nameLength ] = 0; + (void)DrawStringSJIS( pos_x, pos_y, WHITE, (const u8 *)playMember[ n ] ); + }else { + MI_CpuCopy16( (void *)"----------", (void *)playMember[ n ], MB_USER_NAME_LENGTH + 1); + (void)DrawStringSJIS( pos_x, pos_y, WHITE, playMember[ n ] ); + } + memberp++; + + if( ++count_x == 3 ) { // \ʒu̎Zo + pos_x -= 20; + pos_y += 2; + count_x = 0; + }else { + pos_x += 10; + } + } + + SetTargetScreenSJIS( BOTTOM_SCREEN ); +} + + +// ʐMo[\̃NA +static void ClearDispPlayMember( void ) +{ + int i; + + SetTargetScreenSJIS( TOP_SCREEN ); + for( i = 0; i < MB_MEMBER_MAX_NUM + 1; i++ ) { + ClearStringSJIS( (void *)playMember[ i ] ); + } + SetTargetScreenSJIS( BOTTOM_SCREEN ); +} + + +// 10if[^𕶎ɕϊ +static void DecimalToString(u8 *dstp, const void *valuep, u8 drawLength, u8 size) +{ + u16 count; + u32 mask, divisor, target; + + mask = 0xff; + while(--size > 0) { + mask = (mask << 8) | 0xff; + } + target=(*(u32 *)valuep) & mask; + count=10; + divisor=1000000000; + while(count) { + CP_SetDiv32_32(target, divisor); + if (count <= drawLength) { + *dstp++ = (u8)(CP_GetDivResult32()+0x0030); + } + target=(u32)CP_GetDivRemainder32(); + CP_SetDiv32_32(divisor, 10); + divisor=(u32)CP_GetDivResult32(); + count--; + } +} + + +// e@ԕϐ̃NA +static void InitParentFindTime( void ) +{ + int i; + for( i = 0; i < MB_GAME_INFO_RECV_LIST_NUM; i++) { + findTime[i].find = FALSE; + findTime[i].vcount = 0; + } + total_vcount = 0; +} + + +// e@Ԃ̃JEg +static void CountParentFindTime( void ) +{ + u32 i; + + for( i = 0; i < MB_GAME_INFO_RECV_LIST_NUM; i++ ) { + if( !CheckParentFindTime( i ) ) { + findTime[i].vcount = total_vcount; // e@񂪌‚܂ŃJEg + } + } +} + + +// e@񂪑ǂ`FbNāAԃJEg~B +static BOOL CheckParentFindTime( u32 index ) +{ + if( mbrsp->validGameInfoFlag & (0x01 << index) ) { // e@񂪔ꂽȂAJEg~B + findTime[ index ].find = TRUE; + } + return findTime[ index ].find; +} + + +// g[^Ԃ̃JEg\ +static void CountAndDispTotalTime( void ) +{ + total_vcount++; + time_ms = total_vcount * 17; + time_sec = time_ms / 1000; + time_ms = (time_ms % 1000) / 10; + (void)DrawDecimalSJISEx( 23, 2, CYAN, &time_sec, 4, 4, PARENT_VIEW_NUM); + (void)DrawDecimalSJISEx( 27, 2, CYAN, &time_ms, 2, 4, PARENT_VIEW_NUM); +} + + +// ACROBJ̃[h +static void SetIconOBJ( u32 index ) +{ + u16 view_no = (u16)( index & 0x03 ); + const MBIconInfo *iconp = &mbrsp->list[ index ].gameInfo.fixed.icon; + + GXS_LoadOBJPltt( iconp->palette, (u32)( MB_ICON_PALETTE_SIZE * view_no ), MB_ICON_PALETTE_SIZE ); + MI_CpuCopyFast( iconp->data, (void *)((u32)objVramBuff + 0x20 + MB_ICON_DATA_SIZE * view_no), MB_ICON_DATA_SIZE ); + G2_SetOBJAttr( (GXOamAttr*)&oamBakS[ view_no ], // OAM pointer + 8 * (PLIST_X + 3), // X position + 8 * PLIST_Y + (view_no * 32), // Y position + 0, // Priority + GX_OAM_MODE_NORMAL, // Bitmap mode + FALSE, // mosaic off + GX_OAM_EFFECT_NONE, // affine off + GX_OAM_SHAPE_32x32, // 16x16 size + GX_OAM_COLOR_16, // 16 color + 1 + view_no * 16, // charactor + view_no, // palette + 0); // affine +} + +// ACROBJ̃NA +static void ClearIconOBJ( u32 index ) +{ + u16 view_no = (u16)( index & 0x03 ); + u16 *oamp = (u16 *)&oamBakS[ view_no ]; + + *oamp++ = 192; // YWʊOɁBiI[0NAł̓_j + *oamp++ = 0; + *oamp++ = 0; + *oamp = 0; +} + + +// bZ[W\̃Zbg +static void SetDispMessage( u16 color, const u8 *str ) +{ + msgStat.vcount = MSG_VIEW_COUNT; + msgStat.color = color; + msgStat.str = str; +} + + +// bZ[W\ +static BOOL DispMessage(void) +{ + if( msgStat.vcount == MSG_VIEW_COUNT ) { + msgStat.handle = DrawStringSJIS( 4, 21, msgStat.color, msgStat.str ); + } + + if ( --msgStat.vcount == 0 ) { + ClearStringSJIS_handle( msgStat.handle ); + return TRUE; + } + return FALSE; +} + + +// bZ[W\̃Zbgi_ŕ\j +static void SetBlinkMessage( u16 color, const u8 *str ) +{ + msgStat.vcount = MSG_BLINK_COUNT; + msgStat.flag = 1; + msgStat.color = color; + msgStat.str = str; +} + + +// bZ[W\ +static void DispBlinkMessage( void ) +{ + if( ( msgStat.vcount == MSG_BLINK_COUNT ) && msgStat.flag ) { + msgStat.handle = DrawStringSJIS( 4, 21, msgStat.color, msgStat.str ); + } + + if ( --msgStat.vcount == 0 ) { + ClearStringSJIS_handle( msgStat.handle ); + msgStat.flag ^= 0x01; + msgStat.vcount = MSG_BLINK_COUNT; + } +} + + +//============================================================================= +// NintendoS\ +//============================================================================= + +// NintendoS\̏ +static void InitDispNintendoLogo( void ) +{ + int i; + u16 *palettep = (u16 *)(HW_OBJ_PLTT + 0x20 * 15 ) + 1; // pbg15̃J[1ɁB + *palettep++ = 0x7fff; + *palettep = 0x1111; + + // TOPʂ̑S\NA + SetTargetScreenSJIS( TOP_SCREEN ); + ClearAllStringSJIS(); + SetTargetScreenSJIS( BOTTOM_SCREEN ); + + // ʏɎMQ[NintendoS\B +#ifdef NINLOGO_LOAD_1D_CHAR + // 1D}bsOł̃[h\ + GX_SetOBJVRamModeChar( GX_OBJVRAMMODE_CHAR_1D_32K ); + SYSM_LoadNintendoLogo1D( (u16 *)SYSM_GetCardRomHeader()->nintendo_logo, (u16 *)( HW_OBJ_VRAM + 0x40 ), 1, ninLogoBuff ); +// SYSM_LoadNintendoLogo1D( (u16 *)SYSROM9_NINLOGO_ADR, (u16 *)( HW_OBJ_VRAM + 0x40 ), 1, ninLogoBuff ); + + for ( i = 0; i < 3; i++ ) { + G2_SetOBJAttr( &oamBakM[ 10 + i ], // OAM pointer + 72 + 32 * i, // X position + 88, // Y position + 0, // Priority + GX_OAM_MODE_NORMAL, // Bitmap mode + FALSE, // mosaic off + GX_OAM_EFFECT_NONE, // affine off + GX_OAM_SHAPE_32x8, // 16x16 size + GX_OAM_COLOR_16, // 16 color + 0x2 + i * 4, // charactor + 15, // palette + 0); // affine + } + { + G2_SetOBJAttr( &oamBakM[ 13 ], // OAM pointer + 72 + 32 * 3, // X position + 88, // Y position + 0, // Priority + GX_OAM_MODE_NORMAL, // Bitmap mode + FALSE, // mosaic off + GX_OAM_EFFECT_NONE, // affine off + GX_OAM_SHAPE_8x8, // 16x16 size + GX_OAM_COLOR_16, // 16 color + 0x2 + 3 * 4, // charactor + 15, // palette + 0); // affine + } + for ( i = 0; i < 3; i++ ) { + G2_SetOBJAttr( &oamBakM[ 14 + i ], // OAM pointer + 72 + 32 * i, // X position + 96, // Y position + 0, // Priority + GX_OAM_MODE_NORMAL, // Bitmap mode + FALSE, // mosaic off + GX_OAM_EFFECT_NONE, // affine off + GX_OAM_SHAPE_32x8, // 16x16 size + GX_OAM_COLOR_16, // 16 color + 0x0f + i * 4, // charactor + 15, // palette + 0); // affine + } + { + G2_SetOBJAttr( &oamBakM[ 17 ], // OAM pointer + 72 + 32 * 3, // X position + 96, // Y position + 0, // Priority + GX_OAM_MODE_NORMAL, // Bitmap mode + FALSE, // mosaic off + GX_OAM_EFFECT_NONE, // affine off + GX_OAM_SHAPE_8x8, // 16x16 size + GX_OAM_COLOR_16, // 16 color + 0xf + 3 * 4, // charactor + 15, // palette + 0); // affine + } +#else + // 2D}bsOł̃[h\ + GX_SetOBJVRamModeChar( GX_OBJVRAMMODE_CHAR_2D ); + SYSM_LoadNintendoLogo2D( (u16 *)SYSM_GetCardRomHeader()->nintendo_logo, (u16 *)( HW_OBJ_VRAM + 0x40 ), 1, ninLogoBuff ); +// SYSM_LoadNintendoLogo2D( (u16 *)SYSROM9_NINLOGO_ADR, (u16 *)( HW_OBJ_VRAM + 0x40 ), 1, ninLogoBuff ); + + for ( i = 0; i < 4; i++ ) { + G2_SetOBJAttr( &oamBakM[11 + i], // OAM pointer + 72 + 32 * i, // X position + 88, // Y position + 0, // Priority + GX_OAM_MODE_NORMAL, // Bitmap mode + FALSE, // mosaic off + GX_OAM_EFFECT_NONE, // affine off + GX_OAM_SHAPE_32x16, // 16x16 size + GX_OAM_COLOR_16, // 16 color + 0x2 + i * 4, // charactor + 15, // palette + 0); // affine + } +#endif + + loop_count = 120; +} + + +// NintendoS\ +static BOOL DispNintendoLogo( void ) +{ + if( --loop_count == 0 ) { + { + int i; + for ( i = 0; i < 4; i++ ) { + G2_SetOBJPosition( &oamBakM[ 11 + i ], 0, 192 ); + } + } + return TRUE; + } + return FALSE; +} + + +//============================================================================= +// ̑Tu[` +//============================================================================= + +// ̃[U[NITROݒf[^ǂݏoăZbg +static void SetMyUserInfo( MBUserInfo *my ) +{ + NvNickname *nickname = NCD_GetNickname(); + + MI_CpuCopy16( nickname->str, my->name, (u32)( nickname->length * 2 ) ); + my->nameLength = nickname->length; + my->playerNo = 0; // Ƃ肠OɂB + my->favoriteColor = NCD_GetFavoriteColor(); +} + + +// ݃XLbNǂ擾B +static BOOL IsScanLock(void) +{ + return mbrsp->nowScanTargetFlag ? TRUE : FALSE; +} + + +//============================================================================= +// 荞݃[` +//============================================================================= + +// VuN荞 +static void VBlankIntr_WDL(void) +{ + // OAM, BG-VRAM̍XV + DC_FlushRange (oamBakM, sizeof(oamBakM)); + DC_FlushRange (oamBakS, sizeof(oamBakS)); + DC_FlushRange (bgBakM, sizeof(bgBakM)); + DC_FlushRange (bgBakS, sizeof(bgBakS)); + DC_FlushRange (objVramBuff, sizeof(objVramBuff)); + MI_CpuCopyFast(oamBakM, (void*)HW_OAM, sizeof(oamBakM)); + MI_CpuCopyFast(oamBakS, (void*)HW_DB_OAM, sizeof(oamBakS)); + MI_CpuCopyFast(bgBakM, (void*)(HW_BG_VRAM + 0xf000), sizeof(bgBakM)); + MI_CpuCopyFast(bgBakS, (void*)(HW_DB_BG_VRAM + 0xf000), sizeof(bgBakS)); + MI_CpuCopyFast(objVramBuff, (void*)HW_DB_OBJ_VRAM, sizeof(objVramBuff)); + //---- 荞݃`FbNtO + OS_SetIrqCheckFlag(OS_IE_V_BLANK); +} + + +//============================================================================= +// vOV[PXL[ +//============================================================================= + +// L[ +static void InitPrgNextSeqQue( void ) +{ + MI_CpuClear16( &nextSeq, sizeof(nextSeq) ); +} + + +// PrgSeqL[ɃZbgB +static BOOL SetPrgNextSeqQue( PrgSeq seq ) +{ + BOOL preIRQ = OS_DisableIrq(); + BOOL retval = FALSE; + + if( nextSeq.num != PRG_NEXT_SEQ_QUE_NUM ) { + nextSeq.seq[ nextSeq.bottom ] =seq; + nextSeq.num++; + nextSeq.bottom++; + if( nextSeq.bottom == PRG_NEXT_SEQ_QUE_NUM ) { + nextSeq.bottom = 0; + } + retval = TRUE; + } + (void)OS_RestoreIrq( preIRQ ); + return retval; +} + + +// PrgSeqL[o +static BOOL GetPrgNextSeqQue( PrgSeq *seqp ) +{ + BOOL preIRQ = OS_DisableIrq(); + BOOL retval = FALSE; + + if( ( !nextSeq.lock ) && ( nextSeq.num != 0 ) ) { // L[bNĂ炸AŽSeq݂ȂAL[oB + *seqp = nextSeq.seq[ nextSeq.top ]; + nextSeq.num--; + nextSeq.top++; + if( nextSeq.top == PRG_NEXT_SEQ_QUE_NUM ) { + nextSeq.top = 0; + } + retval = TRUE; + } + (void)OS_RestoreIrq( preIRQ ); + return retval; +} + + +// L[bNBibNGetPrgNextSeqQueŎSeqoȂȂ܂Bj +static void LockPrgNextSeqQue(void) +{ + nextSeq.lock = TRUE; +} + + +// L[̃bNB +static void UnlockPrgNextSeqQue(void) +{ + nextSeq.lock = FALSE; +} + +// L[󂩁H +static BOOL IsEmptyPrgNextSeqQue(void) +{ + return nextSeq.num ? FALSE : TRUE; +} + + + +static const u32 searchCode[] = { + 0xe59f1028, + 0xe59f2028, + 0xe1d200b0, + 0xe2100001, + 0x1afffffc, + 0xe1d100b0, + 0xe3500006, + 0x0afffff9, + 0xe1d100b0, + 0xe3500005, + 0x0afffff6, + 0xe12fff1e, + 0x04808214, + 0x0480819c, +}; + + +void SearchPatchAddress( void ) +{ + MBDownloadFileInfo *dlfinfo = (MBDownloadFileInfo *)MB_DOWNLOAD_FILEINFO_ADDRESS; + BOOL find = FALSE; + u32 *tgtp = (u32 *)MB_ARM7_STATIC_RECV_BUFFER; + u32 size = dlfinfo->seg[ 2 ].size >> 2; + + while( size-- ) { + if( *tgtp++ == searchCode[0] ) { + u32 *srcp = (u32 *)&searchCode[ 1 ]; + u32 *checkp = tgtp ; + int i = sizeof( searchCode ) / sizeof(u32) - 1; + while( i-- ) { + if( *srcp++ != *checkp++ ) break; + } + if( i < 0 ) { + u32 addr = (u32)tgtp - 0x04 + 0x18; + OS_TPrintf("Found! -> 0x%08x\n", addr ); + find = TRUE; + } + } + } + if( !find ) { + OS_TPrintf("Not found.\n"); + } +} + diff --git a/build/systemMenu_RED/DS_DownloadPlay/ARM9/src/DS_DownloadPlay.h b/build/systemMenu_RED/DS_DownloadPlay/ARM9/src/DS_DownloadPlay.h new file mode 100644 index 00000000..1c9a8f83 --- /dev/null +++ b/build/systemMenu_RED/DS_DownloadPlay/ARM9/src/DS_DownloadPlay.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: DS_DownloadPlay.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 __DS_DOWNLOAD_PLAY_H__ +#define __DS_DOWNLOAD_PLAY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +// define data---------------------------------------------------------- + +int DS_DownloadPlayMain( void ); + + +#ifdef __cplusplus +} +#endif + +#endif // __DS_DOWNLOAD_PLAY_H__ diff --git a/build/systemMenu_RED/DS_DownloadPlay/Makefile b/build/systemMenu_RED/DS_DownloadPlay/Makefile new file mode 100644 index 00000000..9cf34e12 --- /dev/null +++ b/build/systemMenu_RED/DS_DownloadPlay/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/DS_DownloadPlay/banner/Makefile b/build/systemMenu_RED/DS_DownloadPlay/banner/Makefile new file mode 100644 index 00000000..ea261271 --- /dev/null +++ b/build/systemMenu_RED/DS_DownloadPlay/banner/Makefile @@ -0,0 +1,49 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/systemMenu_RED/DS_DownloadPlay/banner/banner_v3.bsf b/build/systemMenu_RED/DS_DownloadPlay/banner/banner_v3.bsf new file mode 100644 index 00000000..8209887b Binary files /dev/null and b/build/systemMenu_RED/DS_DownloadPlay/banner/banner_v3.bsf differ diff --git a/build/systemMenu_RED/DS_DownloadPlay/banner/icon/gameIcon.bmp b/build/systemMenu_RED/DS_DownloadPlay/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..9c18b2e5 Binary files /dev/null and b/build/systemMenu_RED/DS_DownloadPlay/banner/icon/gameIcon.bmp differ diff --git a/build/systemMenu_RED/HWInfoWriter/ARM9/Makefile b/build/systemMenu_RED/HWInfoWriter/ARM9/Makefile new file mode 100644 index 00000000..594da005 --- /dev/null +++ b/build/systemMenu_RED/HWInfoWriter/ARM9/Makefile @@ -0,0 +1,73 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - SystemMenuRED - HWInfoWriter +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +SUBDIRS = \ + +#---------------------------------------------------------------------------- + +USE_PRODUCT_KEY = TRUE + +KEYS_DIR = $(shell $(CYGPATH) -m $(TWL_KEYSDIR)) +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +TITLEID_LO = HIWR +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +TARGET_BIN = main.srl + +ROM_SPEC = main.rsf + +MISC_DIR = ../../misc + +SRCS = main.c HWInfoWriter.c \ + $(MISC_DIR)/src/misc.c $(MISC_DIR)/src/cmn.c + +LINCLUDES = $(MISC_DIR)/include \ + $(ROOT)/build/libraries/lcfg/ARM9.TWL/include +LLIBRARIES = libacsign_enc$(TWL_LIBSUFFIX).a + +MAKEROM_FLAGS += -DTITLEID_LO='$(TITLEID_LO)' \ + -DHWINFO_PRIVKEY='private_HWInfo.der' +MAKETAD_FLAGS += -s + +ifdef USE_PRODUCT_KEY +MAKEROM_FLAGS += -DPRIVKEY_PATH='$(KEYS_DIR)/rsa' +MACRO_FLAGS += -DUSE_PRODUCT_KEY +else +MAKEROM_FLAGS += -DPRIVKEY_PATH='../../../../keys/dummy/rsa' +endif + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/HWInfoWriter/ARM9/main.rsf b/build/systemMenu_RED/HWInfoWriter/ARM9/main.rsf new file mode 100644 index 00000000..378e391e --- /dev/null +++ b/build/systemMenu_RED/HWInfoWriter/ARM9/main.rsf @@ -0,0 +1,183 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType System + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + #SaveBannerFile TRUE +} + + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot ../../data + Root /data + File NTR_IPL_font_m.NFTR + HostRoot $(PRIVKEY_PATH) + Root /key + File $(HWINFO_PRIVKEY) + +} diff --git a/build/systemMenu_RED/HWInfoWriter/ARM9/src/HWInfoWriter.c b/build/systemMenu_RED/HWInfoWriter/ARM9/src/HWInfoWriter.c new file mode 100644 index 00000000..9ff771c7 --- /dev/null +++ b/build/systemMenu_RED/HWInfoWriter/ARM9/src/HWInfoWriter.c @@ -0,0 +1,516 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: DS_Chat.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "TWLHWInfo_api.h" +#include "TWLSettings_api.h" +#include "misc.h" +#include "HWInfoWriter.h" + +// define data------------------------------------------ +#define WRITER_ELEMENT_NUM 7 +#define MSG_X 3 +#define MSG_Y 19 + +// extern data------------------------------------------ +const LCFGTWLHWNormalInfo *LCFG_THW_GetDefaultNormalInfo( void ); +const LCFGTWLHWSecureInfo *LCFG_THW_GetDefaultSecureInfo( void ); +const LCFGTWLHWNormalInfo *LCFG_THW_GetNormalInfo( void ); +const LCFGTWLHWSecureInfo *LCFG_THW_GetSecureInfo( void ); + +// function's prototype declaration--------------------- +static void ReadTWLSettings( void ); +static void ModifyLanguage( u8 region ); +static void ReadPrivateKey( void ); +static void ReadHWInfoFile( void ); +static void WriteHWInfoFile( u8 region ); +static BOOL WriteHWNormalInfoFile( void ); +static BOOL WriteHWSecureInfoFile( u8 region ); +static void DeleteHWInfoFile( void ); +static void VerifyHWInfo( void ); +static BOOL VerifyData( const u8 *pTgt, const u8 *pOrg, u32 len ); +static void DispMessage( int x, int y, u16 color, const u16 *pMsg ); + +// global variable ------------------------------------- +RTCDrawProperty g_rtcDraw = { + TRUE, RTC_DATE_TOP_X, RTC_DATE_TOP_Y, RTC_TIME_TOP_X, RTC_TIME_TOP_Y +}; + +// static variable ------------------------------------- +static u16 s_csr; +static u8 *s_pPrivKeyBuffer = NULL; +static LCFGReadResult (*s_pReadSecureInfoFunc)( void ); +static BOOL s_isReadTSD; +static u8 s_region_old; + +// const data ----------------------------------------- +static const u16 *const s_pStrWriter[ WRITER_ELEMENT_NUM ] = { + (const u16 *)L"Write HW Info REGION=JAPAN", + (const u16 *)L"Write HW Info REGION=AMERICA", + (const u16 *)L"Write HW Info REGION=EUROPE", + (const u16 *)L"Write HW Info REGION=AUSTRALIA", + (const u16 *)L"Write HW Info REGION=CHINA", + (const u16 *)L"Write HW Info REGION=KOREA", + (const u16 *)L"Delete HW Info", +}; + +static MenuPos s_writerPos[] = { + { TRUE, 3 * 8, 4 * 8 }, + { TRUE, 3 * 8, 6 * 8 }, + { TRUE, 3 * 8, 8 * 8 }, + { TRUE, 3 * 8, 10 * 8 }, + { TRUE, 3 * 8, 12 * 8 }, + { TRUE, 3 * 8, 14 * 8 }, + { TRUE, 3 * 8, 16 * 8 }, +}; + + +static const MenuParam s_writerParam = { + WRITER_ELEMENT_NUM, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_writerPos[ 0 ], + (const u16 **)&s_pStrWriter, +}; + +static const u32 s_langBitmapList[ LCFG_TWL_REGION_MAX ] = { + LCFG_TWL_LANG_BITMAP_JAPAN, + LCFG_TWL_LANG_BITMAP_AMERICA, + LCFG_TWL_LANG_BITMAP_EUROPE, + LCFG_TWL_LANG_BITMAP_AUSTRALIA, + LCFG_TWL_LANG_BITMAP_CHINA, + LCFG_TWL_LANG_BITMAP_KOREA, +}; + +static char *strLanguage[] = { + (char *)"LANG_JAPANESE", + (char *)"LANG_ENGLISH", + (char *)"LANG_FRENCH", + (char *)"LANG_GERMAN", + (char *)"LANG_ITALIAN", + (char *)"LANG_SPANISH", + (char *)"LANG_CHINESE", + (char *)"LANG_KOREAN", +}; + +static const char *strRegion[] = { + "JAPAN", + "AMERICA", + "EUROPE", + "AUSTRALIA", + "CHINA", + "KOREA", +}; + +static const char *strLauncherGameCode[] = { + "LNCJ", + "LNCE", + "LNCP", + "LNCO", + "LNCC", + "LNCK", +}; + +//====================================================== +// HW񃉃C^[ +//====================================================== + +// HW񃉃C^[̏ +void HWInfoWriterInit( void ) +{ + + GX_DispOff(); + GXS_DispOff(); + + InitBG(); + + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_WHITE ); + + PutStringUTF16( 1 * 8, 0 * 8, TXT_COLOR_BLUE, (const u16 *)L"HW Info Writer"); + GetAndDrawRTCData( &g_rtcDraw, TRUE ); + + ACSign_SetAllocFunc( Alloc, Free ); + ReadTWLSettings(); + ReadPrivateKey(); + ReadHWInfoFile(); +// VerifyHWInfo(); + OS_TPrintf( "region = %d\n", LCFG_THW_GetRegion() ); + PrintfSJISSub( 2 * 8, 16 * 8, TXT_COLOR_BLACK, "Region = %s", strRegion[ LCFG_THW_GetRegion() ] ); + PrintfSJISSub( 2 * 8, 18 * 8, TXT_COLOR_BLACK, "SerialNo = %s", LCFG_THW_GetSerialNoPtr() ); + if ( 1 ) + { + int i; + u8 titleID_Lo[ 4 ]; + u8 gameCode[ 5 ] = { 0, 0, 0, 0, 0 }; + LCFG_THW_GetLauncherTitleID_Lo( titleID_Lo ); + for( i = 0; i < 4; i++ ) gameCode[ i ] = titleID_Lo[ 4 - i - 1 ]; + PrintfSJISSub( 2 * 8, 20 * 8, TXT_COLOR_BLACK, "LauncherTitleID_Lo = %s", gameCode ); + } + s_region_old = LCFG_THW_GetRegion(); + s_csr = 0; + DrawMenu( s_csr, &s_writerParam ); + + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); + GX_DispOn(); + GXS_DispOn(); +} + + +// HW񃉃C^[̃C[v +void HWInfoWriterMain( void ) +{ + // J[\ړ + if( pad.trg & PAD_KEY_DOWN ){ + if( ++s_csr == WRITER_ELEMENT_NUM ) { + s_csr = 0; + } + } + if( pad.trg & PAD_KEY_UP ){ + if( --s_csr & 0x8000 ) { + s_csr = WRITER_ELEMENT_NUM - 1; + } + } + DrawMenu( s_csr, &s_writerParam ); + + // s + if( pad.trg == PAD_BUTTON_A ) { + if( s_csr == WRITER_ELEMENT_NUM - 1 ) { + OS_TPrintf( "Delete start.\n" ); + (void)DeleteHWInfoFile(); + }else { + OS_TPrintf( "Write start.\n" ); + WriteHWInfoFile( (u8)s_csr ); + } + } + + GetAndDrawRTCData( &g_rtcDraw, FALSE ); +} + + +// TWLݒf[^̃[h +static void ReadTWLSettings( void ) +{ + s_isReadTSD = LCFGi_TSD_ReadSettings(); + if( s_isReadTSD ) { + OS_TPrintf( "TSD read succeeded.\n" ); + }else { + OS_TPrintf( "TSD read failed.\n" ); + } +} + + +// R[h[Wlɍ킹ďCB +static void ModifyLanguage( u8 region ) +{ + u32 langBitmap = s_langBitmapList[ region ]; + u8 nowLanguage = LCFG_TSD_GetLanguage(); + + // TSDǂݍ߂ĂȂȂA^[ + if( !s_isReadTSD ) { + return; + } + + if( langBitmap & ( 0x0001 << nowLanguage ) ) { + OS_TPrintf( "Language no change.\n" ); + }else { + int i; + for( i = 0; i < LCFG_TWL_LANG_CODE_MAX; i++ ) { + if( langBitmap & ( 0x0001 << i ) ) { + break; + } + } + LCFG_TSD_SetLanguage( (LCFGTWLLangCode)i ); + LCFG_TSD_SetFlagCountry( FALSE ); // ‚łɍR[hNAĂB + LCFG_TSD_SetCountry( LCFG_TWL_COUNTRY_UNDEFINED ); + LCFGi_TSD_WriteSettings(); + OS_TPrintf( "Language Change \"%s\" -> \"%s\"\n", + strLanguage[ nowLanguage ], strLanguage[ LCFG_TSD_GetLanguage() ] ); + } +} + + +// 閧̃[h +static void ReadPrivateKey( void ) +{ + BOOL result = FALSE; + u32 keyLength; + FSFile file; + OSTick start = OS_GetTick(); + + FS_InitFile( &file ); + if( !FS_OpenFileEx( &file, "rom:key/private_HWInfo.der", FS_FILEMODE_R ) ) { + OS_TPrintf( "PrivateKey read failed.\n" ); + }else { + keyLength = FS_GetFileLength( &file ); + if( keyLength > 0 ) { + s_pPrivKeyBuffer = Alloc( keyLength ); + if( FS_ReadFile( &file, s_pPrivKeyBuffer, (s32)keyLength ) == keyLength ) { + OS_TPrintf( "PrivateKey read succeeded.\n" ); + result = TRUE; + }else { + OS_TPrintf( "PrivateKey read failed.\n" ); + } + } + FS_CloseFile( &file ); + } + + if( !result && s_pPrivKeyBuffer ) { + Free( s_pPrivKeyBuffer ); + s_pPrivKeyBuffer = NULL; + } + OS_TPrintf( "PrivKey read time = %dms\n", OS_TicksToMilliSeconds( OS_GetTick() - start ) ); + +#ifdef USE_PRODUCT_KEY + // ip閧LȂÃANZX + s_pReadSecureInfoFunc = LCFGi_THW_ReadSecureInfo; +#else + // łȂȂAȂ̃ANZX + s_pReadSecureInfoFunc = LCFGi_THW_ReadSecureInfo_NoCheck; + PutStringUTF16( 14 * 8, 0 * 8, TXT_COLOR_RED, (const u16 *)L"[No Signature MODE]" ); +#endif +} + + +// HWŜ̃[h +static void ReadHWInfoFile( void ) +{ + LCFGReadResult retval; + OSTick start = OS_GetTick(); + + retval = LCFGi_THW_ReadNormalInfo(); + if( retval == LCFG_TSF_READ_RESULT_SUCCEEDED ) { + OS_TPrintf( "HW Normal Info read succeeded.\n" ); + }else { + OS_TPrintf( "HW Normal Info read failed.\n" ); + } + + OS_TPrintf( "HW Normal Info read time = %dms\n", OS_TicksToMilliSeconds( OS_GetTick() - start ) ); + + start = OS_GetTick(); + retval = s_pReadSecureInfoFunc(); + if( retval == LCFG_TSF_READ_RESULT_SUCCEEDED ) { + OS_TPrintf( "HW Secure Info read succeeded.\n" ); + }else { + OS_TPrintf( "HW Secure Info read failed.\n" ); + } + OS_TPrintf( "HW Secure Info read time = %dms\n", OS_TicksToMilliSeconds( OS_GetTick() - start ) ); +} + + +// HWŜ̃Cg +static void WriteHWInfoFile( u8 region ) +{ + static const u16 *pMsgNormalWriting = (const u16 *)L"Writing Normal File..."; + static const u16 *pMsgSecureWriting = (const u16 *)L"Writing Secure File..."; + static const u16 *pMsgSucceeded = (const u16 *)L"Succeeded!"; + static const u16 *pMsgFailed = (const u16 *)L"Failed!"; + + // m[}t@C̃Cg + (void)PutStringUTF16( MSG_X * 8, MSG_Y * 8, TXT_COLOR_BLACK, pMsgNormalWriting ); + + if( WriteHWNormalInfoFile() ) { + (void)PutStringUTF16( ( MSG_X + 18 ) * 8, MSG_Y * 8, TXT_COLOR_BLUE, pMsgSucceeded ); + }else { + (void)PutStringUTF16( ( MSG_X + 18 ) * 8, MSG_Y * 8, TXT_COLOR_RED, pMsgFailed ); + } + + // ZLAt@C̃Cg + (void)PutStringUTF16( MSG_X * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_BLACK, pMsgSecureWriting ); + + if( WriteHWSecureInfoFile( region ) ) { + (void)PutStringUTF16( ( MSG_X + 18 ) * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_BLUE, pMsgSucceeded ); + }else { + (void)PutStringUTF16( ( MSG_X + 18 ) * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_RED, pMsgFailed ); + } + + ModifyLanguage( region ); + + // bZ[W莞ԕ\ď + DispMessage( 0, 0, TXT_COLOR_NULL, NULL ); + NNS_G2dCharCanvasClearArea( &gCanvas, TXT_COLOR_WHITE, + MSG_X * 8 , MSG_Y * 8, ( 32 - MSG_X ) * 8, ( MSG_Y + 4 ) * 8 ); + + PrintfSJISSub( 2 * 8, 16 * 8, TXT_COLOR_WHITE, "Region = %s", strRegion[ s_region_old ] ); + PrintfSJISSub( 2 * 8, 16 * 8, TXT_COLOR_BLACK, "Region = %s", strRegion[ LCFG_THW_GetRegion() ] ); + s_region_old = LCFG_THW_GetRegion(); +} + + +// HWm[}Infot@C̃Cg +static BOOL WriteHWNormalInfoFile( void ) +{ + BOOL isWrite = TRUE; + LCFGReadResult result; + + result = LCFGi_THW_ReadNormalInfo(); + if( result != LCFG_TSF_READ_RESULT_SUCCEEDED ) { + if( !LCFGi_THW_RecoveryNormalInfo( result ) ) { + OS_TPrintf( "HW Normal Info Recovery failed.\n" ); + isWrite = FALSE; + } + } + if( isWrite && + !LCFGi_THW_WriteNormalInfo() ) { + OS_TPrintf( "HW Normal Info Write failed.\n" ); + } + + return isWrite; +} + + +// HWZLAInfot@C̃Cg +static BOOL WriteHWSecureInfoFile( u8 region ) +{ + BOOL isWrite = TRUE; + LCFGReadResult result; + + // t@C̃[h + result = s_pReadSecureInfoFunc(); + + // [hɎs烊Jo + if( result != LCFG_TSF_READ_RESULT_SUCCEEDED ) { + if( !LCFGi_THW_RecoverySecureInfo( result ) ) { + OS_TPrintf( "HW Secure Info Recovery failed.\n" ); + isWrite = FALSE; + } + } + + // [W̃Zbg + LCFG_THW_SetRegion( region ); + + // Ήrbg}bṽZbg + LCFG_THW_SetValidLanguageBitmap( s_langBitmapList[ region ] ); + + // [TODO:]ʎYHłȂƃVANo.͗pӂłȂ̂ŁAłMACAhXƂɓKȒlZbgB + // VANo.̃Zbg + { + u8 buffer[ 12 ] = "SERIAL"; // KȕMACAhXƌSHA1ASerialNoƂB + u8 serialNo[ SVC_SHA1_DIGEST_SIZE ]; + int i; + int len = ( LCFG_THW_GetRegion() == LCFG_TWL_REGION_AMERICA ) ? + LCFG_TWL_HWINFO_SERIALNO_LEN_AMERICA : LCFG_TWL_HWINFO_SERIALNO_LEN_OTHERS; + OS_GetMacAddress( buffer + 6 ); + SVC_CalcSHA1( serialNo, buffer, sizeof(buffer) ); + for( i = 3; i < SVC_SHA1_DIGEST_SIZE; i++ ) { + serialNo[ i ] = (u8)( ( serialNo[ i ] % 10 ) + 0x30 ); + } + MI_CpuCopy8( "SRN", serialNo, 3 ); + MI_CpuClear8( &serialNo[ len ], sizeof(serialNo) - len ); + OS_TPrintf( "serialNo : %s\n", serialNo ); + LCFG_THW_SetSerialNo( serialNo ); + } + + // `[TitleID_LõZbg + { + int i; + u8 titleID_Lo[4]; + for( i = 0; i < 4; i++ ) titleID_Lo[ i ] = (u8)strLauncherGameCode[ region ][ 4 - i - 1 ]; + LCFG_THW_SetLauncherTitleID_Lo( (const u8 *)titleID_Lo ); + } + + // Cg + if( isWrite && + !LCFGi_THW_WriteSecureInfo( s_pPrivKeyBuffer ) ) { + isWrite = FALSE; + OS_TPrintf( "HW Secure Info Write failed.\n" ); + } + + return isWrite; +} + + +// HWInfot@C̍폜 +static void DeleteHWInfoFile( void ) +{ + static const u16 *pMsgNormalDeleting = (const u16 *)L"Deleting Normal File..."; + static const u16 *pMsgSecureDeleting = (const u16 *)L"Deteting Secure File..."; + static const u16 *pMsgSucceeded = (const u16 *)L"Succeeded!"; + static const u16 *pMsgFailed = (const u16 *)L"Failed!"; + + // m[}t@C + (void)PutStringUTF16( MSG_X * 8, MSG_Y * 8, TXT_COLOR_BLACK, pMsgNormalDeleting ); + if( FS_DeleteFile( (char *)LCFG_TWL_HWINFO_NORMAL_PATH ) ) { + OS_TPrintf( "%s delete succeeded.\n", (char *)LCFG_TWL_HWINFO_NORMAL_PATH ); + (void)PutStringUTF16( ( MSG_X + 19 ) * 8, MSG_Y * 8, TXT_COLOR_BLUE, pMsgSucceeded ); + }else { + OS_TPrintf( "%s delete failed.\n", (char *)LCFG_TWL_HWINFO_NORMAL_PATH ); + (void)PutStringUTF16( ( MSG_X + 19 ) * 8, MSG_Y * 8, TXT_COLOR_RED, pMsgFailed ); + } + + // ZLAt@C + (void)PutStringUTF16( MSG_X * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_BLACK, pMsgSecureDeleting ); + if( FS_DeleteFile( (char *)LCFG_TWL_HWINFO_SECURE_PATH ) ) { + OS_TPrintf( "%s delete succeeded.\n", (char *)LCFG_TWL_HWINFO_SECURE_PATH ); + (void)PutStringUTF16( ( MSG_X + 19 ) * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_BLUE, pMsgSucceeded ); + }else { + OS_TPrintf( "%s delete failed.\n", (char *)LCFG_TWL_HWINFO_SECURE_PATH ); + (void)PutStringUTF16( ( MSG_X + 19 ) * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_RED, pMsgFailed ); + } + DispMessage( 0, 0, TXT_COLOR_NULL, NULL ); + NNS_G2dCharCanvasClearArea( &gCanvas, TXT_COLOR_WHITE, + MSG_X * 8 , MSG_Y * 8, ( 32 - MSG_X ) * 8, ( MSG_Y + 4 ) * 8 ); +} + + +// HWInfot@C̃xt@C +static void VerifyHWInfo( void ) +{ + if( VerifyData( (const u8 *)LCFG_THW_GetNormalInfo(), (const u8 *)LCFG_THW_GetDefaultNormalInfo(), sizeof(LCFGTWLHWNormalInfo) ) ) { + OS_TPrintf( "HW normal Info verify succeeded.\n" ); + }else { + OS_TPrintf( "HW normal Info verify failed.\n" ); + } + if( VerifyData( (const u8 *)LCFG_THW_GetSecureInfo(), (const u8 *)LCFG_THW_GetDefaultSecureInfo(), sizeof(LCFGTWLHWSecureInfo) ) ) { + OS_TPrintf( "HW secure Info verify succeeded.\n" ); + }else { + OS_TPrintf( "HW secure Info verify failed.\n" ); + } + +} + + +// ̃f[^xt@C +static BOOL VerifyData( const u8 *pTgt, const u8 *pOrg, u32 len ) +{ + while( len-- ) { + if( *pTgt++ != *pOrg++ ) { + return FALSE; + } + } + return TRUE; +} + + +// bZ[W\ +static void DispMessage( int x, int y, u16 color, const u16 *pMsg ) +{ + OSTick start = OS_GetTick(); + // bZ[W\ + if( pMsg ) { + (void)PutStringUTF16( x, y, color, pMsg ); + } + // EFCg + while( OS_TicksToSeconds( OS_GetTick() - start ) < 2 ) { + OS_SpinWait( 0x1000 ); + } + // bZ[W + if( pMsg ) { + (void)PutStringUTF16( x, y, TXT_COLOR_WHITE, pMsg ); + } +} diff --git a/build/systemMenu_RED/HWInfoWriter/ARM9/src/HWInfoWriter.h b/build/systemMenu_RED/HWInfoWriter/ARM9/src/HWInfoWriter.h new file mode 100644 index 00000000..3f5c2ed8 --- /dev/null +++ b/build/systemMenu_RED/HWInfoWriter/ARM9/src/HWInfoWriter.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: DS_Chat.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 __DS_CHAT_H__ +#define __DS_CHAT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +// define data---------------------------------------------------------- + +void HWInfoWriterInit( void ); +void HWInfoWriterMain( void ); + +#ifdef __cplusplus +} +#endif + +#endif // __DS_CHAT_H__ diff --git a/build/systemMenu_RED/HWInfoWriter/ARM9/src/main.c b/build/systemMenu_RED/HWInfoWriter/ARM9/src/main.c new file mode 100644 index 00000000..5a5dd378 --- /dev/null +++ b/build/systemMenu_RED/HWInfoWriter/ARM9/src/main.c @@ -0,0 +1,82 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" +#include "HWInfoWriter.h" + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +static void INTR_VBlank( void ); + +// global variable------------------------------------------------------------- + +// static variable------------------------------------------------------------- + +// const data------------------------------------------------------------------ + + +// ============================================================================ +// function's description +// ============================================================================ +void TwlMain(void) +{ + // ---------------------------------- + OS_Init(); + OS_InitTick(); + + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + GX_Init(); + GX_SetPower(GX_POWER_ALL); // eWbN p[ON + + // 荞݋---------------------------- + (void)OS_SetIrqFunction(OS_IE_V_BLANK, INTR_VBlank); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + + // foCX------------------------------- + (void)RTC_Init(); + + // VXȅ------------------ + InitAllocator(); + + // C[v---------------------------- + HWInfoWriterInit(); + while(1){ + OS_WaitIrq(1, OS_IE_V_BLANK); // VuN荞ݑ҂ + ReadKeyPad(); // L[͂̎擾 + + HWInfoWriterMain(); + } +} + + +// ============================================================================ +// 荞ݏ +// ============================================================================ + +// VuN荞 +static void INTR_VBlank(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // VuN`FbÑZbg +} + diff --git a/build/systemMenu_RED/HWInfoWriter/Makefile b/build/systemMenu_RED/HWInfoWriter/Makefile new file mode 100644 index 00000000..66754bca --- /dev/null +++ b/build/systemMenu_RED/HWInfoWriter/Makefile @@ -0,0 +1,30 @@ +#! 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:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/HWInfoWriter/banner/Makefile b/build/systemMenu_RED/HWInfoWriter/banner/Makefile new file mode 100644 index 00000000..27b48038 --- /dev/null +++ b/build/systemMenu_RED/HWInfoWriter/banner/Makefile @@ -0,0 +1,49 @@ +#! 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:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/systemMenu_RED/HWInfoWriter/banner/banner_v3.bsf b/build/systemMenu_RED/HWInfoWriter/banner/banner_v3.bsf new file mode 100644 index 00000000..f097cd88 Binary files /dev/null and b/build/systemMenu_RED/HWInfoWriter/banner/banner_v3.bsf differ diff --git a/build/systemMenu_RED/HWInfoWriter/banner/icon/gameIcon.bmp b/build/systemMenu_RED/HWInfoWriter/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..5fe5ee2c Binary files /dev/null and b/build/systemMenu_RED/HWInfoWriter/banner/icon/gameIcon.bmp differ diff --git a/build/systemMenu_RED/Launcher/ARM9/ARM9-TS.lcf.template b/build/systemMenu_RED/Launcher/ARM9/ARM9-TS.lcf.template new file mode 100644 index 00000000..7551a3d2 --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/ARM9-TS.lcf.template @@ -0,0 +1,1033 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-TS.lcf.template +# +# 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-11-15#$ +# $Rev: 2384 $ +# $Author: nishimoto_takashi $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.NITRO (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN.NITRO (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX.NITRO (RW) : ORIGIN = AFTER(dummy.MAIN_EX.NITRO,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + + check.ITCM (RW) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.TWL (RW) : ORIGIN = 0x0d000000, LENGTH = 0x0 + arena.MAIN.TWL (RW) : ORIGIN = AFTER(,,LTDMAIN,), LENGTH = 0x0 + arena.MAIN_EX.TWL (RW) : ORIGIN = AFTER(dummy.MAIN_EX.TWL,,,LTDMAIN,), LENGTH = 0x0 + + binary.MODULE_FILES (RW) : ORIGIN = 0, LENGTH = 0x0 > component.files +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + libsyscall.a (.text) + OBJECT(_start,*) + crt0.FLX.TWL.o (.text) + crt0.FLX.TWL.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); # Fit to cache line + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + . = ALIGN(4); + + SDK_LTDOVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_LTDOVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_OVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAY_DIGEST =.; + . = . + * 20; + . = . + * 20; + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x02fe0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(32); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW SDK_OVERLAY_DIGEST - ADDR(.); + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > F + + ############################ ARENA ################################## + .dummy.MAIN_EX.NITRO: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.NITRO + + .arena.MAIN.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN.NITRO + + .arena.MAIN_EX.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + + } > arena.MAIN_EX.NITRO + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + + } > arena.DTCM + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + + } > check.ITCM + + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + . = . + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_EDN = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02d00000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > L + + ############################ ARENA ################################## + .dummy.MAIN_EX.TWL: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.TWL + + .arena.MAIN.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_ARENA_LO =.; + + } > arena.MAIN.TWL + + .arena.MAIN_EX.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_EX_ARENA_LO =.; + + } > arena.MAIN_EX.TWL + + ############################ OTHERS ################################# + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + + } > binary.MODULE_FILES + +} diff --git a/build/systemMenu_RED/Launcher/ARM9/ARM9-TS.lsf b/build/systemMenu_RED/Launcher/ARM9/ARM9-TS.lsf new file mode 100644 index 00000000..199d6f87 --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/ARM9-TS.lsf @@ -0,0 +1,54 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-BB.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- +# +# TWL LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x02800000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) +} + + +Autoload ITCM +{ + Address 0x01ff8000 + Object * (.itcm) + Object $(OBJS_AUTOLOAD) (.text) + Object $(OBJS_AUTOLOAD) (.rodata) +} + +Autoload DTCM +{ + Address $(ADDRESS_DTCM) + Object * (.dtcm) + Object $(OBJS_AUTOLOAD) (.data) + Object $(OBJS_AUTOLOAD) (.sdata) + Object $(OBJS_AUTOLOAD) (.bss) + Object $(OBJS_AUTOLOAD) (.sbss) +} + +Ltdautoload LTDMAIN +{ + # NITRO/TWL L̃I[o[C݂ꍇ́Aɂ̌ɔzuKv܂B + After $(TARGET_NAME) + Object * (.ltdmain) + Object $(OBJS_LTDAUTOLOAD) + Library $(LLIBS_EX) $(GLIBS_EX) +} diff --git a/build/systemMenu_RED/Launcher/ARM9/Makefile b/build/systemMenu_RED/Launcher/ARM9/Makefile new file mode 100644 index 00000000..b3f6b70a --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/Makefile @@ -0,0 +1,93 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = \ + ../../../libraries_sysmenu/sysmenu \ + ../../../libraries_sysmenu/hotsw \ + ../../../components/hyena.TWL +# ../../../libraries_sysmenu/reloc_info \ +# ../../../libraries_sysmenu/boot \ + +#---------------------------------------------------------------------------- + +#FIRM_BUILD = TRUE + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_CODEGEN = ARM +TWL_ARCHGEN = LIMITED + +TITLEID_LO = LNCJ +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +TARGET_BIN = main.srl + +LCFILE_SPEC = ARM9-TS.lsf +LCFILE_TEMPLATE = ARM9-TS.lcf.template +ROM_SPEC = main.rsf + +LOGO_DIR = Logo +MISC_DIR = ../../misc + +BG_DIR = ../../data + +SRCS_LOGO = logoDemo.c logoData.c +SRCS = main.c launcher.c sound.c bannerCounter.c \ + $(addprefix $(LOGO_DIR)/, $(SRCS_LOGO)) \ + $(MISC_DIR)/src/misc.c $(MISC_DIR)/src/cmn.c \ + $(BG_DIR)/BGData_Launcher.c + +LINCLUDES = $(MISC_DIR)/include \ + $(SRCDIR)/$(LOGO_DIR) + +LLIBRARIES += libes$(TWL_LIBSUFFIX).a \ + libboc$(TWL_LIBSUFFIX).a \ + libnam$(TWL_LIBSUFFIX).a \ + libreloc_info$(TWL_LIBSUFFIX).a + +ADDRESS_DTCM = 0x0e000000 + +DEFAULT_COMP_ARM7 = hyena + +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' +ifdef FIRM_BUILD +MAKEROM_FLAGS += -s \ + -DSYS_PRIV_KEY=$(TWL_KEYSDIR)/rsa/private9_0.der \ + -DSYS_PUB_KEY=$(TWL_KEYSDIR)/rsa/public9_0.der +endif + +MAKETAD_FLAGS += -s + +include $(TWLSDK_ROOT)/add-ins/es/commondefs.es +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs +include $(TWLSDK_ROOT)/build/libraries/reboot/commondefs.reboot + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/Launcher/ARM9/main.rsf b/build/systemMenu_RED/Launcher/ARM9/main.rsf new file mode 100644 index 00000000..3b0b883f --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/main.rsf @@ -0,0 +1,180 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + #BannerFile ./etc/myGameBanner.bnr + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # +# WramMapping $(MAKEROM_WRAM_MAPPING) + WramMappingDirect $(TWL_IPL_RED_ROOT)/build/components/hyena.TWL/wram_regs/wram_regs.rbin + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType System + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch FALSE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + SaveBannerFile FALSE +} + + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot ../../data + Root /data + File NTR_IPL_font_m.NFTR NoCardBanner.bnr EmptyBanner.bnr NoBanner.bnr fanfare.32.wav +} \ No newline at end of file diff --git a/build/systemMenu_RED/Launcher/ARM9/src/Logo/logoData.c b/build/systemMenu_RED/Launcher/ARM9/src/Logo/logoData.c new file mode 100644 index 00000000..4c42364c --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/src/Logo/logoData.c @@ -0,0 +1,86 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: logoData.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" + +// define data----------------------------------------------------------- + +// extern data----------------------------------------------------------- + +// function's prototype-------------------------------------------------- +void LoadLogoData( void ); + +// global variable------------------------------------------------------- + +// static variable------------------------------------------------------- + +// const data------------------------------------------------------------ + +static const u8 Nin_Char_Diff_Huff[] ATTRIBUTE_ALIGN( 2 ) = { + 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, 0x00, 0x00, +}; + + +// ============================================================================ +// Sf[^[h +// ============================================================================ +void LoadLogoData(void) +{ + *(vu16 *)( HW_OBJ_PLTT + 0x1e ) = 0x7c00; // OBJpbgZbg + *(vu16 *)HW_BG_PLTT = 0xffff; // obNhbvuvɂB + + SYSM_LoadNintendoLogo2D( (u16 *)Nin_Char_Diff_Huff, (u16 *)( HW_OBJ_VRAM + 0x0000 ), 0xf ); + + G2_SetOBJAttr( + (GXOamAttr *)HW_OAM, + 71, + 88, + 2, + GX_OAM_MODE_NORMAL, + FALSE, + GX_OAM_EFFECT_NONE, + GX_OAM_SHAPE_64x32, + GX_OAM_COLORMODE_16, + 0, // charNo. + 0, // paletteNo. + 0 + ); + G2_SetOBJAttr( + (GXOamAttr *)HW_OAM + 1, + 71 + 64, + 88, + 2, + GX_OAM_MODE_NORMAL, + FALSE, + GX_OAM_EFFECT_NONE, + GX_OAM_SHAPE_64x32, + GX_OAM_COLORMODE_16, + 8, // charNo. + 0, // paletteNo. + 0 + ); +} diff --git a/build/systemMenu_RED/Launcher/ARM9/src/Logo/logoDemo.c b/build/systemMenu_RED/Launcher/ARM9/src/Logo/logoDemo.c new file mode 100644 index 00000000..a93a280b --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/src/Logo/logoDemo.c @@ -0,0 +1,118 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: logoDemo.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 "logoDemo.h" +#include "misc.h" + +// define data-------------------------------------------------------- + +#define LOGO_DISP_FRAME 60 // S\t[ + +// S\Xe[^X\ +typedef struct LogoStatus { + s32 state; + s32 value_A; + s32 value_B; + s32 mainCounter; +}LogoStatus; + +// extern data-------------------------------------------------------- +extern void LoadLogoData( void ); + +// function's prototype----------------------------------------------- + +// static variables--------------------------------------------------- +static LogoStatus s_logo = { 0, 0, 0, 0 }; + +// const data--------------------------------------------------------- + +void LogoInit( void ) +{ + if( SYSM_IsLogoDemoSkip() ) { + return; + } + + // OFF + GX_DispOff(); + GXS_DispOff(); + + // VRAM蓖āNA + GX_SetBankForOBJ( GX_VRAM_OBJ_128_A ); // @V@@@@@OBJp + GX_SetGraphicsMode( GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BG0_AS_2D ); + MI_CpuClearFast( (void *)HW_OBJ_VRAM, 0x1000 ); // OBJ-VRAM NA + MI_DmaFill32( 3, (void *)HW_OAM, 192, HW_OAM_SIZE ); // OAM NA + + // ʐݒ + GX_SetGraphicsMode( GX_DISPMODE_GRAPHICS, GX_BGMODE_2, GX_BG0_AS_2D ); + GX_SetOBJVRamModeChar( GX_OBJVRAMMODE_CHAR_2D ); + G2_SetBlendAlpha( GX_BLEND_PLANEMASK_OBJ, GX_BLEND_PLANEMASK_BD, s_logo.value_A, s_logo.value_B ); + GX_SetVisiblePlane( GX_PLANEMASK_OBJ ); + + // Sf[^[h + LoadLogoData(); + + s_logo.state = 1; + s_logo.mainCounter = 0; + s_logo.value_A = 0; + s_logo.value_B = 16; + G2_ChangeBlendAlpha( s_logo.value_A, s_logo.value_B ); + + // Cʂ̂ON + GX_DispOn(); +} + + +// SC +int LogoMain() +{ + if( SYSM_IsLogoDemoSkip() ) { + return 1; + } + + switch( s_logo.state ) { + case 1: // NintendoStF[hC + if( s_logo.mainCounter++ < 16 ){ // Nintendoۺ \ + G2_ChangeBlendAlpha( ++s_logo.value_A, --s_logo.value_B ); + }else { + s_logo.mainCounter = 0; + s_logo.state++; + } + break; + + + case 2: // NintendoS\ + if( s_logo.mainCounter++ == LOGO_DISP_FRAME ) { + s_logo.mainCounter = 0; + s_logo.state++; + } + break; + + case 3: // NintendoStF[hAEg + if( s_logo.mainCounter++ < 16 ) { + G2_ChangeBlendAlpha( --s_logo.value_A, ++s_logo.value_B ); + }else { + return 1; + } + break; + + default: + break; + } + + return 0; +} + diff --git a/build/systemMenu_RED/Launcher/ARM9/src/Logo/logoDemo.h b/build/systemMenu_RED/Launcher/ARM9/src/Logo/logoDemo.h new file mode 100644 index 00000000..4e68c2e8 --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/src/Logo/logoDemo.h @@ -0,0 +1,36 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: logoDemo.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 _LOGO_DEMO_H +#define _LOGO_DEMO_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern void LogoInit( void ); +extern int LogoMain( void ); +extern void SetLogoEnable( BOOL enable ); +extern BOOL IsLogoEnable( void ); + +#ifdef __cplusplus +} +#endif + +#endif /* _LOGO_DEMO_H */ diff --git a/build/systemMenu_RED/Launcher/ARM9/src/bannerCounter.c b/build/systemMenu_RED/Launcher/ARM9/src/bannerCounter.c new file mode 100644 index 00000000..6b7a0783 --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/src/bannerCounter.c @@ -0,0 +1,116 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: launcher.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:: 2008-01-29#$ + $Rev: 533 $ + $Author: yoshida_teruhisa $ + *---------------------------------------------------------------------------*/ + +#include "bannerCounter.h" + +// define data------------------------------------------ + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- + +// global variable ------------------------------------- + +// static variable ------------------------------------- + +// const data ----------------------------------------- + +//=============================================== +// bannerCounter.c +//=============================================== + +void BNC_incrementCount( BannerCounter *c ) +{ + // TWL̂݃JEgCNg + if( c->banner->h.platform == BANNER_PLATFORM_TWL ) + { + if( c->banner->anime.control[0].frameCount == 0 ) + { + // AjɏI[݂Ȃ + OS_TPrintf( "BNC_incrementCount:Only a Terminator!\n" ); + return; + } + + c->count++; + if( c->count >= c->banner->anime.control[c->control].frameCount ) + { + // JEglRg[̃t[JEg𒴂̂Ŏ̃Rg[ + c->control++; + c->count = 0; + + //[vyђ~̏ + if( c->control >= BANNER_ANIME_CONTROL_INFO_NUM ) + { + // Rg[E𒴂疳Ń[v + BNC_resetCount( c ); + } + else if( c->banner->anime.control[c->control].frameCount == 0 ) + { + // Rg[̃t[JEg0ȂI[B + if( c->banner->anime.control[c->control].animeType == 0 ) + { + // Aj^Cv0Ȃ烋[v + BNC_resetCount( c ); + } + else if( c->banner->anime.control[c->control].animeType == 1 ) + { + // Aj^Cv1Ȃ~i‘ÕRg[ɖ߂j + c->control--; + } + } + } + } +} + +FrameAnimeData BNC_getFAD( BannerCounter *c ) +{ + FrameAnimeData ret; + if( c->banner->h.platform == BANNER_PLATFORM_NTR ) + { + ret.image = c->banner->v1.image; + ret.pltt = c->banner->v1.pltt; + ret.hflip = FALSE; + ret.vflip = FALSE; + } + else + { + if( c->banner->anime.control[0].frameCount == 0 ) + { + // AjɏI[݂Ȃ + OS_TPrintf( "BNC_getFAD:Only a Terminator!\n" ); + ret.image = c->banner->v1.image; + ret.pltt = c->banner->v1.pltt; + ret.hflip = FALSE; + ret.vflip = FALSE; + return ret; + } + // Rg[f[^ǂŁÃ݂t[ɊYf[^Ԃ + ret.image = c->banner->anime.image[ c->banner->anime.control[c->control].normal.cellNo ]; + ret.pltt = c->banner->anime.pltt[ c->banner->anime.control[c->control].normal.plttNo ]; + ret.hflip = c->banner->anime.control[c->control].normal.flipType & 0x1; + ret.vflip = (c->banner->anime.control[c->control].normal.flipType & 0x2) >> 1; + } + return ret; +} + +FrameAnimeData BNC_getFADAndIncCount( BannerCounter *c ) +{ + FrameAnimeData ret = BNC_getFAD( c ); + BNC_incrementCount( c ); + return ret; +} + diff --git a/build/systemMenu_RED/Launcher/ARM9/src/bannerCounter.h b/build/systemMenu_RED/Launcher/ARM9/src/bannerCounter.h new file mode 100644 index 00000000..d1fc4586 --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/src/bannerCounter.h @@ -0,0 +1,80 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: bannerCounter.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-11-20#$ + $Rev: 231 $ + $Author: yoshida_teruhisa $ + *---------------------------------------------------------------------------*/ + +#ifndef __BANNERCOUNTER_H__ +#define __BANNERCOUNTER_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// define data------------------------------------------------------- + +typedef struct BannerCounter +{ + u32 control; + u8 count; + TWLBannerFile *banner; +} +BannerCounter; + +typedef struct FrameAnimeData{ + u8 *image; + u8 *pltt; + BOOL vflip; + BOOL hflip; +} +FrameAnimeData; + +// global variables-------------------------------------------------- + +// function---------------------------------------------------------- + +static inline void BNC_resetCount( BannerCounter *c ) +{ + c->count = 0; + c->control = 0; +} + +static inline void BNC_setBanner( BannerCounter *c, TWLBannerFile *b) +{ + c->banner = b; +} + +static inline void BNC_initCounter( BannerCounter *c, TWLBannerFile *b) +{ + BNC_setBanner( c, b ); + BNC_resetCount( c ); +} + +static inline TWLBannerFile* BNC_getBanner( BannerCounter *c ) +{ + return c->banner; +} + +void BNC_incrementCount( BannerCounter *c ); +FrameAnimeData BNC_getFAD( BannerCounter *c ); +FrameAnimeData BNC_getFADAndIncCount( BannerCounter *c ); + +#ifdef __cplusplus +} +#endif + +#endif // __BANNERCOUNTER_H__ diff --git a/build/systemMenu_RED/Launcher/ARM9/src/launcher.c b/build/systemMenu_RED/Launcher/ARM9/src/launcher.c new file mode 100644 index 00000000..8f8f151a --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/src/launcher.c @@ -0,0 +1,732 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: launcher.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" +#include "launcher.h" +#include "bannerCounter.h" +#include "sound.h" +#include + + +// define data------------------------------------------ + +// obNCg{^֌W +#define B_LIGHT_DW_BUTTON_TOP_X ( 0 ) +#define B_LIGHT_DW_BUTTON_TOP_Y ( 22 * 8 ) +#define B_LIGHT_DW_BUTTON_BOTTOM_X ( B_LIGHT_DW_BUTTON_TOP_X + 11 ) +#define B_LIGHT_DW_BUTTON_BOTTOM_Y ( B_LIGHT_DW_BUTTON_TOP_Y + 16 ) +#define B_LIGHT_UP_BUTTON_TOP_X ( 11 ) +#define B_LIGHT_UP_BUTTON_TOP_Y ( 22 * 8 ) +#define B_LIGHT_UP_BUTTON_BOTTOM_X ( B_LIGHT_UP_BUTTON_TOP_X + 22 ) +#define B_LIGHT_UP_BUTTON_BOTTOM_Y ( B_LIGHT_UP_BUTTON_TOP_Y + 16 ) + +// XN[o[֌W +#define BAR_ZERO_X ( (WINDOW_WIDTH - ((ITEM_SIZE + ITEM_INTERVAL) * (LAUNCHER_TITLE_LIST_NUM - 1) + ITEM_SIZE)) / 2) +#define BAR_ZERO_Y WINDOW_HEIGHT - 32 +#define BAR_HEIGHT 14 +#define BAR_WIDTH 32 //((ITEM_SIZE + ITEM_INTERVAL) * 4 + ITEM_SIZE + 2) +#define BAR_LOOSENESS 2 +#define ITEMDOT_PER_FRAME ((double)(ITEM_SIZE + ITEM_INTERVAL) / (double)FRAME_PER_SELECT) +#define FRAME_PER_ITEMDOT ((double)FRAME_PER_SELECT / (double)(ITEM_SIZE + ITEM_INTERVAL)) +#define BAR_OFFSET 0 // \""eLXggĂ̂ŁA^b`W␳ړIOFFSET +#define ITEM_SIZE 2 +#define ITEM_INTERVAL 3 + +// oi[\֌W +#define DOT_PER_FRAME ((BANNER_WIDTH + BANNER_INTERVAL) / FRAME_PER_SELECT) // ؂ȂƓJNJN͂ +#define FRAME_PER_SELECT 14 // oi[oi[ւ̈ړɂt[ +#define BANNER_FAR_LEFT_POS (WINDOW_WIDTH/2 - BANNER_WIDTH*5/2 - BANNER_INTERVAL * 2) +#define BANNER_TOP (WINDOW_HEIGHT/2 - 16) +#define WINDOW_WIDTH 256 +#define WINDOW_HEIGHT 192 +#define BANNER_WIDTH 32 +#define BANNER_HEIGHT 32 +#define BANNER_INTERVAL 24 +#define TITLE_V_CENTER 39 + +#define MAX_SHOW_BANNER 6 + +#define MAX_LOAD_IMAGES 128 + +// tF[hAEg֌W +#define FADE_COUNT_PER_ALPHA ((FADE_COUNT_MAX - FADE_START) / ALPHA_MAX) +#define FADE_COUNT_MAX 124 +#define ALPHA_MAX 31 +#define FADE_START 62 + +// extern data------------------------------------------ + +extern u32 bg_char_data[8 * 6]; +extern u16 bg_scr_data[32 * 32]; +extern u16 bg_scr_data2[32 * 32]; + +// function's prototype declaration--------------------- +static void LoadBannerFiles( void ); +static void BannerInit( void ); +static void SetDefaultBanner( TitleProperty *titleprop ); +static void SetAffineAnimation( BOOL (*flipparam)[4] ); +static void SetBannerCounter( TitleProperty *titleprop ); +static void SetOAMAttr( void ); +static void BannerDraw( int selected, TitleProperty *titleprop); +static BOOL SelectCenterFunc( u16 *csr, TPData *tgt ); +static BOOL SelectFunc( u16 *csr, TPData *tgt ); +static void ProcessBackLightPads( void ); +static TitleProperty *ProcessPads( TitleProperty *pTitleList ); +static void MoveByScrollBar(); +static void DrawScrollBar(); +static void DrawBackLightSwitch(void); + +// global variable ------------------------------------- +RTCDrawProperty g_rtcDraw = { + TRUE, RTC_DATE_TOP_X, RTC_DATE_TOP_Y, RTC_TIME_TOP_X, RTC_TIME_TOP_Y +}; + +// static variable ------------------------------------- +static int s_csr = 0; // ʒWƁAXg̈ԍŏɂoi[̒WƂ̋ + // ړ̂ɕKvȃt[ŕ\߂̕ϐ +static int csr_v = 0; // s_csȓxIϐ + +static TWLBannerFile *empty_banner; +static TWLBannerFile *nobanner_banner; +static TWLBannerFile *no_card_banner; +static GXOamAttr banner_oam_attr[MAX_SHOW_BANNER+10];// AtBp[^߂֌Wŏ傫 +static int selected = 0; +static int bar_left = BAR_ZERO_X; +static fx32 s_selected_banner_size; +static BOOL s_wavstop = FALSE; +static BannerCounter banner_counter[LAUNCHER_TITLE_LIST_NUM]; + +//static StreamInfo strm; // stream info + +// const data ----------------------------------------- +//const char filename[] = "data/fanfare.32.wav"; + +//=============================================== +// Launcher.c +//=============================================== + +//====================================================== +// `[ +//====================================================== + +// oi[\֌Wibj +#define DBGBNR +#ifdef DBGBNR + + +static void LoadBannerFiles( void ) +{ + // ftHgoi[t@C̓ǂݍ݁BŏIIɃu[gĂ܂̂ŁA͖ + u32 size = CMN_LoadFile( (void **)&empty_banner, "data/EmptyBanner.bnr", &g_allocator); + NNS_G2D_ASSERT( size > 0 ); + size = CMN_LoadFile( (void **)&nobanner_banner, "data/NoBanner.bnr", &g_allocator); + NNS_G2D_ASSERT( size > 0 ); + size = CMN_LoadFile( (void **)&no_card_banner, "data/NoCardBanner.bnr", &g_allocator); + NNS_G2D_ASSERT( size > 0 ); +} + +// pbg̓ǂݍ݂OBJ֌W̏ +static void BannerInit( void ) +{ + int l; + LoadBannerFiles(); + + MI_DmaFill32(3, banner_oam_attr, 192, sizeof(banner_oam_attr)); // let out of the screen if not display + + // OBJMode̐ݒ + GX_SetOBJVRamModeChar(GX_OBJVRAMMODE_CHAR_1D_128K); // 2D mapping mode + + // BannerCounteȑ + for( l=0; lh.crc16_v1 != titleprop[l].pBanner->h.crc16_v1) + { + BNC_resetCount( &banner_counter[l] ); + } + } + } +} + +// OAMf[^̐ݒ +static void SetOAMAttr( void ) +{ + int l; + int div1 = s_csr / FRAME_PER_SELECT; + int div2 = s_csr % FRAME_PER_SELECT; + BOOL flipparam[4]; + + for (l=0;lv1.gameName[ LCFG_TSD_GetLanguage() ]; + NNSG2dTextRect rect = NNS_G2dTextCanvasGetTextRect( &gTextCanvas, str ); + NNS_G2dCharCanvasClearArea( &gCanvas, TXT_COLOR_NULL, 0, 24, WINDOW_WIDTH, 32 ); + PutStringUTF16( (WINDOW_WIDTH-rect.width)>>1, TITLE_V_CENTER - (rect.height>>1), TXT_COLOR_BLACK, str ); + old_selected = selected; + } + + if(fadecount < (FADE_COUNT_MAX - FADE_START)) { + fadecount += 2; + G2_ChangeBlendAlpha( ALPHA_MAX-((fadecount)/FADE_COUNT_PER_ALPHA), (fadecount)/FADE_COUNT_PER_ALPHA ); + } +} + +#endif //DBGBNR + + +// `[̏ +void LauncherInit( TitleProperty *pTitleList ) +{ +#pragma unused( pTitleList ) + + InitBG(); // BG + + GX_DispOff(); + GXS_DispOff(); + + ChangeUserColor( LCFG_TSD_GetUserColor() ); + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + + // BGf[^̃[h + GX_LoadBG1Char(bg_char_data, 0, sizeof(bg_char_data)); + GX_LoadBG1Scr(bg_scr_data, 0, sizeof(bg_scr_data)); + + // tF[hAEgpBGf[^쐬ƃ[h + SVC_CpuClear( 0x0004, &bg_scr_data2, sizeof(bg_scr_data2), 16 ); + DC_FlushRange(&bg_scr_data2, sizeof(bg_scr_data2)); + GX_LoadBG2Char(bg_char_data, 0, sizeof(bg_char_data)); + GX_LoadBG2Scr(bg_scr_data2, 0, sizeof(bg_scr_data2)); + + DrawBackLightSwitch(); + PrintfSJIS( 0, 0, TXT_COLOR_BLUE, "TWL-SYSTEM MENU ver.%06x", SYSMENU_VER ); + + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + GetAndDrawRTCData( &g_rtcDraw, TRUE ); + + GX_SetVisiblePlane( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1 | GX_PLANEMASK_BG2 | GX_PLANEMASK_OBJ ); + G2_SetBlendAlpha(GX_BLEND_PLANEMASK_BG2, + GX_BLEND_PLANEMASK_BG0 | GX_BLEND_PLANEMASK_BG1 | GX_BLEND_PLANEMASK_OBJ, ALPHA_MAX,0); + + GX_DispOn(); + GXS_DispOn(); + + // streamInfo + //FS_InitFile(&strm.file); + //strm.isPlay = FALSE; + + #ifdef DBGBNR + BannerInit(); + #endif +} + +// ROM̃[fBÕ`[tF[hAEg +BOOL LauncherFadeout( TitleProperty *pTitleList ) +{ + static int fadecount = 0; + + // `֌W + //NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + //PrintfSJIS( 0, 0, TXT_COLOR_BLUE, "TWL-SYSTEM MENU ver.%06x", SYSMENU_VER ); + //DrawBackLightSwitch(); + DrawScrollBar( pTitleList ); + + #ifdef DBGBNR + BannerDraw( selected, pTitleList ); + #endif + + // `揭lj + { + MtxFx22 mtx; + static double wa; + double s = cos(wa); + if( s!=0 ) mtx._00 = (fx32)((s_selected_banner_size/s) * (1.0 + wa/3)); + else mtx._00 = 0x8fff; + mtx._01 = 0; + mtx._10 = 0; + mtx._11 = (fx32)(s_selected_banner_size * (1.0 + wa/3)); + G2_SetOBJAffine((GXOamAffine *)(&banner_oam_attr[0]), &mtx); + wa += 0.1; + } + + DC_FlushRange(&banner_oam_attr, sizeof(banner_oam_attr)); + GX_LoadOAM(&banner_oam_attr, 0, sizeof(banner_oam_attr)); + + // RTC̎擾\ + GetAndDrawRTCData( &g_rtcDraw, FALSE ); + + // tF[hAEg̃JEg + if(fadecount >= FADE_START) + { + G2_ChangeBlendAlpha( (fadecount-FADE_START)/FADE_COUNT_PER_ALPHA, ALPHA_MAX-((fadecount-FADE_START)/FADE_COUNT_PER_ALPHA) ); + } + if(fadecount < FADE_COUNT_MAX) { + fadecount++; + return FALSE; + }else { + // fBXvCOFFɂȂƋNɃmCY\ + GX_DispOff(); + GXS_DispOff(); + return TRUE; + } +} + +// ProcessPadsSelectSomethingByTPŎgSelectSomethingFunc̎ +static BOOL SelectCenterFunc( u16 *csr, TPData *tgt ) +{ + // PȎ + int x = WINDOW_WIDTH/2 - BANNER_WIDTH; + int y = BANNER_TOP - BANNER_HEIGHT/2; + if(WithinRangeTP( x, y, x+BANNER_WIDTH*2, y+BANNER_HEIGHT*2, tgt )) + { + *csr = (u16)1; + return TRUE; + } + + return FALSE; +} + +static BOOL SelectFunc( u16 *csr, TPData *tgt ) +{ + int l; + + for(l=0; l<2; l++) + { + int x = 11*8 + l*6*8; + int y = 17*8; + if(WithinRangeTP( x, y, x+32, y+16, tgt )) + { + *csr = (u16)l; + return TRUE; + } + } + return FALSE; +} + +static void ProcessBackLightPads( void ) +{ + static BOOL up_bl_bak = FALSE; + static BOOL dw_bl_bak = FALSE; + BOOL up_bl_trg = FALSE; + BOOL dw_bl_trg = FALSE; + int brightness; + + if(tpd.disp.touch) { + BOOL up_bl = WithinRangeTP( B_LIGHT_UP_BUTTON_TOP_X, B_LIGHT_UP_BUTTON_TOP_Y, + B_LIGHT_UP_BUTTON_BOTTOM_X, B_LIGHT_UP_BUTTON_BOTTOM_Y, &tpd.disp ); + BOOL dw_bl = WithinRangeTP( B_LIGHT_DW_BUTTON_TOP_X, B_LIGHT_DW_BUTTON_TOP_Y, + B_LIGHT_DW_BUTTON_BOTTOM_X, B_LIGHT_DW_BUTTON_BOTTOM_Y, &tpd.disp ); + up_bl_trg = ( up_bl && tpd.disp.touch && !up_bl_bak ) ; + dw_bl_trg = ( dw_bl && tpd.disp.touch && !dw_bl_bak ) ; + up_bl_bak = tpd.disp.touch; + dw_bl_bak = tpd.disp.touch; + }else { + up_bl_bak = FALSE; + dw_bl_bak = FALSE; + } + + if( (pad.trg & PAD_BUTTON_START) || up_bl_trg ) { + brightness = LCFG_TSD_GetBacklightBrightness() + 1; + if( brightness > LCFG_TWL_BACKLIGHT_LEVEL_MAX ) { + brightness = 0; + } + SYSM_SetBackLightBrightness( (u8)brightness ); + DrawBackLightSwitch(); + } + if( ( pad.trg & PAD_BUTTON_SELECT) || dw_bl_trg ) { + brightness = LCFG_TSD_GetBacklightBrightness() - 1; + if( brightness < 0 ) { + brightness = LCFG_TWL_BACKLIGHT_LEVEL_MAX; + } + SYSM_SetBackLightBrightness( (u8)brightness ); + DrawBackLightSwitch(); + } +} + +static TitleProperty *ProcessPads( TitleProperty *pTitleList ) +{ + SelectSomethingFunc func[1]={SelectCenterFunc}; + BOOL tp_select = FALSE; + u16 dummy; + u16 tp_lr = 3; + TitleProperty *ret = NULL; + LauncherBootFlags tempflag = {TRUE, LAUNCHER_BOOTTYPE_NAND, TRUE, FALSE, FALSE, FALSE, 0}; + + // obNCg֌W̃L[ + ProcessBackLightPads(); + + // ̑̃L[ + if( tpd.disp.touch ) + { + int x = WINDOW_WIDTH/2 - BANNER_WIDTH; + int y = BANNER_TOP - BANNER_HEIGHT/2; + if(WithinRangeTP( x, y, x+BANNER_WIDTH*2, y+BANNER_HEIGHT*2, &tpd.disp )) + { + s_wavstop = TRUE; + }else + { + s_wavstop = FALSE; + } + (void) SelectFunc( &tp_lr, &tpd.disp ); + }else + { + s_wavstop = FALSE; + } + + if( pad.trg & PAD_BUTTON_B ) { + OS_SetLauncherParamAndResetHardware( 0, NULL, &tempflag ); + } + + if(pad.cont & PAD_KEY_RIGHT || tp_lr == 1){ // oi[I + if(csr_v == 0) csr_v = 1; + } + if( pad.cont & PAD_KEY_LEFT || tp_lr == 0){ + if(csr_v == 0) csr_v = -1; + } + s_csr += csr_v; + if((LAUNCHER_TITLE_LIST_NUM-1)*FRAME_PER_SELECT < s_csr) s_csr = (LAUNCHER_TITLE_LIST_NUM-1)*FRAME_PER_SELECT; + if( s_csr < 0 ) s_csr = 0; + + selected = (s_csr + FRAME_PER_SELECT/2)/FRAME_PER_SELECT; + if(s_csr%FRAME_PER_SELECT == 0){ + csr_v = 0; + + // oi[ɂƂ”\ + tp_select = SelectSomethingByTP(&dummy, func, 1 ); + + if( ( pad.trg & PAD_BUTTON_A ) || ( tp_select ) ) { // j[ڂւ̕ + if( pTitleList[selected].flags.isValid ) + { + //PlayStream(&strm, filename); + ret = &pTitleList[selected]; + } + } + } + + return ret; +} + +// XN[o[ɂXN[ +// \KȎB +// {Ao[̃z[h̓o[W𒆐SɓׂB +static void MoveByScrollBar( void ) +{ + // XN[o[ɂXN[ + { + static BOOL holding = FALSE; + static int dx; + + if(!holding) + { + bar_left = (int)(BAR_ZERO_X + (ITEMDOT_PER_FRAME * s_csr)); + } + + if(tpd.disp.touch) + { + if(holding) + { + if ( tpd.disp.x - dx < bar_left - BAR_LOOSENESS) + { + bar_left = tpd.disp.x - dx + BAR_LOOSENESS; + } + else if ( tpd.disp.x - dx > bar_left + BAR_LOOSENESS) + { + bar_left = tpd.disp.x - dx - BAR_LOOSENESS; + } + s_csr = (u16)((bar_left - BAR_ZERO_X) * FRAME_PER_ITEMDOT); + } + else if(WithinRangeTP(bar_left+5-BAR_WIDTH/2, BAR_ZERO_Y+BAR_OFFSET,bar_left+5+BAR_WIDTH/2,BAR_ZERO_Y+BAR_OFFSET+BAR_HEIGHT,&tpd.disp)) + { + holding = TRUE; + dx = tpd.disp.x - bar_left; + } + } + else + { + if(holding) + { + int det = s_csr % FRAME_PER_SELECT; + holding = FALSE; + csr_v = (det < FRAME_PER_SELECT/2) ? (det == 0 ? 0 : -1) : 1; + } + } + } + + // ^b`pbhɂXN[̒ + if( BAR_ZERO_X + (ITEM_SIZE + ITEM_INTERVAL) * (LAUNCHER_TITLE_LIST_NUM - 1) < bar_left ) + bar_left = BAR_ZERO_X + (ITEM_SIZE + ITEM_INTERVAL) * (LAUNCHER_TITLE_LIST_NUM - 1); + if( bar_left < BAR_ZERO_X ) bar_left = BAR_ZERO_X; + if((LAUNCHER_TITLE_LIST_NUM-1)*FRAME_PER_SELECT < s_csr) s_csr = (LAUNCHER_TITLE_LIST_NUM-1)*FRAME_PER_SELECT; + if( s_csr < 0 ) s_csr = 0; +} + +static void DrawScrollBar( TitleProperty *pTitleList ) +{ + int l; + static int col_count = 0; + static int col_count_d = 1; + static const int COL_FLAME_MAX = 30; + static const int COL_NUM = 15; + static const int COL_DIV = (COL_FLAME_MAX / COL_NUM); + int colc_cold; + static int oldx; + + col_count += col_count_d; + if(col_count < 0) + { + col_count = 0; + col_count_d = 1; + } + if(COL_FLAME_MAX <= col_count) + { + col_count = COL_FLAME_MAX - 1; + col_count_d = -1; + } + + colc_cold = col_count/COL_DIV; + + NNS_G2dCharCanvasClearArea( &gCanvas, TXT_COLOR_NULL, oldx, BAR_ZERO_Y, 12, 13 ); + for(l=0; l +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// define data------------------------------------------------------- +#define SYSMENU_VER 0x071115 + +// global variables-------------------------------------------------- + +// function---------------------------------------------------------- +void LauncherInit( TitleProperty *pTitleList ); + +BOOL LauncherFadeout( TitleProperty *pTitleList ); +TitleProperty *LauncherMain( TitleProperty *pTitleList ); + + +#ifdef __cplusplus +} +#endif + +#endif // __LAUNCHER_H__ diff --git a/build/systemMenu_RED/Launcher/ARM9/src/main.c b/build/systemMenu_RED/Launcher/ARM9/src/main.c new file mode 100644 index 00000000..cfd3ac98 --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/src/main.c @@ -0,0 +1,310 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "launcher.h" +#include "misc.h" +#include "logoDemo.h" +#include "sound.h" + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +static void INTR_VBlank( void ); +static void deleteTmp(); + +// global variable------------------------------------------------------------- + +// static variable------------------------------------------------------------- +static TitleProperty s_titleList[ LAUNCHER_TITLE_LIST_NUM ]; + +static u64 strmThreadStack[THREAD_STACK_SIZE / sizeof(u64)]; +static OSThread strmThread; + +static StreamInfo strm; // stream info + +// const data------------------------------------------------------------------ + +const char filename[] = "data/fanfare.32.wav"; + +//#define DEBUG_LAUNCHER_DUMP +#ifdef DEBUG_LAUNCHER_DUMP +// foOpBSD0x02ffc0000x02ffe000܂dump.datƂ_vf +static void debugWriteToSD( void ) +{ + FSFile dest; + FS_InitFile( &dest ); + (void)FS_CreateFile("sdmc:/dump.dat", FS_PERMIT_W | FS_PERMIT_R); + if ( !FS_OpenFileEx( &dest, "sdmc:/dump.dat", FS_FILEMODE_W ) ) return; + FS_WriteFile( &dest, (void *)0x02ffc000, 0x2000 ); + if ( !FS_CloseFile( &dest ) ) return; + OS_TPrintf( "debugWriteToSD:ok\n"); +} +#endif + +// C +void TwlMain( void ) +{ + enum { + LOGODEMO_INIT = 0, + LOGODEMO = 1, + LAUNCHER_INIT = 2, + LAUNCHER = 3, + LOAD_START = 4, + LOADING = 5, + AUTHENTICATE = 6, + BOOT = 7, + STOP = 8 + }; + u32 state = LOGODEMO_INIT; + TitleProperty *pBootTitle = NULL; + OSTick start, end = 0; + BOOL direct_boot = FALSE; + +#ifdef DEBUG_LAUNCHER_DUMP + // you should comment out to clear GX/G2/DMA/TM/PAD register in reboot.c to retreive valid boot time + STD_TSPrintf((char*)0x02FFCFD0, "\nLauncher Boot Time: %lld usec\n", OS_TicksToMicroSeconds(OS_GetTick())); + STD_TSPrintf((char*)0x02FFCFF0, "HOTSTART(0x%08x): %02x\n", HW_NAND_FIRM_HOTSTART_FLAG, *(u8 *)HW_NAND_FIRM_HOTSTART_FLAG); +#endif + // VXej[---------- + SYSM_Init( Alloc, Free ); // OS_Init̑OŃR[KvB + OS_Init(); + SYSM_SetArena(); // OS_IniťŃR[KvB + + // OS------------------------ + OS_InitTick(); + PM_Init(); + + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + FS_Init( FS_DMA_NOT_USE ); + +#ifdef DEBUG_LAUNCHER_DUMP + // debug + debugWriteToSD(); +#endif + + GX_Init(); + PM_Init(); + TP_Init(); + RTC_Init(); + SND_Init();// sound init + + OS_TPrintf( "SYSM_work size = 0x%x\n", sizeof(SYSM_work) ); + + // 荞݋-------------------- + (void)OS_SetIrqFunction(OS_IE_V_BLANK, INTR_VBlank); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + + // VXȅ---------------- + InitAllocator(); // SYSM_InitȊOSYSMCu֐ĂԑO + // Alloc, Freeœo^AP[^ĂB + // ep[^̎擾------------ + pBootTitle = SYSM_ReadParameters(); // {̐ݒf[^AZbgp[^A + // NV[PXA + // pI[gNJ[hAʎYCpL[V[gJbgN蓙̃[h + + (void)SYSM_GetCardTitleList( s_titleList ); // J[hAvXg̎擾iJ[hAvs_titleList[0]Ɋi[j + + // bootTypeLAUNCHER_BOOTTYPE_TEMPłȂꍇAtmptH_̃f[^ + if( !pBootTitle || pBootTitle->flags.bootType != LAUNCHER_BOOTTYPE_TEMP ) + { + deleteTmp(); + } + + // u_CNgu[głȂvȂ + if( !pBootTitle ) { + // Avԃp^NA + // TODO:炩NTRJ[h̃ZLÄޔɒ0x2000000烍[hĂꍇe͂Ȃ̂Œ + MI_CpuClearFast((void *)HW_PARAM_DELIVER_ARG, HW_PARAM_DELIVER_ARG_SIZE); + + // NAND & J[hAvXg擾 + (void)SYSM_GetNandTitleList( s_titleList, LAUNCHER_TITLE_LIST_NUM ); // NANDAvXg̎擾iAvs_titleList[1]i[j + } + + // u_CNgu[głȂv + // u_CNgu[gASf\v̎Ae탊\[X̃[h------------ + if( !pBootTitle || + ( pBootTitle && !SYSM_IsLogoDemoSkip() ) ) { +// FS_ReadContentFile( ContentID ); // ^Cg\[Xt@C̃[h +// FS_ReadSharedContentFile( ContentID ); // LRegt@C̃[h + } + + // JnXe[g̔-------------- + + if( pBootTitle ) { + // _CNgu[gȂASA`[΂ă[hJn + if( pBootTitle->flags.isLogoSkip ) { + state = LOAD_START; + }else { + state = LOGODEMO_INIT; + } + direct_boot = TRUE; + }else if( SYSM_IsLogoDemoSkip() ) { + // SfXLbvw肳ĂA`[N + state = LAUNCHER_INIT; + }else { + // ȂȂASfN + state = LOGODEMO_INIT; + } + + // `lbN + SND_LockChannel((1 << L_CHANNEL) | (1 << R_CHANNEL), 0); + + /* Xg[Xbh̋N */ + OS_CreateThread(&strmThread, + StrmThread, + NULL, + strmThreadStack + THREAD_STACK_SIZE / sizeof(u64), + THREAD_STACK_SIZE, STREAM_THREAD_PRIO); + OS_WakeupThreadDirect(&strmThread); + + // C[v-------------------- + while( 1 ) { + OS_WaitIrq(1, OS_IE_V_BLANK); // VuN荞ݑ҂ + + // `qlVR}hM + while (SND_RecvCommandReply(SND_COMMAND_NOBLOCK) != NULL) + { + } + + ReadKeyPad(); // L[͂̎擾 + ReadTP(); // TP͂̎擾 + + switch( state ) { + case LOGODEMO_INIT: + LogoInit(); + // ‚炷eXg + FS_InitFile(&strm.file); + strm.isPlay = FALSE; + PlayStream(&strm, filename); + + state = LOGODEMO; + break; + case LOGODEMO: + if( LogoMain() ) { + if( !direct_boot ) { + state = LAUNCHER_INIT; + }else { + state = LOAD_START; + } + } + break; + case LAUNCHER_INIT: + LauncherInit( s_titleList ); + state = LAUNCHER; + break; + case LAUNCHER: + pBootTitle = LauncherMain( s_titleList ); + if( pBootTitle ) { + state = LOAD_START; + } + break; + case LOAD_START: + SYSM_StartLoadTitle( pBootTitle ); + state = LOADING; + + start = OS_GetTick(); + + break; + case LOADING: + if( ( direct_boot || ( !direct_boot && LauncherFadeout( s_titleList ) ) ) && + SYSM_IsLoadTitleFinished( pBootTitle ) ) { + state = AUTHENTICATE; + } + + if( ( end == 0 ) && + SYSM_IsLoadTitleFinished( pBootTitle ) ) { + end = OS_GetTick(); + OS_TPrintf( "Load Time : %dms\n", OS_TicksToMilliSeconds( end - start ) ); + } + break; + case AUTHENTICATE: + switch ( SYSM_AuthenticateTitle( pBootTitle ) ) { // AvF؁u[g Fnever return + case AUTH_RESULT_TITLE_LOAD_FAILED: + case AUTH_RESULT_TITLE_POINTER_ERROR: + case AUTH_RESULT_AUTHENTICATE_FAILED: + case AUTH_RESULT_ENTRY_ADDRESS_ERROR: + state = STOP; + break; + } + break; + case STOP: // ~ + break; + } + + // J[hAvXg̎擾iXbhŐJ[h}ʒm̂C[vŎ擾j + (void)SYSM_GetCardTitleList( s_titleList ); + + // R}htbV + (void)SND_FlushCommand(SND_COMMAND_NOBLOCK); + } +} + + +// ============================================================================ +// 荞ݏ +// ============================================================================ + +// VuN荞 +static void INTR_VBlank(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // VuN`FbÑZbg +} + +// ============================================================================ +// fBNg +// ============================================================================ + +// nandtmpfBNg̒g +static void deleteTmp() +{ + FSFile dir; + FSDirectoryEntryInfo info; + FS_InitFile(&dir); + if(!FS_OpenDirectory(&dir, "nand:/tmp", FS_FILEMODE_R | FS_FILEMODE_W)) + { + OS_TPrintf( "ERROR deleteTmp: open nand:/tmp failed!\n" ); + return; + } + while(FS_ReadDirectory(&dir, &info)) + { + if(info.attributes & FS_ATTRIBUTE_IS_DIRECTORY) + { + //fBNĝ͍Ƃ폜Ȃ + }else + { + //t@Ĉ͍Ƃsrl̂ݍ폜 + char buf[512]; + u32 end = info.longname_length; + if( (info.longname[end-1]=='l' || info.longname[end-1]=='L') && + (info.longname[end-2]=='r' || info.longname[end-2]=='R') && + (info.longname[end-3]=='s' || info.longname[end-3]=='S') && + (info.longname[end-4]=='.') ) + { + STD_TSNPrintf( buf, 512, "nand:/tmp/%s",info.longname); + FS_DeleteFile( buf ); + OS_TPrintf( "deleteTmp: deleted File '%s' \n", buf ); + } + } + } + FS_CloseDirectory(&dir); +} diff --git a/build/systemMenu_RED/Launcher/ARM9/src/sound.c b/build/systemMenu_RED/Launcher/ARM9/src/sound.c new file mode 100644 index 00000000..9b2c3519 --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/src/sound.c @@ -0,0 +1,349 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: sound.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:: 2007-10-25#$ + $Rev: 1800 $ + $Author: ida $ + *---------------------------------------------------------------------------*/ + +#include "sound.h" + +static BOOL ReadWaveFormat(StreamInfo * strm); +static void ReadStrmData(StreamInfo * strm); +static void SoundAlarmHandler(void *arg); +static void VBlankIntr(void); + +static u16 Cont; +static u16 Trg; +static OSMessageQueue msgQ; +static OSMessage msgBuf[1]; + +static u8 strm_lbuf[STRM_BUF_SIZE] ATTRIBUTE_ALIGN(32); +static u8 strm_rbuf[STRM_BUF_SIZE] ATTRIBUTE_ALIGN(32); +static u8 strm_tmp[STRM_BUF_PAGESIZE * 2] ATTRIBUTE_ALIGN(32); + +/*---------------------------------------------------------------------------* + Name: PlayStream + + Description: Xg[ĐĐ + + Arguments: strm - Xg[IuWFNg + filename - Xg[Đt@C + + Returns: None. + *---------------------------------------------------------------------------*/ +void PlayStream(StreamInfo * strm, const char *filename) +{ + int timerValue; + u32 alarmPeriod; + + // ĐłΒ~ + if (strm->isPlay) + { + u32 tag; + StopStream(strm); + tag = SND_GetCurrentCommandTag(); + (void)SND_FlushCommand(SND_COMMAND_NOBLOCK | SND_COMMAND_IMMEDIATE); + SND_WaitForCommandProc(tag); // ~҂ + } + + // t@C + if (FS_IsFile(&strm->file)) + (void)FS_CloseFile(&strm->file); + if ( ! FS_OpenFile(&strm->file, filename) ) { + OS_Panic("Error: failed to open file %s\n", filename); + } + if (!ReadWaveFormat(strm)) + { + OS_Panic("Error: failed to read wavefile\n"); + } + + strm->isPlay = TRUE; + + /* p[^ݒ */ + timerValue = SND_TIMER_CLOCK / strm->format.sampleRate; + alarmPeriod = timerValue * STRM_BUF_PAGESIZE / 32U; + alarmPeriod /= (strm->format.bitPerSample == 16) ? sizeof(s16) : sizeof(s8); + + // Xg[f[^ǂݍ + (void)FS_SeekFile(&strm->file, (s32)strm->beginPos, FS_SEEK_SET); + strm->bufPage = 0; + ReadStrmData(strm); + ReadStrmData(strm); + + // `lƃA[ZbgAbv + SND_SetupChannelPcm(L_CHANNEL, + (strm->format.bitPerSample == + 16) ? SND_WAVE_FORMAT_PCM16 : SND_WAVE_FORMAT_PCM8, strm_lbuf, + SND_CHANNEL_LOOP_REPEAT, 0, STRM_BUF_SIZE / sizeof(u32), 127, + SND_CHANNEL_DATASHIFT_NONE, timerValue, 0); + SND_SetupChannelPcm(R_CHANNEL, + (strm->format.bitPerSample == + 16) ? SND_WAVE_FORMAT_PCM16 : SND_WAVE_FORMAT_PCM8, + (strm->format.channels == 1) ? strm_lbuf : strm_rbuf, + SND_CHANNEL_LOOP_REPEAT, 0, STRM_BUF_SIZE / sizeof(u32), 127, + SND_CHANNEL_DATASHIFT_NONE, timerValue, 127); + SND_SetupAlarm(ALARM_NUM, alarmPeriod, alarmPeriod, SoundAlarmHandler, strm); + SND_StartTimer((1 << L_CHANNEL) | (1 << R_CHANNEL), 0, 1 << ALARM_NUM, 0); +} + +/*---------------------------------------------------------------------------* + Name: StopStream + + Description: Xg[Đ~ + + Arguments: strm - Xg[IuWFNg + + Returns: None. + *---------------------------------------------------------------------------*/ +void StopStream(StreamInfo * strm) +{ + SND_StopTimer((1 << L_CHANNEL) | (1 << R_CHANNEL), 0, 1 << ALARM_NUM, 0); + if (FS_IsFile(&strm->file)) + (void)FS_CloseFile(&strm->file); + strm->isPlay = FALSE; +} + +/*---------------------------------------------------------------------------* + Name: StrmThread + + Description: Xg[Xbh + + Arguments: arg - [U[f[^igpj + + Returns: None. + *---------------------------------------------------------------------------*/ +void StrmThread(void * /*arg */ ) +{ + OSMessage message; + + OS_InitMessageQueue(&msgQ, msgBuf, 1); + + while (1) + { + (void)OS_ReceiveMessage(&msgQ, &message, OS_MESSAGE_BLOCK); + (void)ReadStrmData((StreamInfo *) message); + } +} + +/*---------------------------------------------------------------------------* + Name: SoundAlarmHandler + + Description: A[R[obN֐ + + Arguments: arg - Xg[IuWFNg + + Returns: None. + *---------------------------------------------------------------------------*/ +static void SoundAlarmHandler(void *arg) +{ + (void)OS_SendMessage(&msgQ, (OSMessage)arg, OS_MESSAGE_NOBLOCK); +} + +/*---------------------------------------------------------------------------* + Name: ReadStrmData + + Description: Xg[f[^ǂݍ݊֐ + t@Cobt@̂Py[W̃Xg[f[^ǂݍ + + Arguments: strm - Xg[IuWFNg + + Returns: None. + *---------------------------------------------------------------------------*/ +static void ReadStrmData(StreamInfo * strm) +{ + int i; + s32 readSize; + u8 *lbuf, *rbuf; + + // Xg[I[ɒBĂ + if (strm->dataSize <= 0) + { + StopStream(strm); + return; + } + + // obt@̃y[Wݒ + if (strm->bufPage == 0) + { + lbuf = strm_lbuf; + rbuf = strm_rbuf; + strm->bufPage = 1; + } + else + { + lbuf = strm_lbuf + STRM_BUF_PAGESIZE; + rbuf = strm_rbuf + STRM_BUF_PAGESIZE; + strm->bufPage = 0; + } + + // f[^ǂݍ + if (strm->format.channels == 1) + { + // m + readSize = FS_ReadFile(&strm->file, + strm_tmp, + (strm->dataSize < + STRM_BUF_PAGESIZE) ? strm->dataSize : STRM_BUF_PAGESIZE); + if (readSize == -1) + OS_Panic("read file end\n"); + + if (strm->format.bitPerSample == 16) + { + // 16bitf[^ + for (i = 0; i < readSize / sizeof(s16); i++) + { + ((s16 *)lbuf)[i] = ((s16 *)strm_tmp)[i]; + } + for (; i < STRM_BUF_PAGESIZE / sizeof(s16); i++) + { + ((s16 *)lbuf)[i] = 0; // Xg[̏I[ɒBꍇAcOŖ߂ + } + } + else + { + // 8bitf[^ + for (i = 0; i < readSize / sizeof(s8); i++) + { + ((s8 *)lbuf)[i] = (s8)((s16)strm_tmp[i] - 128); + } + for (; i < STRM_BUF_PAGESIZE / sizeof(s8); i++) + { + ((s8 *)lbuf)[i] = 0; + } + } + } + else + { + // XeI + readSize = FS_ReadFile(&strm->file, + strm_tmp, + (strm->dataSize < + STRM_BUF_PAGESIZE * 2) ? strm->dataSize : STRM_BUF_PAGESIZE * 2); + if (readSize == -1) + OS_Panic("read file end\n"); + + if (strm->format.bitPerSample == 16) + { + // 16bitf[^ + for (i = 0; i < (readSize / 2) / sizeof(s16); i++) + { + ((s16 *)lbuf)[i] = ((s16 *)strm_tmp)[2 * i]; + ((s16 *)rbuf)[i] = ((s16 *)strm_tmp)[2 * i + 1]; + } + for (; i < STRM_BUF_PAGESIZE / sizeof(s16); i++) + { + ((s16 *)lbuf)[i] = 0; + ((s16 *)rbuf)[i] = 0; + } + } + else + { + // 8bitf[^ + for (i = 0; i < (readSize / 2) / sizeof(s8); i++) + { + ((s8 *)lbuf)[i] = (s8)((s16)strm_tmp[2 * i] - 128); + ((s8 *)rbuf)[i] = (s8)((s16)strm_tmp[2 * i + 1] - 128); + } + for (; i < STRM_BUF_PAGESIZE / sizeof(s8); i++) + { + ((s8 *)lbuf)[i] = 0; + ((s8 *)rbuf)[i] = 0; + } + } + } + + strm->dataSize -= readSize; + + return; +} + + +/*---------------------------------------------------------------------------* + Name: ReadWaveFormat + + Description: WAVEtH[}bg̃f[^̃wb_ƃf[^̐擪ʒuAf[^TCY擾 + + Arguments: strm - Xg[IuWFNg + + Returns: ǂݎɐTRUEAsFALSE + *---------------------------------------------------------------------------*/ +static BOOL ReadWaveFormat(StreamInfo * strm) +{ + u32 tag; + s32 size; + BOOL fFmt = FALSE, fData = FALSE; + + (void)FS_SeekFileToBegin(&strm->file); + + (void)FS_ReadFile(&strm->file, &tag, 4); + if (tag != FOURCC_RIFF) + return FALSE; + + (void)FS_ReadFile(&strm->file, &size, 4); + + (void)FS_ReadFile(&strm->file, &tag, 4); + if (tag != FOURCC_WAVE) + return FALSE; + + while (size > 0) + { + s32 chunkSize; + if (FS_ReadFile(&strm->file, &tag, 4) == -1) + { + return FALSE; + } + if (FS_ReadFile(&strm->file, &chunkSize, 4) == -1) + { + return FALSE; + } + + switch (tag) + { + case FOURCC_fmt: + if (FS_ReadFile(&strm->file, (u8 *)&strm->format, chunkSize) == -1) + { + return FALSE; + } + fFmt = TRUE; + break; + case FOURCC_data: + strm->beginPos = FS_GetPosition(&strm->file); + strm->dataSize = chunkSize; + (void)FS_SeekFile(&strm->file, chunkSize, FS_SEEK_CUR); + fData = TRUE; + break; + default: + (void)FS_SeekFile(&strm->file, chunkSize, FS_SEEK_CUR); + break; + } + if (fFmt && fData) + { + return TRUE; // fmt data ǂݏI狭I + } + + size -= chunkSize; + } + + if (size != 0) + return FALSE; + return TRUE; +} + +//-------------------------------------------------------------------------------- +// uuN荞ݏ +// +static void VBlankIntr(void) +{ + // 荞݃`FbNtO + OS_SetIrqCheckFlag(OS_IE_V_BLANK); +} diff --git a/build/systemMenu_RED/Launcher/ARM9/src/sound.h b/build/systemMenu_RED/Launcher/ARM9/src/sound.h new file mode 100644 index 00000000..a84f662b --- /dev/null +++ b/build/systemMenu_RED/Launcher/ARM9/src/sound.h @@ -0,0 +1,81 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: sound.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-11-20#$ + $Rev: 231 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#ifndef __LAUNCHER_SOUND_H__ +#define __LAUNCHER_SOUND_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// define data------------------------------------------------------- + +#define MAKE_FOURCC(cc1, cc2, cc3, cc4) (u32)((cc1) | (cc2 << 8) | (cc3 << 16) | (cc4 << 24)) + +#define FOURCC_RIFF MAKE_FOURCC('R', 'I', 'F', 'F') +#define FOURCC_WAVE MAKE_FOURCC('W', 'A', 'V', 'E') +#define FOURCC_fmt MAKE_FOURCC('f', 'm', 't', ' ') +#define FOURCC_data MAKE_FOURCC('d', 'a', 't', 'a') + +#define L_CHANNEL 4 +#define R_CHANNEL 5 +#define ALARM_NUM 0 +#define STREAM_THREAD_PRIO 12 +#define THREAD_STACK_SIZE 1024 +#define STRM_BUF_PAGESIZE 1024*32 +#define STRM_BUF_SIZE STRM_BUF_PAGESIZE*2 + +// WAVtH[}bgwb_ +typedef struct WaveFormat +{ + u16 format; + u16 channels; + s32 sampleRate; + u32 dataRate; + u16 blockAlign; + u16 bitPerSample; +} +WaveFormat; + +// Xg[IuWFNg +typedef struct StreamInfo +{ + FSFile file; + WaveFormat format; + u32 beginPos; + s32 dataSize; + u32 bufPage; + BOOL isPlay; +} +StreamInfo; + +// global variables-------------------------------------------------- + +// function---------------------------------------------------------- + +void PlayStream(StreamInfo * strm, const char *filename); +void StopStream(StreamInfo * strm); +void StrmThread(void *arg); + + +#ifdef __cplusplus +} +#endif + +#endif // __LAUNCHER_H__ diff --git a/build/systemMenu_RED/Launcher/Makefile b/build/systemMenu_RED/Launcher/Makefile new file mode 100644 index 00000000..9cf34e12 --- /dev/null +++ b/build/systemMenu_RED/Launcher/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/Launcher/banner/Makefile b/build/systemMenu_RED/Launcher/banner/Makefile new file mode 100644 index 00000000..ea261271 --- /dev/null +++ b/build/systemMenu_RED/Launcher/banner/Makefile @@ -0,0 +1,49 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/systemMenu_RED/Launcher/banner/banner_v3.bsf b/build/systemMenu_RED/Launcher/banner/banner_v3.bsf new file mode 100644 index 00000000..975188c4 Binary files /dev/null and b/build/systemMenu_RED/Launcher/banner/banner_v3.bsf differ diff --git a/build/systemMenu_RED/Launcher/banner/icon/gameIcon.bmp b/build/systemMenu_RED/Launcher/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..da2dda86 Binary files /dev/null and b/build/systemMenu_RED/Launcher/banner/icon/gameIcon.bmp differ diff --git a/build/systemMenu_RED/MachineSettings/ARM9/Makefile b/build/systemMenu_RED/MachineSettings/ARM9/Makefile new file mode 100644 index 00000000..e9e20a0f --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/ARM9/Makefile @@ -0,0 +1,69 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - SystemMenuRED - MachineSettings +# 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-11-30#$ +# $Rev: 2778 $ +# $Author: terui $ +#---------------------------------------------------------------------------- + +SUBDIRS = \ +# ../../../libraries_sysmenu/sysmenu \ +# ../../../libraries_sysmenu/settings + +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +TITLEID_LO = MSET +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +TARGET_BIN = main.srl + +ROM_SPEC = main.rsf + +MISC_DIR = ../../misc + +BG_DIR = ../../data + +SRCS = main.c MachineSetting.c \ + setRTC.c selectLanguage.c calibrationTP.c setOwnerInfo.c selectCountry.c \ + CountryNameMappingData.c \ + $(MISC_DIR)/src/misc.c $(MISC_DIR)/src/cmn.c \ + $(BG_DIR)/BGData_MachineSettings.c + +LINCLUDES = $(MISC_DIR)/include + +MAKEROM_FLAGS += -DTITLEID_LO='$(TITLEID_LO)' +MAKETAD_FLAGS += -s + +#LLIBRARIES += libreset_param$(TWL_LIBSUFFIX).a + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/MachineSettings/ARM9/main.rsf b/build/systemMenu_RED/MachineSettings/ARM9/main.rsf new file mode 100644 index 00000000..659fd928 --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/ARM9/main.rsf @@ -0,0 +1,179 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType System + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + SaveBannerFile FALSE +} + + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot ../../data + Root /data + File NTR_IPL_font_m.NFTR +} diff --git a/build/systemMenu_RED/MachineSettings/ARM9/src/CountryNameMappingData.c b/build/systemMenu_RED/MachineSettings/ARM9/src/CountryNameMappingData.c new file mode 100644 index 00000000..b3472b75 --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/ARM9/src/CountryNameMappingData.c @@ -0,0 +1,302 @@ +#include "misc.h" + +const u16 *const s_pStrCountryName[] = { + (const u16 *)L"UNDEFINED", + (const u16 *)L"JAPAN", // { + + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + + // USA[W + (const u16 *)L"Anguilla", // AM + (const u16 *)L"ANTIGUA_AND_BARBUDA", // AeBOAEo[u[_ + (const u16 *)L"ARGENTINA", // A[` + (const u16 *)L"ARUBA", // Ao + (const u16 *)L"BAHAMAS", // on} + (const u16 *)L"BARBADOS", // oohX + (const u16 *)L"BELIZE", // x[Y + (const u16 *)L"BOLIVIA", // {rA + (const u16 *)L"BRAZIL", // uW + (const u16 *)L"BRITISH_VIRGIN_ISLANDS", // p̃@[W + (const u16 *)L"CANADA", // Ji_ + (const u16 *)L"CAYMAN_ISLANDS", // PC} + (const u16 *)L"CHILE", // ` + (const u16 *)L"COLOMBIA", // RrA + (const u16 *)L"COSTA_RICA", // RX^J + (const u16 *)L"DOMINICA", // h~jJ + (const u16 *)L"DOMINICAN_REPUBLIC", // h~jJa + (const u16 *)L"ECUADOR", // GNAh + (const u16 *)L"EL_SALVADOR", // GToh + (const u16 *)L"FRENCH_GUIANA", // tX̃MAi + (const u16 *)L"GRENADA", // Oi_ + (const u16 *)L"GUADELOUPE", // OAh[v + (const u16 *)L"GUATEMALA", // OAe} + (const u16 *)L"GUYANA", // KCAi + (const u16 *)L"HAITI", // nC` + (const u16 *)L"HONDURAS", // zWX + (const u16 *)L"JAMAICA", // W}CJ + (const u16 *)L"MARTINIQUE", // }eBj[N + (const u16 *)L"MEXICO", // LVR + (const u16 *)L"MONTSERRAT", // gZg + (const u16 *)L"NETHERLANDS_ANTILLES", // I_̃AeB + (const u16 *)L"NICARAGUA", // jJOA + (const u16 *)L"PANAMA", // pi} + (const u16 *)L"PARAGUAY", // pOAC + (const u16 *)L"PERU", // y[ + (const u16 *)L"ST_KITTS_AND_NEVIS", // ZgLbcElCrX + (const u16 *)L"ST_LUCIA", // ZgVA + (const u16 *)L"ST_VINCENT()GRENADINES", // ZgrZgEOifB[ + (const u16 *)L"SURINAME", // Xi + (const u16 *)L"TRINIDAD_AND_TOBAGO", // gj_[hEgoS + (const u16 *)L"TURKS_AND_CAICOS_ISLANDS", // ^[NXEJCRX + (const u16 *)L"UNITED_STATES", // AJ + (const u16 *)L"URUGUAY", // EOAC + (const u16 *)L"US_VIRGIN_ISLANDS", // ė̃o[W + (const u16 *)L"VENEZUELA", // xlYG + + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + + // EUR", NAL [W + (const u16 *)L"ALBANIA", // AojA + (const u16 *)L"AUSTRALIA", // I[XgA + (const u16 *)L"AUSTRIA", // I[XgA + (const u16 *)L"BELGIUM", // xM[ + (const u16 *)L"BOSNIA_AND_HERZEGOVINA", // {XjAEwcFSri + (const u16 *)L"BOTSWANA", // {ci + (const u16 *)L"BULGARIA", // uKA + (const u16 *)L"CROATIA", // NA`A + (const u16 *)L"CYPRUS", // LvX + (const u16 *)L"CZECH_REPUBLIC", // `FR + (const u16 *)L"DENMARK", // f}[N + (const u16 *)L"ESTONIA", // GXgjA + (const u16 *)L"FINLAND", // tBh + (const u16 *)L"FRANCE", // tX + (const u16 *)L"GERMANY", // hCc + (const u16 *)L"GREECE", // MV + (const u16 *)L"HUNGARY", // nK[ + (const u16 *)L"ICELAND", // ACXh + (const u16 *)L"IRELAND", // ACh + (const u16 *)L"ITALY", // C^A + (const u16 *)L"LATVIA", // grA + (const u16 *)L"LESOTHO", // \g + (const u16 *)L"LIECHTENSTEIN", // qeV^C + (const u16 *)L"LITHUANIA", // gAjA + (const u16 *)L"LUXEMBOURG", // NZuN + (const u16 *)L"MACEDONIA", // }PhjA + (const u16 *)L"MALTA", // }^ + (const u16 *)L"MONTENEGRO", // elO + (const u16 *)L"MOZAMBIQUE", // Ur[N + (const u16 *)L"NAMIBIA", // i~rA + (const u16 *)L"NETHERLANDS", // I_ + (const u16 *)L"NEW_ZEALAND", // j[W[h + (const u16 *)L"NORWAY", // mEF[ + (const u16 *)L"POLAND", // |[h + (const u16 *)L"PORTUGAL", // |gK + (const u16 *)L"ROMANIA", // [}jA + (const u16 *)L"RUSSIA", // VA + (const u16 *)L"SERBIA", // ZrA + (const u16 *)L"SLOVAKIA", // XoLA + (const u16 *)L"SLOVENIA", // XxjA + (const u16 *)L"SOUTH_AFRICA", // AtJ + (const u16 *)L"SPAIN", // XyC + (const u16 *)L"SWAZILAND", // XWh + (const u16 *)L"SWEDEN", // XEF[f + (const u16 *)L"SWITZERLAND", // XCX + (const u16 *)L"TURKEY", // gR + (const u16 *)L"UNITED_KINGDOM", // CMX + (const u16 *)L"ZAMBIA", // UrA + (const u16 *)L"ZIMBABWE", // WouG + + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + + // TWN[W + (const u16 *)L"TAIWAN", // p + + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + + // KOR[W + (const u16 *)L"SOUTH_KOREA", // ؍ + + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + + // HKG[WiWii̍Xgɑ݁j + (const u16 *)L"HONG_KONG", // zR + (const u16 *)L"MACAU", // }JI + + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + + // ASI[WiWii̍Xgɑ݁j + (const u16 *)L"INDONESIA", // ChlVA + + // USA[W + (const u16 *)L"SINGAPORE", // VK|[ + + // ASI[WiĂсj + (const u16 *)L"THAILAND", // ^C + (const u16 *)L"PHILIPPINES", // tBs + (const u16 *)L"MALAYSIA", // }[VA + + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + + // `[WiIQue[WHj + (const u16 *)L"CHINA", // + + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + + // USA[W + (const u16 *)L"UAE", // Au񒷍AM + + // `[W + (const u16 *)L"INDIA", // Ch + (const u16 *)L"EGYPT", // GWvg + (const u16 *)L"OMAN", // I}[ + (const u16 *)L"QATAR", // J^[ + (const u16 *)L"KUWAIT", // NEF[g + (const u16 *)L"SAUDI_ARABIA", // TEWArA + (const u16 *)L"SYRIA", // VA + (const u16 *)L"BAHRAIN", // o[[ + (const u16 *)L"JORDAN", // _ + + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY",//180 + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY",//190 + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY",//200 + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY",//210 + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY",//220 + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY",//230 + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY",//240 + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY",//250 + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + (const u16 *)L"DUMMY", + + (const u16 *)L"OTHERS", + (const u16 *)L"UNKNOWN" +}; + +const u32 region_country_mapping[LCFG_TWL_REGION_MAX] = +{ + LCFG_TWL_COUNTRY_MAPPING_JAPAN, + LCFG_TWL_COUNTRY_MAPPING_AMERICA, + LCFG_TWL_COUNTRY_MAPPING_EUROPE, + LCFG_TWL_COUNTRY_MAPPING_AUSTRALIA, + LCFG_TWL_COUNTRY_MAPPING_CHINA, + LCFG_TWL_COUNTRY_MAPPING_KOREA +}; \ No newline at end of file diff --git a/build/systemMenu_RED/MachineSettings/ARM9/src/MachineSetting.c b/build/systemMenu_RED/MachineSettings/ARM9/src/MachineSetting.c new file mode 100644 index 00000000..108d912a --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/ARM9/src/MachineSetting.c @@ -0,0 +1,327 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: mainMenu.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" +#include "MachineSetting.h" + +// define data------------------------------------------ + // LZ{^LCD̈ +#define CANCEL_BUTTON_TOP_X ( 12 * 8 ) +#define CANCEL_BUTTON_TOP_Y ( 21 * 8 ) +#define CANCEL_BUTTON_BOTTOM_X ( CANCEL_BUTTON_TOP_X + 5 * 8 ) +#define CANCEL_BUTTON_BOTTOM_Y ( CANCEL_BUTTON_TOP_Y + 2 * 8 ) + // OK{^LCD̈ +#define OK_BUTTON_TOP_X ( 22 * 8 ) +#define OK_BUTTON_TOP_Y ( 21 * 8 ) +#define OK_BUTTON_BOTTOM_X ( OK_BUTTON_TOP_X + 2 * 8 ) +#define OK_BUTTON_BOTTOM_Y ( OK_BUTTON_TOP_Y + 2 * 8 ) + + +#define SETTING_MENU_ELEMENT_NUM 5 // Cj[̍ڐisNg`bgNeXg͏Ăj + +// extern data------------------------------------------ + +extern u32 bg_char_data[8 * 6]; +extern u16 bg_scr_data[32 * 32]; + +// function's prototype declaration--------------------- +static BOOL InitialSetting( void ); +static void InitialSettingFinalizeInit( void ); +static int InitialSettingFinalizeMain( void ); + +// global variable ------------------------------------- +BOOL g_initialSet = FALSE; + +// static variable ------------------------------------- +static u16 s_csr = 0; +static const u16 *s_pStrSetting[ SETTING_MENU_ELEMENT_NUM ]; // Cj[pe[uւ̃|C^Xg + +// const data ----------------------------------------- + + +//=============================================== +// mainMenu.c +//=============================================== +static const u16 *const s_pStrSettingElemTbl[ SETTING_MENU_ELEMENT_NUM ][ LCFG_TWL_LANG_CODE_MAX ] = { + { + (const u16 *)L"", + (const u16 *)L"LANGUAGE", + (const u16 *)L"LANGUAGE(F)", + (const u16 *)L"LANGUAGE(G)", + (const u16 *)L"LANGUAGE(I)", + (const u16 *)L"LANGUAGE(S)", + (const u16 *)L"LANGUAGE(C)", + (const u16 *)L"LANGUAGE(K)", + }, + { + (const u16 *)L"t & ", + (const u16 *)L"DATE & TIME", + (const u16 *)L"DATE & TIME(F)", + (const u16 *)L"DATE & TIME(G)", + (const u16 *)L"DATE & TIME(I)", + (const u16 *)L"DATE & TIME(S)", + (const u16 *)L"DATE & TIME(C)", + (const u16 *)L"DATE & TIME(K)", + }, + { + (const u16 *)L"[U[", + (const u16 *)L"USER INFORMATION", + (const u16 *)L"USER INFORMATION(F)", + (const u16 *)L"USER INFORMATION(G)", + (const u16 *)L"USER INFORMATION(I)", + (const u16 *)L"USER INFORMATION(S)", + (const u16 *)L"USER INFORMATION(C)", + (const u16 *)L"USER INFORMATION(K)", + }, + { + (const u16 *)L"^b`pl␳", + (const u16 *)L"TOUCH PANEL", + (const u16 *)L"TOUCH PANEL(F)", + (const u16 *)L"TOUCH PANEL(G)", + (const u16 *)L"TOUCH PANEL(I)", + (const u16 *)L"TOUCH PANEL(S)", + (const u16 *)L"TOUCH PANEL(C)", + (const u16 *)L"TOUCH PANEL(K)", + }, + { + (const u16 *)L"ݒ", + (const u16 *)L"COUNTRY", + (const u16 *)L"COUNTRY(F)", + (const u16 *)L"COUNTRY(G)", + (const u16 *)L"COUNTRY(I)", + (const u16 *)L"COUNTRY(S)", + (const u16 *)L"COUNTRY(C)", + (const u16 *)L"COUNTRY(K)", + }, +#if 0 + { + (const u16 *)L"sNg`bgNeXg", + (const u16 *)L"PICTOCHAT", + (const u16 *)L"PICTOCHAT(F)", + (const u16 *)L"PICTOCHAT(G)", + (const u16 *)L"PICTOCHAT(I)", + (const u16 *)L"PICTOCHAT(S)", + (const u16 *)L"PICTOCHAT(C)", + (const u16 *)L"PICTOCHAT(K)", + }, +#endif +}; + +static MenuPos s_settingPos[] = { + { TRUE, 4 * 8, 6 * 8 }, + { TRUE, 4 * 8, 8 * 8 }, + { TRUE, 4 * 8, 10 * 8 }, + { TRUE, 4 * 8, 12 * 8 }, + { TRUE, 4 * 8, 14 * 8 }, + { TRUE, 4 * 8, 16 * 8 }, +}; + + +static const MenuParam s_settingParam = { + SETTING_MENU_ELEMENT_NUM, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_settingPos[ 0 ], + (const u16 **)&s_pStrSetting, +}; + +//====================================================== +// Cj[ +//====================================================== + +// Cj[̏ +void MachineSettingInit( void ) +{ + int i; + + // NV[PX + if( InitialSetting() ) { + return; + } + + GX_DispOff(); + GXS_DispOff(); + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + + // BGf[^̃[h + GX_LoadBG1Char(bg_char_data, 0, sizeof(bg_char_data)); + GX_LoadBG1Scr(bg_scr_data, 0, sizeof(bg_scr_data)); + + PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"MACHINE SETTINGS" ); + + // NITROݒf[^languageɉCj[\̐؂ւ + for( i = 0; i < SETTING_MENU_ELEMENT_NUM; i++ ) { + s_pStrSetting[ i ] = s_pStrSettingElemTbl[ i ][ LCFG_TSD_GetLanguage() ]; + } + + ChangeUserColor( LCFG_TSD_GetUserColor() ); + DrawMenu( s_csr, &s_settingParam ); + + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); + GX_DispOn(); + GXS_DispOn(); + + g_pNowProcess = MachineSettingMain; +} + +// Cj[ +int MachineSettingMain( void ) +{ + BOOL tp_select; + + LauncherBootFlags tempflag = {TRUE, LAUNCHER_BOOTTYPE_NAND, TRUE, FALSE, FALSE, FALSE, 0}; + + ReadTP(); + + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( pad.trg & PAD_KEY_DOWN ){ // J[\̈ړ + if( ++s_csr == SETTING_MENU_ELEMENT_NUM ) { + s_csr=0; + } + } + if( pad.trg & PAD_KEY_UP ){ + if( --s_csr & 0x80 ) { + s_csr=SETTING_MENU_ELEMENT_NUM - 1; + } + } + tp_select = SelectMenuByTP( &s_csr, &s_settingParam ); + DrawMenu( s_csr, &s_settingParam ); + + if( pad.trg & PAD_BUTTON_START ) { + OS_SetLauncherParamAndResetHardware( 0, NULL, &tempflag ); + } + + if( ( pad.trg & PAD_BUTTON_A ) || ( tp_select ) ) { // j[ڂւ̕ + if( s_settingPos[ s_csr ].enable ) { + switch( s_csr ) { + case 0: + SelectLanguageInit(); + g_pNowProcess = SelectLanguageMain; + break; + case 1: + SetRTCInit(); + g_pNowProcess = SetRTCMain; + break; + case 2: + SetOwnerInfoInit(); + g_pNowProcess = SetOwnerInfoMain; + break; + case 3: + TP_CalibrationInit(); + g_pNowProcess = TP_CalibrationMain; + break; + case 4: + SelectCountryInit(); + g_pNowProcess = SelectCountryMain; + break; + case 5: + //pictochatNeXg + OS_SetLauncherParamAndResetHardware( 0, 0x0003000550434854, &tempflag ); + } + } + } + + return 0; +} + + +// OK / CANCEL{^̕` +void DrawOKCancelButton(void) +{ + (void)PutStringUTF16( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, TXT_COLOR_CYAN, (const u16 *)L"CANCEL"); + (void)PutStringUTF16( OK_BUTTON_TOP_X, OK_BUTTON_TOP_Y, TXT_COLOR_CYAN, (const u16 *)L"OK"); +} + + +// OK or CANCEL{^`FbN +void CheckOKCancelButton(BOOL *tp_ok, BOOL *tp_cancel) +{ + *tp_cancel = WithinRangeTP( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, + CANCEL_BUTTON_BOTTOM_X, CANCEL_BUTTON_BOTTOM_Y, &tpd.disp ); + *tp_ok = WithinRangeTP( OK_BUTTON_TOP_X, OK_BUTTON_TOP_Y, + OK_BUTTON_BOTTOM_X, OK_BUTTON_BOTTOM_Y, &tpd.disp ); +} + + +//--------------------------------------------------------- +// +// ݒI +// +//--------------------------------------------------------- + +// NV[PX +static BOOL InitialSetting( void ) +{ +#if 0 + if( !TSD_GetFlagLanguage() ) { // ݒ肪܂B + g_initialSet = TRUE; + s_csr = 2; + SelectLangageInit(); + g_pNowProcess = SelectLanguageMain; + return TRUE; + }else if( !TSD_GetFlagTP() ) { // TPLu[V܂B + g_initialSet = TRUE; + s_csr = 3; + TP_CalibrationInit(); + g_pNowProcess = TP_CalibrationMain; + return TRUE; + }else if( !TSD_GetFlagDateTime() ) { // RTCݒ肪܂B + ClearRTC(); + g_initialSet = TRUE; + s_csr = 1; + SetRTCInit(); + g_pNowProcess = SetRTCMain; + return TRUE; + }else if( !TSD_GetFlagNickname() || // jbNl[܂͍DȐF͂܂B + !TSD_GetFlagUserColor() ) { +/* g_initialSet = TRUE; + s_csr = 0; + SetOwnerInfoInit(); + g_pNowProcess = SetOwnerInfoMain; + return TRUE; +*/ } + + if( g_initialSet ) { + InitialSettingFinalizeInit(); + g_pNowProcess = InitialSettingFinalizeMain(); + return TRUE; + } +#endif + return FALSE; +} + + +static void InitialSettingFinalizeInit( void ) +{ + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_WHITE ); + (void)PutStringUTF16( 6 * 8, 10 * 8, TXT_COLOR_BLACK, (const u16 *)L" Initial setting completed."); + (void)PutStringUTF16( 6 * 8, 12 * 8, TXT_COLOR_BLACK, (const u16 *)L" Please reboot."); +} + + +static int InitialSettingFinalizeMain( void ) +{ + return 0; +} + diff --git a/build/systemMenu_RED/MachineSettings/ARM9/src/MachineSetting.h b/build/systemMenu_RED/MachineSettings/ARM9/src/MachineSetting.h new file mode 100644 index 00000000..d9854c3a --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/ARM9/src/MachineSetting.h @@ -0,0 +1,82 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: MachineSetting.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 __MACHINE_SETTING_H__ +#define __MACHINE_SETTING_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + + +// define data---------------------------------------------------------- +#define TP_CSR_TOUCH_COUNT 2 // TPJ[\̃`^Oẑ߂̃JEgl +#define TP_CSR_DETACH_COUNT 2 // TPJ[\uIvƔ肷TPf^b`̃JEgl + +#define HANDLE_MENU 48 +#define HANDLE_RTC_VIEW 240 +#define HANDLE_OK_BUTTON 255 +#define HANDLE_CANCEL_BUTTON 256 + +// l̓C^[tF[Xp[Nivoid InputDecimal()Ŏgpj +typedef struct InputNumParam { + u16 pos_x; // ͒l̕\Xʒu + u16 pos_y; // V@@@@ Yʒu + int up_count; + int down_count; + int keta_max; // ő包 + int value_min; // ͒l̍ŏ + int value_max; // ͒l̍ő + int y_offset; // ^b`pl͂̊ʒuYItZbg +}InputNumParam; + +// global variable------------------------------------------------------ +extern NNSFndAllocator g_allocator; +extern BOOL g_initialSet; +extern int (*g_pNowProcess)( void ); +extern BOOL g_isValidTSD; + +// function------------------------------------------------------------- +extern void MachineSettingInit( void ); +extern int MachineSettingMain( void ); +extern void SetOwnerInfoInit( void ); +extern int SetOwnerInfoMain( void ); +extern void SetRTCInit( void ); +extern int SetRTCMain( void ); +extern void SelectLanguageInit( void ); +extern int SelectLanguageMain( void ); +extern void TP_CalibrationInit( void ); +extern int TP_CalibrationMain( void ); +extern void SelectRegionInit( void ); +extern int SelectRegionMain( void ); +extern void SelectCountryInit( void ); +extern int SelectCountryMain( void ); + +extern void DrawOKCancelButton( void ); +extern void CheckOKCancelButton(BOOL *tp_ok, BOOL *tp_cancel); +extern void InputDecimal(int *tgtp, InputNumParam *inpp); + +extern void ClearRTC( void ); + +#ifdef __cplusplus +} +#endif + +#endif // __MACHINE_SETTING_H__ diff --git a/build/systemMenu_RED/MachineSettings/ARM9/src/calibrationTP.c b/build/systemMenu_RED/MachineSettings/ARM9/src/calibrationTP.c new file mode 100644 index 00000000..97ba1d8b --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/ARM9/src/calibrationTP.c @@ -0,0 +1,533 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: calibrationTP.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" +#include "MachineSetting.h" + +// define data------------------------------------------ + // OK{^LCD̈ +#define OK_BUTTON_TOP_X ( 2 * 8 ) +#define OK_BUTTON_TOP_Y ( 20 * 8 ) +#define OK_BUTTON_BOTTOM_X ( OK_BUTTON_TOP_X + 8 * 8 ) +#define OK_BUTTON_BOTTOM_Y ( OK_BUTTON_TOP_Y + 4 * 8 ) + + // LZ{^LCD̈ +#define CANCEL_BUTTON_TOP_X ( 11 * 8 ) +#define CANCEL_BUTTON_TOP_Y ( 20 * 8 ) +#define CANCEL_BUTTON_BOTTOM_X ( CANCEL_BUTTON_TOP_X + 8 * 8 ) +#define CANCEL_BUTTON_BOTTOM_Y ( CANCEL_BUTTON_TOP_Y + 4 * 8 ) + + // gC{^LCD̈ +#define RETRY_BUTTON_TOP_X ( 20 * 8 ) +#define RETRY_BUTTON_TOP_Y ( 20 * 8 ) +#define RETRY_BUTTON_BOTTOM_X ( RETRY_BUTTON_TOP_X + 8 * 8 ) +#define RETRY_BUTTON_BOTTOM_Y ( RETRY_BUTTON_TOP_Y + 4 * 8 ) + + // Lu[VpOBJf[^ +const u16 bitmapOBJPoint[8 * 8 * 5]; + + // eLN^f[^TCY +#define IMAGE_DATA (bitmapOBJPoint) +#define IMAGE_DATA_SIZE (sizeof(bitmapOBJPoint)) +#define MY_CHAR_SIZE (sizeof(myChar)) + + // NITRO-LCDTCY +#define DISP_X_SIZE 256 +#define DISP_Y_SIZE 192 + +enum { + INIT=0, + INTERVAL_0, + CALIBRATE_1, + INTERVAL_1, + CALIBRATE_2, + INTERVAL_2, + CHECK_PARAM, + INTERVAL_3, + GET_POINT +}; + + // Lu[Vݒ胏[N +typedef struct CalibWork { + u32 seq; + u16 release_count; + u16 touch_count; + u16 last_x; + u16 last_y; + TPData sample[2]; + LCFGTWLTPCalibData calibTemp; +}CalibWork; + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- +static void DisplayInit(); +static BOOL GetSamplePointNow(TPData *data); +static BOOL WaitPanelReleaseNow( void ); +static void ReturnMenu(void); + +// global variable ------------------------------------- + +// static variable ------------------------------------- +static CalibWork *s_pTPC; +static GXOamAttr s_oamBak[ 128 ] ATTRIBUTE_ALIGN(32); // OAM obNAbv + +// const data ----------------------------------------- + +//====================================================== +// function's description +//====================================================== + +/*---------------------------------------------------------------------------* + Name: SetPoint8x8 + + Description: Display a 8x8 OBJ on indicated point. + + Arguments: x - position X. + y - position Y. + + Returns: None. + *---------------------------------------------------------------------------*/ +static inline void SetPoint8x8(u16 pos_x, u16 pos_y) +{ + G2_SetOBJAttr( &s_oamBak[0], // OAM number + pos_x - 4, // X position + pos_y - 4, // Y position + 0, // Priority + GX_OAM_MODE_BITMAPOBJ, // Bitmap mode + FALSE, // mosaic off + GX_OAM_EFFECT_NONE, // affine off + GX_OAM_SHAPE_8x8, // 8x8 size + GX_OAM_COLOR_16, // 16 color + 0x60, // charactor + 15, // alpha + 0); +} + + +/*---------------------------------------------------------------------------* + Name: SetPoint16x16 + + Description: Display a 16x16 OBJ on indicated point. + + Arguments: x - position X. + y - position Y. + + Returns: None. + *---------------------------------------------------------------------------*/ +static inline void SetPoint16x16(u16 pos_x, u16 pos_y) +{ + G2_SetOBJAttr( &s_oamBak[0], // OAM number + pos_x - 8, // X position + pos_y - 8, // Y position + 0, // Priority + GX_OAM_MODE_BITMAPOBJ, // Bitmap mode + FALSE, // mosaic off + GX_OAM_EFFECT_NONE, // affine off + GX_OAM_SHAPE_16x16, // 16x16 size + GX_OAM_COLOR_16, // 16 color + 0x61, // charactor + 15, // alpha + 0); +} + + +/*---------------------------------------------------------------------------* + Name: DisplayInit + + Description: Graphics Initialization + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void DisplayInit() +{ + MI_CpuClearFast( (void *)HW_OAM, 0x20 ); + MI_CpuClearFast( s_oamBak, sizeof(s_oamBak) ); + GX_SetOBJVRamModeBmp( GX_OBJVRAMMODE_BMP_1D_128K ); // 2D mapping OBJ + /* Load charactor bitmap data */ + GX_LoadOBJ( (const void *)IMAGE_DATA, 0x3000 /* 0 */, IMAGE_DATA_SIZE ); // Transfer OBJ bitmap data to VRAM +} + + +/*---------------------------------------------------------------------------* + Name: GetSamplePointNow + + Description: Get touched point by OneTime Sampling. + This function use TP_RequestSampling() and TP_WaitRawResult() + + Arguments: None. + + Returns: data - getton TouchPanel data. + BOOL - if touched and got point this function returns TRUE. + else FALSE. + *---------------------------------------------------------------------------*/ +static BOOL GetSamplePointNow(TPData *data) +{ + TPData temp; + + enum { + OK_COUNT = 4, OK_RANGE = 50 + }; + + // Detect a point pushed during definite time. + while (TP_RequestRawSampling( &temp )) { }; + + if (! temp.touch ) { + s_pTPC->touch_count = 0; + return FALSE; + } + + if ( temp.validity != TP_VALIDITY_VALID ) { + s_pTPC->touch_count = 0; + return FALSE; + } + + OS_Printf("( %d, %d )\n", temp.x, temp.y); + + s_pTPC->touch_count++; + if ( s_pTPC->touch_count == 1 ) { + s_pTPC->last_x = temp.x; + s_pTPC->last_y = temp.y; + return FALSE; + } + + // if jump point from last frame, reset count. + if ( (s32)(s_pTPC->last_x - temp.x) < - OK_RANGE || + (s32)(s_pTPC->last_x - temp.x) > OK_RANGE ) + { + s_pTPC->touch_count = 1; + s_pTPC->last_x = temp.x; + s_pTPC->last_y = temp.y; + return FALSE; + } + + if ( (s32)(s_pTPC->last_y - temp.y) < - OK_RANGE || + (s32)(s_pTPC->last_y - temp.y) > OK_RANGE ) + { + s_pTPC->touch_count = 1; + s_pTPC->last_x = temp.x; + s_pTPC->last_y = temp.y; + return FALSE; + } + + // if the point pressed during OK_COUNT, detect finish. + if ( s_pTPC->touch_count == OK_COUNT ) { + data->x = (u16) ( (temp.x + s_pTPC->last_x) / 2 ); + data->y = (u16) ( (temp.y + s_pTPC->last_y) / 2 ); + data->touch = TP_TOUCH_ON; + data->validity = TP_VALIDITY_VALID; + s_pTPC->touch_count=0; + return TRUE; + } + + s_pTPC->last_x = temp.x; + s_pTPC->last_y = temp.y; + return FALSE; +} + + +/*---------------------------------------------------------------------------* + Name: WaitPanelReleaseNow + + Description: Wait to released TouchPanel, using OneTime Sampling. + This function is using TP_RequestSampling() and TP_WaitRawResult(). + + Arguments: None. + + Returns: BOOL - if TouchPanel is released , this returns TRUE. + else FALSE. + + *---------------------------------------------------------------------------*/ +static BOOL WaitPanelReleaseNow( void ) +{ + TPData temp; + + enum { + INTERVAL_CNT = 10 + }; + + while (TP_RequestRawSampling( &temp )) { + SVC_WaitByLoop(0x400); + }; + + if ( temp.touch ) { + s_pTPC->release_count = 0; + return FALSE; + } + + s_pTPC->release_count++; + if ( s_pTPC->release_count >= INTERVAL_CNT ) { + s_pTPC->release_count = 0; + return TRUE; + } else { + return FALSE; + } +} + + +/*---------------------------------------------------------------------------* + Name: TP_Calibration + + Description: Initialization and main loop + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +int TP_CalibrationMain( void ) +{ + BOOL tp_ok = FALSE; + BOOL tp_cancel = FALSE; + BOOL tp_retry = FALSE; + + switch (s_pTPC->seq) { + case INIT: + NNS_G2dCharCanvasClearArea( &gCanvas, TXT_COLOR_NULL, + 0 * 8 , 20 * 8, 32 * 8, 4 * 8 ); + s_pTPC->seq = INTERVAL_0; + PutStringUTF16( 2 * 8, 21 * 8, TXT_COLOR_CYAN, (const u16 *)L"[B]:CANCEL" ); + break; + + case INTERVAL_0: + // wait release TouchPanel + if ( WaitPanelReleaseNow() ) { + s_pTPC->seq = CALIBRATE_1; + } + break; + + case CALIBRATE_1: + // detect first point. + SetPoint8x8( 32, 32 ); + if ( GetSamplePointNow( &s_pTPC->sample[ 0 ] ) ) { + OS_Printf( "OK! ( %d, %d )\n", s_pTPC->sample[0].x, s_pTPC->sample[0].y ); + s_pTPC->seq = INTERVAL_1; + } + break; + + case INTERVAL_1: + // wait release TouchPanel + if ( WaitPanelReleaseNow() ) { + s_pTPC->seq = CALIBRATE_2; + } + break; + + case CALIBRATE_2: + // detect second point. + SetPoint8x8( DISP_X_SIZE - 32, DISP_Y_SIZE - 32 ); + if ( GetSamplePointNow( &s_pTPC->sample[ 1 ] ) ) { + TPCalibrateParam calibrate; + + OS_Printf( "OK! ( %d, %d )\n", s_pTPC->sample[1].x, s_pTPC->sample[1].y ); + // Calculate and set calibration parameter from two detected point. + (void)TP_CalcCalibrateParam( + &calibrate, + s_pTPC->sample[0].x, s_pTPC->sample[0].y, 32, 32, + s_pTPC->sample[1].x, s_pTPC->sample[1].y, DISP_X_SIZE - 32, DISP_Y_SIZE - 32 ); + TP_SetCalibrateParam( &calibrate ); + + OS_Printf( "Calibrate param: \n" ); + OS_Printf( "\tx = %d, xDotSize = %d\n", calibrate.x0, calibrate.xDotSize / 0x100 ); + OS_Printf( "\ty = %d, yDotSize = %d\n", calibrate.y0, calibrate.yDotSize / 0x100 ); + OS_Printf( "Check calibrate param\n" ); + + s_pTPC->seq = INTERVAL_2; + } + break; + + case INTERVAL_2: + // Wait release TouchPanel + if ( WaitPanelReleaseNow() ) { + s_pTPC->seq = CHECK_PARAM; + } + break; + + case CHECK_PARAM: + // Verify Calibrattion Parameter. + SetPoint8x8( DISP_X_SIZE / 2, DISP_Y_SIZE / 2 ); + if ( GetSamplePointNow( &tpd.raw ) ) { + TP_GetUnCalibratedPoint( &tpd.disp.x, &tpd.disp.y, DISP_X_SIZE / 2, DISP_Y_SIZE / 2 ); + s_pTPC->seq = GET_POINT; + + NNS_G2dCharCanvasClearArea( &gCanvas, TXT_COLOR_NULL, + 2 * 8 , 21 * 8, 10 * 8, 2 * 8 ); + PutStringUTF16( OK_BUTTON_TOP_X, OK_BUTTON_TOP_Y, TXT_COLOR_CYAN, (const u16 *)L" OK "); + PutStringUTF16( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, TXT_COLOR_CYAN, (const u16 *)L" CANCEL "); + PutStringUTF16( RETRY_BUTTON_TOP_X, RETRY_BUTTON_TOP_Y, TXT_COLOR_CYAN, (const u16 *)L" RETRY "); + PutStringUTF16( OK_BUTTON_TOP_X + 2 * 8, OK_BUTTON_TOP_Y + 2 * 8, TXT_COLOR_CYAN, (const u16 *)L"[A]"); + PutStringUTF16( CANCEL_BUTTON_TOP_X + 2 * 8, CANCEL_BUTTON_TOP_Y + 2 * 8, TXT_COLOR_CYAN, (const u16 *)L"[B]"); + PutStringUTF16( RETRY_BUTTON_TOP_X, RETRY_BUTTON_TOP_Y + 2 * 8, TXT_COLOR_CYAN, (const u16 *)L"[START]"); + { + s32 xRange, yRange; + xRange = tpd.raw.x - tpd.disp.x; + yRange = tpd.raw.y - tpd.disp.y; + OS_TPrintf( "OK! ( %d, %d )\n", tpd.raw.x, tpd.raw.y ); + OS_TPrintf( "Raw ( %d, %d )\n", tpd.disp.x, tpd.disp.y ); + OS_TPrintf( "\txRange = %d, yRange = %d\n", xRange, yRange ); + } + } + break; + + case GET_POINT: + // Draw Marker by calibrated point. + while ( TP_RequestRawSampling( &tpd.raw ) ) { + SVC_WaitByLoop( 0x400 ); + } + TP_GetCalibratedPoint( &tpd.disp, &tpd.raw ); + + if ( tpd.raw.touch ) { + SetPoint16x16( tpd.disp.x, tpd.disp.y ); + + // [OK] [CANCEL] [RETRY]{^`FbN + tp_ok = WithinRangeTP( OK_BUTTON_TOP_X, OK_BUTTON_TOP_Y, + OK_BUTTON_BOTTOM_X, OK_BUTTON_BOTTOM_Y, &tpd.disp ); + tp_cancel = WithinRangeTP( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, + CANCEL_BUTTON_BOTTOM_X, CANCEL_BUTTON_BOTTOM_Y, &tpd.disp ); + tp_retry = WithinRangeTP( RETRY_BUTTON_TOP_X, RETRY_BUTTON_TOP_Y, + RETRY_BUTTON_BOTTOM_X, RETRY_BUTTON_BOTTOM_Y, &tpd.disp ); + + if( tpd.raw.validity==TP_VALIDITY_VALID ) { + OS_TPrintf( "( %3d, %3d ) -> ( %4d, %4d )\n", tpd.disp.x, tpd.disp.y, tpd.raw.x, tpd.raw.y ); + } + } + + if( ( pad.trg & PAD_BUTTON_A ) || tp_ok ) { + s_pTPC->calibTemp.data.raw_x1 = s_pTPC->sample[0].x; + s_pTPC->calibTemp.data.raw_y1 = s_pTPC->sample[0].y; + s_pTPC->calibTemp.data.dx1 = 32; + s_pTPC->calibTemp.data.dy1 = 32; + s_pTPC->calibTemp.data.raw_x2 = s_pTPC->sample[1].x; + s_pTPC->calibTemp.data.raw_y2 = s_pTPC->sample[1].y; + s_pTPC->calibTemp.data.dx2 = DISP_X_SIZE - 32; + s_pTPC->calibTemp.data.dy2 = DISP_Y_SIZE - 32; + + LCFG_TSD_SetTPCalibration( &s_pTPC->calibTemp ); + LCFG_TSD_SetFlagTP( TRUE ); // ^b`pl̓tO𗧂ĂB + // :::::::::::::::::::::::::::::::::::::::::::::: + // TWLݒf[^t@Cւ̏ + // :::::::::::::::::::::::::::::::::::::::::::::: + (void)LCFG_WriteTWLSettings(); + + ReturnMenu(); + return 0; + }else if( ( pad.trg & PAD_BUTTON_START ) || tp_retry ) { + s_pTPC->seq = INIT; + } + break; + } + + /* flush cache of OAM buffers to main memory */ + DC_FlushRange( s_oamBak, sizeof(s_oamBak) ); + GX_LoadOAM( s_oamBak, 0, sizeof(s_oamBak) ); + MI_DmaFill32( 3, s_oamBak, 192, sizeof(s_oamBak) ); // Clear OAM buffer + + // B{^LZ + if( ( pad.trg & PAD_BUTTON_B ) || tp_cancel ){ + // Lu[VݒȌԂɖ߂B + { + TPCalibrateParam calibrate; + LCFG_TSD_GetTPCalibration( &s_pTPC->calibTemp ); + (void)TP_CalcCalibrateParam( + &calibrate, + s_pTPC->calibTemp.data.raw_x1, s_pTPC->calibTemp.data.raw_y1, (u16)s_pTPC->calibTemp.data.dx1, (u16)s_pTPC->calibTemp.data.dy1, + s_pTPC->calibTemp.data.raw_x2, s_pTPC->calibTemp.data.raw_y2, (u16)s_pTPC->calibTemp.data.dx2, (u16)s_pTPC->calibTemp.data.dy2 ); + TP_SetCalibrateParam( &calibrate ); + } + ReturnMenu(); + return 0; + } + + return 0; +} + + +// j[ɖ߂ +static void ReturnMenu( void ) +{ + // Lu[Vpϐ̊J + Free( s_pTPC ); + s_pTPC = NULL; + OS_Printf("Free :CalibWork\n"); + MachineSettingInit(); +} + + +// Lu[Vݒ̏ +void TP_CalibrationInit( void ) +{ + GX_DispOff(); + GXS_DispOff(); + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + + PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"TOUCH PANEL CALIBRATION" ); + + if( g_initialSet ) { + PutStringUTF16( 8 * 8, 18 * 8, TXT_COLOR_RED, (const u16 *)L"Calibrate touch panel." ); + } + + DisplayInit(); + + s_pTPC = Alloc( sizeof(CalibWork) ); // Lu[Vpϐ̊m + if( s_pTPC == NULL ) { + OS_Panic("ARM9- Fail to allocate memory...\n"); + } + SVC_CpuClear( 0x0000, s_pTPC, sizeof(CalibWork), 16 ); + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1 | GX_PLANEMASK_OBJ ); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); + GX_DispOn(); + GXS_DispOn(); + + s_pTPC->seq = INIT; +} + + +// ^b`plݒ|Cg@Lf[^ +const u16 bitmapOBJPoint[8 * 8 * 5] = { + 0x0000, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0x0000, // 0 char + 0xFC00, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0xFC00, // 0 char + 0xFC00, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0xFC00, // 0 char + 0xFC00, 0xFC00, 0xFC00, 0x801F, 0x801F, 0xFC00, 0xFC00, 0xFC00, // 0 char + 0xFC00, 0xFC00, 0xFC00, 0x801F, 0x801F, 0xFC00, 0xFC00, 0xFC00, // 0 char + 0xFC00, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0xFC00, // 0 char + 0xFC00, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0xFC00, // 0 char + 0x0000, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0x0000, // 0 char + + 0x0000, 0x0000, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0x0000, 0x0000, // 1 char + 0x0000, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0x0000, // 1 char + 0xFC00, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0xFC00, // 1 char + 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, // 1 char + + 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, // 2 char + 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, // 2 char + 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, // 2 char + 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0x801F, 0x801F, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, // 2 char + + 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0x801F, 0x801F, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, // 3 char + 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, // 3 char + 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, // 3 char + 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, // 3 char + + 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, // 4 char + 0xFC00, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0xFC00, 0xFC00, // 4 char + 0x0000, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0x0000, // 4 char + 0x0000, 0x0000, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0xFC00, 0x0000, 0x0000, // 4 char +}; + diff --git a/build/systemMenu_RED/MachineSettings/ARM9/src/main.c b/build/systemMenu_RED/MachineSettings/ARM9/src/main.c new file mode 100644 index 00000000..55f7f3aa --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/ARM9/src/main.c @@ -0,0 +1,110 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" +#include "MachineSetting.h" + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +static void INTR_VBlank( void ); + +// global variable------------------------------------------------------------- +int (*g_pNowProcess)( void ); +BOOL g_isValidTSD; +RTCDrawProperty g_rtcDraw = { + TRUE, RTC_DATE_TOP_X, RTC_DATE_TOP_Y, RTC_TIME_TOP_X, RTC_TIME_TOP_Y +}; + +// static variable------------------------------------------------------------- + +// const data------------------------------------------------------------------ + + +// ============================================================================ +// function's description +// ============================================================================ +void TwlMain(void) +{ + + // ---------------------------------- + OS_Init(); + OS_InitTick(); + + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + GX_Init(); + GX_SetPower(GX_POWER_ALL); // eWbN p[ON + FS_Init( 3 ); + + // 荞݋---------------------------- + (void)OS_SetIrqFunction(OS_IE_V_BLANK, INTR_VBlank); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + + // foCX------------------------------- + TP_Init(); + (void)RTC_Init(); + + // VXȅ------------------ + InitAllocator(); + + // {Ȃ烉`[̃p[^`FbNsA + // NV[PXɓpX + + // TWLݒ̃[h + SYSM_SetAllocFunc( Alloc, Free ); // SYSM_ReadTWLSettingsFile()̎sɕKvB + + // :::::::::::::::::::::::::::::::::::::::::::::: + // TWLݒf[^t@C̓ǂݍ + // :::::::::::::::::::::::::::::::::::::::::::::: + (void)LCFG_ReadHWSecureInfo(); + g_isValidTSD = LCFG_ReadTWLSettings(); + if( g_isValidTSD ) { + SYSM_CaribrateTP(); + } + + InitBG(); + GetAndDrawRTCData( &g_rtcDraw, TRUE ); + MachineSettingInit(); + // C[v---------------------------- + while ( 1 ) { + OS_WaitIrq( 1, OS_IE_V_BLANK ); // VuN荞ݑ҂ + + ReadKeyPad(); // L[͂̎擾 + + (void)g_pNowProcess(); + + GetAndDrawRTCData( &g_rtcDraw, FALSE ); + } +} + + +// ============================================================================ +// 荞ݏ +// ============================================================================ + +// VuN荞 +static void INTR_VBlank(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // VuN`FbÑZbg +} + diff --git a/build/systemMenu_RED/MachineSettings/ARM9/src/selectCountry.c b/build/systemMenu_RED/MachineSettings/ARM9/src/selectCountry.c new file mode 100644 index 00000000..349fe159 --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/ARM9/src/selectCountry.c @@ -0,0 +1,338 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: SelectCountry.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:: 2007-11-19#$ + $Rev: 215 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" +#include "MachineSetting.h" + +// define data------------------------------------------ +#define CANCEL_BUTTON_TOP_X ( 2 * 8 ) +#define CANCEL_BUTTON_TOP_Y ( 21 * 8 ) +#define CANCEL_BUTTON_BOTTOM_X ( (CANCEL_BUTTON_TOP_X + 8 ) * 8 ) +#define CANCEL_BUTTON_BOTTOM_Y ( (CANCEL_BUTTON_TOP_Y + 2 ) * 8 ) + +#define MENU_DISPLAY_SIZE 7 + +// XN[o[֌W +#define BAR_ZERO_X 230 +#define BAR_ZERO_Y 48 +#define BAR_HEIGHT_MAX 107 +#define BAR_HEIGHT_MIN SQUARE_SIZE +#define BAR_WIDTH SQUARE_SIZE +#define BAR_BUTTON_HEIGHT SQUARE_SIZE +#define BAR_BUTTON_WIDTH SQUARE_SIZE +#define SQUARE_SIZE 11 +#define BAR_LOOSENESS 2 +#define BAR_OFFSET 2 // \""eLXggĂ̂ŁA^b`W␳ړIOFFSET + +// {^ł̃J[\ړ֌W +#define START_AUTOMOVE_COUNT 30 +#define AUTOMOVE_INTERVAL 5 + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- + +// global variable ------------------------------------- + +// static variable ------------------------------------- +static LCFGTWLCountryCode s_countryCode; // R[h +static LCFGTWLRegion s_regionCode; // [W + +static u16 s_list_start, s_list_end; +static u16 s_menu_display_start; + +static const u16 *s_pStrCountry[MENU_DISPLAY_SIZE]; + +static int s_list_size; +static int s_bar_height; +static double s_dots_per_item; + +// const data ----------------------------------------- +extern const u16 *const s_pStrCountryName[]; +extern const u32 region_country_mapping[LCFG_TWL_REGION_MAX]; + +static MenuPos s_countryPos[MENU_DISPLAY_SIZE] = { + { TRUE, 4 * 8, 6 * 8 }, + { TRUE, 4 * 8, 8 * 8 }, + { TRUE, 4 * 8, 10 * 8 }, + { TRUE, 4 * 8, 12 * 8 }, + { TRUE, 4 * 8, 14 * 8 }, + { TRUE, 4 * 8, 16 * 8 }, + { TRUE, 4 * 8, 18 * 8 }, +}; + +static MenuParam countrySel = { + MENU_DISPLAY_SIZE, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_countryPos[ 0 ], + (const u16 **)&s_pStrCountry, +}; + +//====================================================== +// function's description +//====================================================== + +// XN[j[̏ +static void InitScrollMenuList( void ) +{ + int l; + // j[ɕ\鍑XgŜ̍ŏƍŌ}bsOf[^擾 + s_list_start = (u16)(region_country_mapping[s_regionCode] >> 16); + s_list_end = (u16)(region_country_mapping[s_regionCode]); + if(s_list_start > s_list_end) OS_Panic("selectCountry.c:s_list_start>s_list_end!"); + + s_list_size = s_list_end - s_list_start + 1; + + // ʂɕ\ő區ڐAXgH + countrySel.num = (MENU_DISPLAY_SIZE < s_list_size) ? MENU_DISPLAY_SIZE : s_list_size ; + + // ݒ肳ĂR[hXg͈͂ɓĂȂ΃ftHglɂ + if(s_countryCode < s_list_start || s_list_end < s_countryCode) + { + s_countryCode = (LCFGTWLCountryCode)s_list_start; + } + + // ۂɕ\͈͂̒ + s_menu_display_start = s_countryCode; + if(s_countryCode + countrySel.num - 1 > s_list_end) + { + s_menu_display_start = (u16)(s_list_end + 1 - countrySel.num); + } + + // ۂɕ\鍑̂݃Xg + for(l=0; l= LCFG_TWL_COUNTRY_MAX ) ) { + s_countryCode = (LCFGTWLCountryCode)0; + }else { + s_countryCode = LCFG_TSD_GetCountry(); + } + + // XN[j[̏ + InitScrollMenuList(); + + DrawMenu( (u16)(s_countryCode - s_menu_display_start), &countrySel ); + + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); + GX_DispOn(); + GXS_DispOn(); +} + +// L[͂ɂJ[\ړ̏ +static void MoveCursorByKey( void ) +{ + BOOL pad_cont = FALSE; + static int pad_count = 0; + + if( pad.cont & PAD_KEY_DOWN ) { // J[\̈ړ + if(pad_count == 0 || (pad_count>=START_AUTOMOVE_COUNT && pad_count%AUTOMOVE_INTERVAL==0)) + if( s_countryCode < s_list_end ) s_countryCode++; + pad_cont = TRUE; + } + if( pad.cont & PAD_KEY_UP ) { + if(pad_count == 0 || (pad_count>=START_AUTOMOVE_COUNT && pad_count%AUTOMOVE_INTERVAL==0)) + if( s_countryCode > s_list_start ) s_countryCode--; + pad_cont = TRUE; + } + if( pad_cont ) pad_count++; + else pad_count = 0; + pad_cont = FALSE; + + // L[͌A\鍀ڂ̒ + if( s_countryCode < s_menu_display_start ) s_menu_display_start = s_countryCode; + else if( s_menu_display_start + countrySel.num - 1 < s_countryCode ) s_menu_display_start = (u16)(s_countryCode - countrySel.num + 1); +} + +// ȈՃXN[o[̃{^ɂXN[ +static void MoveCursorByScrollBarButton( void ) +{ + static int tpd_count = 0; + BOOL tpd_cont = FALSE; + + if(tpd.disp.touch) + { + if( WithinRangeTP(BAR_ZERO_X,BAR_ZERO_Y+BAR_HEIGHT_MAX+BAR_OFFSET,BAR_ZERO_X+BAR_BUTTON_WIDTH,BAR_ZERO_Y+BAR_HEIGHT_MAX+BAR_OFFSET+BAR_BUTTON_HEIGHT,&tpd.disp) ) {//down + if(tpd_count == 0 || (tpd_count>=START_AUTOMOVE_COUNT && tpd_count%AUTOMOVE_INTERVAL==0)) + if( s_countryCode < s_list_end ) s_menu_display_start++; + tpd_cont = TRUE; + } + if( WithinRangeTP(BAR_ZERO_X,BAR_ZERO_Y-BAR_BUTTON_HEIGHT+BAR_OFFSET,BAR_ZERO_X+BAR_BUTTON_WIDTH,BAR_ZERO_Y+BAR_OFFSET,&tpd.disp) ) {//up + if(tpd_count == 0 || (tpd_count>=START_AUTOMOVE_COUNT && tpd_count%AUTOMOVE_INTERVAL==0)) + if( s_countryCode > s_list_start ) s_menu_display_start--; + tpd_cont = TRUE; + } + } + if( tpd_cont ) tpd_count++; + else tpd_count = 0; + tpd_cont = FALSE; +} + +// ȈՃXN[o[ɂXN[ +static void MoveCursorByScrollBar( void ) +{ + // ȈՃXN[o[̃{^ɂXN[ + MoveCursorByScrollBarButton(); + + // ȈՃXN[o[ɂXN[ + { + static BOOL holding = FALSE; + static int dy; + int bar_top = (int)(BAR_ZERO_Y+s_dots_per_item * (s_menu_display_start - s_list_start)); + if(tpd.disp.touch) + { + if(holding) + { + if ( tpd.disp.y - dy < bar_top - BAR_LOOSENESS) + { + bar_top = tpd.disp.y - dy + BAR_LOOSENESS; + } + else if ( tpd.disp.y - dy > bar_top + BAR_LOOSENESS) + { + bar_top = tpd.disp.y - dy - BAR_LOOSENESS; + } + s_menu_display_start = (u16)(((bar_top - BAR_ZERO_Y)/s_dots_per_item) + s_list_start); + } + else if(WithinRangeTP(BAR_ZERO_X, bar_top+BAR_OFFSET,BAR_ZERO_X + BAR_WIDTH,bar_top+BAR_OFFSET+s_bar_height,&tpd.disp)) + { + holding = TRUE; + dy = tpd.disp.y - bar_top; + } + } + else + { + holding = FALSE; + } + } + + // ^b`pbhɂXN[A\鍀ڂ̒ + if( s_menu_display_start + countrySel.num - 1 > s_list_end ) s_menu_display_start = (u16)(s_list_end - countrySel.num + 1); + if( s_menu_display_start < s_list_start ) s_menu_display_start = s_list_start; + if( s_countryCode < s_menu_display_start ) s_countryCode = (LCFGTWLCountryCode)s_menu_display_start; + else if( s_menu_display_start + countrySel.num - 1 < s_countryCode ) s_countryCode = (LCFGTWLCountryCode)(s_menu_display_start + countrySel.num - 1); +} + +// Iʂ̕`揈 +static void DrawCountryMain( void ) +{ + int l; + // ۂɕ\鍑̂݃Xg + for(l=0; l +#include "misc.h" +#include "MachineSetting.h" + +// define data------------------------------------------ +#define CANCEL_BUTTON_TOP_X ( 2 * 8 ) +#define CANCEL_BUTTON_TOP_Y ( 21 * 8 ) +#define CANCEL_BUTTON_BOTTOM_X ( (CANCEL_BUTTON_TOP_X + 8 ) * 8 ) +#define CANCEL_BUTTON_BOTTOM_Y ( (CANCEL_BUTTON_TOP_Y + 2 ) * 8 ) + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- + +// global variable ------------------------------------- + +// static variable ------------------------------------- +static int s_lang; // ỈԖڂIĂ邩 +static LCFGTWLRegion s_regionCode; // [WR[h + +static const u16* s_pStrLanguage[LCFG_TWL_LANG_CODE_MAX]; +static LCFGTWLLangCode s_langCodeList[LCFG_TWL_LANG_CODE_MAX]; + +// const data ----------------------------------------- +static const u16 region_lang_Mapping[LCFG_TWL_REGION_MAX] = +{ + LCFG_TWL_LANG_BITMAP_JAPAN, + LCFG_TWL_LANG_BITMAP_AMERICA, + LCFG_TWL_LANG_BITMAP_EUROPE, + LCFG_TWL_LANG_BITMAP_AUSTRALIA, + LCFG_TWL_LANG_BITMAP_CHINA, + LCFG_TWL_LANG_BITMAP_KOREA +}; + +static const u16 *const s_pStrLanguageData[LCFG_TWL_LANG_CODE_MAX] = { + (const u16 *)L"{", + (const u16 *)L"English ", + (const u16 *)L"Francais", + (const u16 *)L"Deutsch ", + (const u16 *)L"Italiano", + (const u16 *)L"Espanol ", + (const u16 *)L"ij", + (const u16 *)L"؍ij" +}; + +static MenuPos s_languagePos[LCFG_TWL_LANG_CODE_MAX] = { + { TRUE, 4 * 8, 6 * 8 }, + { TRUE, 4 * 8, 8 * 8 }, + { TRUE, 4 * 8, 10 * 8 }, + { TRUE, 4 * 8, 12 * 8 }, + { TRUE, 4 * 8, 14 * 8 }, + { TRUE, 4 * 8, 16 * 8 }, + { TRUE, 4 * 8, 18 * 8 }, + { TRUE, 4 * 8, 20 * 8 } +}; + +static MenuParam langSel = { + LCFG_TWL_LANG_CODE_MAX, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_languagePos[ 0 ], + (const u16 **)&s_pStrLanguage, +}; + + +//====================================================== +// function's description +//====================================================== + +// ݒ̏ +void SelectLanguageInit( void ) +{ + int l; + u16 temp_langCode = 0; + BOOL in_list_flag = FALSE; + int lang_count = 0; + + GX_DispOff(); + GXS_DispOff(); + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + + PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"LANGUAGE SELECT" ); + PutStringUTF16( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, TXT_COLOR_CYAN, (const u16 *)L"CANCEL" ); + if( g_initialSet ) { + PutStringUTF16( 8 * 8, 18 * 8, TXT_COLOR_RED, (const u16 *)L"Select language." ); + } + + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // 炩TWLݒf[^t@Cǂݍݍς݂̐ݒ擾 + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // [W̎擾 + s_regionCode = (LCFGTWLRegion)LCFG_THW_GetRegion(); + + // ̎擾 + if( !g_isValidTSD || + ( LCFG_TSD_GetLanguage() >= LCFG_TWL_LANG_CODE_MAX ) ) { + temp_langCode = LCFG_TWL_LANG_ENGLISH; + }else { + temp_langCode = LCFG_TSD_GetLanguage(); + } + + // [W-}bsO񂩂Ã݂[WőIł錾XgAbv + s_lang = 0; + for(l=0; l +#include "misc.h" +#include "MachineSetting.h" + +// define data------------------------------------------ +#define CANCEL_BUTTON_TOP_X ( 2 * 8 ) +#define CANCEL_BUTTON_TOP_Y ( 21 * 8 ) +#define CANCEL_BUTTON_BOTTOM_X ( (CANCEL_BUTTON_TOP_X + 8 ) * 8 ) +#define CANCEL_BUTTON_BOTTOM_Y ( (CANCEL_BUTTON_TOP_Y + 2 ) * 8 ) + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- + +// global variable ------------------------------------- + +// static variable ------------------------------------- +static TWLRegion s_regionCode; // [W + +// const data ----------------------------------------- +static const u16 *const s_pStrRegion[] = { + (const u16 *)L"NCL", + (const u16 *)L"NOA", + (const u16 *)L"NOE", + (const u16 *)L"NAL ", + (const u16 *)L"IQue", + (const u16 *)L"NOK ", +}; + +static MenuPos s_regionPos[] = { + { TRUE, 4 * 8, 6 * 8 }, + { TRUE, 4 * 8, 8 * 8 }, + { TRUE, 4 * 8, 10 * 8 }, + { TRUE, 4 * 8, 12 * 8 }, + { TRUE, 4 * 8, 14 * 8 }, + { TRUE, 4 * 8, 16 * 8 }, +}; + +static const MenuParam regionSel = { + 6, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_regionPos[ 0 ], + (const u16 **)&s_pStrRegion, +}; + +TWLLangCode default_lang_list[TWL_REGION_MAX] = +{ + TWL_LANG_JAPANESE, + TWL_LANG_ENGLISH, + TWL_LANG_ENGLISH, + TWL_LANG_ENGLISH, + TWL_LANG_SIMP_CHINESE, + TWL_LANG_KOREAN +}; + +TWLCountryCode default_country_list[TWL_REGION_MAX] = +{ + TWL_COUNTRY_JAPAN, + TWL_COUNTRY_Anguilla, + TWL_COUNTRY_ALBANIA, + TWL_COUNTRY_ALBANIA, + TWL_COUNTRY_CHINA, + TWL_COUNTRY_SOUTH_KOREA +}; + +//====================================================== +// function's description +//====================================================== + +// [Wݒ̏ +void SelectRegionInit( void ) +{ + GX_DispOff(); + GXS_DispOff(); + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + + PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"REGION SELECT" ); + PutStringUTF16( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, TXT_COLOR_CYAN, (const u16 *)L"CANCEL" ); + if( g_initialSet ) { + PutStringUTF16( 8 * 8, 18 * 8, TXT_COLOR_RED, (const u16 *)L"Select region." ); + } + + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // 炩TWLݒf[^t@Cǂݍݍς݂̐ݒ擾 + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // [W̎擾 + s_regionCode = (TWLRegion)THW_GetRegion(); + + DrawMenu( (u16)s_regionCode, ®ionSel ); + + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); + GX_DispOn(); + GXS_DispOn(); +} + + +// [WI +int SelectRegionMain( void ) +{ + BOOL tp_select,tp_cancel = FALSE; + + ReadTP(); // TP͂̎擾 + + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( pad.trg & PAD_KEY_DOWN ) { // J[\̈ړ + if( ++s_regionCode == TWL_REGION_MAX ) { + s_regionCode = (TWLRegion)0; + } + } + if( pad.trg & PAD_KEY_UP ) { + if( --s_regionCode < 0 ) { + s_regionCode = (TWLRegion)( TWL_REGION_MAX - 1 ); + } + } + tp_select = SelectMenuByTP( (u16 *)&s_regionCode, ®ionSel ); + DrawMenu( (u16)s_regionCode, ®ionSel ); + + // [CANCEL]{^`FbN + if( tpd.disp.touch ) { + tp_cancel = WithinRangeTP( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, + CANCEL_BUTTON_BOTTOM_X, CANCEL_BUTTON_BOTTOM_Y, &tpd.disp ); + } + + if( ( pad.trg & PAD_BUTTON_A ) || tp_select ) { // j[ڂւ̕ + // :::::::::::::::::::::::::::::::::::::::::::::: + // HWZLAt@Cւ̏݁iÍȂj + // :::::::::::::::::::::::::::::::::::::::::::::: + THW_SetRegion( s_regionCode ); + (void)THW_WriteSecureInfo( NULL ); + + // :::::::::::::::::::::::::::::::::::::::::::::: + // TWLݒf[^t@Cւ̏ + // :::::::::::::::::::::::::::::::::::::::::::::: + TSD_SetLanguage( default_lang_list[s_regionCode] ); // ftHgɋݒ + TSD_SetCountry( default_country_list[s_regionCode] ); // ftHgɋݒ + TSD_SetFlagLanguage( TRUE ); // Language̓tO𗧂Ă + //TSD_SetFlagCountry( TRUE ); // Country̓tO𗧂Ă + (void)SYSM_WriteTWLSettingsFile(); + + MachineSettingInit(); + return 0; + }else if( ( pad.trg & PAD_BUTTON_B ) || tp_cancel ) { + MachineSettingInit(); + return 0; + } + + return 0; +} + + diff --git a/build/systemMenu_RED/MachineSettings/ARM9/src/setOwnerInfo.c b/build/systemMenu_RED/MachineSettings/ARM9/src/setOwnerInfo.c new file mode 100644 index 00000000..66a5eb47 --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/ARM9/src/setOwnerInfo.c @@ -0,0 +1,1065 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: ownerInfo.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" +#include "MachineSetting.h" + +// define data---------------------------------- + +// \tgEFAL[{[hLCD̈ +#define CLIST_LT_X 23 +#define CLIST_LT_Y 50 + +#define CLIST_MARGIN 14 +#define CLIST_KEY_PER_SEGMENT 5 +#define CLIST_SEGMENT_INTERVAL 7 + +// LZ{^̈ +#define CANCEL_BUTTON_TOP_X ( 2 * 8 ) +#define CANCEL_BUTTON_TOP_Y ( 21 * 8 ) +#define CANCEL_BUTTON_BOTTOM_X ( CANCEL_BUTTON_TOP_X + (8 * 8) ) +#define CANCEL_BUTTON_BOTTOM_Y ( CANCEL_BUTTON_TOP_Y + (2 * 8) ) + +// OK{^̈ +#define OK_BUTTON_TOP_X ( 26 * 8 ) +#define OK_BUTTON_TOP_Y ( 21 * 8 ) +#define OK_BUTTON_BOTTOM_X ( OK_BUTTON_TOP_X + (4 * 8) ) +#define OK_BUTTON_BOTTOM_Y ( OK_BUTTON_TOP_Y + (2 * 8) ) + +#define USER_INFO_MENU_ELEMENT_NUM 4 // [U񃁃j[̍ڐ + +#define CHAR_LIST_CHAR_NUM 120 +#define CHAR_LIST_MODE_NUM 3 + +// L[R[h +#define EOM_ (u16)0xe050 +#define CODE_BUTTON_TOP_ (u16)0xe051 +#define DEL_BUTTON_ (u16)0xe051 +#define SPACE_BUTTON_ (u16)0xe052 +#define VAR_BUTTON1_ (u16)0xe053 +#define VAR_BUTTON2_ (u16)0xe054 +#define OK_BUTTON_ (u16)0xe055 +#define CANCEL_BUTTON_ (u16)0xe056 +#define CODE_BUTTON_BOTTOM_ (u16)0xe057 + +#define CHAR_USCORE L'Q' +#define KEY_PER_LINE 11 + +#define KEY_START 109 //\tgEFAL[̃J[\ftHgʒu̓LZL[ + +#define KEY_OK 0xffff +#define KEY_CANCEL 0xfffe + +typedef enum NameOrComment +{ + NOC_NAME, + NOC_COMMENT +}NameOrComment; + +// extern data---------------------------------- + +extern u32 bg_char_data[8 * 6]; +extern u16 bg_scr_data[32 * 32]; +extern u16 bg_birth_scr_data[32 * 32]; + +// function's prototype------------------------- +static void SetNicknameInit( void ); +static int SetNicknameMain( void ); +static void SetBirthdayInit( void ); +static int SetBirthdayMain( void ); +static void SetUserColorInit( void ); +static int SetUserColorMain( void ); +static void SetCommentInit( void ); +static int SetCommentMain( void ); +static u8 MY_StrLen( const u16 *pStr ); + +// static variable------------------------------ +// ꎞIɂgȂstaticɂĂ̂ +// ł_CGbgWorkɂAllocFree܂傤 +static u16 s_csr = 0; +static const u16 *s_pStrSetting[ USER_INFO_MENU_ELEMENT_NUM ]; // Cj[pe[uւ̃|C^Xg +static int s_char_mode = 0; +static u16 s_key_csr = 0; +static u8 s_color_csr = 0; +static BOOL s_birth_csr = FALSE; +static LCFGTWLDate s_temp_birthday; +static u16 s_temp_name[ LCFG_TWL_NICKNAME_LENGTH + 1 ]; +static u16 s_temp_comment[ LCFG_TWL_COMMENT_LENGTH + 1 ]; +static u8 s_temp_name_length; +static u8 s_temp_comment_length; + +// const data----------------------------------- +static const u16 char_tbl[CHAR_LIST_MODE_NUM][CHAR_LIST_CHAR_NUM]; + +static const u16 *const s_pStrSettingElemTbl[ USER_INFO_MENU_ELEMENT_NUM ][ LCFG_TWL_LANG_CODE_MAX ] = { + { + (const u16 *)L"[U[l[", + (const u16 *)L"NICKNAME", + (const u16 *)L"NICKNAME(F)", + (const u16 *)L"NICKNAME(G)", + (const u16 *)L"NICKNAME(I)", + (const u16 *)L"NICKNAME(S)", + }, + { + (const u16 *)L"a", + (const u16 *)L"BIRTHDAY", + (const u16 *)L"BIRTHDAY(F)", + (const u16 *)L"BIRTHDAY(G)", + (const u16 *)L"BIRTHDAY(I)", + (const u16 *)L"BIRTHDAY(S)", + }, + { + (const u16 *)L"[U[J[", + (const u16 *)L"USER COLOR", + (const u16 *)L"USER COLOR(F)", + (const u16 *)L"USER COLOR(G)", + (const u16 *)L"USER COLOR(I)", + (const u16 *)L"USER COLOR(S)", + }, + { + (const u16 *)L"Rg", + (const u16 *)L"COMMENT", + (const u16 *)L"COMMENT(F)", + (const u16 *)L"COMMENT(G)", + (const u16 *)L"COMMENT(I)", + (const u16 *)L"COMMENT(S)", + }, +}; + +static MenuPos s_settingPos[] = { + { TRUE, 4 * 8, 8 * 8 }, + { TRUE, 4 * 8, 10 * 8 }, + { TRUE, 4 * 8, 12 * 8 }, + { TRUE, 4 * 8, 14 * 8 }, +}; + + +static const MenuParam s_settingParam = { + USER_INFO_MENU_ELEMENT_NUM, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_settingPos[ 0 ], + (const u16 **)&s_pStrSetting, +}; + +static const u16 *str_button_char[CHAR_LIST_MODE_NUM] = { + L"", + L"Ji", + L"p", + }; + +static u16 next_char_mode[CHAR_LIST_MODE_NUM-1]; + +static const u16 str_button_del[] = L"ADEL"; +static const u16 str_button_space[] = L"SPACE"; +static const u16 str_button_ok[] = L"OK"; +static const u16 str_button_cancel[] = L"CANCEL"; + +static const u16 *str_button[] = { + (const u16 *)str_button_del, + (const u16 *)str_button_space, + NULL, + NULL, + (const u16 *)str_button_ok, + (const u16 *)str_button_cancel, + }; + +//====================================================== +// I[i[ҏW +//====================================================== + +static void SetSoftKeyboardButton(int mode) +{ + int l; + int count = 0; + for(l=0; lmonth, LCFG_TSD_GetBirthdayPtr()->day); + // J[ + color = LCFG_TSD_GetUserColor(); + PutStringUTF16( 128 , 12*8, TXT_UCOLOR_G0, L"" ); + // Rg + SVC_CpuCopy( LCFG_TSD_GetCommentPtr(), tempbuf, 13 * 2, 16 ); + *(tempbuf+13)='\n'; + SVC_CpuCopy( LCFG_TSD_GetCommentPtr()+13, tempbuf+14, 13 * 2, 16 ); + *(tempbuf+LCFG_TWL_COMMENT_LENGTH+1)=0; + PutStringUTF16( 128-78 , 16*8 , TXT_UCOLOR_G0, tempbuf ); +} + +// I[i[ҏW̏ +void SetOwnerInfoInit( void ) +{ + int i; + + // NITROݒf[^languageɉCj[\̐؂ւ + for( i = 0; i < USER_INFO_MENU_ELEMENT_NUM; i++ ) { + s_pStrSetting[ i ] = s_pStrSettingElemTbl[ i ][ LCFG_TSD_GetLanguage() ]; + } + + // BGf[^̃[h + GX_LoadBG1Char(bg_char_data, 0, sizeof(bg_char_data)); + GX_LoadBG1Scr(bg_scr_data, 0, sizeof(bg_scr_data)); + + DrawOwnerInfoMenuScene(); + + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); +} + +// I[i[ҏWj[ +int SetOwnerInfoMain( void ) +{ + static u16 dummy = 0; + SelectSomethingFunc func[1]={SelectCancelFunc}; + BOOL tp_select,tp_cancel = FALSE; + + ReadTP(); + + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( pad.trg & PAD_KEY_DOWN ){ // J[\̈ړ + if( ++s_csr == USER_INFO_MENU_ELEMENT_NUM ) { + s_csr=0; + } + } + if( pad.trg & PAD_KEY_UP ){ + if( --s_csr & 0x80 ) { + s_csr=USER_INFO_MENU_ELEMENT_NUM - 1; + } + } + tp_select = SelectMenuByTP( &s_csr, &s_settingParam ); + + DrawOwnerInfoMenuScene(); + + // [CANCEL]{^`FbN + tp_cancel = SelectSomethingByTP(&dummy, func, 1 ); + + if( ( pad.trg & PAD_BUTTON_A ) || ( tp_select ) ) { // j[ڂւ̕ + if( s_settingPos[ s_csr ].enable ) { + switch( s_csr ) { + case 0: + SetNicknameInit(); + g_pNowProcess = SetNicknameMain; + break; + case 1: + SetBirthdayInit(); + g_pNowProcess = SetBirthdayMain; + break; + case 2: + SetUserColorInit(); + g_pNowProcess = SetUserColorMain; + break; + case 3: + SetCommentInit(); + g_pNowProcess = SetCommentMain; + break; + } + } + }else if( ( pad.trg & PAD_BUTTON_B ) || tp_cancel ) { + MachineSettingInit(); + return 0; + } + return 0; +} + +// \tgEFAL[֌W +// L[̕\ +static void DrawCharKeys( void ) +{ + int l; + u16 code; + + for( l=0; l= CODE_BUTTON_TOP_) && (code < CODE_BUTTON_BOTTOM_) ) + { + int x = code - CODE_BUTTON_TOP_; + PutStringUTF16( CLIST_LT_X + CLIST_MARGIN*(l%KEY_PER_LINE) + CLIST_SEGMENT_INTERVAL*((l%KEY_PER_LINE)/CLIST_KEY_PER_SEGMENT) , + CLIST_LT_Y + CLIST_MARGIN*(l/KEY_PER_LINE) , color, str_button[x] ); + } + else + { + u16 s[2]; + s[0] = code; + s[1] = 0; + PutStringUTF16( CLIST_LT_X + CLIST_MARGIN*(l%KEY_PER_LINE) + CLIST_SEGMENT_INTERVAL*((l%KEY_PER_LINE)/CLIST_KEY_PER_SEGMENT) , + CLIST_LT_Y + CLIST_MARGIN*(l/KEY_PER_LINE) , color, s ); + } + } + } +} + +// ꕶ폜 +static void DeleteACharacter( NameOrComment noc ) +{ + u16 *buf; + u8 *length; + if(noc == NOC_NAME) + { + buf = s_temp_name; + length = &s_temp_name_length; + }else if(noc == NOC_COMMENT) + { + buf = s_temp_comment; + length = &s_temp_comment_length; + }else + { + //unknown + return; + } + + if(*length > 0) buf[--(*length)] = CHAR_USCORE; +} + + +// I𒆕L[EL[Ō肵̋ +static void PushKeys( u16 code, NameOrComment noc ) +{ + u16 *buf; + u8 *length; + u16 max_length; + void (*setflag)(BOOL) = NULL; + if(noc == NOC_NAME) + { + buf = s_temp_name; + length = &s_temp_name_length; + max_length = LCFG_TWL_NICKNAME_LENGTH; + setflag = LCFG_TSD_SetFlagNickname; + }else if(noc == NOC_COMMENT) + { + buf = s_temp_comment; + length = &s_temp_comment_length; + max_length = LCFG_TWL_COMMENT_LENGTH; + // setflag = TSD_SetFlagComment; + setflag = NULL; + }else + { + //unknown + return; + } + + if( (code >= CODE_BUTTON_TOP_) && (code < CODE_BUTTON_BOTTOM_) ) + { + // L[ + switch(code) + { + case VAR_BUTTON1_: + case VAR_BUTTON2_: + SetSoftKeyboardButton(next_char_mode[code - VAR_BUTTON1_]); + break; + case DEL_BUTTON_: + DeleteACharacter(noc); + break; + case SPACE_BUTTON_: + if(*length < max_length) buf[(*length)++] = L'@'; + break; + case OK_BUTTON_: + if(setflag) setflag(TRUE);// ݒ芮tO𗧂ĂĂ + SVC_CpuClear(0, buf + *length, (max_length - *length) * 2, 16);// [NA + if(noc == NOC_NAME) { + LCFG_TSD_SetNickname( buf ); + }else if(noc == NOC_COMMENT) { + LCFG_TSD_SetComment( buf ); + } + // :::::::::::::::::::::::::::::::::::::::::::::: + // TWLݒf[^t@Cւ̏ + // :::::::::::::::::::::::::::::::::::::::::::::: + (void)LCFG_WriteTWLSettings();// t@C֏ + // Z[uɃLZƍ + case CANCEL_BUTTON_: + SetOwnerInfoInit(); + g_pNowProcess = SetOwnerInfoMain; + break; + default:// unknown code + break; + } + } + else + { + // ʃL[ + if(*length < max_length) buf[(*length)++] = code; + } +} + +// PadDetectOnKeySelectSomethingByTPŎgSelectSomethingFunc̎ +static BOOL SelectSoftwareKeyFunc( u16 *csr, TPData *tgt ) +{ + // ܂͌ƂȂWiJ[\Pʁj擾 + int csrx; + int csry; + int csrxy; + int a; + int b; + NNSG2dTextRect rect; + u16 code; + BOOL ret; + + csrx = tgt->x - CLIST_LT_X; + csrx = csrx - (CLIST_SEGMENT_INTERVAL*(csrx/(CLIST_MARGIN*CLIST_KEY_PER_SEGMENT+CLIST_SEGMENT_INTERVAL))); + csrx = csrx / CLIST_MARGIN; + csry = (tgt->y - CLIST_LT_Y) / CLIST_MARGIN; + if(csrx < 0 ) return FALSE; + + if ( csrx >= KEY_PER_LINE ) csrx = KEY_PER_LINE - 1; + csrxy = csrx + csry * KEY_PER_LINE; + + if ( csrxy < 0 || csrxy >= CHAR_LIST_CHAR_NUM) return FALSE;// 炩ɂ͂ݏo + + // W̃L[R[h擾 + code = char_tbl[s_char_mode][csrxy]; + if(code == EOM_) return FALSE; + + // Ẅ̗擾 + if( (code >= CODE_BUTTON_TOP_) && (code < CODE_BUTTON_BOTTOM_) ) + { + int x = code - CODE_BUTTON_TOP_; + rect = NNS_G2dTextCanvasGetTextRect( &gTextCanvas, str_button[x] ); + } + else + { + u16 s[2]; + s[0] = code; + s[1] = 0; + // rect = NNS_G2dTextCanvasGetTextRect( &gTextCanvas, s ); + // ႩȂ蔻肪ccMM܂łƂĂ݂ + rect.width = CLIST_MARGIN; + rect.height = CLIST_MARGIN; + } + a = CLIST_LT_X + CLIST_MARGIN*(csrxy%KEY_PER_LINE) + CLIST_SEGMENT_INTERVAL*((csrxy%KEY_PER_LINE)/CLIST_KEY_PER_SEGMENT); + b = CLIST_LT_Y + CLIST_MARGIN*(csrxy/KEY_PER_LINE); + + // Ẅ̗Ƀ^b`W܂܂Ă邩`FbN + ret = WithinRangeTP( a, b, a+rect.width, b+rect.height, tgt ); + + if(ret) + { + *csr = (u16)csrxy; + } + return ret; +} + +// \tgEFAL[ł̃L[pbhyу^b`pbh +// ReadTPĂƁB +static void PadDetectOnKey( NameOrComment noc ) +{ + SelectSomethingFunc func[1]; + BOOL tp_select = FALSE; + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( pad.trg & PAD_KEY_RIGHT ){ // J[\̈ړ + do + { + if(s_key_csr%KEY_PER_LINE != KEY_PER_LINE-1) s_key_csr++; + else s_key_csr -= KEY_PER_LINE-1; + if( s_key_csr == CHAR_LIST_CHAR_NUM ) s_key_csr -= s_key_csr%KEY_PER_LINE; + } + while(char_tbl[s_char_mode][s_key_csr]==EOM_); + } + if( pad.trg & PAD_KEY_LEFT ){ + do + { + if(s_key_csr%KEY_PER_LINE != 0) s_key_csr--; + else s_key_csr += KEY_PER_LINE-1; + if( s_key_csr & 0x8000 ) s_key_csr = KEY_PER_LINE-1; + } + while(char_tbl[s_char_mode][s_key_csr]==EOM_); + } + if( pad.trg & PAD_KEY_DOWN ){ // J[\̈ړ + do + { + s_key_csr += KEY_PER_LINE; + if( s_key_csr >= CHAR_LIST_CHAR_NUM ) s_key_csr -= KEY_PER_LINE*(s_key_csr/KEY_PER_LINE); + } + while(char_tbl[s_char_mode][s_key_csr]==EOM_); + } + if( pad.trg & PAD_KEY_UP ){ + do + { + if( s_key_csr < KEY_PER_LINE ) s_key_csr += (CHAR_LIST_CHAR_NUM/KEY_PER_LINE)*KEY_PER_LINE; + else s_key_csr -= KEY_PER_LINE; + if( s_key_csr >= CHAR_LIST_CHAR_NUM ) s_key_csr -= KEY_PER_LINE; + } + while(char_tbl[s_char_mode][s_key_csr]==EOM_); + } + + func[0] = (SelectSomethingFunc)SelectSoftwareKeyFunc; + tp_select = SelectSomethingByTP(&s_key_csr, func, 1 ); + + if( ( pad.trg & PAD_BUTTON_A ) || ( tp_select ) ) { // L[ꂽ + PushKeys( char_tbl[s_char_mode][s_key_csr], noc ); + }else if( pad.trg & PAD_BUTTON_B ) { + DeleteACharacter(noc); + } +} + +// jbNl[ҏWʂ̕`揈 +static void DrawSetNicknameScene( void ) +{ + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"NICKNAME" ); + PutStringUTF16( 128-60 , 21 , TXT_UCOLOR_G0, s_temp_name ); + DrawCharKeys(); +} + +// jbNl[ҏW̏ +static void SetNicknameInit( void ) +{ + SetSoftKeyboardButton(0); + s_key_csr = KEY_START; + + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // 炩TWLݒf[^t@Cǂݍݍς݂̐ݒ擾 + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // jbNl[pe|obt@̏ + LCFG_TSD_GetNickname( s_temp_name ); + s_temp_name_length = MY_StrLen( s_temp_name ); + if( s_temp_name_length < LCFG_TWL_NICKNAME_LENGTH ) { + SVC_CpuClear(CHAR_USCORE, &s_temp_name[ s_temp_name_length ], + ( LCFG_TWL_NICKNAME_LENGTH - s_temp_name_length ) * 2, 16); + } + + DrawSetNicknameScene(); + + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); +} + +// jbNl[ҏWC +static int SetNicknameMain( void ) +{ + ReadTP(); + + PadDetectOnKey(NOC_NAME); + + // `揈 + DrawSetNicknameScene(); + + return 0; +} + +// aҏWʂ̕\ +static void DrawSetBirthdayScene( void ) +{ + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"BIRTHDAY" ); + PutStringUTF16( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, TXT_UCOLOR_G0, (const u16 *)L"ACANCEL" ); + PutStringUTF16( OK_BUTTON_TOP_X, OK_BUTTON_TOP_Y, TXT_UCOLOR_G0, (const u16 *)L"@OK" ); + PutStringUTF16( 128-36+16, 11*8, TXT_COLOR_BLACK, (const u16 *)L"@@@" ); + PrintfSJIS( 128-36, 11*8, (s_birth_csr ? TXT_COLOR_GREEN : TXT_COLOR_BLACK), "%d", s_temp_birthday.month / 10); + PrintfSJIS( 128-28, 11*8, (s_birth_csr ? TXT_COLOR_GREEN : TXT_COLOR_BLACK), "%d", s_temp_birthday.month % 10); + PrintfSJIS( 128+12, 11*8, (!s_birth_csr ? TXT_COLOR_GREEN : TXT_COLOR_BLACK), "%d", s_temp_birthday.day / 10); + PrintfSJIS( 128+20, 11*8, (!s_birth_csr ? TXT_COLOR_GREEN : TXT_COLOR_BLACK), "%d", s_temp_birthday.day % 10); +} + +// SetBirthdayMainSelectSomethingByTPŎgSelectSomethingFunc̎ +static BOOL SelectBirthdayFunc( u16 *csr, TPData *tgt ) +{ + int l; + + // PȎ + // L͈͑Sɂ‚ĉꂽǂ̊mF + // L͈͂̋敪́A^b`pbh̍WmF͈͂î]܂ + for(l=0; l<4; l++) + { + int x = 12*8 + (l%2)*6*8; + int y = 8*8 + (l/2)*6*8; + if(WithinRangeTP( x, y, x+16, y+16, tgt )) + { + *csr = (u16)l; + return TRUE; + } + } + + return FALSE; +} + +// aҏW̏ +static void SetBirthdayInit( void ) +{ + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // 炩TWLݒf[^t@Cǂݍݍς݂̐ݒ擾 + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // a + LCFG_TSD_GetBirthday( &s_temp_birthday ); + + // BGf[^̃[h + GX_LoadBG1Char(bg_char_data, 0, sizeof(bg_char_data)); + GX_LoadBG1Scr(bg_birth_scr_data, 0, sizeof(bg_birth_scr_data)); + + DrawSetBirthdayScene(); + + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); +} + +static void CheckDate( void ) +{ + u8 maxday; + if( s_temp_birthday.month == 0 ) s_temp_birthday.month = 12; + if( s_temp_birthday.month == 13 ) s_temp_birthday.month = 1; + maxday = (u8)SYSM_GetDayNum( 2000, s_temp_birthday.month ); + if( s_temp_birthday.day == 0 ) s_temp_birthday.day = maxday; + if( s_temp_birthday.day > maxday ) s_temp_birthday.day = 1; +} + +// ĂԐXs[hŕω悤ȏ +static void Birthday_AutoNumScrollByTP( void ) +{ + static u16 first_csr = 0xffff; + u16 temp_csr; + static int same_count = 0; + + if( tpd.disp.touch ) + { + BOOL t = SelectBirthdayFunc( &temp_csr, &tpd.disp ); + if( t ) + { + if(same_count == 0) // count start + { + first_csr = temp_csr; + same_count = 1; + }else if(first_csr == temp_csr) + { + if( same_count == 1 || (same_count > 29 && same_count%10==0)) + { + switch(temp_csr) + { + case 0: + s_birth_csr = TRUE; + s_temp_birthday.month++; + break; + case 1: + s_birth_csr = FALSE; + s_temp_birthday.day++; + break; + case 2: + s_birth_csr = TRUE; + s_temp_birthday.month--; + break; + case 3: + s_birth_csr = FALSE; + s_temp_birthday.day--; + break; + default: + break; + } + } + same_count++; + } + } + }else // touch==0 + { + same_count = 0; + first_csr = 0xffff; + } +} + +// aҏWC +static int SetBirthdayMain( void ) +{ + SelectSomethingFunc func[2]={SelectCancelFunc, SelectOKFunc}; + BOOL tp_touch = FALSE; + u16 temp_ok_cancel; + + ReadTP(); + + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( pad.trg & PAD_KEY_DOWN ){ + (*(s_birth_csr ? &s_temp_birthday.month : &s_temp_birthday.day))--; + } + if( pad.trg & PAD_KEY_UP ){ + (*(s_birth_csr ? &s_temp_birthday.month : &s_temp_birthday.day))++; + } + if( pad.trg & (PAD_KEY_RIGHT | PAD_KEY_LEFT)){ // J[\̈ړ + s_birth_csr = !s_birth_csr; + } + + // t`FbN + CheckDate(); + + // TP`FbN + tp_touch = SelectSomethingByTP(&temp_ok_cancel, func, 2 ); + // TPŃ{^ĂԐXs[hŕω悤ȏ + Birthday_AutoNumScrollByTP(); + + // t`FbN + CheckDate(); + + DrawSetBirthdayScene(); + + if( pad.trg & PAD_BUTTON_A || (tp_touch && temp_ok_cancel == KEY_OK) ) { + LCFG_TSD_SetBirthday(&s_temp_birthday); + LCFG_TSD_SetFlagBirthday( TRUE ); + // :::::::::::::::::::::::::::::::::::::::::::::: + // TWLݒf[^t@Cւ̏ + // :::::::::::::::::::::::::::::::::::::::::::::: + (void)LCFG_WriteTWLSettings();// t@C֏ + SetOwnerInfoInit(); + g_pNowProcess = SetOwnerInfoMain; + return 0; + }else if( ( pad.trg & PAD_BUTTON_B ) || (tp_touch && temp_ok_cancel == KEY_CANCEL) ) { + SetOwnerInfoInit(); + g_pNowProcess = SetOwnerInfoMain; + return 0; + } + return 0; +} + +static void DrawColorSample( void ) +{ + int l; + + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"USER COLOR" ); + PutStringUTF16( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, TXT_UCOLOR_G0, (const u16 *)L"ACANCEL" ); + PutStringUTF16( OK_BUTTON_TOP_X, OK_BUTTON_TOP_Y, TXT_UCOLOR_G0, (const u16 *)L"@OK" ); + for(l=0;l<16;l++) //16F + { + PutStringUTF16( 88 + 24 * (l%4), 54 + 24 * (l/4), TXT_UCOLOR_GRAY + l, (const u16 *)L"" ); + } + for(l=0;l<4;l++) + { + PutStringUTF16( 83 + 24 * (s_color_csr%4) + 10*(l%2), 49 + 24 * (s_color_csr/4) + 10*(l/2), TXT_UCOLOR_G0, (const u16 *)L"" ); + } +} + +// SetUserColorMainSelectSomethingByTPŎgSelectSomethingFunc̎ +static BOOL SelectColorFunc( u16 *csr, TPData *tgt ) +{ + // ܂͌ƂȂWiJ[\Pʁj擾 + int csrx; + int csry; + int csrxy; + int a; + int b; + BOOL ret; + + csrx = (tgt->x - 88) / 24; + csry = (tgt->y - 54) / 24; + if(csrx < 0 ) return FALSE; + + if ( csrx >= 4 ) csrx = 3; + csrxy = csrx + csry * 4; + + if ( csrxy < 0 || csrxy >= 16) return FALSE;// ͂ݏo + + a = 88 + csrx * 24; + b = 54 + csry * 24; + + // Ẅ̗Ƀ^b`W܂܂Ă邩`FbN + ret = WithinRangeTP( a, b, a+11, b+11, tgt ); + + if(ret) + { + *csr = (u16)csrxy; + } + return ret; +} + +// [U[J[ҏW̏ +static void SetUserColorInit( void ) +{ + DrawColorSample(); + + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // 炩TWLݒf[^t@Cǂݍݍς݂̐ݒ擾 + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // [U[J[ + s_color_csr = LCFG_TSD_GetUserColor(); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); +} + +// [U[J[ҏWC +static int SetUserColorMain( void ) +{ + SelectSomethingFunc func[3]={SelectColorFunc, SelectCancelFunc, SelectOKFunc}; + BOOL tp_touch = FALSE; + u16 temp_csr; + + ReadTP(); + + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( pad.trg & PAD_KEY_DOWN ){ // J[\̈ړ + s_color_csr += 4; + if(s_color_csr >= 16) s_color_csr -= 16; + } + if( pad.trg & PAD_KEY_UP ){ + if(s_color_csr < 4) s_color_csr += 16; + s_color_csr -= 4; + } + if( pad.trg & PAD_KEY_RIGHT ){ + s_color_csr += 1; + if(s_color_csr%4 == 0) s_color_csr -= 4; + } + if( pad.trg & PAD_KEY_LEFT ){ + if(s_color_csr%4 == 0) s_color_csr += 4; + s_color_csr -= 1; + } + temp_csr = s_color_csr; + + // TP`FbN + tp_touch = SelectSomethingByTP(&temp_csr, func, 3 ); + if ((temp_csr != KEY_OK && temp_csr != KEY_CANCEL)){ + s_color_csr = (u8)temp_csr; + } + + if( ( pad.trg & PAD_BUTTON_A ) || (tp_touch && temp_csr == KEY_OK) ) { // F + LCFG_TSD_SetUserColor( (u8 )s_color_csr ); + // :::::::::::::::::::::::::::::::::::::::::::::: + // TWLݒf[^t@Cւ̏ + // :::::::::::::::::::::::::::::::::::::::::::::: + (void)LCFG_WriteTWLSettings();// t@C֏ + SetOwnerInfoInit(); + g_pNowProcess = SetOwnerInfoMain; + return 0; + }else if( ( pad.trg & PAD_BUTTON_B ) || (tp_touch && temp_csr == KEY_CANCEL) ) { + ChangeUserColor( LCFG_TSD_GetUserColor() ); // pbgFɂǂ + SetOwnerInfoInit(); + g_pNowProcess = SetOwnerInfoMain; + return 0; + } + + ChangeUserColor( s_color_csr ); + DrawColorSample(); + + return 0; +} + +// RgҏWʂ̕`揈 +static void DrawSetCommentScene( void ) +{ + u16 tempbuf[LCFG_TWL_COMMENT_LENGTH+2]; + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"COMMENT" ); + SVC_CpuCopy( s_temp_comment, tempbuf, 13 * 2, 16 ); + *(tempbuf+13)='\n'; + SVC_CpuCopy( s_temp_comment+13, tempbuf+14, 13 * 2, 16 ); + *(tempbuf+LCFG_TWL_COMMENT_LENGTH+1)=0; + PutStringUTF16( 128-78 , 15 , TXT_UCOLOR_G0, tempbuf ); + DrawCharKeys(); +} + +// RgҏW̏ +static void SetCommentInit( void ) +{ + SetSoftKeyboardButton(0); + s_key_csr = KEY_START; + + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // 炩TWLݒf[^t@Cǂݍݍς݂̐ݒ擾 + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // Rgpe|obt@̏ + LCFG_TSD_GetComment( s_temp_comment ); + s_temp_comment_length = MY_StrLen( s_temp_comment ); + if( s_temp_comment_length < LCFG_TWL_COMMENT_LENGTH ) { + SVC_CpuClear(CHAR_USCORE, &s_temp_comment[ s_temp_comment_length ], + ( LCFG_TWL_COMMENT_LENGTH - s_temp_comment_length ) * 2, 16); + } + + DrawSetCommentScene(); + + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); +} + +// RgҏWC +static int SetCommentMain( void ) +{ + ReadTP(); + + PadDetectOnKey(NOC_COMMENT); + + // `揈 + DrawSetCommentScene(); + + return 0; +} + + +// UTF16̕񒷎Zo +static u8 MY_StrLen( const u16 *pStr ) +{ + u8 len = 0; + while( *pStr++ ) { + ++len; + if( len == 255 ) { + break; + } + } + return len; +} + +//====================================================== +// \tgEFAL[{[hpLe[u +//====================================================== + +static const u16 char_tbl[CHAR_LIST_MODE_NUM][CHAR_LIST_CHAR_NUM] = { + { // Ђ炪 + L'', L'', L'', L'', L'', + L'', L'', L'', L'', L'', DEL_BUTTON_, + L'', L'', L'', L'', L'', + L'', L'', L'', L'', L'', SPACE_BUTTON_, + L'', L'', L'', L'', L'', + L'', L'', L'', L'', L'', EOM_, + + L'', L'', L'', L'', L'', + L'', EOM_, L'', EOM_, L'', VAR_BUTTON1_, + L'', L'', L'', L'', L'', + L'', L'', L'', L'', L'', VAR_BUTTON2_, + L'', L'', L'', L'', L'', + L'', EOM_, L'', EOM_, L'', EOM_, + + L'', L'', L'', L'', L'', + L'', L'', L'', L'', L'', EOM_, + L'', L'', L'', L'', L'', + L'', L'', L'', L'', L'', OK_BUTTON_, + L'', L'', L'', L'', L'', + L'', L'A', L'B', L'I', L'H', EOM_, + + L'u', L'v', L'`', L'E', L'[', + EOM_, EOM_, EOM_, EOM_, EOM_, CANCEL_BUTTON_, + EOM_, EOM_, EOM_, EOM_, EOM_, + EOM_, EOM_, EOM_, EOM_, EOM_, + }, + + { // J^Ji + L'A', L'C', L'E', L'G', L'I', + L'J', L'L', L'N', L'P', L'R', DEL_BUTTON_, + L'T', L'V', L'X', L'Z', L'\', + L'^', L'`', L'c', L'e', L'g', SPACE_BUTTON_, + L'i', L'j', L'k', L'l', L'm', + L'n', L'q', L't', L'w', L'z', EOM_, + + L'}', L'~', L'', L'', L'', + L'', EOM_, L'', EOM_, L'', VAR_BUTTON1_, + L'', L'', L'', L'', L'', + L'', EOM_, L'', EOM_, L'', VAR_BUTTON2_, + L'@', L'B', L'D', L'F', L'H', + L'', EOM_, L'', EOM_, L'', EOM_, + + L'K', L'M', L'O', L'Q', L'S', + L'U', L'W', L'Y', L'[', L']', EOM_, + L'_', L'a', L'd', L'f', L'h', + L'o', L'r', L'u', L'x', L'{', OK_BUTTON_, + L'p', L's', L'v', L'y', L'|', + L'b', L'A', L'B', L'I', L'[', EOM_, + + L'u', L'v', L'`', L'E', EOM_, + EOM_, EOM_, EOM_, EOM_, EOM_, CANCEL_BUTTON_, + EOM_, EOM_, EOM_, EOM_, EOM_, + EOM_, EOM_, EOM_, EOM_, EOM_, + }, + + { // p + L'`', L'a', L'b', L'c', L'd', + L'e', L'f', L'g', L'h', L'i', DEL_BUTTON_, + L'j', L'k', L'l', L'm', L'n', + L'o', L'p', L'q', L'r', L's', SPACE_BUTTON_, + L't', L'u', L'v', L'w', L'x', + L'y', EOM_, EOM_, EOM_, EOM_, EOM_, + + L'', L'', L'', L'', L'', + L'', L'', L'', L'', L'', VAR_BUTTON1_, + L'', L'', L'', L'', L'', + L'', L'', L'', L'', L'', VAR_BUTTON2_, + L'', L'', L'', L'', L'', + L'', EOM_, EOM_, EOM_, EOM_, EOM_, + + L'O', L'P', L'Q', L'R', L'S', + L'T', L'U', L'V', L'W', L'X', EOM_, + L'I', EOM_, L'', EOM_, L'^', + L'C', EOM_, L'D', EOM_, L'|', OK_BUTTON_, + L'f', EOM_, L'h', EOM_, EOM_, + L'', EOM_, L'i', EOM_, L'j', EOM_, + + EOM_, EOM_, EOM_, EOM_, EOM_, + EOM_, EOM_, EOM_, EOM_, EOM_, CANCEL_BUTTON_, + EOM_, EOM_, EOM_, EOM_, EOM_, + EOM_, EOM_, EOM_, EOM_, EOM_, + }, +}; + + diff --git a/build/systemMenu_RED/MachineSettings/ARM9/src/setRTC.c b/build/systemMenu_RED/MachineSettings/ARM9/src/setRTC.c new file mode 100644 index 00000000..270ef72b --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/ARM9/src/setRTC.c @@ -0,0 +1,553 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: setRTC.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" +#include "MachineSetting.h" + +// define data------------------------------------------ + +//#define __RTC_MINUTE_OFFSET // ̒`LȏꍇrtcOffset͕ItZbgŎZo܂B܂Aȏꍇ͕bItZbgƂȂ܂B + + // RETURN{^LCD̈ +#define RETURN_BUTTON_TOP_X ( 2 * 8 ) +#define RETURN_BUTTON_TOP_Y ( 21 * 8 ) +#define RETURN_BUTTON_BOTTOM_X ( RETURN_BUTTON_TOP_X + 6 * 8 ) +#define RETURN_BUTTON_BOTTOM_Y ( RETURN_BUTTON_TOP_Y + 2 * 8 ) + + // tf[^LCD̈ +#define DATE_TOP_Y ( 10 * 8 ) +#define YEAR_TOP_X ( 5 * 8 ) +#define MONTH_TOP_X ( YEAR_TOP_X + 5 * 8 ) +#define DAY_TOP_X ( MONTH_TOP_X + 3 * 8 ) + + // f[^LCD̈ +#define TIME_TOP_Y ( DATE_TOP_Y ) +#define HOUR_TOP_X ( DAY_TOP_X + 5 * 8 ) +#define MINUTE_TOP_X ( HOUR_TOP_X + 3 * 8 ) +#define SECOND_TOP_X ( MINUTE_TOP_X + 3 * 8 ) + + // ̓^b`plpJE^ +#define S_UPDOWN_COUNT_MAX 16 + // l̓^b`plpJE^ +#define D_DOWN_COUNT_MAX -50 +#define D_UP_COUNT_MAX 50 + + + // t̓V[PXp[N +typedef struct DateTimeParam { + int seq; // V[PXԍ + int *pTgt; // ͑Ώۂ̕ϐւ̃|C^ + RTCDate Date; + RTCTime Time; + RTCDate Date_old; + RTCTime Time_old; +}DateTimeParam; + + + // RTCݒV[PXp[N +typedef struct SetRtcWork { + int csr; // J[\ʒu + s64 rtcOffset[ 2 ]; // RTCItZbgli[0]:ݒύXO̒lA[1]:ύX̒lj + DateTimeParam dtp; // t̓V[PXp[N + InputNumParam inp; // l̓C^[tF[Xp[N +}SetRtcWork; + + +typedef struct DateTimeWidth { + int year; + int month; + int day; + int hour; + int minute; + int second; +}DateTimeWidth; + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- +RTCWeek CalcWeekFromDate( u32 year, u32 month, u32 day ); +void InputDecimal(int *pTgt, InputNumParam *inpp); + +static void InputRtcDateTimeInit( int start ); +static int InputRtcDateTimeMain( void ); + +static void SelectString( int *pTgt, const u8 **const pStrp, InputNumParam *inpp); +static void BcdToHex(int *bcdp); +static void HexToBcd(int *hexp); +static BOOL CheckLeapYear( u32 year ); +static void DrawDateTime( RTCDate *pDate, RTCTime *pTime, int color ); + +// global variable ------------------------------------- + +// static variable ------------------------------------- +static SetRtcWork *s_pWork; // RTCݒp[N +// const data ----------------------------------------- + +//====================================================== +// tݒ +//====================================================== + +// RTCݒV[PX̏ +void SetRTCInit( void ) +{ + GX_DispOff(); + GXS_DispOff(); + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL ); + + PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"DATE & TIME SET" ); + PutStringUTF16( RETURN_BUTTON_TOP_X, RETURN_BUTTON_TOP_Y, TXT_COLOR_CYAN, (const u16 *)L" RETURN " ); + + if( g_initialSet ) { + if( SYSMi_GetWork()->rtcStatus & 0x01) { + PutStringUTF16( 8 * 8, 18 * 8, TXT_COLOR_RED, (const u16 *)L"RTC reset is detected!" ); + }else { + PutStringUTF16( 8 * 8, 18 * 8, TXT_COLOR_RED, (const u16 *)L"Set RTC." ); + } + } + + s_pWork = Alloc( sizeof(SetRtcWork) ); // RTCݒp[N̊m + if( s_pWork == NULL ) { + OS_Panic( "ARM9- Fail to allocate memory...\n" ); + } + + SVC_CpuClear( 0x0000, s_pWork, sizeof(SetRtcWork), 16 ); + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); + + RTC_GetDateTime( &s_pWork->dtp.Date, &s_pWork->dtp.Time ); + s_pWork->dtp.Date.year += 2000; + + PrintfSJIS ( YEAR_TOP_X, DATE_TOP_Y, TXT_COLOR_BLACK, "%04d", s_pWork->dtp.Date.year ); + PrintfSJIS ( MONTH_TOP_X, DATE_TOP_Y, TXT_COLOR_BLACK, "%02d", s_pWork->dtp.Date.month ); + PrintfSJIS ( DAY_TOP_X, DATE_TOP_Y, TXT_COLOR_BLACK, "%02d", s_pWork->dtp.Date.day ); + PrintfSJIS ( HOUR_TOP_X, TIME_TOP_Y, TXT_COLOR_BLACK, "%02d", s_pWork->dtp.Time.hour ); + PrintfSJIS ( MINUTE_TOP_X, TIME_TOP_Y, TXT_COLOR_BLACK, "%02d", s_pWork->dtp.Time.minute ); + + DrawDateTime( &s_pWork->dtp.Date, &s_pWork->dtp.Time, TXT_COLOR_BLACK ); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); + GX_DispOn(); + GXS_DispOn(); +} + + +// w肵tE̕\ +static void DrawDateTime( RTCDate *pDate, RTCTime *pTime, int color ) +{ + PrintfSJIS( YEAR_TOP_X, DATE_TOP_Y, color, "%04d", pDate->year ); + PrintfSJIS( MONTH_TOP_X, DATE_TOP_Y, color, "%02d", pDate->month ); + PrintfSJIS( DAY_TOP_X, DATE_TOP_Y, color, "%02d", pDate->day ); + PrintfSJIS( HOUR_TOP_X, TIME_TOP_Y, color, "%02d", pTime->hour ); + PrintfSJIS( MINUTE_TOP_X, TIME_TOP_Y, color, "%02d", pTime->minute ); + PutStringUTF16( YEAR_TOP_X + 4 * 8, DATE_TOP_Y, color, L"/" ); + PutStringUTF16( MONTH_TOP_X + 2 * 8, DATE_TOP_Y, color, L"/" ); + PutStringUTF16( HOUR_TOP_X + 2 * 8, TIME_TOP_Y, color, L":" ); +} + + +// RTCݒV[PX +int SetRTCMain( void ) +{ + BOOL tp_set = FALSE; + BOOL tp_return = FALSE; + + ReadTP(); // TP͂̎擾 + + if(tpd.disp.touch) { + tp_set = WithinRangeTP( YEAR_TOP_X, DATE_TOP_Y, // [RTCݒ]̈扟`FbN + SECOND_TOP_X, DATE_TOP_Y + 16, &tpd.disp ); + // [RETURN]{^`FbN + tp_return = WithinRangeTP( RETURN_BUTTON_TOP_X, RETURN_BUTTON_TOP_Y, + RETURN_BUTTON_BOTTOM_X, RETURN_BUTTON_BOTTOM_Y, &tpd.disp ); + } + if( g_initialSet && !LCFG_TSD_IsSetDateTime() ) { + tp_set = TRUE; + } + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( ( pad.trg & PAD_BUTTON_A ) || tp_set ) { // RTCݒJn + InputRtcDateTimeInit( 1 ); + g_pNowProcess = InputRtcDateTimeMain; + }else if( ( pad.trg & PAD_BUTTON_B ) || tp_return ) { // j[ɖ߂ + Free( s_pWork ); // RTCݒp[N̉ + s_pWork = NULL; + MachineSettingInit(); + } +#ifdef SYSM_DEBUG_ + else if( pad.trg & PAD_BUTTON_START ) { + ClearRTC(); + OS_Printf( "RTC offset in NVRAM is ZERO clear!\n" ); + } +#endif /* SYSM_DEBUG_ */ + + return 0; +} + + +//====================================================== +// t͏ +//====================================================== + +// t͏ +static void InputRtcDateTimeInit( int start ) +{ + NNS_G2dCharCanvasClearArea( &gCanvas, TXT_COLOR_WHITE, + RETURN_BUTTON_TOP_X, RETURN_BUTTON_TOP_Y, 256 - RETURN_BUTTON_TOP_X, 2 * 8 ); + if( start ) { + DrawOKCancelButton(); + s_pWork->dtp.seq = 0; + }else { + PutStringUTF16( RETURN_BUTTON_TOP_X, RETURN_BUTTON_TOP_Y, TXT_COLOR_CYAN, (const u16 *)L"RETURN" ); + } + SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 ); +} + + +// t +static int InputRtcDateTimeMain( void ) +{ + BOOL tp_ok = FALSE; + BOOL tp_cancel = FALSE; + int new_seq, y_base, abs_y_offset; + + enum { // t̓V[PXԍ + SEQ_INIT=0, + SEQ_YEAR_INIT=2, SEQ_YEAR_SET, + SEQ_MONTH_INIT, SEQ_MONTH_SET, + SEQ_DAY_INIT, SEQ_DAY_SET, + SEQ_HOUR_INIT, SEQ_HOUR_SET, + SEQ_MINUTE_INIT, SEQ_MINUTE_SET, + SEQ_END, + SEQ_CANCEL=64 + }; + + ReadTP(); // ^b`pl͂̎擾 + CheckOKCancelButton( &tp_ok, &tp_cancel ); // [OK],[CANCEL]{^`FbN + + s_pWork->inp.y_offset = 0; + + if( tpd.disp.touch ) { // [CANCEL]{^`FbN + if( ( s_pWork->dtp.seq & 0x01 ) && ( s_pWork->dtp.seq < SEQ_END ) ) { // SEQ_**_SET̎̂ݗL + new_seq = s_pWork->dtp.seq; + y_base = DATE_TOP_Y + 6; + + // ͍ڈړ̃`FbN + if( WithinRangeTP( YEAR_TOP_X, DATE_TOP_Y, SECOND_TOP_X, DATE_TOP_Y + 12, &tpd.disp ) ) { + if( tpd.disp.x < YEAR_TOP_X + 32 ) { + new_seq = SEQ_YEAR_SET; + }else if( ( tpd.disp.x >= MONTH_TOP_X ) && ( tpd.disp.x < MONTH_TOP_X + 16 ) ) { + new_seq = SEQ_MONTH_SET; + }else if( ( tpd.disp.x >= DAY_TOP_X ) && ( tpd.disp.x < DAY_TOP_X + 16 ) ) { + new_seq = SEQ_DAY_SET; + }else if( ( tpd.disp.x >= HOUR_TOP_X ) && ( tpd.disp.x < HOUR_TOP_X + 16 ) ) { + new_seq = SEQ_HOUR_SET; + }else if( ( tpd.disp.x >= MINUTE_TOP_X ) && ( tpd.disp.x < MINUTE_TOP_X + 16 ) ) { + new_seq = SEQ_MINUTE_SET; + } + } + if( s_pWork->dtp.seq != new_seq ) { + s_pWork->dtp.seq = new_seq - 1; + }else if( WithinRangeTP( s_pWork->inp.pos_x, y_base - 40, + s_pWork->inp.pos_x + s_pWork->inp.keta_max * 8, y_base + 60, &tpd.disp ) ) { + // ͒l̑ + s_pWork->inp.y_offset = tpd.disp.y - y_base; + abs_y_offset = ( s_pWork->inp.y_offset >= 0 ) ? s_pWork->inp.y_offset : -s_pWork->inp.y_offset; + if( abs_y_offset <= 6 ) { + s_pWork->inp.y_offset = 0; + }else if( abs_y_offset <= 20 ){ + s_pWork->inp.y_offset >>= 2; + }else if( abs_y_offset <= 40 ){ + s_pWork->inp.y_offset >>= 1; + } + } + } + } + + // ^b`pl or L[͂ɂāAJ[\ʒuɁÄʒũJ[\B + if( ( s_pWork->dtp.seq > 0 ) && ( ( s_pWork->dtp.seq & 0x01 ) == 0 ) ) { // SEQ_INIT͎̎sȂ + PrintfSJIS( s_pWork->inp.pos_x, s_pWork->inp.pos_y, TXT_COLOR_BLACK, "%02d", *s_pWork->dtp.pTgt ); + } + + // eV[PX̏ + switch(s_pWork->dtp.seq){ + + case SEQ_INIT: + MI_CpuCopy32( &s_pWork->dtp.Date, &s_pWork->dtp.Date_old, sizeof(RTCDate) ); + MI_CpuCopy32( &s_pWork->dtp.Time, &s_pWork->dtp.Time_old, sizeof(RTCTime) ); + + s_pWork->dtp.seq = SEQ_YEAR_INIT; + // SEQ_INIT͒ʂSEQ_YEAR_INIT + + case SEQ_YEAR_INIT: + s_pWork->inp.pos_x = YEAR_TOP_X; + s_pWork->inp.pos_y = DATE_TOP_Y; + s_pWork->inp.keta_max = 4; + s_pWork->inp.value_max = 2099; + s_pWork->inp.value_min = 2000; +// s_pWork->inp.value_min = 2004; +// if(s_pWork->dtp.Date.year < 2004) { +// s_pWork->dtp.Date.year = 2004; +// } + s_pWork->dtp.pTgt = (int *)&s_pWork->dtp.Date.year; + break; + + case SEQ_MONTH_INIT: + s_pWork->inp.pos_x = MONTH_TOP_X; + s_pWork->inp.keta_max = 2; + s_pWork->inp.value_max = 12; + s_pWork->inp.value_min = 1; + s_pWork->dtp.pTgt = (int *)&s_pWork->dtp.Date.month; + break; + + case SEQ_DAY_INIT: + s_pWork->inp.pos_x = DAY_TOP_X; + s_pWork->inp.keta_max = 2; + s_pWork->inp.value_max = (int)SYSM_GetDayNum( s_pWork->dtp.Date.year, s_pWork->dtp.Date.month ); + // NEƂɂ̌̓ZoB + s_pWork->inp.value_min = 1; + if(s_pWork->dtp.Date.day > s_pWork->inp.value_max) { + s_pWork->dtp.Date.day = (u32)s_pWork->inp.value_max; + } + s_pWork->dtp.pTgt = (int *)&s_pWork->dtp.Date.day; + break; + + case SEQ_HOUR_INIT: + s_pWork->inp.pos_x = HOUR_TOP_X; + s_pWork->inp.keta_max = 2; + s_pWork->inp.value_max = 23; + s_pWork->inp.value_min = 0; + s_pWork->dtp.pTgt = (int *)&s_pWork->dtp.Time.hour; + break; + + case SEQ_MINUTE_INIT: + s_pWork->inp.pos_x = MINUTE_TOP_X; + s_pWork->inp.keta_max = 2; + s_pWork->inp.value_max = 59; + s_pWork->inp.value_min = 0; + s_pWork->dtp.pTgt = (int *)&s_pWork->dtp.Time.minute; + break; + + case SEQ_YEAR_SET: + case SEQ_MONTH_SET: + case SEQ_DAY_SET: + case SEQ_HOUR_SET: + case SEQ_MINUTE_SET: + InputDecimal( s_pWork->dtp.pTgt, &s_pWork->inp ); + + // N͂Ȃ΁AjČvZ + if( ( s_pWork->dtp.seq == SEQ_YEAR_SET ) || + ( s_pWork->dtp.seq == SEQ_MONTH_SET ) || + ( s_pWork->dtp.seq == SEQ_DAY_SET ) ) { + s_pWork->dtp.Date.week = CalcWeekFromDate( s_pWork->dtp.Date.year, s_pWork->dtp.Date.month, s_pWork->dtp.Date.day ); + } + + // NE͂Ȃ΁AZoāA݂͓̓𒴂ĂCB + if( ( s_pWork->dtp.seq == SEQ_YEAR_SET ) || + ( s_pWork->dtp.seq == SEQ_MONTH_SET ) ) { + u32 dayNum = SYSM_GetDayNum( s_pWork->dtp.Date.year, s_pWork->dtp.Date.month ); + if( dayNum < s_pWork->dtp.Date.day ) { + PrintfSJIS( DAY_TOP_X, DATE_TOP_Y, TXT_COLOR_WHITE, "%02d", s_pWork->dtp.Date.day ); + PrintfSJIS( DAY_TOP_X, DATE_TOP_Y, TXT_COLOR_BLACK, "%02d", dayNum ); + s_pWork->dtp.Date.day = dayNum; + } + } + break; + + case SEQ_END: + s_pWork->dtp.Time.second = 0; + { + RTCDate date; // +-2000̂ʓ|Ȃ̂ŁAʃobt@ɃRs[ď + MI_CpuCopy32( &s_pWork->dtp.Date, &date, sizeof(RTCDate) ); + date.year -= 2000; + (void)RTC_SetDateTime( &date, &s_pWork->dtp.Time ); + LCFG_TSD_SetRTCOffset( SYSM_CalcRTCOffset( &date, &s_pWork->dtp.Time ) ); + } + + LCFG_TSD_SetFlagDateTime( TRUE ); // RTC̓tO𗧂ĂB + // :::::::::::::::::::::::::::::::::::::::::::::: + // TWLݒf[^t@Cւ̏ + // :::::::::::::::::::::::::::::::::::::::::::::: + (void)LCFG_WriteTWLSettings(); + + // ʂ̕\XV + GetAndDrawRTCData( &g_rtcDraw, TRUE ); + + g_pNowProcess = SetRTCMain; + InputRtcDateTimeInit( 0 ); // t͉ʂ̃NA + return 0; + + case SEQ_CANCEL: + // tE\̒lɖ߂ĕ\XV + DrawDateTime( &s_pWork->dtp.Date, &s_pWork->dtp.Time, TXT_COLOR_WHITE ); + DrawDateTime( &s_pWork->dtp.Date_old, &s_pWork->dtp.Time_old, TXT_COLOR_BLACK ); + MI_CpuCopy32( &s_pWork->dtp.Date_old, &s_pWork->dtp.Date, sizeof(RTCDate) ); + MI_CpuCopy32( &s_pWork->dtp.Time_old, &s_pWork->dtp.Time, sizeof(RTCTime) ); + g_pNowProcess = SetRTCMain; + InputRtcDateTimeInit( 0 ); // t͉ʂ̃NA + return 0; + } + + if( s_pWork->dtp.seq & 0x01 ) { // SEQ_**_SET̎̂ݗL + if( ( pad.trg & PAD_BUTTON_A ) || tp_ok ) { + s_pWork->dtp.seq = SEQ_END; // A{^Ō + }else if( ( pad.trg & PAD_BUTTON_B ) || tp_cancel ) { // B{^ŃLZ + s_pWork->dtp.seq = SEQ_CANCEL; + }else if( pad.trg & PAD_KEY_LEFT ) { + if( s_pWork->dtp.seq == SEQ_YEAR_SET ) { + s_pWork->dtp.seq = SEQ_MINUTE_INIT; + }else { + s_pWork->dtp.seq -= 3; + } + }else if( pad.trg & PAD_KEY_RIGHT ) { + if( s_pWork->dtp.seq == SEQ_MINUTE_SET ) { + s_pWork->dtp.seq = SEQ_YEAR_INIT; + }else { + s_pWork->dtp.seq++; + } + } + }else { // SEQ_**_INIT̎̂ݗL + s_pWork->dtp.seq++; + } + return 0; +} + + +/* +// 邤N̔ (邤NFPAʏ̔NFO^[j +BOOL CheckLeapYear( u32 year) +{ + if((year & 0x03) == 0) { // 邤ŃAu4Ŋ؂@@100Ŋ؂ȂNv + CP_SetDiv32_32(year, 100); // u400Ŋ؂Nv + if(CP_GetDivRemainder32() != 0) { + return TRUE; + }else { + CP_SetDiv32_32(year, 400); + if(CP_GetDivRemainder32() == 0) { + return TRUE; + } + } + } + return FALSE; +} +*/ + +// tj߂B +RTCWeek CalcWeekFromDate( u32 year, u32 month, u32 day ) +{ + if( month == 1 || month == 2 ){ + year--; + month += 12; + } + return (RTCWeek)( ( year + year/4 - year/100 + year/400 + (13*month + 8)/5 + day) % 7 ); +} + + +/* +// ɂp[^I +static void SelectString(int *pTgt, const u8 **const ppStr, InputNumParam *pInp ) +{ + BOOL value_up = FALSE; + BOOL value_down = FALSE; + const u8 *pStr_old = *pTgt; + + if( pInp->y_offset == 0 ) { + pInp->up_count = S_UPDOWN_COUNT_MAX; + }else { + pInp->up_count ++; + if( pInp->up_count > S_UPDOWN_COUNT_MAX ) { + pInp->up_count = 0; + if( pInp->y_offset < 0 ) value_up = TRUE; + else value_down = TRUE; + } + } + + if( ( pad.trg & PAD_KEY_DOWN ) || value_down ) { // \؂ւ + if( ++ *pTgt > pInp->value_max ) { + *pTgt = 0; + } + }else if( ( pad.trg & PAD_KEY_UP ) || value_up ) { + if( -- *pTgt & 0x8000 ) { + *pTgt = pInp->value_max; + } + } + + PutStringUTF16( pInp->pos_x, pInp->pos_y, TXT_COLOR_WHITE, pStr_old ); // + PutStringUTF16( pInp->pos_x, pInp->pos_y, TXT_COLOR_BLACK, ppStr[ *pTgt ] ); // ݑIĂ镶\ +} +*/ + +// POil +void InputDecimal( int *pTgt, InputNumParam *pInp ) +{ + BOOL value_up = FALSE; + BOOL value_down = FALSE; + int old = *pTgt; + + if( pInp->y_offset == 0 ) { + pInp->up_count = D_UP_COUNT_MAX; + pInp->down_count = D_DOWN_COUNT_MAX; + }else if( pInp->y_offset < 0 ) { + pInp->down_count += pInp->y_offset; + if( pInp->down_count < D_DOWN_COUNT_MAX ) { + pInp->down_count = 0; + value_down = TRUE; + } + }else { // y_offset > 0 + pInp->up_count += pInp->y_offset; + if( pInp->up_count > D_UP_COUNT_MAX ) { + pInp->up_count = 0; + value_up = TRUE; + } + } + + // L[͂ɉđΏےl𑝌 + if( value_down || + ( pad.trg & PAD_KEY_UP ) || + ( ( pad.cont & PAD_KEY_UP ) && ( pad.cont & PAD_BUTTON_R ) ) ) { + if( --*pTgt < pInp->value_min ) { + *pTgt = pInp->value_max; + } + }else if( value_up || + ( pad.trg & PAD_KEY_DOWN ) || + ( ( pad.cont & PAD_KEY_DOWN ) && ( pad.cont & PAD_BUTTON_R ) ) ) { + if( ++*pTgt > pInp->value_max ) { + *pTgt = pInp->value_min; + } + } + + PrintfSJIS( pInp->pos_x, pInp->pos_y, TXT_COLOR_WHITE, "%02d", old ); + PrintfSJIS( pInp->pos_x, pInp->pos_y, TXT_COLOR_GREEN, "%02d", *pTgt ); + // ΏےlnCCg\ +} + + +// RTCݒ̃NA +void ClearRTC( void ) +{ + RTCDate date = { 0, 1, 1, RTC_WEEK_SUNDAY }; + RTCTime time = { 0, 0, 0 }; + (void)RTC_SetDateTime( &date, &time ); + LCFG_TSD_SetFlagDateTime( TRUE ); + LCFG_TSD_SetRTCOffset( 0 ); + LCFG_TSD_SetRTCLastSetYear( 0 ); + // :::::::::::::::::::::::::::::::::::::::::::::: + // TWLݒf[^t@Cւ̏ + // :::::::::::::::::::::::::::::::::::::::::::::: + (void)LCFG_WriteTWLSettings(); +} diff --git a/build/systemMenu_RED/MachineSettings/Makefile b/build/systemMenu_RED/MachineSettings/Makefile new file mode 100644 index 00000000..9cf34e12 --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/MachineSettings/banner/Makefile b/build/systemMenu_RED/MachineSettings/banner/Makefile new file mode 100644 index 00000000..ea261271 --- /dev/null +++ b/build/systemMenu_RED/MachineSettings/banner/Makefile @@ -0,0 +1,49 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/systemMenu_RED/MachineSettings/banner/banner_v3.bsf b/build/systemMenu_RED/MachineSettings/banner/banner_v3.bsf new file mode 100644 index 00000000..c5a4f1d1 Binary files /dev/null and b/build/systemMenu_RED/MachineSettings/banner/banner_v3.bsf differ diff --git a/build/systemMenu_RED/MachineSettings/banner/icon/gameIcon.bmp b/build/systemMenu_RED/MachineSettings/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..1a7a4012 Binary files /dev/null and b/build/systemMenu_RED/MachineSettings/banner/icon/gameIcon.bmp differ diff --git a/build/systemMenu_RED/Makefile b/build/systemMenu_RED/Makefile new file mode 100644 index 00000000..f070f4ca --- /dev/null +++ b/build/systemMenu_RED/Makefile @@ -0,0 +1,32 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS_P = launcher MachineSettings PictoChat HWInfoWriter \ + NandInitializer + #DS_DownloadPlay + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/Makefile b/build/systemMenu_RED/NandInitializer/ARM7.TWL/Makefile new file mode 100644 index 00000000..cbd06120 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/Makefile @@ -0,0 +1,68 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - tests - camera-test +# 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-12-18#$ +# $Rev: 3150 $ +# $Author: yutaka $ +#---------------------------------------------------------------------------- + +SUBDIRS = + + +#---------------------------------------------------------------------------- +TARGET_PLATFORM := TWL +#TWL_CODEGEN = THUMB +TWL_PROC = ARM7 +TWL_ARCHGEN = LIMITED + +TARGET_TEF = main.tef + +SRCS = main.c kami_pxi.c formatter.c nvram_misc.c + +LINCLUDES = ../common/include $(TWLSDK_ROOT)/build/libraries/spi/ARM7/include + + +#SRCDIR = # using default +#LCFILE = # using default + +LCFILE_SPEC = main.lsf +LCFILE_TEMPLATE = racoon.lcf.template +LDRES_TEMPLATE = racoon.response.template + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +ifdef TWLSDK_NOCRYPTO +CCFLAGS += -DSDK_NOCRYPTO +endif + +ifndef TWLSDK_NOCRYPTO +MAKELCF_FLAGS += -DUSE_CRYPTO_LIBS='libaes_sp$(TWL_LIBSUFFIX).a' +endif + + +TWL_LIBS_EX = libcamera_sp$(TWL_LIBSUFFIX).a \ + libfatfs_sp$(TWL_LIBSUFFIX).a \ + libi2c_sp$(TWL_LIBSUFFIX).a \ + libcamera_sp$(TWL_LIBSUFFIX).a \ + libcdc_sp$(TWL_LIBSUFFIX).a \ + libtpex_sp$(TWL_LIBSUFFIX).a + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/include/formatter.h b/build/systemMenu_RED/NandInitializer/ARM7.TWL/include/formatter.h new file mode 100644 index 00000000..d9d10e4b --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/include/formatter.h @@ -0,0 +1,49 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: formatter.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ +#ifndef NAND_INITIALIZER_FORMATTER_H_ +#define NAND_INITIALIZER_FORMATTER_H_ + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +typedef enum { + FORMAT_MODE_QUICK, // QuicktH[}bg + FORMAT_MODE_FULL // FulltH[}bg(ep[eBV0xFFŖ߂j +} FormatMode; + + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +BOOL ExeFormat(FormatMode format_mode); + +/*===========================================================================*/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* NAND_INITIALIZER_FORMATTER_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/include/kami_pxi.h b/build/systemMenu_RED/NandInitializer/ARM7.TWL/include/kami_pxi.h new file mode 100644 index 00000000..ff2df9b6 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/include/kami_pxi.h @@ -0,0 +1,44 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_pxi.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef TWL_CAMERA_TEST_CAMERATEST_H_ +#define TWL_CAMERA_TEST_CAMERATEST_H_ + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +void KamiPxiInit( void ); + +/*===========================================================================*/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* TWL_CAMERA_TEST_CAMERATEST_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/include/nvram.h b/build/systemMenu_RED/NandInitializer/ARM7.TWL/include/nvram.h new file mode 100644 index 00000000..bc65d2df --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/include/nvram.h @@ -0,0 +1,43 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: nvram.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_NVRAM_H_ +#define FIRM_NVRAM_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SDK_ARM9 +#else // SDK_ARM7 + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +void NVRAMi_Read(u32 address, void *buf, u32 size); +void NVRAMi_Write(u32 address, void *buf, u32 size); + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_NVRAM_H_ */ +#endif diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/main.lsf b/build/systemMenu_RED/NandInitializer/ARM7.TWL/main.lsf new file mode 100644 index 00000000..82394109 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/main.lsf @@ -0,0 +1,156 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - components - racoon.TWL +# File: racoon.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-12-11#$ +# $Rev: 2989 $ +# $Author: terui $ +#---------------------------------------------------------------------------- +# +# Nitro LCF SPEC FILE +# +#-------- +Static $(TARGET_NAME) +{ + Address 0x02380000 + Library crt0.LTD.TWL.o + StackSize 1024 1024 +} + +#-------- +Autoload WRAM +{ + Address 0x037c0000 + + Library libsubpsyscall.a \ + libsyscall_sp.twl.a \ + $(CW_LIBS) \ + libos_sp$(LIBSUFFIX).a \ + libmi_sp$(LIBSUFFIX).a \ + libpad_sp$(LIBSUFFIX).a \ + libpxi_sp$(LIBSUFFIX).a \ + libstd_sp$(LIBSUFFIX).a \ + libexi_sp$(LIBSUFFIX).a \ + libsnd_sp$(LIBSUFFIX).a \ + libspi_sp$(LIBSUFFIX).a \ + libpm_sp$(LIBSUFFIX).a \ + libmath_sp$(LIBSUFFIX).a \ + libscfg_sp$(LIBSUFFIX).a \ + libtp_sp$(LIBSUFFIX).a \ + libmic_sp$(LIBSUFFIX).a \ + libfs_sp$(LIBSUFFIX).a \ + libcard_sp$(LIBSUFFIX).a \ + libi2c_sp$(LIBSUFFIX).a \ + libcamera_sp$(LIBSUFFIX).a \ + libcdc_sp$(LIBSUFFIX).a \ + libsndex_sp$(LIBSUFFIX).a \ + libtpex_sp$(LIBSUFFIX).a \ + libmicex_sp$(LIBSUFFIX).a \ + libmcu_sp$(LIBSUFFIX).a \ + + Library libsdio_sp$(LIBSUFFIX).a + + Object * (.etable) + Object * (.wram) + Object * (.ltdwram) + Object $(OBJDIR)/main.o + Object $(OBJDIR)/kami_pxi.o + Object $(OBJDIR)/formatter.o + Object $(OBJDIR)/nvram_misc.o + + # caches in fatfs library, that should be on WRAM. + # 2007/12/11 OBJECT() ɂ .bss V{̃N܂Ȃ̂ŁA + # ϐ`ӏ pragma .ltdwram ZNVɊ܂܂悤Ɏb΍􂵂܂B + #Object OBJECT( FATFSi___mem_drives_structures , libfatfs_sp$(LIBSUFFIX).a) (.bss) + + ##### + # Sub-routines in WL library , that should be on WRAM. + # in TaskMan.o + Object OBJECT( MainTaskRoutine , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AddTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( DeleteTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( LowestIdleTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ExecuteMessage , libwl_sp$(LIBSUFFIX).a ) (.text) + # in BufMan.o + Object OBJECT( NewHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( DeleteHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AllocateHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ReleaseHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( MoveHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AddHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( GetHeapBufNextAdrs , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlCmdIf.o + Object OBJECT( RequestCmdTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SendMessageToWmDirect , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlNic.o + Object OBJECT( WStart , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WStop , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WSetStaState , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlIntr.o + Object OBJECT( WlIntr , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrPreTbtt , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTbtt , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrActEnd , libwl_sp$(LIBSUFFIX).a ) (.text) +# Object OBJECT( WlIntrAckCntOvf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrCntOvf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxErr , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxCntup , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrMpEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrStartTx , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrStartRx , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SetParentTbttTxq , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( MacBugTxMp , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AdjustRingPointer , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( CheckKeyTxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlIntrTask.o + Object OBJECT( WlIntrTxBeaconTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrMpEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SetParentTbttTxqTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( TakeoutRxFrame , libwl_sp$(LIBSUFFIX).a ) (.text) + # in TxCtrl.o + Object OBJECT( InitTxCtrl , libwl_sp$(LIBSUFFIX).a ) (.text) + # in RxCtrl.o + Object OBJECT( InitRxCtrl , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WaitLoop.o + Object OBJECT( WaitLoop_Rxpe , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_Waitus , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_ClrAid , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_BbpAccess , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_RfAccess , libwl_sp$(LIBSUFFIX).a ) (.text) + +} + + + +#-------- +Ltdautoload LTDMAIN +{ + Address 0x02f88000 + + Object * (.ltdmain) + Library libnvram_sp$(LIBSUFFIX).a + Library librtc_sp$(LIBSUFFIX).a + Library libwm_sp$(LIBSUFFIX).a \ + libnwm_sp$(LIBSUFFIX).a \ + libathdrv_sp$(LIBSUFFIX).a \ + libwvr_sp$(LIBSUFFIX).a \ + libwl_sp$(LIBSUFFIX).a + Library libfatfs_sp$(LIBSUFFIX).a \ + $(USE_CRYPTO_LIBS) + Library $(ISDBG_LIBS_TWL) + Library $(ISDBG_LIBS_NITRO) + Library libstubsistd_sp.TWL.LTD.a \ + libstubsisd_sp.TWL.LTD.a +} diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/racoon.lcf.template b/build/systemMenu_RED/NandInitializer/ARM7.TWL/racoon.lcf.template new file mode 100644 index 00000000..5e629531 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/racoon.lcf.template @@ -0,0 +1,930 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - components - racoon.TWL +# File: racoon.lcf.template +# +# 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-11-12#$ +# $Rev: 2249 $ +# $Author: terui $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.WORKRAM (RWX) : ORIGIN = 0x037c0000, LENGTH = 0x50000 > workram.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDMAIN (RWX) : ORIGIN = 0x02f88000, LENGTH = 0x74000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.WRAM.START = 0x037c0000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = . + SDK_AUTOLOAD.WRAM.BSS_END - SDK_AUTOLOAD.WRAM.START + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = 0x02f88000; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + +#### SDK_LTDAUTOLOAD.LTDWRAM.START ̈ʒu͊ԈĂ邩 + SDK_LTDAUTOLOAD.LTDWRAM.START = 0x03800000; + SDK_LTDAUTOLOAD.LTDWRAM.END = SDK_LTDAUTOLOAD.LTDWRAM.START; + SDK_LTDAUTOLOAD.LTDWRAM.BSS_END = SDK_LTDAUTOLOAD.LTDWRAM.START; + SDK_LTDAUTOLOAD.LTDWRAM.SIZE = 0; + SDK_LTDAUTOLOAD.LTDWRAM.BSS_SIZE = 0; +#### + + SDK_LTDAUTOLOAD_TOP_START = 0x02e80000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + SDK_LTDAUTOLOAD_LTDWRAM_START = SDK_LTDAUTOLOAD.LTDWRAM.START; + SDK_LTDAUTOLOAD_LTDWRAM_END = SDK_LTDAUTOLOAD.LTDWRAM.END; + SDK_LTDAUTOLOAD_LTDWRAM_BSS_END = SDK_LTDAUTOLOAD.LTDWRAM.BSS_END; + SDK_LTDAUTOLOAD_LTDWRAM_SIZE = SDK_LTDAUTOLOAD.LTDWRAM.SIZE; + SDK_LTDAUTOLOAD_LTDWRAM_BSS_SIZE = SDK_LTDAUTOLOAD.LTDWRAM.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + .check.LTDMAIN: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.LTDMAIN + +} diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/racoon.response.template b/build/systemMenu_RED/NandInitializer/ARM7.TWL/racoon.response.template new file mode 100644 index 00000000..88b18081 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/racoon.response.template @@ -0,0 +1,40 @@ + + + + + -l + + + + + + + -l + + + + -og ,0 -ol + + + + + -l + + + + + + + + -l + + + + -og ,0 -ol + + + + + -l + + diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/formatter.c b/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/formatter.c new file mode 100644 index 00000000..e0354465 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/formatter.c @@ -0,0 +1,420 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: formatter.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "formatter.h" + +extern BOOL FATFSi_nandFillPartition( int partition_no, u32* buf, u32 blocks); + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +typedef struct FileProperty { + u32 length; + const char *path; +}FileProperty; + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define ERROR_RETURN() { OS_TPrintf("FATAL ERROR OCCURED %s %s\n", __FILE__, __LINE__); return 0; } + +// ҏWASDKFATFS_Init̓p[^CKvB +#define NAND_SIZE 245 // 256MB mobiNANDł̎gp”\TCYiiNANDł͈ႤlɂȂBBj +#define PARTITION_RAW_SIZE 4 +#define PARTITION_0_SIZE 213 +#define PARTITION_1_SIZE ( NAND_SIZE - PARTITION_RAW_SIZE - PARTITION_0_SIZE ) +#define NAND_FAT_PARTITION_NUM 2 // FATp[eBViRAWp[eBVj + + +// const data-------------------------------------------------------- +//#define NAND_SEPARATE_READ +#define FS_READ_BLOCK_SIZE ( 2 * 1024 ) +#define FATFS_CLUSTER_SIZE ( 16 * 1024 ) +// FATFS̃NX^TCY16KBȂ̂ŁAf[^TCY܂ĂȂ̂́A]T16KBɂĂ +static const FileProperty s_fileList[] = { + { 128, "F:/sys/ID.sgn" }, // ASTCY͓KBgB + { FATFS_CLUSTER_SIZE, "F:/sys/HWINFO.dat" }, + { FATFS_CLUSTER_SIZE, "F:/shared1/TWLCFG0.dat" }, + { FATFS_CLUSTER_SIZE, "F:/shared1/TWLCFG1.dat" }, // ~[ +// { FATFS_CLUSTER_SIZE, "F:/shared1/WIFICFG0.dat" }, +// { FATFS_CLUSTER_SIZE, "F:/shared1/WIFICFG1.dat" }, // ~[ + { 0, NULL }, +}; + +static const char *s_pDirList0[] = { + (const char *)"sys", + (const char *)"title", + (const char *)"ticket", + (const char *)"shared1", + (const char *)"import", + (const char *)"tmp", + NULL, + }; + +static const char *s_pDirList1[] = { + (const char *)"photo", + (const char *)"shared2", + NULL, + }; + +/*---------------------------------------------------------------------------* + ֐錾 + *---------------------------------------------------------------------------*/ + +static BOOL CreateDirectory( const char *pDrive, const char **ppDirList ); +static BOOL CheckDirectory ( const char *pDrive, const char **ppDirList ); +static BOOL CreateFile( const FileProperty *pFileList ); +static BOOL CheckFile ( const FileProperty *pFileList ); +static int MY_ReadFile( FATFSFileHandle file, void *pBuffer, int length ); + +/*---------------------------------------------------------------------------* + Name: ExeFormat + + Description: Nand̃tH[}bgs܂ + + Arguments: + + Returns: None. + *---------------------------------------------------------------------------*/ +BOOL +ExeFormat(FormatMode format_mode) +{ + u32 *init_datbuf; + int nand_fat_partition_num; + + init_datbuf = OS_Alloc( 512*16 ); + if( init_datbuf == NULL ) { + OS_TPrintf( "memory allocate error.\n" ); + ERROR_RETURN(); + } + + MI_CpuFill8( init_datbuf, 0xFF, 512*16); + + // NANDtH[}bg + { + int i; + + /* p[eBVTCYvvgݒ */ + u32 partition_MB_size[5]; + partition_MB_size[0] = PARTITION_RAW_SIZE; // RAẄ + partition_MB_size[1] = PARTITION_0_SIZE; // FAT0̈ + partition_MB_size[2] = PARTITION_1_SIZE; // FAT1̈ + nand_fat_partition_num = NAND_FAT_PARTITION_NUM; + + // F G hCuA}Eg + for( i=0; ipath ) { + if( length < pTemp->length ) { + length = pTemp->length; + } + pTemp++; + } + pBuffer = OS_Alloc( length ); + if( pBuffer == NULL ) { + OS_TPrintf( "memory allocate error.\n" ); + ERROR_RETURN(); + } + MI_CpuClearFast( pBuffer, length ); + + OS_TPrintf( "\nCreate File :\n" ); + + // w肳ꂽt@C쐬āA"0" + while( pFileList->path ) { + FATFSFileHandle file; + + OS_TPrintf( " %s, %dbytes...", pFileList->path, pFileList->length ); + // t@C + if( !FATFS_CreateFile( pFileList->path, TRUE, "rwxrwxrwx" ) ) { + OS_TPrintf( "ng.\n" ); + ERROR_RETURN(); + } + // t@CI[v + file = FATFS_OpenFile( pFileList->path, "w" ); + if( !file ) { + OS_TPrintf( "ng.\n" ); + ERROR_RETURN(); + } + // t@CύX + if( !FATFS_SetFileLength( file, (int)pFileList->length ) ) { + OS_TPrintf( "ng.\n" ); + ERROR_RETURN(); + } + // t@C + if( !FATFS_WriteFile( file, pBuffer, (int)pFileList->length ) ) { + OS_TPrintf( "ng.\n" ); + ERROR_RETURN(); + } + // t@CN[Y + (void)FATFS_CloseFile( file ); + OS_TPrintf( "ok.\n" ); + pFileList++; + } + // + OS_Free( pBuffer ); + + return TRUE; +} + + +// t@C`FbN +static BOOL CheckFile( const FileProperty *pFileList ) +{ + // ftHghCu̎w + OS_TPrintf( "\nCheck File :\n" ); + + // w肳ꂽfBNg[gɍ쐬 + while( pFileList->path ) { + FATFSFileHandle file; + u32 *pBuffer; + int i; + OSTick start; + + OS_TPrintf( " %s, %dbytes...", pFileList->path, pFileList->length ); + // t@CI[v + file = FATFS_OpenFile( pFileList->path, "r+" ); + if( !file ) { + OS_TPrintf( "ng.\n" ); + ERROR_RETURN(); + } + // t@C`FbN + if( FATFS_GetFileLength( file ) != pFileList->length ) { + OS_TPrintf( "ng. length = %d\n", FATFS_GetFileLength( file ) ); + ERROR_RETURN(); + } + // obt@ m + pBuffer = OS_Alloc( pFileList->length ); + if( pBuffer == NULL ) { + OS_TPrintf( "memory allocate error.\n" ); + ERROR_RETURN(); + } + start = OS_GetTick(); + // t@Cǂݍ + if( +#ifdef NAND_SEPARATE_READ + MY_ReadFile( file, pBuffer, (int)pFileList->length ) +#else + FATFS_ReadFile( file, pBuffer, (int)pFileList->length ) +#endif + != pFileList->length ) { + OS_TPrintf( "ng.\n" ); + ERROR_RETURN(); + } + OS_TPrintf( " [ReadTime : %dms] ", OS_TicksToMilliSeconds( OS_GetTick() - start ) ); + start = OS_GetTick(); + // t@Cxt@C + for( i = 0; i < pFileList->length / sizeof(u32); i++ ) { + if( pBuffer[ i ] != 0 ) { + OS_TPrintf( "ng.\n" ); + ERROR_RETURN(); + } + } + OS_TPrintf( " [VerifyTime : %dms] ", OS_TicksToMilliSeconds( OS_GetTick() - start ) ); + // + OS_Free( pBuffer ); + // t@CN[Y + (void)FATFS_CloseFile( file ); + OS_TPrintf( "ok.\n" ); + pFileList++; + } + + return TRUE; +} + +#ifdef NAND_SEPARATE_READ +// NANDsARM7FS͋zꂢĂȂ̂ŁAO2KBPʂɕă[h +static int MY_ReadFile( FATFSFileHandle file, void *pBuffer, int length ) +{ + int length_bak = length; + while( length ) { + int rdLength = ( length > FS_READ_BLOCK_SIZE ) ? FS_READ_BLOCK_SIZE : length; + + if( FATFS_ReadFile( file, pBuffer, rdLength ) != rdLength ) { + return -1; + } + pBuffer = (u8 *)pBuffer + rdLength; + length -= rdLength; + } + return length_bak; +} +#endif diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/kami_pxi.c b/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/kami_pxi.c new file mode 100644 index 00000000..87515a83 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/kami_pxi.c @@ -0,0 +1,290 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_pxi.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "kami_pxi.h" +#include "fifo.h" +#include "twl/cdc.h" +#include "formatter.h" +#include "nvram.h" + +#include + +//#include +//#include + + +typedef unsigned char byte; /* Don't change */ +typedef unsigned short word; /* Don't change */ +typedef unsigned long dword; /* Don't change */ +#define BOOLEAN int + +extern BOOL FATFSi_nandRtfsIo( int driveno, dword block, void* buffer, word count, BOOLEAN reading); + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ +#define KAMITEST_MESSAGE_ARRAY_MAX 4 // XbhpbZ[WL[̃TCY +#define KAMITEST_THREAD_STACK_SIZE 2048 // Xbh̃X^bNTCY + +#define KAMITEST_THREAD_PRIORITY 6 + +// ACgăRs[ +#define KAMI_UNPACK_U16(d, s) \ + (*(d) = (u16)((((u8*)s)[0] << 0) | (((u8*)s)[1] << 8))) +#define KAMI_UNPACK_U32(d, s) \ + (*(d) = (u32)((((u8*)s)[0] << 0) | (((u8*)s)[1] << 8) | (((u8*)s)[2] << 16) | (((u8*)s)[3] << 24))) + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ +typedef struct KamiWork +{ + BOOL result; + u32 total; + u32 current; + KamiCommand command; + u8 data[KAMITEST_PXI_DATA_SIZE_MAX]; // 㑱f[^i[p + + OSMessageQueue msgQ; // XbhpbZ[WL[ + OSMessage msgArray[KAMITEST_MESSAGE_ARRAY_MAX]; + // bZ[Wi[obt@ + OSThread thread; // KAMIpXbh + u64 stack[KAMITEST_THREAD_STACK_SIZE / sizeof(u64)]; + // KAMIpXbh̃X^bN +} +KamiWork; + +/*---------------------------------------------------------------------------* + ÓIϐ` + *---------------------------------------------------------------------------*/ +static BOOL kamiInitialized; +static KamiWork kamiWork; + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +static void KamiPxiCallback(PXIFifoTag tag, u32 data, BOOL err); +static void KamiReturnResult(KamiCommand command, KAMIPxiResult result); +static void KamiReturnResultEx(KamiCommand command, KAMIPxiResult result, u8 size, u8* data); +static void KamiThread(void *arg); + +void KamiPxiInit(void) +{ + if (kamiInitialized) + { + return; + } + kamiInitialized = TRUE; + + PXI_Init(); + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_KAMITEST, KamiPxiCallback); + + OS_InitMessageQueue(&kamiWork.msgQ, kamiWork.msgArray, KAMITEST_MESSAGE_ARRAY_MAX); + OS_CreateThread(&kamiWork.thread, KamiThread, 0, + (void *)(kamiWork.stack + (KAMITEST_THREAD_STACK_SIZE / sizeof(u64))), + KAMITEST_THREAD_STACK_SIZE, KAMITEST_THREAD_PRIORITY); + OS_WakeupThreadDirect(&kamiWork.thread); +} + +static void KamiPxiCallback(PXIFifoTag tag, u32 data, BOOL err) +{ +#pragma unused( tag ) + if (err) + { + return; + } + if (data & KAMITEST_PXI_START_BIT) // 擪f[^ + { + kamiWork.total = (u8)((data & KAMITEST_PXI_DATA_NUMS_MASK) >> KAMITEST_PXI_DATA_NUMS_SHIFT); + kamiWork.current = 0; + kamiWork.command = (KamiCommand)((data & KAMITEST_PXI_COMMAND_MASK) >> KAMITEST_PXI_COMMAND_SHIFT); + kamiWork.data[kamiWork.current++] = (u8)((data & KAMITEST_PXI_1ST_DATA_MASK) >> KAMITEST_PXI_1ST_DATA_SHIFT); + } + else // 㑱f[^ + { + kamiWork.data[kamiWork.current++] = (u8)((data & 0xFF0000) >> 16); + kamiWork.data[kamiWork.current++] = (u8)((data & 0x00FF00) >> 8); + kamiWork.data[kamiWork.current++] = (u8)((data & 0x0000FF) >> 0); + } + if (kamiWork.current >= kamiWork.total) + { + switch (kamiWork.command) + { + case CODEC_READ_REGISTER: + case CODEC_WRITE_REGISTER: + case GPIO333_WRITE: + case EXE_FORMAT: + case KAMI_NAND_IO: + case KAMI_NVRAM_IO: + if (!OS_SendMessage(&kamiWork.msgQ, NULL, OS_MESSAGE_NOBLOCK)) + { + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_FATAL_ERROR); + } + break; + + default: + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_INVALID_COMMAND); + } + } +} + +static void KamiReturnResult(KamiCommand command, KAMIPxiResult result) +{ + u32 pxiData = (u32)(KAMITEST_PXI_START_BIT | KAMITEST_PXI_RESULT_BIT | + ((command << KAMITEST_PXI_COMMAND_SHIFT) & KAMITEST_PXI_COMMAND_MASK) | + ((1 << KAMITEST_PXI_DATA_NUMS_SHIFT) & KAMITEST_PXI_DATA_NUMS_MASK) | + ((result << KAMITEST_PXI_1ST_DATA_SHIFT) & KAMITEST_PXI_1ST_DATA_MASK)); + while (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, pxiData, 0)) + { + } +} + +static void KamiReturnResultEx(KamiCommand command, KAMIPxiResult result, u8 size, u8* data) +{ + u32 pxiData = (u32)(KAMITEST_PXI_START_BIT | KAMITEST_PXI_RESULT_BIT | + ((command << KAMITEST_PXI_COMMAND_SHIFT) & KAMITEST_PXI_COMMAND_MASK) | + (((size+1) << KAMITEST_PXI_DATA_NUMS_SHIFT) & KAMITEST_PXI_DATA_NUMS_MASK) | + ((result << KAMITEST_PXI_1ST_DATA_SHIFT) & KAMITEST_PXI_1ST_DATA_MASK)); + int i; + while (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, pxiData, 0)) + { + } + for (i = 0; i < size; i+= 3) + { + pxiData = (u32)((data[i] << 16) | (data[i+1] << 8) | data[i+2]); + while (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, pxiData, 0)) + { + } + } +} + +static void KamiThread(void *arg) +{ +#pragma unused( arg ) + OSMessage msg; + BOOL result; + + while (TRUE) + { + (void)OS_ReceiveMessage(&kamiWork.msgQ, &msg, OS_MESSAGE_BLOCK); + switch (kamiWork.command) + { +//////////////////////////////////////////////////////// + case CODEC_READ_REGISTER: + { + u8 value; + value = CDC_ReadSpiRegisterEx( kamiWork.data[0], kamiWork.data[1] ); + KamiReturnResultEx(kamiWork.command, KAMI_PXI_RESULT_SUCCESS, sizeof(u8), (u8*)&value); + } + break; + + case CODEC_WRITE_REGISTER: + { + CDC_WriteSpiRegisterEx( kamiWork.data[0], kamiWork.data[1], kamiWork.data[2] ); + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS); + } + break; + + case GPIO333_WRITE: + { + if (kamiWork.data[0]) + { + // GPIO333 1o + EXI2i_SetBitGpio2CntL(0x8080, 0x8080); + } + else + { + // GPIO333 0o + EXI2i_SetBitGpio2CntL(0x8080, 0x8000); + } + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS); + } + break; + + case EXE_FORMAT: + { + result = ExeFormat((FormatMode)kamiWork.data[0]); // Quick or Full + if (result) + { + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS_TRUE); + } + else + { + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS_FALSE); + } + } + break; + + case KAMI_NAND_IO: + { + BOOL is_read; + u32 block; + void* buffer; + u32 count; + + is_read = (BOOL)kamiWork.data[0]; + KAMI_UNPACK_U32(&block, &kamiWork.data[1]); + KAMI_UNPACK_U32((u32 *)(&buffer), &kamiWork.data[5]); + KAMI_UNPACK_U32(&count, &kamiWork.data[9]); + + result = FATFSi_nandRtfsIo( 0, block, buffer, (u16)count, is_read ); + if (result) + { + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS_TRUE); + } + else + { + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS_FALSE); + } + } + break; + + case KAMI_NVRAM_IO: + { + BOOL is_read; + u32 adress; + void* buffer; + u32 size; + + is_read = (BOOL)kamiWork.data[0]; + KAMI_UNPACK_U32(&adress, &kamiWork.data[1]); + KAMI_UNPACK_U32((u32 *)(&buffer), &kamiWork.data[5]); + KAMI_UNPACK_U32(&size, &kamiWork.data[9]); + + if (is_read) + { + NVRAMi_Read( adress, buffer, size ); + } + else + { + NVRAMi_Write( adress, buffer, size ); + } + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS); + } + break; + +//////////////////////////////////////////////////////// + + default: + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_INVALID_COMMAND); + } + } +} + +#include diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/main.c b/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/main.c new file mode 100644 index 00000000..2018c20b --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/main.c @@ -0,0 +1,413 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: main.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kami_pxi.h" +#include "formatter.h" + +/* Priorities of each threads */ +#define THREAD_PRIO_SPI 2 +#define THREAD_PRIO_SND 6 +#define THREAD_PRIO_FATFS 8 +#define THREAD_PRIO_RTC 12 +#define THREAD_PRIO_FS 15 +/* OS_THREAD_LAUNCHER_PRIORITY 16 */ + +extern void PMi_InitShutdownControl(void); + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +static OSHeapHandle InitializeAllocateSystem(void); +static void VBlankIntr(void); +static void InitializeFatfs(void); +static void InitializeCdc(void); +static void DummyThread(void* arg); + +/*---------------------------------------------------------------------------* + OV{Q + *---------------------------------------------------------------------------*/ +#ifdef SDK_TWLHYB +extern void SDK_LTDAUTOLOAD_LTDWRAM_BSS_END(void); +extern void SDK_LTDAUTOLOAD_LTDMAIN_BSS_END(void); +#endif + +/*---------------------------------------------------------------------------* + Name: TwlSpMain + + Description: Initialize and do main + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void TwlSpMain(void) +{ + OSThread thread; + u32 stack[18]; + + // OS + OS_Init(); + SPI_Init(2); + OS_InitTick(); + OS_InitAlarm(); + OS_InitThread(); +// (void)PAD_InitXYButton(); + + // q[v̈ݒ + InitializeAllocateSystem(); + + // {^̓T[` + (void)PAD_InitXYButton(); + + // 荞݋ + (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + // _~[Xbh쐬(CDC_InitFS_InitOS_SleepgpĂ邽߁j + OS_CreateThread(&thread, DummyThread, NULL, + (void*)((u32)stack + (sizeof(u32) * 18)), sizeof(u32) * 18, OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&thread); + + // t@CVXe + FS_Init(FS_DMA_NOT_USE); + FS_CreateReadServerThread(THREAD_PRIO_FS); + + if (OS_IsRunOnTwl() == TRUE) + { + InitializeFatfs(); // FATFS + //InitializeNwm(); // NWM +#ifndef SDK_NOCRYPTO + AES_Init(); // AES +#endif + } + + if (OSi_IsCodecTwlMode() == TRUE) + { + // CODEC + InitializeCdc(); + // J + //CAMERA_Init(); + /* CODEC TWL [hłȂƃVb^[Iɖ‚炷 + @\gpł܂Bׁ̈ACODEC TWL [h̏ꍇ + ɂ̂݃JCugp”\ȏԂɂ܂B */ + } + + // TEh + SND_Init(THREAD_PRIO_SND); + + // RTC + RTC_Init(THREAD_PRIO_RTC); + + // + //WVR_Begin(heapHandle); + + // SPI + SPI_Init(THREAD_PRIO_SPI); + + + KamiPxiInit(); + + // _~[Xbhj + OS_KillThread(&thread, NULL); + + while (TRUE) + { + OS_Halt(); + //---- check reset + if (OS_IsResetOccurred()) + { + OS_ResetSystem(); + } + } + + +} +#include +/*---------------------------------------------------------------------------* + Name: InitializeFatfs + Description: FATFSCuB + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeFatfs(void) +{ + OSThread thread; + u32 stack[18]; + + // _~[Xbh쐬 + OS_CreateThread(&thread, DummyThread, NULL, + (void*)((u32)stack + (sizeof(u32) * 18)), sizeof(u32) * 18, OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&thread); + + // FATFSCȕ +#ifndef SDK_NOCRYPTO +#ifdef FATFS_AES_MOUNT_FOR_NAND + if(!FATFS_Init( FATFS_DMA_4, FATFS_DMA_NOT_USE, THREAD_PRIO_FATFS)) +#else + if (FATFS_Init(FATFS_DMA_NOT_USE, FATFS_DMA_NOT_USE, THREAD_PRIO_FATFS)) +#endif +#else + if (FATFS_Init(FATFS_DMA_NOT_USE, FATFS_DMA_NOT_USE, THREAD_PRIO_FATFS)) +#endif + { + // do nothing + } + + // _~[Xbhj + OS_KillThread(&thread, NULL); +} +#include + +#include +/*---------------------------------------------------------------------------* + Name: InitializeCdc + Description: CDCCuBCDC֐ŃXbhx~ + ׁAx~삷_~[̃Xbh𗧂ĂB + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeCdc(void) +{ +#if 1 + // CODEC + CDC_Init(); + CDC_InitMic(); +// CDCi_DumpRegisters(); +#else + /* [Debug] CODEC DS [hŏ */ + *((u8*)(HW_TWL_ROM_HEADER_BUF + 0x01bf)) &= ~(0x01); + CDC_Init(); + CDC_GoDsMode(); + OS_TPrintf("Codec mode changed to DS mode for debug.\n"); +#endif +} + +/*---------------------------------------------------------------------------* + Name: DummyThread + Description: CDCCuۂɗĂ_~[̃XbhB + Arguments: arg - gpȂB + Returns: None. + *---------------------------------------------------------------------------*/ +static void +DummyThread(void* arg) +{ +#pragma unused(arg) + while (TRUE) + { + } +} +#include + +/*---------------------------------------------------------------------------* + Name: InitializeAllocateSystem + Description: ăVXeB + Arguments: None. + Returns: OSHeapHandle - WRAM A[iɊmۂꂽq[ṽnhԂB + *---------------------------------------------------------------------------*/ +static OSHeapHandle +InitializeAllocateSystem(void){ + OSHeapHandle hh; + +#ifdef SDK_TWLHYB + if (OS_IsRunOnTwl() == TRUE) + { + void* basicLo = (void*)OS_GetSubPrivArenaLo(); + void* basicHi = (void*)OS_GetSubPrivArenaHi(); + void* extraLo = (void*)MATH_ROUNDUP((u32)SDK_LTDAUTOLOAD_LTDMAIN_BSS_END, 32); + void* extraHi = (void*)MATH_ROUNDDOWN(HW_MAIN_MEM_SUB, 32); + +#if SDK_DEBUG + // debug information + OS_TPrintf("ARM7: MAIN arena basicLo = %p\n", basicLo); + OS_TPrintf("ARM7: MAIN arena basicHi = %p\n", basicHi); + OS_TPrintf("ARM7: MAIN arena extraLo = %p\n", extraLo); + OS_TPrintf("ARM7: MAIN arena extraHi = %p\n", extraHi); +#endif + + // A[i 0 NA + MI_CpuClear8(basicLo, (u32)basicHi - (u32)basicLo); + MI_CpuClear8(extraLo, (u32)extraHi - (u32)extraLo); + + // 蓖ď + if ((u32)basicLo < (u32)extraLo) + { + basicLo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, basicLo, extraHi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_MAIN_SUBPRIV, basicLo); + } + else + { + extraLo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, extraLo, basicHi, 1); + } + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_MAIN_SUBPRIV, basicLo, basicHi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to create MAIN heap.\n"); + } + + // q[vɊgubNlj + OS_AddToHeap(OS_ARENA_MAIN_SUBPRIV, hh, extraLo, extraHi); + } + else +#endif + { + void* lo = (void*)OS_GetSubPrivArenaLo(); + void* hi = (void*)OS_GetSubPrivArenaHi(); + + // A[i 0 NA + MI_CpuClear8(lo, (u32)hi - (u32)lo); + + // 蓖ď + lo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, lo, hi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_MAIN_SUBPRIV, lo); + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_MAIN_SUBPRIV, lo, hi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to MAIN create heap.\n"); + } + } + // Jgq[vɐݒ + (void)OS_SetCurrentHeap(OS_ARENA_MAIN_SUBPRIV, hh); + // q[vTCY̊mF + { + u32 heapSize; + + heapSize = (u32)OS_CheckHeap(OS_ARENA_MAIN_SUBPRIV, hh); + OS_TPrintf("ARM7: MAIN heap size is %d\n", heapSize); + } +#ifdef SDK_TWLHYB + if (OS_IsRunOnTwl() == TRUE) + { + void* basicLo = (void*)OS_GetWramSubPrivArenaLo(); + void* basicHi = (void*)OS_GetWramSubPrivArenaHi(); + void* extraLo = (void*)MATH_ROUNDUP((u32)SDK_LTDAUTOLOAD_LTDWRAM_BSS_END, 32); + void* extraHi = (void*)MATH_ROUNDDOWN(HW_WRAM_A_HYB_END, 32); + +#if SDK_DEBUG + // debug information + OS_TPrintf("ARM7: WRAM arena basicLo = %p\n", basicLo); + OS_TPrintf("ARM7: WRAM arena basicHi = %p\n", basicHi); + OS_TPrintf("ARM7: WRAM arena extraLo = %p\n", extraLo); + OS_TPrintf("ARM7: WRAM arena extraHi = %p\n", extraHi); +#endif + + // A[i 0 NA + MI_CpuClear8(basicLo, (u32)basicHi - (u32)basicLo); + MI_CpuClear8(extraLo, (u32)extraHi - (u32)extraLo); + + // 蓖ď + if ((u32)basicLo < (u32)extraLo) + { + basicLo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV, basicLo, extraHi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_WRAM_SUBPRIV, basicLo); + } + else + { + extraLo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV, extraLo, basicHi, 1); + } + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_WRAM_SUBPRIV, basicLo, basicHi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to WRAM create heap.\n"); + } + + // q[vɊgubNlj + OS_AddToHeap(OS_ARENA_WRAM_SUBPRIV, hh, extraLo, extraHi); + } + else +#endif + { + void* lo = (void*)OS_GetWramSubPrivArenaLo(); + void* hi = (void*)OS_GetWramSubPrivArenaHi(); + + // A[i 0 NA + MI_CpuClear8(lo, (u32)hi - (u32)lo); + + // 蓖ď + lo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV, lo, hi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_WRAM_SUBPRIV, lo); + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_WRAM_SUBPRIV, lo, hi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to WRAM create heap.\n"); + } + } + + // Jgq[vɐݒ + (void)OS_SetCurrentHeap(OS_ARENA_WRAM_SUBPRIV, hh); + + // q[vTCY̊mF + { + u32 heapSize; + + heapSize = (u32)OS_CheckHeap(OS_ARENA_WRAM_SUBPRIV, hh); + if (WM_WL_HEAP_SIZE > heapSize) + { + OS_Panic("Insufficient heap size. (0x%x < 0x%x)\n", heapSize, WM_WL_HEAP_SIZE); + } + OS_TPrintf("ARM7: WRAM heap size is %d\n", heapSize); + } + + return hh; +} + +/*---------------------------------------------------------------------------* + Name: VBlankIntr + Description: V uN荞݃xN^B + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +extern BOOL PMi_Initialized; +void PM_SelfBlinkProc(void); + +static void +VBlankIntr(void) +{ + if (PMi_Initialized) + { + PM_SelfBlinkProc(); + } +} diff --git a/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/nvram_misc.c b/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/nvram_misc.c new file mode 100644 index 00000000..ad1d5412 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM7.TWL/src/nvram_misc.c @@ -0,0 +1,181 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: nvram_misc.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include "nvram.h" +#include "spi_sp.h" +#include "nvram_sp.h" + +/*---------------------------------------------------------------------------* + Name: NvramCheckReadyToRead + + Description: NVRAMǂݏo”\ȏԂǂmFB + + Arguments: None. + + Returns: BOOL - ǂݏo”\ȏԂ̏ꍇTRUEԂB + FALSȄꍇ͓ǂݏo֎~̏ԁB + *---------------------------------------------------------------------------*/ +static BOOL NvramCheckReadyToRead(void) +{ + u16 tempStatus; + + // Xe[^XWX^ǂݏo + NVRAM_ReadStatusRegister((u8 *)(&tempStatus)); + // ݂͏쒆mF + if (tempStatus & NVRAM_STATUS_REGISTER_WIP) + { + return FALSE; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: NvramCheckReadyToWrite + + Description: NVRAM݉”\ȏԂǂmFB + + Arguments: None. + + Returns: BOOL - ݉”\ȏԂ̏ꍇTRUEԂB + FALSȄꍇ͏݋֎~̏ԁB + *---------------------------------------------------------------------------*/ +static BOOL NvramCheckReadyToWrite(void) +{ + u16 tempStatus; + + // Xe[^XWX^ǂݏo + NVRAM_ReadStatusRegister((u8 *)(&tempStatus)); + // ݂͏쒆mF + if (tempStatus & NVRAM_STATUS_REGISTER_WIP) + { + return FALSE; + } + // ݋‚Ă邩mF + if (!(tempStatus & NVRAM_STATUS_REGISTER_WEL)) + { + return FALSE; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: NVRAM_WaitOperation + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void NVRAM_WaitOperation(void) +{ + while( NvramCheckReadyToRead() == FALSE ) { + } +} + +/*---------------------------------------------------------------------------* + Name: NVRAM_WaitWriteEnable + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void NVRAM_WaitWriteEnable(void) +{ + while( NvramCheckReadyToWrite() == FALSE ) { + } +} + + +/*---------------------------------------------------------------------------* + Name: NVRAMi_Read + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void NVRAMi_Read(u32 address, void *buf, u32 size) +{ + NVRAM_WaitOperation(); + NVRAM_ReadDataBytes(address, size, buf); + return; +} + + +/*---------------------------------------------------------------------------* + Name: NVRAMi_Write + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void NVRAMi_Write(u32 address, void *buf, u32 size) +{ + u32 i; + u32 page_start; + u32 page_end; + u32 offset_start; + u32 offset_end; + u8 *src_ptr; + u8 temp_buffer[SPI_NVRAM_PAGE_SIZE]; + + src_ptr = (u8 *)buf; + page_start = (address / SPI_NVRAM_PAGE_SIZE) * SPI_NVRAM_PAGE_SIZE; + page_end = ((address+size-1) / SPI_NVRAM_PAGE_SIZE ) * SPI_NVRAM_PAGE_SIZE; + offset_start = address % SPI_NVRAM_PAGE_SIZE; + offset_end = (address+size-1) % SPI_NVRAM_PAGE_SIZE; + + while( page_start <= page_end ) { + if( offset_start != 0 ) { + NVRAMi_Read(page_start, temp_buffer, offset_start); + } + if( page_start != page_end ) { + for( i = offset_start ; i < SPI_NVRAM_PAGE_SIZE ; i++ ) { + temp_buffer[i] = *src_ptr++; + } + } + else { + for( i = offset_start ; i <= offset_end ; i++ ) { + temp_buffer[i] = *src_ptr++; + } + if( offset_end != (SPI_NVRAM_PAGE_SIZE-1) ) { + NVRAMi_Read(page_start+offset_end+1, &(temp_buffer[offset_end+1]), SPI_NVRAM_PAGE_SIZE - (offset_end+1) ); + } + } + + NVRAM_WriteEnable(); + NVRAM_WaitWriteEnable(); + + NVRAM_PageErase((u32)page_start); + + NVRAM_WaitOperation(); + + NVRAM_WriteEnable(); + + NVRAM_PageWrite((u32)page_start, (u16)SPI_NVRAM_PAGE_SIZE, temp_buffer); + NVRAM_WaitOperation(); + + page_start += SPI_NVRAM_PAGE_SIZE; + offset_start = 0; + } +} diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/ARM9-TS.lsf b/build/systemMenu_RED/NandInitializer/ARM9.TWL/ARM9-TS.lsf new file mode 100644 index 00000000..55706a80 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/ARM9-TS.lsf @@ -0,0 +1,57 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-TS.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-12-05#$ +# $Rev: 2840 $ +# $Author: yosizaki $ +#---------------------------------------------------------------------------- +# +# TWL LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address $(ADDRESS_STATIC) + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) + StackSize 2048 2048 +} + +Autoload ITCM +{ + Address $(ADDRESS_ITCM) + Object * (.itcm) + Object $(OBJS_AUTOLOAD) (.text) + Object $(OBJS_AUTOLOAD) (.rodata) + Object $(OBJS_AUTOLOAD) (.init) + Object $(OBJS_AUTOLOAD) (.ctor) + Object $(OBJS_AUTOLOAD) (.sinit) +} + +Autoload DTCM +{ + Address $(ADDRESS_DTCM) + Object * (.dtcm) + Object $(OBJS_AUTOLOAD) (.data) + Object $(OBJS_AUTOLOAD) (.sdata) + Object $(OBJS_AUTOLOAD) (.bss) + Object $(OBJS_AUTOLOAD) (.sbss) +} + +Ltdautoload LTDMAIN +{ + # NITRO/TWL L̃I[o[C݂ꍇ́Aɂ̌ɔzuKv܂B + After $(TARGET_NAME) + Object * (.ltdmain) + Object $(OBJS_LTDAUTOLOAD) + Library $(LLIBS_EX) $(GLIBS_EX) +} diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/Makefile b/build/systemMenu_RED/NandInitializer/ARM9.TWL/Makefile new file mode 100644 index 00000000..03c80042 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/Makefile @@ -0,0 +1,107 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - tests - camera-test +# 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-11-28#$ +# $Rev: 2683 $ +# $Author: yutaka $ +#---------------------------------------------------------------------------- + +SUBDIRS = + + +#---------------------------------------------------------------------------- + +USE_PRODUCT_KEY = TRUE + +# if USE_PRODUCT_KEY is set, set USE_SDBOOT_KEY to boot from SDMC, otherwise to boot from CARD/NAND +#USE_SDBOOT_KEY = TRUE + +KEYS_DIR = $(shell $(CYGPATH) -m $(TWL_KEYSDIR)) + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +#TWL_CODEGEN = THUMB + +TITLEID_LO = NINI +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +TARGET_BIN = main.srl +LCFILE_SPEC = ARM9-TS.lsf +ROM_SPEC = main.rsf + +MAKEROM_ARM7_BASE = ../ARM7.TWL/bin/$(TWL_BUILDTYPE_ARM7)/main +MAKEROM_ARM7 = $(MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) + +SRCS = main.c \ + kami_pxi.c \ + font_data.c \ + graphics.c \ + keypad.c \ + kami_font.c \ + cursor.c \ + process_format.c \ + process_topmenu.c \ + process_hw_info.c \ + process_eticket.c \ + process_import.c \ + process_nandfirm.c \ + process_norfirm.c \ + process_auto.c + +LINCLUDES = ../common/include \ + $(ROOT)/build/libraries/lcfg/ARM9.TWL/include + +SRCDIR = src \ + $(ROOT)/build/demos.TWL/camera/saveShoot-1/src +#LCFILE = # using default + +MAKEROM_FLAGS += -DTITLEID_LO='$(TITLEID_LO)' \ + -DHWINFO_PRIVKEY='private_HWInfo.der' +MAKETAD_FLAGS += -s + +ifdef USE_PRODUCT_KEY +MAKEROM_FLAGS += -DPRIVKEY_PATH='$(KEYS_DIR)/rsa' +MACRO_FLAGS += -DUSE_PRODUCT_KEY +ifdef USE_SDBOOT_KEY +MAKEROM_FLAGS += -s -DSYS_PRIV_KEY='$(KEYS_DIR)/rsa/private_sdboot.der' \ + -DSYS_PUB_KEY='$(KEYS_DIR)/rsa/pubkey_sdboot.der' +TARGET_TAD= +endif +else +MAKEROM_FLAGS += -DPRIVKEY_PATH='../../../../keys/dummy/rsa' +endif + +LLIBRARIES += libes$(TWL_LIBSUFFIX).a \ + libboc$(TWL_LIBSUFFIX).a \ + libnam$(TWL_LIBSUFFIX).a \ + libacsign_enc$(TWL_LIBSUFFIX).a + + +#include $(TWLSDK_ROOT)/build/buildtools/commondefs +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs +include $(TWLSDK_ROOT)/build/buildtools/commondefs.gx.demolib + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +#include $(TWLSDK_ROOT)/build/buildtools/modulerules +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/cursor.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/cursor.h new file mode 100644 index 00000000..4765c107 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/cursor.h @@ -0,0 +1,45 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: cursor.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef KAMI_CURSOR_H_ +#define KAMI_CURSOR_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void SetCursorPos(u16 x, u16 y); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* KAMI_CURSOR_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/graphics.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/graphics.h new file mode 100644 index 00000000..bec6dbcc --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/graphics.h @@ -0,0 +1,46 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: graphics.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef GRAPHICS_H_ +#define GRAPHICS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void InitGraphics(void); +void DrawLine(s16 sx, s16 sy, s16 ex, s16 ey, GXRgb color); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* GRAPHICS_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/kami_font.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/kami_font.h new file mode 100644 index 00000000..1357b563 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/kami_font.h @@ -0,0 +1,92 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_font.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef KAMI_FONT_H_ +#define KAMI_FONT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +extern u8 prog_state; +enum +{ STATE_NONE, STATE_SELECT, STATE_KS_PARENTINIT, STATE_KS_PARENT, STATE_KS_CHILDINIT, + STATE_KS_CHILDSCAN, STATE_KS_CHILD +}; +extern OSHeapHandle heapHandle; // Heapnh; + +extern const u16 BgScDataMain[32 * 24]; +extern const u16 BgScDataSub[32 * 24]; +extern const u32 sampleCharData[8 * 0x100]; +extern const u16 PlttDataObj[16][16]; +extern const u16 PlttDataMain[16][16]; +extern const u16 PlttDataSub[16][16]; + +void kamiFontInit(void); +void kamiFontClear(void); +void kamiFontPut(u16 x, u16 y, u16 color, u16 no); +void kamiFontPrintf(s16 x, s16 y, u8 color, char *text, ...); +void kamiFontPrintfMain(s16 x, s16 y, u8 color, char *text, ...); +void kamiFontFill(s16 x, s16 y, u8 color, s16 value, s32 length); +void kamiFontFillChar(int lineNo, u8 color1, u8 color2); +void kamiFontLoadScreenData(void); +void kamiFontPrintfConsole(u8 color, char *text, ...); +void kamiFontPrintfConsoleEx(u8 color, char *text, ...); + +// ʃR\[ppbg +#define CONSOLE_ORANGE 0 +#define CONSOLE_RED 1 +#define CONSOLE_GREEN 2 + +// ʃtHgppbg +#define FONT_COLOR_BLACK 0 +#define FONT_COLOR_RED 1 +#define FONT_COLOR_GREEN 2 +#define FONT_COLOR_BLUE 3 +#define FONT_COLOR_YELLOW 4 +#define FONT_COLOR_CYAN 5 +#define FONT_COLOR_PURPLE 6 + +// ʔwippbg +#define BG_COLOR_TRANS 0 +#define BG_COLOR_WHITE 1 +#define BG_COLOR_BLACK 2 +#define BG_COLOR_GRAY 3 +#define BG_COLOR_PURPLE 4 +#define BG_COLOR_PINK 5 +#define BG_COLOR_BLUE 6 +#define BG_COLOR_GREEN 7 +#define BG_COLOR_VIOLET 8 +#define BG_COLOR_RED 9 + +#define BG_COLOR_NONE 0xff + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* KAMI_FONT_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/kami_pxi.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/kami_pxi.h new file mode 100644 index 00000000..93ac903a --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/kami_pxi.h @@ -0,0 +1,98 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_pxi.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef TWL_KAMI_TEST_KAMITEST_H_ +#define TWL_KAMI_TEST_KAMITEST_H_ + +#include "fifo.h" + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +// ʒ` +typedef enum KAMIResult +{ + KAMI_RESULT_SUCCESS = 0, + KAMI_RESULT_SUCCESS_TRUE = 0, + KAMI_RESULT_SUCCESS_FALSE, + KAMI_RESULT_INVALID_COMMAND, + KAMI_RESULT_INVALID_PARAMETER, + KAMI_RESULT_ILLEGAL_STATUS, + KAMI_RESULT_BUSY, + KAMI_RESULT_FATAL_ERROR, + KAMI_RESULT_SEND_ERROR, + KAMI_RESULT_MAX +} +KAMIResult; + + +typedef enum { + FORMAT_MODE_QUICK, // QuicktH[}bg + FORMAT_MODE_FULL // FulltH[}bg(ep[eBV0xFFŖ߂j +} FormatMode; + +// R[obN +typedef void (*KAMICallback)(KAMIResult result, void *arg); + + +void KamiPxiInit( void ); + +KAMIResult CDC_ReadRegister(u8 page, u8 reg_no, u8* pData); +KAMIResult CDC_WriteRegister(u8 page, u8 reg_no, u8 value); +KAMIResult GPIO333_Write(BOOL value); +KAMIResult ExeFormatAsync(FormatMode format_mode, KAMICallback callback); +KAMIResult kamiNandIo(u32 block, void* buffer, u32 count, BOOL is_read); +KAMIResult kamiNvramIo(u32 address, void* buffer, u32 size, BOOL is_read); + +static KAMIResult kamiNandRead(u32 block, void* buffer, u32 count) +{ + return kamiNandIo(block, buffer, count, TRUE); +} +static KAMIResult kamiNandWrite(u32 block, void* buffer, u32 count) +{ + return kamiNandIo(block, buffer, count, FALSE); +} +static KAMIResult kamiNvramRead(u32 adress, void* buffer, u32 size) +{ + return kamiNvramIo(adress, buffer, size, TRUE); +} +static KAMIResult kamiNvramWrite(u32 adress, void* buffer, u32 size) +{ + return kamiNvramIo(adress, buffer, size, FALSE); +} + + + +/*===========================================================================*/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* TWL_KAMI_TEST_KAMITEST_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/keypad.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/keypad.h new file mode 100644 index 00000000..554f4493 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/keypad.h @@ -0,0 +1,48 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: keypad.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef KAMI_KEY_PAD_H_ +#define KAMI_KEY_PAD_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void kamiPadRead(void); +BOOL kamiPadIsTrigger(u16 key); +BOOL kamiPadIsRepeatTrigger(u16 key); +BOOL kamiPadIsPress(u16 key); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* KAMI_KEY_PAD_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_auto.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_auto.h new file mode 100644 index 00000000..c0a28718 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_auto.h @@ -0,0 +1,62 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_auto.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef AUTO_TOPMENU_H_ +#define AUTO_TOPMENU_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +//typedef void* (*TpProcess)(void); + +/*---------------------------------------------------------------------------* + O[oϐ` + *---------------------------------------------------------------------------*/ + +extern BOOL gAutoFlag; + + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void* AutoProcess0(void); +void* AutoProcess1(void); +void* AutoProcess2(void); +void* AutoProcess3(void); +void* AutoProcess4(void); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* AUTO_TOPMENU_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_eticket.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_eticket.h new file mode 100644 index 00000000..2b24ce98 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_eticket.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_eticket.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef PROCESS_ETICKET_H_ +#define PROCESS_ETICKET_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ +#define E_TICKET_FILE_PATH_IN_ROM "data/cert.sys" +#define E_TICKET_FILE_PATH_IN_NAND "F:sys/cert.sys" + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void* eTicketProcess0(void); +void* eTicketProcess1(void); +void* eTicketProcess2(void); +void* eTicketProcess3(void); +void* eTicketProcess4(void); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* PROCESS_ETICKET_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_format.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_format.h new file mode 100644 index 00000000..737eee82 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_format.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_format.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef PROCESS_FORMAT_H_ +#define PROCESS_FORMAT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +//typedef void* (*TpProcess)(void); + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void* FormatProcess0(void); +void* FormatProcess1(void); +void* FormatProcess2(void); +void* FormatProcess3(void); +void* FormatProcess4(void); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* PROCESS_FORMAT_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_hw_info.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_hw_info.h new file mode 100644 index 00000000..0f9ff672 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_hw_info.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_hw_info.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef PROCESS_HW_INFO_H_ +#define PROCESS_HW_INFO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +//typedef void* (*TpProcess)(void); + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void* HWInfoProcess0(void); +void* HWInfoProcess1(void); +void* HWInfoProcess2(void); +void* HWInfoProcess3(void); +void* HWInfoProcess4(void); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* PROCESS_HW_INFO_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_import.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_import.h new file mode 100644 index 00000000..acbf4fab --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_import.h @@ -0,0 +1,58 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_import.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef PROCESS_IMPORT_H_ +#define PROCESS_IMPORT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +//typedef void* (*TpProcess)(void); + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void* ImportProcess0(void); +void* ImportProcess1(void); +void* ImportProcess2(void); +void* ImportProcess3(void); +void* ImportProcess4(void); + +void ProgressInit(void); +void ProgressDraw(f32 ratio); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* PROCESS_IMPORT_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_nandfirm.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_nandfirm.h new file mode 100644 index 00000000..da7b0c02 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_nandfirm.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_nandfirm.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef PROCESS_NANDFIRM_H_ +#define PROCESS_NANDFIRM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +//typedef void* (*TpProcess)(void); + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void* NandfirmProcess0(void); +void* NandfirmProcess1(void); +void* NandfirmProcess2(void); +void* NandfirmProcess3(void); +void* NandfirmProcess4(void); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* PROCESS_NANDFIRM_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_norfirm.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_norfirm.h new file mode 100644 index 00000000..b1dfbe81 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_norfirm.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_norfirm.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef PROCESS_NORFIRM_H_ +#define PROCESS_NORFIRM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +//typedef void* (*TpProcess)(void); + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void* NorfirmProcess0(void); +void* NorfirmProcess1(void); +void* NorfirmProcess2(void); +void* NorfirmProcess3(void); +void* NorfirmProcess4(void); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* PROCESS_NORFIRM_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_topmenu.h b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_topmenu.h new file mode 100644 index 00000000..709844fb --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/include/process_topmenu.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_topmenu.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#ifndef PROCESS_TOPMENU_H_ +#define PROCESS_TOPMENU_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +//typedef void* (*TpProcess)(void); + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +void* TopmenuProcess0(void); +void* TopmenuProcess1(void); +void* TopmenuProcess2(void); +void* TopmenuProcess3(void); +void* TopmenuProcess4(void); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* PROCESS_TOPMENU_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/main.rsf b/build/systemMenu_RED/NandInitializer/ARM9.TWL/main.rsf new file mode 100644 index 00000000..a7b26f67 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/main.rsf @@ -0,0 +1,182 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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:: 2008-01-07#$ +# $Rev: 436 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType System + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + #SaveBannerFile TRUE +} + + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot ../data + Root /data + File *.* + HostRoot $(PRIVKEY_PATH) + Root /key + File $(HWINFO_PRIVKEY) +} diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/cursor.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/cursor.c new file mode 100644 index 00000000..f7923eea --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/cursor.c @@ -0,0 +1,93 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: cursor.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include "graphics.h" +#include "cursor.h" + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +void SetCursorPos(u16 x, u16 y) +{ + GXOamAttr oam; + +/* [] + G2_SetOBJAttr( + &oam, + x, y, + 0, + GX_OAM_MODE_NORMAL, + FALSE, + GX_OAM_EFFECT_FLIP_H, + GX_OAM_SHAPE_8x8, + GX_OAM_COLORMODE_16, + 0xf6, // charNo + 0, + 0 + ); + + DC_FlushRange( &oam, sizeof(GXOamAttr) ); + GXS_LoadOAM( &oam, 8, sizeof(GXOamAttr) ); + + G2_SetOBJAttr( + &oam, + x+31, y, + 0, + GX_OAM_MODE_NORMAL, + FALSE, + GX_OAM_EFFECT_NONE, + GX_OAM_SHAPE_8x8, + GX_OAM_COLORMODE_16, + 0xf6, // charNo + 0, + 0 + ); + + DC_FlushRange( &oam, sizeof(GXOamAttr) ); + GXS_LoadOAM( &oam, 16, sizeof(GXOamAttr) ); +*/ + + G2_SetOBJAttr( + &oam, + x, y, + 0, + GX_OAM_MODE_NORMAL, + FALSE, + GX_OAM_EFFECT_NONE, + GX_OAM_SHAPE_8x8, + GX_OAM_COLORMODE_16, + 0xff, // charNo + 0, + 0 + ); + DC_FlushRange( &oam, sizeof(GXOamAttr) ); + GXS_LoadOAM( &oam, 24, sizeof(GXOamAttr) ); +} + diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/font_data.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/font_data.c new file mode 100644 index 00000000..19003304 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/font_data.c @@ -0,0 +1,732 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: font_data.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include + +/*---------------------- afXN[ ---------------------------*/ + +const u16 BgScDataMain[32 * 24] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; + +const u16 BgScDataSub[32 * 24] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; + +/*---------------------- pbgf[^ ---------------------------*/ +#define RGB555(r,g,b) (b<<10|g<<5|r) + +const u16 PlttDataObj[16][16] = { + {RGB555( 0, 0, 0), RGB555(31, 10, 0), RGB555(31, 0, 0), RGB555(5, 5, 20),}, // Black + {RGB555(31, 31, 31), RGB555(31, 0, 0), RGB555(31, 0, 0), RGB555(31, 0, 0),}, // Red + {RGB555(31, 31, 31), RGB555(0, 31, 0), RGB555(0, 31, 0), RGB555(0, 31, 0),}, // Green + {RGB555(31, 31, 31), RGB555(0, 0, 31), RGB555(0, 0, 31), RGB555(0, 0, 31),}, // Blue + {RGB555(31, 31, 31), RGB555(31, 31, 0), RGB555(31, 31, 0), RGB555(31, 31, 0),}, // Yellow + {RGB555(31, 31, 31), RGB555(0, 31, 31), RGB555(0, 31, 31), RGB555(0, 31, 31),}, // Cyan + {RGB555(31, 31, 31), RGB555(31, 0, 31), RGB555(31, 0, 31), RGB555(31, 0, 31),}, // Purple + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31),}, // White +}; + +// ʃR\[pbg +const u16 PlttDataMain[16][16] = { + {RGB555( 0, 0, 0), RGB555(31, 10, 0), RGB555(0, 0, 0), RGB555(0, 0, 0),}, // Orange + {RGB555(31, 31, 31), RGB555(31, 0, 0), RGB555(31, 0, 0), RGB555(31, 0, 0),}, // Red + {RGB555(31, 31, 31), RGB555(0, 31, 0), RGB555(0, 31, 0), RGB555(0, 31, 0),}, // Green + {RGB555(31, 31, 31), RGB555(0, 0, 31), RGB555(0, 0, 31), RGB555(0, 0, 31),}, // Blue + {RGB555(31, 31, 31), RGB555(31, 31, 0), RGB555(31, 31, 0), RGB555(31, 31, 0),}, // Yellow + {RGB555(31, 31, 31), RGB555(0, 31, 31), RGB555(0, 31, 31), RGB555(0, 31, 31),}, // Cyan + {RGB555(31, 31, 31), RGB555(31, 0, 31), RGB555(31, 0, 31), RGB555(31, 0, 31),}, // Purple + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31),}, // White +}; + +const u16 PlttDataSub[16][16] = { + {RGB555(31, 31, 31), RGB555( 0, 0, 0), RGB555(25, 25, 25), RGB555(31, 31, 31),}, // Black + {RGB555(31, 31, 31), RGB555(21, 0, 0), RGB555(31, 0, 0), RGB555(31, 0, 0),}, // Red + {RGB555(31, 31, 31), RGB555( 0, 21, 0), RGB555(0, 31, 0), RGB555(0, 31, 0),}, // Green + {RGB555(31, 31, 31), RGB555( 0, 0, 21), RGB555(0, 0, 31), RGB555(0, 0, 31),}, // Blue + {RGB555(31, 31, 31), RGB555(21, 21, 0), RGB555(31, 31, 0), RGB555(31, 31, 0),}, // Yellow + {RGB555(31, 31, 31), RGB555(0, 21, 21), RGB555(0, 31, 31), RGB555(0, 31, 31),}, // Cyan + {RGB555(31, 31, 31), RGB555(21, 0, 21), RGB555(31, 0, 31), RGB555(31, 0, 31),}, // Purple + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31),}, // White + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31),}, // White + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31),}, // White + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31),}, // White + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31),}, // White + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31),}, // White + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31),}, // White + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31),}, // White + + // wiJ[͂16ԃpbg + // D ނ炳 sN ݂ Ž + {RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555( 0, 0, 0), RGB555(20, 20, 20), RGB555(31, 15, 31), RGB555(31, 20, 20), RGB555(20, 29, 31), RGB555(20, 31, 20), RGB555(21, 21, 31), RGB555(31, 0, 0), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), RGB555(31, 31, 31), } // White +}; + +/*---------------------- LN^f[^ -------------------------*/ + +const u32 sampleCharData[8 * 0x100] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 0000h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x11111111, 0x11111111, // 0001h use for import progress bar + 0x11111111, 0x11111111, 0x00000000, 0x00000000, + 0x00000000, 0x01011010, 0x01010010, 0x00010010, // 0002h + 0x00100010, 0x00100010, 0x00100001, 0x00100001, + 0x00000000, 0x01010001, 0x01010001, 0x01111111, // 0003h + 0x00000001, 0x00000001, 0x00000001, 0x01111110, + 0x00000000, 0x01010000, 0x01111111, 0x00100000, // 0004h + 0x00100000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x01010000, 0x01010100, 0x00001010, // 0005h + 0x00010001, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01011000, 0x01011000, 0x01111111, // 0006h + 0x00001000, 0x00101010, 0x01001010, 0x01001001, + 0x00000000, 0x01010010, 0x01101111, 0x01010010, // 0007h + 0x00010010, 0x00010010, 0x00010010, 0x00001001, + 0x00000000, 0x01010010, 0x01011111, 0x00000100, // 0008h + 0x00011111, 0x00001000, 0x00000001, 0x00011110, + 0x00000000, 0x01010000, 0x01011000, 0x00000110, // 0009h + 0x00000001, 0x00000110, 0x00011000, 0x00100000, + 0x00000000, 0x01010000, 0x01111101, 0x00010001, // 000ah + 0x00010001, 0x00010001, 0x00010001, 0x00001010, + 0x00000000, 0x01010000, 0x01011110, 0x00100000, // 000bh + 0x00000000, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x01010100, 0x01011111, 0x00001000, // 000ch + 0x00010000, 0x00000001, 0x00000001, 0x00011110, + 0x00000000, 0x01010001, 0x01010001, 0x00000001, // 000dh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01010000, 0x01111111, 0x00011000, // 000eh + 0x00010100, 0x00010100, 0x00011000, 0x00001100, + 0x00000000, 0x01010010, 0x01111111, 0x00010010, // 000fh + 0x00010010, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x00001110, 0x01010100, 0x01010010, // 0010h + 0x00111111, 0x00000100, 0x00000100, 0x00011000, + 0x00000000, 0x01010100, 0x01011111, 0x00000100, // 0011h + 0x01110100, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x01010100, 0x01011111, 0x00000010, // 0012h + 0x00011110, 0x00100001, 0x00100000, 0x00011110, + 0x00000000, 0x01010000, 0x01011100, 0x00100011, // 0013h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01010000, 0x01111111, 0x00010000, // 0014h + 0x00001000, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x01010010, 0x01010010, 0x00001100, // 0015h + 0x00000010, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x01010001, 0x01111101, 0x00010001, // 0016h + 0x00010001, 0x00111001, 0x01010101, 0x00011001, + 0x00000000, 0x01010100, 0x01010011, 0x01110010, // 0017h + 0x00010001, 0x00010001, 0x00001010, 0x00000100, + 0x00000000, 0x01011110, 0x01011000, 0x00000100, // 0018h + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x01010000, 0x01011100, 0x00010010, // 0019h + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01011101, 0x01010001, 0x00111101, // 001ah + 0x00010001, 0x00011001, 0x00110101, 0x00001001, + 0x00000000, 0x01110001, 0x01011101, 0x00110001, // 001bh + 0x00010001, 0x00111001, 0x01010101, 0x00011001, + 0x00000000, 0x01110100, 0x01010011, 0x00110010, // 001ch + 0x00010001, 0x00010001, 0x00001010, 0x00000100, + 0x00000000, 0x01101110, 0x01011000, 0x00100100, // 001dh + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x01110000, 0x01011100, 0x00110010, // 001eh + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01111101, 0x01010001, 0x00111101, // 001fh + 0x00010001, 0x00011001, 0x00110101, 0x00001001, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 0020h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 0021h + 0x00001000, 0x00001000, 0x00000000, 0x00001000, + 0x00000000, 0x01101100, 0x01001000, 0x00100100, // 0022h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00100100, 0x01111111, 0x00100100, // 0023h + 0x00100100, 0x01111111, 0x00010010, 0x00010010, + 0x00000000, 0x00001000, 0x01111110, 0x00001001, // 0024h + 0x00111110, 0x01001000, 0x00111111, 0x00001000, + 0x00000000, 0x01000010, 0x00100101, 0x00010010, // 0025h + 0x00001000, 0x00100100, 0x01010010, 0x00100001, + 0x00000000, 0x00001110, 0x00010001, 0x00001001, // 0026h + 0x01000110, 0x00101001, 0x00110001, 0x01001110, + 0x00000000, 0x00011000, 0x00010000, 0x00001000, // 0027h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01110000, 0x00001000, 0x00000100, // 0028h + 0x00000100, 0x00000100, 0x00001000, 0x01110000, + 0x00000000, 0x00000111, 0x00001000, 0x00010000, // 0029h + 0x00010000, 0x00010000, 0x00001000, 0x00000111, + 0x00000000, 0x00001000, 0x01001001, 0x00101010, // 002ah + 0x00011100, 0x00101010, 0x01001001, 0x00001000, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 002bh + 0x01111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002ch + 0x00000000, 0x00001100, 0x00001000, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002dh + 0x01111111, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002eh + 0x00000000, 0x00000000, 0x00000000, 0x00001100, + 0x00000000, 0x01000000, 0x00100000, 0x00010000, // 002fh + 0x00001000, 0x00000100, 0x00000010, 0x00000001, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0030h + 0x01000001, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x00011100, 0x00010000, 0x00010000, // 0031h + 0x00010000, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x00111110, 0x01000001, 0x01000000, // 0032h + 0x00111110, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x00111110, 0x01000001, 0x01000000, // 0033h + 0x00111110, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x00100000, 0x00110000, 0x00101000, // 0034h + 0x00100100, 0x00100010, 0x01111111, 0x00100000, + 0x00000000, 0x01111111, 0x00000001, 0x00111111, // 0035h + 0x01000000, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x00111110, 0x00000001, 0x00111111, // 0036h + 0x01000001, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x01111111, 0x00100000, 0x00100000, // 0037h + 0x00010000, 0x00010000, 0x00001000, 0x00001000, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0038h + 0x00111110, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0039h + 0x01000001, 0x01111110, 0x01000000, 0x00111110, + 0x00000000, 0x00000000, 0x00001100, 0x00000000, // 003ah + 0x00000000, 0x00000000, 0x00001100, 0x00000000, + 0x00000000, 0x00000000, 0x00001100, 0x00000000, // 003bh + 0x00000000, 0x00001100, 0x00001000, 0x00000100, + 0x00000000, 0x01100000, 0x00011000, 0x00000110, // 003ch + 0x00000001, 0x00000110, 0x00011000, 0x01100000, + 0x00000000, 0x00000000, 0x01111111, 0x00000000, // 003dh + 0x00000000, 0x00000000, 0x01111111, 0x00000000, + 0x00000000, 0x00000011, 0x00001100, 0x00110000, // 003eh + 0x01000000, 0x00110000, 0x00001100, 0x00000011, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 003fh + 0x00110000, 0x00001000, 0x00000000, 0x00001000, + 0x00000000, 0x00011100, 0x00100010, 0x01001001, // 0040h + 0x01010101, 0x01010101, 0x01010101, 0x00111010, + 0x00000000, 0x00001000, 0x00010100, 0x00010100, // 0041h + 0x00100010, 0x00111110, 0x01000001, 0x01000001, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0042h + 0x00111111, 0x01000001, 0x01000001, 0x00111111, + 0x00000000, 0x00111100, 0x01000010, 0x00000001, // 0043h + 0x00000001, 0x00000001, 0x01000010, 0x00111100, + 0x00000000, 0x00011111, 0x00100001, 0x01000001, // 0044h + 0x01000001, 0x01000001, 0x00100001, 0x00011111, + 0x00000000, 0x01111111, 0x00000001, 0x00000001, // 0045h + 0x01111111, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x01111111, 0x00000001, 0x00000001, // 0046h + 0x00111111, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00111100, 0x01000010, 0x00000001, // 0047h + 0x01111001, 0x01000001, 0x01000010, 0x00111100, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0048h + 0x01111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00111110, 0x00001000, 0x00001000, // 0049h + 0x00001000, 0x00001000, 0x00001000, 0x00111110, + 0x00000000, 0x01000000, 0x01000000, 0x01000000, // 004ah + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01100001, 0x00011001, 0x00000101, // 004bh + 0x00000011, 0x00000101, 0x00011001, 0x01100001, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 004ch + 0x00000001, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x01000001, 0x01100011, 0x01010101, // 004dh + 0x01001001, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x01000001, 0x01000011, 0x01000101, // 004eh + 0x01001001, 0x01010001, 0x01100001, 0x01000001, + 0x00000000, 0x00011100, 0x00100010, 0x01000001, // 004fh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0050h + 0x00111111, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00011100, 0x00100010, 0x01000001, // 0051h + 0x01000001, 0x01011001, 0x00100010, 0x01011100, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0052h + 0x00111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00111110, 0x01000001, 0x00000001, // 0053h + 0x00111110, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x01111111, 0x00001000, 0x00001000, // 0054h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0055h + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01000001, 0x01000001, 0x00100010, // 0056h + 0x00100010, 0x00010100, 0x00010100, 0x00001000, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0057h + 0x01001001, 0x01010101, 0x01100011, 0x01000001, + 0x00000000, 0x01000001, 0x00100010, 0x00010100, // 0058h + 0x00001000, 0x00010100, 0x00100010, 0x01000001, + 0x00000000, 0x01000001, 0x00100010, 0x00010100, // 0059h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01111111, 0x00100000, 0x00010000, // 005ah + 0x00001000, 0x00000100, 0x00000010, 0x01111111, + 0x00000000, 0x01111100, 0x00000100, 0x00000100, // 005bh + 0x00000100, 0x00000100, 0x00000100, 0x01111100, + 0x00000000, 0x00100010, 0x00010100, 0x00111110, // 005ch + 0x00001000, 0x00111110, 0x00001000, 0x00001000, + 0x00000000, 0x00011111, 0x00010000, 0x00010000, // 005dh + 0x00010000, 0x00010000, 0x00010000, 0x00011111, + 0x00000000, 0x00001000, 0x00010100, 0x00100010, // 005eh + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 005fh + 0x00000000, 0x00000000, 0x00000000, 0x01111111, + 0x00000000, 0x00010000, 0x00001000, 0x00011000, // 0060h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00011110, 0x00100001, // 0061h + 0x00111110, 0x00100001, 0x00100001, 0x01011110, + 0x00000000, 0x00000001, 0x00000001, 0x00111111, // 0062h + 0x01000001, 0x01000001, 0x01000001, 0x00111111, + 0x00000000, 0x00000000, 0x00111100, 0x01000010, // 0063h + 0x00000001, 0x00000001, 0x01000010, 0x00111100, + 0x00000000, 0x01000000, 0x01000000, 0x01111110, // 0064h + 0x01000001, 0x01000001, 0x01000001, 0x01111110, + 0x00000000, 0x00000000, 0x00111110, 0x01000001, // 0065h + 0x01111111, 0x00000001, 0x01000001, 0x00111110, + 0x00000000, 0x00110000, 0x00001000, 0x00001000, // 0066h + 0x01111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x01111110, 0x01000001, // 0067h + 0x01000001, 0x01111110, 0x01000000, 0x00111110, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 0068h + 0x00111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00001000, 0x00000000, 0x00001000, // 0069h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00100000, 0x00000000, 0x00100000, // 006ah + 0x00100000, 0x00100001, 0x00100001, 0x00011110, + 0x00000000, 0x00000001, 0x00000001, 0x01100001, // 006bh + 0x00011001, 0x00000111, 0x00011001, 0x01100001, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 006ch + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00110111, 0x01001001, // 006dh + 0x01001001, 0x01001001, 0x01001001, 0x01001001, + 0x00000000, 0x00000000, 0x00111111, 0x01000001, // 006eh + 0x01000001, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00000000, 0x00011100, 0x00100010, // 006fh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00000000, 0x00111101, 0x01000011, // 0070h + 0x01000001, 0x01000011, 0x00111101, 0x00000001, + 0x00000000, 0x00000000, 0x01011110, 0x01100001, // 0071h + 0x01000001, 0x01100001, 0x01011110, 0x01000000, + 0x00000000, 0x00000000, 0x00110001, 0x00001101, // 0072h + 0x00000011, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00000000, 0x00111110, 0x01000001, // 0073h + 0x00001110, 0x00110000, 0x01000001, 0x00111110, + 0x00000000, 0x00000100, 0x00000100, 0x01111111, // 0074h + 0x00000100, 0x00000100, 0x00000100, 0x01111000, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0075h + 0x01000001, 0x01000001, 0x01000001, 0x01111110, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0076h + 0x00100010, 0x00100010, 0x00010100, 0x00001000, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0077h + 0x01001001, 0x00101010, 0x00101010, 0x00010100, + 0x00000000, 0x00000000, 0x00100001, 0x00010010, // 0078h + 0x00001100, 0x00001100, 0x00010010, 0x00100001, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0079h + 0x00100010, 0x00011100, 0x00001000, 0x00000110, + 0x00000000, 0x00000000, 0x00111111, 0x00010000, // 007ah + 0x00001000, 0x00000100, 0x00000010, 0x00111111, + 0x00000000, 0x00001000, 0x00011110, 0x01100100, // 007bh + 0x00011000, 0x00100100, 0x00000100, 0x01111000, + 0x00000000, 0x00000000, 0x00011110, 0x00000100, // 007ch + 0x00011110, 0x00110101, 0x00101101, 0x00010010, + 0x00000000, 0x00000000, 0x00000000, 0x00010001, // 007dh + 0x00100001, 0x00100001, 0x00000001, 0x00000010, + 0x00000000, 0x00000000, 0x00011100, 0x00000000, // 007eh + 0x00011110, 0x00100000, 0x00100000, 0x00011100, + 0x00000000, 0x00000000, 0x00011100, 0x00000000, // 007fh + 0x00111110, 0x00010000, 0x00001100, 0x00110010, + 0x00000000, 0x00000000, 0x00000100, 0x00101111, // 0080h + 0x01000100, 0x00011110, 0x00100101, 0x00010110, + 0x00000000, 0x00000000, 0x00001010, 0x00011110, // 0081h + 0x00101011, 0x00100010, 0x00010100, 0x00000100, + 0x00000000, 0x00000000, 0x00001000, 0x00011101, // 0082h + 0x00101011, 0x00101001, 0x00011001, 0x00000100, + 0x00000000, 0x00000000, 0x00001000, 0x00111000, // 0083h + 0x00001000, 0x00011110, 0x00101001, 0x00000110, + 0x00000000, 0x00000000, 0x00000000, 0x00011100, // 0084h + 0x00100011, 0x00100000, 0x00100000, 0x00011100, + 0x00000000, 0x00000110, 0x01001001, 0x00110000, // 0085h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000100, 0x00111111, 0x00000100, // 0086h + 0x00111110, 0x01010101, 0x01001101, 0x00100110, + 0x00000000, 0x00000000, 0x00100001, 0x01000001, // 0087h + 0x01000001, 0x01000001, 0x00000001, 0x00000010, + 0x00000000, 0x00111100, 0x00000000, 0x00111110, // 0088h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x00011100, 0x00000000, 0x00111110, // 0089h + 0x00010000, 0x00001000, 0x00010100, 0x01100010, + 0x00000000, 0x00100100, 0x01011111, 0x00000100, // 008ah + 0x00111110, 0x01000101, 0x01000101, 0x00100010, + 0x00000000, 0x00100010, 0x01001111, 0x01010010, // 008bh + 0x01010010, 0x00010010, 0x00010010, 0x00001001, + 0x00000000, 0x00000100, 0x00111110, 0x00001000, // 008ch + 0x00111110, 0x00010000, 0x00000010, 0x00111100, + 0x00000000, 0x00100000, 0x00011000, 0x00000110, // 008dh + 0x00000001, 0x00000110, 0x00011000, 0x00100000, + 0x00000000, 0x00100000, 0x01111101, 0x00100001, // 008eh + 0x00100001, 0x00100001, 0x00100001, 0x00010010, + 0x00000000, 0x00011110, 0x00100000, 0x00000000, // 008fh + 0x00000000, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x00001000, 0x01111111, 0x00010000, // 0090h + 0x00100000, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 0091h + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00010000, 0x01111111, 0x00011000, // 0092h + 0x00010100, 0x00010100, 0x00011000, 0x00001100, + 0x00000000, 0x00100010, 0x01111111, 0x00100010, // 0093h + 0x00100010, 0x00000010, 0x00000010, 0x01111100, + 0x00000000, 0x00111100, 0x00010000, 0x00001100, // 0094h + 0x01111111, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x00000100, 0x00011111, 0x00000100, // 0095h + 0x01110100, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x00001000, 0x01111111, 0x00000100, // 0096h + 0x00111100, 0x01000010, 0x01000000, 0x00111100, + 0x00000000, 0x00000000, 0x00011100, 0x00100011, // 0097h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01111111, 0x00010000, 0x00001000, // 0098h + 0x00001000, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x00000010, 0x00110010, 0x00001100, // 0099h + 0x00000010, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x00100100, 0x01001111, 0x01000010, // 009ah + 0x00010001, 0x00111100, 0x00010010, 0x00001100, + 0x00000000, 0x00000010, 0x01111010, 0x01000010, // 009bh + 0x00000010, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x00100010, 0x00111110, 0x01010010, // 009ch + 0x01001011, 0x01101101, 0x01010101, 0x00110010, + 0x00000000, 0x00110010, 0x01001011, 0x01000110, // 009dh + 0x01000110, 0x01110010, 0x01001011, 0x00110010, + 0x00000000, 0x00011100, 0x00101010, 0x01001001, // 009eh + 0x01001001, 0x01000101, 0x01000101, 0x00110010, + 0x00000000, 0x00100001, 0x01111101, 0x00100001, // 009fh + 0x00100001, 0x00111001, 0x01100101, 0x00011001, + 0x00000000, 0x00000100, 0x00100011, 0x01100010, // 00a0h + 0x00100001, 0x00100001, 0x00010010, 0x00001100, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a1h + 0x00000000, 0x00000100, 0x00001010, 0x00000100, + 0x00000000, 0x01110000, 0x00010000, 0x00010000, // 00a2h + 0x00010000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a3h + 0x00001000, 0x00001000, 0x00001000, 0x00001110, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a4h + 0x00000000, 0x00000010, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00011000, // 00a5h + 0x00011000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01111111, 0x01000000, 0x01111111, // 00a6h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x00000000, 0x00111111, 0x00100000, // 00a7h + 0x00010100, 0x00001100, 0x00000100, 0x00000010, + 0x00000000, 0x00000000, 0x00100000, 0x00100000, // 00a8h + 0x00010000, 0x00001111, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00000100, 0x00111111, // 00a9h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x00000000, 0x00000000, 0x00111110, // 00aah + 0x00001000, 0x00001000, 0x00001000, 0x01111111, + 0x00000000, 0x00000000, 0x00010000, 0x00111111, // 00abh + 0x00011000, 0x00010100, 0x00010010, 0x00011001, + 0x00000000, 0x00000000, 0x00000010, 0x00111111, // 00ach + 0x00100010, 0x00010010, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00111110, // 00adh + 0x00100000, 0x00100000, 0x00100000, 0x01111111, + 0x00000000, 0x00000000, 0x00111110, 0x00100000, // 00aeh + 0x00111110, 0x00100000, 0x00100000, 0x00111110, + 0x00000000, 0x00000000, 0x00100101, 0x00101010, // 00afh + 0x00101010, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00b0h + 0x01111111, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01111111, 0x01000000, 0x00101000, // 00b1h + 0x00011000, 0x00001000, 0x00001000, 0x00000100, + 0x00000000, 0x01000000, 0x00100000, 0x00011000, // 00b2h + 0x00010111, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x00001000, 0x01111111, 0x01000001, // 00b3h + 0x01000001, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00000000, 0x00111110, 0x00001000, // 00b4h + 0x00001000, 0x00001000, 0x00001000, 0x01111111, + 0x00000000, 0x00100000, 0x01111111, 0x00110000, // 00b5h + 0x00101000, 0x00100100, 0x00100010, 0x00110001, + 0x00000000, 0x00000100, 0x01111111, 0x01000100, // 00b6h + 0x01000100, 0x01000100, 0x01000010, 0x00100001, + 0x00000000, 0x00000100, 0x00111111, 0x00001000, // 00b7h + 0x01111111, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x01111100, 0x01000100, 0x01000100, // 00b8h + 0x01000010, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00000010, 0x01111110, 0x00100010, // 00b9h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01111110, 0x01000000, 0x01000000, // 00bah + 0x01000000, 0x01000000, 0x01000000, 0x01111110, + 0x00000000, 0x00100010, 0x01111111, 0x00100010, // 00bbh + 0x00100010, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x00000011, 0x00000100, 0x01000011, // 00bch + 0x01000100, 0x00100000, 0x00011000, 0x00000111, + 0x00000000, 0x01111111, 0x01000000, 0x00100000, // 00bdh + 0x00010000, 0x00011000, 0x00100100, 0x01000011, + 0x00000000, 0x00000010, 0x01111111, 0x01000010, // 00beh + 0x00100010, 0x00000010, 0x00000010, 0x01111100, + 0x00000000, 0x01000001, 0x01000010, 0x01000000, // 00bfh + 0x00100000, 0x00100000, 0x00011000, 0x00000110, + 0x00000000, 0x01111110, 0x01000010, 0x01001110, // 00c0h + 0x01110001, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x01100000, 0x00011110, 0x00010000, // 00c1h + 0x01111111, 0x00010000, 0x00010000, 0x00001100, + 0x00000000, 0x01000101, 0x01001010, 0x01001010, // 00c2h + 0x01000000, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00111110, 0x00000000, 0x01111111, // 00c3h + 0x00010000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x00000010, 0x00000010, 0x00000110, // 00c4h + 0x00011010, 0x01100010, 0x00000010, 0x00000010, + 0x00000000, 0x00010000, 0x00010000, 0x01111111, // 00c5h + 0x00010000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x00000000, 0x00111110, 0x00000000, // 00c6h + 0x00000000, 0x00000000, 0x00000000, 0x01111111, + 0x00000000, 0x01111110, 0x01000000, 0x01000100, // 00c7h + 0x00101000, 0x00010000, 0x00101000, 0x01000110, + 0x00000000, 0x00001000, 0x01111111, 0x00100000, // 00c8h + 0x00010000, 0x00011100, 0x01101011, 0x00001000, + 0x00000000, 0x01000000, 0x01000000, 0x01000000, // 00c9h + 0x00100000, 0x00100000, 0x00011000, 0x00000111, + 0x00000000, 0x00010010, 0x00100010, 0x00100010, // 00cah + 0x01000010, 0x01000010, 0x01000001, 0x01000001, + 0x00000000, 0x00000001, 0x00000001, 0x01111111, // 00cbh + 0x00000001, 0x00000001, 0x00000001, 0x01111110, + 0x00000000, 0x01111111, 0x01000000, 0x01000000, // 00cch + 0x01000000, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00000000, 0x00000100, 0x00001010, // 00cdh + 0x00010001, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x00001000, 0x00001000, 0x01111111, // 00ceh + 0x00001000, 0x00101010, 0x01001010, 0x01001001, + 0x00000000, 0x01111111, 0x01000000, 0x01000000, // 00cfh + 0x00100010, 0x00010100, 0x00001000, 0x00010000, + 0x00000000, 0x00001110, 0x01110000, 0x00001110, // 00d0h + 0x01110000, 0x00000110, 0x00011000, 0x01100000, + 0x00000000, 0x00001000, 0x00001000, 0x00000100, // 00d1h + 0x00000100, 0x00100010, 0x01000010, 0x01111111, + 0x00000000, 0x01000000, 0x01000000, 0x00100100, // 00d2h + 0x00101000, 0x00010000, 0x00101100, 0x01000011, + 0x00000000, 0x01111111, 0x00000100, 0x01111111, // 00d3h + 0x00000100, 0x00000100, 0x00000100, 0x01111000, + 0x00000000, 0x00000010, 0x01111111, 0x01000010, // 00d4h + 0x00100010, 0x00010100, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00111110, 0x00100000, // 00d5h + 0x00100000, 0x00100000, 0x00100000, 0x01111111, + 0x00000000, 0x01111110, 0x01000000, 0x01000000, // 00d6h + 0x01111110, 0x01000000, 0x01000000, 0x01111110, + 0x00000000, 0x00111110, 0x00000000, 0x01111111, // 00d7h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01000010, 0x01000010, 0x01000010, // 00d8h + 0x01000010, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00001010, 0x00001010, 0x00001010, // 00d9h + 0x01001010, 0x01001010, 0x00101010, 0x00011001, + 0x00000000, 0x00000010, 0x00000010, 0x01000010, // 00dah + 0x01000010, 0x00100010, 0x00010010, 0x00001110, + 0x00000000, 0x01111111, 0x01000001, 0x01000001, // 00dbh + 0x01000001, 0x01000001, 0x01000001, 0x01111111, + 0x00000000, 0x01111111, 0x01000001, 0x01000001, // 00dch + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01000011, 0x01000100, 0x01000000, // 00ddh + 0x01000000, 0x00100000, 0x00010000, 0x00001111, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00deh 0 + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00dfh 1 + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00011110, 0x00001000, 0x00000100, // 00e0h 2 + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x00000000, 0x00001100, 0x00010010, // 00e1h 3 + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01111101, 0x00100001, 0x01111101, // 00e2h 4 + 0x00100001, 0x00111001, 0x01100101, 0x00011001, + 0x00000000, 0x00111100, 0x00010000, 0x00111100, // 00e3h 5 + 0x00010000, 0x00011100, 0x00110010, 0x00001100, + 0x00000000, 0x00001110, 0x00101000, 0x00101000, // 00e4h 6 + 0x00111110, 0x01100101, 0x00100101, 0x00010010, + 0x00000000, 0x00000100, 0x00101111, 0x01000100, // 00e5h 7 + 0x00000110, 0x01000101, 0x01000101, 0x00111110, + 0x00000000, 0x00100010, 0x00100010, 0x00111110, // 00e6h 8 + 0x01010010, 0x01010101, 0x01001101, 0x00100110, + 0x00000000, 0x00000100, 0x00011111, 0x00000010, // 00e7h 9 + 0x00011111, 0x01000010, 0x01000010, 0x00111100, + 0x00000000, 0x00010010, 0x00111110, 0x01010011, // 00e8h 10 + 0x01000010, 0x00100100, 0x00000100, 0x00000100, + 0x00000000, 0x00001000, 0x00111101, 0x01001011, // 00e9h 11 + 0x01001001, 0x01001001, 0x00111000, 0x00000100, + 0x00000000, 0x00001000, 0x00111000, 0x00001000, // 00eah 12 + 0x00001000, 0x00011110, 0x00101001, 0x00000110, + 0x00000000, 0x00011000, 0x00100000, 0x00000100, // 00ebh 13 + 0x00111010, 0x01000110, 0x01000000, 0x00111000, + 0x00000000, 0x01000010, 0x01000010, 0x01000010, // 00ech 14 + 0x01000110, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00111110, 0x00010000, 0x00111100, // 00edh 15 + 0x01000011, 0x01001100, 0x01010010, 0x00111100, + 0x00000000, 0x00100010, 0x00110011, 0x00101010, // 00eeh 16 + 0x00100110, 0x00100010, 0x00100011, 0x01000010, + 0x00000000, 0x00111110, 0x00010000, 0x00111100, // 00efh 17 + 0x01000011, 0x01000000, 0x01000010, 0x00111100, + 0x00000000, 0x00000010, 0x00111011, 0x01000110, // 00f0h 18 + 0x01000010, 0x01000011, 0x01000010, 0x00110010, + 0x00000000, 0x00000100, 0x00000100, 0x00000010, // 00f1h 19 + 0x01000110, 0x01000101, 0x01000101, 0x00111001, + 0x00000000, 0x01010100, 0x01111111, 0x00100100, // 00f2h 20 + 0x00100100, 0x00100100, 0x00100010, 0x00010001, + 0x00000000, 0x01010100, 0x01011111, 0x00000100, // 00f3h 21 + 0x00111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01011110, 0x01100010, 0x00100010, // 00f4h 22 + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01010010, 0x01111110, 0x00100010, // 00f5h 23 + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + + 0x33330000, + 0x33330000, + 0x33000000, + 0x33000000, // 00f6h + 0x33000000, + 0x33000000, + 0x33330000, + 0x33330000, + + + 0x00020000, // 00f7h + 0x00020000, + 0x00020000, + 0x22222222, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + + 0x00000000, // 00f8h + 0x00000000, + 0x00000000, + 0x00000000, + 0x11111111, + 0x11111111, + 0x11111111, + 0x11111111, + + 0x11111111, // 00f9h + 0x11111111, + 0x11111111, + 0x11111111, + 0x11111111, + 0x11111111, + 0x11111111, + 0x11111111, + + 0x11111111, // 00fah + 0x11111111, + 0x11111111, + 0x11111111, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + + 0x00000000, // 00fbh + 0x00000000, + 0x00000000, + 0x22222222, + 0x00020000, + 0x00020000, + 0x00020000, + 0x00020000, + + 0x00020000, // 00fch + 0x00020000, + 0x00020000, + 0x22222222, + 0x00020000, + 0x00020000, + 0x00020000, + 0x00020000, + + 0x00020000, // 00fdh + 0x00020000, + 0x00020000, + 0x00020000, + 0x00020000, + 0x00020000, + 0x00020000, + 0x00020000, + + 0x00000000, // 00feh + 0x00000000, + 0x00000000, + 0x22222222, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + + 0x00020000, + 0x00220000, + 0x02122222, + 0x21111112, + 0x21111112, + 0x02122222, + 0x00220000, + 0x00020000, + + + +/* + 0x00022222, + 0x00002112, + 0x00021112, + 0x00211122, + 0x02111202, + 0x21112000, + 0x02120000, + 0x00200000, +*/ + +/* + 0x00000000, 0x01011110, 0x01010000, 0x00111111, // 00ffh + 0x00001000, 0x00001000, 0x00001000, 0x00000110 +*/ +}; + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/graphics.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/graphics.c new file mode 100644 index 00000000..9239b235 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/graphics.c @@ -0,0 +1,160 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: praphics.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +//#include +#include +#include "kami_font.h" +#include "graphics.h" + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: InitGraphics + + Description: \̏ + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void +InitGraphics(void) +{ + GX_DispOff(); + GXS_DispOff(); + + //---- VRAM NA + GX_SetBankForLCDC(GX_VRAM_LCDC_ALL); + MI_CpuClearFast((void *)HW_LCDC_VRAM, HW_LCDC_VRAM_SIZE); + + //---- OAMƃpbgNA + MI_CpuFillFast((void *)HW_OAM, 192, HW_OAM_SIZE); + MI_CpuClearFast((void *)HW_PLTT, HW_PLTT_SIZE); + MI_CpuFillFast((void *)HW_DB_OAM, 192, HW_DB_OAM_SIZE); + MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE); + + //---- naioN̐ݒ + GX_SetBankForOBJ(GX_VRAM_OBJ_128_A); + GX_SetBankForSubOBJ(GX_VRAM_SUB_OBJ_128_D); + + //---- afoN̐ݒ + GX_SetBankForBG(GX_VRAM_BG_128_B); + GX_SetBankForSubBG(GX_VRAM_SUB_BG_128_C); + + //---- \[hݒ + GX_SetGraphicsMode (GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BG0_AS_3D); + GX_SetVisiblePlane (GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1 | GX_PLANEMASK_OBJ); + GXS_SetVisiblePlane(GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1 | GX_PLANEMASK_OBJ); + + //---- 3D + G3X_Init(); + G3X_InitMtxStack(); + G2_SetBG0Priority(0); + G3X_AlphaTest(FALSE, 0); + G3X_AntiAlias(TRUE); + G3X_EdgeMarking(FALSE); + G3X_SetFog(FALSE, (GXFogBlend)0, (GXFogSlope)0, 0); + G3X_SetClearColor(0, 0, 0x7fff, 63, FALSE); + G3_ViewPort(0, 0, 255, 191); + G3_MtxMode(GX_MTXMODE_POSITION_VECTOR); + + //---- 32KoCgOBJ2D}bv[hŎgp + GX_SetOBJVRamModeChar(GX_OBJVRAMMODE_CHAR_2D); + + // XN[ItZbgyуLN^[ItZbg̐ݒ + GX_SetBGScrOffset(GX_BGSCROFFSET_0x00000); + GX_SetBGCharOffset(GX_BGCHAROFFSET_0x10000); + + G2_SetBG1Control( + GX_BG_SCRSIZE_TEXT_256x256, + GX_BG_COLORMODE_16, + GX_BG_SCRBASE_0x0000 , + GX_BG_CHARBASE_0x00000, + GX_BG_EXTPLTT_01 + ); + + G2S_SetBG0Control( + GX_BG_SCRSIZE_TEXT_256x256, + GX_BG_COLORMODE_16, + GX_BG_SCRBASE_0x0000 , + GX_BG_CHARBASE_0x04000, + GX_BG_EXTPLTT_01 + ); + + G2S_SetBG1Control( + GX_BG_SCRSIZE_TEXT_256x256, + GX_BG_COLORMODE_16, + GX_BG_SCRBASE_0x2000 , + GX_BG_CHARBASE_0x04000, + GX_BG_EXTPLTT_01 + ); + + G2_BG1Mosaic(FALSE); + G2S_BG1Mosaic(FALSE); + + //---- f[^[h + GX_LoadOBJ ( sampleCharData, 0, sizeof(sampleCharData)); + GX_LoadBG1Char( sampleCharData, 0, sizeof(sampleCharData)); + GX_LoadBGPltt ( PlttDataMain, 0, sizeof(PlttDataMain)); + GX_LoadBG1Scr ( BgScDataMain, 0, sizeof(BgScDataMain)); + GX_LoadOBJPltt( PlttDataObj, 0, sizeof(PlttDataObj)); + + GXS_LoadOBJ ( sampleCharData, 0, sizeof(sampleCharData)); + GXS_LoadBG0Char( sampleCharData, 0, sizeof(sampleCharData)); + GXS_LoadBGPltt ( PlttDataSub, 0, sizeof(PlttDataSub)); + GXS_LoadBG0Scr ( BgScDataSub, 0, sizeof(BgScDataSub)); + GXS_LoadOBJPltt( PlttDataObj, 0, sizeof(PlttDataObj)); + + GX_DispOn(); + GXS_DispOn(); +} + +/*---------------------------------------------------------------------------* + Name: DrawLine + + Description: Op|SŐ` + + Arguments: sx - `悷̊Jn_̂W + sy - `悷̊Jn_̂W + ex - `悷̏I_̂W + ey - `悷̏I_̂W + color - `悷̐F + + Returns: None. + *---------------------------------------------------------------------------*/ +void +DrawLine(s16 sx, s16 sy, s16 ex, s16 ey, GXRgb color) +{ + fx16 fsx = (fx16)(((sx - 128) * 0x1000) / 128); + fx16 fsy = (fx16)(((96 - sy) * 0x1000) / 96); + fx16 fex = (fx16)(((ex - 128) * 0x1000) / 128); + fx16 fey = (fx16)(((96 - ey) * 0x1000) / 96); + + G3_Begin(GX_BEGIN_TRIANGLES); + { + G3_Color( color ); + G3_Vtx(fsx, fsy, 0); + G3_Color( color ); + G3_Vtx(fex, fey, 0); + G3_Color( color ); + G3_Vtx(fsx, fsy, 1); + } + G3_End(); +} diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/kami_font.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/kami_font.c new file mode 100644 index 00000000..06f4d19b --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/kami_font.c @@ -0,0 +1,392 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_font.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include "kami_font.h" + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define SCREEN_DATA_COLOR_PLTT_SHIFT 12 +#define NUM_OF_PRINT_TARGET 2 + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static u8 sXPos; +static u8 sYPos; + +static u32 sBackColorCharData[24*8]; + +static u16 sFontScreenDataMain[32 * 24] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; + +static u16 sFontScreenDataSub[24*32] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; + +static u16 sBackColorScreenData[32 * 24] = { + 0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de,0xf0de, + 0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df,0xf0df, + 0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0,0xf0e0, + 0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1,0xf0e1, + 0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2,0xf0e2, + 0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3,0xf0e3, + 0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4,0xf0e4, + 0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5,0xf0e5, + 0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6,0xf0e6, + 0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7,0xf0e7, + 0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8,0xf0e8, + 0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9,0xf0e9, + 0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea,0xf0ea, + 0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb,0xf0eb, + 0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec,0xf0ec, + 0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed,0xf0ed, + 0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee,0xf0ee, + 0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef,0xf0ef, + 0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0,0xf0f0, + 0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1,0xf0f1, + 0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2,0xf0f2, + 0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3,0xf0f3, + 0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4, + 0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5, +}; + +/*---------------------------------------------------------------------------* + ֐錾 + *---------------------------------------------------------------------------*/ + +static void kamiFontReturnConsole( void ); + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: + + Description: + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontInit(void) +{ + // wipLN^f[^ + MI_CpuCopy32( &sampleCharData[8 * 0xde], sBackColorCharData, sizeof(sBackColorCharData) ); + + // wipXN[f[^Zbg + DC_FlushRange ( sBackColorScreenData, sizeof(sBackColorScreenData) ); + GXS_LoadBG1Scr ( sBackColorScreenData, 0, sizeof(sBackColorScreenData) ); +} + +/*---------------------------------------------------------------------------* + Name: + + Description: + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontLoadScreenData(void) +{ + DC_FlushRange ( sFontScreenDataMain, sizeof(sFontScreenDataMain) ); + GX_LoadBG0Scr ( sFontScreenDataMain, 0, sizeof(sFontScreenDataMain) ); + + DC_FlushRange ( sFontScreenDataSub, sizeof(sFontScreenDataSub) ); + GXS_LoadBG0Scr ( sFontScreenDataSub, 0, sizeof(sFontScreenDataSub) ); + + // wiLN^f[^ + DC_FlushRange( sBackColorCharData, sizeof(sBackColorCharData) ); + GXS_LoadBG0Char( sBackColorCharData, 0xde*32, sizeof(sBackColorCharData) ); +} + +/*---------------------------------------------------------------------------* + Name: kamiFontClear + + Description: zXN[NA + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontClear(void) +{ + MI_CpuClear8( sFontScreenDataSub, sizeof(sFontScreenDataSub) ); +} + +/*---------------------------------------------------------------------------* + Name: kamiFontPrintf + + Description: zXN[ɕzuB32܂ŁB + + Arguments: x - ̐擪zu x W( ~ 8 hbg )B + y - ̐擪zu y W( ~ 8 hbg )B + color - ̐FpbgԍŎwB + text - zu镶BI[NULLB + ... - zB + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontPrintf(s16 x, s16 y, u8 color, char *text, ...) +{ + va_list vlist; + char temp[32 + 2]; + s32 i; + + va_start(vlist, text); + (void)vsnprintf(temp, 33, text, vlist); + va_end(vlist); + + *(u16 *)(&temp[32]) = 0x0000; + for (i = 0;temp[i] != 0x00; i++) + { + sFontScreenDataSub[((y * 32) + x + i) % (24 * 32)] = + (u16)((color << SCREEN_DATA_COLOR_PLTT_SHIFT) | temp[i]); + } +} + +/*---------------------------------------------------------------------------* + Name: kamiFontPrintf + + Description: zXN[ɕzuB32܂ŁB + + Arguments: x - ̐擪zu x W( ~ 8 hbg )B + y - ̐擪zu y W( ~ 8 hbg )B + color - ̐FpbgԍŎwB + text - zu镶BI[NULLB + ... - zB + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontPrintfMain(s16 x, s16 y, u8 color, char *text, ...) +{ + va_list vlist; + char temp[32 + 2]; + s32 i; + + va_start(vlist, text); + (void)vsnprintf(temp, 33, text, vlist); + va_end(vlist); + + *(u16 *)(&temp[32]) = 0x0000; + for (i = 0;temp[i] != 0x00; i++) + { + sFontScreenDataMain[((y * 32) + x + i) % (24 * 32)] = + (u16)((color << SCREEN_DATA_COLOR_PLTT_SHIFT) | temp[i]); + } +} + +/*---------------------------------------------------------------------------* + Name: kamiFontFillChar + + Description: zXN[ + + Arguments: x - ̐擪zu x W( ~ 8 hbg )B + y - ̐擪zu y W( ~ 8 hbg )B + color - ̐FpbgԍŎwB + value + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontFillChar(int lineNo, u8 color1, u8 color2) +{ + s32 i; + u32 line; + int charNo = 0xde + lineNo; + + if (color1 < 0x10) + { + line = (u32)(0x11111111 * color1); + + for (i = 0;i<4; i++) + { + sBackColorCharData[8 * lineNo + i] = line; + } + } + + if (color2 < 0x10) + { + line = (u32)(0x11111111 * color2); + + for (i = 4;i<8; i++) + { + sBackColorCharData[8 * lineNo + i] = line; + } + } +} + +/*---------------------------------------------------------------------------* + Name: kamiFontPrintfConsole + + Description: zR\[ɕzuB256܂ŁB + + Arguments: color - ̐FpbgԍŎwB + text - zu镶BI[NULLB + ... - zB + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontPrintfConsole(u8 color, char *text, ...) +{ + va_list vlist; + char temp[256 + 2]; + s32 i; + + va_start(vlist, text); + (void)vsnprintf(temp, 256, text, vlist); + va_end(vlist); + + // I[lj + *(u16 *)(&temp[256]) = 0x0000; + + for(i=0; temp[i] != 0x00; i++) + { + if (temp[i] == 0x0A) + { + // sR[h + kamiFontReturnConsole(); + } + else + { + // ꕶ + sFontScreenDataMain[((sYPos * 32) + sXPos) % (24 * 32)] = + (u16)((color << SCREEN_DATA_COLOR_PLTT_SHIFT) | temp[i]); + + // XWE[ɓBꍇ͉s + if (++sXPos >= 32) + { + kamiFontReturnConsole(); + } + } + } +} + +/*---------------------------------------------------------------------------* + Name: kamiFontPrintfConsoleEx + + Description: zR\[ɕzuB256܂ŁB + OS_Printf‚łɎsB + + Arguments: color - ̐FpbgԍŎwB + text - zu镶BI[NULLB + ... - zB + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontPrintfConsoleEx(u8 color, char *text, ...) +{ + va_list vlist; + char temp[256 + 2]; + + va_start(vlist, text); + (void)vsnprintf(temp, 256, text, vlist); + va_end(vlist); + + kamiFontPrintfConsole(color, temp); + OS_TPrintf(temp); +} + +/*---------------------------------------------------------------------------* + Name: kamiFontReturnConsole + + Description: zR\[ɂss + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void +kamiFontReturnConsole( void ) +{ + sXPos = 0; + if (sYPos < 23) + { + // ̍s + sYPos++; + } + else + { + // ɍŏIsɓBĂꍇVtgs + MI_CpuCopy32( &sFontScreenDataMain[32], sFontScreenDataMain, sizeof(u16)*32*23 ); + MI_CpuClear32( &sFontScreenDataMain[32*23], sizeof(u16)*32); + } +} + diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/kami_pxi.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/kami_pxi.c new file mode 100644 index 00000000..925eff25 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/kami_pxi.c @@ -0,0 +1,472 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_pxi.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include "kami_pxi.h" +#include "fifo.h" + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ +// l߂ăRs[ +#define KAMI_PACK_U16(d, s) \ + ((d)[0] = (u8)((*((u16*)s) >> 0) & 0xFF), \ + (d)[1] = (u8)((*((u16*)s) >> 8) & 0xFF)) + +#define KAMI_PACK_U32(d, s) \ + ((d)[0] = (u8)((*((u32*)s) >> 0) & 0xFF), \ + (d)[1] = (u8)((*((u32*)s) >> 8) & 0xFF), \ + (d)[2] = (u8)((*((u32*)s) >> 16) & 0xFF), \ + (d)[3] = (u8)((*((u32*)s) >> 24) & 0xFF)) + + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ +typedef struct KamiWork +{ + BOOL lock; + + KamiCommand command; + KAMIPxiResult result; + KAMICallback callback; + void* arg; + + u32 total; + u32 current; + u8* data; +} +KamiWork; + +/*---------------------------------------------------------------------------* + ÓIϐ` + *---------------------------------------------------------------------------*/ +static BOOL kamiInitialized; +static KamiWork kamiWork; + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +static BOOL KamiSendPxiCommand(KamiCommand command, u8 size, u8 data); +static void KamiSendPxiData(u8 *pData); +static void KamiPxiCallback(PXIFifoTag tag, u32 data, BOOL err); +static void KamiDone(KAMIResult result); +static void KamiWaitBusy(void); + + +void KamiPxiInit( void ) +{ + kamiWork.lock = FALSE; + + PXI_Init(); + while ( !PXI_IsCallbackReady(PXI_FIFO_TAG_KAMITEST, PXI_PROC_ARM7 )) + { + } + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_KAMITEST, KamiPxiCallback); + if ( 0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, 0, 0)) + { + return; + } +} + +/////////////////////////////////////////////////////////////////// + +//typedef void (*KAMICallback)(KAMIResult result, void *arg); +/* +void CDC_ReadCallback(KAMIResult result, void* arg); +void CDC_ReadCallback(KAMIResult result, void* arg) +{ + +} +*/ + +/*---------------------------------------------------------------------------* + Name: CODEC WX^[h֐ + + Description: + + Arguments: None. + + Returns: + *---------------------------------------------------------------------------*/ + +KAMIResult CDC_ReadRegister(u8 page, u8 reg_no, u8* pData) +{ + OSIntrMode enabled; + + + // bN + enabled = OS_DisableInterrupts(); + if (kamiWork.lock) + { + (void)OS_RestoreInterrupts(enabled); + return KAMI_RESULT_BUSY; + } + kamiWork.lock = TRUE; + (void)OS_RestoreInterrupts(enabled); + + kamiWork.callback = NULL; + kamiWork.arg = 0; + kamiWork.data = (u8*)pData; + + if (KamiSendPxiCommand(CODEC_READ_REGISTER, 2, page)) + { + KamiSendPxiData(®_no); + KamiWaitBusy(); + return (KAMIResult)kamiWork.result; + } + return KAMI_RESULT_SEND_ERROR; +} + +/*---------------------------------------------------------------------------* + Name: CODEC WX^Cg֐ + + Description: + + Arguments: None. + + Returns: + *---------------------------------------------------------------------------*/ + +KAMIResult CDC_WriteRegister(u8 page, u8 reg_no, u8 value) +{ + OSIntrMode enabled; + u8 data[2]; + int i; + + + // bN + enabled = OS_DisableInterrupts(); + if (kamiWork.lock) + { + (void)OS_RestoreInterrupts(enabled); + return KAMI_RESULT_BUSY; + } + kamiWork.lock = TRUE; + (void)OS_RestoreInterrupts(enabled); + + kamiWork.callback = NULL; + kamiWork.arg = 0; + kamiWork.data = 0; + + // f[^쐬 + data[0] = reg_no; + data[1] = value; + + if (KamiSendPxiCommand(CODEC_WRITE_REGISTER, 3, page)) + { + for (i = 0; i < 2; i++) + { + KamiSendPxiData(&data[i]); + } + KamiWaitBusy(); + return (KAMIResult)kamiWork.result; + } + return KAMI_RESULT_SEND_ERROR; +} + +/*---------------------------------------------------------------------------* + Name: GPIO333 ANZX֐ + + Description: + + Arguments: None. + + Returns: + *---------------------------------------------------------------------------*/ + +KAMIResult GPIO333_Write(BOOL value) +{ + OSIntrMode enabled; + + // bN + enabled = OS_DisableInterrupts(); + if (kamiWork.lock) + { + (void)OS_RestoreInterrupts(enabled); + return KAMI_RESULT_BUSY; + } + kamiWork.lock = TRUE; + (void)OS_RestoreInterrupts(enabled); + + kamiWork.callback = NULL; + kamiWork.arg = 0; + kamiWork.data = 0; + + if (KamiSendPxiCommand(GPIO333_WRITE, 1, (u8)value)) + { + KamiWaitBusy(); + return (KAMIResult)kamiWork.result; + } + return KAMI_RESULT_SEND_ERROR; +} + +/*---------------------------------------------------------------------------* + Name: tH[}bgs֐ + + Description: + + Arguments: FormatMode + + Returns: + *---------------------------------------------------------------------------*/ + +KAMIResult ExeFormatAsync(FormatMode format_mode, KAMICallback callback) +{ + OSIntrMode enabled; + + // bN + enabled = OS_DisableInterrupts(); + if (kamiWork.lock) + { + (void)OS_RestoreInterrupts(enabled); + return KAMI_RESULT_BUSY; + } + kamiWork.lock = TRUE; + (void)OS_RestoreInterrupts(enabled); + + kamiWork.callback = callback; + kamiWork.arg = 0; + kamiWork.data = 0; + + if (KamiSendPxiCommand(EXE_FORMAT, 1, format_mode) == FALSE) + { + return KAMI_RESULT_SEND_ERROR; + } + return KAMI_RESULT_SUCCESS; +} + +/*---------------------------------------------------------------------------* + Name: NANDANZX֐ + + Description: + + Arguments: None. + + Returns: + *---------------------------------------------------------------------------*/ + +KAMIResult kamiNandIo(u32 block, void* buffer, u32 count, BOOL is_read) +{ + OSIntrMode enabled; + u8 data[12]; + int i; + + // bN + enabled = OS_DisableInterrupts(); + if (kamiWork.lock) + { + (void)OS_RestoreInterrupts(enabled); + return KAMI_RESULT_BUSY; + } + kamiWork.lock = TRUE; + (void)OS_RestoreInterrupts(enabled); + + kamiWork.callback = NULL; + kamiWork.arg = 0; + kamiWork.data = 0; + + // f[^쐬 + KAMI_PACK_U32(&data[0], &block); + KAMI_PACK_U32(&data[4], &buffer); + KAMI_PACK_U32(&data[8], &count); + + if (KamiSendPxiCommand(KAMI_NAND_IO, 12, (u8)is_read)) + { + for (i = 0; i < 12; i+=3) + { + KamiSendPxiData(&data[i]); + } + KamiWaitBusy(); + return (KAMIResult)kamiWork.result; + } + return KAMI_RESULT_SEND_ERROR; +} + +/*---------------------------------------------------------------------------* + Name: NvramANZX֐ + + Description: + + Arguments: None. + + Returns: + *---------------------------------------------------------------------------*/ +KAMIResult kamiNvramIo(u32 address, void* buffer, u32 size, BOOL is_read) +{ + OSIntrMode enabled; + u8 data[12]; + int i; + + // bN + enabled = OS_DisableInterrupts(); + if (kamiWork.lock) + { + (void)OS_RestoreInterrupts(enabled); + return KAMI_RESULT_BUSY; + } + kamiWork.lock = TRUE; + (void)OS_RestoreInterrupts(enabled); + + kamiWork.callback = NULL; + kamiWork.arg = 0; + kamiWork.data = 0; + + // f[^쐬 + KAMI_PACK_U32(&data[0], &address); + KAMI_PACK_U32(&data[4], &buffer); + KAMI_PACK_U32(&data[8], &size); + + if (KamiSendPxiCommand(KAMI_NVRAM_IO, 12, (u8)is_read)) + { + for (i = 0; i < 12; i+=3) + { + KamiSendPxiData(&data[i]); + } + KamiWaitBusy(); + return (KAMIResult)kamiWork.result; + } + return KAMI_RESULT_SEND_ERROR; +} +/////////////////////////////////////////////////////////////////// + + +///////// +static BOOL KamiSendPxiCommand(KamiCommand command, u8 size, u8 data) +{ + u32 pxiData = (u32)(KAMITEST_PXI_START_BIT | + ((command << KAMITEST_PXI_COMMAND_SHIFT) & KAMITEST_PXI_COMMAND_MASK) | + ((size << KAMITEST_PXI_DATA_NUMS_SHIFT) & KAMITEST_PXI_DATA_NUMS_MASK) | + ((data << KAMITEST_PXI_1ST_DATA_SHIFT) & KAMITEST_PXI_1ST_DATA_MASK)); + if (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, pxiData, 0)) + { + return FALSE; + } + return TRUE; +} + +static void KamiSendPxiData(u8 *pData) +{ + u32 pxiData = (u32)((pData[0] << 16) | (pData[1] << 8) | pData[2]); + while (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, pxiData, 0)) + { + } +} + +static void KamiPxiCallback(PXIFifoTag tag, u32 data, BOOL err) +{ +#pragma unused( tag ) + if (err) + { + KamiDone(KAMI_RESULT_FATAL_ERROR); + return; + } + if (data & KAMITEST_PXI_START_BIT) // 擪f[^ + { + if (data & KAMITEST_PXI_RESULT_BIT) + { + kamiWork.total = (u8)((data & KAMITEST_PXI_DATA_NUMS_MASK) >> KAMITEST_PXI_DATA_NUMS_SHIFT); + kamiWork.current = 0; + kamiWork.command = (KamiCommand)((data & KAMITEST_PXI_COMMAND_MASK) >> KAMITEST_PXI_COMMAND_SHIFT); + kamiWork.result = (KAMIPxiResult)((data & KAMITEST_PXI_1ST_DATA_MASK) >> KAMITEST_PXI_1ST_DATA_SHIFT); + } + else // m̃f[^ + { + KamiDone(KAMI_RESULT_FATAL_ERROR); + return; + } + } + else // 㑱f[^ + { + if (kamiWork.data == NULL) + { + KamiDone(KAMI_RESULT_FATAL_ERROR); + return; + } + if (kamiWork.current < kamiWork.total-1) + { + kamiWork.data[kamiWork.current++] = (u8)((data & 0xFF0000) >> 16); + } + if (kamiWork.current < kamiWork.total-1) + { + kamiWork.data[kamiWork.current++] = (u8)((data & 0x00FF00) >> 8); + } + if (kamiWork.current < kamiWork.total-1) + { + kamiWork.data[kamiWork.current++] = (u8)((data & 0x0000FF) >> 0); + } + } + if (kamiWork.current == kamiWork.total-1) + { + KAMIResult result; + switch (kamiWork.result) + { + case KAMI_PXI_RESULT_SUCCESS: // alias KAMI_PXI_RESULT_SUCCESS_TRUE + result = KAMI_RESULT_SUCCESS; // alias KAMI_RESULT_SUCCESS_TRUE + break; + case KAMI_PXI_RESULT_SUCCESS_FALSE: + result = KAMI_RESULT_SUCCESS_FALSE; + break; + case KAMI_PXI_RESULT_INVALID_COMMAND: + result = KAMI_RESULT_INVALID_COMMAND; + break; + case KAMI_PXI_RESULT_INVALID_PARAMETER: + result = KAMI_RESULT_INVALID_PARAMETER; + break; + case KAMI_PXI_RESULT_ILLEGAL_STATUS: + result = KAMI_RESULT_ILLEGAL_STATUS; + break; + case KAMI_PXI_RESULT_BUSY: + result = KAMI_RESULT_BUSY; + break; + default: + result = KAMI_RESULT_FATAL_ERROR; + } + KamiDone(result); + return; + } +} + +extern void PXIi_HandlerRecvFifoNotEmpty(void); +static void KamiWaitBusy(void) +{ + volatile BOOL *p = &kamiWork.lock; + + while (*p) + { + if (OS_GetCpsrIrq() == OS_INTRMODE_IRQ_DISABLE) + { + PXIi_HandlerRecvFifoNotEmpty(); + } + } +} + +static void KamiDone(KAMIResult result) +{ + KAMICallback callback = kamiWork.callback; + void* arg = kamiWork.arg; + kamiWork.callback = NULL; + kamiWork.arg = NULL; + if (kamiWork.lock) + { + kamiWork.lock = FALSE; + } + if (callback) + { + callback(result, arg); + } +} diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/keypad.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/keypad.c new file mode 100644 index 00000000..4c2bab13 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/keypad.c @@ -0,0 +1,85 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: keypad.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include "keypad.h" + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define KEY_REPEAT_TRIGGER_START 20 +#define KEY_REPEAT_TRIGGER_TERM 5 + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static u16 Cont; +static u16 Trg; +static u16 Release; +static u16 RepeatTrg; +static u8 key = 60; + +static int repeat_counter; + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +void +kamiPadRead(void) +{ + u16 ReadData; + + ReadData = PAD_Read(); + Trg = (u16)(ReadData & (ReadData ^ Cont)); + Release = (u16)(Cont & (ReadData ^ Cont)); + Cont = ReadData; + + RepeatTrg = Trg; + if (++repeat_counter > (KEY_REPEAT_TRIGGER_START + KEY_REPEAT_TRIGGER_TERM)) + { + repeat_counter = KEY_REPEAT_TRIGGER_START; + } + if (repeat_counter == KEY_REPEAT_TRIGGER_START) + { + RepeatTrg = ReadData; + } + if (!ReadData) + { + repeat_counter = 0; + } +} + +BOOL +kamiPadIsTrigger(u16 key) +{ + return (Trg & key)? TRUE : FALSE; +} + +BOOL +kamiPadIsRepeatTrigger(u16 key) +{ + return (RepeatTrg & key)? TRUE : FALSE; +} + +BOOL +kamiPadIsPress(u16 key) +{ + return (Cont & key)? TRUE : FALSE; +} + diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/main.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/main.c new file mode 100644 index 00000000..2ee3f2c9 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/main.c @@ -0,0 +1,180 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: main.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "kami_font.h" +#include "process_format.h" +#include "process_topmenu.h" +#include "graphics.h" +#include "keypad.h" +#include "kami_pxi.h" +#include +#include +#include + +extern void HWInfoWriterInit( void ); + +typedef void* (*Process)(void); + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static Process sProcess; + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +static void VBlankIntr(void); +static void InitAllocation(void); + +/*---------------------------------------------------------------------------* + Name: TwlMain + + Description: main + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void +TwlMain() +{ + OS_Init(); + OS_InitArena(); + PXI_Init(); + OS_InitLock(); + OS_InitArenaEx(); + OS_InitIrqTable(); + OS_SetIrqStackChecker(); + MI_Init(); + OS_InitVAlarm(); + OSi_InitVramExclusive(); + OS_InitThread(); + OS_InitReset(); + GX_Init(); + FX_Init(); + SND_Init(); + TP_Init(); + RTC_Init(); + + InitAllocation(); + + KamiPxiInit(); /* ƎPXI */ + + // VuN荞ݐݒ + OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)OS_EnableIrqMask(OS_IE_FIFO_RECV); + (void)OS_EnableIrq(); + (void)GX_VBlankIntr(TRUE); + + /* initialize file-system */ + FS_Init(FS_DMA_NOT_USE); + + // SDNȂǂ}EgԂɑΉ + FATFS_UnmountDrive("F:"); + FATFS_UnmountDrive("G:"); + FATFS_MountDrive("F", FATFS_MEDIA_TYPE_NAND, 0); + FATFS_MountDrive("G", FATFS_MEDIA_TYPE_SD, 0); + + // NAMCu + NAM_Init( OS_AllocFromMain, OS_FreeToMain); + + // \֘A + InitGraphics(); + kamiFontInit(); + + /* always preload FS table for faster directory access. */ + { + u32 need_size = FS_GetTableSize(); + void *p_table = OS_Alloc(need_size); + SDK_ASSERT(p_table != NULL); + (void)FS_LoadTable(p_table, need_size); + } + + // V[PXݒ + sProcess = TopmenuProcess0; + + kamiFontPrintfConsole( CONSOLE_ORANGE, "Thank you for using program.\n"); + kamiFontPrintfConsole( CONSOLE_ORANGE, "+---------------------------+\n"); + kamiFontPrintfConsole( CONSOLE_ORANGE, "l A Button : Select Menu l\n"); + kamiFontPrintfConsole( CONSOLE_ORANGE, "l Up/Down Key : Change Menu l\n"); + kamiFontPrintfConsole( CONSOLE_ORANGE, "l L&R Button : Auto Init * l\n"); + kamiFontPrintfConsole( CONSOLE_ORANGE, "+---------------------------+\n"); + kamiFontPrintfConsole( CONSOLE_ORANGE, "* Note that nand memory is deleted.\n"); + + while (1) + { + kamiPadRead(); + + // R}htbV + (void)SND_FlushCommand(SND_COMMAND_NOBLOCK); + + // VuN҂ + OS_WaitVBlankIntr(); + + // `qlVR}hM + while (SND_RecvCommandReply(SND_COMMAND_NOBLOCK) != NULL) + { + } + + // tHgXN[f[^[h + kamiFontLoadScreenData(); + + sProcess = sProcess(); + } +} + +/*---------------------------------------------------------------------------* + Name: VBlankIntr + + Description: VBlank荞ݏ + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void +VBlankIntr(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt +} + +/*---------------------------------------------------------------------------* + Name: InitAllocation + + Description: q[v̏. + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void InitAllocation(void) +{ + void *tmp; + OSHeapHandle hh; + + /* A[ȉ */ + tmp = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1); + OS_SetArenaLo(OS_ARENA_MAIN, tmp); + hh = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi()); + if (hh < 0) + OS_Panic("ARM9: Fail to create heap...\n"); + hh = OS_SetCurrentHeap(OS_ARENA_MAIN, hh); +} diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_auto.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_auto.c new file mode 100644 index 00000000..6f21e0c7 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_auto.c @@ -0,0 +1,216 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_auto.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include "kami_font.h" +#include "process_topmenu.h" +#include "process_format.h" +#include "process_hw_info.h" +#include "process_import.h" +#include "process_eticket.h" +#include "process_nandfirm.h" +#include "process_norfirm.h" +#include "process_auto.h" +#include "cursor.h" +#include "keypad.h" + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define NUM_OF_MENU_SELECT 6 +#define DOT_OF_MENU_SPACE 16 +#define CURSOR_ORIGIN_X 32 +#define CURSOR_ORIGIN_Y 56 + +/*---------------------------------------------------------------------------* + O[oϐ` + *---------------------------------------------------------------------------*/ + +BOOL gAutoFlag = FALSE; + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static s8 sMenuSelectNo; + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + vZX֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: Top Menu vZXO + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* AutoProcess0(void) +{ + // I[gtOZbg + gAutoFlag = TRUE; + + // j[ + sMenuSelectNo = 0; + + // J[\ + SetCursorPos((u16)200, (u16)200); + + return AutoProcess1; +} + +/*---------------------------------------------------------------------------* + Name: Top Menu vZXP + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* AutoProcess1(void) +{ + switch ( sMenuSelectNo++ ) + { + case 0: + return FormatProcess0; + case 1: + return HWInfoProcess0; + break; + case 2: + return eTicketProcess0; + case 3: + return ImportProcess0; + case 4: + return NandfirmProcess0; + case 5: + return AutoProcess2; + } + + // never reach + return TopmenuProcess0; +} + +/*---------------------------------------------------------------------------* + Name: Top Menu vZX2 + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* AutoProcess2(void) +{ + int i; + u8 bg_color; + + // SNA + kamiFontClear(); + + // wiSNA + for (i=0;i<24;i++) + { + kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS ); + } + + // o[W\ + kamiFontPrintf(2, 1, FONT_COLOR_BLACK, "Auto Nand Initialization"); + kamiFontPrintf(0, 2, FONT_COLOR_BLACK, "--------------------------------"); + + // j[ꗗ + kamiFontPrintf(3, 7, FONT_COLOR_BLACK, " FORMAT NAND "); + kamiFontPrintf(3, 9, FONT_COLOR_BLACK, " WRITE HARDWARE INFO "); + kamiFontPrintf(3, 11, FONT_COLOR_BLACK, " WRITE ETICKET SIGN "); + kamiFontPrintf(3, 13, FONT_COLOR_BLACK, " INPORT TAD FROM SD "); + kamiFontPrintf(3, 15, FONT_COLOR_BLACK, " INPORT NANDFIRM FROM SD"); + kamiFontPrintf(3, 22, FONT_COLOR_BLACK, " Button B : return to menu"); + + for (i=0;i +#include +#include +#include +#include "kami_font.h" +#include "kami_pxi.h" +#include "process_topmenu.h" +#include "process_eticket.h" +#include "process_auto.h" +#include "cursor.h" +#include "keypad.h" + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define NUM_OF_MENU_SELECT 2 +#define DOT_OF_MENU_SPACE 16 +#define CURSOR_ORIGIN_X 32 +#define CURSOR_ORIGIN_Y 56 + +#define ROUND_UP(value, alignment) \ + (((u32)(value) + (alignment-1)) & ~(alignment-1)) + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static s8 sMenuSelectNo; + +/*---------------------------------------------------------------------------* + ֐錾 + *---------------------------------------------------------------------------*/ + +static BOOL MakeETicketFile(void); + +/*---------------------------------------------------------------------------* + vZX֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: eTicket vZXO + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* eTicketProcess0(void) +{ + int i; + + // SNA + kamiFontClear(); + + // o[W\ + kamiFontPrintf(2, 1, FONT_COLOR_BLACK, "Write eTicket Sign"); + kamiFontPrintf(0, 2, FONT_COLOR_BLACK, "--------------------------------"); + + // j[ꗗ + kamiFontPrintf(3, 6, FONT_COLOR_BLACK, "+-------------------+-----+"); + kamiFontPrintf(3, 7, FONT_COLOR_BLACK, "l WRITE E-TICKET l l"); + kamiFontPrintf(3, 8, FONT_COLOR_BLACK, "+-------------------+-----+"); + kamiFontPrintf(3, 9, FONT_COLOR_BLACK, "l RETURN l l"); + kamiFontPrintf(3, 10, FONT_COLOR_BLACK, "+-------------------+-----+"); + + // wiSNA + for (i=0;i<24;i++) + { + kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS ); + } + + // wi㕔 + kamiFontFillChar( 0, BG_COLOR_GRAY, BG_COLOR_GRAY ); + kamiFontFillChar( 1, BG_COLOR_GRAY, BG_COLOR_GRAY ); + kamiFontFillChar( 2, BG_COLOR_GRAY, BG_COLOR_TRANS ); + + return eTicketProcess1; +} + +/*---------------------------------------------------------------------------* + Name: eTicket vZXP + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* eTicketProcess1(void) +{ + // I[gsp + if (gAutoFlag) + { + sMenuSelectNo = 0; + return eTicketProcess2; + } + + // Ij[̕ύX + if ( kamiPadIsRepeatTrigger(PAD_KEY_UP) ) + { + if (--sMenuSelectNo < 0) sMenuSelectNo = NUM_OF_MENU_SELECT -1; + } + else if ( kamiPadIsRepeatTrigger(PAD_KEY_DOWN) ) + { + if (++sMenuSelectNo >= NUM_OF_MENU_SELECT) sMenuSelectNo = 0; + } + + // J[\zu + SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNo * DOT_OF_MENU_SPACE)); + + // + if (kamiPadIsTrigger(PAD_BUTTON_A)) + { + return eTicketProcess2; + } + // gbvj[֖߂ + else if (kamiPadIsTrigger(PAD_BUTTON_B)) + { + return TopmenuProcess0; + } + + return eTicketProcess1; +} + +/*---------------------------------------------------------------------------* + Name: eTicket vZXQ + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* eTicketProcess2(void) +{ + BOOL result; + + switch( sMenuSelectNo ) + { + case 0: + result = MakeETicketFile(); + if (result) + { + kamiFontPrintf(25, 7, FONT_COLOR_GREEN, "OK"); + } + else + { + kamiFontPrintf(25, 7, FONT_COLOR_RED, "NG"); + } + break; + case 1: + return TopmenuProcess0; + } + + // Autop + if (gAutoFlag) + { + if (result) return AutoProcess1; + else return AutoProcess2; + } + + return eTicketProcess1; +} + +/*---------------------------------------------------------------------------* + Name: eTicket vZXR + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* eTicketProcess3(void) +{ + return eTicketProcess3; +} + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +static BOOL MakeETicketFile(void) +{ + FSFile file; + FATFSFileHandle fat_handle; + + BOOL open_is_ok; + BOOL read_is_ok; + void* pTempBuf; + u32 file_size; + u32 alloc_size; + BOOL result = TRUE; + + // F:sys/cert.sysɑ݂Ȃ牽Ȃ + fat_handle = FATFS_OpenFile(E_TICKET_FILE_PATH_IN_NAND, "r"); + if (fat_handle) + { + kamiFontPrintfConsoleEx(CONSOLE_RED, "%s already exist\n", E_TICKET_FILE_PATH_IN_NAND); + kamiFontPrintf(2, 20, FONT_COLOR_RED, "%s already exist", E_TICKET_FILE_PATH_IN_NAND); + FATFS_CloseFile(fat_handle); + return FALSE; + } + + // ROMt@CI[v + FS_InitFile(&file); + open_is_ok = FS_OpenFile(&file, E_TICKET_FILE_PATH_IN_ROM); + if (!open_is_ok) + { + OS_Printf("FS_OpenFile(\"%s\") ... ERROR!\n", E_TICKET_FILE_PATH_IN_ROM); + return FALSE; + } + + // ROMt@C[h + file_size = FS_GetFileLength(&file) ; + alloc_size = ROUND_UP(file_size, 32) ; + pTempBuf = OS_Alloc( alloc_size ); + SDK_NULL_ASSERT(pTempBuf); + DC_InvalidateRange(pTempBuf, alloc_size); + read_is_ok = FS_ReadFile( &file, pTempBuf, (s32)file_size ); + if (!read_is_ok) + { + kamiFontPrintfConsoleEx(CONSOLE_RED, "FS_ReadFile(\"%s\") ... ERROR!\n", E_TICKET_FILE_PATH_IN_ROM); + FS_CloseFile(&file); + OS_Free(pTempBuf); + return FALSE; + } + + // ROMt@CN[Y + FS_CloseFile(&file); + + // F:sys/cert.sys쐬 + if (!FATFS_CreateFile(E_TICKET_FILE_PATH_IN_NAND, TRUE, "rwxrwxrwx")) + { + kamiFontPrintfConsoleEx(CONSOLE_RED, "FATFS_CreateFile(%s) failed.\n", E_TICKET_FILE_PATH_IN_NAND); + result = FALSE; + } + else + { + // F:sys/cert.sysI[v + fat_handle = FATFS_OpenFile(E_TICKET_FILE_PATH_IN_NAND, "w"); + if (!fat_handle) + { + kamiFontPrintfConsoleEx(CONSOLE_RED, "FATFS_OpenFile(%s) failed.\n", E_TICKET_FILE_PATH_IN_NAND); + result = FALSE; + } + // F:sys/cert.sys + else if (FATFS_WriteFile(fat_handle, pTempBuf, (s32)file_size) == -1) + { + kamiFontPrintfConsoleEx(CONSOLE_RED, "FATFS_WritFile() failed.\n"); + result = FALSE; + } + (void)FATFS_CloseFile(fat_handle); + } + + OS_Free(pTempBuf); + + return result; +} + diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_format.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_format.c new file mode 100644 index 00000000..c5ac956e --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_format.c @@ -0,0 +1,294 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_format.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include "kami_font.h" +#include "kami_pxi.h" +#include "process_topmenu.h" +#include "process_format.h" +#include "process_auto.h" +#include "cursor.h" +#include "keypad.h" + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define NUM_OF_MENU_SELECT 4 +#define DOT_OF_MENU_SPACE 16 +#define CURSOR_ORIGIN_X 32 +#define CURSOR_ORIGIN_Y 56 + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static s8 sMenuSelectNo; +static u8 sLock; +static u8 sFormatResult; + +/*---------------------------------------------------------------------------* + ֐錾 + *---------------------------------------------------------------------------*/ + +static void FormatCallback(KAMIResult result, void* arg); + +/*---------------------------------------------------------------------------* + vZX֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: Format vZXO + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* FormatProcess0(void) +{ + int i; + + // SNA + kamiFontClear(); + + // o[W\ + kamiFontPrintf(2, 1, FONT_COLOR_BLACK, "Format Nand Flash"); + kamiFontPrintf(0, 2, FONT_COLOR_BLACK, "--------------------------------"); + + // j[ꗗ + kamiFontPrintf(3, 6, FONT_COLOR_BLACK, "+-------------------+-----+"); + kamiFontPrintf(3, 7, FONT_COLOR_BLACK, "l QUICK FORMAT l l"); + kamiFontPrintf(3, 8, FONT_COLOR_BLACK, "+-------------------+-----+"); + kamiFontPrintf(3, 9, FONT_COLOR_BLACK, "l FULL FORMAT l l"); + kamiFontPrintf(3, 10, FONT_COLOR_BLACK, "+-------------------+-----+"); + kamiFontPrintf(3, 11, FONT_COLOR_BLACK, "l CHECK DISK l l"); + kamiFontPrintf(3, 12, FONT_COLOR_BLACK, "+-------------------+-----+"); + kamiFontPrintf(3, 13, FONT_COLOR_BLACK, "l RETURN l l"); + kamiFontPrintf(3, 14, FONT_COLOR_BLACK, "+-------------------+-----+"); + + // wiSNA + for (i=0;i<24;i++) + { + kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS ); + } + + // wi㕔 + kamiFontFillChar( 0, BG_COLOR_BLUE, BG_COLOR_BLUE ); + kamiFontFillChar( 1, BG_COLOR_BLUE, BG_COLOR_BLUE ); + kamiFontFillChar( 2, BG_COLOR_BLUE, BG_COLOR_TRANS ); + + return FormatProcess1; +} + +/*---------------------------------------------------------------------------* + Name: Format vZXP + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* FormatProcess1(void) +{ + // I[gsp + if (gAutoFlag) + { + sMenuSelectNo = 0; + return FormatProcess2; + } + + // Ij[̕ύX + if ( kamiPadIsRepeatTrigger(PAD_KEY_UP) ) + { + if (--sMenuSelectNo < 0) sMenuSelectNo = NUM_OF_MENU_SELECT -1; + } + else if ( kamiPadIsRepeatTrigger(PAD_KEY_DOWN) ) + { + if (++sMenuSelectNo >= NUM_OF_MENU_SELECT) sMenuSelectNo = 0; + } + + // J[\zu + SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNo * DOT_OF_MENU_SPACE)); + + // + if (kamiPadIsTrigger(PAD_BUTTON_A)) + { + return FormatProcess2; + } + // gbvj[֖߂ + else if (kamiPadIsTrigger(PAD_BUTTON_B)) + { + return TopmenuProcess0; + } + + return FormatProcess1; +} + +/*---------------------------------------------------------------------------* + Name: Format vZXQ + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* FormatProcess2(void) +{ + if (sLock == FALSE) + { + switch( sMenuSelectNo ) + { + case 0: + sLock = TRUE; + ExeFormatAsync(FORMAT_MODE_QUICK, FormatCallback); + kamiFontPrintf(24, 7, FONT_COLOR_BLACK, " "); + return FormatProcess3; + case 1: + sLock = TRUE; + ExeFormatAsync(FORMAT_MODE_FULL, FormatCallback); + kamiFontPrintf(24, 9, FONT_COLOR_BLACK, " "); + return FormatProcess3; + case 2: + { + FATFSDiskInfo info; + BOOL result = FALSE; + + kamiFontPrintf(24, 11, FONT_COLOR_BLACK, " "); + kamiFontLoadScreenData(); + + FATFS_UnmountDrive("F:"); + FATFS_UnmountDrive("G:"); + // wNANDp[eBV0FhCuɃ}Eg + if (FATFS_MountDrive("F", FATFS_MEDIA_TYPE_NAND, 0)) + { + // `FbNfBXNs + if (FATFS_CheckDisk("F:", &info, TRUE, TRUE, TRUE)) + { + // wNANDp[eBV1GhCuɃ}Eg + if (FATFS_MountDrive("G", FATFS_MEDIA_TYPE_NAND, 1)) + { + // `FbNfBXNs + if (FATFS_CheckDisk("G:", &info, TRUE, TRUE, TRUE)) + { + result = TRUE; + } + } + } + } + + // ftHg}EgԂɖ߂Ă + FATFS_UnmountDrive("G:"); + FATFS_MountDrive("G", FATFS_MEDIA_TYPE_SD, 0); + + if (result == TRUE) { kamiFontPrintf(24, 11, FONT_COLOR_GREEN, " OK "); } + else { kamiFontPrintf(24, 11, FONT_COLOR_RED, " NG "); } + + return FormatProcess1; + } + case 3: + return TopmenuProcess0; + } + } + + return FormatProcess1; +} + +static void FormatCallback(KAMIResult result, void* /*arg*/) +{ + s16 y_pos; + + if ( sMenuSelectNo == 0 ) y_pos = 7; + else y_pos = 9; + + if ( result == KAMI_RESULT_SUCCESS_TRUE ) + { + kamiFontPrintf(24, y_pos, FONT_COLOR_GREEN, " OK "); + sFormatResult = TRUE; + } + else + { + kamiFontPrintf(24, y_pos, FONT_COLOR_RED, " NG "); + sFormatResult = FALSE; + } + + // bN + sLock = FALSE; +} + +/*---------------------------------------------------------------------------* + Name: Format vZXR + + Description: tH[}bg҂vZX + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* FormatProcess3(void) +{ + static s32 progress; + s16 y_pos; + + // I + if (sLock == FALSE) + { + progress = 0; + + // Autop + if (gAutoFlag) + { + if (sFormatResult == TRUE) return AutoProcess1; + else return AutoProcess2; + } + + return FormatProcess1; + } + + if ( sMenuSelectNo == 0 ) { y_pos = 7; } + else { y_pos = 9; } + + // i\XV + if ( ++progress >= 30*5 ) + { + progress = 0; + kamiFontPrintf(24, y_pos, FONT_COLOR_BLACK, " "); + } + + kamiFontPrintf((s16)(24 + (progress / 30)), y_pos, FONT_COLOR_BLACK, "*"); + + return FormatProcess3; +} + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_hw_info.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_hw_info.c new file mode 100644 index 00000000..8711c2a5 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_hw_info.c @@ -0,0 +1,664 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_hw_info.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include "kami_font.h" +#include "kami_pxi.h" +#include "process_topmenu.h" +#include "process_hw_info.h" +#include "process_auto.h" +#include "cursor.h" +#include "keypad.h" + +#include +//#include +//#include + +// +#include "TWLHWInfo_api.h" +#include "TWLSettings_api.h" +// + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define NUM_OF_MENU_SELECT 8 +#define DOT_OF_MENU_SPACE 16 +#define CHAR_OF_MENU_SPACE 2 +#define CURSOR_ORIGIN_X 32 +#define CURSOR_ORIGIN_Y 56 + +static const u32 s_langBitmapList[ LCFG_TWL_REGION_MAX ] = { + LCFG_TWL_LANG_BITMAP_JAPAN, + LCFG_TWL_LANG_BITMAP_AMERICA, + LCFG_TWL_LANG_BITMAP_EUROPE, + LCFG_TWL_LANG_BITMAP_AUSTRALIA, + LCFG_TWL_LANG_BITMAP_CHINA, + LCFG_TWL_LANG_BITMAP_KOREA, +}; + +static char *strLanguage[] = { + (char *)"LANG_JAPANESE", + (char *)"LANG_ENGLISH", + (char *)"LANG_FRENCH", + (char *)"LANG_GERMAN", + (char *)"LANG_ITALIAN", + (char *)"LANG_SPANISH", + (char *)"LANG_CHINESE", + (char *)"LANG_KOREAN", +}; + +static const char *strRegion[] = { + "JAPAN", + "AMERICA", + "EUROPE", + "AUSTRALIA", + "CHINA", + "KOREA", +}; + +static const char *strLauncherGameCode[] = { + "LNCJ", + "LNCE", + "LNCP", + "LNCO", + "LNCC", + "LNCK", +}; + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static s8 sMenuSelectNo; + +static u8 *s_pPrivKeyBuffer = NULL; +static LCFGReadResult (*s_pReadSecureInfoFunc)( void ); +static BOOL s_isReadTSD; + +/*---------------------------------------------------------------------------* + ֐錾 + *---------------------------------------------------------------------------*/ + +void HWInfoWriterInit( void ); +static void ReadTWLSettings( void ); +static void ModifyLanguage( u8 region ); +static void ReadPrivateKey( void ); +static void ReadHWInfoFile( void ); +static void VerifyHWInfo( void ); +static BOOL WriteHWInfoFile( u8 region ); +static BOOL WriteHWNormalInfoFile( void ); +static BOOL WriteHWSecureInfoFile( u8 region ); +static BOOL DeleteHWInfoFile( void ); + +const LCFGTWLHWNormalInfo *LCFG_THW_GetDefaultNormalInfo( void ); +const LCFGTWLHWSecureInfo *LCFG_THW_GetDefaultSecureInfo( void ); +const LCFGTWLHWNormalInfo *LCFG_THW_GetNormalInfo( void ); +const LCFGTWLHWSecureInfo *LCFG_THW_GetSecureInfo( void ); + +/*---------------------------------------------------------------------------* + vZX֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: HWInfo vZXO + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* HWInfoProcess0(void) +{ + int i; + + // SNA + kamiFontClear(); + + // o[W\ + kamiFontPrintf(2, 1, FONT_COLOR_BLACK, "Write Hardware Information "); + kamiFontPrintf(0, 2, FONT_COLOR_BLACK, "--------------------------------"); + + // j[ꗗ + kamiFontPrintf(3, 6, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 7, FONT_COLOR_BLACK, "l REGION JAPAN l l"); + kamiFontPrintf(3, 8, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 9, FONT_COLOR_BLACK, "l REGION AMERICA l l"); + kamiFontPrintf(3, 10, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 11, FONT_COLOR_BLACK, "l REGION EUROPE l l"); + kamiFontPrintf(3, 12, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 13, FONT_COLOR_BLACK, "l REGION AUSTRALIA l l"); + kamiFontPrintf(3, 14, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 15, FONT_COLOR_BLACK, "l REGION CHINA l l"); + kamiFontPrintf(3, 16, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 17, FONT_COLOR_BLACK, "l REGION KOREA l l"); + kamiFontPrintf(3, 18, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 19, FONT_COLOR_BLACK, "l DELETE l l"); + kamiFontPrintf(3, 20, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 21, FONT_COLOR_BLACK, "l RETURN l l"); + kamiFontPrintf(3, 22, FONT_COLOR_BLACK, "+--------------------+----+"); + + // wiSNA + for (i=0;i<24;i++) + { + kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS ); + } + + // wi㕔 + kamiFontFillChar( 0, BG_COLOR_PURPLE, BG_COLOR_PURPLE ); + kamiFontFillChar( 1, BG_COLOR_PURPLE, BG_COLOR_PURPLE ); + kamiFontFillChar( 2, BG_COLOR_PURPLE, BG_COLOR_TRANS ); + + // O + HWInfoWriterInit(); + + return HWInfoProcess1; +} + +/*---------------------------------------------------------------------------* + Name: HWInfo vZXP + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* HWInfoProcess1(void) +{ + // I[gsp + if (gAutoFlag) + { + sMenuSelectNo = 0; + return HWInfoProcess2; + } + + // Ij[̕ύX + if ( kamiPadIsRepeatTrigger(PAD_KEY_UP) ) + { + if (--sMenuSelectNo < 0) sMenuSelectNo = NUM_OF_MENU_SELECT -1; + } + else if ( kamiPadIsRepeatTrigger(PAD_KEY_DOWN) ) + { + if (++sMenuSelectNo >= NUM_OF_MENU_SELECT) sMenuSelectNo = 0; + } + + // J[\zu + SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNo * DOT_OF_MENU_SPACE)); + + // + if (kamiPadIsTrigger(PAD_BUTTON_A)) + { + return HWInfoProcess2; + } + // gbvj[֖߂ + else if (kamiPadIsTrigger(PAD_BUTTON_B)) + { + return TopmenuProcess0; + } + + return HWInfoProcess1; +} + +/*---------------------------------------------------------------------------* + Name: HWInfo vZXQ + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* HWInfoProcess2(void) +{ + int i; + BOOL result; + + switch( sMenuSelectNo ) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + OS_TPrintf( "Write Start.\n" ); + result = WriteHWInfoFile( (u8)sMenuSelectNo ); + break; + case 6: + OS_TPrintf( "Delete start.\n" ); + result = DeleteHWInfoFile(); + break; + case 7: + return TopmenuProcess0; + } + + // SʂNA + for (i=0;i \"%s\"\n", + strLanguage[ nowLanguage ], strLanguage[ LCFG_TSD_GetLanguage() ] ); + } +} + +/*---------------------------------------------------------------------------* + Name: 閧̃[h + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ + +static void ReadPrivateKey( void ) +{ + BOOL result = FALSE; + u32 keyLength; + FSFile file; + OSTick start = OS_GetTick(); + + FS_InitFile( &file ); + if( !FS_OpenFileEx( &file, "rom:key/private_HWInfo.der", FS_FILEMODE_R ) ) { + kamiFontPrintfConsoleEx(CONSOLE_RED, "PrivateKey read failed.\n" ); + }else { + keyLength = FS_GetFileLength( &file ); + if( keyLength > 0 ) { + s_pPrivKeyBuffer = OS_Alloc( keyLength ); + if( FS_ReadFile( &file, s_pPrivKeyBuffer, (s32)keyLength ) == keyLength ) { + OS_TPrintf( "PrivateKey read succeeded.\n" ); + result = TRUE; + }else { + kamiFontPrintfConsoleEx(CONSOLE_RED, "PrivateKey read failed.\n" ); + } + } + FS_CloseFile( &file ); + } + + if( !result && s_pPrivKeyBuffer ) { + OS_Free( s_pPrivKeyBuffer ); + s_pPrivKeyBuffer = NULL; + } + OS_TPrintf( "PrivKey read time = %dms\n", OS_TicksToMilliSeconds( OS_GetTick() - start ) ); + +#ifdef USE_PRODUCT_KEY + // ip閧LȂÃANZX + s_pReadSecureInfoFunc = LCFGi_THW_ReadSecureInfo; +#else + // łȂȂAȂ̃ANZX + s_pReadSecureInfoFunc = LCFGi_THW_ReadSecureInfo_NoCheck; +// PutStringUTF16( 14 * 8, 0 * 8, TXT_COLOR_RED, (const u16 *)L"[No Signature MODE]" ); +#endif +} + +/*---------------------------------------------------------------------------* + Name: HWŜ̃[h + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ + +static void ReadHWInfoFile( void ) +{ + LCFGReadResult retval; + OSTick start = OS_GetTick(); + + retval = LCFGi_THW_ReadNormalInfo(); + if( retval == LCFG_TSF_READ_RESULT_SUCCEEDED ) { + OS_Printf("HW Normal Info read succeeded.\n" ); + }else { + kamiFontPrintfConsoleEx(0, "HW Normal Info read failed.\n" ); + } + + OS_TPrintf( "HW Normal Info read time = %dms\n", OS_TicksToMilliSeconds( OS_GetTick() - start ) ); + + start = OS_GetTick(); + retval = s_pReadSecureInfoFunc(); + if( retval == LCFG_TSF_READ_RESULT_SUCCEEDED ) { + OS_Printf("HW Secure Info read succeeded.\n" ); + }else { + kamiFontPrintfConsoleEx(0, "HW Secure Info read failed.\n" ); + } + OS_TPrintf( "HW Secure Info read time = %dms\n", OS_TicksToMilliSeconds( OS_GetTick() - start ) ); +} + +/*---------------------------------------------------------------------------* + Name: HWŜ̃Cg + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ + +static BOOL WriteHWInfoFile( u8 region ) +{ + static const u16 *pMsgNormalWriting = (const u16 *)L"Writing Normal File..."; + static const u16 *pMsgSecureWriting = (const u16 *)L"Writing Secure File..."; + static const u16 *pMsgSucceeded = (const u16 *)L"Succeeded!"; + static const u16 *pMsgFailed = (const u16 *)L"Failed!"; + BOOL result = TRUE; + + // m[}t@C̃Cg +// (void)PutStringUTF16( MSG_X * 8, MSG_Y * 8, TXT_COLOR_BLACK, pMsgNormalWriting ); + + if( WriteHWNormalInfoFile() ) { +// (void)PutStringUTF16( ( MSG_X + 18 ) * 8, MSG_Y * 8, TXT_COLOR_BLUE, pMsgSucceeded ); + }else { +// (void)PutStringUTF16( ( MSG_X + 18 ) * 8, MSG_Y * 8, TXT_COLOR_RED, pMsgFailed ); + result = FALSE; + } + + // ZLAt@C̃Cg +// (void)PutStringUTF16( MSG_X * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_BLACK, pMsgSecureWriting ); + + if( WriteHWSecureInfoFile( region ) ) { +// (void)PutStringUTF16( ( MSG_X + 18 ) * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_BLUE, pMsgSucceeded ); + }else { +// (void)PutStringUTF16( ( MSG_X + 18 ) * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_RED, pMsgFailed ); + result = FALSE; + } + + ModifyLanguage( region ); + + // bZ[W莞ԕ\ď +// DispMessage( 0, 0, TXT_COLOR_NULL, NULL ); +// NNS_G2dCharCanvasClearArea( &gCanvas, TXT_COLOR_WHITE, +// MSG_X * 8 , MSG_Y * 8, ( 32 - MSG_X ) * 8, ( MSG_Y + 4 ) * 8 ); + + return result; +} + +/*---------------------------------------------------------------------------* + Name: HWm[}Infot@C̃Cg + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ + +static BOOL WriteHWNormalInfoFile( void ) +{ + BOOL isWrite = TRUE; + LCFGReadResult result; + + result = LCFGi_THW_ReadNormalInfo(); + if( result != LCFG_TSF_READ_RESULT_SUCCEEDED ) { + if( !LCFGi_THW_RecoveryNormalInfo( result ) ) { + kamiFontPrintfConsoleEx(CONSOLE_RED, "HW Normal Info Recovery failed.\n" ); + isWrite = FALSE; + } + } + if( isWrite && + !LCFGi_THW_WriteNormalInfo() ) { + kamiFontPrintfConsoleEx(CONSOLE_RED, "HW Normal Info Write failed.\n" ); + } + + return isWrite; +} + +/*---------------------------------------------------------------------------* + Name: HWZLAInfot@C̃Cg + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ + +static BOOL WriteHWSecureInfoFile( u8 region ) +{ + BOOL isWrite = TRUE; + LCFGReadResult result; + + // t@C̃[h + result = s_pReadSecureInfoFunc(); + + // [hɎs烊Jo + if( result != LCFG_TSF_READ_RESULT_SUCCEEDED ) { + if( !LCFGi_THW_RecoverySecureInfo( result ) ) { + kamiFontPrintfConsoleEx(CONSOLE_RED, "HW Secure Info Recovery failed.\n" ); + isWrite = FALSE; + } + } + + // [W̃Zbg + LCFG_THW_SetRegion( region ); + + // Ήrbg}bṽZbg + LCFG_THW_SetValidLanguageBitmap( s_langBitmapList[ region ] ); + + // [TODO:]ʎYHłȂƃVANo.͗pӂłȂ̂ŁAłMACAhXƂɓKȒlZbgB + // VANo.̃Zbg + { + u8 buffer[ 12 ] = "SERIAL"; // KȕMACAhXƌSHA1ASerialNoƂB + u8 serialNo[ SVC_SHA1_DIGEST_SIZE ]; + int i; + int len = ( LCFG_THW_GetRegion() == LCFG_TWL_REGION_AMERICA ) ? + LCFG_TWL_HWINFO_SERIALNO_LEN_AMERICA : LCFG_TWL_HWINFO_SERIALNO_LEN_OTHERS; + OS_GetMacAddress( buffer + 6 ); + SVC_CalcSHA1( serialNo, buffer, sizeof(buffer) ); + for( i = 3; i < SVC_SHA1_DIGEST_SIZE; i++ ) { + serialNo[ i ] = (u8)( ( serialNo[ i ] % 10 ) + 0x30 ); + } + MI_CpuCopy8( "SRN", serialNo, 3 ); + MI_CpuClear8( &serialNo[ len ], sizeof(serialNo) - len ); + OS_TPrintf( "serialNo : %s\n", serialNo ); + LCFG_THW_SetSerialNo( serialNo ); + } + + // `[Q[R[h + LCFG_THW_SetLauncherTitleID_Lo( (const u8 *)strLauncherGameCode[ region ] ); + + // Cg + if( isWrite && + !LCFGi_THW_WriteSecureInfo( s_pPrivKeyBuffer ) ) { + isWrite = FALSE; + kamiFontPrintfConsoleEx(CONSOLE_RED, "HW Secure Info Write failed.\n" ); + } + + return isWrite; +} + +/*---------------------------------------------------------------------------* + Name: HWInfot@C̍폜 + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ + +static BOOL DeleteHWInfoFile( void ) +{ + static const u16 *pMsgNormalDeleting = (const u16 *)L"Deleting Normal File..."; + static const u16 *pMsgSecureDeleting = (const u16 *)L"Deteting Secure File..."; + static const u16 *pMsgSucceeded = (const u16 *)L"Succeeded!"; + static const u16 *pMsgFailed = (const u16 *)L"Failed!"; + BOOL result = TRUE; + + // m[}t@C +// (void)PutStringUTF16( MSG_X * 8, MSG_Y * 8, TXT_COLOR_BLACK, pMsgNormalDeleting ); + if( FS_DeleteFile( (char *)LCFG_TWL_HWINFO_NORMAL_PATH ) ) { + OS_TPrintf( "%s delete succeeded.\n", (char *)LCFG_TWL_HWINFO_NORMAL_PATH ); +// (void)PutStringUTF16( ( MSG_X + 19 ) * 8, MSG_Y * 8, TXT_COLOR_BLUE, pMsgSucceeded ); + }else { + OS_TPrintf( "%s delete failed.\n", (char *)LCFG_TWL_HWINFO_NORMAL_PATH ); +// (void)PutStringUTF16( ( MSG_X + 19 ) * 8, MSG_Y * 8, TXT_COLOR_RED, pMsgFailed ); + result = FALSE; + } + + // ZLAt@C +// (void)PutStringUTF16( MSG_X * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_BLACK, pMsgSecureDeleting ); + if( FS_DeleteFile( (char *)LCFG_TWL_HWINFO_SECURE_PATH ) ) { + OS_TPrintf( "%s delete succeeded.\n", (char *)LCFG_TWL_HWINFO_SECURE_PATH ); +// (void)PutStringUTF16( ( MSG_X + 19 ) * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_BLUE, pMsgSucceeded ); + }else { + OS_TPrintf( "%s delete failed.\n", (char *)LCFG_TWL_HWINFO_SECURE_PATH ); +// (void)PutStringUTF16( ( MSG_X + 19 ) * 8, ( MSG_Y + 2 ) * 8, TXT_COLOR_RED, pMsgFailed ); + result = FALSE; + } +// DispMessage( 0, 0, TXT_COLOR_NULL, NULL ); +// NNS_G2dCharCanvasClearArea( &gCanvas, TXT_COLOR_WHITE, +// MSG_X * 8 , MSG_Y * 8, ( 32 - MSG_X ) * 8, ( MSG_Y + 4 ) * 8 ); + + return result; +} diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_import.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_import.c new file mode 100644 index 00000000..962827d3 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_import.c @@ -0,0 +1,881 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_import.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include "kami_font.h" +#include "kami_pxi.h" +#include "process_topmenu.h" +#include "process_import.h" +#include "process_eticket.h" +#include "process_auto.h" +#include "cursor.h" +#include "keypad.h" + +#include "TWLHWInfo_api.h" + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +typedef enum { + TAD_WRITE_OPTION_OVERWRITE, // ㏑ + TAD_WRITE_OPTION_NONEXISTENT, // NANDɓvO݂ȂꍇɌ菑 + TAD_WRITE_OPTION_USER // [U[ɑI +} TadWriteOption; + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define NUM_OF_MENU_SELECT 4 +#define NUM_OF_MENU_SELECT_INDIVIDUALLY 17 + +#define DOT_OF_MENU_SPACE 16 +#define DOT_OF_MENU_SPACE_INDIVIDUALLY 8 + +#define CHAR_OF_MENU_SPACE 2 +#define CHAR_OF_MENU_SPACE_INDIVIDUALLY 1 + +#define CURSOR_ORIGIN_X 32 +#define CURSOR_ORIGIN_Y 40 + + +// \C|[gł.TADt@C͍ő16‚܂ +// rcJ[h̃[gɑ݂t@Ĉ݂Ƃy +#define FILE_NUM_MAX 16 + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static s32 sMenuSelectNo; +static s32 sMenuSelectNoIndividually; + +static LCFGReadResult (*s_pReadSecureInfoFunc)( void ); + +static char sFilePath[FILE_NUM_MAX][FS_ENTRY_LONGNAME_MAX]; + +static u8 sFileNum; + +static void* spStack; + +static u32 sCurrentProgress; + +static vu8 sNowImport = FALSE; + +/*---------------------------------------------------------------------------* + ֐錾 + *---------------------------------------------------------------------------*/ + +static BOOL ImportTad(char* file_name, TadWriteOption option); +static void ProgressThread(void* arg); +static void Destructor(void* arg); +static void DumpTadInfo(void); +static void MakeFullPathForSD(char* file_name, char* full_path); +static void ShowTitleinfoDifference( NAMTitleInfo* titleInfoNand, NAMTitleInfo* titleInfoSd); +void ProgessInit(void); +void ProgressDraw(f32 ratio); +static void* ImportProcessReturn(void); + +static void* ImportIndividuallyProcess0(void); +static void* ImportIndividuallyProcess1(void); +static void* ImportIndividuallyProcess2(void); +static void* ImportIndividuallyProcess3(void); + +static void* ImportAllOverwriteProcess0(void); +static void* ImportAllOverwriteProcess1(void); +static void* ImportAllOverwriteProcess2(void); +static void* ImportAllOverwriteProcess3(void); + +static void* ImportAllNonexistentProcess0(void); +static void* ImportAllNonexistentProcess1(void); +static void* ImportAllNonexistentProcess2(void); +static void* ImportAllNonexistentProcess3(void); + +/*---------------------------------------------------------------------------* + vZX֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: Import vZXO + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* ImportProcess0(void) +{ + FATFSFileHandle fat_handle; + FSFile dir; + int i; + + // F:sys/cert.sys݂ȂȂoĂ炤 + fat_handle = FATFS_OpenFile(E_TICKET_FILE_PATH_IN_NAND, "r"); + if (!fat_handle) + { + FATFS_CloseFile(fat_handle); + return ImportProcessReturn; + } + FATFS_CloseFile(fat_handle); + + // SNA + kamiFontClear(); + + // o[W\ + kamiFontPrintf(2, 1, FONT_COLOR_BLACK, "Import TAD from SD"); + kamiFontPrintf(0, 2, FONT_COLOR_BLACK, "--------------------------------"); + + // j[ꗗ + kamiFontPrintf(3, 4, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 5, FONT_COLOR_BLACK, "l OVERWRITE ALL l l"); + kamiFontPrintf(3, 6, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 7, FONT_COLOR_BLACK, "l WRITE NONEXISTENT l l"); + kamiFontPrintf(3, 8, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 9, FONT_COLOR_BLACK, "l SELECT FILE >> l l"); + kamiFontPrintf(3, 10, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf(3, 11, FONT_COLOR_BLACK, "l RETURN l l"); + kamiFontPrintf(3, 12, FONT_COLOR_BLACK, "+--------------------+----+"); + + // zNA + MI_CpuClear8( sFilePath, sizeof(sFilePath) ); + + // t@C + sFileNum = 0; + + // wiSNA + for (i=0;i<24;i++) + { + kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS ); + } + + // wi㕔 + kamiFontFillChar( 0, BG_COLOR_PINK, BG_COLOR_PINK ); + kamiFontFillChar( 1, BG_COLOR_PINK, BG_COLOR_PINK ); + kamiFontFillChar( 2, BG_COLOR_PINK, BG_COLOR_TRANS ); + + // SDJ[h̃[gfBNg + if ( !FS_OpenDirectory(&dir, "sdmc:/", FS_FILEMODE_R | FS_FILEMODE_W) ) + { + kamiFontPrintfConsole(CONSOLE_RED, "Error FS_OpenDirectory(sdmc:/)\n"); + } + else + { + FSDirectoryEntryInfo info[1]; + OS_Printf("[%s]:\n", "sdmc:/"); + + kamiFontPrintfConsole(CONSOLE_ORANGE, "------ tad file List -----\n"); + + // .dat .nand .nor Tăt@CۑĂ + while (FS_ReadDirectory(&dir, info)) + { + OS_Printf(" %s", info->longname); + if ((info->attributes & (FS_ATTRIBUTE_DOS_DIRECTORY | FS_ATTRIBUTE_IS_DIRECTORY)) != 0) + { + OS_Printf("/\n"); + } + else + { + char* pExtension; + OS_Printf(" (%d BYTEs)\n", info->filesize); + + // gq̃`FbN + pExtension = STD_SearchCharReverse( info->longname, '.'); + if (pExtension) + { + if (!STD_CompareString( pExtension, ".tad") ) + { + char full_path[FS_ENTRY_LONGNAME_MAX+6]; + + // tpX쐬 + MakeFullPathForSD(info->longname, full_path); + + STD_CopyString( sFilePath[sFileNum], info->longname ); + kamiFontPrintfConsole(CONSOLE_ORANGE, "%d:%s\n", sFileNum, info->longname); + + // ő16‚ŏI + if (++sFileNum >= FILE_NUM_MAX) + { + break; + } + } + } + } + } + (void)FS_CloseDirectory(&dir); + + kamiFontPrintfConsole(CONSOLE_ORANGE, "--------------------------\n"); + +// DumpTadInfo(); + } + + return ImportProcess1; +} + +/*---------------------------------------------------------------------------* + Name: Import vZXP + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* ImportProcess1(void) +{ + // I[gsp + if (gAutoFlag) + { + sMenuSelectNo = 0; + return ImportProcess2; + } + + // Ij[̕ύX + if ( kamiPadIsRepeatTrigger(PAD_KEY_UP) ) + { + if (--sMenuSelectNo < 0) sMenuSelectNo = NUM_OF_MENU_SELECT -1; + } + else if ( kamiPadIsRepeatTrigger(PAD_KEY_DOWN) ) + { + if (++sMenuSelectNo >= NUM_OF_MENU_SELECT) sMenuSelectNo = 0; + } + + // J[\zu + SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNo * DOT_OF_MENU_SPACE)); + + // + if (kamiPadIsTrigger(PAD_BUTTON_A)) + { + return ImportProcess2; + } + // gbvj[֖߂ + else if (kamiPadIsTrigger(PAD_BUTTON_B)) + { + return TopmenuProcess0; + } + + return ImportProcess1; +} + +/*---------------------------------------------------------------------------* + Name: Import vZXQ + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* ImportProcess2(void) +{ + switch( sMenuSelectNo ) + { + case 0: + return ImportAllOverwriteProcess0; + break; + case 1: + return ImportAllNonexistentProcess0; + break; + case 2: + return ImportIndividuallyProcess0; + case 3: + return TopmenuProcess0; + } + + return ImportProcess1; +} + +/*---------------------------------------------------------------------------* + Name: Import vZXR + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* ImportProcessReturn(void) +{ + int i; + + // SNA + kamiFontClear(); + kamiFontPrintf(4, 10, FONT_COLOR_RED, "%s is not exist", E_TICKET_FILE_PATH_IN_NAND); + kamiFontPrintf(4, 11, FONT_COLOR_RED, "You should write e-ticket", E_TICKET_FILE_PATH_IN_NAND); + kamiFontPrintf(4, 12, FONT_COLOR_RED, "beforehand.", E_TICKET_FILE_PATH_IN_NAND); + kamiFontPrintf(4, 22, FONT_COLOR_BLACK, "B Button : return to menu"); + + // o[W\ + kamiFontPrintf(2, 1, FONT_COLOR_BLACK, "Import TAD from SD"); + kamiFontPrintf(0, 2, FONT_COLOR_BLACK, "--------------------------------"); + + // wiSNA + for (i=0;i<24;i++) + { + kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS ); + } + + // wi㕔 + kamiFontFillChar( 0, BG_COLOR_PINK, BG_COLOR_PINK ); + kamiFontFillChar( 1, BG_COLOR_PINK, BG_COLOR_PINK ); + kamiFontFillChar( 2, BG_COLOR_PINK, BG_COLOR_TRANS ); + + // J[\ + SetCursorPos((u16)200, (u16)200); + + // tHgXN[f[^[h + kamiFontLoadScreenData(); + + while(1) + { + kamiPadRead(); + if (kamiPadIsTrigger(PAD_BUTTON_B)) { break; } + } + + return TopmenuProcess0; +} + +/*---------------------------------------------------------------------------* + St@CC|[gvZXi㏑j + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: St@CImport vZXO + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +static void* ImportAllOverwriteProcess0(void) +{ + int i; + BOOL result = TRUE; + + kamiFontPrintf(25, 5, FONT_COLOR_BLACK, "WAIT"); + + for (i=0;i 0) return AutoProcess1; + else return AutoProcess2; + } + + return ImportProcess1; +} + +/*---------------------------------------------------------------------------* + St@CC|[gvZXit@C͏㏑Ȃj + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: dȂt@CImport vZXO + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +static void* ImportAllNonexistentProcess0(void) +{ + int i; + BOOL result = TRUE; + + kamiFontPrintf(25, 7, FONT_COLOR_BLACK, "WAIT"); + + for (i=0;i sFileNum) sMenuSelectNoIndividually = 0; + DumpTadInfo(); + } + + // J[\zu + SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNoIndividually * DOT_OF_MENU_SPACE_INDIVIDUALLY)); + + // + if (kamiPadIsTrigger(PAD_BUTTON_A)) + { + return ImportIndividuallyProcess2; + } + // ЂƂ‘Õj[֖߂ + else if (kamiPadIsTrigger(PAD_BUTTON_B)) + { + return ImportProcess0; + } + + return ImportIndividuallyProcess1; +} + +/*---------------------------------------------------------------------------* + Name: •Import vZXQ + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +#define THREAD_STACK_SIZE (16*1024) + +void* ImportIndividuallyProcess2(void) +{ + BOOL ret; + + if (STD_GetStringLength(sFilePath[sMenuSelectNoIndividually])) + { + // •ʃC|[g + ret = ImportTad(sFilePath[sMenuSelectNoIndividually], TAD_WRITE_OPTION_USER); + } + else + { + // ^[ + return ImportProcess0; + } + + // ̌ʂ\ + if ( ret == TRUE ) + { + kamiFontPrintf(26, (s16)(5+sMenuSelectNoIndividually*CHAR_OF_MENU_SPACE_INDIVIDUALLY), FONT_COLOR_GREEN, "OK"); + } + else + { + kamiFontPrintf(26, (s16)(5+sMenuSelectNoIndividually*CHAR_OF_MENU_SPACE_INDIVIDUALLY), FONT_COLOR_RED, "NG"); + } + + return ImportIndividuallyProcess1; +} + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: ImportTad + + Description: .tad t@CC|[g + + Arguments: no + + Returns: None. + *---------------------------------------------------------------------------*/ +static BOOL ImportTad(char* file_name, TadWriteOption option) +{ + NAMTadInfo tadInfo; + NAMTitleInfo titleInfo; + char full_path[FS_ENTRY_LONGNAME_MAX+6]; + OSThread thread; + BOOL ret = FALSE; + s32 nam_result; + + // tpX쐬 + MakeFullPathForSD(file_name, full_path); + + // tadt@C̏擾 + if (NAM_ReadTadInfo(&tadInfo, full_path) != NAM_OK) + { + return FALSE; + } + + // NAND̏擾 + if ( option != TAD_WRITE_OPTION_OVERWRITE && NAM_ReadTitleInfo(&titleInfo, tadInfo.titleInfo.titleId) == NAM_OK) + { + // NANDɊɃCXg[Ă邩ǂmF + if (tadInfo.titleInfo.titleId == titleInfo.titleId) + { + switch (option) + { + case TAD_WRITE_OPTION_NONEXISTENT: + return TRUE; + case TAD_WRITE_OPTION_USER: + ShowTitleinfoDifference(&titleInfo, &tadInfo.titleInfo); + + kamiFontPrintfConsole(1, "The program has already existed."); + kamiFontPrintfConsole(1, "Do you overwrite ?\n"); + kamiFontPrintfConsole(1, " \n"); + + // tHgXN[f[^[h + kamiFontLoadScreenData(); + + while(1) + { + kamiPadRead(); + + if (kamiPadIsTrigger(PAD_BUTTON_A)) + { + break; + } + else if (kamiPadIsTrigger(PAD_BUTTON_B)) + { + kamiFontPrintfConsole(CONSOLE_ORANGE, "Import was canceled.\n"); + return TRUE; + } + } + } + } + } + + // C|[gJntO𗧂Ă + sNowImport = TRUE; + + // iXbh쐬 + spStack = OS_Alloc(THREAD_STACK_SIZE); + MI_CpuClear8(spStack, THREAD_STACK_SIZE); + OS_CreateThread(&thread, ProgressThread, NULL, + (void*)((u32)spStack + THREAD_STACK_SIZE), THREAD_STACK_SIZE, OS_THREAD_PRIORITY_MAX); + // fXgN^Zbg + OS_SetThreadDestructor( &thread, Destructor ); + OS_WakeupThreadDirect(&thread); + + // ImportJn + OS_Printf( "Import %s Start.\n", full_path ); + kamiFontPrintfConsole(CONSOLE_ORANGE, "Import %s Start.\n", file_name ); + + nam_result = NAM_ImportTad( full_path ); + + // iXbh̎͏I҂ + while (sNowImport){ OS_Sleep(1); }; + + if ( nam_result == NAM_OK ) + { + kamiFontPrintfConsole(CONSOLE_ORANGE, "Import %s Sucess.\n", file_name ); + ret = TRUE; + } + else + { + kamiFontPrintfConsole(1, "Import %s Fail.\n", file_name ); + } + + return ret; +} + +static void Destructor(void* /*arg*/) +{ + OS_Free(spStack); +} + +/*---------------------------------------------------------------------------* + Name: ProgressThread + + Description: .tad t@CC|[g̐i\XbhB + i100%ɒBƏ𔲂B + + Arguments: arg - gpȂB + + Returns: None. + *---------------------------------------------------------------------------*/ + +static void ProgressThread(void* /*arg*/) +{ + u32 currentSize; + u32 totalSize = 0; + u32 totalSizeBk = 0; + + ProgressInit(); + + while (TRUE) + { + NAM_GetProgress(¤tSize, &totalSize); + + if ((totalSize > 0 && totalSize == currentSize) || totalSizeBk > totalSize) + { + // ɃC|[gI + ProgressDraw((f32)1.0); + break; + } + else if (totalSize > 0) + { + ProgressDraw((f32)currentSize/totalSize); + } + + totalSizeBk = totalSize; + } + + sNowImport = FALSE; +} + +/*---------------------------------------------------------------------------* + Name: DumpTadInfo + + Description: .tad t@C̏\ + + Arguments: arg - gpȂB + + Returns: None. + *---------------------------------------------------------------------------*/ + +static void DumpTadInfo(void) +{ + NAMTadInfo info; + + // t@C̗LmF + if (STD_GetStringLength(sFilePath[sMenuSelectNoIndividually])) + { + char full_path[FS_ENTRY_LONGNAME_MAX+6]; + + // tpX쐬 + MakeFullPathForSD( sFilePath[sMenuSelectNoIndividually], full_path ); + + // TADt@C̏擾 + if (NAM_ReadTadInfo(&info, full_path) == NAM_OK) + { + char temp[100]; + u16 companyCode = MI_SwapEndian16(info.titleInfo.companyCode); + u32 gameCode = (u32)(info.titleInfo.titleId & 0xffffffff); + gameCode = MI_SwapEndian32(gameCode); + + kamiFontPrintfConsole(CONSOLE_ORANGE, "------ tad profile -----\n"); + + // File Name + kamiFontPrintfConsole(CONSOLE_ORANGE, "%s\n", sFilePath[sMenuSelectNoIndividually]); + + // File Size + kamiFontPrintfConsole(CONSOLE_ORANGE, "fileSize = %d Byte\n", info.fileSize); + + // Company Code + MI_CpuCopy8( &companyCode, temp, sizeof(companyCode) ); + temp[sizeof(companyCode)] = NULL; + kamiFontPrintfConsole(CONSOLE_ORANGE, "Company Code = %s\n", temp); + + // Game Code + MI_CpuCopy8( &gameCode, temp, sizeof(gameCode) ); + temp[sizeof(gameCode)] = NULL; + kamiFontPrintfConsole(CONSOLE_ORANGE, "GameCode Code = %s\n", temp); + + // Game Version + kamiFontPrintfConsole(CONSOLE_ORANGE, "GameVersion = %d\n", info.titleInfo.version); + + kamiFontPrintfConsole(CONSOLE_ORANGE, "--------------------------\n"); + } + } +} + +/*---------------------------------------------------------------------------* + Name: MakeFullPathForSD + + Description: + + Arguments: no + + Returns: None. + *---------------------------------------------------------------------------*/ +static void MakeFullPathForSD(char* file_name, char* full_path) +{ + // tpX쐬 + STD_CopyString( full_path, "sdmc:/" ); + STD_ConcatenateString( full_path, file_name ); +} + +/*---------------------------------------------------------------------------* + Name: ShowTitleinfoDifference + + Description: NANDvOSDvO̔r\ + + Arguments: + + Returns: None. + *---------------------------------------------------------------------------*/ +static void ShowTitleinfoDifference( NAMTitleInfo* titleInfoNand, NAMTitleInfo* titleInfoSd) +{ + char tempOld[100]; + char tempNew[100]; + u16 companyCode; + u32 gameCode; + + kamiFontPrintfConsole(CONSOLE_ORANGE, "+--------------+-------+-------+"); + kamiFontPrintfConsole(CONSOLE_ORANGE, "l l NAND l SD l"); + kamiFontPrintfConsole(CONSOLE_ORANGE, "+--------------+-------+-------+"); + + // Company Code (nand) + companyCode = MI_SwapEndian16(titleInfoNand->companyCode); + MI_CpuCopy8( &companyCode, tempOld, sizeof(companyCode) ); + tempOld[sizeof(companyCode)] = NULL; + + // Company Code (sd) + companyCode = MI_SwapEndian16(titleInfoSd->companyCode); + MI_CpuCopy8( &companyCode, tempNew, sizeof(companyCode) ); + tempNew[sizeof(companyCode)] = NULL; + kamiFontPrintfConsole(CONSOLE_ORANGE, "l Company Code l %-2.2s l %-2.2s l", tempOld, tempNew); + + // Game Code (nand) + gameCode = (u32)(titleInfoNand->titleId & 0xffffffff); + gameCode = MI_SwapEndian32(gameCode); + MI_CpuCopy8( &gameCode, tempOld, sizeof(gameCode) ); + tempOld[sizeof(gameCode)] = NULL; + + // Game Code (sd) + gameCode = (u32)(titleInfoSd->titleId & 0xffffffff); + gameCode = MI_SwapEndian32(gameCode); + MI_CpuCopy8( &gameCode, tempNew, sizeof(gameCode) ); + tempNew[sizeof(gameCode)] = NULL; + kamiFontPrintfConsole(CONSOLE_ORANGE, "l Game Code l %-4.4s l %-4.4s l", tempOld, tempNew); + + // Game Version + kamiFontPrintfConsole(CONSOLE_ORANGE, "l Game Version l %-4.4d l %-4.4d l", titleInfoNand->version, titleInfoSd->version ); + kamiFontPrintfConsole(CONSOLE_ORANGE, "+--------------+-------+-------+"); +} + +/*---------------------------------------------------------------------------* + Name: ProgressInit + + Description: C|[g̐i\܂ + + Arguments: + + Returns: None. + *---------------------------------------------------------------------------*/ +void ProgressInit(void) +{ + sCurrentProgress = 0; +} + +/*---------------------------------------------------------------------------* + Name: ProgressDraw + + Description: C|[g̐i\܂ + + Arguments: + + Returns: None. + *---------------------------------------------------------------------------*/ +void ProgressDraw(f32 ratio) +{ + char square[2] = { 0x01, 0x00 }; + u32 temp; + s32 i; + + temp = (u32)(32 * ratio); + if (temp > sCurrentProgress) + { + s32 diff = (s32)(temp - sCurrentProgress); + for (i=0;i +#include +#include +#include +#include +#include "kami_font.h" +#include "kami_pxi.h" +#include "process_topmenu.h" +#include "process_nandfirm.h" +#include "process_import.h" +#include "process_auto.h" +#include "cursor.h" +#include "keypad.h" + +#include "TWLHWInfo_api.h" +#include +#include <../build/libraries/spi/ARM9/include/spi.h> + +/*---------------------------------------------------------------------------* + }N` + *---------------------------------------------------------------------------*/ +#define ROUND_UP(value, alignment) \ + (((u32)(value) + (alignment-1)) & ~(alignment-1)) + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define DOT_OF_MENU_SPACE 8 +#define CHAR_OF_MENU_SPACE 1 +#define CURSOR_ORIGIN_X 32 +#define CURSOR_ORIGIN_Y 40 + +#define FILE_NUM_MAX 16 + +#define NAND_BLOCK_BYTE 0x200 +#define NAND_BOOT_FLAG_ADDRESS 0x2ff +#define NAND_FIRM_START_OFFSET 0x200 + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static s32 sMenuSelectNo; +static char sFilePath[FILE_NUM_MAX][FS_ENTRY_LONGNAME_MAX]; +static u8 sFileNum; +static u8 sNandBootFlag = 0xff; + +/*---------------------------------------------------------------------------* + ֐錾 + *---------------------------------------------------------------------------*/ + +static void MakeFullPathForSD(char* file_name, char* full_path); +static BOOL WriteNandfirm(char* file_name); + +/*---------------------------------------------------------------------------* + vZX֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: Import vZXO + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* NandfirmProcess0(void) +{ + FSFile dir; + int i; + + // SNA + kamiFontClear(); + + // o[W\ + kamiFontPrintf(2, 1, FONT_COLOR_BLACK, "Import NandFirm from SD"); + kamiFontPrintf(0, 2, FONT_COLOR_BLACK, "--------------------------------"); + + // zNA + MI_CpuClear8( sFilePath, sizeof(sFilePath) ); + + // t@C + sFileNum = 0; + + // wiSNA + for (i=0;i<24;i++) + { + kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS ); + } + + // wi㕔 + kamiFontFillChar( 0, BG_COLOR_GREEN, BG_COLOR_GREEN ); + kamiFontFillChar( 1, BG_COLOR_GREEN, BG_COLOR_GREEN ); + kamiFontFillChar( 2, BG_COLOR_GREEN, BG_COLOR_TRANS ); + + // SDJ[h̃[gfBNg + if ( !FS_OpenDirectory(&dir, "sdmc:/", FS_FILEMODE_R | FS_FILEMODE_W) ) + { + OS_Printf("Error FS_OpenDirectory(sdmc:/)\n"); + kamiFontPrintf(3, 13, FONT_COLOR_BLACK, "Error FS_OpenDirectory(sdmc:/)"); + } + else + { + FSDirectoryEntryInfo info[1]; + OS_Printf("[%s]:\n", "sdmc:/"); + + kamiFontPrintfConsole(CONSOLE_ORANGE, "------ nand file list -----\n"); + + // .nand Tăt@CۑĂ + while (FS_ReadDirectory(&dir, info)) + { + OS_Printf(" %s", info->longname); + if ((info->attributes & (FS_ATTRIBUTE_DOS_DIRECTORY | FS_ATTRIBUTE_IS_DIRECTORY)) != 0) + { + OS_Printf("/\n"); + } + else + { + char* pExtension; + OS_Printf(" (%d BYTEs)\n", info->filesize); + + // gq̃`FbN + pExtension = STD_SearchCharReverse( info->longname, '.'); + if (pExtension) + { + if (!STD_CompareString( pExtension, ".nand") || !STD_CompareString( pExtension, ".NAND")) + { + STD_CopyString( sFilePath[sFileNum], info->longname ); + kamiFontPrintfConsole(CONSOLE_ORANGE, "%d:%s\n", sFileNum, info->longname); + + // ő16‚ŏI + if (++sFileNum >= FILE_NUM_MAX) + { + break; + } + } + } + } + } + (void)FS_CloseDirectory(&dir); + + kamiFontPrintfConsole(CONSOLE_ORANGE, "--------------------------\n"); + } + + // j[ꗗ + kamiFontPrintf((s16)3, (s16)4, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf((s16)3, (s16)(5+sFileNum+1), FONT_COLOR_BLACK, "+--------------------+----+"); + + // tad t@CXg\ + for (i=0;i sFileNum) sMenuSelectNo = 0; + } + + // J[\zu + SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNo * DOT_OF_MENU_SPACE)); + + // + if (kamiPadIsTrigger(PAD_BUTTON_A)) + { + return NandfirmProcess2; + } + // gbvj[֖߂ + else if (kamiPadIsTrigger(PAD_BUTTON_B)) + { + return TopmenuProcess0; + } + + return NandfirmProcess1; +} + +/*---------------------------------------------------------------------------* + Name: vZX2 + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* NandfirmProcess2(void) +{ + BOOL ret; + + if (STD_GetStringLength(sFilePath[sMenuSelectNo])) + { + ret = WriteNandfirm(sFilePath[sMenuSelectNo]); + } + else + { + if (gAutoFlag) { return AutoProcess2; } + else { return TopmenuProcess0; } + } + + // ̌ʂ\ + if ( ret == TRUE ) + { + kamiFontPrintf((s16)26, (s16)(5+sMenuSelectNo*CHAR_OF_MENU_SPACE), FONT_COLOR_GREEN, "OK"); + } + else + { + kamiFontPrintf((s16)26, (s16)(5+sMenuSelectNo*CHAR_OF_MENU_SPACE), FONT_COLOR_RED, "NG"); + } + + // Autop + if (gAutoFlag) + { + if (ret) return AutoProcess1; + else return AutoProcess2; + } + + return NandfirmProcess1; +} + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: MakeFullPathForSD + + Description: + + Arguments: no + + Returns: None. + *---------------------------------------------------------------------------*/ +static void MakeFullPathForSD(char* file_name, char* full_path) +{ + // tpX쐬 + STD_CopyString( full_path, "sdmc:/" ); + STD_ConcatenateString( full_path, file_name ); +} + +/*---------------------------------------------------------------------------* + Name: MakeFullPathForSD + + Description: + + Arguments: no + + Returns: None. + *---------------------------------------------------------------------------*/ +static BOOL WriteNandfirm(char* file_name) +{ + FSFile file; + char full_path[FS_ENTRY_LONGNAME_MAX+6]; + BOOL open_is_ok; + BOOL read_is_ok; + u8* pTempBuf; + u32 file_size; + u32 alloc_size; + u32 write_size; + BOOL result = TRUE; + u16 crc_w1, crc_w2; + u16 crc_r1, crc_r2; + + // .nand̃tpX쐬 + MakeFullPathForSD(file_name, full_path); + + // .nandt@CI[v + FS_InitFile(&file); + open_is_ok = FS_OpenFile(&file, full_path); + OS_Printf("FS_OpenFile(\"%s\") ... %s!\n", full_path, open_is_ok ? "OK" : "ERROR"); + + // TCY`FbN + file_size = FS_GetFileLength(&file) ; + if (file_size > (800*1024)) + { + kamiFontPrintfConsoleEx(1, "too big file size!\n"); + FS_CloseFile(&file); + return FALSE; + } + + // obt@m + alloc_size = ROUND_UP(file_size, 32) ; + pTempBuf = OS_Alloc( alloc_size ); + if (pTempBuf == NULL) + { + kamiFontPrintfConsoleEx(1, "Fail Alloc()!\n"); + FS_CloseFile(&file); + return FALSE; + } + + // .nandt@C[h + read_is_ok = FS_ReadFile( &file, pTempBuf, (s32)file_size ); + DC_FlushRange(pTempBuf, file_size); + if (!read_is_ok) + { + kamiFontPrintfConsoleEx(1, "Fail FS_ReadFile!\n"); + FS_CloseFile(&file); + OS_Free(pTempBuf); + return FALSE; + } + + // t@CN[Y + FS_CloseFile(&file); + + // ݑOCRCvZ + crc_w1 = SVC_GetCRC16( 0xffff, pTempBuf, sizeof(NORHeaderDS) ); + crc_w2 = SVC_GetCRC16( 0xffff, pTempBuf+512, file_size-512 ); + + // ܂NORHeaderDS̈ށi40byte?j + if (kamiNvramWrite(0, (void*)pTempBuf, sizeof(NORHeaderDS)) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramWrite()\n"); + result = FALSE; + } + + // CRCvẐŔÔ߂ɃNAĂ烊[h + MI_CpuFill8( pTempBuf, 0xee, sizeof(NORHeaderDS) ); + DC_FlushRange(pTempBuf, sizeof(NORHeaderDS)); + + // CRC`FbN̂Nvram烊[h + if (kamiNvramRead(0, pTempBuf, sizeof(NORHeaderDS) ) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramRead()!\n"); + } + + // ǂݍ݂ARM7ڃɏo + DC_InvalidateRange(pTempBuf, sizeof(NORHeaderDS)); + // ݌CRCvZ + crc_r1 = SVC_GetCRC16( 0xffff, pTempBuf, sizeof(NORHeaderDS) ); + + // NVRAM擪CRCr + if ( crc_w1 != crc_r1 ) + { + OS_Free(pTempBuf); + kamiFontPrintfConsoleEx(1, "Fail! CRC check %x!=%x\n", crc_w1, crc_r1); + return FALSE; + } + + // nandfirm NtO𗧂Ă + if (kamiNvramWrite(NAND_BOOT_FLAG_ADDRESS, &sNandBootFlag, 1) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramWrite()\n"); + result = FALSE; + } + + kamiFontPrintfConsoleEx(0, "NAND Firm Import Start!\n"); + + // NAND + write_size = file_size/NAND_BLOCK_BYTE + (file_size % NAND_BLOCK_BYTE != 0); + kamiNandWrite( NAND_FIRM_START_OFFSET/NAND_BLOCK_BYTE, pTempBuf+NAND_FIRM_START_OFFSET, write_size ); // ubNPʁAoCgPʁAubNP + + kamiFontPrintfConsoleEx(0, "Start CRC check\n"); + kamiFontLoadScreenData(); + + // CRCvẐŔÔ߂ɃNAĂ烊[h + MI_CpuClear8( pTempBuf, file_size ); + DC_FlushRange(pTempBuf, file_size); + + // CRC`FbN̂Nand烊[h + if (kamiNandRead(0, pTempBuf, file_size/512 ) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "kamiNandRead ... %s!\n", "ERROR"); + } + DC_FlushRange(pTempBuf, file_size); + + // ݌CRCvZ + crc_r2 = SVC_GetCRC16( 0xffff, pTempBuf+512, file_size-512 ); + + // NANDɂ‚ĂCRC`FbN + if (crc_w2 == crc_r2) + { + kamiFontPrintfConsoleEx(0, "Success! CRC check %x==%x\n", crc_w2, crc_r2); + } + else + { + result = FALSE; + kamiFontPrintfConsoleEx(1, "Fail! CRC check %x!=%x\n", crc_w2, crc_r2); + } + + // + OS_Free(pTempBuf); + + return result; +} + + + diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_norfirm.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_norfirm.c new file mode 100644 index 00000000..70b5e2eb --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_norfirm.c @@ -0,0 +1,423 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_norfirm.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include "kami_font.h" +#include "kami_pxi.h" +#include "process_topmenu.h" +#include "process_import.h" +#include "process_norfirm.h" +#include "cursor.h" +#include "keypad.h" + +#include "TWLHWInfo_api.h" + +#include +#include +#include <../build/libraries/spi/ARM9/include/spi.h> + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define DOT_OF_MENU_SPACE 8 +#define CHAR_OF_MENU_SPACE 1 + +#define CURSOR_ORIGIN_X 32 +#define CURSOR_ORIGIN_Y 40 + +#define FILE_NUM_MAX 16 + +#define ROUND_UP(value, alignment) \ + (((u32)(value) + (alignment-1)) & ~(alignment-1)) + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static s32 sMenuSelectNo; +static char sFilePath[FILE_NUM_MAX][FS_ENTRY_LONGNAME_MAX]; +static u8 sFileNum; + +/*---------------------------------------------------------------------------* + ֐錾 + *---------------------------------------------------------------------------*/ + +static void MakeFullPathForSD(char* file_name, char* full_path); +static BOOL WriteNorfirm(char* file_name); + +/*---------------------------------------------------------------------------* + vZX֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: Import vZXO + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* NorfirmProcess0(void) +{ + FSFile dir; + int i; + + // SNA + kamiFontClear(); + + // o[W\ + kamiFontPrintf(2, 1, FONT_COLOR_BLACK, "Import Norfirm from SD"); + kamiFontPrintf(0, 2, FONT_COLOR_BLACK, "--------------------------------"); + + // zNA + MI_CpuClear8( sFilePath, sizeof(sFilePath) ); + + // t@C + sFileNum = 0; + + // wiSNA + for (i=0;i<24;i++) + { + kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS ); + } + + // wi㕔 + kamiFontFillChar( 0, BG_COLOR_VIOLET, BG_COLOR_VIOLET ); + kamiFontFillChar( 1, BG_COLOR_VIOLET, BG_COLOR_VIOLET ); + kamiFontFillChar( 2, BG_COLOR_VIOLET, BG_COLOR_TRANS ); + + // SDJ[h̃[gfBNg + if ( !FS_OpenDirectory(&dir, "sdmc:/", FS_FILEMODE_R | FS_FILEMODE_W) ) + { + OS_Printf("Error FS_OpenDirectory(sdmc:/)\n"); + kamiFontPrintf(3, 13, FONT_COLOR_BLACK, "Error FS_OpenDirectory(sdmc:/)"); + } + else + { + FSDirectoryEntryInfo info[1]; + OS_Printf("[%s]:\n", "sdmc:/"); + + kamiFontPrintfConsole(0, "------ nor file list -----\n"); + + // .nor Tăt@CۑĂ + while (FS_ReadDirectory(&dir, info)) + { + OS_Printf(" %s", info->longname); + if ((info->attributes & (FS_ATTRIBUTE_DOS_DIRECTORY | FS_ATTRIBUTE_IS_DIRECTORY)) != 0) + { + OS_Printf("/\n"); + } + else + { + char* pExtension; + OS_Printf(" (%d BYTEs)\n", info->filesize); + + // gq̃`FbN + pExtension = STD_SearchCharReverse( info->longname, '.'); + if (pExtension) + { + if (!STD_CompareString( pExtension, ".nor") || !STD_CompareString( pExtension, ".NOR")) + { + STD_CopyString( sFilePath[sFileNum], info->longname ); + kamiFontPrintfConsole(0, "%d:%s\n", sFileNum, info->longname); + + // ő16‚ŏI + if (++sFileNum >= FILE_NUM_MAX) + { + break; + } + } + } + } + } + (void)FS_CloseDirectory(&dir); + + kamiFontPrintfConsole(0, "--------------------------\n"); + } + + // j[ꗗ + kamiFontPrintf((s16)3, (s16)4, FONT_COLOR_BLACK, "+--------------------+----+"); + kamiFontPrintf((s16)3, (s16)(5+sFileNum+1), FONT_COLOR_BLACK, "+--------------------+----+"); + + // tad t@CXg\ + for (i=0;i sFileNum) sMenuSelectNo = 0; + } + + // J[\zu + SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNo * DOT_OF_MENU_SPACE)); + + // + if (kamiPadIsTrigger(PAD_BUTTON_A)) + { + return NorfirmProcess2; + } + // gbvj[֖߂ + else if (kamiPadIsTrigger(PAD_BUTTON_B)) + { + return TopmenuProcess0; + } + + return NorfirmProcess1; +} + +/*---------------------------------------------------------------------------* + Name: vZX2 + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* NorfirmProcess2(void) +{ + BOOL ret; + + if (STD_GetStringLength(sFilePath[sMenuSelectNo])) + { + ret = WriteNorfirm(sFilePath[sMenuSelectNo]); + } + else + { + // ^[ + return TopmenuProcess0; + } + + // ̌ʂ\ + if ( ret == TRUE ) + { + kamiFontPrintf((s16)26, (s16)(5+sMenuSelectNo*CHAR_OF_MENU_SPACE), FONT_COLOR_GREEN, "OK"); + } + else + { + kamiFontPrintf((s16)26, (s16)(5+sMenuSelectNo*CHAR_OF_MENU_SPACE), FONT_COLOR_RED, "NG"); + } + + return NorfirmProcess1; +} + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: MakeFullPathForSD + + Description: + + Arguments: no + + Returns: None. + *---------------------------------------------------------------------------*/ +static void MakeFullPathForSD(char* file_name, char* full_path) +{ + // tpX쐬 + STD_CopyString( full_path, "sdmc:/" ); + STD_ConcatenateString( full_path, file_name ); +} + +/*---------------------------------------------------------------------------* + Name: MakeFullPathForSD + + Description: + + Arguments: no + + Returns: None. + *---------------------------------------------------------------------------*/ +#define NVRAM_PAGE_SIZE 256 + +static BOOL WriteNorfirm(char* file_name) +{ + FSFile file; + char full_path[FS_ENTRY_LONGNAME_MAX+6]; + BOOL open_is_ok; + BOOL read_is_ok; + u8* pTempBuf; + u32 file_size; + u32 alloc_size; + BOOL result = TRUE; + int nor_addr; + u16 crc_w1, crc_w2; + u16 crc_r1, crc_r2; + + // .nor̃tpX쐬 + MakeFullPathForSD(file_name, full_path); + + // .nort@CI[v + FS_InitFile(&file); + open_is_ok = FS_OpenFile(&file, full_path); + OS_Printf("FS_OpenFile(\"%s\") ... %s!\n", full_path, open_is_ok ? "OK" : "ERROR"); + + // TCY`FbN + file_size = FS_GetFileLength(&file) ; + if (file_size > 256*1024) + { + kamiFontPrintfConsoleEx(1, "too big file size!\n"); + FS_CloseFile(&file); + return FALSE; + } + + // obt@m + alloc_size = ROUND_UP(file_size, 32) ; + pTempBuf = OS_Alloc( alloc_size ); + if (pTempBuf == NULL) + { + kamiFontPrintfConsoleEx(1, "Fail Alloc()\n"); + FS_CloseFile(&file); + return FALSE; + } + + // .nort@C[h + read_is_ok = FS_ReadFile( &file, pTempBuf, (s32)file_size ); + DC_FlushRange(pTempBuf, file_size); + if (!read_is_ok) + { + kamiFontPrintfConsoleEx(1, "FS_ReadFile(\"%s\") ... ERROR!\n", full_path); + FS_CloseFile(&file); + OS_Free(pTempBuf); + return FALSE; + } + + // t@CN[Y + FS_CloseFile(&file); + + // ݑOCRCvZ + crc_w1 = SVC_GetCRC16( 0xffff, pTempBuf, sizeof(NORHeaderDS) ); + crc_w2 = SVC_GetCRC16( 0xffff, pTempBuf+512, file_size-512 ); + + // ܂NORHeaderDS̈ށi40byte?j + if (kamiNvramWrite(0, (void*)pTempBuf, sizeof(NORHeaderDS)) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail SPI_NvramPageWrite()\n"); + result = FALSE; + } + + // CRC`FbN̂Nvram烊[h + if (kamiNvramRead(0, pTempBuf, sizeof(NORHeaderDS) ) == KAMI_RESULT_SEND_ERROR) + { + OS_Printf("kamiNvramRead ... ERROR!\n"); + } + + // ǂݍ݂ARM7ڃɏo + DC_InvalidateRange(pTempBuf, sizeof(NORHeaderDS)); + // ݌CRCvZ + crc_r1 = SVC_GetCRC16( 0xffff, pTempBuf, sizeof(NORHeaderDS) ); + + // NVRAMOCRC`FbN + if ( crc_w1 != crc_r1 ) + { + OS_Free(pTempBuf); + kamiFontPrintfConsoleEx(1, "Fail! CRC check %x!=%x\n", crc_w1, crc_r1); + return FALSE; + } + + nor_addr = offsetof(NORHeader, l); // 512byte + + // i[^[ + ProgressInit(); + kamiFontPrintfConsole(0, "NOR Firm Import Start!\n"); + + while ( nor_addr < file_size) + { + // + if (kamiNvramWrite((u32)nor_addr, (void*)(pTempBuf + nor_addr), NVRAM_PAGE_SIZE) == KAMI_RESULT_SEND_ERROR) + { + OS_TPrintf("======= Fail SPI_NvramPageWrite() ======== \n"); + result = FALSE; + break; + } + nor_addr += NVRAM_PAGE_SIZE; + + // i[^[\ + ProgressDraw((f32)nor_addr/file_size); + } + + kamiFontPrintfConsoleEx(0, "Start CRC check\n"); + kamiFontLoadScreenData(); + + // CRC`FbN̂Nvram烊[h + if (kamiNvramRead(0, pTempBuf, file_size ) == KAMI_RESULT_SEND_ERROR) + { + OS_Printf("kamiNvramRead ... ERROR!\n"); + } + + // ǂݍ݂ARM7ڃɏo + DC_InvalidateRange(pTempBuf, file_size); + + // ݌CRCvZ + crc_r2 = SVC_GetCRC16( 0xffff, pTempBuf+512, file_size-512 ); + + // CRCr + if (crc_w2 != crc_r2) + { + result = FALSE; + kamiFontPrintfConsoleEx(1, "Fail! CRC check %x!=%x\n", crc_w2, crc_r2); + } + + // + OS_Free(pTempBuf); + + return result; +} + + + diff --git a/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_topmenu.c b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_topmenu.c new file mode 100644 index 00000000..6172b2c6 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/ARM9.TWL/src/process_topmenu.c @@ -0,0 +1,217 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: process_topmenu.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +#include +#include "kami_font.h" +#include "process_topmenu.h" +#include "process_format.h" +#include "process_hw_info.h" +#include "process_import.h" +#include "process_eticket.h" +#include "process_nandfirm.h" +#include "process_norfirm.h" +#include "process_auto.h" +#include "cursor.h" +#include "keypad.h" + +/*---------------------------------------------------------------------------* + ^` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ + +#define NUM_OF_MENU_SELECT 6 +#define DOT_OF_MENU_SPACE 16 +#define CURSOR_ORIGIN_X 32 +#define CURSOR_ORIGIN_Y 56 + +/*---------------------------------------------------------------------------* + ϐ` + *---------------------------------------------------------------------------*/ + +static s8 sMenuSelectNo; + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + vZX֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: Top Menu vZXO + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* TopmenuProcess0(void) +{ + int i; + + // SNA + kamiFontClear(); + + // o[W\ + kamiFontPrintf(4, 2, 0, "Nand Initializer ver 0.1"); + + // j[ꗗ + kamiFontPrintf(3, 7, FONT_COLOR_BLACK, " FORMAT NAND "); + kamiFontPrintf(3, 9, FONT_COLOR_BLACK, " WRITE HARDWARE INFO "); + kamiFontPrintf(3, 11, FONT_COLOR_BLACK, " WRITE ETICKET SIGN "); + kamiFontPrintf(3, 13, FONT_COLOR_BLACK, " INPORT TAD FROM SD "); + kamiFontPrintf(3, 15, FONT_COLOR_BLACK, " INPORT NANDFIRM FROM SD"); + kamiFontPrintf(3, 17, FONT_COLOR_BLACK, " INPORT NORFIRM FROM SD"); + + // wiSNA + for (i=0;i<24;i++) + { + kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS ); + } + + // wiݒ + kamiFontFillChar( 6, BG_COLOR_TRANS, BG_COLOR_BLUE ); + kamiFontFillChar( 7, BG_COLOR_BLUE, BG_COLOR_BLUE ); + kamiFontFillChar( 8, BG_COLOR_BLUE, BG_COLOR_TRANS ); + + kamiFontFillChar( 8, BG_COLOR_NONE, BG_COLOR_PURPLE ); + kamiFontFillChar( 9, BG_COLOR_PURPLE, BG_COLOR_PURPLE ); + kamiFontFillChar(10, BG_COLOR_PURPLE, BG_COLOR_TRANS ); + + kamiFontFillChar(10, BG_COLOR_NONE, BG_COLOR_GRAY ); + kamiFontFillChar(11, BG_COLOR_GRAY, BG_COLOR_GRAY ); + kamiFontFillChar(12, BG_COLOR_GRAY, BG_COLOR_TRANS ); + + kamiFontFillChar(12, BG_COLOR_NONE, BG_COLOR_PINK ); + kamiFontFillChar(13, BG_COLOR_PINK, BG_COLOR_PINK ); + kamiFontFillChar(14, BG_COLOR_PINK, BG_COLOR_TRANS ); + + kamiFontFillChar(14, BG_COLOR_NONE, BG_COLOR_GREEN ); + kamiFontFillChar(15, BG_COLOR_GREEN, BG_COLOR_GREEN ); + kamiFontFillChar(16, BG_COLOR_GREEN, BG_COLOR_TRANS ); + + kamiFontFillChar(16, BG_COLOR_NONE, BG_COLOR_VIOLET ); + kamiFontFillChar(17, BG_COLOR_VIOLET, BG_COLOR_VIOLET ); + kamiFontFillChar(18, BG_COLOR_VIOLET, BG_COLOR_TRANS ); + + // J[\zu + SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNo * DOT_OF_MENU_SPACE)); + + return TopmenuProcess1; +} + +/*---------------------------------------------------------------------------* + Name: Top Menu vZXP + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* TopmenuProcess1(void) +{ + // Ij[̕ύX + if ( kamiPadIsRepeatTrigger(PAD_KEY_UP) ) + { + if (--sMenuSelectNo < 0) sMenuSelectNo = NUM_OF_MENU_SELECT -1; + } + else if ( kamiPadIsRepeatTrigger(PAD_KEY_DOWN) ) + { + if (++sMenuSelectNo >= NUM_OF_MENU_SELECT) sMenuSelectNo = 0; + } + + // J[\zu + SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNo * DOT_OF_MENU_SPACE)); + + // + if (kamiPadIsTrigger(PAD_BUTTON_A)) + { + return TopmenuProcess2; + } + + // L&RŃI[gsI + if (kamiPadIsPress(PAD_BUTTON_L) && kamiPadIsPress(PAD_BUTTON_R)) + { + return AutoProcess0; + } + + return TopmenuProcess1; +} + +/*---------------------------------------------------------------------------* + Name: Top Menu vZXQ + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* TopmenuProcess2(void) +{ + switch ( sMenuSelectNo ) + { + case 0: + return FormatProcess0; + case 1: + return HWInfoProcess0; + break; + case 2: + return eTicketProcess0; + break; + case 3: + return ImportProcess0; + break; + case 4: + return NandfirmProcess0; + break; + case 5: + return NorfirmProcess0; + break; + } + + return TopmenuProcess1; +} + +/*---------------------------------------------------------------------------* + Name: Top Menu vZXR + + Description: + + Arguments: None. + + Returns: next sequence + *---------------------------------------------------------------------------*/ + +void* TopmenuProcess3(void) +{ + return TopmenuProcess3; +} + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + diff --git a/build/systemMenu_RED/NandInitializer/Makefile b/build/systemMenu_RED/NandInitializer/Makefile new file mode 100644 index 00000000..4f43d5e7 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/Makefile @@ -0,0 +1,34 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - tests - camera +# 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-30#$ +# $Rev: 1951 $ +# $Author: yutaka $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + banner \ + ARM7.TWL \ + ARM9.TWL \ + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/NandInitializer/banner/Makefile b/build/systemMenu_RED/NandInitializer/banner/Makefile new file mode 100644 index 00000000..27b48038 --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/banner/Makefile @@ -0,0 +1,49 @@ +#! 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:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/systemMenu_RED/NandInitializer/banner/banner_v3.bsf b/build/systemMenu_RED/NandInitializer/banner/banner_v3.bsf new file mode 100644 index 00000000..a86a720b Binary files /dev/null and b/build/systemMenu_RED/NandInitializer/banner/banner_v3.bsf differ diff --git a/build/systemMenu_RED/NandInitializer/banner/icon/gameIcon.bmp b/build/systemMenu_RED/NandInitializer/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..5fe5ee2c Binary files /dev/null and b/build/systemMenu_RED/NandInitializer/banner/icon/gameIcon.bmp differ diff --git a/build/systemMenu_RED/NandInitializer/common/include/fifo.h b/build/systemMenu_RED/NandInitializer/common/include/fifo.h new file mode 100644 index 00000000..a3acad5c --- /dev/null +++ b/build/systemMenu_RED/NandInitializer/common/include/fifo.h @@ -0,0 +1,82 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - camera-test - include + File: fifo.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-11-29#$ + $Rev: 2734 $ + $Author: yutaka $ + *---------------------------------------------------------------------------*/ +#ifndef TWL_KAMI_TEST_FIFO_H_ +#define TWL_KAMI_TEST_FIFO_H_ + +#include + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ +#define PXI_FIFO_TAG_KAMITEST PXI_FIFO_TAG_USER_1 + +#define KAMI_PXI_CONTINUOUS_PACKET_MAX 10 +#define KAMITEST_PXI_DATA_SIZE_MAX ((KAMI_PXI_CONTINUOUS_PACKET_MAX-1)*3+1) // őf[^ + +#define KAMITEST_PXI_START_BIT 0x02000000 // 擪pPbgӖ +#define KAMITEST_PXI_RESULT_BIT 0x00008000 // PXỈ + +#define KAMITEST_PXI_COMMAND_SHIFT 8 // R}hi[̈ʒu +#define KAMITEST_PXI_COMMAND_MASK 0x00007f00 // R}hi[̃}XN +#define KAMITEST_PXI_DATA_NUMS_MASK 0x00ff0000 // f[^̈ +#define KAMITEST_PXI_DATA_NUMS_SHIFT 16 // f[^ʒu +#define KAMITEST_PXI_1ST_DATA_MASK 0x000000ff // 擪pPbg̃f[^̈ +#define KAMITEST_PXI_1ST_DATA_SHIFT 0 // 擪pPbg̃f[^ʒu + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +typedef enum KAMIPxiResult +{ + KAMI_PXI_RESULT_SUCCESS = 0, // (void/void*^) // ꍇɂ㑱pPbg + KAMI_PXI_RESULT_SUCCESS_TRUE = 0, // (BOOL^) + KAMI_PXI_RESULT_SUCCESS_FALSE, // (BOOL^) + KAMI_PXI_RESULT_INVALID_COMMAND, // sPXIR}h + KAMI_PXI_RESULT_INVALID_PARAMETER, // sȃp[^ + KAMI_PXI_RESULT_ILLEGAL_STATUS, // KAMȈԂɂ菈ss + KAMI_PXI_RESULT_BUSY, // ̃NGXgs + KAMI_PXI_RESULT_FATAL_ERROR, // ̑炩̌ŏɎs + KAMI_PXI_RESULT_MAX +} +KAMIPxiResult; + +typedef enum KamiCommand +{ + CODEC_READ_REGISTER, + CODEC_WRITE_REGISTER, + GPIO333_WRITE, + EXE_FORMAT, + KAMI_NAND_IO, + KAMI_NVRAM_IO +} +KamiCommand; + +/*===========================================================================*/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* TWL_KAMI_TEST_FIFO_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_RED/NandInitializer/data/cert.sys b/build/systemMenu_RED/NandInitializer/data/cert.sys new file mode 100644 index 00000000..9368fbbc Binary files /dev/null and b/build/systemMenu_RED/NandInitializer/data/cert.sys differ diff --git a/build/systemMenu_RED/PictoChat/ARM9/Makefile b/build/systemMenu_RED/PictoChat/ARM9/Makefile new file mode 100644 index 00000000..d1972761 --- /dev/null +++ b/build/systemMenu_RED/PictoChat/ARM9/Makefile @@ -0,0 +1,60 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +TITLEID_LO = PCHT +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +TARGET_BIN = main.srl + +ROM_SPEC = main.rsf + +MISC_DIR = ../../misc + +SRCS = main.c PictoChat.c \ + $(MISC_DIR)/src/misc.c $(MISC_DIR)/src/cmn.c + +LINCLUDES = $(MISC_DIR)/include + +MAKEROM_FLAGS += -DTITLEID_LO='$(TITLEID_LO)' +MAKETAD_FLAGS += -s + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/PictoChat/ARM9/main.rsf b/build/systemMenu_RED/PictoChat/ARM9/main.rsf new file mode 100644 index 00000000..659fd928 --- /dev/null +++ b/build/systemMenu_RED/PictoChat/ARM9/main.rsf @@ -0,0 +1,179 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType System + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + SaveBannerFile FALSE +} + + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot ../../data + Root /data + File NTR_IPL_font_m.NFTR +} diff --git a/build/systemMenu_RED/PictoChat/ARM9/src/PictoChat.c b/build/systemMenu_RED/PictoChat/ARM9/src/PictoChat.c new file mode 100644 index 00000000..e2c466e1 --- /dev/null +++ b/build/systemMenu_RED/PictoChat/ARM9/src/PictoChat.c @@ -0,0 +1,83 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: DS_Chat.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "misc.h" +#include "PictoChat.h" + +// define data------------------------------------------ +#define RETURN_BUTTON_TOP_X 2 +#define RETURN_BUTTON_TOP_Y 21 +#define RETURN_BUTTON_BOTTOM_X ( RETURN_BUTTON_TOP_X + 8 ) +#define RETURN_BUTTON_BOTTOM_Y ( RETURN_BUTTON_TOP_Y + 2 ) + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- + +// global variable ------------------------------------- +RTCDrawProperty g_rtcDraw = { + TRUE, RTC_DATE_TOP_X, RTC_DATE_TOP_Y, RTC_TIME_TOP_X, RTC_TIME_TOP_Y +}; + +// static variable ------------------------------------- + +// const data ----------------------------------------- + +//====================================================== +// sNg`bg +//====================================================== + +// sNg`bg̏ +void PictoChatInit( void ) +{ + GX_DispOff(); + GXS_DispOff(); + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_WHITE ); + + PutStringUTF16( 1 * 8, 0 * 8, TXT_COLOR_BLUE, (const u16 *)L"PictoChat"); + PutStringUTF16( 4 * 8, 8 * 8, TXT_COLOR_BLACK, (const u16 *)L"Under Construction..."); + GetAndDrawRTCData( &g_rtcDraw, TRUE ); + + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); + GX_DispOn(); + GXS_DispOn(); +} + + +// sNg`bg̃C[v +void PictoChatMain(void) +{ + BOOL tp_cancel = FALSE; + + ReadTP(); // ^b`pl͂̎擾 + + // [RETURN]{^`FbN + if(tpd.disp.touch) { + tp_cancel = WithinRangeTP( RETURN_BUTTON_TOP_X * 8, RETURN_BUTTON_TOP_Y * 8 - 4, + RETURN_BUTTON_BOTTOM_X * 8, RETURN_BUTTON_BOTTOM_Y * 8 - 4, &tpd.disp ); + } + + if( ( pad.trg & PAD_BUTTON_B ) || tp_cancel ) { +// SYSM_RebootLauncher(); + } + + GetAndDrawRTCData( &g_rtcDraw, FALSE ); +} + + diff --git a/build/systemMenu_RED/PictoChat/ARM9/src/PictoChat.h b/build/systemMenu_RED/PictoChat/ARM9/src/PictoChat.h new file mode 100644 index 00000000..eaea9196 --- /dev/null +++ b/build/systemMenu_RED/PictoChat/ARM9/src/PictoChat.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: DS_Chat.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 __DS_CHAT_H__ +#define __DS_CHAT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +// define data---------------------------------------------------------- + +void PictoChatInit( void ); +void PictoChatMain( void ); + +#ifdef __cplusplus +} +#endif + +#endif // __DS_CHAT_H__ diff --git a/build/systemMenu_RED/PictoChat/ARM9/src/main.c b/build/systemMenu_RED/PictoChat/ARM9/src/main.c new file mode 100644 index 00000000..837e94d0 --- /dev/null +++ b/build/systemMenu_RED/PictoChat/ARM9/src/main.c @@ -0,0 +1,86 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" +#include "PictoChat.h" + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +static void INTR_VBlank( void ); + +// global variable------------------------------------------------------------- + +// static variable------------------------------------------------------------- + +// const data------------------------------------------------------------------ + + +// ============================================================================ +// function's description +// ============================================================================ +void TwlMain(void) +{ + + // ---------------------------------- + OS_Init(); + + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + GX_Init(); + GX_SetPower(GX_POWER_ALL); // eWbN p[ON + + // 荞݋---------------------------- + (void)OS_SetIrqFunction(OS_IE_V_BLANK, INTR_VBlank); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + + // foCX------------------------------- + TP_Init(); + (void)RTC_Init(); + + // VXȅ------------------ + InitAllocator(); + + InitBG(); + PictoChatInit(); + // C[v---------------------------- + while(1){ + OS_WaitIrq(1, OS_IE_V_BLANK); // VuN荞ݑ҂ + + ReadKeyPad(); // L[͂̎擾 + ReadTP(); // TP͂̎擾 + + PictoChatMain(); + } +} + + +// ============================================================================ +// 荞ݏ +// ============================================================================ + +// VuN荞 +static void INTR_VBlank(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // VuN`FbÑZbg +} + diff --git a/build/systemMenu_RED/PictoChat/Makefile b/build/systemMenu_RED/PictoChat/Makefile new file mode 100644 index 00000000..9cf34e12 --- /dev/null +++ b/build/systemMenu_RED/PictoChat/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/systemMenu_RED/PictoChat/banner/Makefile b/build/systemMenu_RED/PictoChat/banner/Makefile new file mode 100644 index 00000000..f3e3ea7e --- /dev/null +++ b/build/systemMenu_RED/PictoChat/banner/Makefile @@ -0,0 +1,46 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +ICON_DIR = ./icon + +BANNER_SPEC = test-utf16_v3.TWL.bsf + +MAKEBANNER = $(TWL_TOOLSDIR)/bin/makebanner.TWL.exe + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(TARGETS:.bnr=.srl) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) + $(MAKEBANNER) -d -p TWL $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/systemMenu_RED/PictoChat/banner/banner_v3.bsf b/build/systemMenu_RED/PictoChat/banner/banner_v3.bsf new file mode 100644 index 00000000..d595b6d3 Binary files /dev/null and b/build/systemMenu_RED/PictoChat/banner/banner_v3.bsf differ diff --git a/build/systemMenu_RED/PictoChat/banner/icon/gameIcon.bmp b/build/systemMenu_RED/PictoChat/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..5fe5ee2c Binary files /dev/null and b/build/systemMenu_RED/PictoChat/banner/icon/gameIcon.bmp differ diff --git a/build/systemMenu_RED/PictoChat/banner/icon/msk_pictchat_icon.bin b/build/systemMenu_RED/PictoChat/banner/icon/msk_pictchat_icon.bin new file mode 100644 index 00000000..5b2734aa Binary files /dev/null and b/build/systemMenu_RED/PictoChat/banner/icon/msk_pictchat_icon.bin differ diff --git a/build/systemMenu_RED/PictoChat/banner/test-utf16_v3.TWL.bsf b/build/systemMenu_RED/PictoChat/banner/test-utf16_v3.TWL.bsf new file mode 100644 index 00000000..1049cbbd Binary files /dev/null and b/build/systemMenu_RED/PictoChat/banner/test-utf16_v3.TWL.bsf differ diff --git a/build/systemMenu_RED/data/BGData_Launcher.c b/build/systemMenu_RED/data/BGData_Launcher.c new file mode 100644 index 00000000..459ede70 --- /dev/null +++ b/build/systemMenu_RED/data/BGData_Launcher.c @@ -0,0 +1,71 @@ +// BGLN^ +u32 bg_char_data[8 * 6] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000,// 0000h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x11111111, 0x44444444, 0x77777777, 0x99999999,// 0001h + 0xaaaaaaaa, 0xbbbbbbbb, 0xcccccccc, 0xcccccccc, + 0xdddddddd, 0xdddddddd, 0xdddddddd, 0xeeeeeeee,// 0002h + 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee, + 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee,// 0003h + 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee, + 0x11111111, 0x11111111, 0x11111111, 0x11111111,// 0004h + 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0xeeeeeeee, 0xeeeeee11, 0xeeeeee11, 0xeeee11ee,// 0005h(_) + 0xeeee11ee, 0xee11eeee, 0xee11eeee, 0x11eeeeee, +}; + + +// BGXN[f[^1 +u16 bg_scr_data[32 * 32]= +{ + 0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,//0 + 0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001, + 0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,//1 + 0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//2 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,//3 + 0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001, + 0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,//4 + 0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002, + 0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,//5 + 0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802, + 0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,//6 + 0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//7 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//8 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//9 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//10 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//11 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//12 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//13 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//14 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//15 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//16 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1405,0x1405,0x1405,0x1405,0x1003,//17 + 0x1003,0x1005,0x1005,0x1005,0x1005,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1c05,0x1c05,0x1c05,0x1c05,0x1003,//18 + 0x1003,0x1805,0x1805,0x1805,0x1805,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//19 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//20 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//21 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,//22 + 0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802, + 0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,//23 + 0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801, +};// Bueeer eor screen data(wi̘g) + +u16 bg_scr_data2[32 * 32];//XN[f[^2 \ No newline at end of file diff --git a/build/systemMenu_RED/data/BGData_MachineSettings.c b/build/systemMenu_RED/data/BGData_MachineSettings.c new file mode 100644 index 00000000..529bf33c --- /dev/null +++ b/build/systemMenu_RED/data/BGData_MachineSettings.c @@ -0,0 +1,122 @@ +// BGLN^ +u32 bg_char_data[8 * 6] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000,// 0000h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x11111111, 0x44444444, 0x77777777, 0x99999999,// 0001h + 0xaaaaaaaa, 0xbbbbbbbb, 0xcccccccc, 0xcccccccc, + 0xdddddddd, 0xdddddddd, 0xdddddddd, 0xeeeeeeee,// 0002h + 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee, 0xeeeeeeee, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,// 0003h + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,// 0004hiEOj + 0xfffffff1, 0xfffffff1, 0xfffff11f, 0xfffff11f, + 0xfff11fff, 0xfff11fff, 0xf11fffff, 0xf11fffff,// 0005hiEOj + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +}; + + +// BGXN[f[^1 +u16 bg_birth_scr_data[32 * 32]= +{ + 0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,//0 + 0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001, + 0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,//1 + 0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//2 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//3 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//4 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//5 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//6 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//7 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1404,0x1004,0x1003,0x1003,//8 + 0x1003,0x1003,0x1404,0x1004,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1405,0x1005,0x1003,0x1003,//9 + 0x1003,0x1003,0x1405,0x1005,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//10 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//11 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//12 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//13 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1c05,0x1805,0x1003,0x1003,//14 + 0x1003,0x1003,0x1c05,0x1805,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1c04,0x1804,0x1003,0x1003,//15 + 0x1003,0x1003,0x1c04,0x1804,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//16 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//17 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//18 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//19 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//20 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//21 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,//22 + 0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802, + 0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,//23 + 0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801, +};// Buffer for screen data(wi̘g) + +// BGXN[f[^1 +u16 bg_scr_data[32 * 32]= +{ + 0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,//0 + 0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001,0x1001, + 0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,//1 + 0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002,0x1002, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//2 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//3 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//4 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//5 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//6 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//7 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//8 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//9 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//10 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//11 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//12 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//13 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//14 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//15 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//16 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//17 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//18 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//19 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//20 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,//21 + 0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003,0x1003, + 0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,//22 + 0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802,0x1802, + 0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,//23 + 0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801,0x1801, +};// Buffer for screen data(aݒBG) \ No newline at end of file diff --git a/build/systemMenu_RED/data/EmptyBanner.bnr b/build/systemMenu_RED/data/EmptyBanner.bnr new file mode 100644 index 00000000..9a4757f3 Binary files /dev/null and b/build/systemMenu_RED/data/EmptyBanner.bnr differ diff --git a/build/systemMenu_RED/data/NTR_IPL_font_l.NFTR b/build/systemMenu_RED/data/NTR_IPL_font_l.NFTR new file mode 100644 index 00000000..b6fe11e0 Binary files /dev/null and b/build/systemMenu_RED/data/NTR_IPL_font_l.NFTR differ diff --git a/build/systemMenu_RED/data/NTR_IPL_font_m.NFTR b/build/systemMenu_RED/data/NTR_IPL_font_m.NFTR new file mode 100644 index 00000000..03ba3a48 Binary files /dev/null and b/build/systemMenu_RED/data/NTR_IPL_font_m.NFTR differ diff --git a/build/systemMenu_RED/data/NTR_IPL_font_s.NFTR b/build/systemMenu_RED/data/NTR_IPL_font_s.NFTR new file mode 100644 index 00000000..59591f8b Binary files /dev/null and b/build/systemMenu_RED/data/NTR_IPL_font_s.NFTR differ diff --git a/build/systemMenu_RED/data/NoBanner.bnr b/build/systemMenu_RED/data/NoBanner.bnr new file mode 100644 index 00000000..6d640e83 Binary files /dev/null and b/build/systemMenu_RED/data/NoBanner.bnr differ diff --git a/build/systemMenu_RED/data/NoCardBanner.bnr b/build/systemMenu_RED/data/NoCardBanner.bnr new file mode 100644 index 00000000..60afadeb Binary files /dev/null and b/build/systemMenu_RED/data/NoCardBanner.bnr differ diff --git a/build/systemMenu_RED/data/fanfare.32.wav b/build/systemMenu_RED/data/fanfare.32.wav new file mode 100644 index 00000000..eb6cc56b Binary files /dev/null and b/build/systemMenu_RED/data/fanfare.32.wav differ diff --git a/build/systemMenu_RED/misc/include/cmn.h b/build/systemMenu_RED/misc/include/cmn.h new file mode 100644 index 00000000..9640c416 --- /dev/null +++ b/build/systemMenu_RED/misc/include/cmn.h @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: mainFunc.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$ + *---------------------------------------------------------------------------*/ + +#ifndef CMN_H_ +#define CMN_H_ + + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +// define data--------------------------------------------- +#define ARY_SIZEOF(ary) ( sizeof(ary) / sizeof( (ary)[0] ) ) +#define ROUNDUP_DIV(a, b) (( (a) + ((b) - 1) ) / (b)) + + +// function------------------------------------------------ +void CMN_InitAllocator( NNSFndAllocator* pAllocator ); +void CMN_InitFileSystem( NNSFndAllocator* pAllocator ); +void CMN_ClearVram( void ); +u32 CMN_LoadFile(void** ppFile, const char* fpath, NNSFndAllocator* pAlloc); +void CMN_UnloadFile(void* pFile, NNSFndAllocator* pAlloc); +NNSFndArchive* CMN_LoadArchive(const char* name, const char* path, NNSFndAllocator* pAllocator); +void CMN_RemoveArchive(NNSFndArchive* archive, NNSFndAllocator* pAllocator); + + +#ifdef __cplusplus +}/* extern "C" */ +#endif + +#endif // CMN_H_ + diff --git a/build/systemMenu_RED/misc/include/misc.h b/build/systemMenu_RED/misc/include/misc.h new file mode 100644 index 00000000..48347ae9 --- /dev/null +++ b/build/systemMenu_RED/misc/include/misc.h @@ -0,0 +1,194 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: misc.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 __MISC_H__ +#define __MISC_H__ + +#include +#include + +#define NNS_G2D_UNICODE +#include +#include +#include +#include + +#include "cmn.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// define data---------------------------------------------------------- +#define TP_CSR_TOUCH_COUNT 2 // TPJ[\̃`^Oẑ߂̃JEgl +#define TP_CSR_DETACH_COUNT 2 // TPJ[\uIvƔ肷TPf^b`̃JEgl + +// DrawText ł̍ +#define TXT_DRAWTEXT_FLAG_DEFAULT (NNS_G2D_VERTICALORIGIN_TOP | NNS_G2D_HORIZONTALORIGIN_LEFT | NNS_G2D_HORIZONTALALIGN_LEFT) + +// TXTColorPalette ̐F 256Fpbgւ̃[hz +enum +{ + // pbg0 TXT_CPALETTE_MAIN + TXT_COLOR_NULL=0, + TXT_COLOR_WHITE, + TXT_COLOR_BLACK, + TXT_COLOR_RED, + TXT_COLOR_GREEN, + TXT_COLOR_BLUE, + TXT_COLOR_CYAN, + TXT_COLOR_MAGENTA, + TXT_COLOR_YELLOW, + + // [U[J[Of[Vpbg̈ + TXT_UCOLOR_GNULL=16, + TXT_UCOLOR_G0, + TXT_UCOLOR_G1, + TXT_UCOLOR_G2, + TXT_UCOLOR_G3, + TXT_UCOLOR_G4, + TXT_UCOLOR_G5, + TXT_UCOLOR_G6, + TXT_UCOLOR_G7, + TXT_UCOLOR_G8, + TXT_UCOLOR_G9, + TXT_UCOLOR_G10, + TXT_UCOLOR_G11, + TXT_UCOLOR_G12, + TXT_UCOLOR_G13, + TXT_UCOLOR_GWHITE, + + // [U[J[Tv̈ + TXT_UCOLOR_GRAY=32, + TXT_UCOLOR_BROWN, + TXT_UCOLOR_RED, + TXT_UCOLOR_PINK, + TXT_UCOLOR_ORANGE, + TXT_UCOLOR_YELLOW, + TXT_UCOLOR_LIMEGREEN, + TXT_UCOLOR_GREEN, + TXT_UCOLOR_DARKGREEN, + TXT_UCOLOR_SEAGREEN, + TXT_UCOLOR_TURQUOISE, + TXT_UCOLOR_BLUE, + TXT_UCOLOR_DARKBLUE, + TXT_UCOLOR_PURPLE, + TXT_UCOLOR_VIOLET, + TXT_UCOLOR_MAGENTA, + + // pbg TXT_CPALETTE_4BPP + TXT_COLOR_4BPP_NULL=48, + TXT_COLOR_4BPP_BG=49, + TXT_COLOR_4BPP_TEXT=49 +}; + +// v\ꏊ +#define RTC_DATE_TOP_X ( 9 * 8 ) +#define RTC_DATE_TOP_Y ( 10 * 8 ) +#define RTC_TIME_TOP_X ( 12 * 8 ) +#define RTC_TIME_TOP_Y ( 12 * 8 ) + + +// L[f[^[N +typedef struct { + u16 trg; // gK + u16 cont; // x^ +}KeyWork; + + +// ^b`pl[N +typedef struct { + int detached; // ̃f[^͂Ń^b`ꂽƂB + TPData disp; // ̓͒liLCDWj + TPData raw; // ̓͒liTP Wj + TPData last; // O̓͒liLCDWj +}TpWork; + + +// j[vfW +typedef struct MenuPos { + BOOL enable; + int x; + int y; +}MenuPos; + + +// j[\p[^\ +typedef struct MenuParam { + int num; + int normal_color; + int select_color; + int disable_color; + MenuPos *pos; + const u16 **str_elem; +}MenuParam; + + +// RTCf[^\ʒu[N +typedef struct RTCDrawProperty { + BOOL isTopLCD; + int date_x; + int date_y; + int time_x; + int time_y; + int vcount; + RTCDate date; + RTCTime time; + RTCDate date_old; + RTCTime time_old; +}RTCDrawProperty; + +typedef BOOL (*SelectSomethingFunc)( u16 *csr, TPData *tgt ); + +// global variables-------------------------------------------------- +extern TpWork tpd; // ^b`plf[^ +extern KeyWork pad; // L[pbh̓f[^ +extern const u8 *const g_strWeek[ 7 ]; // j +extern RTCDrawProperty g_rtcDraw; + +extern NNSFndAllocator g_allocator; // AP[^ +extern NNSG2dFont gFont; // tHg +extern NNSG2dCharCanvas gCanvas; // CharCanvas +extern NNSG2dTextCanvas gTextCanvas; // TextCanvas + +// function------------------------------------------------------------- +void InitAllocator( void ); +void *Alloc( u32 size ); +void Free( void *pBuffer ); +void InitBG( void ); +int GetPrintfWidth( const NNSG2dTextCanvas *pCanvas, const char *fmt, ... ); +void PutStringUTF16 ( int x, int y, int color, const u16 *strUTF16 ); +void PutStringUTF16Sub( int x, int y, int color, const u16 *strUTF16 ); +void PrintfSJIS ( int x, int y, int color, const char *fmt, ... ); +void PrintfSJISSub( int x, int y, int color, const char *fmt, ... ); +void ReadKeyPad( void ); +void ReadTP( void ); +void DrawMenu( u16 nowCsr, const MenuParam *pMenu ); +BOOL SelectSomethingByTP( u16 *nowCsr, SelectSomethingFunc func[], int funcnum ); +BOOL SelectMenuByTP( u16 *nowCsr, const MenuParam *pMenu ); +BOOL WithinRangeTP( int top_x, int top_y, int bottom_x, int bottom_y, TPData *tgt ); +void SetBannerIconOBJ( GXOamAttr *pDstOAM, BannerFileV1 *bannerp ); +BOOL GetRTCData( RTCDrawProperty *pRTCDraw, BOOL forceGetFlag ); +void DrawRTCData( RTCDrawProperty *pRTCDraw ); +void GetAndDrawRTCData( RTCDrawProperty *pRTCDraw, BOOL forceGetFlag ); +void ChangeUserColor( u8 col ); + +#ifdef __cplusplus +} +#endif + +#endif // __MISC_H__ diff --git a/build/systemMenu_RED/misc/src/cmn.c b/build/systemMenu_RED/misc/src/cmn.c new file mode 100644 index 00000000..333fac13 --- /dev/null +++ b/build/systemMenu_RED/misc/src/cmn.c @@ -0,0 +1,250 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: mainFunc.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include + +#include "cmn.h" + + +/*---------------------------------------------------------------------------* + Name: CMN_InitFileSystem + + Description: t@CVXeLɂ܂B + ܂At@Ce[uɓǂݍ݂܂B + + Arguments: pAllocator: LȃAP[^ւ̃|C^B + + Returns: ȂB + *---------------------------------------------------------------------------*/ +// t@CVXe +void CMN_InitFileSystem( NNSFndAllocator* pAllocator ) +{ + SDK_NULL_ASSERT( pAllocator ); + + // ARM7Ƃ̒ʐMFIFO荞݋ + (void)OS_EnableIrqMask(OS_IE_SPFIFO_RECV); + + // t@CVXe + FS_Init( FS_DMA_NOT_USE ); + + // t@Ce[uLbV + if( pAllocator != NULL ) + { + const u32 need_size = FS_GetTableSize(); + void *p_table = NNS_FndAllocFromAllocator( pAllocator, need_size ); + SDK_ASSERT(p_table != NULL); + (void)FS_LoadTable(p_table, need_size); + } +} + + + +/*---------------------------------------------------------------------------* + Name: CMN_ClearVram + + Description: VRAM NA܂B + VRAM SĖ蓖ĂłȂ΂Ȃ܂B + + Arguments: ȂB + + Returns: ȂB + *---------------------------------------------------------------------------*/ +// VRAMNA +void CMN_ClearVram( void ) +{ + //--------------------------------------------------------------------------- + // All VRAM banks to LCDC + //--------------------------------------------------------------------------- + GX_SetBankForLCDC(GX_VRAM_LCDC_ALL); + + //--------------------------------------------------------------------------- + // Clear all LCDC space + //--------------------------------------------------------------------------- + MI_CpuClearFast((void *)HW_LCDC_VRAM, HW_LCDC_VRAM_SIZE); + + //--------------------------------------------------------------------------- + // Disable the banks on LCDC + //--------------------------------------------------------------------------- + (void)GX_DisableBankForLCDC(); + + MI_CpuFillFast((void *)HW_OAM, 192, HW_OAM_SIZE); // clear OAM + MI_CpuClearFast((void *)HW_PLTT, HW_PLTT_SIZE); // clear the standard palette + + MI_CpuFillFast((void*)HW_DB_OAM, 192, HW_DB_OAM_SIZE); // clear OAM + MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE); // clear the standard palette +} + + + +/*---------------------------------------------------------------------------* + Name: CMN_LoadFile + + Description: t@CɃ[h܂B + t@Cf[^svɂȂꍇ + CMN_UnloadFile( *ppFile, pAlloc ) Ńt@Cf[^ + ܂B + + Arguments: ppFile: t@C[hAhX󂯎 + obt@ւ̃|C^B + fpath: [ht@C̃pX + pAlloc: AP[^ւ̃|C^ + + Returns: [ht@C̃t@CTCYԂ܂B + 0 ̏ꍇ̓t@C[hɎs\܂B + ̏ꍇ *ppFile ̒l͖łB + *---------------------------------------------------------------------------*/ +u32 CMN_LoadFile(void** ppFile, const char* fpath, NNSFndAllocator* pAlloc) +{ + BOOL bSuccess; + FSFile f; + u32 length; + u32 read; + + SDK_NULL_ASSERT( ppFile ); + SDK_NULL_ASSERT( fpath ); + SDK_NULL_ASSERT( pAlloc ); + + FS_InitFile(&f); + + bSuccess = FS_OpenFile(&f, fpath); + if( ! bSuccess ) + { + OS_Warning("file (%s) not found", fpath); + return 0; + } + + length = FS_GetLength(&f); + *ppFile = NNS_FndAllocFromAllocator(pAlloc, length); + if( *ppFile == NULL ) + { + OS_Warning("cant allocate memory for file: %s", fpath); + return 0; + } + + read = (u32)FS_ReadFile(&f, *ppFile, (s32)length); + if( read != length ) + { + OS_Warning("fail to load file: %s", fpath); + NNS_FndFreeToAllocator(pAlloc, *ppFile); + return 0; + } + + bSuccess = FS_CloseFile(&f); + if( ! bSuccess ) + { + OS_Warning("fail to close file: %s", fpath); + } + + return length; +} + + + +/*---------------------------------------------------------------------------* + Name: CMN_UnloadFile + + Description: t@Cf[^܂B + + Arguments: pFile: t@Cf[^ւ̃|C^ + pAlloc: t@C[hɗpAP[^ւ̃|C^ + + Returns: ȂB + *---------------------------------------------------------------------------*/ +void CMN_UnloadFile(void* pFile, NNSFndAllocator* pAlloc) +{ + NNS_FndFreeToAllocator(pAlloc, pFile); +} + + + +/*---------------------------------------------------------------------------* + Name: CMN_LoadArchive + + Description: pXŎw肳ꂽA[JCuɓǂݍ݁At@CVX + eɃ}Eg܂B + A[JCusvɂȂꍇ + CMN_RemoveArchive( Ԃl, pAllocator ) ŃA[JCu + ܂B + + Arguments: name: A[JCut@CVXeŎʂׂ̖OB + path: A[JCũpXB + pAllocator: AP[^ւ̃|C^ + + Returns: A[JCũ[hɐ΁ANNSFndArchive \̂ւ̃|C + ^Ԃ܂Bsꍇɂ́ANULLԂ܂B + *---------------------------------------------------------------------------*/ +NNSFndArchive* +CMN_LoadArchive(const char* name, const char* path, NNSFndAllocator* pAllocator) +{ + FSFile file; + NNSFndArchive* archive = NULL; + + SDK_NULL_ASSERT(name); + SDK_NULL_ASSERT(path); + SDK_NULL_ASSERT(pAllocator); + + FS_InitFile(&file); + if (FS_OpenFile(&file, path)) + { + u32 binarySize = FS_GetLength(&file); + u32 memorySize = MATH_ROUNDUP(sizeof(NNSFndArchive), 16) + MATH_ROUNDUP(binarySize, 16); + + u8* memory = (u8*)NNS_FndAllocFromAllocator(pAllocator, memorySize); + + if (memory != NULL) + { + u8* binary = memory + MATH_ROUNDUP(sizeof(NNSFndArchive), 16); + + if ((u32)FS_ReadFile(&file, binary, (s32)binarySize) == binarySize) + { + if (NNS_FndMountArchive((NNSFndArchive*)memory, name, binary)) + { + archive = (NNSFndArchive*)memory; + } + } + } + (void)FS_CloseFile(&file); + } + return archive; +} + + + +/*---------------------------------------------------------------------------* + Name: CMN_RemoveArchive + + Description: w肳ꂽA[JCu폜܂B + + w肳ꂽA[JCut@CVXeA}EgAA + [JCuǂݍ܂Ă܂B + + Arguments: archive: NNSA[JCu\̂ւ̃|C^B + pAllocator: A[JCu[hɗpAP[^ւ̃|C^B + + Returns: ȂB + *---------------------------------------------------------------------------*/ +void +CMN_RemoveArchive(NNSFndArchive* archive, NNSFndAllocator* pAllocator) +{ + SDK_NULL_ASSERT(archive); + SDK_NULL_ASSERT(pAllocator); + + (void)NNS_FndUnmountArchive(archive); + NNS_FndFreeToAllocator(pAllocator, archive); +} + diff --git a/build/systemMenu_RED/misc/src/misc.c b/build/systemMenu_RED/misc/src/misc.c new file mode 100644 index 00000000..68546b04 --- /dev/null +++ b/build/systemMenu_RED/misc/src/misc.c @@ -0,0 +1,759 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: misc.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" + +// define data----------------------------------------------------------------- +#define NTR_IPL_FONT_DATA "data/NTR_IPL_font_m.NFTR" + +#define STRING_LENGTH_MAX 256 + +#define GRAY(x) GX_RGB(x, x, x) + +enum +{ + TXT_CPALETTE_MAIN, + TXT_CPALETTE_USERCOLOR, + TXT_CPALETTE_USERCOLORSAMPLE, + TXT_CPALETTE_4BPP, + TXT_NUM_CPALEETE +}; + +// fʂ̃J[pbg +GXRgb TXTColorPalette[TXT_NUM_CPALEETE * 16] = +{ + GX_RGB(31, 31, 31), GX_RGB(31, 31, 31), GX_RGB( 0, 0, 0), GX_RGB(31, 0, 0),// {F + GX_RGB( 0, 31, 0), GX_RGB( 0, 0, 31), GX_RGB( 0, 31, 31), GX_RGB(31, 0, 31), + GX_RGB(31, 31, 0), GX_RGB( 0, 0, 0), GX_RGB( 0, 0, 0), GX_RGB( 0, 0, 0), + GX_RGB( 0, 0, 0), GX_RGB( 0, 0, 0), GX_RGB( 0, 0, 0), GX_RGB( 0, 0, 0), + + GX_RGB( 0, 0, 0), GX_RGB(12, 16, 19), GX_RGB(23, 9, 0), GX_RGB(31, 0, 3),// [U[J[̈ + GX_RGB(31, 17, 31), GX_RGB(31, 18, 0), GX_RGB(30, 28, 0), GX_RGB(21, 31, 0), + GX_RGB( 0, 20, 7), GX_RGB( 9, 27, 17), GX_RGB( 6, 23, 30), GX_RGB( 0, 11, 30), + GX_RGB( 0, 0, 18), GX_RGB(17, 0, 26), GX_RGB(26, 0, 29), GX_RGB(31, 0, 18), + + GX_RGB(12, 16, 19), GX_RGB(23, 9, 0), GX_RGB(31, 0, 3), GX_RGB(31, 17, 31),// [U[J[̃Tv̈ + GX_RGB(31, 18, 0), GX_RGB(30, 28, 0), GX_RGB(21, 31, 0), GX_RGB( 0, 31, 0), + GX_RGB( 0, 20, 7), GX_RGB( 9, 27, 17), GX_RGB( 6, 23, 30), GX_RGB( 0, 11, 30), + GX_RGB( 0, 0, 18), GX_RGB(17, 0, 26), GX_RGB(26, 0, 29), GX_RGB(31, 0, 18), + + GRAY(31), GRAY(29), GRAY(27), GRAY(25), + GRAY(23), GRAY(21), GRAY(19), GRAY(17), + GRAY(15), GRAY(14), GRAY(12), GRAY(10), + GRAY( 8), GRAY( 6), GRAY( 3), GRAY( 0), +}; + +// Ofpbg邽߂̃}N +#define MAKECOLOR(r,g,b) GX_RGB( 0, 0, 0), GX_RGB(r, g, b), MC(r,g,b,1), MC(r,g,b,2),\ + MC(r,g,b,3), MC(r,g,b,4), MC(r,g,b,5), MC(r,g,b,6),\ + MC(r,g,b,7), MC(r,g,b,8), MC(r,g,b,9), MC(r,g,b,10),\ + MC(r,g,b,11), MC(r,g,b,12), MC(r,g,b,13), GX_RGB(31, 31, 31) + +#define MC(r,g,b,i) GX_RGB(r+((31-r)*i)/14, g+((31-g)*i)/14, b+((31-b)*i)/14) + +// [U[J[pbg؂ւp +GXRgb TempPalette[16 * 16] = +{ + MAKECOLOR(12, 16, 19), + MAKECOLOR(23, 9, 0), + MAKECOLOR(31, 0, 3), + MAKECOLOR(31, 17, 31), + MAKECOLOR(31, 18, 0), + MAKECOLOR(30, 28, 0), + MAKECOLOR(21, 31, 0), + MAKECOLOR( 0, 31, 0), + MAKECOLOR( 0, 20, 7), + MAKECOLOR( 9, 27, 17), + MAKECOLOR( 6, 23, 30), + MAKECOLOR( 0, 11, 30), + MAKECOLOR( 0, 0, 18), + MAKECOLOR(17, 0, 26), + MAKECOLOR(26, 0, 29), + MAKECOLOR(31, 0, 18), +}; + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- +#define CANVAS_WIDTH 32 // `̕ (LN^P) +#define CANVAS_HEIGHT 24 // `̍ (LN^P) +#define CANVAS_LEFT 0 // `̈ʒuX (LN^P) +#define CANVAS_TOP 0 // `̈ʒuY (LN^P) + +#define TEXT_HSPACE 1 // `掞̕ (sNZP) +#define TEXT_VSPACE 1 // `掞̍s (sNZP) + +#define CHARACTER_OFFSET 0 // gpLN^̊Jnԍ + +// RTCf[^\ʒu[N +typedef struct RtcDrawPos{ + int date_x; + int date_y; + int time_x; + int time_y; +}RtcDrawPos; + +// function's prototype------------------------------------------------------- +static BOOL WaitDetachTP( void ); +static void StartDetachTP( void ); +static void InitScreen( void ); +static void InitCanvas( void ); + +// global variable------------------------------------------------------------- +KeyWork pad; // L[pbh̓f[^ +TpWork tpd; // ^b`pl̓f[^ +NNSFndAllocator g_allocator; // AP[^ +NNSG2dFont gFont; // tHg +NNSG2dCharCanvas gCanvas; // CharCanvas +NNSG2dTextCanvas gTextCanvas; // TextCanvas +NNSG2dCharCanvas gCanvasSub; // CharCanvas +NNSG2dTextCanvas gTextCanvasSub; // TextCanvas + +// static variable------------------------------------------------------------- +static int s_detach_count; +static RtcDrawPos s_rtcPos; +static RTCDate s_rtcDate; +static RTCTime s_rtcTime; +static u16 s_vcount; + +static char s_strBuffer[ STRING_LENGTH_MAX * 2 ] ATTRIBUTE_ALIGN(2); +static u16 s_strBufferUTF16[ STRING_LENGTH_MAX ]; + +// const data------------------------------------------------------------------ + +// jf[^\pR[h +const u8 *const g_strWeek[] ATTRIBUTE_ALIGN(2) = { + (const u8 *)"SUN", + (const u8 *)"MON", + (const u8 *)"TUE", + (const u8 *)"WED", + (const u8 *)"THU", + (const u8 *)"FRI", + (const u8 *)"SAT", +}; + + +// ============================================================================ +// Ǘ +// ============================================================================ + +// AP[^̏ +void InitAllocator( void ) +{ + NNSFndAllocator *pAllocator = &g_allocator; + u32 arenaLow = MATH_ROUNDUP ( (u32)OS_GetMainArenaLo(), 16 ); + u32 arenaHigh = MATH_ROUNDDOWN( (u32)OS_GetMainArenaHi(), 16 ); + u32 heapSize = arenaHigh - arenaLow; + void* heapMemory = OS_AllocFromMainArenaLo( heapSize, 16 ); + NNSFndHeapHandle heapHandle; + SDK_NULL_ASSERT( pAllocator ); + + heapHandle = NNS_FndCreateExpHeap( heapMemory, heapSize ); + SDK_ASSERT( heapHandle != NNS_FND_HEAP_INVALID_HANDLE ); + + NNS_FndInitAllocatorForExpHeap( pAllocator, heapHandle, 32 ); +} + + +// 蓖 +void *Alloc( u32 size ) +{ + return NNS_FndAllocFromAllocator( &g_allocator, size ); +} + + +// +void Free( void *pBuffer ) +{ + NNS_FndFreeToAllocator( &g_allocator, pBuffer ); +} + + +// ============================================================================ +// ʐݒ +// ============================================================================ + +// BG +void InitBG(void) +{ + // OFF + GX_DispOff(); + GXS_DispOff(); + + // VRAM̊蓖ĂSĉ + GX_DisableBankForBG(); + GX_DisableBankForOBJ(); + GX_DisableBankForSubBG(); + GX_DisableBankForSubOBJ(); + + // C2DGW̏o͂ʂ + GX_SetDispSelect( GX_DISP_SELECT_SUB_MAIN ); + + // CLCD + { + // VRAM蓖 + GX_SetBankForBG ( GX_VRAM_BG_128_A ); + GX_SetBankForOBJ( GX_VRAM_OBJ_128_B ); + + MI_CpuClearFast( (void *)HW_BG_VRAM, 0x20000 ); // BG -VRAM NA + MI_CpuClearFast( (void *)HW_OBJ_VRAM, 0x20000 ); // OBJ-VRAM NA + MI_DmaFill32( 3, (void *)HW_OAM, 192, HW_OAM_SIZE ); // OAM NA + + // J[pbgݒ + GX_LoadBGPltt( TXTColorPalette, 0, sizeof(TXTColorPalette) ); + + // BG[hݒ + GX_SetGraphicsMode( GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BG0_AS_2D ); + + GX_SetBGScrOffset ( GX_BGSCROFFSET_0x10000 ); + GX_SetBGCharOffset( GX_BGCHAROFFSET_0x00000 ); + } + // TuLCD + { + // VRAM蓖 + GX_SetBankForSubBG ( GX_VRAM_SUB_BG_128_C ); // VRAM-C for BGs + GX_SetBankForSubOBJ( GX_VRAM_SUB_OBJ_128_D ); // VRAM-D for BGs + + MI_CpuClearFast( (void *)HW_DB_BG_VRAM, 0x20000 ); // BG -VRAM NA + MI_CpuClearFast( (void *)HW_DB_OBJ_VRAM, 0x20000 ); // OBJ -VRAM NA + + // J[pbgݒ + GXS_LoadBGPltt( TXTColorPalette, 0, sizeof(TXTColorPalette) ); + + // BG[hݒ + GXS_SetGraphicsMode( GX_BGMODE_0 ); // BGMODE is 0 + } + InitScreen(); + InitCanvas(); +} + + +// XN[ +static void InitScreen( void ) +{ + // C BG 0 ݒ + G2_SetBG0Control( + GX_BG_SCRSIZE_TEXT_256x256, // XN[TCY 256x256 + GX_BG_COLORMODE_256, // J[[h 256F + GX_BG_SCRBASE_0xf800, // XN[x[X + GX_BG_CHARBASE_0x00000, // LN^x[X + GX_BG_EXTPLTT_01 // gpbgXbg + ); + G2_SetBG1Control( + GX_BG_SCRSIZE_TEXT_256x256, // 256pix x 256pix text + GX_BG_COLORMODE_16, // use 16 colors mode + GX_BG_SCRBASE_0xe800, // screen base offset + 0x0000 is the address for BG #1 screen + GX_BG_CHARBASE_0x10000, // character base offset + 0x04000 is the address for BG #0 characters + GX_BG_EXTPLTT_01 // use BGExtPltt slot #0 if BGExtPltt is enabled + ); + G2_SetBG2ControlText( + GX_BG_SCRSIZE_TEXT_256x256, // 256pix x 256pix text + GX_BG_COLORMODE_16, // use 16 colors mode + GX_BG_SCRBASE_0xd800, // screen base offset + 0x0000 is the address for BG #1 screen + GX_BG_CHARBASE_0x14000 // character base offset + 0x04000 is the address for BG #0 characters + ); + GX_SetVisiblePlane( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1); + G2_SetBG2Priority(0); + G2_SetBG0Priority(1); + G2_SetBG1Priority(2); + + // Tu BG 0 ݒ + G2S_SetBG0Control( + GX_BG_SCRSIZE_TEXT_256x256, // 256pix x 256pix text + GX_BG_COLORMODE_16, // use 16 colors mode + GX_BG_SCRBASE_0xf800, // screen base offset + 0x0000 is the address for BG #0 screen + GX_BG_CHARBASE_0x00000, // character base offset + 0x04000 is the address for BG #0 characters + GX_BG_EXTPLTT_01 // use BGExtPltt slot #0 if BGExtPltt is enabled + ); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); // display only BG #0 +} + + +// `̏ +static void InitCanvas( void ) +{ + CMN_InitFileSystem( &g_allocator ); + + // tHgǂݍ݂܂ + { + void* pFontFile; + u32 size = CMN_LoadFile( &pFontFile, NTR_IPL_FONT_DATA, &g_allocator); + NNS_G2D_ASSERT( size > 0 ); + NNS_G2dFontInitUTF16(&gFont, pFontFile); +// NNS_G2dPrintFont(&gFont); + } + + { + // CharCanvas ̏ + NNS_G2dCharCanvasInitForBG( + &gCanvas, + (GXCharFmt256*)G2_GetBG0CharPtr() + CHARACTER_OFFSET, + CANVAS_WIDTH, + CANVAS_HEIGHT, + NNS_G2D_CHARA_COLORMODE_256 + ); + + // TextCanvas̏ + NNS_G2dTextCanvasInit( + &gTextCanvas, + &gCanvas, + &gFont, + TEXT_HSPACE, + TEXT_VSPACE + ); + + // XN[ݒ + NNS_G2dMapScrToCharText( + G2_GetBG0ScrPtr(), + CANVAS_WIDTH, + CANVAS_HEIGHT, + CANVAS_LEFT, + CANVAS_TOP, + NNS_G2D_TEXT_BG_WIDTH_256, + CHARACTER_OFFSET, + TXT_CPALETTE_MAIN + ); + } + { + // CharCanvas ̏ + NNS_G2dCharCanvasInitForBG( + &gCanvasSub, + (GXCharFmt16*)G2S_GetBG0CharPtr() + CHARACTER_OFFSET, + CANVAS_WIDTH, + CANVAS_HEIGHT, + NNS_G2D_CHARA_COLORMODE_16 + ); + + // TextCanvas̏ + NNS_G2dTextCanvasInit( + &gTextCanvasSub, + &gCanvasSub, + &gFont, + TEXT_HSPACE, + TEXT_VSPACE + ); + + // XN[ݒ + NNS_G2dMapScrToCharText( + G2S_GetBG0ScrPtr(), + CANVAS_WIDTH, + CANVAS_HEIGHT, + CANVAS_LEFT, + CANVAS_TOP, + NNS_G2D_TEXT_BG_WIDTH_256, + CHARACTER_OFFSET, + TXT_CPALETTE_MAIN + ); + } +} + + +// UTF16ł̒ڕ\ +void PutStringUTF16( int x, int y, int color, const u16 *strUTF16 ) +{ + NNS_G2dTextCanvasDrawText( &gTextCanvas, x, y, color, TXT_DRAWTEXT_FLAG_DEFAULT, + strUTF16 ); +} + +void PutStringUTF16Sub( int x, int y, int color, const u16 *strUTF16 ) +{ + NNS_G2dTextCanvasDrawText( &gTextCanvasSub, x, y, color, TXT_DRAWTEXT_FLAG_DEFAULT, + strUTF16 ); +} + + +// tō쐬\ꍇ̕擾 +int GetPrintfWidth( const NNSG2dTextCanvas *pCanvas, const char *fmt, ... ) +{ + int srcLen; + int dstLen = sizeof(s_strBufferUTF16); + va_list vlist; + va_start(vlist, fmt); + srcLen = STD_TVSNPrintf( s_strBuffer, sizeof(s_strBuffer), fmt, vlist); + va_end(vlist); + s_strBuffer[ srcLen ] = 0; + + (void)STD_ConvertStringSjisToUnicode( s_strBufferUTF16, &dstLen, s_strBuffer, &srcLen, NULL ); + s_strBufferUTF16[ dstLen ] = 0; + + return NNS_G2dTextCanvasGetTextWidth( pCanvas, s_strBufferUTF16 ); +} + + +// SJISPrintf`ŕ\iUTF16ɕϊ) +void PrintfSJIS( int x, int y, int color, const char *fmt, ... ) +{ + int srcLen; + int dstLen = sizeof(s_strBufferUTF16); + va_list vlist; + va_start(vlist, fmt); + srcLen = STD_TVSNPrintf( s_strBuffer, sizeof(s_strBuffer), fmt, vlist); + va_end(vlist); + s_strBuffer[ srcLen ] = 0; + + (void)STD_ConvertStringSjisToUnicode( s_strBufferUTF16, &dstLen, s_strBuffer, &srcLen, NULL ); + s_strBufferUTF16[ dstLen ] = 0; + + NNS_G2dTextCanvasDrawText(&gTextCanvas, x, y, color, TXT_DRAWTEXT_FLAG_DEFAULT, + s_strBufferUTF16 ); +} + +void PrintfSJISSub( int x, int y, int color, const char *fmt, ... ) +{ + int srcLen; + int dstLen = sizeof(s_strBufferUTF16); + va_list vlist; + va_start(vlist, fmt); + srcLen = STD_TVSNPrintf( s_strBuffer, sizeof(s_strBuffer), fmt, vlist); + va_end(vlist); + s_strBuffer[ srcLen ] = 0; + + (void)STD_ConvertStringSjisToUnicode( s_strBufferUTF16, &dstLen, s_strBuffer, &srcLen, NULL ); + s_strBufferUTF16[ dstLen ] = 0; + + NNS_G2dTextCanvasDrawText(&gTextCanvasSub, x, y, color, TXT_DRAWTEXT_FLAG_DEFAULT, + s_strBufferUTF16 ); +} + + +// L[͓ǂݏo-------------------------------- +void ReadKeyPad(void) +{ + u16 readData = PAD_Read(); + pad.trg = (u16)(readData & (readData ^ pad.cont)); // gK + pad.cont = readData; // x^ +} + + +// ^b`plf[^̎擾----------------------- +void ReadTP(void) +{ + TP_GetCalibratedPoint( &tpd.last, &tpd.raw ); // OTPf[^ޔ + + if( TP_RequestRawSampling(&tpd.raw) ) { // ^b`pl̃TvO + SVC_CpuClear(0x0000, &tpd.raw, sizeof(tpd.raw), 16); // SPI-busyŃf[^擾Ɏśhf[^ȂhŃ^[B + return; + } + TP_GetCalibratedPoint( &tpd.disp, &tpd.raw ); // TPWLCDWɕϊB + + if( !WaitDetachTP() ) { // TPf^b`҂sB + SVC_CpuClear(0x0000, &tpd.disp, sizeof(tpd.disp), 16); // SPI-busyŃf[^擾Ɏśhf[^ȂhŃ^[B + return; + } +#if 1 + if(tpd.disp.touch) { // ݂TPf[^\ + switch ( tpd.disp.validity ) { + case TP_VALIDITY_VALID: + OS_Printf("( %3d, %3d ) -> ( %3d, %3d )\n", tpd.raw.x, tpd.raw.y, tpd.disp.x, tpd.disp.y); + break; + case TP_VALIDITY_INVALID_X: + OS_Printf("( *%3d, %3d ) -> ( *%3d, %3d )\n", tpd.raw.x, tpd.raw.y, tpd.disp.x, tpd.disp.y); + break; + case TP_VALIDITY_INVALID_Y: + OS_Printf("( %3d, *%3d ) -> ( %3d, *%3d )\n", tpd.raw.x, tpd.raw.y, tpd.disp.x, tpd.disp.y); + break; + case TP_VALIDITY_INVALID_XY: + OS_Printf("( *%3d, *%3d ) -> ( *%3d, *%3d )\n", tpd.raw.x, tpd.raw.y, tpd.disp.x, tpd.disp.y); + break; + } + } +#endif +} + + +// TPf^b`҂ +static BOOL WaitDetachTP( void ) +{ + // s_detach_countnĂAJEgB + if(s_detach_count > 0) { + if(tpd.disp.touch == 0) { // TPĂȂ΁AJEgisKlōē͂󂯕tB + s_detach_count--; + }else { + s_detach_count = TP_CSR_DETACH_COUNT; + } + return FALSE; + } + return TRUE; +} + + +// TPf^b`҂̊Jn +static void StartDetachTP( void ) +{ + s_detach_count = TP_CSR_DETACH_COUNT; +} + + +//====================================================== +// j[ +//====================================================== + +// j[` +void DrawMenu( u16 nowCsr, const MenuParam *pMenu ) +{ + int i; + int color; + + for( i = 0; i < pMenu->num; i++ ) { + if(i == nowCsr) { + if( !pMenu->pos[ i ].enable ) { + color = pMenu->disable_color; + }else { + color = pMenu->select_color; + } + }else { + color = pMenu->normal_color; + } + PutStringUTF16( pMenu->pos[ i ].x, pMenu->pos[ i ].y, color, (pMenu->str_elem)[ i ] ); + } +} + +// ^b`plɂIs֐EėpŁB +// Ƀ`^Ozx̋@\B +// SelectSomethingFunc^̊֐|C^funcɂ́AɎ𖞂֐AXgɂăZbgĎgB +// PDvfŃ^b`ĂTRUEԂAłȂFALSEԂB +// QDɗ^|C^̎wϐɃJ[\ʒuĕԂB +BOOL SelectSomethingByTP( u16 *nowCsr, SelectSomethingFunc func[], int funcnum ) +{ + int i; + static u16 detach_count = 0; + static u16 csr_old = 0xffff; + static u16 same_csr_count = 0; + + // detach_countnĂAJEgB + if( detach_count > 0 ) { + if( tpd.disp.touch == 0 ) { // TPĂȂ΁AJEgisATP_CSR_DETACH_COUNTJEgŃj[I + if( ++detach_count == TP_CSR_DETACH_COUNT ) { + detach_count = 0; + same_csr_count = 0; + *nowCsr = csr_old; + return TRUE; + }else { + return FALSE; + } + } + } + detach_count=0; // detachJEgl̃NA + + for( i = 0; i < funcnum; i++ ) { + if( tpd.disp.touch ) { // ^b`pl^b`ĂȂA + u16 csr; + if( func[i]( &csr, &tpd.disp ) ) { // func͗vfɃ^b`ĂTRUEԂAJ[\ʒuԂĂ֐ + OS_TPrintf( "InRange\n" ); + if( tpd.disp.validity == TP_VALIDITY_VALID ) { // J[\̗vfɈړ + if( csr_old == csr ) { + if( same_csr_count < TP_CSR_TOUCH_COUNT ) { + same_csr_count++; + } + if( same_csr_count == TP_CSR_TOUCH_COUNT ) { + *nowCsr = csr; + } + return FALSE; + }else { + csr_old = csr; + } + break; + } + }else { + OS_TPrintf( "OutRange\n" ); + } + }else { // touch==0 + if( same_csr_count == TP_CSR_TOUCH_COUNT ) { + detach_count = 1; + break; + } + } + } + same_csr_count = 0; + return FALSE; +} + +// ^b`plɂ郁j[I +BOOL SelectMenuByTP( u16 *nowCsr, const MenuParam *pMenu ) +{ + u16 i; + static u16 detach_count = 0; + static u16 csr_old = 0xff; + static u16 same_csr_count = 0; + + // detach_countnĂAJEgB + if( detach_count > 0 ) { + if( tpd.disp.touch == 0 ) { // TPĂȂ΁AJEgisAPOJEgŃj[I + if( ++detach_count == TP_CSR_DETACH_COUNT ) { + detach_count = 0; + return TRUE; + }else { + return FALSE; + } + } + } + detach_count=0; // detachJEgl̃NA + + for( i = 0; i < pMenu->num; i++ ) { + if( tpd.disp.touch ) { // ^b`plj[̗vfŃ^b`ĂȂA + NNSG2dTextRect rect = NNS_G2dTextCanvasGetTextRect( &gTextCanvas, (pMenu->str_elem)[ i ] ); + u16 top_x = (u16)( pMenu->pos[ i ].x ); // j[vfLCDWZo + u16 top_y = (u16)( pMenu->pos[ i ].y ); + u16 bottom_x = (u16)( top_x + rect.width ); + u16 bottom_y = (u16)( top_y + rect.height ); + + OS_TPrintf( "MENU[ %d ] : top_x = %02d top_y = %02d bot_x = %02d bot_y = %02d : ", + i, top_x, top_y, bottom_x, bottom_y ); + + if( WithinRangeTP( top_x, top_y, bottom_x, bottom_y, &tpd.disp ) ) { + OS_TPrintf( "InRange\n" ); + if( tpd.disp.validity == TP_VALIDITY_VALID ) { // J[\̗vfɈړ + if( csr_old == i ) { + if( same_csr_count < TP_CSR_TOUCH_COUNT ) { + same_csr_count++; + } + if( same_csr_count == TP_CSR_TOUCH_COUNT ) { + *nowCsr = i; + } + return FALSE; + }else { + csr_old = i; + } + break; + } + }else { + OS_TPrintf( "OutRange\n" ); + } + }else { // touch==0 + if( same_csr_count == TP_CSR_TOUCH_COUNT ) { + detach_count = 1; + break; + } + } + } + same_csr_count = 0; + return FALSE; +} + + +// ݂̃^b`plWẅɂ邩ǂԂB +BOOL WithinRangeTP( int top_x, int top_y, int bottom_x, int bottom_y, TPData *tgt ) +{ + if( ( tgt->x >= top_x ) && + ( tgt->x <= bottom_x ) && + ( tgt->y >= top_y ) && + ( tgt->y <= bottom_y ) ) { + OS_TPrintf( "\nRANGE : tx=%3d ty=%3d bx=%3d by=%3d : x=%3d y=%3d\n", + top_x, top_y, bottom_x, bottom_y, tgt->x, tgt->y ); + return TRUE; + }else { + return FALSE; + } +} + + +// oi[ACROBJ̃[h +void SetBannerIconOBJ( GXOamAttr *pDstOAM, BannerFileV1 *bannerp ) +{ + GXS_LoadOBJPltt( bannerp->pltt, 15, BANNER_PLTT_SIZE ); + MI_CpuCopyFast( bannerp->image, (void *)(HW_DB_OBJ_VRAM + 0x20), BANNER_IMAGE_SIZE ); + G2_SetOBJAttr( pDstOAM, // OAM pointer + 32, // X position + 32, // Y position + 0, // Priority + GX_OAM_MODE_NORMAL, // Bitmap mode + FALSE, // mosaic off + GX_OAM_EFFECT_NONE, // affine off + GX_OAM_SHAPE_32x32, // 16x16 size + GX_OAM_COLOR_16, // 16 color + 1, // charactor + 15, // palette + 0); // affine +} + + +//=============================================== +// RTCANZX[` +//=============================================== + +// RTCf[^̎擾 +BOOL GetRTCData( RTCDrawProperty *pRTCDraw, BOOL forceGetFlag ) +{ + if( forceGetFlag || ( pRTCDraw->vcount++ == 59 ) ) { + pRTCDraw->vcount = 0; + MI_CpuCopy16( &pRTCDraw->date, &pRTCDraw->date_old, sizeof(RTCDate) ); + MI_CpuCopy16( &pRTCDraw->time, &pRTCDraw->time_old, sizeof(RTCTime) ); + (void)RTC_GetDateTime( &pRTCDraw->date, &pRTCDraw->time ); + return TRUE; + } + return FALSE; +} + + +// RTCf[^̕\ +void DrawRTCData( RTCDrawProperty *pRTCDraw ) +{ + void (*pPrintFunc)( int x, int y, int color, const char *fmt, ... ) = + ( pRTCDraw->isTopLCD ) ? PrintfSJISSub : PrintfSJIS; + + // ORTC̏ + { + u32 year = pRTCDraw->date_old.year + 2000; + pPrintFunc( pRTCDraw->date_x, pRTCDraw->date_y, TXT_COLOR_WHITE, "%04d/%02d/%02d[%3s]", + year, + pRTCDraw->date_old.month, + pRTCDraw->date_old.day, + g_strWeek[ pRTCDraw->date_old.week ] + ); + pPrintFunc( pRTCDraw->time_x, pRTCDraw->time_y, TXT_COLOR_WHITE, "%02d:%02d:%02d", + pRTCDraw->time_old.hour, + pRTCDraw->time_old.minute, + pRTCDraw->time_old.second + ); + } + // RTC̕\ + { + u32 year = pRTCDraw->date.year + 2000; + pPrintFunc( pRTCDraw->date_x, pRTCDraw->date_y, TXT_COLOR_BLACK, "%d/%02d/%02d[%3s]", + year, + pRTCDraw->date.month, + pRTCDraw->date.day, + g_strWeek[ pRTCDraw->date.week ] + ); + pPrintFunc( pRTCDraw->time_x, pRTCDraw->time_y, TXT_COLOR_BLACK, "%02d:%02d:%02d", + pRTCDraw->time.hour, + pRTCDraw->time.minute, + pRTCDraw->time.second + ); + } +} + +// RTCf[^̎擾&\ +void GetAndDrawRTCData( RTCDrawProperty *pRTCDraw, BOOL forceGetFlag ) +{ + if( GetRTCData( pRTCDraw, forceGetFlag ) ) { + DrawRTCData( pRTCDraw ); + } +} + +// [U[J[̈̐؂ւ +void ChangeUserColor( u8 col ) +{ + int l; + if(col > 15) return; + for(l=0;l<16;l++) + { + TXTColorPalette[16+l] = TempPalette[16 * col + l]; + } + GX_LoadBGPltt( TXTColorPalette, 0, sizeof(TXTColorPalette) ); +} diff --git a/build/tests/AppliCooperation/CooperationA/ARM9/Makefile b/build/tests/AppliCooperation/CooperationA/ARM9/Makefile new file mode 100644 index 00000000..9ed68572 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationA/ARM9/Makefile @@ -0,0 +1,62 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos.TWL - nandApp - appliCooperation - cooperationA +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- + +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +TITLEID_LO = COPA + +TARGET_BIN = CooperationA.tad + +ROM_SPEC = main.rsf + +MISC_DIR = ../../../misc +DATA_DIR = ../../../data + +SRCS = main.c CooperationA.c \ + $(MISC_DIR)/misc_simple.c \ + $(DATA_DIR)/data.c + +LINCLUDES = $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/include \ + $(MISC_DIR) \ + $(DATA_DIR) + +LLIBRARY_DIRS += $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/lib/$(TWL_BUILDTYPE) + +LLIBRARIES += libDEMO$(TWL_LIBSUFFIX).a + +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +SDK_NMENU_DATADIR = $(ROOT)/build/tools/TwlNMenu/data +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/AppliCooperation/CooperationA/ARM9/main.rsf b/build/tests/AppliCooperation/CooperationA/ARM9/main.rsf new file mode 100644 index 00000000..2f5b1192 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationA/ARM9/main.rsf @@ -0,0 +1,178 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-11-21#$ +# $Rev: 240 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + #_GameCode $(TITLEID_LO) + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType User + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + SaveBannerFile FALSE +} + + +RomSpec +{ + Offset 0x00000000 + Segment ALL +} diff --git a/build/tests/AppliCooperation/CooperationA/ARM9/src/CooperationA.c b/build/tests/AppliCooperation/CooperationA/ARM9/src/CooperationA.c new file mode 100644 index 00000000..b82465f2 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationA/ARM9/src/CooperationA.c @@ -0,0 +1,502 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: CooperationA.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:: 2007-10-31#$ + $Rev: 91 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc_simple.h" +#include "CooperationA.h" + +// define data------------------------------------------ +#define RETURN_BUTTON_TOP_X 2 +#define RETURN_BUTTON_TOP_Y 21 +#define RETURN_BUTTON_BOTTOM_X ( RETURN_BUTTON_TOP_X + 8 ) +#define RETURN_BUTTON_BOTTOM_Y ( RETURN_BUTTON_TOP_Y + 2 ) + +// \tgEFAL[{[hLCD̈ +#define CLIST_LT_X 2 +#define CLIST_LT_Y 6 + +#define CLIST_MARGIN 2 +#define CLIST_KEY_PER_SEGMENT 5 +#define CLIST_SEGMENT_INTERVAL 1 + +#define COPA_MENU_ELEMENT_NUM 3 // j[̍ڐ +#define CHAR_LIST_CHAR_NUM 120 +#define CHAR_LIST_MODE_NUM 1 +// L[R[h +#define EOM_ (char)0xf8 +#define CODE_BUTTON_TOP_ (char)0xf9 +#define DEL_BUTTON_ (char)0xf9 +#define SPACE_BUTTON_ (char)0xfa +#define VAR_BUTTON1_ (char)0xfb +#define VAR_BUTTON2_ (char)0xfc +#define OK_BUTTON_ (char)0xfd +#define CANCEL_BUTTON_ (char)0xfe +#define CODE_BUTTON_BOTTOM_ (char)0xff + +#define CHAR_USCORE '_' +#define KEY_PER_LINE 11 + +#define KEY_START 98 //\tgEFAL[̃J[\ftHgʒu̓LZL[ + +#define PARAM_LENGTH 10 + +typedef struct CopA_Work +{ + u16 csr; + int char_mode; + u16 key_csr; + char parameter[ PARAM_LENGTH + 1 ]; + char temp_parameter[ PARAM_LENGTH + 1 ]; + u8 temp_parameter_length; + void(*pNowProcess)(void); + int starx,stary; +} CopA_Work; + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- + +static void MenuScene( void ); + +// global variable ------------------------------------- + +// static variable ------------------------------------- + +static CopA_Work s_work = (CopA_Work){0,0,0,"","",0,0,0}; + +static char a_or_c = 'A'; + +// const data ----------------------------------------- +static const char char_tbl[CHAR_LIST_MODE_NUM][CHAR_LIST_CHAR_NUM]; + +static const char *s_pStrMenu[ COPA_MENU_ELEMENT_NUM ] = +{ + "Set Parameter", + "Launch CooperationB", + "Return to Launcher", +}; + +static MenuPos s_menuPos[] = { + { TRUE, 3, 6 }, + { TRUE, 3, 8 }, + { TRUE, 3, 10 }, + { TRUE, 3, 12 }, +}; + +static const MenuParam s_menuParam = { + COPA_MENU_ELEMENT_NUM, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_menuPos[ 0 ], + (const char **)&s_pStrMenu, +}; + +static const char *str_button_char[CHAR_LIST_MODE_NUM] = { + "eisuu", + }; + +//static u16 next_char_mode[CHAR_LIST_MODE_NUM-1]; + +static const char str_button_del[] = "DEL"; +static const char str_button_space[] = "SPACE"; +static const char str_button_ok[] = "OK"; +static const char str_button_cancel[] = "CANCEL"; + +static const char *str_button[] = { + (const char *)str_button_del, + (const char *)str_button_space, + NULL, + NULL, + (const char *)str_button_ok, + (const char *)str_button_cancel, + }; + +//====================================================== +// AvAgeXgvOA +//====================================================== + +static void SetSoftKeyboardButton(int mode) +{ +/* + int l; + int count = 0; + for(l=0; l= CODE_BUTTON_TOP_) && (code < CODE_BUTTON_BOTTOM_) ) + { + int x = code - CODE_BUTTON_TOP_; + myDp_Printf( CLIST_LT_X + CLIST_MARGIN*(l%KEY_PER_LINE) + CLIST_SEGMENT_INTERVAL*((l%KEY_PER_LINE)/CLIST_KEY_PER_SEGMENT) , + CLIST_LT_Y + CLIST_MARGIN*(l/KEY_PER_LINE) , color, MAIN_SCREEN, str_button[x] ); + } + else + { + char s[2]; + s[0] = code; + s[1] = 0; + myDp_Printf( CLIST_LT_X + CLIST_MARGIN*(l%KEY_PER_LINE) + CLIST_SEGMENT_INTERVAL*((l%KEY_PER_LINE)/CLIST_KEY_PER_SEGMENT) , + CLIST_LT_Y + CLIST_MARGIN*(l/KEY_PER_LINE) , color, MAIN_SCREEN, s ); + } + } + } +} + +// ꕶ폜 +static void DeleteACharacter( void ) +{ + char *buf; + u8 *length; + buf = s_work.temp_parameter; + length = &s_work.temp_parameter_length; + + if(*length > 0) buf[--(*length)] = CHAR_USCORE; +} + +static void MenuInit( void ) +{ + GX_DispOff(); + GXS_DispOff(); + + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "Cooperation%c", a_or_c); + + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); + + s_work.pNowProcess = MenuScene; + + GX_DispOn(); + GXS_DispOn(); +} + +// I𒆕L[EL[Ō肵̋ +static void PushKeys( char code ) +{ + char *buf; + u8 *length; + u16 max_length; + buf = s_work.temp_parameter; + length = &s_work.temp_parameter_length; + max_length = PARAM_LENGTH; + + if( (code >= CODE_BUTTON_TOP_) && (code < CODE_BUTTON_BOTTOM_) ) + { + // L[ + switch(code) + { + case VAR_BUTTON1_: + case VAR_BUTTON2_: +// SetSoftKeyboardButton(next_char_mode[code - VAR_BUTTON1_]); + break; + case DEL_BUTTON_: + DeleteACharacter(); + break; + case SPACE_BUTTON_: + if(*length < max_length) buf[(*length)++] = ' '; + break; + case OK_BUTTON_: + MI_CpuClear8(buf + *length, (u32)(max_length - *length));// [NA + MI_CpuCopy8(buf, s_work.parameter, (PARAM_LENGTH+1)); + // Z[uɃLZƍ + case CANCEL_BUTTON_: + MenuInit(); + break; + default:// unknown code + break; + } + } + else + { + // ʃL[ + if(*length < max_length) buf[(*length)++] = code; + } +} + +// \tgEFAL[ł̃L[pbhyу^b`pbh +// ReadTPĂƁB +static void PadDetectOnKey( void ) +{ + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( MYPAD_IS_TRIG(PAD_KEY_RIGHT) ){ // J[\̈ړ + do + { + if(s_work.key_csr%KEY_PER_LINE != KEY_PER_LINE-1) s_work.key_csr++; + else s_work.key_csr -= KEY_PER_LINE-1; + if( s_work.key_csr == CHAR_LIST_CHAR_NUM ) s_work.key_csr -= s_work.key_csr%KEY_PER_LINE; + } + while(char_tbl[s_work.char_mode][s_work.key_csr]==EOM_); + } + if( MYPAD_IS_TRIG(PAD_KEY_LEFT) ){ + do + { + if(s_work.key_csr%KEY_PER_LINE != 0) s_work.key_csr--; + else s_work.key_csr += KEY_PER_LINE-1; + if( s_work.key_csr & 0x8000 ) s_work.key_csr = KEY_PER_LINE-1; + } + while(char_tbl[s_work.char_mode][s_work.key_csr]==EOM_); + } + if( MYPAD_IS_TRIG(PAD_KEY_DOWN) ){ // J[\̈ړ + do + { + s_work.key_csr += KEY_PER_LINE; + if( s_work.key_csr >= CHAR_LIST_CHAR_NUM ) s_work.key_csr -= KEY_PER_LINE*(s_work.key_csr/KEY_PER_LINE); + } + while(char_tbl[s_work.char_mode][s_work.key_csr]==EOM_); + } + if( MYPAD_IS_TRIG(PAD_KEY_UP) ){ + do + { + if( s_work.key_csr < KEY_PER_LINE ) s_work.key_csr += (CHAR_LIST_CHAR_NUM/KEY_PER_LINE)*KEY_PER_LINE; + else s_work.key_csr -= KEY_PER_LINE; + if( s_work.key_csr >= CHAR_LIST_CHAR_NUM ) s_work.key_csr -= KEY_PER_LINE; + } + while(char_tbl[s_work.char_mode][s_work.key_csr]==EOM_); + } + + + if( MYPAD_IS_TRIG(PAD_BUTTON_A) ) { // L[ꂽ + PushKeys( char_tbl[s_work.char_mode][s_work.key_csr] ); + }else if( MYPAD_IS_TRIG(PAD_BUTTON_B) ) { + DeleteACharacter(); + } +} + +// p[^ҏWʂ̕`揈 +static void DrawSetParameterScene( void ) +{ + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "PARAMETER" ); + myDp_Printf( 11, 3, TXT_COLOR_BLACK, MAIN_SCREEN, s_work.temp_parameter ); + DrawCharKeys(); +} + +// p[^ҏW̏ +static void SetParameterInit( void ) +{ + SetSoftKeyboardButton(0); + s_work.key_csr = KEY_START; + + // p[^pe|obt@̏ + MI_CpuCopy8(s_work.parameter, s_work.temp_parameter, (PARAM_LENGTH+1)); + s_work.temp_parameter_length = (u8)STD_GetStringLength( s_work.temp_parameter ); + if( s_work.temp_parameter_length < PARAM_LENGTH ) { + MI_CpuFill8( &s_work.temp_parameter[ s_work.temp_parameter_length ], CHAR_USCORE, (u32)(PARAM_LENGTH - s_work.temp_parameter_length) ); + } + + DrawSetParameterScene(); + + GX_SetVisiblePlane ( GX_PLANEMASK_BG0 ); + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); +} + +// p[^ҏWC +static void SetParameterMain( void ) +{ + PadDetectOnKey(); + + // `揈 + DrawSetParameterScene(); +} + +static void DrawMenuScene( void ) +{ + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "Cooperation%c", a_or_c); + myDp_Printf( 19 , 6, TXT_COLOR_DARKLIGHTBLUE, MAIN_SCREEN, s_work.parameter ); + // j[ + myDp_DrawMenu( s_work.csr, MAIN_SCREEN, &s_menuParam ); + myDp_Printf( 1, 20, TXT_COLOR_BLACK, MAIN_SCREEN, "'%c' pos = (%d,%d)", (a_or_c=='A' ? '*' : '$'), s_work.starx, s_work.stary); + myDp_Printf( s_work.starx, s_work.stary, TXT_COLOR_RED, MAIN_SCREEN, (a_or_c=='A' ? "*" : "$")); +} + +static void MenuScene(void) +{ + LauncherBootFlags tempflag = {TRUE, LAUNCHER_BOOTTYPE_NAND, TRUE, FALSE, FALSE, FALSE, 0}; + + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( MYPAD_IS_TRIG(PAD_KEY_DOWN) ){ // J[\̈ړ + if( ++s_work.csr == COPA_MENU_ELEMENT_NUM ) { + s_work.csr=0; + } + if( ++s_work.stary == 24) + { + s_work.stary = 0; + } + } + if( MYPAD_IS_TRIG(PAD_KEY_UP) ){ + if( --s_work.csr & 0x80 ) { + s_work.csr=COPA_MENU_ELEMENT_NUM - 1; + } + if( --s_work.stary == -1) + { + s_work.stary = 23; + } + } + if( MYPAD_IS_TRIG(PAD_KEY_LEFT) ){ // J[\̈ړ + if( --s_work.starx == -1) + { + s_work.starx = 31; + } + } + if( MYPAD_IS_TRIG(PAD_KEY_RIGHT) ){ + if( ++s_work.starx == 32) + { + s_work.starx = 0; + } + } + + DrawMenuScene(); + + if( MYPAD_IS_TRIG(PAD_BUTTON_A)) { // j[ڂւ̕ + if( s_menuPos[ s_work.csr ].enable ) { + switch( s_work.csr ) { + case 0: + SetParameterInit(); + s_work.pNowProcess = SetParameterMain; + break; + case 1: + // ݂̃AvԂZ[u + { + FSFile f; + FS_InitFile(&f); + if(!FS_SetCurrentDirectory("dataPrv:/")) {MI_CpuCopy8("W Error 1",s_work.parameter,10); break;} + FS_CreateFile("test.dat", FS_PERMIT_R | FS_PERMIT_W ); + if(!FS_OpenFileEx(&f, "test.dat", FS_FILEMODE_W)) {MI_CpuCopy8("W Error 2",s_work.parameter,10); break;} + if(-1 == FS_WriteFile(&f, &s_work, sizeof(s_work))) {MI_CpuCopy8("W Error 3",s_work.parameter,10); break;} + if(!FS_CloseFile( &f )) {MI_CpuCopy8("W Error 4",s_work.parameter,10); break;} + } + // Avԃp[^Zbg + { + u16 *maker_code_src_addr = (u16 *)(HW_TWL_ROM_HEADER_BUF + 0x10); + u32 *game_code_src_addr = (u32 *)(HW_TWL_ROM_HEADER_BUF + 0xc); + u64 *title_id_src_addr = (u64 *)(HW_TWL_ROM_HEADER_BUF + 0x230); + // Avԃp[^̏ + OS_InitArgBufferForDelivery( OS_DELIVER_ARG_BUFFER_SIZE ); + // validtO𗧂Ă + OS_SetValidDeliveryArgumentInfo( TRUE ); + // [J[R[hƃQ[R[h̃Zbg + OS_SetMakerCodeToDeliveryArgumentInfo( *maker_code_src_addr ); + OS_SetGameCodeToDeliveryArgumentInfo( *game_code_src_addr ); + OS_SetTitleIdToDeliveryArgumentInfo( *title_id_src_addr ); + // Avp̃Zbg + OS_SetDeliveryArgments( (const char *)s_work.parameter ); + } + //BN + OS_SetLauncherParamAndResetHardware( 0, 0x00030004434f5042, &tempflag ); + break; + case 2: + OS_SetLauncherParamAndResetHardware( 0, NULL, &tempflag ); + //ċN + break; + } + } + } +} + +// +void CooperationAInit( void ) +{ + s_work.parameter[0] = 0; + + a_or_c = *((char *)(HW_TWL_ROM_HEADER_BUF + 0x230));// title_ID̍ʼnʂi[ + + MenuInit(); + FS_Init(3); + + { + if( OS_IsValidDeliveryArgumentInfo() ) + { + OS_DecodeDeliveryBuffer(); + if(STD_CompareNString((const char *)OS_GetArgv(1), "-r", 3) == 0) + { + // Z[uf[^畜A + FSFile f; + FS_InitFile(&f); + if(!FS_SetCurrentDirectory("dataPrv:/")) {MI_CpuCopy8("R Error 1",s_work.parameter,10); return;} + if(!FS_OpenFileEx(&f, "test.dat", FS_FILEMODE_R)) {return;} + if(-1 == FS_ReadFile(&f, &s_work, sizeof(s_work))) {MI_CpuCopy8("R Error 2",s_work.parameter,10); return;} + if(!FS_CloseFile( &f )) {MI_CpuCopy8("R Error 3",s_work.parameter,10); return;} + } + } + } +} + +// C[v +void CooperationAMain(void) +{ + s_work.pNowProcess(); +} + + +//====================================================== +// \tgEFAL[{[hpLe[u +//====================================================== + +static const char char_tbl[CHAR_LIST_MODE_NUM][CHAR_LIST_CHAR_NUM] = { + { // p + 'A', 'B', 'C', 'D', 'E', + 'F', 'G', 'H', 'I', 'J', DEL_BUTTON_, + 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', SPACE_BUTTON_, + 'U', 'V', 'W', 'X', 'Y', + 'Z', EOM_, EOM_, EOM_, EOM_, EOM_, + + 'a', 'b', 'c', 'd', 'e', + 'f', 'g', 'h', 'i', 'j', EOM_, + 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', EOM_, + 'u', 'v', 'w', 'x', 'y', + 'z', EOM_, EOM_, EOM_, EOM_, EOM_, + + '0', '1', '2', '3', '4', + '5', '6', '7', '8', '9', EOM_, + '!', EOM_, '&', EOM_, '/', + ',', EOM_, '.', EOM_, '-', OK_BUTTON_, + '\'', EOM_, '"', EOM_, EOM_, + '@', EOM_, '(', EOM_, ')', CANCEL_BUTTON_, + + EOM_, EOM_, EOM_, EOM_, EOM_, + EOM_, EOM_, EOM_, EOM_, EOM_, EOM_, + EOM_, EOM_, EOM_, EOM_, EOM_, + EOM_, EOM_, EOM_, EOM_, EOM_, + }, +}; \ No newline at end of file diff --git a/build/tests/AppliCooperation/CooperationA/ARM9/src/CooperationA.h b/build/tests/AppliCooperation/CooperationA/ARM9/src/CooperationA.h new file mode 100644 index 00000000..160f0fb9 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationA/ARM9/src/CooperationA.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: CooperationA.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-10-30#$ + $Rev: 73 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#ifndef __COOPERATION_A_H__ +#define __COOPERATION_A_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +// define data---------------------------------------------------------- + +void CooperationAInit( void ); +void CooperationAMain( void ); + +#ifdef __cplusplus +} +#endif + +#endif // __COOPERATION_A_H__ diff --git a/build/tests/AppliCooperation/CooperationA/ARM9/src/main.c b/build/tests/AppliCooperation/CooperationA/ARM9/src/main.c new file mode 100644 index 00000000..c92cd26c --- /dev/null +++ b/build/tests/AppliCooperation/CooperationA/ARM9/src/main.c @@ -0,0 +1,68 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-11-27#$ + $Rev: 272 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc_simple.h" +#include "CooperationA.h" + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +static void INTR_VBlank( void ); + +// global variable------------------------------------------------------------- + +// static variable------------------------------------------------------------- +BOOL g_isValidTSD; + +// const data------------------------------------------------------------------ + + +// ============================================================================ +// function's description +// ============================================================================ +void TwlMain(void) +{ + myInit(); + + CooperationAInit(); + // C[v---------------------------- + while(1){ + + myPreMain(); + + CooperationAMain(); + + myProMain(); + + OS_WaitIrq(1, OS_IE_V_BLANK); // VuN荞ݑ҂ + } +} + + +// ============================================================================ +// 荞ݏ +// ============================================================================ + +// VuN荞 +static void INTR_VBlank(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // VuN`FbÑZbg +} + diff --git a/build/tests/AppliCooperation/CooperationA/Makefile b/build/tests/AppliCooperation/CooperationA/Makefile new file mode 100644 index 00000000..b9a231a1 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationA/Makefile @@ -0,0 +1,30 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos.TWL - nandApp - appliCooperation - cooperationA +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tests/AppliCooperation/CooperationA/banner/Makefile b/build/tests/AppliCooperation/CooperationA/banner/Makefile new file mode 100644 index 00000000..aafe44c2 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationA/banner/Makefile @@ -0,0 +1,50 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +MAKEBANNER = $(TWL_TOOLSDIR)/bin/makebanner.TWL.exe + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/tests/AppliCooperation/CooperationA/banner/banner_v3.bsf b/build/tests/AppliCooperation/CooperationA/banner/banner_v3.bsf new file mode 100644 index 00000000..abd490d1 Binary files /dev/null and b/build/tests/AppliCooperation/CooperationA/banner/banner_v3.bsf differ diff --git a/build/tests/AppliCooperation/CooperationA/banner/icon/gameIcon.bmp b/build/tests/AppliCooperation/CooperationA/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..4837ffe0 Binary files /dev/null and b/build/tests/AppliCooperation/CooperationA/banner/icon/gameIcon.bmp differ diff --git a/build/tests/AppliCooperation/CooperationB/ARM9/Makefile b/build/tests/AppliCooperation/CooperationB/ARM9/Makefile new file mode 100644 index 00000000..c3882c59 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationB/ARM9/Makefile @@ -0,0 +1,62 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos.TWL - nandApp - AppliCooperation - CooperationB +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- + +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +TITLEID_LO = COPB + +TARGET_BIN = CooperationB.tad + +ROM_SPEC = main.rsf + +MISC_DIR = ../../../misc +DATA_DIR = ../../../data + +SRCS = main.c CooperationB.c \ + $(MISC_DIR)/misc_simple.c \ + $(DATA_DIR)/data.c + +LINCLUDES = $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/include \ + $(MISC_DIR) \ + $(DATA_DIR) + +LLIBRARY_DIRS += $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/lib/$(TWL_BUILDTYPE) + +LLIBRARIES += libDEMO$(TWL_LIBSUFFIX).a + +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +SDK_NMENU_DATADIR = $(ROOT)/build/tools/TwlNMenu/data +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/AppliCooperation/CooperationB/ARM9/main.rsf b/build/tests/AppliCooperation/CooperationB/ARM9/main.rsf new file mode 100644 index 00000000..fa4fb30a --- /dev/null +++ b/build/tests/AppliCooperation/CooperationB/ARM9/main.rsf @@ -0,0 +1,178 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-11-21#$ +# $Rev: 240 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + #_GameCode $(TITLEID_LO) + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType User + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + SaveBannerFile FALSE +} + + +RomSpec +{ + Offset 0x00000000 + Segment ALL +} diff --git a/build/tests/AppliCooperation/CooperationB/ARM9/src/CooperationB.c b/build/tests/AppliCooperation/CooperationB/ARM9/src/CooperationB.c new file mode 100644 index 00000000..29d2466b --- /dev/null +++ b/build/tests/AppliCooperation/CooperationB/ARM9/src/CooperationB.c @@ -0,0 +1,175 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: CooperationB.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:: 2007-10-31#$ + $Rev: 91 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc_simple.h" +#include "CooperationB.h" + +// define data------------------------------------------ +#define COPB_MENU_ELEMENT_NUM 2 // j[̍ڐ + +#define PARAM_LENGTH 10 + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- + +static void MenuScene( void ); + +// global variable ------------------------------------- + +// static variable ------------------------------------- +static u16 s_csr = 0; +static char s_parameter[ PARAM_LENGTH + 1 ]; +static void(*s_pNowProcess)(void); + +// const data ----------------------------------------- +static const char *s_pStrMenu[ COPB_MENU_ELEMENT_NUM ] = +{ + "Launch Former App", + "Return to Launcher", +}; + +static MenuPos s_menuPos[] = { + { FALSE, 3, 6 }, + { TRUE, 3, 8 }, +}; + +static const MenuParam s_menuParam = { + COPB_MENU_ELEMENT_NUM, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_menuPos[ 0 ], + (const char **)&s_pStrMenu, +}; + +//====================================================== +// AvAgeXgvOB +//====================================================== + +static void DrawMenuScene( void ) +{ + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "CooperationB"); + myDp_Printf( 1, 18, TXT_COLOR_BLACK, MAIN_SCREEN, "Received Paramater:"); + myDp_Printf( 3 , 19, TXT_COLOR_DARKLIGHTBLUE, MAIN_SCREEN, s_parameter ); + myDp_Printf( 1, 14, TXT_COLOR_BLACK, MAIN_SCREEN, "Former App:"); + myDp_Printf(3, 15, TXT_COLOR_BLACK, MAIN_SCREEN, "0x%llx",OS_IsValidDeliveryArgumentInfo() ? OS_GetTitleIdFromDeliveryArgumentInfo() : 0x0); + // j[ + myDp_DrawMenu( s_csr, MAIN_SCREEN, &s_menuParam ); +} + +static void MenuInit( void ) +{ + GX_DispOff(); + GXS_DispOff(); + + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "CooperationB"); + + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); + + s_pNowProcess = MenuScene; + + MI_CpuClear8(s_parameter, (PARAM_LENGTH+1)); + + { + if( OS_IsValidDeliveryArgumentInfo() ) + { + s_menuPos[ 0 ].enable = TRUE; + OS_DecodeDeliveryBuffer(); + if(OS_GetArgv(1) != NULL) + { + MI_CpuCopy8(OS_GetArgv(1), s_parameter, (PARAM_LENGTH+1)); + } + else + { + s_parameter[0] = '\0'; + } + } + } + + DrawMenuScene(); + + GX_DispOn(); + GXS_DispOn(); +} + +static void MenuScene(void) +{ + LauncherBootFlags tempflag = {TRUE, LAUNCHER_BOOTTYPE_NAND, TRUE, FALSE, FALSE, FALSE, 0}; + + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( MYPAD_IS_TRIG(PAD_KEY_DOWN) ){ // J[\̈ړ + if( ++s_csr == COPB_MENU_ELEMENT_NUM ) { + s_csr=0; + } + } + if( MYPAD_IS_TRIG(PAD_KEY_UP) ){ + if( --s_csr & 0x80 ) { + s_csr=COPB_MENU_ELEMENT_NUM - 1; + } + } + + DrawMenuScene(); + + if( MYPAD_IS_TRIG(PAD_BUTTON_A) ) { // j[ڂւ̕ + if( s_menuPos[ s_csr ].enable ) { + switch( s_csr ) { + case 0: + if(OS_IsValidDeliveryArgumentInfo()) + { + u16 *maker_code_src_addr = (u16 *)(HW_TWL_ROM_HEADER_BUF + 0x10); + u32 *game_code_src_addr = (u32 *)(HW_TWL_ROM_HEADER_BUF + 0xc); + u64 targetApp = OS_GetTitleIdFromDeliveryArgumentInfo(); + // Avԃp[^̏ + OS_InitArgBufferForDelivery( OS_DELIVER_ARG_BUFFER_SIZE ); + // validtO𗧂Ă + OS_SetValidDeliveryArgumentInfo( TRUE ); + // [J[R[hƃQ[R[h̃Zbg(LauncherłׂH) + OS_SetMakerCodeToDeliveryArgumentInfo( *maker_code_src_addr ); + OS_SetGameCodeToDeliveryArgumentInfo( *game_code_src_addr ); + OS_SetTitleIdToDeliveryArgumentInfo( 0x00030004434f5042 ); + // Avp̃Zbg + OS_SetDeliveryArgments( "-r" ); + + //ĂяoAvN + OS_SetLauncherParamAndResetHardware( 0, targetApp, &tempflag ); + } + break; + case 1: + OS_SetLauncherParamAndResetHardware( 0, NULL, &tempflag ); + //ċN + break; + } + } + } +} + +// +void CooperationBInit( void ) +{ + s_parameter[0] = 0; + MenuInit(); +} + +// C[v +void CooperationBMain(void) +{ + s_pNowProcess(); +} diff --git a/build/tests/AppliCooperation/CooperationB/ARM9/src/CooperationB.h b/build/tests/AppliCooperation/CooperationB/ARM9/src/CooperationB.h new file mode 100644 index 00000000..88002c24 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationB/ARM9/src/CooperationB.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: CooperationB.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-10-30#$ + $Rev: 73 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#ifndef __COOPERATION_B_H__ +#define __COOPERATION_B_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +// define data---------------------------------------------------------- + +void CooperationBInit( void ); +void CooperationBMain( void ); + +#ifdef __cplusplus +} +#endif + +#endif // __COOPERATION_B_H__ diff --git a/build/tests/AppliCooperation/CooperationB/ARM9/src/main.c b/build/tests/AppliCooperation/CooperationB/ARM9/src/main.c new file mode 100644 index 00000000..e9267dc1 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationB/ARM9/src/main.c @@ -0,0 +1,68 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-11-27#$ + $Rev: 272 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc_simple.h" +#include "CooperationB.h" + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +static void INTR_VBlank( void ); + +// global variable------------------------------------------------------------- + +// static variable------------------------------------------------------------- +BOOL g_isValidTSD; + +// const data------------------------------------------------------------------ + + +// ============================================================================ +// function's description +// ============================================================================ +void TwlMain(void) +{ + myInit(); + + CooperationBInit(); + // C[v---------------------------- + while(1){ + + myPreMain(); + + CooperationBMain(); + + myProMain(); + + OS_WaitIrq(1, OS_IE_V_BLANK); // VuN荞ݑ҂ + } +} + + +// ============================================================================ +// 荞ݏ +// ============================================================================ + +// VuN荞 +static void INTR_VBlank(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // VuN`FbÑZbg +} + diff --git a/build/tests/AppliCooperation/CooperationB/Makefile b/build/tests/AppliCooperation/CooperationB/Makefile new file mode 100644 index 00000000..9cf34e12 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationB/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tests/AppliCooperation/CooperationB/banner/Makefile b/build/tests/AppliCooperation/CooperationB/banner/Makefile new file mode 100644 index 00000000..aafe44c2 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationB/banner/Makefile @@ -0,0 +1,50 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +MAKEBANNER = $(TWL_TOOLSDIR)/bin/makebanner.TWL.exe + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/tests/AppliCooperation/CooperationB/banner/banner_v3.bsf b/build/tests/AppliCooperation/CooperationB/banner/banner_v3.bsf new file mode 100644 index 00000000..8513828c Binary files /dev/null and b/build/tests/AppliCooperation/CooperationB/banner/banner_v3.bsf differ diff --git a/build/tests/AppliCooperation/CooperationB/banner/icon/gameIcon.bmp b/build/tests/AppliCooperation/CooperationB/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..d2c5448f Binary files /dev/null and b/build/tests/AppliCooperation/CooperationB/banner/icon/gameIcon.bmp differ diff --git a/build/tests/AppliCooperation/CooperationC/ARM9/Makefile b/build/tests/AppliCooperation/CooperationC/ARM9/Makefile new file mode 100644 index 00000000..e001cc54 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationC/ARM9/Makefile @@ -0,0 +1,64 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos.TWL - nandApp - AppliCooperation - CooperationC +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- + +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +TITLEID_LO = COPC + +TARGET_BIN = CooperationC.tad + +ROM_SPEC = main.rsf + +A_SRC_DIR = ../../CooperationA/ARM9/src +MISC_DIR = ../../../misc +DATA_DIR = ../../../data + +SRCS = $(A_SRC_DIR)/main.c $(A_SRC_DIR)/CooperationA.c \ + $(MISC_DIR)/misc_simple.c \ + $(DATA_DIR)/data.c + +LINCLUDES = $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/include \ + $(A_SRC_DIR) \ + $(MISC_DIR) \ + $(DATA_DIR) + +LLIBRARY_DIRS += $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/lib/$(TWL_BUILDTYPE) + +LLIBRARIES += libDEMO$(TWL_LIBSUFFIX).a + +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +SDK_NMENU_DATADIR = $(ROOT)/build/tools/TwlNMenu/data +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/AppliCooperation/CooperationC/ARM9/main.rsf b/build/tests/AppliCooperation/CooperationC/ARM9/main.rsf new file mode 100644 index 00000000..2f5b1192 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationC/ARM9/main.rsf @@ -0,0 +1,178 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-11-21#$ +# $Rev: 240 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + #_GameCode $(TITLEID_LO) + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType User + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + SaveBannerFile FALSE +} + + +RomSpec +{ + Offset 0x00000000 + Segment ALL +} diff --git a/build/tests/AppliCooperation/CooperationC/Makefile b/build/tests/AppliCooperation/CooperationC/Makefile new file mode 100644 index 00000000..9cf34e12 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationC/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tests/AppliCooperation/CooperationC/banner/Makefile b/build/tests/AppliCooperation/CooperationC/banner/Makefile new file mode 100644 index 00000000..aafe44c2 --- /dev/null +++ b/build/tests/AppliCooperation/CooperationC/banner/Makefile @@ -0,0 +1,50 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +MAKEBANNER = $(TWL_TOOLSDIR)/bin/makebanner.TWL.exe + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/tests/AppliCooperation/CooperationC/banner/banner_v3.bsf b/build/tests/AppliCooperation/CooperationC/banner/banner_v3.bsf new file mode 100644 index 00000000..44d1726f Binary files /dev/null and b/build/tests/AppliCooperation/CooperationC/banner/banner_v3.bsf differ diff --git a/build/tests/AppliCooperation/CooperationC/banner/icon/gameIcon.bmp b/build/tests/AppliCooperation/CooperationC/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..0d8cd7c4 Binary files /dev/null and b/build/tests/AppliCooperation/CooperationC/banner/icon/gameIcon.bmp differ diff --git a/build/tests/AppliCooperation/Makefile b/build/tests/AppliCooperation/Makefile new file mode 100644 index 00000000..b640c858 --- /dev/null +++ b/build/tests/AppliCooperation/Makefile @@ -0,0 +1,30 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos.TWL - nandApp - appliCooperation +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = CooperationA CooperationB CooperationC + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tests/ExecPreLoadedApp/ARM7/Makefile b/build/tests/ExecPreLoadedApp/ARM7/Makefile new file mode 100644 index 00000000..ebc1205b --- /dev/null +++ b/build/tests/ExecPreLoadedApp/ARM7/Makefile @@ -0,0 +1,98 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - components - racoon.TWL +# 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-11-30#$ +# $Rev: 2778 $ +# $Author: terui $ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM = TWL +override TWL_PROC = ARM7 +override TWL_ARCHGEN = LIMITED +TWL_NO_STD_PCHDR = True +TWL_CODEGEN ?= ALL + +#---------------------------------------------------------------------------- + +SRCDIR = $(ROOT)/build/components/mongoose.TWL/src + +SRCS = main.c + +TARGET_NAME = my_racoon + +TARGET_NEF = $(TARGET_NAME).tef +LCFILE_SPEC = $(TARGET_NAME).lsf +LCFILE_TEMPLATE = $(TARGET_NAME).lcf.template +LDRES_TEMPLATE = $(TARGET_NAME).response.template + +CRT0_O = crt0.LTD.TWL.o + +#---------------------------------------------------------------------------- +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +ifdef TWLSDK_NOCRYPTO +CCFLAGS += -DSDK_NOCRYPTO +endif + +ifndef TWLSDK_NOCRYPTO +MAKELCF_FLAGS += -DUSE_CRYPTO_LIBS='libaes_sp$(TWL_LIBSUFFIX).a' +endif + +#MACRO_FLAGS += -DSDK_ARM7COMP_LTD + +ifeq ($(TWL_PLATFORM),BB) +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037e0000' +else +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' +endif + +MAKELCF_FLAGS += -DISDBG_LIBS_TWL='$(if $(ISDBG_LIBS_TWL),$(ISDBG_LIBS_TWL),libstubsistd_sp$(TWL_LIBSUFFIX).a)' \ + -DISDBG_LIBS_NITRO='libstubsisd_sp$(TWL_LIBSUFFIX).a' + + +#-------------------------------- +# install target +#-------------------------------- +INSTALL_TARGETS = $(BINDIR)/$(TARGET_NAME).tef \ + $(BINDIR)/$(TARGET_NAME).TWL.FLX.sbin \ + $(BINDIR)/$(TARGET_NAME)_defs.TWL.FLX.sbin \ + $(BINDIR)/$(TARGET_NAME).TWL.LTD.sbin \ + $(BINDIR)/$(TARGET_NAME)_defs.TWL.LTD.sbin + +INSTALL_DIR = $(TWL_INSTALL_COMPONENTSDIR)/$(TARGET_NAME)/$(TWL_BUILDTYPE) + +LINCLUDES = $(ROOT)/build/libraries/spi/ARM7/include +#LLIBRARIES += libwl_sp.TWL.LTD.a libsdio_hcd_twl$(TWL_LIBSUFFIX).a libsdio_busdriver$(TWL_LIBSUFFIX).a libsdio_lib$(TWL_LIBSUFFIX).a libARM7athdrv$(TWL_LIBSUFFIX).a +LLIBRARIES += libwl_sp.TWL.LTD.a +#LLIBRARIES += libwl_sp$(TWL_LIBSUFFIX).a \ +# libcdc_sp$(TWL_LIBSUFFIX).a \ +# libtpex_sp$(TWL_LIBSUFFIX).a \ +# libmicex_sp$(TWL_LIBSUFFIX).a \ +# libsdio_hcd_twl$(TWL_LIBSUFFIX).a \ +# libsdio_busdriver$(TWL_LIBSUFFIX).a \ +# libsdio_lib$(TWL_LIBSUFFIX).a \ +# librompatch_sp$(TWL_LIBSUFFIX).a \ +# libARM7athdrv$(TWL_LIBSUFFIX).a + +LDEPENDS_NEF = $(TWL_LIBS) $(LLIBRARIES) + +do-build: $(TARGETS) + +#---------------------------------------------------------------------------- +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/tests/ExecPreLoadedApp/ARM7/my_racoon.lcf.template b/build/tests/ExecPreLoadedApp/ARM7/my_racoon.lcf.template new file mode 100644 index 00000000..85a5f503 --- /dev/null +++ b/build/tests/ExecPreLoadedApp/ARM7/my_racoon.lcf.template @@ -0,0 +1,915 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - components - racoon.TWL +# File: racoon.lcf.template +# +# 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-11-12#$ +# $Rev: 2249 $ +# $Author: terui $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.WORKRAM (RWX) : ORIGIN = 0x037c0000, LENGTH = 0x50000 > workram.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDMAIN (RWX) : ORIGIN = 0x02f88000, LENGTH = 0x74000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.WRAM.START = 0x037c0000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = . + SDK_AUTOLOAD.WRAM.BSS_END - SDK_AUTOLOAD.WRAM.START + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = 0x02f88000; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02e80000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + .check.LTDMAIN: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.LTDMAIN + +} diff --git a/build/tests/ExecPreLoadedApp/ARM7/my_racoon.lsf b/build/tests/ExecPreLoadedApp/ARM7/my_racoon.lsf new file mode 100644 index 00000000..b3670046 --- /dev/null +++ b/build/tests/ExecPreLoadedApp/ARM7/my_racoon.lsf @@ -0,0 +1,187 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - components - racoon.TWL +# File: racoon.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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:: 2008-02-01#$ +# $Rev: 4002 $ +# $Author: terui $ +#---------------------------------------------------------------------------- +# +# Nitro LCF SPEC FILE +# +#-------- +Static $(TARGET_NAME) +{ + Address 0x02a00000 + Library $(CRT0_O) + StackSize 1024 1024 +} + +#-------- +Autoload WRAM +{ + Address $(ADDRESS_LTDWRAM) + + Library libsubpsyscall.a \ + libsyscall_sp.twl.a \ + $(CW_LIBS) \ + libos_sp$(LIBSUFFIX).a \ + libmi_sp$(LIBSUFFIX).a \ + libpad_sp$(LIBSUFFIX).a \ + libpxi_sp$(LIBSUFFIX).a \ + libstd_sp$(LIBSUFFIX).a \ + libexi_sp$(LIBSUFFIX).a \ + libsnd_sp$(LIBSUFFIX).a \ + libspi_sp$(LIBSUFFIX).a \ + libpm_sp$(LIBSUFFIX).a \ + libmath_sp$(LIBSUFFIX).a \ + libscfg_sp$(LIBSUFFIX).a \ + libtp_sp$(LIBSUFFIX).a \ + libmic_sp$(LIBSUFFIX).a \ + libfs_sp$(LIBSUFFIX).a \ + libcard_sp$(LIBSUFFIX).a \ + libi2c_sp$(LIBSUFFIX).a \ + libcamera_sp$(LIBSUFFIX).a \ + libcdc_sp$(LIBSUFFIX).a \ + libsndex_sp$(LIBSUFFIX).a \ + libtpex_sp$(LIBSUFFIX).a \ + libmicex_sp$(LIBSUFFIX).a \ + libmcu_sp$(LIBSUFFIX).a \ + + Library libsdio_sp$(LIBSUFFIX).a + + Library libnvram_sp$(LIBSUFFIX).a + Library librtc_sp$(LIBSUFFIX).a + + + Object * (.etable) + Object * (.wram) + Object * (.ltdwram) + Object $(OBJDIR)/main.o + + # caches in fatfs library, that should be on WRAM. + # 2007/12/11 OBJECT() ɂ .bss V{̃N܂Ȃ̂ŁA + # ϐ`ӏ pragma .ltdwram ZNVɊ܂܂悤Ɏb΍􂵂܂B +# Object OBJECT( FATFSi___mem_drives_structures , libfatfs_sp$(LIBSUFFIX).a) (.bss) + + ##### + # Sub-routines in WL library , that should be on WRAM. + # in TaskMan.o + Object OBJECT( MainTaskRoutine , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AddTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( DeleteTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( LowestIdleTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ExecuteMessage , libwl_sp$(LIBSUFFIX).a ) (.text) + # in BufMan.o + Object OBJECT( NewHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( DeleteHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AllocateHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ReleaseHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( MoveHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AddHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( GetHeapBufNextAdrs , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlCmdIf.o + Object OBJECT( RequestCmdTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SendMessageToWmDirect , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlNic.o + Object OBJECT( WStart , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WStop , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WSetStaState , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlIntr.o + Object OBJECT( WlIntr , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrPreTbtt , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTbtt , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrActEnd , libwl_sp$(LIBSUFFIX).a ) (.text) +# Object OBJECT( WlIntrAckCntOvf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrCntOvf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxErr , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxCntup , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrMpEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrStartTx , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrStartRx , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SetParentTbttTxq , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( MacBugTxMp , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AdjustRingPointer , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( CheckKeyTxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlIntrTask.o + Object OBJECT( WlIntrTxBeaconTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrMpEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SetParentTbttTxqTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( TakeoutRxFrame , libwl_sp$(LIBSUFFIX).a ) (.text) + # in TxCtrl.o + Object OBJECT( InitTxCtrl , libwl_sp$(LIBSUFFIX).a ) (.text) + # in RxCtrl.o + Object OBJECT( InitRxCtrl , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WaitLoop.o + Object OBJECT( WaitLoop_Rxpe , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_Waitus , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_ClrAid , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_BbpAccess , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_RfAccess , libwl_sp$(LIBSUFFIX).a ) (.text) + +# Object OBJECT( s_ar_cookie_mem , libathdrv_sp$(LIBSUFFIX).a ) (.bss) +# Object OBJECT( nin_ar , libathdrv_sp$(LIBSUFFIX).a ) (.bss) + + Object OBJECT( a_netbuf_alloc_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( a_netbuf_register_rx_callback , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_driver_tx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_tx_queue_full , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_tx_complete , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_bitrate_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_channelList_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_txPwr_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_gpio_intr_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_gpio_data_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_gpio_ack_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_drv_BmiWriteSocReg , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ar6000_control_tx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_drv_BmiReadMemory , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( nin_drv_BmiWriteMemory , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( BMI_read_reg , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( BMI_write_reg , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( BMI_read_mem , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( BMI_write_mem , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( wmi_dix_2_dot3 , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( wmi_control_rx_xtnd , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( wmi_control_rx , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( wmi_cmd_send , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( wmi_cmd_send_xtnd , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( HIFReadWrite , libathdrv_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ath_ioctl , libathdrv_sp$(LIBSUFFIX).a ) (.text) + + Object OBJECT( wpa_sm_rx_eapol , libwpa_sp$(LIBSUFFIX).a ) (.text) + +} + +#-------- +Ltdautoload LTDMAIN +{ + Address 0x02f88000 + + Object * (.ltdmain) + Library libwm_sp$(LIBSUFFIX).a \ + libnwm_sp$(LIBSUFFIX).a \ + libwvr_sp$(LIBSUFFIX).a \ + libwl_sp$(LIBSUFFIX).a + + Library libwpa_sp$(LIBSUFFIX).a + Library libathdrv_sp$(LIBSUFFIX).a + + Library libfatfs_sp$(LIBSUFFIX).a \ + $(USE_CRYPTO_LIBS) + Library $(ISDBG_LIBS_TWL) + Library $(ISDBG_LIBS_NITRO) +} diff --git a/build/tests/ExecPreLoadedApp/ARM7/my_racoon.response.template b/build/tests/ExecPreLoadedApp/ARM7/my_racoon.response.template new file mode 100644 index 00000000..88b18081 --- /dev/null +++ b/build/tests/ExecPreLoadedApp/ARM7/my_racoon.response.template @@ -0,0 +1,40 @@ + + + + + -l + + + + + + + -l + + + + -og ,0 -ol + + + + + -l + + + + + + + + -l + + + + -og ,0 -ol + + + + + -l + + diff --git a/build/tests/ExecPreLoadedApp/ARM9/ARM9-TS.lsf b/build/tests/ExecPreLoadedApp/ARM9/ARM9-TS.lsf new file mode 100644 index 00000000..17f40824 --- /dev/null +++ b/build/tests/ExecPreLoadedApp/ARM9/ARM9-TS.lsf @@ -0,0 +1,54 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-BB.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-11-20#$ +# $Rev: 221 $ +# $Author: yoshida_teruhisa $ +#---------------------------------------------------------------------------- +# +# TWL LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x02800000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) +} + + +Autoload ITCM +{ + Address 0x01ff8000 + Object * (.itcm) + Object $(OBJS_AUTOLOAD) (.text) + Object $(OBJS_AUTOLOAD) (.rodata) +} + +Autoload DTCM +{ + Address $(ADDRESS_DTCM) + Object * (.dtcm) + Object $(OBJS_AUTOLOAD) (.data) + Object $(OBJS_AUTOLOAD) (.sdata) + Object $(OBJS_AUTOLOAD) (.bss) + Object $(OBJS_AUTOLOAD) (.sbss) +} + +Ltdautoload LTDMAIN +{ + # NITRO/TWL L̃I[o[C݂ꍇ́Aɂ̌ɔzuKv܂B + After $(TARGET_NAME) + Object * (.ltdmain) + Object $(OBJS_LTDAUTOLOAD) + Library $(LLIBS_EX) $(GLIBS_EX) +} diff --git a/build/tests/ExecPreLoadedApp/ARM9/Makefile b/build/tests/ExecPreLoadedApp/ARM9/Makefile new file mode 100644 index 00000000..8c730d4b --- /dev/null +++ b/build/tests/ExecPreLoadedApp/ARM9/Makefile @@ -0,0 +1,69 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos.TWL - nandApp - ExecPreLoadedApp +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- + +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +TITLEID_LO = MLEP + +TARGET_BIN = ExecPreLoadedApp.tad + +LCFILE_SPEC = ARM9-TS.lsf +ROM_SPEC = main.rsf + +MISC_DIR = ../../misc +DATA_DIR = ../../data + +SRCS = main.c ExecPreLoadedApp.c \ + $(MISC_DIR)/misc_simple.c \ + $(DATA_DIR)/data.c + +LINCLUDES = $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/include \ + $(MISC_DIR) \ + $(DATA_DIR) + +LLIBRARY_DIRS += $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/lib/$(TWL_BUILDTYPE) + +LLIBRARIES += libDEMO$(TWL_LIBSUFFIX).a + +ADDRESS_DTCM = 0x0e000000 + +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +DEFAULT_COMP_ARM7 = my_racoon +DEFAULT_MAKEROM_ARM7_BASE = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/$(DEFAULT_COMP_ARM7) +DEFAULT_MAKEROM_ARM7 = $(DEFAULT_MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) + +SDK_NMENU_DATADIR = $(ROOT)/build/tools/TwlNMenu/data +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/ExecPreLoadedApp/ARM9/main.rsf b/build/tests/ExecPreLoadedApp/ARM9/main.rsf new file mode 100644 index 00000000..bb1048fc --- /dev/null +++ b/build/tests/ExecPreLoadedApp/ARM9/main.rsf @@ -0,0 +1,178 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-12-19#$ +# $Rev: 378 $ +# $Author: yoshida_teruhisa $ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + #BannerFile ./etc/myGameBanner.bnr + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType User + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + #SaveBannerFile TRUE +} + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot ../../data + Root /data + File simpleapp.srl +} \ No newline at end of file diff --git a/build/tests/ExecPreLoadedApp/ARM9/src/ExecPreLoadedApp.c b/build/tests/ExecPreLoadedApp/ARM9/src/ExecPreLoadedApp.c new file mode 100644 index 00000000..343be51f --- /dev/null +++ b/build/tests/ExecPreLoadedApp/ARM9/src/ExecPreLoadedApp.c @@ -0,0 +1,152 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - demos.TWL - nandApp - ExecPreLoadedApp + File: ExecPreLoadedApp.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:: 2007-10-31#$ + $Rev: 91 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "misc_simple.h" +#include "ExecPreLoadedApp.h" + +// define data------------------------------------------ + +#define MLEP_MENU_ELEMENT_NUM 2 // j[̍ڐ + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- + +static void MenuScene( void ); + +// global variable ------------------------------------- + +// static variable ------------------------------------- +static u16 s_csr = 0; +static void(*s_pNowProcess)(void); + +// const data ----------------------------------------- +static const char *s_pStrMenu[ MLEP_MENU_ELEMENT_NUM ] = +{ + "load app and restart", + "return to launcher", +}; + +static MenuPos s_menuPos[] = { + { TRUE, 3, 6 }, + { TRUE, 3, 8 }, +}; + +static const MenuParam s_menuParam = { + MLEP_MENU_ELEMENT_NUM, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_menuPos[ 0 ], + (const char **)&s_pStrMenu, +}; + +//====================================================== +// eXgvO +//====================================================== + +// ============================================================================ +// +// AvN +// +// ============================================================================ + +static void DrawMenuScene( void ) +{ + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "ExecPreLoadedApp"); + // j[ + myDp_DrawMenu( s_csr, MAIN_SCREEN, &s_menuParam ); +} + +static void MenuInit( void ) +{ + FS_Init(3); + GX_DispOff(); + GXS_DispOff(); + + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "ExecPreLoadedApp"); + + s_pNowProcess = MenuScene; + + DrawMenuScene(); + + GX_DispOn(); + GXS_DispOn(); +} + + +static BOOL LoadTitle( void ) +{ + // [h + if( !OS_SetRelocateInfoAndLoadApplication( "rom:/data/simpleapp.srl" ) ) + { + return FALSE; + } + + return TRUE; +} + +static void MenuScene(void) +{ + LauncherBootFlags tempflag = {TRUE, LAUNCHER_BOOTTYPE_MEMORY, TRUE, FALSE, TRUE, FALSE, 0}; + + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( MYPAD_IS_TRIG(PAD_KEY_DOWN) ){ // J[\̈ړ + if( ++s_csr == MLEP_MENU_ELEMENT_NUM ) { + s_csr=0; + } + } + if( MYPAD_IS_TRIG(PAD_KEY_UP) ){ + if( --s_csr & 0x80 ) { + s_csr=MLEP_MENU_ELEMENT_NUM - 1; + } + } + + DrawMenuScene(); + + if( MYPAD_IS_TRIG(PAD_BUTTON_A) ) { // j[ڂւ̕ + if( s_menuPos[ s_csr ].enable ) { + switch( s_csr ) { + case 0: + //AvN + if(LoadTitle()) + OS_SetLauncherParamAndResetHardware( 0, 0x00030004534d504c, &tempflag ); // SMPL + break; + case 1: + OS_SetLauncherParamAndResetHardware( 0, NULL, &tempflag ); + //ċN + break; + } + } + } +} + +// +void ExecPreLoadedAppInit( void ) +{ + MenuInit(); +} + +// C[v +void ExecPreLoadedAppMain(void) +{ + s_pNowProcess(); +} diff --git a/build/tests/ExecPreLoadedApp/ARM9/src/ExecPreLoadedApp.h b/build/tests/ExecPreLoadedApp/ARM9/src/ExecPreLoadedApp.h new file mode 100644 index 00000000..aa427c35 --- /dev/null +++ b/build/tests/ExecPreLoadedApp/ARM9/src/ExecPreLoadedApp.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: ExecPreLoadedApp.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-10-30#$ + $Rev: 73 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#ifndef __COOPERATION_B_H__ +#define __COOPERATION_B_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +// define data---------------------------------------------------------- + +void ExecPreLoadedAppInit( void ); +void ExecPreLoadedAppMain( void ); + +#ifdef __cplusplus +} +#endif + +#endif // __COOPERATION_B_H__ diff --git a/build/tests/ExecPreLoadedApp/ARM9/src/main.c b/build/tests/ExecPreLoadedApp/ARM9/src/main.c new file mode 100644 index 00000000..0327bac8 --- /dev/null +++ b/build/tests/ExecPreLoadedApp/ARM9/src/main.c @@ -0,0 +1,68 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-11-27#$ + $Rev: 272 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc_simple.h" +#include "ExecPreLoadedApp.h" + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +static void INTR_VBlank( void ); + +// global variable------------------------------------------------------------- + +// static variable------------------------------------------------------------- +BOOL g_isValidTSD; + +// const data------------------------------------------------------------------ + + +// ============================================================================ +// function's description +// ============================================================================ +void TwlMain(void) +{ + myInit(); + + ExecPreLoadedAppInit(); + // C[v---------------------------- + while(1){ + + myPreMain(); + + ExecPreLoadedAppMain(); + + myProMain(); + + OS_WaitIrq(1, OS_IE_V_BLANK); // VuN荞ݑ҂ + } +} + + +// ============================================================================ +// 荞ݏ +// ============================================================================ + +// VuN荞 +static void INTR_VBlank(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // VuN`FbÑZbg +} + diff --git a/build/tests/ExecPreLoadedApp/Makefile b/build/tests/ExecPreLoadedApp/Makefile new file mode 100644 index 00000000..adb8fdbb --- /dev/null +++ b/build/tests/ExecPreLoadedApp/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM7 ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tests/ExecPreLoadedApp/banner/Makefile b/build/tests/ExecPreLoadedApp/banner/Makefile new file mode 100644 index 00000000..aafe44c2 --- /dev/null +++ b/build/tests/ExecPreLoadedApp/banner/Makefile @@ -0,0 +1,50 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +MAKEBANNER = $(TWL_TOOLSDIR)/bin/makebanner.TWL.exe + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/tests/ExecPreLoadedApp/banner/banner_v3.bsf b/build/tests/ExecPreLoadedApp/banner/banner_v3.bsf new file mode 100644 index 00000000..05e7140d Binary files /dev/null and b/build/tests/ExecPreLoadedApp/banner/banner_v3.bsf differ diff --git a/build/tests/ExecPreLoadedApp/banner/icon/gameIcon.bmp b/build/tests/ExecPreLoadedApp/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..a8b22308 Binary files /dev/null and b/build/tests/ExecPreLoadedApp/banner/icon/gameIcon.bmp differ diff --git a/build/tests/ExecTmpApp/ARM9/Makefile b/build/tests/ExecTmpApp/ARM9/Makefile new file mode 100644 index 00000000..4f7b427d --- /dev/null +++ b/build/tests/ExecTmpApp/ARM9/Makefile @@ -0,0 +1,62 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos.TWL - nandApp - ExecTmpApp +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- + +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +TITLEID_LO = ETFA + +TARGET_BIN = ExecTmpApp.tad + +ROM_SPEC = main.rsf + +MISC_DIR = ../../misc +DATA_DIR = ../../data + +SRCS = main.c ExecTmpApp.c \ + $(MISC_DIR)/misc_simple.c \ + $(DATA_DIR)/data.c + +LINCLUDES = $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/include \ + $(MISC_DIR) \ + $(DATA_DIR) + +LLIBRARY_DIRS += $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/lib/$(TWL_BUILDTYPE) + +LLIBRARIES += libDEMO$(TWL_LIBSUFFIX).a + +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +SDK_NMENU_DATADIR = $(ROOT)/build/tools/TwlNMenu/data +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/ExecTmpApp/ARM9/main.rsf b/build/tests/ExecTmpApp/ARM9/main.rsf new file mode 100644 index 00000000..bb1048fc --- /dev/null +++ b/build/tests/ExecTmpApp/ARM9/main.rsf @@ -0,0 +1,178 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-12-19#$ +# $Rev: 378 $ +# $Author: yoshida_teruhisa $ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + #BannerFile ./etc/myGameBanner.bnr + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType User + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + #SaveBannerFile TRUE +} + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot ../../data + Root /data + File simpleapp.srl +} \ No newline at end of file diff --git a/build/tests/ExecTmpApp/ARM9/src/ExecTmpApp.c b/build/tests/ExecTmpApp/ARM9/src/ExecTmpApp.c new file mode 100644 index 00000000..c51ac8c1 --- /dev/null +++ b/build/tests/ExecTmpApp/ARM9/src/ExecTmpApp.c @@ -0,0 +1,173 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: ExecTmpApp.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:: 2007-10-31#$ + $Rev: 91 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc_simple.h" +#include "ExecTmpApp.h" + +// define data------------------------------------------ + +#define COPB_MENU_ELEMENT_NUM 2 // j[̍ڐ + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- + +static void MenuScene( void ); + +// global variable ------------------------------------- + +// static variable ------------------------------------- +static u16 s_csr = 0; +static void(*s_pNowProcess)(void); + +// const data ----------------------------------------- +static const char *s_pStrMenu[ COPB_MENU_ELEMENT_NUM ] = +{ + "save app to tmp and restart", + "return to launcher", +}; + +static MenuPos s_menuPos[] = { + { TRUE, 3, 6 }, + { TRUE, 3, 8 }, +}; + +static const MenuParam s_menuParam = { + COPB_MENU_ELEMENT_NUM, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_menuPos[ 0 ], + (const char **)&s_pStrMenu, +}; + +//====================================================== +// AvAgeXgvOB +//====================================================== + +static void DrawMenuScene( void ) +{ + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "ExecTmpApp"); + // j[ + myDp_DrawMenu( s_csr, MAIN_SCREEN, &s_menuParam ); +} + +static void MenuInit( void ) +{ + FS_Init(3); + GX_DispOff(); + GXS_DispOff(); + + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "ExecTmpApp"); + + s_pNowProcess = MenuScene; + + DrawMenuScene(); + + GX_DispOn(); + GXS_DispOn(); +} + +static void MenuScene(void) +{ + LauncherBootFlags tempflag = {TRUE, LAUNCHER_BOOTTYPE_TEMP, TRUE, FALSE, FALSE, FALSE, 0}; + + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( MYPAD_IS_TRIG(PAD_KEY_DOWN) ){ // J[\̈ړ + if( ++s_csr == COPB_MENU_ELEMENT_NUM ) { + s_csr=0; + } + } + if( MYPAD_IS_TRIG(PAD_KEY_UP) ){ + if( --s_csr & 0x80 ) { + s_csr=COPB_MENU_ELEMENT_NUM - 1; + } + } + + DrawMenuScene(); + + if( MYPAD_IS_TRIG(PAD_BUTTON_A) ) { // j[ڂւ̕ + if( s_menuPos[ s_csr ].enable ) { + u64 targetApp = 0x00030004534d504c;// SMPL + static char destfilename[256]; + s32 len = 0; + s32 llen; + BOOL success = TRUE; + FSFile src,dest; + void *buf; + switch( s_csr ) { + case 0: + + STD_TSNPrintf( destfilename, 31, "nand:/tmp/%.16llx.srl", targetApp ); + // tmpɕۑ + FS_DeleteFile(destfilename); + FS_CreateFile(destfilename, FS_PERMIT_R | FS_PERMIT_W); + FS_InitFile( &src ); + FS_InitFile( &dest ); + if ( !FS_OpenFileEx( &src, "rom:/data/simpleapp.srl", FS_FILEMODE_R ) ) success = FALSE; + len = (int)FS_GetFileLength( &src ); + + buf = (void *)0x2400000; + for(llen = 0; llen < len; ) + { + int rd; + rd = FS_ReadFile( &src, buf, len ); + if(rd == -1) + { + success = FALSE; + break; + } + buf = (void *)((u32)buf + rd); + llen += rd; + } + buf = (void *)0x2400000; + if ( !FS_CloseFile( &src ) ) success = FALSE; + if (len != llen) success = FALSE; + + if ( !FS_OpenFileEx( &dest, destfilename, FS_FILEMODE_W ) ) success = FALSE; + llen = FS_WriteFile( &dest, buf, len ); + if ( !FS_CloseFile( &dest ) ) success = FALSE; + if (len != llen) success = FALSE; + + if( !success ) break; + + //AvN + OS_SetLauncherParamAndResetHardware( 0, targetApp, &tempflag ); + break; + case 1: + OS_SetLauncherParamAndResetHardware( 0, NULL, &tempflag ); + //ċN + break; + } + } + } +} + +// +void ExecTmpAppInit( void ) +{ + MenuInit(); +} + +// C[v +void ExecTmpAppMain(void) +{ + s_pNowProcess(); +} diff --git a/build/tests/ExecTmpApp/ARM9/src/ExecTmpApp.h b/build/tests/ExecTmpApp/ARM9/src/ExecTmpApp.h new file mode 100644 index 00000000..b4ee250a --- /dev/null +++ b/build/tests/ExecTmpApp/ARM9/src/ExecTmpApp.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: ExecTmpApp.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-10-30#$ + $Rev: 73 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#ifndef __COOPERATION_B_H__ +#define __COOPERATION_B_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +// define data---------------------------------------------------------- + +void ExecTmpAppInit( void ); +void ExecTmpAppMain( void ); + +#ifdef __cplusplus +} +#endif + +#endif // __COOPERATION_B_H__ diff --git a/build/tests/ExecTmpApp/ARM9/src/main.c b/build/tests/ExecTmpApp/ARM9/src/main.c new file mode 100644 index 00000000..ab390290 --- /dev/null +++ b/build/tests/ExecTmpApp/ARM9/src/main.c @@ -0,0 +1,68 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-11-27#$ + $Rev: 272 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc_simple.h" +#include "ExecTmpApp.h" + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +static void INTR_VBlank( void ); + +// global variable------------------------------------------------------------- + +// static variable------------------------------------------------------------- +BOOL g_isValidTSD; + +// const data------------------------------------------------------------------ + + +// ============================================================================ +// function's description +// ============================================================================ +void TwlMain(void) +{ + myInit(); + + ExecTmpAppInit(); + // C[v---------------------------- + while(1){ + + myPreMain(); + + ExecTmpAppMain(); + + myProMain(); + + OS_WaitIrq(1, OS_IE_V_BLANK); // VuN荞ݑ҂ + } +} + + +// ============================================================================ +// 荞ݏ +// ============================================================================ + +// VuN荞 +static void INTR_VBlank(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // VuN`FbÑZbg +} + diff --git a/build/tests/ExecTmpApp/Makefile b/build/tests/ExecTmpApp/Makefile new file mode 100644 index 00000000..9cf34e12 --- /dev/null +++ b/build/tests/ExecTmpApp/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tests/ExecTmpApp/banner/Makefile b/build/tests/ExecTmpApp/banner/Makefile new file mode 100644 index 00000000..aafe44c2 --- /dev/null +++ b/build/tests/ExecTmpApp/banner/Makefile @@ -0,0 +1,50 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +MAKEBANNER = $(TWL_TOOLSDIR)/bin/makebanner.TWL.exe + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/tests/ExecTmpApp/banner/banner_v3.bsf b/build/tests/ExecTmpApp/banner/banner_v3.bsf new file mode 100644 index 00000000..d364b2af Binary files /dev/null and b/build/tests/ExecTmpApp/banner/banner_v3.bsf differ diff --git a/build/tests/ExecTmpApp/banner/icon/gameIcon.bmp b/build/tests/ExecTmpApp/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..588fc8cd Binary files /dev/null and b/build/tests/ExecTmpApp/banner/icon/gameIcon.bmp differ diff --git a/build/tests/Makefile b/build/tests/Makefile new file mode 100644 index 00000000..a0b32420 --- /dev/null +++ b/build/tests/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = SimpleApp AppliCooperation ExecPreLoadedApp ExecTmpApp RelocateChecker + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM7/Makefile b/build/tests/RelocateChecker/ARM7/Makefile new file mode 100644 index 00000000..12c1cc68 --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/Makefile @@ -0,0 +1,32 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = Makefile.0 Makefile.1 Makefile.2 Makefile.3 Makefile.4 Makefile.5 + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM7/Makefile.0 b/build/tests/RelocateChecker/ARM7/Makefile.0 new file mode 100644 index 00000000..b0f5e4bc --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/Makefile.0 @@ -0,0 +1,80 @@ +#! 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-09#$ +# $Rev: 1499 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +override TARGET_PLATFORM = TWL +override TWL_PROC = ARM7 +override TWL_ARCHGEN = LIMITED +TWL_NO_STD_PCHDR = True +TWL_CODEGEN ?= ARM + +#---------------------------------------------------------------------------- + +SRCS = main.c + +TARGET_NAME = hyena_rc0 +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) + +TARGET_NEF = $(TARGET_NAME).tef +LCFILE_SPEC = hyena_rc.lsf +LCFILE_TEMPLATE = $(TARGET_NAME).lcf.template +LDRES_TEMPLATE = $(ROOT)/build/components/racoon.TWL/racoon.response.template + +LLIBRARY_DIRS += ../crt/ARM7/obj/ARM7-TS.LTD/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.LTD.TWL.o + +TARGET_FOB += ARM7FLX.fob +FBDSIZE_ARM7FLX = 4 +TARGET_FOB += ARM7LTD.fob +FBDSIZE_ARM7LTD = 4 + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs +include $(TWLSDK_ROOT)/build/libraries/reboot/commondefs.reboot + +ifdef TWLSDK_NOCRYPTO +CCFLAGS += -DSDK_NOCRYPTO +endif + +ifndef TWLSDK_NOCRYPTO +MAKELCF_FLAGS += -DUSE_CRYPTO_LIBS='libaes_sp$(TWL_LIBSUFFIX).a' +endif + +#MACRO_FLAGS += -DSDK_ARM7COMP_LTD + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' \ + -DADDRESS_FLXMAIN='0x02380000' \ + -DADDRESS_BOOTCORE='0x0380f000' \ + -DCRT0_O='$(CRT0_O)' + +MAKELCF_FLAGS += -DISDBG_LIBS_TWL='$(if $(ISDBG_LIBS_TWL),$(ISDBG_LIBS_TWL),libstubsistd_sp$(TWL_LIBSUFFIX).a)' \ + -DISDBG_LIBS_NITRO='libstubsisd_sp$(TWL_LIBSUFFIX).a' + + +LINCLUDES = $(ROOT)/build/libraries/spi/ARM7/include +LLIBRARIES += libwl_sp.TWL.LTD.a +LDEPENDS_NEF = $(TWL_LIBS) $(LLIBRARIES) + +do-build: $(TARGETS) + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules +#include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM7/Makefile.1 b/build/tests/RelocateChecker/ARM7/Makefile.1 new file mode 100644 index 00000000..44601e99 --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/Makefile.1 @@ -0,0 +1,80 @@ +#! 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-09#$ +# $Rev: 1499 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +override TARGET_PLATFORM = TWL +override TWL_PROC = ARM7 +override TWL_ARCHGEN = LIMITED +TWL_NO_STD_PCHDR = True +TWL_CODEGEN ?= ARM + +#---------------------------------------------------------------------------- + +SRCS = main.c + +TARGET_NAME = hyena_rc1 +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) + +TARGET_NEF = $(TARGET_NAME).tef +LCFILE_SPEC = hyena_rc.lsf +LCFILE_TEMPLATE = $(TARGET_NAME).lcf.template +LDRES_TEMPLATE = $(ROOT)/build/components/racoon.TWL/racoon.response.template + +LLIBRARY_DIRS += ../crt/ARM7/obj/ARM7-TS.LTD/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.LTD.TWL.o + +TARGET_FOB += ARM7FLX.fob +FBDSIZE_ARM7FLX = 50000 +TARGET_FOB += ARM7LTD.fob +FBDSIZE_ARM7LTD = 540672 + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs +include $(TWLSDK_ROOT)/build/libraries/reboot/commondefs.reboot + +ifdef TWLSDK_NOCRYPTO +CCFLAGS += -DSDK_NOCRYPTO +endif + +ifndef TWLSDK_NOCRYPTO +MAKELCF_FLAGS += -DUSE_CRYPTO_LIBS='libaes_sp$(TWL_LIBSUFFIX).a' +endif + +#MACRO_FLAGS += -DSDK_ARM7COMP_LTD + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' \ + -DADDRESS_FLXMAIN='0x023a0000' \ + -DADDRESS_BOOTCORE='0x0380f000' \ + -DCRT0_O='$(CRT0_O)' + +MAKELCF_FLAGS += -DISDBG_LIBS_TWL='$(if $(ISDBG_LIBS_TWL),$(ISDBG_LIBS_TWL),libstubsistd_sp$(TWL_LIBSUFFIX).a)' \ + -DISDBG_LIBS_NITRO='libstubsisd_sp$(TWL_LIBSUFFIX).a' + + +LINCLUDES = $(ROOT)/build/libraries/spi/ARM7/include +LLIBRARIES += libwl_sp.TWL.LTD.a +LDEPENDS_NEF = $(TWL_LIBS) $(LLIBRARIES) + +do-build: $(TARGETS) + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules +#include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM7/Makefile.2 b/build/tests/RelocateChecker/ARM7/Makefile.2 new file mode 100644 index 00000000..6345e64b --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/Makefile.2 @@ -0,0 +1,80 @@ +#! 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-09#$ +# $Rev: 1499 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +override TARGET_PLATFORM = TWL +override TWL_PROC = ARM7 +override TWL_ARCHGEN = LIMITED +TWL_NO_STD_PCHDR = True +TWL_CODEGEN ?= ARM + +#---------------------------------------------------------------------------- + +SRCS = main.c + +TARGET_NAME = hyena_rc2 +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) + +TARGET_NEF = $(TARGET_NAME).tef +LCFILE_SPEC = hyena_rc.lsf +LCFILE_TEMPLATE = $(TARGET_NAME).lcf.template +LDRES_TEMPLATE = $(ROOT)/build/components/racoon.TWL/racoon.response.template + +LLIBRARY_DIRS += ../crt/ARM7/obj/ARM7-TS.LTD/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.LTD.TWL.o + +TARGET_FOB += ARM7FLX.fob +FBDSIZE_ARM7FLX = 4 +TARGET_FOB += ARM7LTD.fob +FBDSIZE_ARM7LTD = 4 + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs +include $(TWLSDK_ROOT)/build/libraries/reboot/commondefs.reboot + +ifdef TWLSDK_NOCRYPTO +CCFLAGS += -DSDK_NOCRYPTO +endif + +ifndef TWLSDK_NOCRYPTO +MAKELCF_FLAGS += -DUSE_CRYPTO_LIBS='libaes_sp$(TWL_LIBSUFFIX).a' +endif + +#MACRO_FLAGS += -DSDK_ARM7COMP_LTD + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' \ + -DADDRESS_FLXMAIN='0x0237fffc' \ + -DADDRESS_BOOTCORE='0x0380f000' \ + -DCRT0_O='$(CRT0_O)' + +MAKELCF_FLAGS += -DISDBG_LIBS_TWL='$(if $(ISDBG_LIBS_TWL),$(ISDBG_LIBS_TWL),libstubsistd_sp$(TWL_LIBSUFFIX).a)' \ + -DISDBG_LIBS_NITRO='libstubsisd_sp$(TWL_LIBSUFFIX).a' + + +LINCLUDES = $(ROOT)/build/libraries/spi/ARM7/include +LLIBRARIES += libwl_sp.TWL.LTD.a +LDEPENDS_NEF = $(TWL_LIBS) $(LLIBRARIES) + +do-build: $(TARGETS) + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules +#include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM7/Makefile.3 b/build/tests/RelocateChecker/ARM7/Makefile.3 new file mode 100644 index 00000000..47afc980 --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/Makefile.3 @@ -0,0 +1,80 @@ +#! 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-09#$ +# $Rev: 1499 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +override TARGET_PLATFORM = TWL +override TWL_PROC = ARM7 +override TWL_ARCHGEN = LIMITED +TWL_NO_STD_PCHDR = True +TWL_CODEGEN ?= ARM + +#---------------------------------------------------------------------------- + +SRCS = main.c + +TARGET_NAME = hyena_rc3 +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) + +TARGET_NEF = $(TARGET_NAME).tef +LCFILE_SPEC = hyena_rc.lsf +LCFILE_TEMPLATE = $(TARGET_NAME).lcf.template +LDRES_TEMPLATE = $(ROOT)/build/components/racoon.TWL/racoon.response.template + +LLIBRARY_DIRS += ../crt/ARM7/obj/ARM7-TS.LTD/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.LTD.TWL.o + +TARGET_FOB += ARM7FLX.fob +FBDSIZE_ARM7FLX = 4 +TARGET_FOB += ARM7LTD.fob +FBDSIZE_ARM7LTD = 4 + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs +include $(TWLSDK_ROOT)/build/libraries/reboot/commondefs.reboot + +ifdef TWLSDK_NOCRYPTO +CCFLAGS += -DSDK_NOCRYPTO +endif + +ifndef TWLSDK_NOCRYPTO +MAKELCF_FLAGS += -DUSE_CRYPTO_LIBS='libaes_sp$(TWL_LIBSUFFIX).a' +endif + +#MACRO_FLAGS += -DSDK_ARM7COMP_LTD + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' \ + -DADDRESS_FLXMAIN='0x023c0000' \ + -DADDRESS_BOOTCORE='0x0380f000' \ + -DCRT0_O='$(CRT0_O)' + +MAKELCF_FLAGS += -DISDBG_LIBS_TWL='$(if $(ISDBG_LIBS_TWL),$(ISDBG_LIBS_TWL),libstubsistd_sp$(TWL_LIBSUFFIX).a)' \ + -DISDBG_LIBS_NITRO='libstubsisd_sp$(TWL_LIBSUFFIX).a' + + +LINCLUDES = $(ROOT)/build/libraries/spi/ARM7/include +LLIBRARIES += libwl_sp.TWL.LTD.a +LDEPENDS_NEF = $(TWL_LIBS) $(LLIBRARIES) + +do-build: $(TARGETS) + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules +#include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM7/Makefile.4 b/build/tests/RelocateChecker/ARM7/Makefile.4 new file mode 100644 index 00000000..2463d32c --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/Makefile.4 @@ -0,0 +1,80 @@ +#! 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-09#$ +# $Rev: 1499 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +override TARGET_PLATFORM = TWL +override TWL_PROC = ARM7 +override TWL_ARCHGEN = LIMITED +TWL_NO_STD_PCHDR = True +TWL_CODEGEN ?= ARM + +#---------------------------------------------------------------------------- + +SRCS = main.c + +TARGET_NAME = hyena_rc4 +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) + +TARGET_NEF = $(TARGET_NAME).tef +LCFILE_SPEC = hyena_rc.lsf +LCFILE_TEMPLATE = $(TARGET_NAME).lcf.template +LDRES_TEMPLATE = $(ROOT)/build/components/racoon.TWL/racoon.response.template + +LLIBRARY_DIRS += ../crt/ARM7/obj/ARM7-TS.LTD/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.LTD.TWL.o + +TARGET_FOB += ARM7FLX.fob +FBDSIZE_ARM7FLX = 4 +TARGET_FOB += ARM7LTD.fob +FBDSIZE_ARM7LTD = 4 + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs +include $(TWLSDK_ROOT)/build/libraries/reboot/commondefs.reboot + +ifdef TWLSDK_NOCRYPTO +CCFLAGS += -DSDK_NOCRYPTO +endif + +ifndef TWLSDK_NOCRYPTO +MAKELCF_FLAGS += -DUSE_CRYPTO_LIBS='libaes_sp$(TWL_LIBSUFFIX).a' +endif + +#MACRO_FLAGS += -DSDK_ARM7COMP_LTD + +MAKELCF_FLAGS += -DADDRESS_LTDWRAM='0x037c0000' \ + -DADDRESS_FLXMAIN='0x02000400' \ + -DADDRESS_BOOTCORE='0x0380f000' \ + -DCRT0_O='$(CRT0_O)' + +MAKELCF_FLAGS += -DISDBG_LIBS_TWL='$(if $(ISDBG_LIBS_TWL),$(ISDBG_LIBS_TWL),libstubsistd_sp$(TWL_LIBSUFFIX).a)' \ + -DISDBG_LIBS_NITRO='libstubsisd_sp$(TWL_LIBSUFFIX).a' + + +LINCLUDES = $(ROOT)/build/libraries/spi/ARM7/include +LLIBRARIES += libwl_sp.TWL.LTD.a +LDEPENDS_NEF = $(TWL_LIBS) $(LLIBRARIES) + +do-build: $(TARGETS) + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules +#include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM7/Makefile.5 b/build/tests/RelocateChecker/ARM7/Makefile.5 new file mode 100644 index 00000000..cc517688 --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/Makefile.5 @@ -0,0 +1,79 @@ +#! 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-09#$ +# $Rev: 1499 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +override TARGET_PLATFORM = TWL +override TWL_PROC = ARM7 +override TWL_ARCHGEN = LIMITED +TWL_NO_STD_PCHDR = True +TWL_CODEGEN ?= ARM + +#---------------------------------------------------------------------------- + +SRCS = main.c + +TARGET_NAME = hyena_rc5 +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) + +TARGET_NEF = $(TARGET_NAME).tef +LCFILE_SPEC = hyena_rc5.lsf +LCFILE_TEMPLATE = $(TARGET_NAME).lcf.template +LDRES_TEMPLATE = $(ROOT)/build/components/racoon.TWL/racoon.response.template + +LLIBRARY_DIRS += ../crt/ARM7/obj/ARM7-TS.LTD/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.LTD.TWL.o + +TARGET_FOB += ARM7FLX.fob +FBDSIZE_ARM7FLX = 4 +TARGET_FOB += ARM7LTD.fob +FBDSIZE_ARM7LTD = 4 + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs +include $(TWLSDK_ROOT)/build/libraries/reboot/commondefs.reboot + +ifdef TWLSDK_NOCRYPTO +CCFLAGS += -DSDK_NOCRYPTO +endif + +ifndef TWLSDK_NOCRYPTO +MAKELCF_FLAGS += -DUSE_CRYPTO_LIBS='libaes_sp$(TWL_LIBSUFFIX).a' +endif + +#MACRO_FLAGS += -DSDK_ARM7COMP_LTD + +MAKELCF_FLAGS += -DADDRESS_FLXMAIN='0x037c0000' \ + -DADDRESS_BOOTCORE='0x0380f000' \ + -DCRT0_O='$(CRT0_O)' + +MAKELCF_FLAGS += -DISDBG_LIBS_TWL='$(if $(ISDBG_LIBS_TWL),$(ISDBG_LIBS_TWL),libstubsistd_sp$(TWL_LIBSUFFIX).a)' \ + -DISDBG_LIBS_NITRO='libstubsisd_sp$(TWL_LIBSUFFIX).a' + + +LINCLUDES = $(ROOT)/build/libraries/spi/ARM7/include +LLIBRARIES += libwl_sp.TWL.LTD.a +LDEPENDS_NEF = $(TWL_LIBS) $(LLIBRARIES) + +do-build: $(TARGETS) + +#---------------------------------------------------------------------------- +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules +#include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM7/hyena_rc.lsf b/build/tests/RelocateChecker/ARM7/hyena_rc.lsf new file mode 100644 index 00000000..ec5f7691 --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/hyena_rc.lsf @@ -0,0 +1,150 @@ +#---------------------------------------------------------------------------- +# Project: TwlIPL +# File: hyena.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-11-26#$ +# $Rev: 258 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- +# +# Nitro LCF SPEC FILE +# +#-------- +Static $(TARGET_NAME) +{ + Address $(ADDRESS_FLXMAIN) + Object ../flabObj/ARM7FLX.fob + Library $(CRT0_O) \ + libmi_sp$(LIBSUFFIX).a \ + libsyscall_sp.twl.a + StackSize 1024 1024 +} + +#-------- +Autoload WRAM +{ + Address $(ADDRESS_LTDWRAM) + + Library libsubpsyscall.a \ + $(CW_LIBS) \ + libos_sp$(LIBSUFFIX).a \ + libpad_sp$(LIBSUFFIX).a \ + libpxi_sp$(LIBSUFFIX).a \ + libstd_sp$(LIBSUFFIX).a \ + libexi_sp$(LIBSUFFIX).a \ + libsnd_sp$(LIBSUFFIX).a \ + libspi_sp$(LIBSUFFIX).a \ + libpm_sp$(LIBSUFFIX).a \ + libmath_sp$(LIBSUFFIX).a \ + libscfg_sp$(LIBSUFFIX).a \ + libtp_sp$(LIBSUFFIX).a \ + libmic_sp$(LIBSUFFIX).a \ + libfs_sp$(LIBSUFFIX).a \ + libcard_sp$(LIBSUFFIX).a \ + libi2c_sp$(LIBSUFFIX).a \ + libcamera_sp$(LIBSUFFIX).a \ + libcdc_sp$(LIBSUFFIX).a \ + libsndex_sp$(LIBSUFFIX).a \ + libtpex_sp$(LIBSUFFIX).a \ + libmicex_sp$(LIBSUFFIX).a \ + libmcu_sp$(LIBSUFFIX).a \ + libboot_sp$(LIBSUFFIX).a \ + libreboot_sp$(LIBSUFFIX).a \ + libhotsw_sp$(LIBSUFFIX).a \ + + Library libsdio_sp$(LIBSUFFIX).a + + Object * (.etable) + Object * (.wram) + Object * (.ltdwram) + Object $(OBJDIR)/main.o + + ##### + # Sub-routines in WL library , that should be on WRAM. + # in TaskMan.o + Object OBJECT( MainTaskRoutine , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AddTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( DeleteTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( LowestIdleTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ExecuteMessage , libwl_sp$(LIBSUFFIX).a ) (.text) + # in BufMan.o + Object OBJECT( NewHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( DeleteHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AllocateHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ReleaseHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( MoveHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AddHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( GetHeapBufNextAdrs , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlCmdIf.o + Object OBJECT( RequestCmdTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SendMessageToWmDirect , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlNic.o + Object OBJECT( WStart , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WStop , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WSetStaState , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlIntr.o + Object OBJECT( WlIntr , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrPreTbtt , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTbtt , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrActEnd , libwl_sp$(LIBSUFFIX).a ) (.text) +# Object OBJECT( WlIntrAckCntOvf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrCntOvf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxErr , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxCntup , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrMpEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrStartTx , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrStartRx , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SetParentTbttTxq , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( MacBugTxMp , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AdjustRingPointer , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( CheckKeyTxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlIntrTask.o + Object OBJECT( WlIntrTxBeaconTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrMpEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SetParentTbttTxqTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( TakeoutRxFrame , libwl_sp$(LIBSUFFIX).a ) (.text) + # in TxCtrl.o + Object OBJECT( InitTxCtrl , libwl_sp$(LIBSUFFIX).a ) (.text) + # in RxCtrl.o + Object OBJECT( InitRxCtrl , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WaitLoop.o + Object OBJECT( WaitLoop_Rxpe , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_Waitus , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_ClrAid , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_BbpAccess , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_RfAccess , libwl_sp$(LIBSUFFIX).a ) (.text) + +} + +#-------- +Ltdautoload LTDMAIN +{ +# After $(TARGET_NAME) + Address 0x02d00000 + + Object * (.ltdmain) + Object ../flabObj/ARM7LTD.fob + Library libnvram_sp$(LIBSUFFIX).a + Library librtc_sp$(LIBSUFFIX).a + Library libwm_sp$(LIBSUFFIX).a \ + libnwm_sp$(LIBSUFFIX).a \ + libwvr_sp$(LIBSUFFIX).a \ + libwl_sp$(LIBSUFFIX).a \ + + Library libfatfs_sp$(LIBSUFFIX).a \ + $(USE_CRYPTO_LIBS) + Library $(ISDBG_LIBS_TWL) + Library $(ISDBG_LIBS_NITRO) +} diff --git a/build/tests/RelocateChecker/ARM7/hyena_rc0.lcf.template b/build/tests/RelocateChecker/ARM7/hyena_rc0.lcf.template new file mode 100644 index 00000000..cc365bde --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/hyena_rc0.lcf.template @@ -0,0 +1,915 @@ +#--------------------------------------------------------------------------- +# Project: TwlIPL +# File: hyena.lcf.template +# +# 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-11-16#$ +# $Rev: 192 $ +# $Author: yosiokat $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.WORKRAM (RWX) : ORIGIN = 0x037c0000, LENGTH = 0x50000 > workram.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDMAIN (RWX) : ORIGIN = 0x02d00000, LENGTH = 0x01080000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.WRAM.START = 0x037c0000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = . + SDK_AUTOLOAD.WRAM.BSS_END - SDK_AUTOLOAD.WRAM.START + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02e80000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + .check.LTDMAIN: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.LTDMAIN + +} diff --git a/build/tests/RelocateChecker/ARM7/hyena_rc1.lcf.template b/build/tests/RelocateChecker/ARM7/hyena_rc1.lcf.template new file mode 100644 index 00000000..26466c4f --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/hyena_rc1.lcf.template @@ -0,0 +1,915 @@ +#--------------------------------------------------------------------------- +# Project: TwlIPL +# File: hyena.lcf.template +# +# 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-11-16#$ +# $Rev: 192 $ +# $Author: yosiokat $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.WORKRAM (RWX) : ORIGIN = 0x037c0000, LENGTH = 0x50000 > workram.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDMAIN (RWX) : ORIGIN = 0x02d00000, LENGTH = 0x01080000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.WRAM.START = 0x037c0000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = . + SDK_AUTOLOAD.WRAM.BSS_END - SDK_AUTOLOAD.WRAM.START + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02f04000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + .check.LTDMAIN: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.LTDMAIN + +} diff --git a/build/tests/RelocateChecker/ARM7/hyena_rc2.lcf.template b/build/tests/RelocateChecker/ARM7/hyena_rc2.lcf.template new file mode 100644 index 00000000..029d2df8 --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/hyena_rc2.lcf.template @@ -0,0 +1,915 @@ +#--------------------------------------------------------------------------- +# Project: TwlIPL +# File: hyena.lcf.template +# +# 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-11-16#$ +# $Rev: 192 $ +# $Author: yosiokat $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.WORKRAM (RWX) : ORIGIN = 0x037c0000, LENGTH = 0x50000 > workram.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDMAIN (RWX) : ORIGIN = 0x02d00000, LENGTH = 0x01080000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.WRAM.START = 0x037c0000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = . + SDK_AUTOLOAD.WRAM.BSS_END - SDK_AUTOLOAD.WRAM.START + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02e7fffc; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + .check.LTDMAIN: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.LTDMAIN + +} diff --git a/build/tests/RelocateChecker/ARM7/hyena_rc3.lcf.template b/build/tests/RelocateChecker/ARM7/hyena_rc3.lcf.template new file mode 100644 index 00000000..3e4d5fab --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/hyena_rc3.lcf.template @@ -0,0 +1,915 @@ +#--------------------------------------------------------------------------- +# Project: TwlIPL +# File: hyena.lcf.template +# +# 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-11-16#$ +# $Rev: 192 $ +# $Author: yosiokat $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.WORKRAM (RWX) : ORIGIN = 0x037c0000, LENGTH = 0x50000 > workram.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDMAIN (RWX) : ORIGIN = 0x02d00000, LENGTH = 0x01080000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.WRAM.START = 0x037c0000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = . + SDK_AUTOLOAD.WRAM.BSS_END - SDK_AUTOLOAD.WRAM.START + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02280000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + .check.LTDMAIN: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.LTDMAIN + +} diff --git a/build/tests/RelocateChecker/ARM7/hyena_rc4.lcf.template b/build/tests/RelocateChecker/ARM7/hyena_rc4.lcf.template new file mode 100644 index 00000000..cc365bde --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/hyena_rc4.lcf.template @@ -0,0 +1,915 @@ +#--------------------------------------------------------------------------- +# Project: TwlIPL +# File: hyena.lcf.template +# +# 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-11-16#$ +# $Rev: 192 $ +# $Author: yosiokat $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.WORKRAM (RWX) : ORIGIN = 0x037c0000, LENGTH = 0x50000 > workram.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDMAIN (RWX) : ORIGIN = 0x02d00000, LENGTH = 0x01080000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.WRAM.START = 0x037c0000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = . + SDK_AUTOLOAD.WRAM.BSS_END - SDK_AUTOLOAD.WRAM.START + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02e80000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + .check.LTDMAIN: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.LTDMAIN + +} diff --git a/build/tests/RelocateChecker/ARM7/hyena_rc5.lcf.template b/build/tests/RelocateChecker/ARM7/hyena_rc5.lcf.template new file mode 100644 index 00000000..3e4d5fab --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/hyena_rc5.lcf.template @@ -0,0 +1,915 @@ +#--------------------------------------------------------------------------- +# Project: TwlIPL +# File: hyena.lcf.template +# +# 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-11-16#$ +# $Rev: 192 $ +# $Author: yosiokat $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.WORKRAM (RWX) : ORIGIN = 0x037c0000, LENGTH = 0x50000 > workram.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDMAIN (RWX) : ORIGIN = 0x02d00000, LENGTH = 0x01080000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.WRAM.START = 0x037c0000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = . + SDK_AUTOLOAD.WRAM.BSS_END - SDK_AUTOLOAD.WRAM.START + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02280000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + .check.LTDMAIN: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.LTDMAIN + +} diff --git a/build/tests/RelocateChecker/ARM7/hyena_rc5.lsf b/build/tests/RelocateChecker/ARM7/hyena_rc5.lsf new file mode 100644 index 00000000..0eef1579 --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/hyena_rc5.lsf @@ -0,0 +1,150 @@ +#---------------------------------------------------------------------------- +# Project: TwlIPL +# File: hyena.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-11-26#$ +# $Rev: 258 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- +# +# Nitro LCF SPEC FILE +# +#-------- +Static $(TARGET_NAME) +{ + Address $(ADDRESS_FLXMAIN) + Object ../flabObj/ARM7FLX.fob + Library $(CRT0_O) \ + libmi_sp$(LIBSUFFIX).a \ + libsyscall_sp.twl.a + + Library libsubpsyscall.a \ + $(CW_LIBS) \ + libos_sp$(LIBSUFFIX).a \ + libpad_sp$(LIBSUFFIX).a \ + libpxi_sp$(LIBSUFFIX).a \ + libstd_sp$(LIBSUFFIX).a \ + libexi_sp$(LIBSUFFIX).a \ + libsnd_sp$(LIBSUFFIX).a \ + libspi_sp$(LIBSUFFIX).a \ + libpm_sp$(LIBSUFFIX).a \ + libmath_sp$(LIBSUFFIX).a \ + libscfg_sp$(LIBSUFFIX).a \ + libtp_sp$(LIBSUFFIX).a \ + libmic_sp$(LIBSUFFIX).a \ + libfs_sp$(LIBSUFFIX).a \ + libcard_sp$(LIBSUFFIX).a \ + libi2c_sp$(LIBSUFFIX).a \ + libcamera_sp$(LIBSUFFIX).a \ + libcdc_sp$(LIBSUFFIX).a \ + libsndex_sp$(LIBSUFFIX).a \ + libtpex_sp$(LIBSUFFIX).a \ + libmicex_sp$(LIBSUFFIX).a \ + libmcu_sp$(LIBSUFFIX).a \ + libboot_sp$(LIBSUFFIX).a \ + libreboot_sp$(LIBSUFFIX).a \ + libhotsw_sp$(LIBSUFFIX).a \ + + Library libsdio_sp$(LIBSUFFIX).a + + ##### + # Sub-routines in WL library , that should be on WRAM. + # in TaskMan.o + Object OBJECT( MainTaskRoutine , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AddTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( DeleteTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( LowestIdleTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ExecuteMessage , libwl_sp$(LIBSUFFIX).a ) (.text) + # in BufMan.o + Object OBJECT( NewHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( DeleteHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AllocateHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( ReleaseHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( MoveHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AddHeapBuf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( GetHeapBufNextAdrs , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlCmdIf.o + Object OBJECT( RequestCmdTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SendMessageToWmDirect , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlNic.o + Object OBJECT( WStart , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WStop , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WSetStaState , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlIntr.o + Object OBJECT( WlIntr , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrPreTbtt , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTbtt , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrActEnd , libwl_sp$(LIBSUFFIX).a ) (.text) +# Object OBJECT( WlIntrAckCntOvf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrCntOvf , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxErr , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxCntup , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrMpEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrStartTx , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrStartRx , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SetParentTbttTxq , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( MacBugTxMp , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( AdjustRingPointer , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( CheckKeyTxEnd , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WlIntrTask.o + Object OBJECT( WlIntrTxBeaconTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrTxEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrRxEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WlIntrMpEndTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( SetParentTbttTxqTask , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( TakeoutRxFrame , libwl_sp$(LIBSUFFIX).a ) (.text) + # in TxCtrl.o + Object OBJECT( InitTxCtrl , libwl_sp$(LIBSUFFIX).a ) (.text) + # in RxCtrl.o + Object OBJECT( InitRxCtrl , libwl_sp$(LIBSUFFIX).a ) (.text) + # in WaitLoop.o + Object OBJECT( WaitLoop_Rxpe , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_Waitus , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_ClrAid , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_BbpAccess , libwl_sp$(LIBSUFFIX).a ) (.text) + Object OBJECT( WaitLoop_RfAccess , libwl_sp$(LIBSUFFIX).a ) (.text) + + Object $(OBJDIR)/main.o + StackSize 1024 1024 +} + +#-------- +Autoload WRAM +{ + After $(TARGET_NAME) + + #Object * (.etable) + Object * (.wram) + Object * (.ltdwram) +} + +#-------- +Ltdautoload LTDMAIN +{ +# After $(TARGET_NAME) + Address 0x02d00000 + + Object * (.ltdmain) + Object ../flabObj/ARM7LTD.fob + Library libnvram_sp$(LIBSUFFIX).a + Library librtc_sp$(LIBSUFFIX).a + Library libwm_sp$(LIBSUFFIX).a \ + libnwm_sp$(LIBSUFFIX).a \ + libwvr_sp$(LIBSUFFIX).a \ + libwl_sp$(LIBSUFFIX).a \ + + Library libfatfs_sp$(LIBSUFFIX).a \ + $(USE_CRYPTO_LIBS) + Library $(ISDBG_LIBS_TWL) + Library $(ISDBG_LIBS_NITRO) +} diff --git a/build/tests/RelocateChecker/ARM7/src/main.c b/build/tests/RelocateChecker/ARM7/src/main.c new file mode 100644 index 00000000..df0df5ce --- /dev/null +++ b/build/tests/RelocateChecker/ARM7/src/main.c @@ -0,0 +1,623 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - components - mongoose.TWL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-12-05#$ + $Rev: 312 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "nvram_sp.h" + +/*---------------------------------------------------------------------------* + 萔` + *---------------------------------------------------------------------------*/ +/* [TODO] Work around. Should be defined in wm_sp.h */ +#define WM_WL_HEAP_SIZE 0x2100 + +/* Priorities of each threads */ +#define THREAD_PRIO_SPI 2 +#define THREAD_PRIO_SND 6 +#define THREAD_PRIO_FATFS 8 +#define THREAD_PRIO_RTC 12 +#define THREAD_PRIO_FS 15 +/* OS_THREAD_LAUNCHER_PRIORITY 16 */ + +/* [TODO] ȉ New WM ɈڍsقD܂? */ +#define NWM_DMANO 3 +#define THREAD_PRIO_NWM_COMMMAND 6 +#define THREAD_PRIO_NWM_EVENT 4 +#define THREAD_PRIO_NWM_SDIO 5 +#define THREAD_PRIO_NWM_WPA 7 + +// ROM o^GÅgR[h +#define ROMHEADER_FOR_CHINA_BIT 0x80 +#define ROMHEADER_FOR_KOREA_BIT 0x40 + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +static void SetSCFGWork( void ); +static void ReadLauncherParameter( void ); +static void PrintDebugInfo(void); +static OSHeapHandle InitializeAllocateSystem(void); +static void InitializeFatfs(void); +static void InitializeNwm(void); +static void InitializeCdc(void); +static void DummyThread(void* arg); +static void ReadUserInfo(void); +static void VBlankIntr(void); + +/*---------------------------------------------------------------------------* + OV{Q + *---------------------------------------------------------------------------*/ +extern u32 *begin_data_ARM7FLX; +extern u32 *begin_data_ARM7LTD; + +#ifdef SDK_TWLHYB +extern void SDK_LTDAUTOLOAD_LTDWRAM_BSS_END(void); +extern void SDK_LTDAUTOLOAD_LTDMAIN_BSS_END(void); +#endif + +static u32 c; +/*---------------------------------------------------------------------------* + Name: TwlSpMain + Description: NxN^B + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +void +TwlSpMain(void) +{ + OSHeapHandle heapHandle; + u32 a = (u32)begin_data_ARM7FLX; + u32 b = (u32)begin_data_ARM7LTD; + c = a+b; + + // SYSM[ÑNA + MI_CpuClear32( SYSMi_GetWork(), sizeof(SYSM_work) ); + + // MMEMTCY`FbŃAARM7_startłĂ̂ŁAm[PAOK. + // SCFGWX^HWi_WSYS04 etc.system shared̈ւ̒lZbǵA`[N_ł͍sĂȂ̂ŁA + // `[g̒lgɂ́Agł̒lZbgĂKvB + // `[AvNۂɂ́Areboot.clăZbgĂB +// SetSCFGWork(); // [TODO]fobO + + // OS + OS_Init(); + OS_InitTick(); + PrintDebugInfo(); + + // NVRAM 烆[U[ǂݏo + ReadUserInfo(); + + // Cold/HotX^[g + ReadLauncherParameter(); + + // [TODO:] J[hdONāAROMwb_̂݃[h`FbN炢͂Ă + + SYSMi_GetWork()->flags.common.isARM9Start = TRUE; // [TODO:] HW_RED_RESERVEDNANDt@[ŃNAĂė~ + + // q[v̈ݒ + { + void *wram = OS_GetWramSubPrivArenaHi(); + void *mmem = OS_GetSubPrivArenaHi(); + OS_SetSubPrivArenaHi( (void*)0x02e80000 ); // zuĂ̂ŁAA[iHiύXȂƃ_II + OS_SetWramSubPrivArenaHi( (void*)SYSM_OWN_ARM7_WRAM_ADDR_END ); + OS_TPrintf( "MMEM SUBPRV ARENA HI : %08x -> %08x\n", mmem, OS_GetSubPrivArenaHi() ); + OS_TPrintf( "WRAM SUBPRV ARENA HI : %08x -> %08x\n", wram, OS_GetWramSubPrivArenaHi() ); + } + heapHandle = InitializeAllocateSystem(); + + // {^̓T[` + (void)PAD_InitXYButton(); + + // 荞݋ + (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + // t@CVXe + FS_Init(FS_DMA_NOT_USE); + FS_CreateReadServerThread(THREAD_PRIO_FS); + + if (OS_IsRunOnTwl() == TRUE) + { + InitializeFatfs(); // FATFS +#ifndef SDK_NOCRYPTO + AES_Init(); // AES +#endif + } + + if (OSi_IsCodecTwlMode() == TRUE) + { + // CODEC + InitializeCdc(); + } + + // RTC + RTC_Init(THREAD_PRIO_RTC); + + // SPI + SPI_Init(THREAD_PRIO_SPI); + + BOOT_Init(); + + while (TRUE) + { + OS_Halt(); + //---- check reset + if (OS_IsResetOccurred()) + { + OS_ResetSystem(); + } + BOOT_WaitStart(); + } +} + + +// VXë(WRAM & MMEM)SCFGZbg +static void SetSCFGWork( void ) +{ + /* + // SCFGWX^Lȏꍇ̂݃Zbg + if( reg_SCFG_EXT & REG_SCFG_EXT_CFG_MASK ) { + // WRAM̃VXëɃZbg + u32 *wsys4 = (void*)HWi_WSYS04_ADDR; + u8 *wsys8 = (void*)HWi_WSYS08_ADDR; + u8 *wsys9 = (void*)HWi_WSYS09_ADDR; + // copy scfg registers + *wsys4 = reg_SCFG_EXT; + *wsys8 = (u8)(((reg_SCFG_OP & REG_SCFG_OP_OPT_MASK)) | + ((reg_SCFG_A9ROM & (REG_SCFG_A9ROM_RSEL_MASK | REG_SCFG_A9ROM_SEC_MASK)) << (HWi_WSYS08_ROM_ARM9SEC_SHIFT - REG_SCFG_A9ROM_SEC_SHIFT)) | + ((reg_SCFG_A7ROM & (REG_SCFG_A7ROM_RSEL_MASK | REG_SCFG_A7ROM_SEC_MASK | REG_SCFG_A7ROM_FUSE_MASK)) << (HWi_WSYS08_ROM_ARM7SEC_SHIFT - REG_SCFG_A7ROM_SEC_SHIFT)) | + ((reg_SCFG_WL & REG_SCFG_WL_OFFB_MASK) << (HWi_WSYS08_WL_OFFB_SHIFT - REG_SCFG_WL_OFFB_SHIFT)) + ); + *wsys9 = (u8)((*wsys9 & (HWi_WSYS09_JTAG_DSPJE_MASK | HWi_WSYS09_JTAG_CPUJE_MASK | HWi_WSYS09_JTAG_ARM7SEL_MASK)) | + ((reg_SCFG_JTAG & (REG_SCFG_JTAG_CPUJE_MASK | REG_SCFG_JTAG_ARM7SEL_MASK))) | + ((reg_SCFG_JTAG & REG_SCFG_JTAG_DSPJE_MASK) >> (REG_SCFG_JTAG_DSPJE_SHIFT - HWi_WSYS09_JTAG_DSPJE_SHIFT)) | + ((reg_SCFG_CLK & (REG_SCFG_CLK_AESHCLK_MASK | REG_SCFG_CLK_SD2HCLK_MASK | REG_SCFG_CLK_SD1HCLK_MASK)) << (HWi_WSYS09_CLK_SD1HCLK_SHIFT - REG_SCFG_CLK_SD1HCLK_SHIFT)) | + ((reg_SCFG_CLK & (REG_SCFG_CLK_SNDMCLK_MASK | REG_SCFG_CLK_WRAMHCLK_MASK)) >> (REG_SCFG_CLK_WRAMHCLK_SHIFT - HWi_WSYS09_CLK_WRAMHCLK_SHIFT)) + ); + + // MMEM̃VXëɃRs[ + MI_CpuCopy8( (void*)HWi_WSYS04_ADDR, (void *)HW_SYS_CONF_BUF, 6 ); + } + */ +} + +static BOOL IsEnableJTAG( void ) +{ + // SCFGWX^ɂȂĂASCFGWX^̒l"0"ɂȂ̂ŁAWRAMɑޔĂl`FbNB + u8 value = ( reg_SCFG_EXT & REG_SCFG_EXT_CFG_MASK ) ? + (u8)( reg_SCFG_JTAG & REG_SCFG_JTAG_CPUJE_MASK ) : + (u8)( *(u8 *)HWi_WSYS09_ADDR & HWi_WSYS09_JTAG_CPUJE_MASK ); + return value ? TRUE : FALSE; +} + +// `[p[^̃[hHot/ColdX^[g +#define MCU_RESET_VALUE_BUF_ENABLE_MASK 0x80000000 +#define MCU_RESET_VALUE_OFS 0 +#define MCU_RESET_VALUE_LEN 1 +void ReadLauncherParameter( void ) +{ + /* + if( ( *(u32 *)HW_RESET_PARAMETER_BUF & MCU_RESET_VALUE_BUF_ENABLE_MASK ) == 0 ) { + (void)MCU_GetFreeRegisters( MCU_RESET_VALUE_OFS, (u8 *)HW_RESET_PARAMETER_BUF, MCU_RESET_VALUE_LEN ); + } + + // Hot/ColdX^[g + if( IsEnableJTAG() || // ISfobKł̃fobO쎞ɏɃzbgX^[g肳̂h + ( SYSMi_GetMCUFreeRegisterValue() == 0 ) ) { // "JTAGL""}CRt[WX^l=0"ȂColdX^[g + u8 data = 1; + MCU_SetFreeRegisters( MCU_RESET_VALUE_OFS, &data, MCU_RESET_VALUE_LEN ); // }CRt[WX^ɃzbgX^[gtOZbg + SYSMi_GetWork()->flags.common.isHotStart = FALSE; + }else { + SYSMi_GetWork()->flags.common.isHotStart = TRUE; + // `[p[^L + if( ( STD_StrNCmp( (const char *)&SYSMi_GetLauncherParamAddr()->header.magicCode, + SYSM_LAUNCHER_PARAM_MAGIC_CODE, + SYSM_LAUNCHER_PARAM_MAGIC_CODE_LEN ) == 0 ) && + ( SYSMi_GetLauncherParamAddr()->header.bodyLength > 0 ) && + ( SYSMi_GetLauncherParamAddr()->header.crc16 == SVC_GetCRC16( 65535, &SYSMi_GetLauncherParamAddr()->body, SYSMi_GetLauncherParamAddr()->header.bodyLength ) ) + ) { + // `[p[^LȂA[Nɑޔ + MI_CpuCopy32 ( SYSMi_GetLauncherParamAddr(), &SYSMi_GetWork()->launcherParam, sizeof(LauncherParam) ); + SYSMi_GetWork()->flags.common.isValidLauncherParam = TRUE; + } + } + // C̃`[p[^NAĂ + MI_CpuClear32( SYSMi_GetLauncherParamAddr(), HW_PARAM_LAUNCH_PARAM_SIZE ); + */ +} + + +/*---------------------------------------------------------------------------* + Name: PrintDebugInfo + Description: ARM7 R|[lg̏fobOo͂B + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +PrintDebugInfo(void) +{ + if(OS_IsRunOnTwl()) + { + OS_TPrintf("ARM7: This component is running on TWL.\n"); + } + else + { + OS_TPrintf("ARM7: This component is running on NITRO.\n"); + } +#ifdef SDK_TWLLTD + OS_TPrintf("ARM7: This component is \"racoon.TWL\"\n"); +#else /* SDK_TWLHYB */ +#ifdef SDK_WIRELESS_IN_VRAM + OS_TPrintf("ARM7: This component is \"ichneumon.TWL\"\n"); +#else + OS_TPrintf("ARM7: This component is \"mongoose.TWL\"\n"); +#endif +#endif +} + +#include +/*---------------------------------------------------------------------------* + Name: InitializeFatfs + Description: FATFSCuB + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeFatfs(void) +{ + // FATFSCȕ + if (FATFS_Init(FATFS_DMA_NOT_USE, FATFS_DMA_NOT_USE, THREAD_PRIO_FATFS)) + { + // do nothing + } +} +#include + +#include +/*---------------------------------------------------------------------------* + Name: InitializeNwm + Description: NWMCuB + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeNwm(void) +{ + NwmspInit nwmInit; + + OSHeapHandle heapHandle; + void* Lo = (void*)OS_GetSubPrivArenaLo(); + void* Hi = (void*)OS_GetSubPrivArenaHi(); + heapHandle = OS_CreateHeap(OS_ARENA_MAIN_SUBPRIV, Lo, Hi); + + /* [TODO] mۂq[v̈悪VꎮKvƂĂ郁ʈȏォ̃`FbNKv */ + + nwmInit.dmaNo = NWM_DMANO; + nwmInit.cmdPrio = THREAD_PRIO_NWM_COMMMAND; + nwmInit.evtPrio = THREAD_PRIO_NWM_EVENT; + nwmInit.sdioPrio = THREAD_PRIO_NWM_SDIO; + nwmInit.drvHeap.id = OS_ARENA_MAIN_SUBPRIV; /* [TODO] */ + nwmInit.drvHeap.handle = heapHandle; +#ifdef WPA_BUILT_IN /* WPA gݍ܂ꍇAȉ̃olj */ + nwmInit.wpaPrio = THREAD_PRIO_NWM_WPA; + nwmInit.wpaHeap.id = OS_ARENA_MAIN_SUBPRIV; /* [TODO] */ + nwmInit.wpaHeap.handle = heapHandle; +#endif + NWMSP_Init(&nwmInit); + +} +#include + +#include +/*---------------------------------------------------------------------------* + Name: InitializeCdc + Description: CDCCuBCDC֐ŃXbhx~ + ׁAx~삷_~[̃Xbh𗧂ĂB + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeCdc(void) +{ + OSThread thread; + u32 stack[18]; + + // _~[Xbh쐬 + OS_CreateThread(&thread, DummyThread, NULL, + (void*)((u32)stack + (sizeof(u32) * 18)), sizeof(u32) * 18, OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&thread); + + // CODEC + CDC_Init(); + CDC_InitMic(); +// CDCi_DumpRegisters(); + + // _~[Xbhj + OS_KillThread(&thread, NULL); +} + +/*---------------------------------------------------------------------------* + Name: DummyThread + Description: CDCCuۂɗĂ_~[̃XbhB + Arguments: arg - gpȂB + Returns: None. + *---------------------------------------------------------------------------*/ +static void +DummyThread(void* arg) +{ +#pragma unused(arg) + while (TRUE) + { + } +} +#include + +/*---------------------------------------------------------------------------* + Name: InitializeAllocateSystem + Description: ăVXeB + Arguments: None. + Returns: OSHeapHandle - WRAM A[iɊmۂꂽq[ṽnhԂB + *---------------------------------------------------------------------------*/ +static OSHeapHandle +InitializeAllocateSystem(void) +{ + OSHeapHandle hh; + +#ifdef SDK_TWLHYB + if (OS_IsRunOnTwl() == TRUE) + { + void* basicLo = (void*)OS_GetSubPrivArenaLo(); + void* basicHi = (void*)OS_GetSubPrivArenaHi(); + void* extraLo = (void*)MATH_ROUNDUP((u32)SDK_LTDAUTOLOAD_LTDMAIN_BSS_END, 32); + void* extraHi = (void*)MATH_ROUNDDOWN(HW_MAIN_MEM_SUB, 32); + +#if SDK_DEBUG + // debug information + OS_TPrintf("ARM7: MAIN arena basicLo = %p\n", basicLo); + OS_TPrintf("ARM7: MAIN arena basicHi = %p\n", basicHi); + OS_TPrintf("ARM7: MAIN arena extraLo = %p\n", extraLo); + OS_TPrintf("ARM7: MAIN arena extraHi = %p\n", extraHi); +#endif + + // A[i 0 NA + MI_CpuClear8(basicLo, (u32)basicHi - (u32)basicLo); + MI_CpuClear8(extraLo, (u32)extraHi - (u32)extraLo); + + // 蓖ď + if ((u32)basicLo < (u32)extraLo) + { + basicLo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, basicLo, extraHi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_MAIN_SUBPRIV, basicLo); + } + else + { + extraLo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, extraLo, basicHi, 1); + } + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_MAIN_SUBPRIV, basicLo, basicHi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to create MAIN heap.\n"); + } + + // q[vɊgubNlj + OS_AddToHeap(OS_ARENA_MAIN_SUBPRIV, hh, extraLo, extraHi); + } + else +#endif + { + void* lo = (void*)OS_GetSubPrivArenaLo(); + void* hi = (void*)OS_GetSubPrivArenaHi(); + + // A[i 0 NA + MI_CpuClear8(lo, (u32)hi - (u32)lo); + + // 蓖ď + lo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, lo, hi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_MAIN_SUBPRIV, lo); + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_MAIN_SUBPRIV, lo, hi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to MAIN create heap.\n"); + } + } + // Jgq[vɐݒ + (void)OS_SetCurrentHeap(OS_ARENA_MAIN_SUBPRIV, hh); + // q[vTCY̊mF + { + u32 heapSize; + + heapSize = (u32)OS_CheckHeap(OS_ARENA_MAIN_SUBPRIV, hh); + OS_TPrintf("ARM7: MAIN heap size is %d\n", heapSize); + } +#ifdef SDK_TWLHYB + if (OS_IsRunOnTwl() == TRUE) + { + void* basicLo = (void*)OS_GetWramSubPrivArenaLo(); + void* basicHi = (void*)OS_GetWramSubPrivArenaHi(); + void* extraLo = (void*)MATH_ROUNDUP((u32)SDK_LTDAUTOLOAD_LTDWRAM_BSS_END, 32); + void* extraHi = (void*)MATH_ROUNDDOWN(HW_WRAM_A_HYB_END, 32); + +#if SDK_DEBUG + // debug information + OS_TPrintf("ARM7: WRAM arena basicLo = %p\n", basicLo); + OS_TPrintf("ARM7: WRAM arena basicHi = %p\n", basicHi); + OS_TPrintf("ARM7: WRAM arena extraLo = %p\n", extraLo); + OS_TPrintf("ARM7: WRAM arena extraHi = %p\n", extraHi); +#endif + + // A[i 0 NA + MI_CpuClear8(basicLo, (u32)basicHi - (u32)basicLo); + MI_CpuClear8(extraLo, (u32)extraHi - (u32)extraLo); + + // 蓖ď + if ((u32)basicLo < (u32)extraLo) + { + basicLo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV, basicLo, extraHi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_WRAM_SUBPRIV, basicLo); + } + else + { + extraLo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV, extraLo, basicHi, 1); + } + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_WRAM_SUBPRIV, basicLo, basicHi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to WRAM create heap.\n"); + } + + // q[vɊgubNlj + OS_AddToHeap(OS_ARENA_WRAM_SUBPRIV, hh, extraLo, extraHi); + } + else +#endif + { + void* lo = (void*)OS_GetWramSubPrivArenaLo(); + void* hi = (void*)OS_GetWramSubPrivArenaHi(); + + // A[i 0 NA + MI_CpuClear8(lo, (u32)hi - (u32)lo); + + // 蓖ď + lo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV, lo, hi, 1); + // A[iʃAhXݒ + OS_SetArenaLo(OS_ARENA_WRAM_SUBPRIV, lo); + + // q[v쐬 + hh = OS_CreateHeap(OS_ARENA_WRAM_SUBPRIV, lo, hi); + + if (hh < 0) + { + OS_Panic("ARM7: Failed to WRAM create heap.\n"); + } + } + + // Jgq[vɐݒ + (void)OS_SetCurrentHeap(OS_ARENA_WRAM_SUBPRIV, hh); + + // q[vTCY̊mF + { + u32 heapSize; + + heapSize = (u32)OS_CheckHeap(OS_ARENA_WRAM_SUBPRIV, hh); + if (WM_WL_HEAP_SIZE > heapSize) + { + OS_Panic("Insufficient heap size. (0x%x < 0x%x)\n", heapSize, WM_WL_HEAP_SIZE); + } + OS_TPrintf("ARM7: WRAM heap size is %d\n", heapSize); + } + + return hh; +} + +#ifdef WM_PRECALC_ALLOWEDCHANNEL +extern u16 WMSP_GetAllowedChannel(u16 bitField); +#endif +/*---------------------------------------------------------------------------* + Name: ReadUserInfo + + Description: NVRAM烆[U[ǂݏoAL̈ɓWJB + ~[OĂobt@Ăꍇ́A + L̈̃[U[i[ꏊNAB + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void ReadUserInfo(void) +{ + u8 *p; + + // MACAhX[U[̌ɓWJ + { + u8 wMac[6]; + + // NVRAMMACAhXǂݏo + NVRAM_ReadDataBytes(NVRAM_CONFIG_MACADDRESS_ADDRESS, 6, wMac); + // WJAhXvZ + p = (u8 *)((u32)p + ((sizeof(NVRAMConfig) + 3) & ~0x00000003)); + // L̈ɓWJ + MI_CpuCopy8(wMac, p, 6); + } + +#ifdef WM_PRECALC_ALLOWEDCHANNEL + // gp”\`lgpƒ`lvZ + { + u16 enableChannel; + u16 allowedChannel; + + // gp”\`lǂݏo + NVRAM_ReadDataBytes(NVRAM_CONFIG_ENABLECHANNEL_ADDRESS, 2, (u8 *)(&enableChannel)); + // gpƒ`lvZ + allowedChannel = WMSP_GetAllowedChannel((u16)(enableChannel >> 1)); + // WJAhXvZ(MACAhX̌2oCg) + p = (u8 *)((u32)p + 6); + // L̈ɓWJ + *((u16 *)p) = allowedChannel; + } +#endif +} + + +/*---------------------------------------------------------------------------* + Name: VBlankIntr + Description: V uN荞݃xN^B + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +extern BOOL PMi_Initialized; +void PM_SelfBlinkProc(void); + +static void +VBlankIntr(void) +{ + if (PMi_Initialized) + { + PM_SelfBlinkProc(); + } +} diff --git a/build/tests/RelocateChecker/ARM9/ARM9-TS.lsf b/build/tests/RelocateChecker/ARM9/ARM9-TS.lsf new file mode 100644 index 00000000..a2db2cc2 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/ARM9-TS.lsf @@ -0,0 +1,55 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-BB.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-11-20#$ +# $Rev: 221 $ +# $Author: yoshida_teruhisa $ +#---------------------------------------------------------------------------- +# +# TWL LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address $(ADDRESS_FLXMAIN) + Object $(OBJS_STATIC) ../flabObj/ARM9FLX.fob + Library $(LLIBS) $(GLIBS) $(CW_LIBS) +} + + +Autoload ITCM +{ + Address 0x01ff8000 + Object * (.itcm) + Object $(OBJS_AUTOLOAD) (.text) + Object $(OBJS_AUTOLOAD) (.rodata) +} + +Autoload DTCM +{ + Address $(ADDRESS_DTCM) + Object * (.dtcm) + Object $(OBJS_AUTOLOAD) (.data) + Object $(OBJS_AUTOLOAD) (.sdata) + Object $(OBJS_AUTOLOAD) (.bss) + Object $(OBJS_AUTOLOAD) (.sbss) +} + +Ltdautoload LTDMAIN +{ + # NITRO/TWL L̃I[o[C݂ꍇ́Aɂ̌ɔzuKv܂B +# After $(TARGET_NAME) + Address 0x02900000 + Object * (.ltdmain) + Object $(OBJS_LTDAUTOLOAD) ../flabObj/ARM9LTD.fob + Library $(LLIBS_EX) $(GLIBS_EX) +} diff --git a/build/tests/RelocateChecker/ARM9/Makefile b/build/tests/RelocateChecker/ARM9/Makefile new file mode 100644 index 00000000..12c1cc68 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/Makefile @@ -0,0 +1,32 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = Makefile.0 Makefile.1 Makefile.2 Makefile.3 Makefile.4 Makefile.5 + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM9/Makefile.0 b/build/tests/RelocateChecker/ARM9/Makefile.0 new file mode 100644 index 00000000..5d383ad9 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/Makefile.0 @@ -0,0 +1,80 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +#ARM9_FLX_addr +MAKELCF_FLAGS += -DADDRESS_FLXMAIN='0x02000400' + +TARGET_FOB = ARM9FLX.fob +#ARM9_FLX_addsize +FBDSIZE_ARM9FLX = 4 +TARGET_FOB += ARM9LTD.fob +#ARM9_LTD_addsize +FBDSIZE_ARM9LTD = 4 + +TARGET_NUMBER = 0 +TARGET_NAME = RelocateChecker$(TARGET_NUMBER) +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) +TARGET_BIN = $(TARGET_NAME).srl + +TITLEID_LO = RCK$(TARGET_NUMBER) +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +LCFILE_SPEC = ARM9-TS.lsf +ROM_SPEC = main.rsf +LCFILE_TEMPLATE = rc$(TARGET_NUMBER).lcf.template + +MISC_DIR = $(SYSMENU_ROOT)/build/systemMenu_RED/misc + +SRCS = main.c RelocateChecker.c \ + $(MISC_DIR)/src/misc.c $(MISC_DIR)/src/cmn.c + +LINCLUDES = $(MISC_DIR)/include +LLIBRARY_DIRS += ../crt/ARM9/obj/ARM9-TS.HYB/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.FLX.TWL.o + +//MAKEROM_FLAGS += -DTITLEID_LO='$(TITLEID_LO)' +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs + +DEFAULT_COMP_ARM7 = hyena_rc$(TARGET_NUMBER) +DEFAULT_MAKEROM_ARM7_BASE = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/$(DEFAULT_COMP_ARM7)/$(DEFAULT_COMP_ARM7) +DEFAULT_MAKEROM_ARM7 = $(DEFAULT_MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM9/Makefile.1 b/build/tests/RelocateChecker/ARM9/Makefile.1 new file mode 100644 index 00000000..7eb0972e --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/Makefile.1 @@ -0,0 +1,80 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +#ARM9_FLX_addr +MAKELCF_FLAGS += -DADDRESS_FLXMAIN='0x02140000' + +TARGET_FOB = ARM9FLX.fob +#ARM9_FLX_addsize +FBDSIZE_ARM9FLX = 1310720 +TARGET_FOB += ARM9LTD.fob +#ARM9_LTD_addsize +FBDSIZE_ARM9LTD = 2097152 + +TARGET_NUMBER = 1 +TARGET_NAME = RelocateChecker$(TARGET_NUMBER) +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) +TARGET_BIN = $(TARGET_NAME).srl + +TITLEID_LO = RCK$(TARGET_NUMBER) +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +LCFILE_SPEC = ARM9-TS.lsf +ROM_SPEC = main.rsf +LCFILE_TEMPLATE = rc$(TARGET_NUMBER).lcf.template + +MISC_DIR = $(SYSMENU_ROOT)/build/systemMenu_RED/misc + +SRCS = main.c RelocateChecker.c \ + $(MISC_DIR)/src/misc.c $(MISC_DIR)/src/cmn.c + +LINCLUDES = $(MISC_DIR)/include +LLIBRARY_DIRS += ../crt/ARM9/obj/ARM9-TS.HYB/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.FLX.TWL.o + +//MAKEROM_FLAGS += -DTITLEID_LO='$(TITLEID_LO)' +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs + +DEFAULT_COMP_ARM7 = hyena_rc$(TARGET_NUMBER) +DEFAULT_MAKEROM_ARM7_BASE = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/$(DEFAULT_COMP_ARM7)/$(DEFAULT_COMP_ARM7) +DEFAULT_MAKEROM_ARM7 = $(DEFAULT_MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM9/Makefile.2 b/build/tests/RelocateChecker/ARM9/Makefile.2 new file mode 100644 index 00000000..3d4db7ca --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/Makefile.2 @@ -0,0 +1,80 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +#ARM9_FLX_addr +MAKELCF_FLAGS += -DADDRESS_FLXMAIN='0x02000400' + +TARGET_FOB = ARM9FLX.fob +#ARM9_FLX_addsize +FBDSIZE_ARM9FLX = 4 +TARGET_FOB += ARM9LTD.fob +#ARM9_LTD_addsize +FBDSIZE_ARM9LTD = 4 + +TARGET_NUMBER = 2 +TARGET_NAME = RelocateChecker$(TARGET_NUMBER) +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) +TARGET_BIN = $(TARGET_NAME).srl + +TITLEID_LO = RCK$(TARGET_NUMBER) +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +LCFILE_SPEC = ARM9-TS.lsf +ROM_SPEC = main.rsf +LCFILE_TEMPLATE = rc$(TARGET_NUMBER).lcf.template + +MISC_DIR = $(SYSMENU_ROOT)/build/systemMenu_RED/misc + +SRCS = main.c RelocateChecker.c \ + $(MISC_DIR)/src/misc.c $(MISC_DIR)/src/cmn.c + +LINCLUDES = $(MISC_DIR)/include +LLIBRARY_DIRS += ../crt/ARM9/obj/ARM9-TS.HYB/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.FLX.TWL.o + +//MAKEROM_FLAGS += -DTITLEID_LO='$(TITLEID_LO)' +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs + +DEFAULT_COMP_ARM7 = hyena_rc$(TARGET_NUMBER) +DEFAULT_MAKEROM_ARM7_BASE = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/$(DEFAULT_COMP_ARM7)/$(DEFAULT_COMP_ARM7) +DEFAULT_MAKEROM_ARM7 = $(DEFAULT_MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM9/Makefile.3 b/build/tests/RelocateChecker/ARM9/Makefile.3 new file mode 100644 index 00000000..0bfe8dee --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/Makefile.3 @@ -0,0 +1,80 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +#ARM9_FLX_addr +MAKELCF_FLAGS += -DADDRESS_FLXMAIN='0x02300000' + +TARGET_FOB = ARM9FLX.fob +#ARM9_FLX_addsize +FBDSIZE_ARM9FLX = 4 +TARGET_FOB += ARM9LTD.fob +#ARM9_LTD_addsize +FBDSIZE_ARM9LTD = 4 + +TARGET_NUMBER = 3 +TARGET_NAME = RelocateChecker$(TARGET_NUMBER) +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) +TARGET_BIN = $(TARGET_NAME).srl + +TITLEID_LO = RCK$(TARGET_NUMBER) +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +LCFILE_SPEC = ARM9-TS.lsf +ROM_SPEC = main.rsf +LCFILE_TEMPLATE = rc$(TARGET_NUMBER).lcf.template + +MISC_DIR = $(SYSMENU_ROOT)/build/systemMenu_RED/misc + +SRCS = main.c RelocateChecker.c \ + $(MISC_DIR)/src/misc.c $(MISC_DIR)/src/cmn.c + +LINCLUDES = $(MISC_DIR)/include +LLIBRARY_DIRS += ../crt/ARM9/obj/ARM9-TS.HYB/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.FLX.TWL.o + +//MAKEROM_FLAGS += -DTITLEID_LO='$(TITLEID_LO)' +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs + +DEFAULT_COMP_ARM7 = hyena_rc$(TARGET_NUMBER) +DEFAULT_MAKEROM_ARM7_BASE = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/$(DEFAULT_COMP_ARM7)/$(DEFAULT_COMP_ARM7) +DEFAULT_MAKEROM_ARM7 = $(DEFAULT_MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM9/Makefile.4 b/build/tests/RelocateChecker/ARM9/Makefile.4 new file mode 100644 index 00000000..c921713d --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/Makefile.4 @@ -0,0 +1,80 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +#ARM9_FLX_addr +MAKELCF_FLAGS += -DADDRESS_FLXMAIN='0x02380000' + +TARGET_FOB = ARM9FLX.fob +#ARM9_FLX_addsize +FBDSIZE_ARM9FLX = 4 +TARGET_FOB += ARM9LTD.fob +#ARM9_LTD_addsize +FBDSIZE_ARM9LTD = 4 + +TARGET_NUMBER = 4 +TARGET_NAME = RelocateChecker$(TARGET_NUMBER) +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) +TARGET_BIN = $(TARGET_NAME).srl + +TITLEID_LO = RCK$(TARGET_NUMBER) +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +LCFILE_SPEC = ARM9-TS.lsf +ROM_SPEC = main.rsf +LCFILE_TEMPLATE = rc$(TARGET_NUMBER).lcf.template + +MISC_DIR = $(SYSMENU_ROOT)/build/systemMenu_RED/misc + +SRCS = main.c RelocateChecker.c \ + $(MISC_DIR)/src/misc.c $(MISC_DIR)/src/cmn.c + +LINCLUDES = $(MISC_DIR)/include +LLIBRARY_DIRS += ../crt/ARM9/obj/ARM9-TS.HYB/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.FLX.TWL.o + +//MAKEROM_FLAGS += -DTITLEID_LO='$(TITLEID_LO)' +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs + +DEFAULT_COMP_ARM7 = hyena_rc$(TARGET_NUMBER) +DEFAULT_MAKEROM_ARM7_BASE = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/$(DEFAULT_COMP_ARM7)/$(DEFAULT_COMP_ARM7) +DEFAULT_MAKEROM_ARM7 = $(DEFAULT_MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM9/Makefile.5 b/build/tests/RelocateChecker/ARM9/Makefile.5 new file mode 100644 index 00000000..29881c10 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/Makefile.5 @@ -0,0 +1,80 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- + +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +#ARM9_FLX_addr +MAKELCF_FLAGS += -DADDRESS_FLXMAIN='0x02300000' + +TARGET_FOB = ARM9FLX.fob +#ARM9_FLX_addsize +FBDSIZE_ARM9FLX = 4 +TARGET_FOB += ARM9LTD.fob +#ARM9_LTD_addsize +FBDSIZE_ARM9LTD = 4 + +TARGET_NUMBER = 5 +TARGET_NAME = RelocateChecker$(TARGET_NUMBER) +BINDIR = ./bin/$(TWL_BUILDTYPE)/$(TARGET_NAME) +TARGET_BIN = $(TARGET_NAME).srl + +TITLEID_LO = RCK$(TARGET_NUMBER) +TARGET_TAD = $(BINDIR)/$(TITLEID_LO).$(TWL_BUILD_DIR)$(CODEGEN_ARCH).tad + +LCFILE_SPEC = ARM9-TS.lsf +ROM_SPEC = main.rsf +LCFILE_TEMPLATE = rc$(TARGET_NUMBER).lcf.template + +MISC_DIR = $(SYSMENU_ROOT)/build/systemMenu_RED/misc + +SRCS = main.c RelocateChecker.c \ + $(MISC_DIR)/src/misc.c $(MISC_DIR)/src/cmn.c + +LINCLUDES = $(MISC_DIR)/include +LLIBRARY_DIRS += ../crt/ARM9/obj/ARM9-TS.HYB/$(TWL_BUILD_DIR) + +CRT0_O = crt0_rc.FLX.TWL.o + +//MAKEROM_FLAGS += -DTITLEID_LO='$(TITLEID_LO)' +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/commondefs + +DEFAULT_COMP_ARM7 = hyena_rc$(TARGET_NUMBER) +DEFAULT_MAKEROM_ARM7_BASE = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/$(DEFAULT_COMP_ARM7)/$(DEFAULT_COMP_ARM7) +DEFAULT_MAKEROM_ARM7 = $(DEFAULT_MAKEROM_ARM7_BASE).$(TWL_ELF_EXT) + +LDIRT_CLEAN = $(TARGET_TAD) +INSTALL_TARGETS = $(TARGET_TAD) +INSTALL_DIR = $(SDK_NMENU_DATADIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/ARM9/main.rsf b/build/tests/RelocateChecker/ARM9/main.rsf new file mode 100644 index 00000000..b00baaa9 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/main.rsf @@ -0,0 +1,179 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-11-21#$ +# $Rev: 240 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType User + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + #SaveBannerFile TRUE +} + + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot $(TWL_IPL_RED_ROOT)/build/systemMenu_RED/data + Root /data + File NTR_IPL_font_m.NFTR +} diff --git a/build/tests/RelocateChecker/ARM9/rc0.lcf.template b/build/tests/RelocateChecker/ARM9/rc0.lcf.template new file mode 100644 index 00000000..28106bc3 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/rc0.lcf.template @@ -0,0 +1,1033 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-TS.lcf.template +# +# 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-11-15#$ +# $Rev: 2384 $ +# $Author: nishimoto_takashi $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.NITRO (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN.NITRO (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX.NITRO (RW) : ORIGIN = AFTER(dummy.MAIN_EX.NITRO,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + + check.ITCM (RW) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.TWL (RW) : ORIGIN = 0x0d000000, LENGTH = 0x0 + arena.MAIN.TWL (RW) : ORIGIN = AFTER(,,LTDMAIN,), LENGTH = 0x0 + arena.MAIN_EX.TWL (RW) : ORIGIN = AFTER(dummy.MAIN_EX.TWL,,,LTDMAIN,), LENGTH = 0x0 + + binary.MODULE_FILES (RW) : ORIGIN = 0, LENGTH = 0x0 > component.files +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + libsyscall.a (.text) + OBJECT(_start,*) + crt0_rc.FLX.TWL.o (.text) + crt0_rc.FLX.TWL.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); # Fit to cache line + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + . = ALIGN(4); + + SDK_LTDOVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_LTDOVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_OVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAY_DIGEST =.; + . = . + * 20; + . = . + * 20; + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x02fe0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(32); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW SDK_OVERLAY_DIGEST - ADDR(.); + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > F + + ############################ ARENA ################################## + .dummy.MAIN_EX.NITRO: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.NITRO + + .arena.MAIN.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN.NITRO + + .arena.MAIN_EX.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + + } > arena.MAIN_EX.NITRO + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + + } > arena.DTCM + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + + } > check.ITCM + + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + . = . + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_EDN = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02400000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > L + + ############################ ARENA ################################## + .dummy.MAIN_EX.TWL: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.TWL + + .arena.MAIN.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_ARENA_LO =.; + + } > arena.MAIN.TWL + + .arena.MAIN_EX.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_EX_ARENA_LO =.; + + } > arena.MAIN_EX.TWL + + ############################ OTHERS ################################# + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + + } > binary.MODULE_FILES + +} diff --git a/build/tests/RelocateChecker/ARM9/rc1.lcf.template b/build/tests/RelocateChecker/ARM9/rc1.lcf.template new file mode 100644 index 00000000..99234f92 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/rc1.lcf.template @@ -0,0 +1,1033 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-TS.lcf.template +# +# 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-11-15#$ +# $Rev: 2384 $ +# $Author: nishimoto_takashi $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.NITRO (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN.NITRO (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX.NITRO (RW) : ORIGIN = AFTER(dummy.MAIN_EX.NITRO,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + + check.ITCM (RW) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.TWL (RW) : ORIGIN = 0x0d000000, LENGTH = 0x0 + arena.MAIN.TWL (RW) : ORIGIN = AFTER(,,LTDMAIN,), LENGTH = 0x0 + arena.MAIN_EX.TWL (RW) : ORIGIN = AFTER(dummy.MAIN_EX.TWL,,,LTDMAIN,), LENGTH = 0x0 + + binary.MODULE_FILES (RW) : ORIGIN = 0, LENGTH = 0x0 > component.files +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + libsyscall.a (.text) + OBJECT(_start,*) + crt0_rc.FLX.TWL.o (.text) + crt0_rc.FLX.TWL.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); # Fit to cache line + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + . = ALIGN(4); + + SDK_LTDOVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_LTDOVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_OVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAY_DIGEST =.; + . = . + * 20; + . = . + * 20; + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x02fe0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(32); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW SDK_OVERLAY_DIGEST - ADDR(.); + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > F + + ############################ ARENA ################################## + .dummy.MAIN_EX.NITRO: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.NITRO + + .arena.MAIN.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN.NITRO + + .arena.MAIN_EX.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + + } > arena.MAIN_EX.NITRO + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + + } > arena.DTCM + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + + } > check.ITCM + + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + . = . + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_EDN = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02600000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > L + + ############################ ARENA ################################## + .dummy.MAIN_EX.TWL: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.TWL + + .arena.MAIN.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_ARENA_LO =.; + + } > arena.MAIN.TWL + + .arena.MAIN_EX.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_EX_ARENA_LO =.; + + } > arena.MAIN_EX.TWL + + ############################ OTHERS ################################# + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + + } > binary.MODULE_FILES + +} diff --git a/build/tests/RelocateChecker/ARM9/rc2.lcf.template b/build/tests/RelocateChecker/ARM9/rc2.lcf.template new file mode 100644 index 00000000..35b45072 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/rc2.lcf.template @@ -0,0 +1,1033 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-TS.lcf.template +# +# 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-11-15#$ +# $Rev: 2384 $ +# $Author: nishimoto_takashi $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.NITRO (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN.NITRO (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX.NITRO (RW) : ORIGIN = AFTER(dummy.MAIN_EX.NITRO,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + + check.ITCM (RW) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.TWL (RW) : ORIGIN = 0x0d000000, LENGTH = 0x0 + arena.MAIN.TWL (RW) : ORIGIN = AFTER(,,LTDMAIN,), LENGTH = 0x0 + arena.MAIN_EX.TWL (RW) : ORIGIN = AFTER(dummy.MAIN_EX.TWL,,,LTDMAIN,), LENGTH = 0x0 + + binary.MODULE_FILES (RW) : ORIGIN = 0, LENGTH = 0x0 > component.files +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + libsyscall.a (.text) + OBJECT(_start,*) + crt0_rc.FLX.TWL.o (.text) + crt0_rc.FLX.TWL.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); # Fit to cache line + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + . = ALIGN(4); + + SDK_LTDOVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_LTDOVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_OVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAY_DIGEST =.; + . = . + * 20; + . = . + * 20; + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x02fe0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(32); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW SDK_OVERLAY_DIGEST - ADDR(.); + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > F + + ############################ ARENA ################################## + .dummy.MAIN_EX.NITRO: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.NITRO + + .arena.MAIN.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN.NITRO + + .arena.MAIN_EX.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + + } > arena.MAIN_EX.NITRO + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + + } > arena.DTCM + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + + } > check.ITCM + + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + . = . + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_EDN = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x023ffffc; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > L + + ############################ ARENA ################################## + .dummy.MAIN_EX.TWL: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.TWL + + .arena.MAIN.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_ARENA_LO =.; + + } > arena.MAIN.TWL + + .arena.MAIN_EX.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_EX_ARENA_LO =.; + + } > arena.MAIN_EX.TWL + + ############################ OTHERS ################################# + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + + } > binary.MODULE_FILES + +} diff --git a/build/tests/RelocateChecker/ARM9/rc3.lcf.template b/build/tests/RelocateChecker/ARM9/rc3.lcf.template new file mode 100644 index 00000000..2d457b95 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/rc3.lcf.template @@ -0,0 +1,1033 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-TS.lcf.template +# +# 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-11-15#$ +# $Rev: 2384 $ +# $Author: nishimoto_takashi $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.NITRO (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN.NITRO (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX.NITRO (RW) : ORIGIN = AFTER(dummy.MAIN_EX.NITRO,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + + check.ITCM (RW) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.TWL (RW) : ORIGIN = 0x0d000000, LENGTH = 0x0 + arena.MAIN.TWL (RW) : ORIGIN = AFTER(,,LTDMAIN,), LENGTH = 0x0 + arena.MAIN_EX.TWL (RW) : ORIGIN = AFTER(dummy.MAIN_EX.TWL,,,LTDMAIN,), LENGTH = 0x0 + + binary.MODULE_FILES (RW) : ORIGIN = 0, LENGTH = 0x0 > component.files +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + libsyscall.a (.text) + OBJECT(_start,*) + crt0_rc.FLX.TWL.o (.text) + crt0_rc.FLX.TWL.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); # Fit to cache line + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + . = ALIGN(4); + + SDK_LTDOVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_LTDOVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_OVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAY_DIGEST =.; + . = . + * 20; + . = . + * 20; + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x02fe0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(32); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW SDK_OVERLAY_DIGEST - ADDR(.); + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > F + + ############################ ARENA ################################## + .dummy.MAIN_EX.NITRO: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.NITRO + + .arena.MAIN.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN.NITRO + + .arena.MAIN_EX.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + + } > arena.MAIN_EX.NITRO + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + + } > arena.DTCM + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + + } > check.ITCM + + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + . = . + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_EDN = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02800000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > L + + ############################ ARENA ################################## + .dummy.MAIN_EX.TWL: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.TWL + + .arena.MAIN.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_ARENA_LO =.; + + } > arena.MAIN.TWL + + .arena.MAIN_EX.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_EX_ARENA_LO =.; + + } > arena.MAIN_EX.TWL + + ############################ OTHERS ################################# + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + + } > binary.MODULE_FILES + +} diff --git a/build/tests/RelocateChecker/ARM9/rc4.lcf.template b/build/tests/RelocateChecker/ARM9/rc4.lcf.template new file mode 100644 index 00000000..28106bc3 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/rc4.lcf.template @@ -0,0 +1,1033 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-TS.lcf.template +# +# 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-11-15#$ +# $Rev: 2384 $ +# $Author: nishimoto_takashi $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.NITRO (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN.NITRO (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX.NITRO (RW) : ORIGIN = AFTER(dummy.MAIN_EX.NITRO,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + + check.ITCM (RW) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.TWL (RW) : ORIGIN = 0x0d000000, LENGTH = 0x0 + arena.MAIN.TWL (RW) : ORIGIN = AFTER(,,LTDMAIN,), LENGTH = 0x0 + arena.MAIN_EX.TWL (RW) : ORIGIN = AFTER(dummy.MAIN_EX.TWL,,,LTDMAIN,), LENGTH = 0x0 + + binary.MODULE_FILES (RW) : ORIGIN = 0, LENGTH = 0x0 > component.files +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + libsyscall.a (.text) + OBJECT(_start,*) + crt0_rc.FLX.TWL.o (.text) + crt0_rc.FLX.TWL.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); # Fit to cache line + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + . = ALIGN(4); + + SDK_LTDOVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_LTDOVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_OVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAY_DIGEST =.; + . = . + * 20; + . = . + * 20; + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x02fe0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(32); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW SDK_OVERLAY_DIGEST - ADDR(.); + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > F + + ############################ ARENA ################################## + .dummy.MAIN_EX.NITRO: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.NITRO + + .arena.MAIN.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN.NITRO + + .arena.MAIN_EX.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + + } > arena.MAIN_EX.NITRO + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + + } > arena.DTCM + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + + } > check.ITCM + + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + . = . + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_EDN = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02400000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > L + + ############################ ARENA ################################## + .dummy.MAIN_EX.TWL: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.TWL + + .arena.MAIN.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_ARENA_LO =.; + + } > arena.MAIN.TWL + + .arena.MAIN_EX.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_EX_ARENA_LO =.; + + } > arena.MAIN_EX.TWL + + ############################ OTHERS ################################# + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + + } > binary.MODULE_FILES + +} diff --git a/build/tests/RelocateChecker/ARM9/rc5.lcf.template b/build/tests/RelocateChecker/ARM9/rc5.lcf.template new file mode 100644 index 00000000..2d457b95 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/rc5.lcf.template @@ -0,0 +1,1033 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-TS.lcf.template +# +# 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-11-15#$ +# $Rev: 2384 $ +# $Author: nishimoto_takashi $ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.NITRO (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN.NITRO (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX.NITRO (RW) : ORIGIN = AFTER(dummy.MAIN_EX.NITRO,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + + check.ITCM (RW) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.TWL (RW) : ORIGIN = 0x0d000000, LENGTH = 0x0 + arena.MAIN.TWL (RW) : ORIGIN = AFTER(,,LTDMAIN,), LENGTH = 0x0 + arena.MAIN_EX.TWL (RW) : ORIGIN = AFTER(dummy.MAIN_EX.TWL,,,LTDMAIN,), LENGTH = 0x0 + + binary.MODULE_FILES (RW) : ORIGIN = 0, LENGTH = 0x0 > component.files +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + libsyscall.a (.text) + OBJECT(_start,*) + crt0_rc.FLX.TWL.o (.text) + crt0_rc.FLX.TWL.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); # Fit to cache line + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + . = ALIGN(4); + + SDK_LTDOVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_LTDOVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAYTABLE_DIGEST =.; + . = . + 20; + SDK_OVERLAYTABLE_DIGEST_END =.; + SDK_OVERLAY_DIGEST =.; + . = . + * 20; + . = . + * 20; + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x02fe0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_AUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_AUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(32); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW SDK_OVERLAY_DIGEST - ADDR(.); + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > F + + ############################ ARENA ################################## + .dummy.MAIN_EX.NITRO: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.NITRO + + .arena.MAIN.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN.NITRO + + .arena.MAIN_EX.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + + } > arena.MAIN_EX.NITRO + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + + } > arena.DTCM + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + + } > check.ITCM + + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + . = . + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_EDN = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02800000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START = .; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDAUTOLOAD..SINIT_END = .; + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # compressed state + + + } > L + + ############################ ARENA ################################## + .dummy.MAIN_EX.TWL: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.TWL + + .arena.MAIN.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_ARENA_LO =.; + + } > arena.MAIN.TWL + + .arena.MAIN_EX.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_EX_ARENA_LO =.; + + } > arena.MAIN_EX.TWL + + ############################ OTHERS ################################# + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + + } > binary.MODULE_FILES + +} diff --git a/build/tests/RelocateChecker/ARM9/src/RelocateChecker.c b/build/tests/RelocateChecker/ARM9/src/RelocateChecker.c new file mode 100644 index 00000000..4cf960c2 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/src/RelocateChecker.c @@ -0,0 +1,152 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: RelocateChecker.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:: 2007-10-31#$ + $Rev: 91 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "misc.h" +#include "RelocateChecker.h" + +// define data------------------------------------------ +#define RETURN_BUTTON_TOP_X 2 +#define RETURN_BUTTON_TOP_Y 21 +#define RETURN_BUTTON_BOTTOM_X ( RETURN_BUTTON_TOP_X + 8 ) +#define RETURN_BUTTON_BOTTOM_Y ( RETURN_BUTTON_TOP_Y + 2 ) + +// extern data------------------------------------------ +extern u32 *begin_data_ARM9FLX; +extern u32 *begin_data_ARM9LTD; + +// function's prototype declaration--------------------- + +// global variable ------------------------------------- +RTCDrawProperty g_rtcDraw = { + TRUE, RTC_DATE_TOP_X, RTC_DATE_TOP_Y, RTC_TIME_TOP_X, RTC_TIME_TOP_Y +}; + +// static variable ------------------------------------- +static BOOL s_switch = FALSE; + +//static u32 dummy[1024*1024/2]={1,2,3,};//2MB + +// const data ----------------------------------------- + +//====================================================== +// Ĕzu`FbJ[i鎖͕\̂݁j +//====================================================== + +static void draw_sub1(u8 *ram_addr, u8 *header_addr, int y) +{ + int l; + PrintfSJIS(8,y,TXT_UCOLOR_DARKGREEN, "ARM9FLX ( VERIFY %s ) :",( (*(BOOL *)0x02000280) ? "OK" : "NG" )); + + for (l=0; l<20; l++) + { + PrintfSJIS(24+(l%10)*19, y+12+12*(l/10), TXT_COLOR_BLACK, "%.2x", *(ram_addr+l)); + if(s_switch) + { + PrintfSJIS(24+(l%10)*19, y+12+12*(l/10), (*(ram_addr+l) != *(header_addr+l)) ? TXT_COLOR_RED : TXT_COLOR_BLUE, "%.2x", *(header_addr+l)); + } + } +} + +static void draw_sub2(u8 *ram_addr, u8 *header_addr, int y, const u16 *str) +{ + int l; + PutStringUTF16(8,y,TXT_UCOLOR_DARKGREEN, str); + for (l=0; l<20; l++) + { + PrintfSJIS(24+(l%10)*19, y+12+12*(l/10), TXT_COLOR_BLACK, "%.2x", *(ram_addr+l)); + if(s_switch ) + { + PrintfSJIS(24+(l%10)*19, y+12+12*(l/10), (*(ram_addr+l) != *(header_addr+l)) ? TXT_COLOR_RED : TXT_COLOR_BLUE, "%.2x", *(header_addr+l)); + } + } +} + +static void encryObjdraw(void) +{ + int l; + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_WHITE ); + for (l=0; l<0x200; l++) + { + PrintfSJIS(24+(l%3)*66, 12*2+4+12+12*(l/3), TXT_COLOR_BLACK, "%.8x", *(((u32 *)0x02000280)+l) ); + } +} + +static void draw() +{ + NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_WHITE ); + + PutStringUTF16( 1 * 8, 0 * 8, TXT_COLOR_BLUE, (const u16 *)L"RelocateChecker"); + PutStringUTF16( 3 * 8, 1 * 12, TXT_COLOR_BLACK, (const u16 *)L"Press A to Check Digest...."); + + draw_sub1((u8 *)0x02000200, (u8 *)(HW_TWL_ROM_HEADER_BUF + 0x300), 12*2+4 ); + + draw_sub2((u8 *)0x02000220, (u8 *)(HW_TWL_ROM_HEADER_BUF + 0x314), 12*5+8, (const u16 *)L"ARM7FLX :" ); + draw_sub2((u8 *)0x02000240, (u8 *)(HW_TWL_ROM_HEADER_BUF + 0x350), 12*8+12, (const u16 *)L"ARM9LTD :" ); + draw_sub2((u8 *)0x02000260, (u8 *)(HW_TWL_ROM_HEADER_BUF + 0x364), 12*11+16, (const u16 *)L"ARM7LTD :" ); +} + +// +void RelocateCheckerInit( void ) +{ + GX_DispOff(); + GXS_DispOff(); + + draw(); + + GetAndDrawRTCData( &g_rtcDraw, TRUE ); + + GXS_SetVisiblePlane( GX_PLANEMASK_BG0 ); + GX_DispOn(); + GXS_DispOn(); +} + +static u32 c; +// C[v +void RelocateCheckerMain(void) +{ + BOOL tp_cancel = FALSE; + u32 a = (u32)begin_data_ARM9FLX; + u32 b = (u32)begin_data_ARM9LTD; + c = a+b; + + ReadTP(); // ^b`pl͂̎擾 + + // [RETURN]{^`FbN + if(tpd.disp.touch) { + tp_cancel = WithinRangeTP( RETURN_BUTTON_TOP_X * 8, RETURN_BUTTON_TOP_Y * 8 - 4, + RETURN_BUTTON_BOTTOM_X * 8, RETURN_BUTTON_BOTTOM_Y * 8 - 4, &tpd.disp ); + } + + if( ( pad.trg & PAD_BUTTON_A )) { + s_switch = !s_switch; + draw(); + } + + if( ( pad.trg & PAD_BUTTON_X )) { + encryObjdraw(); + } + + if( ( pad.trg & PAD_BUTTON_B ) || tp_cancel ) { +// SYSM_RebootLauncher(); + } + + GetAndDrawRTCData( &g_rtcDraw, FALSE ); +} + + diff --git a/build/tests/RelocateChecker/ARM9/src/RelocateChecker.h b/build/tests/RelocateChecker/ARM9/src/RelocateChecker.h new file mode 100644 index 00000000..5df076a0 --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/src/RelocateChecker.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: RelocateChecker.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-10-30#$ + $Rev: 73 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#ifndef __RELOCATE_CHECKER_H__ +#define __RELOCATE_CHECKER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +// define data---------------------------------------------------------- + +void RelocateCheckerInit( void ); +void RelocateCheckerMain( void ); + +#ifdef __cplusplus +} +#endif + +#endif // __RELOCATE_CHECKER_H__ diff --git a/build/tests/RelocateChecker/ARM9/src/main.c b/build/tests/RelocateChecker/ARM9/src/main.c new file mode 100644 index 00000000..e45155ca --- /dev/null +++ b/build/tests/RelocateChecker/ARM9/src/main.c @@ -0,0 +1,87 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-11-27#$ + $Rev: 272 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc.h" +#include "RelocateChecker.h" + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +static void INTR_VBlank( void ); + +// global variable------------------------------------------------------------- + +// static variable------------------------------------------------------------- + +// const data------------------------------------------------------------------ + + +// ============================================================================ +// function's description +// ============================================================================ +void TwlMain(void) +{ + + // ---------------------------------- + OS_Init(); + + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + GX_Init(); + GX_SetPower(GX_POWER_ALL); // eWbN p[ON + + // 荞݋---------------------------- + (void)OS_SetIrqFunction(OS_IE_V_BLANK, INTR_VBlank); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + + // foCX------------------------------- + TP_Init(); + (void)RTC_Init(); + + // VXȅ------------------ + OS_SetArenaHi(OS_ARENA_MAIN, (void *)0x02d00000);// arm9MMEMheap + InitAllocator(); + + InitBG(); + RelocateCheckerInit(); + // C[v---------------------------- + while(1){ + OS_WaitIrq(1, OS_IE_V_BLANK); // VuN荞ݑ҂ + + ReadKeyPad(); // L[͂̎擾 + ReadTP(); // TP͂̎擾 + + RelocateCheckerMain(); + } +} + + +// ============================================================================ +// 荞ݏ +// ============================================================================ + +// VuN荞 +static void INTR_VBlank(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // VuN`FbÑZbg +} + diff --git a/build/tests/RelocateChecker/Makefile b/build/tests/RelocateChecker/Makefile new file mode 100644 index 00000000..b0329da4 --- /dev/null +++ b/build/tests/RelocateChecker/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner crt ARM7 ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/banner/Makefile b/build/tests/RelocateChecker/banner/Makefile new file mode 100644 index 00000000..ea261271 --- /dev/null +++ b/build/tests/RelocateChecker/banner/Makefile @@ -0,0 +1,49 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/tests/RelocateChecker/banner/banner_v3.bsf b/build/tests/RelocateChecker/banner/banner_v3.bsf new file mode 100644 index 00000000..b0f7d965 Binary files /dev/null and b/build/tests/RelocateChecker/banner/banner_v3.bsf differ diff --git a/build/tests/RelocateChecker/banner/icon/gameIcon.bmp b/build/tests/RelocateChecker/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..8ec56f1c Binary files /dev/null and b/build/tests/RelocateChecker/banner/icon/gameIcon.bmp differ diff --git a/build/tests/RelocateChecker/buildtools/commondefs b/build/tests/RelocateChecker/buildtools/commondefs new file mode 100644 index 00000000..019292a6 --- /dev/null +++ b/build/tests/RelocateChecker/buildtools/commondefs @@ -0,0 +1,48 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - commondefs - common definitions for build system +# File: commondefs +# +# 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: 318 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- +ifndef TWL_RELOCATECHECKER_COMMONDEFS_ +TWL_RELOCATECHECKER_COMMONDEFS_ = TRUE + +#---------------------------------------------------------------------------- +# path settings +# + +FBDDIR = $(TWL_IPL_RED_ROOT)/build/tests/RelocateChecker/flabObj + +#---------------------------------------------------------------------------- +### TWL-commondefs +# +#include $(TWLSDK_ROOT)/build/buildtools/commondefs +#include $(NITROSYSTEM_ROOT)/build/buildtools/commondefs + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +ifneq ($(TARGET_FOB),) +TARGETS := $(TARGET_FOB) $(TARGETS) +endif + +#---------------------------------------------------------------------------- +# MY BUILD TOOLS +# + +MAKEFBD ?= $(FBDDIR)/incre.exe +MAKEFOB ?= $(TWLSDK_ROOT)/tools/bin/bin2obj.exe + +#---------------------------------------------------------------------------- +endif # TWL_RELOCATECHECKER_COMMONDEFS_ +#----- End of commondefs ----- diff --git a/build/tests/RelocateChecker/buildtools/modulerules b/build/tests/RelocateChecker/buildtools/modulerules new file mode 100644 index 00000000..0b008b21 --- /dev/null +++ b/build/tests/RelocateChecker/buildtools/modulerules @@ -0,0 +1,36 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - modulerules - common rules for build system +# File: modulerules +# +# 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: 290 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- +ifndef TWL_RELOCATECHECKER_MODULERULES_ + +#---------------------------------------------------------------------------- +### TWL-modulerules +# +#include $(TWLSDK_ROOT)/build/buildtools/modulerules +#include $(NITROSYSTEM_ROOT)/build/buildtools/modulerules +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + +#fob +%.fob: + $(MAKEFBD) $(FBDDIR)/$*.fbd $(FBDSIZE_$*) ;\ + $(MAKEFOB) -b begin_data_$* $(FBDDIR)/$*.fbd $(FBDDIR)/$@ + + +#---------------------------------------------------------------------------- +TWL_RELOCATECHECKER_MODULERULES_ = TRUE +endif # TWL_RELOCATECHECKER_MODULERULES_ +#----- End of modulerules ----- diff --git a/build/tests/RelocateChecker/crt/ARM7/@ b/build/tests/RelocateChecker/crt/ARM7/@ new file mode 100644 index 00000000..70a3b5c9 --- /dev/null +++ b/build/tests/RelocateChecker/crt/ARM7/@ @@ -0,0 +1 @@ +NINTENDO CONFIDENTIAL diff --git a/build/tests/RelocateChecker/crt/ARM7/Makefile b/build/tests/RelocateChecker/crt/ARM7/Makefile new file mode 100644 index 00000000..7336448f --- /dev/null +++ b/build/tests/RelocateChecker/crt/ARM7/Makefile @@ -0,0 +1,32 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK +# 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-09-18#$ +# $Rev: 947 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = Makefile.LTD + +override TARGET_PLATFORM = TWL + +#---------------------------------------------------------------------------- +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/crt/ARM7/Makefile.LTD b/build/tests/RelocateChecker/crt/ARM7/Makefile.LTD new file mode 100644 index 00000000..95731aed --- /dev/null +++ b/build/tests/RelocateChecker/crt/ARM7/Makefile.LTD @@ -0,0 +1,51 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - libraries - init - ARM7.TWL +# File: Makefile.LTD +# +# 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-11-16#$ +# $Rev: 2423 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM = TWL + +# Codegen for sub processer +override TWL_PROC = ARM7 + +# Avoid to use pre-compile-header of "nitro.h" +TWL_NO_STD_PCHDR = True + +# Avoid to build THUMB version object +override TWL_CODEGEN = ARM + +override TWL_ARCHGEN = LIMITED + +SRCDIR = ../common/src src +INCDIR = ../common/include + +SRCS = crt0_rc.LTD.c +TARGET_OBJ = crt0_rc.LTD.TWL.o + +MACRO_FLAGS += -DSDK_NOINIT + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +$(OBJDIR)/$(TARGET_OBJ): $(OBJDIR)/$(SRCS:.c=.o) + $(CP) $< $@ + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/crt/ARM7/src/crt0_rc.LTD.c b/build/tests/RelocateChecker/crt/ARM7/src/crt0_rc.LTD.c new file mode 100644 index 00000000..c2dd6201 --- /dev/null +++ b/build/tests/RelocateChecker/crt/ARM7/src/crt0_rc.LTD.c @@ -0,0 +1,757 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - libraries - init - ARM7.TWL + File: crt0.LTD.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:: 2007-11-28#$ + $Rev: 2690 $ + $Author: yada $ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include "boot_sync.h" + +/*---------------------------------------------------------------------------*/ +void _start(void); +void _start_AutoloadDoneCallback(void* argv[]); + +#define SDK_NITROCODE_LE 0x2106c0de +#define SDK_NITROCODE_BE 0xdec00621 + +#define SDK_TWLCODE_LE 0x6314c0de +#define SDK_TWLCODE_BE 0xdec01463 + +/* O֐Qƒ` */ +extern void OS_IrqHandler(void); +extern void _fp_init(void); +extern void __call_static_initializers(void); + +/* ֐vg^Cv` */ +static void INITi_SetHMACSHA1ToAppParam(void); +static void INITi_DoAutoload(void); +static void INITi_ShelterLtdBinary(void); +static void detect_main_memory_size(void); +#ifndef SDK_NOINIT +static void INITi_ShelterStaticInitializer(u32* ptr); +static void INITi_CallStaticInitializers(void); +#endif + +/* JXNvgɂ`V{Q */ +extern void SDK_AUTOLOAD_LIST(void); +extern void SDK_AUTOLOAD_LIST_END(void); +extern void SDK_AUTOLOAD_START(void); +extern void SDK_STATIC_BSS_START(void); +extern void SDK_STATIC_BSS_END(void); + +void* const _start_ModuleParams[] = +{ + (void*)SDK_AUTOLOAD_LIST, + (void*)SDK_AUTOLOAD_LIST_END, + (void*)SDK_AUTOLOAD_START, + (void*)SDK_STATIC_BSS_START, + (void*)SDK_STATIC_BSS_END, + (void*)0, // CompressedStaticEnd. This fixed number will be updated by compstatic tool. + (void*)0, // SDK_VERSION_ID // SDK version info /* [TODO] rhʂ */ + (void*)SDK_NITROCODE_BE, + (void*)SDK_NITROCODE_LE, +}; + +extern void SDK_LTDAUTOLOAD_LIST(void); +extern void SDK_LTDAUTOLOAD_LIST_END(void); +extern void SDK_LTDAUTOLOAD_START(void); + +void* const _start_LtdModuleParams[] = +{ + (void*)SDK_LTDAUTOLOAD_LIST, + (void*)SDK_LTDAUTOLOAD_LIST_END, + (void*)SDK_LTDAUTOLOAD_START, + (void*)0, // CompressedLtdautoloadEnd. This fixed number will be updated by compstatic tool. + (void*)SDK_TWLCODE_BE, + (void*)SDK_TWLCODE_LE, +}; + +#ifdef DEBUG_WRAM_SETTING +u32 const wramMapping[12] = { + 0x8d898581, 0x8c888480, 0x9c989490, 0x8c888480, + 0x9c989490, 0x00000000, 0x09403900, 0x09803940, + 0x080037c0, 0x09403900, 0x09803940, 0x0000000f +}; +#endif + +#define DIGEST_HASH_BLOCK_SIZE_SHA1 (512/8) +static const u8 s_digestDefaultKey[ DIGEST_HASH_BLOCK_SIZE_SHA1 ] = +{ + 0x21, 0x06, 0xc0, 0xde, + 0xba, 0x98, 0xce, 0x3f, + 0xa6, 0x92, 0xe3, 0x9d, + 0x46, 0xf2, 0xed, 0x01, + + 0x76, 0xe3, 0xcc, 0x08, + 0x56, 0x23, 0x63, 0xfa, + 0xca, 0xd4, 0xec, 0xdf, + 0x9a, 0x62, 0x78, 0x34, + + 0x8f, 0x6d, 0x63, 0x3c, + 0xfe, 0x22, 0xca, 0x92, + 0x20, 0x88, 0x97, 0x23, + 0xd2, 0xcf, 0xae, 0xc2, + + 0x32, 0x67, 0x8d, 0xfe, + 0xca, 0x83, 0x64, 0x98, + 0xac, 0xfd, 0x3e, 0x37, + 0x87, 0x46, 0x58, 0x24, +}; + +/* [TODO] + * TWL ̃}`u[g[_[ǂɏcĂ邩̂߁A + * rhʂ߂̂ł߂Ȓ`łB*/ +#define TWLIPL_PARAM_DOWNLOAD_PARAMETER 0x02ffb000 + +/*---------------------------------------------------------------------------* + Name: ShakeHand + Description: ARM9 ShakeHand ֐ƓB + CłȂԂŎsKvB + Arguments: r0 - ARM9 pϐւ̃|C^B + r1 - ARM7 pϐւ̃|C^B + Returns: ȂB + *---------------------------------------------------------------------------*/ +static const u32 microcode_ShakeHand[10] = +{ + 0xe1d020b0, /* ldrh r2, [r0] ; ϐXLǂ */ + 0xe1d130b0, /* ldrh r3, [r1] ; ϐVLǂ */ + 0xe2833001, /* @1: add r3, r3, #1 ; ϐV ++ */ + 0xe1c130b0, /* strh r3, [r1] ; ϐVLɏ */ + 0xe1d0c0b0, /* ldrh r12, [r0] ; ϐX̌Lǂ */ + 0xe152000c, /* cmp r2, r12 ; ϐX̕ω𔻒肷 */ + 0x0afffffa, /* beq @1 ; ωĂȂ΃[v */ + 0xe2833001, /* add r3, r3, #1 ; ϐV ++ */ + 0xe1c130b0, /* strh r3, [r1] ; ϐVLɏ */ + 0xe12fff1e /* bx lr ; nhVFCN */ +}; + +#ifdef DEBUG_WRAM_SETTING +/*---------------------------------------------------------------------------* + Name: WaitAgreement + Description: ARM9 ̋NxN^̏ԂɂȂ܂ő҂B + CłȂԂŎsKvB + Arguments: r0 - ptF[YǗϐւ̃|C^B + r1 - ҋ@tF[YԍB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static const u32 microcode_WaitAgreement[7] = +{ + 0xe1d020b0, /* @1: ldrh r2, [r0] ; tF[YǗϐLǂ */ + 0xe1510002, /* cmp r1, r2 ; ҋ@tF[YԍƔr */ + 0x012fff1e, /* bxeq lr ; vĂΑҋ@ */ + 0xe3a03010, /* mov r3, #16 ; 󃋁[v񐔏 */ + 0xe2533001, /* @2: subs r3, r3, #1 ; 󃋁[v -- */ + 0x1afffffd, /* bne @2 ; 16 񃋁[v */ + 0xeafffff8 /* b @1 ; 擪ɖ߂ */ +}; +#endif + +/*---------------------------------------------------------------------------* + Name: GotoMain + Description: ARM9 ɓ̏ԂɂȂƂ`ŁAMain ֐փWv + BCłȂԂŎsKvB + Arguments: r0 - Main ֐̃|C^BMain ֐ Thumb R[hłꍇ + ɂ́Abx ߂ŃWv邽ߍʼnʃrbg 1 ɂȂ + KvB + r1 - ptF[YǗϐւ̃|C^B + r2 - ARM9 ɓ`tF[YԍB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static const u32 microcode_GotoMain[2] = +{ + 0xe1c120b0, /* strh r2, [r1] ; tF[YǗϐXV */ + 0xe12fff10 /* bx r0 ; Main ֐փWv */ +}; + +/*---------------------------------------------------------------------------*/ +#include + +/*---------------------------------------------------------------------------* + Name: _start + Description: NxN^B + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL asm void +_start(void) +{ +@000: + /* 荞݋֎~ */ + mov r12, #HW_REG_BASE + str r12, [r12, #REG_IME_OFFSET] // Use that LSB of HW_REG_BASE is 0b0 + + /* nhVFCNp}CNR[hp WRAM ɃRs[ */ + ldr r1, =microcode_ShakeHand + ldr r2, =HW_PRV_WRAM + add r3, r2, #40 +@001: ldr r0, [r1], #4 + str r0, [r2], #4 + cmp r2, r3 + blt @001 + + /* p WRAM ̃R[h ARM9 ƃnhVFCN1 */ + ldr r0, =HW_BOOT_SHAKEHAND_9 + ldr r1, =HW_BOOT_SHAKEHAND_7 + ldr r2, =HW_PRV_WRAM + mov lr, pc + bx r2 + + // [hꂽAṽ_CWFXgvZăAvԃp[^Ɋi[ + bl INITi_SetHMACSHA1ToAppParam + +@010: + /* X^bN|C^ݒ */ + mov r0, #HW_PSR_SVC_MODE // SuperVisor mode + msr cpsr_c, r0 + ldr sp, =HW_PRV_WRAM_SVC_STACK_END + mov r0, #HW_PSR_IRQ_MODE // IRQ mode + msr cpsr_c, r0 + ldr sp, =HW_PRV_WRAM_IRQ_STACK_END + ldr r1, =SDK_IRQ_STACKSIZE + sub r1, sp, r1 + sub sp, sp, #4 // 4 bytes for stack check code + mov r0, #HW_PSR_SYS_MODE + msr cpsr_csfx, r0 + sub sp, r1, #4 // 4 bytes for stack check code + + /* X^bN̈NA */ + ldr r0, =SDK_SYS_STACKSIZE + sub r1, r1, r0 + ldr r2, =HW_PRV_WRAM_IRQ_STACK_END + mov r0, #0 +@011: cmp r1, r2 + strlt r0, [r1], #4 + blt @011 + + /* TWL n[hEFAœ삵Ă邩ǂ𒲍 */ + ldr r1, =REG_CLK_ADDR + ldrh r0, [r1] + tst r0, #REG_SCFG_CLK_WRAMHCLK_MASK + /* TWL n[hEFAœ삵ĂȂꍇ͉iv[v */ +@012: beq @012 + + /* _E[hp[^LGAɑޔ */ + ldr r1, =HW_DOWNLOAD_PARAMETER + ldr r2, =TWLIPL_PARAM_DOWNLOAD_PARAMETER + add r3, r2, #HW_DOWNLOAD_PARAMETER_SIZE +@013: ldr r0, [r2], #4 + str r0, [r1], #4 + cmp r2, r3 + blt @013 + + /* ̑M@\𓮍삳ݒs */ + ldr r1, =REG_WL_ADDR + ldrh r0, [r1] + orr r0, r0, #REG_SCFG_WL_OFFB_MASK + strh r0, [r1] + /* ARM7 DMA ɂ͐V DMA H̗pATEhɂV DMA H𗘗p */ + ldr r1, =REG_EXT_ADDR + ldr r0, [r1] + orr r0, r0, #REG_SCFG_EXT_DMAC_MASK + orr r0, r0, #REG_SCFG_EXT_DSEL_MASK + str r0, [r1] + /* [TODO] ARM7 łݒłȂlj I/O WX^̏ݒs */ + + + /* Autoload { */ + bl INITi_DoAutoload + +@020: + /* STATIC ubN .bss ZNV 0 NA */ + ldr r0, =_start_ModuleParams + ldr r1, [r0, #12] // SDK_STATIC_BSS_START + ldr r2, [r0, #16] // SDK_STATIC_BSS_END + mov r0, #0 +@021: cmp r1, r2 + strlt r0, [r1], #4 + blt @021 + + //---- detect main memory size + bl detect_main_memory_size + + /* 荞݃xN^ݒ */ + ldr r1, =HW_INTR_VECTOR_BUF + ldr r0, =OS_IrqHandler + str r0, [r1] + +#ifndef SDK_NOINIT + /* c++ p */ + bl _fp_init + bl TwlSpStartUp + bl __call_static_initializers + bl INITi_CallStaticInitializers +#endif + +@030: + /* Main ֐ւ̃Wvp}CNR[hX^bN̒ɃRs[ */ + ldr r1, =microcode_GotoMain + ldr r0, [r1], #4 + str r0, [sp, #-4] + ldr r0, [r1] + str r0, [sp] + + /* }CNR[hoR Main ֐փWv */ + ldr r0, =TwlSpMain + ldr r1, =HW_BOOT_SYNC_PHASE + mov r2, #BOOT_SYNC_PHASE_4 + ldr lr, =HW_RESET_VECTOR + sub r3, sp, #4 + bx r3 +} + +#include +#include +#include +/*---------------------------------------------------------------------------* + Name: INITi_SetHMACSHA1ToAppParam + Description: ROM[hꂽeAv̈HMACSHA1vZÃAh + Xɕۑ + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +#define UNDEF_CODE 0xe7ffdeff +#define ENCRYPT_DEF_SIZE 0x800 +#define DGT_TGT_ADDR ( HW_MAIN_MEM + 0x0200 ) + +static void INITi_SetHMACSHA1ToAppParam(void) +{ + u32 *arm9_flx_addr = (u32 *)(*(u32 *)(HW_TWL_ROM_HEADER_BUF + 0x028)); + u32 *p_arm9encryObjVerify = (u32 *)(DGT_TGT_ADDR + 4 * 32); + int l; + SVCHMACSHA1Context *pCon = ( SVCHMACSHA1Context * ) (0x2000400 - sizeof(SVCHMACSHA1Context)); + //SVCHMACSHA1Context *pCon = &Con; + + // arm9_flx + *p_arm9encryObjVerify = TRUE; + for( l=0; l + * 0x02f88000 crt0 yшiڃ[hoCizuĂB + * NITRO ƋL”\ WRAM ɔzuׂoCif[^ 0x037c0000 Ƀ[hB + * TWL ł삵Ȃ WRAM ɔzuׂoCif[^𑱂̃AhXɃ[hB + * 0x02e80000 ɓiڃ[hoCizuĂB + * 0x04000 oCg̓J[h ROM ēǂݏos‚Ȃ̂ŁA0x02f84000 - 0x02f88000 ɑޔB + * NITRO ƋL”\ MAIN ɔzuׂoCif[^ 0x02f88000 + sizeof(crt0) Ƀ[hB + * TWL ł삵Ȃ MAIN ɔzuׂoCif[^𑱂̃AhXɃ[hB + */ +static asm void +INITi_DoAutoload(void) +{ +@000: + stmdb sp!, {lr} + /* WRAM pubNI[g[h */ + ldr r1, =_start_ModuleParams + ldr r12, [r1] // r12 = SDK_AUTOLOAD_LIST + ldr r0, [r1, #4] // r0 = SDK_AUTOLOAD_LIST_END + ldr r1, [r1, #8] // r1 = SDK_AUTOLOAD_START +@001: cmp r12, r0 + bge @010 + /* ŒZNV[h */ + stmdb sp!, {r0} + ldr r2, [r12], #4 // r2 = start address of destination range + ldr r3, [r12], #4 // r3 = size of fixed section + add r3, r3, r2 // r3 = end address of destination range of fixed section +@002: cmp r2, r3 + ldrlt r0, [r1], #4 + strlt r0, [r2], #4 + blt @002 + /* static initializer e[uǂݏo */ + ldr r0, [r12], #4 // r0 = address of the table managing pointers of static initializers +#ifndef SDK_NOINIT + stmdb sp!, {r0-r3, r12} + bl INITi_ShelterStaticInitializer + ldmia sp!, {r0-r3, r12} +#endif + /* .bss ZNV 0 NA */ + mov r0, #0 + ldr r3, [r12], #4 // r3 = size of .bss section + add r3, r3, r2 // r3 = end address of destination range of .bss section +@003: cmp r2, r3 + strlt r0, [r2], #4 + blt @003 +@004: ldmia sp!, {r0} + b @001 + +@010: /* CpubN݂̑mF */ + ldr r1, =HW_TWL_ROM_HEADER_BUF + 0x1dc /* ARM7 pg풓W[ ROM TCY */ + ldr r0, [r1] + cmp r0, #0 + beq @020 + + /* ēǂݏos•ޔ */ + //bl INITi_ShelterLtdBinary + + /* CpubNI[g[h */ + ldr r1, =_start_LtdModuleParams + ldr r12, [r1] // r12 = SDK_LTDAUTOLOAD_LIST + ldr r0, [r1, #4] // r0 = SDK_LTDAUTOLOAD_LIST_END + ldr r1, [r1, #8] // r1 = SDK_LTDAUTOLOAD_START +@011: cmp r12, r0 + bge @020 + /* ŒZNV[h */ + stmdb sp!, {r0} + ldr r2, [r12], #4 // r2 = start address of destination range + ldr r3, [r12], #4 // r3 = size of fixed section + add r3, r3, r2 // r3 = end address of destination range of fixed section +@012: cmp r2, r3 + ldrlt r0, [r1], #4 + strlt r0, [r2], #4 + blt @012 + /* static initializer e[uǂݏo */ + ldr r0, [r12], #4 // r0 = address of the table managing pointers of static initializers +#ifndef SDK_NOINIT + stmdb sp!, {r0-r3, r12} + bl INITi_ShelterStaticInitializer + ldmia ap!, {r0-r3, r12} +#endif + /* .bss ZNV 0 NA */ + mov r0, #0 + ldr r3, [r12], #4 // r3 = size of .bss section + add r3, r3, r2 // r3 = end address of destination range of .bss section +@013: cmp r2, r3 + strlt r0, [r2], #4 + blt @013 +@014: ldmia sp!, {r0} + b @011 + +@020: /* I[g[hR[obN֐Ăяo */ + ldr r0, =_start_ModuleParams + ldr r1, =_start_LtdModuleParams + ldmia sp!, {lr} + b _start_AutoloadDoneCallback +} + +/*---------------------------------------------------------------------------* + Name: INITi_ShelterLtdBinary + Description: TWL p̃I[g[hoCif[^̓AJ[h ROM + ēǂݏołȂ̈̃f[^ޔGAɑޔB + ēǂݏołȂ̈̃f[^ ARM7 p ARM9 p̊g풓 + W[̂Q‚ɕÔ\̂ŁA璷ł͂邪 + ̐擪 0x4000 ꂼޔB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_ShelterLtdBinary(void) +{ + /* ޔEAhX𒲍 */ + ldr r1, =HW_TWL_ROM_HEADER_BUF + 0x1d8 /* ARM7 pg풓W[ RAM AhX */ + ldr r1, [r1] + ldr r3, =HW_TWL_ROM_HEADER_BUF + 0x038 /* ARM7 p풓W[ RAM AhX */ + ldr r3, [r3] + sub r2, r3, #0x4000 /* ēǂݏos—̈TCY */ /* ARM7 pޔGA */ + + /* Rs[ */ +@loop: ldr r0, [r1], #4 + str r0, [r2], #4 + cmp r2, r3 + blt @loop + + bx lr +} + +#ifndef SDK_NOINIT +/*---------------------------------------------------------------------------* + Name: INITi_ShelterStaticInitializer + Description: eI[g[hZOg static initializer ւ̃|C^ + e[u IRQ X^bN̍ŏ㕔ɑޔB + Arguments: ptr - ZOg̃|C^e[uւ̃|C^B + e[u NULL ŏI[ĂKvB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_ShelterStaticInitializer(u32* ptr) +{ + /* mF */ + cmp r0, #0 + bxeq lr + + /* ޔꏊ擪AhXvZ */ + ldr r1, =HW_PRV_WRAM_IRQ_STACK_END + ldr r2, =SDK_IRQ_STACKSIZE + sub r1, r1, r2 + add r1, r1, #4 + + /* ޔꏊ擪󂫏ꏊ𒲍 */ +@001: ldr r2, [r1] + cmp r2, #0 + addne r1, r1, #4 + bne @001 + + /* 󂫏ꏊɃe[uRs[ */ +@002: ldr r2, [r0], #4 + str r2, [r1], #4 + cmp r2, #0 + bne @002 + + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_CallStaticInitializers + Description: eI[g[hZOg static initializer ĂяoB + I[g[hɂ IRQ X^bN̍ŏ㕔ɑޔĂ + ֐|C^e[u‚ŒĂяoB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_CallStaticInitializers(void) +{ + stmdb sp!, {lr} + + /* e[uޔꏊ擪AhXvZ */ + ldr r1, =HW_PRV_WRAM_IRQ_STACK_END + ldr r2, =SDK_IRQ_STACKSIZE + sub r1, r1, r2 + add r1, r1, #4 + + /* e[uɊǗĂ|C^‚ŒĂяo */ +@001: ldr r0, [r1] + cmp r0, #0 + beq @002 + stmdb sp!, {r1} + mov lr, pc + bx r0 + ldmia sp!, {r1} + /* UĂяo|C^̓[NA (IRQX^bNԎ؂肵Ă) */ + mov r0, #0 + str r0, [r1], #4 + b @001 + +@002: ldmia sp!, {lr} + bx lr +} +#endif + +/*---------------------------------------------------------------------------* + Name: _start_AutoloadDoneCallback + Description: I[g[hR[obNB + Arguments: argv - I[g[hp[^ێĂzB + argv[0] = SDK_AUTOLOAD_LIST + argv[1] = SDK_AUTOLOAD_LIST_END + argv[2] = SDK_AUTOLOAD_START + argv[3] = SDK_STATIC_BSS_START + argv[4] = SDK_STATIC_BSS_END + Returns: ȂB + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL asm void +_start_AutoloadDoneCallback(void* argv[]) +{ + bx lr +} + +/*---------------------------------------------------------------------------* + Name: detect_main_memory_size + + Description: detect main memory size. + result is written into (u32*)HW_MMEMCHECKER_SUB. + value is [OS_CONSOLE_SIZE_4MB|OS_CONSOLE_SIZE_8MB| + OS_CONSOLE_SIZE_16MB|OS_CONSOLE_SIZE_32MB] + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +#define OSi_IMAGE_DIFFERENCE 0x400000 +#define OSi_IMAGE_DIFFERENCE2 0xb000000 +#define OSi_DETECT_NITRO_MASK (REG_SND_SMX_CNT_E_MASK | REG_SND_SMX_CNT_FSEL_MASK) +#define OSi_DETECT_NITRO_VAL (REG_SND_SMX_CNT_E_MASK) + +static asm void detect_main_memory_size( void ) +{ +//################ temp: this process will be done in IPL + // SCFG enable? + ldr r2, =REG_EXT_ADDR + ldr r0, [r2] + tst r0, #0x80000000 + beq @9 + + ldr r2, =HW_PRV_WRAM_SYSRV + //OPT(bonding option) + ldr r3, =REG_OP_ADDR + ldrh r0, [r3] + strh r0, [r2, #8] + //OPT(JTAG info) + ldr r3, =REG_JTAG_ADDR + ldrb r0, [r3] + //CLK(only wram clock) + ldr r3, =REG_CLK_ADDR + ldrh r1, [r3] + and r1, r1, #0x80 + orr r0, r0, r1, LSR 1 + strb r0, [r2, #9] +@9: +//################ + + //---- copy scfg setting + ldr r2, =HW_PRV_WRAM_SYSRV + ldr r3, =HW_SYS_CONF_BUF + ldr r0, [r2, #HWi_WSYS04_WRAMOFFSET] + str r0, [r3, #HWi_WSYS04_OFFSET] + ldrh r0, [r2, #HWi_WSYS08_WRAMOFFSET] + strh r0, [r3, #HWi_WSYS08_OFFSET] + + //---- detect memory size + mov r0, #OS_CONSOLE_SIZE_4MB + mov r1, #0 + + ldr r2, =HW_MMEMCHECKER_SUB + sub r3, r2, #OSi_IMAGE_DIFFERENCE +@1: + strh r1, [r2] + ldrh r12, [r3] + cmp r1, r12 + bne @2 + + add r1, r1, #1 + cmp r1, #2 // check 2 loop + bne @1 + + //---- 4MB + b @4 + + //---- 8MB or 16MB or 32MB +@2: + // check if running on twl/nitro + ldr r1, =HW_SYS_CONF_BUF + ldrb r12, [r1,#HWi_WSYS09_OFFSET] + tst r12, #HWi_WSYS09_CLK_WRAMHCLK_MASK + moveq r0, #OS_CONSOLE_SIZE_8MB + beq @4 + + //---- 16MB or 32MB + mov r1, #0 + add r3, r2, #OSi_IMAGE_DIFFERENCE2 +@3: + strh r1, [r2] + ldrh r12, [r3] + cmp r1, r12 + + movne r0, #OS_CONSOLE_SIZE_32MB + bne @4 + + add r1, r1, #1 + cmp r1, #2 // check 2 loop + bne @3 + mov r0, #OS_CONSOLE_SIZE_16MB +@4: + //---- check SMX_CNT + ldr r3, =REG_SMX_CNT_ADDR + ldrh r1, [r3] + and r1, r1, #OSi_DETECT_NITRO_MASK + cmp r1, #OSi_DETECT_NITRO_VAL + orreq r0, r0, #OS_CHIPTYPE_SMX_MASK + + strb r0, [r2] + bx lr +} + +/*---------------------------------------------------------------------------* + Name: NitroSpStartUp + Description: Hook for user start up. + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL void +NitroSpStartUp(void) +{ +} + +#include diff --git a/build/tests/RelocateChecker/crt/ARM9/Makefile b/build/tests/RelocateChecker/crt/ARM9/Makefile new file mode 100644 index 00000000..03385d14 --- /dev/null +++ b/build/tests/RelocateChecker/crt/ARM9/Makefile @@ -0,0 +1,32 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK +# 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-09-18#$ +# $Rev: 947 $ +# $Author: hatamoto_minoru $ +#---------------------------------------------------------------------------- + +SUBDIRS = +SUBMAKES = Makefile.FLX + +override TARGET_PLATFORM = TWL + +#---------------------------------------------------------------------------- +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/crt/ARM9/Makefile.FLX b/build/tests/RelocateChecker/crt/ARM9/Makefile.FLX new file mode 100644 index 00000000..e026a0a7 --- /dev/null +++ b/build/tests/RelocateChecker/crt/ARM9/Makefile.FLX @@ -0,0 +1,53 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - libraries - init - ARM9.TWL +# File: Makefile.FLX +# +# 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-11-06#$ +# $Rev: 2142 $ +# $Author: terui $ +#---------------------------------------------------------------------------- + +override TARGET_PLATFORM = TWL + +# Codegen for main processer +override TWL_PROC = ARM9 + +# Avoid to build THUMB version object +override TWL_CODEGEN = ARM + +# Avoid to build LIMITED version object +override TWL_ARCHGEN = HYBRID + +# Avoid to use pre-compile-header of "nitro.h" +TWL_NO_STD_PCHDR = True + +# build ARM & THUMB libraries +TWL_CODEGEN ?= ALL + +SRCDIR = ../common/src src +INCDIR = ../common/include + +SRCS = crt0_rc.FLX.c +TARGET_OBJ = crt0_rc.FLX.TWL.o + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +$(OBJDIR)/$(TARGET_OBJ): $(OBJDIR)/$(SRCS:.c=.o) + $(CP) $< $@ + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/crt/ARM9/src/crt0.c b/build/tests/RelocateChecker/crt/ARM9/src/crt0.c new file mode 100644 index 00000000..cf90ef6f --- /dev/null +++ b/build/tests/RelocateChecker/crt/ARM9/src/crt0.c @@ -0,0 +1,647 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK + File: crt0.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:: 2007-07-31#$ + $Rev: 387 $ + $Author: terui $ + *---------------------------------------------------------------------------*/ +#include +#include + +extern void NitroMain(void); +extern void OS_IrqHandler(void); +static void do_autoload(void); +static void init_cp15(void); +void _start(void); +static void INITi_CpuClear32(register u32 data, register void *destp, register u32 size); +extern void *const _start_ModuleParams[]; +void _start_AutoloadDoneCallback(void *argv[]); + +extern void __call_static_initializers(void); +extern void _fp_init(void); + +// from LCF +extern unsigned long SDK_IRQ_STACKSIZE[]; +extern void SDK_AUTOLOAD_START(void); // autoload data will start from here +extern void SDK_AUTOLOAD_LIST(void); // start pointer to autoload information +extern void SDK_AUTOLOAD_LIST_END(void); // end pointer to autoload information +extern void SDK_STATIC_BSS_START(void); // static bss start address +extern void SDK_STATIC_BSS_END(void); // static bss end address + +#include +#define SDK_VERSION_ID ((u32)SDK_VERSION_MAJOR<<24|\ + (u32)SDK_VERSION_MINOR<<16|\ + (u32)SDK_VERSION_RELSTEP) + +#define SDK_NITROCODE_LE 0x2106c0de +#define SDK_NITROCODE_BE 0xdec00621 + + +/*---------------------------------------------------------------------------* + Name: _start + + Description: Start up + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +#define INITi_HW_DTCM SDK_AUTOLOAD_DTCM_START + +SDK_WEAK_SYMBOL asm void _start( void ) +{ + //---- set IME = 0 + // ( use that LSB of HW_REG_BASE equal to 0 ) + mov r12, #HW_REG_BASE + str r12, [r12, #REG_IME_OFFSET] + + //---- adjust VCOUNT. +@wait_vcount_0: + ldrh r0, [r12, #REG_VCOUNT_OFFSET] + cmp r0, #0 + bne @wait_vcount_0 + + //---- initialize cp15 + bl init_cp15 + + //---- initialize stack pointer + // SVC mode + mov r0, #HW_PSR_SVC_MODE + msr cpsr_c, r0 + ldr r0, =INITi_HW_DTCM + add r0, r0, #0x3fc0 + mov sp, r0 + + // IRQ mode + mov r0, #HW_PSR_IRQ_MODE + msr cpsr_c, r0 + ldr r0, =INITi_HW_DTCM + add r0, r0, #0x3fc0 + sub r0, r0, #HW_SVC_STACK_SIZE + sub sp, r0, #4 // 4byte for stack check code + tst sp, #4 + subeq sp, sp, #4 // for 8byte-alignment + + // System mode + ldr r1, =SDK_IRQ_STACKSIZE + sub r1, r0, r1 + mov r0, #HW_PSR_SYS_MODE + msr cpsr_csfx, r0 + sub sp, r1, #4 // 4byte for stack check code + + //---- clear memory + // DTCM (16KB) + mov r0, #0 + ldr r1, =INITi_HW_DTCM + mov r2, #HW_DTCM_SIZE + bl INITi_CpuClear32 + + // BG/OBJ palette (1KB) + mov r0, #0 + ldr r1, =HW_PLTT + mov r2, #HW_PLTT_SIZE + bl INITi_CpuClear32 + + // OAM (1KB) + mov r0, #0x0200 + ldr r1, =HW_OAM + mov r2, #HW_OAM_SIZE + bl INITi_CpuClear32 + + //---- load autoload block and initialize bss + ldr r1, =_start_ModuleParams + ldr r0, [r1, #20] // r0 = bottom of compressed data + bl MIi_UncompressBackward + bl do_autoload + + //---- fill static static bss with 0 + ldr r0, =_start_ModuleParams + ldr r1, [r0, #12] // BSS segment start + ldr r2, [r0, #16] // BSS segment end + mov r3, r1 // for next step(flush bss) + mov r0, #0 +@1: cmp r1, r2 + strcc r0, [r1], #4 + bcc @1 + + //---- flush static bss region + // (r0 == #0, r3 == _start_ModuleParams::BSS_segment_start) + bic r1, r3, #HW_CACHE_LINE_SIZE - 1 +@cacheflush: + mcr p15, 0, r0, c7, c10, 4 // wait writebuffer empty + mcr p15, 0, r1, c7, c5, 1 // ICache + mcr p15, 0, r1, c7, c14, 1 // DCache + add r1, r1, #HW_CACHE_LINE_SIZE + cmp r1, r2 + blt @cacheflush + + // print buffer (used for ARM7's printing) + ldr r1, =HW_COMPONENT_PARAM + str r0, [r1, #0] + + //---- set interrupt vector + ldr r1, =INITi_HW_DTCM + add r1, r1, #0x3fc0 + add r1, r1, #HW_DTCM_SYSRV_OFS_INTR_VECTOR + ldr r0, =OS_IrqHandler + str r0, [r1, #0] + +#ifndef SDK_NOINIT + //---- for C++ + bl _fp_init + bl NitroStartUp + bl __call_static_initializers +#endif + //---- start (to 16bit code) + ldr r1, =NitroMain + ldr lr, =HW_RESET_VECTOR + + tst sp, #4 + subne sp, sp, #4 // for 8byte-alignment + bx r1 +} + + +/*---------------------------------------------------------------------------* + Name: INITi_CpuClear32 + + Description: fill memory with specified data. + 32bit version + + Arguments: data : fill data + destp : destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +static asm void INITi_CpuClear32( register u32 data, register void *destp, register u32 size ) +{ + add r12, r1, r2 // r12: destEndp = destp + size +@20: + cmp r1, r12 // while (destp < destEndp) + stmltia r1!, {r0} // *((vu32 *)(destp++)) = data + blt @20 + bx lr +} + + +/*---------------------------------------------------------------------------* + Name: _start_ModuleParams + + Description: autoload/compress/arguments data block + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void *const _start_ModuleParams[] = { + (void *)SDK_AUTOLOAD_LIST, + (void *)SDK_AUTOLOAD_LIST_END, + (void *)SDK_AUTOLOAD_START, + (void *)SDK_STATIC_BSS_START, + (void *)SDK_STATIC_BSS_END, + (void *)0, // CompressedStaticEnd + (void *)SDK_VERSION_ID, // SDK version info + (void *)SDK_NITROCODE_BE, // Checker 1 + (void *)SDK_NITROCODE_LE, // Checker 2 +}; + +/*---------------------------------------------------------------------------* + Name: MIi_UncompressBackward + + Description: Uncompress special archive for module compression + + Arguments: bottom = Bottom adrs of packed archive + 1 + bottom[-8..-6] = offset for top of compressed data + inp_top = bottom - bottom[-8..-6] + bottom[-5] = offset for bottom of compressed data + inp = bottom - bottom[-5] + bottom[-4..-1] = offset for bottom of original data + outp = bottom + bottom[-4..-1] + + typedef struct + { + u32 bufferTop:24; + u32 compressBottom:8; + u32 originalBottom; + } CompFooter; + + Returns: None. + *---------------------------------------------------------------------------*/ +asm void MIi_UncompressBackward( register void* bottom ) +{ +#define data r0 +#define inp_top r1 +#define outp r2 +#define inp r3 +#define outp_save r4 +#define flag r5 +#define count8 r6 +#define index r7 +#define len r12 + cmp bottom, #0 + beq @exit + stmfd sp!, {r4-r7} + ldmdb bottom, {r1-r2} + add outp, bottom, outp + sub inp, bottom, inp_top, LSR #24 + bic inp_top, inp_top, #0xff000000 + sub inp_top, bottom, inp_top + mov outp_save, outp +@loop: + cmp inp, inp_top // exit if inp==inp_top + ble @end_loop + ldrb flag, [inp, #-1]! // r4 = compress_flag = *--inp + mov count8, #8 +@loop8: + subs count8, count8, #1 + blt @loop + tst flag, #0x80 + bne @blockcopy +@bytecopy: + ldrb data, [inp, #-1]! +#ifdef SDK_TEG + sub outp, outp, #1 + swpb data, data, [outp] +#else + strb data, [outp, #-1]! // Copy 1 byte +#endif + b @joinhere +@blockcopy: + ldrb len, [inp, #-1]! + ldrb index, [inp, #-1]! + orr index, index, len, LSL #8 + bic index, index, #0xf000 + add index, index, #0x0002 + add len, len, #0x0020 +@patterncopy: + ldrb data, [outp, index] +#ifdef SDK_TEG + sub outp, outp, #1 + swpb data, data, [outp] +#else + strb data, [outp, #-1]! +#endif + subs len, len, #0x0010 + bge @patterncopy + +@joinhere: + cmp inp, inp_top + mov flag, flag, LSL #1 + bgt @loop8 +@end_loop: + + // DC_FlushRange & IC_InvalidateRange + mov r0, #0 + bic inp, inp_top, #HW_CACHE_LINE_SIZE - 1 +@cacheflush: + mcr p15, 0, r0, c7, c10, 4 // wait writebuffer empty + mcr p15, 0, inp, c7, c5, 1 // ICache + mcr p15, 0, inp, c7, c14, 1 // DCache + add inp, inp, #HW_CACHE_LINE_SIZE + cmp inp, outp_save + blt @cacheflush + + ldmfd sp!, {r4-r7} +@exit bx lr +} + + +/*---------------------------------------------------------------------------* + Name: do_autoload + + Description: put autoload data block according to autoload information, + and clear static bss by filling with 0. + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static asm void do_autoload( void ) +{ +#define ptable r0 +#define infop r1 +#define infop_end r2 +#define src r3 +#define dest r4 +#define dest_begin r5 +#define dest_end r6 +#define tmp r7 + + ldr ptable, =_start_ModuleParams + ldr infop, [ptable, #0] // r1 = start pointer to autoload_info + ldr infop_end, [ptable, #4] // r2 = end pointer to autoload_info + ldr src, [ptable, #8] // r3 = autoload block + +@2: + cmp infop, infop_end // reach to end? + beq @skipout + + ldr dest_begin,[infop], #4 // dest_begin + ldr tmp, [infop], #4 // size + add dest_end, dest_begin, tmp // dest_end + mov dest, dest_begin // dest working pointer +@1: + cmp dest, dest_end + ldrmi tmp, [src], #4 // [dest++] <- [src++] + strmi tmp, [dest], #4 + bmi @1 + + //---- fill bss with 0 + ldr tmp, [infop], #4 // size + add dest_end, dest, tmp // bss end + mov tmp, #0 +@3: + cmp dest, dest_end + strcc tmp, [dest], #4 + bcc @3 + + //---- cache work (DC_FlushRange & IC_InvalidateRange) + bic dest, dest_begin, #HW_CACHE_LINE_SIZE - 1 +@cacheflush: + mcr p15, 0, tmp, c7, c10, 4 /* wait writebuffer empty */ + mcr p15, 0, dest, c7, c5, 1 // ICache + mcr p15, 0, dest, c7, c14, 1 // DCache + add dest, dest, #HW_CACHE_LINE_SIZE + cmp dest, dest_end + blt @cacheflush + + b @2 + +@skipout: + // r0 = _start_ModuleParams + b _start_AutoloadDoneCallback // Jump into the callback +} + +/*---------------------------------------------------------------------------* + Name: _start_AutoloadDoneCallback + + Description: hook for end of autoload (This is dummy target for DEBUGGER) + + Arguments: argv: pointer for autoload parameters + argv[0] = SDK_AUTOLOAD_LIST + argv[1] = SDK_AUTOLOAD_LIST_END + argv[2] = SDK_AUTOLOAD_START + argv[3] = SDK_STATIC_BSS_START + argv[4] = SDK_STATIC_BSS_END + + Returns: None. + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL asm void _start_AutoloadDoneCallback( void* argv[] ) +{ + bx lr +} + +//----------------------------------------------------------------------- +// VXeRvZbT +//----------------------------------------------------------------------- +static asm void init_cp15(void) +{ + // veNVjbg/LbV/TCM fBZ[u + + mrc p15, 0, r0, c1, c0, 0 + ldr r1, =HW_C1_ICACHE_ENABLE | HW_C1_DCACHE_ENABLE \ + | HW_C1_ITCM_ENABLE | HW_C1_DTCM_ENABLE \ + | HW_C1_ITCM_LOAD_MODE | HW_C1_DTCM_LOAD_MODE \ + | HW_C1_LD_INTERWORK_DISABLE \ + | HW_C1_PROTECT_UNIT_ENABLE + bic r0, r0, r1 + mcr p15, 0, r0, c1, c0, 0 + + // LbV + mov r0, #0 + mcr p15, 0, r0, c7, c5, 0 // ߃LbV + mcr p15, 0, r0, c7, c6, 0 // f[^LbV + + // Cgobt@ GveB҂ + mcr p15, 0, r0, c7, c10, 4 + +/* +; Region G: BACK_GROUND: Base = 0x0, Size = 4GB, I:NC NB / D:NC NB, I:NA / D:NA +; Region 0: IO_VRAM: Base = 0x04000000, Size = 64MB, I:NC NB / D:NC NB, I:RW / D:RW +; Region 1Rel: MAIN_MEM+W: Base = 0x02000000, Size = 32MB*, I:Cach Buf / D:Cach Buf, I:RW / D:RW +; Region 1Dbg: MAIN_MEM+W: Base = 0x02000000, Size = 32MB, I:Cach Buf / D:Cach Buf, I:RW / D:RW +; (* Size will be arranged in OS_InitArena(). ) +; Region 2Rel: SOUND_DATA: Base = 0x02380000, Size = 512KB, I:NC NB / D:NC NB, I:NA / D:NA +; Region 2D4M: SOUND_DATA: Base = 0x02300000, Size = 1MB, I:NC NB / D:NC NB, I:NA / D:NA +; Region 2D8M: SOUND_DATA: Base = 0x02600000, Size = 2MB, I:NC NB / D:NC NB, I:NA / D:NA +; Region 3: MAIN_MEM_HI: Base = 0x08000000, Size = 128MB, I:NC NB / D:NC NB, I:NA / D:RW +; Region 4: DTCM: Base = SOUND_DATA, Size = 16KB, I:NC NB / D:NC NB, I:NA / D:RW +; Region 5: ITCM: Base = 0x01000000, Size = 16MB, I:NC NB / D:NC NB, I:RW / D:RW + +; Region 6: BIOS: Base = 0xffff0000, Size = 32KB, I:Cach NB / D:Cach NB, I:RO / D:RO +; Region 7: SHARE_WORK: Base = 0x027ff000, Size = 4KB, I:NC NB / D:NC NB, I:NA / D:RW +;(Region 7: DBG_RESERVE: Base = 0x02700000, Size = 1MB, I:NC NB / D:NC NB, I:RW / D:RW) +*/ +#define SET_PROTECTION_A( id, adr, siz ) ldr r0, =(adr|HW_C6_PR_##siz|HW_C6_PR_ENABLE) +#define SET_PROTECTION_B( id, adr, siz ) mcr p15, 0, r0, c6, id, 0 +#define REGION_BIT(a,b,c,d,e,f,g,h) (((a)<<0)|((b)<<1)|((c)<<2)|((d)<<3)|((e)<<4)|((f)<<5)|((g)<<6)|((h)<<7)) +#define REGION_ACC(a,b,c,d,e,f,g,h) (((a)<<0)|((b)<<4)|((c)<<8)|((d)<<12)|((e)<<16)|((f)<<20)|((g)<<24)|((h)<<28)) +#define NA 0 +#define RW 1 +#define RO 5 + + + // + // [W + // + //---- I/O WX^ & VRAM + SET_PROTECTION_A( c0, HW_IOREG, 64MB ) + SET_PROTECTION_B( c0, HW_IOREG, 64MB ) + + //---- C + SET_PROTECTION_A( c1, HW_MAIN_MEM_MAIN, 32MB ) + SET_PROTECTION_B( c1, HW_MAIN_MEM_MAIN, 32MB ) + + //---- TEhf[^̈ +#if HW_MAIN_MEM_SUB_SIZE+HW_MAIN_MEM_SHARED_SIZE == 0x1000 + SET_PROTECTION_A( c2, HW_MAIN_MEM_SUB, 4KB ) + SET_PROTECTION_B( c2, HW_MAIN_MEM_SUB, 4KB ) +#elif HW_MAIN_MEM_SUB_SIZE+HW_MAIN_MEM_SHARED_SIZE == 0x2000 + SET_PROTECTION_A( c2, HW_MAIN_MEM_SUB, 8KB ) + SET_PROTECTION_B( c2, HW_MAIN_MEM_SUB, 8KB ) +#elif HW_MAIN_MEM_SUB_SIZE+HW_MAIN_MEM_SHARED_SIZE == 0x4000 + SET_PROTECTION_A( c2, HW_MAIN_MEM_SUB, 16KB ) + SET_PROTECTION_B( c2, HW_MAIN_MEM_SUB, 16KB ) +#elif HW_MAIN_MEM_SUB_SIZE+HW_MAIN_MEM_SHARED_SIZE == 0x8000 + SET_PROTECTION_A( c2, HW_MAIN_MEM_SUB, 32KB ) + SET_PROTECTION_B( c2, HW_MAIN_MEM_SUB, 32KB ) +#elif HW_MAIN_MEM_SUB_SIZE+HW_MAIN_MEM_SHARED_SIZE == 0x10000 + SET_PROTECTION_A( c2, HW_MAIN_MEM_SUB, 64KB ) + SET_PROTECTION_B( c2, HW_MAIN_MEM_SUB, 64KB ) +#elif HW_MAIN_MEM_SUB_SIZE+HW_MAIN_MEM_SHARED_SIZE == 0x20000 + SET_PROTECTION_A( c2, HW_MAIN_MEM_SUB, 128KB ) + SET_PROTECTION_B( c2, HW_MAIN_MEM_SUB, 128KB ) +#elif HW_MAIN_MEM_SUB_SIZE+HW_MAIN_MEM_SHARED_SIZE == 0x40000 + SET_PROTECTION_A( c2, HW_MAIN_MEM_SUB, 256KB ) + SET_PROTECTION_B( c2, HW_MAIN_MEM_SUB, 256KB ) +#elif HW_MAIN_MEM_SUB_SIZE+HW_MAIN_MEM_SHARED_SIZE == 0x80000 + SET_PROTECTION_A( c2, HW_MAIN_MEM_SUB, 512KB ) + SET_PROTECTION_B( c2, HW_MAIN_MEM_SUB, 512KB ) +#elif HW_MAIN_MEM_SUB_SIZE+HW_MAIN_MEM_SHARED_SIZE == 0x100000 + SET_PROTECTION_A( c2, HW_MAIN_MEM_SUB, 1MB ) + SET_PROTECTION_B( c2, HW_MAIN_MEM_SUB, 1MB ) +#elif HW_MAIN_MEM_SUB_SIZE+HW_MAIN_MEM_SHARED_SIZE == 0x200000 + SET_PROTECTION_A( c2, HW_MAIN_MEM_SUB, 2MB ) + SET_PROTECTION_B( c2, HW_MAIN_MEM_SUB, 2MB ) +#else +#pragma message(ERROR: Size unmatch HW_MAIN_MEM_SUB_SIZE) +#endif + +#if 0 + //---- J[gbW̗͑pr + // CPU [N RAM + SET_PROTECTION_A( c3, HW_CTRDG_ROM, 32MB ) + SET_PROTECTION_B( c3, HW_CTRDG_ROM, 32MB ) +#endif + //---- CʃC[W̗͑pr + // J[gbWACPU [N RAM + SET_PROTECTION_A( c3, HW_TWL_MAIN_MEM_IMAGE, 32MB ) + SET_PROTECTION_B( c3, HW_TWL_MAIN_MEM_IMAGE, 32MB ) + + //---- f[^ TCM + // + CPU [N RAM ̏ꍇ +//#if (HW_DTCM & 0x3FFF) != 0 +//#pragma message(ERROR: HW_DTCM need to be aligned 16KB!) +//#endif + +// SET_PROTECTION_A( c4, HW_DTCM, 16KB ) + ldr r0, =SDK_AUTOLOAD_DTCM_START + orr r0, r0, #HW_C6_PR_16KB + orr r0, r0, #HW_C6_PR_ENABLE + SET_PROTECTION_B( c4, HW_DTCM, 16KB ) + + //---- TCM + // f[^ TCM D悪AC̈܂ł̃C[W + SET_PROTECTION_A( c5, HW_ITCM_IMAGE, 16MB ) + SET_PROTECTION_B( c5, HW_ITCM_IMAGE, 16MB ) + + //---- BIOS + SET_PROTECTION_A( c6, HW_BIOS, 32KB ) + SET_PROTECTION_B( c6, HW_BIOS, 32KB ) + + //---- SHARED CPU ԒʐM[N̈ + SET_PROTECTION_A( c7, HW_MAIN_MEM_SHARED, 4KB ) + SET_PROTECTION_B( c7, HW_MAIN_MEM_SHARED, 4KB ) + +#if HW_MAIN_MEM_SHARED_SIZE != 0x1000 +#pragma message(ERROR: Size unmatch HW_MAIN_MEM_SHARED_SIZE) +#endif + + // + // ߂sbl ݒ + // + mov r0, #HW_C9_TCMR_32MB + mcr p15, 0, r0, c9, c1, 1 + + // + // f[^sbl ݒ + // + ldr r0, =INITi_HW_DTCM + orr r0, r0, #HW_C9_TCMR_16KB + mcr p15, 0, r0, c9, c1, 0 + + // + // ߃LbV Cl[u ([Wݒ) + // 1: MAIN_MEM + WRAM + // 3: MAIN_MEM_HI (or CTRDG) + // 6: BIOS + // + mov r0, #REGION_BIT(0,1,0,1,0,0,1,0) + mcr p15, 0, r0, c2, c0, 1 + + // + // f[^LbV Cl[u ([Wݒ) + // 1: MAIN_MEM + WRAM + // 3: MAIN_MEM_HI (or CTRDG) + // 6: BIOS + // + mov r0, #REGION_BIT(0,1,0,1,0,0,1,0) + mcr p15, 0, r0, c2, c0, 0 + + // + // Cgobt@ Cl[u([Wݒ) + // 1: MAIN_MEM + WRAM + // 3: MAIN_MEM (or CTRDG) + // + mov r0, #REGION_BIT(0,1,0,1,0,0,0,0) + mcr p15, 0, r0, c3, c0, 0 + + // + // ߃ANZX ([Wݒ) + // IO_VRAM : RW + // MAIN_MEM_MAIN : RW + // MAIN_MEM_SUB : NA + // MAIN_MEM_HI : RW + // DTCM : NA + // ITCM : RW + // BIOS : RO + // SHARED : NA + // + ldr r0, =REGION_ACC(RW,RW,NA,RW,NA,RW,RO,NA) + mcr p15, 0, r0, c5, c0, 3 + + // + // f[^ANZXi[Wݒj + // IO_VRAM : RW + // MAIN_MEM_MAIN : RW + // MAIN_MEM_SUB : NA + // MAIN_MEM_HI : RW + // DTCM : RW + // ITCM : RW + // BIOS : RO + // SHARED : RW + // + ldr r0, =REGION_ACC(RW,RW,NA,RW,RW,RW,RO,RW) + mcr p15, 0, r0, c5, c0, 2 + + // + // VXeRvZbT }X^[ݒ + // + mrc p15, 0, r0, c1, c0, 0 + ldr r1,=HW_C1_ICACHE_ENABLE | HW_C1_DCACHE_ENABLE | HW_C1_CACHE_ROUND_ROBIN \ + | HW_C1_ITCM_ENABLE | HW_C1_DTCM_ENABLE \ + | HW_C1_SB1_BITSET | HW_C1_EXCEPT_VEC_UPPER \ + | HW_C1_PROTECT_UNIT_ENABLE + orr r0, r0, r1 + mcr p15, 0, r0, c1, c0, 0 + + bx lr +} + + +/*---------------------------------------------------------------------------* + Name: NitroStartUp + + Description: hook for user start up + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL void NitroStartUp(void) +{ +} + +/*---------------------------------------------------------------------------* + Name: OSi_ReferSymbol + + Description: used by SDK_REFER_SYMBOL macro to avoid dead-strip. + + Arguments: symbol unused + + Returns: None. + *---------------------------------------------------------------------------*/ +void OSi_ReferSymbol(void *symbol) +{ +#pragma unused(symbol) +} diff --git a/build/tests/RelocateChecker/crt/ARM9/src/crt0_rc.FLX.c b/build/tests/RelocateChecker/crt/ARM9/src/crt0_rc.FLX.c new file mode 100644 index 00000000..b0c17b46 --- /dev/null +++ b/build/tests/RelocateChecker/crt/ARM9/src/crt0_rc.FLX.c @@ -0,0 +1,1007 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - libraries - init - ARM9.TWL + File: crt0_rc.FLX.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:: 2007-11-26#$ + $Rev: 2650 $ + $Author: nakasima $ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include "boot_sync.h" + +/*---------------------------------------------------------------------------*/ +void _start(void); +void _start_AutoloadDoneCallback(void* argv[]); + +#define SDK_NITROCODE_LE 0x2106c0de +#define SDK_NITROCODE_BE 0xdec00621 + +#define SDK_TWLCODE_LE 0x6314c0de +#define SDK_TWLCODE_BE 0xdec01463 + +/* O֐Qƒ` */ +extern void OS_IrqHandler(void); +extern void _fp_init(void); +extern void __call_static_initializers(void); + +/* ֐vg^Cv` */ +static void INITi_CpuClear32(register u32 data, register void* destp, register u32 size); +static void INITi_InitCoprocessor(void); +static void INITi_InitRegion(void); +static void INITi_DoAutoload(void); +static void INITi_ShelterLtdBinary(void); +#ifndef SDK_NOINIT +static void INITi_ShelterStaticInitializer(u32* ptr); +static void INITi_CallStaticInitializers(void); +#endif + +/* JXbNvgɂ`V{Q */ +extern void SDK_AUTOLOAD_LIST(void); +extern void SDK_AUTOLOAD_LIST_END(void); +extern void SDK_AUTOLOAD_START(void); +extern void SDK_STATIC_BSS_START(void); +extern void SDK_STATIC_BSS_END(void); + +void* const _start_ModuleParams[] = +{ + (void*)SDK_AUTOLOAD_LIST, + (void*)SDK_AUTOLOAD_LIST_END, + (void*)SDK_AUTOLOAD_START, + (void*)SDK_STATIC_BSS_START, + (void*)SDK_STATIC_BSS_END, + (void*)0, // CompressedStaticEnd. This fixed number will be updated by compstatic tool. + (void*)0, // SDK_VERSION_ID // SDK version info /* [TODO] rhʂ */ + (void*)SDK_NITROCODE_BE, + (void*)SDK_NITROCODE_LE, +}; + +extern void SDK_LTDAUTOLOAD_LIST(void); +extern void SDK_LTDAUTOLOAD_LIST_END(void); +extern void SDK_LTDAUTOLOAD_START(void); + +void* const _start_LtdModuleParams[] = +{ + (void*)SDK_LTDAUTOLOAD_LIST, + (void*)SDK_LTDAUTOLOAD_LIST_END, + (void*)SDK_LTDAUTOLOAD_START, + (void*)0, // CompressedLtdautoloadEnd. This fixed number will be updated by compstatic tool. + (void*)SDK_TWLCODE_BE, + (void*)SDK_TWLCODE_LE, +}; + +/*---------------------------------------------------------------------------* + Name: ShakeHand + Description: ARM7 ShakeHand ֐ƓB + CłȂԂŎsKvB + Arguments: r0 - ARM9 pϐւ̃|C^B + r1 - ARM7 pϐւ̃|C^B + Returns: ȂB + *---------------------------------------------------------------------------*/ +static const u32 microcode_ShakeHand[10] = +{ + 0xe1d120b0, /* ldrh r2, [r1] ; ϐVLǂ */ + 0xe1d030b0, /* ldrh r3, [r0] ; ϐXLǂ */ + 0xe2833001, /* @1: add r3, r3, #1 ; ϐX++ */ + 0xe1c030b0, /* strh r3, [r0] ; ϐXLɏ */ + 0xe1d1c0b0, /* ldrh r12, [r1] ; ϐV̌Lǂ */ + 0xe152000c, /* cmp r2, r12 ; ϐV̕ω𔻒肷 */ + 0x0afffffa, /* beq @1 ; ωĂȂ΃[v */ + 0xe2833001, /* add r3, r3, #1 ; ϐX++ */ + 0xe1c030b0, /* strh r3, [r0] ; ϐXLɏ */ + 0xe12fff1e /* bx lr ; nhVFCN */ +}; + +/*---------------------------------------------------------------------------* + Name: WaitAgreement + Description: ARM7 ̋NxN^̏ԂɂȂ܂ő҂B + CłȂԂŎsKvB + Arguments: r0 - ptF[YǗϐւ̃|C^B + r1 - ҋ@tF[YԍB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static const u32 microcode_WaitAgreement[7] = +{ + 0xe1d020b0, /* @1: ldrh r2, [r0] ; tF[YǗϐLǂ */ + 0xe1510002, /* cmp r1, r2 ; ҋ@tF[YԍƔr */ + 0x012fff1e, /* bxeq lr ; vĂΑҋ@ */ + 0xe3a03010, /* mov r3, #16 ; 󃋁[v񐔏 */ + 0xe2533001, /* @2: subs r3, r3, #1 ; 󃋁[v -- */ + 0x1afffffd, /* bne @2 ; 16 񃋁[v */ + 0xeafffff8 /* b @1 ; 擪ɖ߂ */ +}; + +/*---------------------------------------------------------------------------* + Name: SwitchCpuClock + Description: ARM9 CPU RA̓NbNύXB + I-TCM ŎsKvB + Arguments: r0 - ؂ւ鑬x[hB + ( 0: / 0ȊO: { ) + r1 - NbNύXҋ@TCNB + Returns: r0 - ύXȎx[hԂB + ( 0: / 1: { ) + *---------------------------------------------------------------------------*/ +static const u32 microcode_SwitchCpuClock[13] = +{ + 0xe3500000, /* cmp r0, #0 ; P] */ + 0xe59f3024, /* ldr r3, [pc, #36] ; REG_CLK_ADDR 萔ǂݍ */ + 0xe1d300b0, /* ldrh r0, [r3] ; REG_CLK_ADDR eǂݍ */ + 0x03c02001, /* biceq r2, r0, #1 ; ւ̕ύX REG_SCFG_CLK_CPUSPD_MASK tO */ + 0x13802001, /* orrne r2, r0, #1 ; {ւ̕ύX REG_SCFG_CLK_CPUSPD_MASK tOグ */ + 0xe1500002, /* cmp r0, r2 ; REG_CLK_ADDR eύXKv] */ + 0xe2000001, /* and r0, r0, #1 ; ֐߂lҏW */ + 0x012fff1e, /* bxeq lr ; ύXKvȂꍇ͊֐I */ + 0xe1c320b0, /* strh r2, [r3] ; REG_CLK_ADDR ɕύXe */ + 0xe2511004, /* @1: subs r1, r1, #4 ; 1 cycle ; 󃋁[v -- */ + 0xaafffffd, /* bge @1 ; 3 cycles or 1 cycle ; (ҋ@TCN / 4) 񃋁[v ; NbNύX */ + 0xe12fff1e, /* bx lr ; 2 cycleڂŕ悩疽߃tFb` */ + 0x04004004 /* REG_CLK_ADDR ; REG_CLK_ADDR 萔` */ +}; + +/*---------------------------------------------------------------------------*/ +#include + +/*---------------------------------------------------------------------------* + Name: _start + Description: NxN^B + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL asm void +_start(void) +{ + +@000: + /* 荞݋֎~ */ + mov r12, #HW_REG_BASE + str r12, [r12, #REG_IME_OFFSET] // Use that LSB of HW_REG_BASE is 0b0 + + /* VXeRvZbT */ + bl INITi_InitCoprocessor + + // IPL̏ԂJo[邽߂̏ + + // (1) J[h̃ZbgMď + ldr r1, =REG_MCCNT1_ADDR + mov r0, #REG_MI_MCCNT1_A_RESB_MASK + str r0, [r1] + + // (2) shared̈̃[NA + mov r0, #0 + ldr r1, =HW_PXI_SIGNAL_PARAM_ARM9 + ldr r2, =(HW_MAIN_MEM_SYSTEM+HW_MAIN_MEM_SYSTEM_SIZE-HW_PXI_SIGNAL_PARAM_ARM9) + bl INITi_CpuClear32 + + /* nhVFCNp}CNR[h ITCM ɃRs[ */ + ldr r1, =microcode_ShakeHand + ldr r2, =HW_ITCM + add r3, r2, #40 +@001: ldr r0, [r1], #4 + str r0, [r2], #4 + cmp r2, r3 + blt @001 + + /* ITCM ̃R[h ARM7 ƃnhVFCN1 */ + ldr r0, =HW_BOOT_SYNC_PHASE + mov r1, #BOOT_SYNC_PHASE_1 + strh r1, [r0] + ldr r0, =HW_BOOT_SHAKEHAND_9 + ldr r1, =HW_BOOT_SHAKEHAND_7 + ldr r2, =HW_ITCM + blx r2 + + /* ARM7 Ƃ̓҂p}CNR[h ITCM ɏ㏑Rs[ */ + ldr r1, =microcode_WaitAgreement + ldr r2, =HW_ITCM + add r3, r2, #28 +@002: ldr r0, [r1], #4 + str r0, [r2], #4 + cmp r2, r3 + blt @002 + +@003: + /* ARM7 Ɠ */ + ldr r0, =HW_BOOT_SYNC_PHASE + mov r1, #BOOT_SYNC_PHASE_4 + ldr r2, =HW_ITCM + blx r2 + +@010: + /* TWL n[hEFAœ삵Ă邩ǂ𒲍 */ + ldr r1, =REG_CLK_ADDR + ldrh r0, [r1] + tst r0, #REG_SCFG_CLK_WRAMHCLK_MASK + beq @020 + + /* {[hւ̕ύXp}CNR[h ITCM ɃRs[ */ + ldr r1, =microcode_SwitchCpuClock + ldr r2, =HW_ITCM + add r2, r2, #28 + mov r3, #52 +@011: subs r3, r3, #4 + ldr r0, [r1, r3] + str r0, [r2, r3] + bgt @011 + /* CPU NbN{[h֕ύX */ + mov r0, #REG_SCFG_CLK_CPUSPD_MASK + mov r1, #8 + blx r2 + + /* [TODO] ARM9 łݒłȂlj I/O WX^̏ݒs */ + +@020: + /* [Wݒ */ + bl INITi_InitRegion + + /* X^bN|C^ݒ */ + mov r0, #HW_PSR_SVC_MODE // SuperVisor mode + msr cpsr_c, r0 + ldr r1, =SDK_AUTOLOAD_DTCM_START + add r1, r1, #HW_DTCM_SIZE + sub sp, r1, #HW_DTCM_SYSRV_SIZE + sub r1, sp, #HW_SVC_STACK_SIZE + mov r0, #HW_PSR_IRQ_MODE // IRQ mode + msr cpsr_c, r0 + sub sp, r1, #4 // 4 bytes for stack check code + tst sp, #4 + subeq sp, sp, #4 /* IRQ nhɃWv_ sp 8byte ACɂȂ悤ɒ */ + ldr r0, =SDK_IRQ_STACKSIZE + sub r1, r1, r0 + mov r0, #HW_PSR_SYS_MODE // System mode + msr cpsr_csfx, r0 + sub sp, r1, #4 // 4 bytes for stack check code + tst sp, #4 + subne sp, sp, #4 /* Main ֐ɃWv_ sp 8byte ACɂȂ悤ɒ */ + + /* X^bN̈NA */ + mov r0, #0 + ldr r1, =SDK_AUTOLOAD_DTCM_START + mov r2, #HW_DTCM_SIZE + bl INITi_CpuClear32 + + /* VRAM 0 NA */ + mov r0, #0 + ldr r1, =HW_PLTT + mov r2, #HW_PLTT_SIZE + bl INITi_CpuClear32 + mov r0, #0 + ldr r1, =HW_OAM + mov r2, #HW_OAM_SIZE + bl INITi_CpuClear32 + + /* Autoload { */ + bl INITi_DoAutoload + + /* STATIC ubN .bss ZNV 0 NA */ + mov r0, #0 + ldr r3, =_start_ModuleParams + ldr r1, [r3, #12] // SDK_STATIC_BSS_START + ldr r2, [r3, #16] // SDK_STATIC_BSS_END + sub r2, r2, r1 + bl INITi_CpuClear32 + + /* 荞݃xN^ݒ */ + ldr r1, =SDK_AUTOLOAD_DTCM_START + add r1, r1, #HW_DTCM_SIZE - HW_DTCM_SYSRV_SIZE + add r1, r1, #HW_DTCM_SYSRV_OFS_INTR_VECTOR + ldr r0, =OS_IrqHandler + str r0, [r1] + +#ifndef SDK_NOINIT + /* c++ p */ + bl _fp_init + bl TwlStartUp + bl __call_static_initializers + bl INITi_CallStaticInitializers +#endif + + /* V JEg */ + ldr r1, =REG_VCOUNT_ADDR +@021: ldrh r0, [r1] + cmp r0, #0 + bne @021 + +@030: + /* Main ֐փWv */ + ldr r1, =TwlMain + ldr lr, =HW_RESET_VECTOR + bx r1 +} + +/*---------------------------------------------------------------------------* + Name: INITi_CpuClear32 + Description: 32 bit PʂŃobt@̃NAsB + Arguments: r0 - NAlB + r1 - NAւ̃|C^B + r2 - AăNAobt@B + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_CpuClear32(register u32 data, register void* destp, register u32 size) +{ + add r12, r1, r2 +@001: cmp r1, r12 + strlt r0, [r1], #4 + blt @001 + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_InitCoprocessor + Description: VXeRvZbTB + ɁAI-TCM y D-TCM gp”\ȏԂɂB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_InitCoprocessor(void) +{ + /* RvZbT̏Ԏ擾 */ + mrc p15, 0, r0, c1, c0, 0 + + tst r0, #HW_C1_PROTECT_UNIT_ENABLE + beq @010 + tst r0, #HW_C1_DCACHE_ENABLE + beq @003 + + /* D-Cache eɃCgobN */ + mov r1, #0 +@001: mov r2, #0 +@002: orr r3, r1, r2 + mcr p15, 0, r3, c7, c10, 2 + add r2, r2, #HW_CACHE_LINE_SIZE + cmp r2, #HW_DCACHE_SIZE / 4 + blt @002 + adds r1, r1, #1 << HW_C7_CACHE_SET_NO_SHIFT + bne @001 + +@003: /* Cgobt@ɂȂ̂҂ */ + mov r1, #0 + mcr p15, 0, r1, c7, c10, 4 + +@010: /* RvZbT̏Ԃ */ + ldr r1, = HW_C1_ITCM_LOAD_MODE \ + | HW_C1_DTCM_LOAD_MODE \ + | HW_C1_ITCM_ENABLE \ + | HW_C1_DTCM_ENABLE \ + | HW_C1_LD_INTERWORK_DISABLE \ + | HW_C1_ICACHE_ENABLE \ + | HW_C1_DCACHE_ENABLE \ + | HW_C1_PROTECT_UNIT_ENABLE + bic r0, r0, r1 + ldr r1, = HW_C1_SB1_BITSET \ + | HW_C1_EXCEPT_VEC_UPPER + orr r0, r0, r1 + mcr p15, 0, r0, c1, c0, 0 + + /* I-TCM ̃TCYݒ */ + mov r1, #HW_C9_TCMR_32MB + mcr p15, 0, r1, c9, c1, 1 + /* D-TCM ̃TCYyї̈x[XAhXݒ */ + ldr r1, =SDK_AUTOLOAD_DTCM_START + orr r1, r1, #HW_C9_TCMR_16KB + mcr p15, 0, r1, c9, c1, 0 + + /* I-TCM / D-TCM gpݒ */ + mov r1, #HW_C1_ITCM_ENABLE | HW_C1_DTCM_ENABLE + orr r0, r0, r1 + mcr p15, 0, r0, c1, c0, 0 + + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_InitRegion + Description: [WݒsB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +/* When hardware is TWL +; Region G: BACK_GROUND: Base = 0x0, Size = 4GB, I:NC NB / D:NC NB, I:NA / D:NA +; Region 0: IO_VRAM: Base = 0x04000000, Size = 64MB, I:NC NB / D:NC NB, I:RW / D:RW +; Region 1: MAINMEM_WRAM: Base = 0x02000000, Size = 32MB, I:Cach Buf / D:Cach Buf, I:RW / D:RW +; Region 2: ARM7_RESERVE: Base = 0x02f80000, Size = 512KB, I:NC NB / D:NC NB, I:NA / D:NA +; Region 3: EX_MAINMEM: Base = 0x0d000000, Size = 16MB, I:Cach Buf / D:Cach Buf, I:RW / D:RW +; Region 4: DTCM: Base = 0x02fe0000, Size = 16KB, I:NC NB / D:NC NB, I:NA / D:RW +; Region 5: ITCM: Base = 0x01000000, Size = 16MB, I:NC NB / D:NC NB, I:RW / D:RW +; Region 6: BIOS: Base = 0xffff0000, Size = 32KB, I:Cach NB / D:Cach NB, I:RO / D:RO +; Region 7: SHARED_WORK: Base = 0x02ffc000, Size = 16KB, I:NC NB / D:NC NB, I:NA / D:RW +*/ +/* When hardware is NITRO +; Region G: BACK_GROUND: Base = 0x0, Size = 4GB, I:NC NB / D:NC NB, I:NA / D:NA +; Region 0: IO_VRAM: Base = 0x04000000, Size = 64MB, I:NC NB / D:NC NB, I:RW / D:RW +; Region 1: MAIN_MEM: Base = 0x02000000, Size = 8MB*, I:Cach Buf / D:Cach Buf, I:RW / D:RW +; (* When hardware is not debugger, size will be reduced to 4MB in OS_InitArena() ) +;// Region 2: ARM7_RESERVE: Base = 0x027e0000, Size = 128KB, I:NC NB / D:NC NB, I:NA / D:NA +;// (* When hardware is not debugger, base will be moved to 0x023e0000 in OS_InitArena() ) +; Region 2: SHARED_WORK: Base = 0x027ff000, Size = 4KB, I:NC NB / D:NC NB, I:NA / D:RW +; Region 3: CARTRIDGE: Base = 0x08000000, Size = 128MB, I:NC NB / D:NC NB, I:NA / D:RW +; Region 4: DTCM: Base = 0x02fe0000, Size = 16KB, I:NC NB / D:NC NB, I:NA / D:RW +; Region 5: ITCM: Base = 0x01000000, Size = 16MB, I:NC NB / D:NC NB, I:RW / D:RW +; Region 6: BIOS: Base = 0xffff0000, Size = 32KB, I:Cach NB / D:Cach NB, I:RO / D:RO +; Region 7: SHARED_WORK: Base = 0x02fff000, Size = 4KB, I:NC NB / D:NC NB, I:NA / D:RW +*/ + +static asm void +INITi_InitRegion(void) +{ +#define SET_PROTECTION_A(id, adr, siz) ldr r0, =(adr|HW_C6_PR_##siz|HW_C6_PR_ENABLE) +#define SET_PROTECTION_B(id, adr, siz) mcr p15, 0, r0, c6, id, 0 +#define REGION_BIT(a, b, c, d, e, f, g, h) (((a) << 0) | ((b) << 1) | ((c) << 2) | ((d) << 3) | ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7)) +#define REGION_ACC(a, b, c, d, e, f, g, h) (((a) << 0) | ((b) << 4) | ((c) << 8) | ((d) << 12) | ((e) << 16) | ((f) << 20) | ((g) << 24) | ((h) << 28)) +#define NA 0 +#define RW 1 +#define RO 5 + + /* (0) I/O WX^y VRAM */ + SET_PROTECTION_A(c0, HW_IOREG, 64MB) + SET_PROTECTION_B(c0, HW_IOREG, 64MB) + + /* (4) D-TCM */ + ldr r0, =SDK_AUTOLOAD_DTCM_START + orr r0, r0, #HW_C6_PR_16KB | HW_C6_PR_ENABLE + SET_PROTECTION_B(c4, SDK_AUTOLOAD_DTCM_START, 16KB) + + /* (5) I-TCM */ + SET_PROTECTION_A(c5, HW_ITCM_IMAGE, 16MB) + SET_PROTECTION_B(c5, HW_ITCM_IMAGE, 16MB) + + /* (6) VXeR[ ROM */ + SET_PROTECTION_A(c6, HW_BIOS, 32KB) + SET_PROTECTION_B(c6, HW_BIOS, 32KB) + + /* TWL n[hEFAœ삵Ă邩ǂ𒲍 */ + ldr r1, =REG_CLK_ADDR + ldrh r0, [r1] + tst r0, #REG_SCFG_CLK_WRAMHCLK_MASK + beq @002 + +@001: /* n[hEFA TWL ̏ꍇ */ + /* (1) Cy WRAM */ + SET_PROTECTION_A(c1, HW_TWL_MAIN_MEM_MAIN, 32MB) + SET_PROTECTION_B(c1, HW_TWL_MAIN_MEM_MAIN, 32MB) + + /* (2) ARM7 pC */ + SET_PROTECTION_A(c2, HW_TWL_MAIN_MEM_SUB, 512KB) + SET_PROTECTION_B(c2, HW_TWL_MAIN_MEM_SUB, 512KB) + + /* (3) gC */ + SET_PROTECTION_A(c3, HW_TWL_MAIN_MEM_EX, 16MB) + SET_PROTECTION_B(c3, HW_TWL_MAIN_MEM_EX, 16MB) + + /* (7) ARM9/ARM7 LC */ + SET_PROTECTION_A(c7, HW_TWL_MAIN_MEM_SHARED, 16KB) + SET_PROTECTION_B(c7, HW_TWL_MAIN_MEM_SHARED, 16KB) + + /* ߃LbV */ + mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 1, 0) + mcr p15, 0, r0, c2, c0, 1 + + /* f[^LbV */ + mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 1, 0) + mcr p15, 0, r0, c2, c0, 0 + + /* Cgobt@ */ + mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 0, 0) + mcr p15, 0, r0, c3, c0, 0 + + /* ߃ANZX */ + ldr r0, =REGION_ACC(RW, RW, NA, RW, NA, RW, RO, NA) + mcr p15, 0, r0, c5, c0, 3 + + /* f[^ANZX */ + ldr r0, =REGION_ACC(RW, RW, NA, RW, RW, RW, RO, RW) + mcr p15, 0, r0, c5, c0, 2 + + b @003 + +@002: /* n[hEFA NITRO ̏ꍇ */ + /* (1) C */ + //SET_PROTECTION_A(c1, HW_MAIN_MEM_MAIN, 8MB) + //SET_PROTECTION_B(c1, HW_MAIN_MEM_MAIN, 8MB) + SET_PROTECTION_A(c1, HW_MAIN_MEM_MAIN, 32MB) + SET_PROTECTION_B(c1, HW_MAIN_MEM_MAIN, 32MB) + /* Size will be arranged in OS_InitArena(). */ + + /* (2) ARM7 pC */ + //SET_PROTECTION_A(c2, (HW_MAIN_MEM_EX_END - HW_MAIN_MEM_SHARED_SIZE - HW_MAIN_MEM_SUB_SIZE), 128KB) + //SET_PROTECTION_B(c2, (HW_MAIN_MEM_EX_END - HW_MAIN_MEM_SHARED_SIZE - HW_MAIN_MEM_SUB_SIZE), 128KB) + SET_PROTECTION_A(c2, (HW_MAIN_MEM_IM_SHARED_END - HW_MAIN_MEM_IM_SHARED_SIZE), 4KB) + SET_PROTECTION_B(c2, (HW_MAIN_MEM_IM_SHARED_END - HW_MAIN_MEM_IM_SHARED_SIZE), 4KB) + /* Base address will be moved in OS_InitArena(). */ + + /* (3) J[gbW */ + //SET_PROTECTION_A(c3, HW_CTRDG_ROM, 128MB) + //SET_PROTECTION_B(c3, HW_CTRDG_ROM, 128MB) + SET_PROTECTION_A(c3, HW_CTRDG_ROM, 32MB) + SET_PROTECTION_B(c3, HW_CTRDG_ROM, 32MB) + + /* (7) ARM9/ARM7 LC */ + SET_PROTECTION_A(c7, HW_MAIN_MEM_SHARED, 4KB) + SET_PROTECTION_B(c7, HW_MAIN_MEM_SHARED, 4KB) + + /* ߃LbV */ + //mov r0, #REGION_BIT(0, 1, 0, 0, 0, 0, 1, 0) + mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 1, 0) + mcr p15, 0, r0, c2, c0, 1 + + /* f[^LbV */ + //mov r0, #REGION_BIT(0, 1, 0, 0, 0, 0, 1, 0) + mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 1, 0) + mcr p15, 0, r0, c2, c0, 0 + + /* Cgobt@ */ + //mov r0, #REGION_BIT(0, 1, 0, 0, 0, 0, 0, 0) + mov r0, #REGION_BIT(0, 1, 0, 1, 0, 0, 0, 0) + mcr p15, 0, r0, c3, c0, 0 + + /* ߃ANZX */ + //ldr r0, =REGION_ACC(RW, RW, NA, NA, NA, RW, RO, NA) + ldr r0, =REGION_ACC(RW, RW, NA, RW, NA, RW, RO, NA) + mcr p15, 0, r0, c5, c0, 3 + + /* f[^ANZX */ + ldr r0, =REGION_ACC(RW, RW, RW, RW, RW, RW, RO, RW) + mcr p15, 0, r0, c5, c0, 2 + +@003: /* veNVjbgyуLbVgpݒ */ + mrc p15, 0, r0, c1, c0, 0 + ldr r1, = HW_C1_ICACHE_ENABLE \ + | HW_C1_DCACHE_ENABLE \ + | HW_C1_CACHE_ROUND_ROBIN \ + | HW_C1_PROTECT_UNIT_ENABLE + orr r0, r0, r1 + mcr p15, 0, r0, c1, c0, 0 + + /* LbV̓ej */ + mov r1, #0 + mcr p15, 0, r1, c7, c6, 0 + mcr p15, 0, r1, c7, c5, 0 + + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_DoAutoload + Description: NɉāAeI[g[hubŇŒf[^̓WJ + yѕϐ 0 NAsB4M bytes z PSRAM + ɔzuI[g[hubN̓WJ́An[hEFA TWL + ꍇɂsBI[g[hf[^ƃI[g[h悪ꕔ + dȂꍇ̂ŁAWJsB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +/* + * < iKI[g[h > + * 0x02000000 Static ZOgyшiڃ[hoCi(KvɉČ㔼k)zuĂB + * kĂꍇ́A܂ 0x02000000 Ɍ㏑‚‰𓀂B + * NITRO ƋL”\ ITCM ɔzuׂoCif[^ 0x01ff8000 Ƀ[hB + * NITRO ƋL”\ DTCM ɔzuׂoCif[^ 0x02fe0000 Ƀ[hB + * 0x02400000 ɓiڃ[hoCi(KvɉđSĈk)zuĂB + * 0x04000 oCg̓J[h ROM ēǂݏos‚Ȃ̂ŁA0x02f80000 - 0x02f84000 ɑޔB + * kĂꍇ́A܂ 0x02400000 Ɍ㏑‚‰𓀂B + * TWL ł삵Ȃ WRAM ɔzuׂoCif[^ꂼwAhXɃ[hB + * TWL ł삵ȂCɔzuׂoCif[^ORs[邱ƂŃ[hB + * ́ANITRO ƋL”\ȃCɔzuf[^ 0x02400000 zȂ͂ł邽߁A + * zuׂAhX 0x02400000 菬AhXɂȂ͂łׁB + * ܂AI[g[h񃊃Xg̎̂Cւ̃I[g[hubN .bss ZNṼNẢߒ + * j󂳂”\邪AÃI[g[h̍Ō̒iKȂ̂ŁAj󂳂ĂȂB + */ +static asm void +INITi_DoAutoload(void) +{ +@000: + stmdb sp!, {lr} + /* NITRO pubN̉ */ + ldr r1, =_start_ModuleParams + ldr r0, [r1, #20] // r0 = bottom of compressed data + bl MIi_UncompressBackward + +@010: + /* NITRO pubNI[g[h */ + ldr r1, =_start_ModuleParams + ldr r12, [r1] // r12 = SDK_AUTOLOAD_LIST + ldr r0, [r1, #4] // r0 = SDK_AUTOLOAD_LIST_END + ldr r1, [r1, #8] // r1 = SDK_AUTOLOAD_START +@011: cmp r12, r0 + bge @020 + /* ŒZNV[h */ + stmdb sp!, {r0} + ldr r2, [r12], #4 // r2 = start address of destination range + stmdb sp!, {r2} + ldr r3, [r12], #4 // r3 = size of fixed section + add r3, r3, r2 // r3 = end address of destination range of fixed section +@012: cmp r2, r3 + ldrlt r0, [r1], #4 + strlt r0, [r2], #4 + blt @012 + /* static initializer e[uǂݏo */ + ldr r0, [r12], #4 // r0 = address of the table managing pointers of static initializers +#ifndef SDK_NOINIT + stmdb sp!, {r0-r3, r12} + bl INITi_ShelterStaticInitializer + ldmia sp!, {r0-r3, r12} +#endif + /* .bss ZNV 0 NA */ + mov r0, #0 // r0 = number to fill .bss section + ldr r3, [r12], #4 // r3 = size of .bss section + add r3, r3, r2 // r3 = end address of destination range of .bss section +@013: cmp r2, r3 + strlt r0, [r2], #4 + blt @013 + /* LbV𒲐 */ + ldmia sp!, {r2} // r2 = start address of destination range + mov r0, #HW_ITCM_IMAGE + cmp r2, r0 + movge r0, #HW_ITCM_END + cmpge r0, r2 + bgt @015 // If I-TCM autoload block, skip cache control logic. + ldr r0, =SDK_AUTOLOAD_DTCM_START + cmp r2, r0 + addge r0, r0, #HW_DTCM_SIZE + cmpge r0, r2 + bgt @015 // If D-TCM autoload block, skip cache control logic. + bic r2, r2, #HW_CACHE_LINE_SIZE - 1 // RoundDown32 +@014: cmp r2, r3 + bge @015 + mcr p15, 0, r2, c7, c14, 1 // Store and Invalidate D-Cache + mcr p15, 0, r2, c7, c5, 1 // Invalidate I-Cache + add r2, r2, #HW_CACHE_LINE_SIZE + b @014 +@015: ldmia sp!, {r0} + b @011 + +@020: + /* TWL n[hEFAœ삵Ă邩ǂ𒲍 */ + ldr r1, =REG_CLK_ADDR + ldrh r0, [r1] + tst r0, #REG_SCFG_CLK_WRAMHCLK_MASK + beq @030 + + /* TWL pubN݂̑mF */ + ldr r1, =HW_TWL_ROM_HEADER_BUF + 0x1cc /* ARM9 pg풓W[ ROM TCY */ + ldr r0, [r1] + cmp r0, #0 + beq @030 + + /* ēǂݏos•ޔ */ + bl INITi_ShelterLtdBinary + + /* TWL pubN̉ */ + ldr r1, =_start_LtdModuleParams + ldr r0, [r1, #12] + bl MIi_UncompressBackward + + /* TWL pubNI[g[h */ + ldr r1, =_start_LtdModuleParams + ldr r12, [r1] // r12 = SDK_LTDAUTOLOAD_LIST + ldr r0, [r1, #4] // r0 = SDK_LTDAUTOLOAD_LIST_END + ldr r1, [r1, #8] // r1 = SDK_LTDAUTOLOAD_START +@021: cmp r12, r0 + bge @030 + /* ŒZNV[h */ + stmdb sp!, {r0} + ldr r2, [r12], #4 // r2 = start address of destination range + stmdb sp!, {r2} + ldr r3, [r12], #4 // r3 = size of fixed section + add r3, r3, r2 // r3 = end address of destination range of fixed section +@022: cmp r2, r3 + ldrlt r0, [r1], #4 + strlt r0, [r2], #4 + blt @022 + /* static initializer e[uǂݏo */ + ldr r0, [r12], #4 // r0 = address of the table managing pointers of static initializers +#ifndef SDK_NOINIT + stmdb sp!, {r0-r3, r12} + bl INITi_ShelterStaticInitializer + ldmia sp!, {r0-r3, r12} +#endif + /* .bss ZNV 0 NA */ + mov r0, #0 // r0 = number to fill .bss section + ldr r3, [r12], #4 // r3 = size of .bss section + add r3, r3, r2 // r3 = end address of destination range of .bss section +@023: cmp r2, r3 + strlt r0, [r2], #4 + blt @023 + /* LbV𒲐 */ + ldmia sp!, {r2} // r2 = start address of destination range + mov r0, #HW_ITCM_IMAGE + cmp r2, r0 + movge r0, #HW_ITCM_END + cmpge r0, r2 + bgt @025 // If I-TCM autoload block, skip cache control logic. + ldr r0, =SDK_AUTOLOAD_DTCM_START + cmp r2, r0 + addge r0, r0, #HW_DTCM_SIZE + cmpge r0, r2 + bgt @025 // If D-TCM autoload block, skip cache control logic. + bic r2, r2, #HW_CACHE_LINE_SIZE - 1 // RoundDown32 +@024: cmp r2, r3 + bge @025 + mcr p15, 0, r2, c7, c14, 1 // Store and Invalidate D-Cache + mcr p15, 0, r2, c7, c5, 1 // Invalidate I-Cache + add r2, r2, #HW_CACHE_LINE_SIZE + b @024 +@025: ldmia sp!, {r0} + b @021 + +@030: /* Cgobt@ɂȂ̂҂ */ + mov r0, #0 + mcr p15, 0, r0, c7, c10, 4 + + /* I[g[hR[obN֐Ăяo */ + ldr r0, =_start_ModuleParams + ldr r1, =_start_LtdModuleParams + ldmia sp!, {lr} + b _start_AutoloadDoneCallback +} + +/*---------------------------------------------------------------------------* + Name: INITi_ShelterLtdBinary + Description: TWL p̃I[g[hoCif[^̓AJ[h ROM + ēǂݏołȂ̈̃f[^ޔGAɑޔB + ēǂݏołȂ̈̃f[^ ARM7 p ARM9 p̊g풓 + W[̂Q‚ɕÔ\̂ŁA璷ł͂邪 + ̐擪 0x4000 ꂼޔB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_ShelterLtdBinary(void) +{ + /* ARM7 pCԕی샊[WUANZX”\ɕύX */ + mrc p15, 0, r0, c5, c0, 3 + mrc p15, 0, r1, c5, c0, 2 + stmdb sp!, {r0, r1} + bic r0, r0, #(0xf << 8) + orr r0, r0, #(0x1 << 8) + bic r1, r1, #(0xf << 8) + orr r1, r1, #(0x1 << 8) + mcr p15, 0, r0, c5, c0, 3 + mcr p15, 0, r1, c5, c0, 2 + + /* ޔEAhX𒲍 */ + ldr r1, =HW_TWL_ROM_HEADER_BUF + 0x1c8 /* ARM9 pg풓W[ RAM AhX */ + ldr r1, [r1] + ldr r3, =HW_TWL_ROM_HEADER_BUF + 0x038 /* ARM7 p풓W[ RAM AhX */ + ldr r3, [r3] + sub r3, r3, #0x4000 /* ēǂݏos—̈TCY */ /* ARM7 pޔGA */ + sub r2, r3, #0x4000 /* ēǂݏos—̈TCY */ /* ARM9 pޔGA */ + + /* Rs[ */ +@loop: ldr r0, [r1], #4 + str r0, [r2], #4 + cmp r2, r3 + blt @loop + + /* ARM7 pCԕی샊[Wݒɖ߂ */ + ldmia sp!, {r0, r1} + mcr p15, 0, r0, c5, c0, 3 + mcr p15, 0, r1, c5, c0, 2 + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_ShelterStaticInitializer + Description: eI[g[hZOg static initializer ւ̃|C^ + e[u IRQ X^bN̍ŏ㕔 ( 4 oCg炵ʒu) + ɑޔB + Arguments: ptr - ZOg̃|C^e[uւ̃|C^B + e[u NULL ŏI[ĂKvB + Returns: ȂB + *---------------------------------------------------------------------------*/ +#ifndef SDK_NOINIT +static asm void +INITi_ShelterStaticInitializer(u32* ptr) +{ + /* mF */ + cmp r0, #0 + bxeq lr + + /* ޔꏊ擪AhXvZ */ + ldr r1, =SDK_AUTOLOAD_DTCM_START + add r1, r1, #HW_DTCM_SIZE + sub r1, r1, #HW_DTCM_SYSRV_SIZE + sub r1, r1, #HW_SVC_STACK_SIZE + ldr r2, =SDK_IRQ_STACKSIZE + sub r1, r1, r2 + add r1, r1, #4 + + /* ޔꏊ擪󂫏ꏊ𒲍 */ +@001: ldr r2, [r1] + cmp r2, #0 + addne r1, r1, #4 + bne @001 + + /* 󂫏ꏊɃe[uRs[ */ +@002: ldr r2, [r0], #4 + str r2, [r1], #4 + cmp r2, #0 + bne @002 + + bx lr +} + +/*---------------------------------------------------------------------------* + Name: INITi_CallStaticInitializers + Description: eI[g[hZOg static initializer ĂяoB + I[g[hɂ IRQ X^bN̍ŏ㕔 ( 4 oCg + 炵ʒu) ɑޔĂ֐|C^e[u‚ + ĂяoB + Arguments: ȂB + Returns: ȂB + *---------------------------------------------------------------------------*/ +static asm void +INITi_CallStaticInitializers(void) +{ + stmdb sp!, {lr} + + /* e[uޔꏊ擪AhXvZ */ + ldr r1, =SDK_AUTOLOAD_DTCM_START + add r1, r1, #HW_DTCM_SIZE + sub r1, r1, #HW_DTCM_SYSRV_SIZE + sub r1, r1, #HW_SVC_STACK_SIZE + ldr r2, =SDK_IRQ_STACKSIZE + sub r1, r1, r2 + add r1, r1, #4 + + /* e[uɊǗĂ|C^‚ŒĂяo */ +@001: ldr r0, [r1] + cmp r0, #0 + beq @002 + stmdb sp!, {r1} + blx r0 + ldmia sp!, {r1} + /* UĂяo|C^̓[NA (IRQX^bNԎ؂肵Ă) */ + mov r0, #0 + str r0, [r1], #4 + b @001 + +@002: + ldmia sp!, {lr} + bx lr +} +#endif + +/*---------------------------------------------------------------------------* + Name: MIi_UncompressBackward + Description: Uncompress special archive for module compression. + Arguments: bottom = Bottom adrs of packed archive + 1 + bottom[-8..-6] = offset for top of compressed data + inp_top = bottom - bottom[-8..-6] + bottom[-5] = offset for bottom of compressed data + inp = bottom - bottom[-5] + bottom[-4..-1] = offset for bottom of original data + outp = bottom + bottom[-4..-1] + typedef struct + { + u32 bufferTop:24; + u32 compressBottom:8; + u32 originalBottom; + } CompFooter; + Returns: None. + *---------------------------------------------------------------------------*/ +asm void +MIi_UncompressBackward(register void* bottom) +{ +#define data r0 +#define inp_top r1 +#define outp r2 +#define inp r3 +#define outp_save r4 +#define flag r5 +#define count8 r6 +#define index r7 +#define len r12 + + cmp bottom, #0 + beq @exit + stmfd sp!, {r4-r7} + ldmdb bottom, {r1-r2} + add outp, bottom, outp + sub inp, bottom, inp_top, LSR #24 + bic inp_top, inp_top, #0xff000000 + sub inp_top, bottom, inp_top + mov outp_save, outp +@loop: + cmp inp, inp_top // exit if inp==inp_top + ble @end_loop + ldrb flag, [inp, #-1]! // r4 = compress_flag = *--inp + mov count8, #8 +@loop8: + subs count8, count8, #1 + blt @loop + tst flag, #0x80 + bne @blockcopy +@bytecopy: + ldrb data, [inp, #-1]! + strb data, [outp, #-1]! // Copy 1 byte + b @joinhere +@blockcopy: + ldrb len, [inp, #-1]! + ldrb index, [inp, #-1]! + orr index, index, len, LSL #8 + bic index, index, #0xf000 + add index, index, #0x0002 + add len, len, #0x0020 +@patterncopy: + ldrb data, [outp, index] + strb data, [outp, #-1]! + subs len, len, #0x0010 + bge @patterncopy + +@joinhere: + cmp inp, inp_top + mov flag, flag, LSL #1 + bgt @loop8 +@end_loop: + + // DC_FlushRange & IC_InvalidateRange + mov r0, #0 + bic inp, inp_top, #HW_CACHE_LINE_SIZE - 1 +@cacheflush: + mcr p15, 0, r0, c7, c10, 4 // wait writebuffer empty + mcr p15, 0, inp, c7, c5, 1 // ICache + mcr p15, 0, inp, c7, c14, 1 // DCache + add inp, inp, #HW_CACHE_LINE_SIZE + cmp inp, outp_save + blt @cacheflush + + ldmfd sp!, {r4-r7} +@exit bx lr +} + +/*---------------------------------------------------------------------------* + Name: _start_AutoloadDoneCallback + Description: I[g[hR[obNB + Arguments: argv - I[g[hp[^ێĂzB + argv[0] = SDK_AUTOLOAD_LIST + argv[1] = SDK_AUTOLOAD_LIST_END + argv[2] = SDK_AUTOLOAD_START + argv[3] = SDK_STATIC_BSS_START + argv[4] = SDK_STATIC_BSS_END + Returns: ȂB + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL asm void +_start_AutoloadDoneCallback(void* argv[]) +{ + bx lr +} + +/*---------------------------------------------------------------------------* + Name: NitroStartUp + Description: Hook for user start up. + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +SDK_WEAK_SYMBOL void +NitroStartUp(void) +{ +} + +/*---------------------------------------------------------------------------* + Name: OSi_ReferSymbol + Description: Used by SDK_REFER_SYMBOL macro to avoid dead-strip. + Arguments: symbol - unused. + Returns: None. + *---------------------------------------------------------------------------*/ +void +OSi_ReferSymbol(void* symbol) +{ +#pragma unused(symbol) +} + +#include diff --git a/build/tests/RelocateChecker/crt/Makefile b/build/tests/RelocateChecker/crt/Makefile new file mode 100644 index 00000000..a04204bf --- /dev/null +++ b/build/tests/RelocateChecker/crt/Makefile @@ -0,0 +1,31 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - 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. +# +# $Date:: 2007-11-13#$ +# $Rev: 2282 $ +# $Author: adachi_hiroaki $ +#---------------------------------------------------------------------------- + +TARGET_PLATFORM := TWL NITRO + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = ARM9 ARM7 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#===== End of Makefile ===== diff --git a/build/tests/RelocateChecker/crt/common/include/boot_sync.h b/build/tests/RelocateChecker/crt/common/include/boot_sync.h new file mode 100644 index 00000000..4f51ae64 --- /dev/null +++ b/build/tests/RelocateChecker/crt/common/include/boot_sync.h @@ -0,0 +1,35 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - libraries - init - common + File: boot_sync.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-25#$ + $Rev: 1102 $ + $Author: terui $ + *---------------------------------------------------------------------------*/ +#ifndef TWL_LIBRARIES_INIT_COMMON_BOOT_SYNC_H_ +#define TWL_LIBRARIES_INIT_COMMON_BOOT_SYNC_H_ +#ifdef __cplusplus +extern "C" { +#endif +/*---------------------------------------------------------------------------*/ + +#define BOOT_SYNC_PHASE_1 1 +#define BOOT_SYNC_PHASE_2 2 +#define BOOT_SYNC_PHASE_3 3 +#define BOOT_SYNC_PHASE_4 4 +#define BOOT_SYNC_PHASE_5 5 +#define BOOT_SYNC_PHASE_6 6 + +/*---------------------------------------------------------------------------*/ +#ifdef __cplusplus +} /* extern "C" */ +#endif +#endif /* TWL_LIBRARIES_INIT_COMMON_BOOT_SYNC_H_ */ diff --git a/build/tests/RelocateChecker/crt/common/include/dma_red.h b/build/tests/RelocateChecker/crt/common/include/dma_red.h new file mode 100644 index 00000000..671e9128 --- /dev/null +++ b/build/tests/RelocateChecker/crt/common/include/dma_red.h @@ -0,0 +1,462 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - MI - + File: dma_red.h + + Copyright 2003 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-07-31#$ + $Rev: 387 $ + $Author: terui $ + + *---------------------------------------------------------------------------*/ + +#ifndef NITRO_MI_DMA_RED_H_ +#define NITRO_MI_DMA_RED_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include + +//---------------------------------------------------------------- +// JZp쐬C^tF[X +// v]ɂcĂ܂B +// nitro-sdk/include/nitro/mi/dma.h ɓꂸɂɁB +// + +//---------------------------------------------------------------------- +// cl` Zbg +//---------------------------------------------------------------------- +//#define SIMULATOR +#ifndef SIMULATOR +#define __MI_DmaSet(dmaNo, srcp, destp, dmaCntData) \ +{ \ + vu32 *dmaCntp = &((vu32 *)REG_DMA0SAD_ADDR)[dmaNo * 3]; \ + dmaCntp[0] = (vu32 )(srcp); \ + dmaCntp[1] = (vu32 )(destp); \ + dmaCntp[2] = (vu32 )(dmaCntData); \ + {u32 dummy = dmaCntp[2];} \ + {u32 dummy = dmaCntp[2];} \ +} +#define __MI_DmaSetAsync(dmaNo, srcp, destp, dmaCntData) \ +{ \ + vu32 *dmaCntp = &((vu32 *)REG_DMA0SAD_ADDR)[dmaNo * 3]; \ + dmaCntp[0] = (vu32 )(srcp); \ + dmaCntp[1] = (vu32 )(destp); \ + dmaCntp[2] = (vu32 )(dmaCntData); \ +} +#else +#define __MI_DmaSet(dmaNo, srcp, destp, dmaCntData) \ +{ \ + int i; \ + for (i=0; i<(dmaCntData & 0x1ffff); i++) \ + if ((dmaCntData) & MI_DMA_SRC_FIX) { \ + if ((dmaCntData) & MI_DMA_32BIT_BUS) \ + ((vu32 *)(destp))[i] = ((vu32 *)(srcp))[0]; \ + else ((vu16 *)(destp))[i] = ((vu16 *)(srcp))[0]; \ + } else { \ + if ((dmaCntData) & MI_DMA_32BIT_BUS) \ + ((vu32 *)(destp))[i] = ((vu32 *)(srcp))[i]; \ + else ((vu16 *)(destp))[i] = ((vu16 *)(srcp))[i]; \ + } \ +} +#define __MI_DmaSetAsync(dmaNo, srcp, destp, dmaCntData) \ + __MI_DmaSet( dmaNo, srcp, destp, dmaCntData) +#endif + +//EDMARg[Ƀp[^Zbg܂B +//ESIMULATER`CPUŃV~[g܂B +// GDBŃfobOꍇȂǂɗLłB +//EŌDMAN҂̂߂"LDR"߂}܂B +// +//EF +// dmaNo DMAԍ +// srcp \[XAhX +// destp fXeBl[VAhX +// dmaCntData p[^f[^ +// +//CPURAM̃vOɂDMAN +// ̖̎߂Ɏs܂B +// āADMAɓ]CPUɂĕύX悤ƂꍇA +// ǂݍ݁^߂̊ԂDMANĂ܂܂̂ŁA +// DMA̓]̃f[^Ӑ}ĂȂlɂȂꍇ܂B +// ̏ꍇɂWaitDma()𒼌ɑ}āADMAI +// ǂ`FbNƑR[hւ̉emɉł܂B + + +//---------------------------------------------------------------------- +// cl` NA +//---------------------------------------------------------------------- + +#define __MI_DmaClear(dmaNo, data, destp, size, bit) \ +{ \ + *(vu##bit *)HW_DMA_CLEAR_DATA_BUF = (vu##bit )(data); \ + __MI_DmaSet(dmaNo, HW_DMA_CLEAR_DATA_BUF, destp, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_IMM | \ + MI_DMA_SRC_FIX | MI_DMA_DEST_INC | \ + MI_DMA_##bit##BIT_BUS | ((size)/(bit/8)))); \ +} + +#define __MI_DmaClearIf(dmaNo, data, destp, size, bit) \ +{ \ + *(vu##bit *)DMA_CLEAR_DATA_BUF = (vu##bit )(data); \ + __MI_DmaSet(dmaNo, DMA_CLEAR_DATA_BUF, destp, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_IMM | \ + MI_DMA_IF_ENABLE | \ + MI_DMA_SRC_FIX | MI_DMA_DEST_INC | \ + MI_DMA_##bit##BIT_BUS | ((size)/(bit/8)))); \ +} + +#define __MI_DmaClearArray( dmaNo, data, destp, bit) \ + __MI_DmaClear( dmaNo, data, destp, sizeof(destp), bit) + +#define MI_DmaClearArrayIf(dmaNo, data, destp, bit) \ + __MI_DmaClearIf( dmaNo, data, destp, sizeof(destp), bit) + +//EDMARAMNA܂B +//ENAf[^̓X^bNɒuAfXeBl[VփRs[܂B +//EMI_DmaClearIf^MI_DmaClearArrayIf͏IɊ荞ݗv𔭐܂B +//EMI_DmaClearArray^MI_DmaClearArrayIf̓fXeBl[VzŜNA܂B +// +//EF +// dmaNo DMAԍ +// data NAf[^ +// destp fXeBl[VAhX +// size NAoCg +// bit ]rbgi16|32j +// +// +//CPURAM̃vOɂDMAN +// ̖̎߂Ɏs܂B +// āADMAɓ]CPUɂĕύX悤ƂꍇA +// ǂݍ݁^߂̊ԂDMANĂ܂܂̂ŁA +// DMA̓]̃f[^Ӑ}ĂȂlɂȂꍇ܂B +// ̏ꍇɂWaitDma()𒼌ɑ}āADMAI +// ǂ`FbNƑR[hւ̉emɉł܂B + +//---------------------------------------------------------------------- +// cl` Rs[ +//---------------------------------------------------------------------- + +#define __MI_DmaCopy(dmaNo, srcp, destp, size, bit) \ + \ + __MI_DmaSet(dmaNo, srcp, destp, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_IMM | \ + MI_DMA_SRC_INC | MI_DMA_DEST_INC | \ + MI_DMA_##bit##BIT_BUS | ((size)/((bit)/8)))) + +#define __MI_DmaCopyIf(dmaNo, srcp, destp, size, bit) \ + \ + __MI_DmaSet(dmaNo, srcp, destp, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_IMM | \ + MI_DMA_IF_ENABLE | \ + MI_DMA_SRC_INC | MI_DMA_DEST_INC | \ + MI_DMA_##bit##BIT_BUS | ((size)/(bit/8)))) + +#define __MI_DmaCopyArray( dmaNo, srcp, destp, bit) \ + __MI_DmaCopy( dmaNo, srcp, destp, sizeof(srcp), bit) + +#define __MI_DmaCopyArrayIf(dmaNo, srcp, destp, bit) \ + __MI_DmaCopyIf( dmaNo, srcp, destp, sizeof(srcp), bit) + +//EDMAŃRs[܂B +//EMI_DmaCopyIf^MI_DmaCopyArrayIf͏IɊ荞ݗv𔭐܂B +//EMI_DmaCopyArray^MI_DmaCopyArrayIf̓\[XzŜRs[܂B +// +//EF +// dmaNo DMAԍ +// srcp \[XAhX +// destp fXeBl[VAhX +// size ]oCg +// bit ]rbgi16|32j +// +// +//CPURAM̃vOɂDMAN +// ̖̎߂Ɏs܂B +// āADMAɓ]CPUɂĕύX悤ƂꍇA +// ǂݍ݁^߂̊ԂDMANĂ܂܂̂ŁA +// DMA̓]̃f[^Ӑ}ĂȂlɂȂꍇ܂B +// ̏ꍇɂWaitDma()𒼌ɑ}āADMAI +// ǂ`FbNƑR[hւ̉emɉł܂B + +//---------------------------------------------------------------------- +// guNcl` Rs[ +//---------------------------------------------------------------------- + +#define __MI_H_DmaCopy(dmaNo, srcp, destp, size, bit) \ + \ + __MI_DmaSet(dmaNo, srcp, destp, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_H_BLANK | \ + MI_DMA_SRC_INC | MI_DMA_DEST_RELOAD | \ + MI_DMA_CONTINUOUS_ON | \ + MI_DMA_##bit##BIT_BUS | ((size)/((bit)/8)))) + +#define __MI_H_DmaCopyIf(dmaNo, srcp, destp, size, bit) \ + \ + __MI_DmaSet(dmaNo, srcp, destp, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_H_BLANK | \ + MI_DMA_IF_ENABLE | \ + MI_DMA_SRC_INC | MI_DMA_DEST_RELOAD | \ + MI_DMA_CONTINUOUS_ON | \ + MI_DMA_##bit##BIT_BUS | ((size)/(bit/8)))) + +#define __MI_H_DmaCopyArray( dmaNo, srcp, destp, bit) \ + __MI_H_DmaCopy( dmaNo, srcp, destp, sizeof(srcp), bit) + +#define __MI_H_DmaCopyArrayIf(dmaNo, srcp, destp, bit) \ + __MI_H_DmaCopyIf( dmaNo, srcp, destp, sizeof(srcp), bit) + +//EHuNɓDMAŃRs[܂B +//EMI_H_DmaCopyIf^MI_H_DmaCopyArrayIf͏IɊ荞ݗv𔭐܂B +//EMI_H_DmaCopyArray^MI_H_DmaCopyArrayIf̓\[XzŜRs[܂B +// +//EF +// dmaNo DMAԍ +// srcp \[XAhX +// destp fXeBl[VAhX +// size ]oCg +// bit ]rbgi16|32j + +//---------------------------------------------------------------------- +// uuNcl` Rs[ +//---------------------------------------------------------------------- + +#define __MI_V_DmaCopy(dmaNo, srcp, destp, size, bit) \ + \ + __MI_DmaSet(dmaNo, srcp, destp, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_V_BLANK | \ + MI_DMA_SRC_INC | MI_DMA_DEST_INC | \ + MI_DMA_##bit##BIT_BUS | ((size)/(bit/8)))) + +#define __MI_V_DmaCopyIf(dmaNo, srcp, destp, size, bit) \ + \ + __MI_DmaSet(dmaNo, srcp, destp, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_V_BLANK | \ + MI_DMA_IF_ENABLE | \ + MI_DMA_SRC_INC | MI_DMA_DEST_INC | \ + MI_DMA_##bit##BIT_BUS | ((size)/(bit/8)))) + +#define __MI_V_DmaCopyArray( dmaNo, srcp, destp, bit) \ + __MI_V_DmaCopy( dmaNo, srcp, destp, sizeof(srcp), bit) + +#define __MI_V_DmaCopyArrayIf(dmaNo, srcp, destp, bit) \ + __MI_V_DmaCopyIf( dmaNo, srcp, destp, sizeof(srcp), bit) + +//EVuNɓDMAŃRs[܂B +//EMI_V_DmaCopyIf^MI_V_DmaCopyArrayIf͏IɊ荞ݗv𔭐܂B +//EMI_V_DmaCopyArray^MI_V_DmaCopyArrayIf̓\[XzŜRs[܂B +// +//EF +// dmaNo DMAԍ +// srcp \[XAhX +// destp fXeBl[VAhX +// size ]oCg +// bit ]rbgi16|32j + +//---------------------------------------------------------------------- +// C\cl` +//---------------------------------------------------------------------- + +#define __MI_DmaDispMainmem(dmaNo, srcp) \ + \ + __MI_DmaSet(dmaNo, srcp, REG_DISP_MMEM_FIFO_ADDR, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_DISP_MMEM | \ + MI_DMA_SRC_INC | MI_DMA_DEST_FIX | \ + MI_DMA_CONTINUOUS_ON | \ + MI_DMA_32BIT_BUS | (4))) + +//EC̃C[W\DMA]s܂B +// +//EF +// dmaNo DMAԍ +// srcp \[XAhX + +//---------------------------------------------------------------------- +// WIgehen|cl` +//---------------------------------------------------------------------- + +#define __MI_GX_Dma(dmaNo, srcp, length) \ + \ + __MI_DmaSetAsync(dmaNo, srcp, REG_GXFIFO_ADDR, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_GXFIFO | \ + MI_DMA_SRC_INC | MI_DMA_DEST_FIX | \ + MI_DMA_32BIT_BUS | (length))) + +#define __MI_GX_DmaIf(dmaNo, srcp, length) \ + \ + __MI_DmaSetAsync(dmaNo, srcp, REG_GXFIFO_ADDR ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_GXFIFO | \ + MI_DMA_IF_ENABLE | \ + MI_DMA_SRC_INC | MI_DMA_DEST_FIX | \ + MI_DMA_32BIT_BUS | (length))) + +#define __MI_GX_DmaFast(dmaNo, srcp, length) \ + \ + __MI_DmaSetAsync(dmaNo, srcp, REG_GXFIFO_ADDR, ( \ + MI_DMA_ENABLE | MI_DMA_TIMING_IMM | \ + MI_DMA_SRC_INC | MI_DMA_DEST_FIX | \ + MI_DMA_32BIT_BUS | (length))) + +#define __MI_GX_DmaFastIf(dmaNo, srcp, length) \ + \ + __MI_DmaSetAsync(dmaNo, srcp, REG_GXFIFO_ADDR, ( \ + DMA_ENABLE | DMA_TIMING_IMM | \ + DMA_IF_ENABLE | \ + DMA_SRC_INC | DMA_DEST_FIX | \ + DMA_32BIT_BUS | (length))) + +#define __MI_GX_DmaArray( dmaNo, srcp, destp, bit) \ + __MI_GX_Dma( dmaNo, srcp, destp, sizeof(srcp), bit) + +#define __MI_GX_DmaArrayIf(dmaNo, srcp, destp, bit) \ + __MI_GX_DmaIf(dmaNo, srcp, destp, sizeof(srcp), bit) + +#define __MI_GX_DmaArrayFast( dmaNo, srcp, destp, bit) \ + __MI_GX_DmaFast( dmaNo, srcp, destp, sizeof(srcp), bit) + +#define __MI_GX_DmaArrayFastIf(dmaNo, srcp, destp, bit) \ + __MI_GX_DmaFastIf(dmaNo, srcp, destp, sizeof(srcp), bit) + +//EWIgFIFO̗vɂDMAŃRs[܂B +//EMI_GX_DmaIf^MI_GX_DmaArrayIf^MI_GX_DmaFastIf^MI_GX_DmaArrayFastIf +// ͏IɊ荞ݗv𔭐܂B +//EMI_GX_DmaArray^MI_GX_DmaArrayIf^MI_GX_DmaArrayFast^MI_GX_DmaArrayFastIf +// ̓\[XzŜRs[܂B +// +//EF +// dmaNo DMAԍ +// srcp \[XAhX +// size ]oCg + + +//---------------------------------------------------------------------- +// cl` I҂ +//---------------------------------------------------------------------- + +#define __MI_WaitDma(dmaNo) \ +{ \ + vu32 *(dmaCntp) = &((vu32 *)REG_DMA0SAD_ADDR)[dmaNo * 3]; \ + while (dmaCntp[2] & MI_DMA_ENABLE) ; \ +} + +//EDMȀI҂܂B +// +//EF +// dmaNo DMAԍ + + +//---------------------------------------------------------------------- +// cl` Xgbv +//---------------------------------------------------------------------- + +#define __MI_StopDma(dmaNo) \ +{ \ + vu16* dmaCntp = &((vu16 *)REG_DMA0SAD_ADDR)[dmaNo * 6]; \ + dmaCntp[5] &= ~((MI_DMA_TIMING_MASK | MI_DMA_CONTINUOUS_ON) \ + >> 16); \ + dmaCntp[5] &= ~( MI_DMA_ENABLE >> 16); \ + {u32 dummy = dmaCntp[5];} \ + {u32 dummy = dmaCntp[5];} \ +} + +//EDMA~܂B +//EAADMA̎N|ꍇ͈xDMAs܂B +// +//EF +// dmaNo DMAԍ + + +//---------------------------------------------------------------------- +// bot NA +//---------------------------------------------------------------------- + +#define __MI_CpuClear(data, destp, size, bit) UTL_CpuClear##bit(data, (void *)(destp), size) + +#define __MI_CpuClearArray(data, destp, bit) \ + __MI_CpuClear( data, destp, sizeof(destp), bit) + +//ECPURAMNAVXeR[Ăяo܂B +//ENAf[^̓X^bNɒuAfXeBl[VփRs[܂B +//ECpuClearArray̓fXeBl[VzŜNA܂B +// +//EF +// data NAf[^ +// destp fXeBl[VAhX +// size NAoCg +// bit ]rbgi16|32j + +//---------------------------------------------------------------------- +// bot Rs[ +//---------------------------------------------------------------------- + +#define __MI_CpuCopy(srcp, destp, size, bit) UTL_CpuCopy##bit((void *)(srcp), (void *)(destp), size) + +#define __MI_CpuCopyArray(srcp, destp, bit) \ + __MI_CpuCopy( srcp, destp, sizeof(srcp), bit) + +//ECPUŃRs[VXeR[Ăяo܂B +//ECpuCopyArray̓\[XzŜRs[܂B +// +//EF +// srcp \[XAhX +// destp fXeBl[VAhX +// size ]oCg +// bit ]rbgi16|32j + +//---------------------------------------------------------------------- +// bot NA(32ByteP) +//---------------------------------------------------------------------- + +#define __MI_CpuClearFast(data, destp, size) UTL_CpuClearFast(data, (void *)(destp), size) + +#define MI_CpuClearArrayFast(data, destp) \ + __MI_CpuClearFast( data, destp, sizeof(destp)) + +//ECPUōRAMNAVXeR[Ăяo܂B +//ENAf[^̓X^bNɒuAfXeBl[VփRs[܂B +//ECpuClearArrayFast̓fXeBl[VzŜNA܂B +// +//EF +// data NAf[^ +// destp fXeBl[VAhX +// size NAoCg + +//---------------------------------------------------------------------- +// bot Rs[(32ByteP) +//---------------------------------------------------------------------- + +#define __MI_CpuCopyFast(srcp, destp, size) UTL_CpuCopyFast((void *)(srcp), (void *)(destp), size) + + +#define MI_CpuCopyArrayFast(srcp, destp) \ + __MI_CpuCopyFast( srcp, destp, sizeof(srcp)) + +//ECPUōɃRs[VXeR[Ăяo܂B +//ECpuCopyArrayFast̓\[XzŜRs[܂B +// +//EF +// srcp \[XAhX +// destp fXeBl[VAhX +// size ]oCg + + + + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* NITRO_MI_DMA_RED_H_ */ +#endif diff --git a/build/tests/RelocateChecker/crt/common/include/mi_dma.h b/build/tests/RelocateChecker/crt/common/include/mi_dma.h new file mode 100644 index 00000000..e7ad3748 --- /dev/null +++ b/build/tests/RelocateChecker/crt/common/include/mi_dma.h @@ -0,0 +1,252 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - MI + File: mi_dma.h + + Copyright 2003 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-07-31#$ + $Rev: 387 $ + $Author: terui $ + *---------------------------------------------------------------------------*/ +#ifndef NITRO_COMMON_MI_DMA_H_ +#define NITRO_COMMON_MI_DMA_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +//================================================================================ +// DMA system work +//================================================================================ +#ifdef SDK_ARM9 +# ifdef SDK_TS +# define MIi_DMA_CLEAR_DATA_BUF REG_DMA0_CLR_DATA_ADDR // ARM9-TS: defined ARM9/ioreg_MI.h +# else +# define MIi_DMA_CLEAR_DATA_BUF HW_DMA_CLEAR_DATA_BUF // ARM9-TEG: defined common/mmap_shared.h +# endif +#else // ifdef SDK_ARM9 +# define MIi_DMA_CLEAR_DATA_BUF HW_PRV_WRAM_DMA_CLEAR_DATA_BUF // ARM7: defined ARM7/mmap_wram.h +#endif // ifdef SDK_ARM9 + +typedef union +{ + u32 b32; + u16 b16; +} +MIiDmaClearSrc; + +//================================================================================ +// setting DMA +//================================================================================ +//---------------- set parameters +#ifdef SDK_ARM9 + +void MIi_DmaSetParams(u32 dmaNo, u32 src, u32 dest, u32 ctrl); +void MIi_DmaSetParams_wait(u32 dmaNo, u32 src, u32 dest, u32 ctrl); +void MIi_DmaSetParams_noInt(u32 dmaNo, u32 src, u32 dest, u32 ctrl); +void MIi_DmaSetParams_wait_noInt(u32 dmaNo, u32 src, u32 dest, u32 ctrl); + +#else // ifdef SDK_ARM9 +static inline void MIi_DmaSetParams(u32 dmaNo, u32 src, u32 dest, u32 ctrl) +{ + OSIntrMode enabled = OS_DisableInterrupts(); + vu32 *p = (vu32 *)((u32)REG_DMA0SAD_ADDR + dmaNo * 12); + *p = (vu32)src; + *(p + 1) = (vu32)dest; + *(p + 2) = (vu32)ctrl; + (void)OS_RestoreInterrupts(enabled); +} + +static inline void MIi_DmaSetParams_wait(u32 dmaNo, u32 src, u32 dest, u32 ctrl) +{ + OSIntrMode enabled = OS_DisableInterrupts(); + vu32 *p = (vu32 *)((u32)REG_DMA0SAD_ADDR + dmaNo * 12); + *p = (vu32)src; + *(p + 1) = (vu32)dest; + *(p + 2) = (vu32)ctrl; + + // ARM7 must wait 2 cycle (load is 3 cycle) + { + u32 dummy = reg_MI_DMA0SAD; + } + + (void)OS_RestoreInterrupts(enabled); +} + +static inline void MIi_DmaSetParams_noInt(u32 dmaNo, u32 src, u32 dest, u32 ctrl) +{ + vu32 *p = (vu32 *)((u32)REG_DMA0SAD_ADDR + dmaNo * 12); + *p = (vu32)src; + *(p + 1) = (vu32)dest; + *(p + 2) = (vu32)ctrl; +} + +static inline void MIi_DmaSetParams_wait_noInt(u32 dmaNo, u32 src, u32 dest, u32 ctrl) +{ + vu32 *p = (vu32 *)((u32)REG_DMA0SAD_ADDR + dmaNo * 12); + *p = (vu32)src; + *(p + 1) = (vu32)dest; + *(p + 2) = (vu32)ctrl; + + // ARM7 must wait 2 cycle (load is 3 cycle) + { + u32 dummy = reg_MI_DMA0SAD; + } +} +#endif + + +static inline void MIi_DmaSetParams_src32(u32 dmaNo, u32 data, u32 dest, u32 ctrl) +{ + OSIntrMode enabled = OS_DisableInterrupts(); + + MIiDmaClearSrc *srcp = (MIiDmaClearSrc *) ((u32)MIi_DMA_CLEAR_DATA_BUF + dmaNo * 4); + srcp->b32 = data; + MIi_DmaSetParams_noInt(dmaNo, (u32)srcp, dest, ctrl); + + (void)OS_RestoreInterrupts(enabled); +} + +static inline void MIi_DmaSetParams_src16(u32 dmaNo, u16 data, u32 dest, u32 ctrl) +{ + OSIntrMode enabled = OS_DisableInterrupts(); + + MIiDmaClearSrc *srcp = (MIiDmaClearSrc *) ((u32)MIi_DMA_CLEAR_DATA_BUF + dmaNo * 4); + srcp->b16 = data; + MIi_DmaSetParams_noInt(dmaNo, (u32)srcp, dest, ctrl); + + (void)OS_RestoreInterrupts(enabled); +} + +static inline void MIi_DmaSetParams_wait_src32(u32 dmaNo, u32 data, u32 dest, u32 ctrl) +{ + OSIntrMode enabled = OS_DisableInterrupts(); + + MIiDmaClearSrc *srcp = (MIiDmaClearSrc *) ((u32)MIi_DMA_CLEAR_DATA_BUF + dmaNo * 4); + srcp->b32 = data; + MIi_DmaSetParams_wait_noInt(dmaNo, (u32)srcp, dest, ctrl); + + (void)OS_RestoreInterrupts(enabled); +} + +static inline void MIi_DmaSetParams_wait_src16(u32 dmaNo, u16 data, u32 dest, u32 ctrl) +{ + OSIntrMode enabled = OS_DisableInterrupts(); + + MIiDmaClearSrc *srcp = (MIiDmaClearSrc *) ((u32)MIi_DMA_CLEAR_DATA_BUF + dmaNo * 4); + srcp->b16 = data; + MIi_DmaSetParams_wait_noInt(dmaNo, (u32)srcp, dest, ctrl); + + (void)OS_RestoreInterrupts(enabled); +} + +//================================================================================ +// CALLBACK +//================================================================================ +extern void OSi_EnterDmaCallback(u32 dmaNo, MIDmaCallback callback, void *arg); + +static inline void MIi_CallCallback(MIDmaCallback callback, void *arg) +{ + if (callback) + { + (callback) (arg); + } +} + +//================================================================================ +// WAIT +//================================================================================ +//---------------------------------------------------------------- +// for waiting DMA busy +#define MIi_Wait_BeforeDMA( dmaCntp, dmaNo ) \ + do { \ + dmaCntp = &((vu32*)REG_DMA0SAD_ADDR)[dmaNo * 3 + 2]; \ + MIi_ASSERT_DMANO( dmaNo ); \ + while ( *dmaCntp & REG_MI_DMA0CNT_E_MASK ) {} \ + }while(0) + +#define MIi_Wait_AfterDMA( dmaCntp ) \ + do { \ + while ( *dmaCntp & REG_MI_DMA0CNT_E_MASK ) {} \ + }while(0) + + +//================================================================================ +// ASSERT +//================================================================================ +#define MIi_ASSERT_DMANO( dmaNo ) SDK_ASSERTMSG( (dmaNo) <= MI_DMA_MAX_NUM, "illegal DMA No." ) +#define MIi_ASSERT_MUL2( size ) SDK_ASSERTMSG( ((size) & 1) == 0, "size & 1 must be 0" ) +#define MIi_ASSERT_MUL4( size ) SDK_ASSERTMSG( ((size) & 3) == 0, "size & 3 must be 0" ) +#define MIi_ASSERT_SRC_ALIGN512( src ) SDK_ASSERTMSG( ((u32)(src) & 511) == 0, "source address must be in 512-byte alignment" ) +#define MIi_ASSERT_SRC_ALIGN4( src ) SDK_ASSERTMSG( ((u32)(src) & 3) == 0, "source address must be in 4-byte alignment" ) +#define MIi_ASSERT_SRC_ALIGN2( src ) SDK_ASSERTMSG( ((u32)(src) & 1) == 0, "source address must be in 2-byte alignment" ) +#define MIi_ASSERT_DEST_ALIGN4( dest ) SDK_ASSERTMSG( ((u32)(dest) & 3) == 0, "destination address must be in 4-byte alignment" ) +#define MIi_ASSERT_DEST_ALIGN2( dest ) SDK_ASSERTMSG( ((u32)(dest) & 1) == 0, "destination address must be in 2-byte alignment" ) + +#ifdef SDK_ARM9 +# define MIi_ASSERT_SIZE( dmaNo, size ) SDK_ASSERTMSG( (size) <= 0x1fffff, "size too large" ); +#else //SDK_ARM7 +# define MIi_ASSERT_SIZE( dmaNo, size ) \ + do{ \ + if ( dmaNo <= 2 ) \ + { \ + SDK_ASSERTMSG( (size) <= 0x3fff, "size too large" );\ + } \ + else \ + { \ + SDK_ASSERTMSG( (size) <= 0xffff, "size too large" );\ + } \ + } while(0) +#endif + + +//================================================================================ +// CHECK +//================================================================================ +//---------------------------------------------------------------- +// Check if specified area is in ITCM/DTCM. +// +#if defined( SDK_ARM9 ) && defined( SDK_DEBUG ) +void MIi_CheckAddressInTCM(u32 addr, u32 size); +#define MIi_WARNING_ADDRINTCM( addr, size ) MIi_CheckAddressInTCM( (u32)addr, (u32)size ) +#else +#define MIi_WARNING_ADDRINTCM( addr, size ) ((void)0) +#endif + + +//---------------------------------------------------------------- +// for DMA check +// (must avoid multiple auto start DMA) +// +#ifdef SDK_ARM9 +void MIi_CheckAnotherAutoDMA(u32 dmaNo, u32 dmaType); +#endif + +//---------------------------------------------------------------- +// for DMA0 check +// Source address which is in I/O register or cartridge bus +// is not available. +void MIi_CheckDma0SourceAddress(u32 dmaNo, u32 src, u32 size, u32 dir); + +//================================================================================ +// dummy DMA for multi DMA problem +//================================================================================ +#define MIi_DUMMY_DMA_NO 0 +#define MIi_DUMMY_SRC 0 +#define MIi_DUMMY_DEST 0 +#define MIi_DUMMY_CNT ( MI_DMA_ENABLE | MI_DMA_SRC_FIX | MI_DMA_DEST_FIX | MI_DMA_16BIT_BUS | 1 ) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* MI_COMMON_MI_DMA_H_ */ +#endif diff --git a/build/tests/RelocateChecker/crt/common/src/os_common.c b/build/tests/RelocateChecker/crt/common/src/os_common.c new file mode 100644 index 00000000..d106e7ce --- /dev/null +++ b/build/tests/RelocateChecker/crt/common/src/os_common.c @@ -0,0 +1,25 @@ +/*---------------------------------------------------------------------------* + Project: TWL + File: os_common.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:: 2007-07-31#$ + $Rev: 387 $ + $Author: terui $ + *---------------------------------------------------------------------------*/ + +#include + +void os_common_test(void); + +void os_common_test(void) +{ + // do nothing +} diff --git a/build/tests/RelocateChecker/flabObj/incre.exe b/build/tests/RelocateChecker/flabObj/incre.exe new file mode 100644 index 00000000..36ec6d3d Binary files /dev/null and b/build/tests/RelocateChecker/flabObj/incre.exe differ diff --git a/build/tests/SimpleApp/ARM9/Makefile b/build/tests/SimpleApp/ARM9/Makefile new file mode 100644 index 00000000..12b45c85 --- /dev/null +++ b/build/tests/SimpleApp/ARM9/Makefile @@ -0,0 +1,61 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - demos - simpleShoot-1 +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev: $ +# $Author: $ +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- + +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED + +TITLEID_LO = SMPL + +TARGET_BIN = simpleapp.srl + +ROM_SPEC = main.rsf + +MISC_DIR = ../../misc +DATA_DIR = ../../data + +SRCS = main.c SimpleApp.c \ + $(MISC_DIR)/misc_simple.c \ + $(DATA_DIR)/data.c + +LINCLUDES = $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/include \ + $(MISC_DIR) \ + $(DATA_DIR) + +LLIBRARY_DIRS += $(TWLSDK_ROOT)/build/demos/gx/UnitTours/DEMOLib/lib/$(TWL_BUILDTYPE) + +LLIBRARIES += libDEMO$(TWL_LIBSUFFIX).a + +MAKEROM_FLAGS += -F -DTITLEID_LO='$(TITLEID_LO)' + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) +INSTALL_DIR = $(DATA_DIR) + +#---------------------------------------------------------------------------- + +do-build : $(TARGETS) + + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- + +#===== End of Makefile ===== diff --git a/build/tests/SimpleApp/ARM9/main.rsf b/build/tests/SimpleApp/ARM9/main.rsf new file mode 100644 index 00000000..fa4fb30a --- /dev/null +++ b/build/tests/SimpleApp/ARM9/main.rsf @@ -0,0 +1,178 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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-11-21#$ +# $Rev: 240 $ +# $Author: yosiokat $ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + #TitleName "YourAppName" + + #_GameCode $(TITLEID_LO) + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + #MakerCode "00" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + BannerFile ../banner/banner.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + WramMapping $(MAKEROM_WRAM_MAPPING) + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType User + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + SaveBannerFile FALSE +} + + +RomSpec +{ + Offset 0x00000000 + Segment ALL +} diff --git a/build/tests/SimpleApp/ARM9/src/SimpleApp.c b/build/tests/SimpleApp/ARM9/src/SimpleApp.c new file mode 100644 index 00000000..d6ad601a --- /dev/null +++ b/build/tests/SimpleApp/ARM9/src/SimpleApp.c @@ -0,0 +1,125 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: SimpleApp.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:: 2007-10-31#$ + $Rev: 91 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc_simple.h" +#include "SimpleApp.h" + +// define data------------------------------------------ + +#define COPB_MENU_ELEMENT_NUM 1 // j[̍ڐ + +// extern data------------------------------------------ + +// function's prototype declaration--------------------- + +static void MenuScene( void ); + +// global variable ------------------------------------- + +// static variable ------------------------------------- +static u16 s_csr = 0; +static void(*s_pNowProcess)(void); + +// const data ----------------------------------------- +static const char *s_pStrMenu[ COPB_MENU_ELEMENT_NUM ] = +{ + "return to launcher", +}; + +static MenuPos s_menuPos[] = { + { TRUE, 3, 8 }, +}; + +static const MenuParam s_menuParam = { + COPB_MENU_ELEMENT_NUM, + TXT_COLOR_BLACK, + TXT_COLOR_GREEN, + TXT_COLOR_RED, + &s_menuPos[ 0 ], + (const char **)&s_pStrMenu, +}; + +//====================================================== +// AvAgeXgvOB +//====================================================== + +static void DrawMenuScene( void ) +{ + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "SimpleApp"); + // j[ + myDp_DrawMenu( s_csr, MAIN_SCREEN, &s_menuParam ); +} + +static void MenuInit( void ) +{ + GX_DispOff(); + GXS_DispOff(); + + myDp_Printf( 1, 0, TXT_COLOR_BLUE, MAIN_SCREEN, "SimpleApp"); + + s_pNowProcess = MenuScene; + + DrawMenuScene(); + + GX_DispOn(); + GXS_DispOn(); +} + +static void MenuScene(void) +{ + LauncherBootFlags tempflag = {TRUE, OS_BOOTTYPE_NAND, TRUE, FALSE, FALSE, FALSE, 0}; + + //-------------------------------------- + // L[͏ + //-------------------------------------- + if( MYPAD_IS_TRIG(PAD_KEY_DOWN) ){ // J[\̈ړ + if( ++s_csr == COPB_MENU_ELEMENT_NUM ) { + s_csr=0; + } + } + if( MYPAD_IS_TRIG(PAD_KEY_UP) ){ + if( --s_csr & 0x80 ) { + s_csr=COPB_MENU_ELEMENT_NUM - 1; + } + } + + DrawMenuScene(); + + if( MYPAD_IS_TRIG(PAD_BUTTON_A) ) { // j[ڂւ̕ + if( s_menuPos[ s_csr ].enable ) { + switch( s_csr ) { + case 0: + OS_SetLauncherParamAndResetHardware( 0, NULL, &tempflag ); + //ċN + break; + } + } + } +} + +// +void SimpleAppInit( void ) +{ + MenuInit(); +} + +// C[v +void SimpleAppMain(void) +{ + s_pNowProcess(); +} diff --git a/build/tests/SimpleApp/ARM9/src/SimpleApp.h b/build/tests/SimpleApp/ARM9/src/SimpleApp.h new file mode 100644 index 00000000..1131e15b --- /dev/null +++ b/build/tests/SimpleApp/ARM9/src/SimpleApp.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: SimpleApp.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-10-30#$ + $Rev: 73 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#ifndef __SIMPLEAPP_H__ +#define __SIMPLEAPP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include + +// define data---------------------------------------------------------- + +void SimpleAppInit( void ); +void SimpleAppMain( void ); + +#ifdef __cplusplus +} +#endif + +#endif // __SIMPLEAPP_H__ diff --git a/build/tests/SimpleApp/ARM9/src/main.c b/build/tests/SimpleApp/ARM9/src/main.c new file mode 100644 index 00000000..fd69843d --- /dev/null +++ b/build/tests/SimpleApp/ARM9/src/main.c @@ -0,0 +1,68 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: main.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-11-27#$ + $Rev: 272 $ + $Author: yosiokat $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc_simple.h" +#include "SimpleApp.h" + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + +// function's prototype------------------------------------------------------- +static void INTR_VBlank( void ); + +// global variable------------------------------------------------------------- + +// static variable------------------------------------------------------------- +BOOL g_isValidTSD; + +// const data------------------------------------------------------------------ + + +// ============================================================================ +// function's description +// ============================================================================ +void TwlMain(void) +{ + myInit(); + + SimpleAppInit(); + // C[v---------------------------- + while(1){ + + myPreMain(); + + SimpleAppMain(); + + myProMain(); + + OS_WaitIrq(1, OS_IE_V_BLANK); // VuN荞ݑ҂ + } +} + + +// ============================================================================ +// 荞ݏ +// ============================================================================ + +// VuN荞 +static void INTR_VBlank(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // VuN`FbÑZbg +} + diff --git a/build/tests/SimpleApp/Makefile b/build/tests/SimpleApp/Makefile new file mode 100644 index 00000000..9cf34e12 --- /dev/null +++ b/build/tests/SimpleApp/Makefile @@ -0,0 +1,30 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +SUBDIRS = banner ARM9 + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tests/SimpleApp/banner/Makefile b/build/tests/SimpleApp/banner/Makefile new file mode 100644 index 00000000..aafe44c2 --- /dev/null +++ b/build/tests/SimpleApp/banner/Makefile @@ -0,0 +1,50 @@ +#! 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 $ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs +MAKEBANNER = $(TWL_TOOLSDIR)/bin/makebanner.TWL.exe + +ICON_DIR = ./icon + +BANNER_ICON = $(ICON_DIR)/gameIcon.bmp +BANNER_SPEC = banner_v3.bsf + +TARGETS = banner.bnr +INSTALL_DIR = ./ +INSTALL_TARGETS = $(TARGETS) + +BANNER_ICON_NAME = $(basename $(BANNER_ICON)) + +LDIRT_CLEAN = $(TARGETS) \ + $(BANNER_ICON_NAME).nbfs \ + $(BANNER_ICON_NAME).nbfc \ + $(BANNER_ICON_NAME).nbfp \ + $(TARGETS:.bnr=.srl) + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(BANNER_SPEC) $(BANNER_ICON) + $(NTEXCONV) -no -bg -bgb -bgnc $(BANNER_ICON) >/dev/null && \ + $(MAKEBANNER) -d -N $(BANNER_ICON_NAME) $(BANNER_SPEC) $(TARGETS) + +# diff --git a/build/tests/SimpleApp/banner/banner_v3.bsf b/build/tests/SimpleApp/banner/banner_v3.bsf new file mode 100644 index 00000000..d602c7f8 Binary files /dev/null and b/build/tests/SimpleApp/banner/banner_v3.bsf differ diff --git a/build/tests/SimpleApp/banner/icon/gameIcon.bmp b/build/tests/SimpleApp/banner/icon/gameIcon.bmp new file mode 100644 index 00000000..71221647 Binary files /dev/null and b/build/tests/SimpleApp/banner/icon/gameIcon.bmp differ diff --git a/build/tests/data/data.c b/build/tests/data/data.c new file mode 100644 index 00000000..caf8429f --- /dev/null +++ b/build/tests/data/data.c @@ -0,0 +1,620 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - demos.TWL - nandApp - ExecPreLoadedApp + File: data.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:: 2007-08-29#$ + $Rev: 640 $ + $Author: kitase_hirotake $ + *---------------------------------------------------------------------------*/ + +#include "data.h" + +/*---------------------- Palette Data ---------------------------*/ +const unsigned int d_64_256_bg_sclDT[8 * 16] = { + 0x0000ffff, 0x00000000, 0x00000000, 0x00000000, // black + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x001f001e, 0x001d001c, 0x001b001a, 0x00190018, // red + 0x00170016, 0x00150014, 0x00130012, 0x00110010, + 0x03e00000, 0x00000000, 0x00000000, 0x00000000, // green + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7c000000, 0x00000000, 0x00000000, 0x00000000, // blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03ff0000, 0x00000000, 0x00000000, 0x00000000, // yellow + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7c1f0000, 0x00000000, 0x00000000, 0x00000000, // purple + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7fe00000, 0x00000000, 0x00000000, 0x00000000, // light blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x000f000e, 0x000d000c, 0x000b000a, 0x00090008, // dark red + 0x00070006, 0x00050004, 0x00030002, 0x00010000, + 0x03000000, 0x00000000, 0x00000000, 0x00000000, // dark green + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x60000000, 0x00000000, 0x00000000, 0x00000000, // dark blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x03180000, 0x00000000, 0x00000000, 0x00000000, // dark yellow + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x60180000, 0x00000000, 0x00000000, 0x00000000, // dark purple + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x63000000, 0x00000000, 0x00000000, 0x00000000, // dark light blue + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x56b50000, 0x00000000, 0x00000000, 0x00000000, // gray + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x2d6b0000, 0x00000000, 0x00000000, 0x00000000, // dark gray + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x7fff0000, 0x00000000, 0x00000000, 0x00000000, // white + 0x00000000, 0x00000000, 0x00000000, 0x00000000 +}; + +/*---------------------- Character Data -------------------------*/ +const unsigned int d_64_256_bg_schDT[8 * 256] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 0000h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01010010, 0x01010010, 0x00000110, // 0001h + 0x00011010, 0x01100010, 0x00000010, 0x00000010, + 0x00000000, 0x01011010, 0x01010010, 0x00010010, // 0002h + 0x00100010, 0x00100010, 0x00100001, 0x00100001, + 0x00000000, 0x01010001, 0x01010001, 0x01111111, // 0003h + 0x00000001, 0x00000001, 0x00000001, 0x01111110, + 0x00000000, 0x01010000, 0x01111111, 0x00100000, // 0004h + 0x00100000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x01010000, 0x01010100, 0x00001010, // 0005h + 0x00010001, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01011000, 0x01011000, 0x01111111, // 0006h + 0x00001000, 0x00101010, 0x01001010, 0x01001001, + 0x00000000, 0x01010010, 0x01101111, 0x01010010, // 0007h + 0x00010010, 0x00010010, 0x00010010, 0x00001001, + 0x00000000, 0x01010010, 0x01011111, 0x00000100, // 0008h + 0x00011111, 0x00001000, 0x00000001, 0x00011110, + 0x00000000, 0x01010000, 0x01011000, 0x00000110, // 0009h + 0x00000001, 0x00000110, 0x00011000, 0x00100000, + 0x00000000, 0x01010000, 0x01111101, 0x00010001, // 000ah + 0x00010001, 0x00010001, 0x00010001, 0x00001010, + 0x00000000, 0x01010000, 0x01011110, 0x00100000, // 000bh + 0x00000000, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x01010100, 0x01011111, 0x00001000, // 000ch + 0x00010000, 0x00000001, 0x00000001, 0x00011110, + 0x00000000, 0x01010001, 0x01010001, 0x00000001, // 000dh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01010000, 0x01111111, 0x00011000, // 000eh + 0x00010100, 0x00010100, 0x00011000, 0x00001100, + 0x00000000, 0x01010010, 0x01111111, 0x00010010, // 000fh + 0x00010010, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x00001110, 0x01010100, 0x01010010, // 0010h + 0x00111111, 0x00000100, 0x00000100, 0x00011000, + 0x00000000, 0x01010100, 0x01011111, 0x00000100, // 0011h + 0x01110100, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x01010100, 0x01011111, 0x00000010, // 0012h + 0x00011110, 0x00100001, 0x00100000, 0x00011110, + 0x00000000, 0x01010000, 0x01011100, 0x00100011, // 0013h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01010000, 0x01111111, 0x00010000, // 0014h + 0x00001000, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x01010010, 0x01010010, 0x00001100, // 0015h + 0x00000010, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x01010001, 0x01111101, 0x00010001, // 0016h + 0x00010001, 0x00111001, 0x01010101, 0x00011001, + 0x00000000, 0x01010100, 0x01010011, 0x01110010, // 0017h + 0x00010001, 0x00010001, 0x00001010, 0x00000100, + 0x00000000, 0x01011110, 0x01011000, 0x00000100, // 0018h + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x01010000, 0x01011100, 0x00010010, // 0019h + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01011101, 0x01010001, 0x00111101, // 001ah + 0x00010001, 0x00011001, 0x00110101, 0x00001001, + 0x00000000, 0x01110001, 0x01011101, 0x00110001, // 001bh + 0x00010001, 0x00111001, 0x01010101, 0x00011001, + 0x00000000, 0x01110100, 0x01010011, 0x00110010, // 001ch + 0x00010001, 0x00010001, 0x00001010, 0x00000100, + 0x00000000, 0x01101110, 0x01011000, 0x00100100, // 001dh + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x01110000, 0x01011100, 0x00110010, // 001eh + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01111101, 0x01010001, 0x00111101, // 001fh + 0x00010001, 0x00011001, 0x00110101, 0x00001001, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 0020h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 0021h + 0x00001000, 0x00001000, 0x00000000, 0x00001000, + 0x00000000, 0x01101100, 0x01001000, 0x00100100, // 0022h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00100100, 0x01111111, 0x00100100, // 0023h + 0x00100100, 0x01111111, 0x00010010, 0x00010010, + 0x00000000, 0x00001000, 0x01111110, 0x00001001, // 0024h + 0x00111110, 0x01001000, 0x00111111, 0x00001000, + 0x00000000, 0x01000010, 0x00100101, 0x00010010, // 0025h + 0x00001000, 0x00100100, 0x01010010, 0x00100001, + 0x00000000, 0x00001110, 0x00010001, 0x00001001, // 0026h + 0x01000110, 0x00101001, 0x00110001, 0x01001110, + 0x00000000, 0x00011000, 0x00010000, 0x00001000, // 0027h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01110000, 0x00001000, 0x00000100, // 0028h + 0x00000100, 0x00000100, 0x00001000, 0x01110000, + 0x00000000, 0x00000111, 0x00001000, 0x00010000, // 0029h + 0x00010000, 0x00010000, 0x00001000, 0x00000111, + 0x00000000, 0x00001000, 0x01001001, 0x00101010, // 002ah + 0x00011100, 0x00101010, 0x01001001, 0x00001000, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 002bh + 0x01111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002ch + 0x00000000, 0x00001100, 0x00001000, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002dh + 0x01111111, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 002eh + 0x00000000, 0x00000000, 0x00000000, 0x00001100, + 0x00000000, 0x01000000, 0x00100000, 0x00010000, // 002fh + 0x00001000, 0x00000100, 0x00000010, 0x00000001, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0030h + 0x01000001, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x00011100, 0x00010000, 0x00010000, // 0031h + 0x00010000, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x00111110, 0x01000001, 0x01000000, // 0032h + 0x00111110, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x00111110, 0x01000001, 0x01000000, // 0033h + 0x00111110, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x00100000, 0x00110000, 0x00101000, // 0034h + 0x00100100, 0x00100010, 0x01111111, 0x00100000, + 0x00000000, 0x01111111, 0x00000001, 0x00111111, // 0035h + 0x01000000, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x00111110, 0x00000001, 0x00111111, // 0036h + 0x01000001, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x01111111, 0x00100000, 0x00100000, // 0037h + 0x00010000, 0x00010000, 0x00001000, 0x00001000, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0038h + 0x00111110, 0x01000001, 0x01000001, 0x00111110, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 0039h + 0x01000001, 0x01111110, 0x01000000, 0x00111110, + 0x00000000, 0x00000000, 0x00001100, 0x00000000, // 003ah + 0x00000000, 0x00000000, 0x00001100, 0x00000000, + 0x00000000, 0x00000000, 0x00001100, 0x00000000, // 003bh + 0x00000000, 0x00001100, 0x00001000, 0x00000100, + 0x00000000, 0x01100000, 0x00011000, 0x00000110, // 003ch + 0x00000001, 0x00000110, 0x00011000, 0x01100000, + 0x00000000, 0x00000000, 0x01111111, 0x00000000, // 003dh + 0x00000000, 0x00000000, 0x01111111, 0x00000000, + 0x00000000, 0x00000011, 0x00001100, 0x00110000, // 003eh + 0x01000000, 0x00110000, 0x00001100, 0x00000011, + 0x00000000, 0x00111110, 0x01000001, 0x01000001, // 003fh + 0x00110000, 0x00001000, 0x00000000, 0x00001000, + 0x00000000, 0x00011100, 0x00100010, 0x01001001, // 0040h + 0x01010101, 0x01010101, 0x01010101, 0x00111010, + 0x00000000, 0x00001000, 0x00010100, 0x00010100, // 0041h + 0x00100010, 0x00111110, 0x01000001, 0x01000001, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0042h + 0x00111111, 0x01000001, 0x01000001, 0x00111111, + 0x00000000, 0x00111100, 0x01000010, 0x00000001, // 0043h + 0x00000001, 0x00000001, 0x01000010, 0x00111100, + 0x00000000, 0x00011111, 0x00100001, 0x01000001, // 0044h + 0x01000001, 0x01000001, 0x00100001, 0x00011111, + 0x00000000, 0x01111111, 0x00000001, 0x00000001, // 0045h + 0x01111111, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x01111111, 0x00000001, 0x00000001, // 0046h + 0x00111111, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00111100, 0x01000010, 0x00000001, // 0047h + 0x01111001, 0x01000001, 0x01000010, 0x00111100, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0048h + 0x01111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00111110, 0x00001000, 0x00001000, // 0049h + 0x00001000, 0x00001000, 0x00001000, 0x00111110, + 0x00000000, 0x01000000, 0x01000000, 0x01000000, // 004ah + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01100001, 0x00011001, 0x00000101, // 004bh + 0x00000011, 0x00000101, 0x00011001, 0x01100001, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 004ch + 0x00000001, 0x00000001, 0x00000001, 0x01111111, + 0x00000000, 0x01000001, 0x01100011, 0x01010101, // 004dh + 0x01001001, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x01000001, 0x01000011, 0x01000101, // 004eh + 0x01001001, 0x01010001, 0x01100001, 0x01000001, + 0x00000000, 0x00011100, 0x00100010, 0x01000001, // 004fh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0050h + 0x00111111, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00011100, 0x00100010, 0x01000001, // 0051h + 0x01000001, 0x01011001, 0x00100010, 0x01011100, + 0x00000000, 0x00111111, 0x01000001, 0x01000001, // 0052h + 0x00111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00111110, 0x01000001, 0x00000001, // 0053h + 0x00111110, 0x01000000, 0x01000001, 0x00111110, + 0x00000000, 0x01111111, 0x00001000, 0x00001000, // 0054h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0055h + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x01000001, 0x01000001, 0x00100010, // 0056h + 0x00100010, 0x00010100, 0x00010100, 0x00001000, + 0x00000000, 0x01000001, 0x01000001, 0x01000001, // 0057h + 0x01001001, 0x01010101, 0x01100011, 0x01000001, + 0x00000000, 0x01000001, 0x00100010, 0x00010100, // 0058h + 0x00001000, 0x00010100, 0x00100010, 0x01000001, + 0x00000000, 0x01000001, 0x00100010, 0x00010100, // 0059h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01111111, 0x00100000, 0x00010000, // 005ah + 0x00001000, 0x00000100, 0x00000010, 0x01111111, + 0x00000000, 0x01111100, 0x00000100, 0x00000100, // 005bh + 0x00000100, 0x00000100, 0x00000100, 0x01111100, + 0x00000000, 0x00100010, 0x00010100, 0x00111110, // 005ch + 0x00001000, 0x00111110, 0x00001000, 0x00001000, + 0x00000000, 0x00011111, 0x00010000, 0x00010000, // 005dh + 0x00010000, 0x00010000, 0x00010000, 0x00011111, + 0x00000000, 0x00001000, 0x00010100, 0x00100010, // 005eh + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 005fh + 0x00000000, 0x00000000, 0x00000000, 0x01111111, + 0x00000000, 0x00010000, 0x00001000, 0x00011000, // 0060h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00011110, 0x00100001, // 0061h + 0x00111110, 0x00100001, 0x00100001, 0x01011110, + 0x00000000, 0x00000001, 0x00000001, 0x00111111, // 0062h + 0x01000001, 0x01000001, 0x01000001, 0x00111111, + 0x00000000, 0x00000000, 0x00111100, 0x01000010, // 0063h + 0x00000001, 0x00000001, 0x01000010, 0x00111100, + 0x00000000, 0x01000000, 0x01000000, 0x01111110, // 0064h + 0x01000001, 0x01000001, 0x01000001, 0x01111110, + 0x00000000, 0x00000000, 0x00111110, 0x01000001, // 0065h + 0x01111111, 0x00000001, 0x01000001, 0x00111110, + 0x00000000, 0x00110000, 0x00001000, 0x00001000, // 0066h + 0x01111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x01111110, 0x01000001, // 0067h + 0x01000001, 0x01111110, 0x01000000, 0x00111110, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 0068h + 0x00111111, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00001000, 0x00000000, 0x00001000, // 0069h + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00100000, 0x00000000, 0x00100000, // 006ah + 0x00100000, 0x00100001, 0x00100001, 0x00011110, + 0x00000000, 0x00000001, 0x00000001, 0x01100001, // 006bh + 0x00011001, 0x00000111, 0x00011001, 0x01100001, + 0x00000000, 0x00001000, 0x00001000, 0x00001000, // 006ch + 0x00001000, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00110111, 0x01001001, // 006dh + 0x01001001, 0x01001001, 0x01001001, 0x01001001, + 0x00000000, 0x00000000, 0x00111111, 0x01000001, // 006eh + 0x01000001, 0x01000001, 0x01000001, 0x01000001, + 0x00000000, 0x00000000, 0x00011100, 0x00100010, // 006fh + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00000000, 0x00111101, 0x01000011, // 0070h + 0x01000001, 0x01000011, 0x00111101, 0x00000001, + 0x00000000, 0x00000000, 0x01011110, 0x01100001, // 0071h + 0x01000001, 0x01100001, 0x01011110, 0x01000000, + 0x00000000, 0x00000000, 0x00110001, 0x00001101, // 0072h + 0x00000011, 0x00000001, 0x00000001, 0x00000001, + 0x00000000, 0x00000000, 0x00111110, 0x01000001, // 0073h + 0x00001110, 0x00110000, 0x01000001, 0x00111110, + 0x00000000, 0x00000100, 0x00000100, 0x01111111, // 0074h + 0x00000100, 0x00000100, 0x00000100, 0x01111000, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0075h + 0x01000001, 0x01000001, 0x01000001, 0x01111110, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0076h + 0x00100010, 0x00100010, 0x00010100, 0x00001000, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0077h + 0x01001001, 0x00101010, 0x00101010, 0x00010100, + 0x00000000, 0x00000000, 0x00100001, 0x00010010, // 0078h + 0x00001100, 0x00001100, 0x00010010, 0x00100001, + 0x00000000, 0x00000000, 0x01000001, 0x01000001, // 0079h + 0x00100010, 0x00011100, 0x00001000, 0x00000110, + 0x00000000, 0x00000000, 0x00111111, 0x00010000, // 007ah + 0x00001000, 0x00000100, 0x00000010, 0x00111111, + 0x00000000, 0x00001000, 0x00011110, 0x01100100, // 007bh + 0x00011000, 0x00100100, 0x00000100, 0x01111000, + 0x00000000, 0x00000000, 0x00011110, 0x00000100, // 007ch + 0x00011110, 0x00110101, 0x00101101, 0x00010010, + 0x00000000, 0x00000000, 0x00000000, 0x00010001, // 007dh + 0x00100001, 0x00100001, 0x00000001, 0x00000010, + 0x00000000, 0x00000000, 0x00011100, 0x00000000, // 007eh + 0x00011110, 0x00100000, 0x00100000, 0x00011100, + 0x00000000, 0x00000000, 0x00011100, 0x00000000, // 007fh + 0x00111110, 0x00010000, 0x00001100, 0x00110010, + 0x00000000, 0x00000000, 0x00000100, 0x00101111, // 0080h + 0x01000100, 0x00011110, 0x00100101, 0x00010110, + 0x00000000, 0x00000000, 0x00001010, 0x00011110, // 0081h + 0x00101011, 0x00100010, 0x00010100, 0x00000100, + 0x00000000, 0x00000000, 0x00001000, 0x00011101, // 0082h + 0x00101011, 0x00101001, 0x00011001, 0x00000100, + 0x00000000, 0x00000000, 0x00001000, 0x00111000, // 0083h + 0x00001000, 0x00011110, 0x00101001, 0x00000110, + 0x00000000, 0x00000000, 0x00000000, 0x00011100, // 0084h + 0x00100011, 0x00100000, 0x00100000, 0x00011100, + 0x00000000, 0x00000110, 0x01001001, 0x00110000, // 0085h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000100, 0x00111111, 0x00000100, // 0086h + 0x00111110, 0x01010101, 0x01001101, 0x00100110, + 0x00000000, 0x00000000, 0x00100001, 0x01000001, // 0087h + 0x01000001, 0x01000001, 0x00000001, 0x00000010, + 0x00000000, 0x00111100, 0x00000000, 0x00111110, // 0088h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x00011100, 0x00000000, 0x00111110, // 0089h + 0x00010000, 0x00001000, 0x00010100, 0x01100010, + 0x00000000, 0x00100100, 0x01011111, 0x00000100, // 008ah + 0x00111110, 0x01000101, 0x01000101, 0x00100010, + 0x00000000, 0x00100010, 0x01001111, 0x01010010, // 008bh + 0x01010010, 0x00010010, 0x00010010, 0x00001001, + 0x00000000, 0x00000100, 0x00111110, 0x00001000, // 008ch + 0x00111110, 0x00010000, 0x00000010, 0x00111100, + 0x00000000, 0x00100000, 0x00011000, 0x00000110, // 008dh + 0x00000001, 0x00000110, 0x00011000, 0x00100000, + 0x00000000, 0x00100000, 0x01111101, 0x00100001, // 008eh + 0x00100001, 0x00100001, 0x00100001, 0x00010010, + 0x00000000, 0x00011110, 0x00100000, 0x00000000, // 008fh + 0x00000000, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x00001000, 0x01111111, 0x00010000, // 0090h + 0x00100000, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x00000001, 0x00000001, 0x00000001, // 0091h + 0x01000001, 0x01000001, 0x00100010, 0x00011100, + 0x00000000, 0x00010000, 0x01111111, 0x00011000, // 0092h + 0x00010100, 0x00010100, 0x00011000, 0x00001100, + 0x00000000, 0x00100010, 0x01111111, 0x00100010, // 0093h + 0x00100010, 0x00000010, 0x00000010, 0x01111100, + 0x00000000, 0x00111100, 0x00010000, 0x00001100, // 0094h + 0x01111111, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x00000100, 0x00011111, 0x00000100, // 0095h + 0x01110100, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x00001000, 0x01111111, 0x00000100, // 0096h + 0x00111100, 0x01000010, 0x01000000, 0x00111100, + 0x00000000, 0x00000000, 0x00011100, 0x00100011, // 0097h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01111111, 0x00010000, 0x00001000, // 0098h + 0x00001000, 0x00001000, 0x00001000, 0x00110000, + 0x00000000, 0x00000010, 0x00110010, 0x00001100, // 0099h + 0x00000010, 0x00000001, 0x00000001, 0x00111110, + 0x00000000, 0x00100100, 0x01001111, 0x01000010, // 009ah + 0x00010001, 0x00111100, 0x00010010, 0x00001100, + 0x00000000, 0x00000010, 0x01111010, 0x01000010, // 009bh + 0x00000010, 0x00000010, 0x00001010, 0x01110010, + 0x00000000, 0x00100010, 0x00111110, 0x01010010, // 009ch + 0x01001011, 0x01101101, 0x01010101, 0x00110010, + 0x00000000, 0x00110010, 0x01001011, 0x01000110, // 009dh + 0x01000110, 0x01110010, 0x01001011, 0x00110010, + 0x00000000, 0x00011100, 0x00101010, 0x01001001, // 009eh + 0x01001001, 0x01000101, 0x01000101, 0x00110010, + 0x00000000, 0x00100001, 0x01111101, 0x00100001, // 009fh + 0x00100001, 0x00111001, 0x01100101, 0x00011001, + 0x00000000, 0x00000100, 0x00100011, 0x01100010, // 00a0h + 0x00100001, 0x00100001, 0x00010010, 0x00001100, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a1h + 0x00000000, 0x00000100, 0x00001010, 0x00000100, + 0x00000000, 0x01110000, 0x00010000, 0x00010000, // 00a2h + 0x00010000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a3h + 0x00001000, 0x00001000, 0x00001000, 0x00001110, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00a4h + 0x00000000, 0x00000010, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00011000, // 00a5h + 0x00011000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01111111, 0x01000000, 0x01111111, // 00a6h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x00000000, 0x00111111, 0x00100000, // 00a7h + 0x00010100, 0x00001100, 0x00000100, 0x00000010, + 0x00000000, 0x00000000, 0x00100000, 0x00100000, // 00a8h + 0x00010000, 0x00001111, 0x00001000, 0x00001000, + 0x00000000, 0x00000000, 0x00000100, 0x00111111, // 00a9h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x00000000, 0x00000000, 0x00111110, // 00aah + 0x00001000, 0x00001000, 0x00001000, 0x01111111, + 0x00000000, 0x00000000, 0x00010000, 0x00111111, // 00abh + 0x00011000, 0x00010100, 0x00010010, 0x00011001, + 0x00000000, 0x00000000, 0x00000010, 0x00111111, // 00ach + 0x00100010, 0x00010010, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00000000, 0x00111110, // 00adh + 0x00100000, 0x00100000, 0x00100000, 0x01111111, + 0x00000000, 0x00000000, 0x00111110, 0x00100000, // 00aeh + 0x00111110, 0x00100000, 0x00100000, 0x00111110, + 0x00000000, 0x00000000, 0x00100101, 0x00101010, // 00afh + 0x00101010, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 00b0h + 0x01111111, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x01111111, 0x01000000, 0x00101000, // 00b1h + 0x00011000, 0x00001000, 0x00001000, 0x00000100, + 0x00000000, 0x01000000, 0x00100000, 0x00011000, // 00b2h + 0x00010111, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x00001000, 0x01111111, 0x01000001, // 00b3h + 0x01000001, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00000000, 0x00111110, 0x00001000, // 00b4h + 0x00001000, 0x00001000, 0x00001000, 0x01111111, + 0x00000000, 0x00100000, 0x01111111, 0x00110000, // 00b5h + 0x00101000, 0x00100100, 0x00100010, 0x00110001, + 0x00000000, 0x00000100, 0x01111111, 0x01000100, // 00b6h + 0x01000100, 0x01000100, 0x01000010, 0x00100001, + 0x00000000, 0x00000100, 0x00111111, 0x00001000, // 00b7h + 0x01111111, 0x00010000, 0x00010000, 0x00010000, + 0x00000000, 0x01111100, 0x01000100, 0x01000100, // 00b8h + 0x01000010, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00000010, 0x01111110, 0x00100010, // 00b9h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01111110, 0x01000000, 0x01000000, // 00bah + 0x01000000, 0x01000000, 0x01000000, 0x01111110, + 0x00000000, 0x00100010, 0x01111111, 0x00100010, // 00bbh + 0x00100010, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x00000011, 0x00000100, 0x01000011, // 00bch + 0x01000100, 0x00100000, 0x00011000, 0x00000111, + 0x00000000, 0x01111111, 0x01000000, 0x00100000, // 00bdh + 0x00010000, 0x00011000, 0x00100100, 0x01000011, + 0x00000000, 0x00000010, 0x01111111, 0x01000010, // 00beh + 0x00100010, 0x00000010, 0x00000010, 0x01111100, + 0x00000000, 0x01000001, 0x01000010, 0x01000000, // 00bfh + 0x00100000, 0x00100000, 0x00011000, 0x00000110, + 0x00000000, 0x01111110, 0x01000010, 0x01001110, // 00c0h + 0x01110001, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x01100000, 0x00011110, 0x00010000, // 00c1h + 0x01111111, 0x00010000, 0x00010000, 0x00001100, + 0x00000000, 0x01000101, 0x01001010, 0x01001010, // 00c2h + 0x01000000, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00111110, 0x00000000, 0x01111111, // 00c3h + 0x00010000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x00000010, 0x00000010, 0x00000110, // 00c4h + 0x00011010, 0x01100010, 0x00000010, 0x00000010, + 0x00000000, 0x00010000, 0x00010000, 0x01111111, // 00c5h + 0x00010000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x00000000, 0x00111110, 0x00000000, // 00c6h + 0x00000000, 0x00000000, 0x00000000, 0x01111111, + 0x00000000, 0x01111110, 0x01000000, 0x01000100, // 00c7h + 0x00101000, 0x00010000, 0x00101000, 0x01000110, + 0x00000000, 0x00001000, 0x01111111, 0x00100000, // 00c8h + 0x00010000, 0x00011100, 0x01101011, 0x00001000, + 0x00000000, 0x01000000, 0x01000000, 0x01000000, // 00c9h + 0x00100000, 0x00100000, 0x00011000, 0x00000111, + 0x00000000, 0x00010010, 0x00100010, 0x00100010, // 00cah + 0x01000010, 0x01000010, 0x01000001, 0x01000001, + 0x00000000, 0x00000001, 0x00000001, 0x01111111, // 00cbh + 0x00000001, 0x00000001, 0x00000001, 0x01111110, + 0x00000000, 0x01111111, 0x01000000, 0x01000000, // 00cch + 0x01000000, 0x00100000, 0x00010000, 0x00001110, + 0x00000000, 0x00000000, 0x00000100, 0x00001010, // 00cdh + 0x00010001, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x00001000, 0x00001000, 0x01111111, // 00ceh + 0x00001000, 0x00101010, 0x01001010, 0x01001001, + 0x00000000, 0x01111111, 0x01000000, 0x01000000, // 00cfh + 0x00100010, 0x00010100, 0x00001000, 0x00010000, + 0x00000000, 0x00001110, 0x01110000, 0x00001110, // 00d0h + 0x01110000, 0x00000110, 0x00011000, 0x01100000, + 0x00000000, 0x00001000, 0x00001000, 0x00000100, // 00d1h + 0x00000100, 0x00100010, 0x01000010, 0x01111111, + 0x00000000, 0x01000000, 0x01000000, 0x00100100, // 00d2h + 0x00101000, 0x00010000, 0x00101100, 0x01000011, + 0x00000000, 0x01111111, 0x00000100, 0x01111111, // 00d3h + 0x00000100, 0x00000100, 0x00000100, 0x01111000, + 0x00000000, 0x00000010, 0x01111111, 0x01000010, // 00d4h + 0x00100010, 0x00010100, 0x00000100, 0x00000100, + 0x00000000, 0x00000000, 0x00111110, 0x00100000, // 00d5h + 0x00100000, 0x00100000, 0x00100000, 0x01111111, + 0x00000000, 0x01111110, 0x01000000, 0x01000000, // 00d6h + 0x01111110, 0x01000000, 0x01000000, 0x01111110, + 0x00000000, 0x00111110, 0x00000000, 0x01111111, // 00d7h + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01000010, 0x01000010, 0x01000010, // 00d8h + 0x01000010, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00001010, 0x00001010, 0x00001010, // 00d9h + 0x01001010, 0x01001010, 0x00101010, 0x00011001, + 0x00000000, 0x00000010, 0x00000010, 0x01000010, // 00dah + 0x01000010, 0x00100010, 0x00010010, 0x00001110, + 0x00000000, 0x01111111, 0x01000001, 0x01000001, // 00dbh + 0x01000001, 0x01000001, 0x01000001, 0x01111111, + 0x00000000, 0x01111111, 0x01000001, 0x01000001, // 00dch + 0x01000000, 0x01000000, 0x00100000, 0x00011100, + 0x00000000, 0x01000011, 0x01000100, 0x01000000, // 00ddh + 0x01000000, 0x00100000, 0x00010000, 0x00001111, + 0x00000100, 0x00001000, 0x00000010, 0x00000100, // 00deh + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000100, 0x00001010, 0x00001010, 0x00000100, // 00dfh + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00011110, 0x00001000, 0x00000100, // 00e0h + 0x00101001, 0x01010001, 0x01010001, 0x00001100, + 0x00000000, 0x00000000, 0x00001100, 0x00010010, // 00e1h + 0x00010010, 0x00100001, 0x01000000, 0x00000000, + 0x00000000, 0x01111101, 0x00100001, 0x01111101, // 00e2h + 0x00100001, 0x00111001, 0x01100101, 0x00011001, + 0x00000000, 0x00111100, 0x00010000, 0x00111100, // 00e3h + 0x00010000, 0x00011100, 0x00110010, 0x00001100, + 0x00000000, 0x00001110, 0x00101000, 0x00101000, // 00e4h + 0x00111110, 0x01100101, 0x00100101, 0x00010010, + 0x00000000, 0x00000100, 0x00101111, 0x01000100, // 00e5h + 0x00000110, 0x01000101, 0x01000101, 0x00111110, + 0x00000000, 0x00100010, 0x00100010, 0x00111110, // 00e6h + 0x01010010, 0x01010101, 0x01001101, 0x00100110, + 0x00000000, 0x00000100, 0x00011111, 0x00000010, // 00e7h + 0x00011111, 0x01000010, 0x01000010, 0x00111100, + 0x00000000, 0x00010010, 0x00111110, 0x01010011, // 00e8h + 0x01000010, 0x00100100, 0x00000100, 0x00000100, + 0x00000000, 0x00001000, 0x00111101, 0x01001011, // 00e9h + 0x01001001, 0x01001001, 0x00111000, 0x00000100, + 0x00000000, 0x00001000, 0x00111000, 0x00001000, // 00eah + 0x00001000, 0x00011110, 0x00101001, 0x00000110, + 0x00000000, 0x00011000, 0x00100000, 0x00000100, // 00ebh + 0x00111010, 0x01000110, 0x01000000, 0x00111000, + 0x00000000, 0x01000010, 0x01000010, 0x01000010, // 00ech + 0x01000110, 0x01000000, 0x00100000, 0x00011000, + 0x00000000, 0x00111110, 0x00010000, 0x00111100, // 00edh + 0x01000011, 0x01001100, 0x01010010, 0x00111100, + 0x00000000, 0x00100010, 0x00110011, 0x00101010, // 00eeh + 0x00100110, 0x00100010, 0x00100011, 0x01000010, + 0x00000000, 0x00111110, 0x00010000, 0x00111100, // 00efh + 0x01000011, 0x01000000, 0x01000010, 0x00111100, + 0x00000000, 0x00000010, 0x00111011, 0x01000110, // 00f0h + 0x01000010, 0x01000011, 0x01000010, 0x00110010, + 0x00000000, 0x00000100, 0x00000100, 0x00000010, // 00f1h + 0x01000110, 0x01000101, 0x01000101, 0x00111001, + 0x00000000, 0x01010100, 0x01111111, 0x00100100, // 00f2h + 0x00100100, 0x00100100, 0x00100010, 0x00010001, + 0x00000000, 0x01010100, 0x01011111, 0x00000100, // 00f3h + 0x00111111, 0x00001000, 0x00001000, 0x00001000, + 0x00000000, 0x01011110, 0x01100010, 0x00100010, // 00f4h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01010010, 0x01111110, 0x00100010, // 00f5h + 0x00100001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01010000, 0x01111111, 0x00100000, // 00f6h + 0x00100000, 0x00100000, 0x00100000, 0x00111111, + 0x00000000, 0x01010010, 0x01010010, 0x00111111, // 00f7h + 0x00010010, 0x00010000, 0x00010000, 0x00001100, + 0x00000000, 0x01010011, 0x01010100, 0x00100011, // 00f8h + 0x00100100, 0x00010000, 0x00001000, 0x00000111, + 0x00000000, 0x01010000, 0x01011111, 0x00010000, // 00f9h + 0x00001000, 0x00001100, 0x00010010, 0x00100001, + 0x00000000, 0x01010010, 0x01111111, 0x00100010, // 00fah + 0x00010010, 0x00000010, 0x00000010, 0x00111100, + 0x00000000, 0x01010001, 0x01010010, 0x00100000, // 00fbh + 0x00100000, 0x00010000, 0x00001000, 0x00000110, + 0x00000000, 0x01011110, 0x01010010, 0x00100110, // 00fch + 0x00111001, 0x00100000, 0x00010000, 0x00001100, + 0x00000000, 0x01010000, 0x01011110, 0x00010000, // 00fdh + 0x01111111, 0x00010000, 0x00010000, 0x00001100, + 0x00000000, 0x00100101, 0x01001010, 0x00101010, // 00feh + 0x00100000, 0x00010000, 0x00001000, 0x00000111, + 0x00000000, 0x01011110, 0x01010000, 0x00111111, // 00ffh + 0x00001000, 0x00001000, 0x00001000, 0x00000110, +}; + +/*---------------------- Character Data2 -------------------------*/ +const unsigned int d_64_256_bg_schDT2[16 * 11] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // 0000h + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xf1f1f1f1, 0xf1f1f1f1, 0x00000000, 0x00000000, // + 0xf1f1f1f1, 0xf1f1f1f1, 0x00000000, 0x00000000, + 0xf1f1f1f1, 0xf1f1f1f1, 0x00000000, 0x00000000, + 0xf1f1f1f1, 0xf1f1f1f1, 0x00000000, 0x00000000, + 0xf100f100, 0xf100f100, 0xf100f100, 0xf100f100, // c + 0xf100f100, 0xf100f100, 0xf100f100, 0xf100f100, + 0xf100f100, 0xf100f100, 0xf100f100, 0xf100f100, + 0xf100f100, 0xf100f100, 0xf100f100, 0xf100f100, + 0xf1f1f1f1, 0xf1f1f1f1, 0xf1f1f1f1, 0xf1f1f1f1, // w + 0xf1f1f1f1, 0xf1f1f1f1, 0xf1f1f1f1, 0xf1f1f1f1, + 0xf1f1f1f1, 0xf1f1f1f1, 0xf1f1f1f1, 0xf1f1f1f1, + 0xf1f1f1f1, 0xf1f1f1f1, 0xf1f1f1f1, 0xf1f1f1f1, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, // blk + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, // r + 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x11111111, 0x11111111, 0x11111111, 0x11111111, + 0x21212121, 0x21212121, 0x21212121, 0x21212121, // g + 0x21212121, 0x21212121, 0x21212121, 0x21212121, + 0x21212121, 0x21212121, 0x21212121, 0x21212121, + 0x21212121, 0x21212121, 0x21212121, 0x21212121, + 0x31313131, 0x31313131, 0x31313131, 0x31313131, // b + 0x31313131, 0x31313131, 0x31313131, 0x31313131, + 0x31313131, 0x31313131, 0x31313131, 0x31313131, + 0x31313131, 0x31313131, 0x31313131, 0x31313131, + 0x41414141, 0x41414141, 0x41414141, 0x41414141, // y + 0x41414141, 0x41414141, 0x41414141, 0x41414141, + 0x41414141, 0x41414141, 0x41414141, 0x41414141, + 0x41414141, 0x41414141, 0x41414141, 0x41414141, + 0x51515151, 0x51515151, 0x51515151, 0x51515151, // m + 0x51515151, 0x51515151, 0x51515151, 0x51515151, + 0x51515151, 0x51515151, 0x51515151, 0x51515151, + 0x51515151, 0x51515151, 0x51515151, 0x51515151, + 0x61616161, 0x61616161, 0x61616161, 0x61616161, // c + 0x61616161, 0x61616161, 0x61616161, 0x61616161, + 0x61616161, 0x61616161, 0x61616161, 0x61616161, + 0x61616161, 0x61616161, 0x61616161, 0x61616161, +}; + +/* EOF */ diff --git a/build/tests/data/data.h b/build/tests/data/data.h new file mode 100644 index 00000000..7f1e3c9e --- /dev/null +++ b/build/tests/data/data.h @@ -0,0 +1,29 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - GX - demos - UnitTours/2D_CharBg_1 + File: data.h + + Copyright 2003 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-08-29#$ + $Rev: 640 $ + $Author: kitase_hirotake $ + *---------------------------------------------------------------------------*/ + +#ifndef BG_DATA_H_ +#define BG_DATA_H_ + +#define SCREEN_SIZE (32 * 24) + +/*-------------------------- Data -------------------------------*/ +#define CHAR_SIZE (16 * 128 * sizeof(int)) +extern const unsigned int d_64_256_bg_schDT[8 * 256]; +extern const unsigned int d_64_256_bg_schDT2[16 * 11]; +extern const unsigned int d_64_256_bg_sclDT[8 * 16]; + +#endif diff --git a/build/tests/docs/NANDアプリ間連携サンプル動作解説およびパラメタ仕様.pdf b/build/tests/docs/NANDアプリ間連携サンプル動作解説およびパラメタ仕様.pdf new file mode 100644 index 00000000..e3dd1e5f Binary files /dev/null and b/build/tests/docs/NANDアプリ間連携サンプル動作解説およびパラメタ仕様.pdf differ diff --git a/build/tests/docs/NANDアプリ間連携サンプル動作解説およびパラメタ仕様.vsd b/build/tests/docs/NANDアプリ間連携サンプル動作解説およびパラメタ仕様.vsd new file mode 100644 index 00000000..09a83d4f Binary files /dev/null and b/build/tests/docs/NANDアプリ間連携サンプル動作解説およびパラメタ仕様.vsd differ diff --git a/build/tests/docs/tmp保存アプリ起動サンプル動作解説.pdf b/build/tests/docs/tmp保存アプリ起動サンプル動作解説.pdf new file mode 100644 index 00000000..a677975a Binary files /dev/null and b/build/tests/docs/tmp保存アプリ起動サンプル動作解説.pdf differ diff --git a/build/tests/docs/tmp保存アプリ起動サンプル動作解説.vsd b/build/tests/docs/tmp保存アプリ起動サンプル動作解説.vsd new file mode 100644 index 00000000..c833785f Binary files /dev/null and b/build/tests/docs/tmp保存アプリ起動サンプル動作解説.vsd differ diff --git a/build/tests/docs/メモリロード済みアプリ起動サンプル動作解説.pdf b/build/tests/docs/メモリロード済みアプリ起動サンプル動作解説.pdf new file mode 100644 index 00000000..4864d5bd Binary files /dev/null and b/build/tests/docs/メモリロード済みアプリ起動サンプル動作解説.pdf differ diff --git a/build/tests/docs/メモリロード済みアプリ起動サンプル動作解説.vsd b/build/tests/docs/メモリロード済みアプリ起動サンプル動作解説.vsd new file mode 100644 index 00000000..f7e11360 Binary files /dev/null and b/build/tests/docs/メモリロード済みアプリ起動サンプル動作解説.vsd differ diff --git a/build/tests/misc/misc_simple.c b/build/tests/misc/misc_simple.c new file mode 100644 index 00000000..4f5c5d29 --- /dev/null +++ b/build/tests/misc/misc_simple.c @@ -0,0 +1,154 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: misc.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2008-01-30#$ + $Rev: 547 $ + $Author: yoshida_teruhisa $ + *---------------------------------------------------------------------------*/ + +#include +#include "misc_simple.h" +#include "data.h" + +// define data----------------------------------------------------------------- + + +// extern data----------------------------------------------------------------- + +// define data----------------------------------------------------------------- + + +// function's prototype------------------------------------------------------- + + +// global variable------------------------------------------------------------- + + +// static variable------------------------------------------------------------- +static u16 sScrnBuf[2][SCREEN_SIZE]; // Buffer for screen data(BG #0) + +// const data------------------------------------------------------------------ + +void myInit( void ) +{ + //--------------------------------------------------------------------------- + // Initialize: + // They enable IRQ interrupts, initialize VRAM, and set BG #0 for text mode. + //--------------------------------------------------------------------------- + DEMOInitCommon(); + DEMOInitVRAM(); + DEMOInitDisplayBG0Only(); + DEMOInitDisplaySubBG0Only(); + + //--------------------------------------------------------------------------- + // Transmitting the character data and the palette data + //--------------------------------------------------------------------------- + G2_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256, + GX_BG_COLORMODE_16, + GX_BG_SCRBASE_0x0800, GX_BG_CHARBASE_0x04000, GX_BG_EXTPLTT_01); + + GX_LoadBG0Char(d_64_256_bg_schDT, 0, sizeof(d_64_256_bg_schDT)); + GX_LoadBGPltt(d_64_256_bg_sclDT, 0, sizeof(d_64_256_bg_sclDT)); + + G2S_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256, + GX_BG_COLORMODE_16, + GX_BG_SCRBASE_0x1000, GX_BG_CHARBASE_0x08000, GX_BG_EXTPLTT_01); + + GXS_LoadBG0Char(d_64_256_bg_schDT, 0, sizeof(d_64_256_bg_schDT)); + GXS_LoadBGPltt(d_64_256_bg_sclDT, 0, sizeof(d_64_256_bg_sclDT)); + + GX_SetVisiblePlane(GX_PLANEMASK_BG0|GX_PLANEMASK_BG2); + GXS_SetVisiblePlane(GX_PLANEMASK_BG0|GX_PLANEMASK_BG2); + + G2_SetBG0Priority(0); + G2S_SetBG0Priority(0); + + GX_SetDispSelect(GX_DISP_SELECT_SUB_MAIN); + + DEMOStartDisplay(); +} + +void myPreMain( void ) +{ + // `ONAB܂ǂ̃V[łĝŁB + myDp_Cls16(MAIN_SCREEN); + myDp_Cls16(SUB_SCREEN); + + DEMOReadKey(); +} + +void myProMain( void ) +{ + // Store the data onto the main memory, and invalidate the cache. + // LbVONɂȂĂƁACPUDMǍĂ郁̒lāA߂N + DC_FlushRange(sScrnBuf[0], sizeof(sScrnBuf[0])); + DC_FlushRange(sScrnBuf[1], sizeof(sScrnBuf[1])); + // `tbvB܂ǂ̃V[łĝŁB + OS_WaitVBlankIntr(); // Waiting the end of VBlank interrupt + GX_LoadBG0Scr(sScrnBuf[0], 0, sizeof(sScrnBuf[0])); + GXS_LoadBG0Scr(sScrnBuf[1], 0, sizeof(sScrnBuf[1])); +} + +void myDp_Cls16(MyScreen scr) +{ + if( !(scr < SCREEN_MAX) ) return; + MI_CpuClear8((void *)sScrnBuf[scr],SCREEN_SIZE * sizeof(u16)); +} + +void myDp_Cls8(MyScreen scr) +{ + if( !(scr < SCREEN_MAX) ) return; + MI_CpuClear8((void *)sScrnBuf[scr],SCREEN_SIZE * sizeof(u8)); +} + +void myDp_Putchar(s32 x, s32 y, u8 color, MyScreen scr, u8 c) +{ + if( !(scr < SCREEN_MAX) ) return; + sScrnBuf[scr][(y * 32) + x] = (u16)((color << 12) | c); +} + +void myDp_Write(s32 x, s32 y, u8 color, MyScreen scr, char* str) +{ + while (*str) { + while (x >= 32) { + x -= 32; + y++; + } + while (y >= 24) { + return; // out of range + } + myDp_Putchar(x, y, color, scr, (u8)*str++); + x++; + } +} + +void myDp_Printf(s32 x, s32 y, u8 color, MyScreen scr, const char *s, ...) +{ + va_list vlist; + char temp[SCREEN_SIZE+1]; + temp[sizeof(temp)-1] = 0; + va_start(vlist, s); + vsnprintf(temp, sizeof(temp) - 1, s, vlist); + va_end(vlist); + myDp_Write(x, y, color, scr, temp); +} + +void myDp_DrawMenu( u16 csr, MyScreen scr, const MenuParam *param ) +{ + int l; + for( l=0; lnum; l++) + { + myDp_Printf( param->pos[l].x, param->pos[l].y, + (u8)( param->pos[l].enable ? ( l==csr ? param->select_color : param->normal_color ) : param->disable_color ), + scr, ( l==csr ? "=>%s" : " %s" ), param->str_elem[l] ); + } +} \ No newline at end of file diff --git a/build/tests/misc/misc_simple.h b/build/tests/misc/misc_simple.h new file mode 100644 index 00000000..9064e906 --- /dev/null +++ b/build/tests/misc/misc_simple.h @@ -0,0 +1,97 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: misc.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-11-15#$ + $Rev: 188 $ + $Author: yoshida_teruhisa $ + *---------------------------------------------------------------------------*/ + +#ifndef __MISC_SIMPLE_H__ +#define __MISC_SIMPLE_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// define data---------------------------------------------------------- + +#define MYPAD_IS_TRIG DEMO_IS_TRIG +#define MYPAD_IS_PRESS DEMO_IS_PRESS + +// TXTColorPalette ̐F 256Fpbgւ̃[hz +enum +{ + TXT_COLOR_BLACK=0, + TXT_COLOR_RED, + TXT_COLOR_GREEN, + TXT_COLOR_BLUE, + TXT_COLOR_YELLOW, + TXT_COLOR_PURPLE, + TXT_COLOR_LIGHTBLUE, + TXT_COLOR_DARKRED, + TXT_COLOR_DARKGREEN, + TXT_COLOR_DARKBLUE, + TXT_COLOR_DARKYELLOW, + TXT_COLOR_DARKPURPLE, + TXT_COLOR_DARKLIGHTBLUE, + TXT_COLOR_GRAY, + TXT_COLOR_DARKGRAY, + TXT_COLOR_WHITE +}; + +typedef enum +{ + MAIN_SCREEN = 0, + SUB_SCREEN, + SCREEN_MAX +} +MyScreen; + +// j[vfW +typedef struct MenuPos { + BOOL enable; + int x; + int y; +}MenuPos; + +// j[\p[^\ +typedef struct MenuParam { + int num; + int normal_color; + int select_color; + int disable_color; + MenuPos *pos; + const char **str_elem; +}MenuParam; + +// global variables-------------------------------------------------- + +// function------------------------------------------------------------- +void myInit( void ); +void myPreMain( void ); +void myProMain( void ); + +void myDp_Cls16(MyScreen scr); +void myDp_Cls8(MyScreen scr); +void myDp_Putchar(s32 x, s32 y, u8 color, MyScreen scr, u8 c); +void myDp_Write(s32 x, s32 y, u8 color, MyScreen scr, char* str); +void myDp_Printf(s32 x, s32 y, u8 color, MyScreen scr, const char *s, ...); +void myDp_DrawMenu( u16 csr, MyScreen scr, const MenuParam *param ); + +#ifdef __cplusplus +} +#endif + +#endif // __MISC_H__ diff --git a/build/tools/Makefile b/build/tools/Makefile new file mode 100644 index 00000000..100895b3 --- /dev/null +++ b/build/tools/Makefile @@ -0,0 +1,37 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - firmware +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + makenorfirm \ + makegcdfirm \ + makenandfirm \ + makerom.TWL.sys \ + makerom.TWL.shop + + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tools/acsign/Makefile b/build/tools/acsign/Makefile new file mode 100644 index 00000000..d66418af --- /dev/null +++ b/build/tools/acsign/Makefile @@ -0,0 +1,61 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: NitroSDK - libraries - acsign +# File: Makefile +# +# Copyright 2003,2004 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. +# +# $NoKeywords: $ +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Codegen for sub processer +NITRO_PROC = ARM9 + +# build ARM & THUMB libraries +NITRO_CODEGEN_ALL = True + +#---------------------------------------------------------------------------- + +SUBDIRS = + + +#---------------------------------------------------------------------------- + +SRCDIR = ./src +INCDIR = ./include $(ROOT)/build/libraries/mb/include + + +SRCS = acsign.c acmemory.c acsign_util.c + +TARGET_LIB = libacsign_x86.a + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +# CCFLAGS += -DOPT_32_BIT -DSTANDALONE -DNO_SPLIT -DNO_FP_API -DNO_R_DIAG -DNO_STDIO_H -DNO_STDLIB_H +CCFLAGS += -DSMALL_CODE_SIZE \ + -DSTANDALONE \ + -DOPT_32_BIT \ + -DNO_SPLIT \ + -DNO_FP_API \ + -DNO_R_DIAG \ + -DNO_STDIO_H \ + -DNO_STDLIB_H + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = . + + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tools/acsign/acsign.c b/build/tools/acsign/acsign.c new file mode 100644 index 00000000..7b63142f --- /dev/null +++ b/build/tools/acsign/acsign.c @@ -0,0 +1,334 @@ +#include +#include "format_sign.h" +#include "acsign.h" + +// SHA1 +#include "sha1dgst.c" + +// RSA + +// BN +#include "bn.h" + +#include "bn_lib.c" +#include "bn_asm.c" +#include "bn_comba.c" +#include "bn_lsh.c" +#include "bn_rsh.c" +#include "bn_word.c" +#include "bn_add.c" +#include "bn_mul.c" +#include "bn_div.c" +#include "bn_exp.c" +#include "bn_sqr.c" +#include "bn_fm_w.c" +#include "bn_gcd.c" +#include "bn_ex_str.c" +#include "bn_ms_w.c" +//#include "bn_me.c" +#include "bn_rec.c" +#include "bn_mont.c" +#include "bn_recp.c" +#include "bn_wdiv.c" +#include "bn_r_exp.c" +#include "bn_m_exp.c" + + + +#define BER_NULL 5 +#define BER_OBJECT 6 +#define BER_SEQUENCE 16 +#define BER_OCTET_STRING 4 +#define BER_CONSTRUCTED 0x20 + + +/** + * Perform the EMSA-PKCS1_v1_5 padding + * + * @param random random context for seed data generation + * @param out destination buffer + * @param out_len length written to out + * @param in data to be padded + * @param in_len length of in + * @param flags mask of operation directives + * + * @pre out_len must contain length of data allocated to out + * @pre out must be the allocated the total length to be padded + * + * @note Method from PKCS#1 v2.1 standard 9.2.1 EMSA-PKCS1-v1_5 + * @li In: Hash is hash funtion, hLen denotes length of octets of hash output + * @li In: M is message to be encoded + * @li In: emLen is intended length of octets + * @li Out: EM encoded message of length emLen + * + * @li Apply the hash function to message M to produce a hash value H + * If hash output is message to long the output message too long and + * stop + * @li Encode the algorithm ID for the hash in function into an ASN1 value + * @li if emLen < 10 + BER encoded message T output message length too short + * and stop + * @li generate octet string PS consisting of emLen - Length(T) - 2 octets + * with value FF + * @li Concatenate PS, DER encoding T and other padding such that EM is: + * 01 || PS || 00 || T + * + * @note it is the out layers responsibility to DER encode the + * data prior to padding as described in the first 2 steps in method + */ +// +// rsa_padding_add_pkcs1_type_1֐ +// +static int add_padding(unsigned char *out, + int out_len, const unsigned char *in, int in_len) +{ + unsigned char *p; + int j,i; + + if ((in_len+11) > out_len) + return(1); + + /* First we copy data bytes to the output buffer, this + * way the input and output buffers can be the same + * and things will still work */ + p=out+out_len-in_len; + for (i=in_len-1; i>=0; i--) + p[i]=in[i]; + p=out; + *(p++)=0; + *(p++)=1; /* Private Key BT (Block Type) */ + + /* pad with 0xff data */ + j=out_len-3-in_len; + Memset(p,0xff,j); + p[j]='\0'; + return(0); +} + +static void debug_dump(const void* buf, int len, const char* str, int line_elms) +{ + const u8* bufp = (u8*)buf; + int i,ii; + + if (str) + { + debug_printf("%s :\n", str); + } + for (i=0; i<=len/line_elms; i++) + { + if (i*line_elms >= len) + { + break; + } + for (ii=0; ii= len) + { + break; + } + debug_printf("%02x ", bufp[i*line_elms+ii]); + } + debug_printf("\n"); + } +} + +// +// RSA +// +BOOL ACSign_Encrypto(void *sign, const void *key, const void *data, int length) +{ + BN_CTX *ctx; + BIGNUM src, dst, exp, mod; + u8* key_exp = &((u8*)key)[ACS_RSA_PRVEXP_OFFSET]; + u8* key_mod = &((u8*)key)[ACS_RSA_PRVMOD_OFFSET]; + u8 buf[ACS_ENCRYPTED_HASH_LEN]; + u32 len = length; + BOOL result = TRUE; + + if (NULL == sign || NULL == key || NULL == data || 0 > length) { + return FALSE; + } + + if ( add_padding( buf, ACS_ENCRYPTED_HASH_LEN, data, length ) ) { + debug_printf2("encode_padding was failed.\n"); + result = FALSE; + goto end; + } + + { + debug_dump(buf, ACS_ENCRYPTED_HASH_LEN, "padded hash", 16); + debug_dump(key_mod, ACS_RSA_PRVMOD_LEN, "key mod", 16); + debug_dump(key_exp, ACS_RSA_PRVEXP_LEN, "key exp", 16); + } + + ctx = BN_CTX_new(); + + BN_init(&src); + BN_init(&dst); + BN_init(&exp); + BN_init(&mod); + + BN_bin2bn((u8*)buf, ACS_ENCRYPTED_HASH_LEN, &src); + BN_bin2bn(key_exp, ACS_RSA_PRVEXP_LEN, &exp); + BN_bin2bn(key_mod, ACS_RSA_PRVMOD_LEN, &mod); + + BN_mod_exp( &dst, &src, &exp, &mod, ctx ); + + len = BN_bn2bin( &dst, sign ); + + BN_free(&src); + BN_free(&dst); + BN_free(&exp); + BN_free(&mod); + + if (ctx) { + BN_CTX_free(ctx); + } + + if ( len != ACS_DECRYPTED_HASH_LEN ) { + result = FALSE; + goto end; + } +end: + return result; +} + +BOOL ACSign_Decrypto(void *buf, const void *key, const void *sign, int length) +{ + BN_CTX *ctx; + BIGNUM src, dst, exp, mod; + u32 key_exp = ACS_RSA_EXP; + u8* key_mod = &((u8*)key)[ACS_RSA_PRVMOD_OFFSET]; + u8* bufp = (u8*)buf; + u32 len = length; + BOOL result = TRUE; + + if (NULL == buf || NULL == key || NULL == sign || 0 > length) { + return FALSE; + } + + ctx = BN_CTX_new(); + + BN_init(&src); + BN_init(&dst); + BN_init(&exp); + BN_init(&mod); + + BN_bin2bn((u8*)sign, ACS_ENCRYPTED_HASH_LEN, &src); + BN_bin2bn((u8*)&key_exp, ACS_RSA_PUBEXP_LEN, &exp); + BN_bin2bn(key_mod, ACS_RSA_PRVMOD_LEN, &mod); + + BN_mod_exp( &dst, &src, &exp, &mod, ctx ); + + len = BN_bn2bin( &dst, bufp ); + + BN_free(&src); + BN_free(&dst); + BN_free(&exp); + BN_free(&mod); + + if (ctx) { + BN_CTX_free(ctx); + } + + if ( len != ACS_DECRYPTED_HASH_LEN ) { + result = FALSE; + goto end; + } +end: + return result; +} + +// +int ACSign_DigestUnit( + void* buffer, // o͗̈ + const void* buf, // f[^ւ̃|C^ + unsigned int len // f[^̒ + ) +{ + HASHContext context; + unsigned char *bufferp = buffer; + + HASHReset( &context ); + HASHUpdate( &context, buf, len ); + HASHGetDigest( &context, bufferp ); + + return TRUE; +} + +// +int ACSign_CompareUnit( + const void* decedHash, // ACSign_Decryptȍo + const void* digest // ACSign_DigestUnit̏o + ) +{ + const unsigned char* dgt = digest; + const unsigned char* dgtCmp = decedHash; + int i; + int test = TRUE; + + if ( !decedHash ) return FALSE; + if ( !digest ) return FALSE; + + for ( i = 0; i < ACS_HASH_LEN; i++ ) + { + if ( *dgt++ != *dgtCmp++ ) + { + test = FALSE; + break; + } + } + return test; +} + +/* + CӃoCg̓̓f[^ + CӃoCg̏o̓f[^𓾂܂B + ΂Ă邩Ȃ͒llȒlɃ}bv邾łB + o̓ԂĂĂȂ +*/ +int ACSign_GetKey( + void* dest_ptr, // o̓f[^ւ̃|C^ + unsigned int dest_len, // o̓f[^̒ + const void* src_ptr, // ̓f[^ւ̃|C^ + unsigned int src_len // ̓f[^̒ + ) +{ + HASHContext ctx; + unsigned char *ptr; + unsigned char state[ACS_HASH_LEN]; + unsigned char output[ACS_HASH_LEN]; + int i; + + if (dest_ptr == NULL) + return 1; + if (src_ptr == NULL && src_len > 0) + return 0; + + HASHReset(&ctx); + + HASHUpdate(&ctx, src_ptr, src_len); + HASHGetDigest(&ctx, state); + + ptr = dest_ptr; + while (dest_len > 0) + { + unsigned int len = dest_len < ACS_HASH_LEN ? dest_len : ACS_HASH_LEN; + + // plus one + for (i = 0; i < ACS_HASH_LEN; i++) + { + if (state[ACS_HASH_LEN-1-i]++) + break; + } + + HASHUpdate(&ctx, state, ACS_HASH_LEN); + HASHGetDigest(&ctx, output); + memcpy(ptr, output, len); + ptr += len; + dest_len -= len; + } + memset(state, 0, ACS_HASH_LEN); + memset(output, 0, ACS_HASH_LEN); + return 1; +} + diff --git a/build/tools/acsign/acsign_gcd.c b/build/tools/acsign/acsign_gcd.c new file mode 100644 index 00000000..e8b45670 --- /dev/null +++ b/build/tools/acsign/acsign_gcd.c @@ -0,0 +1,74 @@ +#include +#include "acsign_gcd.h" + +static void debug_dump(void* buf, int len, char* str, int line_elms) +{ + u8* bufp = (u8*)buf; + int i,ii; + + if (str) + { + debug_printf("%s :\n", str); + } + for (i=0; i<=len/line_elms; i++) + { + if (i*line_elms >= len) + { + break; + } + for (ii=0; ii= len) + { + break; + } + debug_printf("%02x ", bufp[i*line_elms+ii]); + } + debug_printf("\n"); + } +} + +// +int ACSign_DigestHeader( + void* buffer, // o͗̈ + GCDHeader* header // wb_ւ̃|C^ + ) +{ + HASHContext context; + GCDHeader* nh = header; + unsigned char *bufferp = buffer; + + HASHReset( &context ); + HASHUpdate( &context, (void*)&nh->l, sizeof(GCDHeaderLow) ); + HASHUpdate( &context, (void*)&nh->h, sizeof(GCDHeaderHigh) ); + HASHGetDigest( &context, bufferp ); + + return TRUE; +} + +// +int ACSign_Final( + GCDHeader* header, // wb_ւ̃|C^ + void* buffer, // ͗̈ + const void* key + ) +{ + GCDHeader* nh = header; + FIRMSignedContext* sc = buffer; + + if (key) + { + unsigned char decSign[ACS_ENCRYPTED_HASH_LEN]; + + debug_dump(sc->hash, sizeof(sc->hash), "5 hashs of header, norfirms and total", 20); + + ACSign_Encrypto(&nh->sign, key, buffer, sizeof(FIRMSignedContext)); + ACSign_Decrypto(decSign, key, (void*)&nh->sign, ACS_ENCRYPTED_HASH_LEN); + + debug_dump(&nh->sign, ACS_ENCRYPTED_HASH_LEN, "encrypted sign", 16); + debug_dump(decSign, ACS_ENCRYPTED_HASH_LEN, "decrypted sign", 16); + } + + return TRUE; +} + diff --git a/build/tools/acsign/acsign_nand.c b/build/tools/acsign/acsign_nand.c new file mode 100644 index 00000000..8b0b719c --- /dev/null +++ b/build/tools/acsign/acsign_nand.c @@ -0,0 +1,75 @@ +#include +#include "acsign_nand.h" + +static void debug_dump(void* buf, int len, char* str, int line_elms) +{ + u8* bufp = (u8*)buf; + int i,ii; + + if (str) + { + debug_printf("%s :\n", str); + } + for (i=0; i<=len/line_elms; i++) + { + if (i*line_elms >= len) + { + break; + } + for (ii=0; ii= len) + { + break; + } + debug_printf("%02x ", bufp[i*line_elms+ii]); + } + debug_printf("\n"); + } +} + +// +int ACSign_DigestHeader( + void* buffer, // o͗̈ + NANDHeader* header // wb_ւ̃|C^ + ) +{ + HASHContext context; + NANDHeader* nh = header; + unsigned char *bufferp = buffer; + + HASHReset( &context ); + HASHUpdate( &context, (void*)&nh->d, sizeof(NORHeaderDS) ); + HASHUpdate( &context, (void*)&nh->l, sizeof(NANDHeaderLow) ); + HASHUpdate( &context, (void*)&nh->h, sizeof(NANDHeaderHigh) ); + HASHGetDigest( &context, bufferp ); + + return TRUE; +} + +// +int ACSign_Final( + NANDHeader* header, // wb_ւ̃|C^ + void* buffer, // ͗̈ + const void* key + ) +{ + NANDHeader* nh = header; + FIRMSignedContext* sc = buffer; + + if (key) + { + unsigned char decSign[ACS_ENCRYPTED_HASH_LEN]; + + debug_dump(sc->hash, sizeof(sc->hash), "5 hashs of header, nandfirms and total", 20); + + ACSign_Encrypto(&nh->sign, key, buffer, sizeof(FIRMSignedContext)); + ACSign_Decrypto(decSign, key, (void*)&nh->sign, ACS_ENCRYPTED_HASH_LEN); + + debug_dump(&nh->sign, ACS_ENCRYPTED_HASH_LEN, "encrypted sign", 16); + debug_dump(decSign, ACS_ENCRYPTED_HASH_LEN, "decrypted sign", 16); + } + + return TRUE; +} + diff --git a/build/tools/acsign/acsign_nor.c b/build/tools/acsign/acsign_nor.c new file mode 100644 index 00000000..0bb690c9 --- /dev/null +++ b/build/tools/acsign/acsign_nor.c @@ -0,0 +1,75 @@ +#include +#include "acsign_nor.h" + +static void debug_dump(void* buf, int len, char* str, int line_elms) +{ + u8* bufp = (u8*)buf; + int i,ii; + + if (str) + { + debug_printf("%s :\n", str); + } + for (i=0; i<=len/line_elms; i++) + { + if (i*line_elms >= len) + { + break; + } + for (ii=0; ii= len) + { + break; + } + debug_printf("%02x ", bufp[i*line_elms+ii]); + } + debug_printf("\n"); + } +} + +// +int ACSign_DigestHeader( + void* buffer, // o͗̈ + NORHeader* header // wb_ւ̃|C^ + ) +{ + HASHContext context; + NORHeader* nh = header; + unsigned char *bufferp = buffer; + + HASHReset( &context ); + HASHUpdate( &context, (void*)&nh->d, sizeof(NORHeaderDS) ); + HASHUpdate( &context, (void*)&nh->l, sizeof(NORHeaderLow) ); + HASHUpdate( &context, (void*)&nh->h, sizeof(NORHeaderHigh) ); + HASHGetDigest( &context, bufferp ); + + return TRUE; +} + +// +int ACSign_Final( + NORHeader* header, // wb_ւ̃|C^ + void* buffer, // ͗̈ + const void* key + ) +{ + NORHeader* nh = header; + FIRMSignedContext* sc = buffer; + + if (key) + { + unsigned char decSign[ACS_ENCRYPTED_HASH_LEN]; + + debug_dump(sc->hash, sizeof(sc->hash), "5 hashs of header, norfirms and total", 20); + + ACSign_Encrypto(&nh->sign, key, buffer, sizeof(FIRMSignedContext)); + ACSign_Decrypto(decSign, key, (void*)&nh->sign, ACS_ENCRYPTED_HASH_LEN); + + debug_dump(&nh->sign, ACS_ENCRYPTED_HASH_LEN, "encrypted sign", 16); + debug_dump(decSign, ACS_ENCRYPTED_HASH_LEN, "decrypted sign", 16); + } + + return TRUE; +} + diff --git a/build/tools/acsign/aes.h b/build/tools/acsign/aes.h new file mode 100644 index 00000000..a7a75d8d --- /dev/null +++ b/build/tools/acsign/aes.h @@ -0,0 +1,139 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + */ + +#ifndef HEADER_COMMON_AES_H +#define HEADER_COMMON_AES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define AES_ecb_encrypt(key, out, in) \ + AES_ecb_encrypt_com((key), (out), (in), AES_encrypt) +#define AES_ecb_encrypt_m(key, out, in) \ + AES_ecb_encrypt_com((key), (out), (in), AES_encrypt_m) +#define AES_ecb_encrypt_s(key, out, in) \ + AES_ecb_encrypt_com((key), (out), (in), AES_encrypt_s) + +#define AES_ecb_decrypt(key, out, in) \ + AES_ecb_decrypt_com((key), (out), (in), AES_decrypt) +#define AES_ecb_decrypt_m(key, out, in) \ + AES_ecb_decrypt_com((key), (out), (in), AES_decrypt_m) +#define AES_ecb_decrypt_s(key, out, in) \ + AES_ecb_decrypt_com((key), (out), (in), AES_decrypt_s) + +#define AES_cbc_encrypt(ctx, out, in, len, iv) \ + AES_cbc_encrypt_com((ctx), (out), (in), (len), (iv), AES_encrypt) +#define AES_cbc_encrypt_m(ctx, out, in, len, iv) \ + AES_cbc_encrypt_com((ctx), (out), (in), (len), (iv), AES_encrypt_m) +#define AES_cbc_encrypt_s(ctx, out, in, len, iv) \ + AES_cbc_encrypt_com((ctx), (out), (in), (len), (iv), AES_encrypt_s) + +#define AES_cbc_decrypt(ctx, out, in, len, iv) \ + AES_cbc_decrypt_com((ctx), (out), (in), (len), (iv), AES_decrypt) +#define AES_cbc_decrypt_m(ctx, out, in, len, iv) \ + AES_cbc_decrypt_com((ctx), (out), (in), (len), (iv), AES_decrypt_m) +#define AES_cbc_decrypt_s(ctx, out, in, len, iv) \ + AES_cbc_decrypt_com((ctx), (out), (in), (len), (iv), AES_decrypt_s) + +#define AES_cfb128_encrypt(ks, out, in, len, iv, num) \ + AES_cfb128_encrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_encrypt) +#define AES_cfb128_encrypt_m(ks, out, in, len, iv, num) \ + AES_cfb128_encrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_encrypt_m) +#define AES_cfb128_encrypt_s(ks, out, in, len, iv, num) \ + AES_cfb128_encrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_encrypt_s) + +#define AES_cfb128_decrypt(ks, out, in, len, iv, num) \ + AES_cfb128_decrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_decrypt) +#define AES_cfb128_decrypt_m(ks, out, in, len, iv, num) \ + AES_cfb128_decrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_decrypt_m) +#define AES_cfb128_decrypt_s(ks, out, in, len, iv, num) \ + AES_cfb128_decrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_decrypt_s) + +/** Note. OFB encryption is also used for decryption */ +#define AES_ofb128_encrypt(ks, out, in, len, iv, num) \ + AES_ofb128_encrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_encrypt) +#define AES_ofb128_encrypt_m(ks, out, in, len, iv, num) \ + AES_ofb128_encrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_encrypt_m) +#define AES_ofb128_encrypt_s(ks, out, in, len, iv, num) \ + AES_ofb128_encrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_encrypt_s) + +#define AES_ofb128_decrypt(ks, out, in, len, iv, num) \ + AES_ofb128_encrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_encrypt) +#define AES_ofb128_decrypt_m(ks, out, in, len, iv, num) \ + AES_ofb128_encrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_encrypt_m) +#define AES_ofb128_decrypt_s(ks, out, in, len, iv, num) \ + AES_ofb128_encrypt_com((ks), (out), (in), (len), (iv), (num), \ + AES_encrypt_s) + + +#define AES_MAXROUNDS 14 + +#define AES_ENCRYPT 1 +#define AES_DECRYPT 0 + +typedef unsigned int AES_INT4; + +typedef struct aes_key_st { + unsigned int rounds; + unsigned int key_size; + AES_INT4 ks[(AES_MAXROUNDS+1)*8]; + } AES_KEY; + +typedef void (* AES_ENC_DEC_FN)(AES_KEY *, AES_INT4 *); + +void AES_encrypt(AES_KEY *ctx,AES_INT4 *data); +void AES_encrypt_m(AES_KEY *ctx,AES_INT4 *data); +void AES_encrypt_s(AES_KEY *ctx,AES_INT4 *data); +void AES_decrypt(AES_KEY *ctx,AES_INT4 *data); +void AES_decrypt_m(AES_KEY *ctx,AES_INT4 *data); +void AES_decrypt_s(AES_KEY *ctx,AES_INT4 *data); + +void AES_ecb_encrypt_com(AES_KEY *key, unsigned char *out, + const unsigned char *in, AES_ENC_DEC_FN enc_fn); +void AES_ecb_decrypt_com(AES_KEY *key, unsigned char *out, + const unsigned char *in, AES_ENC_DEC_FN dec_fn); +void AES_cbc_encrypt_com(AES_KEY *ctx, unsigned char *out, + const unsigned char *in, long length, unsigned char *iv, + AES_ENC_DEC_FN enc_fn); +void AES_cbc_decrypt_com(AES_KEY *ctx, unsigned char *out, + const unsigned char *in, long length, unsigned char *iv, + AES_ENC_DEC_FN dec_fn); +void AES_ofb128_encrypt_com(AES_KEY *ks,const unsigned char *in, + unsigned char *out, long length, unsigned char *ivec, int *num, + AES_ENC_DEC_FN enc_fn); +void AES_cfb128_encrypt_com(AES_KEY *ks, const unsigned char *in, + unsigned char *out, long length, unsigned char *ivec, int *num, + AES_ENC_DEC_FN enc_fn); +void AES_cfb128_decrypt_com(AES_KEY *ks, const unsigned char *in, + unsigned char *out, long length, unsigned char *ivec, int *num, + AES_ENC_DEC_FN dec_fn); + +int AES_set_key(AES_KEY *ctx, const unsigned char *key, int len); +void AES_convert_key(AES_KEY *ctx); +AES_INT4 AES_rotate(AES_INT4 u); +unsigned char AES_xtime(AES_INT4 x); + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_COMMON_AES_H */ diff --git a/build/tools/acsign/aes2.c b/build/tools/acsign/aes2.c new file mode 100644 index 00000000..778dc53a --- /dev/null +++ b/build/tools/acsign/aes2.c @@ -0,0 +1,133 @@ +#include +#include + +#include "aes2.h" + +#include "aes_e.c" +#include "aes_e_ecb.c" +#include "aes_skey.c" + +// +// swap with memory allocation +// +static unsigned char* AES_Swap(const unsigned char *src, int len, int unit) +{ + int i; + int j; + unsigned char *dest = malloc(len); + for (i = 0; i < len; i+=unit) + for (j = 0; j < unit; j++) + dest[i + j] = src[i + unit - j - 1]; + return dest; +} + +// +// set keys +// +void AES_SetKey(AES_KEY *key, const unsigned char seed[AES_BLOCK_SIZE], const unsigned char id[AES_BLOCK_SIZE]) +{ + static const unsigned char f[AES_BLOCK_SIZE] = {0xff, 0xfe, 0xfb, 0x4e, 0x29, 0x59, 0x02, 0x58, 0x2a, 0x68, 0x0f, 0x5f, 0x1a, 0x4f, 0x3e, 0x79}; + static const unsigned char s = 0x2a; + + unsigned char key1[AES_BLOCK_SIZE]; + unsigned char key2[AES_BLOCK_SIZE]; + int i; + int o = 0; + + for (i = 0; i < AES_BLOCK_SIZE; i++) { + key1[i] = seed[AES_BLOCK_SIZE-i-1] ^ id[AES_BLOCK_SIZE-i-1]; + } + for (i = AES_BLOCK_SIZE - 1; i >= 0; i--) { + int t = key1[i] + f[i] + o; + o = (t > 0xFF ? 1 : 0); + key1[i] = t & 0xFF; + } + for (i = 0; i < AES_BLOCK_SIZE; i++) { + int j1 = (i + s / 8) % AES_BLOCK_SIZE; + int j2 = (j1 + 1) % AES_BLOCK_SIZE; + int k = s % 8; + key2[i] = ((key1[j1] << k) & 0xFF) | ((key1[j2] >> (8 - k)) & 0xFF); + } + AES_set_key(key, key2, 16); + memset(key2, 0, 16); + memset(key1, 0, 16); +} + +// +// ctr mode +// +#define GETU32(pt) (((unsigned long)(pt)[0] << 24) ^ ((unsigned long)(pt)[1] << 16) ^ ((unsigned long)(pt)[2] << 8) ^ ((unsigned long)(pt)[3])) +#define PUTU32(ct, st) { (ct)[0] = (unsigned char)((st) >> 24); (ct)[1] = (unsigned char)((st) >> 16); (ct)[2] = (unsigned char)((st) >> 8); (ct)[3] = (unsigned char)(st); } + +/* increment counter as u128 */ +static void AES_ctr128_increment(unsigned char *counter) { + unsigned long c; + + c = GETU32(counter + 12); + c++; c &= 0xFFFFFFFF; + PUTU32(counter + 12, c); + if (c) return; // return unless overflow + + c = GETU32(counter + 8); + c++; c &= 0xFFFFFFFF; + PUTU32(counter + 8, c); + if (c) return; // return unless overflow + + c = GETU32(counter + 4); + c++; c &= 0xFFFFFFFF; + PUTU32(counter + 4, c); + if (c) return; // return unless overflow + + c = GETU32(counter + 0); + c++; c &= 0xFFFFFFFF; + PUTU32(counter + 0, c); +} +static void AES_ctr128(const unsigned char *in, unsigned char *out, const unsigned long length, AES_KEY *key, + unsigned char ivec[AES_BLOCK_SIZE], unsigned char ebuf[AES_BLOCK_SIZE], unsigned int *num) { + + unsigned int n; + unsigned long l=length; + + n = *num; + + while (l--) { // loop each byte + if (n == 0) { + AES_ecb_encrypt(key, ebuf, ivec); // encrypt counter + AES_ctr128_increment(ivec); // increment counter + } + *(out++) = *(in++) ^ ebuf[n]; + n = (n+1) % AES_BLOCK_SIZE; + } + + *num=n; +} + +void AES_Ctr(AES_KEY *key, unsigned char *outdata, const unsigned char *indata, int len, unsigned char iv[AES_BLOCK_SIZE]) +{ + unsigned char ebuf[AES_BLOCK_SIZE]; + unsigned char *tmp; + unsigned int nums; + + if (len <= 0 || len > 0xFFFF00 || (len % AES_BLOCK_SIZE) != 0 || indata == NULL || outdata == NULL) + { + return; + } + + // CTR + memset(ebuf, 0, AES_BLOCK_SIZE); + nums = 0; + + tmp = AES_Swap(iv, AES_BLOCK_SIZE, AES_BLOCK_SIZE); + memcpy(iv, tmp, AES_BLOCK_SIZE); + free(tmp); + + tmp = AES_Swap(indata, len, AES_BLOCK_SIZE); + AES_ctr128(tmp, outdata, len, key, iv, ebuf, &nums); + free(tmp); + + tmp = AES_Swap(outdata, len, AES_BLOCK_SIZE); + memcpy(outdata, tmp, len); + free(tmp); + return; +} + diff --git a/build/tools/acsign/aes2.h b/build/tools/acsign/aes2.h new file mode 100644 index 00000000..3e80799d --- /dev/null +++ b/build/tools/acsign/aes2.h @@ -0,0 +1,21 @@ +#ifndef __AES_2_H__ +#define __AES_2_H__ + +#include "aes.h" + +#define AES_BLOCK_SIZE 16 +#define AES_NONCE_SIZE 12 +#define AES_QUANTITY (AES_BLOCK_SIZE - AES_NONCE_SIZE - 1) + +#ifdef __cplusplus +extern "C" { +#endif + +void AES_SetKey(AES_KEY *key, const unsigned char seed[AES_BLOCK_SIZE], const unsigned char id[AES_BLOCK_SIZE]); +void AES_Ctr(AES_KEY *key, unsigned char *outdata, const unsigned char *indata, int len, unsigned char iv[AES_BLOCK_SIZE]); + +#ifdef __cplusplus +} +#endif + +#endif // __AES_2_H__ diff --git a/build/tools/acsign/aes_e.c b/build/tools/acsign/aes_e.c new file mode 100644 index 00000000..fab235c1 --- /dev/null +++ b/build/tools/acsign/aes_e.c @@ -0,0 +1,115 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + */ + +/** + * @file aes_e.c + * \brief Large code size (thus fast) AES Encryption + */ + +#ifndef NO_AES + +#include "aes.h" + +/* Include the Large aes_submix tables */ +#include "aes_e.h" + +/* AES ECB Encryption of 1 x 128 bit Block */ +void AES_encrypt(AES_KEY *ctx, AES_INT4 *data) +{ + int r; + int rounds; + AES_INT4 *k; + AES_INT4 o0,o1,o2,o3; + AES_INT4 tmp0,tmp1,tmp2,tmp3; + + rounds=ctx->rounds; + k= (AES_INT4 *)ctx->ks; + + /* Encrypt one block. + */ + tmp0=data[0]; + tmp1=data[1]; + tmp2=data[2]; + tmp3=data[3]; +/*printf("K %08X %08X %08X %08X\n",tmp0,tmp1,tmp2,tmp3); +printf("KS %08X %08X %08X %08X\n",k[0],k[1],k[2],k[3]); */ + tmp0^=k[0]; + tmp1^=k[1]; + tmp2^=k[2]; + tmp3^=k[3]; + k+=4; + + for(r = 1; r < rounds; r++) + { +/*printf("%2d %08X %08X %08X %08X\n",r,tmp0,tmp1,tmp2,tmp3); */ + o0 = aes_submix[3][(tmp3 )&0xff]^ + aes_submix[2][(tmp2>> 8)&0xff]^ + aes_submix[1][(tmp1>>16)&0xff]^ + aes_submix[0][(tmp0>>24)&0xff]; + + o1 = aes_submix[3][(tmp0 )&0xff]^ + aes_submix[2][(tmp3>> 8)&0xff]^ + aes_submix[1][(tmp2>>16)&0xff]^ + aes_submix[0][(tmp1>>24)&0xff]; + + o2 = + aes_submix[3][(tmp1 )&0xff]^ + aes_submix[2][(tmp0>> 8)&0xff]^ + aes_submix[1][(tmp3>>16)&0xff]^ + aes_submix[0][(tmp2>>24)&0xff]; + + o3 = + aes_submix[3][(tmp2 )&0xff]^ + aes_submix[2][(tmp1>> 8)&0xff]^ + aes_submix[1][(tmp0>>16)&0xff]^ + aes_submix[0][(tmp3>>24)&0xff]; + +/* +printf(" %08X %08X %08X %08X\n",o0,o1,o2,o3); +printf("KS %08X %08X %08X %08X\n",k[0],k[1],k[2],k[3]); */ + tmp0=o0^k[0]; + tmp1=o1^k[1]; + tmp2=o2^k[2]; + tmp3=o3^k[3]; + k+=4; + } +/*printf("O %08X %08X %08X %08X\n",o0,o1,o2,o3); */ + o0 = (aes_submix[0][(tmp3 )&0xff]>> 8)&0xFF; + o1 = (aes_submix[0][(tmp0 )&0xff]>> 8)&0xFF; + o2 = (aes_submix[0][(tmp1 )&0xff]>> 8)&0xFF; + o3 = (aes_submix[0][(tmp2 )&0xff]>> 8)&0xFF; + + o0|= (aes_submix[0][(tmp2>> 8)&0xff] )&0xFF00; + o1|= (aes_submix[0][(tmp3>> 8)&0xff] )&0xFF00; + o2|= (aes_submix[0][(tmp0>> 8)&0xff] )&0xFF00; + o3|= (aes_submix[0][(tmp1>> 8)&0xff] )&0xFF00; + + o0|= (aes_submix[0][(tmp1>>16)&0xff]<< 8)&0xFF0000; + o1|= (aes_submix[0][(tmp2>>16)&0xff]<< 8)&0xFF0000; + o2|= (aes_submix[0][(tmp3>>16)&0xff]<< 8)&0xFF0000; + o3|= (aes_submix[0][(tmp0>>16)&0xff]<< 8)&0xFF0000; + + o0|= (aes_submix[0][(tmp0>>24) ]<<16)&0xFF000000; + o1|= (aes_submix[0][(tmp1>>24) ]<<16)&0xFF000000; + o2|= (aes_submix[0][(tmp2>>24) ]<<16)&0xFF000000; + o3|= (aes_submix[0][(tmp3>>24) ]<<16)&0xFF000000; +/*printf("P %08X %08X %08X %08X\n",o0,o1,o2,o3); */ + o0^=k[0]; + o1^=k[1]; + o2^=k[2]; + o3^=k[3]; +/*printf("Q %08X %08X %08X %08X\n",o0,o1,o2,o3); */ + data[0]= o0; + data[1]= o1; + data[2]= o2; + data[3]= o3; + } + +#endif /* NO_AES */ diff --git a/build/tools/acsign/aes_e.h b/build/tools/acsign/aes_e.h new file mode 100644 index 00000000..74f6db70 --- /dev/null +++ b/build/tools/acsign/aes_e.h @@ -0,0 +1,284 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + */ + +#ifndef HEADER_COMMON_AES_E_H +#define HEADER_COMMON_AES_E_H + +#ifdef __cplusplus +extern "C" { +#endif + +const AES_INT4 aes_submix[4][256]={{ + 0xC66363A5,0xF87C7C84,0xEE777799,0xF67B7B8D, + 0xFFF2F20D,0xD66B6BBD,0xDE6F6FB1,0x91C5C554, + 0x60303050,0x02010103,0xCE6767A9,0x562B2B7D, + 0xE7FEFE19,0xB5D7D762,0x4DABABE6,0xEC76769A, + 0x8FCACA45,0x1F82829D,0x89C9C940,0xFA7D7D87, + 0xEFFAFA15,0xB25959EB,0x8E4747C9,0xFBF0F00B, + 0x41ADADEC,0xB3D4D467,0x5FA2A2FD,0x45AFAFEA, + 0x239C9CBF,0x53A4A4F7,0xE4727296,0x9BC0C05B, + 0x75B7B7C2,0xE1FDFD1C,0x3D9393AE,0x4C26266A, + 0x6C36365A,0x7E3F3F41,0xF5F7F702,0x83CCCC4F, + 0x6834345C,0x51A5A5F4,0xD1E5E534,0xF9F1F108, + 0xE2717193,0xABD8D873,0x62313153,0x2A15153F, + 0x0804040C,0x95C7C752,0x46232365,0x9DC3C35E, + 0x30181828,0x379696A1,0x0A05050F,0x2F9A9AB5, + 0x0E070709,0x24121236,0x1B80809B,0xDFE2E23D, + 0xCDEBEB26,0x4E272769,0x7FB2B2CD,0xEA75759F, + 0x1209091B,0x1D83839E,0x582C2C74,0x341A1A2E, + 0x361B1B2D,0xDC6E6EB2,0xB45A5AEE,0x5BA0A0FB, + 0xA45252F6,0x763B3B4D,0xB7D6D661,0x7DB3B3CE, + 0x5229297B,0xDDE3E33E,0x5E2F2F71,0x13848497, + 0xA65353F5,0xB9D1D168,0x00000000,0xC1EDED2C, + 0x40202060,0xE3FCFC1F,0x79B1B1C8,0xB65B5BED, + 0xD46A6ABE,0x8DCBCB46,0x67BEBED9,0x7239394B, + 0x944A4ADE,0x984C4CD4,0xB05858E8,0x85CFCF4A, + 0xBBD0D06B,0xC5EFEF2A,0x4FAAAAE5,0xEDFBFB16, + 0x864343C5,0x9A4D4DD7,0x66333355,0x11858594, + 0x8A4545CF,0xE9F9F910,0x04020206,0xFE7F7F81, + 0xA05050F0,0x783C3C44,0x259F9FBA,0x4BA8A8E3, + 0xA25151F3,0x5DA3A3FE,0x804040C0,0x058F8F8A, + 0x3F9292AD,0x219D9DBC,0x70383848,0xF1F5F504, + 0x63BCBCDF,0x77B6B6C1,0xAFDADA75,0x42212163, + 0x20101030,0xE5FFFF1A,0xFDF3F30E,0xBFD2D26D, + 0x81CDCD4C,0x180C0C14,0x26131335,0xC3ECEC2F, + 0xBE5F5FE1,0x359797A2,0x884444CC,0x2E171739, + 0x93C4C457,0x55A7A7F2,0xFC7E7E82,0x7A3D3D47, + 0xC86464AC,0xBA5D5DE7,0x3219192B,0xE6737395, + 0xC06060A0,0x19818198,0x9E4F4FD1,0xA3DCDC7F, + 0x44222266,0x542A2A7E,0x3B9090AB,0x0B888883, + 0x8C4646CA,0xC7EEEE29,0x6BB8B8D3,0x2814143C, + 0xA7DEDE79,0xBC5E5EE2,0x160B0B1D,0xADDBDB76, + 0xDBE0E03B,0x64323256,0x743A3A4E,0x140A0A1E, + 0x924949DB,0x0C06060A,0x4824246C,0xB85C5CE4, + 0x9FC2C25D,0xBDD3D36E,0x43ACACEF,0xC46262A6, + 0x399191A8,0x319595A4,0xD3E4E437,0xF279798B, + 0xD5E7E732,0x8BC8C843,0x6E373759,0xDA6D6DB7, + 0x018D8D8C,0xB1D5D564,0x9C4E4ED2,0x49A9A9E0, + 0xD86C6CB4,0xAC5656FA,0xF3F4F407,0xCFEAEA25, + 0xCA6565AF,0xF47A7A8E,0x47AEAEE9,0x10080818, + 0x6FBABAD5,0xF0787888,0x4A25256F,0x5C2E2E72, + 0x381C1C24,0x57A6A6F1,0x73B4B4C7,0x97C6C651, + 0xCBE8E823,0xA1DDDD7C,0xE874749C,0x3E1F1F21, + 0x964B4BDD,0x61BDBDDC,0x0D8B8B86,0x0F8A8A85, + 0xE0707090,0x7C3E3E42,0x71B5B5C4,0xCC6666AA, + 0x904848D8,0x06030305,0xF7F6F601,0x1C0E0E12, + 0xC26161A3,0x6A35355F,0xAE5757F9,0x69B9B9D0, + 0x17868691,0x99C1C158,0x3A1D1D27,0x279E9EB9, + 0xD9E1E138,0xEBF8F813,0x2B9898B3,0x22111133, + 0xD26969BB,0xA9D9D970,0x078E8E89,0x339494A7, + 0x2D9B9BB6,0x3C1E1E22,0x15878792,0xC9E9E920, + 0x87CECE49,0xAA5555FF,0x50282878,0xA5DFDF7A, + 0x038C8C8F,0x59A1A1F8,0x09898980,0x1A0D0D17, + 0x65BFBFDA,0xD7E6E631,0x844242C6,0xD06868B8, + 0x824141C3,0x299999B0,0x5A2D2D77,0x1E0F0F11, + 0x7BB0B0CB,0xA85454FC,0x6DBBBBD6,0x2C16163A, + },{ + 0xA5C66363,0x84F87C7C,0x99EE7777,0x8DF67B7B, + 0x0DFFF2F2,0xBDD66B6B,0xB1DE6F6F,0x5491C5C5, + 0x50603030,0x03020101,0xA9CE6767,0x7D562B2B, + 0x19E7FEFE,0x62B5D7D7,0xE64DABAB,0x9AEC7676, + 0x458FCACA,0x9D1F8282,0x4089C9C9,0x87FA7D7D, + 0x15EFFAFA,0xEBB25959,0xC98E4747,0x0BFBF0F0, + 0xEC41ADAD,0x67B3D4D4,0xFD5FA2A2,0xEA45AFAF, + 0xBF239C9C,0xF753A4A4,0x96E47272,0x5B9BC0C0, + 0xC275B7B7,0x1CE1FDFD,0xAE3D9393,0x6A4C2626, + 0x5A6C3636,0x417E3F3F,0x02F5F7F7,0x4F83CCCC, + 0x5C683434,0xF451A5A5,0x34D1E5E5,0x08F9F1F1, + 0x93E27171,0x73ABD8D8,0x53623131,0x3F2A1515, + 0x0C080404,0x5295C7C7,0x65462323,0x5E9DC3C3, + 0x28301818,0xA1379696,0x0F0A0505,0xB52F9A9A, + 0x090E0707,0x36241212,0x9B1B8080,0x3DDFE2E2, + 0x26CDEBEB,0x694E2727,0xCD7FB2B2,0x9FEA7575, + 0x1B120909,0x9E1D8383,0x74582C2C,0x2E341A1A, + 0x2D361B1B,0xB2DC6E6E,0xEEB45A5A,0xFB5BA0A0, + 0xF6A45252,0x4D763B3B,0x61B7D6D6,0xCE7DB3B3, + 0x7B522929,0x3EDDE3E3,0x715E2F2F,0x97138484, + 0xF5A65353,0x68B9D1D1,0x00000000,0x2CC1EDED, + 0x60402020,0x1FE3FCFC,0xC879B1B1,0xEDB65B5B, + 0xBED46A6A,0x468DCBCB,0xD967BEBE,0x4B723939, + 0xDE944A4A,0xD4984C4C,0xE8B05858,0x4A85CFCF, + 0x6BBBD0D0,0x2AC5EFEF,0xE54FAAAA,0x16EDFBFB, + 0xC5864343,0xD79A4D4D,0x55663333,0x94118585, + 0xCF8A4545,0x10E9F9F9,0x06040202,0x81FE7F7F, + 0xF0A05050,0x44783C3C,0xBA259F9F,0xE34BA8A8, + 0xF3A25151,0xFE5DA3A3,0xC0804040,0x8A058F8F, + 0xAD3F9292,0xBC219D9D,0x48703838,0x04F1F5F5, + 0xDF63BCBC,0xC177B6B6,0x75AFDADA,0x63422121, + 0x30201010,0x1AE5FFFF,0x0EFDF3F3,0x6DBFD2D2, + 0x4C81CDCD,0x14180C0C,0x35261313,0x2FC3ECEC, + 0xE1BE5F5F,0xA2359797,0xCC884444,0x392E1717, + 0x5793C4C4,0xF255A7A7,0x82FC7E7E,0x477A3D3D, + 0xACC86464,0xE7BA5D5D,0x2B321919,0x95E67373, + 0xA0C06060,0x98198181,0xD19E4F4F,0x7FA3DCDC, + 0x66442222,0x7E542A2A,0xAB3B9090,0x830B8888, + 0xCA8C4646,0x29C7EEEE,0xD36BB8B8,0x3C281414, + 0x79A7DEDE,0xE2BC5E5E,0x1D160B0B,0x76ADDBDB, + 0x3BDBE0E0,0x56643232,0x4E743A3A,0x1E140A0A, + 0xDB924949,0x0A0C0606,0x6C482424,0xE4B85C5C, + 0x5D9FC2C2,0x6EBDD3D3,0xEF43ACAC,0xA6C46262, + 0xA8399191,0xA4319595,0x37D3E4E4,0x8BF27979, + 0x32D5E7E7,0x438BC8C8,0x596E3737,0xB7DA6D6D, + 0x8C018D8D,0x64B1D5D5,0xD29C4E4E,0xE049A9A9, + 0xB4D86C6C,0xFAAC5656,0x07F3F4F4,0x25CFEAEA, + 0xAFCA6565,0x8EF47A7A,0xE947AEAE,0x18100808, + 0xD56FBABA,0x88F07878,0x6F4A2525,0x725C2E2E, + 0x24381C1C,0xF157A6A6,0xC773B4B4,0x5197C6C6, + 0x23CBE8E8,0x7CA1DDDD,0x9CE87474,0x213E1F1F, + 0xDD964B4B,0xDC61BDBD,0x860D8B8B,0x850F8A8A, + 0x90E07070,0x427C3E3E,0xC471B5B5,0xAACC6666, + 0xD8904848,0x05060303,0x01F7F6F6,0x121C0E0E, + 0xA3C26161,0x5F6A3535,0xF9AE5757,0xD069B9B9, + 0x91178686,0x5899C1C1,0x273A1D1D,0xB9279E9E, + 0x38D9E1E1,0x13EBF8F8,0xB32B9898,0x33221111, + 0xBBD26969,0x70A9D9D9,0x89078E8E,0xA7339494, + 0xB62D9B9B,0x223C1E1E,0x92158787,0x20C9E9E9, + 0x4987CECE,0xFFAA5555,0x78502828,0x7AA5DFDF, + 0x8F038C8C,0xF859A1A1,0x80098989,0x171A0D0D, + 0xDA65BFBF,0x31D7E6E6,0xC6844242,0xB8D06868, + 0xC3824141,0xB0299999,0x775A2D2D,0x111E0F0F, + 0xCB7BB0B0,0xFCA85454,0xD66DBBBB,0x3A2C1616, + },{ + 0x63A5C663,0x7C84F87C,0x7799EE77,0x7B8DF67B, + 0xF20DFFF2,0x6BBDD66B,0x6FB1DE6F,0xC55491C5, + 0x30506030,0x01030201,0x67A9CE67,0x2B7D562B, + 0xFE19E7FE,0xD762B5D7,0xABE64DAB,0x769AEC76, + 0xCA458FCA,0x829D1F82,0xC94089C9,0x7D87FA7D, + 0xFA15EFFA,0x59EBB259,0x47C98E47,0xF00BFBF0, + 0xADEC41AD,0xD467B3D4,0xA2FD5FA2,0xAFEA45AF, + 0x9CBF239C,0xA4F753A4,0x7296E472,0xC05B9BC0, + 0xB7C275B7,0xFD1CE1FD,0x93AE3D93,0x266A4C26, + 0x365A6C36,0x3F417E3F,0xF702F5F7,0xCC4F83CC, + 0x345C6834,0xA5F451A5,0xE534D1E5,0xF108F9F1, + 0x7193E271,0xD873ABD8,0x31536231,0x153F2A15, + 0x040C0804,0xC75295C7,0x23654623,0xC35E9DC3, + 0x18283018,0x96A13796,0x050F0A05,0x9AB52F9A, + 0x07090E07,0x12362412,0x809B1B80,0xE23DDFE2, + 0xEB26CDEB,0x27694E27,0xB2CD7FB2,0x759FEA75, + 0x091B1209,0x839E1D83,0x2C74582C,0x1A2E341A, + 0x1B2D361B,0x6EB2DC6E,0x5AEEB45A,0xA0FB5BA0, + 0x52F6A452,0x3B4D763B,0xD661B7D6,0xB3CE7DB3, + 0x297B5229,0xE33EDDE3,0x2F715E2F,0x84971384, + 0x53F5A653,0xD168B9D1,0x00000000,0xED2CC1ED, + 0x20604020,0xFC1FE3FC,0xB1C879B1,0x5BEDB65B, + 0x6ABED46A,0xCB468DCB,0xBED967BE,0x394B7239, + 0x4ADE944A,0x4CD4984C,0x58E8B058,0xCF4A85CF, + 0xD06BBBD0,0xEF2AC5EF,0xAAE54FAA,0xFB16EDFB, + 0x43C58643,0x4DD79A4D,0x33556633,0x85941185, + 0x45CF8A45,0xF910E9F9,0x02060402,0x7F81FE7F, + 0x50F0A050,0x3C44783C,0x9FBA259F,0xA8E34BA8, + 0x51F3A251,0xA3FE5DA3,0x40C08040,0x8F8A058F, + 0x92AD3F92,0x9DBC219D,0x38487038,0xF504F1F5, + 0xBCDF63BC,0xB6C177B6,0xDA75AFDA,0x21634221, + 0x10302010,0xFF1AE5FF,0xF30EFDF3,0xD26DBFD2, + 0xCD4C81CD,0x0C14180C,0x13352613,0xEC2FC3EC, + 0x5FE1BE5F,0x97A23597,0x44CC8844,0x17392E17, + 0xC45793C4,0xA7F255A7,0x7E82FC7E,0x3D477A3D, + 0x64ACC864,0x5DE7BA5D,0x192B3219,0x7395E673, + 0x60A0C060,0x81981981,0x4FD19E4F,0xDC7FA3DC, + 0x22664422,0x2A7E542A,0x90AB3B90,0x88830B88, + 0x46CA8C46,0xEE29C7EE,0xB8D36BB8,0x143C2814, + 0xDE79A7DE,0x5EE2BC5E,0x0B1D160B,0xDB76ADDB, + 0xE03BDBE0,0x32566432,0x3A4E743A,0x0A1E140A, + 0x49DB9249,0x060A0C06,0x246C4824,0x5CE4B85C, + 0xC25D9FC2,0xD36EBDD3,0xACEF43AC,0x62A6C462, + 0x91A83991,0x95A43195,0xE437D3E4,0x798BF279, + 0xE732D5E7,0xC8438BC8,0x37596E37,0x6DB7DA6D, + 0x8D8C018D,0xD564B1D5,0x4ED29C4E,0xA9E049A9, + 0x6CB4D86C,0x56FAAC56,0xF407F3F4,0xEA25CFEA, + 0x65AFCA65,0x7A8EF47A,0xAEE947AE,0x08181008, + 0xBAD56FBA,0x7888F078,0x256F4A25,0x2E725C2E, + 0x1C24381C,0xA6F157A6,0xB4C773B4,0xC65197C6, + 0xE823CBE8,0xDD7CA1DD,0x749CE874,0x1F213E1F, + 0x4BDD964B,0xBDDC61BD,0x8B860D8B,0x8A850F8A, + 0x7090E070,0x3E427C3E,0xB5C471B5,0x66AACC66, + 0x48D89048,0x03050603,0xF601F7F6,0x0E121C0E, + 0x61A3C261,0x355F6A35,0x57F9AE57,0xB9D069B9, + 0x86911786,0xC15899C1,0x1D273A1D,0x9EB9279E, + 0xE138D9E1,0xF813EBF8,0x98B32B98,0x11332211, + 0x69BBD269,0xD970A9D9,0x8E89078E,0x94A73394, + 0x9BB62D9B,0x1E223C1E,0x87921587,0xE920C9E9, + 0xCE4987CE,0x55FFAA55,0x28785028,0xDF7AA5DF, + 0x8C8F038C,0xA1F859A1,0x89800989,0x0D171A0D, + 0xBFDA65BF,0xE631D7E6,0x42C68442,0x68B8D068, + 0x41C38241,0x99B02999,0x2D775A2D,0x0F111E0F, + 0xB0CB7BB0,0x54FCA854,0xBBD66DBB,0x163A2C16, + },{ + 0x6363A5C6,0x7C7C84F8,0x777799EE,0x7B7B8DF6, + 0xF2F20DFF,0x6B6BBDD6,0x6F6FB1DE,0xC5C55491, + 0x30305060,0x01010302,0x6767A9CE,0x2B2B7D56, + 0xFEFE19E7,0xD7D762B5,0xABABE64D,0x76769AEC, + 0xCACA458F,0x82829D1F,0xC9C94089,0x7D7D87FA, + 0xFAFA15EF,0x5959EBB2,0x4747C98E,0xF0F00BFB, + 0xADADEC41,0xD4D467B3,0xA2A2FD5F,0xAFAFEA45, + 0x9C9CBF23,0xA4A4F753,0x727296E4,0xC0C05B9B, + 0xB7B7C275,0xFDFD1CE1,0x9393AE3D,0x26266A4C, + 0x36365A6C,0x3F3F417E,0xF7F702F5,0xCCCC4F83, + 0x34345C68,0xA5A5F451,0xE5E534D1,0xF1F108F9, + 0x717193E2,0xD8D873AB,0x31315362,0x15153F2A, + 0x04040C08,0xC7C75295,0x23236546,0xC3C35E9D, + 0x18182830,0x9696A137,0x05050F0A,0x9A9AB52F, + 0x0707090E,0x12123624,0x80809B1B,0xE2E23DDF, + 0xEBEB26CD,0x2727694E,0xB2B2CD7F,0x75759FEA, + 0x09091B12,0x83839E1D,0x2C2C7458,0x1A1A2E34, + 0x1B1B2D36,0x6E6EB2DC,0x5A5AEEB4,0xA0A0FB5B, + 0x5252F6A4,0x3B3B4D76,0xD6D661B7,0xB3B3CE7D, + 0x29297B52,0xE3E33EDD,0x2F2F715E,0x84849713, + 0x5353F5A6,0xD1D168B9,0x00000000,0xEDED2CC1, + 0x20206040,0xFCFC1FE3,0xB1B1C879,0x5B5BEDB6, + 0x6A6ABED4,0xCBCB468D,0xBEBED967,0x39394B72, + 0x4A4ADE94,0x4C4CD498,0x5858E8B0,0xCFCF4A85, + 0xD0D06BBB,0xEFEF2AC5,0xAAAAE54F,0xFBFB16ED, + 0x4343C586,0x4D4DD79A,0x33335566,0x85859411, + 0x4545CF8A,0xF9F910E9,0x02020604,0x7F7F81FE, + 0x5050F0A0,0x3C3C4478,0x9F9FBA25,0xA8A8E34B, + 0x5151F3A2,0xA3A3FE5D,0x4040C080,0x8F8F8A05, + 0x9292AD3F,0x9D9DBC21,0x38384870,0xF5F504F1, + 0xBCBCDF63,0xB6B6C177,0xDADA75AF,0x21216342, + 0x10103020,0xFFFF1AE5,0xF3F30EFD,0xD2D26DBF, + 0xCDCD4C81,0x0C0C1418,0x13133526,0xECEC2FC3, + 0x5F5FE1BE,0x9797A235,0x4444CC88,0x1717392E, + 0xC4C45793,0xA7A7F255,0x7E7E82FC,0x3D3D477A, + 0x6464ACC8,0x5D5DE7BA,0x19192B32,0x737395E6, + 0x6060A0C0,0x81819819,0x4F4FD19E,0xDCDC7FA3, + 0x22226644,0x2A2A7E54,0x9090AB3B,0x8888830B, + 0x4646CA8C,0xEEEE29C7,0xB8B8D36B,0x14143C28, + 0xDEDE79A7,0x5E5EE2BC,0x0B0B1D16,0xDBDB76AD, + 0xE0E03BDB,0x32325664,0x3A3A4E74,0x0A0A1E14, + 0x4949DB92,0x06060A0C,0x24246C48,0x5C5CE4B8, + 0xC2C25D9F,0xD3D36EBD,0xACACEF43,0x6262A6C4, + 0x9191A839,0x9595A431,0xE4E437D3,0x79798BF2, + 0xE7E732D5,0xC8C8438B,0x3737596E,0x6D6DB7DA, + 0x8D8D8C01,0xD5D564B1,0x4E4ED29C,0xA9A9E049, + 0x6C6CB4D8,0x5656FAAC,0xF4F407F3,0xEAEA25CF, + 0x6565AFCA,0x7A7A8EF4,0xAEAEE947,0x08081810, + 0xBABAD56F,0x787888F0,0x25256F4A,0x2E2E725C, + 0x1C1C2438,0xA6A6F157,0xB4B4C773,0xC6C65197, + 0xE8E823CB,0xDDDD7CA1,0x74749CE8,0x1F1F213E, + 0x4B4BDD96,0xBDBDDC61,0x8B8B860D,0x8A8A850F, + 0x707090E0,0x3E3E427C,0xB5B5C471,0x6666AACC, + 0x4848D890,0x03030506,0xF6F601F7,0x0E0E121C, + 0x6161A3C2,0x35355F6A,0x5757F9AE,0xB9B9D069, + 0x86869117,0xC1C15899,0x1D1D273A,0x9E9EB927, + 0xE1E138D9,0xF8F813EB,0x9898B32B,0x11113322, + 0x6969BBD2,0xD9D970A9,0x8E8E8907,0x9494A733, + 0x9B9BB62D,0x1E1E223C,0x87879215,0xE9E920C9, + 0xCECE4987,0x5555FFAA,0x28287850,0xDFDF7AA5, + 0x8C8C8F03,0xA1A1F859,0x89898009,0x0D0D171A, + 0xBFBFDA65,0xE6E631D7,0x4242C684,0x6868B8D0, + 0x4141C382,0x9999B029,0x2D2D775A,0x0F0F111E, + 0xB0B0CB7B,0x5454FCA8,0xBBBBD66D,0x16163A2C, + }}; + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_COMMON_AES_E_H */ diff --git a/build/tools/acsign/aes_e_ecb.c b/build/tools/acsign/aes_e_ecb.c new file mode 100644 index 00000000..55867bd9 --- /dev/null +++ b/build/tools/acsign/aes_e_ecb.c @@ -0,0 +1,48 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + */ + +#ifndef NO_AES + +#include "aes.h" + + +void AES_ecb_encrypt_com(AES_KEY *key, unsigned char *out, + const unsigned char *in, AES_ENC_DEC_FN enc_fn) + { + AES_INT4 data[4],w; + + data[0]=((in[ 0]<<24)|(in[ 1]<<16)|(in[ 2]<<8)|(in[ 3])); + data[1]=((in[ 4]<<24)|(in[ 5]<<16)|(in[ 6]<<8)|(in[ 7])); + data[2]=((in[ 8]<<24)|(in[ 9]<<16)|(in[10]<<8)|(in[11])); + data[3]=((in[12]<<24)|(in[13]<<16)|(in[14]<<8)|(in[15])); + enc_fn(key,&(data[0])); + w=data[0]; + out[ 0]=(w>>24)&0xff; + out[ 1]=(w>>16)&0xff; + out[ 2]=(w>> 8)&0xff; + out[ 3]=(w )&0xff; + w=data[1]; + out[ 4]=(w>>24)&0xff; + out[ 5]=(w>>16)&0xff; + out[ 6]=(w>> 8)&0xff; + out[ 7]=(w )&0xff; + w=data[2]; + out[ 8]=(w>>24)&0xff; + out[ 9]=(w>>16)&0xff; + out[10]=(w>> 8)&0xff; + out[11]=(w )&0xff; + w=data[3]; + out[12]=(w>>24)&0xff; + out[13]=(w>>16)&0xff; + out[14]=(w>> 8)&0xff; + out[15]=(w )&0xff; + } + +#endif /* NO_AES */ diff --git a/build/tools/acsign/aes_sbox.h b/build/tools/acsign/aes_sbox.h new file mode 100644 index 00000000..6a584f4b --- /dev/null +++ b/build/tools/acsign/aes_sbox.h @@ -0,0 +1,59 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + */ + +#ifndef HEADER_COMMON_AES_SBOX_H +#define HEADER_COMMON_AES_SBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern const unsigned char aes_sbox[256]; + +const unsigned char aes_sbox[256]={ + 0x63,0x7C,0x77,0x7B,0xF2,0x6B,0x6F,0xC5, + 0x30,0x01,0x67,0x2B,0xFE,0xD7,0xAB,0x76, + 0xCA,0x82,0xC9,0x7D,0xFA,0x59,0x47,0xF0, + 0xAD,0xD4,0xA2,0xAF,0x9C,0xA4,0x72,0xC0, + 0xB7,0xFD,0x93,0x26,0x36,0x3F,0xF7,0xCC, + 0x34,0xA5,0xE5,0xF1,0x71,0xD8,0x31,0x15, + 0x04,0xC7,0x23,0xC3,0x18,0x96,0x05,0x9A, + 0x07,0x12,0x80,0xE2,0xEB,0x27,0xB2,0x75, + 0x09,0x83,0x2C,0x1A,0x1B,0x6E,0x5A,0xA0, + 0x52,0x3B,0xD6,0xB3,0x29,0xE3,0x2F,0x84, + 0x53,0xD1,0x00,0xED,0x20,0xFC,0xB1,0x5B, + 0x6A,0xCB,0xBE,0x39,0x4A,0x4C,0x58,0xCF, + 0xD0,0xEF,0xAA,0xFB,0x43,0x4D,0x33,0x85, + 0x45,0xF9,0x02,0x7F,0x50,0x3C,0x9F,0xA8, + 0x51,0xA3,0x40,0x8F,0x92,0x9D,0x38,0xF5, + 0xBC,0xB6,0xDA,0x21,0x10,0xFF,0xF3,0xD2, + 0xCD,0x0C,0x13,0xEC,0x5F,0x97,0x44,0x17, + 0xC4,0xA7,0x7E,0x3D,0x64,0x5D,0x19,0x73, + 0x60,0x81,0x4F,0xDC,0x22,0x2A,0x90,0x88, + 0x46,0xEE,0xB8,0x14,0xDE,0x5E,0x0B,0xDB, + 0xE0,0x32,0x3A,0x0A,0x49,0x06,0x24,0x5C, + 0xC2,0xD3,0xAC,0x62,0x91,0x95,0xE4,0x79, + 0xE7,0xC8,0x37,0x6D,0x8D,0xD5,0x4E,0xA9, + 0x6C,0x56,0xF4,0xEA,0x65,0x7A,0xAE,0x08, + 0xBA,0x78,0x25,0x2E,0x1C,0xA6,0xB4,0xC6, + 0xE8,0xDD,0x74,0x1F,0x4B,0xBD,0x8B,0x8A, + 0x70,0x3E,0xB5,0x66,0x48,0x03,0xF6,0x0E, + 0x61,0x35,0x57,0xB9,0x86,0xC1,0x1D,0x9E, + 0xE1,0xF8,0x98,0x11,0x69,0xD9,0x8E,0x94, + 0x9B,0x1E,0x87,0xE9,0xCE,0x55,0x28,0xDF, + 0x8C,0xA1,0x89,0x0D,0xBF,0xE6,0x42,0x68, + 0x41,0x99,0x2D,0x0F,0xB0,0x54,0xBB,0x16, + }; + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_COMMON_AES_SBOX_H */ diff --git a/build/tools/acsign/aes_skey.c b/build/tools/acsign/aes_skey.c new file mode 100644 index 00000000..682766ea --- /dev/null +++ b/build/tools/acsign/aes_skey.c @@ -0,0 +1,143 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + */ + +#ifndef NO_AES + +#include "aes.h" +#include "aes_sbox.h" + +static const unsigned char Rcon[30]={ + 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80, + 0x1b,0x36,0x6c,0xd8,0xab,0x4d,0x9a,0x2f, + 0x5e,0xbc,0x63,0xc6,0x97,0x35,0x6a,0xd4, + 0xb3,0x7d,0xfa,0xef,0xc5,0x91, + }; + +int AES_set_key(AES_KEY *ctx, const unsigned char *key, int len) + { + int i,ii; + AES_INT4 *W,tmp,tmp2; + const unsigned char *ip; + int words; + + if (len == 16) + { + i=10; + words=4; + } + else if (len == 24) + { + i=12; + words=6; + } + else if (len == 32) + { + i=14; + words=8; + } + else + return(1); + + ctx->rounds=i; + ctx->key_size=words; + W=(unsigned int *)ctx->ks; + for (i=0; irounds+1); + for (i=words; i> 8)&0xff]<<16; + tmp2|=(AES_INT4)aes_sbox[(tmp>>16)&0xff]<<24; + tmp2|=(AES_INT4)aes_sbox[(tmp>>24) ]; + tmp=tmp2^(((unsigned int)*ip)<<24); + ip++; + } + if ((words == 8) && ((i % words) == 4)) + { + tmp2 =(AES_INT4)aes_sbox[(tmp )&0xff] ; + tmp2|=(AES_INT4)aes_sbox[(tmp>> 8)&0xff]<< 8; + tmp2|=(AES_INT4)aes_sbox[(tmp>>16)&0xff]<<16; + tmp2|=(AES_INT4)aes_sbox[(tmp>>24) ]<<24; + tmp=tmp2; + } + W[i]=W[i-words]^tmp; + } + return(0); + } + +#define rot1(x) (((x) << 24) | ((x) >> 8)) +#define rot2(x) (((x) << 16) | ((x) >> 16)) +#define rot3(x) (((x) << 8) | ((x) >> 24)) + +/* This cute trick does 4 'mul by two' at once. Stolen from + * Dr B. R. Gladman but I'm sure the u-(u>>7) is + * a standard graphics trick + * The key to this is that we need to xor with 0x1b if the top bit is set. + * a 1xxx xxxx 0xxx 0xxx First we mask the 7bit, + * b 1000 0000 0000 0000 then we shift right by 7 puting the 7bit in 0bit, + * c 0000 0001 0000 0000 we then subtract (c) from (b) + * d 0111 1111 0000 0000 and now we and with our mask + * e 0001 1011 0000 0000 + */ +#define mt 0x80808080 +#define ml 0x7f7f7f7f +#define mh 0xfefefefe +#define mm 0x1b1b1b1b +#define mul2(x,t) ((t)=((x)&mt), \ + ((((x)+(x))&mh)^(((t)-((t)>>7))&mm))) + +#define mix_col(x,f2,f3) (\ + (f2)=mul2(x,f3), \ + (f3)=(x)^(f2), \ + (rot3(f3) ^ rot2(x) ^ rot1(x)^(f2))) + +#define inv_mix_col(x,f2,f4,f8,f9) (\ + (f2)=mul2(x,f2), \ + (f4)=mul2(f2,f4), \ + (f8)=mul2(f4,f8), \ + (f9)=(x)^(f8), \ + (f8)=((f2)^(f4)^(f8)), \ + (f2)^=(f9), \ + (f4)^=(f9), \ + (f8)^=rot3(f2), \ + (f8)^=rot2(f4), \ + (f8)^rot1(f9)) + +void AES_convert_key(AES_KEY *ctx) + { + int i; + AES_INT4 *k,w,t1,t2,t3,t4; + + k= ctx->ks; + k+=4; + for (i=ctx->rounds*4; i>4; i--) + { + w= *k; + w = inv_mix_col(w,t1,t2,t3,t4); + *k++ =w; + } + } +#endif /* NO_AES */ diff --git a/build/tools/acsign/bn_add.c b/build/tools/acsign/bn_add.c new file mode 100644 index 00000000..75820c61 --- /dev/null +++ b/build/tools/acsign/bn_add.c @@ -0,0 +1,304 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +/** + * @file bn_add.c + * @brief BIGNUM addition and subtraction functions + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_ADD +#define SPLIT_BN_UADD +#define SPLIT_BN_USUB +#define SPLIT_BN_SUB +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BN_ADD +/* r can == a or b */ +int BN_add(r, a, b) +BIGNUM *r; +BIGNUM *a; +BIGNUM *b; + { + BIGNUM *tmp; + + bn_check_top(a); + bn_check_top(b); + + /* a + b a+b + * a + -b a-b + * -a + b b-a + * -a + -b -(a+b) + */ + if (a->neg ^ b->neg) + { + /* only one is negative */ + if (a->neg) + { tmp=a; a=b; b=tmp; } + + /* we are now a - b */ + + if (BN_ucmp(a,b) < 0) + { + if (!BN_usub(r,b,a)) return(0); + r->neg=1; + } + else + { + if (!BN_usub(r,a,b)) return(0); + r->neg=0; + } + return(1); + } + + if (a->neg) /* both are neg */ + r->neg=1; + else + r->neg=0; + + if (!BN_uadd(r,a,b)) return(0); + return(1); + } +#endif + +#ifdef SPLIT_BN_UADD +/* unsigned add of b to a, r must be large enough */ +int BN_uadd(r,a,b) +BIGNUM *r; +BIGNUM *a; +BIGNUM *b; + { + register int i; + int max,min; + BN_ULONG *ap,*bp,*rp,carry,t1; + BIGNUM *tmp; + + bn_check_top(a); + bn_check_top(b); + + if (a->top < b->top) + { tmp=a; a=b; b=tmp; } + max=a->top; + min=b->top; + + if (bn_wexpand(r,max+1) == NULL) + return(0); + + r->top=max; + + + ap=a->d; + bp=b->d; + rp=r->d; + carry=0; + + carry=bn_add_words(rp,ap,bp,min); + rp+=min; + ap+=min; + bp+=min; + i=min; + + if (carry) + { + while (i < max) + { + i++; + t1= *(ap++); + if ((*(rp++)=(t1+1)&BN_MASK2) >= t1) + { + carry=0; + break; + } + } + if ((i >= max) && carry) + { + *(rp++)=1; + r->top++; + } + } + if (rp != ap) + { + for (; ib from a + * @param r result of subtraction + * @param a pointer to a BIGNUM + * @param b pointer to a BIGNUM + * @pre a must be larger than b + * @return 1 on success, 0 on failure + * @todo On next IRIX port check the validity of IRIX_CC_BUG. + */ +#ifdef SPLIT_BN_USUB +int BN_usub(r, a, b) +BIGNUM *r; +BIGNUM *a; +BIGNUM *b; + { + int max,min; + register BN_ULONG t1,t2,*ap,*bp,*rp; + int i,carry; +#if defined(IRIX_CC_BUG) && !defined(LINT) + int dummy; +#endif + + bn_check_top(a); + bn_check_top(b); + + /* + * check for pre-condition violation + */ + if (a->top < b->top) + { +#ifndef NO_ERR + BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3); +#endif + return(0); + } + + max=a->top; + min=b->top; + if (bn_wexpand(r,max) == NULL) return(0); + + ap=a->d; + bp=b->d; + rp=r->d; + + /* + * perform the subtraction and see if we + * have a (final) carry + */ + carry=0; + for (i=0; i t2) break; + } + } + + if (rp != ap) + { +#ifdef BN_LIBRARY_SMALL + Memcpy(rp,ap,sizeof(*rp)*(max-i)); +#else /* BN_LIBRARY_SMALL */ + for (;;) + { + if (i++ >= max) break; + rp[0]=ap[0]; + if (i++ >= max) break; + rp[1]=ap[1]; + if (i++ >= max) break; + rp[2]=ap[2]; + if (i++ >= max) break; + rp[3]=ap[3]; + rp+=4; + ap+=4; + } +#endif /* BN_LIBRARY_SMALL */ + } + + r->top=max; + bn_fix_top(r); + return(1); + } +#endif + +#ifdef SPLIT_BN_SUB +int BN_sub(r, a, b) +BIGNUM *r; +BIGNUM *a; +BIGNUM *b; + { + int max; + int add=0,neg=0; + BIGNUM *tmp; + + bn_check_top(a); + bn_check_top(b); + + /* a - b a-b + * a - -b a+b + * -a - b -(a+b) + * -a - -b b-a + */ + if (a->neg) + { + if (b->neg) + { tmp=a; a=b; b=tmp; } + else + { add=1; neg=1; } + } + else + { + if (b->neg) { add=1; neg=0; } + } + + if (add) + { + if (!BN_uadd(r,a,b)) return(0); + r->neg=neg; + return(1); + } + + /* We are actually doing a - b */ + + max=(a->top > b->top)?a->top:b->top; + if (bn_wexpand(r,max) == NULL) return(0); + if (BN_ucmp(a,b) < 0) + { + if (!BN_usub(r,b,a)) return(0); + r->neg=1; + } + else + { + if (!BN_usub(r,a,b)) return(0); + r->neg=0; + } + return(1); + } +#endif + +#endif diff --git a/build/tools/acsign/bn_asm.c b/build/tools/acsign/bn_asm.c new file mode 100644 index 00000000..59326c1f --- /dev/null +++ b/build/tools/acsign/bn_asm.c @@ -0,0 +1,509 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#ifndef OPT_BN_ASM + +#define BN_MUL_ADD_WORDS + +#ifndef BN_MUL_WORDS +#define BN_MUL_WORDS +#endif + +#ifndef BN_SQR_WORDS +#define BN_SQR_WORDS +#endif + +#ifndef BN_ADD_WORDS +#define BN_ADD_WORDS +#endif + +#ifndef BN_SUB_WORDS +#define BN_SUB_WORDS +#endif + +#endif + + +#include "bn_lcl.h" + +#ifdef BN_LLONG + +/* + * bn_mul_add_words + * + * for(i=0;i=0; i--) + fprintf(stderr,BN_HEX_FMT,ap[i]); + fprintf(stderr,"*"); + fprintf(stderr,BN_HEX_FMT,w); + fprintf(stderr,"+"); + for (i=num-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,rp[i]); +#endif + + for (;;) + { + mul_add(rp[0],ap[0],w,c1); + if (--num == 0) break; + mul_add(rp[1],ap[1],w,c1); + if (--num == 0) break; + mul_add(rp[2],ap[2],w,c1); + if (--num == 0) break; + mul_add(rp[3],ap[3],w,c1); + if (--num == 0) break; + ap+=4; + rp+=4; + } + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + fprintf(stderr,"-"); + fprintf(stderr,BN_HEX_FMT,c1); + for (i=nn-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,rp[i]); + fprintf(stderr,"\n"); + } +#endif + return(c1); + } +#endif + +#ifdef BN_MUL_WORDS +BN_ULONG bn_mul_words(rp,ap,num,w) +BN_ULONG *rp,*ap; +int num; +BN_ULONG w; + { + BN_ULONG c1=0; + + bn_check_num(num); + if (num <= 0) return(c1); + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + { + int i,nn=num; + + for (i=num-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,ap[i]); + fprintf(stderr,"*"); + fprintf(stderr,BN_HEX_FMT,w); +#endif + + for (;;) + { + mul(rp[0],ap[0],w,c1); + if (--num == 0) break; + mul(rp[1],ap[1],w,c1); + if (--num == 0) break; + mul(rp[2],ap[2],w,c1); + if (--num == 0) break; + mul(rp[3],ap[3],w,c1); + if (--num == 0) break; + ap+=4; + rp+=4; + } + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + fprintf(stderr,"-"); + fprintf(stderr,BN_HEX_FMT,c1); + for (i=nn-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,rp[i]); + fprintf(stderr,"\n"); + } +#endif + return(c1); + } +#endif + +#ifdef BN_SQR_WORDS +void bn_sqr_words(r,a,n) +BN_ULONG *r,*a; +int n; + { + bn_check_num(n); + if (n <= 0) return; + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + { + int i,nn=n; + + for (i=n-1; i>=0; i--) + { + fprintf(stderr,BN_HEX_FMT,a[i]); + if (i != 0) + fprintf(stderr,"^2*2^%X+",i*2*BN_BITS2); + else + fprintf(stderr,"^2"); + } +#endif + + for (;;) + { + BN_ULLONG t; + + t=(BN_ULLONG)(a[0])*(a[0]); + r[0]=Lw(t); r[1]=Hw(t); + if (--n == 0) break; + + t=(BN_ULLONG)(a[1])*(a[1]); + r[2]=Lw(t); r[3]=Hw(t); + if (--n == 0) break; + + t=(BN_ULLONG)(a[2])*(a[2]); + r[4]=Lw(t); r[5]=Hw(t); + if (--n == 0) break; + + t=(BN_ULLONG)(a[3])*(a[3]); + r[6]=Lw(t); r[7]=Hw(t); + if (--n == 0) break; + + a+=4; + r+=8; + } +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + + fprintf(stderr,"-"); + for (i=nn+nn-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,r[i]); + fprintf(stderr,"\n"); + } +#endif + } +#endif + +#else + +#ifdef BN_MUL_ADD_WORDS + +BN_ULONG bn_mul_add_words(rp,ap,num,w) +BN_ULONG *rp,*ap; +int num; +BN_ULONG w; + { + BN_ULONG c=0; + BN_ULONG bl,bh,b_hl; + + bn_check_num(num); + if (num <= 0) return((BN_ULONG)0); + + bl=LBITS(w); + bh=HBITS(w); + b_hl=bh-bl; +/* +{ int i,nnum=num; +BN_ULONG *rrp=rp; +for (i=num-1; i>=0; i--) printf("%02X",rp[i]); +printf("+"); +for (i=num-1; i>=0; i--) printf("%02X",ap[i]); +printf("*%02X - ",w); +*/ + for (;;) + { + mul_add(rp[0],ap[0],bl,bh,b_hl,c); + if (--num == 0) break; + mul_add(rp[1],ap[1],bl,bh,b_hl,c); + if (--num == 0) break; + mul_add(rp[2],ap[2],bl,bh,b_hl,c); + if (--num == 0) break; + mul_add(rp[3],ap[3],bl,bh,b_hl,c); + if (--num == 0) break; + ap+=4; + rp+=4; + } + +/* +printf("%02X",c); +for (i=nnum-1; i>=0; i--) printf("%02X",rrp[i]); +printf("\n"); +} +*/ + return(c); + } + +#endif + +#ifdef BN_MUL_WORDS +BN_ULONG bn_mul_words(rp,ap,num,w) +BN_ULONG *rp,*ap; +int num; +BN_ULONG w; + { + BN_ULONG carry=0; + BN_ULONG bl,bh; + + bn_check_num(num); + if (num <= 0) return((BN_ULONG)0); + + bl=LBITS(w); + bh=HBITS(w); + + for (;;) + { + mul(rp[0],ap[0],bl,bh,carry); + if (--num == 0) break; + mul(rp[1],ap[1],bl,bh,carry); + if (--num == 0) break; + mul(rp[2],ap[2],bl,bh,carry); + if (--num == 0) break; + mul(rp[3],ap[3],bl,bh,carry); + if (--num == 0) break; + ap+=4; + rp+=4; + } + return(carry); + } +#endif + +#ifdef BN_SQR_WORDS +void bn_sqr_words(r,a,n) +BN_ULONG *r,*a; +int n; + { + bn_check_num(n); + if (n <= 0) return; + for (;;) + { + sqr64(r[0],r[1],a[0]); + if (--n == 0) break; + + sqr64(r[2],r[3],a[1]); + if (--n == 0) break; + + sqr64(r[4],r[5],a[2]); + if (--n == 0) break; + + sqr64(r[6],r[7],a[3]); + if (--n == 0) break; + + a+=4; + r+=8; + } + } +#endif + +#endif + +#ifdef BN_ADD_WORDS +#ifdef BN_LLONG +BN_ULONG bn_add_words(r,a,b,n) +BN_ULONG *r,*a,*b; +int n; + { + BN_ULLONG ll=0; + + bn_check_num(n); + if (n <= 0) return((BN_ULONG)0); + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + { + int i,nn=n; + + for (i=n-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,a[i]); + fprintf(stderr,"+"); + for (i=n-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,b[i]); +#endif + + for (;;) + { + ll+=(BN_ULLONG)a[0]+b[0]; + r[0]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + ll+=(BN_ULLONG)a[1]+b[1]; + r[1]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + ll+=(BN_ULLONG)a[2]+b[2]; + r[2]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + ll+=(BN_ULLONG)a[3]+b[3]; + r[3]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + a+=4; + b+=4; + r+=4; + } +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + fprintf(stderr,"-"); + fprintf(stderr,BN_HEX_FMT,(BN_ULONG)ll); + for (i=nn-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,r[i]); + fprintf(stderr,"\n"); + } +#endif + return((BN_ULONG)ll); + } +#else +BN_ULONG bn_add_words(r,a,b,n) +BN_ULONG *r,*a,*b; +int n; + { + BN_ULONG c,l,t; + + bn_check_num(n); + if (n <= 0) return((BN_ULONG)0); + + c=0; + for (;;) + { + t=a[0]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[0])&BN_MASK2; + c+=(l < t); + r[0]=l; + if (--n <= 0) break; + + t=a[1]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[1])&BN_MASK2; + c+=(l < t); + r[1]=l; + if (--n <= 0) break; + + t=a[2]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[2])&BN_MASK2; + c+=(l < t); + r[2]=l; + if (--n <= 0) break; + + t=a[3]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[3])&BN_MASK2; + c+=(l < t); + r[3]=l; + if (--n <= 0) break; + + a+=4; + b+=4; + r+=4; + } + + return((BN_ULONG)c); + } +#endif +#endif + +#ifdef BN_SUB_WORDS +BN_ULONG bn_sub_words(r,a,b,n) +BN_ULONG *r,*a,*b; +int n; + { + BN_ULONG c,t1,t2; + + bn_check_num(n); + if (n <= 0) return((BN_ULONG)0); + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + { + int i,nn=n; + + for (i=n-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,a[i]); + fprintf(stderr,"-"); + for (i=n-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,b[i]); +#endif + + c=0; + for (;;) + { + t1=a[0]; t2=b[0]; + r[0]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + t1=a[1]; t2=b[1]; + r[1]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + t1=a[2]; t2=b[2]; + r[2]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + t1=a[3]; t2=b[3]; + r[3]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + a+=4; + b+=4; + r+=4; + } + +#if defined(BN_ASM_DEBUG) && !defined(NO_FP_API) + fprintf(stderr,"- "); + if (c) fprintf(stderr,"-"); + for (i=nn-1; i>=0; i--) + fprintf(stderr,BN_HEX_FMT,r[i]); + fprintf(stderr,"\n"); + } +#endif + return(c); + } +#endif + diff --git a/build/tools/acsign/bn_comba.c b/build/tools/acsign/bn_comba.c new file mode 100644 index 00000000..61dbc937 --- /dev/null +++ b/build/tools/acsign/bn_comba.c @@ -0,0 +1,434 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_MUL_COMBA8 +#define SPLIT_BN_MUL_COMBA4 +#define SPLIT_BN_SQR_COMBA8 +#define SPLIT_BN_SQR_COMBA4 +#endif /* NO_SPLIT */ + +#ifndef OPT_BN_ASM +/* #if 1 */ + +#ifdef BN_LLONG +#define mul_add_c(a,b,c0,c1,c2) \ + t=(BN_ULLONG)a*b; \ + t1=(BN_ULONG)Lw(t); \ + t2=(BN_ULONG)Hw(t); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define mul_add_c2(a,b,c0,c1,c2) \ + t=(BN_ULLONG)a*b; \ + tt=(t+t)&BN_MASK; \ + if (tt < t) c2++; \ + t1=(BN_ULONG)Lw(tt); \ + t2=(BN_ULONG)Hw(tt); \ + c0=(c0+t1)&BN_MASK2; \ + if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c(a,i,c0,c1,c2) \ + t=(BN_ULLONG)a[i]*a[i]; \ + t1=(BN_ULONG)Lw(t); \ + t2=(BN_ULONG)Hw(t); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c2(a,i,j,c0,c1,c2) \ + mul_add_c2((a)[i],(a)[j],c0,c1,c2) +#else +#define mul_add_c(a,b,c0,c1,c2) \ + t1=LBITS(a); t2=HBITS(a); \ + bl=LBITS(b); bh=HBITS(b); \ + mul64(t1,t2,bl,bh); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define mul_add_c2(a,b,c0,c1,c2) \ + t1=LBITS(a); t2=HBITS(a); \ + bl=LBITS(b); bh=HBITS(b); \ + mul64(t1,t2,bl,bh); \ + if (t2 & BN_TBIT) c2++; \ + t2=(t2+t2)&BN_MASK2; \ + if (t1 & BN_TBIT) t2++; \ + t1=(t1+t1)&BN_MASK2; \ + c0=(c0+t1)&BN_MASK2; \ + if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c(a,i,c0,c1,c2) \ + sqr64(t1,t2,(a)[i]); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c2(a,i,j,c0,c1,c2) \ + mul_add_c2((a)[i],(a)[j],c0,c1,c2) +#endif + +#if defined(BN_MUL_COMBA) + +#ifdef SPLIT_BN_MUL_COMBA8 +#undef bn_mul_comba8 +void bn_mul_comba8(r,a,b) +BN_ULONG *r,*a,*b; + { +#ifdef BN_LLONG + BN_ULLONG t; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + mul_add_c(a[0],b[0],c1,c2,c3); + r[0]=c1; + c1=0; + mul_add_c(a[0],b[1],c2,c3,c1); + mul_add_c(a[1],b[0],c2,c3,c1); + r[1]=c2; + c2=0; + mul_add_c(a[2],b[0],c3,c1,c2); + mul_add_c(a[1],b[1],c3,c1,c2); + mul_add_c(a[0],b[2],c3,c1,c2); + r[2]=c3; + c3=0; + mul_add_c(a[0],b[3],c1,c2,c3); + mul_add_c(a[1],b[2],c1,c2,c3); + mul_add_c(a[2],b[1],c1,c2,c3); + mul_add_c(a[3],b[0],c1,c2,c3); + r[3]=c1; + c1=0; + mul_add_c(a[4],b[0],c2,c3,c1); + mul_add_c(a[3],b[1],c2,c3,c1); + mul_add_c(a[2],b[2],c2,c3,c1); + mul_add_c(a[1],b[3],c2,c3,c1); + mul_add_c(a[0],b[4],c2,c3,c1); + r[4]=c2; + c2=0; + mul_add_c(a[0],b[5],c3,c1,c2); + mul_add_c(a[1],b[4],c3,c1,c2); + mul_add_c(a[2],b[3],c3,c1,c2); + mul_add_c(a[3],b[2],c3,c1,c2); + mul_add_c(a[4],b[1],c3,c1,c2); + mul_add_c(a[5],b[0],c3,c1,c2); + r[5]=c3; + c3=0; + mul_add_c(a[6],b[0],c1,c2,c3); + mul_add_c(a[5],b[1],c1,c2,c3); + mul_add_c(a[4],b[2],c1,c2,c3); + mul_add_c(a[3],b[3],c1,c2,c3); + mul_add_c(a[2],b[4],c1,c2,c3); + mul_add_c(a[1],b[5],c1,c2,c3); + mul_add_c(a[0],b[6],c1,c2,c3); + r[6]=c1; + c1=0; + mul_add_c(a[0],b[7],c2,c3,c1); + mul_add_c(a[1],b[6],c2,c3,c1); + mul_add_c(a[2],b[5],c2,c3,c1); + mul_add_c(a[3],b[4],c2,c3,c1); + mul_add_c(a[4],b[3],c2,c3,c1); + mul_add_c(a[5],b[2],c2,c3,c1); + mul_add_c(a[6],b[1],c2,c3,c1); + mul_add_c(a[7],b[0],c2,c3,c1); + r[7]=c2; + c2=0; + mul_add_c(a[7],b[1],c3,c1,c2); + mul_add_c(a[6],b[2],c3,c1,c2); + mul_add_c(a[5],b[3],c3,c1,c2); + mul_add_c(a[4],b[4],c3,c1,c2); + mul_add_c(a[3],b[5],c3,c1,c2); + mul_add_c(a[2],b[6],c3,c1,c2); + mul_add_c(a[1],b[7],c3,c1,c2); + r[8]=c3; + c3=0; + mul_add_c(a[2],b[7],c1,c2,c3); + mul_add_c(a[3],b[6],c1,c2,c3); + mul_add_c(a[4],b[5],c1,c2,c3); + mul_add_c(a[5],b[4],c1,c2,c3); + mul_add_c(a[6],b[3],c1,c2,c3); + mul_add_c(a[7],b[2],c1,c2,c3); + r[9]=c1; + c1=0; + mul_add_c(a[7],b[3],c2,c3,c1); + mul_add_c(a[6],b[4],c2,c3,c1); + mul_add_c(a[5],b[5],c2,c3,c1); + mul_add_c(a[4],b[6],c2,c3,c1); + mul_add_c(a[3],b[7],c2,c3,c1); + r[10]=c2; + c2=0; + mul_add_c(a[4],b[7],c3,c1,c2); + mul_add_c(a[5],b[6],c3,c1,c2); + mul_add_c(a[6],b[5],c3,c1,c2); + mul_add_c(a[7],b[4],c3,c1,c2); + r[11]=c3; + c3=0; + mul_add_c(a[7],b[5],c1,c2,c3); + mul_add_c(a[6],b[6],c1,c2,c3); + mul_add_c(a[5],b[7],c1,c2,c3); + r[12]=c1; + c1=0; + mul_add_c(a[6],b[7],c2,c3,c1); + mul_add_c(a[7],b[6],c2,c3,c1); + r[13]=c2; + c2=0; + mul_add_c(a[7],b[7],c3,c1,c2); + r[14]=c3; + r[15]=c1; + } +#endif + +#ifdef SPLIT_BN_MUL_COMBA4 +#undef bn_mul_comba4 +void bn_mul_comba4(r,a,b) +BN_ULONG *r,*a,*b; + { +#ifdef BN_LLONG + BN_ULLONG t; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + mul_add_c(a[0],b[0],c1,c2,c3); + r[0]=c1; + c1=0; + mul_add_c(a[0],b[1],c2,c3,c1); + mul_add_c(a[1],b[0],c2,c3,c1); + r[1]=c2; + c2=0; + mul_add_c(a[2],b[0],c3,c1,c2); + mul_add_c(a[1],b[1],c3,c1,c2); + mul_add_c(a[0],b[2],c3,c1,c2); + r[2]=c3; + c3=0; + mul_add_c(a[0],b[3],c1,c2,c3); + mul_add_c(a[1],b[2],c1,c2,c3); + mul_add_c(a[2],b[1],c1,c2,c3); + mul_add_c(a[3],b[0],c1,c2,c3); + r[3]=c1; + c1=0; + mul_add_c(a[3],b[1],c2,c3,c1); + mul_add_c(a[2],b[2],c2,c3,c1); + mul_add_c(a[1],b[3],c2,c3,c1); + r[4]=c2; + c2=0; + mul_add_c(a[2],b[3],c3,c1,c2); + mul_add_c(a[3],b[2],c3,c1,c2); + r[5]=c3; + c3=0; + mul_add_c(a[3],b[3],c1,c2,c3); + r[6]=c1; + r[7]=c2; + } +#endif + +#else + +#ifdef SPLIT_BN_MUL_COMBA4 +#undef bn_mul_comba4 +void bn_mul_comba4(r,a,b) +BN_ULONG *r,*a,*b; + { + r[4]=bn_mul_words( &(r[0]),a,4,b[0]); + r[5]=bn_mul_add_words(&(r[1]),a,4,b[1]); + r[6]=bn_mul_add_words(&(r[2]),a,4,b[2]); + r[7]=bn_mul_add_words(&(r[3]),a,4,b[3]); + } +#endif + +#ifdef SPLIT_BN_MUL_COMBA8 +#undef bn_mul_comba8 +void bn_mul_comba8(r,a,b) +BN_ULONG *r,*a,*b; + { + r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]); + r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]); + r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]); + r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]); + r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]); + r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]); + r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]); + r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]); + } +#endif + +#endif /* BN_MUL_COMBA */ + +#ifdef BN_SQR_COMBA + +#ifdef SPLIT_BN_SQR_COMBA8 +#undef bn_sqr_comba8 +void bn_sqr_comba8(r,a) +BN_ULONG *r,*a; + { +#ifdef BN_LLONG + BN_ULLONG t,tt; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + sqr_add_c(a,0,c1,c2,c3); + r[0]=c1; + c1=0; + sqr_add_c2(a,1,0,c2,c3,c1); + r[1]=c2; + c2=0; + sqr_add_c(a,1,c3,c1,c2); + sqr_add_c2(a,2,0,c3,c1,c2); + r[2]=c3; + c3=0; + sqr_add_c2(a,3,0,c1,c2,c3); + sqr_add_c2(a,2,1,c1,c2,c3); + r[3]=c1; + c1=0; + sqr_add_c(a,2,c2,c3,c1); + sqr_add_c2(a,3,1,c2,c3,c1); + sqr_add_c2(a,4,0,c2,c3,c1); + r[4]=c2; + c2=0; + sqr_add_c2(a,5,0,c3,c1,c2); + sqr_add_c2(a,4,1,c3,c1,c2); + sqr_add_c2(a,3,2,c3,c1,c2); + r[5]=c3; + c3=0; + sqr_add_c(a,3,c1,c2,c3); + sqr_add_c2(a,4,2,c1,c2,c3); + sqr_add_c2(a,5,1,c1,c2,c3); + sqr_add_c2(a,6,0,c1,c2,c3); + r[6]=c1; + c1=0; + sqr_add_c2(a,7,0,c2,c3,c1); + sqr_add_c2(a,6,1,c2,c3,c1); + sqr_add_c2(a,5,2,c2,c3,c1); + sqr_add_c2(a,4,3,c2,c3,c1); + r[7]=c2; + c2=0; + sqr_add_c(a,4,c3,c1,c2); + sqr_add_c2(a,5,3,c3,c1,c2); + sqr_add_c2(a,6,2,c3,c1,c2); + sqr_add_c2(a,7,1,c3,c1,c2); + r[8]=c3; + c3=0; + sqr_add_c2(a,7,2,c1,c2,c3); + sqr_add_c2(a,6,3,c1,c2,c3); + sqr_add_c2(a,5,4,c1,c2,c3); + r[9]=c1; + c1=0; + sqr_add_c(a,5,c2,c3,c1); + sqr_add_c2(a,6,4,c2,c3,c1); + sqr_add_c2(a,7,3,c2,c3,c1); + r[10]=c2; + c2=0; + sqr_add_c2(a,7,4,c3,c1,c2); + sqr_add_c2(a,6,5,c3,c1,c2); + r[11]=c3; + c3=0; + sqr_add_c(a,6,c1,c2,c3); + sqr_add_c2(a,7,5,c1,c2,c3); + r[12]=c1; + c1=0; + sqr_add_c2(a,7,6,c2,c3,c1); + r[13]=c2; + c2=0; + sqr_add_c(a,7,c3,c1,c2); + r[14]=c3; + r[15]=c1; + } +#endif + +#ifdef SPLIT_BN_SQR_COMBA4 +#undef bn_sqr_comba4 +void bn_sqr_comba4(r,a) +BN_ULONG *r,*a; + { +#ifdef BN_LLONG + BN_ULLONG t,tt; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + sqr_add_c(a,0,c1,c2,c3); + r[0]=c1; + c1=0; + sqr_add_c2(a,1,0,c2,c3,c1); + r[1]=c2; + c2=0; + sqr_add_c(a,1,c3,c1,c2); + sqr_add_c2(a,2,0,c3,c1,c2); + r[2]=c3; + c3=0; + sqr_add_c2(a,3,0,c1,c2,c3); + sqr_add_c2(a,2,1,c1,c2,c3); + r[3]=c1; + c1=0; + sqr_add_c(a,2,c2,c3,c1); + sqr_add_c2(a,3,1,c2,c3,c1); + r[4]=c2; + c2=0; + sqr_add_c2(a,3,2,c3,c1,c2); + r[5]=c3; + c3=0; + sqr_add_c(a,3,c1,c2,c3); + r[6]=c1; + r[7]=c2; + } +#endif +#else + +#ifdef SPLIT_BN_SQR_COMBA4 +/* hmm... is it faster just to do a multiply? */ +#undef bn_sqr_comba4 +void bn_sqr_comba4(r,a) +BN_ULONG *r,*a; + { + BN_ULONG t[8]; + bn_sqr_normal(r,a,4,t); + } +#endif + +#ifdef SPLIT_BN_SQR_COMBA8 +#undef bn_sqr_comba8 +void bn_sqr_comba8(r,a) +BN_ULONG *r,*a; + { + BN_ULONG t[16]; + bn_sqr_normal(r,a,8,t); + } +#endif + +#endif + +#endif /* OPT_BN_ASM */ + +#endif diff --git a/build/tools/acsign/bn_div.c b/build/tools/acsign/bn_div.c new file mode 100644 index 00000000..d2c12575 --- /dev/null +++ b/build/tools/acsign/bn_div.c @@ -0,0 +1,365 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/** + * @file bn_div.c + * @brief Division and modulus functions + */ +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_DIV +#define SPLIT_BN_MOD +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BN_DIV +/* The old slow way */ +#ifdef OLD_BN_DIVISION +int BN_div(dv, rem, m, d,ctx) +BIGNUM *dv; +BIGNUM *rem; +BIGNUM *m; +BIGNUM *d; +BN_CTX *ctx; + { + int i,nm,nd; + BIGNUM *D; + + bn_check_top(m); + bn_check_top(d); + if (BN_is_zero(d)) + { +#ifndef NO_ERR + BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); +#endif + return(0); + } + + if (BN_ucmp(m,d) < 0) + { + if (rem != NULL) + { if (BN_copy(rem,m) == NULL) return(0); } + if (dv != NULL) BN_zero(dv); + return(1); + } + + D= &(ctx->bn[ctx->tos]); + if (dv == NULL) dv= &(ctx->bn[ctx->tos+1]); + if (rem == NULL) rem= &(ctx->bn[ctx->tos+2]); + + nd=BN_num_bits(d); + nm=BN_num_bits(m); + if (BN_copy(D,d) == NULL) return(0); + if (BN_copy(rem,m) == NULL) return(0); + + /* The next 2 are needed so we can do a dv->d[0]|=1 later + * since BN_lshift1 will only work once there is a value + */ + BN_zero(dv); + bn_wexpand(dv,1); + dv->top=1; + + if (!BN_lshift(D,D,nm-nd)) return(0); + for (i=nm-nd; i>=0; i--) + { + if (!BN_lshift1(dv,dv)) return(0); + if (BN_ucmp(rem,D) >= 0) + { + dv->d[0]|=1; + if (!BN_usub(rem,rem,D)) return(0); + } +/* CAN IMPROVE (and have now :=) */ + if (!BN_rshift1(D,D)) return(0); + } + rem->neg=BN_is_zero(rem)?0:m->neg; + dv->neg=m->neg^d->neg; + return(1); + } + +#else +/** + * Performs Big number division + * + * @param dv [In] division + * @param rm [Out] remainder + * @param num [In] number + * @param divisor [In] divisor + * @param ctx [In] Temporary data storage + * + * @todo add more comments to this function + */ +int BN_div(BIGNUM *dv, BIGNUM *rm, BIGNUM *num, BIGNUM *divisor, BN_CTX *ctx) + { + int norm_shift,i,j,loop; + BIGNUM *tmp,wnum,*snum,*sdiv,*res; + BN_ULONG *resp,*wnump; + BN_ULONG d0,d1; + int num_n,div_n; + + bn_check_top(num); + bn_check_top(divisor); + + if (BN_is_zero(divisor)) + { +#ifndef NO_ERR + BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); +#endif + return(0); + } + + if (BN_ucmp(num,divisor) < 0) + { + if (rm != NULL) + { if (BN_copy(rm,num) == NULL) return(0); } + if (dv != NULL) (void)BN_zero(dv); + return(1); + } + + tmp= &(ctx->bn[ctx->tos]); + tmp->neg=0; + snum= &(ctx->bn[ctx->tos+1]); + sdiv= &(ctx->bn[ctx->tos+2]); + if (dv == NULL) + res= &(ctx->bn[ctx->tos+3]); + else res=dv; + + /* First we normalise the numbers */ + norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2); + if (!BN_lshift(sdiv,divisor,norm_shift)) return(0); + sdiv->neg=0; + norm_shift+=BN_BITS2; + if (!BN_lshift(snum,num,norm_shift)) return(0); + snum->neg=0; + div_n=sdiv->top; + num_n=snum->top; + loop=num_n-div_n; + + /* Lets setup a 'window' into snum + * This is the part that corresponds to the current + * 'area' being divided */ + BN_init(&wnum); + wnum.d= &(snum->d[loop]); + wnum.top= div_n; + wnum.max= snum->max+1; /* a bit of a lie */ + + /* Get the top 2 words of sdiv */ + /* i=sdiv->top; */ + d0=sdiv->d[div_n-1]; + d1=(div_n == 1)?0:sdiv->d[div_n-2]; + + /* pointer to the 'top' of snum */ + wnump= &(snum->d[num_n-1]); + + /* Setup to 'res' */ + if (!bn_wexpand(res,(loop+1))) goto err; + res->neg= (num->neg^divisor->neg); + res->top=loop; + resp= &(res->d[loop-1]); + + /* space for temp */ + if (!bn_wexpand(tmp,(div_n+1))) goto err; + + if (BN_ucmp(&wnum,sdiv) >= 0) + { + if (!BN_usub(&wnum,&wnum,sdiv)) goto err; + *resp=1; + res->d[res->top-1]=1; + } + else + res->top--; + resp--; + + for (i=0; i>BN_BITS2) || + (t2 <= ((BN_ULLONG)(rem< t1l) t3h++; + t3h=(t1h-t3h)&BN_MASK2; + + /*if ((t3>>BN_BITS2) || + (t2 <= ((t3<d,sdiv->d,div_n,q); + tmp->d[div_n]=l0; + for (j=div_n+1; j>0; j--) + if (tmp->d[j-1]) break; + tmp->top=j; + + j=wnum.top; +#ifdef BN_DEBUG + /* Sometimes this is 0 now (wnum.top is not). + * We need to look at this some time, I am quite + * sure it has no affect. + */ + bn_fix_top(&wnum); +#endif + (void)BN_sub(&wnum,&wnum,tmp); + + snum->top=snum->top+wnum.top-j; + + if (wnum.neg) + { + q--; + j=wnum.top; + (void)BN_add(&wnum,&wnum,sdiv); + snum->top+=wnum.top-j; + } + *(resp--)=q; + wnump--; + } + bn_fix_top(snum); + if (rm != NULL) + { + i=num->neg; /* just in case num == rm */ + if (BN_rshift(rm,snum,norm_shift) == 0) + return(0); + rm->neg=i; + } + return(1); +err: + return(0); + } +#endif +#endif + +#ifdef SPLIT_BN_MOD +/** + * Calculate the remainder where rem = m mod d + * + * @param rem [Out] Modulus result + * @param m [In] Base value + * @param d [In] Divisor + * @param ctx [In] BN_CTX for data space + * + * @pre variables are initialised and valid + * @post rem contained modulus + * + * @retval 1 success + * @retval 0 failure + * + * @note when BN_LIBRARY_SMALL define uses following algorithm + * otherwise calls through to BN_div + * + * @note m < d rem = m + * (length m = length of d) and (m > d) , rem = m - d + * alg otherwise + * let rem = m + * loop while rem > d + * let dv = shift left d, n bits to = length rem + * if dv > rem + * let dv = shift left d, n - 1 bits ( = length rem - 1) + * end if + * let rem = rem - dv; + * end loop + * + * @relates BN_div + */ +int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx) +{ +#ifdef BN_LIBRARY_SMALL + int nm,nd; + BIGNUM *dv, *dv2; + + /* if m < d , mod = m */ + if (BN_ucmp(m,d) < 0) + return((BN_copy(rem,m) == NULL)?0:1); + + dv= &(ctx->bn[ctx->tos]); + dv2 = &(ctx->bn[ctx->tos+1]); + + nm=BN_num_bits(m); + nd=BN_num_bits(d); + + /* if bits m = bits d and m >= d (from above) + * rem = m - d + */ + if(nm == nd) + { + BN_usub(rem, m, d); + goto end; + } + + if (BN_copy(rem, m) == NULL) + { + return 0; + } + + /* while the rem > d */ + while(BN_ucmp(rem,d) > 0) + { + nm=BN_num_bits(rem); + if(!BN_lshift(dv2,d,nm-nd)) + { + return(0); + } + + if(BN_ucmp(dv2, rem) >0) + { + if(!BN_lshift(dv2,d,nm-nd-1)) + { + return(0); + } + } + + BN_usub(rem,rem,dv2); + } +end: + return(1); +#else + return(BN_div(NULL,rem,m,d,ctx)); +#endif +} +#endif + +#endif diff --git a/build/tools/acsign/bn_ex_str.c b/build/tools/acsign/bn_ex_str.c new file mode 100644 index 00000000..dc40f5c0 --- /dev/null +++ b/build/tools/acsign/bn_ex_str.c @@ -0,0 +1,437 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +#include "bn_lcl.h" + +const static unsigned char p2 []={0,8,1,1,1,1,1,0,0,0}; +const static unsigned char p4 []={0,8,1,1,1,4,1,0,0,0}; +const static unsigned char p16[]={0,8,1,1,1,16,1,0,0,0}; + +/* The following defines allow for redefinition of the window size + * of the exponent string at compile time, this affects the size + * of temporary data required in montgomery operations. + * Larger window sizes have more memory and are slightly faster + */ +#ifndef MAX_WIN_SIZE +#define MAX_WIN_SIZE 5 +#endif + +#if (MAX_WIN_SIZE == 6) +#define MAX_NUM_SIZE 16 +#endif + +#if (MAX_WIN_SIZE == 5) +#define MAX_NUM_SIZE 16 +#endif + +#if (MAX_WIN_SIZE == 4) +#define MAX_NUM_SIZE 8 +#endif + +#if (MAX_WIN_SIZE == 3) +#define MAX_NUM_SIZE 4 +#endif + +#ifndef MAX_NUM_SIZE +#define MAX_NUM_SIZE 16 +#endif + +/* This table is used to calculate how far to shift a window to find + * the next 1 bit within the window, for a given window size + * Comment next to each value represents window size, value of the window + * and the number of shifts to find the next 1 bit. + * where the value of the window is 0, the shift is the size of the window + * and thus may not necessary yield a 1 bit, but refreshes the window + */ +const static unsigned char shift[64]= + {6, /* window 6, bits 000000, shift 6 */ + 0, /* 6, bits 000001, shift 0 */ + 1, /* 6, bits 000010, shift 1 */ + 0, /* 6, bits 000011, shift 0 */ + 2, /* 6, bits 000100, shift 2 */ + 0, /* 6, bits 000101, shift 0 */ + 1, /* 6, bits 000110, shift 1 */ + 0, /* 6, bits 000111, shift 0 */ + 3, /* 6, bits 001000, shift 3 */ + 0, /* 6, bits 001001, shift 0 */ + 1, /* 6, bits 001010, shift 1 */ + 0, /* 6, bits 001011, shift 0 */ + 2, /* 6, bits 001100, shift 2 */ + 0, /* 6, bits 001101, shift 0 */ + 1, /* 6, bits 001110, shift 1 */ + 0, /* 6, bits 001111, shift 0 */ + 4, /* 6, bits 010000, shift 4 */ + 0, /* 6, bits 010001, shift 0 */ + 1, /* 6, bits 010010, shift 1 */ + 0, /* 6, bits 010011, shift 0 */ + 2, /* 6, bits 010100, shift 2 */ + 0, /* 6, bits 010101, shift 0 */ + 1, /* 6, bits 010110, shift 1 */ + 0, /* 6, bits 010111, shift 0 */ + 3, /* 6, bits 011000, shift 3 */ + 0, /* 6, bits 011001, shift 0 */ + 1, /* 6, bits 011010, shift 1 */ + 0, /* 6, bits 011011, shift 0 */ + 2, /* 6, bits 011100, shift 2 */ + 0, /* 6, bits 011101, shift 0 */ + 1, /* 6, bits 011110, shift 1 */ + 0, /* 6, bits 011111, shift 0 */ + 5, /* 6, bits 100000, shift 5 */ + /* also window 5, bits 00000, shift 5 */ + 0, /* 5 ,bits 00001, shift 0 */ + 1, /* 5 ,bits 00010, shift 1 */ + 0, /* 5 ,bits 00011, shift 0 */ + 2, /* 5 ,bits 00100, shift 2 */ + 0, /* 5 ,bits 00101, shift 0 */ + 1, /* 5 ,bits 00110, shift 1 */ + 0, /* 5 ,bits 00111, shift 0 */ + 3, /* 5 ,bits 01000, shift 3 */ + 0, /* 5 ,bits 01001, shift 0 */ + 1, /* 5 ,bits 01010, shift 1 */ + 0, /* 5 ,bits 01011, shift 0 */ + 2, /* 5 ,bits 01100, shift 2 */ + 0, /* 5 ,bits 01101, shift 0 */ + 1, /* 5 ,bits 01110, shift 1 */ + 0, /* 5 ,bits 01111, shift 0 */ + 4, /* 5 ,bits 10000, shift 1 */ + /* also window 4, bits 0000, shift 4 */ + 0, /* 4 ,bits 0001, shift 0 */ + 1, /* 4 ,bits 0010, shift 1 */ + 0, /* 4 ,bits 0011, shift 0 */ + 2, /* 4 ,bits 0100, shift 2 */ + 0, /* 4 ,bits 0101, shift 0 */ + 1, /* 4 ,bits 0110, shift 1 */ + 0, /* 4 ,bits 0111, shift 0 */ + 3, /* 4 ,bits 1000, shift 3 */ + /* also window 3, bits 000, shift 3 */ + 0, /* 3 ,bits 001, shift 0 */ + 1, /* 3 ,bits 010, shift 1 */ + 0, /* 3 ,bits 011, shift 0 */ + 2, /* 3 ,bits 100, shift 2 */ + 0, /* 3 ,bits 101, shift 0 */ + 1, /* 3 ,bits 110, shift 1 */ + 0 /* 3 ,bits 111, shift 0 */ + }; + +/* This table defines the starting point in the shift table for + * a particular window size + */ +const static unsigned char *shift_val[7]= + { + &(shift[63]), /* window 0 - unused */ + &(shift[62]), /* window 1 */ + &(shift[60]), /* window 2 - unused */ + &(shift[56]), /* window 3 */ + &(shift[48]), /* window 4 */ + &(shift[32]), /* window 5 */ + &(shift[ 0]), /* window 6 - unused */ + }; + +/** + * Calculates a Montgomery exponent string. + * + * For a supplied exponent p, generate an exponent string strp, which + * defines in pairs the number of multiplies and square operations + * required by a particular bit pattern, commonly used exponents + * 3, 11 and F4 have predefined constant string values, the rest + * are calculated into a cast unsigned char * array via the data + * pointer of a BIGNUM taken from the BN_CTX stack of BIGNUMs + * + * @param p [In] Exponent + * @param strp [Out] Exponent string result + * @param flags [In] Unused + * @param ctx [In] Temporary data storage + * + * @pre p, and ctx are initialised and valid + * @post strp points to required exponent string + * + * @notes String length value in strp[2] is invalid for strings + * greater than length 255 + * string terminates with pattern, 0, 0 this should be + * used in accurately determining the length of a returned + * string strp. + * + * @note strings with value sqr = 255, mul = 0, sqr value should be + * treated as value 256, and added to the next sqr value, this + * is used by exponent strings where more then 256 contiguous + * zero bits are in the exponent bit representation. + * + * @note code contains conditional compilation of code dependent on + * the OS int/long sizes + */ +int BN_gen_exp_bits(p,strp,flags,ctx) +BIGNUM *p; +unsigned char **strp; +int flags; +BN_CTX *ctx; + { + int bits,i,j,window,num; + unsigned char *str=NULL; + BIGNUM *tmp; + + flags=flags; + bits=p->top*BN_BITS2; + tmp=&(ctx->bn[ctx->tos]); + if (p->top == 0) + return(0); + +#if (BN_BITS2 > 17) + if (p->top == 1) +#else + if (bits <= 32) +#endif + { +#if (BN_BITS2 > 17) + if ((p->top == 1) && (p->d[0] == 0x10001)) + str=(unsigned char *)p16; +#endif +#if (16 >= BN_BITS2) && (BN_BITS > 8) + if ( (p->top == 2) && + (p->d[0] == 0x0001) && + (p->d[1] == 0x0001)) + str=(unsigned char *)p16; +#endif +#if (8 >= BN_BITS) + if ( (p->top == 3) && + (p->d[0] == 0x01) && + (p->d[1] == 0x00) && + (p->d[2] == 0x01)) + str=(unsigned char *)p16; +#endif + else if ((p->d[0] == 0x11) && (p->top == 1)) + str=(unsigned char *)p4; + else if ((p->d[0] == 0x3) && (p->top == 1)) + str=(unsigned char *)p2; + window=1; + num=1; + i=BN_BITS2; + } + else if (bits >= 256) + { + window=MAX_WIN_SIZE; /* max size of window */ + num=MAX_NUM_SIZE; + i=(BN_BITS2+(MAX_WIN_SIZE -1))/MAX_WIN_SIZE; + } + else if (bits >= 128) + { + window=4; + num=8; + i=(BN_BITS2+3)/4; + } + else /* 128 to 33 */ + { + window=3; + num=4; + i=(BN_BITS2+2)/3; + } + + /* Number of tmp words */ + j=(p->top*i*2+BN_BYTES-1+4)/BN_BYTES; + + if (str == NULL) + { + if (!bn_wexpand(tmp,j)) + return(0); + str=(unsigned char *)tmp->d; + i=BN_gen_exp_string(&(str[4]),p,window); + i+=2; + str[0]=(unsigned char)((i>>8)&0xff); + str[1]=(unsigned char)((i )&0xff); + str[2]=(unsigned char)window; + str[3]=(unsigned char)num; + } + else + { + i=8; + } + *strp=str; + return(i+2); + } + + +/** + * Generates the Montgomery exponent string. + * + * This function is used to generate an 'exponent string' + * which is an array of bytes that encode how to perform the steps in + * the a^p%m operation. + * + * @param str [Out] Containing the generated string + * @param p [In] Exponent to generate the string for + * @param bits [In] Size of the window for shifting the values of the BIGNUM + * + * @pre p is initialised and value BIGNUM, bits is not 0 + * @post str points to generated exponent string + * + * @note str is cast assigned the data of a BIGNUM allocated and + * expanded from the BN_CTX of the calling function BN_gen_exp_bits + * it does not need to be de-allocated + * + * @note string consisted of unsigned char pairs and 4 byte init + * pairs are sqr count and multiply, where strings are greater + * than 256 bit, length in position str[2] is invalid + * + * @note strings with value sqr = 255, mul = 0, sqr value should be + * treated as value 256, and added to the next sqr value, this + * is used by exponent strings where more then 256 contiguous + * zero bits are in the exponent bit representation. + * + */ +int BN_gen_exp_string(str,p,bits) +unsigned char *str; +BIGNUM *p; +int bits; + { + unsigned char *sp; + unsigned int mask; + const unsigned char *shift; + BN_ULONG w,wh,wl,*d; + unsigned int i,mul,sqr,t,s,ss; + int top; + + if (bits > 6) bits=6; + shift= shift_val[bits]; + + /* This is the mask for the bits we wish to operate on */ + mask=(1<top*BN_BITS2+bits-1)/bits)*2+2]); + *sp-- = 0; + *sp-- = 0; + top=p->top; /* Total words we will shift in */ + d=p->d; + w=wl= *d++; + if (top <= 1) + wh=0; + else + wh= *d++; + sqr=0; + i=0; + + for (;;) + { + /* t will contain how far we need to shift to set a 1 + * in the bottom bit. */ + for (;;) + { + t=w&mask; /* retrieve our window */ + s=shift[t]; /* get the shift value for the window */ + if (s == 0) break; /* no shift write out the vals */ + sqr+=s; /* add the shifted zero count to sqr */ + ss+=s; /* ss is total shift for wl */ + if (ss >= BN_BITS2) /* we have shifted > word len */ + { + if (top <= 1) break; /* no more to do */ + top--; /* dec the count */ + + wl=wh; /* copy the next word */ + /* load the word after or 0 if no more */ + wh=(top <= 1)?0:(*d++); + /* adjust our shift by len of word */ + ss-=BN_BITS2; + } + /* reset our window word w */ + if (ss == 0) + w=wl; + else + w=(wl>>ss)|(wh<<(BN_BITS2-ss)); + } + + /* At this point we have the 0th bit set */ + mul=t; + if (t == 0) break; /* we have reached the end of p */ + /* write out sqr/mul pair */ + *sp-- = (unsigned char)(sqr & 0xff); + *sp-- = (unsigned char)(mul & 0xff); + if(sqr >= 256) /* check whether sqr exceeds max uchar */ + { + /* output the expanded list of to allow for this + * and numbers will require to be added together + * at interpret time + */ + while(sqr >= 256) + { + *sp-- = 255; + *sp-- = 0; /* mul is never zero normally */ + sqr-= 256; + } + } + sqr=bits; /* set sqr to be the window size */ + + ss+=bits; /* ss is total shift for wl */ + if (ss >= BN_BITS2) /* adjust window words w,wl, wh again */ + { + if (top <= 1) break; + top--; + + wl=wh; + wh=(top <= 1)?0:(*(d++)); + ss-=BN_BITS2; + } + + if (ss == 0) + w=wl; + else + w=(wl>>ss)|(wh<<(BN_BITS2-ss)); + } + sp++; + i=2; + /* reverse the string from the top of the exponent string + * and copy to the bottom, allocated exponent string is 2 * max length + * expected for exponent string + */ + while (sp[0] != 0 || sp[1] != 0) + { + str[0]=sp[0]; + str[1]=sp[1]; + str+=2; + sp+=2; + i+=2; + } + str[0]=0; + str[1]=0; + + return(i); + } + +#ifdef MAIN +main() + { + BIGNUM p; + unsigned char buf[512],*pp; + int i; + + BN_init(&p); + BN_rand(&p,33,1,0); +#ifndef NO_FP_API + BN_print_fp(stdout,&p); fprintf(stdout,"\n"); +#endif + + BN_rand(&p,512,1,1); +#ifndef NO_FP_API + BN_print_fp(stdout,&p); fprintf(stdout,"\n"); +#endif + for (i=0; i<10000; i++) + BN_gen_exp_string(buf,&p,5); + +#if 0 + BN_gen_exp_string(buf,&p,3); + + pp=buf; + for (;;) + { + printf("mul %d sqr %d\n",pp[0],pp[1]); + if (pp[1] == 0) break; + pp+=2; + } +#endif + } +#endif diff --git a/build/tools/acsign/bn_exp.c b/build/tools/acsign/bn_exp.c new file mode 100644 index 00000000..08634e7e --- /dev/null +++ b/build/tools/acsign/bn_exp.c @@ -0,0 +1,156 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_MOD_EXP_ORIG +#define SPLIT_BN_MOD_EXP +#endif /* NO_SPLIT */ + +#define TABLE_SIZE 16 + +#ifdef SPLIT_BN_MOD_EXP_ORIG +#if 0 +/* this one works - simple but works */ +int BN_mod_exp_orig(r,a,p,m,ctx) +BIGNUM *r,*a,*p,*m; +BN_CTX *ctx; + { + int i,bits,ret=0; + BIGNUM *v,*tmp; + + v= &(ctx->bn[ctx->tos++]); + tmp= &(ctx->bn[ctx->tos++]); + + if (BN_copy(v,a) == NULL) goto err; + bits=BN_num_bits(p); + + if (BN_is_odd(p)) + { if (BN_copy(r,a) == NULL) goto err; } + else { if (!BN_one(r)) goto err; } + + for (i=1; itos-=2; + return(ret); + } + +#endif + +/* this one works - simple but works */ +int BN_exp(r,a,p,ctx) +BIGNUM *r,*a,*p; +BN_CTX *ctx; + { + int i,bits,ret=0,tos; + BIGNUM *v,*rr; + + bn_check_top(a); + bn_check_top(p); + + tos=ctx->tos; + v= &(ctx->bn[ctx->tos++]); + if ((r == a) || (r == p)) + rr= &(ctx->bn[ctx->tos++]); + else + rr=r; + + if (BN_copy(v,a) == NULL) goto err; + bits=BN_num_bits(p); + + if (BN_is_odd(p)) + { if (BN_copy(rr,a) == NULL) goto err; } + else { if (!BN_one(rr)) goto err; } + + for (i=1; itos=tos; + if (r != rr) (void)BN_copy(r,rr); + return(ret); + } +#endif + +#ifdef SPLIT_BN_MOD_EXP +/** + * Perform mod exp on BIGNUM + * @param r Pointer to return value BIGNUM + * @param a Pointer to data value BIGNUM + * @param p Pointer to Public exponent BIGNUM + * @param m Pointer to modulus BIGNUM + * @param ctx Pointer to BN_CTX + * @return 0 success + * @pre BIGNUMs a, p, m and BN_CTX ctx exist and are valid + * @post BIGNUM r points to evaluated mod_exp + * @note BN_mod_exp_mont is only available if library compiled + * with define BN_MONT_MUL, and will only be used to compute + * mod_exp operation where the modulus m is odd. + * BN_mod_exp_recp is only available if library is compiled + * with define RECP_MUL_MOD. + * BN_mod_exp_simple is the default method, not available if + * library is compiled with define RECP_MUL_MOD. + * if BN_mod_exp_mont is available, which ever of BN_mod_exp_simple + * or BN_mod_exp_recp is available will only be used for even + * modulus m values. + * @relates BN_mod_exp_mont + * @relates BN_mod_exp_recp + * @relates BN_mod_exp_simple + */ +int BN_mod_exp(r,a,p,m,ctx) +BIGNUM *r; +BIGNUM *a; +BIGNUM *p; +BIGNUM *m; +BN_CTX *ctx; + { + int ret; + + bn_check_top(a); + bn_check_top(p); + bn_check_top(m); + +#ifdef MONT_MUL_MOD + + if (BN_is_odd(m)) + { ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); } + else +#endif +#ifdef RECP_MUL_MOD + { ret=BN_mod_exp_recp(r,a,p,m,ctx); } +#else + { ret=BN_mod_exp_simple(r,a,p,m,ctx); } +#endif + + return(ret); + } +#endif + +#endif diff --git a/build/tools/acsign/bn_fm_w.c b/build/tools/acsign/bn_fm_w.c new file mode 100644 index 00000000..999ed55f --- /dev/null +++ b/build/tools/acsign/bn_fm_w.c @@ -0,0 +1,63 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +#include "bn_lcl.h" + +/* rp has w words, the top w words are 0 */ +void bn_from_montgomery_words(ret,a,np,w,n0) +BN_ULONG *ret; +BN_ULONG *a; +BN_ULONG *np; +int w; +BN_ULONG n0; + { + BN_ULONG v0,v1,*ap,*wap; + int i; + + v1=0; + + ap=a; + wap= &(a[w]); + /* Consider putting this loop in ASM */ + for (i=0; i0; i--) + if (ap[i] != np[i]) break; + } + v1=(ap[i] >= np[i]); + } + if (v1) + (void)bn_sub_words(ret,ap,np,w); + else + { +#if 0 /* Alpha does not like Memcpy */ + Memcpy(ret,ap,sizeof(BN_ULONG)*w); +#else + for (i=0; ibn[ctx->tos]); + b= &(ctx->bn[ctx->tos+1]); + + if (BN_copy(a,in_a) == NULL) goto err; + if (BN_copy(b,in_b) == NULL) goto err; + + if (BN_cmp(a,b) < 0) { t=a; a=b; b=t; } + t=bn_euclid(a,b); + if (t == NULL) goto err; + + if (BN_copy(r,t) == NULL) goto err; + ret=1; +err: + return(ret); + } + +BIGNUM *bn_euclid(a,b) +BIGNUM *a,*b; + { + BIGNUM *t; + int shifts=0; + + bn_check_top(a); + bn_check_top(b); + + for (;;) + { + if (BN_is_zero(b)) + break; + + if (BN_is_odd(a)) + { + if (BN_is_odd(b)) + { + if (!BN_sub(a,a,b)) goto err; + if (!BN_rshift1(a,a)) goto err; + if (BN_cmp(a,b) < 0) + { t=a; a=b; b=t; } + } + else /* a odd - b even */ + { + if (!BN_rshift1(b,b)) goto err; + if (BN_cmp(a,b) < 0) + { t=a; a=b; b=t; } + } + } + else /* a is even */ + { + if (BN_is_odd(b)) + { + if (!BN_rshift1(a,a)) goto err; + if (BN_cmp(a,b) < 0) + { t=a; a=b; b=t; } + } + else /* a even - b even */ + { + if (!BN_rshift1(a,a)) goto err; + if (!BN_rshift1(b,b)) goto err; + shifts++; + } + } + } + if (shifts) + { + if (!BN_lshift(a,a,shifts)) goto err; + } + return(a); +err: + return(NULL); + } +#endif + +#ifdef SPLIT_BN_MOD_INVERSE +/* solves ax == 1 (mod n) */ +BIGNUM *BN_mod_inverse(in, a, n, ctx) +BIGNUM *in; +BIGNUM *a; +BIGNUM *n; +BN_CTX *ctx; + { + BIGNUM *A,*B,*X,*Y,*M,*D,*R; + BIGNUM *T,*ret=NULL; + int sign; + + bn_check_top(a); + bn_check_top(n); + + A= &(ctx->bn[ctx->tos]); + B= &(ctx->bn[ctx->tos+1]); + X= &(ctx->bn[ctx->tos+2]); + D= &(ctx->bn[ctx->tos+3]); + M= &(ctx->bn[ctx->tos+4]); + Y= &(ctx->bn[ctx->tos+5]); + ctx->tos+=6; + if (in == NULL) + R=BN_new(); + else + R=in; + if (R == NULL) goto err; + + (void)BN_zero(X); + (void)BN_one(Y); + if (BN_copy(A,a) == NULL) goto err; + if (BN_copy(B,n) == NULL) goto err; + sign=1; + + while (!BN_is_zero(B)) + { + if (!BN_div(D,M,A,B,ctx)) goto err; + T=A; + A=B; + B=M; + /* T has a struct, M does not */ + + if (!BN_mul(T,D,X,ctx)) goto err; + if (!BN_add(T,T,Y)) goto err; + M=Y; + Y=X; + X=T; + sign= -sign; + } + if (sign < 0) + { + if (!BN_sub(Y,n,Y)) goto err; + } + + if (BN_is_one(A)) + { if (!BN_mod(R,Y,n,ctx)) goto err; } + else + { +#ifndef NO_ERR + BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE); +#endif + goto err; + } + ret=R; +err: + if ((ret == NULL) && (in == NULL)) BN_free(R); + ctx->tos-=6; + return(ret); + } +#endif + +#ifdef SPLIT_BN_MOD_INVERSE_WORD +/* solves 1 == (ret*(1<l + * @param l [In] a word (size of word depends on machine) + * @returns number of bits in parameter l + */ +#ifdef SPLIT_BN_NUM_BITS_WORD +int BN_num_bits_word(l) +BN_ILONG l; + { + int i; + + /* + * This table represents the number of bits required to + * represent a "number", where "number" is indexed from + * 0 into the table. So: + * number 0 = # bits req'd to represent 0 = bits[0] = 0 + * number 1 = # bits req'd to represent 1 = bits[1] = 1 + * number 2 = # bits req'd to represent 2 = bits[2] = 2 + * number 3 = # bits req'd to represent 3 = bits[3] = 2 + * number 4 = # bits req'd to represent 4 = bits[4] = 3 + * etc. + * + * The small code size table exists to save some space, + * but requires (at most) an extra shift, an extra AND, + * and an extra add. + */ +#ifdef SMALL_CODE_SIZE + const static char bits[16]={ + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4 + }; +#else + const static char bits[256]={ + 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4, + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, + }; +#endif + +#if defined(SIXTY_FOUR_BIT_LONG) + if (l & 0xffffffff00000000L) + { + if (l & 0xffff000000000000L) + { + if (l & 0xff00000000000000L) + i=56; + else i=48; + } + else + { + if (l & 0x0000ff0000000000L) + i=40; + else i=32; + } + } + else +#else +#ifdef SIXTY_FOUR_BIT + if (l & 0xffffffff00000000LL) + { + if (l & 0xffff000000000000LL) + { + if (l & 0xff00000000000000LL) + i=56; + else i=48; + } + else + { + if (l & 0x0000ff0000000000LL) + i=40; + else i=32; + } + } + else +#endif +#endif + { +#if defined(THIRTY_BIT) || defined(THIRTY_ONE_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) + if (l & 0xffff0000L) + { + if (l & 0xff000000L) + i=24; + else i=16; + } + else +#endif + { + if (l & 0xff00L) + i=8; + else + i=0; + } + } +#ifndef SMALL_CODE_SIZE + return(i+bits[l>>i]); +#else + l>>=i; + if (l & 0xf0) + return(bits[l>>4]+i+4); + else + return(bits[l]+i); +#endif + } +#endif + +#ifdef SPLIT_BN_NUM_BITS +int BN_num_bits(a) +BIGNUM *a; + { + BN_ULONG l; + int i; + + bn_check_top(a); + + if (a->top == 0) return(0); + l=a->d[a->top-1]; + i=(a->top-1)*BN_BITS2; +#ifdef BN_DEBUG + if (l == 0) + { +#if !defined(NO_FP_API) && !defined(WIN16) + fprintf(stderr,"BAD TOP VALUE\n"); +#endif + abort(); /* BN_DEBUG */ + /* TODO: need to understand what sort of error can + * be reported for this error + */ + return(0); + } +#endif + return(i+BN_num_bits_word(l)); + } +#endif + +/** + * Clears and free a BIGNUM + * + * @param a [In] BIGNUM to clear then free + */ +#ifdef SPLIT_BN_CLEAR_FREE +void BN_clear_free(BIGNUM *a) +{ + if (a == NULL) + { + return; + } + + BN_clear(a); + BN_free(a); +} +#endif + +#ifdef SPLIT_BN_FREE +/** + * Frees a BIGNUM + * + * @param a [In] BIGNUM to free + */ +void BN_free(a) +BIGNUM *a; + { + if (a == NULL) return; + if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA))) + Free(a->d); + a->flags|=BN_FLG_FREE; /* REMOVE? */ + if (a->flags & BN_FLG_MALLOCED) + Free(a); + } +#endif + +#ifdef SPLIT_BN_INIT + +#ifdef SMALL_CODE_SIZE +/** + * Zero expands a bignum + * + * @param a [In] BIGNUM to expand + * @param n [In] number of bits to expand to + * + * @pre a is a valid BIGNUM. + */ +void bn_zexpand(a,n) +BIGNUM *a; +int n; + { + if ((a)->top < n) + { + int i; + bn_wexpand((a),n); + if (a->d!=NULL) + { + for (i=(a)->top; id[i]=0; + } + } + } + +/** + * Fixes the top value in the BIGNUM to be the count of BN_ULONGs with data. + * + * @param a [In] BIGNUM to free + * + * @pre a is a valid BIGNUM. + */ +void bn_fix_top(a) +BIGNUM *a; + { + BN_ULONG *ftl; + if ((a)->top > 0) + { + for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) + if (*(ftl--)) break; + } + } +#endif + +/** + * Initializes a BIGNUM + * + * @param a [In] BIGNUM reference + * + * @pre a is a valid BIGNUM. + */ +void BN_init(a) +BIGNUM *a; + { + (void)Memset(a,0,sizeof(BIGNUM)); + } +#endif + +#ifdef SPLIT_BN_NEW +/** + * Allocates a BIGNUM + * + * @return pointer to allocated BIGNUM + */ +BIGNUM *BN_new() + { + BIGNUM *ret; + + if ((ret=(BIGNUM *)Malloc(sizeof(BIGNUM))) == NULL) + { +#ifndef NO_ERR + BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE); +#endif + return(NULL); + } + ret->flags=BN_FLG_MALLOCED; + ret->top=0; + ret->neg=0; + ret->max=0; + ret->d=NULL; + return(ret); + } +#endif + +#ifdef SPLIT_BN_CTX_NEW +/** + * Allocates a BIGNUM context + * + * @return pointer to allocated BIGNUM context + */ +BN_CTX *BN_CTX_new() + { + BN_CTX *ret; + + ret=(BN_CTX *)Malloc(sizeof(BN_CTX)); + if (ret == NULL) + { +#ifndef NO_ERR + BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE); +#endif + return(NULL); + } + + BN_CTX_init(ret); + ret->flags=BN_FLG_MALLOCED; + return(ret); + } +#endif + +#ifdef SPLIT_CTX_INIT +/** + * Initializes a BIGNUM context + * + * @param a [In] BIGNUM context reference + * + * @pre a is a valid BIGNUM context. + */ +void BN_CTX_init(ctx) +BN_CTX *ctx; + { + (void)Memset(ctx,0,sizeof(BN_CTX)); + ctx->tos=0; + ctx->flags=0; + } +#endif + +#ifdef SPLIT_BN_CTX_FREE +/** + * Frees a BIGNUM context + * + * @param a [In] BIGNUM context reference + * + * @pre a is a valid BIGNUM context. + */ +void BN_CTX_free(c) +BN_CTX *c; + { + int i; + + for (i=0; ibn[i])); + if (c->flags & BN_FLG_MALLOCED) + Free(c); + } +#endif + +#ifdef SPLIT_BN_EXPAND2 +BIGNUM *bn_expand2(b, words) +BIGNUM *b; +int words; + { + BN_ULONG *A,*B,*a; + + R_DIAG_CHECK_STACK; + + bn_check_top(b); + + if (words > b->max) + { + bn_check_top(b); + if (BN_get_flags(b,BN_FLG_STATIC_DATA)) + { +#ifndef NO_ERR + BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); +#endif + return(NULL); + } + a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1)); + if (A == NULL) + { +#ifndef NO_ERR + BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); +#endif + return(NULL); + } + /* during development this is a nice way of making sure + * that we are not relying on the top byte being 0 or + * other such things + */ +#ifdef BN_DEBUG + (void)Memset(A,0x5c,sizeof(BN_ULONG)*(words+1)); +#endif + + B=b->d; + if (B != NULL) + { +#ifndef SMALL_CODE_SIZE + int i; + + /* for (i=b->top&(~7); i>0; i-=8) */ + /* The above line can induce a SunC compiler bug */ + for (i=(b->top>>3); i>0; i--) + { + BN_ULONG T0,T1,T2,T3; + + T0=B[0]; + T1=B[1]; + T2=B[2]; + T3=B[3]; + A[0]=T0; + A[1]=T1; + A[2]=T2; + A[3]=T3; + T0=B[4]; + T1=B[5]; + T2=B[6]; + T3=B[7]; + A[4]=T0; + A[5]=T1; + A[6]=T2; + A[7]=T3; + A+=8; + B+=8; + } + switch (b->top&7) + { + case 7: + A[6]=B[6]; + case 6: + A[5]=B[5]; + case 5: + A[4]=B[4]; + case 4: + A[3]=B[3]; + case 3: + A[2]=B[2]; + case 2: + A[1]=B[1]; + case 1: + A[0]=B[0]; + case 0: + /* I need the 'case 0' entry for utrix cc. + * If the optimiser is turned on, it does the + * switch table by doing + * a=top&7 + * a--; + * goto jump_table[a]; + * If top is 0, this makes us jump to 0xffffffc + * which is rather bad. + * eric 23-Apr-1998 + */ + ; + } +#if 0 /* Not needed */ + B= &(b->d[b->top]); + j=b->max-8; + for (i=b->top; itop); +#endif + Free(b->d); + } + + b->d=a; + b->max=words; + } + return(b); + } +#endif + +#ifdef SPLIT_BN_DUP +/** + * Duplicates a BIGNUM + * + * @param a [In] BIGNUM reference + * + * @returns pointer to duplicate BIGNUM of a + */ +BIGNUM *BN_dup(a) +BIGNUM *a; + { + BIGNUM *r; + BIGNUM *ret; + + bn_check_top(a); + + r=BN_new(); + if (r == NULL) return(NULL); + ret = (BIGNUM *)BN_copy(r,a); + if (ret == NULL) + { + BN_free(r); + } + return(ret); + } +#endif + +#ifdef SPLIT_BN_COPY +/** + * Copies a BIGNUM to an existing BIGNUM + * + * @param a [In] To BIGNUM reference + * @param b [Out] From BIGNUM reference + * + * @pre Both a and b are valid BIGNUMs + * + * @returns pointer to duplicate BIGNUM of a + */ +BIGNUM *BN_copy(a, b) +BIGNUM *a; +BIGNUM *b; + { +#ifndef SMALL_CODE_SIZE + int i; + BN_ULONG *A,*B; +#endif + + bn_check_top(b); + + if (a == b) return(a); + if (bn_wexpand(a,b->top) == NULL) return(NULL); +#ifndef SMALL_CODE_SIZE + A=a->d; + B=b->d; + +/* for (i=b->top&~0x07; i>0; i-=8) */ +/* The above version of this loop has been removed. It appeared + to generate a compiler bug in SunC 4.x and 5.x. I do not believe + that the code was to blame. Compiling with -fast was the problem + since this would loop unroll the loop below another 3 times. + The compiler would generate generate + andcc %o0,-8,%o1 # load ~0x07 + ld [%i2],%o3 # load *B + ble .L77000125 # exit loop unless 8 or more + ld [%i1],%o2 # load *A + sub %o1,-7,%o0 # + sdivcc %o0,8,%o0 # when do we clear %y? + bvs,a .L900001510 + sethi %hi(0x80000000),%o0 +.L900001510: + cmp %o0,3 + bl .L77000114 # one loop + ld [%o2],%o0 + # three loop code + + The loop would then be unrolled 3 times. The problem I believe + I was seeing was that the sdivcc operates is %y:%o0 / 8. + %y is not being cleared, and so occasionally this would + cause problems. The replacement code sequence stops + the compiler generating the sdiv instruction. + */ + for (i=(b->top>>3); i>0; i--) + { + BN_ULONG T0,T1,T2,T3; + T0=B[0]; + T1=B[1]; + T2=B[2]; + T3=B[3]; + A[0]=T0; + A[1]=T1; + A[2]=T2; + A[3]=T3; + T0=B[4]; + T1=B[5]; + T2=B[6]; + T3=B[7]; + A[4]=T0; + A[5]=T1; + A[6]=T2; + A[7]=T3; + A+=8; + B+=8; + } + switch (b->top&0x07) + { + case 7: + A[6]=B[6]; + case 6: + A[5]=B[5]; + case 5: + A[4]=B[4]; + case 4: + A[3]=B[3]; + case 3: + A[2]=B[2]; + case 2: + A[1]=B[1]; + case 1: + A[0]=B[0]; + case 0: + /* I need the 'case 0' entry for utrix cc. + * If the optimiser is turned on, it does the + * switch table by doing + * a=top&7 + * a--; + * goto jump_table[a]; + * If top is 0, this makes us jump to 0xffffffc which is + * rather bad. + * eric 23-Apr-1998 + */ + ; + } +#else + (void)Memcpy(a->d,b->d,sizeof(b->d[0])*b->top); +#endif + +/* (void)Memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/ + a->top=b->top; + if ((a->top == 0) && (a->d != NULL)) + a->d[0]=0; + a->neg=b->neg; + return(a); + } +#endif + +#ifdef SPLIT_BN_CLEAR +/** + * Clears a BIGNUM + * + * @param a [In] BIGNUM to clear + * + * @pre a is valid + */ +void BN_clear(a) +BIGNUM *a; + { + if (a->d != NULL) + (void)Memset(a->d,0,a->max*sizeof(a->d[0])); + a->top=0; + a->neg=0; + } +#endif + +#ifdef SPLIT_BN_GET_WORD +BN_ULONG BN_get_word(a) +BIGNUM *a; + { + int i,n; + BN_ULONG ret=0; + + n=BN_num_bytes(a); + if (n > ((int) sizeof(BN_ULONG))) + return(BN_MASK2); + for (i=a->top-1; i>=0; i--) + { +#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ + ret<<=BN_BITS4; /* stops the compiler complaining */ + ret<<=BN_BITS4; +#else + ret=0; +#endif + ret|=a->d[i]; + } + return(ret); + } +#endif + +#ifdef SPLIT_BN_SET_WORD +/** + * Set the BIGNUM to the supplied BN_ULONG value. + * + * @param a [In/Out] BIGNUM to be updated + * @param w [In] Value to be set in a + * + * @notes Function will expand a to be an + * array of 8 BN_ULONGs in size. + * @todo Review behaviour of expansion without checking + * of size first. + */ +int BN_set_word(a,w) +BIGNUM *a; +BN_ULONG w; + { + int i,n; + + if (bn_expand(a,(int)(sizeof(BN_ULONG)*8)) == NULL) return(0); + +#ifdef BN_BYTES + /* This is used when a BN_ULONG is greater in size + * than the BN_BYTES of the array, eg BN_ULONG 64 bits + * and actual a->d array of 32 bits. + */ + n=sizeof(BN_ULONG)/BN_BYTES; +#else + n=1; +#endif + a->neg=0; + a->top=0; + a->d[0]=(BN_ULONG)w&BN_MASK2; + if (a->d[0] != 0) a->top=1; + for (i=1; i>=BN_BITS2 so compilers don't complain + * on builds where sizeof(long) == BN_TYPES */ +#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ + w>>=BN_BITS4; + w>>=BN_BITS4; +#else + w=0; +#endif + a->d[i]=(BN_ULONG)w&BN_MASK2; + if (a->d[i] != 0) a->top=i+1; + } + return(1); + } +#endif + +#ifdef BN_BYTES +#ifdef SPLIT_BN_BIN2BN +/* ignore negative */ +BIGNUM *BN_bin2bn(s, len, ret) +unsigned char *s; +int len; +BIGNUM *ret; + { + unsigned int i,m; + unsigned int n; + BN_ULONG l; + + if (ret == NULL) ret=BN_new(); + if (ret == NULL) return(NULL); + l=0; + n=len; + if (n == 0) + { + ret->top=0; + return(ret); + } + if (bn_expand(ret,(int)(n+2)*8) == NULL) + return(NULL); + i=((n-1)/BN_BYTES)+1; + m=((n-1)%(BN_BYTES)); + ret->top=i; + while (n-- > 0) + { + l=(l<<8L)| *(s++); + if (m-- == 0) + { + ret->d[--i]=l; + l=0; + m=BN_BYTES-1; + } + } + /* need to call this due to clear byte at top if avoiding + * having the top bit set (-ve number) */ + bn_fix_top(ret); + return(ret); + } +#endif + +#ifdef SPLIT_BN_BN2BIN +/* ignore negative */ +int BN_bn2bin(a, to) +BIGNUM *a; +unsigned char *to; + { + int n,i; + BN_ULONG l; + + bn_check_top(a); + + n=i=BN_num_bytes(a); + while (i-- > 0) + { + l=a->d[i/BN_BYTES]; + *(to++)=(unsigned char)((l>>(8*(i%BN_BYTES)))&0xff); + } + return(n); + } +#endif +#else +#ifdef SPLIT_BN_BIN2BN +/* ignore negative */ +BIGNUM *BN_bin2bn(s, len, ret) +unsigned char *s; +int len; +BIGNUM *ret; + { + int i,w,r,b,j,v; + int n; + BN_ULONG l; + + if (ret == NULL) ret=BN_new(); + if (ret == NULL) return(NULL); + while (len > 0) + { + if (*s != 0) break; + s++; + len--; + } + n=len*8; + if (bn_expand(ret,n) == NULL) + return(NULL); + for (i=0; imax; i++) + ret->d[i]=0; + j=0; + for (i=len-1; i>=0; i--) + { + v=((int)s[i])&0xff; + w=j/BN_BITS2; + b=j%BN_BITS2; + r=BN_BITS2-b; + j+=8; + if (r >= 8) + { + ret->d[w]|=(((BN_ULONG)v)<d[w] =(ret->d[w]|(((BN_ULONG)v)<d[w+1]=(ret->d[w+1]|(((BN_ULONG)v)>>r)); + } + } + + ret->top=((n-1)/BN_BITS2)+1; + bn_fix_top(ret); + return(ret); + } +#endif + +#ifdef SPLIT_BN_BN2BIN +int BN_bn2bin(a, to) +BIGNUM *a; +unsigned char *to; + { + int num,i,bi,w,b,r,max; + BN_ULONG l,*lp; + + bn_check_top(a); + + num=bi=BN_num_bytes(a); + lp=a->d; + for (i=0; i= 8) + to[bi]=(lp[w]>>b)&0xff; + else + { + to[bi]=(lp[w]>>b); + if (w+1 < a->top) + to[bi]|=lp[w+1]<top-b->top; + if (i != 0) return(i); + ap=a->d; + bp=b->d; + for (i=a->top-1; i>=0; i--) + { + t1= ap[i]; + t2= bp[i]; + if (t1 != t2) + return(t1 > t2?1:-1); + } + return(0); + } +#endif + +#ifdef SPLIT_BN_CMP +int BN_cmp(a, b) +BIGNUM *a; +BIGNUM *b; + { + int i; + int gt,lt; + BN_ULONG t1,t2; + + if ((a == NULL) || (b == NULL)) + { + if (a != NULL) + return(-1); + else if (b != NULL) + return(1); + else + return(0); + } + + bn_check_top(a); + bn_check_top(b); + + if (a->neg != b->neg) + { + if (a->neg) + return(-1); + else return(1); + } + if (a->neg == 0) + { gt=1; lt= -1; } + else { gt= -1; lt=1; } + + if (a->top > b->top) return(gt); + if (a->top < b->top) return(lt); + for (i=a->top-1; i>=0; i--) + { + t1=a->d[i]; + t2=b->d[i]; + if (t1 > t2) return(gt); + if (t1 < t2) return(lt); + } + return(0); + } +#endif + +#ifdef SPLIT_BN_SET_BIT +int BN_set_bit(a, n) +BIGNUM *a; +int n; + { + int i,j,k; + + bn_check_top(a); + + i=n/BN_BITS2; + j=n%BN_BITS2; + if (a->top <= i) + { + if (bn_wexpand(a,i+1) == NULL) return(0); + for(k=a->top; kd[k]=0; + a->top=i+1; + } + + a->d[i]|=(((BN_ULONG)1)<top <= i) return(0); + + a->d[i]&=(~(((BN_ULONG)1)<top <= i) return(0); + return((a->d[i]&(((BN_ULONG)1)<= a->top) return(0); + if (b == 0) + a->top=w; + else + { + a->top=w+1; + a->d[w]&= ~(((BN_ULONG)BN_MASK2)< bb)?1:-1); + for (i=n-2; i>=0; i--) + { + aa=a[i]; + bb=b[i]; + if (aa != bb) return((aa > bb)?1:-1); + } + return(0); + } +#endif +#endif + diff --git a/build/tools/acsign/bn_lsh.c b/build/tools/acsign/bn_lsh.c new file mode 100644 index 00000000..133b33ed --- /dev/null +++ b/build/tools/acsign/bn_lsh.c @@ -0,0 +1,112 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_LSHIFT1 +#define SPLIT_BN_LSHIFT +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BN_LSHIFT1 +#ifdef SMALL_CODE_SIZE + +int BN_lshift1(r, a) +BIGNUM *r,*a; + { + return(BN_lshift(r, a, 1)); + } + +#else + +int BN_lshift1(r, a) +BIGNUM *r; +BIGNUM *a; + { + register BN_ULONG *ap,*rp,t,c; + int i; + + bn_check_top(a); + + if (r != a) + { + if (bn_wexpand(r,a->top+1) == NULL) return(0); + r->neg=a->neg; + r->top=a->top; + } + else + { + if (bn_wexpand(r,a->top+1) == NULL) return(0); + } + ap=a->d; + rp=r->d; + c=0; + for (i=0; itop; i++) + { + t= *(ap++); + *(rp++)=((t<<1L)|c)&BN_MASK2; + c=(t & BN_TBIT)?1:0; + } + if (c) + { + *rp=1; + r->top++; + } + return(1); + } +#endif +#endif + +#ifdef SPLIT_BN_LSHIFT +int BN_lshift(r, a, n) +BIGNUM *r; +BIGNUM *a; +int n; + { + int i,nw,lb,rb; + BN_ULONG *t,*f; + BN_ULONG l; + + bn_check_top(a); + +#ifndef SMALL_CODE_SIZE + if (n == 1) return(BN_lshift1(r,a)); +#endif + if (bn_wexpand(r,a->top+(n/BN_BITS2)+1) == NULL) return(0); + r->neg=a->neg; + nw=n/BN_BITS2; + lb=n%BN_BITS2; + rb=BN_BITS2-lb; + f=a->d; + t=r->d; + t[a->top+nw]=0; + if (lb == 0) + for (i=a->top-1; i>=0; i--) + t[nw+i]=f[i]; + else + for (i=a->top-1; i>=0; i--) + { + l=f[i]; + t[nw+i+1]|=(l>>rb)&BN_MASK2; + t[nw+i]=(l<top=a->top+nw+1; + bn_fix_top(r); + return(1); + } +#endif + +#endif diff --git a/build/tools/acsign/bn_m_exp.c b/build/tools/acsign/bn_m_exp.c new file mode 100644 index 00000000..8d8afe94 --- /dev/null +++ b/build/tools/acsign/bn_m_exp.c @@ -0,0 +1,283 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#if 0 //RSA +#include +#endif +#include "bn_lcl.h" + +/* #ifdef MONT_MUL_MOD */ +/** + * Generic form of Montgomery Exponentiation, can be called directly + * out side of a BN_ME_METH + * + * @param rr_in BIGNUM pointer for result + * @param a_in BIGNUM pointer for base + * @param p BIGNUM pointer to the exponent + * @param m BIGNUM pointer to the modulus + * @param ctx BN_CTX pointer for temp values are argument storage + * @param in_mont BN_MONT_CTX pointer to structure of montgomery values + * + * @pre arguments are all initialised and not NULL or zero + * @post rr_in contains evaluated result + * + * @note + */ +int BN_mod_exp_mont(rr_in,a_in,p,m,ctx,in_mont) +BIGNUM *rr_in; +BIGNUM *a_in; +BIGNUM *p; +BIGNUM *m; +BN_CTX *ctx; +BN_MONT_CTX *in_mont; + { + int i,j,k,ret=0,tos,top; + int mul,sqr,num; + BIGNUM *d,*aa,*r,*a,*t; + BN_ULONG *vall[BN_EXP_TABLE_SIZE],*dp,*rp,n0,*rr,*tmp,*np; + BN_MONT_CTX *mont=NULL; + unsigned char *str=NULL; +#ifdef BN_SURRENDER + R_SURRENDER *surrender=NULL; + int count=0; +#endif + + bn_check_top(a_in); + bn_check_top(p); + bn_check_top(m); + + if (!(m->d[0] & 1)) + { +#ifndef NO_ERR + BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); +#endif + return(0); + } + + tos=ctx->tos; + + if (BN_is_zero(a_in)) + { (void)BN_zero(rr_in); return(1); } + if (BN_is_zero(p)) + { (void)BN_one(rr_in); return(1); } + if (BN_is_one(p)) + { (void)BN_copy(rr_in,a_in); return(1); } + + /* If this is not done, things will break in the montgomery + * part */ + +#if 1 + if (in_mont != NULL) + mont=in_mont; + else +#endif + { + if ((mont=BN_MONT_CTX_new()) == NULL) goto err; + if (!BN_MONT_CTX_set(mont,m,ctx)) goto err; + } + +#ifdef BN_SURRENDER + surrender=ctx->surrender; +#endif + + if (!BN_gen_exp_bits(p,&str,0,ctx)) goto err; + /* Remember this function uses another element from the passed ctx */ + ctx->tos++; + num=str[3]; + i=(BN_BITS+str[2]-1)/str[2]; + str+=4; + + + top=mont->N.top; + if ((a_in->top == top) && (a_in->d[top-1] < m->d[top-1])) + { + a=a_in; + } + else if (a_in->top < top) + { + a= &(ctx->bn[ctx->tos++]); + a->top=a_in->top; + bn_zexpand(a,top); + for (j=0; jtop; j++) + a->d[j]=a_in->d[j]; + } + else /* if (a_in->top > i) */ + { + a= &(ctx->bn[ctx->tos++]); + if (!BN_mod(a,a_in,m,ctx)) goto err; + bn_zexpand(a,top); + } + + /* At this point a is the size of the modulus and is 0 padded + * out to its size if needed. + */ + + /* Number of tmp words */ + k=num*top; + j=k+(p->top*i*2+BN_BYTES-1+4)/BN_BYTES; + + aa=&(ctx->bn[ctx->tos++]); + d= &(ctx->bn[ctx->tos++]); + r= &(ctx->bn[ctx->tos++]); + t= &(ctx->bn[ctx->tos++]); + + if (bn_wexpand(rr_in,top) == NULL) goto err; + if (bn_wexpand(d,top*4) == NULL) goto err; /* *2? */ + if (bn_wexpand(r,top*2) == NULL) goto err; + if (bn_wexpand(aa,j) == NULL) goto err; + if (bn_wexpand(t,top*2) == NULL) goto err; + dp=d->d; + rp=r->d; + tmp=t->d; + rr=mont->RR.d; + + n0=mont->n0; + np=mont->N.d; + + vall[0]=aa->d; + + bn_mul_normal(tmp,a->d,top,rr,top); + bn_from_montgomery_words(vall[0],tmp,np,top,n0); + + if (num > 1) + { + bn_sqr_normal(tmp,vall[0],top,dp); + bn_from_montgomery_words(dp,tmp,np,top,n0); + + for (i=1; i>1],sizeof(BN_ULONG)*top); + while (sqr != 0) + { +#ifdef BN_SURRENDER + /* + * Check this at the start of the loop rather than the + * end so we avoid as many of the bn operations as possible + */ + if (surrender != NULL) + { + if (surrender->callback(surrender,0xff, count++) != 0) + { + goto err; + } + } +#endif /* BN_SURRENDER */ + + /* + * check the abort flag at the start of the loop so we avoid + * as many of the bn operations as possible + */ + if (BN_CTX_get_flags(ctx, BN_CTX_FLG_ABORT)) + { + goto err; + } + + for (i=0; i>1],top); + bn_from_montgomery_words(rp,tmp,np,top,n0); + } + else + { + bn_mul_normal(tmp,rp,top,a->d,top); + bn_from_montgomery_words(rr_in->d,tmp,np,top,n0); + goto end; + } + } + + /* if (mul != 1) */ + { + for (i=top; id,rp,np,top,n0); + } +end: /* Use this to avoid an if */ + + /* + * Even if the operation has completed successfully, if the + * abort flag is set we want to abort so that anything + * calling this function will know not to continue. + */ + if (BN_CTX_get_flags(ctx, BN_CTX_FLG_ABORT)) + { + goto err; + } + + rr_in->top=top; + bn_fix_top(rr_in); + ret=1; +err: +#ifdef BN_SURRENDER + /* + * Even if the operation completed successfully we want to abort + * if the abort flag has been is set, so that subsequent operations + * do not continue. Allow the caller change to return value and + * cause the function to fail. + */ + if (surrender != NULL) + { + if (surrender->callback(surrender, 0xff, -1) != 0) + { + ret = 0; + } + } +#endif + if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); + ctx->tos=tos; + return(ret); + } +/* #endif */ + diff --git a/build/tools/acsign/bn_me.c b/build/tools/acsign/bn_me.c new file mode 100644 index 00000000..250967c9 --- /dev/null +++ b/build/tools/acsign/bn_me.c @@ -0,0 +1,251 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/** + * @file bn_me.c + * @brief BN method functions and utilities + */ +#include "bn_lcl.h" +#include "bn_thx.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_MOD_EXP_METH_DEFAULT +#define SPLIT_BN_MONT_CTX_USEIT +#define SPLIT_BN_ME_CTX_NAME +#define SPLIT_BN_ME_CTX_NEW +#define SPLIT_BN_ME_CTX_FREE +#define SPLIT_BN_ME_CTX_SET +#define SPLIT_BN_ME_CTX_MOD_EXP +#endif /* NO_SPLIT */ + +#ifndef NOPROTO +BN_ME_METH *bn_mod_exp_meth_default(int fallback); +#else +BN_ME_METH *bn_mod_exp_meth_default(); +#endif + +#ifdef SPLIT_BN_MOD_EXP_METH_DEFAULT + +/** + * Returns the default mod_exp method, choose first available in the + * method table or a hardwired default + * + * @param fallback [In] Flag for choice of method + * - 0 use the first value in the method table + * - 1 use the all encompassing default method + * + * @pre BN_default_init() has been run setting up library + * + * @post + * + * @internal uses global table bnme[] and counter me_num + * + * @internal only read the BN_ME_METH_INFO table no need for locking + * + * @relates BN_library_init + * @relates BN_default_init + * @relates BN_ME_CTX_new + * @relates BN_ME_CTX_free + * + */ +BN_ME_METH *bn_mod_exp_meth_default(int fallback) +{ + const BN_ME_METH *tmp; + +#ifndef BN_LIBRARY_SMALL + BN_ME_METH_INFO *meth_info; + + if(!fallback && ((meth_info = BN_bnme_get_info(0)) != NULL)) + { + tmp = meth_info->meth(); + } + else +#endif + { + /* set in bn.h or override bn_thx.h */ + tmp = BN_ME_METH_DEFAULT(); + } + return((BN_ME_METH *)tmp); +} +#endif + +#ifdef SPLIT_BN_MONT_CTX_USEIT + +#ifndef NOPROTO +int bn_mont_ctx_useit(int argi); +#else +int bn_mont_ctx_useit(); +#endif + +/** + * Montgomery method default useit function + * + * @param argi [In] reserved for future use + * + * @return 0 success + */ +int bn_mont_ctx_useit(int argi) + { + return(0); + } +#endif + +#ifdef SPLIT_BN_ME_CTX_NAME +/** + * Retrieve the BN method name string + * + * @param ctx [In] Method + * + * @pre ctx is valid and not NULL + * + * @return string pointer + */ +char *BN_ME_CTX_name(BN_ME_CTX *ctx) + { + return(ctx->meth->name); + } +#endif + +#ifdef SPLIT_BN_ME_CTX_NEW +/** + * Allocate a new BN_ME_CTX structure and assign method + * + * @param meth [In] Method to assign + * @param in [Out] Result BN_ME_CTX + * + * @note if meth is NULL system method default is used + * + * @retval pointer to BN_ME_CTX success + * @retval NULL failure + */ +BN_ME_CTX *BN_ME_CTX_new(BN_ME_METH *meth, BN_ME_CTX **in) + { + int i; + BN_ME_CTX *ret; + + if (in == NULL) + in= &ret; + + if (meth == NULL) + meth=bn_mod_exp_meth_default(0); + i=meth->init_ctx(meth,in); + if (i) + return(NULL); + else + return(*in); + } +#endif + +#ifdef SPLIT_BN_ME_CTX_FREE +/** + * Free context method + * + * @param mctx [In] Context object to be deallocated + * + * @note it is the callers responsibility to set mctx to NULL after free + * + * @pre mctx is not NULL and is valide BN_ME_CTX + */ +void BN_ME_CTX_free(BN_ME_CTX *mctx) + { + mctx->meth->free_ctx(mctx); + } +#endif + +#ifdef SPLIT_BN_ME_CTX_SET +/** + * Set value to BN_ME_CTX by identifier + * + * @param mctx [In] Method context object + * @param b [In] Big number + * @param cmd [In] Command identifier + * @param flags [In] Mask operation directives + * @param ctx [In] BN data store + * + * @note cmd values: + * @li BN_ME_SET_MOD will cause a method lookup is method not set + * + * @note passes control to set method in mctx + * + * @return result of mctx method set operation + */ +int BN_ME_CTX_set(BN_ME_CTX *mctx, BIGNUM *b, int cmd, int flags, BN_CTX *ctx) + { +#ifndef BN_LIBRARY_SMALL +#ifndef NOPROTO + const BN_ME_METH *(*meth)(void); +#else + const BN_ME_METH *(*meth)(); +#endif +#endif /* BN_LIBRARY_SMALL */ + + /* If we are loading the modulus, and we do not have the + * no_lookup flag (without a null method) + */ + if ((cmd == BN_ME_SET_MOD) && + ((mctx->meth != NULL) && !(flags & BN_ME_SET_FLG_NO_LOOKUP))) + { +#ifndef BN_LIBRARY_SMALL + meth=(const BN_ME_METH*(*)(void)) + BN_bnme_get(BN_num_bits(b),BN_BNME_F_BITS); + if (meth != NULL) + mctx->meth=meth(); + else +#endif + mctx->meth=bn_mod_exp_meth_default(1); + } + return(mctx->meth->set(mctx,b,cmd,flags,ctx)); + } +#endif + +#ifdef SPLIT_BN_ME_CTX_MOD_EXP +/** + * Call method mod_exp operation + * + * @param mctx [In] Method context object + * @param ret [Out] Result + * @param a [In] Base value + * @param p [In] Exponent + * @param m [In] Modulus + * @param ctx [In] Data storage + * + * @pre a must be expandable + * + * @return 0 success + */ +int BN_ME_CTX_mod_exp(BN_ME_CTX *mctx, BIGNUM *ret, BIGNUM *a, BIGNUM *p, + BIGNUM *m, BN_CTX *ctx) + { + int wtop; + + /* Before we call the method, make sure we are not doing 0^p, + * and p is not 0 or 1 */ + if (BN_is_zero(a)) + { BN_zero(ret); return(0); } + if (p != NULL) + { + if (BN_is_zero(p)) + { BN_one(ret); return(0); } + else if (BN_is_one(p)) + { BN_copy(ret,a); return(0); } + } + + /* wtop is the size 'a' needs to be for the method */ + wtop=mctx->meth->num; + bn_zexpand(a,wtop); + + return(mctx->meth->mod_exp(mctx,ret,a,p,ctx)); + } +#endif + +#endif + diff --git a/build/tools/acsign/bn_mont.c b/build/tools/acsign/bn_mont.c new file mode 100644 index 00000000..6fc5fea4 --- /dev/null +++ b/build/tools/acsign/bn_mont.c @@ -0,0 +1,231 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#undef BN_DEBUG +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_MOD_MUL_MONTGOMERY +#define SPLIT_BN_FROM_MONTGOMERY +#define SPLIT_BN_MONT_CTX_NEW +#define SPLIT_BN_MONT_CTX_INIT +#define SPLIT_BN_MONT_CTX_FREE +#define SPLIT_BN_MONT_CTX_COPY +#endif /* NO_SPLIT */ + +/* #define DEBUG */ + +#ifdef SPLIT_BN_MOD_MUL_MONTGOMERY +/* We multiply a by b, generating a number 2n words long. + * This is then reduced by the montogmery number, which is + * n words. */ +int BN_mod_mul_montgomery(r,a,b,mont,ctx) +BIGNUM *r,*a,*b; +BN_MONT_CTX *mont; +BN_CTX *ctx; + { + BIGNUM *tmp,*tmp2; + int ret=0,w; + int i; + + bn_check_top(a); + bn_check_top(b); + + w=mont->riw; + + tmp= &(ctx->bn[ctx->tos++]); + tmp2= &(ctx->bn[ctx->tos++]); + bn_check_top(tmp); + bn_check_top(tmp2); + if (bn_wexpand(tmp,w+w) == NULL) goto err; + if (bn_wexpand(r,w+w) == NULL) goto err; + + if (a == b) + { + if (bn_wexpand(tmp2,w+w) == NULL) goto err; +#ifdef BN_SQR_COMBA + if ((a->top == 8) && (a->top == b->top)) + bn_sqr_comba8(tmp->d,a->d); + else +#endif + { + bn_sqr_normal(tmp->d,a->d,a->top,tmp2->d); + } + } + else + { +#ifdef BN_MUL_COMBA + if (a->top == 8) + bn_mul_comba8(tmp->d,a->d,b->d); + else +#endif + { + bn_mul_normal(tmp->d,a->d,a->top,b->d,b->top); + } + } + + i=a->top+b->top; + while (i<(w+w)) + { + tmp->d[i]=0; + i++; + } + tmp->top=w+w; + tmp->neg=0; + + /* reduce from aRR to aR */ + /* tmp->d is 2w words */ +#if 0 + bn_fix_top(tmp); + BN_from_montgomery_words(r,tmp,mont,ctx); +#else + bn_from_montgomery_words(r->d,tmp->d,mont->N.d,w,mont->n0); +#endif + r->top=w; + r->neg=0; + bn_fix_top(r); + + ret=1; +err: + ctx->tos-=2; + return(ret); + } +#endif + +#ifdef SPLIT_BN_FROM_MONTGOMERY +int BN_from_montgomery(ret,a,mont,ctx) +BIGNUM *ret; +BIGNUM *a; +BN_MONT_CTX *mont; +BN_CTX *ctx; + { + BIGNUM *n,*r; + BN_ULONG *np,*rp,n0,v0,v1,*nrp; + int al,nl,max,i; + int retn=0; + + bn_check_top(a); + + r= &(ctx->bn[ctx->tos]); + + if (!BN_copy(r,a)) goto err1; + n= &(mont->N); + + /* mont->riw is the size of mont->N in bits/words */ + al=mont->riw; + + nl=n->top; + if ((al == 0) || (nl == 0)) { r->top=0; return(1); } + + max=(nl+al+1); /* allow for overflow (no?) XXX */ + if (bn_wexpand(r,max) == NULL) goto err1; + if (bn_wexpand(ret,max) == NULL) goto err1; + + r->neg=a->neg^n->neg; + np=n->d; + rp=r->d; + nrp= &(r->d[nl]); + + /* clear the top words of T */ + for (i=r->top; id[i]=0; + + r->top=max; + n0=mont->n0; + + v1=0; + for (i=0; iriw will be a multiple of the word size */ + (void)BN_rshift(ret,r,mont->riw*BN_BITS2); + + if (BN_ucmp(ret, &(mont->N)) >= 0) + { + (void)BN_usub(ret,ret,&(mont->N)); /* XXX */ + } + retn=1; + +err1: + return(retn); + } +#endif + +#ifdef SPLIT_BN_MONT_CTX_NEW +BN_MONT_CTX *BN_MONT_CTX_new() + { + BN_MONT_CTX *ret; + + if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL) + return(NULL); + + BN_MONT_CTX_init(ret); + ret->flags=BN_FLG_MALLOCED; + return(ret); + } +#endif + +#ifdef SPLIT_BN_MONT_CTX_INIT +void BN_MONT_CTX_init(ctx) +BN_MONT_CTX *ctx; + { + ctx->use_word=0; + ctx->riw=0; + BN_init(&(ctx->RR)); + BN_init(&(ctx->N)); + BN_init(&(ctx->Ni)); + ctx->flags=0; + } +#endif + +#ifdef SPLIT_BN_MONT_CTX_FREE +void BN_MONT_CTX_free(mont) +BN_MONT_CTX *mont; + { + BN_free(&(mont->RR)); + BN_free(&(mont->N)); + BN_free(&(mont->Ni)); + if (mont->flags & BN_FLG_MALLOCED) + Free(mont); + } +#endif + +#ifdef SPLIT_BN_MONT_CTX_COPY +BN_MONT_CTX *BN_MONT_CTX_copy(to, from) +BN_MONT_CTX *to, *from; + { + if (to == from) return(to); + + (void)BN_copy(&(to->RR),&(from->RR)); + (void)BN_copy(&(to->N),&(from->N)); + (void)BN_copy(&(to->Ni),&(from->Ni)); + bn_zexpand(&(to->RR),from->riw); + bn_zexpand(&(to->Ni),from->riw); + to->use_word=from->use_word; + to->riw=from->riw; + to->n0=from->n0; + return(to); + } +#endif + +#endif diff --git a/build/tools/acsign/bn_ms_w.c b/build/tools/acsign/bn_ms_w.c new file mode 100644 index 00000000..1ddd40e3 --- /dev/null +++ b/build/tools/acsign/bn_ms_w.c @@ -0,0 +1,121 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +int BN_MONT_CTX_set_word(mont,mod,ctx) +BN_MONT_CTX *mont; +BIGNUM *mod; +BN_CTX *ctx; + { + BIGNUM Ri,*R; +#if 1 + BN_ULONG tmod,rr; +#else + BN_ULONG buf[2]; + BIGNUM tmod; +#endif + + + bn_check_top(mod); + if (mod->top == 0) return(0); + + R= &(mont->RR); /* grab RR as a temp */ + if (BN_copy(&(mont->N),mod) == NULL) /* Set N */ + return(0); + + BN_init(&Ri); + + mont->use_word=1; + +/* EAY is this number of words to shift, or the number to shift to end up + * with a '1' in the next word? + * for 8 bit words, is 0x01ab == 1 or 2 + */ + mont->riw=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2; + if (!BN_zero(R)) return(0); + + /* We are now setting a number which is larger than our current + * one after we do the shift + */ + if (!BN_set_bit(R,BN_BITS2)) + goto err; + +#if 0 + tmod.d=buf; + tmod.top=1; + tmod.max=mod->max; + tmod.neg=mod->neg; + buf[0]=mod->d[0]&BN_MASK2; + buf[1]=0; + + if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL) + goto err; +#else + tmod=mod->d[0]; + rr=BN_mod_inverse_word(tmod); + if (!BN_set_word(&Ri,rr)) + goto err; +#endif + + /* R*Ri */ + if (!BN_lshift(&Ri,&Ri,BN_BITS2)) + goto err; + + if (!BN_is_zero(&Ri)) + (void)BN_sub_word(&Ri,1); + else + { + /* This is not common..., 1 in BN_MASK2, + * It happens when buf[0] was == 1. So for 8 bit, + * this is 1/256, 16bit, 1 in 2^16 etc. + */ + if (!BN_set_word(&Ri,BN_MASK2)) + goto err; + } +#if 0 + BN_div(&Ri,NULL,&Ri,&tmod,ctx); + //BN_div_word(&Ri,tmod); + mont->n0=Ri.d[0]; +#else +#if 0 + { + BN_ULONG h,l; + + h=l=0; + if (Ri.top >= 2) h=Ri.d[1]; + if (Ri.top >= 1) l=Ri.d[0]; + mont->n0=bn_div_words(h,l,tmod); + } +#endif + mont->n0=bn_div_words( + (Ri.top >= 2)?Ri.d[1]:0, + (Ri.top >= 1)?Ri.d[0]:0, + tmod); +#endif + /* mod->top=z; */ + + /* setup RR for conversions */ + (void)BN_zero(&(mont->RR)); + if (!BN_set_bit(&(mont->RR),mont->riw*2*BN_BITS2)) + goto err; + (void)BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx); + bn_zexpand(&(mont->RR),mont->riw); +#if 0 + bn_zexpand(&(mont->Ni),mont->riw); /*This is not used? */ +#endif + +err: + BN_free(&Ri); + return(1); + } + + diff --git a/build/tools/acsign/bn_mul.c b/build/tools/acsign/bn_mul.c new file mode 100644 index 00000000..4dd0e235 --- /dev/null +++ b/build/tools/acsign/bn_mul.c @@ -0,0 +1,779 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_MUL_RECURSIVE +#define SPLIT_BN_MUL_PART_RECURSIVE +#define SPLIT_BN_MUL_LOW_RECURSIVE +#define SPLIT_BN_MUL_HIGH +#define SPLIT_BN_MUL +#define SPLIT_BN_MUL_NORMAL +#define SPLIT_BN_MUL_LOW_NORMAL +#endif /* NO_SPLIT */ + +#ifdef SMALL_CODE_SIZE +#undef BN_RECURSION_MUL +#endif + +#ifdef BN_RECURSION_MUL +#if 0 /* Replaced by bn_mul_rec_words() */ +/* r is 2*n2 words in size, + * a and b are both n2 words in size. + * n2 must be a power of 2. + * We multiply and return the result. + * t must be 2*n2 words in size + * We calulate + * a[0]*b[0] + * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) + * a[1]*b[1] + */ +#ifdef SPLIT_BN_MUL_RECURSIVE +void bn_mul_recursive(r,a,b,n2,t) +BN_ULONG *r,*a,*b; +int n2; +BN_ULONG *t; + { + int n=n2/2,c1,c2; + unsigned int neg,zero; + BN_ULONG ln,lo,*p; + +#ifdef BN_COUNT +printf(" bn_mul_recursive %d * %d\n",n2,n2); +#endif +#ifdef BN_MUL_COMBA +/* if (n2 == 4) + { + bn_mul_comba4(r,a,b); + return; + } + else */ if (n2 == 8) + { + bn_mul_comba8(r,a,b); + return; + } +#endif + if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) + { + /* This should not happen */ + bn_mul_normal(r,a,n2,b,n2); + return; + } + /* r=(a[0]-a[1])*(b[1]-b[0]) */ + c1=bn_cmp_words(a,&(a[n]),n); + c2=bn_cmp_words(&(b[n]),b,n); + zero=neg=0; + switch (c1*3+c2) + { + case -4: + bn_sub_words(t, &(a[n]),a, n); /* - */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + break; + case -3: + zero=1; + break; + case -2: + bn_sub_words(t, &(a[n]),a, n); /* - */ + bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */ + neg=1; + break; + case -1: + case 0: + case 1: + zero=1; + break; + case 2: + bn_sub_words(t, a, &(a[n]),n); /* + */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + neg=1; + break; + case 3: + zero=1; + break; + case 4: + bn_sub_words(t, a, &(a[n]),n); + bn_sub_words(&(t[n]),&(b[n]),b, n); + break; + } + +#ifdef BN_MUL_COMBA + if (n == 4) + { + if (!zero) + bn_mul_comba4(&(t[n2]),t,&(t[n])); + else + Memset(&(t[n2]),0,8*sizeof(BN_ULONG)); + + bn_mul_comba4(r,a,b); + bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n])); + } + else if (n == 8) + { + if (!zero) + bn_mul_comba8(&(t[n2]),t,&(t[n])); + else + Memset(&(t[n2]),0,16*sizeof(BN_ULONG)); + + bn_mul_comba8(r,a,b); + bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n])); + } + else +#endif + { + p= &(t[n2*2]); + if (!zero) + bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); + else + Memset(&(t[n2]),0,n2*sizeof(BN_ULONG)); + bn_mul_recursive(r,a,b,n,p); + bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p); + } + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=(int)bn_add_words(t,r,&(r[n2]),n2); + + if (neg) /* if t[32] is negative */ + { + c1-=(int)bn_sub_words(&(t[n2]),t,&(t[n2]),n2); + } + else + { + /* Might have a carry */ + c1+=(int)bn_add_words(&(t[n2]),&(t[n2]),t,n2); + } + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + * c1 holds the carry bits + */ + c1+=(int)bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < (BN_ULONG)c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } +#endif +#endif + +#if 0 +#ifdef SPLIT_BN_MUL_PART_RECURSIVE +/* n+tn is the word length + * t must be n*4 is size, as does r */ +void bn_mul_part_recursive(r,a,b,tn,n,t) +BN_ULONG *r,*a,*b; +int tn,n; +BN_ULONG *t; + { + int i,j,n2=n*2; + int c1; + BN_ULONG ln,lo,*p; + +#ifdef BN_COUNT +printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n); +#endif + if (n < 8) + { + i=tn+n; + bn_mul_normal(r,a,i,b,i); + return; + } + + /* r=(a[0]-a[1])*(b[1]-b[0]) */ + bn_sub_words(t, a, &(a[n]),n); /* + */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + +#ifdef BN_MUL_COMBA +/* if (n == 4) + { + bn_mul_comba4(&(t[n2]),t,&(t[n])); + bn_mul_comba4(r,a,b); + bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); + Memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); + } + else */ if (n == 8) + { + bn_mul_comba8(&(t[n2]),t,&(t[n])); + bn_mul_comba8(r,a,b); + bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); + Memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); + } + else +#endif + { + p= &(t[n2*2]); + bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); + bn_mul_recursive(r,a,b,n,p); + i=n/2; + /* If there is only a bottom half to the number, + * just do it */ + j=tn-i; + if (j == 0) + { + bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p); + Memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2)); + } + else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */ + { + bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]), + j,i,p); + Memset(&(r[n2+tn*2]),0, + sizeof(BN_ULONG)*(n2-tn*2)); + } + else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */ + { + Memset(&(r[n2]),0,sizeof(BN_ULONG)*n2); + if (tn < BN_MUL_RECURSIVE_SIZE_NORMAL) + { + bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); + } + else + { + for (;;) + { + i/=2; + if (i < tn) + { + bn_mul_part_recursive(&(r[n2]), + &(a[n]),&(b[n]), + tn-i,i,p); + break; + } + else if (i == tn) + { + bn_mul_recursive(&(r[n2]), + &(a[n]),&(b[n]), + i,p); + break; + } + } + } + } + } + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=(int)bn_add_words(t,r,&(r[n2]),n2); + c1-=(int)bn_sub_words(&(t[n2]),t,&(t[n2]),n2); + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + * c1 holds the carry bits + */ + c1+=(int)bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < (BN_ULONG)c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } +#endif +#endif + +#if 0 +#ifdef SPLIT_BN_MUL_LOW_RECURSIVE +/* a and b must be the same size, which is n2. + * r must be n2 words and t must be n2*2 + */ +void bn_mul_low_recursive(r,a,b,n2,t) +BN_ULONG *r,*a,*b; +int n2; +BN_ULONG *t; + { + int n=n2/2; + +#ifdef BN_COUNT +printf(" bn_mul_low_recursive %d * %d\n",n2,n2); +#endif + + bn_mul_recursive(r,a,b,n,&(t[0])); + if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL) + { + bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2])); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + bn_mul_low_recursive(&(t[0]),&(a[n]),&(b[0]),n,&(t[n2])); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + } + else + { + bn_mul_low_normal(&(t[0]),&(a[0]),&(b[n]),n); + bn_mul_low_normal(&(t[n]),&(a[n]),&(b[0]),n); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + bn_add_words(&(r[n]),&(r[n]),&(t[n]),n); + } + } +#endif +#endif + +#ifdef SPLIT_BN_MUL_HIGH +#if 0 +/* a and b must be the same size, which is n2. + * r must be n2 words and t must be n2*2 + * l is the low words of the output. + * t must be n2*3 + */ +void bn_mul_high(r,a,b,l,n2,t) +BN_ULONG *r,*a,*b,*l; +int n2; +BN_ULONG *t; + { + int i,n; + int c1,c2; + int neg,oneg,zero; + BN_ULONG ll,lc,*lp,*mp; + +#ifdef BN_COUNT +printf(" bn_mul_high %d * %d\n",n2,n2); +#endif + n=n2/2; + + /* Calculate (al-ah)*(bh-bl) */ + neg=zero=0; + c1=bn_cmp_words(&(a[0]),&(a[n]),n); + c2=bn_cmp_words(&(b[n]),&(b[0]),n); + switch (c1*3+c2) + { + case -4: + bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n); + bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n); + break; + case -3: + zero=1; + break; + case -2: + bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n); + bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n); + neg=1; + break; + case -1: + case 0: + case 1: + zero=1; + break; + case 2: + bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n); + bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n); + neg=1; + break; + case 3: + zero=1; + break; + case 4: + bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n); + bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n); + break; + } + + oneg=neg; + /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */ + /* r[10] = (a[1]*b[1]) */ +#ifdef BN_MUL_COMBA + if (n == 8) + { + bn_mul_comba8(&(t[0]),&(r[0]),&(r[n])); + bn_mul_comba8(r,&(a[n]),&(b[n])); + } + else +#endif + { +#ifdef BN_MUL_RECURSION + bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2])); + bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2])); +#else + bn_mul_normal(&(t[0]),&(r[0]),n,&(r[n]),n); + bn_mul_normal(r,&(a[n]),n,&(b[n]),n); +#endif + } + + /* s0 == low(al*bl) + * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl) + * We know s0 and s1 so the only unknown is high(al*bl) + * high(al*bl) == s1 - low(ah*bh+s0+(al-ah)*(bh-bl)) + * high(al*bl) == s1 - (r[0]+l[0]+t[0]) + */ + if (l != NULL) + { + lp= &(t[n2+n]); + c1=(int)bn_add_words(lp,&(r[0]),&(l[0]),n); + } + else + { + c1=0; + lp= &(r[0]); + } + + if (neg) + neg=(int)bn_sub_words(&(t[n2]),lp,&(t[0]),n); + else + { + bn_add_words(&(t[n2]),lp,&(t[0]),n); + neg=0; + } + + if (l != NULL) + { + bn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n); + } + else + { + lp= &(t[n2+n]); + mp= &(t[n2]); + for (i=0; i 0) + { + lc=c1; + do { + ll=(r[i]+lc)&BN_MASK2; + r[i++]=ll; + lc=(lc > ll); + } while (lc); + } + else + { + lc= -c1; + do { + ll=r[i]; + r[i++]=(ll-lc)&BN_MASK2; + lc=(lc > ll); + } while (lc); + } + } + if (c2 != 0) /* Add starting at r[1] */ + { + i=n; + if (c2 > 0) + { + lc=c2; + do { + ll=(r[i]+lc)&BN_MASK2; + r[i++]=ll; + lc=(lc > ll); + } while (lc); + } + else + { + lc= -c2; + do { + ll=r[i]; + r[i++]=(ll-lc)&BN_MASK2; + lc=(lc > ll); + } while (lc); + } + } + } +#endif +#endif +#endif + +#ifdef SPLIT_BN_MUL +int BN_mul(r,a,b,ctx) +BIGNUM *r,*a,*b; +BN_CTX *ctx; + { + int top,al,bl,neg; + BIGNUM *rr; +#ifdef BN_RECURSION_MUL + BIGNUM *t; + int i,j,k,l; +#endif + +#ifdef BN_COUNT +printf("BN_mul %d * %d\n",a->top,b->top); +#endif + + bn_check_top(a); + bn_check_top(b); + bn_check_top(r); + + al=a->top; + bl=b->top; + + if ((al == 0) || (bl == 0)) + { + (void)BN_zero(r); + return(1); + } + top=al+bl; + neg=a->neg^b->neg; + + if ((r == a) || (r == b)) + rr= &(ctx->bn[ctx->tos+1]); + else + rr=r; + + if (bn_wexpand(rr,top) == NULL) return(0); + rr->top=top; + +#if defined(BN_MUL_COMBA) || defined(BN_RECURSION_MUL) + if (al == bl) + { +# ifdef BN_MUL_COMBA +/* if (al == 4) + { + bn_mul_comba4(rr->d,a->d,b->d); + goto end; + } + else */ if (al == 8) + { + bn_mul_comba8(rr->d,a->d,b->d); + goto end; + } + else +# endif +#ifdef BN_RECURSION_MUL + if (al < BN_MULL_SIZE_NORMAL) +#endif + { + bn_mul_normal(rr->d,a->d,al,b->d,bl); + goto end; + } +# ifdef BN_RECURSION_MUL + goto symetric; +# endif + } +#endif +#ifdef BN_RECURSION_MUL + else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL)) + { + bn_mul_normal(rr->d,a->d,al,b->d,bl); + goto end; + } + else + { + i=(al-bl); + if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA)) + { + bn_wexpand(b,al); + b->d[bl]=0; + bl++; + goto symetric; + } + else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) + { + bn_wexpand(a,bl); + a->d[al]=0; + al++; + goto symetric; + } + } +#endif + +#ifdef BN_RECURSION_MUL +normal_mul: +#endif + bn_mul_normal(rr->d,a->d,al,b->d,bl); + +#ifdef BN_RECURSION_MUL + if (0) + { +symetric: + /* symetric and > 4 */ + /* 16 or larger */ + l=BN_num_bits_word((BN_ULONG)al); + j=1<<(l-1); + k=j+j; + t= &(ctx->bn[ctx->tos]); + if (al == j) /* exact multiple */ + { + BN_REC rec; + rec.depth=l-5; + rec.n=j; + rec.mul=bn_mul_comba8; + rec.sqr=bn_sqr_comba8; + if (bn_wexpand(t,k+k) == NULL) + return(0); + if (bn_wexpand(rr,k) == NULL) + return(0); + bn_mul_rec_words(rr->d,a->d,b->d,t->d,&rec); + } + else + goto normal_mul; +#if 0 + { + bn_zexpand(a,k); + bn_zexpand(b,k); + bn_wexpand(t,k); + bn_wexpand(rr,k); + bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d); + } +#endif + } +#endif +#if defined(BN_MUL_COMBA) || defined(BN_RECURSION_MUL) +end: +#endif + + r->neg=neg; + bn_fix_top(rr); + if (r != rr) (void)BN_copy(r,rr); + return(1); + } +#endif + + +#ifdef SPLIT_BN_MUL_NORMAL +void bn_mul_normal(r,a,na,b,nb) +BN_ULONG *r,*a; +int na; +BN_ULONG *b; +int nb; + { + BN_ULONG *rr; + +#ifdef BN_COUNT +printf(" bn_mul_normal %d * %d\n",na,nb); +#endif + /* asymetric and >= 4 */ +#if 0 + if ((na == nb) && (na == 8)) + { + bn_mul_normal(r,a,na,b,nb); + return; + } +#endif + + if (na < nb) + { + int itmp; + BN_ULONG *ltmp; + + itmp=na; na=nb; nb=itmp; + ltmp=a; a=b; b=ltmp; + + } + rr= &(r[na]); + rr[0]=bn_mul_words(r,a,na,b[0]); + + for (;;) + { + if (--nb <= 0) return; + rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]); + if (--nb <= 0) return; + rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]); + if (--nb <= 0) return; + rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]); + if (--nb <= 0) return; + rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]); + rr+=4; + r+=4; + b+=4; + } + } +#endif + +#ifdef SPLIT_BN_MUL_LOW_NORMAL +void bn_mul_low_normal(r,a,b,n) +BN_ULONG *r,*a,*b; +int n; + { +#ifdef BN_COUNT +printf(" bn_mul_low_normal %d * %d\n",n,n); +#endif + (void)bn_mul_words(r,a,n,b[0]); + + for (;;) + { + if (--n <= 0) return; + (void)bn_mul_add_words(&(r[1]),a,n,b[1]); + if (--n <= 0) return; + (void)bn_mul_add_words(&(r[2]),a,n,b[2]); + if (--n <= 0) return; + (void)bn_mul_add_words(&(r[3]),a,n,b[3]); + if (--n <= 0) return; + (void)bn_mul_add_words(&(r[4]),a,n,b[4]); + r+=4; + b+=4; + } + } +#endif +#endif diff --git a/build/tools/acsign/bn_r_exp.c b/build/tools/acsign/bn_r_exp.c new file mode 100644 index 00000000..9465e402 --- /dev/null +++ b/build/tools/acsign/bn_r_exp.c @@ -0,0 +1,134 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +/* #ifdef RECP_MUL_MOD */ +int BN_mod_exp_recp(r,a,p,m,ctx) +BIGNUM *r; +BIGNUM *a; +BIGNUM *p; +BIGNUM *m; +BN_CTX *ctx; + { + int i,j,bits,ret=0,wstart,wend,window,wvalue; + int start=1,ts=0; + BIGNUM *aa; + BIGNUM val[BN_EXP_TABLE_SIZE]; + BN_RECP_CTX recp; + + bits=BN_num_bits(p); + + if (BN_is_zero(a)) + { (void)BN_zero(r); return(1); } + if (BN_is_zero(p)) + { (void)BN_one(r); return(1); } + if (BN_is_one(p)) + { (void)BN_copy(r,a); return(1); } + + BN_RECP_CTX_init(&recp); + if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err; + + BN_init(&(val[0])); + ts=1; + + aa= &(ctx->bn[ctx->tos++]); + + if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */ + if (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx)) + goto err; /* 2 */ + + if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */ + window=1; + else if (bits >= 256) + window=5; /* max size of window */ + else if (bits >= 128) + window=4; + else + window=3; + + j=1<<(window-1); + for (i=1; i>1]),&recp,ctx)) + goto err; + + /* move the 'window' down further */ + wstart-=wend+1; + wvalue=0; + start=0; + if (wstart < 0) break; + } + ret=1; +err: + ctx->tos--; + for (i=0; in; + int n2=n/2; + int c1,neg=0; + + + if (rec->depth == 0) + { + /* t needs to have space for 4*n words + * The multiply needs to be a n2*n2 -> n + */ +#ifndef NOPROTO + void (PRE_CCONV CCONV *rmul)(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b); +#else + void (PRE_CCONV CCONV *rmul)(); +#endif + rmul=rec->mul; + +#ifdef _EXTRA_ARG_ + /* THIS IS WRONG - there is no extra int arg on the end */ + rmul(&(r[0]),&(a[0]),&(b[0]),n2); + rmul(&(r[n]),&(a[n2]),&(b[n2]),n2); +#else + rmul(&(r[0]),&(a[0]),&(b[0])); + rmul(&(r[n]),&(a[n2]),&(b[n2])); +#endif + + if (bn_sub_words(&(tt[n+0]), &(a[0]),&(a[n2]),n2)) + { + bn_2s_comp(&(tt[n+ 0]),&(tt[n+ 0]),n2); + neg=1; + } + else + neg=0; + if (bn_sub_words(&(tt[n+n2]),&(b[n2]),&(b[0]),n2)) + { + neg^=1; + bn_2s_comp(&(tt[n+n2]),&(tt[n+n2]),n2); + } + +#ifdef _EXTRA_ARG_ + rmul(&(tt[0]),&(tt[n+0]),&(tt[n+n2]),n2); +#else + rmul(&(tt[0]),&(tt[n+0]),&(tt[n+n2])); +#endif + } + else /* Leaf node */ + { + /* t has 4*n words taken per call. + * Since n is half the size per call, we need + * 6*n words for our current level and all sub levels + * The multiply needs to be a n2*n2 -> n + */ + rec->depth--; + rec->n=n2; + bn_mul_rec_words(&(r[0]), &(a[0]), &(b[0]), &(tt[n+n]),rec); + bn_mul_rec_words(&(r[n]), &(a[n2]),&(b[n2]), &(tt[n+n]),rec); + + neg=0; + if (bn_sub_words(&(tt[n+0]), &(a[0]),&(a[n2]),n2)) + { + bn_2s_comp(&(tt[n+ 0]),&(tt[n+ 0]),n2); + neg=1; + } + else + neg=0; + if (bn_sub_words(&(tt[n+n2]),&(b[n2]),&(b[0]),n2)) + { + neg^=1; + bn_2s_comp(&(tt[n+n2]),&(tt[n+n2]),n2); + } + + bn_mul_rec_words(&(tt[0]),&(tt[n]),&(tt[n+n2]),&(tt[n+n]),rec); + rec->n=n; + rec->depth++; + } + + c1=bn_add_words(&(tt[n]),&(r[0]),&(r[n]),n); + + if (neg) + c1-=bn_sub_words(&(tt[0]),&(tt[n]),&(tt[0]),n); + else + c1+=bn_add_words(&(tt[0]),&(tt[n]),&(tt[0]),n); + tt[n]=c1; + c1=bn_add_words(&(r[n2]),&(r[n2]),&(tt[0]),n+1); + if (c1) + { + tt= &(r[n+n2+1]); + do { + } while (++(*(tt++)) == 0); + } + } +#endif + +#ifdef SPLIT_BN_SQR_REC_WORDS +/* tt needs to be 3*n words */ +void bn_sqr_rec_words(r,a,tt,rec) +BN_ULONG *r,*a,*tt; +BN_REC *rec; + { + int n=rec->n; + int n2=n/2; + int c1; + + if (rec->depth == 0) + { + /* t needs to have space for 4*n words + * The multiply needs to be a n2*n2 -> n + */ +#ifndef NOPROTO + void (PRE_CCONV CCONV *rsqr)(BN_ULONG *r, BN_ULONG *a); +#else + void (PRE_CCONV CCONV *rsqr)(); +#endif + + rsqr=rec->sqr; + +#ifdef _EXTRA_ARG_ + /* THIS IS WRONG - there is no extra int arg on the end */ + rsqr(&(r[0]), &(a[0]), n2); + rsqr(&(r[n]), &(a[n2]),n2); +#else + rsqr(&(r[0]), &(a[0])); + rsqr(&(r[n]), &(a[n2])); +#endif + + if (bn_sub_words(&(tt[n+0]), &(a[0]),&(a[n2]),n2)) + bn_2s_comp(&(tt[n+0]),&tt[n+0], n2); + +#ifdef _EXTRA_ARG_ + rsqr(&(tt[0]),&(tt[n]), n2); +#else + rsqr(&(tt[0]),&(tt[n])); +#endif + + } + else /* Leaf node */ + { + /* t has 4*n words taken per call. + * Since n is half the size per call, we need + * 6*n words for our current level and all sub levels + * The multiply needs to be a n2*n2 -> n + */ + rec->depth--; + rec->n=n2; + bn_sqr_rec_words(&(r[0]), &(a[0]), &(tt[n+n]),rec); + bn_sqr_rec_words(&(r[n]), &(a[n2]),&(tt[n+n]),rec); + + if (bn_sub_words(&(tt[n+0]), &(a[0]),&(a[n2]),n2)) + bn_2s_comp(&(tt[n+0]),&tt[n+0], n2); + bn_sqr_rec_words(&(tt[0]),&(tt[n]),&(tt[n+n]),rec); + + rec->n=n; + rec->depth++; + } + + c1=bn_add_words(&(tt[n]),&(r[0]),&(r[n]),n); + c1-=bn_sub_words(&(tt[0]),&(tt[n]),&(tt[0]),n); + + tt[n]=c1; + c1=bn_add_words(&(r[n2]),&(r[n2]),&(tt[0]),n+1); + if (c1) + { + tt= &(r[n+n2+1]); + do { + } while (++(*(tt++)) == 0); + } + } +#endif + +#endif /* !NO_SPLIT || !SPLIT_FILE */ diff --git a/build/tools/acsign/bn_recp.c b/build/tools/acsign/bn_recp.c new file mode 100644 index 00000000..e762a819 --- /dev/null +++ b/build/tools/acsign/bn_recp.c @@ -0,0 +1,202 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +void BN_RECP_CTX_init(recp) +BN_RECP_CTX *recp; + { + BN_init(&(recp->N)); + BN_init(&(recp->Nr)); + recp->num_bits=0; + recp->flags=0; + } + +BN_RECP_CTX *BN_RECP_CTX_new() + { + BN_RECP_CTX *ret; + + if ((ret=(BN_RECP_CTX *)Malloc(sizeof(BN_RECP_CTX))) == NULL) + return(NULL); + + BN_RECP_CTX_init(ret); + ret->flags=BN_FLG_MALLOCED; + return(ret); + } + +void BN_RECP_CTX_free(recp) +BN_RECP_CTX *recp; + { + BN_free(&(recp->N)); + BN_free(&(recp->Nr)); + if (recp->flags & BN_FLG_MALLOCED) + Free(recp); + } + +int BN_RECP_CTX_set(recp,d,ctx) +BN_RECP_CTX *recp; +BIGNUM *d; +BN_CTX *ctx; + { + (void)BN_copy(&(recp->N),d); + (void)BN_zero(&(recp->Nr)); + recp->num_bits=BN_num_bits(d); + recp->shift=0; + ctx=ctx; /* Stop warning */ + return(1); + } + +int BN_mod_mul_reciprocal(r, x, y, recp, ctx) +BIGNUM *r; +BIGNUM *x; +BIGNUM *y; +BN_RECP_CTX *recp; +BN_CTX *ctx; + { + int ret=0; + BIGNUM *a; + + bn_check_top(x); + bn_check_top(y); + + a= &(ctx->bn[ctx->tos++]); + if (y != NULL) + { + if (x == y) + { if (!BN_sqr(a,x,ctx)) goto err; } + else + { if (!BN_mul(a,x,y,ctx)) goto err; } + } + else + a=x; /* Just do the mod */ + + (void)BN_div_recp(NULL,r,a,recp,ctx); + ret=1; +err: + ctx->tos--; + return(ret); + } + +int BN_div_recp(dv,rem,m,recp,ctx) +BIGNUM *dv; +BIGNUM *rem; +BIGNUM *m; +BN_RECP_CTX *recp; +BN_CTX *ctx; + { + int i,j,tos,ret=0,ex; + BIGNUM *a,*b,*d,*r; + + bn_check_top(m); + + tos=ctx->tos; + a= &(ctx->bn[ctx->tos++]); + b= &(ctx->bn[ctx->tos++]); + if (dv != NULL) + d=dv; + else + d= &(ctx->bn[ctx->tos++]); + if (rem != NULL) + r=rem; + else + r= &(ctx->bn[ctx->tos++]); + + if (BN_ucmp(m,&(recp->N)) < 0) + { + (void)BN_zero(d); + (void)BN_copy(r,m); + ctx->tos=tos; + return(1); + } + + /* We want the remainder + * Given input of ABCDEF / ab + * we need multiply ABCDEF by 3 digests of the reciprocal of ab + * + */ + i=BN_num_bits(m); + + j=recp->num_bits*2; + if (j > i) + { + i=j; + ex=0; + } + else + { + ex=(i-j)/2; + } + + j=i/2; + + if (i != recp->shift) + recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N), + i,ctx); + + if (!BN_rshift(a,m,j-ex)) goto err; + if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err; + if (!BN_rshift(d,b,j+ex)) goto err; + d->neg=0; + if (!BN_mul(b,&(recp->N),d,ctx)) goto err; + if (!BN_usub(r,m,b)) goto err; + r->neg=0; + + j=0; +#if 1 + while (BN_ucmp(r,&(recp->N)) >= 0) + { + if (j++ > 2) + { +#ifndef NO_ERR + BNerr(BN_F_BN_DIV_RECP,BN_R_BAD_RECIPROCAL); +#endif + goto err; + } + if (!BN_usub(r,r,&(recp->N))) goto err; + if (!BN_add_word(d,1)) goto err; + } +#endif + + r->neg=BN_is_zero(r)?0:m->neg; + d->neg=m->neg^recp->N.neg; + ret=1; +err: + ctx->tos=tos; + return(ret); + } + +/* len is the expected size of the result + * We actually calculate with an extra word of precision, so + * we can do faster division if the remainder is not required. + */ +int BN_reciprocal(r,m,len,ctx) +BIGNUM *r; +BIGNUM *m; +int len; +BN_CTX *ctx; + { + int ret= -1; + BIGNUM t; + + bn_check_top(m); + + BN_init(&t); + + (void)BN_zero(&t); + if (!BN_set_bit(&t,len)) goto err; + + if (!BN_div(r,NULL,&t,m,ctx)) goto err; + ret=len; +err: + BN_free(&t); + return(ret); + } + diff --git a/build/tools/acsign/bn_rsh.c b/build/tools/acsign/bn_rsh.c new file mode 100644 index 00000000..909cd9a1 --- /dev/null +++ b/build/tools/acsign/bn_rsh.c @@ -0,0 +1,123 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_RSHIFT1 +#define SPLIT_BN_RSHIFT +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BN_RSHIFT1 +#ifdef SMALL_CODE_SIZE +int BN_rshift1(r, a) +BIGNUM *r; +BIGNUM *a; + { + return(BN_rshift(r,a,1)); + } + +#else + +int BN_rshift1(r, a) +BIGNUM *r; +BIGNUM *a; + { + BN_ULONG *ap,*rp,t,c; + int i; + + bn_check_top(a); + + if (BN_is_zero(a)) + { + BN_zero(r); + return(1); + } + if (a != r) + { + if (bn_wexpand(r,a->top) == NULL) return(0); + r->top=a->top; + r->neg=a->neg; + } + ap=a->d; + rp=r->d; + c=0; + for (i=a->top-1; i>=0; i--) + { + t=ap[i]; + rp[i]=((t>>1)&BN_MASK2)|c; + c=(t&1)?BN_TBIT:0; + } + bn_fix_top(r); + return(1); + } +#endif +#endif + +#ifdef SPLIT_BN_RSHIFT +int BN_rshift(r, a, n) +BIGNUM *r; +BIGNUM *a; +int n; + { + int i,j,nw,lb,rb; + BN_ULONG *t,*f; + BN_ULONG l,tmp; + + bn_check_top(a); + +#ifndef SMALL_CODE_SIZE + if (n == 1) return(BN_rshift1(r,a)); +#endif + nw=n/BN_BITS2; + rb=n%BN_BITS2; + lb=BN_BITS2-rb; + if (nw > a->top) + { + (void)BN_zero(r); + return(1); + } + if (r != a) + { + if (bn_wexpand(r,a->top-nw+1+1/*???*/) == NULL) return(0); + r->neg=a->neg; + } + + f= &(a->d[nw]); + t=r->d; + j=a->top-nw; + r->top=j; + + if (rb == 0) + { + for (i=j+1; i > 0; i--) + *(t++)= *(f++); + } + else + { + l= *(f++); + for (i=1; i>rb)&BN_MASK2; + l= *(f++); + *(t++) =(tmp|(l<>rb)&BN_MASK2; + *t=0; + } + bn_fix_top(r); + return(1); + } +#endif + +#endif diff --git a/build/tools/acsign/bn_sqr.c b/build/tools/acsign/bn_sqr.c new file mode 100644 index 00000000..4762cd9d --- /dev/null +++ b/build/tools/acsign/bn_sqr.c @@ -0,0 +1,273 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#ifdef SMALL_CODE_SIZE +#undef BN_RECURSION_SQR +#endif + +#if !(defined(NO_SPLIT) && defined(SPLIT_FILE)) + +#ifdef NO_SPLIT +#define SPLIT_BN_SQR +#define SPLIT_BN_SQR_NORMAL +#define SPLIT_BN_RECURSION_SQR +#endif /* NO_SPLIT */ + +#ifdef SPLIT_BN_SQR +/* r must not be a */ +int BN_sqr(r, a, ctx) +BIGNUM *r; +BIGNUM *a; +BN_CTX *ctx; + { + int max,al; + BIGNUM *tmp,*rr; + +#ifdef BN_COUNT +printf("BN_sqr %d * %d\n",a->top,a->top); +#endif + bn_check_top(a); + tmp= &(ctx->bn[ctx->tos]); + rr=(a != r)?r: (&ctx->bn[ctx->tos+1]); + + al=a->top; + if (al <= 0) + { + r->top=0; + return(1); + } + + max=(al+al); + if (bn_wexpand(rr,max) == NULL) return(0); + + rr->top=max; + rr->neg=0; + + if (al == 4) + { +#ifndef BN_SQR_COMBA + BN_ULONG t[8]; + bn_sqr_normal(rr->d,a->d,4,t); +#else + bn_sqr_comba4(rr->d,a->d); +#endif + } + else if (al == 8) + { +#ifndef BN_SQR_COMBA + BN_ULONG t[16]; + bn_sqr_normal(rr->d,a->d,8,t); +#else + bn_sqr_comba8(rr->d,a->d); +#endif + } + else + { +#if 1 && defined(BN_RECURSION_SQR) + if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) + { + BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2]; + bn_sqr_normal(rr->d,a->d,al,t); + } + else + { + int j,l,k; + + l=BN_num_bits_word((BN_ULONG)al); + j=1<<(l-1); + k=j+j; + if ((al == j) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) + { + BN_REC rec; + if (bn_wexpand(tmp,k*2) == NULL) return(0); + rec.depth=l-5; + rec.n=j; + rec.mul=bn_mul_comba8; + rec.sqr=bn_sqr_comba8; + + bn_sqr_rec_words(rr->d,a->d,tmp->d,&rec); + } + else + { + if (bn_wexpand(tmp,max) == NULL) return(0); + bn_assert(al*2 <= max); + bn_sqr_normal(rr->d,a->d,al,tmp->d); + } + } +#else + if (bn_wexpand(tmp,max) == NULL) return(0); + bn_assert(al*2 <= max); + bn_sqr_normal(rr->d,a->d,al,tmp->d); +#endif +#ifdef BN_DEBUG + tmp->top=0; +#endif + } + + if ((max > 0) && (rr->d[max-1] == 0)) rr->top--; + if (rr != r) (void)BN_copy(r,rr); + return(1); + } +#endif + +#ifdef SPLIT_BN_SQR_NORMAL +/* tmp must have 2*n words */ +void bn_sqr_normal(r, a, n, tmp) +BN_ULONG *r; +BN_ULONG *a; +int n; +BN_ULONG *tmp; + { + int i,j,max; + BN_ULONG *ap,*rp,m; + + max=n*2; + ap=a; + rp=r; + rp[0]=rp[max-1]=0; + rp++; + j=n; + + if (--j > 0) + { + m= (*ap++); + rp[j]=bn_mul_words(rp,ap,j,m); + rp+=2; + } + + for (i=n-2; i>0; i--) + { + j--; + m= *(ap++); + rp[j]=bn_mul_add_words(rp,ap,j,m); + rp+=2; + } + + (void)bn_add_words(r,r,r,max); + + /* There will not be a carry */ + + bn_sqr_words(tmp,a,n); + + (void)bn_add_words(r,r,tmp,max); + } +#endif + +#if 0 /* replaced by bn_sqr_rec_words() AND this has bugs */ +#ifdef SPLIT_BN_RECURSION_SQR +#ifdef BN_RECURSION_SQR +/* r is 2*n words in size, + * a and b are both n words in size. + * n must be a power of 2. + * We multiply and return the result. + * t must be 2*n words in size + * We calulate + * a[0]*b[0] + * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) + * a[1]*b[1] + */ +void bn_sqr_recursive(r,a,n2,t) +BN_ULONG *r,*a; +int n2; +BN_ULONG *t; + { + int n=n2/2; + int zero,c1; + BN_ULONG ln,lo,*p; + +#ifdef BN_COUNT +printf(" bn_sqr_recursive %d * %d\n",n2,n2); +#endif + if (n2 == 4) + { +#ifndef BN_SQR_COMBA + bn_sqr_normal(r,a,4,t); +#else + bn_sqr_comba4(r,a); +#endif + return; + } + else if (n2 == 8) + { +#ifndef BN_SQR_COMBA + bn_sqr_normal(r,a,8,t); +#else + bn_sqr_comba8(r,a); +#endif + return; + } + if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL) + { + bn_sqr_normal(r,a,n2,t); + return; + } + /* r=(a[0]-a[1])*(a[1]-a[0]) */ + c1=bn_cmp_words(a,&(a[n]),n); + zero=0; + if (c1 > 0) + bn_sub_words(t,a,&(a[n]),n); + else if (c1 < 0) + bn_sub_words(t,&(a[n]),a,n); + else + zero=1; + + /* The result will always be negative unless it is zero */ + p= &(t[n2*2]); + + if (!zero) + bn_sqr_recursive(&(t[n2]),t,n,p); + else + Memset(&(t[n2]),0,n*sizeof(BN_ULONG)); + bn_sqr_recursive(r,a,n,p); + bn_sqr_recursive(&(r[n2]),&(a[n]),n,p); + + /* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=(int)(bn_add_words(t,r,&(r[n2]),n2)); + + /* t[32] is negative */ + c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2)); + + /* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1]) + * r[10] holds (a[0]*a[0]) + * r[32] holds (a[1]*a[1]) + * c1 holds the carry bits + */ + c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2)); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < (BN_ULONG)c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } +#endif +#endif +#endif +#endif diff --git a/build/tools/acsign/bn_wdiv.c b/build/tools/acsign/bn_wdiv.c new file mode 100644 index 00000000..d76752a4 --- /dev/null +++ b/build/tools/acsign/bn_wdiv.c @@ -0,0 +1,100 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#include "bn_lcl.h" + +#ifndef OPT_BN_ASM + +#ifndef BN_DIV_WORDS +#define BN_DIV_WORDS +#endif + +#endif + +#ifdef BN_DIV_WORDS +#if defined(BN_LLONG) +BN_ULONG bn_div_words(h,l,d) +BN_ULONG h,l,d; + { + return((BN_ULONG)(((((BN_ULLONG)h)< ((BN_ULONG)1)<= d) h-=d; + + if (i) + { + d=(d<>(BN_BITS2-i)))&BN_MASK2; + l=(l<>BN_BITS4)&BN_MASK2lh; + dl=(d&BN_MASK2l); + for (;;) + { + if ((h>>BN_BITS4) == dh) + q=BN_MASK2l; + else + q=h/dh; + + for (;;) + { + t=(h-q*dh)&BN_MASK2; + if ((t&BN_MASK2h) || + (((dl*q)&BN_MASK2) <= (( + (t<>BN_BITS4)&BN_MASK2lh))&BN_MASK2))) + break; + q--; + } + th=(q*dh)&BN_MASK2; + tl=(q*dl)&BN_MASK2; + t=(tl>>BN_BITS4); + tl=(tl&BN_MASK2lh)<>BN_BITS4))&BN_MASK2; + l=(l&BN_MASK2l)<top-1; i>=0; i--) + { +#ifndef BN_LLONG + ret=((ret<d[i]>>BN_BITS4)&BN_MASK2l))%w; + ret=((ret<d[i]&BN_MASK2l))%w; +#else + ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])% + (BN_ULLONG)w); +#endif + } + return((BN_ULONG)ret); + } +#endif + +#ifdef SPLIT_BN_DIV_WORD +BN_ULONG BN_div_word(a, w) +BIGNUM *a; +BN_ULONG w; + { + BN_ULONG ret; + int i; + + if (a->top == 0) return(0); + ret=0; + w=w&BN_MASK2;//w&=BN_MASK2; + for (i=a->top-1; i>=0; i--) + { + BN_ULONG l,d; + + l=a->d[i]; + d=bn_div_words(ret,l,w); + ret=(l-((d*w)&BN_MASK2))&BN_MASK2; + a->d[i]=d; + } + if ((a->top > 0) && (a->d[a->top-1] == 0)) + a->top--; + return(ret); + } +#endif + +#ifdef SPLIT_BN_ADD_WORD +int BN_add_word(a, w) +BIGNUM *a; +BN_ULONG w; + { + BN_ULONG l; + int i; + + if (w == 0) return(1); + bn_check_top(a); + + w=w&BN_MASK2;//w&=BN_MASK2; + if (a->neg) + { + if(a->top > 1) + { + a->neg=0; + i=BN_sub_word(a,w); + a->neg=1; + return(i); + } + else + { /* a->top == 1, it cannot be 0 */ + l=a->d[0]; + if (l > w) + a->d[0]=l-w; + else if (l < w) + { + a->neg=0; + a->d[0]=w-l; + } + else + { + a->neg=0; + a->top=0; + } + return(1); + } + } + w=w&BN_MASK2;//w&=BN_MASK2; + if (bn_wexpand(a,a->top+1) == NULL) return(0); + a->d[a->top]=0; + i=0; + for (;;) + { + l=(a->d[i]+(BN_ULONG)w)&BN_MASK2; + a->d[i]=l; + if (w > l) + w=1; + else + break; + i++; + } + if (i >= a->top) + a->top++; + return(1); + } +#endif + +#ifdef SPLIT_BN_SUB_WORD +int BN_sub_word(a, w) +BIGNUM *a; +BN_ULONG w; + { + int i; + + bn_check_top(a); + if (w == 0) return(1); + + w=w&BN_MASK2;//w&=BN_MASK2; + if (a->neg) + { + a->neg=0; + i=BN_add_word(a,w); + a->neg=1; + return(i); + } + + w=w&BN_MASK2;//w&=BN_MASK2; + if (a->top <= 1) + { + BN_ULONG l; + + if (a->top == 0) + { + if (bn_wexpand(a,1) == NULL) return(0); + a->d[0]=w; + a->neg = 1; + a->top = 1; + return(1); + } + l=a->d[0]; + if (l == w) + a->top=0; + else if (l > w) + a->d[0]=l-w; + else + { + a->neg=1; + a->d[0]=w-l; + } + return(1); + } + i=0; + for (;;) + { + if (a->d[i] >= w) + { + a->d[i]-=w; + break; + } + else + { + a->d[i]=(a->d[i]-w)&BN_MASK2; + i++; + w=1; + } + } + if ((a->d[i] == 0) && (i == (a->top-1))) + a->top--; + return(1); + } +#endif + +#ifdef SPLIT_BN_MUL_WORD +int BN_mul_word(a,w) +BIGNUM *a; +BN_ULONG w; + { + BN_ULONG ll; + + w=w&BN_MASK2;//w&=BN_MASK2; + if (a->top) + { + ll=bn_mul_words(a->d,a->d,a->top,w); + if (ll) + { + if (bn_wexpand(a,a->top+1) == NULL) return(0); + a->d[a->top++]=ll; + } + } + return(1); + } +#endif + +#endif diff --git a/build/tools/acsign/include/acsign.h b/build/tools/acsign/include/acsign.h new file mode 100644 index 00000000..6e11663c --- /dev/null +++ b/build/tools/acsign/include/acsign.h @@ -0,0 +1,49 @@ +#ifndef _ACSIGN_H_ +#define _ACSIGN_H_ + +#include "sha.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define HASHContext SHA_CTX + +#define HASHReset( _context ) \ +do{ \ + (_context)->sha_block = NULL; \ + (void)SHA1_Init( _context ); \ +} while(0) +#define HASHUpdate( _context, _ptr, _len ) (void)SHA1_Update( _context, _ptr, _len ) +#define HASHGetDigest( _context, _ptr ) (void)SHA1_Final( _ptr, _context ) + +// +BOOL ACSign_Encrypto(void *sign, const void *key, const void *data, int length); +BOOL ACSign_Decrypto(void *buf, const void *key, const void *sign, int length); + +// +int ACSign_DigestUnit( + void* buffer, // o͗̈ + const void* buf, // f[^ւ̃|C^ + unsigned int len // f[^̒ + ); + +// +int ACSign_CompareUnit( + const void* decedHash, // ACSign_Decryptȍo + const void* digest // ACSign_DigestUnit̏o + ); + +// +int ACSign_GetKey( + void* dest_ptr, // o̓f[^ւ̃|C^ + unsigned int dest_len, // o̓f[^̒ + const void* src_ptr, // ̓f[^ւ̃|C^ + unsigned int src_len // ̓f[^̒ + ); + +#ifdef __cplusplus +} +#endif + +#endif //_ACSIGN_H_ diff --git a/build/tools/acsign/include/acsign_gcd.h b/build/tools/acsign/include/acsign_gcd.h new file mode 100644 index 00000000..2c9853e6 --- /dev/null +++ b/build/tools/acsign/include/acsign_gcd.h @@ -0,0 +1,30 @@ +#ifndef _ACSIGN_GCD_H_ +#define _ACSIGN_GCD_H_ + +#include "sha.h" +#include "format_sign.h" +#include "format_rom.h" +#include "acsign.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// +int ACSign_Final( + GCDHeader* header, // wb_ւ̃|C^ + void* buffer, // o͗̈ + const void* key + ); + +// +int ACSign_DigestHeader( + void* buffer, // o͗̈ + GCDHeader* header // f[^ւ̃|C^ + ); + +#ifdef __cplusplus +} +#endif + +#endif //_ACSIGN_GCD_H_ diff --git a/build/tools/acsign/include/acsign_nand.h b/build/tools/acsign/include/acsign_nand.h new file mode 100644 index 00000000..97afa980 --- /dev/null +++ b/build/tools/acsign/include/acsign_nand.h @@ -0,0 +1,30 @@ +#ifndef _ACSIGN_NAND_H_ +#define _ACSIGN_NAND_H_ + +#include "sha.h" +#include "format_sign.h" +#include "format_rom.h" +#include "acsign.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// +int ACSign_Final( + NANDHeader* header, // wb_ւ̃|C^ + void* buffer, // o͗̈ + const void* key + ); + +// +int ACSign_DigestHeader( + void* buffer, // o͗̈ + NANDHeader* header // f[^ւ̃|C^ + ); + +#ifdef __cplusplus +} +#endif + +#endif //_ACSIGN_NAND_H_ diff --git a/build/tools/acsign/include/acsign_nor.h b/build/tools/acsign/include/acsign_nor.h new file mode 100644 index 00000000..eb097b50 --- /dev/null +++ b/build/tools/acsign/include/acsign_nor.h @@ -0,0 +1,30 @@ +#ifndef _ACSIGN_NOR_H_ +#define _ACSIGN_NOR_H_ + +#include "sha.h" +#include "format_sign.h" +#include "format_rom.h" +#include "acsign.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// +int ACSign_Final( + NORHeader* header, // wb_ւ̃|C^ + void* buffer, // o͗̈ + const void* key + ); + +// +int ACSign_DigestHeader( + void* buffer, // o͗̈ + NORHeader* header // f[^ւ̃|C^ + ); + +#ifdef __cplusplus +} +#endif + +#endif //_ACSIGN_NOR_H_ diff --git a/build/tools/acsign/include/bn.h b/build/tools/acsign/include/bn.h new file mode 100644 index 00000000..f68b3d22 --- /dev/null +++ b/build/tools/acsign/include/bn.h @@ -0,0 +1,1120 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#ifndef HEADER_COMMON_BN_H +#define HEADER_COMMON_BN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef FLAT_INC +#include "r_types.h" +#else +#include "../include/r_types.h" +#endif + +#if !defined(CCONV) +#define CCONV +#endif + +#ifndef PRE_CCONV +#define PRE_CCONV +#endif + +/* convert from the new to the old option names */ +#if defined(OPT_BN_LLONG) +#define BN_LLONG /* comment to make sure Configure leaves this alone */ +#endif + +#if defined(OPT_BN_MUL_LATENCY) +#define BN_MUL_LATENCY +#endif + +/* by default we have the following switched on - unless we have an option + * that switched them off for a specific platform + */ +#ifdef OPT_NO_COMBA +#define OPT_NO_BN_MUL_COMBA +#define OPT_NO_BN_SQR_COMBA +#endif + +#ifdef OPT_NO_REC +#define OPT_NO_BN_RECURSION_MUL +#define OPT_NO_BN_RECURSION_SQR +#endif + +#ifndef OPT_NO_BN_MUL_COMBA +#define BN_MUL_COMBA +#endif +#ifndef OPT_NO_BN_SQR_COMBA +#define BN_SQR_COMBA +#endif +#ifndef OPT_NO_BN_RECURSION_MUL +#define BN_RECURSION_MUL +#endif +#ifndef OPT_NO_BN_RECURSION_SQR +#define BN_RECURSION_SQR +#endif +#ifndef OPT_NO_BN_RECURSION_MONT +#undef BN_RECURSION_MONT /* DO NOT TURN THIS ON, IT IS BROKEN */ +#endif + +#if (!defined(OPT_NO_BN_MUL_COMBA) && !defined(OPT_NO_BN_SQR_COMBA)) +#if OPT_MONT_REDUCE_COMBA /* TEMP UNTIL C IS IMPLEMENTED-DEF'd ON PLATFORMS W/ ASM */ +#define BN_REDUCE_COMBA +#endif +#endif + +#define RECP_MUL_MOD +#define MONT_MUL_MOD + +#ifndef OPT_NO_BN_SURRENDER +#define BN_SURRENDER +#else +#undef BN_SURRENDER +#endif + +#ifdef SMALL_CODE_SIZE +#undef BN_MUL_COMBA /* stop modification */ +#undef BN_SQR_COMBA /* stop modification */ +#undef BN_REDUCE_COMBA /* stop modification */ +#undef BN_RECURSION_MUL /* stop modification */ +#undef BN_RECURSION_SQR /* stop modification */ +#undef BN_RECURSION_MONT /* stop modification */ +#endif + + + +/* This next option uses the C libraries (2 word)/(1 word) function. + * If it is not defined, I use my C version (which is slower). + * The reason for this flag is that when the particular C compiler + * library routine is used, and the library is linked with a different + * compiler, the library is missing. This mostly happens when the + * library is built with gcc and then linked using nornal cc. This would + * be a common occurance because gcc normally produces code that is + * 2 times faster than system compilers for the big number stuff. + * For machines with only one compiler (or shared libraries), this should + * be on. Again this in only really a problem on machines + * using "long long's", are 32bit, and are not using my assember code. */ +#if defined(MSDOS) || defined(WINDOWS) || defined(linux) +#define BN_DIV2W +#endif + +/* Only one for the following should be defined */ +/* The prime number generation stuff may not work when + * EIGHT_BIT but I don't care since I've only used this mode + * for debuging the bignum libraries */ +#undef SIXTY_FOUR_BIT_LONG +#undef SIXTY_FOUR_BIT +#undef SIXTY_BIT +#undef THIRTY_TWO_BIT +#undef THIRTY_BIT +#undef SIXTEEN_BIT +#undef EIGHT_BIT +#undef TEST_EIGHT_BIT + +#if defined(OPT_64_BIT_LONG) +#define SIXTY_FOUR_BIT_LONG +#endif +#if defined(OPT_64_BIT) +#define SIXTY_FOUR_BIT +#endif +#if defined(OPT_60_BIT) +#define SIXTY_BIT +#endif +#if defined(OPT_32_BIT) +#define THIRTY_TWO_BIT +#endif +#if defined(OPT_32_BIT_INT) +#define THIRTY_TWO_BIT +#endif +#if defined(OPT_30_BIT) +#define THIRTY_BIT +#endif +#if defined(OPT_16_BIT) +#define SIXTEEN_BIT +#endif +#if defined(OPT_8_BIT) +#define EIGHT_BIT +#endif +#if defined(OPT_8_BIT_TEST) +#define TEST_EIGHT_BIT +#endif + +/* This define is used for those few functions that 'break' when + * things are compiled for 8 bit words. Basically the size of an + * integer. + */ +#define BN_ILONG BN_ULONG + +/* assuming long is 64bit - this is the DEC Alpha + * unsigned long long is only 64 bits, don't define + * BN_LLONG for the DEC Alpha */ +#ifdef SIXTY_FOUR_BIT_LONG +#undef BN_LLONG +#define BN_ULLONG unsigned long long +#define BN_ULONG unsigned long +#define BN_LONG long +#define BN_BITS 128 +#define BN_BYTES 8 +#define BN_BITS2 64 +#define BN_BITS4 32 +#define BN_MASK (0xffffffffffffffffffffffffffffffffLL) +#define BN_MASK2 (0xffffffffffffffffL) +#define BN_MASK2l (0xffffffffL) +#define BN_MASK2lh (0xffffffffL) +#define BN_MASK2h (0xffffffff00000000L) +#define BN_MASK2h1 (0xffffffff80000000L) +#define BN_TBIT (0x8000000000000000L) +#define BN_DEC_CONV (10000000000000000000UL) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%019lu" +#define BN_DEC_NUM 19 +#define BN_HEX_FMT "%016lX" +#endif + +/* This is where the long long data type is 64 bits, but long is 32. + * For machines where there are 64bit registers, this is the mode to use. + * IRIX, on R4000 and above should use this mode, along with the relevent + * assember code. Do NOT define BN_LLONG. + */ +#ifdef SIXTY_FOUR_BIT +#undef BN_LLONG /* Protect against config */ +/* #define BN_ULLONG unsigned long long */ +#ifdef WIN64 +#define BN_ULONG unsigned _int64 +#define BN_LONG _int64 +#else +#define BN_ULONG unsigned long long +#define BN_LONG long long +#endif +#define BN_BITS 128 +#define BN_BYTES 8 +#define BN_BITS2 64 +#define BN_BITS4 32 +#define BN_MASK2 (0xffffffffffffffffLL) +#define BN_MASK2l (0xffffffffL) +#define BN_MASK2lh (0xffffffffL) +#define BN_MASK2h (0xffffffff00000000LL) +#define BN_MASK2h1 (0xffffffff80000000LL) +#define BN_TBIT (0x8000000000000000LL) +#define BN_DEC_CONV (10000000000000000000ULL) +#ifdef WIN64 +#define BN_DEC_FMT1 "%I64u" +#define BN_DEC_FMT2 "%019I64u" +#define BN_DEC_NUM 19 +#define BN_HEX_FMT "%016I64X" +#else +#define BN_DEC_FMT1 "%llu" +#define BN_DEC_FMT2 "%019llu" +#define BN_DEC_NUM 19 +#define BN_HEX_FMT "%016llX" +#endif +#endif + +#ifdef SIXTY_BIT +#undef SIXTY_FOUR_BIT +#undef BN_LLONG /* Protect against config */ +/* #define BN_ULLONG unsigned long long */ +#define BN_ULONG unsigned long long +#define BN_LONG long long +#define BN_BITS 120 +#define BN_BITS2 60 +#define BN_BITS4 30 +#define BN_MASK2 (0x0fffffffffffffffLL) +#define BN_MASK2l ( 0x3fffffffL) +#define BN_MASK2lh ( 0x3fffffffL) +#define BN_MASK2h (0x0fffffffc0000000LL) +#define BN_MASK2h1 (0x0fffffffe0000000LL) +#define BN_TBIT (0x0800000000000000LL) +#define BN_DEC_CONV (100000000000000000LL) +#define BN_DEC_FMT1 "%9u" +#define BN_DEC_FMT2 "%017llu" +#define BN_DEC_NUM 17 +#define BN_HEX_FMT "%016llX" +#endif + +#ifdef THIRTY_TWO_BIT +#ifdef WIN32 +#if defined(__BORLANDC__) +#define BN_ULLONG unsigned __int64 +#else /* !__BORLANDC__ */ +#if defined(__MINGW32__) || defined(__DJGPP__) +#define BN_ULLONG unsigned long long +#else +#define BN_ULLONG unsigned _int64 +#endif /* __MINGW32__ || __DJGPP__ */ +#endif /* __BORLANDC__ */ +#else /* !WIN32 */ +#define BN_ULLONG unsigned long long +#endif /* WIN32 */ +#ifdef OPT_32_BIT_INT +#define BN_ULONG unsigned int +#define BN_LONG int +#else +#define BN_ULONG unsigned long +#define BN_LONG long +#endif +#define BN_BITS 64 +#define BN_BYTES 4 +#define BN_BITS2 32 +#define BN_BITS4 16 +/* This is needed because the Watcom compiler pre-processor + * under QNX tries to parses the 'LL' part even though it is + * never used. + */ +#ifdef BN_LLONG +#ifndef WIN32 +#define BN_MASK (0xffffffffffffffffLL) +#else +#define BN_MASK (0xffffffffffffffffL) +#endif +#endif +#define BN_MASK2 (0xffffffffL) +#define BN_MASK2l (0xffff) +#define BN_MASK2lh (0xffff) +#define BN_MASK2h1 (0xffff8000L) +#define BN_MASK2h (0xffff0000L) +#define BN_TBIT (0x80000000L) +#define BN_DEC_CONV (1000000000L) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%09lu" +#define BN_DEC_NUM 9 +#define BN_HEX_FMT "%08lX" +#endif + +#ifdef THIRTY_BIT +#ifdef WIN32 +#if defined(__MINGW32__) || defined(__DJGPP__) +#define BN_ULLONG unsigned long long +#else /* ! (__MINGW32__ || __DJGPP__) */ +#define BN_ULLONG unsigned _int64 +#endif /* __MINGW32__ || __DJGPP__ */ +#else /* !WIN32 */ +#define BN_ULLONG unsigned long long +#endif /* WIN32 */ +#define BN_ULONG unsigned long +#define BN_LONG long +#define BN_BITS 60 +#define BN_BITS2 30 +#define BN_BITS4 15 +/* This is needed because the Watcom compiler pre-processor + * under QNX tries to parses the 'LL' part even though it is + * never used. + */ +#ifdef BN_LLONG +#ifndef WIN32 +#define BN_MASK (0x0fffffffffffffffLL) +#else +#define BN_MASK (0x0fffffffffffffffL) +#endif +#endif +#define BN_MASK2 (0x3fffffffL) +#define BN_MASK2l (0x7fff) +#define BN_MASK2lh (0x7fff) +#define BN_MASK2h1 (0x3fffc000L) +#define BN_MASK2h (0x3fff8000L) +#define BN_TBIT (0x20000000L) +#define BN_DEC_CONV (1000000000L) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%09lu" +#define BN_DEC_NUM 9 +#define BN_HEX_FMT "%08lX" +#endif + +#ifdef SIXTEEN_BIT +#ifndef BN_DIV2W +#define BN_DIV2W +#endif +#define BN_ULLONG unsigned long +#define BN_ULONG unsigned short +#define BN_LONG short +#define BN_BITS 32 +#define BN_BYTES 2 +#define BN_BITS2 16 +#define BN_BITS4 8 +#define BN_MASK (0xffffffff) +#define BN_MASK2 (0xffff) +#define BN_MASK2l (0xff) +#define BN_MASK2lh (0xff) +#define BN_MASK2h1 (0xff80) +#define BN_MASK2h (0xff00) +#define BN_TBIT (0x8000) +#define BN_DEC_CONV (10000) +#define BN_DEC_FMT1 "%u" +#define BN_DEC_FMT2 "%04u" +#define BN_DEC_NUM 4 +#define BN_HEX_FMT "%04X" +#endif + +#ifdef TEST_EIGHT_BIT +#define EIGHT_BIT /* comment to stop editing */ +#endif + +#ifdef EIGHT_BIT +#undef BN_ILONG +#define BN_ILONG unsigned int +#ifndef BN_DIV2W +#define BN_DIV2W +#endif +#ifdef TEST_EIGHT_BIT +#define BN_ULLONG unsigned int +#define BN_ULONG unsigned int +#define BN_LONG int +#else +#define BN_ULLONG unsigned short +#define BN_ULONG unsigned char +#define BN_LONG char +#endif +#define BN_BITS 16 +#define BN_BYTES 1 +#define BN_BITS2 8 +#define BN_BITS4 4 +#define BN_MASK (0xffff) +#define BN_MASK2 (0xff) +#define BN_MASK2lh (0xf) +#define BN_MASK2l (0xf) +#define BN_MASK2h1 (0xf8) +#define BN_MASK2h (0xf0) +#define BN_TBIT (0x80) +#define BN_DEC_CONV (100) +#define BN_DEC_FMT1 "%u" +#define BN_DEC_FMT2 "%02u" +#define BN_DEC_NUM 2 +#define BN_HEX_FMT "%02X" +#endif + +#ifdef BIGNUM +#undef BIGNUM +#endif + +#define BN_FLG_MALLOCED 0x01 +#define BN_FLG_STATIC_DATA 0x02 +#define BN_FLG_FREE 0x8000 /* used for debuging */ +#define BN_CTX_FLG_ABORT 0x4000 /* used for aborting RSA operations*/ +#define BN_set_flags(b,n) ((b)->flags|=(n)) +#define BN_get_flags(b,n) ((b)->flags&(n)) +#define BN_CTX_set_flags(b,n) ((b)->flags|=(n)) +#define BN_CTX_get_flags(b,n) ((b)->flags&(n)) + +#ifndef HEADER_COMMON_BN_H_TYPEDEF_DEF +#define HEADER_COMMON_BN_H_TYPEDEF_DEF +typedef struct bignum_st BIGNUM; +typedef struct bignum_ctx BN_CTX; +typedef struct bn_mont_ctx_st BN_MONT_CTX; +typedef struct bn_recp_ctx_st BN_RECP_CTX; +typedef struct bn_prime_ctx_st BN_PRIME_CTX; +typedef struct bn_blind_ctx_st BN_BLIND_CTX; +typedef struct bn_blind_meth_st BN_BLIND_METH; +#endif + +typedef struct bn_mod_exp_meth_st BN_ME_METH; +typedef struct bn_mod_exp_ctx_st BN_ME_CTX; + + +/* The data array d must always have an extra 'valid' word in location + * bn->d[bn->max]. It must be ok for reading. This is needed if + * BN_MUL_LATENCY is defined. + */ +struct bignum_st + { + BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ + int top; /* Index of last used d +1. */ + /* The next are internal book keeping for bn_expand. */ + int max; /* Size of the d array. */ + int neg; /* one if the number is negative */ + int flags; + }; + +/* Used for temp variables */ +#define BN_CTX_NUM 12 +struct bignum_ctx + { + int tos; + BIGNUM bn[BN_CTX_NUM+1]; + int flags; + R_SURRENDER *surrender; + }; + +#if defined(WIN64) || defined(__ia64__) || defined(CPU_IA64) +#define BN_USHORT unsigned int +#else +#define BN_USHORT unsigned short +#endif + +/* Used for prime number generation */ +struct bn_prime_ctx_st + { + BN_USHORT *primes; + BN_USHORT *mods; + int num_primes; + int prime_checks; + R_SURRENDER *surrender; + R_RANDOM *random; + int flags; + }; + +struct bn_blind_ctx_st + { + int init; + BN_BLIND_METH *meth; + BIGNUM B; + BIGNUM Bi; + BIGNUM mod; + }; + +struct bn_blind_meth_st + { + void (*init) (BN_BLIND_CTX *); + void (*ctx_free)(BN_BLIND_CTX *); + int (*set) (BN_BLIND_CTX *,R_RANDOM *,BIGNUM *,BIGNUM *, BN_ME_CTX *,BN_CTX *); + int (*convert) (BN_BLIND_CTX *,BIGNUM *,BN_CTX *); + int (*invert) (BN_BLIND_CTX *,BIGNUM *,BN_CTX *); + int (*update) (BN_BLIND_CTX *,BN_CTX *); + int (*copy) (BN_BLIND_CTX *,BN_BLIND_CTX *); + }; + +/* Used for montgomery multiplication */ +struct bn_mont_ctx_st + { + int use_word; /* 0 for word form, 1 for long form */ + int ri; /* number of bits in R */ + int riw; /* number of words in R */ + BIGNUM RR; /* used to convert to montgomery form */ + BIGNUM N; /* The modulus */ + BIGNUM Ni; /* The inverse of N */ + BN_ULONG n0; /* word form of inverse, normally only one of + * Ni or n0 is defined */ + int flags; + }; + +/* Used by the recursive exponentiation implementations */ +typedef struct bn_mod_exp_rec_meth_st + { +#ifndef NOPROTO + void (PRE_CCONV CCONV *mul)(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b); + void (PRE_CCONV CCONV *sqr)(BN_ULONG *r, BN_ULONG *a); + void (PRE_CCONV CCONV *low_mul)(); +#else + void (PRE_CCONV CCONV *mul)(); + void (PRE_CCONV CCONV *sqr)(); + void (PRE_CCONV CCONV *low_mul)(); +#endif + } BN_MOD_EXP_REC_METH; + +/* If this flag is set, if there is a custom method for a modulus + * two times larger, use it. This is mostly mean for use on the + * itanium where a 512*512 routine is 10 times faster than the C + * code version, so we need to detect that we can turn of CRT + * for RSA if there is an native IA64 512*512 present. + */ +#define BN_ME_FLG_FAST_ASM 0x0001 + +struct bn_mod_exp_meth_st + { + int num; /* Word size we target */ + char *name; /* Identify the method */ +#ifndef NOPROTO + int (*useit)(const BN_ME_METH *meth); + /* If 'power' is null, reuse the old one */ + int (*mod_exp)(BN_ME_CTX *mctx,BIGNUM *r,BIGNUM *a,BIGNUM *p, + BN_CTX *ctx); + /* Create the BN_ME_CTX */ + int (*init_ctx)(const BN_ME_METH *meth,BN_ME_CTX **mctx); + /* Get rid of it */ + int (*free_ctx)(BN_ME_CTX *mctx); + /* Assign the modulus */ + int (*set)(BN_ME_CTX *mctx,BIGNUM *n,int cmd,int flags,BN_CTX *ctx); +#else + int (*useit)(); + int (*mod_exp)(); + int (*init_ctx)(); + int (*free_ctx)(); + int (*set)(); +#endif + int argi; + char *argp; /* 'Extra stuff' */ + }; + +#define BN_ME_METH_TABLE_MAX 32 +/* Used in BN_library_init */ +#define BN_INIT_LAST 0x00 +#define BN_INIT_BN_ME_METH 0x01 + +#define BN_BNME_F_DEFAULT 0x01 +/* Used only when loading, kept as bits internally, normally loaded as + * words */ +#define BN_BNME_F_BITS 0x02 +typedef struct bn_me_meth_info_st + { +#ifndef NOPROTO + const BN_ME_METH *(*meth)(void); +#else + const BN_ME_METH *(*meth)(); +#endif + int min; + int max; + int flags; + } BN_ME_METH_INFO; + +#define BN_ME_SET_MOD 0x01 +#define BN_ME_SET_BASE 0x02 +#define BN_ME_SET_EXP 0x03 +#define BN_ME_SET_FLG_NO_LOOKUP 0x01 /* Passed to BN_ME_CTX_set() */ + +#define BN_FLG_CACHE 0x10 /* Cache values */ +#define BN_ME_FLG_BASE 0x40 /* base has been cached */ +#define BN_ME_FLG_EXP 0x80 /* power has been cached */ +/* When one of these structures is setup, it is intended that the + * base or power, if not null, will be used for the current calculation. + * If the base and/or power are cached, they will only be used if the input + * value is null. + * For RSA, the power would normally be set. + * For DH, the base and power would be set. The initial value generated + * would be the public key, which is exchanged. The phase2 part would + * change the base but not the power. + * For DSA signing, a fixed base is used, but a random power. + * For DSA verification, there are two bases and two powers, + * a^p%m * b^q%m + * One way to implement this is to use a special function to + * generate a composite power value, and or a special base form. + * The other option is to have a special function to generate + * the 'base' array. The problem is that we are exponentiating with + * a 3 value power value, instead of the normal two. It should be possible + * to use the standard a^b%m function. + */ +struct bn_mod_exp_ctx_st + { + const BN_ME_METH *meth; + char *callback; + char *cb_arg; + int flags; + /* Evil hack for storage of data values, it should really be here + * other than the first value */ + char *modulus; /* eg BN_MONT_CTX */ + char *power; /* eg power representation */ + char *base; /* eg base representation */ + char *arg; + }; + +/* Used for reciprocal division/mod functions + * It cannot be shared between threads + */ +struct bn_recp_ctx_st + { + BIGNUM N; /* the divisor */ + BIGNUM Nr; /* the reciprocal */ + int num_bits; + int shift; + int flags; + }; + +typedef struct bn_rec_st + { + int depth; + int n; +#ifndef NOPROTO + void (PRE_CCONV CCONV *mul)(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b); + void (PRE_CCONV CCONV *sqr)(BN_ULONG *r, BN_ULONG *a); + void (PRE_CCONV CCONV *low_mul)(); +#else + void (PRE_CCONV CCONV *mul)(); + void (PRE_CCONV CCONV *sqr)(); + void (PRE_CCONV CCONV *low_mul)(); +#endif + } BN_REC; + +#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ + r,a,&((mont)->RR),(mont),ctx) + +#define BN_prime_checks (5) + +#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) +#define BN_length(a) ((a)->top * BN_BYTES) +#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) +#define BN_is_zero(a) (((a)->top == 0) || BN_is_word(a,0)) +#define BN_is_one(a) (BN_is_word((a),1)) +#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) +#define BN_one(a) (BN_set_word((a),(BN_ULONG)1)) +#define BN_zero(a) (BN_set_word((a),(BN_ULONG)0)) + +/*#define BN_ascii2bn(a) BN_hex2bn(a) */ +/*#define BN_bn2ascii(a) BN_bn2hex(a) */ + +#define bn_expand(n,b) ((((((b+BN_BITS2-1))/BN_BITS2)) <= (n)->max)?\ + (n):bn_expand2((n),(b)/BN_BITS2+1)) +#define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b))) + +#ifdef SMALL_CODE_SIZE +void bn_zexpand(BIGNUM *a,int n); +void bn_fix_top(BIGNUM *a); +#else +#define bn_zexpand(a,n) \ + if ((a)->top < n) \ + { \ + int i; \ + bn_wexpand((a),n); \ + if ((a)->d!=NULL) \ + { \ + for (i=(a)->top; id[i]=0; \ + } \ + } + +#define bn_fix_top(a) \ + { \ + BN_ULONG *ftl; \ + if ((a)->top > 0) \ + { \ + for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ + if (*(ftl--)) break; \ + } \ + } +#endif + +#define BN_MONT_CTX_set(a,b,c) BN_MONT_CTX_set_word((a),(b),(c)) + +#ifndef NOPROTO + + +const BN_ME_METH *BN_ME_METH_word(void); +const BN_ME_METH *BN_ME_METH_full(void); + +#if (defined(BN_MUL_COMBA) || defined(BN_SQR_COMBA)) + +/* word4 - used for 64bit multiprime*/ +const BN_ME_METH *BN_ME_METH_word4(void); +const BN_ME_METH *BN_ME_METH_rec4_word8(void); +const BN_ME_METH *BN_ME_METH_rec4_word16(void); +const BN_ME_METH *BN_ME_METH_rec4_word32(void); +const BN_ME_METH *BN_ME_METH_rec4_word64(void); +const BN_ME_METH *BN_ME_METH_rec4_word128(void); + +/* word6 - used for 64bit multiprime*/ +const BN_ME_METH *BN_ME_METH_word6(void); +const BN_ME_METH *BN_ME_METH_rec6_word12(void); +const BN_ME_METH *BN_ME_METH_rec6_word24(void); +const BN_ME_METH *BN_ME_METH_rec6_word48(void); +const BN_ME_METH *BN_ME_METH_rec6_word96(void); + +const BN_ME_METH *BN_ME_METH_word8(void); +const BN_ME_METH *BN_ME_METH_rec8_word16(void); +const BN_ME_METH *BN_ME_METH_rec8_word32(void); +const BN_ME_METH *BN_ME_METH_rec8_word64(void); +const BN_ME_METH *BN_ME_METH_rec8_word128(void); +const BN_ME_METH *BN_ME_METH_rec8_word256(void); + +const BN_ME_METH *BN_ME_METH_word11(void); +const BN_ME_METH *BN_ME_METH_rec11_word22(void); +const BN_ME_METH *BN_ME_METH_rec11_word44(void); +const BN_ME_METH *BN_ME_METH_rec11_word88(void); + +const BN_ME_METH *BN_ME_METH_word16(void); +const BN_ME_METH *BN_ME_METH_rec16_word32(void); +const BN_ME_METH *BN_ME_METH_rec16_word64(void); +const BN_ME_METH *BN_ME_METH_rec16_word128(void); +const BN_ME_METH *BN_ME_METH_rec16_word256(void); + +#endif + +#ifdef CPU_IA64 +const BN_ME_METH *BN_ME_METH_ia64_384(void); +const BN_ME_METH *BN_ME_METH_ia64_512(void); +const BN_ME_METH *BN_ME_METH_ia64_1024(void); +#endif + +#if (defined(CPU_SPARC_V8PLUS) || defined (CPU_SPARC_V9)) +const BN_ME_METH *BN_ME_METH_usparc(void); +const BN_ME_METH *BN_ME_METH_usparc_352(void); +const BN_ME_METH *BN_ME_METH_usparc_512(void); +#endif + +#if 1 || defined(CPU_X86) +const BN_ME_METH *BN_ME_METH_pentium4_29(void); +const BN_ME_METH *BN_ME_METH_pentium4_28(void); +#endif + +/* NCipher Nfast hardware accelerator method prototype */ +const BN_ME_METH *BN_ME_METH_nfast(void); + + +BIGNUM *BN_value_one(void); +const char * BN_options(void); +BN_CTX *BN_CTX_new(void); +void BN_CTX_init(BN_CTX *c); +void BN_CTX_free(BN_CTX *c); +#ifndef NO_BN_RAND +int BN_rand(BIGNUM *rnd, R_RANDOM *rand, int bits, int top,int bottom); +#endif +int BN_num_bits(BIGNUM *a); +int BN_num_bits_word(BN_ILONG); +BIGNUM *BN_new(void); +void BN_init(BIGNUM *); +void BN_clear_free(BIGNUM *a); +BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b); +BIGNUM *BN_bin2bn(unsigned char *s,int len,BIGNUM *ret); +int BN_bn2bin(BIGNUM *a, unsigned char *to); +BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret); +int BN_bn2mpi(BIGNUM *a, unsigned char *to); +int BN_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b); +int BN_usub(BIGNUM *r, BIGNUM *a, BIGNUM *b); +int BN_uadd(BIGNUM *r, BIGNUM *a, BIGNUM *b); +int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b); +int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx); +int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx); +int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b,BN_CTX *ctx); +int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx); +BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w); +BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); +int BN_mul_word(BIGNUM *a, BN_ULONG w); +int BN_add_word(BIGNUM *a, BN_ULONG w); +int BN_sub_word(BIGNUM *a, BN_ULONG w); +int BN_set_word(BIGNUM *a, BN_ULONG w); +BN_ULONG BN_get_word(BIGNUM *a); +int BN_cmp(BIGNUM *a, BIGNUM *b); +void BN_free(BIGNUM *a); +int BN_is_bit_set(BIGNUM *a, int n); +int BN_lshift(BIGNUM *r, BIGNUM *a, int n); +int BN_lshift1(BIGNUM *r, BIGNUM *a); +int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx); +int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx); +int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx, + BN_MONT_CTX *m_ctx); +int BN_mod_exp2_mont(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2, + BIGNUM *p2,BIGNUM *m,BN_CTX *ctx,BN_MONT_CTX *m_ctx); +int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, + BIGNUM *m,BN_CTX *ctx); +int BN_mask_bits(BIGNUM *a,int n); +int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, BIGNUM *m, + BN_CTX *ctx); +#if !defined(WIN16) && !defined(NO_FP_API) +int BN_print_fp(FILE *fp, BIGNUM *a); +#endif +#ifdef HEADER_COMMON_BIO_H +int BN_print(BIO *fp, BIGNUM *a); +#else +/* int BN_print(char *fp, BIGNUM *a); */ +#endif +int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx); +int BN_rshift(BIGNUM *r, BIGNUM *a, int n); +int BN_rshift1(BIGNUM *r, BIGNUM *a); +void BN_clear(BIGNUM *a); +BIGNUM *bn_expand2(BIGNUM *b, int bits); +BIGNUM *BN_dup(BIGNUM *a); +int BN_ucmp(BIGNUM *a, BIGNUM *b); +int BN_set_bit(BIGNUM *a, int n); +int BN_clear_bit(BIGNUM *a, int n); +char * BN_bn2hex(BIGNUM *a); +char * BN_bn2dec(BIGNUM *a); +int BN_hex2bn(BIGNUM **a,char *str); +int BN_dec2bn(BIGNUM **a,char *str); +int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx); +BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, BIGNUM *n,BN_CTX *ctx); +/* Return R, where it is R*(1< +#include +//#include "r_error.h" +//#include "err.h" +#include + +#ifndef STANDALONE +#include "r_com.h" +#else +#define NO_STDLIB_MAPPING +#define Malloc(a) malloc(a) +#define Free(a) free(a) +#define Memset(a,b,c) memset(a,b,c) +#define Memcpy(a,b,c) memcpy(a,b,c) +#endif + +/* TEMP FIX */ +#undef BNerr +#define BNerr(a,b) +#include "bn.h" + +#define BN_EXP_TABLE_SIZE 16 + +/* see the bn_limit_ fields which are the start of a runtime + * tunable set of values to match these fixed compile-time constants + */ +/* Pentium pro 16,16,16,32,64 */ +/* Alpha 16,16,16,16.64 */ +/* StrongARM */ +#define BN_MULL_SIZE_NORMAL (16) /* 32 */ +#define BN_MUL_RECURSIVE_SIZE_NORMAL (16) /* 32 */ /* less than */ +#define BN_SQR_RECURSIVE_SIZE_NORMAL (16) /* 32 */ +#define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32) /* 32 */ +#define BN_MONT_CTX_SET_SIZE_WORD (64) /* 32 */ + +/************************************************************* + * Using the long long type + */ +#define Lw(t) (((BN_ULONG)(t))&BN_MASK2) +#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) + +/* These are used for internal error checking and are not normally used */ +#ifdef BN_DEBUG +#define bn_check_top(a) \ + { if ( ((a)->top < 0) || \ + ((a)->top > (a)->max) || \ + (((a)->top == 0) && (a)->neg) || \ + (((a)->top == 1) && (a->d[0] == 0))) \ + { char *nullp=NULL; *nullp='z'; } } +#define bn_check_num(a) if ((a) < 0) { char *nullp=NULL; *nullp='z'; } +#define bn_assert(a) if (!(a)) { char *nullp=NULL; *nullp='z'; } +#define bn_set_used_check(l,size,num) bn_su_check(l,size,num) +#ifdef BN_DEBUG2 +#define bn_do_used_check(fp,str,l,size,num) bn_du_check(fp,str,l,size,num) +#else +#define bn_do_used_check(fp,str,l,size,num) +#endif +#else +#define bn_assert(a) +#define bn_check_top(a) +#define bn_check_num(a) +#define bn_set_used_check(l,size,num) +#define bn_do_used_check(fp,str,l,size,num) +#endif + + +/*********************************************** +* IA64 32 bit build SWIZZLE code +* This essentially casts our points which are +* 32bits under abi32 to 64bit unsigned long +* longs and then grabs the top two bits of the +* pointer and places it in the 2nd and 3rd bits +* of the unsigned long long. +**********************************************/ +#ifdef HPUX_IA64_32 +#define SWIZLLE(VALUE) ((((unsigned long long)(VALUE) & 0xc0000000LL) <<31)\ +|((unsigned long long)(VALUE))) +#else +#define SWIZZLE(VALUE) (VALUE) +#endif + +#define bn_neg_words(a,n) \ + { \ + int iii; \ + \ + for (iii=0; iiimax=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA)) +#else +#define bn_set_max(r) +#endif + +/* These macros are used to 'take' a section of a bignum for read only use */ +#define bn_set_low(r,a,n) \ + { \ + (r)->top=((a)->top > (n))?(n):(a)->top; \ + (r)->d=(a)->d; \ + (r)->neg=(a)->neg; \ + (r)->flags|=BN_FLG_STATIC_DATA; \ + bn_set_max(r); \ + } + +#define bn_set_high(r,a,n) \ + { \ + if ((a)->top > (n)) \ + { \ + (r)->top=(a)->top-n; \ + (r)->d= &((a)->d[n]); \ + } \ + else \ + (r)->top=0; \ + (r)->neg=(a)->neg; \ + (r)->flags|=BN_FLG_STATIC_DATA; \ + bn_set_max(r); \ + } + +/* #define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?(n):bn_expand2((n),(b))) */ + +#ifdef BN_LLONG +#define mul_add(r,a,w,c) { \ + BN_ULLONG t; \ + t=(BN_ULLONG)w * (a) + (r) + (c); \ + (r)= Lw(t); \ + (c)= Hw(t); \ + } + +#define mul(r,a,w,c) { \ + BN_ULLONG t; \ + t=(BN_ULLONG)w * (a) + (c); \ + (r)= Lw(t); \ + (c)= Hw(t); \ + } + +#else +/************************************************************* + * No long long type + */ + +#define LBITS(a) ((a)&BN_MASK2l) +#define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2lh) +#define L2HBITS(a) ((BN_ULONG)((a)&BN_MASK2lh)<>(BN_BITS4-1); \ + m =((m&BN_MASK2l)<<(BN_BITS4+1))&BN_MASK2; \ + l=(l+m)&BN_MASK2; if (l < m) h++; \ + (lo)=l; \ + (ho)=h; \ + } + +#if 0 +#define mul_add(r,a,bl,bh,b_hl,c) { \ + BN_ULONG l,h; \ + BN_ULONG lt,mt; \ + \ + h= (a); \ + l=LBITS(h); \ + h=HBITS(h); \ + mt=bl*l; \ + lt=mt+c+(r); \ + c=bh*h; \ + mt+=c+(l-h)*b_hl; \ + mt+=(lt>>BN_BITS4); \ + (r)=(lt&BN_MASK2l)|((mt&BN_MASK2l)<>BN_BITS4); \ + } +#else /* Normal version */ +#define mul_add(r,a,bl,bh,b_hl,c) { \ + BN_ULONG l,h; \ + \ + h= (a); \ + l=LBITS(h); \ + h=HBITS(h); \ + mul64(l,h,(bl),(bh)); \ + \ + /* non-multiply part */ \ + l=(l+(c))&BN_MASK2; if (l < (c)) h++; \ + (c)=(r); \ + l=(l+(c))&BN_MASK2; if (l < (c)) h++; \ + (c)=h&BN_MASK2; \ + (r)=l; \ + } +#endif + +#define mul(r,a,bl,bh,c) { \ + BN_ULONG l,h; \ + \ + h= (a); \ + l=LBITS(h); \ + h=HBITS(h); \ + mul64(l,h,(bl),(bh)); \ + \ + /* non-multiply part */ \ + l+=(c); if ((l&BN_MASK2) < (c)) h++; \ + (c)=h&BN_MASK2; \ + (r)=l&BN_MASK2; \ + } + +#endif + +#ifndef BN_MUL_COMBA +#define bn_mul_comba4(r,a,b) bn_mul_normal(r,a,4,b,4) +#define bn_mul_comba5(r,a,b) bn_mul_normal(r,a,5,b,5) +#define bn_mul_comba6(r,a,b) bn_mul_normal(r,a,6,b,6) +#define bn_mul_comba8(r,a,b) bn_mul_normal(r,a,8,b,8) +#define bn_mul_comba11(r,a,b) bn_mul_normal(r,a,11,b,11) +#define bn_mul_comba12(r,a,b) bn_mul_normal(r,a,12,b,12) +#define bn_mul_comba16(r,a,b) bn_mul_normal(r,a,16,b,16) +#endif +#if 1 +#ifndef BN_SQR_COMBA +#define bn_sqr_comba4(r,a) bn_mul_normal(r,a,4,a,4) +#define bn_sqr_comba5(r,a) bn_mul_normal(r,a,5,a,5) +#define bn_sqr_comba6(r,a) bn_mul_normal(r,a,6,a,6) +#define bn_sqr_comba8(r,a) bn_mul_normal(r,a,8,a,8) +#define bn_sqr_comba11(r,a) bn_mul_normal(r,a,11,a,11) +#define bn_sqr_comba12(r,a) bn_mul_normal(r,a,12,a,12) +#define bn_sqr_comba16(r,a) bn_mul_normal(r,a,16,a,16) +#endif +#else +#ifndef BN_SQR_COMBA +#define bn_sqr_comba4(r,a) bn_mul_comba4(r,a,a) +#define bn_sqr_comba5(r,a) bn_mul_comba5(r,a,a) +#define bn_sqr_comba6(r,a) bn_mul_comba6(r,a,a) +#define bn_sqr_comba8(r,a) bn_mul_comba8(r,a,a) +#define bn_sqr_comba11(r,a) bn_mul_comba11(r,a,a) +#define bn_sqr_comba12(r,a) bn_mul_comba12(r,a,a) +#define bn_sqr_comba16(r,a) bn_mul_comba16(r,a,a) +#endif +#endif +#ifndef BN_REDUCE_COMBA +#define r0_bn_mont_comba4(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba5(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba6(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba8(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba11(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba12(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#define r0_bn_mont_comba16(r,a,n,num,n0) bn_from_montgomery_words(r,a,n,num,n0) +#endif + +#ifndef NOPROTO + +BIGNUM *bn_expand2(BIGNUM *b, int bits); + +#ifdef X86_ASM +void bn_add_words(BN_ULONG *r,BN_ULONG *a,int num); +#endif + +#else + +BIGNUM *bn_expand2(); +#ifdef X86_ASM +BN_ULONG bn_add_words(); +#endif + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_COMMON_BN_LCL_H */ + +void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,BN_ULONG *t); +void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2, BN_ULONG *t); +int BN_gen_exp_string(unsigned char *str, BIGNUM *p, int bits); +void bn_from_montgomery_rec_full(BN_ULONG *rp, BN_ULONG *ap, + BN_ULONG *np, BN_ULONG *nip, BN_ULONG *tmp,BN_REC *rec); + +int bn_mont_ctx_new_word(const BN_ME_METH *meth, BN_ME_CTX **retp); + diff --git a/build/tools/acsign/include/bn_thx.h b/build/tools/acsign/include/bn_thx.h new file mode 100644 index 00000000..13e157b7 --- /dev/null +++ b/build/tools/acsign/include/bn_thx.h @@ -0,0 +1,301 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/***************************************************************************** + * Copyright (c). 2001 RSA Security Inc. All rights reserved. + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + ****************************************************************************/ +/** + * @file bn_thx.h + * @brief header file created for used as interface defines for systems + * containing hetergeneous environments where some bn operations + * will be performed in isolation from the rest of the library + */ +#ifndef HEADER_COMMON_BN_THX_H +#define HEADER_COMMON_BN_THX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* These defines are required on systems so that the mod_exp code + * to be used in isolation from the bn operation with library will work, + * if these are not available, the header files with equivalent functionality + * should be added inside a CPU or Operating system define + */ +#ifndef NO_STDIO_H +#include +#endif + +#ifndef NO_STDLIB_H +#include +#endif + +#ifndef NO_STRING_H +#include +#endif + +/* Interface for ARM/DSP systems, this interface requires only + * the standard defines and includes at the moment + */ +#ifdef CPU_TMS320 +#define THX_RECIPIENT +#define CPU_DSP +#endif + +#ifdef THX_RECIPIENT + +#ifndef restrict +#define restrict +#endif + +#ifndef Malloc +#define Malloc malloc +#endif + +#ifndef Memcpy +#define Memcpy memcpy +#endif + +#ifndef Memmove +#define Memmove memmove +#endif + +#ifndef Memset +#define Memset memset +#endif + +#ifndef Free +#define Free free +#endif + +#endif /* THX_RECIPIENT */ + +#ifndef THX_RECIPIENT /* not the recipient, we must be the caller */ + +#include "bn_lcl.h" + +#endif /* ! THX_RECIPIENT */ + +/* The follow define protected inclusions are excerpts from the + * header file bn.h, this has been done, so that code written for the + * THX systems can be used in isolation from the library + * This code may need to be updated in line with changes to the bn.h + * header file. + */ +#ifndef HEADER_COMMON_BN_H +#define HEADER_COMMON_BN_H + +#if !defined(CCONV) +#define CCONV +#endif + +#ifndef PRE_CCONV +#define PRE_CCONV +#endif + +/* convert from the new to the old option names */ +#if defined(OPT_BN_LLONG) +#define BN_LLONG /* comment to make sure Configure leaves this alone */ +#endif + +#if defined(OPT_32_BIT_INT) || defined(OPT_32_BIT) +#define THIRTY_TWO_BIT +#endif + +#define BN_ILONG BN_ULONG + +#ifdef THIRTY_TWO_BIT +#define BN_ULLONG unsigned long long +#ifdef OPT_32_BIT_INT +#define BN_ULONG unsigned int +#define BN_LONG int +#else +#define BN_ULONG unsigned long +#define BN_LONG long +#endif +#define BN_BITS 64 +#define BN_BYTES 4 +#define BN_BITS2 32 +#define BN_BITS4 16 +/* This is needed because the Watcom compiler pre-processor + * under QNX is perverted and tries to parses the 'LL' + * part even though it is never used. + */ +#ifdef BN_LLONG +#define BN_MASK (0xffffffffffffffffL) +#endif +#define BN_MASK2 (0xffffffffL) +#define BN_MASK2l (0xffff) +#define BN_MASK2lh (0xffff) +#define BN_MASK2h1 (0xffff8000L) +#define BN_MASK2h (0xffff0000L) +#define BN_TBIT (0x80000000L) +#define BN_DEC_CONV (1000000000L) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%09lu" +#define BN_DEC_NUM 9 +#define BN_HEX_FMT "%08lX" +#endif + +#define BN_EXP_TABLE_SIZE 16 + +typedef struct bignum_st BIGNUM; + +struct bignum_st + { + BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ + int top; /* Index of last used d +1. */ + /* The next are internal book keeping for bn_expand. */ + int max; /* Size of the d array. */ + int neg; /* one if the number is negative */ + int flags; + }; + +PRE_CCONV BN_ULONG CCONV bn_mul_add_words(BN_ULONG *rp,BN_ULONG *ap, + int num, BN_ULONG w); +PRE_CCONV BN_ULONG CCONV bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, + int num, BN_ULONG w); +PRE_CCONV void CCONV bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num); +BN_ULONG CCONV bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d); +PRE_CCONV BN_ULONG CCONV bn_add_words(BN_ULONG *rp, BN_ULONG *ap, + BN_ULONG *bp,int num); +PRE_CCONV BN_ULONG CCONV bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, + BN_ULONG *bp,int num); + +#ifndef BN_ME_METH +#define BN_ME_METH void +#endif + +#endif /* ! HEADER_COMMON_BN_H */ + +/* The follow define protected inclusions are excerpts from the + * header file r_error.h, this has been done, so that code written for the + * THX systems can be used in isolation from the library + * This code may need to be updated in line with changes to the r_error.h + * header file. + */ +#ifndef HEADER_COMMON_R_ERROR_H +#define HEADER_COMMON_R_ERROR_H + +/* The FATAL_INTERNAL_ERROR is a flag that is set with the following + * error codes: + * R_ERROR_INVALID_STATE + * R_ERROR_INIT_NOT_CALLED + * R_ERROR_SHOULD_NOT_HAVE_BEEN_CALLED + */ +#define R_ERROR_FATAL_INTERNAL_ERROR 64 + +/* The BAD_PARAMETER is a flag that is set with the following error + * codes: + * R_ERROR_NULL_ARG + * R_ERROR_BUFFER_TOO_SMALL + * R_ERROR_BAD_VALUE + * R_ERROR_BAD_RANGE + * R_ERROR_BAD_FORMAT + * R_ERROR_BAD_TYPE + * R_ERROR_BAD_DATA + * R_ERROR_BAD_LENGTH + */ +#define R_ERROR_BAD_PARAMETER 32 + +/* Base value for all general errors used through all products */ +#define R_ERROR_BASE 10000 + +#define R_ERROR_NONE 0 + +#define R_ERROR_FAILED (R_ERROR_BASE+1) +#define R_ERROR_IO (R_ERROR_BASE+2) +#define R_ERROR_PROTOCOL (R_ERROR_BASE+3) +#define R_ERROR_EOF (R_ERROR_BASE+4) +#define R_ERROR_ALLOC_FAILURE (R_ERROR_BASE+5) +#define R_ERROR_EVAL_RESTRICTION (R_ERROR_BASE+6) +#define R_ERROR_EVAL_EXPIRED (R_ERROR_BASE+7) +#define R_ERROR_NOT_FOUND (R_ERROR_BASE+8) +#define R_ERROR_NOT_AVAILABLE (R_ERROR_BASE+9) +#define R_ERROR_NOT_IMPLEMENTED (R_ERROR_BASE+10) +#define R_ERROR_NOT_SUPPORTED (R_ERROR_BASE+11) +#define R_ERROR_INVALID_STATE \ + ((R_ERROR_BASE+12) | R_ERROR_FATAL_INTERNAL_ERROR) +#define R_ERROR_INIT_NOT_CALLED \ + ((R_ERROR_BASE+13) | R_ERROR_FATAL_INTERNAL_ERROR) +#define R_ERROR_SHOULD_NOT_HAVE_BEEN_CALLED \ + ((R_ERROR_BASE+14) | R_ERROR_FATAL_INTERNAL_ERROR) +#define R_ERROR_METHOD_UNDEFINED \ + ((R_ERROR_BASE+15) | R_ERROR_FATAL_INTERNAL_ERROR) +#define R_ERROR_BUFFER_TOO_SMALL \ + ((R_ERROR_BASE+16) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_NULL_ARG ((R_ERROR_BASE+17) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_VALUE ((R_ERROR_BASE+18) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_RANGE ((R_ERROR_BASE+19) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_FORMAT ((R_ERROR_BASE+20) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_TYPE ((R_ERROR_BASE+21) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_DATA ((R_ERROR_BASE+22) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_BAD_LENGTH ((R_ERROR_BASE+23) | R_ERROR_BAD_PARAMETER) +#define R_ERROR_RCOM_LIBRARY_NOT_SUPPORTED (R_ERROR_BASE+24) + +/* Resource Manager base for errors */ +#define R_COM_ERR_LIB_CTX_BASE 10100 + +#endif /* HEADER_COMMON_R_ERROR_H */ + + +const BN_ME_METH *BN_ME_METH_thxc(void); +/** + * @note THX code only needs to store rr, n0, str + * + */ +typedef struct thxc_mont_ctx_st + { + BIGNUM *rr; + unsigned char *str; + unsigned int str_len; + BN_ULONG n0; + } THXC_MONT_CTX; + + +int Rx_thxr_mod_exp_mont( BN_ULONG *result, BN_ULONG *ap, BN_ULONG *np, + BN_ULONG *rrp, BN_ULONG n0, int top, int tmp_len, unsigned char *str); + +int Ri_thxr_mod_exp_mont( BN_ULONG *result, BN_ULONG *ap, BN_ULONG *np, + BN_ULONG *rrp, BN_ULONG *dp, BN_ULONG *aap, BN_ULONG *rp, BN_ULONG *tmp, + BN_ULONG n0, int top, unsigned char *str); + +void Ri_thxr_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb); +void Ri_thxr_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp); + +void Ri_thxr_from_montgomery_words(BN_ULONG *ret,BN_ULONG *ap,BN_ULONG *np, + int w, BN_ULONG n0); + +BN_ULONG Ri_thxr_from_mont_words(BN_ULONG *ap,BN_ULONG *wap, + BN_ULONG *np, int w, BN_ULONG n0); + +#ifdef CPU_TMS320 + +/* Method and functions required for the ARM/DSP interface */ + +const BN_ME_METH *BN_ME_METH_dspc(void); + +int Rx_dsp_mod_exp_mont( BN_ULONG *result, BN_ULONG *ap, BN_ULONG *np, + BN_ULONG *rrp, BN_ULONG n0, int top, int tmp_len, unsigned char *str); + +int Ri_dsp_mod_exp_mont( BN_ULONG *result, BN_ULONG *ap, BN_ULONG *np, + BN_ULONG *rrp, BN_ULONG *dp, BN_ULONG *aap, BN_ULONG *rp, BN_ULONG *tmp, + BN_ULONG n0, int top, unsigned char *str); + +#endif + +#ifdef __cplusplus +} +#endif +#endif /* HEADER_COMMON_BN_THX_H */ diff --git a/build/tools/acsign/include/r_error.h b/build/tools/acsign/include/r_error.h new file mode 100644 index 00000000..8e269f36 --- /dev/null +++ b/build/tools/acsign/include/r_error.h @@ -0,0 +1,210 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/** + * @file r_error.h + * This file contains the error definitions for the toolkit. + */ +#ifndef HEADER_COMMON_R_ERROR_H +#define HEADER_COMMON_R_ERROR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup R_ERROR_IDS Error Identifiers + * This section outlines the error codes returned, enabling identification of + * specific errors. For more information, see the + * Developer's Guide. + * + * @{ + */ +/** + * Indicates that a fatal error has occurred in the operation performed. + * This flag is set with the following error codes:
    + *
      + *
    • #R_ERROR_INVALID_STATE.
    • + *
    • #R_ERROR_INIT_NOT_CALLED.
    • + *
    • #R_ERROR_SHOULD_NOT_HAVE_BEEN_CALLED.
    • + *
    + */ +#define R_ERROR_FATAL_INTERNAL_ERROR 64 + +/** + * Indicates that the specified parameter is incorrect or contains invalid + * information. This flag is set with the following error codes:
    + *
      + *
    • #R_ERROR_NULL_ARG.
    • + *
    • #R_ERROR_BUFFER_TOO_SMALL.
    • + *
    • #R_ERROR_BAD_VALUE.
    • + *
    • #R_ERROR_BAD_RANGE.
    • + *
    • #R_ERROR_BAD_FORMAT.
    • + *
    • #R_ERROR_BAD_TYPE.
    • + *
    • #R_ERROR_BAD_DATA.
    • + *
    • #R_ERROR_BAD_LENGTH.
    • + *
    + */ +#define R_ERROR_BAD_PARAMETER 32 + +/* Indicates the base value for all general errors used through all products */ +#define R_ERROR_BASE 10000 + +/** + * Indicates that no errors were detected in the requested operation. + */ +#define R_ERROR_NONE 0 + +/** + * Indicates that the requested operation failed. + */ +#define R_ERROR_FAILED (R_ERROR_BASE+1) +/** + * Indicates that the requested operation detected an Input/Output error. + */ +#define R_ERROR_IO (R_ERROR_BASE+2) +/** + * Indicates that the requested operation detected a protocol error. + */ +#define R_ERROR_PROTOCOL (R_ERROR_BASE+3) +/** + * Indicates that the requested operation detected an End-of-File (EOF) error. + */ +#define R_ERROR_EOF (R_ERROR_BASE+4) +/** + * Indicates that the requested operation failed in a memory allocation + * operation. + */ +#define R_ERROR_ALLOC_FAILURE (R_ERROR_BASE+5) +/** + * Indicates that the requested operation is restricted in an evaluation + * version of the library. + */ +#define R_ERROR_EVAL_RESTRICTION (R_ERROR_BASE+6) +/** + * Indicates that the evaluation period of the library has expired. + */ +#define R_ERROR_EVAL_EXPIRED (R_ERROR_BASE+7) +/** + * Indicates that the requested operation detected that a pre-requirement was + * not found. + */ +#define R_ERROR_NOT_FOUND (R_ERROR_BASE+8) +/** + * Indicates that the requested operation detected that a pre-requirement was + * unavailable. + */ +#define R_ERROR_NOT_AVAILABLE (R_ERROR_BASE+9) +/** + * Indicates that the requested operation is not implemented in the current + * instantiation of the library. + */ +#define R_ERROR_NOT_IMPLEMENTED (R_ERROR_BASE+10) +/** + * Indicates that the requested operation is not supported in the current + * instantiation of the library. + */ +#define R_ERROR_NOT_SUPPORTED (R_ERROR_BASE+11) +/** + * Indicates that the requested operation entered an invalid state. + */ +#define R_ERROR_INVALID_STATE \ + ((R_ERROR_BASE+12) | R_ERROR_FATAL_INTERNAL_ERROR) +/** + * Indicates that the requested operation detected that an initialization + * operation has not been performed. + */ +#define R_ERROR_INIT_NOT_CALLED \ + ((R_ERROR_BASE+13) | R_ERROR_FATAL_INTERNAL_ERROR) +/** + * Indicates that the requested operation should not have been called. + */ +#define R_ERROR_SHOULD_NOT_HAVE_BEEN_CALLED \ + ((R_ERROR_BASE+14) | R_ERROR_FATAL_INTERNAL_ERROR) +/** + * Indicates that the requested method is not defined. + */ +#define R_ERROR_METHOD_UNDEFINED \ + ((R_ERROR_BASE+15) | R_ERROR_FATAL_INTERNAL_ERROR) +/** + * Indicates that the requested operation detected an inadequately sized + * buffer. + */ +#define R_ERROR_BUFFER_TOO_SMALL \ + ((R_ERROR_BASE+16) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * was passed as NULL. + */ +#define R_ERROR_NULL_ARG ((R_ERROR_BASE+17) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed contained a bad or incorrect value. + */ +#define R_ERROR_BAD_VALUE ((R_ERROR_BASE+18) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed was out of the allowed range. + */ +#define R_ERROR_BAD_RANGE ((R_ERROR_BASE+19) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed used a format that is not supported or incorrect. + */ +#define R_ERROR_BAD_FORMAT ((R_ERROR_BASE+20) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed used a type that is not supported or incorrect. + */ +#define R_ERROR_BAD_TYPE ((R_ERROR_BASE+21) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed contained incorrect or invalid data. + */ +#define R_ERROR_BAD_DATA ((R_ERROR_BASE+22) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the requested operation detected that a required argument + * passed contained an incorrect length value. + */ +#define R_ERROR_BAD_LENGTH ((R_ERROR_BASE+23) | R_ERROR_BAD_PARAMETER) +/** + * Indicates that the library instantiation requested is not supported. + */ +#define R_ERROR_RCOM_LIBRARY_NOT_SUPPORTED (R_ERROR_BASE+24) +/** + * Indicates that the request operation was denied. + */ +#define R_ERROR_DENIED (R_ERROR_BASE+25) +/** + * Indicates that authentication is required before the operation + * can succeed. + */ +#define R_ERROR_AUTHENTICATION_REQUIRED (R_ERROR_BASE+26) + +/** + * Indicates that a required module was unable to be loaded. + */ +#define R_ERROR_MODULE_LOAD_FAILED \ + ((R_ERROR_BASE+27)|R_ERROR_FATAL_INTERNAL_ERROR) + +/* Resource Manager base for errors */ +#define R_COM_ERR_LIB_CTX_BASE 10100 + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif /* HEADER_COMMON_R_ERROR_H */ + + + diff --git a/build/tools/acsign/include/r_stdiag.h b/build/tools/acsign/include/r_stdiag.h new file mode 100644 index 00000000..566de6fa --- /dev/null +++ b/build/tools/acsign/include/r_stdiag.h @@ -0,0 +1,82 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +/* + * *************************************************************************** + * + * Purpose: + * + * This file defines an API for performing stack diagnostics. + * + * It provides: + * Peek Stack Usage statistics + * To use it: + * 1. Build the library without "NO_R_DIAG" defined + * 2. Make a call to R_DIAG_set_stack_datum() prior to + * calling the first library function. + * 3. Add calls to the macro R_DIAG_CHECK_STACK where potential + * high stack usage points are. + * 4. Call R_DIAG_get_stack_low_water_mark() at then end of the + * library calls to return the maximum stack usage OR + * 5. Call R_DIAG_print_stack_depth() to display the peek stack + * usage + * + * + * + * History: + * 3-Aug-00 mjs development + * + * ************************************************************************** + */ + + +#ifndef HEADER_COMMON_R_STDIAG_H +#define HEADER_COMMON_R_STDIAG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NO_R_DIAG + +#ifdef NOPROTO +int R_DIAG_set_stack_datum(char *ptr); +int R_DIAG_check_stack(char *ptr, char *file, int line, int hit); +int R_DIAG_get_stack_low_water_mark(int *depth, char **file, int *line, + int *hit); +int R_DIAG_print_stack_depth(BIO *bio); + +#else + +int R_DIAG_set_stack_datum(); +int R_DIAG_check_stack(); +int R_DIAG_get_stack_low_water_mark(); +int R_DIAG_print_stack_depth(); + +#endif + +#define R_DIAG_CHECK_STACK {\ + char r_diag_stack_check_var = 0;\ + static int r_diag_stack_check_cnt = 0;\ +\ + R_DIAG_check_stack(&r_diag_stack_check_var, __FILE__,\ + __LINE__,++r_diag_stack_check_cnt);\ + } +#else +#define R_DIAG_CHECK_STACK +#endif + + +#ifdef __cplusplus +} +#endif +#endif /* HEADER_COMMON_R_STDIAG_H */ + diff --git a/build/tools/acsign/include/r_types.h b/build/tools/acsign/include/r_types.h new file mode 100644 index 00000000..d35556ad --- /dev/null +++ b/build/tools/acsign/include/r_types.h @@ -0,0 +1,241 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ +/** + * @file r_types.h + * This file contains the library structure and type definitions. + */ +#ifndef HEADER_COMMON_R_TYPES_H +#define HEADER_COMMON_R_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup DATA_MNG_FLAGS Data Management Flags + * This section lists the data management flags. + * @{ + */ + +/** + * @} + */ + +/* This gets set if the flags field if the we need to 'free' the + * R_RANDOM when we call R_rand_free(). If it is not set, the + * rand_ctrl will only be called to clean things up. + */ +#define R_RANDOM_FLG_MALLOCED 0x01 + +/* portable form of a random callback function */ +/** + * @typedef R_RANDOM + * The random object type. + */ +typedef struct r_random_st R_RANDOM; +/** + * This structure is used by the random object type. + */ +struct r_random_st +{ + /** + * A method function for generation of random data. + * + * @see R_rand_bytes(). + */ + int (*rand_bytes)(R_RANDOM *ctx,unsigned char *bytes,int len); + /** + * A method function for seeding of the random generator. + * @see R_rand_seed(). + */ + int (*rand_seed)(R_RANDOM *ctx,unsigned char *bytes,int len); + /** + * A method function for control of the random generator used by + * other functions as a single interface. + * + * @see R_rand_entropy_count(), R_rand_set_entropy_func(), + * R_rand_get_entropy_func(), R_rand_load_file(), R_rand_write_file() + * and R_rand_file_name(). + */ + int (*rand_ctrl)(R_RANDOM *ctx,int op,char *arg); + /** + * The data used by the random implementation. + */ + char *arg; + /** + * A method flag for used for keeping the state of the #R_RANDOM. + */ + int flags; /* normally set to zero */ +}; +/** + * @typedef R_SURRENDER + * The surrender function and argument. + */ +typedef struct r_surrender_st R_SURRENDER; +/** + * This structure provides a status update of a time intensive operation. It + * also allows you to abort the operation if required. + */ +struct r_surrender_st +{ + /* Return 0 to continue, non-zero to 'cancel' function */ + /** + * The surrender function pointer used as a generic method of + * passing user-defined callback or information collection functions. + */ + int (*callback)(R_SURRENDER *ctx,int function,int num); + /** + * The argument data used by the callback operation. + */ + char *arg; +}; + +typedef struct r_fixed_point_number_st R_FIXED_POINT_NUMBER; +struct r_fixed_point_number_st +{ + unsigned long hi; + unsigned long lo; +}; + +/** + * @typedef R_INDEXED_INFO + * This structure details the index containing information for get and set + * functions. + */ +typedef struct r_indexed_info_st R_INDEXED_INFO; +/** This structure details the index containing information for get and set + * functions. + */ +struct r_indexed_info_st +{ + /** The index into the list of the item to work with. */ + int index; + /** The data of the item in the list. */ + void *data; + /** The length of the data. */ + unsigned int len; + /** The data value as an integer. */ + int value; +}; + +/** + * @typedef R_ID_INFO + * The information to work with requires a second identity value to find it. + */ +typedef struct r_id_info_st R_ID_INFO; +/** The information to get or set requires a second information identifier. + * This type is used when calling set_info and get_info to get a number of + * information items in one call. + */ +struct r_id_info_st +{ + /** The information identifier. */ + int info_id; + /** The information data associated with the identifier. */ + void *value; +}; + +/** @defgroup R_FLAG_COPY_IDS Copy Flag Identifiers + * + * This section provides information on the copy mode. When data is passed + * to/from the library you can specify whether or not the copy should be done + * by value, by reference or by direct assignment. + * @ingroup DATA_MNG_FLAGS + * @{ + */ + +/** + * The copy flag. When data is passed to/from the library you can specify + * whether or not the copy should be done by value, by reference or + * by direct assignment. + */ +typedef int R_FLAG_COPY; + +/* + * action flag app lib + * obj_get BY_VAL F X + * BY_REF X F [app will not free "obj" until it is + * BY_ASSIGN F X finished with the returned reference] + * obj_set BY_VAL F X + * BY_REF F X [app will not free passed reference + * BY_ASSIGN X F until after it has freed "obj"] + * + * BY_REF makes the lifetime of the two objects linked and it is up to + * the application to manage the objects in a manner that preserves this + * relationship. + */ + +/** + * Indicates to copy by value. A complete clone of the object is made. + * The lifecycles of the two objects are independent. + */ +#define R_FLAG_COPY_BY_VALUE 0x0000 + +/** + * Indicates to copy by reference. A reference to the object is made. + * The lifecycles of objects sharing references are linked. + */ +#define R_FLAG_COPY_BY_REFERENCE 0x0001 + +/** + * Indicates to copy by assignment. The object is assigned to the required + * party. The caller does not keep a reference to the passed object. + */ +#define R_FLAG_COPY_BY_ASSIGN 0x0002 + +/** + * Indicates to copy using the default flag settings. + */ +#define R_FLAG_COPY_DEFAULT R_FLAG_COPY_BY_VALUE + +/** + * @} + */ + +/** @defgroup R_FLAG_SHARE_IDS Shared Flag Identifiers + * + * This section provides information on the shared flags available. + * @ingroup DATA_MNG_FLAGS + * @{ + */ + +/** + * The constructor flag. Indicates whether or not it is permissible to share + * the internal state between objects. + */ +typedef int R_FLAG_SHARE; + +/** + * Indicates to share nothing. The states of the two objects are completely + * separate. + */ +#define R_FLAG_SHARE_NONE 0x0000 + +/** + * Indicates to share data. Constructed objects may reference the state of + * the object from which it was constructed. The lifecycles of the two objects + * are linked. + */ +#define R_FLAG_SHARE_DATA 0x0001 + +/** Indicates the share default in which nothing is shared. */ +#define R_FLAG_SHARE_DEFAULT R_FLAG_SHARE_NONE + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/build/tools/acsign/include/sha.h b/build/tools/acsign/include/sha.h new file mode 100644 index 00000000..d6eeed2b --- /dev/null +++ b/build/tools/acsign/include/sha.h @@ -0,0 +1,89 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#ifndef HEADER_COMMON_SHA_H +#define HEADER_COMMON_SHA_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(CCONV) +#define CCONV +#endif + +#ifndef PRE_CCONV +#define PRE_CCONV +#endif + +#define SHA_CBLOCK 64 +#define SHA_LBLOCK 16 +#define SHA_BLOCK 16 +#define SHA_LAST_BLOCK 56 +#define SHA_LENGTH_BLOCK 8 +#define SHA_DIGEST_LENGTH 20 + +/* the default is to use unsigned long */ +#if !defined(OPT_SHA_INT) && !defined(OPT_SHA_LONG) +#define OPT_SHA_LONG +#endif + +#ifdef OPT_SHA_LONG +#define SHA_LONG unsigned long +#endif + +#ifdef OPT_SHA_INT +#define SHA_LONG unsigned int +#endif + +typedef struct sha_ctx_st SHA_CTX; + +struct sha_ctx_st + { + SHA_LONG h0,h1,h2,h3,h4; + SHA_LONG Nl,Nh; + SHA_LONG data[SHA_LBLOCK]; + int num; + void (PRE_CCONV CCONV *sha_block)(SHA_CTX *c, const unsigned char *W, + int num); + }; + +#ifndef NOPROTO +int SHA1_Setup(SHA_CTX *c, void (PRE_CCONV CCONV *sha_block)(SHA_CTX *c, + const unsigned char *W, int num)); +void SHA_Init(SHA_CTX *c); +void SHA_Update(SHA_CTX *c, const unsigned char *data, unsigned long len); +void SHA_Final(unsigned char *md, SHA_CTX *c); +unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md); +void SHA_Transform(SHA_CTX *c, const unsigned char *data); +void SHA1_Init(SHA_CTX *c); +void SHA1_Update(SHA_CTX *c, const unsigned char *data, unsigned long len); +void SHA1_Final(unsigned char *md, SHA_CTX *c); +unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md); +void SHA1_Transform(SHA_CTX *c, const unsigned char *data); +#else +void SHA_Init(); +void SHA_Update(); +void SHA_Final(); +unsigned char *SHA(); +void SHA_Transform(); +void SHA1_Init(); +void SHA1_Update(); +void SHA1_Final(); +unsigned char *SHA1(); +void SHA1_Transform(); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_COMMON_SHA_H */ diff --git a/build/tools/acsign/include/sha1.h b/build/tools/acsign/include/sha1.h new file mode 100644 index 00000000..ed4a672e --- /dev/null +++ b/build/tools/acsign/include/sha1.h @@ -0,0 +1,73 @@ +/* + * sha1.h + * + * Description: + * This is the header file for code which implements the Secure + * Hashing Algorithm 1 as defined in FIPS PUB 180-1 published + * April 17, 1995. + * + * Many of the variable names in this code, especially the + * single character names, were used because those were the names + * used in the publication. + * + * Please read the file sha1.c for more information. + * + */ + +#ifndef _SHA1_H_ +#define _SHA1_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _SHA_enum_ +#define _SHA_enum_ +enum +{ + shaSuccess = 0, + shaNull, /* Null pointer parameter */ + shaInputTooLong, /* input data too long */ + shaStateError /* called Input after Result */ +}; +#endif + +/* + * This structure will hold context information for the SHA-1 + * hashing operation + */ +typedef struct SHA1Context +{ + unsigned long Intermediate_Hash[20/4]; /* Message Digest */ + + unsigned long Length_Low; /* Message length in bits */ + unsigned long Length_High; /* Message length in bits */ + + int Message_Block_Index; /* Index into message block array */ + unsigned char Message_Block[64]; /* 512-bit message blocks */ + + int Computed; /* Is the digest computed? */ + int Corrupted; /* Is the message digest corrupted? */ +} SHA1Context; + +/* + * Function Prototypes + */ + +int SHA1Reset( SHA1Context *); +int SHA1Input( SHA1Context *, + const unsigned char *, + unsigned int); +int SHA1Result( SHA1Context *, + unsigned char Message_Digest[20]); + +#if defined( SHA1_TEST ) +int SHA1Test( ); +#endif // SHA1_TEST + + +#ifdef __cplusplus +} +#endif + +#endif // _SHA1_H_ diff --git a/build/tools/acsign/include/sha_locl.h b/build/tools/acsign/include/sha_locl.h new file mode 100644 index 00000000..2361282b --- /dev/null +++ b/build/tools/acsign/include/sha_locl.h @@ -0,0 +1,274 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +#ifndef HEADER_COMMON_SHA_LOCL_H +#define HEADER_COMMON_SHA_LOCL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef STANDALONE +//#include "r_com.h" +#else +#if 1 //RSA +#include +#include +#include +//#define Memcpy memcpy +//#define Memset memset +#define Strcpy strcpy +#else //NITRO +#include "acmemory.h" +#define Malloc(a) ACMemory_Alloc(a) +#define Free(a) ACMemory_Free(a) +#define Memset(a,b,c) ACMemory_Memset(a,b,c) +#define Memcpy(a,b,c) ACMemory_Memcpy(a,b,c) +#endif +#endif + +#ifdef undef +/* one or the other must be defined */ +#ifndef SHA_1 /* FIPE 180-1 */ +#define SHA_0 /* FIPS 180 */ +#endif +#endif + +#define ULONG unsigned long +#define UCHAR unsigned char +#define UINT unsigned int + +#ifdef NOCONST +#define const +#endif + +#undef c2nl +#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ + l|=(((unsigned long)(*((c)++)))<<16), \ + l|=(((unsigned long)(*((c)++)))<< 8), \ + l|=(((unsigned long)(*((c)++))) )) + +#undef p_c2nl +#define p_c2nl(c,l,n) { \ + switch (n) { \ + case 0: l =((unsigned long)(*((c)++)))<<24; \ + case 1: l|=((unsigned long)(*((c)++)))<<16; \ + case 2: l|=((unsigned long)(*((c)++)))<< 8; \ + case 3: l|=((unsigned long)(*((c)++))); \ + } \ + } + +#undef c2nl_p +/* NOTE the pointer is not incremented at the end of this */ +#define c2nl_p(c,l,n) { \ + l=0; \ + (c)+=n; \ + switch (n) { \ + case 3: l =((unsigned long)(*(--(c))))<< 8; \ + case 2: l|=((unsigned long)(*(--(c))))<<16; \ + case 1: l|=((unsigned long)(*(--(c))))<<24; \ + } \ + } + +#undef p_c2nl_p +#define p_c2nl_p(c,l,sc,len) { \ + switch (sc) \ + { \ + case 0: l =((unsigned long)(*((c)++)))<<24; \ + if (--len == 0) break; \ + case 1: l|=((unsigned long)(*((c)++)))<<16; \ + if (--len == 0) break; \ + case 2: l|=((unsigned long)(*((c)++)))<< 8; \ + } \ + } + +#undef nl2c +#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16)&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ + *((c)++)=(unsigned char)(((l) )&0xff)) + +#undef c2l +#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ + l|=(((unsigned long)(*((c)++)))<< 8), \ + l|=(((unsigned long)(*((c)++)))<<16), \ + l|=(((unsigned long)(*((c)++)))<<24)) + +#undef p_c2l +#define p_c2l(c,l,n) { \ + switch (n) { \ + case 0: l =((unsigned long)(*((c)++))); \ + case 1: l|=((unsigned long)(*((c)++)))<< 8; \ + case 2: l|=((unsigned long)(*((c)++)))<<16; \ + case 3: l|=((unsigned long)(*((c)++)))<<24; \ + } \ + } + +#undef c2l_p +/* NOTE the pointer is not incremented at the end of this */ +#define c2l_p(c,l,n) { \ + l=0; \ + (c)+=n; \ + switch (n) { \ + case 3: l =((unsigned long)(*(--(c))))<<16; \ + case 2: l|=((unsigned long)(*(--(c))))<< 8; \ + case 1: l|=((unsigned long)(*(--(c)))); \ + } \ + } + +#undef p_c2l_p +#define p_c2l_p(c,l,sc,len) { \ + switch (sc) \ + { \ + case 0: l =((unsigned long)(*((c)++))); \ + if (--len == 0) break; \ + case 1: l|=((unsigned long)(*((c)++)))<< 8; \ + if (--len == 0) break; \ + case 2: l|=((unsigned long)(*((c)++)))<<16; \ + } \ + } + +#undef l2c +#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16)&0xff), \ + *((c)++)=(unsigned char)(((l)>>24)&0xff)) + +#ifdef OPT_SHA_B_ENDIAN +#define B_ENDIAN +#endif +#ifdef OPT_SHA_L_ENDIAN +#define L_ENDIAN +#endif + +#undef ROTATE +#if defined(WIN32) +#define ROTATE(a,n) _lrotl(a,n) +#else +#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) +#endif + +/* byte order reversal */ +#if defined(WIN32) +/* 5 instructions with rotate instruction, else 9 */ +#define Endian_Reverse32(a) \ + { \ + unsigned long l=(a); \ + (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ + } +#else +/* 6 instructions with rotate instruction, else 8 */ +#define Endian_Reverse32(a) \ + { \ + unsigned long l=(a); \ + l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ + (a)=ROTATE(l,16L); \ + } +#endif + +/* F() below can be + * simplified to the code in F_00_19. + * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) + * another tweak to be made + * in F_40_59, (x&a)|(y&a) -> (x|y)&a + */ +#define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) +#define F_20_39(b,c,d) ((b) ^ (c) ^ (d)) +#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) +#define F_60_79(b,c,d) F_20_39(b,c,d) + +#ifdef SHA_0 +#undef Xupdate +#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\ + (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]); +#endif +#ifdef SHA_1 +#undef Xupdate +#define Xupdate(a,i,ia,ib,ic,id) (a)=\ + (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\ + X[(i)&0x0f]=(a)=ROTATE((a),1); +#endif + +#define BODY_00_15(i,a,b,c,d,e,f,xa) \ + (f)=xa[i]+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_60_79(i,a,b,c,d,e,f,xa) \ + Xupdate(f,i,xa,xa,xa,xa); \ + (f)=X[(i)&0x0f]+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \ + (b)=ROTATE((b),30); + +/* + * The CodeWarrior compiler has a problem correctly expanding things like + * + * (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); + * + * so we separate this to 3 explicit adds, just for PalmOS. + */ +#ifndef UNDER_PALMOS + +#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \ + Xupdate(f,i,xa,xb,xc,xd); \ + (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \ + Xupdate(f,i,xa,xb,xc,xd); \ + (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_32_39(i,a,b,c,d,e,f,xa) \ + Xupdate(f,i,xa,xa,xa,xa); \ + (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_40_59(i,a,b,c,d,e,f,xa) \ + Xupdate(f,i,xa,xa,xa,xa); \ + (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#else /* UNDER_PALMOS */ + +#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \ + Xupdate(f,i,xa,xb,xc,xd); \ + (f)+=(e); \ + (f)+=K_00_19; \ + (f)+=ROTATE((a),5)+F_00_19((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \ + Xupdate(f,i,xa,xb,xc,xd); \ + (f)+=(e); \ + (f)+=K_20_39; \ + (f)+=ROTATE((a),5)+F_20_39((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_32_39(i,a,b,c,d,e,f,xa) \ + Xupdate(f,i,xa,xa,xa,xa); \ + (f)+=(e); \ + (f)+=K_20_39; \ + (f)+=ROTATE((a),5)+F_20_39((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#define BODY_40_59(i,a,b,c,d,e,f,xa) \ + Xupdate(f,i,xa,xa,xa,xa); \ + (f)+=(e); \ + (f)+=K_40_59; \ + (f)+=ROTATE((a),5)+F_40_59((b),(c),(d)); \ + (b)=ROTATE((b),30); + +#endif /* UNDER_PALMOS */ + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_COMMON_SHA_LOCL_H */ diff --git a/build/tools/acsign/sha1.c b/build/tools/acsign/sha1.c new file mode 100644 index 00000000..6bebd125 --- /dev/null +++ b/build/tools/acsign/sha1.c @@ -0,0 +1,453 @@ +/* + * sha1.c + * + * Description: + * This file implements the Secure Hashing Algorithm 1 as + * defined in FIPS PUB 180-1 published April 17, 1995. + * + * The SHA-1, produces a 160-bit message digest for a given + * data stream. It should take about 2**n steps to find a + * message with the same digest as a given message and + * 2**(n/2) to find any two messages with the same digest, + * when n is the digest size in bits. Therefore, this + * algorithm can serve as a means of providing a + * "fingerprint" for a message. + * + * Portability Issues: + * SHA-1 is defined in terms of 32-bit "words". This code + * uses (included via "sha1.h" to define 32 and 8 + * bit unsigned integer types. If your C compiler does not + * support 32 bit unsigned integers, this code is not + * appropriate. + * + * Caveats: + * SHA-1 is designed to work with messages less than 2^64 bits + * long. Although SHA-1 allows a message digest to be generated + * for messages of any number of bits less than 2^64, this + * implementation only works with messages with a length that is + * a multiple of the size of an 8-bit character. + * + */ + +#include "sha1.h" + +/* + * Define the SHA1 circular left shift macro + */ +#define SHA1CircularShift(bits,word) \ + (((word) << (bits)) | ((word) >> (32-(bits)))) + +/* Local Function Prototyptes */ +void SHA1PadMessage(SHA1Context *); +void SHA1ProcessMessageBlock(SHA1Context *); + +/* + * SHA1Reset + * + * Description: + * This function will initialize the SHA1Context in preparation + * for computing a new SHA1 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * + * Returns: + * sha Error Code. + * + */ +int SHA1Reset(SHA1Context *context) +{ + if (!context) + { + return shaNull; + } + + context->Length_Low = 0; + context->Length_High = 0; + context->Message_Block_Index = 0; + + context->Intermediate_Hash[0] = 0x67452301; + context->Intermediate_Hash[1] = 0xEFCDAB89; + context->Intermediate_Hash[2] = 0x98BADCFE; + context->Intermediate_Hash[3] = 0x10325476; + context->Intermediate_Hash[4] = 0xC3D2E1F0; + + context->Computed = 0; + context->Corrupted = 0; + + return shaSuccess; +} + +/* + * SHA1Result + * + * Description: + * This function will return the 160-bit message digest into the + * Message_Digest array provided by the caller. + * NOTE: The first octet of hash is stored in the 0th element, + * the last octet of hash in the 19th element. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA-1 hash. + * Message_Digest: [out] + * Where the digest is returned. + * + * Returns: + * sha Error Code. + * + */ +int SHA1Result( SHA1Context *context, + unsigned char Message_Digest[20]) +{ + int i; + + if (!context || !Message_Digest) + { + return shaNull; + } + + if (context->Corrupted) + { + return context->Corrupted; + } + + if (!context->Computed) + { + SHA1PadMessage(context); + for(i=0; i<64; ++i) + { + /* message may be sensitive, clear it out */ + context->Message_Block[i] = 0; + } + context->Length_Low = 0; /* and clear length */ + context->Length_High = 0; + context->Computed = 1; + + } + + for(i = 0; i < 20; ++i) + { + Message_Digest[i] = (unsigned char) + (context->Intermediate_Hash[i>>2] + >> 8 * ( 3 - ( i & 0x03 ) )); + } + + return shaSuccess; +} + +/* + * SHA1Input + * + * Description: + * This function accepts an array of octets as the next portion + * of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update + * message_array: [in] + * An array of characters representing the next portion of + * the message. + * length: [in] + * The length of the message in message_array + * + * Returns: + * sha Error Code. + * + */ +int SHA1Input( SHA1Context *context, + const unsigned char *message_array, + unsigned int length) +{ + if (!length) + { + return shaSuccess; + } + + if (!context || !message_array) + { + return shaNull; + } + + if (context->Computed) + { + context->Corrupted = shaStateError; + + return shaStateError; + } + + if (context->Corrupted) + { + return context->Corrupted; + } + while(length-- && !context->Corrupted) + { + context->Message_Block[context->Message_Block_Index++] = + (unsigned char)(*message_array & 0xFF); + + context->Length_Low += 8; + if (context->Length_Low == 0) + { + context->Length_High++; + if (context->Length_High == 0) + { + /* Message is too long */ + context->Corrupted = 1; + } + } + + if (context->Message_Block_Index == 64) + { + SHA1ProcessMessageBlock(context); + } + + message_array++; + } + + return shaSuccess; +} + +/* + * SHA1ProcessMessageBlock + * + * Description: + * This function will process the next 512 bits of the message + * stored in the Message_Block array. + * + * Parameters: + * None. + * + * Returns: + * Nothing. + * + * Comments: + * + * Many of the variable names in this code, especially the + * single character names, were used because those were the + * names used in the publication. + * + * + */ +void SHA1ProcessMessageBlock(SHA1Context *context) +{ + const unsigned long K[] = { /* Constants defined in SHA-1 */ + 0x5A827999, + 0x6ED9EBA1, + 0x8F1BBCDC, + 0xCA62C1D6 + }; + int t; /* Loop counter */ + unsigned long temp; /* Temporary word value */ + unsigned long W[80]; /* Word sequence */ + unsigned long A, B, C, D, E; /* Word buffers */ + + /* + * Initialize the first 16 words in the array W + */ + for(t = 0; t < 16; t++) + { + W[t] = context->Message_Block[t * 4 ] << 24; + W[t] |= context->Message_Block[t * 4 + 1] << 16; + W[t] |= context->Message_Block[t * 4 + 2] << 8; + W[t] |= context->Message_Block[t * 4 + 3]; + } + + for(t = 16; t < 80; t++) + { + W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]); + } + + A = context->Intermediate_Hash[0]; + B = context->Intermediate_Hash[1]; + C = context->Intermediate_Hash[2]; + D = context->Intermediate_Hash[3]; + E = context->Intermediate_Hash[4]; + + for(t = 0; t < 20; t++) + { + temp = SHA1CircularShift(5,A) + + ((B & C) | ((~B) & D)) + E + W[t] + K[0]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + + B = A; + A = temp; + } + + for(t = 20; t < 40; t++) + { + temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + for(t = 40; t < 60; t++) + { + temp = SHA1CircularShift(5,A) + + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + for(t = 60; t < 80; t++) + { + temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + context->Intermediate_Hash[0] += A; + context->Intermediate_Hash[1] += B; + context->Intermediate_Hash[2] += C; + context->Intermediate_Hash[3] += D; + context->Intermediate_Hash[4] += E; + + context->Message_Block_Index = 0; +} + +/* + * SHA1PadMessage + * + + * Description: + * According to the standard, the message must be padded to an even + * 512 bits. The first padding bit must be a '1'. The last 64 + * bits represent the length of the original message. All bits in + * between should be 0. This function will pad the message + * according to those rules by filling the Message_Block array + * accordingly. It will also call the ProcessMessageBlock function + * provided appropriately. When it returns, it can be assumed that + * the message digest has been computed. + * + * Parameters: + * context: [in/out] + * The context to pad + * ProcessMessageBlock: [in] + * The appropriate SHA*ProcessMessageBlock function + * Returns: + * Nothing. + * + */ + +void SHA1PadMessage(SHA1Context *context) +{ + /* + * Check to see if the current message block is too small to hold + * the initial padding bits and length. If so, we will pad the + * block, process it, and then continue padding into a second + * block. + */ + if (context->Message_Block_Index > 55) + { + context->Message_Block[context->Message_Block_Index++] = 0x80; + while(context->Message_Block_Index < 64) + { + context->Message_Block[context->Message_Block_Index++] = 0; + } + + SHA1ProcessMessageBlock(context); + + while(context->Message_Block_Index < 56) + { + context->Message_Block[context->Message_Block_Index++] = 0; + } + } + else + { + context->Message_Block[context->Message_Block_Index++] = 0x80; + while(context->Message_Block_Index < 56) + { + + context->Message_Block[context->Message_Block_Index++] = 0; + } + } + + /* + * Store the message length as the last 8 octets + */ + context->Message_Block[56] = (unsigned char)(context->Length_High >> 24); + context->Message_Block[57] = (unsigned char)(context->Length_High >> 16); + context->Message_Block[58] = (unsigned char)(context->Length_High >> 8); + context->Message_Block[59] = (unsigned char)(context->Length_High ); + context->Message_Block[60] = (unsigned char)(context->Length_Low >> 24); + context->Message_Block[61] = (unsigned char)(context->Length_Low >> 16); + context->Message_Block[62] = (unsigned char)(context->Length_Low >> 8); + context->Message_Block[63] = (unsigned char)(context->Length_Low ); + + SHA1ProcessMessageBlock(context); +} + + + + +////////////////////////////////////////////////////////////////////////////// +#if defined( SHA1_TEST ) + +#include "string.h" + +char* samplearray[4] = +{ + "abc", + "abcdbcdecdefdefgefghfghighijhi" "jkijkljklmklmnlmnomnopnopq", + "a", + "01234567012345670123456701234567" "01234567012345670123456701234567" +}; + +char* resultarray[ 4 ] = +{ + "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D", + "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1", + "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F", + "\xDE\xA3\x56\xA2\xCD\xDD\x90\xC7\xA7\xEC\xED\xC5\xEB\xB5\x63\x93\x4F\x46\x04\x52" +}; + +long int repeatcount[4] = { 1, 1, 1000000, 10 }; + +int SHA1Test( ) +{ + SHA1Context sha; + unsigned char digest[20]; + int i, j, error; + + error = 0; + for ( j = 0; j < 4; ++j ) + { + if ( !error ) + error = SHA1Reset(&sha); + + for(i = 0; i < repeatcount[j]; ++i) + { + if ( !error ) + error = SHA1Input(&sha, + (const unsigned char *)samplearray[j], + (unsigned int)strlen(samplearray[j])); + } + + if ( !error ) + error = SHA1Result(&sha, digest); + + if ( !error ) + error = memcmp( digest, resultarray[j], 20 ); + + if (error) + break; + } + + return error ? 0 : 1; +} + +#endif // SHA1_TEST +////////////////////////////////////////////////////////////////////////////// + diff --git a/build/tools/acsign/sha1dgst.c b/build/tools/acsign/sha1dgst.c new file mode 100644 index 00000000..f9759158 --- /dev/null +++ b/build/tools/acsign/sha1dgst.c @@ -0,0 +1,770 @@ +/* $Id$ */ +/* + * Copyright (C) 1998-2002 RSA Security Inc. All rights reserved. + * + * This work contains proprietary information of RSA Security. + * Distribution is limited to authorized licensees of RSA + * Security. Any unauthorized reproduction, distribution or + * modification of this work is strictly prohibited. + * + */ + +////!!!!#include "r_com.h" + +#ifndef NO_SHA1 +#undef SHA_0 +#define SHA_1 +#include "sha.h" +#include "sha_locl.h" +#ifdef CPU_X86 +#include "r_cpuid.h" +#endif /* NO_SHA1 */ + +const char *SHA1_version="SHA1 part of RCOM 2.3.0 11-Jun-2002"; + +/* Implemented from SHA-1 document - The Secure Hash Algorithm + */ + +#define INIT_DATA_h0 (SHA_LONG)0x67452301L +#define INIT_DATA_h1 (SHA_LONG)0xefcdab89L +#define INIT_DATA_h2 (SHA_LONG)0x98badcfeL +#define INIT_DATA_h3 (SHA_LONG)0x10325476L +#define INIT_DATA_h4 (SHA_LONG)0xc3d2e1f0L + +#define K_00_19 (SHA_LONG)0x5a827999L +#define K_20_39 (SHA_LONG)0x6ed9eba1L +#define K_40_59 (SHA_LONG)0x8f1bbcdcL +#define K_60_79 (SHA_LONG)0xca62c1d6L + +#ifndef CCONV +#define CCONV +#endif + +#ifndef PRE_CCONV +#define PRE_CCONV +#endif + +/* Endian flags are only used for the assembler code */ +#ifndef OPT_SHA1_ASM +#undef L_ENDIAN +#undef B_ENDIAN +#endif + + +#ifdef OPT_SHA1_ASM + +#ifdef CPU_X86 +void CCONV sha1_block_586(SHA_CTX *c,const unsigned char *p, int num); +void CCONV sha1_block_686(SHA_CTX *c,const unsigned char *p, int num); +void CCONV sha1_block_786(SHA_CTX *c,const unsigned char *p, int num); +unsigned long r_cpuid(unsigned long *,char **name); + +#elif OPT_SHA1_ARM +PRE_CCONV void CCONV sha1_arm4_fast(SHA_CTX *c, const unsigned char *p, + int num); +PRE_CCONV void CCONV sha1_arm4_small(SHA_CTX *c, const unsigned char *p, + int num); +#else +void CCONV sha1_block_asm(SHA_CTX *c, const unsigned char *p, int num); +#endif /* CPU_X86 */ + +#else /* OPT_SHA1_ASM */ + +void sha1_block(SHA_CTX *c, SHA_LONG *p, int num); + +#endif /* OPT_SHA1_ASM */ + +#undef M_c2nl +#undef M_p_c2nl +#undef M_c2nl_p +#undef M_p_c2nl_p +#undef M_nl2c + +#if defined(L_ENDIAN) && !defined(OPT_SHA1_ASM) +# define M_c2nl c2l +# define M_p_c2nl p_c2l +# define M_c2nl_p c2l_p +# define M_p_c2nl_p p_c2l_p +# define M_nl2c l2c +#else +# define M_c2nl c2nl +# define M_p_c2nl p_c2nl +# define M_c2nl_p c2nl_p +# define M_p_c2nl_p p_c2nl_p +# define M_nl2c nl2c +#endif /* defined(L_ENDIAN) && !defined(OPT_SHA1_ASM) */ + +int SHA1_Setup(c,sha_block) +SHA_CTX *c; +void (PRE_CCONV CCONV *sha_block)(SHA_CTX *c, const unsigned char *W, int num); + { + c->sha_block=sha_block; + return(0); + } + +void SHA1_Init(c) +SHA_CTX *c; + { + c->h0=INIT_DATA_h0; + c->h1=INIT_DATA_h1; + c->h2=INIT_DATA_h2; + c->h3=INIT_DATA_h3; + c->h4=INIT_DATA_h4; + c->Nl=0; + c->Nh=0; + c->num=0; + +#ifdef OPT_SHA1_ASM +#ifdef CPU_X86 + if (c->sha_block == NULL) + { + unsigned long cpu,attrib; + + /* We should make the methods loadable */ + cpu=r_cpuid(&attrib,NULL); + if (attrib & R_CPU_X86_HAS_PENTIUM_IV) + c->sha_block=sha1_block_786; + else if (attrib & R_CPU_X86_HAS_PENTIUM_PRO) + c->sha_block=sha1_block_686; + else + c->sha_block=sha1_block_586; + } +#else /* CPU_X86 */ + +#ifndef OPT_SHA1_ARM + c->sha_block=sha1_block_asm; +#else /* OPT_SHA1_ARM */ + if (c->sha_block == NULL) + { +#ifdef SMALL_CODE_SIZE + c->sha_block = sha1_arm4_small; +#else /* SMALL_CODE_SIZE */ + c->sha_block = sha1_arm4_fast; +#endif /* SMALL_CODE_SIZE */ + } +#endif /* OPT_SHA1_ARM */ +#endif /* CPU_X86 */ + +#else /* OPT_SHA1_ASM */ + c->sha_block=(void (PRE_CCONV CCONV *)(SHA_CTX *, const unsigned char *, int))sha1_block; +#endif /* OPT_SHA1_ASM */ + } + +#ifdef OPT_SHA1_ASM + +void SHA1_Update(c, data, len) +SHA_CTX *c; +const register unsigned char *data; +unsigned long len; + { + int i; + unsigned int alignment; + unsigned long l; + unsigned char *cp=(unsigned char *)c->data; + + if (len == 0) return; + + l=(c->Nl+(len<<3))&0xffffffffL; + if (l < c->Nl) /* overflow */ + c->Nh++; + c->Nh+=(len>>29); + c->Nl=l; + + if (c->num != 0) + { + if (c->num+len >= SHA_CBLOCK) + { + i=SHA_CBLOCK-c->num; + Memcpy(&(cp[c->num]),data,i); + len-=i; + data+=i; + + c->sha_block(c,cp,64); + c->num=0; + /* drop through and do the rest */ + } + else + { + Memcpy(&(cp[c->num]),data,len); + c->num+=(int)len; + return; + } + } + /* we now can process the input data in blocks of SHA_CBLOCK + * chars and save the leftovers to c->data. */ + if (len >= SHA_CBLOCK) + { + i=(int)(len& ~63); + len-=i; + + /* + * Check to see if the input data lies on a word boundary. + * Do this as the ASM relies on input data being word aligned. + */ + alignment = (((unsigned int)data) & (sizeof(unsigned int)-1)) + & 0x03; + if (alignment == 0) + { + c->sha_block(c,data,i); + data+=i; + } + else + { + do { + Memcpy(cp, data, SHA_CBLOCK); + data += SHA_CBLOCK; + c->sha_block(c, cp, SHA_CBLOCK); + i -= SHA_CBLOCK; + } while (i > 0); + } + } + c->num=len; + if (len) + { + Memcpy(cp,data,(int)len); + } + } + +void SHA1_Transform(c,b) +SHA_CTX *c; +const unsigned char *b; + { + c->sha_block(c,b,64); + } + +void SHA1_Final(md, c) +unsigned char *md; +SHA_CTX *c; + { + register int i,j; + register SHA_LONG l; + register SHA_LONG *p; + const static unsigned char end[4]={0x80,0x00,0x00,0x00}; + unsigned char *cp= (unsigned char *)end; + unsigned char *pc; + + /* c->num should definitly have room for at least one more byte. */ + p=c->data; + j=c->num; + i=j>>2; + +#ifdef PURIFY + /* PURIFY */ + /* we reference uninitialised data but don't keep the result + * which purify complains about ... and we don't want to have + * to come back here to find a non-existant problem later + */ + + /* purify often complains about the following line as an + * Uninitialized Memory Read. While this can be true, the + * following p_c2l macro will reset l when that case is true. + * This is because j&0x03 contains the number of 'valid' bytes + * already in p[i]. If and only if j&0x03 == 0, the UMR will + * occur but this is also the only time p_c2l will do + * l= *(cp++) instead of l|= *(cp++) + */ + if ((j&0x03) == 0) p[i]=0; +#endif + + pc=(unsigned char *)c->data; + pc[j]=0x80; + for (j++; j & 0x03; j++) + pc[j]=0; + i++; + /* i is the next 'undefined word' */ + if (c->num >= SHA_LAST_BLOCK) + { + for (; isha_block(c,(unsigned char *)p,64); + i=0; + } + for (; i<(SHA_LBLOCK-2); i++) + p[i]=0; + + l=c->Nl; + pc[63]=(unsigned char)((l )&0xff); + pc[62]=(unsigned char)((l>> 8)&0xff); + pc[61]=(unsigned char)((l>>16)&0xff); + pc[60]=(unsigned char)((l>>24)&0xff); + l=c->Nh; + pc[59]=(unsigned char)((l )&0xff); + pc[58]=(unsigned char)((l>> 8)&0xff); + pc[57]=(unsigned char)((l>>16)&0xff); + pc[56]=(unsigned char)((l>>24)&0xff); + + c->sha_block(c,(unsigned char *)p,64); + cp=md; + l=c->h0; nl2c(l,cp); + l=c->h1; nl2c(l,cp); + l=c->h2; nl2c(l,cp); + l=c->h3; nl2c(l,cp); + l=c->h4; nl2c(l,cp); + + /* clear stuff, sha1_block_asm may be leaving some stuff on the stack + * but I'm not worried :-) */ + c->num=0; +/* Memset((char *)&c,0,sizeof(c));*/ + } + +#else /* !OPT_SHA1_ASM */ + +void SHA1_Update(c, data, len) +SHA_CTX *c; +const register unsigned char *data; +unsigned long len; + { + register SHA_LONG *p; + int ew,ec,sw,sc; + SHA_LONG l; + + if (len == 0) return; + + l=(c->Nl+(len<<3))&0xffffffffL; + if (l < c->Nl) /* overflow */ + c->Nh++; + c->Nh+=(len>>29); + c->Nl=l; + + if (c->num != 0) + { + p=c->data; + sw=c->num>>2; + sc=c->num&0x03; + + if ((c->num+len) >= SHA_CBLOCK) + { + l= p[sw]; + M_p_c2nl(data,l,sc); + p[sw++]=l; + for (; swnum); + + c->sha_block(c,(unsigned char *)p,64); + c->num=0; + /* drop through and do the rest */ + } + else + { + c->num+=(int)len; + if ((sc+len) < 4) /* ugly, add char's to a word */ + { + l= p[sw]; + M_p_c2nl_p(data,l,sc,len); + p[sw]=l; + } + else + { + ew=(c->num>>2); + ec=(c->num&0x03); + l= p[sw]; + M_p_c2nl(data,l,sc); + p[sw++]=l; + for (; sw < ew; sw++) + { M_c2nl(data,l); p[sw]=l; } + if (ec) + { + M_c2nl_p(data,l,ec); + p[sw]=l; + } + } + return; + } + } + /* We can only do the following code for assember, the reason + * being that the sha1_block 'C' version changes the values + * in the 'data' array. The assember code avoids this and + * copies it to a local array. I should be able to do this for + * the C version as well.... + */ +#if defined(B_ENDIAN) || defined(OPT_SHA1_ASM) + if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0) + { + sw=len/SHA_CBLOCK; + if (sw) + { + sw*=SHA_CBLOCK; + c->sha_block(c,(SHA_LONG *)data,sw); + data+=sw; + len-=sw; + } + } +#endif + /* we now can process the input data in blocks of SHA_CBLOCK + * chars and save the leftovers to c->data. */ + p=c->data; + while (len >= SHA_CBLOCK) + { +#if defined(B_ENDIAN) || defined(L_ENDIAN) + if (p != (SHA_LONG *)data) + Memcpy(p,data,SHA_CBLOCK); + data+=SHA_CBLOCK; +# ifdef L_ENDIAN +# ifndef OPT_SHA1_ASM /* Will not happen */ + for (sw=(SHA_LBLOCK/4); sw; sw--) + { + Endian_Reverse32(p[0]); + Endian_Reverse32(p[1]); + Endian_Reverse32(p[2]); + Endian_Reverse32(p[3]); + p+=4; + } + p=c->data; +# endif +# endif +#else + for (sw=(SHA_BLOCK/4); sw; sw--) + { + M_c2nl(data,l); *(p++)=l; + M_c2nl(data,l); *(p++)=l; + M_c2nl(data,l); *(p++)=l; + M_c2nl(data,l); *(p++)=l; + } + p=c->data; +#endif + c->sha_block(c,(unsigned char *)p,64); + len-=SHA_CBLOCK; + } + ec=(int)len; + c->num=ec; + ew=(ec>>2); + ec&=0x03; + + for (sw=0; sw < ew; sw++) + { M_c2nl(data,l); p[sw]=l; } + M_c2nl_p(data,l,ec); + p[sw]=l; + } + +void SHA1_Transform(c,b) +SHA_CTX *c; +const unsigned char *b; + { + SHA_LONG p[16]; +#ifndef B_ENDIAN + SHA_LONG *q; + int i; +#endif + +#if defined(B_ENDIAN) || defined(L_ENDIAN) + Memcpy(p,b,64); +#ifdef L_ENDIAN + q=p; + for (i=(SHA_LBLOCK/4); i; i--) + { + Endian_Reverse32(q[0]); + Endian_Reverse32(q[1]); + Endian_Reverse32(q[2]); + Endian_Reverse32(q[3]); + q+=4; + } +#endif +#else + q=p; + for (i=(SHA_LBLOCK/4); i; i--) + { + SHA_LONG l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + } +#endif + c->sha_block(c,(unsigned char *)p,64); + } + + +void sha1_block(c, W, num) +SHA_CTX *c; +SHA_LONG *W; +int num; + { +#ifndef SMALL_CODE_SIZE + register SHA_LONG A,B,C,D,E,T; + SHA_LONG X[16]; + + A=c->h0; + B=c->h1; + C=c->h2; + D=c->h3; + E=c->h4; + + for (;;) + { + BODY_00_15( 0,A,B,C,D,E,T,W); + BODY_00_15( 1,T,A,B,C,D,E,W); + BODY_00_15( 2,E,T,A,B,C,D,W); + BODY_00_15( 3,D,E,T,A,B,C,W); + BODY_00_15( 4,C,D,E,T,A,B,W); + BODY_00_15( 5,B,C,D,E,T,A,W); + BODY_00_15( 6,A,B,C,D,E,T,W); + BODY_00_15( 7,T,A,B,C,D,E,W); + BODY_00_15( 8,E,T,A,B,C,D,W); + BODY_00_15( 9,D,E,T,A,B,C,W); + BODY_00_15(10,C,D,E,T,A,B,W); + BODY_00_15(11,B,C,D,E,T,A,W); + BODY_00_15(12,A,B,C,D,E,T,W); + BODY_00_15(13,T,A,B,C,D,E,W); + BODY_00_15(14,E,T,A,B,C,D,W); + BODY_00_15(15,D,E,T,A,B,C,W); + BODY_16_19(16,C,D,E,T,A,B,W,W,W,W); + BODY_16_19(17,B,C,D,E,T,A,W,W,W,W); + BODY_16_19(18,A,B,C,D,E,T,W,W,W,W); + BODY_16_19(19,T,A,B,C,D,E,W,W,W,X); + + BODY_20_31(20,E,T,A,B,C,D,W,W,W,X); + BODY_20_31(21,D,E,T,A,B,C,W,W,W,X); + BODY_20_31(22,C,D,E,T,A,B,W,W,W,X); + BODY_20_31(23,B,C,D,E,T,A,W,W,W,X); + BODY_20_31(24,A,B,C,D,E,T,W,W,X,X); + BODY_20_31(25,T,A,B,C,D,E,W,W,X,X); + BODY_20_31(26,E,T,A,B,C,D,W,W,X,X); + BODY_20_31(27,D,E,T,A,B,C,W,W,X,X); + BODY_20_31(28,C,D,E,T,A,B,W,W,X,X); + BODY_20_31(29,B,C,D,E,T,A,W,W,X,X); + BODY_20_31(30,A,B,C,D,E,T,W,X,X,X); + BODY_20_31(31,T,A,B,C,D,E,W,X,X,X); + BODY_32_39(32,E,T,A,B,C,D,X); + BODY_32_39(33,D,E,T,A,B,C,X); + BODY_32_39(34,C,D,E,T,A,B,X); + BODY_32_39(35,B,C,D,E,T,A,X); + BODY_32_39(36,A,B,C,D,E,T,X); + BODY_32_39(37,T,A,B,C,D,E,X); + BODY_32_39(38,E,T,A,B,C,D,X); + BODY_32_39(39,D,E,T,A,B,C,X); + + BODY_40_59(40,C,D,E,T,A,B,X); + BODY_40_59(41,B,C,D,E,T,A,X); + BODY_40_59(42,A,B,C,D,E,T,X); + BODY_40_59(43,T,A,B,C,D,E,X); + BODY_40_59(44,E,T,A,B,C,D,X); + BODY_40_59(45,D,E,T,A,B,C,X); + BODY_40_59(46,C,D,E,T,A,B,X); + BODY_40_59(47,B,C,D,E,T,A,X); + BODY_40_59(48,A,B,C,D,E,T,X); + BODY_40_59(49,T,A,B,C,D,E,X); + BODY_40_59(50,E,T,A,B,C,D,X); + BODY_40_59(51,D,E,T,A,B,C,X); + BODY_40_59(52,C,D,E,T,A,B,X); + BODY_40_59(53,B,C,D,E,T,A,X); + BODY_40_59(54,A,B,C,D,E,T,X); + BODY_40_59(55,T,A,B,C,D,E,X); + BODY_40_59(56,E,T,A,B,C,D,X); + BODY_40_59(57,D,E,T,A,B,C,X); + BODY_40_59(58,C,D,E,T,A,B,X); + BODY_40_59(59,B,C,D,E,T,A,X); + + BODY_60_79(60,A,B,C,D,E,T,X); + BODY_60_79(61,T,A,B,C,D,E,X); + BODY_60_79(62,E,T,A,B,C,D,X); + BODY_60_79(63,D,E,T,A,B,C,X); + BODY_60_79(64,C,D,E,T,A,B,X); + BODY_60_79(65,B,C,D,E,T,A,X); + BODY_60_79(66,A,B,C,D,E,T,X); + BODY_60_79(67,T,A,B,C,D,E,X); + BODY_60_79(68,E,T,A,B,C,D,X); + BODY_60_79(69,D,E,T,A,B,C,X); + BODY_60_79(70,C,D,E,T,A,B,X); + BODY_60_79(71,B,C,D,E,T,A,X); + BODY_60_79(72,A,B,C,D,E,T,X); + BODY_60_79(73,T,A,B,C,D,E,X); + BODY_60_79(74,E,T,A,B,C,D,X); + BODY_60_79(75,D,E,T,A,B,C,X); + BODY_60_79(76,C,D,E,T,A,B,X); + BODY_60_79(77,B,C,D,E,T,A,X); + BODY_60_79(78,A,B,C,D,E,T,X); + BODY_60_79(79,T,A,B,C,D,E,X); + + c->h0=(c->h0+E)&0xffffffffL; + c->h1=(c->h1+T)&0xffffffffL; + c->h2=(c->h2+A)&0xffffffffL; + c->h3=(c->h3+B)&0xffffffffL; + c->h4=(c->h4+C)&0xffffffffL; + + num-=64; + if (num <= 0) break; + + A=c->h0; + B=c->h1; + C=c->h2; + D=c->h3; + E=c->h4; + + W+=16; + } +#else /* SMALL_CODE_SIZE */ + SHA_LONG A,B,C,D,E,T; + SHA_LONG X[16]; + SHA_LONG *a1,*a2,*a3; + + A=c->h0; + B=c->h1; + C=c->h2; + D=c->h3; + E=c->h4; + + for (;;) + { + int i; + + for (i=0; i<16; i++) + { + BODY_00_15(i,A,B,C,D,E,T,W); + E=D; D=C; C=B; B=A; A=T; + } + + a1=W; + for (i=16; i<20; i++) + { + if (i == 19) a1=X; + BODY_16_19(i,A,B,C,D,E,T,W,W,W,a1); + E=D; D=C; C=B; B=A; A=T; + } + + a1=a2=a3=W; + for (i=20; i<40; i++) + { + if (i == 24) a3=X; + if (i == 30) a2=X; + if (i == 32) a1=X; + BODY_20_31(i,A,B,C,D,E,T,a1,a2,a3,X); + E=D; D=C; C=B; B=A; A=T; + } + + for (i=40; i<60; i++) + { + BODY_40_59(i,A,B,C,D,E,T,X); + E=D; D=C; C=B; B=A; A=T; + } + + for (i=60; i<80; i++) + { + BODY_60_79(i,A,B,C,D,E,T,X); + E=D; D=C; C=B; B=A; A=T; + } + + c->h0=(c->h0+A)&0xffffffffL; + c->h1=(c->h1+B)&0xffffffffL; + c->h2=(c->h2+C)&0xffffffffL; + c->h3=(c->h3+D)&0xffffffffL; + c->h4=(c->h4+E)&0xffffffffL; + + num-=64; + if (num <= 0) break; + + A=c->h0; + B=c->h1; + C=c->h2; + D=c->h3; + E=c->h4; + + W+=16; + } +#endif /* SMALL_CODE_SIZE */ + } + +void SHA1_Final(md, c) +unsigned char *md; +SHA_CTX *c; + { + register int i,j; + register SHA_LONG l; + register SHA_LONG *p; + const static unsigned char end[4]={0x80,0x00,0x00,0x00}; + unsigned char *cp= (unsigned char *)end; + + /* c->num should definitly have room for at least one more byte. */ + p=c->data; + j=c->num; + i=j>>2; + +#ifdef PURIFY + /* PURIFY */ + /* we reference uninitialised data but don't keep the result + * which purify complains about ... and we don't want to have + * to come back here to find a non-existant problem later + */ + + /* purify often complains about the following line as an + * Uninitialized Memory Read. While this can be true, the + * following p_c2l macro will reset l when that case is true. + * This is because j&0x03 contains the number of 'valid' bytes + * already in p[i]. If and only if j&0x03 == 0, the UMR will + * occur but this is also the only time p_c2l will do + * l= *(cp++) instead of l|= *(cp++) + */ + if ((j&0x03) == 0) p[i]=0; +#endif + + l=p[i]; + M_p_c2nl(cp,l,j&0x03); + p[i]=l; + i++; + /* i is the next 'undefined word' */ + if (c->num >= SHA_LAST_BLOCK) + { + for (; isha_block(c,(unsigned char *)p,64); + i=0; + } + for (; i<(SHA_LBLOCK-2); i++) + p[i]=0; + p[SHA_LBLOCK-2]=c->Nh; + p[SHA_LBLOCK-1]=c->Nl; +#if defined(L_ENDIAN) + Endian_Reverse32(p[SHA_LBLOCK-2]); + Endian_Reverse32(p[SHA_LBLOCK-1]); +#endif + c->sha_block(c,(unsigned char *)p,64); + cp=md; + l=c->h0; nl2c(l,cp); + l=c->h1; nl2c(l,cp); + l=c->h2; nl2c(l,cp); + l=c->h3; nl2c(l,cp); + l=c->h4; nl2c(l,cp); + + /* clear stuff, sha1_block may be leaving some stuff on the stack + * but I'm not worried :-) */ + c->num=0; +/* Memset((char *)&c,0,sizeof(c));*/ + } +#endif + +#if 0 +int pr(ctx) +SHA_CTX *ctx; + { + int i,j; + unsigned char *p=(unsigned char *)(ctx->data); + + fprintf(stderr,"num = %08X%08X\n",ctx->Nh,ctx->Nl); + fprintf(stderr," %08X %08X %08X %08X %08X\n", + ctx->h0,ctx->h1,ctx->h2,ctx->h3,ctx->h4); + fprintf(stderr,"bufnum = %d\n",ctx->num); + fprintf(stderr," "); + for (j=0; j<64; j+=16) + { + for (i=0; i<16; i++) + { +/* + if ((i+j) >= ctx->num) + fprintf(stderr,"--"); + else +*/ + fprintf(stderr,"%02X",p[i+j]); + } + if ((j+16) >=64) + fprintf(stderr,"\n"); + else + fprintf(stderr,"\n "); + } + } + +#endif + +#endif /* NO_SHA1 */ diff --git a/build/tools/makegcdfirm/Makefile b/build/tools/makegcdfirm/Makefile new file mode 100644 index 00000000..a46292ac --- /dev/null +++ b/build/tools/makegcdfirm/Makefile @@ -0,0 +1,151 @@ +#! make -f +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makegcdfirm +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#--------------------------------------------------------------------------- + +TARGET_PLATFORM = TWL + +SUPPORT_ECC = 0 + +ifeq ($(SUPPORT_ECC),1) +ECC_SRCDIR = ../../libraries/acsign_ecc/common \ + ../../libraries/acsign_ecc/common/algae/common/ecc \ + ../../libraries/acsign_ecc/common/algae/cmp \ + ../../libraries/acsign_ecc/common/algae/ecsource \ + +ECC_INCDIR = ../../libraries/acsign_ecc/include \ + ../../libraries/acsign_ecc/common/algae/include \ + ../../libraries/acsign_ecc/common/algae/common/include \ + +ECC_SRCS = acsign_ecc.c acsign_cryptoc.c \ + \ + cmparith.c cmpbits.c cmpcnv.c cmpdiv.c cmpmem.c \ + cmpmod.c cmpmuldv.c cmpspprt.c cmpsqr.c cmpvectr.c \ + computem.c ecfpatbl.c ecfpsmul.c \ + spcprime.c secfpcom.c \ + \ + p224v1.c p224v1a.c \ + +ECC_DEFS = -DRSA_PROTOTYPES=RSA_ENABLED \ + -DRCOM_BUILD=RSA_ENABLED -DRSA_FAST_INVERSE=RSA_ENABLED \ + -DRSA_STD_MEM_FUNCS=RSA_ENABLED -DRSA_STD_ALLOC_FUNCS=RSA_ENABLED \ +else +ECC_SRCDIR = +ECC_INCDIR = +ECC_SRCS = +ECC_DEFS = +endif + +SRCDIR += ../acsign $(ECC_SRCDIR) +INCDIR += ../acsign/include $(ECC_INCDIR) $(ECC_SRCDIR) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +TARGETS = makegcdfirm.exe + +SOURCES_C = makegcdfirm.c \ + out_gcdfirm.c \ + misc.c \ + path.c \ + defval.c \ + compress.c \ + wram_regs.c \ + acsign.c \ + acsign_gcd.c \ + aes2.c \ + $(ECC_SRCS) + +SOURCES = $(SORUCES_C) + +OBJECTS = $(SOURCES_C:.c=.o) + +HEADERS = format_nlist.h \ + makegcdfirm.h \ + path.h \ + format_rom.h \ + misc.h \ + defval.h \ + compress.h \ + +MACROS += -DSMALL_CODE_SIZE \ + -DSTANDALONE \ + -DOPT_32_BIT \ + -DNO_SPLIT \ + -DNO_FP_API \ + -DNO_R_DIAG \ + $(ECC_DEFS) + +INSTALL_DIR = $(FIRM_INSTALL_TOOLSDIR)/bin +INSTALL_TARGETS = $(TARGETS) + +LDIRT_CLEAN = $(OBJECTS) $(TARGETS) version.h + + +VPATH = $(SRCDIR) +TWL_INCDIR := $(TWL_INCDIR) $(addprefix -I,$(INCDIR)) $(addprefix -I,$(FIRM_INCDIR)) + +include $(TWLSDK_ROOT)/build/buildtools/twl/modulerules.x86 + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(OBJECTS) + $(CC_X86) $+ -o $@ + +makegcdfirm.o: makegcdfirm.c makegcdfirm.h format_rom.h path.h version.h +out_gcdfirm.o: out_gcdfirm.c misc.h format_rom.h format_nlist.h format_sign.h elf.h compress.h \ + $(FIRM_INCDIR)/firm/format/sign.h \ + $(FIRM_INCDIR)/firm/format/wram_regs.h \ + $(FIRM_INCDIR)/firm/format/gcdfirm.h \ + +misc.o: misc.c misc.h +path.o: path.c path.h +compress.o: compress.c compress.h +wram_regs.o: wram_regs.c +acsign.o: acsign.c ../acsign/include/acsign.h +acsign_gcd.o: acsign_gcd.c format_sign.h \ + $(FIRM_INCDIR)/firm/format/sign.h \ + $(FIRM_INCDIR)/firm/format/wram_regs.h \ + $(FIRM_INCDIR)/firm/format/gcdfirm.h \ + +aes2.o: aes2.c aes2.h + +$(FIRM_INCDIR)/firm/format/sign.h: +$(FIRM_INCDIR)/firm/format/wram_regs.h: +$(FIRM_INCDIR)/firm/format/gcdfirm.h: +format_nlist.h: +format_rom.h: +makegcdfirm.h: +acsign.h: +acsign_gcd.h: +path.h: + +# avoid to warning message +misc.o:WARNING += -Wno-format-y2k + +# + +version.h: $(SOURCES) $(HEADERS) + @for i in $^ ; \ + do \ + date -r $$i +'#define SDK_DATE_OF_LATEST_FILE %Y%m%dUL'; \ + done | sort | tail -1 > $@ + +test: path.c misc.c + $(CC_X86) -DTEST $+ -o $@ diff --git a/build/tools/makegcdfirm/compress.c b/build/tools/makegcdfirm/compress.c new file mode 100644 index 00000000..6a8c4038 --- /dev/null +++ b/build/tools/makegcdfirm/compress.c @@ -0,0 +1,293 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makegcdfirm + File: compress.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:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include // atoi() +#include // strcmp() +#include // isprint() +#include // chdir() +#include +#include // UCHAR_MAX +#include +#include // stat() +#include "elf.h" +#include "misc.h" +#include "defval.h" +#include "format_rom.h" +#include "format_nlist.h" +#include "makegcdfirm.h" + +//#define ADD_HEADER + +#define DIFF_CODE_HEADER (0x80) +#define RL_CODE_HEADER (0x30) +#define LZ_CODE_HEADER (0x10) +#define HUFF_CODE_HEADER (0x20) +#define CODE_HEADER_MASK (0xF0) + +//=========================================================================== +// LZ77k +//=========================================================================== +static u8 SearchLZ(const u8 *nextp, u32 remainSize, u16 *offset); + +static u16 windowPos; +static u16 windowLen; + +static s16 LZOffsetTable[4096]; +static s16 LZByteTable[256]; +static s16 LZEndTable[256]; + + +static void LZInitTable(void) +{ + u16 i; + + for (i = 0; i < 256; i++) + { + LZByteTable[i] = -1; + LZEndTable[i] = -1; + } + windowPos = 0; + windowLen = 0; +} + +static void SlideByte(const u8 *srcp) +{ + s16 offset; + u8 in_data = *srcp; + u16 insert_offset; + + if (windowLen == 4096) + { + u8 out_data = *(srcp - 4096); + if ((LZByteTable[out_data] = LZOffsetTable[LZByteTable[out_data]]) == -1) + { + LZEndTable[out_data] = -1; + } + insert_offset = windowPos; + } + else + { + insert_offset = windowLen; + } + + offset = LZEndTable[in_data]; + if (offset == -1) + { + LZByteTable[in_data] = insert_offset; + } + else + { + LZOffsetTable[offset] = insert_offset; + } + LZEndTable[in_data] = insert_offset; + LZOffsetTable[insert_offset] = -1; + + if (windowLen == 4096) + { + windowPos = (u16)((windowPos + 1) % 0x1000); + } + else + { + windowLen++; + } +} + +static void LZSlide(const u8 *srcp, u32 n) +{ + u32 i; + + for (i = 0; i < n; i++) + { + SlideByte(srcp++); + } +} + +/*---------------------------------------------------------------------------* + Name: MI_CompressLZ + + Description: LZ77ksȂ֐ + + Arguments: srcp kf[^ւ̃|C^ + size kf[^TCY + dstp kf[^ւ̃|C^ + kf[^傫TCỸobt@KvłB + + Returns: k̃f[^TCYB + k̃f[^kO傫Ȃꍇɂ͈k𒆒f0Ԃ܂B + *---------------------------------------------------------------------------*/ +u32 LZCompWrite(u8 *srcp, u32 size, u8 *dstp, int boundary) +{ + u32 LZDstCount; // kf[^̃oCg + u8 LZCompFlags; // k̗LtOn + u8 *LZCompFlagsp; // LZCompFlags i[郁̈|Cg + u16 lastOffset; // vf[^܂ł̃ItZbg (̎_ł̍Œvf[^) + u8 lastLength; // vf[^ (̎_ł̍Œvf[^) + u8 i; + u32 dstMax; + +#ifdef ADD_HEADER + *(u32 *)dstp = size << 8 | LZ_CODE_HEADER; // f[^Ewb_ + dstp += 4; +#endif + LZDstCount = 4; + dstMax = size; + LZInitTable(); + + while (size > 0) + { + LZCompFlags = 0; + LZCompFlagsp = dstp++; // tOn̊i[ + LZDstCount++; + + // tOn8rbgf[^ƂĊi[邽߁A8񃋁[v + for (i = 0; i < 8; i++) + { + LZCompFlags <<= 1; // (i=0) ͓ɈӖ͂Ȃ + if (size <= 0) + { + // I[ɗꍇ̓tOŌ܂ŃVtgĂI + continue; + } + + if ((lastLength = SearchLZ(srcp, size, &lastOffset))) + { + // k”\ȏꍇ̓tO𗧂Ă + LZCompFlags |= 0x1; + + // ItZbg͏4rbgƉ8rbgɕĊi[ + *dstp++ = (u8)((lastLength - 3) << 4 | (lastOffset - 1) >> 8); + *dstp++ = (u8)((lastOffset - 1) & 0xff); + LZDstCount += 2; + LZSlide(srcp, lastLength); + srcp += lastLength; + size -= lastLength; + } + else + { + // kȂ + LZSlide(srcp, 1); + *dstp++ = *srcp++; + size--; + LZDstCount++; + } + } // 8񃋁[vI + *LZCompFlagsp = LZCompFlags; // tOni[ + } + + // 16oCgEACg + // ACgpf[^0 ̓f[^TCYɊ܂߂ + i = 0; + while (LZDstCount & (boundary - 1)) +// while ((LZDstCount + i) & 0x3) + { + *dstp++ = 0; + LZDstCount++; + i++; + } + + return LZDstCount; +} + +//-------------------------------------------------------- +// LZ77kŃXCh̒Œv܂B +// Arguments: startp f[^̊Jnʒu|C^ +// nextp Jnf[^̃|C^ +// remainSize cf[^TCY +// offset vItZbgi[̈ւ̃|C^ +// Return : v񂪌‚ꍇ TRUE +// ‚Ȃꍇ FALSE +//-------------------------------------------------------- +static u8 SearchLZ(const u8 *nextp, u32 remainSize, u16 *offset) +{ + const u8 *searchp; + const u8 *headp, *searchHeadp; + u16 maxOffset; + u8 maxLength = 2; + u8 tmpLength; + s32 w_offset; + + if (remainSize < 3) + { + return 0; + } + + w_offset = LZByteTable[*nextp]; + + while (w_offset != -1) + { + if (w_offset < windowPos) + { + searchp = nextp - windowPos + w_offset; + } + else + { + searchp = nextp - windowLen - windowPos + w_offset; + } + + /* ĂǂA͂ɍ */ + if (*(searchp + 1) != *(nextp + 1) || *(searchp + 2) != *(nextp + 2)) + { + w_offset = LZOffsetTable[w_offset]; + continue; + } + + if (nextp - searchp < 2) + { + // VRAM2oCgANZXȂ̂ (VRAMf[^ǂݏoꍇ邽)A + // Ώۃf[^2oCgÕf[^ɂȂ΂ȂȂB + // + // ItZbg12rbgŊi[邽߁A4096ȉ + break; + } + tmpLength = 3; + searchHeadp = searchp + 3; + headp = nextp + 3; + + while (((u32)(headp - nextp) < remainSize) && (*headp == *searchHeadp)) + { + headp++; + searchHeadp++; + tmpLength++; + + // f[^4rbgŊi[邽߁A18ȉ (3̉ʂ͂) + if (tmpLength == (0xF + 3)) + { + break; + } + } + if (tmpLength > maxLength) + { + // ő咷ItZbgXV + maxLength = tmpLength; + maxOffset = (u16)(nextp - searchp); + if (maxLength == (0xF + 3)) + { + // vőȂ̂ŁAIB + break; + } + } + w_offset = LZOffsetTable[w_offset]; + } + + if (maxLength < 3) + { + return 0; + } + *offset = maxOffset; + return maxLength; +} + diff --git a/build/tools/makegcdfirm/compress.h b/build/tools/makegcdfirm/compress.h new file mode 100644 index 00000000..e3dc58f0 --- /dev/null +++ b/build/tools/makegcdfirm/compress.h @@ -0,0 +1,38 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: compress.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 COMPRESS_H_ +#define COMPRESS_H_ + +#include "misc.h" + + +/*---------------------------------------------------------------------------* + Name: MI_CompressLZ + + Description: LZ77ksȂ֐ + + Arguments: srcp kf[^ւ̃|C^ + size kf[^TCY + dstp kf[^ւ̃|C^ + kf[^傫TCỸobt@KvłB + + Returns: k̃f[^TCYB + *---------------------------------------------------------------------------*/ +u32 LZCompWrite(u8 *srcp, u32 size, u8 *dstp, int boundary); + + +#endif //COMPRESS_H_ diff --git a/build/tools/makegcdfirm/defval.c b/build/tools/makegcdfirm/defval.c new file mode 100644 index 00000000..679fb0e6 --- /dev/null +++ b/build/tools/makegcdfirm/defval.c @@ -0,0 +1,315 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makerom + File: defval.c + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: defval.c,v $ + Revision 1.10 2006/01/18 02:11:19 kitase_hirotake + do-indent + + Revision 1.9 2005/02/28 05:26:03 yosizaki + do-indent. + + Revision 1.8 2004/08/05 13:50:13 yasu + Support -M option + + Revision 1.7 2004/06/29 04:55:40 yasu + Use VBuffer to resolve variables + + Revision 1.6 2004/06/23 07:51:02 yasu + fix a bug as illegal memory freeing at ResolveDefVal() + + Revision 1.5 2004/05/27 00:40:49 yasu + care also about current directory (dot ".") + + Revision 1.4 2004/05/27 00:25:46 yasu + care about double-dots ".." for defvalue option :r, :e + + Revision 1.3 2004/05/27 00:11:19 yasu + fix a error when searching a "dot" of file extension + + Revision 1.2 2004/05/26 12:02:47 yasu + support :h, :t, :r, :e option for variable name + + Revision 1.1 2004/03/26 05:06:45 yasu + support variables like as -DNAME=VALUE + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include // getenv() +#include // strcasecmp() +#include // getopt() +#include "misc.h" +#include "defval.h" + +typedef struct tValdef +{ + struct tValdef *next; + char *name; + char *value; +} +tValdef; + +tValdef *valdef_top = NULL; + + +// +// Add new define value via file +// +// opt : "DEFINE=VALUE" +// +BOOL AddDefValFromFile(char *filename) +{ + char *buffer; + int buffer_size; + int read_size; + FILE *fp; + + if (filename[0] == '-' && filename[1] == '\0') + { + fp = stdin; + } + else if (NULL == (fp = fopen(filename, "rb"))) + { + fprintf(stderr, "Cannot open file \"%s\".\n", filename); + return FALSE; + } + + buffer_size = DEFVAL_DEFAULT_BUFFER_SIZE; + + if (NULL == (buffer = malloc(buffer_size))) + { + fprintf(stderr, "Cannot allocate memory.\n"); + return FALSE; + } + + read_size = 0; + + while (NULL != fgets(buffer + read_size, buffer_size - read_size, fp)) + { + read_size = strlen(buffer); + + if (read_size == buffer_size - 1 && buffer[read_size - 1] != '\n') + { + buffer_size *= 2; + + if (NULL == (buffer = realloc(buffer, buffer_size))) + { + fprintf(stderr, "Cannot allocate memory.\n"); + return FALSE; + } + continue; + } + + AddDefVal(buffer); + read_size = 0; + } + + if (fp != stdin) + { + fclose(fp); + } + free(buffer); + + return TRUE; +} + + +// +// Add new define value +// +// opt : "DEFINE=VALUE" +// +void AddDefVal(char *opt) +{ + int i; + tValdef *t; + + for (i = 0;; i++) + { + if ('=' == opt[i] || '\0' == opt[i]) + { + break; + } + } + + if (i > 0) + { + t = Alloc(sizeof(tValdef)); + t->name = strncpy(Alloc(i + 1), opt, i); + t->name[i] = '\0'; + + if (opt[i] == '=') + { + i++; + } + t->value = strdup(opt + i); + + t->next = valdef_top; + valdef_top = t; + + debug_printf("DEFINE:$(%s)=\"%s\"\n", t->name, t->value); + } + return; +} + +// +// Search define value +// +// Return: value of specified name +// +char *SearchDefVal(char *name) +{ + tValdef *t; + + for (t = valdef_top; t; t = t->next) + { + if (!strcmp(t->name, name)) + { + return t->value; + } + } + + return getenv(name); +} + + +// +// Search define value and Modify it by : option +// +// Return: duplicated value of specified name modified by :x option +// +char *SearchDefValWithOption(char *name) +{ + int len_name = strlen(name); + char *value; + char option = '\0'; + + if (len_name > 2 && name[len_name - 2] == ':') + { + name[len_name - 2] = '\0'; + option = name[len_name - 1]; + } + + value = SearchDefVal(name); + + if (value) + { + int value_len = strlen(value); + int col_dot = value_len; + int col_filename = 0; + int i; + + for (i = 0; i < value_len; i++) + { + switch (value[i]) + { + case '.': + if (col_filename == i && + (value[i + 1] == '\0' || (value[i + 1] == '.' && value[i + 2] == '\0'))) + { + i = value_len; // exit loop if last entry is . or .. + } + else + { + col_dot = i; // Save the last dot column + } + break; + + case '/': + case '\\': + case ':': + col_filename = i + 1; // Save the last filename + col_dot = value_len; // Reset dot position + break; + + default: + ; + } + } + + switch (option) + { + case 'h': // Dirname with the last slash + value = strdup(value); + value[col_filename] = '\0'; + break; + + case 't': // Filename + value = strdup(value + col_filename); + break; + + case 'r': // All without . file extension + value = strdup(value); + value[col_dot] = '\0'; + break; + + case 'e': // File extension + value = strdup(value + col_dot + 1); + break; + + default: + value = strdup(value); + } + } + return value; +} + + +// +// Resolve define value +// +// Return: new string +// +char *ResolveDefVal(char *str) +{ + int i, j; + char *val; + VBuffer buf; + + InitVBuffer(&buf); + + for (i = 0; '\0' != str[i]; i++) + { + // search $(XXX) + if ('$' == str[i] && '(' == str[i + 1]) + { + for (j = i + 2; '\0' != str[j]; j++) + { + if (')' == str[j]) + { + str[j] = '\0'; + + // get value of XXX + val = SearchDefValWithOption(&str[i + 2]); + + // copy value of XXX + if (val) + { + char *s = val; + + while (*s) + { + PutVBuffer(&buf, *s); + s++; + } + free(val); + } + i = j; + goto next; + } + } + } + PutVBuffer(&buf, str[i]); + next:; + } + return GetVBuffer(&buf); // pass allocated buffer, should be freed by caller +} diff --git a/build/tools/makegcdfirm/defval.h b/build/tools/makegcdfirm/defval.h new file mode 100644 index 00000000..71355101 --- /dev/null +++ b/build/tools/makegcdfirm/defval.h @@ -0,0 +1,38 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makerom + File: defval.h + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: defval.h,v $ + Revision 1.4 2006/01/18 02:11:19 kitase_hirotake + do-indent + + Revision 1.3 2005/02/28 05:26:03 yosizaki + do-indent. + + Revision 1.2 2004/08/05 13:50:13 yasu + Support -M option + + Revision 1.1 2004/03/26 05:06:45 yasu + support variables like as -DNAME=VALUE + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#ifndef DEFVAL_H_ +#define DEFVAL_H_ + +#define DEFVAL_DEFAULT_BUFFER_SIZE (1024) + +BOOL AddDefValFromFile(char *filename); +void AddDefVal(char *opt); +char *SearchDefVal(char *name); +char *ResolveDefVal(char *str); + +#endif //DEFVAL_H_ diff --git a/build/tools/makegcdfirm/elf.h b/build/tools/makegcdfirm/elf.h new file mode 100644 index 00000000..c360cd33 --- /dev/null +++ b/build/tools/makegcdfirm/elf.h @@ -0,0 +1,431 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - ELF + File: elf.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. + *---------------------------------------------------------------------------*/ + +#ifndef ELF_H_ +#define ELF_H_ + +#include "misc.h" + +/*--------------------------------------------------------- + ^` + --------------------------------------------------------*/ +typedef u32 Elf32_Addr; /* size:4, align:4 Unsigned program address */ +typedef u16 Elf32_Half; /* size:2, align:2 Unsigned medium int */ +typedef u32 Elf32_Off; /* size:4, align:4 Unsigned file offset */ +typedef s32 Elf32_Sword; /* size:4, align:4 Signed large int */ +typedef u32 Elf32_Word; /* size:4, align:4 Unsigned large int */ + +/*--------------------------------------------------------- + ELF Header + --------------------------------------------------------*/ +/* e_ident̃CfbNX */ +#define EI_MAG0 0 /* File identification */ +#define EI_MAG1 1 /* File identification */ +#define EI_MAG2 2 /* File identification */ +#define EI_MAG3 3 /* File identification */ +#define EI_CLASS 4 /* File class 0=invalid, 1=32bit, 2=64bit */ +#define EI_DATA 5 /* Data encoding 0=invalid, 1=LSB, 2=MSB */ +#define EI_VERSION 6 /* File version ݂1 */ +#define EI_PAD 7 /* Start of padding bytes */ +#define EI_NIDENT 16 /* Size of e_ident[] */ + +typedef struct { + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; /* ELF̌`(Ĕzu”\, s”\Ȃ) */ + Elf32_Half e_machine; /* t@CŗvA[LeN` */ + Elf32_Word e_version; /* ELFtH[}bg̃o[Wi݂1j */ + Elf32_Addr e_entry; /* vÕGg|CgBw薳Ȃ0B */ + Elf32_Off e_phoff; /* vOwb_e[ũt@C擪̃ItZbg */ + Elf32_Off e_shoff; /* ZNVwb_e[ũt@C擪̃ItZbg */ + Elf32_Word e_flags; /* vZbTŗL̃tO */ + Elf32_Half e_ehsize; /* ELFwb_̃TCY */ + Elf32_Half e_phentsize; /* 1vOwb_̃TCY */ + Elf32_Half e_phnum; /* vOwb_̐ */ + Elf32_Half e_shentsize; /* 1ZNVwb_̃TCY */ + Elf32_Half e_shnum; /* ZNVwb_̐ */ + Elf32_Half e_shstrndx; /* ZNVe[uZNVւ̃CfbNX */ +} Elf32_Ehdr; + +/* e_ident[EI_*]̒g` */ +#define ELFMAG0 0x7f +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFCLASSNONE 0 /* invalid */ +#define ELFCLASS32 1 /* ARM and Thumb processors use 32-bit ELF. */ +#define ELFCLASS64 2 +#define ELFDATANONE 0 /* invalid */ +#define ELFDATA2LSB 1 /* little-endian */ +#define ELFDATA2MSB 2 /* big-endian */ + + +/* [e_type] */ +#define ET_NONE 0 /* No file type */ +#define ET_REL 1 /* Re-locatable file */ +#define ET_EXEC 2 /* Executable file */ +#define ET_DYN 3 /* Shared object file */ +#define ET_CORE 4 /* Core file */ +#define ET_LOPROC 0xff00 /* Processor-specific */ +#define ET_HIPROC 0xffff /* Processor-specific */ + +/* [e_machine] */ +#define EM_NONE 0 /* No machine */ +#define EM_M32 1 +#define EM_SPARC 2 +#define EM_386 3 +#define EM_68K 4 +#define EM_88K 5 +#define EM_860 7 +#define EM_MIPS 8 +#define EM_MIPS_RS4_BE 10 +#define EM_ARM 40 /* ARM/Thumb Architecture */ + + +/* [e_version] This member identifies the object file version.*/ +#define EV_NONE 0 /* Invalid version */ +#define EV_CURRENT 1 /* Current version */ + + +/* + ARM-specific e_flags + e_flags Field Value Meaning + EF_ARM_HASENTRY (0x02) e_entry contains a program-loader entry point + (see section 4.1.1, Entry points, below). + EF_ARM_SYMSARESORTED (0x04) Each subsection of the symbol table is sorted by symbol value + (see section 4.4.8, Symbol table order, below) + EF_ARM_DYNSYMSUSESEGIDX (0x8) Symbols in dynamic symbol tables that are defined in sections + included in program segment n have st_shndx = n + 1. + (see section 4.4.9, Dynamic symbol table entries, below). + EF_ARM_MAPSYMSFIRST (0x10) Mapping symbols precede other local symbols in the symbol table + (see section 4.4.8, Symbol table order, below). + + EF_ARM_EABIMASK (0xFF000000)(current version is 0x02000000) + This masks an 8-bit version number, the version of the ARM + EABI to which this ELF file conforms. This EABI is version 2. A + value of 0 denotes unknown conformance. +*/ +#define EF_ARM_HASENTRY 0x02 +#define EF_ARM_SYMSARESORTED 0x04 +#define EF_ARM_DYNSYMSUSESEGIDX 0x8 +#define EF_ARM_MAPSYMSFIRST 0x10 +#define EF_ARM_EABIMASK 0xFF000000 + + +/*--------------------------------------------------------- + Program headers + --------------------------------------------------------*/ +typedef struct { + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; +} Elf32_Phdr; + +/* [p_type] */ +#define PT_NULL 0 /* gȂGgŁÃo̒l̈Ӗ͖` */ +#define PT_LOAD 1 /* sɃ[hZOg */ +#define PT_DYNAMIC 2 /* I\̔zێZOg */ +#define PT_INTERP 3 /* t@C̉߂ɎgC^v^̃pXێZOg */ +#define PT_NOTE 4 /* t@C̉߂ɂ͎gȂێZOg */ +#define PT_SHLIB 5 /* \ */ +#define PT_PHDR 6 /* vOwb_e[uivÕC[Ẅꕔłꍇ̂ݑ݁j */ +//#define PT_TLS ? /* XbhǏL̈̃ev[g */ + +#define PT_LOOS 0x60000000 /* OSŗLɗ\񂳂ꂽ̈ */ +#define PT_HIOS 0x6fffffff + +#define PT_LOPROC 0x70000000 /* vZbTŗLɗ\񂳂ꂽ̈ */ +#define PT_HIPROC 0x7fffffff + +/* [p_flags]*/ +#define PF_X 1 /*s”\*/ +#define PF_W 2 /*݉”\*/ +#define PF_R 4 /*ǂݏo”\*/ +#define PF_ARM_SB 0x10000000 /*The segment contains the location addressed by the static base*/ +#define PF_ARM_PI 0x20000000 /*The segment is position-independent*/ +#define PF_ARM_ENTRY 0x80000000 /*The segment contains the entry point*/ +#define PF_MASKPROC 0xf0000000 + + +/*--------------------------------------------------------- + Section headers + --------------------------------------------------------*/ +typedef struct { + Elf32_Word sh_name; /*ZNVwb_e[uZNṼCfbNX*/ + Elf32_Word sh_type; /* ^CviL`QƁj */ + Elf32_Word sh_flags; + Elf32_Addr sh_addr; /* */ + Elf32_Off sh_offset; /* t@C̐擪̃ItZbg */ + Elf32_Word sh_size; /* oCgPʂ̃TCY */ + Elf32_Word sh_link; /* sh_typeɂĒl̈Ӗς */ + Elf32_Word sh_info; /* sh_typeɂĒl̈Ӗς */ + Elf32_Word sh_addralign; /* ACg(0or1ŐȂ,44ByteAlign) */ + Elf32_Word sh_entsize; /* ŒTCỸGge[uꍇA1vf̃TCY */ +} Elf32_Shdr; + +/* sh_addr mod sh_addralign = 0 łȂ΂ȂȂ */ + +/* Section Types, [sh_type] */ +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xffffffff + + +/* [sh_flags] */ +#define SHF_WRITE 0x1 +#define SHF_ALLOC 0x2 +#define SHF_EXECINSTR 0x4 +#define SHF_MASKPROC 0xf0000000 +/* ARM-EABI-specific */ +#define SHF_ENTRYSECT 0x10000000 /* The section contains an entry point. */ +#define SHF_COMDEF 0x80000000 /* The section may be multiply defined in the input to a link step. */ +/* others */ +#define SHF_LINK_ORDER 0x80 + +/*ZNVCfbNX*/ +//Sym->st_shndxȂ +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_LOPROC 0xff00 +#define SHN_HIPROC 0xff1f +#define SHN_ABS 0xfff1 +#define SHN_COMMON 0xfff2 +#define SHN_HIRESERVE 0xffff + + +//̓wb_łȂ̃f[^\ + +/*--------------------------------------------------------- + Symbol Table Entry + --------------------------------------------------------*/ +typedef struct { + Elf32_Word st_name; /* V{e[ũCfbNX */ + Elf32_Addr st_value; /* 炭֘AZNVł̃ItZbgl */ + Elf32_Word st_size; /* TCYȂAsȏꍇ 0 */ + unsigned char st_info; /* oCh ^Cv */ + unsigned char st_other; /* ݂ 0 */ + Elf32_Half st_shndx; /* ֘AZNVwb_e[ũCfbNX */ +} Elf32_Sym; + + +/* st_info */ +#define ELF32_ST_BIND(i) ((i)>>4) +#define ELF32_ST_TYPE(i) ((i)&0xf) +#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) + +/* st_info BIND */ +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 +#define STB_LOPROC 13 +#define STB_HIPROC 15 + +/* st_info TYPE */ +#define STT_NOTYPE 0 /*`*/ +#define STT_OBJECT 1 /*f[^IuWFNg*/ +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 +#define STT_LOPROC 13 +#define STT_HIPROC 15 + + +/*--------------------------------------------------------- + Relocation Entry + --------------------------------------------------------*/ +typedef struct { + Elf32_Addr r_offset; + Elf32_Word r_info; +} Elf32_Rel; + +typedef struct { + Elf32_Addr r_offset; + Elf32_Word r_info; + Elf32_Sword r_addend; +} Elf32_Rela; + +#define ELF32_R_SYM(i) ((i)>>8) +#define ELF32_R_TYPE(i) ((unsigned char)(i)) +#define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t)) + + +/* r_info TYPE */ +#define R_ARM_NONE 0 /* Any No relocation. Encodes dependencies between sections. */ +#define R_ARM_PC24 1 /* ARM B/BL S . P + A */ +#define R_ARM_ABS32 2 /* 32-bit word S + A */ +#define R_ARM_REL32 3 /* 32-bit word S . P + A */ +#define R_ARM_PC13 4 /* ARM LDR r, [pc,c] S . P + A */ +#define R_ARM_ABS16 5 /* 16-bit half-word S + A */ +#define R_ARM_ABS12 6 /* ARM LDR/STR S + A */ +#define R_ARM_THM_ABS5 7 /* Thumb LDR/STR S + A */ +#define R_ARM_ABS8 8 /* 8-bit byte S + A */ +#define R_ARM_SBREL32 9 /* 32-bit word S . B + A */ +#define R_ARM_THM_PC22 10 /* Thumb BL pair S . P+ A */ +#define R_ARM_THM_PC8 11 /* Thumb LDR r, [pc,c] S . P + A */ +#define R_ARM_AMP_VCALL9 12 /* AMP VCALL Obsolete.SA-1500 only. */ +#define R_ARM_SWI24 13 /* ARM SWI S + A */ +#define R_ARM_THM_SWI8 14 /* Thumb SWI S + A */ +#define R_ARM_XPC25 15 /* ARM BLX S . P+ A */ +#define R_ARM_THM_XPC22 16 /* Thumb BLX pair S . P+ A */ + +/* 17-31, reserved to ARM Linux */ +//17-19 Reserved to ARM LINUX +#define R_ARM_COPY 20 /* 32 bit word Copy symbol at dynamic link time. */ +#define R_ARM_GLOB_DAT 21 /* 32 bit word Create GOT entry. */ +#define R_ARM_JUMP_SLOT 22 /* 32 bit word Create PLT entry. */ +#define R_ARM_RELATIVE 23 /* 32 bit word Adjust by program base. */ +#define R_ARM_GOTOFF 24 /* 32 bit word Offset relative to start of GOT. */ +#define R_ARM_GOTPC 25 /* 32 bit word Insert address of GOT. */ +#define R_ARM_GOT32 26 /* 32 bit word Entry in GOT. */ +#define R_ARM_PLT32 27 /* ARM BL Entry in PLT. */ + +/* 28-31 Reserved to ARM LINUX */ +#define R_ARM_ALU_PCREL_7_0 32 /* ARM ADD/SUB (S . P + A) & 0x000000FF */ +#define R_ARM_ALU_PCREL_15_8 33 /* ARM ADD/SUB (S . P + A) & 0x0000FF00 */ +#define R_ARM_ALU_PCREL_23_15 34 /* ARM ADD/SUB (S . P + A) & 0x00FF0000 */ +#define R_ARM_LDR_SBREL_11_0 35 /* ARM LDR/STR (S . B + A) & 0x00000FFF */ +#define R_ARM_ALU_SBREL_19_12 36 /* ARM ADD/SUB (S . B + A) & 0x000FF000 */ +#define R_ARM_ALU_SBREL_27_20 37 /* ARM ADD/SUB (S . B + A) & 0x0FF00000 */ + +#define R_ARM_TARGET1 38 +#define R_ARM_ROSEGREL32 39 +#define R_ARM_V4BX 40 +#define R_ARM_TARGET2 41 +#define R_ARM_PREL31 42 + +/* 96-111, reserved to ARM g++ */ +#define R_ARM_GNU_VTENTRY 100 /* 32 bit word Record C++ vtable entry. */ +#define R_ARM_GNU_VTINHERIT 101 /* 32 bit word Record C++ member usage. */ +#define R_ARM_THM_PC11 102 /* Thumb B S . P + A */ +#define R_ARM_THM_PC9 103 /* Thumb B S . P + A */ + +/* 112-127, reserved for private experiments */ + +/* 128-248, reserved to ARM */ +#define R_ARM_RXPC25 249 /* ARM BLX (S . P) + A #define For calls between program segments. */ +#define R_ARM_RSBREL32 250 /* Word (S . SB) + A For an offset from SB, the static base. */ +#define R_ARM_THM_RPC22 251 /* Thumb BL/BLX pair (S . P) + A For calls between program segments. */ +#define R_ARM_RREL32 252 /* Word (S . P) + A For on offset between two segments. */ +#define R_ARM_RABS32 253 /* Word S + A For the address of a location in the target segment. */ +#define R_ARM_RPC24 254 /* ARM B/BL (S . P) + A For calls between program segments. */ +#define R_ARM_RBASE 255 /* None None.Identifies the segment being relocated by the following + relocation directives. The ARM EABI poses two problems for relocating + executables and shared objects encoded in */ + + +// shirait +#define R_ARM_LDR_PC_G0 4 //LDR + +#define R_ARM_ABS12 6 //LDR, STR + +#define R_ARM_THM_CALL 10 //R_ARM_THM_PC22Ɠ + +#define R_ARM_CALL 28 //BL/BLX +#define R_ARM_JUMP24 29 //B/BL +#define R_ARM_THM_JUMP24 30 + +#define R_ARM_MOVW_ABS_NC 43 //MOVW +#define R_ARM_MOVT_ABS 44 //MOVT +#define R_ARM_MOVW_PREL_NC 45 //MOVW +#define R_ARM_MOVT_PREL 46 //MOVT + +#define R_ARM_ALU_PC_G0_NC 57 //ADD, SUB +#define R_ARM_ALU_PC_G0 58 //ADD, SUB +#define R_ARM_ALU_PC_G1_NC 59 //ADD, SUB +#define R_ARM_ALU_PC_G1 60 //ADD, SUB +#define R_ARM_ALU_PC_G2 61 //ADD, SUB +#define R_ARM_LDR_PC_G1 62 //LDR, STR, LDRB, STRB +#define R_ARM_LDR_PC_G2 63 //LDR, STR, LDRB, STRB +#define R_ARM_LDRS_PC_G0 64 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_PC_G1 65 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_PC_G2 66 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDC_PC_G0 67 //LDC, STC +#define R_ARM_LDC_PC_G1 68 //LDC, STC +#define R_ARM_LDC_PC_G2 69 //LDC, STC +#define R_ARM_ALU_SB_G0_NC 70 //ADD, SUB +#define R_ARM_ALU_SB_G0 71 //ADD, SUB +#define R_ARM_ALU_SB_G1_NC 72 //ADD, SUB +#define R_ARM_ALU_SB_G1 73 //ADD, SUB +#define R_ARM_ALU_SB_G2 74 //ADD, SUB +#define R_ARM_LDR_SB_G0 75 //LDR, STR, LDRB, STRB +#define R_ARM_LDR_SB_G1 76 //LDR, STR, LDRB, STRB +#define R_ARM_LDR_SB_G2 77 //LDR, STR, LDRB, STRB +#define R_ARM_LDRS_SB_G0 78 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_SB_G1 79 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_SB_G2 80 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDC_SB_G0 81 //LDC, STC +#define R_ARM_LDC_SB_G1 82 //LDC, STC +#define R_ARM_LDC_SB_G2 83 //LDC, STC +#define R_ARM_MOVW_BREL_NC 84 //MOVW +#define R_ARM_MOVT_BREL 85 //MOVT +#define R_ARM_MOVW_BREL 86 //MOVW + +#define R_ARM_GOT_BREL12 97 //LDR +#define R_ARM_GOTOFF12 98 //LDR, STR + +#define R_ARM_TLS_LDO12 109 //LDR, STR +#define R_ARM_TLS_LE12 110 //LDR, STR +#define R_ARM_TLS_TE12GP 111 //LDR + + + +/*--------------------------------------------------------- + Dynamic Section elf_v1.2 + --------------------------------------------------------*/ +typedef struct { + Elf32_Sword d_tag; + union { + Elf32_Word d_val; + Elf32_Addr d_ptr; + } d_un; +} Elf32_Dyn; + + +/* Additional symbol types for Thumb. */ +#define STT_ARM_TFUNC STT_LOPROC /* A Thumb function. */ +#define STT_ARM_16BIT STT_HIPROC /* A Thumb label. */ + + + + + + + + + +/*--------------------------------------------------------- + ELFwb_ǂݏo + --------------------------------------------------------*/ +void *ELF_LoadELFHeader(const void *buf, Elf32_Ehdr *ehdr); + + + +#endif /* ELF_H_ */ + diff --git a/build/tools/makegcdfirm/format_nlist.h b/build/tools/makegcdfirm/format_nlist.h new file mode 100644 index 00000000..e3bee645 --- /dev/null +++ b/build/tools/makegcdfirm/format_nlist.h @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makegcdfirm + File: format_nlist.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 FORMAT_NLIST_H_ +#define FORMAT_NLIST_H_ + +#include +#include "misc.h" +#include "path.h" + +#define SPECFILE_MAGIC_ID "#NORSF" + +#define CRC16_INIT_VALUE 0xffff + +//--------------------------------------------------------------------------- +// Banner Spec File +//--------------------------------------------------------------------------- + +// Command List +typedef struct +{ + char *string; + BOOL (*funcp) (char *, int num); + +} +tCommandDesc; + + +// F Command +typedef struct +{ + u32 offsetStart; + u32 offsetEnd; + u32 padding; + char fullPathSrc[FILENAME_MAX]; + +} +tFileDesc; + + +#endif // FORMAT_NLIST_H_ diff --git a/build/tools/makegcdfirm/format_rom.h b/build/tools/makegcdfirm/format_rom.h new file mode 100644 index 00000000..c1c6d89e --- /dev/null +++ b/build/tools/makegcdfirm/format_rom.h @@ -0,0 +1,59 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makegcdfirm + File: format_rom.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 FORMAT_ROM_H_ +#define FORMAT_ROM_H_ + +#include "misc.h" +#include + + +#define DEFAULT_ALIGN 0x200 +#define FIRM_ALIGN DEFAULT_ALIGN +#define FIRM_ALIGN_MASK (FIRM_ALIGN - 1) + +#define NML_AREA_ALIGN 0x80000 // 512KB +#define TWL_AREA_ALIGN 0x80000 // 512KB +#define SEC2_AREA_OFFSET 0x3000 // 12KB +#define GAME2_AREA_OFFSET 0x7000 // 28KB + +#define DEFAULT_HOSTROOT "." +#define DEFAULT_ROOT "/" + +#define DEFAULT_REJECT_1 "CVS" +#define DEFAULT_REJECT_2 "vssver.scc" + +#define FORMAT_VERSION "1.0" + +#define ENTRYNAME_MAX 127 + +#define ROM_SIZE_MIN 0x20000 + +#define DEFAULT_ROMHEADER_TEMPLATE "gcdfirm_header_twlj.template.sbin" +#define DEFAULT_LISTFILE "default.nlf" + +#define DEFAULT_NORFIRM_SUFFIX ".gcd" +#define DEFAULT_SPECFILE_SUFFIX ".gcdsf" + +/*===========================================================================* + * ROM FORMAT + *===========================================================================*/ + +//--------------------------------------------------------------------------- +// ROM HEADER +//--------------------------------------------------------------------------- + +#endif //FORMAT_ROM_H_ diff --git a/build/tools/makegcdfirm/format_sign.h b/build/tools/makegcdfirm/format_sign.h new file mode 100644 index 00000000..782a5d2b --- /dev/null +++ b/build/tools/makegcdfirm/format_sign.h @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - SS + File: format_sign.h + + Copyright 2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_MAKENORFIRM_ACSIGN_FORMAT_H_ +#define FIRM_MAKENORFIRM_ACSIGN_FORMAT_H_ + +#include "format_rom.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_MAKENORFIRM_ACSIGN_FORMAT_H_ */ +#endif diff --git a/build/tools/makegcdfirm/gcdfirm_header_twlj.template.sbin b/build/tools/makegcdfirm/gcdfirm_header_twlj.template.sbin new file mode 100644 index 00000000..06a88213 Binary files /dev/null and b/build/tools/makegcdfirm/gcdfirm_header_twlj.template.sbin differ diff --git a/build/tools/makegcdfirm/makegcdfirm.c b/build/tools/makegcdfirm/makegcdfirm.c new file mode 100644 index 00000000..887cc4c8 --- /dev/null +++ b/build/tools/makegcdfirm/makegcdfirm.c @@ -0,0 +1,111 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makegcdfirm + File: makegcdfirm.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:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include +#include // strcasecmp() +#include // getopt() +#include "makegcdfirm.h" +#include "format_rom.h" +#include "path.h" +#include "defval.h" +#include "version.h" + +static int makegcdfirm(const char *specFile, const char *norFile, const char *rhFile); + +//--------------------------------------------------------------------------- +// Main +//--------------------------------------------------------------------------- + +int main(int argc, char *argv[]) +{ + int n; + int narg; + char *gcdfirmFile; + char *rhFile = NULL; + + InitAppName(argv[0]); + + while ((n = getopt(argc, argv, "D:hvt:pd")) != -1) + { + switch (n) + { + case 'h': + case 'v': + goto usage; + + case 'D': + AddDefVal(optarg); + break; + + case 't': + rhFile = optarg; + break; + + case 'p': + PrintMode = TRUE; + break; + + case 'd': + DebugMode = TRUE; + break; + + default: + break; + } + } + + narg = argc - optind; + if (narg > 0) + { + // Make SpecFile->GcdfirmFile + gcdfirmFile = + strdup(narg > + 1 ? argv[optind + 1] : ChangeSuffix(argv[optind], DEFAULT_NORFIRM_SUFFIX)); + return makegcdfirm(argv[optind], gcdfirmFile, rhFile); + } + + usage: + { + char *makegcdfirm = GetAppName(); + + fprintf(stderr, + "NITRO-SDK Development Tool - %s - Make gcdfirm file \n" + "Build %lu\n\n" + "Usage: %s [-phv] [-tROMHEADERFILE] [-DNAME=VALUE ...] SPECFILE [NORFIRMFILE]\n\n", + makegcdfirm, SDK_DATE_OF_LATEST_FILE, makegcdfirm); + } + return 1; +} + + +//--------------------------------------------------------------------------- +// makegcdfirm +//--------------------------------------------------------------------------- + +static int makegcdfirm(const char *specFile, const char *norFile, const char *rhFile) +{ + debug_printf("makegcdfirm(): '%s' -> '%s'\n", specFile, norFile); + + // Check identical + if (specFile && norFile && !strcasecmp(specFile, norFile)) + { + error("gcdfirm spec file is identical '%s'", norFile); + return 1; + } + + return OutputGcdfirmFile(specFile, norFile, rhFile) ? 0 : 1; +} diff --git a/build/tools/makegcdfirm/makegcdfirm.h b/build/tools/makegcdfirm/makegcdfirm.h new file mode 100644 index 00000000..803ce06f --- /dev/null +++ b/build/tools/makegcdfirm/makegcdfirm.h @@ -0,0 +1,24 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makegcdfirm + File: makegcdfirm.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 MAKEGCDFIRM_H_ +#define MAKEGCDFIRM_H_ + +#include "misc.h" + +BOOL OutputGcdfirmFile(const char *specFile, const char *gcdFile, const char *rhFile); + +#endif //MAKEGCDFIRM_H_ diff --git a/build/tools/makegcdfirm/misc.c b/build/tools/makegcdfirm/misc.c new file mode 100644 index 00000000..7706d6be --- /dev/null +++ b/build/tools/makegcdfirm/misc.c @@ -0,0 +1,628 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: misc.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include // calloc() +#include // free(), exit() +#include // setmode() +#include // stat() +#include // setmode() +#include // strlen() +#include // va_start(),va_end() +#include // localtime() + +#include +#include "misc.h" + +BOOL DebugMode = FALSE; +BOOL PrintMode = FALSE; +char *PubkeyFileName = NULL; + +/*---------------------------------------------------------------------------* + * File Output Utilities + * + * BOOL OpenFile( const char* filename ) + * void CloseFile( void ) + * BOOL CheckResult( void ) + * void PutBuffer( const void* ptr, int len ) + * void PutByte( u8 c ) + * void PutWord( u16 c ) + * void PutWord( u32 c ) + * void PutString( const char *str ) + *---------------------------------------------------------------------------*/ + +static FILE *OutFile = NULL; +static const char *FileName = NULL; +static BOOL Status = FALSE; + + +// +// File Open +// + +BOOL OpenFile(const char *filename) +{ + if (OutFile) + CloseFile(); + + if (filename) + { + if (NULL == (OutFile = fopen(filename, "wb+"))) + { + error("Can't write '%s'", filename); + Status = FALSE; + return FALSE; + } + } + else + { + setmode(1, O_BINARY); + OutFile = stdout; // out to console if filename == NULL + } + FileName = filename; + Status = TRUE; + + return TRUE; +} + + +// +// File Close +// + +BOOL CloseFile(void) +{ + if (OutFile) + { + if (FileName) + { + if (fclose(OutFile) == -1) + { + error("Can't close '%s'", FileName); + Status = FALSE; + } + } + else + { + setmode(1, O_TEXT); + } + } + OutFile = NULL; + + return Status; +} + + +// +// File Seek +// + +void SeekFile(long pos) +{ + if (OutFile && fseek(OutFile, pos, SEEK_SET)) + { + error("Can't seek '%s'", FileName ? FileName : ""); + CloseFile(); + Status = FALSE; + } +} + + +// +// Error Check +// + +BOOL CheckResult(void) +{ + return Status; +} + + +// +// Delete outfile +// + +void DeleteOutFile(void) +{ + // Delete outfile + if (FileName) + { + debug_printf("Delete '%s'\n", FileName); + (void)unlink(FileName); + FileName = NULL; + } + return; +} + + +// +// Buffer Output +// + +void PutBuffer(const void *ptr, int len) /* If error, close file */ +{ + if (OutFile && len != fwrite(ptr, 1, len, OutFile)) + { + error("Can't write buffer to '%s'", FileName ? FileName : ""); + CloseFile(); + Status = FALSE; + } +} + +// +// Buffer Input +// + +void GetBuffer(void *ptr, int len) /* If error, close file */ +{ + if (OutFile && len != fread(ptr, 1, len, OutFile)) + { + error("Can't read '%s'", FileName ? FileName : ""); + CloseFile(); + Status = FALSE; + } +} + +// +// Byte/Half/Word Output +// + +void PutByte(u8 c) +{ + PutBuffer(&c, 1); +} +void PutHalf(u16 c) +{ + PutBuffer(&c, 2); +} +void PutWord(u32 c) +{ + PutBuffer(&c, 4); +} +void PutString(const char *str) +{ + PutBuffer(str, strlen(str)); +} + + +// +// Printf +// + +void PrintString(const char *fmt, ...) +{ + char *buffer; + va_list va; + int nchars; + int bufsize = FILENAME_MAX; + + while (1) + { + buffer = Alloc(bufsize); + va_start(va, fmt); + nchars = vsnprintf(buffer, bufsize, fmt, va); + va_end(va); + + if (0 <= nchars && nchars < bufsize) + { + break; + } + + Free(&buffer); + bufsize *= 2; + } + + if (nchars > 0) + { + PutBuffer(buffer, nchars); + } + Free(&buffer); +} + + +/*---------------------------------------------------------------------------* + * File Read/Write Utilities + * + * int ReadFile( const char* filename, void** buffer ) + * + * Read a file to buffer allocated internally + * Return read size + * Add '\0' at tail of file for help to handle text file + * + * BOOL WriteFile( const char* filename, void** buffer, int size ) + *---------------------------------------------------------------------------*/ + +int ReadFile(const char *filename, void *filebuffer, int size) +{ + FILE *fp; + struct stat fileStat; + int fileSize, readSize; + void **buffer = (void **)filebuffer; + + /* Check file */ + if (stat(filename, &fileStat) || !S_ISREG(fileStat.st_mode)) + { + goto error; + } + fileSize = fileStat.st_size; + if (fileSize < 0) + { + goto error; + } + + /* Open file */ + fp = fopen(filename, "rb"); + if (!fp) + { + goto error; + } + + if (size && (size < fileSize)) + { + readSize = size; + } + else + { + readSize = fileSize; + } + + /* Read file */ + *buffer = Alloc(readSize + 1); /* error handle is done in Alloc() */ + /* size+1 for '\0' to handle text file */ + if (readSize != fread(*buffer, sizeof(char), readSize, fp)) + { + goto error_free_close; + } + + (*(char **)buffer)[readSize] = '\0'; /* Works as terminater if file is text file */ + + /* Close file */ + fclose(fp); + return readSize; + + error_free_close: + Free(buffer); + fclose(fp); + error: + error("Can't read '%s'", filename); + return -1; +} + + +int ReadFileWithPadding(const char *filename, void *filebuffer, int size, int boundary) +{ + FILE *fp; + struct stat fileStat; + int fileSize, readSize, padSize; + void **buffer = (void **)filebuffer; + + if (!boundary) + { + return ReadFile(filename, buffer, size); + } + + /* Check file */ + if (stat(filename, &fileStat) || !S_ISREG(fileStat.st_mode)) + { + goto error; + } + fileSize = fileStat.st_size; + if (fileSize < 0) + { + goto error; + } + + /* Open file */ + fp = fopen(filename, "rb"); + if (!fp) + { + goto error; + } + + if (size && (size < fileSize)) + { + readSize = size; + } + else + { + readSize = fileSize; + } + + padSize = (boundary - (readSize & (boundary-1))) & (boundary-1); + + /* Read file */ + *buffer = Alloc(readSize + padSize); /* error handle is done in Alloc() */ + /* size+1 for '\0' to handle text file */ + if (readSize != fread(*buffer, sizeof(char), readSize, fp)) + { + goto error_free_close; + } + + memset((char*)*buffer + readSize, 0, padSize); + + /* Close file */ + fclose(fp); + return readSize + padSize; + + error_free_close: + Free(buffer); + fclose(fp); + error: + error("Can't read '%s'", filename); + return -1; +} + + +BOOL WriteFile(const char *filename, void *buffer, int size) +{ + debug_printf("WriteFile %s\n", filename); + + (void)OpenFile(filename); + PutBuffer(buffer, size); + CloseFile(); + Free(&buffer); + return CheckResult(); +} + + +/*---------------------------------------------------------------------------* + * Time Format Utilities + * + * char* GetGMTime( const time_t time ) Show GMT + * char* GetTime( const time_t time ) Show local Time + *---------------------------------------------------------------------------*/ + +char *GetGMTime(const time_t time) +{ + static char timebuffer[32]; + strftime(timebuffer, sizeof(timebuffer), "%y/%m/%d-%H:%M:%S", gmtime(&time)); + return timebuffer; +} + + +char *GetTime(const time_t time) +{ + static char timebuffer[32]; + strftime(timebuffer, sizeof(timebuffer), "%y/%m/%d-%H:%M:%S", localtime(&time)); + return timebuffer; +} + + +/*---------------------------------------------------------------------------* + * Memory Allocation Utilities + * + * void* Alloc( size_t size ) + *---------------------------------------------------------------------------*/ + +void *Alloc(size_t size) +{ + void *t = calloc(1, size); + + if (t == NULL) + { + error("Can't allocate memory."); + exit(10); + } + return t; +} + + +void Free(void *p) +{ + void **ptr = (void **)p; + + if (*ptr) + { + free(*ptr); + (*ptr) = NULL; + } +} + + +/*---------------------------------------------------------------------------* + * VBuffer + * + * void PutVBuffer( VBuffer* vbuf, char c ) + *---------------------------------------------------------------------------*/ + +void PutVBuffer(VBuffer * vbuf, char c) +{ + int size; + char *tmp_buffer; + + if (vbuf->buffer == 0) + { + vbuf->size = VBUFFER_INITIAL_SIZE; + vbuf->buffer = Alloc(vbuf->size); // buffer is CALLOCed + } + size = strlen(vbuf->buffer); + + if (size >= vbuf->size - 1) + { + // Need buffer expansion + vbuf->size *= 2; + tmp_buffer = Alloc(vbuf->size); // buffer is CALLOCed + strcpy(tmp_buffer, vbuf->buffer); + Free(&vbuf->buffer); + vbuf->buffer = tmp_buffer; + } + vbuf->buffer[size] = c; + return; +} + +char *GetVBuffer(VBuffer * vbuf) +{ + return vbuf->buffer; +} + +void InitVBuffer(VBuffer * vbuf) +{ + vbuf->buffer = 0; + vbuf->size = 0; +} + +void FreeVBuffer(VBuffer * vbuf) +{ + Free(&vbuf->buffer); +} + + +/*---------------------------------------------------------------------------* + * File Path Utilities + * + * char* ChangeBackSlash( char* path ) + *---------------------------------------------------------------------------*/ + +char *ChangeBackSlash(char *path) +{ + char *p = path; + + while (*p) + { + if (*p == '\\') + { + *p = '/'; + } + p++; + } + return path; +} + + +/*---------------------------------------------------------------------------* + * Math + * + * u16 CalcCRC16( u16 start, u8 *data, int size ) + *---------------------------------------------------------------------------*/ + +static u16 crc16_table[16] = { + 0x0000, 0xCC01, 0xD801, 0x1400, + 0xF001, 0x3C00, 0x2800, 0xE401, + 0xA001, 0x6C00, 0x7800, 0xB401, + 0x5000, 0x9C01, 0x8801, 0x4400 +}; + +u16 CalcCRC16(u16 start, u8 *data, int size) +{ + u16 r1; + u16 total = start; + + while (size-- > 0) + { + // 4bit + r1 = crc16_table[total & 0xf]; + total = (total >> 4) & 0x0fff; + total = total ^ r1 ^ crc16_table[*data & 0xf]; + + // 4bit + r1 = crc16_table[total & 0xf]; + total = (total >> 4) & 0x0fff; + total = total ^ r1 ^ crc16_table[(*data >> 4) & 0xf]; + + data++; + } + return total; +} + + +/*---------------------------------------------------------------------------* + * for firm header + * + *---------------------------------------------------------------------------*/ + +static u8 ConvertAlign( u32 ofs ) +{ + u8 i; + + ofs /= 4; + for (i=0; i<7; i++) + { + if ( ofs & 1 ) + { + break; + } + ofs >>= 1; + } + + return i; +} + +tROMAddrConvType ConvertHeaderRamAddr( s32 p ) +{ + tROMAddrConvType retval; + + retval.align = ConvertAlign( p ); + retval.address = (u16)((p - HW_WRAM)/(4< + +typedef enum +{ + FALSE = 0, + TRUE = 1 +} +BOOL; + +typedef unsigned char u8; +typedef unsigned short int u16; +typedef unsigned long int u32; +typedef unsigned long long u64; +typedef signed char s8; +typedef signed short int s16; +typedef signed long int s32; +typedef signed long long s64; +typedef volatile u8 vu8; +typedef volatile u32 vu32; +typedef vu32 REGType32v; + +#define error(...) do { fprintf(stderr, "Error: "); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); } while(0) + +#define warning(...) do { fprintf(stderr, "Warning: "); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); } while(0) + +BOOL OpenFile(const char *filename); +BOOL CloseFile(void); +void SeekFile(long pos); +BOOL CheckResult(void); +void DeleteOutFile(void); +void PutBuffer(const void *ptr, int len); +void GetBuffer(void *ptr, int len); +void PutByte(u8 c); +void PutHalf(u16 c); +void PutWord(u32 c); +void PutString(const char *str); +void PrintString(const char *fmt, ...); + +#define READ_ALL 0 +int ReadFile(const char *filename, void *filebuffer, int size); +int ReadFileWithPadding(const char *filename, void *filebuffer, int size, int boundary); +BOOL WriteFile(const char *filename, void *buffer, int size); + +char *GetGMTime(const time_t time); +char *GetTime(const time_t time); + +void *Alloc(size_t size); +void Free(void *p); + +typedef struct +{ + char *buffer; + int size; +} +VBuffer; + +#define VBUFFER_INITIAL_SIZE 1024 +void InitVBuffer(VBuffer * vbuf); +void FreeVBuffer(VBuffer * vbuf); +void PutVBuffer(VBuffer * vbuf, char c); +char *GetVBuffer(VBuffer * vbuf); + +char *ChangeBackSlash(char *path); + +u16 CalcCRC16(u16 start, u8 *data, int size); +const char *WrapNull(const char *str); + +typedef struct +{ + u16 address; + u8 align; +} +tROMAddrConvType; + +tROMAddrConvType ConvertHeaderRamAddr( s32 p ); +tROMAddrConvType ConvertHeaderRomOffset( s32 p ); +u16 ConvertHeaderRomOffsetAlign( s32 p, u32 align ); + +typedef union +{ + struct + { + u32 sign:1; + u32 header_hash:1; + u32 arm9_hash:1; + u32 arm7_hash:1; + u32 hash_table_hash:1; + u32 final_hash:1; + u32 header_footer:1; + } + e; + u32 raw; +} +tErrorFlags; + +extern BOOL DebugMode; +extern BOOL PrintMode; +extern char *PubkeyFileName; +void debug_printf(const char *str, ...); +void debug_printf2(const char *str, ...); + +#endif //MISC_H_ diff --git a/build/tools/makegcdfirm/out_gcdfirm.c b/build/tools/makegcdfirm/out_gcdfirm.c new file mode 100644 index 00000000..6e33fa88 --- /dev/null +++ b/build/tools/makegcdfirm/out_gcdfirm.c @@ -0,0 +1,1009 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makegcdfirm + File: out_gcdfirm.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:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include // atoi() +#include // strcmp() +#include // isprint() +#include // chdir() +#include +#include // UCHAR_MAX +#include +#include // stat() +#include "elf.h" +#include "misc.h" +#include "defval.h" +#include "format_rom.h" +#include "format_nlist.h" +#include "makegcdfirm.h" +#include "format_sign.h" +#include "acsign_gcd.h" +#include "compress.h" + +#define SDK_ASM + +#include +#include "../acsign/aes2.h" + +#define ROMHDRCMD "ROM_HDR" +#define SBIN9CMD "ARM9_SBIN" +#define SBIN7CMD "ARM7_SBIN" +#define ELF9CMD "ARM9_ELF" +#define ELF7CMD "ARM7_ELF" +#define GAMECODECMD "GAMECODE" +#define ARM9X2CMD "ARM9_X2" +#define NMLOFSCMD "NML_OFS" +#define TWLOFSCMD "TWL_OFS" +#define VERCMD "VERSION" +#define RSAKEYCMD "RSA_KEY" +#define OUTKEYCMD "OUT_KEY" +#define WREGCMD "WRAM_RBIN" +#define NANDFMCMD "NANDFIRM" +#define NORFMCMD "NORFIRM" +#define ERRCMD "ERROR" + +static BOOL ConstructGcdfirmFile(char * specFile); +static BOOL ReadRomHeaderFile(const char *fileName); +static BOOL ReadSbinFile(const char *fileName, void* minfo, void* hash, BOOL comp); +static size_t ReadFirmFile(const char *fileName); +static BOOL ReadKeyFile(const char *fileName); +static BOOL ReadWramRegFile(const char *fileName); +static s32 GetRamAddr(const char *fileName); + +static BOOL EncryptBuffer(char *buffer, int length); + +static BOOL RomHeader_Command(char * line, int num); +static BOOL Sbin9_Command(char * line, int num); +static BOOL Sbin7_Command(char * line, int num); +static BOOL Elf9_Command(char * line, int num); +static BOOL Elf7_Command(char * line, int num); +static BOOL GAMECODE_Command(char * line, int num); +static BOOL ARM9X2_Command(char * line, int num); +static BOOL NMLOFS_Command(char * line, int num); +static BOOL TWLOFS_Command(char * line, int num); +static BOOL VERSION_Command(char * line, int num); +static BOOL RSAKEY_Command(char * line, int num); +static BOOL OUTKEY_Command(char * line, int num); +static BOOL WramRegs_Command(char * line, int num); +static BOOL NorFirm_Command(char * line, int num); +static BOOL NandFirm_Command(char * line, int num); +static BOOL ERROR_Command(char * line, int num); + +static BOOL InitializeAesKey(void); +static BOOL InitializeGcdfirmFile(const char *rhFile); +static BOOL FinalizeGcdfirmFile(const char *gcdFile); + +static s32 Offset; // Current offset +static int LineNum; // Line number for error message +static const char *specFileName; // specFile name for error message + +GCDHeader gcdHeader; // Gcdfirm Header Shadow +FIRMSignedContext signedContext; +u8 *keyFileBuf; +BOOL compArm9 = FALSE; +BOOL compArm7 = FALSE; +tErrorFlags errFlags; + +//--------------------------------------------------------------------------- +// Output - gcdfirm File +//--------------------------------------------------------------------------- + +BOOL OutputGcdfirmFile(const char *specFile, const char *gcdFile, const char *rhFile) +{ + char *buffer; + BOOL state; + + if (ReadFile(specFile, &buffer, READ_ALL) <= 0) + { + return FALSE; + } + + if (!OpenFile(gcdFile)) + { + return FALSE; + } + + specFileName = specFile; + + state = InitializeGcdfirmFile( rhFile ) && ConstructGcdfirmFile(buffer) && + FinalizeGcdfirmFile(gcdFile) && CloseFile(); + + if (!state) + { + DeleteOutFile(); + } + + return state; +} + + +//--------------------------------------------------------------------------- +// Output - Gcdfirm File +//--------------------------------------------------------------------------- + +static const tCommandDesc command[] = { + {ROMHDRCMD, RomHeader_Command}, + {SBIN9CMD, Sbin9_Command}, {SBIN7CMD, Sbin7_Command}, + {ELF9CMD, Elf9_Command},{ELF7CMD, Elf7_Command}, + {VERCMD, VERSION_Command}, + {GAMECODECMD, GAMECODE_Command}, + {ARM9X2CMD, ARM9X2_Command}, + {NMLOFSCMD, NMLOFS_Command}, + {TWLOFSCMD, TWLOFS_Command}, + {RSAKEYCMD, RSAKEY_Command}, + {OUTKEYCMD, OUTKEY_Command}, + {WREGCMD, WramRegs_Command}, + {NANDFMCMD, NandFirm_Command}, + {NORFMCMD, NorFirm_Command}, + {ERRCMD, ERROR_Command}, +}; + +BOOL ConstructGcdfirmFile(char * specFile) +{ + char *line; + char *line_top; + char *p; + int i; + + LineNum = 0; + Offset = 0x4000; + SeekFile(Offset); + + line = specFile++; + + while (*line != '\0') + { + LineNum++; + + // Get command line + line_top = line; + while (*line != '\0') + { + if (*line++ == '\n') + { + break; + } + } + + // Print for debug + debug_printf("GCDSF Line%4d [", LineNum, line); + for (p = line_top; p != line; p++) + { + if (isprint(*p)) + { + debug_printf("%c", *p); + } + } + debug_printf("]\n"); + + if (*line_top == '#') + { + } + else + { + for (i = 0; i < (sizeof(command) / sizeof(command[0])); i++) + { + if (!strncmp(line_top, command[i].string, strlen(command[i].string))) + { + if (command[i].funcp != NULL) + { + char line_cmd[FILENAME_MAX]; + char line_scan[FILENAME_MAX]; + char* line_conv; + int num; + + num = sscanf( line_top, + "%1024[^ :] : %1024[^ \x0d:#\n]", + line_cmd, line_scan + ); + line_conv = ResolveDefVal(line_scan); + + debug_printf("line_cmd = %s, line_conv = %s\n", line_cmd, line_conv); + + if (!command[i].funcp(line_conv, num - 1)) + return FALSE; + } + } + } + } + + } + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - 'RomHeader' Command +//--------------------------------------------------------------------------- + +static BOOL RomHeader_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("hom header file = %s\n", line); + + return ReadRomHeaderFile(line); +} + + +static BOOL ReadRomHeaderFile(const char *fileName) +{ + char *file; + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &file, READ_ALL)) < 0) + return FALSE; + + gcdHeader = *(GCDHeader*)file; + + // Output file image with fitting region + SeekFile(0L); + PutBuffer(file, file_size); + + Free(&file); + + return CheckResult(); +} + +//--------------------------------------------------------------------------- +// Output - 'WramRegs' Command +//--------------------------------------------------------------------------- + +extern MIHeader_WramRegs wram_regs_init; +MIHeader_WramRegs* wram_regs; + +static BOOL WramRegs_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("wram regs file = %s\n", line); + + return ReadWramRegFile(line); +} + +static BOOL ReadWramRegFile(const char *fileName) +{ + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &wram_regs, READ_ALL)) < 0) + return FALSE; + + gcdHeader.h.w = *wram_regs; + + return CheckResult(); +} + +//--------------------------------------------------------------------------- +// Output - 'RSAKEY' Command +//--------------------------------------------------------------------------- + +static BOOL RSAKEY_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("rsa key = %s\n", line); + + return ReadKeyFile(line); +} + +static BOOL ReadKeyFile(const char *fileName) +{ + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &keyFileBuf, READ_ALL)) < 0) + return FALSE; + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'OUTKEY' Command +//--------------------------------------------------------------------------- + +static BOOL OUTKEY_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("out key = %s\n", line); + + PubkeyFileName = line; + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'VERSION' Command +//--------------------------------------------------------------------------- + +static u8 ConvToBCD8(int x) +{ + u8 bcd = 0; + + x %= 100; + bcd |= (x / 10)<<4; + bcd |= (x % 10); + + return bcd; +} + +static BOOL VERSION_Command(char * line, int num) +{ + char scan[FILENAME_MAX]; + u64 version = -1; + + // rescan + num = sscanf( line, + "0x%1024[^\x0d\n]", + scan + ); + + if (num == 1) + { + // convert version info + version = strtoull(scan, NULL, 16); + } + else if (num == 0) + { + // generate version info + u8* ver8 = (u8*)&version; + time_t timer; + struct tm *t_st; + + time(&timer); + t_st = localtime(&timer); + + ver8[0] = ConvToBCD8(t_st->tm_min); + ver8[1] = ConvToBCD8(t_st->tm_hour); + ver8[2] = ConvToBCD8(t_st->tm_mday); + ver8[3] = ConvToBCD8(t_st->tm_mon+1); + ver8[4] = ConvToBCD8(t_st->tm_year); + ver8[5] = 0x57; + ver8[6] = 0xff; + ver8[7] = 0xff; + } + + debug_printf2("version = %08llx\n", version); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'NMLOFS' Command +//--------------------------------------------------------------------------- + +static BOOL NMLOFS_Command(char * line, int num) +{ + u32 offset = 0; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + offset = strtoul(line, NULL, 0); + + gcdHeader.l.normal_area_offset = offset / NML_AREA_ALIGN; + + debug_printf2("normal area offset = %#x\n", offset); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'TWLOFS' Command +//--------------------------------------------------------------------------- + +static BOOL TWLOFS_Command(char * line, int num) +{ + u32 offset = 0; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + offset = strtoul(line, NULL, 0); + + gcdHeader.l.twl_area_offset = offset / TWL_AREA_ALIGN; + + debug_printf2("twl area offset = %#x\n", offset); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'ARM9_X2' Command +//--------------------------------------------------------------------------- + +static BOOL ARM9X2_Command(char * line, int num) +{ + char* dbg_str = "FALSE"; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + if (!strcmp(line, "TRUE")) + { + gcdHeader.l.arm9_x2 = TRUE; + dbg_str = "TRUE"; + } + + debug_printf2("arm9 x2 = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'GAMECODE' Command +//--------------------------------------------------------------------------- + +static BOOL GAMECODE_Command(char * line, int num) +{ + u32 key; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + key = strtoul(line, NULL, 0); + + debug_printf2("keyinfo = %#x\n", key); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Elf9' Command +//--------------------------------------------------------------------------- + +static BOOL Elf9_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm9 elf = %s\n", line); + + { + s32 ramAddr = GetRamAddr(line); + gcdHeader.l.main_ram_address = (void*)ramAddr; + } + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Elf7' Command +//--------------------------------------------------------------------------- + +static BOOL Elf7_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm7 elf = %s\n", line); + + { + s32 ramAddr = GetRamAddr(line); + gcdHeader.l.sub_ram_address = (void*)ramAddr; + } + + return CheckResult(); +} + + +static s32 GetRamAddr(const char *fileName) +{ + Elf32_Ehdr *ehdr; + s32 ramAddr; + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &ehdr, sizeof(Elf32_Ehdr))) < 0) + return FALSE; + + ramAddr = ehdr->e_entry; + + Free(&ehdr); + + debug_printf2("ramaddr = 0x%08x\n", ramAddr); + + return ramAddr; +} + + +//--------------------------------------------------------------------------- +// Output - 'NANDFIRM' Command +//--------------------------------------------------------------------------- + +static BOOL NandFirm_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("nandfirm = %s\n", line); + + if ( ! line ) + { + return TRUE; + } + + // Set NANDFIRM ROM Offset + if (!Offset) + { + Offset = sizeof(GCDHeader); + SeekFile(Offset); + } + debug_printf2("romoffset = %#x\n", Offset); + { + gcdHeader.l.nandfirm_offset = Offset; + gcdHeader.l.nandfirm_size = ReadFirmFile(line); + } + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'NORFIRM' Command +//--------------------------------------------------------------------------- + +static BOOL NorFirm_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("norfirm = %s\n", line); + + if ( ! line ) + { + return TRUE; + } + + // Set NORFIRM ROM Offset + if (!Offset) + { + Offset = sizeof(GCDHeader); + SeekFile(Offset); + } + debug_printf2("romoffset = %#x\n", Offset); + { + gcdHeader.l.norfirm_offset = Offset; + gcdHeader.l.norfirm_size = ReadFirmFile(line); + } + + return CheckResult(); +} + + +static size_t ReadFirmFile(const char *fileName) +{ + char *file; + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFileWithPadding(fileName, &file, READ_ALL, FIRM_ALIGN)) < 0) + return FALSE; + + Offset += file_size; + + // Output file image with fitting region + PutBuffer(file, file_size); + + Free(&file); + + return file_size; +} + + +//--------------------------------------------------------------------------- +// Output - 'Sbin9' Command +//--------------------------------------------------------------------------- + +static BOOL Sbin9_Command(char * line, int num) +{ + FIRMSignedContext* sc = &signedContext; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm9 sbin = %s\n", line); + + // Set ARM9 ROM Offset + if (!Offset) + + { + Offset = sizeof(GCDHeader); + SeekFile(Offset); + } + debug_printf2("romoffset = %#x\n", Offset); + { + gcdHeader.l.main_rom_offset = Offset; + } + + return ReadSbinFile(line, &gcdHeader.l.main_rom_offset, &sc->hash[FIRM_SIGNED_HASH_IDX_ARM9], compArm9); +} + +//--------------------------------------------------------------------------- +// Output - 'Sbin7' Command +//--------------------------------------------------------------------------- + +static BOOL Sbin7_Command(char * line, int num) +{ + FIRMSignedContext* sc = &signedContext; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm7 sbin = %s\n", line); + + // Set ARM7 ROM Offset + if (!Offset) + { + Offset = sizeof(GCDHeader); + SeekFile(Offset); + } + debug_printf2("romoffset = %#x\n", Offset); + { + gcdHeader.l.sub_rom_offset = Offset; + } + + return ReadSbinFile(line, &gcdHeader.l.sub_rom_offset, &sc->hash[FIRM_SIGNED_HASH_IDX_ARM7], compArm7); +} + + +static BOOL ReadSbinFile(const char *fileName, void* minfo, void* hash, BOOL comp) +{ + const GCDHeader_ModuleInfo *m = minfo; + u32 *size = (void*)&m->size; + u32 *orig_size = (void*)&m->decomp_size; + char *buffer; + char *file; + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &file, READ_ALL)) < 0) + return FALSE; + + *orig_size = file_size; + + // Digest file image + if (hash) + { + ACSign_DigestUnit(hash, file, file_size); + } + + // Compress file image with fitting region + buffer = Alloc(file_size * 2); + if ( comp ) + { + file_size = LZCompWrite(file, file_size, buffer, FIRM_ALIGN); + } + else + { + memcpy(&buffer[0], file, file_size); + { + u32 pad_size = (DEFAULT_ALIGN - (file_size % FIRM_ALIGN)) % FIRM_ALIGN; + if (pad_size) + memset(&buffer[file_size], 0, pad_size); + file_size += pad_size; + } + } + Free(&file); + file = buffer; + + if (size) + { + *size = file_size; + } + Offset += file_size; + + // Encrypt file image + EncryptBuffer(file, file_size); + + // Output file image with fitting region + PutBuffer(file, file_size); + + Free(&file); + + return CheckResult(); +} + +typedef struct +{ + unsigned long e[4]; +} u128; + +static BOOL EncryptBuffer(char *buffer, int length) +{ + const u128 id = {{ AES_IDS_ID2_A, AES_IDS_ID2_B, AES_IDS_ID2_C, AES_IDS_ID2_D }}; + u128 iv = {{ length, -length, ~length, 0 }}; + FIRMSignedContext* sc = &signedContext; + char *buffer2 = Alloc(length); + AES_KEY key; + if (!buffer2) + return FALSE; + AES_SetKey(&key, sc->aes_key, (unsigned char*)&id); + AES_Ctr(&key, buffer2, buffer, length, (unsigned char*)&iv); + memcpy(buffer, buffer2, length); + memset(buffer2, 0, length); + Free(buffer2); + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - 'ERROR' Command +//--------------------------------------------------------------------------- +static char* error_type[] = +{ + "SIGN", + "HEADER_HASH", + "ARM9_HASH", + "ARM7_HASH", + "HASH_TABLE_HASH", + "FINAL_HASH", + "HEADER_FOOTER", +}; + +static BOOL ERROR_Command(char * line, int num) +{ + char* dbg_str = "UNKNOWN"; + int i; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + for (i=0; ihash[FIRM_SIGNED_HASH_IDX_HEADER][0] ^= 1; + } + if ( errFlags.e.arm9_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_ARM9][0] ^= 1; + } + if ( errFlags.e.arm7_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_ARM7][0] ^= 1; + } + if ( errFlags.e.hash_table_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_HASH_TABLE][0] ^= 1; + } +} + +static void SetFinalHashError(FIRMSignedContext* sc) +{ + if ( errFlags.e.final_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_FINAL][0] ^= 1; + } +} + +static void SetSignError(GCDHeader* nh) +{ + if ( errFlags.e.sign ) + { + nh->sign.raw[0] ^= 1; + } + +} + +static void SetFooterError(GCDHeader* nh) +{ + if ( errFlags.e.header_footer ) + { + nh->h.reserved_footer[sizeof(nh->h.reserved_footer)-1] ^= 1; + } + +} + +//--------------------------------------------------------------------------- +// Output - Initialize AES Key +//--------------------------------------------------------------------------- +static BOOL InitializeAesKey(void) +{ + FIRMSignedContext* sc = &signedContext; + struct stat specstat; + time_t spectime; + if (stat(specFileName, &specstat) != 0) + return FALSE; + time(&spectime); + memcpy(&sc->aes_key[0], &specstat.st_atime, 4); + memcpy(&sc->aes_key[4], &specstat.st_mtime, 4); + memcpy(&sc->aes_key[8], &specstat.st_ctime, 4); + memcpy(&sc->aes_key[12], &spectime, 4); + ACSign_GetKey(sc->aes_key, sizeof(sc->aes_key), sc->aes_key, sizeof(sc->aes_key)); + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - Initialize Gcdfirm File +//--------------------------------------------------------------------------- + +static BOOL InitializeGcdfirmFile(const char *rhFile) +{ + if ( !rhFile ) + { + rhFile = GetSrcPath(GetAppBaseName(), DEFAULT_ROMHEADER_TEMPLATE); + } + + ReadRomHeaderFile( rhFile ); + + memset(&signedContext.hash[FIRM_SIGNED_HASH_IDX_HASH_TABLE], 0x00, sizeof(signedContext.hash[0])); + gcdHeader.h.w = wram_regs_init; + InitializeAesKey(); + return TRUE; +} + +//--------------------------------------------------------------------------- +// Output - Finalize Gcdfirm File +//--------------------------------------------------------------------------- + +static BOOL FinalizeGcdfirmFile(const char *gcdFile) +{ + GCDHeader* nh = &gcdHeader; + FIRMSignedContext* sc = &signedContext; + u8* key = keyFileBuf; + int size; + + // set rom size + size = ROM_SIZE_MIN; + nh->l.rom_size = 0; + while (size < Offset) + { + size <<= 1; + nh->l.rom_size++; + } + + ACSign_DigestHeader(&sc->hash[FIRM_SIGNED_HASH_IDX_HEADER], nh); + + SetUnitHashErrors(sc); + + ACSign_DigestUnit(&sc->hash[FIRM_SIGNED_HASH_IDX_FINAL], sc, FIRM_HEADER_2ND_HASH_AREA_LEN); + + SetFinalHashError(sc); + + if (key) + { + ACSign_Final(nh, sc, key); + } + + SetFooterError(nh); + + SetSignError(nh); + + // Output file image + SeekFile(0L); + PutBuffer(&gcdHeader, sizeof(gcdHeader)); + + // Output public key (modulus) + if (PubkeyFileName) + { + WriteFile(PubkeyFileName, &keyFileBuf[ACS_RSA_PRVMOD_OFFSET], ACS_RSA_PRVMOD_LEN); + } + + return TRUE; +} diff --git a/build/tools/makegcdfirm/path.c b/build/tools/makegcdfirm/path.c new file mode 100644 index 00000000..eeeb9895 --- /dev/null +++ b/build/tools/makegcdfirm/path.c @@ -0,0 +1,931 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makebanner + File: path.c + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: path.c,v $ + Revision 1.3 2006/01/18 02:11:20 kitase_hirotake + do-indent + + Revision 1.2 2005/02/28 05:26:13 yosizaki + do-indent. + + Revision 1.1 2004/08/30 08:41:14 yasu + makebanner moves into CVS tree + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include // free() +#include // strcasecmp() +#include // stat() +#include // opendir()/readdir()/closedir() +#include // getcwd() +#ifdef __CYGWIN__ +#include // cygwin_conv_to_win32_path() +#endif +#include "path.h" + +//--------------------------------------------------------------------------- +// Get File Statue +//--------------------------------------------------------------------------- + +tFileStatus GetFileStatus(struct stat *s, const char *filename) +{ + // Get file status + if (stat(filename, s)) + { + error("Can't get status %s", filename); + return FILESTATUS_ERROR; + } + + if (S_ISREG(s->st_mode)) + { + return FILESTATUS_FILE; + } + else if (S_ISDIR(s->st_mode)) + { + return FILESTATUS_DIR; + } + + error("Unknown file type %s", filename); + return FILESTATUS_ERROR; +} + + +//--------------------------------------------------------------------------- +// File Globbing & Dir Listing +//--------------------------------------------------------------------------- + +typedef struct +{ + tCallBack callBack; + void *param; + tWildCard *accept; + tWildCard *reject; + +} +tForeachEntryParam; + + +static BOOL isAcceptEntryName(char *pathName, tWildCard * accept, tWildCard * reject) +{ + char *p = pathName; + + while (*p) + { + if (*p == '/') + pathName = p + 1; + p++; + } + + if (accept) + { + while (accept) + { + if (WildCardCmp(accept->name, pathName)) + { + goto accepted; + } + accept = accept->next; + } + return FALSE; + } + accepted: + + while (reject) + { + if (WildCardCmp(reject->name, pathName)) + { + return FALSE; + } + reject = reject->next; + } + return TRUE; +} + + +static BOOL ForeachEntry_CallBack(char *pathName, void *param) +{ + tForeachEntryParam *t = (tForeachEntryParam *) param; + struct stat fstat; + + if (!isAcceptEntryName(pathName, t->accept, t->reject)) + { + // Reject!!! ignored + return TRUE; + } + + switch (GetFileStatus(&fstat, pathName)) + { + case FILESTATUS_FILE: + return t->callBack(pathName, t->param); + + case FILESTATUS_DIR: + return ForeachDirList(pathName, ForeachEntry_CallBack, param); + + default: + break; + } + return FALSE; +} + + +BOOL ForeachEntry(const char *pathName, tWildCard * reject, tCallBack callBack, void *param) +{ + tForeachEntryParam t; + + t.callBack = callBack; + t.param = param; + t.accept = NULL; + t.reject = reject; + + return ForeachPathGlobbing(pathName, ForeachEntry_CallBack, &t); +} + + +typedef struct +{ + tCallBack callBack; + void *param; + char *baseName; + +} +tForeachFileParam; + + +static BOOL ForeachFile_CallBack(char *pathName, void *param) +{ + tForeachFileParam *t = (tForeachFileParam *) param; + + int len = strlen(t->baseName); + + debug_printf(" ForeachFile_CallBack path[%s] base[%s]\n", pathName, t->baseName); + + if (strncmp(pathName, t->baseName, len)) + { + error("Wildcard in Root is not supported"); + return FALSE; + } + + return t->callBack(pathName + len, t->param); +} + + +BOOL ForeachFile(const char *baseName, const char *fileName, tWildCard * reject, tCallBack callBack, + void *param) +{ + char *cBaseName; + char *cPathName; + BOOL state; + tForeachFileParam t; + + debug_printf("ForeachFile : baseName[%s] fileName[%s]\n", baseName, fileName); + + cBaseName = GetSrcPath(baseName, ""); + cPathName = GetSrcPath(baseName, fileName); + + debug_printf("ForeachFile : cBaseName[%s] cPathName[%s]\n", cBaseName, cPathName); + + t.callBack = callBack; + t.param = param; + t.baseName = cBaseName; + + state = ForeachEntry(cPathName, reject, ForeachFile_CallBack, &t); + + free(cBaseName); + free(cPathName); + + return state; +} + + +//--------------------------------------------------------------------------- +// FilePath Globbing +//--------------------------------------------------------------------------- + +typedef struct +{ + char *baseName; + char *pathName; + tCallBack callBack; + void *param; + +} +tGlobParam; + + +static int CountFile; +static BOOL ForeachPathGlobbing_Entry(tGlobParam * pg); +static BOOL ForeachPathGlobbing_WildCard(char *pathName, void *param); + +BOOL ForeachPathGlobbing(const char *pathName, tCallBack callBack, void *param) +{ + tGlobParam g; + BOOL ret; + + g.baseName = NULL; + g.pathName = PathNormalize(pathName, TRUE); + g.callBack = callBack; + g.param = param; + CountFile = 0; + + debug_printf("PathGlobbing : Name [%s]->[%s]\n", pathName, g.pathName); + + ret = ForeachPathGlobbing_Entry(&g); + + free(g.pathName); + + if (ret && CountFile == 0) + { + error("No file or directory matched %s", pathName); + return FALSE; + } + return ret; +} + + +static BOOL ForeachPathGlobbing_Entry(tGlobParam * pg) +{ + tGlobParam g; + char *entryName; + struct stat s; + BOOL state; + + if (pg->pathName) + { + entryName = PathDup(pg->pathName); + + g = *pg; + g.pathName = PathGetDirLevelDown(pg->pathName); + + if (pg->baseName) + { + g.baseName = Alloc(strlen(pg->baseName) + strlen(entryName) + 2); + sprintf(g.baseName, "%s/%s", pg->baseName, entryName); + } + else + { + g.baseName = strdup(entryName); + } + + // Check if wildcard ? + if (isPathWildCard(entryName)) + { + state = ForeachDirList(pg->baseName, ForeachPathGlobbing_WildCard, &g); + } + else + { + state = ForeachPathGlobbing_Entry(&g); + } + + Free(&entryName); + Free(&g.baseName); + } + else + { + // Check if file exists + if (!stat(pg->baseName, &s)) + { + debug_printf(" File Found [%s]\n", pg->baseName); + + // Globbing done, exec callback + + state = pg->callBack(pg->baseName, pg->param); + CountFile++; + } + else + { + debug_printf(" File Not Found [%s]\n", pg->baseName); + state = TRUE; // Ignored + } + } + return state; +} + + +static BOOL ForeachPathGlobbing_WildCard(char *pathName, void *param) +{ + tGlobParam g; + tGlobParam *pg = (tGlobParam *) param; + + debug_printf(" WildCardCmp: [%s] [%s]\n", pg->baseName, pathName); + + if (WildCardCmp(pg->baseName, pathName)) + { + g = *pg; + g.baseName = pathName; + return ForeachPathGlobbing_Entry(&g); + } + + return TRUE; // Ignored +} + + +//--------------------------------------------------------------------------- +// Directory Listing +// Listing directory & Exec CallBack +//--------------------------------------------------------------------------- + +BOOL ForeachDirList(const char *dirName, tCallBack callBack, void *param) +{ + DIR *dir; + struct dirent *entry; + char *pathName; + BOOL state = TRUE; + + if (!dirName) + { + dirName = "."; + } + + debug_printf("DirectoryList: Name [%s]\n", dirName); + + // Open directory + if (NULL == (dir = opendir(dirName))) + { + error("Can't read directory %s", dirName); + return FALSE; + } + + // Store new files + while (NULL != (entry = readdir(dir))) + { + pathName = entry->d_name; + + if (!strcmp(pathName, ".") || !strcmp(pathName, "..")) + { + continue; + } + + debug_printf(" :%s\n", pathName); + pathName = GetSrcPath(dirName, pathName); + state = callBack(pathName, param); + free(pathName); + + if (!state) + break; + } + + closedir(dir); + return state; +} + + +//--------------------------------------------------------------------------- +// +// PathName Utilities +// +//--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- +// StrCmp/StrCpy entry name terminated / or \0 +//--------------------------------------------------------------------------- + +int PathCmp(const char *path, const char *cmp) +{ + char c; + + do + { + c = *path; + if (c == '/') + c = '\0'; // end of string if '/' + if (c != *cmp) + return 1; + path++; + cmp++; + } + while (c); + + return 0; +} + + +char *PathCpy(char *dest, const char *src) +{ + while (*src != '\0' && *src != '/') + { + *dest++ = *src++; + } + return dest; // Don't set '\0' +} + + +int PathLen(const char *path) +{ + int n = 0; + + while (*path != '\0' && *path != '/') + { + n++; + path++; + } + return n; +} + + +char *PathDup(const char *src) +{ + int n = PathLen(src); + char *dest = Alloc(n + 2); + + PathCpy(dest, src); + dest[n] = '\0'; + + return dest; +} + + +BOOL WildCardCmp(const char *wildcard, const char *path) +{ + if (*wildcard == '*') + { + if (*path != '\0' && WildCardCmp(wildcard, path + 1)) + return TRUE; + if (WildCardCmp(wildcard + 1, path)) + return TRUE; + } + + else if (*wildcard == '?') + { + return *path != '\0' && WildCardCmp(wildcard + 1, path + 1); + } + + else if (*wildcard == *path) + { + return *path == '\0' || WildCardCmp(wildcard + 1, path + 1); + } + + return FALSE; +} + + +BOOL isPathWildCard(const char *path) +{ + while (*path != '\0' && *path != '/') + { + if (*path == '*' || *path == '?') + { + return TRUE; + } + path++; + } + return FALSE; +} + + +//--------------------------------------------------------------------------- +// Go up/down directory level +//--------------------------------------------------------------------------- + +char *PathGetDirLevelDown(const char *path) +{ + while (*path) + { + if (*path == '/') + return (char *)path + 1; + path++; + } + return NULL; +} + + +//--------------------------------------------------------------------------- +// Get Basename +//--------------------------------------------------------------------------- + +char *GetBaseName(const char *path) +{ + int i; + char *new_path; + + for (i = strlen(path) - 1; i >= 0; i--) + { + if (path[i] == '/') + { + new_path = strdup(path); + new_path[i] = '\0'; + return new_path; + } + if (path[i] == ':') + { + new_path = Alloc(i + 3); + strncpy(new_path, path, i); + strcpy(new_path + i, ":."); + return new_path; + } + } + + new_path = strdup("."); + return new_path; +} + + +//--------------------------------------------------------------------------- +// Get Filename +//--------------------------------------------------------------------------- + +char *GetFileName(const char *path) +{ + int i; + char *new_file; + + for (i = strlen(path) - 1; i >= 0; i--) + { + if (path[i] == '/' || path[i] == ':') + { + new_file = strdup(path + i + 1); + return new_file; + } + } + new_file = strdup(path); + return new_file; +} + + +//--------------------------------------------------------------------------- +// Reconstruct path name +// +// - Resolve '.' or '..' in path name +// - Work around . and / to translate regular form +// +// Regular form of path: +// Absolute Path [Drive:]/.[/Entry...] +// Relative Path [Drive:].[/Entry]... +// +// ex) +// abc/def -> ./abc/def +// /aaa -> /./aaa +// D:/aaa -> D:/./aaa +// / -> /. +// . -> . +// ../aa -> ./../aa +//--------------------------------------------------------------------------- + +char *PathNormalize(const char *pathName, BOOL isTreatDotDot) +{ + int i, level, level_root, n; + BOOL isAbsolute; + const char *entry[DIRLEVEL_MAX]; + + char *pathNormal = Alloc(strlen(pathName) + 4); + const char *p_org; + char *p_new; + + // + // Check if drive letter C: D: E: + // Check if absolute path + // + p_new = pathNormal; + p_org = SkipDriveName(pathName); + n = (int)p_org - (int)pathName; + + if (n > 0) + { + strncpy(p_new, pathName, n); + p_new += n; + } + isAbsolute = isAbsolutePath(p_org); + + // + // Resolve '.' and '..' + // + // Slice the path at point of / , put them into entry[] + // + + level = level_root = 0; + + for (; p_org; p_org = PathGetDirLevelDown(p_org)) + { + if (!PathCmp(p_org, "") || !PathCmp(p_org, ".")) + { + // skip it + continue; + } + else if (!PathCmp(p_org, "..") && isTreatDotDot) + { + if (level > level_root) + { + // Back to parent dir + level--; + continue; + } + + // if pathname starts with '/', no directory to go up + if (isAbsolute) + { + error("Can't go up directory, '..' Ignored. %s", pathName); + continue; + } + + // keep '..' + level_root = level + 1; + } + + // name entry + entry[level] = p_org; + level++; + } + + // Reconstruct pathname + if (isAbsolute) + { + *p_new++ = '/'; + } + *p_new++ = '.'; + + for (i = 0; i < level; i++) + { + *p_new++ = '/'; + p_new = PathCpy(p_new, entry[i]); + } + *p_new = '\0'; + +#if 0 + if (strcmp(pathNormal, pathName)) + { + debug_printf(" PathNormal: [%s] -> [%s]\n", pathName, pathNormal); + } +#endif + return pathNormal; +} + + +//--------------------------------------------------------------------------- +// Get Src Path +// Normalize BASENAME +// Normalize FILENAME +// Concat both +//--------------------------------------------------------------------------- + +char *GetSrcPath(const char *baseName, const char *fileName) +{ + char *base; + char *file; + char *t; + char *path; + + base = PathNormalize(baseName, TRUE); + file = PathNormalize(fileName, TRUE); + t = Alloc(strlen(base) + strlen(file) + 2); + + // Concat base + '/' + file + sprintf(t, "%s/%s", base, file); + path = PathNormalize(t, FALSE); + + free(base); + free(file); + free(t); + + debug_printf(" GetSrcPath: [%s]\n", path); + return path; +} + + +//--------------------------------------------------------------------------- +// Get Dest Path +// Concat BASENAME + FILENAME +// Normalize it +//--------------------------------------------------------------------------- + +char *GetDestPath(const char *baseName, const char *fileName) +{ + char *t; + char *path; + + t = Alloc(strlen(baseName) + strlen(fileName) + 2); + + // Concat base + '/' + file + sprintf(t, "%s/%s", baseName, fileName); + path = PathNormalize(t, TRUE); + + free(t); + + debug_printf(" GetDestPath: [%s]\n", path); + return path; +} + + +//--------------------------------------------------------------------------- +// Remake the path into familier shape +// Delete ./ +//--------------------------------------------------------------------------- + +char *PathDenormalize(char *path) +{ + char *p; + + p = (char *)SkipDriveName(path); + if (*p == '/') + { + p++; + } + + // Cut './' + if (*p == '.' && *(p + 1) == '/') + { + while ('\0' != (*p = *(p + 2))) + { + p++; + } + + if (p == path) + { + + } + } + + + + return path; +} + + +//--------------------------------------------------------------------------- +// Get PC Path +//--------------------------------------------------------------------------- + +char *GetWin32Path(char *cygpath) +{ + static char buffer[FILENAME_MAX]; + +#ifdef __CYGWIN__ + if (*cygpath == '/') + { + cygwin_conv_to_win32_path(cygpath, buffer); + } + else +#endif + { + strcpy(buffer, cygpath); + } + + return ChangeBackSlash(buffer); +} + +char *ChangeWin32Path(char *cygpath) +{ + char *win32path = strdup(GetWin32Path(cygpath)); + + free(cygpath); + return win32path; +} + +//--------------------------------------------------------------------------- +// Change suffix +//--------------------------------------------------------------------------- +char *ChangeSuffix(const char *file, const char *suffix) +{ + int i, n; + char *path; + + n = strlen(file); + + for (i = n; file[i] != '.'; i--) + { + if (file[i] == '/' || i == 0) + { + i = n; + break; + } + } + + path = Alloc(i + strlen(suffix) + 1); + strncpy(path, file, i); + strcpy(path + i, suffix); + + return path; +} + + +//--------------------------------------------------------------------------- +// Get Current Dir +//--------------------------------------------------------------------------- + +char *GetCurrentDirectory(void) +{ + static char buffer[FILENAME_MAX]; + char *cwd; + + cwd = getcwd(buffer, FILENAME_MAX); + if (!cwd) + { + error("Can't access current directory"); + exit(10); + } + return cwd; +} + + +//--------------------------------------------------------------------------- +// Check if absolute path +// +// Return True in case of ... +// +// /dirA/dirB/fileC +// D:/dirA/dirB/fileC +// +// Return False in case of ... +// +// dirX/dirY/fileZ +// D:dirX/dirY/fileZ +//--------------------------------------------------------------------------- + +BOOL isAbsolutePath(const char *path) +{ + const char *p = path; + + while (*p != '\0') + { + if (*p == '/' || *p == '\\') + { + if (p == path || p[-1] == ':') + { + return TRUE; + } + } + p++; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +// Check if drive name +// +// Return next character of ':' if drive name +// Return head of path if no drive name +//--------------------------------------------------------------------------- + +const char *SkipDriveName(const char *path) +{ + const char *p = path; + + while (*p != '\0' && *p != '/' && *p != '\\') + { + if (*p == ':') + { + return p + 1; + } + p++; + } + return path; +} + + +//--------------------------------------------------------------------------- +// App Name Utilities +//--------------------------------------------------------------------------- +static char *appName; +static char *appBaseName; +static char *appFileName; + +void InitAppName(const char *path) +{ + char *slash_path = ChangeBackSlash(strdup(path)); + + appBaseName = GetBaseName(slash_path); + appFileName = GetFileName(slash_path); + appName = ChangeSuffix(appFileName, ""); + + free(slash_path); +} + +char *GetAppName(void) +{ + return appName; +} + +char *GetAppBaseName(void) +{ + return appBaseName; +} + +char *GetAppFileName(void) +{ + return appFileName; +} + + +#ifdef TEST +int main(int argc, char *argv[]) +{ + int i; + char *s; + + for (i = 1; i < argc; i++) + { + s = PathNormalize(argv[i], TRUE); + printf("[%s] -> [%s]\n", argv[i], s); + free(s); + } + return 0; +} +#endif diff --git a/build/tools/makegcdfirm/path.h b/build/tools/makegcdfirm/path.h new file mode 100644 index 00000000..e9956dc6 --- /dev/null +++ b/build/tools/makegcdfirm/path.h @@ -0,0 +1,93 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makebanner + File: path.h + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: path.h,v $ + Revision 1.3 2006/01/18 02:11:20 kitase_hirotake + do-indent + + Revision 1.2 2005/02/28 05:26:13 yosizaki + do-indent. + + Revision 1.1 2004/08/30 08:41:14 yasu + makebanner moves into CVS tree + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#ifndef PATH_H_ +#define PATH_H_ + +#include // struct tat +#include "misc.h" + +#define DIRLEVEL_MAX 256 +#ifndef FILENAME_MAX +#define FILENAME_MAX 1024 +#endif + +typedef enum +{ + FILESTATUS_ERROR = -1, + FILESTATUS_FILE = 0, + FILESTATUS_DIR = 1 +} +tFileStatus; + + +// Item Reject Control + +typedef struct tWildCard +{ + struct tWildCard *next; + char *name; + +} +tWildCard; + + +// CallBacks + +typedef BOOL (*tCallBack) (char *, void *); + + +// Prototypes + +tFileStatus GetFileStatus(struct stat *s, const char *filename); +BOOL ForeachEntry(const char *pathName, tWildCard * reject, tCallBack callBack, void *param); +BOOL ForeachFile(const char *baseName, const char *fileName, tWildCard * reject, + tCallBack callBack, void *param); +BOOL ForeachPathGlobbing(const char *pathName, tCallBack callBack, void *param); +BOOL ForeachDirList(const char *dirName, tCallBack callBack, void *param); +int PathCmp(const char *path, const char *cmp); +char *PathCpy(char *dest, const char *src); +int PathLen(const char *path); +char *PathDup(const char *src); +char *PathGetDirLevelDown(const char *path); +char *GetBaseName(const char *path); +char *GetFileName(const char *path); +BOOL WildCardCmp(const char *wildcard, const char *path); +BOOL isPathWildCard(const char *path); +char *PathNormalize(const char *pathName, BOOL isTreatDotDot); +char *PathDenormalize(char *path); +char *GetSrcPath(const char *base, const char *file); +char *GetDestPath(const char *base, const char *file); +char *GetWin32Path(char *cygpath); +char *ChangeWin32Path(char *cygpath); +char *ChangeSuffix(const char *file, const char *suffix); +char *GetCurrentDirectory(void); +BOOL isAbsolutePath(const char *path); +const char *SkipDriveName(const char *path); +void InitAppName(const char *path); +char *GetAppName(void); +char *GetAppBaseName(void); +char *GetAppFileName(void); + +#endif //PATH_H_ diff --git a/build/tools/makegcdfirm/test/Makefile b/build/tools/makegcdfirm/test/Makefile new file mode 100644 index 00000000..2c2b4741 --- /dev/null +++ b/build/tools/makegcdfirm/test/Makefile @@ -0,0 +1,56 @@ +#! make -f +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makenorfirm +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#--------------------------------------------------------------------------- + +SUBDIRS = wram_rbin \ + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +MAKEGCDFIRM = ../makegcdfirm.exe + +MAKEFIRM_ARM9 = ./twl_gcdfirm9_print.axf +MAKEFIRM_ARM7 = ./twl_gcdfirm7_print.axf +SDEPENDS_BIN += $(MAKEFIRM_ARM9) $(MAKEFIRM_ARM7) +MAKEFIRM_FLAGS += -d +MAKEFIRM_DEFS += -DFIRM_ROOT='$(FIRM_ROOT)' \ + -DMAKEFIRM_ARM9='$(basename $(MAKEFIRM_ARM9))' \ + -DMAKEFIRM_ARM7='$(basename $(MAKEFIRM_ARM7))' \ + -DMAKEFIRM_RSA_PRVKEY='$(MAKEFIRM_RSA_PRVKEY)' \ + +TARGET = test.srl + +%.srl: %.gcdsf $(MAKEGCDFIRM) + $(MAKEGCDFIRM) $(MAKEFIRM_FLAGS) $(MAKEFIRM_DEFS) $< $@ + +.PHONY: build install do-autotest clean clobber + +define ECHO_CURDIR + echo "==== $(CURDIR)"; +endef + +build: + @$(ECHO_CURDIR) + @$(MAKE) $(TARGET) + +install do-autotest: + @$(ECHO_CURDIR) + +clean clobber super-clobber: + @$(ECHO_CURDIR) + -rm -f $(TARGET) *~ + +test-utf16.bsf: icon.nbfc icon.nbfp diff --git a/build/tools/makegcdfirm/test/nandfirm_print.nand b/build/tools/makegcdfirm/test/nandfirm_print.nand new file mode 100644 index 00000000..999ce185 Binary files /dev/null and b/build/tools/makegcdfirm/test/nandfirm_print.nand differ diff --git a/build/tools/makegcdfirm/test/norfirm_print.nor b/build/tools/makegcdfirm/test/norfirm_print.nor new file mode 100644 index 00000000..2a6baecd Binary files /dev/null and b/build/tools/makegcdfirm/test/norfirm_print.nor differ diff --git a/build/tools/makegcdfirm/test/rsa_private.der b/build/tools/makegcdfirm/test/rsa_private.der new file mode 100644 index 00000000..06f5f4cc Binary files /dev/null and b/build/tools/makegcdfirm/test/rsa_private.der differ diff --git a/build/tools/makegcdfirm/test/test.gcdsf b/build/tools/makegcdfirm/test/test.gcdsf new file mode 100644 index 00000000..88d50675 --- /dev/null +++ b/build/tools/makegcdfirm/test/test.gcdsf @@ -0,0 +1,22 @@ +#GCDSF --- Gcdfirm Spec File + +VERSION : GENERATE + +RSA_KEY : rsa_private.der +OUT_KEY : rsa_public.sbin + +WRAM_RBIN: ./wram_rbin/wram_regs.rbin + +ARM9_SBIN : $(MAKEFIRM_ARM9).sbin +ARM9_ELF : $(MAKEFIRM_ARM9).axf + +ARM7_SBIN : $(MAKEFIRM_ARM7).sbin +ARM7_ELF : $(MAKEFIRM_ARM7).axf + +ARM9_X2 : TRUE # TRUE or FALSE + +NML_OFS : 0x80000 +TWL_OFS : 0x100000 + +ERROR : ARM7_HASH # SIGN, HEADER_HASH, ARM9_HASH, ARM7_HASH, HASH_TABLE_HASH or FINAL_HASH +ERROR : HEADER_FOOTER # for debug diff --git a/build/tools/makegcdfirm/test/twl_gcdfirm7_print.axf b/build/tools/makegcdfirm/test/twl_gcdfirm7_print.axf new file mode 100644 index 00000000..b255bd21 Binary files /dev/null and b/build/tools/makegcdfirm/test/twl_gcdfirm7_print.axf differ diff --git a/build/tools/makegcdfirm/test/twl_gcdfirm7_print.sbin b/build/tools/makegcdfirm/test/twl_gcdfirm7_print.sbin new file mode 100644 index 00000000..a4eeebce Binary files /dev/null and b/build/tools/makegcdfirm/test/twl_gcdfirm7_print.sbin differ diff --git a/build/tools/makegcdfirm/test/twl_gcdfirm9_print.axf b/build/tools/makegcdfirm/test/twl_gcdfirm9_print.axf new file mode 100644 index 00000000..3d064b38 Binary files /dev/null and b/build/tools/makegcdfirm/test/twl_gcdfirm9_print.axf differ diff --git a/build/tools/makegcdfirm/test/twl_gcdfirm9_print.sbin b/build/tools/makegcdfirm/test/twl_gcdfirm9_print.sbin new file mode 100644 index 00000000..cd305be4 Binary files /dev/null and b/build/tools/makegcdfirm/test/twl_gcdfirm9_print.sbin differ diff --git a/build/tools/makegcdfirm/test/wram_rbin/Makefile b/build/tools/makegcdfirm/test/wram_rbin/Makefile new file mode 100644 index 00000000..926c9b05 --- /dev/null +++ b/build/tools/makegcdfirm/test/wram_rbin/Makefile @@ -0,0 +1,48 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - gcdfirm-print +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tools/makegcdfirm/test/wram_rbin/wram_regs.c b/build/tools/makegcdfirm/test/wram_rbin/wram_regs.c new file mode 100644 index 00000000..ee7d112c --- /dev/null +++ b/build/tools/makegcdfirm/test/wram_rbin/wram_regs.c @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makegcdfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs = +{ + // ARM9 + { + REG_WRAM_A_BNK_PACK(0, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_0KB, TRUE), + REG_WRAM_A_BNK_PACK(1, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_64KB, TRUE), + REG_WRAM_A_BNK_PACK(2, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_128KB, TRUE), + REG_WRAM_A_BNK_PACK(3, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_192KB, TRUE), + }, + { + REG_WRAM_B_BNK_PACK(0, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_0KB, TRUE), + REG_WRAM_B_BNK_PACK(1, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_32KB, TRUE), + REG_WRAM_B_BNK_PACK(2, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_64KB, TRUE), + REG_WRAM_B_BNK_PACK(3, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_96KB, TRUE), + REG_WRAM_B_BNK_PACK(4, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_128KB, TRUE), + REG_WRAM_B_BNK_PACK(5, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_160KB, TRUE), + REG_WRAM_B_BNK_PACK(6, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_192KB, TRUE), + REG_WRAM_B_BNK_PACK(7, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_224KB, TRUE), + }, + { + REG_WRAM_C_BNK_PACK(0, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_0KB, TRUE), + REG_WRAM_C_BNK_PACK(1, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_32KB, TRUE), + REG_WRAM_C_BNK_PACK(2, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_64KB, TRUE), + REG_WRAM_C_BNK_PACK(3, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_96KB, TRUE), + REG_WRAM_C_BNK_PACK(4, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_128KB, TRUE), + REG_WRAM_C_BNK_PACK(5, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_160KB, TRUE), + REG_WRAM_C_BNK_PACK(6, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_192KB, TRUE), + REG_WRAM_C_BNK_PACK(7, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_224KB, TRUE), + }, + REG_WRAM_A_MAP_PACK(MI_WRAM_MAP_NULL, + MI_WRAM_MAP_NULL, + MI_WRAM_A_IMG_128KB + ), + REG_WRAM_B_MAP_PACK(MI_WRAM_MAP_NULL, + MI_WRAM_MAP_NULL, + MI_WRAM_B_IMG_128KB + ), + REG_WRAM_C_MAP_PACK(HW_WRAM_AREA_HALF, + HW_WRAM_AREA_HALF + 0x00020000, + MI_WRAM_C_IMG_128KB + ), + + // ARM7 + REG_WRAM_A_MAP_PACK(HW_WRAM_AREA_HALF, + HW_WRAM_AREA_HALF + 0x00020000, + MI_WRAM_A_IMG_128KB + ), + REG_WRAM_B_MAP_PACK(HW_WRAM_AREA_HALF + 0x00020000, + HW_WRAM_AREA_HALF + 0x00040000, + MI_WRAM_B_IMG_128KB + ), + REG_WRAM_C_MAP_PACK(MI_WRAM_MAP_NULL, + MI_WRAM_MAP_NULL, + MI_WRAM_C_IMG_128KB + ), + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + MI_WRAM_ARM7_ALL, + + // VRAM-C + 7, + // VRAM-D + 7, +}; diff --git a/build/tools/makegcdfirm/wram_regs.c b/build/tools/makegcdfirm/wram_regs.c new file mode 100644 index 00000000..fba20ce8 --- /dev/null +++ b/build/tools/makegcdfirm/wram_regs.c @@ -0,0 +1,96 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makegcdfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include "format_rom.h" +//#define SDK_ASM +#define NITRO_TYPES_H_ +#include +#include +#include + + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM9 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF + 0x00020000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF + 0x00020000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA_HALF + 0x00040000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA_HALF + 0x00020000 ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/tools/makenandfirm/Makefile b/build/tools/makenandfirm/Makefile new file mode 100644 index 00000000..09832e39 --- /dev/null +++ b/build/tools/makenandfirm/Makefile @@ -0,0 +1,151 @@ +#! make -f +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makenandfirm +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#--------------------------------------------------------------------------- + +TARGET_PLATFORM = TWL + +SUPPORT_ECC = 0 + +ifeq ($(SUPPORT_ECC),1) +ECC_SRCDIR = ../../libraries/acsign_ecc/common \ + ../../libraries/acsign_ecc/common/algae/common/ecc \ + ../../libraries/acsign_ecc/common/algae/cmp \ + ../../libraries/acsign_ecc/common/algae/ecsource \ + +ECC_INCDIR = ../../libraries/acsign_ecc/include \ + ../../libraries/acsign_ecc/common/algae/include \ + ../../libraries/acsign_ecc/common/algae/common/include \ + +ECC_SRCS = acsign_ecc.c acsign_cryptoc.c \ + \ + cmparith.c cmpbits.c cmpcnv.c cmpdiv.c cmpmem.c \ + cmpmod.c cmpmuldv.c cmpspprt.c cmpsqr.c cmpvectr.c \ + computem.c ecfpatbl.c ecfpsmul.c \ + spcprime.c secfpcom.c \ + \ + p224v1.c p224v1a.c \ + +ECC_DEFS = -DRSA_PROTOTYPES=RSA_ENABLED \ + -DRCOM_BUILD=RSA_ENABLED -DRSA_FAST_INVERSE=RSA_ENABLED \ + -DRSA_STD_MEM_FUNCS=RSA_ENABLED -DRSA_STD_ALLOC_FUNCS=RSA_ENABLED \ +else +ECC_SRCDIR = +ECC_INCDIR = +ECC_SRCS = +ECC_DEFS = +endif + +SRCDIR += ../acsign $(ECC_SRCDIR) +INCDIR += ../acsign/include $(ECC_INCDIR) $(ECC_SRCDIR) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +TARGETS = makenandfirm.exe + +SOURCES_C = makenandfirm.c \ + out_nandfirm.c \ + misc.c \ + path.c \ + defval.c \ + compress.c \ + wram_regs.c \ + acsign.c \ + acsign_nand.c \ + aes2.c \ + $(ECC_SRCS) + +SOURCES = $(SORUCES_C) + +OBJECTS = $(SOURCES_C:.c=.o) + +HEADERS = format_nlist.h \ + makenandfirm.h \ + path.h \ + format_rom.h \ + misc.h \ + defval.h \ + compress.h \ + +MACROS += -DSMALL_CODE_SIZE \ + -DSTANDALONE \ + -DOPT_32_BIT \ + -DNO_SPLIT \ + -DNO_FP_API \ + -DNO_R_DIAG \ + $(ECC_DEFS) + +INSTALL_DIR = $(FIRM_INSTALL_TOOLSDIR)/bin +INSTALL_TARGETS = $(TARGETS) + +LDIRT_CLEAN = $(OBJECTS) $(TARGETS) version.h + + +VPATH = $(SRCDIR) +TWL_INCDIR := $(TWL_INCDIR) $(addprefix -I,$(INCDIR)) $(addprefix -I,$(FIRM_INCDIR)) + +include $(TWLSDK_ROOT)/build/buildtools/twl/modulerules.x86 + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(OBJECTS) + $(CC_X86) $+ -o $@ + +makenandfirm.o: makenandfirm.c makenandfirm.h format_rom.h path.h version.h +out_nandfirm.o: out_nandfirm.c misc.h format_rom.h format_nlist.h format_sign.h elf.h compress.h \ + $(FIRM_INCDIR)/firm/format/sign.h \ + $(FIRM_INCDIR)/firm/format/wram_regs.h \ + $(FIRM_INCDIR)/firm/format/nandfirm.h \ + +misc.o: misc.c misc.h +path.o: path.c path.h +compress.o: compress.c compress.h +wram_regs.o: wram_regs.c +acsign.o: acsign.c ../acsign/include/acsign.h +acsign_nand.o: acsign_nand.c format_sign.h \ + $(FIRM_INCDIR)/firm/format/sign.h \ + $(FIRM_INCDIR)/firm/format/wram_regs.h \ + $(FIRM_INCDIR)/firm/format/nandfirm.h \ + +aes2.o: aes2.c aes2.h + +$(FIRM_INCDIR)/firm/format/sign.h: +$(FIRM_INCDIR)/firm/format/wram_regs.h: +$(FIRM_INCDIR)/firm/format/nandfirm.h: +format_nlist.h: +format_rom.h: +makenandfirm.h: +acsign.h: +acsign_nand.h: +path.h: + +# avoid to warning message +misc.o:WARNING += -Wno-format-y2k + +# + +version.h: $(SOURCES) $(HEADERS) + @for i in $^ ; \ + do \ + date -r $$i +'#define SDK_DATE_OF_LATEST_FILE %Y%m%dUL'; \ + done | sort | tail -1 > $@ + +test: path.c misc.c + $(CC_X86) -DTEST $+ -o $@ diff --git a/build/tools/makenandfirm/compress.c b/build/tools/makenandfirm/compress.c new file mode 100644 index 00000000..71e468cc --- /dev/null +++ b/build/tools/makenandfirm/compress.c @@ -0,0 +1,293 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenandfirm + File: compress.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:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include // atoi() +#include // strcmp() +#include // isprint() +#include // chdir() +#include +#include // UCHAR_MAX +#include +#include // stat() +#include "elf.h" +#include "misc.h" +#include "defval.h" +#include "format_rom.h" +#include "format_nlist.h" +#include "makenandfirm.h" + +//#define ADD_HEADER + +#define DIFF_CODE_HEADER (0x80) +#define RL_CODE_HEADER (0x30) +#define LZ_CODE_HEADER (0x10) +#define HUFF_CODE_HEADER (0x20) +#define CODE_HEADER_MASK (0xF0) + +//=========================================================================== +// LZ77k +//=========================================================================== +static u8 SearchLZ(const u8 *nextp, u32 remainSize, u16 *offset); + +static u16 windowPos; +static u16 windowLen; + +static s16 LZOffsetTable[4096]; +static s16 LZByteTable[256]; +static s16 LZEndTable[256]; + + +static void LZInitTable(void) +{ + u16 i; + + for (i = 0; i < 256; i++) + { + LZByteTable[i] = -1; + LZEndTable[i] = -1; + } + windowPos = 0; + windowLen = 0; +} + +static void SlideByte(const u8 *srcp) +{ + s16 offset; + u8 in_data = *srcp; + u16 insert_offset; + + if (windowLen == 4096) + { + u8 out_data = *(srcp - 4096); + if ((LZByteTable[out_data] = LZOffsetTable[LZByteTable[out_data]]) == -1) + { + LZEndTable[out_data] = -1; + } + insert_offset = windowPos; + } + else + { + insert_offset = windowLen; + } + + offset = LZEndTable[in_data]; + if (offset == -1) + { + LZByteTable[in_data] = insert_offset; + } + else + { + LZOffsetTable[offset] = insert_offset; + } + LZEndTable[in_data] = insert_offset; + LZOffsetTable[insert_offset] = -1; + + if (windowLen == 4096) + { + windowPos = (u16)((windowPos + 1) % 0x1000); + } + else + { + windowLen++; + } +} + +static void LZSlide(const u8 *srcp, u32 n) +{ + u32 i; + + for (i = 0; i < n; i++) + { + SlideByte(srcp++); + } +} + +/*---------------------------------------------------------------------------* + Name: MI_CompressLZ + + Description: LZ77ksȂ֐ + + Arguments: srcp kf[^ւ̃|C^ + size kf[^TCY + dstp kf[^ւ̃|C^ + kf[^傫TCỸobt@KvłB + + Returns: k̃f[^TCYB + k̃f[^kO傫Ȃꍇɂ͈k𒆒f0Ԃ܂B + *---------------------------------------------------------------------------*/ +u32 LZCompWrite(u8 *srcp, u32 size, u8 *dstp, int boundary) +{ + u32 LZDstCount; // kf[^̃oCg + u8 LZCompFlags; // k̗LtOn + u8 *LZCompFlagsp; // LZCompFlags i[郁̈|Cg + u16 lastOffset; // vf[^܂ł̃ItZbg (̎_ł̍Œvf[^) + u8 lastLength; // vf[^ (̎_ł̍Œvf[^) + u8 i; + u32 dstMax; + +#ifdef ADD_HEADER + *(u32 *)dstp = size << 8 | LZ_CODE_HEADER; // f[^Ewb_ + dstp += 4; +#endif + LZDstCount = 4; + dstMax = size; + LZInitTable(); + + while (size > 0) + { + LZCompFlags = 0; + LZCompFlagsp = dstp++; // tOn̊i[ + LZDstCount++; + + // tOn8rbgf[^ƂĊi[邽߁A8񃋁[v + for (i = 0; i < 8; i++) + { + LZCompFlags <<= 1; // (i=0) ͓ɈӖ͂Ȃ + if (size <= 0) + { + // I[ɗꍇ̓tOŌ܂ŃVtgĂI + continue; + } + + if ((lastLength = SearchLZ(srcp, size, &lastOffset))) + { + // k”\ȏꍇ̓tO𗧂Ă + LZCompFlags |= 0x1; + + // ItZbg͏4rbgƉ8rbgɕĊi[ + *dstp++ = (u8)((lastLength - 3) << 4 | (lastOffset - 1) >> 8); + *dstp++ = (u8)((lastOffset - 1) & 0xff); + LZDstCount += 2; + LZSlide(srcp, lastLength); + srcp += lastLength; + size -= lastLength; + } + else + { + // kȂ + LZSlide(srcp, 1); + *dstp++ = *srcp++; + size--; + LZDstCount++; + } + } // 8񃋁[vI + *LZCompFlagsp = LZCompFlags; // tOni[ + } + + // 16oCgEACg + // ACgpf[^0 ̓f[^TCYɊ܂߂ + i = 0; + while (LZDstCount & (boundary - 1)) +// while ((LZDstCount + i) & 0x3) + { + *dstp++ = 0; + LZDstCount++; + i++; + } + + return LZDstCount; +} + +//-------------------------------------------------------- +// LZ77kŃXCh̒Œv܂B +// Arguments: startp f[^̊Jnʒu|C^ +// nextp Jnf[^̃|C^ +// remainSize cf[^TCY +// offset vItZbgi[̈ւ̃|C^ +// Return : v񂪌‚ꍇ TRUE +// ‚Ȃꍇ FALSE +//-------------------------------------------------------- +static u8 SearchLZ(const u8 *nextp, u32 remainSize, u16 *offset) +{ + const u8 *searchp; + const u8 *headp, *searchHeadp; + u16 maxOffset; + u8 maxLength = 2; + u8 tmpLength; + s32 w_offset; + + if (remainSize < 3) + { + return 0; + } + + w_offset = LZByteTable[*nextp]; + + while (w_offset != -1) + { + if (w_offset < windowPos) + { + searchp = nextp - windowPos + w_offset; + } + else + { + searchp = nextp - windowLen - windowPos + w_offset; + } + + /* ĂǂA͂ɍ */ + if (*(searchp + 1) != *(nextp + 1) || *(searchp + 2) != *(nextp + 2)) + { + w_offset = LZOffsetTable[w_offset]; + continue; + } + + if (nextp - searchp < 2) + { + // VRAM2oCgANZXȂ̂ (VRAMf[^ǂݏoꍇ邽)A + // Ώۃf[^2oCgÕf[^ɂȂ΂ȂȂB + // + // ItZbg12rbgŊi[邽߁A4096ȉ + break; + } + tmpLength = 3; + searchHeadp = searchp + 3; + headp = nextp + 3; + + while (((u32)(headp - nextp) < remainSize) && (*headp == *searchHeadp)) + { + headp++; + searchHeadp++; + tmpLength++; + + // f[^4rbgŊi[邽߁A18ȉ (3̉ʂ͂) + if (tmpLength == (0xF + 3)) + { + break; + } + } + if (tmpLength > maxLength) + { + // ő咷ItZbgXV + maxLength = tmpLength; + maxOffset = (u16)(nextp - searchp); + if (maxLength == (0xF + 3)) + { + // vőȂ̂ŁAIB + break; + } + } + w_offset = LZOffsetTable[w_offset]; + } + + if (maxLength < 3) + { + return 0; + } + *offset = maxOffset; + return maxLength; +} + diff --git a/build/tools/makenandfirm/compress.h b/build/tools/makenandfirm/compress.h new file mode 100644 index 00000000..f8fd899e --- /dev/null +++ b/build/tools/makenandfirm/compress.h @@ -0,0 +1,38 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenandfirm + File: compress.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 COMPRESS_H_ +#define COMPRESS_H_ + +#include "misc.h" + + +/*---------------------------------------------------------------------------* + Name: MI_CompressLZ + + Description: LZ77ksȂ֐ + + Arguments: srcp kf[^ւ̃|C^ + size kf[^TCY + dstp kf[^ւ̃|C^ + kf[^傫TCỸobt@KvłB + + Returns: k̃f[^TCYB + *---------------------------------------------------------------------------*/ +u32 LZCompWrite(u8 *srcp, u32 size, u8 *dstp, int boundary); + + +#endif //COMPRESS_H_ diff --git a/build/tools/makenandfirm/defval.c b/build/tools/makenandfirm/defval.c new file mode 100644 index 00000000..679fb0e6 --- /dev/null +++ b/build/tools/makenandfirm/defval.c @@ -0,0 +1,315 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makerom + File: defval.c + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: defval.c,v $ + Revision 1.10 2006/01/18 02:11:19 kitase_hirotake + do-indent + + Revision 1.9 2005/02/28 05:26:03 yosizaki + do-indent. + + Revision 1.8 2004/08/05 13:50:13 yasu + Support -M option + + Revision 1.7 2004/06/29 04:55:40 yasu + Use VBuffer to resolve variables + + Revision 1.6 2004/06/23 07:51:02 yasu + fix a bug as illegal memory freeing at ResolveDefVal() + + Revision 1.5 2004/05/27 00:40:49 yasu + care also about current directory (dot ".") + + Revision 1.4 2004/05/27 00:25:46 yasu + care about double-dots ".." for defvalue option :r, :e + + Revision 1.3 2004/05/27 00:11:19 yasu + fix a error when searching a "dot" of file extension + + Revision 1.2 2004/05/26 12:02:47 yasu + support :h, :t, :r, :e option for variable name + + Revision 1.1 2004/03/26 05:06:45 yasu + support variables like as -DNAME=VALUE + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include // getenv() +#include // strcasecmp() +#include // getopt() +#include "misc.h" +#include "defval.h" + +typedef struct tValdef +{ + struct tValdef *next; + char *name; + char *value; +} +tValdef; + +tValdef *valdef_top = NULL; + + +// +// Add new define value via file +// +// opt : "DEFINE=VALUE" +// +BOOL AddDefValFromFile(char *filename) +{ + char *buffer; + int buffer_size; + int read_size; + FILE *fp; + + if (filename[0] == '-' && filename[1] == '\0') + { + fp = stdin; + } + else if (NULL == (fp = fopen(filename, "rb"))) + { + fprintf(stderr, "Cannot open file \"%s\".\n", filename); + return FALSE; + } + + buffer_size = DEFVAL_DEFAULT_BUFFER_SIZE; + + if (NULL == (buffer = malloc(buffer_size))) + { + fprintf(stderr, "Cannot allocate memory.\n"); + return FALSE; + } + + read_size = 0; + + while (NULL != fgets(buffer + read_size, buffer_size - read_size, fp)) + { + read_size = strlen(buffer); + + if (read_size == buffer_size - 1 && buffer[read_size - 1] != '\n') + { + buffer_size *= 2; + + if (NULL == (buffer = realloc(buffer, buffer_size))) + { + fprintf(stderr, "Cannot allocate memory.\n"); + return FALSE; + } + continue; + } + + AddDefVal(buffer); + read_size = 0; + } + + if (fp != stdin) + { + fclose(fp); + } + free(buffer); + + return TRUE; +} + + +// +// Add new define value +// +// opt : "DEFINE=VALUE" +// +void AddDefVal(char *opt) +{ + int i; + tValdef *t; + + for (i = 0;; i++) + { + if ('=' == opt[i] || '\0' == opt[i]) + { + break; + } + } + + if (i > 0) + { + t = Alloc(sizeof(tValdef)); + t->name = strncpy(Alloc(i + 1), opt, i); + t->name[i] = '\0'; + + if (opt[i] == '=') + { + i++; + } + t->value = strdup(opt + i); + + t->next = valdef_top; + valdef_top = t; + + debug_printf("DEFINE:$(%s)=\"%s\"\n", t->name, t->value); + } + return; +} + +// +// Search define value +// +// Return: value of specified name +// +char *SearchDefVal(char *name) +{ + tValdef *t; + + for (t = valdef_top; t; t = t->next) + { + if (!strcmp(t->name, name)) + { + return t->value; + } + } + + return getenv(name); +} + + +// +// Search define value and Modify it by : option +// +// Return: duplicated value of specified name modified by :x option +// +char *SearchDefValWithOption(char *name) +{ + int len_name = strlen(name); + char *value; + char option = '\0'; + + if (len_name > 2 && name[len_name - 2] == ':') + { + name[len_name - 2] = '\0'; + option = name[len_name - 1]; + } + + value = SearchDefVal(name); + + if (value) + { + int value_len = strlen(value); + int col_dot = value_len; + int col_filename = 0; + int i; + + for (i = 0; i < value_len; i++) + { + switch (value[i]) + { + case '.': + if (col_filename == i && + (value[i + 1] == '\0' || (value[i + 1] == '.' && value[i + 2] == '\0'))) + { + i = value_len; // exit loop if last entry is . or .. + } + else + { + col_dot = i; // Save the last dot column + } + break; + + case '/': + case '\\': + case ':': + col_filename = i + 1; // Save the last filename + col_dot = value_len; // Reset dot position + break; + + default: + ; + } + } + + switch (option) + { + case 'h': // Dirname with the last slash + value = strdup(value); + value[col_filename] = '\0'; + break; + + case 't': // Filename + value = strdup(value + col_filename); + break; + + case 'r': // All without . file extension + value = strdup(value); + value[col_dot] = '\0'; + break; + + case 'e': // File extension + value = strdup(value + col_dot + 1); + break; + + default: + value = strdup(value); + } + } + return value; +} + + +// +// Resolve define value +// +// Return: new string +// +char *ResolveDefVal(char *str) +{ + int i, j; + char *val; + VBuffer buf; + + InitVBuffer(&buf); + + for (i = 0; '\0' != str[i]; i++) + { + // search $(XXX) + if ('$' == str[i] && '(' == str[i + 1]) + { + for (j = i + 2; '\0' != str[j]; j++) + { + if (')' == str[j]) + { + str[j] = '\0'; + + // get value of XXX + val = SearchDefValWithOption(&str[i + 2]); + + // copy value of XXX + if (val) + { + char *s = val; + + while (*s) + { + PutVBuffer(&buf, *s); + s++; + } + free(val); + } + i = j; + goto next; + } + } + } + PutVBuffer(&buf, str[i]); + next:; + } + return GetVBuffer(&buf); // pass allocated buffer, should be freed by caller +} diff --git a/build/tools/makenandfirm/defval.h b/build/tools/makenandfirm/defval.h new file mode 100644 index 00000000..71355101 --- /dev/null +++ b/build/tools/makenandfirm/defval.h @@ -0,0 +1,38 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makerom + File: defval.h + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: defval.h,v $ + Revision 1.4 2006/01/18 02:11:19 kitase_hirotake + do-indent + + Revision 1.3 2005/02/28 05:26:03 yosizaki + do-indent. + + Revision 1.2 2004/08/05 13:50:13 yasu + Support -M option + + Revision 1.1 2004/03/26 05:06:45 yasu + support variables like as -DNAME=VALUE + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#ifndef DEFVAL_H_ +#define DEFVAL_H_ + +#define DEFVAL_DEFAULT_BUFFER_SIZE (1024) + +BOOL AddDefValFromFile(char *filename); +void AddDefVal(char *opt); +char *SearchDefVal(char *name); +char *ResolveDefVal(char *str); + +#endif //DEFVAL_H_ diff --git a/build/tools/makenandfirm/elf.h b/build/tools/makenandfirm/elf.h new file mode 100644 index 00000000..c360cd33 --- /dev/null +++ b/build/tools/makenandfirm/elf.h @@ -0,0 +1,431 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - ELF + File: elf.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. + *---------------------------------------------------------------------------*/ + +#ifndef ELF_H_ +#define ELF_H_ + +#include "misc.h" + +/*--------------------------------------------------------- + ^` + --------------------------------------------------------*/ +typedef u32 Elf32_Addr; /* size:4, align:4 Unsigned program address */ +typedef u16 Elf32_Half; /* size:2, align:2 Unsigned medium int */ +typedef u32 Elf32_Off; /* size:4, align:4 Unsigned file offset */ +typedef s32 Elf32_Sword; /* size:4, align:4 Signed large int */ +typedef u32 Elf32_Word; /* size:4, align:4 Unsigned large int */ + +/*--------------------------------------------------------- + ELF Header + --------------------------------------------------------*/ +/* e_ident̃CfbNX */ +#define EI_MAG0 0 /* File identification */ +#define EI_MAG1 1 /* File identification */ +#define EI_MAG2 2 /* File identification */ +#define EI_MAG3 3 /* File identification */ +#define EI_CLASS 4 /* File class 0=invalid, 1=32bit, 2=64bit */ +#define EI_DATA 5 /* Data encoding 0=invalid, 1=LSB, 2=MSB */ +#define EI_VERSION 6 /* File version ݂1 */ +#define EI_PAD 7 /* Start of padding bytes */ +#define EI_NIDENT 16 /* Size of e_ident[] */ + +typedef struct { + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; /* ELF̌`(Ĕzu”\, s”\Ȃ) */ + Elf32_Half e_machine; /* t@CŗvA[LeN` */ + Elf32_Word e_version; /* ELFtH[}bg̃o[Wi݂1j */ + Elf32_Addr e_entry; /* vÕGg|CgBw薳Ȃ0B */ + Elf32_Off e_phoff; /* vOwb_e[ũt@C擪̃ItZbg */ + Elf32_Off e_shoff; /* ZNVwb_e[ũt@C擪̃ItZbg */ + Elf32_Word e_flags; /* vZbTŗL̃tO */ + Elf32_Half e_ehsize; /* ELFwb_̃TCY */ + Elf32_Half e_phentsize; /* 1vOwb_̃TCY */ + Elf32_Half e_phnum; /* vOwb_̐ */ + Elf32_Half e_shentsize; /* 1ZNVwb_̃TCY */ + Elf32_Half e_shnum; /* ZNVwb_̐ */ + Elf32_Half e_shstrndx; /* ZNVe[uZNVւ̃CfbNX */ +} Elf32_Ehdr; + +/* e_ident[EI_*]̒g` */ +#define ELFMAG0 0x7f +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFCLASSNONE 0 /* invalid */ +#define ELFCLASS32 1 /* ARM and Thumb processors use 32-bit ELF. */ +#define ELFCLASS64 2 +#define ELFDATANONE 0 /* invalid */ +#define ELFDATA2LSB 1 /* little-endian */ +#define ELFDATA2MSB 2 /* big-endian */ + + +/* [e_type] */ +#define ET_NONE 0 /* No file type */ +#define ET_REL 1 /* Re-locatable file */ +#define ET_EXEC 2 /* Executable file */ +#define ET_DYN 3 /* Shared object file */ +#define ET_CORE 4 /* Core file */ +#define ET_LOPROC 0xff00 /* Processor-specific */ +#define ET_HIPROC 0xffff /* Processor-specific */ + +/* [e_machine] */ +#define EM_NONE 0 /* No machine */ +#define EM_M32 1 +#define EM_SPARC 2 +#define EM_386 3 +#define EM_68K 4 +#define EM_88K 5 +#define EM_860 7 +#define EM_MIPS 8 +#define EM_MIPS_RS4_BE 10 +#define EM_ARM 40 /* ARM/Thumb Architecture */ + + +/* [e_version] This member identifies the object file version.*/ +#define EV_NONE 0 /* Invalid version */ +#define EV_CURRENT 1 /* Current version */ + + +/* + ARM-specific e_flags + e_flags Field Value Meaning + EF_ARM_HASENTRY (0x02) e_entry contains a program-loader entry point + (see section 4.1.1, Entry points, below). + EF_ARM_SYMSARESORTED (0x04) Each subsection of the symbol table is sorted by symbol value + (see section 4.4.8, Symbol table order, below) + EF_ARM_DYNSYMSUSESEGIDX (0x8) Symbols in dynamic symbol tables that are defined in sections + included in program segment n have st_shndx = n + 1. + (see section 4.4.9, Dynamic symbol table entries, below). + EF_ARM_MAPSYMSFIRST (0x10) Mapping symbols precede other local symbols in the symbol table + (see section 4.4.8, Symbol table order, below). + + EF_ARM_EABIMASK (0xFF000000)(current version is 0x02000000) + This masks an 8-bit version number, the version of the ARM + EABI to which this ELF file conforms. This EABI is version 2. A + value of 0 denotes unknown conformance. +*/ +#define EF_ARM_HASENTRY 0x02 +#define EF_ARM_SYMSARESORTED 0x04 +#define EF_ARM_DYNSYMSUSESEGIDX 0x8 +#define EF_ARM_MAPSYMSFIRST 0x10 +#define EF_ARM_EABIMASK 0xFF000000 + + +/*--------------------------------------------------------- + Program headers + --------------------------------------------------------*/ +typedef struct { + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; +} Elf32_Phdr; + +/* [p_type] */ +#define PT_NULL 0 /* gȂGgŁÃo̒l̈Ӗ͖` */ +#define PT_LOAD 1 /* sɃ[hZOg */ +#define PT_DYNAMIC 2 /* I\̔zێZOg */ +#define PT_INTERP 3 /* t@C̉߂ɎgC^v^̃pXێZOg */ +#define PT_NOTE 4 /* t@C̉߂ɂ͎gȂێZOg */ +#define PT_SHLIB 5 /* \ */ +#define PT_PHDR 6 /* vOwb_e[uivÕC[Ẅꕔłꍇ̂ݑ݁j */ +//#define PT_TLS ? /* XbhǏL̈̃ev[g */ + +#define PT_LOOS 0x60000000 /* OSŗLɗ\񂳂ꂽ̈ */ +#define PT_HIOS 0x6fffffff + +#define PT_LOPROC 0x70000000 /* vZbTŗLɗ\񂳂ꂽ̈ */ +#define PT_HIPROC 0x7fffffff + +/* [p_flags]*/ +#define PF_X 1 /*s”\*/ +#define PF_W 2 /*݉”\*/ +#define PF_R 4 /*ǂݏo”\*/ +#define PF_ARM_SB 0x10000000 /*The segment contains the location addressed by the static base*/ +#define PF_ARM_PI 0x20000000 /*The segment is position-independent*/ +#define PF_ARM_ENTRY 0x80000000 /*The segment contains the entry point*/ +#define PF_MASKPROC 0xf0000000 + + +/*--------------------------------------------------------- + Section headers + --------------------------------------------------------*/ +typedef struct { + Elf32_Word sh_name; /*ZNVwb_e[uZNṼCfbNX*/ + Elf32_Word sh_type; /* ^CviL`QƁj */ + Elf32_Word sh_flags; + Elf32_Addr sh_addr; /* */ + Elf32_Off sh_offset; /* t@C̐擪̃ItZbg */ + Elf32_Word sh_size; /* oCgPʂ̃TCY */ + Elf32_Word sh_link; /* sh_typeɂĒl̈Ӗς */ + Elf32_Word sh_info; /* sh_typeɂĒl̈Ӗς */ + Elf32_Word sh_addralign; /* ACg(0or1ŐȂ,44ByteAlign) */ + Elf32_Word sh_entsize; /* ŒTCỸGge[uꍇA1vf̃TCY */ +} Elf32_Shdr; + +/* sh_addr mod sh_addralign = 0 łȂ΂ȂȂ */ + +/* Section Types, [sh_type] */ +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xffffffff + + +/* [sh_flags] */ +#define SHF_WRITE 0x1 +#define SHF_ALLOC 0x2 +#define SHF_EXECINSTR 0x4 +#define SHF_MASKPROC 0xf0000000 +/* ARM-EABI-specific */ +#define SHF_ENTRYSECT 0x10000000 /* The section contains an entry point. */ +#define SHF_COMDEF 0x80000000 /* The section may be multiply defined in the input to a link step. */ +/* others */ +#define SHF_LINK_ORDER 0x80 + +/*ZNVCfbNX*/ +//Sym->st_shndxȂ +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_LOPROC 0xff00 +#define SHN_HIPROC 0xff1f +#define SHN_ABS 0xfff1 +#define SHN_COMMON 0xfff2 +#define SHN_HIRESERVE 0xffff + + +//̓wb_łȂ̃f[^\ + +/*--------------------------------------------------------- + Symbol Table Entry + --------------------------------------------------------*/ +typedef struct { + Elf32_Word st_name; /* V{e[ũCfbNX */ + Elf32_Addr st_value; /* 炭֘AZNVł̃ItZbgl */ + Elf32_Word st_size; /* TCYȂAsȏꍇ 0 */ + unsigned char st_info; /* oCh ^Cv */ + unsigned char st_other; /* ݂ 0 */ + Elf32_Half st_shndx; /* ֘AZNVwb_e[ũCfbNX */ +} Elf32_Sym; + + +/* st_info */ +#define ELF32_ST_BIND(i) ((i)>>4) +#define ELF32_ST_TYPE(i) ((i)&0xf) +#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) + +/* st_info BIND */ +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 +#define STB_LOPROC 13 +#define STB_HIPROC 15 + +/* st_info TYPE */ +#define STT_NOTYPE 0 /*`*/ +#define STT_OBJECT 1 /*f[^IuWFNg*/ +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 +#define STT_LOPROC 13 +#define STT_HIPROC 15 + + +/*--------------------------------------------------------- + Relocation Entry + --------------------------------------------------------*/ +typedef struct { + Elf32_Addr r_offset; + Elf32_Word r_info; +} Elf32_Rel; + +typedef struct { + Elf32_Addr r_offset; + Elf32_Word r_info; + Elf32_Sword r_addend; +} Elf32_Rela; + +#define ELF32_R_SYM(i) ((i)>>8) +#define ELF32_R_TYPE(i) ((unsigned char)(i)) +#define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t)) + + +/* r_info TYPE */ +#define R_ARM_NONE 0 /* Any No relocation. Encodes dependencies between sections. */ +#define R_ARM_PC24 1 /* ARM B/BL S . P + A */ +#define R_ARM_ABS32 2 /* 32-bit word S + A */ +#define R_ARM_REL32 3 /* 32-bit word S . P + A */ +#define R_ARM_PC13 4 /* ARM LDR r, [pc,c] S . P + A */ +#define R_ARM_ABS16 5 /* 16-bit half-word S + A */ +#define R_ARM_ABS12 6 /* ARM LDR/STR S + A */ +#define R_ARM_THM_ABS5 7 /* Thumb LDR/STR S + A */ +#define R_ARM_ABS8 8 /* 8-bit byte S + A */ +#define R_ARM_SBREL32 9 /* 32-bit word S . B + A */ +#define R_ARM_THM_PC22 10 /* Thumb BL pair S . P+ A */ +#define R_ARM_THM_PC8 11 /* Thumb LDR r, [pc,c] S . P + A */ +#define R_ARM_AMP_VCALL9 12 /* AMP VCALL Obsolete.SA-1500 only. */ +#define R_ARM_SWI24 13 /* ARM SWI S + A */ +#define R_ARM_THM_SWI8 14 /* Thumb SWI S + A */ +#define R_ARM_XPC25 15 /* ARM BLX S . P+ A */ +#define R_ARM_THM_XPC22 16 /* Thumb BLX pair S . P+ A */ + +/* 17-31, reserved to ARM Linux */ +//17-19 Reserved to ARM LINUX +#define R_ARM_COPY 20 /* 32 bit word Copy symbol at dynamic link time. */ +#define R_ARM_GLOB_DAT 21 /* 32 bit word Create GOT entry. */ +#define R_ARM_JUMP_SLOT 22 /* 32 bit word Create PLT entry. */ +#define R_ARM_RELATIVE 23 /* 32 bit word Adjust by program base. */ +#define R_ARM_GOTOFF 24 /* 32 bit word Offset relative to start of GOT. */ +#define R_ARM_GOTPC 25 /* 32 bit word Insert address of GOT. */ +#define R_ARM_GOT32 26 /* 32 bit word Entry in GOT. */ +#define R_ARM_PLT32 27 /* ARM BL Entry in PLT. */ + +/* 28-31 Reserved to ARM LINUX */ +#define R_ARM_ALU_PCREL_7_0 32 /* ARM ADD/SUB (S . P + A) & 0x000000FF */ +#define R_ARM_ALU_PCREL_15_8 33 /* ARM ADD/SUB (S . P + A) & 0x0000FF00 */ +#define R_ARM_ALU_PCREL_23_15 34 /* ARM ADD/SUB (S . P + A) & 0x00FF0000 */ +#define R_ARM_LDR_SBREL_11_0 35 /* ARM LDR/STR (S . B + A) & 0x00000FFF */ +#define R_ARM_ALU_SBREL_19_12 36 /* ARM ADD/SUB (S . B + A) & 0x000FF000 */ +#define R_ARM_ALU_SBREL_27_20 37 /* ARM ADD/SUB (S . B + A) & 0x0FF00000 */ + +#define R_ARM_TARGET1 38 +#define R_ARM_ROSEGREL32 39 +#define R_ARM_V4BX 40 +#define R_ARM_TARGET2 41 +#define R_ARM_PREL31 42 + +/* 96-111, reserved to ARM g++ */ +#define R_ARM_GNU_VTENTRY 100 /* 32 bit word Record C++ vtable entry. */ +#define R_ARM_GNU_VTINHERIT 101 /* 32 bit word Record C++ member usage. */ +#define R_ARM_THM_PC11 102 /* Thumb B S . P + A */ +#define R_ARM_THM_PC9 103 /* Thumb B S . P + A */ + +/* 112-127, reserved for private experiments */ + +/* 128-248, reserved to ARM */ +#define R_ARM_RXPC25 249 /* ARM BLX (S . P) + A #define For calls between program segments. */ +#define R_ARM_RSBREL32 250 /* Word (S . SB) + A For an offset from SB, the static base. */ +#define R_ARM_THM_RPC22 251 /* Thumb BL/BLX pair (S . P) + A For calls between program segments. */ +#define R_ARM_RREL32 252 /* Word (S . P) + A For on offset between two segments. */ +#define R_ARM_RABS32 253 /* Word S + A For the address of a location in the target segment. */ +#define R_ARM_RPC24 254 /* ARM B/BL (S . P) + A For calls between program segments. */ +#define R_ARM_RBASE 255 /* None None.Identifies the segment being relocated by the following + relocation directives. The ARM EABI poses two problems for relocating + executables and shared objects encoded in */ + + +// shirait +#define R_ARM_LDR_PC_G0 4 //LDR + +#define R_ARM_ABS12 6 //LDR, STR + +#define R_ARM_THM_CALL 10 //R_ARM_THM_PC22Ɠ + +#define R_ARM_CALL 28 //BL/BLX +#define R_ARM_JUMP24 29 //B/BL +#define R_ARM_THM_JUMP24 30 + +#define R_ARM_MOVW_ABS_NC 43 //MOVW +#define R_ARM_MOVT_ABS 44 //MOVT +#define R_ARM_MOVW_PREL_NC 45 //MOVW +#define R_ARM_MOVT_PREL 46 //MOVT + +#define R_ARM_ALU_PC_G0_NC 57 //ADD, SUB +#define R_ARM_ALU_PC_G0 58 //ADD, SUB +#define R_ARM_ALU_PC_G1_NC 59 //ADD, SUB +#define R_ARM_ALU_PC_G1 60 //ADD, SUB +#define R_ARM_ALU_PC_G2 61 //ADD, SUB +#define R_ARM_LDR_PC_G1 62 //LDR, STR, LDRB, STRB +#define R_ARM_LDR_PC_G2 63 //LDR, STR, LDRB, STRB +#define R_ARM_LDRS_PC_G0 64 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_PC_G1 65 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_PC_G2 66 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDC_PC_G0 67 //LDC, STC +#define R_ARM_LDC_PC_G1 68 //LDC, STC +#define R_ARM_LDC_PC_G2 69 //LDC, STC +#define R_ARM_ALU_SB_G0_NC 70 //ADD, SUB +#define R_ARM_ALU_SB_G0 71 //ADD, SUB +#define R_ARM_ALU_SB_G1_NC 72 //ADD, SUB +#define R_ARM_ALU_SB_G1 73 //ADD, SUB +#define R_ARM_ALU_SB_G2 74 //ADD, SUB +#define R_ARM_LDR_SB_G0 75 //LDR, STR, LDRB, STRB +#define R_ARM_LDR_SB_G1 76 //LDR, STR, LDRB, STRB +#define R_ARM_LDR_SB_G2 77 //LDR, STR, LDRB, STRB +#define R_ARM_LDRS_SB_G0 78 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_SB_G1 79 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_SB_G2 80 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDC_SB_G0 81 //LDC, STC +#define R_ARM_LDC_SB_G1 82 //LDC, STC +#define R_ARM_LDC_SB_G2 83 //LDC, STC +#define R_ARM_MOVW_BREL_NC 84 //MOVW +#define R_ARM_MOVT_BREL 85 //MOVT +#define R_ARM_MOVW_BREL 86 //MOVW + +#define R_ARM_GOT_BREL12 97 //LDR +#define R_ARM_GOTOFF12 98 //LDR, STR + +#define R_ARM_TLS_LDO12 109 //LDR, STR +#define R_ARM_TLS_LE12 110 //LDR, STR +#define R_ARM_TLS_TE12GP 111 //LDR + + + +/*--------------------------------------------------------- + Dynamic Section elf_v1.2 + --------------------------------------------------------*/ +typedef struct { + Elf32_Sword d_tag; + union { + Elf32_Word d_val; + Elf32_Addr d_ptr; + } d_un; +} Elf32_Dyn; + + +/* Additional symbol types for Thumb. */ +#define STT_ARM_TFUNC STT_LOPROC /* A Thumb function. */ +#define STT_ARM_16BIT STT_HIPROC /* A Thumb label. */ + + + + + + + + + +/*--------------------------------------------------------- + ELFwb_ǂݏo + --------------------------------------------------------*/ +void *ELF_LoadELFHeader(const void *buf, Elf32_Ehdr *ehdr); + + + +#endif /* ELF_H_ */ + diff --git a/build/tools/makenandfirm/format_nlist.h b/build/tools/makenandfirm/format_nlist.h new file mode 100644 index 00000000..a1ac95fd --- /dev/null +++ b/build/tools/makenandfirm/format_nlist.h @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenandfirm + File: format_nlist.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 FORMAT_NLIST_H_ +#define FORMAT_NLIST_H_ + +#include +#include "misc.h" +#include "path.h" + +#define SPECFILE_MAGIC_ID "#NANDSF" + +#define CRC16_INIT_VALUE 0xffff + +//--------------------------------------------------------------------------- +// Banner Spec File +//--------------------------------------------------------------------------- + +// Command List +typedef struct +{ + char *string; + BOOL (*funcp) (char *, int num); + +} +tCommandDesc; + + +// F Command +typedef struct +{ + u32 offsetStart; + u32 offsetEnd; + u32 padding; + char fullPathSrc[FILENAME_MAX]; + +} +tFileDesc; + + +#endif // FORMAT_NLIST_H_ diff --git a/build/tools/makenandfirm/format_rom.h b/build/tools/makenandfirm/format_rom.h new file mode 100644 index 00000000..e7195c10 --- /dev/null +++ b/build/tools/makenandfirm/format_rom.h @@ -0,0 +1,51 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenandfirm + File: format_rom.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 FORMAT_ROM_H_ +#define FORMAT_ROM_H_ + +#include "misc.h" +#include + + +#define DEFAULT_ALIGN 0x200 +#define FIRM_ALIGN DEFAULT_ALIGN +#define FIRM_ALIGN_MASK (FIRM_ALIGN - 1) + +#define DEFAULT_HOSTROOT "." +#define DEFAULT_ROOT "/" + +#define DEFAULT_REJECT_1 "CVS" +#define DEFAULT_REJECT_2 "vssver.scc" + +#define FORMAT_VERSION "1.0" + +#define ENTRYNAME_MAX 127 + +#define DEFAULT_LISTFILE "default.nlf" + +#define DEFAULT_NANDFIRM_SUFFIX ".nand" +#define DEFAULT_SPECFILE_SUFFIX ".nandsf" + +/*===========================================================================* + * ROM FORMAT + *===========================================================================*/ + +//--------------------------------------------------------------------------- +// ROM HEADER +//--------------------------------------------------------------------------- + +#endif //FORMAT_ROM_H_ diff --git a/build/tools/makenandfirm/format_sign.h b/build/tools/makenandfirm/format_sign.h new file mode 100644 index 00000000..6d3d2770 --- /dev/null +++ b/build/tools/makenandfirm/format_sign.h @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - SS + File: format_sign.h + + Copyright 2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_MAKENANDFIRM_ACSIGN_FORMAT_H_ +#define FIRM_MAKENANDFIRM_ACSIGN_FORMAT_H_ + +#include "format_rom.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_MAKENANDFIRM_ACSIGN_FORMAT_H_ */ +#endif diff --git a/build/tools/makenandfirm/makenandfirm.c b/build/tools/makenandfirm/makenandfirm.c new file mode 100644 index 00000000..abdb1c57 --- /dev/null +++ b/build/tools/makenandfirm/makenandfirm.c @@ -0,0 +1,106 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenandfirm + File: makenandfirm.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:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include +#include // strcasecmp() +#include // getopt() +#include "makenandfirm.h" +#include "format_rom.h" +#include "path.h" +#include "defval.h" +#include "version.h" + +static int makenandfirm(const char *specFile, const char *nandFile); + +//--------------------------------------------------------------------------- +// Main +//--------------------------------------------------------------------------- + +int main(int argc, char *argv[]) +{ + int n; + int narg; + char *nandfirmFile; + + InitAppName(argv[0]); + + while ((n = getopt(argc, argv, "D:hvpd")) != -1) + { + switch (n) + { + case 'h': + case 'v': + goto usage; + + case 'D': + AddDefVal(optarg); + break; + + case 'p': + PrintMode = TRUE; + break; + + case 'd': + DebugMode = TRUE; + break; + + default: + break; + } + } + + narg = argc - optind; + if (narg > 0) + { + // Make SpecFile->NandfirmFile + nandfirmFile = + strdup(narg > + 1 ? argv[optind + 1] : ChangeSuffix(argv[optind], DEFAULT_NANDFIRM_SUFFIX)); + return makenandfirm(argv[optind], nandfirmFile); + } + + usage: + { + char *makenandfirm = GetAppName(); + + fprintf(stderr, + "NITRO-SDK Development Tool - %s - Make nandfirm file \n" + "Build %lu\n\n" + "Usage: %s [-phv] [-DNAME=VALUE ...] SPECFILE [NANDFIRMFILE]\n\n", + makenandfirm, SDK_DATE_OF_LATEST_FILE, makenandfirm); + } + return 1; +} + + +//--------------------------------------------------------------------------- +// makenandfirm +//--------------------------------------------------------------------------- + +static int makenandfirm(const char *specFile, const char *nandFile) +{ + debug_printf("makenandfirm(): '%s' -> '%s'\n", specFile, nandFile); + + // Check identical + if (specFile && nandFile && !strcasecmp(specFile, nandFile)) + { + error("nandfirm spec file is identical '%s'", nandFile); + return 1; + } + + return OutputNandfirmFile(specFile, nandFile) ? 0 : 1; +} diff --git a/build/tools/makenandfirm/makenandfirm.h b/build/tools/makenandfirm/makenandfirm.h new file mode 100644 index 00000000..21ac7e0d --- /dev/null +++ b/build/tools/makenandfirm/makenandfirm.h @@ -0,0 +1,24 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenandfirm + File: makenandfirm.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 MAKENANDFIRM_H_ +#define MAKENANDFIRM_H_ + +#include "misc.h" + +BOOL OutputNandfirmFile(const char *specFile, const char *nandFile); + +#endif //MAKENANDFIRM_H_ diff --git a/build/tools/makenandfirm/misc.c b/build/tools/makenandfirm/misc.c new file mode 100644 index 00000000..7326f41f --- /dev/null +++ b/build/tools/makenandfirm/misc.c @@ -0,0 +1,628 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenandfirm + File: misc.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include // calloc() +#include // free(), exit() +#include // setmode() +#include // stat() +#include // setmode() +#include // strlen() +#include // va_start(),va_end() +#include // localtime() + +#include +#include "misc.h" + +BOOL DebugMode = FALSE; +BOOL PrintMode = FALSE; +char *PubkeyFileName = NULL; + +/*---------------------------------------------------------------------------* + * File Output Utilities + * + * BOOL OpenFile( const char* filename ) + * void CloseFile( void ) + * BOOL CheckResult( void ) + * void PutBuffer( const void* ptr, int len ) + * void PutByte( u8 c ) + * void PutWord( u16 c ) + * void PutWord( u32 c ) + * void PutString( const char *str ) + *---------------------------------------------------------------------------*/ + +static FILE *OutFile = NULL; +static const char *FileName = NULL; +static BOOL Status = FALSE; + + +// +// File Open +// + +BOOL OpenFile(const char *filename) +{ + if (OutFile) + CloseFile(); + + if (filename) + { + if (NULL == (OutFile = fopen(filename, "wb+"))) + { + error("Can't write '%s'", filename); + Status = FALSE; + return FALSE; + } + } + else + { + setmode(1, O_BINARY); + OutFile = stdout; // out to console if filename == NULL + } + FileName = filename; + Status = TRUE; + + return TRUE; +} + + +// +// File Close +// + +BOOL CloseFile(void) +{ + if (OutFile) + { + if (FileName) + { + if (fclose(OutFile) == -1) + { + error("Can't close '%s'", FileName); + Status = FALSE; + } + } + else + { + setmode(1, O_TEXT); + } + } + OutFile = NULL; + + return Status; +} + + +// +// File Seek +// + +void SeekFile(long pos) +{ + if (OutFile && fseek(OutFile, pos, SEEK_SET)) + { + error("Can't seek '%s'", FileName ? FileName : ""); + CloseFile(); + Status = FALSE; + } +} + + +// +// Error Check +// + +BOOL CheckResult(void) +{ + return Status; +} + + +// +// Delete outfile +// + +void DeleteOutFile(void) +{ + // Delete outfile + if (FileName) + { + debug_printf("Delete '%s'\n", FileName); + (void)unlink(FileName); + FileName = NULL; + } + return; +} + + +// +// Buffer Output +// + +void PutBuffer(const void *ptr, int len) /* If error, close file */ +{ + if (OutFile && len != fwrite(ptr, 1, len, OutFile)) + { + error("Can't write buffer to '%s'", FileName ? FileName : ""); + CloseFile(); + Status = FALSE; + } +} + +// +// Buffer Input +// + +void GetBuffer(void *ptr, int len) /* If error, close file */ +{ + if (OutFile && len != fread(ptr, 1, len, OutFile)) + { + error("Can't read '%s'", FileName ? FileName : ""); + CloseFile(); + Status = FALSE; + } +} + +// +// Byte/Half/Word Output +// + +void PutByte(u8 c) +{ + PutBuffer(&c, 1); +} +void PutHalf(u16 c) +{ + PutBuffer(&c, 2); +} +void PutWord(u32 c) +{ + PutBuffer(&c, 4); +} +void PutString(const char *str) +{ + PutBuffer(str, strlen(str)); +} + + +// +// Printf +// + +void PrintString(const char *fmt, ...) +{ + char *buffer; + va_list va; + int nchars; + int bufsize = FILENAME_MAX; + + while (1) + { + buffer = Alloc(bufsize); + va_start(va, fmt); + nchars = vsnprintf(buffer, bufsize, fmt, va); + va_end(va); + + if (0 <= nchars && nchars < bufsize) + { + break; + } + + Free(&buffer); + bufsize *= 2; + } + + if (nchars > 0) + { + PutBuffer(buffer, nchars); + } + Free(&buffer); +} + + +/*---------------------------------------------------------------------------* + * File Read/Write Utilities + * + * int ReadFile( const char* filename, void** buffer ) + * + * Read a file to buffer allocated internally + * Return read size + * Add '\0' at tail of file for help to handle text file + * + * BOOL WriteFile( const char* filename, void** buffer, int size ) + *---------------------------------------------------------------------------*/ + +int ReadFile(const char *filename, void *filebuffer, int size) +{ + FILE *fp; + struct stat fileStat; + int fileSize, readSize; + void **buffer = (void **)filebuffer; + + /* Check file */ + if (stat(filename, &fileStat) || !S_ISREG(fileStat.st_mode)) + { + goto error; + } + fileSize = fileStat.st_size; + if (fileSize < 0) + { + goto error; + } + + /* Open file */ + fp = fopen(filename, "rb"); + if (!fp) + { + goto error; + } + + if (size && (size < fileSize)) + { + readSize = size; + } + else + { + readSize = fileSize; + } + + /* Read file */ + *buffer = Alloc(readSize + 1); /* error handle is done in Alloc() */ + /* size+1 for '\0' to handle text file */ + if (readSize != fread(*buffer, sizeof(char), readSize, fp)) + { + goto error_free_close; + } + + (*(char **)buffer)[readSize] = '\0'; /* Works as terminater if file is text file */ + + /* Close file */ + fclose(fp); + return readSize; + + error_free_close: + Free(buffer); + fclose(fp); + error: + error("Can't read '%s'", filename); + return -1; +} + + +int ReadFileWithPadding(const char *filename, void *filebuffer, int size, int boundary) +{ + FILE *fp; + struct stat fileStat; + int fileSize, readSize, padSize; + void **buffer = (void **)filebuffer; + + if (!boundary) + { + return ReadFile(filename, buffer, size); + } + + /* Check file */ + if (stat(filename, &fileStat) || !S_ISREG(fileStat.st_mode)) + { + goto error; + } + fileSize = fileStat.st_size; + if (fileSize < 0) + { + goto error; + } + + /* Open file */ + fp = fopen(filename, "rb"); + if (!fp) + { + goto error; + } + + if (size && (size < fileSize)) + { + readSize = size; + } + else + { + readSize = fileSize; + } + + padSize = (boundary - (readSize & (boundary-1))) & (boundary-1); + + /* Read file */ + *buffer = Alloc(readSize + padSize); /* error handle is done in Alloc() */ + /* size+1 for '\0' to handle text file */ + if (readSize != fread(*buffer, sizeof(char), readSize, fp)) + { + goto error_free_close; + } + + memset((char*)*buffer + readSize, 0, padSize); + + /* Close file */ + fclose(fp); + return readSize + padSize; + + error_free_close: + Free(buffer); + fclose(fp); + error: + error("Can't read '%s'", filename); + return -1; +} + + +BOOL WriteFile(const char *filename, void *buffer, int size) +{ + debug_printf("WriteFile %s\n", filename); + + (void)OpenFile(filename); + PutBuffer(buffer, size); + CloseFile(); + Free(&buffer); + return CheckResult(); +} + + +/*---------------------------------------------------------------------------* + * Time Format Utilities + * + * char* GetGMTime( const time_t time ) Show GMT + * char* GetTime( const time_t time ) Show local Time + *---------------------------------------------------------------------------*/ + +char *GetGMTime(const time_t time) +{ + static char timebuffer[32]; + strftime(timebuffer, sizeof(timebuffer), "%y/%m/%d-%H:%M:%S", gmtime(&time)); + return timebuffer; +} + + +char *GetTime(const time_t time) +{ + static char timebuffer[32]; + strftime(timebuffer, sizeof(timebuffer), "%y/%m/%d-%H:%M:%S", localtime(&time)); + return timebuffer; +} + + +/*---------------------------------------------------------------------------* + * Memory Allocation Utilities + * + * void* Alloc( size_t size ) + *---------------------------------------------------------------------------*/ + +void *Alloc(size_t size) +{ + void *t = calloc(1, size); + + if (t == NULL) + { + error("Can't allocate memory."); + exit(10); + } + return t; +} + + +void Free(void *p) +{ + void **ptr = (void **)p; + + if (*ptr) + { + free(*ptr); + (*ptr) = NULL; + } +} + + +/*---------------------------------------------------------------------------* + * VBuffer + * + * void PutVBuffer( VBuffer* vbuf, char c ) + *---------------------------------------------------------------------------*/ + +void PutVBuffer(VBuffer * vbuf, char c) +{ + int size; + char *tmp_buffer; + + if (vbuf->buffer == 0) + { + vbuf->size = VBUFFER_INITIAL_SIZE; + vbuf->buffer = Alloc(vbuf->size); // buffer is CALLOCed + } + size = strlen(vbuf->buffer); + + if (size >= vbuf->size - 1) + { + // Need buffer expansion + vbuf->size *= 2; + tmp_buffer = Alloc(vbuf->size); // buffer is CALLOCed + strcpy(tmp_buffer, vbuf->buffer); + Free(&vbuf->buffer); + vbuf->buffer = tmp_buffer; + } + vbuf->buffer[size] = c; + return; +} + +char *GetVBuffer(VBuffer * vbuf) +{ + return vbuf->buffer; +} + +void InitVBuffer(VBuffer * vbuf) +{ + vbuf->buffer = 0; + vbuf->size = 0; +} + +void FreeVBuffer(VBuffer * vbuf) +{ + Free(&vbuf->buffer); +} + + +/*---------------------------------------------------------------------------* + * File Path Utilities + * + * char* ChangeBackSlash( char* path ) + *---------------------------------------------------------------------------*/ + +char *ChangeBackSlash(char *path) +{ + char *p = path; + + while (*p) + { + if (*p == '\\') + { + *p = '/'; + } + p++; + } + return path; +} + + +/*---------------------------------------------------------------------------* + * Math + * + * u16 CalcCRC16( u16 start, u8 *data, int size ) + *---------------------------------------------------------------------------*/ + +static u16 crc16_table[16] = { + 0x0000, 0xCC01, 0xD801, 0x1400, + 0xF001, 0x3C00, 0x2800, 0xE401, + 0xA001, 0x6C00, 0x7800, 0xB401, + 0x5000, 0x9C01, 0x8801, 0x4400 +}; + +u16 CalcCRC16(u16 start, u8 *data, int size) +{ + u16 r1; + u16 total = start; + + while (size-- > 0) + { + // 4bit + r1 = crc16_table[total & 0xf]; + total = (total >> 4) & 0x0fff; + total = total ^ r1 ^ crc16_table[*data & 0xf]; + + // 4bit + r1 = crc16_table[total & 0xf]; + total = (total >> 4) & 0x0fff; + total = total ^ r1 ^ crc16_table[(*data >> 4) & 0xf]; + + data++; + } + return total; +} + + +/*---------------------------------------------------------------------------* + * for firm header + * + *---------------------------------------------------------------------------*/ + +static u8 ConvertAlign( u32 ofs ) +{ + u8 i; + + ofs /= 4; + for (i=0; i<7; i++) + { + if ( ofs & 1 ) + { + break; + } + ofs >>= 1; + } + + return i; +} + +tROMAddrConvType ConvertHeaderRamAddr( s32 p ) +{ + tROMAddrConvType retval; + + retval.align = ConvertAlign( p ); + retval.address = (u16)((p - HW_WRAM)/(4< + +typedef enum +{ + FALSE = 0, + TRUE = 1 +} +BOOL; + +typedef unsigned char u8; +typedef unsigned short int u16; +typedef unsigned long int u32; +typedef unsigned long long u64; +typedef signed char s8; +typedef signed short int s16; +typedef signed long int s32; +typedef signed long long s64; +typedef volatile u8 vu8; +typedef volatile u32 vu32; +typedef vu32 REGType32v; + +#define error(...) do { fprintf(stderr, "Error: "); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); } while(0) + +#define warning(...) do { fprintf(stderr, "Warning: "); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); } while(0) + +BOOL OpenFile(const char *filename); +BOOL CloseFile(void); +void SeekFile(long pos); +BOOL CheckResult(void); +void DeleteOutFile(void); +void PutBuffer(const void *ptr, int len); +void GetBuffer(void *ptr, int len); +void PutByte(u8 c); +void PutHalf(u16 c); +void PutWord(u32 c); +void PutString(const char *str); +void PrintString(const char *fmt, ...); + +#define READ_ALL 0 +int ReadFile(const char *filename, void *filebuffer, int size); +int ReadFileWithPadding(const char *filename, void *filebuffer, int size, int boundary); +BOOL WriteFile(const char *filename, void *buffer, int size); + +char *GetGMTime(const time_t time); +char *GetTime(const time_t time); + +void *Alloc(size_t size); +void Free(void *p); + +typedef struct +{ + char *buffer; + int size; +} +VBuffer; + +#define VBUFFER_INITIAL_SIZE 1024 +void InitVBuffer(VBuffer * vbuf); +void FreeVBuffer(VBuffer * vbuf); +void PutVBuffer(VBuffer * vbuf, char c); +char *GetVBuffer(VBuffer * vbuf); + +char *ChangeBackSlash(char *path); + +u16 CalcCRC16(u16 start, u8 *data, int size); +const char *WrapNull(const char *str); + +typedef struct +{ + u16 address; + u8 align; +} +tROMAddrConvType; + +tROMAddrConvType ConvertHeaderRamAddr( s32 p ); +tROMAddrConvType ConvertHeaderRomOffset( s32 p ); +u16 ConvertHeaderRomOffsetAlign( s32 p, u32 align ); + +typedef union +{ + struct + { + u32 sign:1; + u32 header_hash:1; + u32 arm9_hash:1; + u32 arm7_hash:1; + u32 hash_table_hash:1; + u32 final_hash:1; + u32 header_footer:1; + } + e; + u32 raw; +} +tErrorFlags; + +extern BOOL DebugMode; +extern BOOL PrintMode; +extern char *PubkeyFileName; +void debug_printf(const char *str, ...); +void debug_printf2(const char *str, ...); + +#endif //MISC_H_ diff --git a/build/tools/makenandfirm/out_nandfirm.c b/build/tools/makenandfirm/out_nandfirm.c new file mode 100644 index 00000000..c3ed1210 --- /dev/null +++ b/build/tools/makenandfirm/out_nandfirm.c @@ -0,0 +1,981 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenandfirm + File: out_nandfirm.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:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include // atoi() +#include // strcmp() +#include // isprint() +#include // chdir() +#include +#include // UCHAR_MAX +#include +#include // stat() +#include "elf.h" +#include "misc.h" +#include "defval.h" +#include "format_rom.h" +#include "format_nlist.h" +#include "makenandfirm.h" +#include "format_sign.h" +#include "acsign_nand.h" +#include "compress.h" + +#define SDK_ASM + +#include +#include "../acsign/aes2.h" + +#define SBIN9CMD "ARM9_SBIN" +#define SBIN7CMD "ARM7_SBIN" +#define ELF9CMD "ARM9_ELF" +#define ELF7CMD "ARM7_ELF" +#define COMP9CMD "ARM9_COMP" +#define COMP7CMD "ARM7_COMP" +#define DECOMPCMD "DECOMP_PROC" +#define ARM9X2CMD "ARM9_X2" +#define VERCMD "VERSION" +#define RSAKEYCMD "RSA_KEY" +#define OUTKEYCMD "OUT_KEY" +#define WREGCMD "WRAM_RBIN" +#define ENDKEYCMD "ENC_KEYINFO" +#define NCDCMD "NCD_ROMOFS" +#define MIRRORCMD "MIRROR_OFS" +#define ERRCMD "ERROR" + +static BOOL ConstructNandfirmFile(char * specFile); +static BOOL ReadSbinFile(const char *fileName, void* minfo, void* minfo2, void* hash, BOOL comp); +static BOOL ReadKeyFile(const char *fileName); +static BOOL ReadWramRegFile(const char *fileName); +static s32 GetRamAddr(const char *fileName); + +static BOOL EncryptBuffer(char *buffer, int length); + +static BOOL Sbin9_Command(char * line, int num); +static BOOL Sbin7_Command(char * line, int num); +static BOOL Elf9_Command(char * line, int num); +static BOOL Elf7_Command(char * line, int num); +static BOOL Comp9_Command(char * line, int num); +static BOOL Comp7_Command(char * line, int num); +static BOOL Decomp_Command(char * line, int num); +static BOOL ARM9X2_Command(char * line, int num); +static BOOL VERSION_Command(char * line, int num); +static BOOL RSAKEY_Command(char * line, int num); +static BOOL OUTKEY_Command(char * line, int num); +static BOOL WramRegs_Command(char * line, int num); +static BOOL ENCKEY_Command(char * line, int num); +static BOOL NcdOffset_Command(char * line, int num); +static BOOL MirrorOffset_Command(char * line, int num); +static BOOL ERROR_Command(char * line, int num); + +static BOOL InitializeAesKey(void); +static BOOL InitializeNandfirmFile(void); +static BOOL FinalizeNandfirmFile(const char *nandFile); + +static s32 Offset; // Current offset +static int LineNum; // Line number for error message +static const char *specFileName; // specFile name for error message + +NANDHeaderEx nandHeader; // Nandfirm Header Shadow +FIRMSignedContext signedContext; +u8 *keyFileBuf; +BOOL compArm9 = TRUE; +BOOL compArm7 = TRUE; +u32 mirrorOfs = 0; +tErrorFlags errFlags; + +//--------------------------------------------------------------------------- +// Output - nandfirm File +//--------------------------------------------------------------------------- + +BOOL OutputNandfirmFile(const char *specFile, const char *nandFile) +{ + char *buffer; + BOOL state; + + if (ReadFile(specFile, &buffer, READ_ALL) <= 0) + { + return FALSE; + } + + if (!OpenFile(nandFile)) + { + return FALSE; + } + + specFileName = specFile; + + state = InitializeNandfirmFile() && ConstructNandfirmFile(buffer) && + FinalizeNandfirmFile(nandFile) && CloseFile(); + + if (!state) + { + DeleteOutFile(); + } + + return state; +} + + +//--------------------------------------------------------------------------- +// Output - Nandfirm File +//--------------------------------------------------------------------------- + +static const tCommandDesc command[] = { + {SBIN9CMD, Sbin9_Command}, {SBIN7CMD, Sbin7_Command}, + {ELF9CMD, Elf9_Command},{ELF7CMD, Elf7_Command}, + {COMP9CMD, Comp9_Command},{COMP7CMD, Comp7_Command}, + {DECOMPCMD, Decomp_Command}, + {VERCMD, VERSION_Command}, + {ARM9X2CMD, ARM9X2_Command}, + {RSAKEYCMD, RSAKEY_Command}, + {OUTKEYCMD, OUTKEY_Command}, + {WREGCMD, WramRegs_Command}, + {ENDKEYCMD, ENCKEY_Command}, + {NCDCMD, NcdOffset_Command}, + {MIRRORCMD, MirrorOffset_Command}, + {ERRCMD, ERROR_Command}, +}; + +BOOL ConstructNandfirmFile(char * specFile) +{ + char *line; + char *line_top; + char *p; + int i; + + LineNum = 0; + Offset = 0x00000000; + + line = specFile++; + + while (*line != '\0') + { + LineNum++; + + // Get command line + line_top = line; + while (*line != '\0') + { + if (*line++ == '\n') + { + break; + } + } + + // Print for debug + debug_printf("NANDSF Line%4d [", LineNum, line); + for (p = line_top; p != line; p++) + { + if (isprint(*p)) + { + debug_printf("%c", *p); + } + } + debug_printf("]\n"); + + if (*line_top == '#') + { + } + else + { + for (i = 0; i < (sizeof(command) / sizeof(command[0])); i++) + { + if (!strncmp(line_top, command[i].string, strlen(command[i].string))) + { + if (command[i].funcp != NULL) + { + char line_cmd[FILENAME_MAX]; + char line_scan[FILENAME_MAX]; + char* line_conv; + int num; + + num = sscanf( line_top, + "%1024[^ :] : %1024[^ \x0d:#\n]", + line_cmd, line_scan + ); + line_conv = ResolveDefVal(line_scan); + + debug_printf("line_cmd = %s, line_conv = %s\n", line_cmd, line_conv); + + if (!command[i].funcp(line_conv, num - 1)) + return FALSE; + } + } + } + } + + } + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - 'WramRegs' Command +//--------------------------------------------------------------------------- + +extern MIHeader_WramRegs wram_regs_init; +MIHeader_WramRegs* wram_regs; + +static BOOL WramRegs_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("wram regs file = %s\n", line); + + return ReadWramRegFile(line); +} + +static BOOL ReadWramRegFile(const char *fileName) +{ + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &wram_regs, READ_ALL)) < 0) + return FALSE; + + nandHeader.o.h.w = *wram_regs; + nandHeader.m.h.w = *wram_regs; + + return CheckResult(); +} + +//--------------------------------------------------------------------------- +// Output - 'RSAKEY' Command +//--------------------------------------------------------------------------- + +static BOOL RSAKEY_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("rsa key = %s\n", line); + + return ReadKeyFile(line); +} + +static BOOL ReadKeyFile(const char *fileName) +{ + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &keyFileBuf, READ_ALL)) < 0) + return FALSE; + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'OUTKEY' Command +//--------------------------------------------------------------------------- + +static BOOL OUTKEY_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("out key = %s\n", line); + + PubkeyFileName = line; + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'VERSION' Command +//--------------------------------------------------------------------------- + +static u8 ConvToBCD8(int x) +{ + u8 bcd = 0; + + x %= 100; + bcd |= (x / 10)<<4; + bcd |= (x % 10); + + return bcd; +} + +static BOOL VERSION_Command(char * line, int num) +{ + char scan[FILENAME_MAX]; + u64 version = -1; + + // rescan + num = sscanf( line, + "0x%1024[^\x0d\n]", + scan + ); + + if (num == 1) + { + // convert version info + version = strtoull(scan, NULL, 16); + } + else if (num == 0) + { + // generate version info + u8* ver8 = (u8*)&version; + time_t timer; + struct tm *t_st; + + time(&timer); + t_st = localtime(&timer); + + ver8[0] = ConvToBCD8(t_st->tm_min); + ver8[1] = ConvToBCD8(t_st->tm_hour); + ver8[2] = ConvToBCD8(t_st->tm_mday); + ver8[3] = ConvToBCD8(t_st->tm_mon+1); + ver8[4] = ConvToBCD8(t_st->tm_year); + ver8[5] = 0x57; + ver8[6] = 0xff; + ver8[7] = 0xff; + } + + nandHeader.g.d.card_key = version; + + debug_printf2("version = %08llx\n", version); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Decomp' Command +//--------------------------------------------------------------------------- + +static BOOL Decomp_Command(char * line, int num) +{ + char* dbg_str = "ARM7"; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + if (!strcmp(line, "ARM9")) + { + nandHeader.o.l.arm9_decomp = TRUE; + nandHeader.m.l.arm9_decomp = TRUE; + dbg_str = "ARM9"; + } + + debug_printf2("decompress processor = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'ARM9_X2' Command +//--------------------------------------------------------------------------- + +static BOOL ARM9X2_Command(char * line, int num) +{ + char* dbg_str = "FALSE"; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + if (!strcmp(line, "TRUE")) + { + nandHeader.o.l.arm9_x2 = TRUE; + nandHeader.m.l.arm9_x2 = TRUE; + dbg_str = "TRUE"; + } + + debug_printf2("arm9 x2 = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Comp9' Command +//--------------------------------------------------------------------------- + +static BOOL Comp9_Command(char * line, int num) +{ + char* dbg_str = "FALSE"; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + compArm9 = FALSE; + + if (!strcmp(line, "TRUE")) + { + nandHeader.o.l.comp_arm9_boot_area = TRUE; + nandHeader.m.l.comp_arm9_boot_area = TRUE; + compArm9 = TRUE; + dbg_str = "TRUE"; + } + + debug_printf2("arm9 compress = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Comp7' Command +//--------------------------------------------------------------------------- + +static BOOL Comp7_Command(char * line, int num) +{ + char* dbg_str = "FALSE"; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + compArm7 = FALSE; + + if (!strcmp(line, "TRUE")) + { + nandHeader.o.l.comp_arm7_boot_area = TRUE; + nandHeader.m.l.comp_arm7_boot_area = TRUE; + compArm7 = TRUE; + dbg_str = "TRUE"; + } + + debug_printf2("arm7 compress = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Elf9' Command +//--------------------------------------------------------------------------- + +static BOOL Elf9_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm9 elf = %s\n", line); + + { + s32 ramAddr = GetRamAddr(line); + nandHeader.o.l.main_ram_address = (void*)ramAddr; + nandHeader.m.l.main_ram_address = (void*)ramAddr; + } + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Elf7' Command +//--------------------------------------------------------------------------- + +static BOOL Elf7_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm7 elf = %s\n", line); + + { + s32 ramAddr = GetRamAddr(line); + nandHeader.o.l.sub_ram_address = (void*)ramAddr; + nandHeader.m.l.sub_ram_address = (void*)ramAddr; + } + + return CheckResult(); +} + + +static s32 GetRamAddr(const char *fileName) +{ + Elf32_Ehdr *ehdr; + s32 ramAddr; + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &ehdr, sizeof(Elf32_Ehdr))) < 0) + return FALSE; + + ramAddr = ehdr->e_entry; + + Free(&ehdr); + + debug_printf2("ramaddr = 0x%08x\n", ramAddr); + + return ramAddr; +} + + +//--------------------------------------------------------------------------- +// Output - 'Sbin9' Command +//--------------------------------------------------------------------------- + +static BOOL Sbin9_Command(char * line, int num) +{ + FIRMSignedContext* sc = &signedContext; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm9 sbin = %s\n", line); + + // Set ARM9 ROM Offset + if (!Offset) + { + Offset = (sizeof(NANDHeader) + FIRM_ALIGN_MASK) & ~FIRM_ALIGN_MASK; + if (mirrorOfs) + { + Offset += sizeof(NANDHeaderCore) * 2; + } + SeekFile(Offset); + } + debug_printf2("romoffset = %#x\n", Offset); + { + nandHeader.o.l.main_rom_offset = Offset; + nandHeader.m.l.main_rom_offset = Offset + mirrorOfs - sizeof(NANDHeaderCore) * 2; + } + + return ReadSbinFile(line, &nandHeader.o.l.main_rom_offset, &nandHeader.m.l.main_rom_offset, &sc->hash[FIRM_SIGNED_HASH_IDX_ARM9], compArm9); +} + +//--------------------------------------------------------------------------- +// Output - 'Sbin7' Command +//--------------------------------------------------------------------------- + +static BOOL Sbin7_Command(char * line, int num) +{ + FIRMSignedContext* sc = &signedContext; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm7 sbin = %s\n", line); + + // Set ARM7 ROM Offset + if (!Offset) + { + Offset = (sizeof(NANDHeader) + FIRM_ALIGN_MASK) & ~FIRM_ALIGN_MASK; + if (mirrorOfs) + { + Offset += sizeof(NANDHeaderCore) * 2; + } + SeekFile(Offset); + } + debug_printf2("romoffset = %#x\n", Offset); + { + nandHeader.o.l.sub_rom_offset = Offset; + nandHeader.m.l.sub_rom_offset = Offset + mirrorOfs - sizeof(NANDHeaderCore) * 2; + } + + return ReadSbinFile(line, &nandHeader.o.l.sub_rom_offset, &nandHeader.m.l.sub_rom_offset, &sc->hash[FIRM_SIGNED_HASH_IDX_ARM7], compArm7); +} + + +static BOOL ReadSbinFile(const char *fileName, void* minfo, void* minfo2, void* hash, BOOL comp) +{ + const NANDHeader_ModuleInfo *m = minfo; + u32 *size = (void*)&m->size; + u32 *orig_size = (void*)&m->decomp_size; + const NANDHeader_ModuleInfo *m2 = minfo2; + u32 *size2 = (void*)&m2->size; + u32 *orig_size2 = (void*)&m2->decomp_size; + char *buffer; + char *file; + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &file, READ_ALL)) < 0) + return FALSE; + + *orig_size = *orig_size2 = file_size; + + // Digest file image + if (hash) + { + ACSign_DigestUnit(hash, file, file_size); + } + + // Compress file image with fitting region + buffer = Alloc(file_size * 2); + if ( comp ) + { + file_size = LZCompWrite(file, file_size, buffer, FIRM_ALIGN); + } + else + { + memcpy(&buffer[0], file, file_size); + { + u32 pad_size = (FIRM_ALIGN - (file_size % FIRM_ALIGN)) % FIRM_ALIGN; + if (pad_size) + memset(&buffer[file_size], 0, pad_size); + file_size += pad_size; + } + } + Free(&file); + file = buffer; + + if (size) + { + *size = *size2 = file_size; + } + Offset += file_size; + + // Encrypt file image + EncryptBuffer(file, file_size); + + // Output file image with fitting region + PutBuffer(file, file_size); + + Free(&file); + + if (mirrorOfs && mirrorOfs < Offset + sizeof(NANDHeaderCore) * 2) + { + error("mirrorOfs is too small (%ld < %ld).\n", mirrorOfs, Offset + sizeof(NANDHeaderCore) * 2); + return FALSE; + } + + return CheckResult(); +} + +typedef struct +{ + unsigned long e[4]; +} u128; + +static BOOL EncryptBuffer(char *buffer, int length) +{ + const u128 id = {{ AES_IDS_ID2_A, AES_IDS_ID2_B, AES_IDS_ID2_C, AES_IDS_ID2_D }}; + u128 iv = {{ length, -length, ~length, 0 }}; + FIRMSignedContext* sc = &signedContext; + char *buffer2 = Alloc(length); + AES_KEY key; + if (!buffer2) + return FALSE; + AES_SetKey(&key, sc->aes_key, (unsigned char*)&id); + AES_Ctr(&key, buffer2, buffer, length, (unsigned char*)&iv); + memcpy(buffer, buffer2, length); + memset(buffer2, 0, length); + Free(buffer2); + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - 'ENC_KEYINFO' Command +//--------------------------------------------------------------------------- + +static BOOL ENCKEY_Command(char * line, int num) +{ + u32 key; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + key = strtoul(line, NULL, 0); + nandHeader.g.d.ds_key = key; + + debug_printf2("keyinfo = %#x\n", key); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'NcdOffset' Command +//--------------------------------------------------------------------------- + +static BOOL NcdOffset_Command(char * line, int num) +{ + u32 ofs; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + ofs = strtoul(line, NULL, 0); + { + nandHeader.g.d.ncd_romAdr = ConvertHeaderRomOffsetAlign(ofs, 8); + } + + debug_printf2("ncd romoffset = %#x\n", ofs); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'MirrorOffset' Command +//--------------------------------------------------------------------------- + +static BOOL MirrorOffset_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + mirrorOfs = strtoul(line, NULL, 0); + + debug_printf2("mirrored image offset = %#x\n", mirrorOfs); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'ERROR' Command +//--------------------------------------------------------------------------- +static char* error_type[] = +{ + "SIGN", + "HEADER_HASH", + "ARM9_HASH", + "ARM7_HASH", + "HASH_TABLE_HASH", + "FINAL_HASH", + "HEADER_FOOTER", +}; + +static BOOL ERROR_Command(char * line, int num) +{ + char* dbg_str = "UNKNOWN"; + int i; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + for (i=0; ihash[FIRM_SIGNED_HASH_IDX_HEADER][0] ^= 1; + } + if ( errFlags.e.arm9_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_ARM9][0] ^= 1; + } + if ( errFlags.e.arm7_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_ARM7][0] ^= 1; + } + if ( errFlags.e.hash_table_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_HASH_TABLE][0] ^= 1; + } +} + +static void SetFinalHashError(FIRMSignedContext* sc) +{ + if ( errFlags.e.final_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_FINAL][0] ^= 1; + } +} + +static void SetSignError(NANDHeader* nh) +{ + if ( errFlags.e.sign ) + { + nh->sign.raw[0] ^= 1; + } + +} + +static void SetFooterError(NANDHeader* nh) +{ + if ( errFlags.e.header_footer ) + { + nh->h.reserved_footer[sizeof(nh->h.reserved_footer)-1] ^= 1; + } + +} + +//--------------------------------------------------------------------------- +// Output - Initialize AES Key +//--------------------------------------------------------------------------- +static BOOL InitializeAesKey(void) +{ + FIRMSignedContext* sc = &signedContext; + struct stat specstat; + time_t spectime; + if (stat(specFileName, &specstat) != 0) + return FALSE; + time(&spectime); + memcpy(&sc->aes_key[0], &specstat.st_atime, 4); + memcpy(&sc->aes_key[4], &specstat.st_mtime, 4); + memcpy(&sc->aes_key[8], &specstat.st_ctime, 4); + memcpy(&sc->aes_key[12], &spectime, 4); + ACSign_GetKey(sc->aes_key, sizeof(sc->aes_key), sc->aes_key, sizeof(sc->aes_key)); + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - Initialize Nandfirm File +//--------------------------------------------------------------------------- + +static BOOL InitializeNandfirmFile(void) +{ + memset(&signedContext.hash[FIRM_SIGNED_HASH_IDX_HASH_TABLE], 0x00, sizeof(signedContext.hash[0])); + nandHeader.o.h.w = wram_regs_init; + nandHeader.m.h.w = wram_regs_init; + InitializeAesKey(); + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - Finalize Nandfirm File +//--------------------------------------------------------------------------- + +static void FinalizeNandfirmFileCore(NANDHeaderCore* master) +{ + NANDHeader *nh = &nandHeader.g; + FIRMSignedContext* sc = &signedContext; + u8* key = keyFileBuf; + + memcpy(&nh->l, &master->l, sizeof(NANDHeaderLow)); + memcpy(&nh->h, &master->h, sizeof(NANDHeaderHigh)); + + ACSign_DigestHeader(&sc->hash[FIRM_SIGNED_HASH_IDX_HEADER], nh); + + SetUnitHashErrors(sc); + + ACSign_DigestUnit(&sc->hash[FIRM_SIGNED_HASH_IDX_FINAL], sc, FIRM_HEADER_2ND_HASH_AREA_LEN); + + SetFinalHashError(sc); + + if (key) + { + ACSign_Final(nh, sc, key); + } + + SetFooterError(nh); + + SetSignError(nh); + + memcpy(&master->sign, &nh->sign, sizeof(FIRMPaddedSign)); +} + +static BOOL FinalizeNandfirmFile(const char *nandFile) +{ + // for m header (copy to g) + FinalizeNandfirmFileCore(&nandHeader.m); + + // for o header (copy to g) + FinalizeNandfirmFileCore(&nandHeader.o); + + // Output file image + SeekFile(0L); + if (mirrorOfs) + { + PutBuffer(&nandHeader, sizeof(nandHeader)); + } + else + { + PutBuffer(&nandHeader.g, sizeof(nandHeader.g)); + } + + // Output public key (modulus) + if (PubkeyFileName) + { + WriteFile(PubkeyFileName, &keyFileBuf[ACS_RSA_PRVMOD_OFFSET], ACS_RSA_PRVMOD_LEN); + } + + return TRUE; +} diff --git a/build/tools/makenandfirm/path.c b/build/tools/makenandfirm/path.c new file mode 100644 index 00000000..eeeb9895 --- /dev/null +++ b/build/tools/makenandfirm/path.c @@ -0,0 +1,931 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makebanner + File: path.c + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: path.c,v $ + Revision 1.3 2006/01/18 02:11:20 kitase_hirotake + do-indent + + Revision 1.2 2005/02/28 05:26:13 yosizaki + do-indent. + + Revision 1.1 2004/08/30 08:41:14 yasu + makebanner moves into CVS tree + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include // free() +#include // strcasecmp() +#include // stat() +#include // opendir()/readdir()/closedir() +#include // getcwd() +#ifdef __CYGWIN__ +#include // cygwin_conv_to_win32_path() +#endif +#include "path.h" + +//--------------------------------------------------------------------------- +// Get File Statue +//--------------------------------------------------------------------------- + +tFileStatus GetFileStatus(struct stat *s, const char *filename) +{ + // Get file status + if (stat(filename, s)) + { + error("Can't get status %s", filename); + return FILESTATUS_ERROR; + } + + if (S_ISREG(s->st_mode)) + { + return FILESTATUS_FILE; + } + else if (S_ISDIR(s->st_mode)) + { + return FILESTATUS_DIR; + } + + error("Unknown file type %s", filename); + return FILESTATUS_ERROR; +} + + +//--------------------------------------------------------------------------- +// File Globbing & Dir Listing +//--------------------------------------------------------------------------- + +typedef struct +{ + tCallBack callBack; + void *param; + tWildCard *accept; + tWildCard *reject; + +} +tForeachEntryParam; + + +static BOOL isAcceptEntryName(char *pathName, tWildCard * accept, tWildCard * reject) +{ + char *p = pathName; + + while (*p) + { + if (*p == '/') + pathName = p + 1; + p++; + } + + if (accept) + { + while (accept) + { + if (WildCardCmp(accept->name, pathName)) + { + goto accepted; + } + accept = accept->next; + } + return FALSE; + } + accepted: + + while (reject) + { + if (WildCardCmp(reject->name, pathName)) + { + return FALSE; + } + reject = reject->next; + } + return TRUE; +} + + +static BOOL ForeachEntry_CallBack(char *pathName, void *param) +{ + tForeachEntryParam *t = (tForeachEntryParam *) param; + struct stat fstat; + + if (!isAcceptEntryName(pathName, t->accept, t->reject)) + { + // Reject!!! ignored + return TRUE; + } + + switch (GetFileStatus(&fstat, pathName)) + { + case FILESTATUS_FILE: + return t->callBack(pathName, t->param); + + case FILESTATUS_DIR: + return ForeachDirList(pathName, ForeachEntry_CallBack, param); + + default: + break; + } + return FALSE; +} + + +BOOL ForeachEntry(const char *pathName, tWildCard * reject, tCallBack callBack, void *param) +{ + tForeachEntryParam t; + + t.callBack = callBack; + t.param = param; + t.accept = NULL; + t.reject = reject; + + return ForeachPathGlobbing(pathName, ForeachEntry_CallBack, &t); +} + + +typedef struct +{ + tCallBack callBack; + void *param; + char *baseName; + +} +tForeachFileParam; + + +static BOOL ForeachFile_CallBack(char *pathName, void *param) +{ + tForeachFileParam *t = (tForeachFileParam *) param; + + int len = strlen(t->baseName); + + debug_printf(" ForeachFile_CallBack path[%s] base[%s]\n", pathName, t->baseName); + + if (strncmp(pathName, t->baseName, len)) + { + error("Wildcard in Root is not supported"); + return FALSE; + } + + return t->callBack(pathName + len, t->param); +} + + +BOOL ForeachFile(const char *baseName, const char *fileName, tWildCard * reject, tCallBack callBack, + void *param) +{ + char *cBaseName; + char *cPathName; + BOOL state; + tForeachFileParam t; + + debug_printf("ForeachFile : baseName[%s] fileName[%s]\n", baseName, fileName); + + cBaseName = GetSrcPath(baseName, ""); + cPathName = GetSrcPath(baseName, fileName); + + debug_printf("ForeachFile : cBaseName[%s] cPathName[%s]\n", cBaseName, cPathName); + + t.callBack = callBack; + t.param = param; + t.baseName = cBaseName; + + state = ForeachEntry(cPathName, reject, ForeachFile_CallBack, &t); + + free(cBaseName); + free(cPathName); + + return state; +} + + +//--------------------------------------------------------------------------- +// FilePath Globbing +//--------------------------------------------------------------------------- + +typedef struct +{ + char *baseName; + char *pathName; + tCallBack callBack; + void *param; + +} +tGlobParam; + + +static int CountFile; +static BOOL ForeachPathGlobbing_Entry(tGlobParam * pg); +static BOOL ForeachPathGlobbing_WildCard(char *pathName, void *param); + +BOOL ForeachPathGlobbing(const char *pathName, tCallBack callBack, void *param) +{ + tGlobParam g; + BOOL ret; + + g.baseName = NULL; + g.pathName = PathNormalize(pathName, TRUE); + g.callBack = callBack; + g.param = param; + CountFile = 0; + + debug_printf("PathGlobbing : Name [%s]->[%s]\n", pathName, g.pathName); + + ret = ForeachPathGlobbing_Entry(&g); + + free(g.pathName); + + if (ret && CountFile == 0) + { + error("No file or directory matched %s", pathName); + return FALSE; + } + return ret; +} + + +static BOOL ForeachPathGlobbing_Entry(tGlobParam * pg) +{ + tGlobParam g; + char *entryName; + struct stat s; + BOOL state; + + if (pg->pathName) + { + entryName = PathDup(pg->pathName); + + g = *pg; + g.pathName = PathGetDirLevelDown(pg->pathName); + + if (pg->baseName) + { + g.baseName = Alloc(strlen(pg->baseName) + strlen(entryName) + 2); + sprintf(g.baseName, "%s/%s", pg->baseName, entryName); + } + else + { + g.baseName = strdup(entryName); + } + + // Check if wildcard ? + if (isPathWildCard(entryName)) + { + state = ForeachDirList(pg->baseName, ForeachPathGlobbing_WildCard, &g); + } + else + { + state = ForeachPathGlobbing_Entry(&g); + } + + Free(&entryName); + Free(&g.baseName); + } + else + { + // Check if file exists + if (!stat(pg->baseName, &s)) + { + debug_printf(" File Found [%s]\n", pg->baseName); + + // Globbing done, exec callback + + state = pg->callBack(pg->baseName, pg->param); + CountFile++; + } + else + { + debug_printf(" File Not Found [%s]\n", pg->baseName); + state = TRUE; // Ignored + } + } + return state; +} + + +static BOOL ForeachPathGlobbing_WildCard(char *pathName, void *param) +{ + tGlobParam g; + tGlobParam *pg = (tGlobParam *) param; + + debug_printf(" WildCardCmp: [%s] [%s]\n", pg->baseName, pathName); + + if (WildCardCmp(pg->baseName, pathName)) + { + g = *pg; + g.baseName = pathName; + return ForeachPathGlobbing_Entry(&g); + } + + return TRUE; // Ignored +} + + +//--------------------------------------------------------------------------- +// Directory Listing +// Listing directory & Exec CallBack +//--------------------------------------------------------------------------- + +BOOL ForeachDirList(const char *dirName, tCallBack callBack, void *param) +{ + DIR *dir; + struct dirent *entry; + char *pathName; + BOOL state = TRUE; + + if (!dirName) + { + dirName = "."; + } + + debug_printf("DirectoryList: Name [%s]\n", dirName); + + // Open directory + if (NULL == (dir = opendir(dirName))) + { + error("Can't read directory %s", dirName); + return FALSE; + } + + // Store new files + while (NULL != (entry = readdir(dir))) + { + pathName = entry->d_name; + + if (!strcmp(pathName, ".") || !strcmp(pathName, "..")) + { + continue; + } + + debug_printf(" :%s\n", pathName); + pathName = GetSrcPath(dirName, pathName); + state = callBack(pathName, param); + free(pathName); + + if (!state) + break; + } + + closedir(dir); + return state; +} + + +//--------------------------------------------------------------------------- +// +// PathName Utilities +// +//--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- +// StrCmp/StrCpy entry name terminated / or \0 +//--------------------------------------------------------------------------- + +int PathCmp(const char *path, const char *cmp) +{ + char c; + + do + { + c = *path; + if (c == '/') + c = '\0'; // end of string if '/' + if (c != *cmp) + return 1; + path++; + cmp++; + } + while (c); + + return 0; +} + + +char *PathCpy(char *dest, const char *src) +{ + while (*src != '\0' && *src != '/') + { + *dest++ = *src++; + } + return dest; // Don't set '\0' +} + + +int PathLen(const char *path) +{ + int n = 0; + + while (*path != '\0' && *path != '/') + { + n++; + path++; + } + return n; +} + + +char *PathDup(const char *src) +{ + int n = PathLen(src); + char *dest = Alloc(n + 2); + + PathCpy(dest, src); + dest[n] = '\0'; + + return dest; +} + + +BOOL WildCardCmp(const char *wildcard, const char *path) +{ + if (*wildcard == '*') + { + if (*path != '\0' && WildCardCmp(wildcard, path + 1)) + return TRUE; + if (WildCardCmp(wildcard + 1, path)) + return TRUE; + } + + else if (*wildcard == '?') + { + return *path != '\0' && WildCardCmp(wildcard + 1, path + 1); + } + + else if (*wildcard == *path) + { + return *path == '\0' || WildCardCmp(wildcard + 1, path + 1); + } + + return FALSE; +} + + +BOOL isPathWildCard(const char *path) +{ + while (*path != '\0' && *path != '/') + { + if (*path == '*' || *path == '?') + { + return TRUE; + } + path++; + } + return FALSE; +} + + +//--------------------------------------------------------------------------- +// Go up/down directory level +//--------------------------------------------------------------------------- + +char *PathGetDirLevelDown(const char *path) +{ + while (*path) + { + if (*path == '/') + return (char *)path + 1; + path++; + } + return NULL; +} + + +//--------------------------------------------------------------------------- +// Get Basename +//--------------------------------------------------------------------------- + +char *GetBaseName(const char *path) +{ + int i; + char *new_path; + + for (i = strlen(path) - 1; i >= 0; i--) + { + if (path[i] == '/') + { + new_path = strdup(path); + new_path[i] = '\0'; + return new_path; + } + if (path[i] == ':') + { + new_path = Alloc(i + 3); + strncpy(new_path, path, i); + strcpy(new_path + i, ":."); + return new_path; + } + } + + new_path = strdup("."); + return new_path; +} + + +//--------------------------------------------------------------------------- +// Get Filename +//--------------------------------------------------------------------------- + +char *GetFileName(const char *path) +{ + int i; + char *new_file; + + for (i = strlen(path) - 1; i >= 0; i--) + { + if (path[i] == '/' || path[i] == ':') + { + new_file = strdup(path + i + 1); + return new_file; + } + } + new_file = strdup(path); + return new_file; +} + + +//--------------------------------------------------------------------------- +// Reconstruct path name +// +// - Resolve '.' or '..' in path name +// - Work around . and / to translate regular form +// +// Regular form of path: +// Absolute Path [Drive:]/.[/Entry...] +// Relative Path [Drive:].[/Entry]... +// +// ex) +// abc/def -> ./abc/def +// /aaa -> /./aaa +// D:/aaa -> D:/./aaa +// / -> /. +// . -> . +// ../aa -> ./../aa +//--------------------------------------------------------------------------- + +char *PathNormalize(const char *pathName, BOOL isTreatDotDot) +{ + int i, level, level_root, n; + BOOL isAbsolute; + const char *entry[DIRLEVEL_MAX]; + + char *pathNormal = Alloc(strlen(pathName) + 4); + const char *p_org; + char *p_new; + + // + // Check if drive letter C: D: E: + // Check if absolute path + // + p_new = pathNormal; + p_org = SkipDriveName(pathName); + n = (int)p_org - (int)pathName; + + if (n > 0) + { + strncpy(p_new, pathName, n); + p_new += n; + } + isAbsolute = isAbsolutePath(p_org); + + // + // Resolve '.' and '..' + // + // Slice the path at point of / , put them into entry[] + // + + level = level_root = 0; + + for (; p_org; p_org = PathGetDirLevelDown(p_org)) + { + if (!PathCmp(p_org, "") || !PathCmp(p_org, ".")) + { + // skip it + continue; + } + else if (!PathCmp(p_org, "..") && isTreatDotDot) + { + if (level > level_root) + { + // Back to parent dir + level--; + continue; + } + + // if pathname starts with '/', no directory to go up + if (isAbsolute) + { + error("Can't go up directory, '..' Ignored. %s", pathName); + continue; + } + + // keep '..' + level_root = level + 1; + } + + // name entry + entry[level] = p_org; + level++; + } + + // Reconstruct pathname + if (isAbsolute) + { + *p_new++ = '/'; + } + *p_new++ = '.'; + + for (i = 0; i < level; i++) + { + *p_new++ = '/'; + p_new = PathCpy(p_new, entry[i]); + } + *p_new = '\0'; + +#if 0 + if (strcmp(pathNormal, pathName)) + { + debug_printf(" PathNormal: [%s] -> [%s]\n", pathName, pathNormal); + } +#endif + return pathNormal; +} + + +//--------------------------------------------------------------------------- +// Get Src Path +// Normalize BASENAME +// Normalize FILENAME +// Concat both +//--------------------------------------------------------------------------- + +char *GetSrcPath(const char *baseName, const char *fileName) +{ + char *base; + char *file; + char *t; + char *path; + + base = PathNormalize(baseName, TRUE); + file = PathNormalize(fileName, TRUE); + t = Alloc(strlen(base) + strlen(file) + 2); + + // Concat base + '/' + file + sprintf(t, "%s/%s", base, file); + path = PathNormalize(t, FALSE); + + free(base); + free(file); + free(t); + + debug_printf(" GetSrcPath: [%s]\n", path); + return path; +} + + +//--------------------------------------------------------------------------- +// Get Dest Path +// Concat BASENAME + FILENAME +// Normalize it +//--------------------------------------------------------------------------- + +char *GetDestPath(const char *baseName, const char *fileName) +{ + char *t; + char *path; + + t = Alloc(strlen(baseName) + strlen(fileName) + 2); + + // Concat base + '/' + file + sprintf(t, "%s/%s", baseName, fileName); + path = PathNormalize(t, TRUE); + + free(t); + + debug_printf(" GetDestPath: [%s]\n", path); + return path; +} + + +//--------------------------------------------------------------------------- +// Remake the path into familier shape +// Delete ./ +//--------------------------------------------------------------------------- + +char *PathDenormalize(char *path) +{ + char *p; + + p = (char *)SkipDriveName(path); + if (*p == '/') + { + p++; + } + + // Cut './' + if (*p == '.' && *(p + 1) == '/') + { + while ('\0' != (*p = *(p + 2))) + { + p++; + } + + if (p == path) + { + + } + } + + + + return path; +} + + +//--------------------------------------------------------------------------- +// Get PC Path +//--------------------------------------------------------------------------- + +char *GetWin32Path(char *cygpath) +{ + static char buffer[FILENAME_MAX]; + +#ifdef __CYGWIN__ + if (*cygpath == '/') + { + cygwin_conv_to_win32_path(cygpath, buffer); + } + else +#endif + { + strcpy(buffer, cygpath); + } + + return ChangeBackSlash(buffer); +} + +char *ChangeWin32Path(char *cygpath) +{ + char *win32path = strdup(GetWin32Path(cygpath)); + + free(cygpath); + return win32path; +} + +//--------------------------------------------------------------------------- +// Change suffix +//--------------------------------------------------------------------------- +char *ChangeSuffix(const char *file, const char *suffix) +{ + int i, n; + char *path; + + n = strlen(file); + + for (i = n; file[i] != '.'; i--) + { + if (file[i] == '/' || i == 0) + { + i = n; + break; + } + } + + path = Alloc(i + strlen(suffix) + 1); + strncpy(path, file, i); + strcpy(path + i, suffix); + + return path; +} + + +//--------------------------------------------------------------------------- +// Get Current Dir +//--------------------------------------------------------------------------- + +char *GetCurrentDirectory(void) +{ + static char buffer[FILENAME_MAX]; + char *cwd; + + cwd = getcwd(buffer, FILENAME_MAX); + if (!cwd) + { + error("Can't access current directory"); + exit(10); + } + return cwd; +} + + +//--------------------------------------------------------------------------- +// Check if absolute path +// +// Return True in case of ... +// +// /dirA/dirB/fileC +// D:/dirA/dirB/fileC +// +// Return False in case of ... +// +// dirX/dirY/fileZ +// D:dirX/dirY/fileZ +//--------------------------------------------------------------------------- + +BOOL isAbsolutePath(const char *path) +{ + const char *p = path; + + while (*p != '\0') + { + if (*p == '/' || *p == '\\') + { + if (p == path || p[-1] == ':') + { + return TRUE; + } + } + p++; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +// Check if drive name +// +// Return next character of ':' if drive name +// Return head of path if no drive name +//--------------------------------------------------------------------------- + +const char *SkipDriveName(const char *path) +{ + const char *p = path; + + while (*p != '\0' && *p != '/' && *p != '\\') + { + if (*p == ':') + { + return p + 1; + } + p++; + } + return path; +} + + +//--------------------------------------------------------------------------- +// App Name Utilities +//--------------------------------------------------------------------------- +static char *appName; +static char *appBaseName; +static char *appFileName; + +void InitAppName(const char *path) +{ + char *slash_path = ChangeBackSlash(strdup(path)); + + appBaseName = GetBaseName(slash_path); + appFileName = GetFileName(slash_path); + appName = ChangeSuffix(appFileName, ""); + + free(slash_path); +} + +char *GetAppName(void) +{ + return appName; +} + +char *GetAppBaseName(void) +{ + return appBaseName; +} + +char *GetAppFileName(void) +{ + return appFileName; +} + + +#ifdef TEST +int main(int argc, char *argv[]) +{ + int i; + char *s; + + for (i = 1; i < argc; i++) + { + s = PathNormalize(argv[i], TRUE); + printf("[%s] -> [%s]\n", argv[i], s); + free(s); + } + return 0; +} +#endif diff --git a/build/tools/makenandfirm/path.h b/build/tools/makenandfirm/path.h new file mode 100644 index 00000000..e9956dc6 --- /dev/null +++ b/build/tools/makenandfirm/path.h @@ -0,0 +1,93 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makebanner + File: path.h + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: path.h,v $ + Revision 1.3 2006/01/18 02:11:20 kitase_hirotake + do-indent + + Revision 1.2 2005/02/28 05:26:13 yosizaki + do-indent. + + Revision 1.1 2004/08/30 08:41:14 yasu + makebanner moves into CVS tree + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#ifndef PATH_H_ +#define PATH_H_ + +#include // struct tat +#include "misc.h" + +#define DIRLEVEL_MAX 256 +#ifndef FILENAME_MAX +#define FILENAME_MAX 1024 +#endif + +typedef enum +{ + FILESTATUS_ERROR = -1, + FILESTATUS_FILE = 0, + FILESTATUS_DIR = 1 +} +tFileStatus; + + +// Item Reject Control + +typedef struct tWildCard +{ + struct tWildCard *next; + char *name; + +} +tWildCard; + + +// CallBacks + +typedef BOOL (*tCallBack) (char *, void *); + + +// Prototypes + +tFileStatus GetFileStatus(struct stat *s, const char *filename); +BOOL ForeachEntry(const char *pathName, tWildCard * reject, tCallBack callBack, void *param); +BOOL ForeachFile(const char *baseName, const char *fileName, tWildCard * reject, + tCallBack callBack, void *param); +BOOL ForeachPathGlobbing(const char *pathName, tCallBack callBack, void *param); +BOOL ForeachDirList(const char *dirName, tCallBack callBack, void *param); +int PathCmp(const char *path, const char *cmp); +char *PathCpy(char *dest, const char *src); +int PathLen(const char *path); +char *PathDup(const char *src); +char *PathGetDirLevelDown(const char *path); +char *GetBaseName(const char *path); +char *GetFileName(const char *path); +BOOL WildCardCmp(const char *wildcard, const char *path); +BOOL isPathWildCard(const char *path); +char *PathNormalize(const char *pathName, BOOL isTreatDotDot); +char *PathDenormalize(char *path); +char *GetSrcPath(const char *base, const char *file); +char *GetDestPath(const char *base, const char *file); +char *GetWin32Path(char *cygpath); +char *ChangeWin32Path(char *cygpath); +char *ChangeSuffix(const char *file, const char *suffix); +char *GetCurrentDirectory(void); +BOOL isAbsolutePath(const char *path); +const char *SkipDriveName(const char *path); +void InitAppName(const char *path); +char *GetAppName(void); +char *GetAppBaseName(void); +char *GetAppFileName(void); + +#endif //PATH_H_ diff --git a/build/tools/makenandfirm/test/Makefile b/build/tools/makenandfirm/test/Makefile new file mode 100644 index 00000000..7ed88947 --- /dev/null +++ b/build/tools/makenandfirm/test/Makefile @@ -0,0 +1,56 @@ +#! make -f +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makenandfirm +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#--------------------------------------------------------------------------- + +SUBDIRS = wram_rbin \ + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +MAKENANDFIRM = ../makenandfirm.exe + +MAKEFIRM_ARM9 = ./twl_nandfirm9_print.axf +MAKEFIRM_ARM7 = ./twl_nandfirm7_print.axf +SDEPENDS_BIN += $(MAKEFIRM_ARM9) $(MAKEFIRM_ARM7) +MAKEFIRM_FLAGS += -d +MAKEFIRM_DEFS += -DFIRM_ROOT='$(FIRM_ROOT)' \ + -DMAKEFIRM_ARM9='$(basename $(MAKEFIRM_ARM9))' \ + -DMAKEFIRM_ARM7='$(basename $(MAKEFIRM_ARM7))' \ + -DMAKEFIRM_RSA_PRVKEY='$(MAKEFIRM_RSA_PRVKEY)' \ + +TARGET = test.srl + +%.srl: %.nandsf $(MAKENANDFIRM) + $(MAKENANDFIRM) $(MAKEFIRM_FLAGS) $(MAKEFIRM_DEFS) $< $@ + +.PHONY: build install do-autotest clean clobber + +define ECHO_CURDIR + echo "==== $(CURDIR)"; +endef + +build: + @$(ECHO_CURDIR) + @$(MAKE) $(TARGET) + +install do-autotest: + @$(ECHO_CURDIR) + +clean clobber super-clobber: + @$(ECHO_CURDIR) + -rm -f $(TARGET) *~ + +test-utf16.bsf: icon.nbfc icon.nbfp diff --git a/build/tools/makenandfirm/test/rsa_private.der b/build/tools/makenandfirm/test/rsa_private.der new file mode 100644 index 00000000..06f5f4cc Binary files /dev/null and b/build/tools/makenandfirm/test/rsa_private.der differ diff --git a/build/tools/makenandfirm/test/test.nandsf b/build/tools/makenandfirm/test/test.nandsf new file mode 100644 index 00000000..545d66cd --- /dev/null +++ b/build/tools/makenandfirm/test/test.nandsf @@ -0,0 +1,28 @@ +#NANDSF --- Nandfirm Spec File + +VERSION : 0x0 # GENERATE + +RSA_KEY : rsa_private.der +OUT_KEY : rsa_public.sbin + +WRAM_RBIN: ./wram_rbin/wram_regs.rbin + +DECOMP_PROC : ARM9 # ARM9 or ARM7 + +MIRROR_OFS : 0xc000 # 0x8000 is too small + +ARM9_COMP : TRUE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).sbin +ARM9_ELF : $(MAKEFIRM_ARM9).axf + +ARM7_COMP : FALSE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).sbin +ARM7_ELF : $(MAKEFIRM_ARM7).axf + +ARM9_X2 : TRUE # TRUE or FALSE + +ENC_KEYINFO : 0x5043414d # 'MACP' +NCD_ROMOFS : 0x07fe00 + +ERROR : ARM7_HASH # SIGN, HEADER_HASH, ARM9_HASH, ARM7_HASH, HASH_TABLE_HASH or FINAL_HASH +ERROR : HEADER_FOOTER # for debug diff --git a/build/tools/makenandfirm/test/twl_nandfirm7_print.axf b/build/tools/makenandfirm/test/twl_nandfirm7_print.axf new file mode 100644 index 00000000..b255bd21 Binary files /dev/null and b/build/tools/makenandfirm/test/twl_nandfirm7_print.axf differ diff --git a/build/tools/makenandfirm/test/twl_nandfirm7_print.sbin b/build/tools/makenandfirm/test/twl_nandfirm7_print.sbin new file mode 100644 index 00000000..a4eeebce Binary files /dev/null and b/build/tools/makenandfirm/test/twl_nandfirm7_print.sbin differ diff --git a/build/tools/makenandfirm/test/twl_nandfirm9_print.axf b/build/tools/makenandfirm/test/twl_nandfirm9_print.axf new file mode 100644 index 00000000..3d064b38 Binary files /dev/null and b/build/tools/makenandfirm/test/twl_nandfirm9_print.axf differ diff --git a/build/tools/makenandfirm/test/twl_nandfirm9_print.sbin b/build/tools/makenandfirm/test/twl_nandfirm9_print.sbin new file mode 100644 index 00000000..cd305be4 Binary files /dev/null and b/build/tools/makenandfirm/test/twl_nandfirm9_print.sbin differ diff --git a/build/tools/makenandfirm/test/wram_rbin/Makefile b/build/tools/makenandfirm/test/wram_rbin/Makefile new file mode 100644 index 00000000..63e58e5b --- /dev/null +++ b/build/tools/makenandfirm/test/wram_rbin/Makefile @@ -0,0 +1,48 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - nandfirm-print +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tools/makenandfirm/test/wram_rbin/wram_regs.c b/build/tools/makenandfirm/test/wram_rbin/wram_regs.c new file mode 100644 index 00000000..88332abb --- /dev/null +++ b/build/tools/makenandfirm/test/wram_rbin/wram_regs.c @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenandfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs = +{ + // ARM9 + { + REG_WRAM_A_BNK_PACK(0, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_0KB, TRUE), + REG_WRAM_A_BNK_PACK(1, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_64KB, TRUE), + REG_WRAM_A_BNK_PACK(2, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_128KB, TRUE), + REG_WRAM_A_BNK_PACK(3, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_192KB, TRUE), + }, + { + REG_WRAM_B_BNK_PACK(0, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_0KB, TRUE), + REG_WRAM_B_BNK_PACK(1, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_32KB, TRUE), + REG_WRAM_B_BNK_PACK(2, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_64KB, TRUE), + REG_WRAM_B_BNK_PACK(3, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_96KB, TRUE), + REG_WRAM_B_BNK_PACK(4, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_128KB, TRUE), + REG_WRAM_B_BNK_PACK(5, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_160KB, TRUE), + REG_WRAM_B_BNK_PACK(6, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_192KB, TRUE), + REG_WRAM_B_BNK_PACK(7, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_224KB, TRUE), + }, + { + REG_WRAM_C_BNK_PACK(0, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_0KB, TRUE), + REG_WRAM_C_BNK_PACK(1, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_32KB, TRUE), + REG_WRAM_C_BNK_PACK(2, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_64KB, TRUE), + REG_WRAM_C_BNK_PACK(3, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_96KB, TRUE), + REG_WRAM_C_BNK_PACK(4, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_128KB, TRUE), + REG_WRAM_C_BNK_PACK(5, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_160KB, TRUE), + REG_WRAM_C_BNK_PACK(6, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_192KB, TRUE), + REG_WRAM_C_BNK_PACK(7, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_224KB, TRUE), + }, + REG_WRAM_A_MAP_PACK(MI_WRAM_MAP_NULL, + MI_WRAM_MAP_NULL, + MI_WRAM_A_IMG_128KB + ), + REG_WRAM_B_MAP_PACK(MI_WRAM_MAP_NULL, + MI_WRAM_MAP_NULL, + MI_WRAM_B_IMG_128KB + ), + REG_WRAM_C_MAP_PACK(HW_WRAM_AREA_HALF, + HW_WRAM_AREA_HALF + 0x00020000, + MI_WRAM_C_IMG_128KB + ), + + // ARM7 + REG_WRAM_A_MAP_PACK(HW_WRAM_AREA_HALF, + HW_WRAM_AREA_HALF + 0x00020000, + MI_WRAM_A_IMG_128KB + ), + REG_WRAM_B_MAP_PACK(HW_WRAM_AREA_HALF + 0x00020000, + HW_WRAM_AREA_HALF + 0x00040000, + MI_WRAM_B_IMG_128KB + ), + REG_WRAM_C_MAP_PACK(MI_WRAM_MAP_NULL, + MI_WRAM_MAP_NULL, + MI_WRAM_C_IMG_128KB + ), + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + MI_WRAM_ARM7_ALL, + + // VRAM-C + 7, + // VRAM-D + 7, +}; diff --git a/build/tools/makenandfirm/wram_regs.c b/build/tools/makenandfirm/wram_regs.c new file mode 100644 index 00000000..5f09a868 --- /dev/null +++ b/build/tools/makenandfirm/wram_regs.c @@ -0,0 +1,96 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenandfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include "format_rom.h" +//#define SDK_ASM +#define NITRO_TYPES_H_ +#include +#include +#include + + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM9 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF + 0x00020000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF + 0x00020000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA_HALF + 0x00040000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA_HALF + 0x00020000 ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/tools/makenorfirm/Makefile b/build/tools/makenorfirm/Makefile new file mode 100644 index 00000000..8f624c9e --- /dev/null +++ b/build/tools/makenorfirm/Makefile @@ -0,0 +1,151 @@ +#! make -f +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makenorfirm +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#--------------------------------------------------------------------------- + +TARGET_PLATFORM = TWL + +SUPPORT_ECC = 0 + +ifeq ($(SUPPORT_ECC),1) +ECC_SRCDIR = ../../libraries/acsign_ecc/common \ + ../../libraries/acsign_ecc/common/algae/common/ecc \ + ../../libraries/acsign_ecc/common/algae/cmp \ + ../../libraries/acsign_ecc/common/algae/ecsource \ + +ECC_INCDIR = ../../libraries/acsign_ecc/include \ + ../../libraries/acsign_ecc/common/algae/include \ + ../../libraries/acsign_ecc/common/algae/common/include \ + +ECC_SRCS = acsign_ecc.c acsign_cryptoc.c \ + \ + cmparith.c cmpbits.c cmpcnv.c cmpdiv.c cmpmem.c \ + cmpmod.c cmpmuldv.c cmpspprt.c cmpsqr.c cmpvectr.c \ + computem.c ecfpatbl.c ecfpsmul.c \ + spcprime.c secfpcom.c \ + \ + p224v1.c p224v1a.c \ + +ECC_DEFS = -DRSA_PROTOTYPES=RSA_ENABLED \ + -DRCOM_BUILD=RSA_ENABLED -DRSA_FAST_INVERSE=RSA_ENABLED \ + -DRSA_STD_MEM_FUNCS=RSA_ENABLED -DRSA_STD_ALLOC_FUNCS=RSA_ENABLED \ +else +ECC_SRCDIR = +ECC_INCDIR = +ECC_SRCS = +ECC_DEFS = +endif + +SRCDIR += ../acsign $(ECC_SRCDIR) +INCDIR += ../acsign/include $(ECC_INCDIR) $(ECC_SRCDIR) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +TARGETS = makenorfirm.exe + +SOURCES_C = makenorfirm.c \ + out_norfirm.c \ + misc.c \ + path.c \ + defval.c \ + compress.c \ + wram_regs.c \ + acsign.c \ + acsign_nor.c \ + aes2.c \ + $(ECC_SRCS) + +SOURCES = $(SORUCES_C) + +OBJECTS = $(SOURCES_C:.c=.o) + +HEADERS = format_nlist.h \ + makenorfirm.h \ + path.h \ + format_rom.h \ + misc.h \ + defval.h \ + compress.h \ + +MACROS += -DSMALL_CODE_SIZE \ + -DSTANDALONE \ + -DOPT_32_BIT \ + -DNO_SPLIT \ + -DNO_FP_API \ + -DNO_R_DIAG \ + $(ECC_DEFS) + +INSTALL_DIR = $(FIRM_INSTALL_TOOLSDIR)/bin +INSTALL_TARGETS = $(TARGETS) + +LDIRT_CLEAN = $(OBJECTS) $(TARGETS) version.h + + +VPATH = $(SRCDIR) +TWL_INCDIR := $(TWL_INCDIR) $(addprefix -I,$(INCDIR)) $(addprefix -I,$(FIRM_INCDIR)) + +include $(TWLSDK_ROOT)/build/buildtools/twl/modulerules.x86 + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): $(OBJECTS) + $(CC_X86) $+ -o $@ + +makenorfirm.o: makenorfirm.c makenorfirm.h format_rom.h path.h version.h +out_norfirm.o: out_norfirm.c misc.h format_rom.h format_nlist.h format_sign.h elf.h compress.h \ + $(FIRM_INCDIR)/firm/format/sign.h \ + $(FIRM_INCDIR)/firm/format/wram_regs.h \ + $(FIRM_INCDIR)/firm/format/norfirm.h \ + +misc.o: misc.c misc.h +path.o: path.c path.h +compress.o: compress.c compress.h +wram_regs.o: wram_regs.c +acsign.o: acsign.c ../acsign/include/acsign.h +acsign_nor.o: acsign_nor.c format_sign.h \ + $(FIRM_INCDIR)/firm/format/sign.h \ + $(FIRM_INCDIR)/firm/format/wram_regs.h \ + $(FIRM_INCDIR)/firm/format/norfirm.h \ + +aes2.o: aes2.c aes2.h + +$(FIRM_INCDIR)/firm/format/sign.h: +$(FIRM_INCDIR)/firm/format/wram_regs.h: +$(FIRM_INCDIR)/firm/format/norfirm.h: +format_nlist.h: +format_rom.h: +makenorfirm.h: +acsign.h: +acsign_nor.h: +path.h: + +# avoid to warning message +misc.o:WARNING += -Wno-format-y2k + +# + +version.h: $(SOURCES) $(HEADERS) + @for i in $^ ; \ + do \ + date -r $$i +'#define SDK_DATE_OF_LATEST_FILE %Y%m%dUL'; \ + done | sort | tail -1 > $@ + +test: path.c misc.c + $(CC_X86) -DTEST $+ -o $@ diff --git a/build/tools/makenorfirm/compress.c b/build/tools/makenorfirm/compress.c new file mode 100644 index 00000000..0d7a555d --- /dev/null +++ b/build/tools/makenorfirm/compress.c @@ -0,0 +1,293 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: compress.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:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include // atoi() +#include // strcmp() +#include // isprint() +#include // chdir() +#include +#include // UCHAR_MAX +#include +#include // stat() +#include "elf.h" +#include "misc.h" +#include "defval.h" +#include "format_rom.h" +#include "format_nlist.h" +#include "makenorfirm.h" + +//#define ADD_HEADER + +#define DIFF_CODE_HEADER (0x80) +#define RL_CODE_HEADER (0x30) +#define LZ_CODE_HEADER (0x10) +#define HUFF_CODE_HEADER (0x20) +#define CODE_HEADER_MASK (0xF0) + +//=========================================================================== +// LZ77k +//=========================================================================== +static u8 SearchLZ(const u8 *nextp, u32 remainSize, u16 *offset); + +static u16 windowPos; +static u16 windowLen; + +static s16 LZOffsetTable[4096]; +static s16 LZByteTable[256]; +static s16 LZEndTable[256]; + + +static void LZInitTable(void) +{ + u16 i; + + for (i = 0; i < 256; i++) + { + LZByteTable[i] = -1; + LZEndTable[i] = -1; + } + windowPos = 0; + windowLen = 0; +} + +static void SlideByte(const u8 *srcp) +{ + s16 offset; + u8 in_data = *srcp; + u16 insert_offset; + + if (windowLen == 4096) + { + u8 out_data = *(srcp - 4096); + if ((LZByteTable[out_data] = LZOffsetTable[LZByteTable[out_data]]) == -1) + { + LZEndTable[out_data] = -1; + } + insert_offset = windowPos; + } + else + { + insert_offset = windowLen; + } + + offset = LZEndTable[in_data]; + if (offset == -1) + { + LZByteTable[in_data] = insert_offset; + } + else + { + LZOffsetTable[offset] = insert_offset; + } + LZEndTable[in_data] = insert_offset; + LZOffsetTable[insert_offset] = -1; + + if (windowLen == 4096) + { + windowPos = (u16)((windowPos + 1) % 0x1000); + } + else + { + windowLen++; + } +} + +static void LZSlide(const u8 *srcp, u32 n) +{ + u32 i; + + for (i = 0; i < n; i++) + { + SlideByte(srcp++); + } +} + +/*---------------------------------------------------------------------------* + Name: MI_CompressLZ + + Description: LZ77ksȂ֐ + + Arguments: srcp kf[^ւ̃|C^ + size kf[^TCY + dstp kf[^ւ̃|C^ + kf[^傫TCỸobt@KvłB + + Returns: k̃f[^TCYB + k̃f[^kO傫Ȃꍇɂ͈k𒆒f0Ԃ܂B + *---------------------------------------------------------------------------*/ +u32 LZCompWrite(u8 *srcp, u32 size, u8 *dstp, int boundary) +{ + u32 LZDstCount; // kf[^̃oCg + u8 LZCompFlags; // k̗LtOn + u8 *LZCompFlagsp; // LZCompFlags i[郁̈|Cg + u16 lastOffset; // vf[^܂ł̃ItZbg (̎_ł̍Œvf[^) + u8 lastLength; // vf[^ (̎_ł̍Œvf[^) + u8 i; + u32 dstMax; + +#ifdef ADD_HEADER + *(u32 *)dstp = size << 8 | LZ_CODE_HEADER; // f[^Ewb_ + dstp += 4; +#endif + LZDstCount = 4; + dstMax = size; + LZInitTable(); + + while (size > 0) + { + LZCompFlags = 0; + LZCompFlagsp = dstp++; // tOn̊i[ + LZDstCount++; + + // tOn8rbgf[^ƂĊi[邽߁A8񃋁[v + for (i = 0; i < 8; i++) + { + LZCompFlags <<= 1; // (i=0) ͓ɈӖ͂Ȃ + if (size <= 0) + { + // I[ɗꍇ̓tOŌ܂ŃVtgĂI + continue; + } + + if ((lastLength = SearchLZ(srcp, size, &lastOffset))) + { + // k”\ȏꍇ̓tO𗧂Ă + LZCompFlags |= 0x1; + + // ItZbg͏4rbgƉ8rbgɕĊi[ + *dstp++ = (u8)((lastLength - 3) << 4 | (lastOffset - 1) >> 8); + *dstp++ = (u8)((lastOffset - 1) & 0xff); + LZDstCount += 2; + LZSlide(srcp, lastLength); + srcp += lastLength; + size -= lastLength; + } + else + { + // kȂ + LZSlide(srcp, 1); + *dstp++ = *srcp++; + size--; + LZDstCount++; + } + } // 8񃋁[vI + *LZCompFlagsp = LZCompFlags; // tOni[ + } + + // 16oCgEACg + // ACgpf[^0 ̓f[^TCYɊ܂߂ + i = 0; + while (LZDstCount & (boundary - 1)) +// while ((LZDstCount + i) & 0x3) + { + *dstp++ = 0; + LZDstCount++; + i++; + } + + return LZDstCount; +} + +//-------------------------------------------------------- +// LZ77kŃXCh̒Œv܂B +// Arguments: startp f[^̊Jnʒu|C^ +// nextp Jnf[^̃|C^ +// remainSize cf[^TCY +// offset vItZbgi[̈ւ̃|C^ +// Return : v񂪌‚ꍇ TRUE +// ‚Ȃꍇ FALSE +//-------------------------------------------------------- +static u8 SearchLZ(const u8 *nextp, u32 remainSize, u16 *offset) +{ + const u8 *searchp; + const u8 *headp, *searchHeadp; + u16 maxOffset; + u8 maxLength = 2; + u8 tmpLength; + s32 w_offset; + + if (remainSize < 3) + { + return 0; + } + + w_offset = LZByteTable[*nextp]; + + while (w_offset != -1) + { + if (w_offset < windowPos) + { + searchp = nextp - windowPos + w_offset; + } + else + { + searchp = nextp - windowLen - windowPos + w_offset; + } + + /* ĂǂA͂ɍ */ + if (*(searchp + 1) != *(nextp + 1) || *(searchp + 2) != *(nextp + 2)) + { + w_offset = LZOffsetTable[w_offset]; + continue; + } + + if (nextp - searchp < 2) + { + // VRAM2oCgANZXȂ̂ (VRAMf[^ǂݏoꍇ邽)A + // Ώۃf[^2oCgÕf[^ɂȂ΂ȂȂB + // + // ItZbg12rbgŊi[邽߁A4096ȉ + break; + } + tmpLength = 3; + searchHeadp = searchp + 3; + headp = nextp + 3; + + while (((u32)(headp - nextp) < remainSize) && (*headp == *searchHeadp)) + { + headp++; + searchHeadp++; + tmpLength++; + + // f[^4rbgŊi[邽߁A18ȉ (3̉ʂ͂) + if (tmpLength == (0xF + 3)) + { + break; + } + } + if (tmpLength > maxLength) + { + // ő咷ItZbgXV + maxLength = tmpLength; + maxOffset = (u16)(nextp - searchp); + if (maxLength == (0xF + 3)) + { + // vőȂ̂ŁAIB + break; + } + } + w_offset = LZOffsetTable[w_offset]; + } + + if (maxLength < 3) + { + return 0; + } + *offset = maxOffset; + return maxLength; +} + diff --git a/build/tools/makenorfirm/compress.h b/build/tools/makenorfirm/compress.h new file mode 100644 index 00000000..e3dc58f0 --- /dev/null +++ b/build/tools/makenorfirm/compress.h @@ -0,0 +1,38 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: compress.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 COMPRESS_H_ +#define COMPRESS_H_ + +#include "misc.h" + + +/*---------------------------------------------------------------------------* + Name: MI_CompressLZ + + Description: LZ77ksȂ֐ + + Arguments: srcp kf[^ւ̃|C^ + size kf[^TCY + dstp kf[^ւ̃|C^ + kf[^傫TCỸobt@KvłB + + Returns: k̃f[^TCYB + *---------------------------------------------------------------------------*/ +u32 LZCompWrite(u8 *srcp, u32 size, u8 *dstp, int boundary); + + +#endif //COMPRESS_H_ diff --git a/build/tools/makenorfirm/defval.c b/build/tools/makenorfirm/defval.c new file mode 100644 index 00000000..679fb0e6 --- /dev/null +++ b/build/tools/makenorfirm/defval.c @@ -0,0 +1,315 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makerom + File: defval.c + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: defval.c,v $ + Revision 1.10 2006/01/18 02:11:19 kitase_hirotake + do-indent + + Revision 1.9 2005/02/28 05:26:03 yosizaki + do-indent. + + Revision 1.8 2004/08/05 13:50:13 yasu + Support -M option + + Revision 1.7 2004/06/29 04:55:40 yasu + Use VBuffer to resolve variables + + Revision 1.6 2004/06/23 07:51:02 yasu + fix a bug as illegal memory freeing at ResolveDefVal() + + Revision 1.5 2004/05/27 00:40:49 yasu + care also about current directory (dot ".") + + Revision 1.4 2004/05/27 00:25:46 yasu + care about double-dots ".." for defvalue option :r, :e + + Revision 1.3 2004/05/27 00:11:19 yasu + fix a error when searching a "dot" of file extension + + Revision 1.2 2004/05/26 12:02:47 yasu + support :h, :t, :r, :e option for variable name + + Revision 1.1 2004/03/26 05:06:45 yasu + support variables like as -DNAME=VALUE + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include // getenv() +#include // strcasecmp() +#include // getopt() +#include "misc.h" +#include "defval.h" + +typedef struct tValdef +{ + struct tValdef *next; + char *name; + char *value; +} +tValdef; + +tValdef *valdef_top = NULL; + + +// +// Add new define value via file +// +// opt : "DEFINE=VALUE" +// +BOOL AddDefValFromFile(char *filename) +{ + char *buffer; + int buffer_size; + int read_size; + FILE *fp; + + if (filename[0] == '-' && filename[1] == '\0') + { + fp = stdin; + } + else if (NULL == (fp = fopen(filename, "rb"))) + { + fprintf(stderr, "Cannot open file \"%s\".\n", filename); + return FALSE; + } + + buffer_size = DEFVAL_DEFAULT_BUFFER_SIZE; + + if (NULL == (buffer = malloc(buffer_size))) + { + fprintf(stderr, "Cannot allocate memory.\n"); + return FALSE; + } + + read_size = 0; + + while (NULL != fgets(buffer + read_size, buffer_size - read_size, fp)) + { + read_size = strlen(buffer); + + if (read_size == buffer_size - 1 && buffer[read_size - 1] != '\n') + { + buffer_size *= 2; + + if (NULL == (buffer = realloc(buffer, buffer_size))) + { + fprintf(stderr, "Cannot allocate memory.\n"); + return FALSE; + } + continue; + } + + AddDefVal(buffer); + read_size = 0; + } + + if (fp != stdin) + { + fclose(fp); + } + free(buffer); + + return TRUE; +} + + +// +// Add new define value +// +// opt : "DEFINE=VALUE" +// +void AddDefVal(char *opt) +{ + int i; + tValdef *t; + + for (i = 0;; i++) + { + if ('=' == opt[i] || '\0' == opt[i]) + { + break; + } + } + + if (i > 0) + { + t = Alloc(sizeof(tValdef)); + t->name = strncpy(Alloc(i + 1), opt, i); + t->name[i] = '\0'; + + if (opt[i] == '=') + { + i++; + } + t->value = strdup(opt + i); + + t->next = valdef_top; + valdef_top = t; + + debug_printf("DEFINE:$(%s)=\"%s\"\n", t->name, t->value); + } + return; +} + +// +// Search define value +// +// Return: value of specified name +// +char *SearchDefVal(char *name) +{ + tValdef *t; + + for (t = valdef_top; t; t = t->next) + { + if (!strcmp(t->name, name)) + { + return t->value; + } + } + + return getenv(name); +} + + +// +// Search define value and Modify it by : option +// +// Return: duplicated value of specified name modified by :x option +// +char *SearchDefValWithOption(char *name) +{ + int len_name = strlen(name); + char *value; + char option = '\0'; + + if (len_name > 2 && name[len_name - 2] == ':') + { + name[len_name - 2] = '\0'; + option = name[len_name - 1]; + } + + value = SearchDefVal(name); + + if (value) + { + int value_len = strlen(value); + int col_dot = value_len; + int col_filename = 0; + int i; + + for (i = 0; i < value_len; i++) + { + switch (value[i]) + { + case '.': + if (col_filename == i && + (value[i + 1] == '\0' || (value[i + 1] == '.' && value[i + 2] == '\0'))) + { + i = value_len; // exit loop if last entry is . or .. + } + else + { + col_dot = i; // Save the last dot column + } + break; + + case '/': + case '\\': + case ':': + col_filename = i + 1; // Save the last filename + col_dot = value_len; // Reset dot position + break; + + default: + ; + } + } + + switch (option) + { + case 'h': // Dirname with the last slash + value = strdup(value); + value[col_filename] = '\0'; + break; + + case 't': // Filename + value = strdup(value + col_filename); + break; + + case 'r': // All without . file extension + value = strdup(value); + value[col_dot] = '\0'; + break; + + case 'e': // File extension + value = strdup(value + col_dot + 1); + break; + + default: + value = strdup(value); + } + } + return value; +} + + +// +// Resolve define value +// +// Return: new string +// +char *ResolveDefVal(char *str) +{ + int i, j; + char *val; + VBuffer buf; + + InitVBuffer(&buf); + + for (i = 0; '\0' != str[i]; i++) + { + // search $(XXX) + if ('$' == str[i] && '(' == str[i + 1]) + { + for (j = i + 2; '\0' != str[j]; j++) + { + if (')' == str[j]) + { + str[j] = '\0'; + + // get value of XXX + val = SearchDefValWithOption(&str[i + 2]); + + // copy value of XXX + if (val) + { + char *s = val; + + while (*s) + { + PutVBuffer(&buf, *s); + s++; + } + free(val); + } + i = j; + goto next; + } + } + } + PutVBuffer(&buf, str[i]); + next:; + } + return GetVBuffer(&buf); // pass allocated buffer, should be freed by caller +} diff --git a/build/tools/makenorfirm/defval.h b/build/tools/makenorfirm/defval.h new file mode 100644 index 00000000..71355101 --- /dev/null +++ b/build/tools/makenorfirm/defval.h @@ -0,0 +1,38 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makerom + File: defval.h + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: defval.h,v $ + Revision 1.4 2006/01/18 02:11:19 kitase_hirotake + do-indent + + Revision 1.3 2005/02/28 05:26:03 yosizaki + do-indent. + + Revision 1.2 2004/08/05 13:50:13 yasu + Support -M option + + Revision 1.1 2004/03/26 05:06:45 yasu + support variables like as -DNAME=VALUE + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#ifndef DEFVAL_H_ +#define DEFVAL_H_ + +#define DEFVAL_DEFAULT_BUFFER_SIZE (1024) + +BOOL AddDefValFromFile(char *filename); +void AddDefVal(char *opt); +char *SearchDefVal(char *name); +char *ResolveDefVal(char *str); + +#endif //DEFVAL_H_ diff --git a/build/tools/makenorfirm/elf.h b/build/tools/makenorfirm/elf.h new file mode 100644 index 00000000..c360cd33 --- /dev/null +++ b/build/tools/makenorfirm/elf.h @@ -0,0 +1,431 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - ELF + File: elf.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. + *---------------------------------------------------------------------------*/ + +#ifndef ELF_H_ +#define ELF_H_ + +#include "misc.h" + +/*--------------------------------------------------------- + ^` + --------------------------------------------------------*/ +typedef u32 Elf32_Addr; /* size:4, align:4 Unsigned program address */ +typedef u16 Elf32_Half; /* size:2, align:2 Unsigned medium int */ +typedef u32 Elf32_Off; /* size:4, align:4 Unsigned file offset */ +typedef s32 Elf32_Sword; /* size:4, align:4 Signed large int */ +typedef u32 Elf32_Word; /* size:4, align:4 Unsigned large int */ + +/*--------------------------------------------------------- + ELF Header + --------------------------------------------------------*/ +/* e_ident̃CfbNX */ +#define EI_MAG0 0 /* File identification */ +#define EI_MAG1 1 /* File identification */ +#define EI_MAG2 2 /* File identification */ +#define EI_MAG3 3 /* File identification */ +#define EI_CLASS 4 /* File class 0=invalid, 1=32bit, 2=64bit */ +#define EI_DATA 5 /* Data encoding 0=invalid, 1=LSB, 2=MSB */ +#define EI_VERSION 6 /* File version ݂1 */ +#define EI_PAD 7 /* Start of padding bytes */ +#define EI_NIDENT 16 /* Size of e_ident[] */ + +typedef struct { + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; /* ELF̌`(Ĕzu”\, s”\Ȃ) */ + Elf32_Half e_machine; /* t@CŗvA[LeN` */ + Elf32_Word e_version; /* ELFtH[}bg̃o[Wi݂1j */ + Elf32_Addr e_entry; /* vÕGg|CgBw薳Ȃ0B */ + Elf32_Off e_phoff; /* vOwb_e[ũt@C擪̃ItZbg */ + Elf32_Off e_shoff; /* ZNVwb_e[ũt@C擪̃ItZbg */ + Elf32_Word e_flags; /* vZbTŗL̃tO */ + Elf32_Half e_ehsize; /* ELFwb_̃TCY */ + Elf32_Half e_phentsize; /* 1vOwb_̃TCY */ + Elf32_Half e_phnum; /* vOwb_̐ */ + Elf32_Half e_shentsize; /* 1ZNVwb_̃TCY */ + Elf32_Half e_shnum; /* ZNVwb_̐ */ + Elf32_Half e_shstrndx; /* ZNVe[uZNVւ̃CfbNX */ +} Elf32_Ehdr; + +/* e_ident[EI_*]̒g` */ +#define ELFMAG0 0x7f +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFCLASSNONE 0 /* invalid */ +#define ELFCLASS32 1 /* ARM and Thumb processors use 32-bit ELF. */ +#define ELFCLASS64 2 +#define ELFDATANONE 0 /* invalid */ +#define ELFDATA2LSB 1 /* little-endian */ +#define ELFDATA2MSB 2 /* big-endian */ + + +/* [e_type] */ +#define ET_NONE 0 /* No file type */ +#define ET_REL 1 /* Re-locatable file */ +#define ET_EXEC 2 /* Executable file */ +#define ET_DYN 3 /* Shared object file */ +#define ET_CORE 4 /* Core file */ +#define ET_LOPROC 0xff00 /* Processor-specific */ +#define ET_HIPROC 0xffff /* Processor-specific */ + +/* [e_machine] */ +#define EM_NONE 0 /* No machine */ +#define EM_M32 1 +#define EM_SPARC 2 +#define EM_386 3 +#define EM_68K 4 +#define EM_88K 5 +#define EM_860 7 +#define EM_MIPS 8 +#define EM_MIPS_RS4_BE 10 +#define EM_ARM 40 /* ARM/Thumb Architecture */ + + +/* [e_version] This member identifies the object file version.*/ +#define EV_NONE 0 /* Invalid version */ +#define EV_CURRENT 1 /* Current version */ + + +/* + ARM-specific e_flags + e_flags Field Value Meaning + EF_ARM_HASENTRY (0x02) e_entry contains a program-loader entry point + (see section 4.1.1, Entry points, below). + EF_ARM_SYMSARESORTED (0x04) Each subsection of the symbol table is sorted by symbol value + (see section 4.4.8, Symbol table order, below) + EF_ARM_DYNSYMSUSESEGIDX (0x8) Symbols in dynamic symbol tables that are defined in sections + included in program segment n have st_shndx = n + 1. + (see section 4.4.9, Dynamic symbol table entries, below). + EF_ARM_MAPSYMSFIRST (0x10) Mapping symbols precede other local symbols in the symbol table + (see section 4.4.8, Symbol table order, below). + + EF_ARM_EABIMASK (0xFF000000)(current version is 0x02000000) + This masks an 8-bit version number, the version of the ARM + EABI to which this ELF file conforms. This EABI is version 2. A + value of 0 denotes unknown conformance. +*/ +#define EF_ARM_HASENTRY 0x02 +#define EF_ARM_SYMSARESORTED 0x04 +#define EF_ARM_DYNSYMSUSESEGIDX 0x8 +#define EF_ARM_MAPSYMSFIRST 0x10 +#define EF_ARM_EABIMASK 0xFF000000 + + +/*--------------------------------------------------------- + Program headers + --------------------------------------------------------*/ +typedef struct { + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; +} Elf32_Phdr; + +/* [p_type] */ +#define PT_NULL 0 /* gȂGgŁÃo̒l̈Ӗ͖` */ +#define PT_LOAD 1 /* sɃ[hZOg */ +#define PT_DYNAMIC 2 /* I\̔zێZOg */ +#define PT_INTERP 3 /* t@C̉߂ɎgC^v^̃pXێZOg */ +#define PT_NOTE 4 /* t@C̉߂ɂ͎gȂێZOg */ +#define PT_SHLIB 5 /* \ */ +#define PT_PHDR 6 /* vOwb_e[uivÕC[Ẅꕔłꍇ̂ݑ݁j */ +//#define PT_TLS ? /* XbhǏL̈̃ev[g */ + +#define PT_LOOS 0x60000000 /* OSŗLɗ\񂳂ꂽ̈ */ +#define PT_HIOS 0x6fffffff + +#define PT_LOPROC 0x70000000 /* vZbTŗLɗ\񂳂ꂽ̈ */ +#define PT_HIPROC 0x7fffffff + +/* [p_flags]*/ +#define PF_X 1 /*s”\*/ +#define PF_W 2 /*݉”\*/ +#define PF_R 4 /*ǂݏo”\*/ +#define PF_ARM_SB 0x10000000 /*The segment contains the location addressed by the static base*/ +#define PF_ARM_PI 0x20000000 /*The segment is position-independent*/ +#define PF_ARM_ENTRY 0x80000000 /*The segment contains the entry point*/ +#define PF_MASKPROC 0xf0000000 + + +/*--------------------------------------------------------- + Section headers + --------------------------------------------------------*/ +typedef struct { + Elf32_Word sh_name; /*ZNVwb_e[uZNṼCfbNX*/ + Elf32_Word sh_type; /* ^CviL`QƁj */ + Elf32_Word sh_flags; + Elf32_Addr sh_addr; /* */ + Elf32_Off sh_offset; /* t@C̐擪̃ItZbg */ + Elf32_Word sh_size; /* oCgPʂ̃TCY */ + Elf32_Word sh_link; /* sh_typeɂĒl̈Ӗς */ + Elf32_Word sh_info; /* sh_typeɂĒl̈Ӗς */ + Elf32_Word sh_addralign; /* ACg(0or1ŐȂ,44ByteAlign) */ + Elf32_Word sh_entsize; /* ŒTCỸGge[uꍇA1vf̃TCY */ +} Elf32_Shdr; + +/* sh_addr mod sh_addralign = 0 łȂ΂ȂȂ */ + +/* Section Types, [sh_type] */ +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xffffffff + + +/* [sh_flags] */ +#define SHF_WRITE 0x1 +#define SHF_ALLOC 0x2 +#define SHF_EXECINSTR 0x4 +#define SHF_MASKPROC 0xf0000000 +/* ARM-EABI-specific */ +#define SHF_ENTRYSECT 0x10000000 /* The section contains an entry point. */ +#define SHF_COMDEF 0x80000000 /* The section may be multiply defined in the input to a link step. */ +/* others */ +#define SHF_LINK_ORDER 0x80 + +/*ZNVCfbNX*/ +//Sym->st_shndxȂ +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_LOPROC 0xff00 +#define SHN_HIPROC 0xff1f +#define SHN_ABS 0xfff1 +#define SHN_COMMON 0xfff2 +#define SHN_HIRESERVE 0xffff + + +//̓wb_łȂ̃f[^\ + +/*--------------------------------------------------------- + Symbol Table Entry + --------------------------------------------------------*/ +typedef struct { + Elf32_Word st_name; /* V{e[ũCfbNX */ + Elf32_Addr st_value; /* 炭֘AZNVł̃ItZbgl */ + Elf32_Word st_size; /* TCYȂAsȏꍇ 0 */ + unsigned char st_info; /* oCh ^Cv */ + unsigned char st_other; /* ݂ 0 */ + Elf32_Half st_shndx; /* ֘AZNVwb_e[ũCfbNX */ +} Elf32_Sym; + + +/* st_info */ +#define ELF32_ST_BIND(i) ((i)>>4) +#define ELF32_ST_TYPE(i) ((i)&0xf) +#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) + +/* st_info BIND */ +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 +#define STB_LOPROC 13 +#define STB_HIPROC 15 + +/* st_info TYPE */ +#define STT_NOTYPE 0 /*`*/ +#define STT_OBJECT 1 /*f[^IuWFNg*/ +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 +#define STT_LOPROC 13 +#define STT_HIPROC 15 + + +/*--------------------------------------------------------- + Relocation Entry + --------------------------------------------------------*/ +typedef struct { + Elf32_Addr r_offset; + Elf32_Word r_info; +} Elf32_Rel; + +typedef struct { + Elf32_Addr r_offset; + Elf32_Word r_info; + Elf32_Sword r_addend; +} Elf32_Rela; + +#define ELF32_R_SYM(i) ((i)>>8) +#define ELF32_R_TYPE(i) ((unsigned char)(i)) +#define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t)) + + +/* r_info TYPE */ +#define R_ARM_NONE 0 /* Any No relocation. Encodes dependencies between sections. */ +#define R_ARM_PC24 1 /* ARM B/BL S . P + A */ +#define R_ARM_ABS32 2 /* 32-bit word S + A */ +#define R_ARM_REL32 3 /* 32-bit word S . P + A */ +#define R_ARM_PC13 4 /* ARM LDR r, [pc,c] S . P + A */ +#define R_ARM_ABS16 5 /* 16-bit half-word S + A */ +#define R_ARM_ABS12 6 /* ARM LDR/STR S + A */ +#define R_ARM_THM_ABS5 7 /* Thumb LDR/STR S + A */ +#define R_ARM_ABS8 8 /* 8-bit byte S + A */ +#define R_ARM_SBREL32 9 /* 32-bit word S . B + A */ +#define R_ARM_THM_PC22 10 /* Thumb BL pair S . P+ A */ +#define R_ARM_THM_PC8 11 /* Thumb LDR r, [pc,c] S . P + A */ +#define R_ARM_AMP_VCALL9 12 /* AMP VCALL Obsolete.SA-1500 only. */ +#define R_ARM_SWI24 13 /* ARM SWI S + A */ +#define R_ARM_THM_SWI8 14 /* Thumb SWI S + A */ +#define R_ARM_XPC25 15 /* ARM BLX S . P+ A */ +#define R_ARM_THM_XPC22 16 /* Thumb BLX pair S . P+ A */ + +/* 17-31, reserved to ARM Linux */ +//17-19 Reserved to ARM LINUX +#define R_ARM_COPY 20 /* 32 bit word Copy symbol at dynamic link time. */ +#define R_ARM_GLOB_DAT 21 /* 32 bit word Create GOT entry. */ +#define R_ARM_JUMP_SLOT 22 /* 32 bit word Create PLT entry. */ +#define R_ARM_RELATIVE 23 /* 32 bit word Adjust by program base. */ +#define R_ARM_GOTOFF 24 /* 32 bit word Offset relative to start of GOT. */ +#define R_ARM_GOTPC 25 /* 32 bit word Insert address of GOT. */ +#define R_ARM_GOT32 26 /* 32 bit word Entry in GOT. */ +#define R_ARM_PLT32 27 /* ARM BL Entry in PLT. */ + +/* 28-31 Reserved to ARM LINUX */ +#define R_ARM_ALU_PCREL_7_0 32 /* ARM ADD/SUB (S . P + A) & 0x000000FF */ +#define R_ARM_ALU_PCREL_15_8 33 /* ARM ADD/SUB (S . P + A) & 0x0000FF00 */ +#define R_ARM_ALU_PCREL_23_15 34 /* ARM ADD/SUB (S . P + A) & 0x00FF0000 */ +#define R_ARM_LDR_SBREL_11_0 35 /* ARM LDR/STR (S . B + A) & 0x00000FFF */ +#define R_ARM_ALU_SBREL_19_12 36 /* ARM ADD/SUB (S . B + A) & 0x000FF000 */ +#define R_ARM_ALU_SBREL_27_20 37 /* ARM ADD/SUB (S . B + A) & 0x0FF00000 */ + +#define R_ARM_TARGET1 38 +#define R_ARM_ROSEGREL32 39 +#define R_ARM_V4BX 40 +#define R_ARM_TARGET2 41 +#define R_ARM_PREL31 42 + +/* 96-111, reserved to ARM g++ */ +#define R_ARM_GNU_VTENTRY 100 /* 32 bit word Record C++ vtable entry. */ +#define R_ARM_GNU_VTINHERIT 101 /* 32 bit word Record C++ member usage. */ +#define R_ARM_THM_PC11 102 /* Thumb B S . P + A */ +#define R_ARM_THM_PC9 103 /* Thumb B S . P + A */ + +/* 112-127, reserved for private experiments */ + +/* 128-248, reserved to ARM */ +#define R_ARM_RXPC25 249 /* ARM BLX (S . P) + A #define For calls between program segments. */ +#define R_ARM_RSBREL32 250 /* Word (S . SB) + A For an offset from SB, the static base. */ +#define R_ARM_THM_RPC22 251 /* Thumb BL/BLX pair (S . P) + A For calls between program segments. */ +#define R_ARM_RREL32 252 /* Word (S . P) + A For on offset between two segments. */ +#define R_ARM_RABS32 253 /* Word S + A For the address of a location in the target segment. */ +#define R_ARM_RPC24 254 /* ARM B/BL (S . P) + A For calls between program segments. */ +#define R_ARM_RBASE 255 /* None None.Identifies the segment being relocated by the following + relocation directives. The ARM EABI poses two problems for relocating + executables and shared objects encoded in */ + + +// shirait +#define R_ARM_LDR_PC_G0 4 //LDR + +#define R_ARM_ABS12 6 //LDR, STR + +#define R_ARM_THM_CALL 10 //R_ARM_THM_PC22Ɠ + +#define R_ARM_CALL 28 //BL/BLX +#define R_ARM_JUMP24 29 //B/BL +#define R_ARM_THM_JUMP24 30 + +#define R_ARM_MOVW_ABS_NC 43 //MOVW +#define R_ARM_MOVT_ABS 44 //MOVT +#define R_ARM_MOVW_PREL_NC 45 //MOVW +#define R_ARM_MOVT_PREL 46 //MOVT + +#define R_ARM_ALU_PC_G0_NC 57 //ADD, SUB +#define R_ARM_ALU_PC_G0 58 //ADD, SUB +#define R_ARM_ALU_PC_G1_NC 59 //ADD, SUB +#define R_ARM_ALU_PC_G1 60 //ADD, SUB +#define R_ARM_ALU_PC_G2 61 //ADD, SUB +#define R_ARM_LDR_PC_G1 62 //LDR, STR, LDRB, STRB +#define R_ARM_LDR_PC_G2 63 //LDR, STR, LDRB, STRB +#define R_ARM_LDRS_PC_G0 64 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_PC_G1 65 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_PC_G2 66 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDC_PC_G0 67 //LDC, STC +#define R_ARM_LDC_PC_G1 68 //LDC, STC +#define R_ARM_LDC_PC_G2 69 //LDC, STC +#define R_ARM_ALU_SB_G0_NC 70 //ADD, SUB +#define R_ARM_ALU_SB_G0 71 //ADD, SUB +#define R_ARM_ALU_SB_G1_NC 72 //ADD, SUB +#define R_ARM_ALU_SB_G1 73 //ADD, SUB +#define R_ARM_ALU_SB_G2 74 //ADD, SUB +#define R_ARM_LDR_SB_G0 75 //LDR, STR, LDRB, STRB +#define R_ARM_LDR_SB_G1 76 //LDR, STR, LDRB, STRB +#define R_ARM_LDR_SB_G2 77 //LDR, STR, LDRB, STRB +#define R_ARM_LDRS_SB_G0 78 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_SB_G1 79 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDRS_SB_G2 80 //LDRD, STRD, LDRH, STRH, LDRSH, LDRSB +#define R_ARM_LDC_SB_G0 81 //LDC, STC +#define R_ARM_LDC_SB_G1 82 //LDC, STC +#define R_ARM_LDC_SB_G2 83 //LDC, STC +#define R_ARM_MOVW_BREL_NC 84 //MOVW +#define R_ARM_MOVT_BREL 85 //MOVT +#define R_ARM_MOVW_BREL 86 //MOVW + +#define R_ARM_GOT_BREL12 97 //LDR +#define R_ARM_GOTOFF12 98 //LDR, STR + +#define R_ARM_TLS_LDO12 109 //LDR, STR +#define R_ARM_TLS_LE12 110 //LDR, STR +#define R_ARM_TLS_TE12GP 111 //LDR + + + +/*--------------------------------------------------------- + Dynamic Section elf_v1.2 + --------------------------------------------------------*/ +typedef struct { + Elf32_Sword d_tag; + union { + Elf32_Word d_val; + Elf32_Addr d_ptr; + } d_un; +} Elf32_Dyn; + + +/* Additional symbol types for Thumb. */ +#define STT_ARM_TFUNC STT_LOPROC /* A Thumb function. */ +#define STT_ARM_16BIT STT_HIPROC /* A Thumb label. */ + + + + + + + + + +/*--------------------------------------------------------- + ELFwb_ǂݏo + --------------------------------------------------------*/ +void *ELF_LoadELFHeader(const void *buf, Elf32_Ehdr *ehdr); + + + +#endif /* ELF_H_ */ + diff --git a/build/tools/makenorfirm/format_nlist.h b/build/tools/makenorfirm/format_nlist.h new file mode 100644 index 00000000..6e5ba825 --- /dev/null +++ b/build/tools/makenorfirm/format_nlist.h @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: format_nlist.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 FORMAT_NLIST_H_ +#define FORMAT_NLIST_H_ + +#include +#include "misc.h" +#include "path.h" + +#define SPECFILE_MAGIC_ID "#NORSF" + +#define CRC16_INIT_VALUE 0xffff + +//--------------------------------------------------------------------------- +// Banner Spec File +//--------------------------------------------------------------------------- + +// Command List +typedef struct +{ + char *string; + BOOL (*funcp) (char *, int num); + +} +tCommandDesc; + + +// F Command +typedef struct +{ + u32 offsetStart; + u32 offsetEnd; + u32 padding; + char fullPathSrc[FILENAME_MAX]; + +} +tFileDesc; + + +#endif // FORMAT_NLIST_H_ diff --git a/build/tools/makenorfirm/format_rom.h b/build/tools/makenorfirm/format_rom.h new file mode 100644 index 00000000..3cb717fc --- /dev/null +++ b/build/tools/makenorfirm/format_rom.h @@ -0,0 +1,51 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: format_rom.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 FORMAT_ROM_H_ +#define FORMAT_ROM_H_ + +#include "misc.h" +#include + + +#define DEFAULT_ALIGN 16 +#define FIRM_ALIGN DEFAULT_ALIGN +#define FIRM_ALIGN_MASK (FIRM_ALIGN - 1) + +#define DEFAULT_HOSTROOT "." +#define DEFAULT_ROOT "/" + +#define DEFAULT_REJECT_1 "CVS" +#define DEFAULT_REJECT_2 "vssver.scc" + +#define FORMAT_VERSION "1.0" + +#define ENTRYNAME_MAX 127 + +#define DEFAULT_LISTFILE "default.nlf" + +#define DEFAULT_NORFIRM_SUFFIX ".nor" +#define DEFAULT_SPECFILE_SUFFIX ".norsf" + +/*===========================================================================* + * ROM FORMAT + *===========================================================================*/ + +//--------------------------------------------------------------------------- +// ROM HEADER +//--------------------------------------------------------------------------- + +#endif //FORMAT_ROM_H_ diff --git a/build/tools/makenorfirm/format_sign.h b/build/tools/makenorfirm/format_sign.h new file mode 100644 index 00000000..782a5d2b --- /dev/null +++ b/build/tools/makenorfirm/format_sign.h @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - SS + File: format_sign.h + + Copyright 2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_MAKENORFIRM_ACSIGN_FORMAT_H_ +#define FIRM_MAKENORFIRM_ACSIGN_FORMAT_H_ + +#include "format_rom.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_MAKENORFIRM_ACSIGN_FORMAT_H_ */ +#endif diff --git a/build/tools/makenorfirm/makenorfirm.c b/build/tools/makenorfirm/makenorfirm.c new file mode 100644 index 00000000..613efa74 --- /dev/null +++ b/build/tools/makenorfirm/makenorfirm.c @@ -0,0 +1,106 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: makenorfirm.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:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include +#include // strcasecmp() +#include // getopt() +#include "makenorfirm.h" +#include "format_rom.h" +#include "path.h" +#include "defval.h" +#include "version.h" + +static int makenorfirm(const char *specFile, const char *norFile); + +//--------------------------------------------------------------------------- +// Main +//--------------------------------------------------------------------------- + +int main(int argc, char *argv[]) +{ + int n; + int narg; + char *norfirmFile; + + InitAppName(argv[0]); + + while ((n = getopt(argc, argv, "D:hvpd")) != -1) + { + switch (n) + { + case 'h': + case 'v': + goto usage; + + case 'D': + AddDefVal(optarg); + break; + + case 'p': + PrintMode = TRUE; + break; + + case 'd': + DebugMode = TRUE; + break; + + default: + break; + } + } + + narg = argc - optind; + if (narg > 0) + { + // Make SpecFile->NorfirmFile + norfirmFile = + strdup(narg > + 1 ? argv[optind + 1] : ChangeSuffix(argv[optind], DEFAULT_NORFIRM_SUFFIX)); + return makenorfirm(argv[optind], norfirmFile); + } + + usage: + { + char *makenorfirm = GetAppName(); + + fprintf(stderr, + "NITRO-SDK Development Tool - %s - Make norfirm file \n" + "Build %lu\n\n" + "Usage: %s [-phv] [-DNAME=VALUE ...] SPECFILE [NORFIRMFILE]\n\n", + makenorfirm, SDK_DATE_OF_LATEST_FILE, makenorfirm); + } + return 1; +} + + +//--------------------------------------------------------------------------- +// makenorfirm +//--------------------------------------------------------------------------- + +static int makenorfirm(const char *specFile, const char *norFile) +{ + debug_printf("makenorfirm(): '%s' -> '%s'\n", specFile, norFile); + + // Check identical + if (specFile && norFile && !strcasecmp(specFile, norFile)) + { + error("norfirm spec file is identical '%s'", norFile); + return 1; + } + + return OutputNorfirmFile(specFile, norFile) ? 0 : 1; +} diff --git a/build/tools/makenorfirm/makenorfirm.h b/build/tools/makenorfirm/makenorfirm.h new file mode 100644 index 00000000..bb8eed65 --- /dev/null +++ b/build/tools/makenorfirm/makenorfirm.h @@ -0,0 +1,24 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: makenorfirm.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 MAKENORFIRM_H_ +#define MAKENORFIRM_H_ + +#include "misc.h" + +BOOL OutputNorfirmFile(const char *specFile, const char *norFile); + +#endif //MAKENORFIRM_H_ diff --git a/build/tools/makenorfirm/misc.c b/build/tools/makenorfirm/misc.c new file mode 100644 index 00000000..7706d6be --- /dev/null +++ b/build/tools/makenorfirm/misc.c @@ -0,0 +1,628 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: misc.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include // calloc() +#include // free(), exit() +#include // setmode() +#include // stat() +#include // setmode() +#include // strlen() +#include // va_start(),va_end() +#include // localtime() + +#include +#include "misc.h" + +BOOL DebugMode = FALSE; +BOOL PrintMode = FALSE; +char *PubkeyFileName = NULL; + +/*---------------------------------------------------------------------------* + * File Output Utilities + * + * BOOL OpenFile( const char* filename ) + * void CloseFile( void ) + * BOOL CheckResult( void ) + * void PutBuffer( const void* ptr, int len ) + * void PutByte( u8 c ) + * void PutWord( u16 c ) + * void PutWord( u32 c ) + * void PutString( const char *str ) + *---------------------------------------------------------------------------*/ + +static FILE *OutFile = NULL; +static const char *FileName = NULL; +static BOOL Status = FALSE; + + +// +// File Open +// + +BOOL OpenFile(const char *filename) +{ + if (OutFile) + CloseFile(); + + if (filename) + { + if (NULL == (OutFile = fopen(filename, "wb+"))) + { + error("Can't write '%s'", filename); + Status = FALSE; + return FALSE; + } + } + else + { + setmode(1, O_BINARY); + OutFile = stdout; // out to console if filename == NULL + } + FileName = filename; + Status = TRUE; + + return TRUE; +} + + +// +// File Close +// + +BOOL CloseFile(void) +{ + if (OutFile) + { + if (FileName) + { + if (fclose(OutFile) == -1) + { + error("Can't close '%s'", FileName); + Status = FALSE; + } + } + else + { + setmode(1, O_TEXT); + } + } + OutFile = NULL; + + return Status; +} + + +// +// File Seek +// + +void SeekFile(long pos) +{ + if (OutFile && fseek(OutFile, pos, SEEK_SET)) + { + error("Can't seek '%s'", FileName ? FileName : ""); + CloseFile(); + Status = FALSE; + } +} + + +// +// Error Check +// + +BOOL CheckResult(void) +{ + return Status; +} + + +// +// Delete outfile +// + +void DeleteOutFile(void) +{ + // Delete outfile + if (FileName) + { + debug_printf("Delete '%s'\n", FileName); + (void)unlink(FileName); + FileName = NULL; + } + return; +} + + +// +// Buffer Output +// + +void PutBuffer(const void *ptr, int len) /* If error, close file */ +{ + if (OutFile && len != fwrite(ptr, 1, len, OutFile)) + { + error("Can't write buffer to '%s'", FileName ? FileName : ""); + CloseFile(); + Status = FALSE; + } +} + +// +// Buffer Input +// + +void GetBuffer(void *ptr, int len) /* If error, close file */ +{ + if (OutFile && len != fread(ptr, 1, len, OutFile)) + { + error("Can't read '%s'", FileName ? FileName : ""); + CloseFile(); + Status = FALSE; + } +} + +// +// Byte/Half/Word Output +// + +void PutByte(u8 c) +{ + PutBuffer(&c, 1); +} +void PutHalf(u16 c) +{ + PutBuffer(&c, 2); +} +void PutWord(u32 c) +{ + PutBuffer(&c, 4); +} +void PutString(const char *str) +{ + PutBuffer(str, strlen(str)); +} + + +// +// Printf +// + +void PrintString(const char *fmt, ...) +{ + char *buffer; + va_list va; + int nchars; + int bufsize = FILENAME_MAX; + + while (1) + { + buffer = Alloc(bufsize); + va_start(va, fmt); + nchars = vsnprintf(buffer, bufsize, fmt, va); + va_end(va); + + if (0 <= nchars && nchars < bufsize) + { + break; + } + + Free(&buffer); + bufsize *= 2; + } + + if (nchars > 0) + { + PutBuffer(buffer, nchars); + } + Free(&buffer); +} + + +/*---------------------------------------------------------------------------* + * File Read/Write Utilities + * + * int ReadFile( const char* filename, void** buffer ) + * + * Read a file to buffer allocated internally + * Return read size + * Add '\0' at tail of file for help to handle text file + * + * BOOL WriteFile( const char* filename, void** buffer, int size ) + *---------------------------------------------------------------------------*/ + +int ReadFile(const char *filename, void *filebuffer, int size) +{ + FILE *fp; + struct stat fileStat; + int fileSize, readSize; + void **buffer = (void **)filebuffer; + + /* Check file */ + if (stat(filename, &fileStat) || !S_ISREG(fileStat.st_mode)) + { + goto error; + } + fileSize = fileStat.st_size; + if (fileSize < 0) + { + goto error; + } + + /* Open file */ + fp = fopen(filename, "rb"); + if (!fp) + { + goto error; + } + + if (size && (size < fileSize)) + { + readSize = size; + } + else + { + readSize = fileSize; + } + + /* Read file */ + *buffer = Alloc(readSize + 1); /* error handle is done in Alloc() */ + /* size+1 for '\0' to handle text file */ + if (readSize != fread(*buffer, sizeof(char), readSize, fp)) + { + goto error_free_close; + } + + (*(char **)buffer)[readSize] = '\0'; /* Works as terminater if file is text file */ + + /* Close file */ + fclose(fp); + return readSize; + + error_free_close: + Free(buffer); + fclose(fp); + error: + error("Can't read '%s'", filename); + return -1; +} + + +int ReadFileWithPadding(const char *filename, void *filebuffer, int size, int boundary) +{ + FILE *fp; + struct stat fileStat; + int fileSize, readSize, padSize; + void **buffer = (void **)filebuffer; + + if (!boundary) + { + return ReadFile(filename, buffer, size); + } + + /* Check file */ + if (stat(filename, &fileStat) || !S_ISREG(fileStat.st_mode)) + { + goto error; + } + fileSize = fileStat.st_size; + if (fileSize < 0) + { + goto error; + } + + /* Open file */ + fp = fopen(filename, "rb"); + if (!fp) + { + goto error; + } + + if (size && (size < fileSize)) + { + readSize = size; + } + else + { + readSize = fileSize; + } + + padSize = (boundary - (readSize & (boundary-1))) & (boundary-1); + + /* Read file */ + *buffer = Alloc(readSize + padSize); /* error handle is done in Alloc() */ + /* size+1 for '\0' to handle text file */ + if (readSize != fread(*buffer, sizeof(char), readSize, fp)) + { + goto error_free_close; + } + + memset((char*)*buffer + readSize, 0, padSize); + + /* Close file */ + fclose(fp); + return readSize + padSize; + + error_free_close: + Free(buffer); + fclose(fp); + error: + error("Can't read '%s'", filename); + return -1; +} + + +BOOL WriteFile(const char *filename, void *buffer, int size) +{ + debug_printf("WriteFile %s\n", filename); + + (void)OpenFile(filename); + PutBuffer(buffer, size); + CloseFile(); + Free(&buffer); + return CheckResult(); +} + + +/*---------------------------------------------------------------------------* + * Time Format Utilities + * + * char* GetGMTime( const time_t time ) Show GMT + * char* GetTime( const time_t time ) Show local Time + *---------------------------------------------------------------------------*/ + +char *GetGMTime(const time_t time) +{ + static char timebuffer[32]; + strftime(timebuffer, sizeof(timebuffer), "%y/%m/%d-%H:%M:%S", gmtime(&time)); + return timebuffer; +} + + +char *GetTime(const time_t time) +{ + static char timebuffer[32]; + strftime(timebuffer, sizeof(timebuffer), "%y/%m/%d-%H:%M:%S", localtime(&time)); + return timebuffer; +} + + +/*---------------------------------------------------------------------------* + * Memory Allocation Utilities + * + * void* Alloc( size_t size ) + *---------------------------------------------------------------------------*/ + +void *Alloc(size_t size) +{ + void *t = calloc(1, size); + + if (t == NULL) + { + error("Can't allocate memory."); + exit(10); + } + return t; +} + + +void Free(void *p) +{ + void **ptr = (void **)p; + + if (*ptr) + { + free(*ptr); + (*ptr) = NULL; + } +} + + +/*---------------------------------------------------------------------------* + * VBuffer + * + * void PutVBuffer( VBuffer* vbuf, char c ) + *---------------------------------------------------------------------------*/ + +void PutVBuffer(VBuffer * vbuf, char c) +{ + int size; + char *tmp_buffer; + + if (vbuf->buffer == 0) + { + vbuf->size = VBUFFER_INITIAL_SIZE; + vbuf->buffer = Alloc(vbuf->size); // buffer is CALLOCed + } + size = strlen(vbuf->buffer); + + if (size >= vbuf->size - 1) + { + // Need buffer expansion + vbuf->size *= 2; + tmp_buffer = Alloc(vbuf->size); // buffer is CALLOCed + strcpy(tmp_buffer, vbuf->buffer); + Free(&vbuf->buffer); + vbuf->buffer = tmp_buffer; + } + vbuf->buffer[size] = c; + return; +} + +char *GetVBuffer(VBuffer * vbuf) +{ + return vbuf->buffer; +} + +void InitVBuffer(VBuffer * vbuf) +{ + vbuf->buffer = 0; + vbuf->size = 0; +} + +void FreeVBuffer(VBuffer * vbuf) +{ + Free(&vbuf->buffer); +} + + +/*---------------------------------------------------------------------------* + * File Path Utilities + * + * char* ChangeBackSlash( char* path ) + *---------------------------------------------------------------------------*/ + +char *ChangeBackSlash(char *path) +{ + char *p = path; + + while (*p) + { + if (*p == '\\') + { + *p = '/'; + } + p++; + } + return path; +} + + +/*---------------------------------------------------------------------------* + * Math + * + * u16 CalcCRC16( u16 start, u8 *data, int size ) + *---------------------------------------------------------------------------*/ + +static u16 crc16_table[16] = { + 0x0000, 0xCC01, 0xD801, 0x1400, + 0xF001, 0x3C00, 0x2800, 0xE401, + 0xA001, 0x6C00, 0x7800, 0xB401, + 0x5000, 0x9C01, 0x8801, 0x4400 +}; + +u16 CalcCRC16(u16 start, u8 *data, int size) +{ + u16 r1; + u16 total = start; + + while (size-- > 0) + { + // 4bit + r1 = crc16_table[total & 0xf]; + total = (total >> 4) & 0x0fff; + total = total ^ r1 ^ crc16_table[*data & 0xf]; + + // 4bit + r1 = crc16_table[total & 0xf]; + total = (total >> 4) & 0x0fff; + total = total ^ r1 ^ crc16_table[(*data >> 4) & 0xf]; + + data++; + } + return total; +} + + +/*---------------------------------------------------------------------------* + * for firm header + * + *---------------------------------------------------------------------------*/ + +static u8 ConvertAlign( u32 ofs ) +{ + u8 i; + + ofs /= 4; + for (i=0; i<7; i++) + { + if ( ofs & 1 ) + { + break; + } + ofs >>= 1; + } + + return i; +} + +tROMAddrConvType ConvertHeaderRamAddr( s32 p ) +{ + tROMAddrConvType retval; + + retval.align = ConvertAlign( p ); + retval.address = (u16)((p - HW_WRAM)/(4< + +typedef enum +{ + FALSE = 0, + TRUE = 1 +} +BOOL; + +typedef unsigned char u8; +typedef unsigned short int u16; +typedef unsigned long int u32; +typedef unsigned long long u64; +typedef signed char s8; +typedef signed short int s16; +typedef signed long int s32; +typedef signed long long s64; +typedef volatile u8 vu8; +typedef volatile u32 vu32; +typedef vu32 REGType32v; + + + + +#define error(...) do { fprintf(stderr, "Error: "); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); } while(0) + +#define warning(...) do { fprintf(stderr, "Warning: "); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); } while(0) + +BOOL OpenFile(const char *filename); +BOOL CloseFile(void); +void SeekFile(long pos); +BOOL CheckResult(void); +void DeleteOutFile(void); +void PutBuffer(const void *ptr, int len); +void GetBuffer(void *ptr, int len); +void PutByte(u8 c); +void PutHalf(u16 c); +void PutWord(u32 c); +void PutString(const char *str); +void PrintString(const char *fmt, ...); + +#define READ_ALL 0 +int ReadFile(const char *filename, void *filebuffer, int size); +int ReadFileWithPadding(const char *filename, void *filebuffer, int size, int boundary); +BOOL WriteFile(const char *filename, void *buffer, int size); + +char *GetGMTime(const time_t time); +char *GetTime(const time_t time); + +void *Alloc(size_t size); +void Free(void *p); + +typedef struct +{ + char *buffer; + int size; +} +VBuffer; + +#define VBUFFER_INITIAL_SIZE 1024 +void InitVBuffer(VBuffer * vbuf); +void FreeVBuffer(VBuffer * vbuf); +void PutVBuffer(VBuffer * vbuf, char c); +char *GetVBuffer(VBuffer * vbuf); + +char *ChangeBackSlash(char *path); + +u16 CalcCRC16(u16 start, u8 *data, int size); +const char *WrapNull(const char *str); + +typedef struct +{ + u16 address; + u8 align; +} +tROMAddrConvType; + +tROMAddrConvType ConvertHeaderRamAddr( s32 p ); +tROMAddrConvType ConvertHeaderRomOffset( s32 p ); +u16 ConvertHeaderRomOffsetAlign( s32 p, u32 align ); + +typedef union +{ + struct + { + u32 sign:1; + u32 header_hash:1; + u32 arm9_hash:1; + u32 arm7_hash:1; + u32 hash_table_hash:1; + u32 final_hash:1; + u32 header_footer:1; + u32 wl_check:1; + } + e; + u32 raw; +} +tErrorFlags; + +extern BOOL DebugMode; +extern BOOL PrintMode; +extern char *PubkeyFileName; +void debug_printf(const char *str, ...); +void debug_printf2(const char *str, ...); + +#endif //MISC_H_ diff --git a/build/tools/makenorfirm/out_norfirm.c b/build/tools/makenorfirm/out_norfirm.c new file mode 100644 index 00000000..2eb98bd8 --- /dev/null +++ b/build/tools/makenorfirm/out_norfirm.c @@ -0,0 +1,984 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: out_norfirm.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:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include // atoi() +#include // strcmp() +#include // isprint() +#include // chdir() +#include +#include // UCHAR_MAX +#include +#include // stat() +#include "elf.h" +#include "misc.h" +#include "defval.h" +#include "format_rom.h" +#include "format_nlist.h" +#include "makenorfirm.h" +#include "format_sign.h" +#include "acsign_nor.h" +#include "compress.h" + +#define SDK_ASM + +#include +#include "../acsign/aes2.h" + +#define NANDCMD "BOOT_NAND" +#define SBIN9CMD "ARM9_SBIN" +#define SBIN7CMD "ARM7_SBIN" +#define ELF9CMD "ARM9_ELF" +#define ELF7CMD "ARM7_ELF" +#define COMP9CMD "ARM9_COMP" +#define COMP7CMD "ARM7_COMP" +#define DECOMPCMD "DECOMP_PROC" +#define BAUDCMD "BAUDRATE" +#define ARM9X2CMD "ARM9_X2" +#define VERCMD "VERSION" +#define RSAKEYCMD "RSA_KEY" +#define OUTKEYCMD "OUT_KEY" +#define WREGCMD "WRAM_RBIN" +#define ENDKEYCMD "ENC_KEYINFO" +#define NCDCMD "NCD_ROMOFS" +#define ERRCMD "ERROR" + +static BOOL ConstructNorfirmFile(char * specFile); +static BOOL ReadSbinFile(const char *fileName, void* minfo, void* hash, BOOL comp); +static BOOL ReadKeyFile(const char *fileName); +static BOOL ReadWramRegFile(const char *fileName); +static s32 GetRamAddr(const char *fileName); + +static BOOL EncryptBuffer(char *buffer, int length); + +static BOOL BTNAND_Command(char * line, int num); +static BOOL Sbin9_Command(char * line, int num); +static BOOL Sbin7_Command(char * line, int num); +static BOOL Elf9_Command(char * line, int num); +static BOOL Elf7_Command(char * line, int num); +static BOOL Comp9_Command(char * line, int num); +static BOOL Comp7_Command(char * line, int num); +static BOOL Decomp_Command(char * line, int num); +static BOOL BAUDRATE_Command(char * line, int num); +static BOOL ARM9X2_Command(char * line, int num); +static BOOL VERSION_Command(char * line, int num); +static BOOL RSAKEY_Command(char * line, int num); +static BOOL OUTKEY_Command(char * line, int num); +static BOOL WramRegs_Command(char * line, int num); +static BOOL ENCKEY_Command(char * line, int num); +static BOOL NcdOffset_Command(char * line, int num); +static BOOL ERROR_Command(char * line, int num); + +static BOOL InitializeAesKey(void); +static BOOL InitializeNorfirmFile(void); +static BOOL FinalizeNorfirmFile(const char *norFile); + +static s32 Offset; // Current offset +static int LineNum; // Line number for error message +static const char *specFileName; // specFile name for error message + +NORHeader norHeader; // Norfirm Header Shadow +FIRMSignedContext signedContext; +u8 *keyFileBuf; +BOOL compArm9 = TRUE; +BOOL compArm7 = TRUE; +tErrorFlags errFlags; + +//--------------------------------------------------------------------------- +// Output - norfirm File +//--------------------------------------------------------------------------- + +BOOL OutputNorfirmFile(const char *specFile, const char *norFile) +{ + char *buffer; + BOOL state; + + if (ReadFile(specFile, &buffer, READ_ALL) <= 0) + { + return FALSE; + } + + if (!OpenFile(norFile)) + { + return FALSE; + } + + specFileName = specFile; + + state = InitializeNorfirmFile() && ConstructNorfirmFile(buffer) && + FinalizeNorfirmFile(norFile) && CloseFile(); + + if (!state) + { + DeleteOutFile(); + } + + return state; +} + + +//--------------------------------------------------------------------------- +// Output - Norfirm File +//--------------------------------------------------------------------------- + +static const tCommandDesc command[] = { + {SBIN9CMD, Sbin9_Command}, {SBIN7CMD, Sbin7_Command}, + {ELF9CMD, Elf9_Command},{ELF7CMD, Elf7_Command}, + {COMP9CMD, Comp9_Command},{COMP7CMD, Comp7_Command}, + {DECOMPCMD, Decomp_Command}, + {NANDCMD, BTNAND_Command}, + {VERCMD, VERSION_Command}, + {BAUDCMD, BAUDRATE_Command}, + {ARM9X2CMD, ARM9X2_Command}, + {RSAKEYCMD, RSAKEY_Command}, + {OUTKEYCMD, OUTKEY_Command}, + {WREGCMD, WramRegs_Command}, + {ENDKEYCMD, ENCKEY_Command}, + {NCDCMD, NcdOffset_Command}, + {ERRCMD, ERROR_Command}, +}; + +BOOL ConstructNorfirmFile(char * specFile) +{ + char *line; + char *line_top; + char *p; + int i; + + LineNum = 0; + Offset = 0x00000000; + + line = specFile++; + + while (*line != '\0') + { + LineNum++; + + // Get command line + line_top = line; + while (*line != '\0') + { + if (*line++ == '\n') + { + break; + } + } + + // Print for debug + debug_printf("NORSF Line%4d [", LineNum, line); + for (p = line_top; p != line; p++) + { + if (isprint(*p)) + { + debug_printf("%c", *p); + } + } + debug_printf("]\n"); + + if (*line_top == '#') + { + } + else + { + for (i = 0; i < (sizeof(command) / sizeof(command[0])); i++) + { + if (!strncmp(line_top, command[i].string, strlen(command[i].string))) + { + if (command[i].funcp != NULL) + { + char line_cmd[FILENAME_MAX]; + char line_scan[FILENAME_MAX]; + char* line_conv; + int num; + + num = sscanf( line_top, + "%1024[^ :] : %1024[^ \x0d:#\n]", + line_cmd, line_scan + ); + line_conv = ResolveDefVal(line_scan); + + debug_printf("line_cmd = %s, line_conv = %s\n", line_cmd, line_conv); + + if (!command[i].funcp(line_conv, num - 1)) + return FALSE; + } + } + } + } + + } + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - 'WramRegs' Command +//--------------------------------------------------------------------------- + +extern MIHeader_WramRegs wram_regs_init; +MIHeader_WramRegs* wram_regs; + +static BOOL WramRegs_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("wram regs file = %s\n", line); + + return ReadWramRegFile(line); +} + +static BOOL ReadWramRegFile(const char *fileName) +{ + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &wram_regs, READ_ALL)) < 0) + return FALSE; + + norHeader.h.w = *wram_regs; + + return CheckResult(); +} + +//--------------------------------------------------------------------------- +// Output - 'RSAKEY' Command +//--------------------------------------------------------------------------- + +static BOOL RSAKEY_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("rsa key = %s\n", line); + + return ReadKeyFile(line); +} + +static BOOL ReadKeyFile(const char *fileName) +{ + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &keyFileBuf, READ_ALL)) < 0) + return FALSE; + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'OUTKEY' Command +//--------------------------------------------------------------------------- + +static BOOL OUTKEY_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("out key = %s\n", line); + + PubkeyFileName = line; + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'VERSION' Command +//--------------------------------------------------------------------------- + +static u8 ConvToBCD8(int x) +{ + u8 bcd = 0; + + x %= 100; + bcd |= (x / 10)<<4; + bcd |= (x % 10); + + return bcd; +} + +static BOOL VERSION_Command(char * line, int num) +{ + char scan[FILENAME_MAX]; + u64 version = -1; + + // rescan + num = sscanf( line, + "0x%1024[^\x0d\n]", + scan + ); + + if (num == 1) + { + // convert version info + version = strtoull(scan, NULL, 16); + } + else if (num == 0) + { + // generate version info + u8* ver8 = (u8*)&version; + time_t timer; + struct tm *t_st; + + time(&timer); + t_st = localtime(&timer); + + ver8[0] = ConvToBCD8(t_st->tm_min); + ver8[1] = ConvToBCD8(t_st->tm_hour); + ver8[2] = ConvToBCD8(t_st->tm_mday); + ver8[3] = ConvToBCD8(t_st->tm_mon+1); + ver8[4] = ConvToBCD8(t_st->tm_year); + ver8[5] = 0x57; + ver8[6] = 0xff; + ver8[7] = 0xff; + } + + norHeader.d.card_key = version; + + debug_printf2("version = %08llx\n", version); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'BOOT_NAND' Command +//--------------------------------------------------------------------------- + +static BOOL BTNAND_Command(char * line, int num) +{ + char* dbg_str = "FALSE"; + + norHeader.l.boot_nandfirm = FALSE; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + if (!strcmp(line, "TRUE")) + { + norHeader.l.boot_nandfirm = TRUE; + dbg_str = "TRUE"; + } + + debug_printf2("boot nandfirm = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Decomp' Command +//--------------------------------------------------------------------------- + +static BOOL Decomp_Command(char * line, int num) +{ + char* dbg_str = "ARM7"; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + if (!strcmp(line, "ARM9")) + { + norHeader.l.arm9_decomp = TRUE; + dbg_str = "ARM9"; + } + + debug_printf2("decompress processor = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'ARM9_X2' Command +//--------------------------------------------------------------------------- + +static BOOL ARM9X2_Command(char * line, int num) +{ + char* dbg_str = "FALSE"; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + if (!strcmp(line, "TRUE")) + { + norHeader.l.arm9_x2 = TRUE; + dbg_str = "TRUE"; + } + + debug_printf2("arm9 x2 = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'BAUDRATE' Command +//--------------------------------------------------------------------------- + +static BOOL BAUDRATE_Command(char * line, int num) +{ + char* dbg_str = "4M"; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + if (!strcmp(line, "8M")) + { + norHeader.l.baudrate = TRUE; + dbg_str = "8M"; + } + + debug_printf2("spi speed = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Comp9' Command +//--------------------------------------------------------------------------- + +static BOOL Comp9_Command(char * line, int num) +{ + char* dbg_str = "FALSE"; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + compArm9 = FALSE; + + if (!strcmp(line, "TRUE")) + { + norHeader.l.comp_arm9_boot_area = TRUE; + compArm9 = TRUE; + dbg_str = "TRUE"; + } + + debug_printf2("arm9 compress = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Comp7' Command +//--------------------------------------------------------------------------- + +static BOOL Comp7_Command(char * line, int num) +{ + char* dbg_str = "FALSE"; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + compArm7 = FALSE; + + if (!strcmp(line, "TRUE")) + { + norHeader.l.comp_arm7_boot_area = TRUE; + compArm7 = TRUE; + dbg_str = "TRUE"; + } + + debug_printf2("arm7 compress = %s\n", dbg_str); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Elf9' Command +//--------------------------------------------------------------------------- + +static BOOL Elf9_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm9 elf = %s\n", line); + + { + s32 ramAddr = GetRamAddr(line); + norHeader.l.main_ram_address = (void*)ramAddr; + } + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'Elf7' Command +//--------------------------------------------------------------------------- + +static BOOL Elf7_Command(char * line, int num) +{ + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm7 elf = %s\n", line); + + { + s32 ramAddr = GetRamAddr(line); + norHeader.l.sub_ram_address = (void*)ramAddr; + } + + return CheckResult(); +} + + +static s32 GetRamAddr(const char *fileName) +{ + Elf32_Ehdr *ehdr; + s32 ramAddr; + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &ehdr, sizeof(Elf32_Ehdr))) < 0) + return FALSE; + + ramAddr = ehdr->e_entry; + + Free(&ehdr); + + debug_printf2("ramaddr = 0x%08x\n", ramAddr); + + return ramAddr; +} + + +//--------------------------------------------------------------------------- +// Output - 'Sbin9' Command +//--------------------------------------------------------------------------- + +static BOOL Sbin9_Command(char * line, int num) +{ + FIRMSignedContext* sc = &signedContext; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm9 sbin = %s\n", line); + + // Set ARM9 ROM Offset + if (!Offset) + { + Offset = (sizeof(NORHeader) + FIRM_ALIGN_MASK) & ~FIRM_ALIGN_MASK; + SeekFile(Offset); + } + debug_printf2("romoffset = %#x\n", Offset); + { + norHeader.l.main_rom_offset = Offset; + } + + return ReadSbinFile(line, &norHeader.l.main_rom_offset, &sc->hash[FIRM_SIGNED_HASH_IDX_ARM9], compArm9); +} + +//--------------------------------------------------------------------------- +// Output - 'Sbin7' Command +//--------------------------------------------------------------------------- + +static BOOL Sbin7_Command(char * line, int num) +{ + FIRMSignedContext* sc = &signedContext; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + debug_printf2("arm7 sbin = %s\n", line); + + // Set ARM7 ROM Offset + if (!Offset) + { + Offset = (sizeof(NORHeader) + FIRM_ALIGN_MASK) & ~FIRM_ALIGN_MASK; + SeekFile(Offset); + } + debug_printf2("romoffset = %#x\n", Offset); + { + norHeader.l.sub_rom_offset = Offset; + } + + return ReadSbinFile(line, &norHeader.l.sub_rom_offset, &sc->hash[FIRM_SIGNED_HASH_IDX_ARM7], compArm7); +} + + +static BOOL ReadSbinFile(const char *fileName, void* minfo, void* hash, BOOL comp) +{ + const NORHeader_ModuleInfo *m = minfo; + u32 *size = (void*)&m->size; + u32 *orig_size = (void*)&m->decomp_size; + char *buffer; + char *file; + int file_size; + struct stat st; + + if (FILESTATUS_FILE != GetFileStatus(&st, fileName)) + { + error("'%s' is not regular file.", fileName); + return FALSE; + } + + if ((file_size = ReadFile(fileName, &file, READ_ALL)) < 0) + return FALSE; + + *orig_size = file_size; + + // Digest file image + if (hash) + { + ACSign_DigestUnit(hash, file, file_size); + } + + // Compress file image with fitting region + buffer = Alloc(file_size * 2); + if ( comp ) + { + file_size = LZCompWrite(file, file_size, buffer, FIRM_ALIGN); + } + else + { + memcpy(&buffer[0], file, file_size); + { + u32 pad_size = (FIRM_ALIGN - (file_size % FIRM_ALIGN)) % FIRM_ALIGN; + if (pad_size) + memset(&buffer[file_size], 0, pad_size); + file_size += pad_size; + } + } + Free(&file); + file = buffer; + + if (size) + { + *size = file_size; + } + Offset += file_size; + + // Encrypt file image + EncryptBuffer(file, file_size); + + // Output file image with fitting region + PutBuffer(file, file_size); + + Free(&file); + + return CheckResult(); +} + +typedef struct +{ + unsigned long e[4]; +} u128; + +static BOOL EncryptBuffer(char *buffer, int length) +{ + const u128 id = {{ AES_IDS_ID2_A, AES_IDS_ID2_B, AES_IDS_ID2_C, AES_IDS_ID2_D }}; + u128 iv = {{ length, -length, ~length, 0 }}; + FIRMSignedContext* sc = &signedContext; + char *buffer2 = Alloc(length); + AES_KEY key; + if (!buffer2) + return FALSE; + AES_SetKey(&key, sc->aes_key, (unsigned char*)&id); + AES_Ctr(&key, buffer2, buffer, length, (unsigned char*)&iv); + memcpy(buffer, buffer2, length); + memset(buffer2, 0, length); + Free(buffer2); + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - 'ENC_KEYINFO' Command +//--------------------------------------------------------------------------- + +static BOOL ENCKEY_Command(char * line, int num) +{ + u32 key; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + key = strtoul(line, NULL, 0); + norHeader.d.ds_key = key; + + debug_printf2("keyinfo = %#x\n", key); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'NcdOffset' Command +//--------------------------------------------------------------------------- + +static BOOL NcdOffset_Command(char * line, int num) +{ + u32 ofs; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + ofs = strtoul(line, NULL, 0); + { + norHeader.d.ncd_romAdr = ConvertHeaderRomOffsetAlign(ofs, 8); + } + + debug_printf2("ncd romoffset = %#x\n", ofs); + + return CheckResult(); +} + + +//--------------------------------------------------------------------------- +// Output - 'ERROR' Command +//--------------------------------------------------------------------------- +static char* error_type[] = +{ + "SIGN", + "HEADER_HASH", + "ARM9_HASH", + "ARM7_HASH", + "HASH_TABLE_HASH", + "FINAL_HASH", + "HEADER_FOOTER", + "WL_CHECK", +}; + +static BOOL ERROR_Command(char * line, int num) +{ + char* dbg_str = "UNKNOWN"; + int i; + + if (num != 1) + { + error("Wrong format spec file '%s' line:%d", specFileName, LineNum); + return FALSE; + } + + for (i=0; ihash[FIRM_SIGNED_HASH_IDX_HEADER][0] ^= 1; + } + if ( errFlags.e.arm9_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_ARM9][0] ^= 1; + } + if ( errFlags.e.arm7_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_ARM7][0] ^= 1; + } + if ( errFlags.e.hash_table_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_HASH_TABLE][0] ^= 1; + } +} + +static void SetFinalHashError(FIRMSignedContext* sc) +{ + if ( errFlags.e.final_hash ) + { + sc->hash[FIRM_SIGNED_HASH_IDX_FINAL][0] ^= 1; + } +} + +static void SetSignError(NORHeader* nh) +{ + if ( errFlags.e.sign ) + { + nh->sign.raw[0] ^= 1; + } + +} + +static void SetFooterError(NORHeader* nh) +{ + if ( errFlags.e.header_footer ) + { + nh->h.reserved_footer[sizeof(nh->h.reserved_footer)-1] ^= 1; + } + +} + +static void SetWirelessCheck(NORHeader* nh) +{ + if ( errFlags.e.wl_check ) + { + nh->wl_params[0] ^= 0x80; + nh->wl_params[sizeof(nh->wl_params)-1] ^= 0x80; + } + +} + + +//--------------------------------------------------------------------------- +// Output - Initialize AES Key +//--------------------------------------------------------------------------- +static BOOL InitializeAesKey(void) +{ + FIRMSignedContext* sc = &signedContext; + struct stat specstat; + time_t spectime; + if (stat(specFileName, &specstat) != 0) + return FALSE; + time(&spectime); + memcpy(&sc->aes_key[0], &specstat.st_atime, 4); + memcpy(&sc->aes_key[4], &specstat.st_mtime, 4); + memcpy(&sc->aes_key[8], &specstat.st_ctime, 4); + memcpy(&sc->aes_key[12], &spectime, 4); + ACSign_GetKey(sc->aes_key, sizeof(sc->aes_key), sc->aes_key, sizeof(sc->aes_key)); + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - Initialize Norfirm File +//--------------------------------------------------------------------------- + +static BOOL InitializeNorfirmFile(void) +{ + memset(norHeader.wl_params, 0xff, sizeof(norHeader.wl_params)); + memset(&signedContext.hash[FIRM_SIGNED_HASH_IDX_HASH_TABLE], 0x00, sizeof(signedContext.hash[0])); + norHeader.l.boot_nandfirm = TRUE; + InitializeAesKey(); + return TRUE; +} + + +//--------------------------------------------------------------------------- +// Output - Finalize Norfirm File +//--------------------------------------------------------------------------- + +static BOOL FinalizeNorfirmFile(const char *norFile) +{ + NORHeader* nh = &norHeader; + FIRMSignedContext* sc = &signedContext; + u8* key = keyFileBuf; + + ACSign_DigestHeader(&sc->hash[FIRM_SIGNED_HASH_IDX_HEADER], nh); + + SetUnitHashErrors(sc); + + ACSign_DigestUnit(&sc->hash[FIRM_SIGNED_HASH_IDX_FINAL], sc, FIRM_HEADER_2ND_HASH_AREA_LEN); + + SetFinalHashError(sc); + + if (key) + { + ACSign_Final(nh, sc, key); + } + + SetFooterError(nh); + + SetSignError(nh); + + SetWirelessCheck(nh); + + // Output file image + SeekFile(0L); + PutBuffer(&norHeader, sizeof(norHeader)); + + // Output public key (modulus) + if (PubkeyFileName) + { + WriteFile(PubkeyFileName, &keyFileBuf[ACS_RSA_PRVMOD_OFFSET], ACS_RSA_PRVMOD_LEN); + } + + return TRUE; +} diff --git a/build/tools/makenorfirm/path.c b/build/tools/makenorfirm/path.c new file mode 100644 index 00000000..eeeb9895 --- /dev/null +++ b/build/tools/makenorfirm/path.c @@ -0,0 +1,931 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makebanner + File: path.c + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: path.c,v $ + Revision 1.3 2006/01/18 02:11:20 kitase_hirotake + do-indent + + Revision 1.2 2005/02/28 05:26:13 yosizaki + do-indent. + + Revision 1.1 2004/08/30 08:41:14 yasu + makebanner moves into CVS tree + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#include +#include // free() +#include // strcasecmp() +#include // stat() +#include // opendir()/readdir()/closedir() +#include // getcwd() +#ifdef __CYGWIN__ +#include // cygwin_conv_to_win32_path() +#endif +#include "path.h" + +//--------------------------------------------------------------------------- +// Get File Statue +//--------------------------------------------------------------------------- + +tFileStatus GetFileStatus(struct stat *s, const char *filename) +{ + // Get file status + if (stat(filename, s)) + { + error("Can't get status %s", filename); + return FILESTATUS_ERROR; + } + + if (S_ISREG(s->st_mode)) + { + return FILESTATUS_FILE; + } + else if (S_ISDIR(s->st_mode)) + { + return FILESTATUS_DIR; + } + + error("Unknown file type %s", filename); + return FILESTATUS_ERROR; +} + + +//--------------------------------------------------------------------------- +// File Globbing & Dir Listing +//--------------------------------------------------------------------------- + +typedef struct +{ + tCallBack callBack; + void *param; + tWildCard *accept; + tWildCard *reject; + +} +tForeachEntryParam; + + +static BOOL isAcceptEntryName(char *pathName, tWildCard * accept, tWildCard * reject) +{ + char *p = pathName; + + while (*p) + { + if (*p == '/') + pathName = p + 1; + p++; + } + + if (accept) + { + while (accept) + { + if (WildCardCmp(accept->name, pathName)) + { + goto accepted; + } + accept = accept->next; + } + return FALSE; + } + accepted: + + while (reject) + { + if (WildCardCmp(reject->name, pathName)) + { + return FALSE; + } + reject = reject->next; + } + return TRUE; +} + + +static BOOL ForeachEntry_CallBack(char *pathName, void *param) +{ + tForeachEntryParam *t = (tForeachEntryParam *) param; + struct stat fstat; + + if (!isAcceptEntryName(pathName, t->accept, t->reject)) + { + // Reject!!! ignored + return TRUE; + } + + switch (GetFileStatus(&fstat, pathName)) + { + case FILESTATUS_FILE: + return t->callBack(pathName, t->param); + + case FILESTATUS_DIR: + return ForeachDirList(pathName, ForeachEntry_CallBack, param); + + default: + break; + } + return FALSE; +} + + +BOOL ForeachEntry(const char *pathName, tWildCard * reject, tCallBack callBack, void *param) +{ + tForeachEntryParam t; + + t.callBack = callBack; + t.param = param; + t.accept = NULL; + t.reject = reject; + + return ForeachPathGlobbing(pathName, ForeachEntry_CallBack, &t); +} + + +typedef struct +{ + tCallBack callBack; + void *param; + char *baseName; + +} +tForeachFileParam; + + +static BOOL ForeachFile_CallBack(char *pathName, void *param) +{ + tForeachFileParam *t = (tForeachFileParam *) param; + + int len = strlen(t->baseName); + + debug_printf(" ForeachFile_CallBack path[%s] base[%s]\n", pathName, t->baseName); + + if (strncmp(pathName, t->baseName, len)) + { + error("Wildcard in Root is not supported"); + return FALSE; + } + + return t->callBack(pathName + len, t->param); +} + + +BOOL ForeachFile(const char *baseName, const char *fileName, tWildCard * reject, tCallBack callBack, + void *param) +{ + char *cBaseName; + char *cPathName; + BOOL state; + tForeachFileParam t; + + debug_printf("ForeachFile : baseName[%s] fileName[%s]\n", baseName, fileName); + + cBaseName = GetSrcPath(baseName, ""); + cPathName = GetSrcPath(baseName, fileName); + + debug_printf("ForeachFile : cBaseName[%s] cPathName[%s]\n", cBaseName, cPathName); + + t.callBack = callBack; + t.param = param; + t.baseName = cBaseName; + + state = ForeachEntry(cPathName, reject, ForeachFile_CallBack, &t); + + free(cBaseName); + free(cPathName); + + return state; +} + + +//--------------------------------------------------------------------------- +// FilePath Globbing +//--------------------------------------------------------------------------- + +typedef struct +{ + char *baseName; + char *pathName; + tCallBack callBack; + void *param; + +} +tGlobParam; + + +static int CountFile; +static BOOL ForeachPathGlobbing_Entry(tGlobParam * pg); +static BOOL ForeachPathGlobbing_WildCard(char *pathName, void *param); + +BOOL ForeachPathGlobbing(const char *pathName, tCallBack callBack, void *param) +{ + tGlobParam g; + BOOL ret; + + g.baseName = NULL; + g.pathName = PathNormalize(pathName, TRUE); + g.callBack = callBack; + g.param = param; + CountFile = 0; + + debug_printf("PathGlobbing : Name [%s]->[%s]\n", pathName, g.pathName); + + ret = ForeachPathGlobbing_Entry(&g); + + free(g.pathName); + + if (ret && CountFile == 0) + { + error("No file or directory matched %s", pathName); + return FALSE; + } + return ret; +} + + +static BOOL ForeachPathGlobbing_Entry(tGlobParam * pg) +{ + tGlobParam g; + char *entryName; + struct stat s; + BOOL state; + + if (pg->pathName) + { + entryName = PathDup(pg->pathName); + + g = *pg; + g.pathName = PathGetDirLevelDown(pg->pathName); + + if (pg->baseName) + { + g.baseName = Alloc(strlen(pg->baseName) + strlen(entryName) + 2); + sprintf(g.baseName, "%s/%s", pg->baseName, entryName); + } + else + { + g.baseName = strdup(entryName); + } + + // Check if wildcard ? + if (isPathWildCard(entryName)) + { + state = ForeachDirList(pg->baseName, ForeachPathGlobbing_WildCard, &g); + } + else + { + state = ForeachPathGlobbing_Entry(&g); + } + + Free(&entryName); + Free(&g.baseName); + } + else + { + // Check if file exists + if (!stat(pg->baseName, &s)) + { + debug_printf(" File Found [%s]\n", pg->baseName); + + // Globbing done, exec callback + + state = pg->callBack(pg->baseName, pg->param); + CountFile++; + } + else + { + debug_printf(" File Not Found [%s]\n", pg->baseName); + state = TRUE; // Ignored + } + } + return state; +} + + +static BOOL ForeachPathGlobbing_WildCard(char *pathName, void *param) +{ + tGlobParam g; + tGlobParam *pg = (tGlobParam *) param; + + debug_printf(" WildCardCmp: [%s] [%s]\n", pg->baseName, pathName); + + if (WildCardCmp(pg->baseName, pathName)) + { + g = *pg; + g.baseName = pathName; + return ForeachPathGlobbing_Entry(&g); + } + + return TRUE; // Ignored +} + + +//--------------------------------------------------------------------------- +// Directory Listing +// Listing directory & Exec CallBack +//--------------------------------------------------------------------------- + +BOOL ForeachDirList(const char *dirName, tCallBack callBack, void *param) +{ + DIR *dir; + struct dirent *entry; + char *pathName; + BOOL state = TRUE; + + if (!dirName) + { + dirName = "."; + } + + debug_printf("DirectoryList: Name [%s]\n", dirName); + + // Open directory + if (NULL == (dir = opendir(dirName))) + { + error("Can't read directory %s", dirName); + return FALSE; + } + + // Store new files + while (NULL != (entry = readdir(dir))) + { + pathName = entry->d_name; + + if (!strcmp(pathName, ".") || !strcmp(pathName, "..")) + { + continue; + } + + debug_printf(" :%s\n", pathName); + pathName = GetSrcPath(dirName, pathName); + state = callBack(pathName, param); + free(pathName); + + if (!state) + break; + } + + closedir(dir); + return state; +} + + +//--------------------------------------------------------------------------- +// +// PathName Utilities +// +//--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- +// StrCmp/StrCpy entry name terminated / or \0 +//--------------------------------------------------------------------------- + +int PathCmp(const char *path, const char *cmp) +{ + char c; + + do + { + c = *path; + if (c == '/') + c = '\0'; // end of string if '/' + if (c != *cmp) + return 1; + path++; + cmp++; + } + while (c); + + return 0; +} + + +char *PathCpy(char *dest, const char *src) +{ + while (*src != '\0' && *src != '/') + { + *dest++ = *src++; + } + return dest; // Don't set '\0' +} + + +int PathLen(const char *path) +{ + int n = 0; + + while (*path != '\0' && *path != '/') + { + n++; + path++; + } + return n; +} + + +char *PathDup(const char *src) +{ + int n = PathLen(src); + char *dest = Alloc(n + 2); + + PathCpy(dest, src); + dest[n] = '\0'; + + return dest; +} + + +BOOL WildCardCmp(const char *wildcard, const char *path) +{ + if (*wildcard == '*') + { + if (*path != '\0' && WildCardCmp(wildcard, path + 1)) + return TRUE; + if (WildCardCmp(wildcard + 1, path)) + return TRUE; + } + + else if (*wildcard == '?') + { + return *path != '\0' && WildCardCmp(wildcard + 1, path + 1); + } + + else if (*wildcard == *path) + { + return *path == '\0' || WildCardCmp(wildcard + 1, path + 1); + } + + return FALSE; +} + + +BOOL isPathWildCard(const char *path) +{ + while (*path != '\0' && *path != '/') + { + if (*path == '*' || *path == '?') + { + return TRUE; + } + path++; + } + return FALSE; +} + + +//--------------------------------------------------------------------------- +// Go up/down directory level +//--------------------------------------------------------------------------- + +char *PathGetDirLevelDown(const char *path) +{ + while (*path) + { + if (*path == '/') + return (char *)path + 1; + path++; + } + return NULL; +} + + +//--------------------------------------------------------------------------- +// Get Basename +//--------------------------------------------------------------------------- + +char *GetBaseName(const char *path) +{ + int i; + char *new_path; + + for (i = strlen(path) - 1; i >= 0; i--) + { + if (path[i] == '/') + { + new_path = strdup(path); + new_path[i] = '\0'; + return new_path; + } + if (path[i] == ':') + { + new_path = Alloc(i + 3); + strncpy(new_path, path, i); + strcpy(new_path + i, ":."); + return new_path; + } + } + + new_path = strdup("."); + return new_path; +} + + +//--------------------------------------------------------------------------- +// Get Filename +//--------------------------------------------------------------------------- + +char *GetFileName(const char *path) +{ + int i; + char *new_file; + + for (i = strlen(path) - 1; i >= 0; i--) + { + if (path[i] == '/' || path[i] == ':') + { + new_file = strdup(path + i + 1); + return new_file; + } + } + new_file = strdup(path); + return new_file; +} + + +//--------------------------------------------------------------------------- +// Reconstruct path name +// +// - Resolve '.' or '..' in path name +// - Work around . and / to translate regular form +// +// Regular form of path: +// Absolute Path [Drive:]/.[/Entry...] +// Relative Path [Drive:].[/Entry]... +// +// ex) +// abc/def -> ./abc/def +// /aaa -> /./aaa +// D:/aaa -> D:/./aaa +// / -> /. +// . -> . +// ../aa -> ./../aa +//--------------------------------------------------------------------------- + +char *PathNormalize(const char *pathName, BOOL isTreatDotDot) +{ + int i, level, level_root, n; + BOOL isAbsolute; + const char *entry[DIRLEVEL_MAX]; + + char *pathNormal = Alloc(strlen(pathName) + 4); + const char *p_org; + char *p_new; + + // + // Check if drive letter C: D: E: + // Check if absolute path + // + p_new = pathNormal; + p_org = SkipDriveName(pathName); + n = (int)p_org - (int)pathName; + + if (n > 0) + { + strncpy(p_new, pathName, n); + p_new += n; + } + isAbsolute = isAbsolutePath(p_org); + + // + // Resolve '.' and '..' + // + // Slice the path at point of / , put them into entry[] + // + + level = level_root = 0; + + for (; p_org; p_org = PathGetDirLevelDown(p_org)) + { + if (!PathCmp(p_org, "") || !PathCmp(p_org, ".")) + { + // skip it + continue; + } + else if (!PathCmp(p_org, "..") && isTreatDotDot) + { + if (level > level_root) + { + // Back to parent dir + level--; + continue; + } + + // if pathname starts with '/', no directory to go up + if (isAbsolute) + { + error("Can't go up directory, '..' Ignored. %s", pathName); + continue; + } + + // keep '..' + level_root = level + 1; + } + + // name entry + entry[level] = p_org; + level++; + } + + // Reconstruct pathname + if (isAbsolute) + { + *p_new++ = '/'; + } + *p_new++ = '.'; + + for (i = 0; i < level; i++) + { + *p_new++ = '/'; + p_new = PathCpy(p_new, entry[i]); + } + *p_new = '\0'; + +#if 0 + if (strcmp(pathNormal, pathName)) + { + debug_printf(" PathNormal: [%s] -> [%s]\n", pathName, pathNormal); + } +#endif + return pathNormal; +} + + +//--------------------------------------------------------------------------- +// Get Src Path +// Normalize BASENAME +// Normalize FILENAME +// Concat both +//--------------------------------------------------------------------------- + +char *GetSrcPath(const char *baseName, const char *fileName) +{ + char *base; + char *file; + char *t; + char *path; + + base = PathNormalize(baseName, TRUE); + file = PathNormalize(fileName, TRUE); + t = Alloc(strlen(base) + strlen(file) + 2); + + // Concat base + '/' + file + sprintf(t, "%s/%s", base, file); + path = PathNormalize(t, FALSE); + + free(base); + free(file); + free(t); + + debug_printf(" GetSrcPath: [%s]\n", path); + return path; +} + + +//--------------------------------------------------------------------------- +// Get Dest Path +// Concat BASENAME + FILENAME +// Normalize it +//--------------------------------------------------------------------------- + +char *GetDestPath(const char *baseName, const char *fileName) +{ + char *t; + char *path; + + t = Alloc(strlen(baseName) + strlen(fileName) + 2); + + // Concat base + '/' + file + sprintf(t, "%s/%s", baseName, fileName); + path = PathNormalize(t, TRUE); + + free(t); + + debug_printf(" GetDestPath: [%s]\n", path); + return path; +} + + +//--------------------------------------------------------------------------- +// Remake the path into familier shape +// Delete ./ +//--------------------------------------------------------------------------- + +char *PathDenormalize(char *path) +{ + char *p; + + p = (char *)SkipDriveName(path); + if (*p == '/') + { + p++; + } + + // Cut './' + if (*p == '.' && *(p + 1) == '/') + { + while ('\0' != (*p = *(p + 2))) + { + p++; + } + + if (p == path) + { + + } + } + + + + return path; +} + + +//--------------------------------------------------------------------------- +// Get PC Path +//--------------------------------------------------------------------------- + +char *GetWin32Path(char *cygpath) +{ + static char buffer[FILENAME_MAX]; + +#ifdef __CYGWIN__ + if (*cygpath == '/') + { + cygwin_conv_to_win32_path(cygpath, buffer); + } + else +#endif + { + strcpy(buffer, cygpath); + } + + return ChangeBackSlash(buffer); +} + +char *ChangeWin32Path(char *cygpath) +{ + char *win32path = strdup(GetWin32Path(cygpath)); + + free(cygpath); + return win32path; +} + +//--------------------------------------------------------------------------- +// Change suffix +//--------------------------------------------------------------------------- +char *ChangeSuffix(const char *file, const char *suffix) +{ + int i, n; + char *path; + + n = strlen(file); + + for (i = n; file[i] != '.'; i--) + { + if (file[i] == '/' || i == 0) + { + i = n; + break; + } + } + + path = Alloc(i + strlen(suffix) + 1); + strncpy(path, file, i); + strcpy(path + i, suffix); + + return path; +} + + +//--------------------------------------------------------------------------- +// Get Current Dir +//--------------------------------------------------------------------------- + +char *GetCurrentDirectory(void) +{ + static char buffer[FILENAME_MAX]; + char *cwd; + + cwd = getcwd(buffer, FILENAME_MAX); + if (!cwd) + { + error("Can't access current directory"); + exit(10); + } + return cwd; +} + + +//--------------------------------------------------------------------------- +// Check if absolute path +// +// Return True in case of ... +// +// /dirA/dirB/fileC +// D:/dirA/dirB/fileC +// +// Return False in case of ... +// +// dirX/dirY/fileZ +// D:dirX/dirY/fileZ +//--------------------------------------------------------------------------- + +BOOL isAbsolutePath(const char *path) +{ + const char *p = path; + + while (*p != '\0') + { + if (*p == '/' || *p == '\\') + { + if (p == path || p[-1] == ':') + { + return TRUE; + } + } + p++; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +// Check if drive name +// +// Return next character of ':' if drive name +// Return head of path if no drive name +//--------------------------------------------------------------------------- + +const char *SkipDriveName(const char *path) +{ + const char *p = path; + + while (*p != '\0' && *p != '/' && *p != '\\') + { + if (*p == ':') + { + return p + 1; + } + p++; + } + return path; +} + + +//--------------------------------------------------------------------------- +// App Name Utilities +//--------------------------------------------------------------------------- +static char *appName; +static char *appBaseName; +static char *appFileName; + +void InitAppName(const char *path) +{ + char *slash_path = ChangeBackSlash(strdup(path)); + + appBaseName = GetBaseName(slash_path); + appFileName = GetFileName(slash_path); + appName = ChangeSuffix(appFileName, ""); + + free(slash_path); +} + +char *GetAppName(void) +{ + return appName; +} + +char *GetAppBaseName(void) +{ + return appBaseName; +} + +char *GetAppFileName(void) +{ + return appFileName; +} + + +#ifdef TEST +int main(int argc, char *argv[]) +{ + int i; + char *s; + + for (i = 1; i < argc; i++) + { + s = PathNormalize(argv[i], TRUE); + printf("[%s] -> [%s]\n", argv[i], s); + free(s); + } + return 0; +} +#endif diff --git a/build/tools/makenorfirm/path.h b/build/tools/makenorfirm/path.h new file mode 100644 index 00000000..e9956dc6 --- /dev/null +++ b/build/tools/makenorfirm/path.h @@ -0,0 +1,93 @@ +/*---------------------------------------------------------------------------* + Project: NitroSDK - tools - makebanner + File: path.h + + Copyright 2003-2006 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Log: path.h,v $ + Revision 1.3 2006/01/18 02:11:20 kitase_hirotake + do-indent + + Revision 1.2 2005/02/28 05:26:13 yosizaki + do-indent. + + Revision 1.1 2004/08/30 08:41:14 yasu + makebanner moves into CVS tree + + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#ifndef PATH_H_ +#define PATH_H_ + +#include // struct tat +#include "misc.h" + +#define DIRLEVEL_MAX 256 +#ifndef FILENAME_MAX +#define FILENAME_MAX 1024 +#endif + +typedef enum +{ + FILESTATUS_ERROR = -1, + FILESTATUS_FILE = 0, + FILESTATUS_DIR = 1 +} +tFileStatus; + + +// Item Reject Control + +typedef struct tWildCard +{ + struct tWildCard *next; + char *name; + +} +tWildCard; + + +// CallBacks + +typedef BOOL (*tCallBack) (char *, void *); + + +// Prototypes + +tFileStatus GetFileStatus(struct stat *s, const char *filename); +BOOL ForeachEntry(const char *pathName, tWildCard * reject, tCallBack callBack, void *param); +BOOL ForeachFile(const char *baseName, const char *fileName, tWildCard * reject, + tCallBack callBack, void *param); +BOOL ForeachPathGlobbing(const char *pathName, tCallBack callBack, void *param); +BOOL ForeachDirList(const char *dirName, tCallBack callBack, void *param); +int PathCmp(const char *path, const char *cmp); +char *PathCpy(char *dest, const char *src); +int PathLen(const char *path); +char *PathDup(const char *src); +char *PathGetDirLevelDown(const char *path); +char *GetBaseName(const char *path); +char *GetFileName(const char *path); +BOOL WildCardCmp(const char *wildcard, const char *path); +BOOL isPathWildCard(const char *path); +char *PathNormalize(const char *pathName, BOOL isTreatDotDot); +char *PathDenormalize(char *path); +char *GetSrcPath(const char *base, const char *file); +char *GetDestPath(const char *base, const char *file); +char *GetWin32Path(char *cygpath); +char *ChangeWin32Path(char *cygpath); +char *ChangeSuffix(const char *file, const char *suffix); +char *GetCurrentDirectory(void); +BOOL isAbsolutePath(const char *path); +const char *SkipDriveName(const char *path); +void InitAppName(const char *path); +char *GetAppName(void); +char *GetAppBaseName(void); +char *GetAppFileName(void); + +#endif //PATH_H_ diff --git a/build/tools/makenorfirm/test/Makefile b/build/tools/makenorfirm/test/Makefile new file mode 100644 index 00000000..992184a0 --- /dev/null +++ b/build/tools/makenorfirm/test/Makefile @@ -0,0 +1,58 @@ +#! make -f +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makenorfirm +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#--------------------------------------------------------------------------- + +SUBDIRS = wram_rbin \ + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +MAKENORFIRM = ../makenorfirm.exe + +MAKEFIRM_RSA_PRVKEY = ./rsa_private.der + +MAKEFIRM_ARM9 = ./twl_norfirm9_print.axf +MAKEFIRM_ARM7 = ./twl_norfirm7_print.axf +SDEPENDS_BIN += $(MAKEFIRM_ARM9) $(MAKEFIRM_ARM7) +MAKEFIRM_FLAGS += -d +MAKEFIRM_DEFS += -DFIRM_ROOT='$(FIRM_ROOT)' \ + -DMAKEFIRM_ARM9='$(basename $(MAKEFIRM_ARM9))' \ + -DMAKEFIRM_ARM7='$(basename $(MAKEFIRM_ARM7))' \ + -DMAKEFIRM_RSA_PRVKEY='$(MAKEFIRM_RSA_PRVKEY)' \ + +TARGET = test.srl + +%.srl: %.norsf $(MAKENORFIRM) $(MAKEFIRM_RSA_PRVKEY) + $(MAKENORFIRM) $(MAKEFIRM_FLAGS) $(MAKEFIRM_DEFS) $< $@ + +.PHONY: build install do-autotest clean clobber + +define ECHO_CURDIR + echo "==== $(CURDIR)"; +endef + +build: + @$(ECHO_CURDIR) + @$(MAKE) $(TARGET) + +install do-autotest: + @$(ECHO_CURDIR) + +clean clobber super-clobber: + @$(ECHO_CURDIR) + -rm -f $(TARGET) *~ + +test-utf16.bsf: icon.nbfc icon.nbfp diff --git a/build/tools/makenorfirm/test/rsa_private.der b/build/tools/makenorfirm/test/rsa_private.der new file mode 100644 index 00000000..ccf67c18 Binary files /dev/null and b/build/tools/makenorfirm/test/rsa_private.der differ diff --git a/build/tools/makenorfirm/test/test.norsf b/build/tools/makenorfirm/test/test.norsf new file mode 100644 index 00000000..7c3093af --- /dev/null +++ b/build/tools/makenorfirm/test/test.norsf @@ -0,0 +1,30 @@ +#NORSF --- Norfirm Spec File + +VERSION : 0x0 # GENERATE + +BOOT_NAND : TRUE # TRUE or FALSE + +RSA_KEY : rsa_private.der +OUT_KEY : rsa_public.sbin + +WRAM_RBIN: ./wram_rbin/wram_regs.rbin + +DECOMP_PROC : ARM9 # ARM9 or ARM7 + +ARM9_COMP : TRUE # TRUE or FALSE, should be before ARM9_SBIN +ARM9_SBIN : $(MAKEFIRM_ARM9).sbin +ARM9_ELF : $(MAKEFIRM_ARM9).axf + +ARM7_COMP : FALSE # TRUE or FALSE, should be before ARM7_SBIN +ARM7_SBIN : $(MAKEFIRM_ARM7).sbin +ARM7_ELF : $(MAKEFIRM_ARM7).axf + +BAUDRATE : 8M # 4M or 8M +ARM9_X2 : TRUE # TRUE or FALSE + +ENC_KEYINFO : 0x5043414d # 'MACP' +NCD_ROMOFS : 0x07fe00 + +ERROR : ARM7_HASH # SIGN, HEADER_HASH, ARM9_HASH, ARM7_HASH, HASH_TABLE_HASH or FINAL_HASH +ERROR : HEADER_FOOTER # for debug +ERROR : WL_CHECK # for debug diff --git a/build/tools/makenorfirm/test/twl_norfirm7_print.axf b/build/tools/makenorfirm/test/twl_norfirm7_print.axf new file mode 100644 index 00000000..b255bd21 Binary files /dev/null and b/build/tools/makenorfirm/test/twl_norfirm7_print.axf differ diff --git a/build/tools/makenorfirm/test/twl_norfirm7_print.sbin b/build/tools/makenorfirm/test/twl_norfirm7_print.sbin new file mode 100644 index 00000000..a4eeebce Binary files /dev/null and b/build/tools/makenorfirm/test/twl_norfirm7_print.sbin differ diff --git a/build/tools/makenorfirm/test/twl_norfirm9_print.axf b/build/tools/makenorfirm/test/twl_norfirm9_print.axf new file mode 100644 index 00000000..3d064b38 Binary files /dev/null and b/build/tools/makenorfirm/test/twl_norfirm9_print.axf differ diff --git a/build/tools/makenorfirm/test/twl_norfirm9_print.sbin b/build/tools/makenorfirm/test/twl_norfirm9_print.sbin new file mode 100644 index 00000000..cd305be4 Binary files /dev/null and b/build/tools/makenorfirm/test/twl_norfirm9_print.sbin differ diff --git a/build/tools/makenorfirm/test/wram_rbin/Makefile b/build/tools/makenorfirm/test/wram_rbin/Makefile new file mode 100644 index 00000000..8e7621d8 --- /dev/null +++ b/build/tools/makenorfirm/test/wram_rbin/Makefile @@ -0,0 +1,48 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlFirm - tools - norfirm-print +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- + +SUBDIRS = + +LINCLUDES = ../include + +#---------------------------------------------------------------------------- + +TARGET_BIN = wram_regs.rbin + +SRCS = \ + wram_regs.c \ + +#SRCDIR = # using default +#LCFILE = # using default + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_DIR = . +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN) + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/tools/makenorfirm/test/wram_rbin/wram_regs.c b/build/tools/makenorfirm/test/wram_rbin/wram_regs.c new file mode 100644 index 00000000..d2cdda90 --- /dev/null +++ b/build/tools/makenorfirm/test/wram_rbin/wram_regs.c @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include +#include + +MIHeader_WramRegs wram_regs = +{ + // ARM9 + { + REG_WRAM_A_BNK_PACK(0, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_0KB, TRUE), + REG_WRAM_A_BNK_PACK(1, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_64KB, TRUE), + REG_WRAM_A_BNK_PACK(2, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_128KB, TRUE), + REG_WRAM_A_BNK_PACK(3, MI_WRAM_A_ARM7, MI_WRAM_A_OFS_192KB, TRUE), + }, + { + REG_WRAM_B_BNK_PACK(0, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_0KB, TRUE), + REG_WRAM_B_BNK_PACK(1, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_32KB, TRUE), + REG_WRAM_B_BNK_PACK(2, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_64KB, TRUE), + REG_WRAM_B_BNK_PACK(3, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_96KB, TRUE), + REG_WRAM_B_BNK_PACK(4, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_128KB, TRUE), + REG_WRAM_B_BNK_PACK(5, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_160KB, TRUE), + REG_WRAM_B_BNK_PACK(6, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_192KB, TRUE), + REG_WRAM_B_BNK_PACK(7, MI_WRAM_B_ARM7, MI_WRAM_B_OFS_224KB, TRUE), + }, + { + REG_WRAM_C_BNK_PACK(0, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_0KB, TRUE), + REG_WRAM_C_BNK_PACK(1, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_32KB, TRUE), + REG_WRAM_C_BNK_PACK(2, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_64KB, TRUE), + REG_WRAM_C_BNK_PACK(3, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_96KB, TRUE), + REG_WRAM_C_BNK_PACK(4, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_128KB, TRUE), + REG_WRAM_C_BNK_PACK(5, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_160KB, TRUE), + REG_WRAM_C_BNK_PACK(6, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_192KB, TRUE), + REG_WRAM_C_BNK_PACK(7, MI_WRAM_C_ARM9, MI_WRAM_C_OFS_224KB, TRUE), + }, + REG_WRAM_A_MAP_PACK(MI_WRAM_MAP_NULL, + MI_WRAM_MAP_NULL, + MI_WRAM_A_IMG_128KB + ), + REG_WRAM_B_MAP_PACK(MI_WRAM_MAP_NULL, + MI_WRAM_MAP_NULL, + MI_WRAM_B_IMG_128KB + ), + REG_WRAM_C_MAP_PACK(HW_WRAM_AREA_HALF, + HW_WRAM_AREA_HALF + 0x00020000, + MI_WRAM_C_IMG_128KB + ), + + // ARM7 + REG_WRAM_A_MAP_PACK(HW_WRAM_AREA_HALF, + HW_WRAM_AREA_HALF + 0x00020000, + MI_WRAM_A_IMG_128KB + ), + REG_WRAM_B_MAP_PACK(HW_WRAM_AREA_HALF + 0x00020000, + HW_WRAM_AREA_HALF + 0x00040000, + MI_WRAM_B_IMG_128KB + ), + REG_WRAM_C_MAP_PACK(MI_WRAM_MAP_NULL, + MI_WRAM_MAP_NULL, + MI_WRAM_C_IMG_128KB + ), + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + MI_WRAM_ARM7_ALL, + + // VRAM-C + 7, + // VRAM-D + 7, +}; diff --git a/build/tools/makenorfirm/wram_regs.c b/build/tools/makenorfirm/wram_regs.c new file mode 100644 index 00000000..68ed4689 --- /dev/null +++ b/build/tools/makenorfirm/wram_regs.c @@ -0,0 +1,96 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - tools - makenorfirm + File: wram_regs.c + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#include "format_rom.h" +//#define SDK_ASM +#define NITRO_TYPES_H_ +#include +#include +#include + + +MIHeader_WramRegs wram_regs_init = +{ + // ARM9 + { + REG_MI_MBK_A0_FIELD( 1, MI_WRAM_A_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_A1_FIELD( 1, MI_WRAM_A_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_A2_FIELD( 1, MI_WRAM_A_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_A3_FIELD( 1, MI_WRAM_A_OFFSET_192KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_B0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM7 ), + REG_MI_MBK_B4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM7 ), + REG_MI_MBK_B7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM7 ), + }, + { + REG_MI_MBK_C0_FIELD( 1, MI_WRAM_BC_OFFSET_0KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C1_FIELD( 1, MI_WRAM_BC_OFFSET_32KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C2_FIELD( 1, MI_WRAM_BC_OFFSET_64KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C3_FIELD( 1, MI_WRAM_BC_OFFSET_96KB , MI_WRAM_ARM9 ), + REG_MI_MBK_C4_FIELD( 1, MI_WRAM_BC_OFFSET_128KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C5_FIELD( 1, MI_WRAM_BC_OFFSET_160KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C6_FIELD( 1, MI_WRAM_BC_OFFSET_192KB, MI_WRAM_ARM9 ), + REG_MI_MBK_C7_FIELD( 1, MI_WRAM_BC_OFFSET_224KB, MI_WRAM_ARM9 ), + }, + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, MI_WRAM_MAP_NULL ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, HW_WRAM_AREA_HALF + 0x00020000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, HW_WRAM_AREA_HALF ) + ), + + // ARM7 + REG_MI_MBK6_FIELD( REG_WRAM_MAP_CONV_ADDR( 6, A, EADDR, HW_WRAM_AREA_HALF + 0x00020000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 6, A, SADDR, HW_WRAM_AREA_HALF ) + ), + REG_MI_MBK7_FIELD( REG_WRAM_MAP_CONV_ADDR( 7, B, EADDR, HW_WRAM_AREA_HALF + 0x00040000 ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 7, B, SADDR, HW_WRAM_AREA_HALF + 0x00020000 ) + ), + REG_MI_MBK8_FIELD( REG_WRAM_MAP_CONV_ADDR( 8, C, EADDR, MI_WRAM_MAP_NULL ), + MI_WRAM_IMAGE_128KB, + REG_WRAM_MAP_CONV_ADDR( 8, C, SADDR, MI_WRAM_MAP_NULL ) + ), + + // WRAM Lock + { + 0, + 0, + 0, + }, + + // WRAM-0/1 + 3, + + // VRAM-C + 7, + // VRAM-D + 7, +}; + diff --git a/build/tools/makerom.TWL.shop/Makefile b/build/tools/makerom.TWL.shop/Makefile new file mode 100644 index 00000000..bde8028a --- /dev/null +++ b/build/tools/makerom.TWL.shop/Makefile @@ -0,0 +1,150 @@ +#! make -f +#--------------------------------------------------------------------------- +# Project: TwlSDK - tools - makerom.TWL +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#--------------------------------------------------------------------------- +TARGET_PLATFORM = TWL + +TARGET_FIRM = SYSTEMMENU + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +SRCDIR = $(ROOT)/build/tools/makerom.TWL +INCDIR = $(SRCDIR) + +#SUBDIRS = $(addprefix $(SRCDIR)/,acsign aes digest) + +TARGETS = makerom.TWL.shop.exe + +SOURCES_C = makerom.c \ + optarg.c \ + misc.c \ + path.c \ + defval.c \ + container.c \ + spec_rom.c \ + spec_proc.c \ + spec_property.c \ + spec_nandAppProperty.c \ + spec_segment.c \ + file_sort.c \ + file_offset.c \ + out_romheader.c \ + out_filename.c \ + out_overlaytable.c \ + out_listfile.c \ + out_romimage.c \ + calc_digest_size.c \ + set_digest.c \ + set_signature.c \ + encrypt_aes.c \ + get_moduleParam.c + +SOURCES = $(addprefix $(SRCDIR)/,$(SOURCES_C) spec.l spec.y ) ca_keys_shop_dev.c +DEPEND_TARGETS = $(addprefix $(SRCDIR)/,$(SOURCES_C)) ca_keys_shop_dev.c +OBJECTS = $(SOURCES_C:.c=.o) spec.tab.o spec.yy.patched.o ca_keys_shop_dev.o + +HEADERS_H = container.h \ + format_nlist.h \ + makerom.h \ + path.h \ + spec_proc.h \ + spec_rom.h \ + defval.h \ + format_rom_private.h \ + misc.h \ + optarg.h \ + spec_property.h + +HEADERS = $(addprefix $(INCDIR)/,$(HEADERS_H)) + +LIBACSIGN = $(SRCDIR)/acsign/lib/X86/libacsign_x86.a +LIBAES = $(SRCDIR)/aes/lib/X86/libaes_x86.a +LIBDIGEST = $(SRCDIR)/digest/lib/X86/libdigest_x86.a + +#NITRO_DIGEST_DIR = $(NITRO_ADDINS)/digest/build/libraries/dgt +#MACROS += -I$(NITRO_DIGEST_DIR)/include \ +# -I$(NITRO_DIGEST_DIR)/src +MACROS = -I$(ROOT)/build/tools/makerom.TWL \ + -I$(ROOT)/include \ + -I$(ROOT)/include/twl/os/common \ + -I$(ROOT)/include/nitro/os/ARM9 + +#INSTALL_DIR = $(TWL_INSTALL_TOOLSDIR)/bin +#INSTALL_TARGETS = $(TARGETS) rom_header.template.sbin +INSTALL_DIR = $(SYSMENU_INSTALL_TOOLSDIR)/bin +INSTALL_TARGETS = $(TARGETS) + +LDIRT_CLEAN = $(OBJECTS) $(TARGETS) version.h \ + spec.tab.c spec.tab.h spec.yy.c \ + spec.yy.patched.c \ + depend.inc + +include $(TWLSDK_ROOT)/build/buildtools/twl/modulerules.x86 + + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): version.h $(OBJECTS) $(LIBACSIGN) $(LIBAES) $(LIBDIGEST) + $(CC_X86) $+ -o $@ + +spec.yy.c : $(SRCDIR)/spec.l +spec.tab.c : $(SRCDIR)/spec.y + +spec.yy.patched.o : WARNING += -Wno-unused-label -Wno-unused-function +spec.yy.patched.c : $(SRCDIR)/spec.yy.c + sed 's/^#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (1024*1024)/' $< > $@ + +makerom.o: version.h + +version.h: $(SOURCES) $(HEADERS) $(MAKEFILE) + @for i in $^ ; \ + do \ + date -r $$i +'#define SDK_DATE_OF_LATEST_FILE %Y%m%dUL'; \ + done | sort | tail -1 > $@ + + + +%.o: $(SRCDIR)/%.c +ifdef SILENT + echo $(MSG_COMPILE) $(notdir $<) +endif + $(COMPILE_C) + +%.o: $(SRCDIR)/%.cpp +ifdef SILENT + echo $(MSG_COMPILE) $(notdir $<) +endif + $(COMPILE_CXX) + +%.yy.c: $(SRCDIR)/%.l + $(LEX) -P$(basename $<)_yy -o$@ $< + +%.tab.c: $(SRCDIR)/%.y + $(YACC) -d -p $(notdir $(basename $<))_yy -b $(notdir $(basename $<)) $< + +%.tab.h: %.tab.c; + + +depend.inc: version.h $(DEPEND_TARGETS) + -@ $(RM) depend.inc + -@ for i in $(DEPEND_TARGETS); do\ + $(CC_X86) $(MACROS) -MM -w -DSDK_WIN32 $(WARNING) -I. -c -I$(TWL_INCDIR) $$i >> depend.inc;\ + done + +-include depend.inc diff --git a/build/tools/makerom.TWL.shop/ca_keys_shop_dev.c b/build/tools/makerom.TWL.shop/ca_keys_shop_dev.c new file mode 100644 index 00000000..2451f2d8 --- /dev/null +++ b/build/tools/makerom.TWL.shop/ca_keys_shop_dev.c @@ -0,0 +1,96 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - makerom.TWL + File: ca_keys.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 "misc.h" +#include "aes/include/aes2.h" + + +// JpVbvAv@ROMwb_pJ +const u8 g_devPubKey_DER[ 0xa2 ] = { + 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, + 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xA7, 0x9F, 0x54, + 0xA0, 0xC7, 0x45, 0xAE, 0xF6, 0x63, 0xA7, 0x53, 0xB7, 0x0A, 0xCC, 0x0B, 0xCB, 0x65, 0xE1, 0x11, + 0xC6, 0x05, 0x15, 0xB5, 0x6E, 0xBD, 0xAC, 0x0C, 0xCA, 0xF4, 0x7C, 0x68, 0x7A, 0xF9, 0x0E, 0x5D, + 0x98, 0x5B, 0xC8, 0x4D, 0x22, 0x3B, 0xA3, 0xBE, 0x8B, 0x5B, 0x7F, 0x26, 0x44, 0x9F, 0xC4, 0x48, + 0x44, 0xB1, 0x32, 0xB7, 0xBE, 0x63, 0xBA, 0xD6, 0xC1, 0x10, 0xCE, 0xF6, 0xED, 0x47, 0x8F, 0xE1, + 0xFF, 0x7F, 0x5A, 0xD5, 0x5D, 0x94, 0x38, 0x2F, 0xA1, 0xD4, 0xEF, 0x82, 0xB1, 0x0D, 0xC4, 0x43, + 0xEC, 0xBE, 0x77, 0xB6, 0x82, 0x9C, 0xFA, 0x17, 0x87, 0x84, 0x82, 0x25, 0x46, 0xFB, 0xD6, 0x05, + 0xC8, 0x9A, 0x7E, 0xAD, 0x44, 0x40, 0x0D, 0x35, 0x9C, 0x45, 0x44, 0x64, 0x36, 0x61, 0x4B, 0xF7, + 0xE6, 0x31, 0x5C, 0x7D, 0x96, 0x73, 0xE8, 0xAC, 0xB4, 0xE3, 0x5E, 0xD1, 0x9D, 0x02, 0x03, 0x01, + 0x00, 0x01, +}; + +// JpVbvAv@ROMwb_p閧 +const u8 g_devPrivKey_DER[ 0x263 ] = { + 0x30, 0x82, 0x02, 0x5D, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xA7, 0x9F, 0x54, 0xA0, 0xC7, + 0x45, 0xAE, 0xF6, 0x63, 0xA7, 0x53, 0xB7, 0x0A, 0xCC, 0x0B, 0xCB, 0x65, 0xE1, 0x11, 0xC6, 0x05, + 0x15, 0xB5, 0x6E, 0xBD, 0xAC, 0x0C, 0xCA, 0xF4, 0x7C, 0x68, 0x7A, 0xF9, 0x0E, 0x5D, 0x98, 0x5B, + 0xC8, 0x4D, 0x22, 0x3B, 0xA3, 0xBE, 0x8B, 0x5B, 0x7F, 0x26, 0x44, 0x9F, 0xC4, 0x48, 0x44, 0xB1, + 0x32, 0xB7, 0xBE, 0x63, 0xBA, 0xD6, 0xC1, 0x10, 0xCE, 0xF6, 0xED, 0x47, 0x8F, 0xE1, 0xFF, 0x7F, + 0x5A, 0xD5, 0x5D, 0x94, 0x38, 0x2F, 0xA1, 0xD4, 0xEF, 0x82, 0xB1, 0x0D, 0xC4, 0x43, 0xEC, 0xBE, + 0x77, 0xB6, 0x82, 0x9C, 0xFA, 0x17, 0x87, 0x84, 0x82, 0x25, 0x46, 0xFB, 0xD6, 0x05, 0xC8, 0x9A, + 0x7E, 0xAD, 0x44, 0x40, 0x0D, 0x35, 0x9C, 0x45, 0x44, 0x64, 0x36, 0x61, 0x4B, 0xF7, 0xE6, 0x31, + 0x5C, 0x7D, 0x96, 0x73, 0xE8, 0xAC, 0xB4, 0xE3, 0x5E, 0xD1, 0x9D, 0x02, 0x03, 0x01, 0x00, 0x01, + 0x02, 0x81, 0x80, 0x48, 0xCA, 0x9C, 0x49, 0xA5, 0xBF, 0xD1, 0x17, 0x16, 0x77, 0x97, 0x97, 0x29, + 0x8D, 0x2A, 0xA2, 0x0D, 0x80, 0x0B, 0xE3, 0xDE, 0x59, 0x6B, 0x0C, 0xC8, 0x39, 0x6A, 0xE4, 0xC7, + 0xFF, 0x2E, 0xB0, 0x18, 0x6F, 0xF0, 0x9D, 0x35, 0x5E, 0x6A, 0x80, 0xAF, 0x3D, 0x90, 0x85, 0x9C, + 0x1A, 0x3F, 0x58, 0x15, 0xB9, 0x7B, 0x58, 0xB9, 0x4A, 0xB9, 0x18, 0x68, 0xDE, 0xBE, 0x5B, 0xE1, + 0x1C, 0xBF, 0x85, 0xDF, 0x5F, 0x30, 0xFD, 0xD2, 0xEC, 0xC0, 0x77, 0x33, 0x62, 0x58, 0xEC, 0xC1, + 0x47, 0xF7, 0x41, 0xE8, 0x2B, 0x21, 0x83, 0xE0, 0x8E, 0xE0, 0xF4, 0x03, 0x5D, 0x07, 0x84, 0x91, + 0xFA, 0x5B, 0xD8, 0xD3, 0x47, 0x90, 0x6E, 0x7D, 0x81, 0x9C, 0x1A, 0xB3, 0x03, 0x2F, 0xBC, 0x1A, + 0x28, 0x01, 0xBB, 0x78, 0x33, 0x60, 0xD2, 0x32, 0x34, 0x09, 0xEE, 0x08, 0x35, 0x50, 0x7A, 0x02, + 0x77, 0xB9, 0x01, 0x02, 0x41, 0x00, 0xCF, 0x39, 0xB3, 0x95, 0xDB, 0x1A, 0x2C, 0xD5, 0x6B, 0x0E, + 0xD8, 0x7B, 0xEC, 0x36, 0x14, 0xC5, 0x6C, 0x6C, 0x03, 0x34, 0xCB, 0x8A, 0x03, 0xF0, 0x94, 0x9C, + 0x2E, 0xBB, 0xA4, 0x24, 0x85, 0x6F, 0x3C, 0x8B, 0xAD, 0x44, 0x88, 0xA1, 0xDC, 0x88, 0xFE, 0xE7, + 0x02, 0x24, 0xB3, 0x73, 0xEA, 0xD1, 0xF6, 0x61, 0x6A, 0x73, 0x00, 0x86, 0x0B, 0x67, 0xAB, 0x00, + 0xFB, 0xF7, 0xFD, 0x0D, 0x92, 0x91, 0x02, 0x41, 0x00, 0xCF, 0x13, 0x5C, 0xD1, 0x72, 0x12, 0xA5, + 0x1D, 0x3A, 0x86, 0xAB, 0xAC, 0x87, 0x11, 0x37, 0x6D, 0xEB, 0x90, 0x14, 0x41, 0x7B, 0xAA, 0x38, + 0x88, 0xFF, 0xAF, 0xAA, 0xAE, 0x12, 0x3E, 0x7C, 0x28, 0x59, 0xDB, 0xBE, 0xAE, 0x79, 0x20, 0x0C, + 0x4F, 0xE5, 0xAB, 0x97, 0x64, 0x0D, 0x1E, 0x31, 0x54, 0x10, 0xB0, 0x1C, 0x7E, 0x5A, 0x7B, 0x98, + 0x32, 0x00, 0xF7, 0xE0, 0x18, 0x15, 0x53, 0xFC, 0x4D, 0x02, 0x41, 0x00, 0x90, 0x5F, 0x38, 0x01, + 0xD0, 0x9B, 0x44, 0xDF, 0x0F, 0x6E, 0x51, 0x5E, 0xCC, 0xEB, 0xC4, 0xBE, 0xE2, 0xD1, 0xC1, 0xCE, + 0x17, 0x7C, 0x39, 0x50, 0x74, 0x88, 0xF7, 0x7A, 0x1D, 0x5A, 0xA0, 0x68, 0x26, 0x3B, 0x7D, 0xE4, + 0xC0, 0x78, 0x5C, 0x68, 0x49, 0x86, 0xF2, 0x14, 0x55, 0xBE, 0x0D, 0xBC, 0x68, 0x35, 0xE8, 0x6E, + 0xE4, 0xCF, 0x7E, 0xC4, 0xA3, 0xFB, 0xD4, 0x90, 0x2A, 0x8A, 0x39, 0x31, 0x02, 0x41, 0x00, 0x93, + 0x88, 0xE3, 0x17, 0xA2, 0xA3, 0xA0, 0x1A, 0x4C, 0x09, 0x89, 0x24, 0xD9, 0xF2, 0xAD, 0x40, 0x56, + 0x96, 0x07, 0xA8, 0x84, 0x18, 0x4A, 0x41, 0x69, 0x92, 0x5A, 0x13, 0xBD, 0x91, 0xE1, 0x59, 0xCA, + 0x73, 0xE2, 0xCE, 0x62, 0x24, 0x30, 0x41, 0x78, 0x8C, 0x21, 0xC7, 0xBA, 0x04, 0xE9, 0xF6, 0x50, + 0x11, 0x79, 0xAB, 0x98, 0x81, 0xF8, 0x74, 0x9F, 0xF5, 0xFB, 0x26, 0x8D, 0x83, 0x91, 0xFD, 0x02, + 0x40, 0x4D, 0xA4, 0x03, 0x7E, 0x00, 0xB6, 0xA2, 0xEE, 0x85, 0x19, 0x5C, 0xB3, 0xBE, 0x06, 0x48, + 0xF7, 0xA8, 0x27, 0xB3, 0xC9, 0xED, 0x60, 0xE1, 0x56, 0x0A, 0x3F, 0x8D, 0x64, 0x56, 0xBA, 0x2E, + 0xC3, 0xF6, 0x2D, 0x95, 0x38, 0x87, 0x58, 0xD6, 0x95, 0xF7, 0xA6, 0xD6, 0xEE, 0x85, 0x7D, 0xD7, + 0x93, 0x80, 0xF5, 0x1D, 0xBF, 0x5F, 0x3E, 0x3A, 0x22, 0x29, 0x18, 0xE5, 0x95, 0x73, 0x0D, 0xEA, + 0x42, +}; + + +// iAvROMwb_pJ ̌͋UȂ̂ŒӁII +const u8 g_caPubKey_DER[ 0xa2 ] = { + 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, + 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xdf, 0x56, 0x30, + 0xc9, 0xae, 0x05, 0x55, 0xe8, 0xdf, 0xbe, 0xe6, 0xb9, 0x30, 0xb9, 0x76, 0x93, 0xb4, 0xc2, 0x20, + 0xe7, 0xae, 0x4c, 0x3e, 0xc3, 0xed, 0x27, 0xcf, 0x5d, 0x4f, 0xb5, 0x7d, 0xde, 0x38, 0xbc, 0xfe, + 0x25, 0x32, 0xd8, 0x23, 0x98, 0x52, 0xb5, 0xda, 0xf7, 0x39, 0xdc, 0xb3, 0x0a, 0x94, 0x7a, 0x2b, + 0x79, 0xe6, 0xe0, 0x4c, 0xbc, 0x21, 0xbd, 0x59, 0xb2, 0xc7, 0xf1, 0xc0, 0xf1, 0xfb, 0x29, 0x75, + 0xa1, 0x21, 0x93, 0x01, 0x29, 0x1c, 0x9a, 0xe1, 0x2d, 0x55, 0xfc, 0x7b, 0xb8, 0xcb, 0x07, 0x33, + 0xc5, 0x91, 0x0d, 0xc8, 0x45, 0x59, 0xef, 0xbe, 0x58, 0xc7, 0xc1, 0x1d, 0xd5, 0xf2, 0xcf, 0x1f, + 0xe0, 0x6d, 0x21, 0x00, 0xcd, 0x42, 0xd8, 0x84, 0x85, 0xe3, 0xb2, 0x02, 0x1a, 0xa5, 0x89, 0x02, + 0xa1, 0x96, 0xc6, 0xf7, 0x61, 0x68, 0x66, 0xe6, 0x65, 0x12, 0xb7, 0xf1, 0x49, 0x02, 0x03, 0x01, + 0x00, 0x01, +}; + diff --git a/build/tools/makerom.TWL.sys/Makefile b/build/tools/makerom.TWL.sys/Makefile new file mode 100644 index 00000000..d4d8dbd3 --- /dev/null +++ b/build/tools/makerom.TWL.sys/Makefile @@ -0,0 +1,150 @@ +#! make -f +#--------------------------------------------------------------------------- +# Project: TwlSDK - tools - makerom.TWL +# File: Makefile +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#--------------------------------------------------------------------------- +TARGET_PLATFORM = TWL + +TARGET_FIRM = SYSTEMMENU + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +SRCDIR = $(ROOT)/build/tools/makerom.TWL +INCDIR = $(SRCDIR) + +#SUBDIRS = $(addprefix $(SRCDIR)/,acsign aes digest) + +TARGETS = makerom.TWL.sys.exe + +SOURCES_C = makerom.c \ + optarg.c \ + misc.c \ + path.c \ + defval.c \ + container.c \ + spec_rom.c \ + spec_proc.c \ + spec_property.c \ + spec_nandAppProperty.c \ + spec_segment.c \ + file_sort.c \ + file_offset.c \ + out_romheader.c \ + out_filename.c \ + out_overlaytable.c \ + out_listfile.c \ + out_romimage.c \ + calc_digest_size.c \ + set_digest.c \ + set_signature.c \ + encrypt_aes.c \ + get_moduleParam.c + +SOURCES = $(addprefix $(SRCDIR)/,$(SOURCES_C) spec.l spec.y ) ca_keys_sys_dev.c +DEPEND_TARGETS = $(addprefix $(SRCDIR)/,$(SOURCES_C)) ca_keys_sys_dev.c +OBJECTS = $(SOURCES_C:.c=.o) spec.tab.o spec.yy.patched.o ca_keys_sys_dev.o + +HEADERS_H = container.h \ + format_nlist.h \ + makerom.h \ + path.h \ + spec_proc.h \ + spec_rom.h \ + defval.h \ + format_rom_private.h \ + misc.h \ + optarg.h \ + spec_property.h + +HEADERS = $(addprefix $(INCDIR)/,$(HEADERS_H)) + +LIBACSIGN = $(SRCDIR)/acsign/lib/X86/libacsign_x86.a +LIBAES = $(SRCDIR)/aes/lib/X86/libaes_x86.a +LIBDIGEST = $(SRCDIR)/digest/lib/X86/libdigest_x86.a + +#NITRO_DIGEST_DIR = $(NITRO_ADDINS)/digest/build/libraries/dgt +#MACROS += -I$(NITRO_DIGEST_DIR)/include \ +# -I$(NITRO_DIGEST_DIR)/src +MACROS = -I$(ROOT)/build/tools/makerom.TWL \ + -I$(ROOT)/include \ + -I$(ROOT)/include/twl/os/common \ + -I$(ROOT)/include/nitro/os/ARM9 + +#INSTALL_DIR = $(TWL_INSTALL_TOOLSDIR)/bin +#INSTALL_TARGETS = $(TARGETS) rom_header.template.sbin +INSTALL_DIR = $(SYSMENU_INSTALL_TOOLSDIR)/bin +INSTALL_TARGETS = $(TARGETS) + +LDIRT_CLEAN = $(OBJECTS) $(TARGETS) version.h \ + spec.tab.c spec.tab.h spec.yy.c \ + spec.yy.patched.c \ + depend.inc + +include $(TWLSDK_ROOT)/build/buildtools/twl/modulerules.x86 + + +#---------------------------------------------------------------------------- +# build +#---------------------------------------------------------------------------- +do-build: $(TARGETS) + +$(TARGETS): version.h $(OBJECTS) $(LIBACSIGN) $(LIBAES) $(LIBDIGEST) + $(CC_X86) $+ -o $@ + +spec.yy.c : $(SRCDIR)/spec.l +spec.tab.c : $(SRCDIR)/spec.y + +spec.yy.patched.o : WARNING += -Wno-unused-label -Wno-unused-function +spec.yy.patched.c : $(SRCDIR)/spec.yy.c + sed 's/^#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (1024*1024)/' $< > $@ + +makerom.o: version.h + +version.h: $(SOURCES) $(HEADERS) $(MAKEFILE) + @for i in $^ ; \ + do \ + date -r $$i +'#define SDK_DATE_OF_LATEST_FILE %Y%m%dUL'; \ + done | sort | tail -1 > $@ + + +%.o: $(SRCDIR)/%.c +ifdef SILENT + echo $(MSG_COMPILE) $(notdir $<) +endif + $(COMPILE_C) + +%.o: $(SRCDIR)/%.cpp +ifdef SILENT + echo $(MSG_COMPILE) $(notdir $<) +endif + $(COMPILE_CXX) + +%.yy.c: $(SRCDIR)/%.l + $(LEX) -P$(basename $<)_yy -o$@ $< + +%.tab.c: $(SRCDIR)/%.y + $(YACC) -d -p $(notdir $(basename $<))_yy -b $(notdir $(basename $<)) $< + +%.tab.h: %.tab.c; + + +depend.inc: version.h $(DEPEND_TARGETS) + -@ $(RM) depend.inc + -@ for i in $(DEPEND_TARGETS); do\ + $(CC_X86) $(MACROS) -MM -w -DSDK_WIN32 $(WARNING) -I. -c -I$(TWL_INCDIR) $$i >> depend.inc;\ + done + +-include depend.inc + diff --git a/build/tools/makerom.TWL.sys/ca_keys_sys_dev.c b/build/tools/makerom.TWL.sys/ca_keys_sys_dev.c new file mode 100644 index 00000000..e08c7cd2 --- /dev/null +++ b/build/tools/makerom.TWL.sys/ca_keys_sys_dev.c @@ -0,0 +1,96 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - tools - makerom.TWL + File: ca_keys.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 "misc.h" +#include "aes/include/aes2.h" + + +// JpVXeAv@ROMwb_pJ +const u8 g_devPubKey_DER[ 0xa2 ] = { + 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, + 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xE9, 0x9E, 0xA7, + 0x9F, 0x59, 0x4D, 0xF4, 0xA7, 0x60, 0x04, 0xBD, 0x47, 0xF2, 0xB3, 0x64, 0xCD, 0x16, 0x79, 0xC1, + 0x47, 0x39, 0xF6, 0xA9, 0xF8, 0xEE, 0x1A, 0xD0, 0x72, 0xCF, 0x43, 0x97, 0x0C, 0x93, 0xA1, 0x38, + 0x4E, 0x13, 0x40, 0x6C, 0x10, 0x59, 0x43, 0xE2, 0x71, 0x29, 0x54, 0x14, 0x2C, 0xC5, 0xDA, 0x59, + 0x4D, 0xB4, 0x6A, 0xEF, 0x85, 0x61, 0x6F, 0x7F, 0x1C, 0x59, 0x34, 0x2C, 0xC6, 0x24, 0xF3, 0x7B, + 0xC3, 0xB7, 0x40, 0xD1, 0x46, 0xF8, 0x90, 0xB7, 0xC2, 0x98, 0x50, 0xAF, 0x95, 0x52, 0x42, 0xDB, + 0xAC, 0xD6, 0x7E, 0xA9, 0xC3, 0x3D, 0x1B, 0x51, 0x56, 0x07, 0x06, 0xD0, 0x0B, 0x01, 0xBB, 0x58, + 0x93, 0xEA, 0xA0, 0x2C, 0xC7, 0x7D, 0x6A, 0x31, 0x7E, 0xC9, 0xE2, 0xDA, 0xFE, 0x1F, 0x2E, 0x9D, + 0xA7, 0x54, 0x84, 0xDC, 0x28, 0xB9, 0x18, 0xEA, 0x16, 0xF2, 0x95, 0x55, 0x6D, 0x02, 0x03, 0x01, + 0x00, 0x01, +}; + +// JpVXeAv@ROMwb_p閧 +const u8 g_devPrivKey_DER[ 0x263 ] = { + 0x30, 0x82, 0x02, 0x5E, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xE9, 0x9E, 0xA7, 0x9F, 0x59, + 0x4D, 0xF4, 0xA7, 0x60, 0x04, 0xBD, 0x47, 0xF2, 0xB3, 0x64, 0xCD, 0x16, 0x79, 0xC1, 0x47, 0x39, + 0xF6, 0xA9, 0xF8, 0xEE, 0x1A, 0xD0, 0x72, 0xCF, 0x43, 0x97, 0x0C, 0x93, 0xA1, 0x38, 0x4E, 0x13, + 0x40, 0x6C, 0x10, 0x59, 0x43, 0xE2, 0x71, 0x29, 0x54, 0x14, 0x2C, 0xC5, 0xDA, 0x59, 0x4D, 0xB4, + 0x6A, 0xEF, 0x85, 0x61, 0x6F, 0x7F, 0x1C, 0x59, 0x34, 0x2C, 0xC6, 0x24, 0xF3, 0x7B, 0xC3, 0xB7, + 0x40, 0xD1, 0x46, 0xF8, 0x90, 0xB7, 0xC2, 0x98, 0x50, 0xAF, 0x95, 0x52, 0x42, 0xDB, 0xAC, 0xD6, + 0x7E, 0xA9, 0xC3, 0x3D, 0x1B, 0x51, 0x56, 0x07, 0x06, 0xD0, 0x0B, 0x01, 0xBB, 0x58, 0x93, 0xEA, + 0xA0, 0x2C, 0xC7, 0x7D, 0x6A, 0x31, 0x7E, 0xC9, 0xE2, 0xDA, 0xFE, 0x1F, 0x2E, 0x9D, 0xA7, 0x54, + 0x84, 0xDC, 0x28, 0xB9, 0x18, 0xEA, 0x16, 0xF2, 0x95, 0x55, 0x6D, 0x02, 0x03, 0x01, 0x00, 0x01, + 0x02, 0x81, 0x81, 0x00, 0xCF, 0x67, 0xAA, 0x3B, 0x1F, 0x26, 0xC5, 0x68, 0x7F, 0x27, 0x55, 0xFF, + 0xF5, 0x29, 0x6C, 0xF9, 0x62, 0xD5, 0xCF, 0x50, 0xF3, 0xD5, 0xD8, 0x4B, 0x06, 0xE0, 0xC9, 0x64, + 0xD4, 0x3B, 0x96, 0x73, 0x74, 0xF1, 0x71, 0xB2, 0x67, 0x07, 0x0F, 0xA9, 0x68, 0x06, 0x8B, 0x97, + 0x99, 0x70, 0x6A, 0xC4, 0xE1, 0x16, 0x9B, 0xA8, 0x0F, 0xDF, 0xCC, 0x2B, 0xE7, 0x37, 0xFC, 0x6A, + 0x67, 0x8B, 0x99, 0x9E, 0xD1, 0xDA, 0xCC, 0x68, 0xFC, 0xEB, 0x8D, 0xFE, 0x42, 0x84, 0x72, 0x88, + 0x05, 0xAF, 0x23, 0x32, 0x30, 0x1F, 0xFA, 0xCC, 0x67, 0x52, 0x93, 0x6C, 0xC1, 0x0A, 0xCF, 0xD6, + 0xD3, 0x5F, 0x75, 0xE9, 0x4D, 0x32, 0xC0, 0x31, 0x1B, 0xD4, 0xB5, 0x4B, 0xB4, 0x4E, 0xB0, 0x3E, + 0xD5, 0x6C, 0x3C, 0xDC, 0x57, 0xBB, 0x32, 0x24, 0x41, 0x9C, 0x79, 0xBE, 0xFC, 0xC0, 0x3B, 0x63, + 0x0C, 0x5D, 0xC6, 0xE5, 0x02, 0x41, 0x00, 0xF6, 0x77, 0x12, 0x72, 0x63, 0xD0, 0x9B, 0x22, 0xC6, + 0x4F, 0x19, 0x1E, 0x2A, 0xE1, 0x97, 0xCF, 0x28, 0xD3, 0xC3, 0x5E, 0xFB, 0x22, 0x57, 0xE5, 0x4F, + 0x90, 0x83, 0x53, 0xB0, 0x80, 0xD3, 0x2D, 0xFB, 0x77, 0x55, 0x52, 0x5E, 0x00, 0xD8, 0x72, 0x39, + 0x93, 0xF0, 0x89, 0x83, 0x97, 0xFB, 0x78, 0xD2, 0xB0, 0xCD, 0xED, 0x1C, 0x9B, 0x8F, 0x5D, 0xBD, + 0x00, 0x26, 0x37, 0xA1, 0xE5, 0x38, 0xE7, 0x02, 0x41, 0x00, 0xF2, 0xA8, 0x5D, 0x86, 0xE0, 0x33, + 0xC8, 0x93, 0x5C, 0xB9, 0xBD, 0xCF, 0x27, 0x70, 0x81, 0x79, 0xE1, 0x12, 0x82, 0x09, 0x64, 0xCB, + 0xDB, 0xCF, 0xBB, 0x52, 0xD3, 0x3F, 0x22, 0x90, 0x47, 0x23, 0xAA, 0x20, 0x7D, 0x92, 0xFD, 0xD6, + 0x58, 0x68, 0xF3, 0xB1, 0xFA, 0x7B, 0x81, 0x0D, 0x8F, 0x22, 0xDC, 0x84, 0x08, 0x91, 0x60, 0x07, + 0xE8, 0x98, 0x9A, 0x84, 0xDA, 0x4C, 0x24, 0xC7, 0x10, 0x8B, 0x02, 0x41, 0x00, 0xB3, 0xB0, 0xAA, + 0x75, 0x55, 0xCA, 0x90, 0x60, 0xB1, 0x1E, 0x98, 0x1C, 0x83, 0x7D, 0x08, 0x36, 0x53, 0xF8, 0xD8, + 0x77, 0x16, 0x37, 0xBA, 0xC7, 0x87, 0xD3, 0xBF, 0xBB, 0xB3, 0x72, 0xA9, 0x04, 0xDC, 0x52, 0xEB, + 0x94, 0xEA, 0xCE, 0x49, 0x00, 0x36, 0x74, 0x62, 0xA9, 0x8F, 0x94, 0xAE, 0x16, 0x2F, 0xDE, 0x11, + 0xB4, 0xEE, 0xE7, 0x87, 0x85, 0xFB, 0x36, 0xF1, 0xA6, 0x1B, 0xD5, 0xC8, 0x3F, 0x02, 0x40, 0x73, + 0x18, 0x72, 0xCC, 0x1F, 0x99, 0xD0, 0x40, 0x3D, 0x52, 0x08, 0x7A, 0xB2, 0x5D, 0x45, 0xBC, 0x76, + 0x8A, 0x1D, 0xCD, 0xB0, 0xD6, 0x94, 0xDB, 0x32, 0x21, 0xB5, 0xFB, 0x13, 0x3C, 0xD5, 0xD1, 0x4F, + 0xC7, 0x7B, 0x68, 0x76, 0x27, 0xED, 0xE5, 0x51, 0xF9, 0x90, 0x32, 0x76, 0x62, 0xE5, 0x0A, 0x87, + 0x07, 0xC5, 0x3C, 0x97, 0x0D, 0x09, 0x41, 0x20, 0xC1, 0x74, 0xFD, 0x7A, 0xD0, 0x44, 0xC3, 0x02, + 0x41, 0x00, 0xAF, 0xA3, 0x2C, 0x53, 0x8E, 0x8E, 0xA8, 0xE7, 0x36, 0xC0, 0x5C, 0x9E, 0x95, 0xEE, + 0xC1, 0x97, 0x02, 0x63, 0x7F, 0x3B, 0x4E, 0xB2, 0x0F, 0xF2, 0x7A, 0xBD, 0x57, 0x9C, 0x8B, 0x85, + 0xA8, 0x5D, 0x14, 0x3B, 0x7B, 0xF0, 0xBE, 0xFE, 0x0F, 0x8E, 0x4F, 0xD5, 0xB8, 0x49, 0xE8, 0x90, + 0xF5, 0x12, 0xBF, 0xB2, 0xD6, 0xE2, 0x78, 0x20, 0x26, 0x6C, 0x3F, 0x5C, 0xE4, 0x57, 0x6D, 0xE9, + 0xB4, 0x63, +}; + + +// iAvROMwb_pJ ̌͋UȂ̂ŒӁII +const u8 g_caPubKey_DER[ 0xa2 ] = { + 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, + 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xdf, 0x56, 0x30, + 0xc9, 0xae, 0x05, 0x55, 0xe8, 0xdf, 0xbe, 0xe6, 0xb9, 0x30, 0xb9, 0x76, 0x93, 0xb4, 0xc2, 0x20, + 0xe7, 0xae, 0x4c, 0x3e, 0xc3, 0xed, 0x27, 0xcf, 0x5d, 0x4f, 0xb5, 0x7d, 0xde, 0x38, 0xbc, 0xfe, + 0x25, 0x32, 0xd8, 0x23, 0x98, 0x52, 0xb5, 0xda, 0xf7, 0x39, 0xdc, 0xb3, 0x0a, 0x94, 0x7a, 0x2b, + 0x79, 0xe6, 0xe0, 0x4c, 0xbc, 0x21, 0xbd, 0x59, 0xb2, 0xc7, 0xf1, 0xc0, 0xf1, 0xfb, 0x29, 0x75, + 0xa1, 0x21, 0x93, 0x01, 0x29, 0x1c, 0x9a, 0xe1, 0x2d, 0x55, 0xfc, 0x7b, 0xb8, 0xcb, 0x07, 0x33, + 0xc5, 0x91, 0x0d, 0xc8, 0x45, 0x59, 0xef, 0xbe, 0x58, 0xc7, 0xc1, 0x1d, 0xd5, 0xf2, 0xcf, 0x1f, + 0xe0, 0x6d, 0x21, 0x00, 0xcd, 0x42, 0xd8, 0x84, 0x85, 0xe3, 0xb2, 0x02, 0x1a, 0xa5, 0x89, 0x02, + 0xa1, 0x96, 0xc6, 0xf7, 0x61, 0x68, 0x66, 0xe6, 0x65, 0x12, 0xb7, 0xf1, 0x49, 0x02, 0x03, 0x01, + 0x00, 0x01, +}; + diff --git a/docs/ISデバッガタスク.vsd b/docs/ISデバッガタスク.vsd new file mode 100644 index 00000000..100a4495 Binary files /dev/null and b/docs/ISデバッガタスク.vsd differ diff --git a/docs/NANDファームメモリマップ.vsd b/docs/NANDファームメモリマップ.vsd new file mode 100644 index 00000000..cb0901b7 Binary files /dev/null and b/docs/NANDファームメモリマップ.vsd differ diff --git a/docs/NANDフラッシュマップ&フォルダツリー.vsd b/docs/NANDフラッシュマップ&フォルダツリー.vsd new file mode 100644 index 00000000..a1924b90 Binary files /dev/null and b/docs/NANDフラッシュマップ&フォルダツリー.vsd differ diff --git a/docs/NORフラッシュマップ.xls b/docs/NORフラッシュマップ.xls new file mode 100644 index 00000000..4efbd6b4 Binary files /dev/null and b/docs/NORフラッシュマップ.xls differ diff --git a/docs/SystemMenu_REDリリース.txt b/docs/SystemMenu_REDリリース.txt new file mode 100644 index 00000000..b11ea33c --- /dev/null +++ b/docs/SystemMenu_REDリリース.txt @@ -0,0 +1,92 @@ +SystemMenu_RED + +E`[ + EJ[hAv擾 iTWLoi[ւ̑Ή͂܂j + ETWLJ[hN + EJ[h} ~ + ENTRJ[hiNTR[hjN ƒ + ENANDAvXg擾 + ENANDAvN + EAvu[g̍Ĕzu + EISfobKΉ ~ i^XNj + Et@[EFAƂĐK i^XNj + EAvNWRAM-MAPݒ + EAvNSCFGWX^bN +@@EAvNSDJ[hANZX” @iƂ肠ɂĂAZLeBʂł̌sBj + EEÍ ~ + EǗ ~ + E}bvFIX +@@EN̖t@[ ~ + ENTRR|[lgpb` ~ +E{̐ݒ + Eݒf[^tH[}bgFIX + EI + ETP␳ + EtEݒ + E[U[ @iBAGȂLjꕔ͓͂łȂdlj + Ȇݒ ~ + ENANDւ̕ۑ + ENTR(NVRAM)ւ̕ۑ + +EWiFiݒ ~ + Eݒf[^tH[}bgFIX + EdlFIX + +EDS_E[hvC + EdlFIX iDS_E[hvCƓdlj + E ~ +Elbg[NAbvf[g + EdlFIX + E ~ + +EAvǗ + ESDɃRs[ۂ̃t@CtH[}bg~ + E ~ + +ETWLoi[Ή ~ + EdlFIX ƒ + Emakebanner쐬 ~ +ENANDfirm`[@p[^n ~ + EdlFIX +E`[NANDAv@p[^n ~ + E{̐ݒf[^Ȃǂ̏ ~ + EDS_E[hvC̏ ~ +ENANDAv`[@p[^n ~ + EdlFIX +@@EoG[V̌ ƒ +@@Ee퓮̃f쐬 ƒ +ENANDI[o[CFS + EdlFIX + ENAND,SD}EgiANZXj +EL\[XANZX ~ + EdlFIX ~ +E^CgO\[XANZX ~ + EdlFIX ~ + +ENANDAvCXg[ @iTwlSDKNMenugpj +ENANDtH[}bg iTwlSDKdemos.TWL/fatfs/formattergpj + EdlFIX + ENANDŒlŃx^ ~ +@NłȂ`[ċNȂȂ́̕AGCDt@[̃J[hN”\t@[āA +@@formatterɉςformatter+NANDt@[VXej[CXg[[ŏ݁B + +Emakerom.TWLΉ + Et@[prhiPKIsgpAAESÍ͈͕ύXjɑΉ ~ + ETWLJ[h̃m[}̈}jAݒł悤ɁB ~ + EROMwb_PKIdl̍폜 ~ + +EISfobKΉ + ENANDAvfobOΉ ~@iJ[hAvƂăfobOj + EdlFIX iTwlNmenugNTRDS_E[hvCq@vOfobOƎdg݁j + Eoi[mF@\ ~ + EdlFIX ~ + +E}X^O ~ + ECLST[o\zHH ~ + EROM}X^Oc[ ~ + +EYHldl ~ + EpJ[h̏ݒXLbvN ~ + EV[gJbgL[ɂ鏉ݒXLbvN ~ + EYHŏ܂vFIXf[^dl ~ + diff --git a/docs/TWL-NANDファーム二重化.vsd b/docs/TWL-NANDファーム二重化.vsd new file mode 100644 index 00000000..8afcfd41 Binary files /dev/null and b/docs/TWL-NANDファーム二重化.vsd differ diff --git a/docs/TWLBanner.xls b/docs/TWLBanner.xls new file mode 100644 index 00000000..0ddbe23a Binary files /dev/null and b/docs/TWLBanner.xls differ diff --git a/docs/TWL_SystemMenuメモリマップ.vsd b/docs/TWL_SystemMenuメモリマップ.vsd new file mode 100644 index 00000000..5ca94bc9 Binary files /dev/null and b/docs/TWL_SystemMenuメモリマップ.vsd differ diff --git a/docs/TWL_staticModule.xls b/docs/TWL_staticModule.xls new file mode 100644 index 00000000..2921a9b5 Binary files /dev/null and b/docs/TWL_staticModule.xls differ diff --git a/docs/TWLカード_NANDアプリ仕様.txt b/docs/TWLカード_NANDアプリ仕様.txt new file mode 100644 index 00000000..6c0d64a1 --- /dev/null +++ b/docs/TWLカード_NANDアプリ仕様.txt @@ -0,0 +1,75 @@ +TWLJ[h/NANDAvdl + + +J[hAv +@ENTRp^TWLΉ^TWLpAv`T|[g + + +NANDAv +@ETWLΉ^TWLpAv`T|[gB +@@ƂPictoChatDS_E[hvĈDS[hNANDAvƂȂ”\B +@@NTRpST|[gꍇ̒lj +@@@NTR-SRLt@C̃tH[}bgύXBitEꕔ̈ÍBNTR{̂ł͔̓T|[gɂȂƈꕔ̈Í͑ΉBj +@@@makerom̏LtH[}bgΉB +@@@`[̏LtH[}bgu[gΉB +@@@NTR[hu[gI2C@\LɂKvBiHWZbg@\gpB`[ւ̕AщL̃p[^tAv؂ւ邽߂ɕKvBj +@@@SDKɂČTWL[hɂgȂI2C֌W̃CuNTR[hłgpł悤ɂB + +@{̋@\łԑԂꂻBBB + + +TitleID +@ENTRpAvɂ͕tȂB +@ETWLΉ^TWLpAvɂ́AJ[h^NANDAvɊ֌WȂtB + + +NANDւ̃f[^Z[u +@ENANDɃZ[uf[^ۑł̂́ANANDAv̂݁B +@@J[hAvNANDɃZ[usB +@@J[hAvΉꍇ̒lj +@@@`[ŏNɃtH_t@C쐬KvBit@[Abvf[gł̌tNGj +@@@AvǗʂŃZ[ut@CȂ̂uAvvƂĔFNANDSDȂ΂ȂȂB +@EZ[uf[^́ASDɃRs[”\PublicSaveDataƃRs[s‚PrivateSaveDataB +@@PublicSaveData TCYF16KB, 32KB, 64KB, 128KB, 256KB, 512KB, 1MB, 2MB, 4MB, 8MB +@@PrivateSaveDataTCYF16KBŒ + + +Z[uoi[t@C +@NANDAv̂ݎgp”\BJ[hAv͕sB + + +p[^tAvĂяo +@TitleIDNΏۃAvʂɎgp + +@Ăяogݍ킹 +@NAND@ @Av@@NAND@ Av +@NAND@ @Av@@TWLJ[hAv +@NAND@ @Av@@NTRJ[hAv ~iNTRJ[hAvɂTitleIDȂ̂ŁA`[ł͎łdg݂͎ĂA{jƂẮ~ɂĂj +@TWLJ[hAv@@NAND@ Av +@NTRJ[hAv@@NAND@ Av ~ +@ANYJ[hAv@@ANYJ[hAv ~iXbgP‚Ȃ̂Łj + +@Ăяoʁ +@[hԂ̋N +@IԂł̋NiĔzuȂj +@ĂяǒAvA”\iSȒfĊJ͂łȂj + + +Q[J[h} +@`[̂݉”\BAvł͋֎~B + +@{̋@\łԑԂꂻBBB + + +NANDAvÑJ[h̓d +@dONԁB +@ZLeB̓sANOɃ`[J[hdOFFONāAJ[h̃Xe[gNORMALXe[gɂĂBi\msj +@`[AvNOARM7SCFGWX^̓bNĂH + + +NANDAṽJ[hANZX”\̈ +@ROMwb_ +@obNAbv̈ +@NORMAL̈iTWLJ[h̎̂݁j + + diff --git a/docs/TWLカードメモリ容量による仕様違い.xls b/docs/TWLカードメモリ容量による仕様違い.xls new file mode 100644 index 00000000..559fdca8 Binary files /dev/null and b/docs/TWLカードメモリ容量による仕様違い.xls differ diff --git a/docs/TWLデバッガROMエミュレーション要求仕様.doc b/docs/TWLデバッガROMエミュレーション要求仕様.doc new file mode 100644 index 00000000..6920a890 Binary files /dev/null and b/docs/TWLデバッガROMエミュレーション要求仕様.doc differ diff --git a/docs/mb_childメモリマップ.vsd b/docs/mb_childメモリマップ.vsd new file mode 100644 index 00000000..e4633458 Binary files /dev/null and b/docs/mb_childメモリマップ.vsd differ diff --git a/docs/rom_header_format.xls b/docs/rom_header_format.xls new file mode 100644 index 00000000..e287c714 Binary files /dev/null and b/docs/rom_header_format.xls differ diff --git a/docs/ネットワークアップデート.vsd b/docs/ネットワークアップデート.vsd new file mode 100644 index 00000000..b8953242 Binary files /dev/null and b/docs/ネットワークアップデート.vsd differ diff --git a/docs/言語コード処理.xls b/docs/言語コード処理.xls new file mode 100644 index 00000000..918dd37e Binary files /dev/null and b/docs/言語コード処理.xls differ diff --git a/docs/鍵管理.xls b/docs/鍵管理.xls new file mode 100644 index 00000000..4b6620b0 Binary files /dev/null and b/docs/鍵管理.xls differ diff --git a/docs/開発用各種本体とアプリバイナリ仕様.vsd b/docs/開発用各種本体とアプリバイナリ仕様.vsd new file mode 100644 index 00000000..b661cf08 Binary files /dev/null and b/docs/開発用各種本体とアプリバイナリ仕様.vsd differ diff --git a/include/firm.h b/include/firm.h new file mode 100644 index 00000000..c2005e7a --- /dev/null +++ b/include/firm.h @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm + File: firm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_H_ +#define FIRM_H_ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +/* FIRM_H_ */ +#endif diff --git a/include/firm/acsign.h b/include/firm/acsign.h new file mode 100644 index 00000000..f275754a --- /dev/null +++ b/include/firm/acsign.h @@ -0,0 +1,33 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - ACSIGN + File: acsign.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_ACSIGN_H_ +#define FIRM_ACSIGN_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_ACSIGN_H_ */ +#endif diff --git a/include/firm/aes.h b/include/firm/aes.h new file mode 100644 index 00000000..98e63da4 --- /dev/null +++ b/include/firm/aes.h @@ -0,0 +1,34 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - include - AES + File: aes.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_AES_H_ +#define FIRM_AES_H_ + +#define PXI_FIFO_TAG_DATA PXI_FIFO_TAG_USER_0 + +#include + +#ifdef SDK_ARM7 +#include +#include +#include +#include +#else // !SDK_ARM7 +#include +#endif // !SDK_ARM7 + +/* FIRM_AES_H_ */ +#endif diff --git a/include/firm/aes/ARM7/aes_ids.h b/include/firm/aes/ARM7/aes_ids.h new file mode 100644 index 00000000..39694429 --- /dev/null +++ b/include/firm/aes/ARM7/aes_ids.h @@ -0,0 +1,42 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirmSDK - AES - include + File: aes_ids.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_AES_AES_IDS_H_ +#define TWL_AES_AES_IDS_H_ + +#define AES_IDS_ID0_A (('N' << 0) | ('i' << 8) | ('n' << 16) | ('t' << 24)) +#define AES_IDS_ID0_B (('e' << 0) | ('n' << 8) | ('d' << 16) | ('o' << 24)) +#define AES_IDS_ID0_C(c) (((unsigned long)c[0] << 0) | ((unsigned long)c[1] << 8) | ((unsigned long)c[2] << 16) | ((unsigned long)c[3] << 24)) +#define AES_IDS_ID0_D(c) (((unsigned long)c[3] << 0) | ((unsigned long)c[2] << 8) | ((unsigned long)c[1] << 16) | ((unsigned long)c[0] << 24)) + +#define AES_IDS_ID1_A(c) (((unsigned long)c[3] << 0) | ((unsigned long)c[1] << 8) | ((unsigned long)c[2] << 16) | ((unsigned long)c[0] << 24)) +#define AES_IDS_ID1_B(c) (((unsigned long)c[0] << 0) | ((unsigned long)c[2] << 8) | ((unsigned long)c[1] << 16) | ((unsigned long)c[3] << 24)) +#define AES_IDS_ID1_C (*(unsigned long*)0x04004d04) +#define AES_IDS_ID1_D (*(unsigned long*)0x04004d00) + +#define AES_IDS_ID2_A (('N' << 0) | ('i' << 8) | ('n' << 16) | ('t' << 24)) +#define AES_IDS_ID2_B (('e' << 0) | ('n' << 8) | ('d' << 16) | ('o' << 24)) +#define AES_IDS_ID2_C ((' ' << 0) | ('D' << 8) | ('S' << 16) | ('\0' << 24)) +#define AES_IDS_ID2_D ((0x01 << 0) | (0x23 << 8) | (0x21 << 16) | (0x00 << 24)) + +#define AES_IDS_ID3_A (*(unsigned long*)0x04004d00) +#define AES_IDS_ID3_B (('N' << 0) | ('I' << 8) | ('N' << 16) | ('T' << 24)) +#define AES_IDS_ID3_C (('E' << 0) | ('N' << 8) | ('D' << 16) | ('O' << 24)) +#define AES_IDS_ID3_D (*(unsigned long*)0x04004d04) + +/* TWL_AES_AES_IDS_H_ */ +#endif diff --git a/include/firm/aes/ARM7/aes_init.h b/include/firm/aes/ARM7/aes_init.h new file mode 100644 index 00000000..9804a053 --- /dev/null +++ b/include/firm/aes/ARM7/aes_init.h @@ -0,0 +1,97 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - AES - include + File: aes_init.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_AES_AES_INIT_H_ +#define TWL_AES_AES_INIT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------* + Name: AESi_InitKeysForApp + + Description: set IDs depending on the application. + you SHOULD NOT touch any ID registers after this call. + + Arguments: game_code game code + + Returns: None + *---------------------------------------------------------------------------*/ +void AESi_InitKeysForApp( u8 game_code[4] ); + +/*---------------------------------------------------------------------------* + Name: AESi_InitKeysForHard + + Description: set IDs depending on the system hardware. + you SHOULD NOT use this for standard applications. + + Arguments: fuse camouflaged fuse id + + Returns: None + *---------------------------------------------------------------------------*/ +void AESi_InitKeysForHard( u8 fuse[8] ); + +/*---------------------------------------------------------------------------* + Name: AESi_ResetAesKey + + Description: set SEED/KEYs by dummy data without seed[3] + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void AESi_ResetAesKey( void ); + +/*---------------------------------------------------------------------------* + Name: AESi_InitKeysFIRM + + Description: set IDs depending on the application. + you SHOULD NOT touch any ID registers after this call. + + Arguments: game_code game code + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void AESi_InitKeysFIRM( void ) +{ + AESi_InitKeysForApp( (u8*)((ROM_Header_Short*)HW_TWL_ROM_HEADER_BUF)->game_code ); +// AESi_ResetAesKey(); +} + +/*---------------------------------------------------------------------------* + Name: AESi_RecvSeed + + Description: set SEED/KEY from ARM9 via PXI. + + Arguments: developer_encrypt set TRUE if received key is using as direct key + + Returns: None + *---------------------------------------------------------------------------*/ +void AESi_RecvSeed( BOOL developer_encrypt ); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* TWL_AES_AES_INIT_H_ */ +#endif diff --git a/include/firm/aes/ARM9/aes_init.h b/include/firm/aes/ARM9/aes_init.h new file mode 100644 index 00000000..8d3cfbe7 --- /dev/null +++ b/include/firm/aes/ARM9/aes_init.h @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - AES - include + File: aes_init.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_AES_AES_INIT_H_ +#define TWL_AES_AES_INIT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: AESi_SendSeed + + Description: send SEED/KEY to ARM7 via PXI. + + Arguments: pSeed pointer to seed + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void AESi_SendSeed( const AESKey *pSeed ) +{ + PXI_SendStream( pSeed, AES_BLOCK_SIZE ); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* TWL_AES_AES_INIT_H_ */ +#endif diff --git a/include/firm/fatfs.h b/include/firm/fatfs.h new file mode 100644 index 00000000..8e6ecd9c --- /dev/null +++ b/include/firm/fatfs.h @@ -0,0 +1,30 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - fatfs + File: fatfs.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_FATFS_H_ +#define FIRM_FATFS_H_ + +#ifdef SDK_ARM7 +#include +#include +#else +#include +#endif // SDK_ARM7 + + +/* FIRM_FATFS_H_ */ +#endif diff --git a/include/firm/fatfs/ARM7/fatfs_firm.h b/include/firm/fatfs/ARM7/fatfs_firm.h new file mode 100644 index 00000000..375a5a7b --- /dev/null +++ b/include/firm/fatfs/ARM7/fatfs_firm.h @@ -0,0 +1,92 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - fatfs + File: fatfs.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_FATFS_FATFS_FIRM_H_ +#define FIRM_FATFS_FATFS_FIRM_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: FATFS_EnableAES + + Description: enable AES data path + + Arguments: counter initial counter value + + Returns: None + *---------------------------------------------------------------------------*/ +void FATFS_EnableAES( const AESCounter* pCounter ); + +/*---------------------------------------------------------------------------* + Name: FATFS_DisableAES + + Description: bypass AES + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void FATFS_DisableAES( void ); + +/*---------------------------------------------------------------------------* + Name: FATFS_InitFIRM + + Description: init file system + + Arguments: nandContext : nand context to omit initialization (if any) + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL FATFS_InitFIRM( void* nandContext ); + +/*---------------------------------------------------------------------------* + Name: FATFS_MountDriveFIRM + + Description: mount nand partition + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL FATFS_MountDriveFIRM( int driveno, FATFSMediaType media, int partition_no ); + +/*---------------------------------------------------------------------------* + Name: FATFS_UnmountDriveFIRM + + Description: unmount specified partition + + ȃhCȍI܂B + + Arguments: driveno drive number "A:" is 0 + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL FATFS_UnmountDriveFIRM( int driveno ); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +/* FIRM_FATFS_FATFS_FIRM_H_ */ +#endif diff --git a/include/firm/fatfs/ARM7/fatfs_loader.h b/include/firm/fatfs/ARM7/fatfs_loader.h new file mode 100644 index 00000000..0df8c70d --- /dev/null +++ b/include/firm/fatfs/ARM7/fatfs_loader.h @@ -0,0 +1,175 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - fatfs + File: fatfs_loader.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_FATFS_FATFS_LOADER_H_ +#define FIRM_FATFS_FATFS_LOADER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: FATFS_OpenRecentMenu + + Description: open recent menu file + + Arguments: driveno drive number ('A' is 0) + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL FATFS_OpenRecentMenu( int driveno ); + +/*---------------------------------------------------------------------------* + Name: FATFS_OpenSpecifiedSrl + + Description: open specified menu file + + Arguments: menufile target filename + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL FATFS_OpenSpecifiedSrl( const char* menufile ); + +/*---------------------------------------------------------------------------* + Name: FATFS_SaveSrlFilename + + Description: store filename to HW_TWL_FS_BOOT_SRL_PATH_BUF + + t@CHW_TWL_FS_BOOT_SRL_PATH_BUFɏ݂܂B + + Arguments: media media type + filename target filename + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL FATFS_SaveSrlFilename( FATFSMediaType media, const char* filename ); + +/*---------------------------------------------------------------------------* + Name: FATFS_GetSrlDescriptor + + Description: open specified menu file + + Cӂ̃t@CI[vAt@CIDmenu_fdɃZbg܂B + + Arguments: None + + Returns: int + *---------------------------------------------------------------------------*/ +int FATFS_GetSrlDescriptor( void ); + +/*---------------------------------------------------------------------------* + Name: FATFS_SetSrlDescriptor + + Description: set current file descriptor that was opened outside + + I[vς݂̃t@CIDmenu_fdɃZbg܂B + + Arguments: None + + Returns: int + *---------------------------------------------------------------------------*/ +void FATFS_SetSrlDescriptor( int fd ); + +/*---------------------------------------------------------------------------* + Name: FATFS_LoadBuffer + + Description: load data and pass to ARM9 via WRAM[B] + + LoadBufferJjYŁAFAT̃t@C̓eARM9ɓ]܂B + + [LoadBufferJjY] + WRAM[B]𗘗pāAARM7,ARM9Ԃ̃f[^]s܂B + WRAM[B]̊eXbgoPc[œn܂B + 1Xbg̃f[^܂͑Sf[^i[łƂAARM9 + FIRM_PXI_ID_LOAD_PIRIOD𑗐M܂B + f[^cꍇ͎̃Xbg̏Ɉڂ܂B + 2ڈȍ~̌Ăяoł́AOŌ̃Xbg̑gp܂B + gpXbgARM9Ɋ蓖ĂĂƂ́AARM7 + Ȃ܂ŃXg[܂B + + [gp] + WRAM[B]bNAԂƂARM7ɓ|ĂƁB + + [ӓ_] + offsetsizeARM9ɒʒm܂Bʂ̌oHœĂB + SRLt@Cǂݍޏꍇ́A݂ROMwb_QƂłΏ\łB + (ROMwb_͌mĂ͂) + + ⑫: + ł́A郉CuARM7/ARM9ŕ킹邱Ƃ + OɂĂ邪AėpIɂɂ(ƗCuȂ)A + MŃXbg𔼕‚ƂAꂼɎMPXIR[obN + XbhpӂAMAPIf[^WRAMɊi[A + destsizeʒmƂ`OKł͂ȂH + (ŊԎԂ) + + ⑫QF + xɕXbggȏꍇ́ACpo_readB + ARM9f[^eG\肪ȂȂA{APIg킸Aʂ + ڃCɓ]B + + Arguments: offset offset of the file to load (512 bytes alignment) + size size to load + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL FATFS_LoadBuffer(u32 offset, u32 size); + +/*---------------------------------------------------------------------------* + Name: FATFS_LoadHeader + + Description: load menu header + + Arguments: None + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FATFS_LoadHeader( void ); + +/*---------------------------------------------------------------------------* + Name: FATFS_LoadStatic + + Description: load static binary + + Arguments: None + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FATFS_LoadStatic( void ); + +/*---------------------------------------------------------------------------* + Name: FATFS_Boot + + Description: boot + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void FATFS_Boot( void ); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +/* FIRM_FATFS_FATFS_LOADER_H_ */ +#endif diff --git a/include/firm/fatfs/ARM9/fatfs_firm.h b/include/firm/fatfs/ARM9/fatfs_firm.h new file mode 100644 index 00000000..757b7a83 --- /dev/null +++ b/include/firm/fatfs/ARM9/fatfs_firm.h @@ -0,0 +1,44 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - fatfs + File: fatfs_firm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_FATFS_FATFS_FIRM_H_ +#define FIRM_FATFS_FATFS_FIRM_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: FATFS_InitFIRM + + Description: initialize fatfs for firm + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void FATFS_InitFIRM( void ); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +/* FIRM_FATFS_FATFS_FIRM_H_ */ +#endif diff --git a/include/firm/format/firm_common.h b/include/firm/format/firm_common.h new file mode 100644 index 00000000..404ec28b --- /dev/null +++ b/include/firm/format/firm_common.h @@ -0,0 +1,67 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - format - firm + File: firm_common.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_FORMAT_FIRM_COMMON_H_ +#define FIRM_FORMAT_FIRM_COMMON_H_ + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +// 풓W[ +typedef struct +{ + u32 rom_offset; /* ] ROM ItZbg */ + u32 decomp_size; /* WJTCY */ + void *ram_address; /* ] RAM ItZbg */ + u32 size; /* ]TCY */ +} +FIRMHeader_ModuleInfo; + +// DS-IPL2wb_ +typedef struct +{ + u16 reserved_0h[4]; + u32 ds_key; + u16 ds_arm9_romAdr; + u16 ds_arm9_ramAdr; + u16 ds_arm7_romAdr; + u16 ds_arm7_ramAdr; + u16 ds_arm9_romOffsetUnit:3; + u16 ds_arm9_ramOffsetUnit:3; + u16 ds_arm7_romOffsetUnit:3; + u16 ds_arm7_ramOffsetUnit:3; + u16 :2; + u16 ds_header_ver:2; + u16 ds_data_romAdr; + u64 card_key; + u16 ncd_romAdr; + u16 reserved_24h[2]; + u16 ds_data_crc16; +} +NORHeaderDS; + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // FIRM_FORMAT_FIRM_COMMON_H_ diff --git a/include/firm/format/from_brom.h b/include/firm/format/from_brom.h new file mode 100644 index 00000000..0a0341db --- /dev/null +++ b/include/firm/format/from_brom.h @@ -0,0 +1,106 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - format - from_brom + File: from_brom.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_FORMAT_FROM_BROM_H_ +#define FIRM_FORMAT_FROM_BROM_H_ + +#include +#include +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SDK_ARM9 +#define RSA_PUBKEY_NUM_FROM_BROM 8 +#define AESKEY_NUM_FROM_BROM 8 +#else // SDK_ARM7 +#define RSA_PUBKEY_NUM_FROM_BROM 4 +#define AESKEY_NUM_FROM_BROM 4 +#endif // SDK_ARM7 + + +// sizeof(SDPortContext) +typedef struct SDportContextData +{ + u32 data[17]; +} +SDPortContextData; + +/* + hash_table_hash́At@[wb_̏̒ɖ߂ꂽl(0xffŖ߂Ă) + t@[u[gɒljf[^CɃ[hKvɋꂽꍇA + ̃nbVlmakenandfirmŖߍނ悤ɂ邱ƂŕیłB + (Staticɖ߂Ă卷ȂƎv邪EEE) + gp̏ꍇ()A0xffŖ߂Ă邱ƂmFׂ +*/ +typedef struct +{ + union + { + NANDHeader nand; + NORHeader nor; + GCDHeader gcd; + u8 max[0x400]; + } + header; // 1KB + + u8 rsa_pubkey[RSA_PUBKEY_NUM_FROM_BROM][ACS_PUBKEY_LEN]; // 1KB + u8 aes_key[AESKEY_NUM_FROM_BROM][ACS_AES_LEN]; // 128B + u8 hash_table_hash[ACS_HASH_LEN]; // 20B + + BLOWFISH_CTX ds_blowfish; // 4KB + + BLOWFISH_CTX twl_blowfish; // 4KB + +} +OSFromBrom9Buf; + +typedef struct +{ + union + { + NANDHeader nand; + NORHeader nor; + GCDHeader gcd; + u8 max[0x400]; + } + header; // 1KB + + u8 rsa_pubkey[RSA_PUBKEY_NUM_FROM_BROM][ACS_PUBKEY_LEN]; // 512B + u8 aes_key[AESKEY_NUM_FROM_BROM][ACS_AES_LEN]; // 64B + u8 hash_table_hash[ACS_HASH_LEN]; // 20B + + BLOWFISH_CTX twl_blowfish[2]; // (4KB + ) * 2 + + SDPortContextData SDNandContext; +} +OSFromBrom7Buf; + +#ifdef SDK_ARM9 +typedef OSFromBrom9Buf OSFromBromBuf; +#else // SDK_ARM7 +typedef OSFromBrom7Buf OSFromBromBuf; +#endif // SDK_ARM7 + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // FIRM_FORMAT_FROM_BROM_H_ diff --git a/include/firm/format/from_firm.h b/include/firm/format/from_firm.h new file mode 100644 index 00000000..d1bdd351 --- /dev/null +++ b/include/firm/format/from_firm.h @@ -0,0 +1,69 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - format - from_firm + File: from_firm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_FORMAT_FROM_FIRM_H_ +#define FIRM_FORMAT_FROM_FIRM_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SDK_ARM9 +#define RSA_PUBKEY_NUM_FROM_FIRM 8 +#define AESKEY_NUM_FROM_FIRM 8 +#else // SDK_ARM7 +#define RSA_PUBKEY_NUM_FROM_FIRM 4 +#define AESKEY_NUM_FROM_FIRM 4 +#endif // SDK_ARM7 + +typedef struct +{ + u8 rsa_pubkey[RSA_PUBKEY_NUM_FROM_FIRM][ACS_PUBKEY_LEN]; // 1KB + u8 aes_key[AESKEY_NUM_FROM_FIRM][ACS_AES_LEN]; // 128B + u8 reserved[ACS_HASH_LEN]; // 20B + + BLOWFISH_CTX ds_blowfish; // 4KB + + BLOWFISH_CTX twl_blowfish; // 4KB + +} +OSFromFirm9Buf; + +typedef struct +{ + u8 rsa_pubkey[RSA_PUBKEY_NUM_FROM_FIRM][ACS_PUBKEY_LEN]; // 512B + u8 aes_key[AESKEY_NUM_FROM_FIRM][ACS_AES_LEN]; // 64B + u8 reserved[ACS_HASH_LEN]; // 20B + + BLOWFISH_CTX twl_blowfish[2]; // (4KB + ) * 2 + + SDPortContextData SDNandContext; +} +OSFromFirm7Buf; + +#ifdef SDK_ARM9 +typedef OSFromFirm9Buf OSFromFirmBuf; +#else // SDK_ARM7 +typedef OSFromFirm7Buf OSFromFirmBuf; +#endif // SDK_ARM7 + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // FIRM_FORMAT_FROM_FIRM_H_ diff --git a/include/firm/format/gcdfirm.h b/include/firm/format/gcdfirm.h new file mode 100644 index 00000000..3e489a1e --- /dev/null +++ b/include/firm/format/gcdfirm.h @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - format - gcdfirm + File: gcdfirm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_FORMAT_GCDFIRM_H_ +#define FIRM_FORMAT_GCDFIRM_H_ + +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*===========================================================================* + * NOR FORMAT + *===========================================================================*/ + +//--------------------------------------------------------------------------- +// Section A NOR HEADER +//--------------------------------------------------------------------------- + +// 풓W[ +typedef FIRMHeader_ModuleInfo GCDHeader_ModuleInfo; + +// TWL-GCDt@[wb_ +typedef struct +{ + /* 0x000-0x020 [VXe\̈] */ + u8 reserved_0h[0x14]; + u8 rom_size; // Rom size (2rom_size Mbit: ex. 128Mbit̂Ƃrom_size = 7) + u8 reserved_16h[0xb]; + + /* 0x020-0x040 [풓W[pp[^] */ + u32 main_rom_offset; /* ARM9 ] ROM ItZbg */ + u32 main_decomp_size; /* ARM9 WJTCY */ + void *main_ram_address; /* ARM9 ] RAM ItZbg */ + u32 main_size; /* ARM9 ]TCY */ + u32 sub_rom_offset; /* ARM7 ] ROM ItZbg */ + u32 sub_decomp_size; /* ARM9 WJTCY */ + void *sub_ram_address; /* ARM7 ] RAM ItZbg */ + u32 sub_size; /* ARM7 ]TCY */ + + /* 0x040-0x080 [VXe\̈] */ + u8 reserved_40h[0x40]; + + /* 0x080-0x090 [t@[oCi] */ + u32 nandfirm_offset; // address of rom_valid_size + u32 nandfirm_size; // address of rom_header_size + u32 norfirm_offset; // address of main_module_param + u32 norfirm_size; // address of sub_module_param + + /* 0x090-0x094 [TWL-ROMRg[] */ + u16 normal_area_offset; + u16 twl_area_offset; + + /* 0x094-0x0c0 [VXe\̈] */ + u8 reserved_98h[0x2c]; + + /* 0x0c0-0x100 [DSJ[hNINTENDOSd̈] */ + u8 reserved_C0h[0x3f]; + + u8 comp_arm9_boot_area:1; // Compress arm9 boot area + u8 comp_arm7_boot_area:1; // Compress arm7 boot area + u8 arm9_x2:1; + u8 :0; +} +GCDHeaderLow; + +typedef struct +{ + /* 0x180-0x1b0 [WRAMWX^p[^] */ + MIHeader_WramRegs w; + + /* 0x1b0-0x200 [VXe\̈] */ + u8 reserved_footer[0x50]; +} +GCDHeaderHigh; + +// GCDwb_ +typedef struct +{ + /* 0x000-0x100 */ + GCDHeaderLow l; + + /* 0x100-0x180 */ + FIRMPaddedSign sign; + + /* 0x180-0x200 */ + GCDHeaderHigh h; +} +GCDHeader; + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif //FIRM_FORMAT_GCDFIRM_H_ diff --git a/include/firm/format/nandfirm.h b/include/firm/format/nandfirm.h new file mode 100644 index 00000000..68b9ad66 --- /dev/null +++ b/include/firm/format/nandfirm.h @@ -0,0 +1,131 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - format - nandfirm + File: nandfirm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_FORMAT_NAND_H_ +#define FIRM_FORMAT_NAND_H_ + +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*===========================================================================* + * NAND FORMAT + *===========================================================================*/ + +//--------------------------------------------------------------------------- +// Section A NAND HEADER +//--------------------------------------------------------------------------- + +// 풓W[ +typedef FIRMHeader_ModuleInfo NANDHeader_ModuleInfo; + +// TWL-NANDt@[wb_ +typedef struct +{ + /* 0x000-0x020 [VXe\̈] */ + u8 reserved_0h[0x20]; /* VXe\ A */ + + /* 0x020-0x040 [풓W[pp[^] */ + u32 main_rom_offset; /* ARM9 ] ROM ItZbg */ + u32 main_decomp_size; /* ARM9 WJTCY */ + void *main_ram_address; /* ARM9 ] RAM ItZbg */ + u32 main_size; /* ARM9 ]TCY */ + u32 sub_rom_offset; /* ARM7 ] ROM ItZbg */ + u32 sub_decomp_size; /* ARM9 WJTCY */ + void *sub_ram_address; /* ARM7 ] RAM ItZbg */ + u32 sub_size; /* ARM7 ]TCY */ + + /* 0x040-0x0c0 [VXe\̈] */ + u8 reserved_40h[0x80]; + + /* 0x0c0-0x100 [DSJ[hNINTENDOSd̈] */ + u8 reserved_C0h[0x3f]; + + u8 comp_arm9_boot_area:1; // Compress arm9 boot area + u8 comp_arm7_boot_area:1; // Compress arm7 boot area + u8 arm9_x2:1; + u8 arm9_decomp:1; + u8 :0; +} +NANDHeaderLow; + +typedef struct +{ + /* 0x180-0x1b0 [WRAMWX^p[^] */ + MIHeader_WramRegs w; + + /* 0x1b0-0x200 [VXe\̈] */ + u8 reserved_footer[0x50]; +} +NANDHeaderHigh; + +// NANDwb_ +typedef struct +{ + /* 0x000-0x028 [DS-NORwb_] */ + NORHeaderDS d; + + /* 0x028-0x200 [VXe\̈(O)] */ + u8 reserved_mbr[512 - sizeof(NORHeaderDS)]; + + /* 0x200-0x300 */ + NANDHeaderLow l; + + /* 0x300-0x380 */ + FIRMPaddedSign sign; + + /* 0x380-0x400 */ + NANDHeaderHigh h; +} +NANDHeader; + +// 璷wb_ (璷) +typedef struct +{ + /* 0x400-0x500 *//* 0x600-0x700 */ + NANDHeaderLow l; + + /* 0x500-0x580 *//* 0x700-0x780 */ + FIRMPaddedSign sign; + + /* 0x580-0x600 *//* 0x780-0x800 */ + NANDHeaderHigh h; +} +NANDHeaderCore; + +// 璷wb_ (S) +typedef struct +{ + /* 0x000-0x400 [ۂɎgpwb_] */ + NANDHeader g; + /* 0x400-0x600 [ftHgʒuC[Wɑ΂wb_] */ + NANDHeaderCore o; + /* 0x600-0x800 [ꎞҔʒuC[Wɑ΂wb_] */ + NANDHeaderCore m; +} +NANDHeaderEx; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif //FIRM_FORMAT_NAND_H_ diff --git a/include/firm/format/norfirm.h b/include/firm/format/norfirm.h new file mode 100644 index 00000000..27587fa8 --- /dev/null +++ b/include/firm/format/norfirm.h @@ -0,0 +1,108 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - format - norfirm + File: norfirm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_FORMAT_NOR_H_ +#define FIRM_FORMAT_NOR_H_ + +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*===========================================================================* + * NOR FORMAT + *===========================================================================*/ + +//--------------------------------------------------------------------------- +// Section A NOR HEADER +//--------------------------------------------------------------------------- + +// 풓W[ +typedef FIRMHeader_ModuleInfo NORHeader_ModuleInfo; + +// TWL-NORt@[wb_ +typedef struct +{ + /* 0x000-0x020 [VXe\̈] */ + u8 reserved_0h[0x20]; /* VXe\ A */ + + /* 0x020-0x040 [풓W[pp[^] */ + u32 main_rom_offset; /* ARM9 ] ROM ItZbg */ + u32 main_decomp_size; /* ARM9 WJTCY */ + void *main_ram_address; /* ARM9 ] RAM ItZbg */ + u32 main_size; /* ARM9 ]TCY */ + u32 sub_rom_offset; /* ARM7 ] ROM ItZbg */ + u32 sub_decomp_size; /* ARM9 WJTCY */ + void *sub_ram_address; /* ARM7 ] RAM ItZbg */ + u32 sub_size; /* ARM7 ]TCY */ + + /* 0x040-0x0c0 [VXe\̈] */ + u8 reserved_40h[0x80]; + + /* 0x0c0-0x100 [DSJ[hNINTENDOSd̈] */ + u8 reserved_C0h[0x3f]; + + u8 comp_arm9_boot_area:1; // Compress arm9 boot area + u8 comp_arm7_boot_area:1; // Compress arm7 boot area + u8 arm9_x2:1; + u8 arm9_decomp:1; + u8 :2; + u8 baudrate:1; + u8 boot_nandfirm:1; +} +NORHeaderLow; + +typedef struct +{ + /* 0x180-0x1b0 [WRAMWX^p[^] */ + MIHeader_WramRegs w; + + /* 0x1b0-0x200 [VXe\̈] */ + u8 reserved_footer[0x50]; +} +NORHeaderHigh; + +// NORwb_ +typedef struct +{ + /* 0x000-0x028 */ + NORHeaderDS d; + + /* 0x028-0x200 */ + u8 wl_params[472]; + + /* 0x200-0x300 */ + NORHeaderLow l; + + /* 0x300-0x380 */ + FIRMPaddedSign sign; + + /* 0x380-0x400 */ + NORHeaderHigh h; +} +NORHeader; + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif //FIRM_FORMAT_NOR_H_ diff --git a/include/firm/format/sign.h b/include/firm/format/sign.h new file mode 100644 index 00000000..25887d7b --- /dev/null +++ b/include/firm/format/sign.h @@ -0,0 +1,95 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - format - sign + File: sign.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 FORMAT_SIGN_H_ +#define FORMAT_SIGN_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +// signed hash index +typedef enum +{ + FIRM_SIGNED_HASH_IDX_HEADER = 0, + FIRM_SIGNED_HASH_IDX_ARM9 = 1, + FIRM_SIGNED_HASH_IDX_ARM7 = 2, + FIRM_SIGNED_HASH_IDX_HASH_TABLE = 3, + FIRM_SIGNED_HASH_IDX_FINAL = 4, + + FIRM_SIGNED_HASH_NUM = 5 +} +FIRMSignedHashIndex; + + +#define ACS_BASE_BLOCK_SIZE 4096 // should be the multiple of 16 +#define ACS_META_BLOCK_SIZE 5120 // should be the multiple of 16 and the multiple of 20 + // would be the multiple of 512, then the mutilple of 2560 + +#define ACS_PUBKEY_LEN 128 +#define ACS_HASH_LEN 20 +#define ACS_AES_LEN 16 + +#define ACS_ENCRYPTED_HASH_LEN ACS_PUBKEY_LEN +#define ACS_DECRYPTED_HASH_LEN ACS_HASH_LEN + +#define ACS_RSA_EXP 0x00010001 +#define ACS_RSA_EXP_LEN 3 + +// DER format of RSA keys + +#define ACS_RSA_PRVMOD_OFFSET 0x0B +#define ACS_RSA_PRVEXP_OFFSET 0x93 +#define ACS_RSA_PRVMOD_LEN 128 +#define ACS_RSA_PRVEXP_LEN 128 + +#define ACS_RSA_PUBMOD_OFFSET 0x1D +#define ACS_RSA_PUBEXP_OFFSET 0x93 +#define ACS_RSA_PUBMOD_LEN 128 +#define ACS_RSA_PUBEXP_LEN ACS_RSA_EXP_LEN + +#define FIRM_HEADER_2ND_HASH_AREA_LEN (sizeof(FIRMSignedContext) - ACS_HASH_LEN) + + +// ReLXg +typedef struct +{ + unsigned char aes_key[ACS_AES_LEN]; + unsigned char hash[FIRM_SIGNED_HASH_NUM][ACS_HASH_LEN]; +} +FIRMSignedContext; + +// +typedef union +{ + struct + { + unsigned char prePad[(ACS_ENCRYPTED_HASH_LEN - sizeof(FIRMSignedContext))-1]; + FIRMSignedContext c; + unsigned char postPad[1]; + } + e; + unsigned int raw[ACS_ENCRYPTED_HASH_LEN/4]; +} +FIRMPaddedSign; + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif //FORMAT_SIGN_H_ diff --git a/include/firm/format/wram_regs.h b/include/firm/format/wram_regs.h new file mode 100644 index 00000000..08c8d19c --- /dev/null +++ b/include/firm/format/wram_regs.h @@ -0,0 +1,85 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - MI - include + File: wram_regs.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_FORMAT_WRAM_REGS_H_ +#define FIRM_FORMAT_WRAM_REGS_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef enum +{ + MI_WRAM_A_OFFSET_0KB = 0, + MI_WRAM_A_OFFSET_64KB = 1, + MI_WRAM_A_OFFSET_128KB = 2, + MI_WRAM_A_OFFSET_192KB = 3 +} MIWramAOffset; + +typedef enum +{ + MI_WRAM_BC_OFFSET_0KB = 0, + MI_WRAM_BC_OFFSET_32KB = 1, + MI_WRAM_BC_OFFSET_64KB = 2, + MI_WRAM_BC_OFFSET_96KB = 3, + MI_WRAM_BC_OFFSET_128KB = 4, + MI_WRAM_BC_OFFSET_160KB = 5, + MI_WRAM_BC_OFFSET_192KB = 6, + MI_WRAM_BC_OFFSET_224KB = 7 +} MIWramBCOffset; + + +#define MI_WRAM_MAP_NULL HW_WRAM_AREA + +#define REG_WRAM_MAP_CONV_ADDR( regno, abc, border, addr ) \ +( \ + ((((addr) - HW_WRAM_AREA) / MI_WRAM_##abc##_SLOT_SIZE) & \ + (REG_MI_MBK##regno##_W##abc##_##border##_MASK >> \ + REG_MI_MBK##regno##_W##abc##_##border##_SHIFT)) \ +) + + +// WRAM}bsOWX^ +typedef struct +{ + u8 main_wrambnk_a[4]; // ARM9 SCFG_MBK1 + u8 main_wrambnk_b[8]; // ARM9 SCFG_MBK2-3 + u8 main_wrambnk_c[8]; // ARM9 SCFG_MBK4-5 + + u32 main_wrammap_a; // ARM9 SCFG_MBK6 + u32 main_wrammap_b; // ARM9 SCFG_MBK7 + u32 main_wrammap_c; // ARM9 SCFG_MBK8 + + u32 sub_wrammap_a; // ARM7 SCFG_MBK6 + u32 sub_wrammap_b; // ARM7 SCFG_MBK7 + u32 sub_wrammap_c; // ARM7 SCFG_MBK8 + + u8 sub_wramlock[3]; // ARM7 SCFG_MBK9 + + u8 main_wrambnk_01:2; // ARM9 RBKCNT1_H + u8 main_vrambnk_c:3; // ARM9 RBKCNT0_H + u8 main_vrambnk_d:3; // ARM9 RBKCNT0_H +} +MIHeader_WramRegs; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_FORMAT_WRAM_REGS_H_ */ +#endif diff --git a/include/firm/fs.h b/include/firm/fs.h new file mode 100644 index 00000000..cabe2145 --- /dev/null +++ b/include/firm/fs.h @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - fs + File: fs.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_FS_H_ +#define FIRM_FS_H_ + +#ifdef SDK_ARM7 +#include +#include +#else +#include +#include +#include +#endif // SDK_ARM7 + + +/* FIRM_FS_H_ */ +#endif diff --git a/include/firm/fs/ARM7/fs_firm.h b/include/firm/fs/ARM7/fs_firm.h new file mode 100644 index 00000000..c0e98a6c --- /dev/null +++ b/include/firm/fs/ARM7/fs_firm.h @@ -0,0 +1,43 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - fs + File: fs_firm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_FS_FS_FIRM_H_ +#define FIRM_FS_FS_FIRM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: FS_OpenSrl + + Description: open srl file named in HW_TWL_FS_BOOT_SRL_PATH_BUF + + Arguments: None + + Returns: file discriptor + *---------------------------------------------------------------------------*/ +int FS_OpenSrl( void ); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +/* FIRM_FS_FS_FIRM_H_ */ +#endif diff --git a/include/firm/fs/ARM7/fs_loader.h b/include/firm/fs/ARM7/fs_loader.h new file mode 100644 index 00000000..1ff82cc0 --- /dev/null +++ b/include/firm/fs/ARM7/fs_loader.h @@ -0,0 +1,85 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - fs + File: fs.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_FS_FS_LOADER_H_ +#define FIRM_FS_FS_LOADER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: FS_LoadBuffer + + Description: load data in file and pass to ARM9 via WRAM-B + + Arguments: fd file discriptor to read + offset offset to start to read in bytes + size total length to read in bytes + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadBuffer( int fd, u32 offset, u32 size ); + +/*---------------------------------------------------------------------------* + Name: FS_LoadModule + + Description: load data in file and pass to ARM9 via WRAM-B in view of AES + settings in the ROM header at HW_TWL_ROM_HEADER_BUF + + Arguments: fd file discriptor to read + offset offset to start to read in bytes + size total length to read in bytes + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadModule( int fd, u32 offset, u32 size ); + +/*---------------------------------------------------------------------------* + Name: FS_LoadHeader + + Description: load ROM header in the head of file and pass to ARM9 via WRAM-B + + Arguments: fd file discriptor to read + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadHeader( int fd ); + +/*---------------------------------------------------------------------------* + Name: FS_LoadStatic + + Description: load static regions in file and pass to ARM9 via WRAM-B + specified by ROM header at HW_TWL_ROM_HEADER_BUF + + Arguments: fd file discriptor to read + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadStatic( int fd ); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +/* FIRM_FS_FS_LOADER_H_ */ +#endif diff --git a/include/firm/fs/ARM9/fs_firm.h b/include/firm/fs/ARM9/fs_firm.h new file mode 100644 index 00000000..b88957ae --- /dev/null +++ b/include/firm/fs/ARM9/fs_firm.h @@ -0,0 +1,83 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - fs + File: fs_firm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_FS_FS_FIRM_H_ +#define FIRM_FS_FS_FIRM_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: FS_InitFIRM + + Description: initialize FS/FATFS for firm + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void FS_InitFIRM( void ); + +/*---------------------------------------------------------------------------* + Name: FS_GetTitleBootContentPathFast + + Description: NAND ɃCXg[ĂAv̎st@C̃pX + 擾܂B + 擾̐؂ȂߍłA + 񂪉₂Ô\邱ƂɒӂȂ΂Ȃ܂B + + Arguments: buf: pXi[obt@ւ̃|C^B + FS_ENTRY_LONGNAME_MAX ȏ̃TCYKvłB + titleId: pX擾Av Title IDB + + Returns: ɏsꂽȂ TRUE Ԃ܂B + *---------------------------------------------------------------------------*/ +BOOL FS_GetTitleBootContentPathFast(char* buf, u64 titleId); + +/*---------------------------------------------------------------------------* + Name: FS_ResolveSrl + + Description: resolve srl filename and store to HW_TWL_FS_BOOT_SRL_PATH_BUF + + Arguments: titleId title id for srl file + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_ResolveSrl( u64 titleId ); + +/*---------------------------------------------------------------------------* + Name: FS_ResolveSrlUnsecured + + Description: resolve srl filename and store to HW_TWL_FS_BOOT_SRL_PATH_BUF + without almost security check + + Arguments: titleId title id for srl file + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_ResolveSrlUnsecured( u64 titleId ); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +/* FIRM_FS_FS_FIRM_H_ */ +#endif diff --git a/include/firm/fs/ARM9/fs_loader.h b/include/firm/fs/ARM9/fs_loader.h new file mode 100644 index 00000000..12c3b6b0 --- /dev/null +++ b/include/firm/fs/ARM9/fs_loader.h @@ -0,0 +1,125 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - fs + File: fs_loader.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_FS_FS_LOADER_H_ +#define FIRM_FS_FS_LOADER_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: FS_GetAesKeySeed + + Description: retreive aes key seed in the signature + + Arguments: None + + Returns: pointer to seed + *---------------------------------------------------------------------------*/ +AESKey* const FS_GetAesKeySeed( void ); + +/*---------------------------------------------------------------------------* + Name: FS_DeleteAesKeySeed + + Description: delete aes key seed in the signature + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void FS_DeleteAesKeySeed( void ); + +/*---------------------------------------------------------------------------* + Name: FS_SetDigestKey + + Description: set specified key or default key for HMAC-SHA-1 + + Arguments: digestKey pointer to key + if NULL, use default key + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +void FS_SetDigestKey( const u8* digestKey ); + +/*---------------------------------------------------------------------------* + Name: FS_LoadBuffer + + Description: receive data from ARM7 via WRAM-B and store in destination address, + calculate SHA1 in parallel if ctx is specified + + Arguments: dest destination address to read + size total length to read in bytes + ctx pointer to SHA1 context or NULL + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadBuffer( u8* dest, u32 size, SVCSHA1Context *ctx ); + +/*---------------------------------------------------------------------------* + Name: FS_LoadModule + + Description: receive data from ARM7 via WRAM-B and store in destination address + in view of AES settings in the ROM header at HW_TWL_ROM_HEADER_BUF, + then verify the digest + + Arguments: dest destination address to read + offset file offset to start to read in bytes + size total length to read in bytes + digest digest to verify + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadModule( u8* dest, u32 offset, u32 size, const u8 digest[SVC_SHA1_BLOCK_SIZE] ); + +/*---------------------------------------------------------------------------* + Name: FS_LoadHeader + + Description: receive ROM header, store to HW_TWL_ROM_HEADER_BUF, + and verify signature + + Arguments: pool heap context to call SVC_DecryptSign + rsa_key public key to verify the signature + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadHeader( SVCSignHeapContext* pool, const void* rsa_key ); + +/*---------------------------------------------------------------------------* + Name: FS_LoadStatic + + Description: receive static regions from ARM6 via WRAM-B and store them + specified by ROM header at HW_TWL_ROM_HEADER_BUF + + Arguments: None + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS_LoadStatic( void ); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +/* FIRM_FS_FS_LOADER_H_ */ +#endif diff --git a/include/firm/fs/ARM9/fs_loader2.h b/include/firm/fs/ARM9/fs_loader2.h new file mode 100644 index 00000000..edb22fb0 --- /dev/null +++ b/include/firm/fs/ARM9/fs_loader2.h @@ -0,0 +1,124 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - fs + File: fs_loader2.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_FS_FS_LOADER2_H_ +#define FIRM_FS_FS_LOADER2_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: FS2_GetAesKeySeed + + Description: retreive aes key seed in the signature + + Arguments: None + + Returns: pointer to seed + *---------------------------------------------------------------------------*/ +AESKey* const FS2_GetAesKeySeed( void ); + +/*---------------------------------------------------------------------------* + Name: FS2_DeleteAesKeySeed + + Description: delete aes key seed in the signature + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void FS2_DeleteAesKeySeed( void ); + +/*---------------------------------------------------------------------------* + Name: FS2_SetDigestKey + + Description: set specified key or default key for HMAC-SHA-1 + + Arguments: digestKey pointer to key + if NULL, use default key + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +void FS2_SetDigestKey( const u8* digestKey ); + +/*---------------------------------------------------------------------------* + Name: FS2_LoadModule + + Description: receive data from ARM7 via WRAM-B and store in destination address + in view of AES settings in the ROM header at HW_TWL_ROM_HEADER_BUF, + then verify the digest + + Arguments: pFile pointer to FSFile streucture + dest destination address to read + offset file offset to start to read in bytes + size total length to read in bytes + digest digest to verify + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS2_LoadModule( FSFile *pFile, u8* dest, u32 offset, u32 size, const u8 digest[SVC_SHA1_DIGEST_SIZE] ); + +/*---------------------------------------------------------------------------* + Name: FS2_OpenSrl + + Description: open srl file named at HW_TWL_FS_BOOT_SRL_PATH_BUF + + Arguments: pFile pointer to FSFile streucture + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS2_OpenSrl( FSFile *pFile ); + +/*---------------------------------------------------------------------------* + Name: FS2_LoadHeader + + Description: load ROM header to HW_TWL_ROM_HEADER_BUF using normal FS, + and verify signature + + Arguments: pFile pointer to FSFile streucture + pool heap context to call SVC_DecryptSign + rsa_key public key to verify the signature + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS2_LoadHeader( FSFile *pFile, SVCSignHeapContext* pool, const void* rsa_key ); + +/*---------------------------------------------------------------------------* + Name: FS2_LoadStatic + + Description: receive static regions from ARM6 via WRAM-B and store them + specified by ROM header at HW_TWL_ROM_HEADER_BUF + + Arguments: pFile pointer to FSFile streucture + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL FS2_LoadStatic( FSFile *pFile ); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +/* FIRM_FS_FS_LOADER2_H_ */ +#endif diff --git a/include/firm/gcd.h b/include/firm/gcd.h new file mode 100644 index 00000000..26593c55 --- /dev/null +++ b/include/firm/gcd.h @@ -0,0 +1,26 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - GCD + File: gcd.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_GCD_H_ +#define FIRM_GCD_H_ + +//#include +#include +#include + +/* FIRM_GCD_H_ */ +#endif diff --git a/include/firm/gcd/blowfish.h b/include/firm/gcd/blowfish.h new file mode 100644 index 00000000..bba522a4 --- /dev/null +++ b/include/firm/gcd/blowfish.h @@ -0,0 +1,42 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - GCD - include + File: blowfish.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_GCD_BLOWFISH_H +#define FIRM_GCD_BLOWFISH_H + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + u32 P[16 + 2]; + u32 S[4][256]; +} BLOWFISH_CTX; + + +void InitBlowfish(BLOWFISH_CTX *ctx, const unsigned char *key, int keyLen); +void EncryptByBlowfish(const BLOWFISH_CTX *ctx, u32 *xl, u32 *xr); +void DecryptByBlowfish(const BLOWFISH_CTX *ctx, u32 *xl, u32 *xr); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // FIRM_GCD_BLOWFISH_H diff --git a/include/firm/gcd/gcd.h b/include/firm/gcd/gcd.h new file mode 100644 index 00000000..c9106759 --- /dev/null +++ b/include/firm/gcd/gcd.h @@ -0,0 +1,779 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - GCD - include + File: gcd.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_GCD_GCD_H_ +#define FIRM_GCD_GCD_H_ + +#include +#include +#include +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum +{ + GCD_PRIMARY_SLOT = 0, + GCD_SECONDARY_SLOT = 1, + + GCD_NO_SLOT = -1 +} +GCDSlot; + + +/*****************/ + +/* ROMwb_Eu[gp[^\ */ +typedef struct { + u8 *romAddr; // ROMAhX + u8 *entryAddr; // GgAhX + u8 *ramAddr; // RAMAhX + s32 romSize; // ROMTCY +} GCDBootUsrParam; + +// J[hANZXERg[WX^\ +typedef struct { + u16 latency1:13; // CeVP̃TCN + u16 dataScramble_on:1; // f[^XNu nm + u16 scrambleUnit_on:1; // XNuH nm + u16 initScramblePN:1; // XNuomf[^ + u16 latency2:6; // CeVQ̃TCN + u16 cmdScramble_on:1; // R}hXNu nm + u16 dataReady:1; // f[^ fB + u16 pages:3; // y[W + u16 clockType:1; // NbN^CviPTO^QSOj + u16 clockInLatency:1; // CeVԂɃNbN + u16 reset:1; // ZbgM + u16 accessMode:1; // ANZX[h + u16 start:1; // X^[g +} GCDCardCnt; + +// J[hRg[Ep[^\ +typedef struct { + // u32 dmaNo; // DMAԍ + u32 cardCnt; // J[hRg[ + u32 op[2]; // R}h +} GCDCardCtrlParam; + + +/* ROMwb_\ */ +typedef struct { + s8 titleName[12]; // \tg^Cg + u32 initialCode; // CjVR[h + + u16 makerCode; // [J[R[h + u8 machineCode; // {̃R[h + u8 deviceType; // foCX^Cv + + u8 nonVerReserved[4]; // \i4oCgj + u8 verDepReserved[4]; // \io[WˑA4oCgj + u16 wirelessSerialNo; + u16 softVersion:8; // \tgo[W + u16 compArm9BootArea:1; // ARM9u[gGAktO + u16 compArm7BootArea:1; // ARM7u[gGAktO + u16 :0; + + GCDBootUsrParam arm9; // ARM9u[g̈p[^ + GCDBootUsrParam arm7; // ARM7u[g̈p[^ + + u32 fileSysReserved[8]; // t@CVXe\i32oCgj + + GCDCardCnt romCtrl4Game; // ROMRg[iNORMAL & GAME[hj + GCDCardCnt romCtrl4Secure; // iSECURE[hj + u8 romCtrlReserved_l[4]; // \ + u16 secureCRC16; // ZLÄCRC16bit + u16 romTimerLatency; // ^C}[CeVi(TCN/256) - 2A3Dpj + u8 romReserved_h[8]; // \ + u32 romNormalModeKey[2]; // NORMAL[hL[ + + u8 reserved_80h[0x10]; // \̈i16oCgj + + u16 normalAreaOffset; // NORMAL̈ + u16 twlAreaOffset; // TWLp̈ + + u8 reserved_94h[0x2c]; // \̈i44oCgj + + u16 nintendoLogo[0x9c/2]; // NINTENDOSi156oCgj + u16 ninLogoCRC16; // NINTENDOSCRC16 + u16 headerCRC16; // wb_CRC16 + + u8 *dbgRomAddr; // fobKj^ROMAhX + s32 dbgRomSize; // fobKj^ROMTCY + u8 *dbgArm9RamAddr; // fobKj^ARM9-RAMAhX + u8 *dbgArm7RamAddr; // fobKj^ARM7-RAMAhX + + u8 reserved_170h[0x10]; // \̈i16oCgj +} +GCDRomHeaderDS; + +typedef struct { + // DS݊ + GCDRomHeaderDS l; + + // TWLg + MIHeader_WramRegs w; + + u8 reserved_1b0h[0x10]; // \̈i16oCgj + + GCDBootUsrParam arm9ex; // ARM9gu[g̈p[^ + GCDBootUsrParam arm7ex; // ARM7gu[g̈p[^ + + u8 reserved_1e0h[0x1000 - 0x1e0 - 0x200]; // \̈ + + u8 acsign_contents[0x180]; // Recؖ + + u8 acsign_header[0x80]; // ROMwb_dq +} +GCDRomHeader; + + +/* ZLA[N\ */ +typedef struct { + u8 recvRtcBuf[8]; // RTCf[^Mobt@iv4oCgEj +#if 0 + u16 flashCrc16; // tbVCRC16 + u16 flashCount; // tbV 8oCgJEg + u32 flashBuf[2]; // tbVMobt@iv4oCgEj + u32 flashKeyBuf[3]; // tbVL[Ee|obt@ +#endif + u32 unScrambleKey[2]; // XNuL[i8oCgAMakeBlowfishTable() ŎZoj + s16 isGenUnScrambleKey; // XNuL[iMakeBlowfishTable() Őݒj + + u32 va; // 24biti24bitMj + u32 vb; // 20biti+`4bitAVBI: 32bitMj + u32 vc_dummy; // 16biti16bitMj + u32 vd; // 24biti24bitMj + + GCDCardCnt cardCntBak4Secure; // SECURER}hp[^EobNAbv + s16 enableReadSecure; // SECURË惊[hECl[uiLoadSecure4Card() Őݒj + u32 cardNormalModeKey[2]; // NORMAL[hL[iMakeBlowfishTable() ŎZoj + u32 cardKeyBuf[3]; // J[hL[Ee|obt@ + s32 secureSize; // SECURËTCY + s16 sequenceNo4Secure; // V[PXԍiSECUREpj + s16 segmentTblShift; // ZOgԍe[uVtgliSECUREpj + u8 *segmentTblp; // ZOge[u|C^iSECUREpj + s16 numSecureSegment; // SECUREZOgiSECUREpj + s16 segmentOffset; // ZOgItZbgiSECUREpj + s16 blockOffset; // ubNItZbgiSECUREpj + + // CardCtrlParam paramBak; // J[hp[^ ÍOobNAbviSECUREpj + + BLOWFISH_CTX blowfishCardTable; // J[hpBlowfishe[u + BLOWFISH_CTX blowfishFlashTable; + + u8 bufEnd[4]; // ZLA[NŏIf[^ +} GCDSecureWork; + + +/* L[N\ */ +typedef struct { + u32 nCardID; // NORMALJ[hIDiLoadCardHeader() Ŏ擾j + u32 sCardID; // SECUREJ[hIDiCardTimerIntr4Secure() Ŏ擾j + u16 cardHeaderCrc16; // J[hwb_CRC16iLoadCardHeader() ŎZoj + u16 cardSecureCrc16; // J[hSECURËCRC16iLoadSecure4Card() ŎZoj + s16 cardHeaderError; // J[hwb_G[iCheckCardHeader() Őݒj + s16 disableEncryptedCardData;// J[hSECURËÍf[^iDecryptObjectFile() Őݒj + s16 cardSequenceNo; // J[hǂݍ݃V[PXԍ + s16 enableCardNormalOnly; // J[hNORMAL[ĥݗLiLoadFlashDemo() Őݒj + + // s16 isOnDebugger; // fobKœ쒆 + // s16 rtcError; // RTCG[ + + u32 recvRtc[2]; // RTCXe[^X1^C}[f[^iv4oCgEj + +} GCDSharedWork; + + +typedef union +{ + u64 dw; + u8 b[8]; +} +GCDCmd64; + +typedef struct +{ + u32 ctrl; + s32 cmdcount; + u32 latency; + u32 scramble; + u8 master; + u8 spi; + GCDSlot slot; +} +GCDCtrlRegs; + +typedef struct +{ + GCDCmd64 gcdOp; + u32 dmaNo; + u32 lastDmaNo; + BOOL ltckReq; + GCDCtrlRegs *gcdRegs; + GCDCtrlRegs nLoadTableRegs; + GCDCtrlRegs nSendOnlyOpRegs; + GCDCtrlRegs sSendOnlyOpRegs; + GCDCtrlRegs nIDRegs; + GCDCtrlRegs sIDRegs; + GCDCtrlRegs gIDRegs; + GCDCtrlRegs nReadShortHeaderRegs; + GCDCtrlRegs nReadRomRegs; + GCDCtrlRegs sReadRomRegs; + GCDCtrlRegs gReadRomRegs; + GCDCtrlRegs gWriteRomRegs; +} +GCDRomCtrls; + +typedef void (* GCDRomFuncp)( u32 romp, void *ramp, s32 size ); +typedef void (* GCDAsyncCoreFuncp)( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ); + + +typedef struct +{ + u32 romp; // ROM offset + u8 *ramp; // RAM address + s32 restSize; // rest size + s32 oneShotSize; // one shot size + vs8 intrDone; + s8 isAsync; + volatile BOOL isPxiDone; + GCDRomCtrls ctrls; + GCDAsyncCoreFuncp funcp; +} +GCDWork; + + +#define GCD_DEFAULT_DMA_A_NO 7 +#define GCD_DEFAULT_DMA_B_NO 6 + +#define GCD_CHATTERING_CYCLES 0x200U + +#define GCD_ROM_PAGE_SIZE 0x200 // 512B +#define GCD_SECURE_SEGMENT_SIZE 0x1000 // 4KB +#define GCD_LOAD_TABLE_SIZE 0x2000 // 8KB + +#define GCD_NML_AREA_ALIGN 0x80000 // 512KB +#define GCD_TWL_AREA_ALIGN 0x80000 // 512KB +#define GCD_SECURE2_AREA_SIZE 0x4000 // 16KB +#define GCD_SECURE2_AREA_OFFSET 0x3000 // 12KB +#define GCD_GAME2_AREA_OFFSET 0x7000 // 28KB + + +// ROM area + +#define GCD_LOAD_TABLE_SIZE 0x2000 // 8KB +#define GCD_DS_ROM_HEADER_SIZE 0x200 // 512B +#define GCD_ROM_HEADER_SIZE 0x1000 // 4KB +#define GCD_SECURE_AREA_SIZE 0x4000 // 16KB + +#define GCD_SECURE_AREA_OFFSET 0x4000 +#define GCD_GAME_AREA_OFFSET 0x8000 + + +// ROM command + +#define GCDOP_BIT_NUM 64 + +// NORMAL mode + +#define GCDOP_N_OP_MASK 0xff00000000000000ULL +#define GCDOP_N_OP_SIZE 8 + +#define GCDOP_N_OP_RD_ROM_ID 0x9000000000000000ULL +#define GCDOP_N_OP_RD_PAGE 0x0000000000000000ULL +#define GCDOP_N_OP_WR_PAGE 0x8000000000000000ULL +#define GCDOP_N_OP_LD_TABLE 0x9f00000000000000ULL +#define GCDOP_N_OP_CHG_MODE 0x3c00000000000000ULL +#define GCDOP_N_OP_CHG2_MODE 0x3d00000000000000ULL + +#define GCDOP_N_RD_ROM_ID_PAD 0x00ffffffffffffffULL +#define GCDOP_N_RD_PAGE_PAD 0x00fffffeff00ffffULL +#define GCDOP_N_CHG_MODE_PAD 0x00000000f00000ffULL +#define GCDOP_N_CHG2_MODE_PAD GCDOP_N_CHG_MODE_PAD + +#define GCDOP_N_RD_PAGE_ADDR_SHIFT 33 +#define GCDOP_N_RD_PAGE_ADDR_SIZE 23 +#define GCDOP_N_RD_PAGE_ADDR_MASK 0x00fffffe00000000ULL + +#define GCDOP_N_VAE_SHIFT 32 +#define GCDOP_N_VAE_SIZE 24 +#define GCDOP_N_VAE_MASK 0x00ffffff00000000ULL + +#define GCDOP_N_VBI_SHIFT 8 +#define GCDOP_N_VBI_SIZE 20 +#define GCDOP_N_VBI_MASK 0x000000000fffff00ULL + + +// SECURE mode + +#define GCDOP_S_OP_MASK 0xf000000000000000ULL +#define GCDOP_S_OP_SIZE 4 + +#define GCDOP_S_OP_RD_ROM_ID 0x1000000000000000ULL +#define GCDOP_S_OP_RD_SEGMENT 0x2000000000000000ULL +#define GCDOP_S_OP_PNG_ON 0x4000000000000000ULL +#define GCDOP_S_OP_PNG_OFF 0x6000000000000000ULL +#define GCDOP_S_OP_CHG_MODE 0xa000000000000000ULL + +#define GCDOP_S_VA_SHIFT GCDOP_S_VB_SIZE +#define GCDOP_S_VA_SIZE 24 +#define GCDOP_S_VA_MASK 0x00000ffffff00000ULL + +#define GCDOP_S_VB_SHIFT 0 +#define GCDOP_S_VB_SIZE 20 +#define GCDOP_S_VB_MASK 0x00000000000fffffULL + +#define GCDOP_S_VC_SHIFT (GCDOP_S_VA_SIZE + GCDOP_S_VB_SIZE) +#define GCDOP_S_VC_SIZE 16 +#define GCDOP_S_VC_MASK 0x0ffff00000000000ULL + +#define GCDOP_S_VD_SHIFT GCDOP_S_VA_SHIFT +#define GCDOP_S_VD_SIZE GCDOP_S_VA_SIZE +#define GCDOP_S_VD_MASK GCDOP_S_VA_MASK + + +// GAME mode + +#define GCDOP_G_OP_MASK 0xff00000000000000ULL +#define GCDOP_G_OP_SIZE 8 + +#define GCDOP_G_OP_RD_ROM_ID 0xb800000000000000ULL +#define GCDOP_G_OP_RD_ROM_UID 0xb900000000000000ULL +#define GCDOP_G_OP_RD_PAGE 0xb700000000000000ULL +#define GCDOP_G_OP_RD_CACHE_START 0x5800000000000000ULL +#define GCDOP_G_OP_RD_CACHE 0x6000000000000000ULL +#define GCDOP_G_OP_RD_CACHE_LAST 0x6800000000000000ULL +#define GCDOP_G_OP_WR_PAGE 0x8000000000000000ULL + +#define GCDOP_G_RD_ROM_ID_PAD 0x00ffffffffffffffULL +#define GCDOP_G_RD_ROM_UID_PAD 0x00ffffffffffffffULL +#define GCDOP_G_RD_PAGE_PAD 0x00f0000000ffffffULL + +#define GCDOP_G_RD_PAGE_ADDR_SHIFT 33 +#define GCDOP_G_RD_PAGE_ADDR_SIZE 23 +#define GCDOP_G_RD_PAGE_ADDR_MASK 0x000ffffe00000000ULL + + +// ROM ID + +#define GCD_ROMID_1TROM_MASK 0x80000000UL +#define GCD_ROMID_TWLROM_MASK 0x40000000UL +#define GCD_ROMID_BADBLK_MASK 0x20000000UL +#define GCD_ROMID_SIZE_MASK 0x0000ff00UL + + + +/*---------------------------------------------------------------------------* + Name: GCDi_ReadRomID + + Description: read rom ID + sync version + + Arguments: None + + Returns: rom ID + *---------------------------------------------------------------------------*/ +u32 GCDi_ReadRomID( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_ReadRom + + Description: read rom data + sync version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_ReadRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCDi_ReadRomAsync + + Description: read rom data + async version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_ReadRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCDi_ReadNormalModeRom + + Description: read rom data on normal mode + sync version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_ReadNormalModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCD_ReadNormalModeRomAsync + + Description: read rom data on normal mode + async version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_ReadNormalModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCDi_ReadGameModeRom + + Description: read rom data on game mode + sync version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_ReadGameModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCDi_ReadGameModeRomAsync + + Description: read rom data on game mode + async version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_ReadGameModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCDi_WriteGameModeRom + + Description: write rom data on game mode + sync version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_WriteGameModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCDi_WriteGameModeRomAsync + + Description: write rom data on game mode + async version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_WriteGameModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCDi_Enable + + Description: Enable game card master control + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_Enable( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_Disable + + Description: disable game card master control + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_Disable( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCD_SetPrimarySlot + + Description: set primary game card slot + + Arguments: primary slot + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_SetPrimarySlot( u8 slot ); + +/*---------------------------------------------------------------------------* + Name: GCD_GetPrimarySlot + + Description: get primary game card slot + + Arguments: None + + Returns: primary slot + *---------------------------------------------------------------------------*/ +u8 GCD_GetPrimarySlot(void ); + +/*---------------------------------------------------------------------------* + Name: GCD_Reset + + Description: reset game card + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_Reset( GCDSlot slot, u32 chat_cycles ); + +/*---------------------------------------------------------------------------* + Name: GCD_Reset + + Description: reset game card + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_ResetAll( u32 chat_cycles ); + +/*---------------------------------------------------------------------------* + Name: GCDi_SelectRom + + Description: select game card spi + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_SelectRom( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_SelectSpi + + Description: select game card spi + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_SelectSpi( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_SetDmaNo + + Description: set card dma number + + Arguments: dmaNo : dma channel number + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_SetDmaNo( GCDSlot slot, u32 dmaNo ); + +/*---------------------------------------------------------------------------* + Name: GCDi_GetDmaNo + + Description: get card dma number + + Arguments: None + + Returns: dmaNo : dma channel number + *---------------------------------------------------------------------------*/ +u32 GCDi_GetDmaNo( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_InterruptHandler + + Description: interrupt handler + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_InterruptHandlerPRIME( void ); +void GCDi_InterruptHandlerSECOND( void ); +void GCDi_InterruptHandlerCommon( GCDSlot slot ); + +//================================================================================ +// WAIT/STOP +//================================================================================ +/*---------------------------------------------------------------------------* + Name: GCDi_IsBusy + + Description: check whether game card is busy or not + + Arguments: None + + Returns: TRUE if game card is busy, FALSE if not + *---------------------------------------------------------------------------*/ +BOOL GCDi_IsBusy( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_IsDataReady + + Description: check whether data is ready or not + + Arguments: None + + Returns: TRUE if game card is busy, FALSE if not + *---------------------------------------------------------------------------*/ +BOOL GCDi_IsDataReady( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_Stop + + Description: stop game card access + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_Stop( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_WaitCtrl + + Description: wait while game card is busy + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_WaitCtrl( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_WaitData + + Description: wait until data is ready + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_WaitData( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_WaitDma + + Description: wait for stopping game card DMA + + Arguments: dmaNo : DMA channel No. + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_WaitDma( GCDSlot slot, u32 dmaNo ); + +/*---------------------------------------------------------------------------* + Name: GCDi_WaitInterrupt + + Description: wait for game card interrupt + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_WaitInterrupt( GCDSlot slot ); + + +// internal + +BOOL GCDi_IsSecureInitialized( GCDSlot slot ); +BOOL GCDi_IsCtrApp( GCDSlot slot ); +BOOL GCDi_IsDsApp( GCDSlot slot ); + +u32 GCDi_ReadNormalModeID( GCDSlot slot ); +u32 GCDi_ReadSecureModeID( GCDSlot slot ); +u32 GCDi_ReadGameModeID( GCDSlot slot ); + +u32 GCDi_ReadRomIDCore( GCDSlot slot, GCDRomCtrls *ctrls ); +void GCDi_ReadRomCore( GCDSlot slot, void *ramp, s32 size, GCDRomCtrls *ctrls ); +BOOL GCDi_ReadRomCommonPreCore( GCDSlot slot, u32 romp, void *ram, s32 size ); +void GCDi_WriteRomCore( GCDSlot slot, void *ramp, s32 size, GCDRomCtrls *ctrls ); + +void GCDi_ReadNormalModeRomCore( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ); + +void GCDi_InitSecureParam( GCDSlot slot, BOOL twl_ex ); +void GCDi_InitPngIntf( GCDSlot slot ); +void GCDi_SetInitCardOpBlowfish( void (*p)( void ) ); +void GCDi_SetDecryptObjectFilep( void (*p)( void ) ); +void GCDi_SetSetPngIntf( void (*p)( u32 pnA_l, u8 pnA_h, u32 pnB_l, u8 pnB_h ) ); +void GCDi_SetReadSecureModeIDCorep( u32 (p)( GCDRomCtrls *ctrls ) ); +void GCDi_SetReadSecureModeRomCorep( void (p)( u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ) ); +void GCDi_SetGetOneShotSizeFromCtrlp( s32 (p)( u32 ctrl ) ); + +void GCDi_SetSendOnlyCardOpCorep( void (*p)( GCDRomCtrls *ctrls ) ); +void GCDi_ChangeIntoSecureMode( GCDSlot slot ); +void GCDi_ChangeIntoSecure2Mode( GCDSlot slot ); +void GCDi_SendPngON( GCDSlot slot ); +void GCDi_SendPngOFF( GCDSlot slot ); +void GCDi_ChangeIntoGameMode( GCDSlot slot ); +void GCDi_ReadCardSegmentAsync4Secure( GCDSlot slot, BOOL twl_ex ); + +void GCDi_InitCardOpBlowfish( GCDSlot slot ); +void GCDi_InitCardOpBlowfishDS( GCDSlot slot ); +void GCDi_DecryptObjectFile( GCDSlot slot ); +void GCDi_DecryptObjectFileDS( GCDSlot slot ); + +void GCD_SetInterrupt( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDWork *wp ); + +void* GCDi_GetRomHeaderAddr( GCDSlot slot ); + + +extern u32 GCDi_HeaderBuf[2][ GCD_ROM_HEADER_SIZE/sizeof(u32) ]; +extern u32 GCDi_SecureAreaBuf[2][ GCD_SECURE_AREA_SIZE/sizeof(u32) ]; +extern u32 GCDi_Secure2AreaBuf[2][ GCD_SECURE_AREA_SIZE/sizeof(u32) ]; + +extern GCDSharedWork GCDi_SharedWork[2]; +extern GCDWork GCDi_Work[2]; + +// e[u +extern const BLOWFISH_CTX GCDi_BlowfishInitTableDS; +extern const BLOWFISH_CTX GCDi_BlowfishInitTableGCDFIRM; + + +// SecondarySlot̃J[hbNpӂĂȂ̂ŁAƂ肠PrimarySlotƋpŁB +s32 OS_LockExCard( u16 lockID ); +s32 OS_UnlockExCard( u16 lockID ); + +#ifdef __cplusplus +} /* extern "C" */ + +#endif + +/* FIRM_GCD_GCD_H_ */ +#endif diff --git a/include/firm/gcd/gcd_misc.h b/include/firm/gcd/gcd_misc.h new file mode 100644 index 00000000..4b3da84f --- /dev/null +++ b/include/firm/gcd/gcd_misc.h @@ -0,0 +1,516 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - GCD - include + File: ngcd.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_GCD_GCD_MISC_H_ +#define FIRM_GCD_GCD_MISC_H_ + +#include +#include "./gcd.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +#define PXI_FIFO_TAG_GCD PXI_FIFO_TAG_USER_1 + +#define reg_MI_MC_DET (*(REGType8v *) REG_MC_OFFSET) +#define reg_MI_MC_SWP (*(REGType8v *) ( REG_MC_OFFSET + 1 ) ) + +#define REG_MCCHAT_OFFSET 0x4012 +#define REG_MCCHAT_ADDR (HW_REG_BASE + REG_MCCHAT_OFFSET) +#define reg_MI_MCCHAT (*( REGType16v *) REG_MCCHAT_ADDR) + +/* MCSCRA_L */ + +#define REG_MCSCRA_L_OFFSET 0x1b0 +#define REG_MCSCRA_L_ADDR (HW_REG_BASE + REG_MCSCRA_L_OFFSET) +#define reg_MI_MCSCRA_L (*( REGType32v *) REG_MCSCRA_L_ADDR) + +/* MCSCRB_L */ + +#define REG_MCSCRB_L_OFFSET 0x1b4 +#define REG_MCSCRB_L_ADDR (HW_REG_BASE + REG_MCSCRB_L_OFFSET) +#define reg_MI_MCSCRB_L (*( REGType32v *) REG_MCSCRB_L_ADDR) + +/* MCSCRA_H */ + +#define REG_MCSCRA_H_OFFSET 0x1b8 +#define REG_MCSCRA_H_ADDR (HW_REG_BASE + REG_MCSCRA_H_OFFSET) +#define reg_MI_MCSCRA_H (*( REGType8v *) REG_MCSCRA_H_ADDR) + +/* MCSCRB_H */ + +#define REG_MCSCRB_H_OFFSET 0x1ba +#define REG_MCSCRB_H_ADDR (HW_REG_BASE + REG_MCSCRB_H_OFFSET) +#define reg_MI_MCSCRB_H (*( REGType8v *) REG_MCSCRB_H_ADDR) + + +#define REG_MI_MCCNT1_A_CSC_SHIFT 22 +#define REG_MI_MCCNT1_A_CSC_SIZE 1 +#define REG_MI_MCCNT1_A_CSC_MASK 0x00400000 + +#define REG_MI_MC_SWP_E_SHIFT 7 +#define REG_MI_MC_SWP_E_SIZE 1 +#define REG_MI_MC_SWP_E_MASK 0x80 + + + +typedef enum +{ + GCD_PAGE_0 = 0x0UL << REG_MI_MCCNT1_A_PC_SHIFT, + GCD_PAGE_1 = 0x1UL << REG_MI_MCCNT1_A_PC_SHIFT, + GCD_PAGE_2 = 0x2UL << REG_MI_MCCNT1_A_PC_SHIFT, + GCD_PAGE_4 = 0x3UL << REG_MI_MCCNT1_A_PC_SHIFT, + GCD_PAGE_8 = 0x4UL << REG_MI_MCCNT1_A_PC_SHIFT, + GCD_PAGE_16 = 0x5UL << REG_MI_MCCNT1_A_PC_SHIFT, + GCD_PAGE_32 = 0x6UL << REG_MI_MCCNT1_A_PC_SHIFT, + GCD_PAGE_STAT = 0x7UL << REG_MI_MCCNT1_A_PC_SHIFT +} +GCDPageCount; + +typedef enum +{ + GCD_CKT_150NS = 0x0UL << REG_MI_MCCNT1_A_CT_SHIFT, + GCD_CKT_240NS = 0x1UL << REG_MI_MCCNT1_A_CT_SHIFT +} +GCDClockType; + +typedef enum +{ + GCD_RW_READ = 0x0UL << REG_MI_MCCNT1_WR_SHIFT, + GCD_RW_WRITE = 0x1UL << REG_MI_MCCNT1_WR_SHIFT +} +GCDRw; + +typedef enum +{ + GCD_RESET_LO = 0x0UL << REG_MI_MCCNT1_A_RESB_SHIFT, + GCD_RESET_HI = 0x1UL << REG_MI_MCCNT1_A_RESB_SHIFT +} +GCDReset; + +typedef enum +{ +#ifdef SDK_ARM9 + GCD_LTCK_DISABLE = 0x0UL << REG_MI_MCCNT1_A_TRM_SHIFT, + GCD_LTCK_ENABLE = 0x1UL << REG_MI_MCCNT1_A_TRM_SHIFT +#else + GCD_LTCK_DISABLE = 0x0UL << REG_MI_MCCNT1_A_RTM_SHIFT, + GCD_LTCK_ENABLE = 0x1UL << REG_MI_MCCNT1_A_RTM_SHIFT +#endif +} +GCDLtClkEnable; + +typedef struct +{ + u32 ctrl; + u8 master; + u8 spi; +} +NGCDCtrlRegs; + +// PXIł̒ʐMvgR֘A` +#define GCD_PXI_COMMAND_MASK 0x0000003f // Jn[h̃R}h +#define GCD_PXI_COMMAND_SHIFT 0 +#define GCD_PXI_COMMAND_SIZE 6 +#define GCD_PXI_COMMAND_PARAM_MASK 0x03ffffc0 // Jn[h̃p[^ +#define GCD_PXI_COMMAND_PARAM_SHIFT 6 +#define GCD_PXI_COMMAND_PARAM_SIZE 20 + +typedef union +{ + struct + { + u32 cmd:GCD_PXI_COMMAND_SIZE; + u32 param:GCD_PXI_COMMAND_PARAM_SIZE-1; + u32 slot:1; + } + e; + u32 raw; +} +GCDPxiCmd; + +// PXIoRŔs閽 +#define GCD_PXI_COMMAND_RESET 0x01 +#define GCD_PXI_COMMAND_LOADED 0x02 + + +/*---------------------------------------------------------------------------* + Name: GCD_Init + + Description: initialize for game card access + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_Init( void ); + +/*---------------------------------------------------------------------------* + Name: GCDi_Init + + Description: initialize for game card access + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_Init( BOOL reset ); + +/*---------------------------------------------------------------------------* + Name: GCD_ReadRomID + + Description: read rom ID + sync version + + Arguments: None + + Returns: rom ID + *---------------------------------------------------------------------------*/ +u32 GCD_ReadRomID( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCD_ReadRom + + Description: read rom data + sync version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_ReadRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCD_ReadRomAsync + + Description: read rom data + async version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_ReadRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCD_ReadNormalModeRom + + Description: read rom data on normal mode + sync version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_ReadNormalModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCD_ReadGameModeRom + + Description: read rom data on game mode + sync version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_ReadGameModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCD_ReadRomPreCore + + Description: read rom data + sync version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL GCD_ReadRomPreCore( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCD_ReadGameModeRomAsync + + Description: read rom data on game mode + async version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_ReadGameModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCD_WriteGameModeRom + + Description: write rom data on game mode + sync version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_WriteGameModeRom( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCD_WriteGameModeRomAsync + + Description: write rom data on game mode + async version + + Arguments: romp : rom offset + ramp : ram destination address + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_WriteGameModeRomAsync( GCDSlot slot, u32 romp, void *ramp, s32 size ); + +/*---------------------------------------------------------------------------* + Name: GCDi_Enable + + Description: Enable game card master control + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_Enable( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_Disable + + Description: disable game card master control + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCDi_Disable( GCDSlot slot ); + +//================================================================================ +// WAIT/STOP +//================================================================================ +/*---------------------------------------------------------------------------* + Name: GCD_IsExisting + + Description: get whether cartridge exists + + Arguments: None + + Returns: TRUE if game card is busy, FALSE if not + *---------------------------------------------------------------------------*/ +static inline BOOL GCD_IsExisting( GCDSlot slot ) +{ + s32 ofs = (GCD_GetPrimarySlot() ^ slot) * 4; + s32 r = ~reg_MI_MC_DET & (REG_MI_MC_SL1_CDET_MASK << ofs); + return r >> (REG_MI_MC_SL1_CDET_SHIFT + ofs); +} + +/*---------------------------------------------------------------------------* + Name: GCD_SetDetectMode + + Description: + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void GCD_SetDetectMode( GCDSlot slot, u32 mode ) +{ + s32 ofs = (GCD_GetPrimarySlot() ^ slot) * 4; + s32 others = reg_MI_MC_DET & ~(REG_MI_MC_SL1_MODE_MASK << ofs); + reg_MI_MC_DET = (u8)((mode << (REG_MI_MC_SL1_MODE_SHIFT + ofs)) | others); +} + +/*---------------------------------------------------------------------------* + Name: GCD_GetDetectMode + + Description: + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +static inline u8 GCD_GetDetectMode( GCDSlot slot ) +{ + s32 ofs = (GCD_GetPrimarySlot() ^ slot) * 4; + return (u8)((reg_MI_MC_DET & (REG_MI_MC_SL1_MODE_MASK << ofs)) + >> (REG_MI_MC_SL1_MODE_SHIFT + ofs)); +} + +/*---------------------------------------------------------------------------* + Name: GCD_SetChatCounter + + Description: + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void GCD_SetChatCounter( u16 value ) +{ + reg_MI_MCCHAT = value; +} + +/*---------------------------------------------------------------------------* + Name: GCD_IsBusy + + Description: check whether game card is busy or not + + Arguments: None + + Returns: TRUE if game card is busy, FALSE if not + *---------------------------------------------------------------------------*/ +BOOL GCD_IsBusy( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCD_IsDataReady + + Description: check whether data is ready or not + + Arguments: None + + Returns: TRUE if game card is busy, FALSE if not + *---------------------------------------------------------------------------*/ +BOOL GCD_IsDataReady( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCD_Stop + + Description: stop game card access + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_Stop( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCD_WaitRomAsync + + Description: wait for game card async access + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void GCD_WaitRomAsync( GCDSlot slot ); + +/*---------------------------------------------------------------------------* + Name: GCDi_SelectRegAddr + + Description: + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void* GCDi_SelectRegAddr( GCDSlot slot, u32 base ) +{ + u32 addr = base; + + if ( slot == GCD_SECONDARY_SLOT ) + { + addr += REG_MCCNT0_B_ADDR - REG_MCCNT0_ADDR; + } + + return (void*)addr; +} + +/*---------------------------------------------------------------------------* + Name: GCDi_SelectIrqMask + + Description: + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +static inline u32 GCDi_SelectIrqMask( GCDSlot slot, u32 base_mask ) +{ + u32 mask = base_mask; + + if ( slot == GCD_SECONDARY_SLOT ) + { + switch ( mask ) + { + case OS_IE_CARD_DATA: + mask = OS_IE_CARD_B_DATA; + break; + case OS_IE_CARD_IREQ: + mask = OS_IE_CARD_B_IREQ; + break; + case OS_IE_CARD_A_DET: + mask = OS_IE_CARD_B_DET; + break; + } + } + + return mask; +} + + +// internal + +u32 GCD_ReadNormalModeID( GCDSlot slot ); +u32 GCD_ReadSecureModeID( GCDSlot slot ); +u32 GCD_ReadGameModeID( GCDSlot slot ); + +void GCDi_SetOp( GCDSlot slot, GCDCmd64* op ); +void GCDi_SetCtrl( GCDSlot slot, GCDCtrlRegs* regs ); +void GCDi_GenCtrl( GCDCtrlRegs* regs, + GCDRw rw, + GCDPageCount pcount, + GCDClockType ckt, u32 lt1, u32 lt2, + BOOL cpn, BOOL dpn, BOOL csc, BOOL dsc ); +s32 GCDi_GetOneShotSizeFromCtrl( u32 ctrl ); +void GCD_SendOnlyCardOpCore( GCDSlot slot, GCDRomCtrls *ctrls ); +u32 GCDi_ReadRomIDCore( GCDSlot slot, GCDRomCtrls *ctrls ); +void GCD_ReadRomCore( GCDSlot slot, u32 romp, void *ramp, s32 size, GCDRomCtrls *ctrls ); +void GCD_WaitRomAsyncCore( GCDSlot slot ); + +void GCDi_WaitCtrl( GCDSlot slot ); +void GCDi_WaitData( GCDSlot slot ); +void GCDi_WaitDma( GCDSlot slot, u32 dmaNo ); +void GCDi_WaitInterrupt( GCDSlot slot ); + +void GCDi_SendtoPxi(u32 data); + +#ifdef __cplusplus +} /* extern "C" */ + +#endif + +/* FIRM_GCD_GCD_MISC_H_ */ +#endif diff --git a/include/firm/hw/ARM7/mmap_firm.h b/include/firm/hw/ARM7/mmap_firm.h new file mode 100644 index 00000000..0a4752ab --- /dev/null +++ b/include/firm/hw/ARM7/mmap_firm.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - HW - include + File: mmap_firm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_HW_MMAP_FIRM_H_ +#define FIRM_HW_MMAP_FIRM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +//------------------------------------- FIRM +#define HW_FIRM HW_WRAM +#define HW_FIRM_END (HW_FIRM + HW_FIRM_SIZE) +#define HW_FIRM_SIZE (HW_WRAM_0_SIZE + HW_WRAM_1_SIZE + HW_WRAM_A_SIZE_MAX + HW_WRAM_B_SIZE_MAX) + +//------------------------------------- FIRM_SVC_STACK +#define HW_FIRM_SVC_STACK (HW_FIRM_SVC_STACK_END-HW_FIRM_SVC_STACK_SIZE) +#define HW_FIRM_SVC_STACK_END (HW_WRAM_AREA_END - HW_PRV_WRAM_SYSRV_SIZE) +#define HW_FIRM_SVC_STACK_SIZE HW_SVC_STACK_SIZE + +//------------------------------------- FIRM_IRQ_STACK +#define HW_FIRM_IRQ_STACK (HW_FIRM_IRQ_STACK_END-HW_FIRM_IRQ_STACK_SIZE) +#define HW_FIRM_IRQ_STACK_END HW_FIRM_SVC_STACK +#define HW_FIRM_IRQ_STACK_SIZE SDK_IRQ_STACKSIZE + +//------------------------------------- FIRM_FROM_BROM_BUF +#define HW_FIRM_FROM_BROM_BUF (HW_FIRM_FROM_BROM_BUF_END - HW_FIRM_FROM_BROM_BUF_SIZE) +#define HW_FIRM_FROM_BROM_BUF_END (HW_WRAM_AREA_END - 0x1000) // END - 4KB +#define HW_FIRM_FROM_BROM_BUF_SIZE 0x3000 // 12KB + +//------------------------------------- FIRM_FROM_FIRM_BUF +#define HW_FIRM_FROM_FIRM_BUF (HW_FIRM_FROM_FIRM_BUF_END - HW_FIRM_FROM_FIRM_BUF_SIZE) +#define HW_FIRM_FROM_FIRM_BUF_END (HW_WRAM_AREA_END - 0x1000) // END - 4KB +#define HW_FIRM_FROM_FIRM_BUF_SIZE 0x2C00 // 11KB + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_HW_MMAP_FIRM_H_ */ +#endif diff --git a/include/firm/hw/ARM9/mmap_firm.h b/include/firm/hw/ARM9/mmap_firm.h new file mode 100644 index 00000000..9b2c9aec --- /dev/null +++ b/include/firm/hw/ARM9/mmap_firm.h @@ -0,0 +1,51 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - HW - include + File: mmap_firm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_HW_MMAP_FIRM_H_ +#define FIRM_HW_MMAP_FIRM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +//------------------------------------- FIRM +#define HW_FIRM HW_WRAM_EX +#define HW_FIRM_END (HW_FIRM + HW_FIRM_SIZE) +#define HW_FIRM_SIZE HW_WRAM_C_SIZE_MAX + +//------------------------------------- FIRM_RESET_BUF +#define HW_FIRM_RESET_BUF HW_MAIN_MEM +#define HW_FIRM_RESET_BUF_END (HW_FIRM_RESET_BUF + HW_FIRM_RESET_BUF_SIZE) +//#define HW_FIRM_RESET_BUF_SIZE 0x400 // 12KB +#define HW_FIRM_RESET_BUF_SIZE 0x800000 // 8MB + +//------------------------------------- FIRM_FROM_BROM_BUF +#define HW_FIRM_FROM_BROM_BUF (HW_FIRM_FROM_BROM_BUF_END - HW_FIRM_FROM_BROM_BUF_SIZE) +#define HW_FIRM_FROM_BROM_BUF_END (HW_ITCM_END - 0x1000) // END - 4KB +#define HW_FIRM_FROM_BROM_BUF_SIZE 0x3000 // 12KB + +//------------------------------------- FIRM_FROM_FIRM_BUF +#define HW_FIRM_FROM_FIRM_BUF (HW_FIRM_FROM_FIRM_BUF_END - HW_FIRM_FROM_FIRM_BUF_SIZE) +#define HW_FIRM_FROM_FIRM_BUF_END (HW_ITCM_END - 0x1000) // END - 4KB +#define HW_FIRM_FROM_FIRM_BUF_SIZE 0x2C00 // 11KB + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_HW_MMAP_FIRM_H_ */ +#endif diff --git a/include/firm/hw/common/mmap_firm.h b/include/firm/hw/common/mmap_firm.h new file mode 100644 index 00000000..dd22402e --- /dev/null +++ b/include/firm/hw/common/mmap_firm.h @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - HW - include + File: mmap_firm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_HW_COMMON_MMAP_FIRM_H_ +#define FIRM_HW_COMMON_MMAP_FIRM_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +//------------------------------------- *_LoadBuffer +#define HW_FIRM_LOAD_BUFFER_BASE MI_GetWramMapStart_B() +#define HW_FIRM_LOAD_BUFFER_UNIT_SIZE 0x8000 +#define HW_FIRM_LOAD_BUFFER_UNIT_NUMS 8 +#define HW_FIRM_LOAD_BUFFER_SIZE (HW_FIRM_LOAD_BUFFER_UNIT_SIZE * HW_FIRM_LOAD_BUFFER_UNIT_NUMS) +#define HW_FIRM_LOAD_BUFFER_END (HW_FIRM_LOAD_BUFFER_BASE + HW_FIRM_LOAD_BUFFER_SIZE) + +//------------------------------------- FS/FATFS +#define HW_FIRM_FS_AES_BUFFER (HW_FIRM_FS_AES_BUFFER_END - HW_FIRM_FS_AES_BUFFER_SIZE) // 0x02FF3800 +#define HW_FIRM_FS_AES_BUFFER_SIZE 0x4000 +#define HW_FIRM_FS_AES_BUFFER_END HW_FIRM_FATFS_COMMAND_BUFFER // 0x02ff7800 + +#define HW_FIRM_FATFS_COMMAND_BUFFER (HW_FIRM_FATFS_COMMAND_BUFFER_END - HW_FIRM_FATFS_COMMAND_BUFFER_SIZE) +#define HW_FIRM_FATFS_COMMAND_BUFFER_SIZE FATFS_COMMAND_BUFFER_MAX // 0x800 +#define HW_FIRM_FATFS_COMMAND_BUFFER_END HW_FIRM_FS_TEMP_BUFFER // 0x02ff8000 + +#define HW_FIRM_FS_TEMP_BUFFER (HW_FIRM_FS_TEMP_BUFFER_END - HW_FIRM_FS_TEMP_BUFFER_SIZE) +#define HW_FIRM_FS_TEMP_BUFFER_SIZE FS_TEMPORARY_BUFFER_MAX // 0x4000 +#define HW_FIRM_FS_TEMP_BUFFER_END HW_TWL_MAIN_MEM_SHARED // 0x02ffc000 + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_HW_COMMON_MMAP_FIRM_H_ */ +#endif diff --git a/include/firm/memorymap.h b/include/firm/memorymap.h new file mode 100644 index 00000000..fa95b481 --- /dev/null +++ b/include/firm/memorymap.h @@ -0,0 +1,30 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - include - HW + File: memorymap.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_MEMORYMAP_H_ +#define FIRM_MEMORYMAP_H_ + +#include +#include + +#ifdef SDK_ARM9 +#include +#else //SDK_ARM7 +#include +#endif + +/* FIRM_MEMORYMAP_H_ */ +#endif diff --git a/include/firm/mi.h b/include/firm/mi.h new file mode 100644 index 00000000..475c4c18 --- /dev/null +++ b/include/firm/mi.h @@ -0,0 +1,30 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - include - MI + File: mi.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_MI_H_ +#define FIRM_MI_H_ + +#include + +#include +#include +#ifdef SDK_ARM9 +#include +#endif + +/* FIRM_MI_H_ */ +#endif diff --git a/include/firm/mi/ARM9/mi_loader.h b/include/firm/mi/ARM9/mi_loader.h new file mode 100644 index 00000000..86350ba3 --- /dev/null +++ b/include/firm/mi/ARM9/mi_loader.h @@ -0,0 +1,109 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - mi + File: mi_loader.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_MI_LOADER_H_ +#define FIRM_MI_LOADER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: MIi_LoadBuffer + + Description: receive data from ARM7 and store(move) via WRAM[B] + + LoadBufferJjYŁAt@C̓eARM7󂯎܂B + SVCSHA1Contextw肵ĂꍇARs[̂‚łSHA1 + vZs܂B + + [LoadBufferJjY] + WRAM[B]𗘗pāAARM7,ARM9Ԃ̃f[^]s܂B + WRAM[B]̊eXbgoPc[œn܂B + 1Xbg̃f[^܂͑Sf[^i[ꂽƂAARM7 + FIRM_PXI_ID_LOAD_PIRIODM܂B + ARM9͎Mɂ̃Xbg̎gpARM9ɕύXăf[^ + oAɃNA(ZLeB)Agp + ARM7ɖ߂܂B + + [gp] + WRAM[B]bNAԂƂARM7ɓ|ĂƁB + + [ӓ_] + offsetsizeARM7ʒm܂Bʂ̌oHœĂB + SRLt@Cǂݍޏꍇ́A݂ROMwb_QƂłΏ\łB + (ROMwb_͌mĂ͂) + + ⑫: + ł́A郉CuARM7/ARM9ŕ킹邱Ƃ + OɂĂ邪AėpIɂɂ(ƗCuȂ)A + MŃXbg𔼕‚ƂAꂼɎMPXIR[obN + XbhpӂAMAPIf[^WRAMɊi[A + destsizeʒmƂ`OKł͂ȂH + (ŊԎԂ) + + Arguments: dest destination address for received data + size size to load + ctx context for SHA1 if execute SVC_SHA1Update + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL MI_LoadBuffer(u8* dest, u32 size, SVCSHA1Context *ctx); + +/*---------------------------------------------------------------------------* + Name: MI_LoadHeader + + Description: load header + + Arguments: pool pointer to the pool info for SVCSignHeapContext + rsa_key key address + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL MI_LoadHeader( SVCSignHeapContext* pool, const void* rsa_key ); + +/*---------------------------------------------------------------------------* + Name: MI_LoadStatic + + Description: load static binary + + Arguments: None + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL MI_LoadStatic( void ); + +/*---------------------------------------------------------------------------* + Name: MI_Boot + + Description: boot + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void MI_Boot( void ); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +/* FIRM_MI_LOADER_H_ */ +#endif 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/mi/mainMemory.h b/include/firm/mi/mainMemory.h new file mode 100644 index 00000000..9a4b58b9 --- /dev/null +++ b/include/firm/mi/mainMemory.h @@ -0,0 +1,141 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - include - MI + File: mainMemory.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_MI_MAINMEMORY_H_ +#define FIRM_MI_MAINMEMORY_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct +{ + u16 cr0; + u16 cr1; + u16 cr2; +} +MIMmemCR; + +//---------------------------------------------------------------------- +// C CRR}h +//---------------------------------------------------------------------- + +// for DS-PSRAM + +// CR0 +#define MMEM_DCR0_PARTIAL_REFRESH_NONE 0x0003 // p[VtbV +#define MMEM_DCR0_BURST_CONTINUOUS 0x001c // Ao[XgiQQSoCgj +#define MMEM_DCR0_BURST_MODE 0x0000 // o[Xg[h +#define MMEM_DCR0_PAGE_MODE 0x0020 // y[W[h +#define MMEM_DCR0_SB1 0xffc0 // PŒ + +// CR1 +#define MMEM_DCR1_1ST_R4_W3 0x0002 // Pq^v S^R +#define MMEM_DCR1_BURST_WRITE 0x0000 // o[XgCg +#define MMEM_DCR1_CLOCK_TRIGGER_UP 0x0100 // NbN +#define MMEM_DCR1_BURST_LINER 0x0200 // o[XgjAEV[PX +#define MMEM_DCR1_SB1 0xe430 // PŒ + +// CR2 +#define MMEM_DCR2_SB1 0x004003fe // PŒ +#define MMEM_DCR2_CLOCK_TRIGGER_UP 0x00000400 // NbN +#define MMEM_DCR2_BURST_WRITE 0x00000000 // o[XgCg +#define MMEM_DCR2_BURST_LINER 0x00001000 // o[XgjAEV[PX +#define MMEM_DCR2_1ST_R4_W3 0x00004000 // Pq^v S^R +#define MMEM_DCR2_BURST_MODE 0x00000000 // o[Xg[h +#define MMEM_DCR2_PAGE_MODE 0x00010000 // y[W[h +#define MMEM_DCR2_BURST_CONTINUOUS 0x000e0000 // Ao[XgiQQSoCgj +#define MMEM_DCR2_PARTIAL_REFRESH_NONE 0x00300000 // p[VtbV + +// for TWL-PSRAM + +// CR0 +#define MMEM_TCR0_SET 0x0001 // Zbg +#define MMEM_TCR0_VERIFY 0x0000 // xt@C +#define MMEM_TCR0_SB1 0xfffe // PŒ + +#define MMEM_TCR0 (MMEM_TCR0_SET | \ + MMEM_TCR0_SB1) // 0xFFFF + +#define MMEM_TCR0_R (MMEM_TCR0_VERIFY | \ + MMEM_TCR0_SB1) // 0xFFFE + +// CR1 +#define MMEM_TCR1_PARTIAL_REFRESH_8MB 0x0002 // p[VtbV擪Wla +#define MMEM_TCR1_BURST_CONTINUOUS 0x001c // Ao[XgiQQSoCgj +#define MMEM_TCR1_BURST_MODE 0x0000 // o[Xg[h +#define MMEM_TCR1_DRV_SZ_CENTER 0x00c0 // hCo[TCYS +#define MMEM_TCR1_SB1 0xff00 // PŒ + +#define MMEM_TCR1 (MMEM_TCR1_PARTIAL_REFRESH_8MB | \ + MMEM_TCR1_BURST_CONTINUOUS | \ + MMEM_TCR1_BURST_MODE | \ + MMEM_TCR1_DRV_SZ_CENTER | \ + MMEM_TCR1_SB1) // 0xFFDE +// CR2 +#define MMEM_TCR2_1ST_R4_W3 0x0002 // Pq^v S^R +#define MMEM_TCR2_REMAIN_PRV_MODE 0x0040 // O[hێ +#define MMEM_TCR2_WE_LEVEL 0x0080 // vdxRg[ +#define MMEM_TCR2_SB1 0xff28 // PŒ + +#define MMEM_TCR2 (MMEM_TCR2_1ST_R4_W3 | \ + MMEM_TCR2_REMAIN_PRV_MODE | \ + MMEM_TCR2_WE_LEVEL | \ + MMEM_TCR2_SB1) // 0xFFEA + + +/*---------------------------------------------------------------------------* + Name: MIi_InitMainMemCR + + Description: change main memory into the burst mode + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_InitMainMemCR( BOOL setCR ); + +void MIi_GetMainMemCR( MIMmemCR* dest ); + +/*---------------------------------------------------------------------------* + Name: MIi_IsMainMemoryInitialized + + Description: + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL MIi_IsMainMemoryInitialized( void ); + +/*---------------------------------------------------------------------------* + Name: MIi_WaitMainMemoryInitialize + + Description: + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void MIi_WaitMainMemoryInitialize( void ); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_MI_MAINMEMORY_H_ */ +#endif diff --git a/include/firm/misc.h b/include/firm/misc.h new file mode 100644 index 00000000..36d3cfc4 --- /dev/null +++ b/include/firm/misc.h @@ -0,0 +1,33 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - include - + File: misc.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_MISC_H_ +#define FIRM_MISC_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define offsetof(t, memb) ((size_t)(&(((t *)0)->memb))) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_MISC_H_ */ +#endif diff --git a/include/firm/nvram.h b/include/firm/nvram.h new file mode 100644 index 00000000..ea9e4c89 --- /dev/null +++ b/include/firm/nvram.h @@ -0,0 +1,43 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - NVRAM + File: nvram.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_NVRAM_H_ +#define FIRM_NVRAM_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SDK_ARM9 +#else // SDK_ARM7 + +/*---------------------------------------------------------------------------* + ֐` + *---------------------------------------------------------------------------*/ +void NVRAMi_Read(u32 address, void *buf, u32 size); +void NVRAMi_Write(u32 address, void *buf, u32 size); + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_NVRAM_H_ */ +#endif diff --git a/include/firm/os.h b/include/firm/os.h new file mode 100644 index 00000000..f91cfcf3 --- /dev/null +++ b/include/firm/os.h @@ -0,0 +1,36 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - OS + File: os.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_OS_H_ +#define FIRM_OS_H_ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_OS_H_ */ +#endif diff --git a/include/firm/os/ARM9/os_cache_tag.h b/include/firm/os/ARM9/os_cache_tag.h new file mode 100644 index 00000000..7116eaf6 --- /dev/null +++ b/include/firm/os/ARM9/os_cache_tag.h @@ -0,0 +1,151 @@ +/*---------------------------------------------------------------------------* + 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/firm/os/common/boot.h b/include/firm/os/common/boot.h new file mode 100644 index 00000000..d4ec0318 --- /dev/null +++ b/include/firm/os/common/boot.h @@ -0,0 +1,98 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - OS - include + File: boot.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_OS_BOOT_H_ +#define FIRM_OS_BOOT_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: OS_BootWithRomHeaderFromFIRM + + Description: boot with ROM header + + Arguments: rom_header : ROM header + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_BootWithRomHeaderFromFIRM( ROM_Header* rom_header ); + +/*---------------------------------------------------------------------------* + Name: OS_BootDefault + + Description: boot system menu using ROM_Header in HW_TWL_ROM_HEADER_BUF + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void OS_BootFromFIRM( void ) +{ + OS_BootWithRomHeaderFromFIRM( (ROM_Header*)HW_TWL_ROM_HEADER_BUF ); +} + +/*---------------------------------------------------------------------------* + Name: OSi_FromBromToMenu + + Description: convert OSFromBromBuf to OSFromFirmBuf + + Arguments: None + + Returns: FALSE if FromBrom is broken + *---------------------------------------------------------------------------*/ +BOOL OSi_FromBromToMenu( void ); + +/*---------------------------------------------------------------------------* + Name: OSi_GetFromBromAddr + + Description: data address from bootrom to firm + + Arguments: None + + Returns: address + *---------------------------------------------------------------------------*/ +static inline OSFromBromBuf* const OSi_GetFromBromAddr( void ) +{ + return (OSFromBromBuf*)HW_FIRM_FROM_BROM_BUF; +} + +/*---------------------------------------------------------------------------* + Name: OSi_GetFromFirmAddr + + Description: data address from firm to menu + + Arguments: None + + Returns: address + *---------------------------------------------------------------------------*/ +static inline OSFromFirmBuf* const OSi_GetFromFirmAddr( void ) +{ + return (OSFromFirmBuf*)HW_FIRM_FROM_FIRM_BUF; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_OS_BOOT_H_ */ +#endif diff --git a/include/firm/os/common/init.h b/include/firm/os/common/init.h new file mode 100644 index 00000000..45e596ca --- /dev/null +++ b/include/firm/os/common/init.h @@ -0,0 +1,43 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - OS - include + File: init.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_OS_INIT_H_ +#define FIRM_OS_INIT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: OS_InitFIRM + + Description: initialize sdk os for firm + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_InitFIRM(void); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_OS_INIT_H_ */ +#endif diff --git a/include/firm/os/common/system.h b/include/firm/os/common/system.h new file mode 100644 index 00000000..2cdd5f8c --- /dev/null +++ b/include/firm/os/common/system.h @@ -0,0 +1,53 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - OS - include + File: system.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. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ +#ifndef TWL_FIRM_OS_SYSTEM_H_ +#define TWL_FIRM_OS_SYSTEM_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +//---------------------------------------------------------------------------- + +typedef u32 OSCpuCycle; + +#define OS_CPU_CLOCK HW_CPU_CLOCK + +//---- sec to cpu cycle +// 150nsec - 30sec +#define OS_SEC_TO_CPUCYC( sec ) ((OSCpuCycle)( ( OS_CPU_CLOCK * (u32)(sec)) )) +#define OS_MSEC_TO_CPUCYC( msec ) ((OSCpuCycle)( ((OS_CPU_CLOCK/1000) * (u32)(msec)) )) +#define OS_USEC_TO_CPUCYC( usec ) ((OSCpuCycle)( ((OS_CPU_CLOCK/1000) * (u32)(usec)) / 1000 )) +#define OS_NSEC_TO_CPUCYC( nsec ) ((OSCpuCycle)( ((OS_CPU_CLOCK/1000) * (u32)(nsec)) / (1000 * 1000) )) + +//---- cpu cycle to sec +// 150nsec - 30sec +#define OS_CPUCYC_TO_SEC( cyc ) ( ((u32)(cyc) ) / OS_CPU_CLOCK ) +#define OS_CPUCYC_TO_MSEC( cyc ) ( ((u32)(cyc) ) / (OS_CPU_CLOCK/1000) ) +#define OS_CPUCYC_TO_USEC( cyc ) ( ((u32)(cyc) * 1000) / (OS_CPU_CLOCK/1000) ) +#define OS_CPUCYC_TO_NSEC( cyc ) ( ((u32)(cyc) * 1000 * 1000) / (OS_CPU_CLOCK/1000) ) + + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* TWL_FIRM_OS_SYSTEM_H_ */ +#endif diff --git a/include/firm/os/common/tick_brom.h b/include/firm/os/common/tick_brom.h new file mode 100644 index 00000000..c0471bfd --- /dev/null +++ b/include/firm/os/common/tick_brom.h @@ -0,0 +1,51 @@ +/*---------------------------------------------------------------------------* + Project: TwlBromSDK - OS - include + File: tick_addin.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 FRIM_OS_TICK_BROM_H_ +#define FRIM_OS_TICK_BROM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +//---- sec to tick +#define OS_MicroSecondsToTicksBROM( usec ) ((OSTick)( ((OS_SYSTEM_CLOCK/1000) * (u64)(usec)) / 1024 / 1000 )) +#define OS_MicroSecondsToTicksBROM32( usec ) ((OSTick)( ((OS_SYSTEM_CLOCK/1000) * (u32)(usec)) / 1024 / 1000 )) + +#define OS_MilliSecondsToTicksBROM( msec ) ((OSTick)( ((OS_SYSTEM_CLOCK/1000) * (u64)(msec)) / 1024 )) +#define OS_MilliSecondsToTicksBROM32( msec ) ((OSTick)( ((OS_SYSTEM_CLOCK/1000) * (u32)(msec)) / 1024 )) + +#define OS_SecondsToTicksBROM( sec ) ((OSTick)( (OS_SYSTEM_CLOCK * (u64)(sec)) / 1024 )) +#define OS_SecondsToTicksBROM32( sec ) ((OSTick)( (OS_SYSTEM_CLOCK * (u32)(sec)) / 1024 )) + +//---- tick to sec +#define OS_TicksToMicroSecondsBROM( tick ) ( ((u64)(tick) * 1024 * 1000) / (OS_SYSTEM_CLOCK/1000) ) +#define OS_TicksToMicroSecondsBROM32( tick ) ( ((u32)(tick) * 1024 * 1000) / (OS_SYSTEM_CLOCK/1000) ) + +#define OS_TicksToMilliSecondsBROM( tick ) ( ((u64)(tick) * 1024) / (OS_SYSTEM_CLOCK/1000) ) +#define OS_TicksToMilliSecondsBROM32( tick ) ( ((u32)(tick) * 1024) / (OS_SYSTEM_CLOCK/1000) ) + +#define OS_TicksToSecondsBROM( tick ) ( ((u64)(tick) * 1024) / OS_SYSTEM_CLOCK ) +#define OS_TicksToSecondsBROM32( tick ) ( ((u32)(tick) * 1024) / OS_SYSTEM_CLOCK ) + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FRIM_OS_TICK_BROM_H_ */ +#endif diff --git a/include/firm/pm.h b/include/firm/pm.h new file mode 100644 index 00000000..dfb8919a --- /dev/null +++ b/include/firm/pm.h @@ -0,0 +1,27 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - pm + File: pm.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_PM_H_ +#define FIRM_PM_H_ + +#ifdef SDK_ARM7 +#include +#include +#endif // SDK_ARM7 + +/* FIRM_PM_H_ */ +#endif diff --git a/include/firm/pm/ARM7/pm_init.h b/include/firm/pm/ARM7/pm_init.h new file mode 100644 index 00000000..055c8d93 --- /dev/null +++ b/include/firm/pm/ARM7/pm_init.h @@ -0,0 +1,64 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - pm + File: pm_init.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_PM_ARM7_PM_INIT_H_ +#define FIRM_PM_ARM7_PM_INIT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Name: PM_InitFIRM + + Description: power B/L on + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void PM_InitFIRM( void ); + +/*---------------------------------------------------------------------------* + Name: PM_CheckINIFlag + + Description: Check INI in GX_DISPSTAT (able to call before PM_InitFIRM) + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void PM_CheckINIFlag(void); + +/*---------------------------------------------------------------------------* + Name: PM_BackLightOn + + Description: power B/L on if not set yet + + Arguments: force TRUE: wait until valid condition + FALSE not set unless valid condition + + Returns: None + *---------------------------------------------------------------------------*/ +void PM_BackLightOn( BOOL force ); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_PM_ARM7_PM_INIT_H_ */ +#endif diff --git a/include/firm/pm/ARM7/pm_pmic_ex.h b/include/firm/pm/ARM7/pm_pmic_ex.h new file mode 100644 index 00000000..36515905 --- /dev/null +++ b/include/firm/pm/ARM7/pm_pmic_ex.h @@ -0,0 +1,73 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - pm + File: pm_pmic_ex.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef FIRM_PM_PMIC_EX_H_ +#define FIRM_PM_PMIC_EX_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +//================================================================================ +// PMIC ACCESS +//================================================================================ +/*---------------------------------------------------------------------------* + Name: PMi_SetParams + + Description: set control bit to device register + + Arguments: reg : device register + setBits : bits to set + maskBits : bits to mask + + Returns: None + *---------------------------------------------------------------------------*/ +void PMi_SetParams( u8 reg, u8 setBits, u8 maskBits ); + +/*---------------------------------------------------------------------------* + Name: PMi_SetFlags + + Description: set control bit to device register + + Arguments: reg : device register + setBits : bits to set + + Returns: None + *---------------------------------------------------------------------------*/ +void PMi_SetFlags( u8 reg, u8 setBits ); + +/*---------------------------------------------------------------------------* + Name: PMi_ResetFlags + + Description: clear control bit to device register + + Arguments: reg : device register + clrBits : bits to set + + Returns: None + *---------------------------------------------------------------------------*/ +void PMi_ResetFlags( u8 reg, u8 clrBits ); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_PM_PMIC_EX_H_ */ +#endif diff --git a/include/firm/pxi.h b/include/firm/pxi.h new file mode 100644 index 00000000..7290d329 --- /dev/null +++ b/include/firm/pxi.h @@ -0,0 +1,27 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - include - PXI + File: pxi.h + + Copyright 2007 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: 2007-09-06$ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_PXI_H_ +#define FIRM_PXI_H_ + +#include + +#include +#include + +/* FIRM_PXI_H_ */ +#endif diff --git a/include/firm/pxi/common/misc.h b/include/firm/pxi/common/misc.h new file mode 100644 index 00000000..fa3cb6bf --- /dev/null +++ b/include/firm/pxi/common/misc.h @@ -0,0 +1,224 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - -include - PXI + File: misc.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. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_PXI_COMMON_MISC_H_ +#define FIRM_PXI_COMMON_MISC_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// PXI sync ID for bootrom +typedef enum +{ + // from ARM7 + FIRM_PXI_ID_COLDBOOT = 1, // _start + FIRM_PXI_ID_WARMBOOT = 2, // _start + + FIRM_PXI_ID_INIT_ARM7 = 7, // PXI_InitFifoFIRM + + FIRM_PXI_ID_LOAD_HEADER = 6, // FATFS_LoadHeader + FIRM_PXI_ID_LOAD_STATIC = 5, // FATFS_LoadStatic + + FIRM_PXI_ID_LOAD_PIRIOD = 1, // *_LoadBuffer + + // from ARM9 + FIRM_PXI_ID_INIT_MMEM = 3, // _start + + FIRM_PXI_ID_INIT_ARM9 = 9, // PXI_InitFifoFIRM + + FIRM_PXI_ID_AUTH_HEADER = 10, // MI_LoadHeader + FIRM_PXI_ID_AUTH_STATIC = 11, // MI_LoadStatic + + FIRM_PXI_ID_SET_PATH = 4, // main (nandfirm) + FIRM_PXI_ID_DONE_HEADER = 5, // main (nandfirm) + FIRM_PXI_ID_DONE_STATIC = 6, // main (nandfirm) + + // from both of ARM9 and ARM7 + FIRM_PXI_ID_NULL = 0, + FIRM_PXI_ID_ERR = 0xF +} +FIRMPxiID; + + +/*---------------------------------------------------------------------------* + Name: PXI_InitFifoFIRM + + Description: initialize FIFO system for bootrom + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_InitFifoFIRM(void); + +/*---------------------------------------------------------------------------* + Name: PXI_NotifyID + + Description: send 4bit id to other processor + + Arguments: id notifying id + + Returns: None + *---------------------------------------------------------------------------*/ +void PXI_NotifyID( u32 id ); + +/*---------------------------------------------------------------------------* + Name: PXI_WaitID + + Description: Wait 4bit id from the other processor + + Arguments: id waiting id + + Returns: None + *---------------------------------------------------------------------------*/ +void PXI_WaitID( u32 id ); + +/*---------------------------------------------------------------------------* + Name: PXI_RecvID + + Description: Receive 4bit id from the other processor + + Arguments: None + + Returns: id + *---------------------------------------------------------------------------*/ +u8 PXI_RecvID( void ); + +/*---------------------------------------------------------------------------* + Name: PXI_SendIDByIntf + + Description: send 4bit id to other processor + + Arguments: id notifying id + + Returns: None + *---------------------------------------------------------------------------*/ +void PXI_SendIDByIntf( u32 id ); + +/*---------------------------------------------------------------------------* + Name: PXI_RecvIDByIntf + + Description: receive 4bit id from the other processor + + Arguments: None + + Returns: received id + *---------------------------------------------------------------------------*/ +u32 PXI_RecvIDByIntf( void ); + +/*---------------------------------------------------------------------------* + Name: PXI_WaitIDByIntf + + Description: Wait 4bit id from the other processor + + Arguments: id waiting id + + Returns: None + *---------------------------------------------------------------------------*/ +void PXI_WaitIDByIntf( u32 id ); + +/*---------------------------------------------------------------------------* + Name: PXI_SendIDByFifo + + Description: Send 32bit-word to another CPU via FIFO + + Arguments: + + Returns: None + *---------------------------------------------------------------------------*/ +void PXI_SendIDByFifo(PXIFifoTag tag, u32 id); + +/*---------------------------------------------------------------------------* + Name: PXI_RecvIDByFifo + + Description: Recv 32bit-word from another CPU via FIFO + + Arguments: + + Returns: if error occured, returns minus value + *---------------------------------------------------------------------------*/ +PXIFifoStatus PXI_RecvIDByFifo(PXIFifoTag tag, void* buf); + +/*---------------------------------------------------------------------------* + Name: PXI_WaitIDByFifo + + Description: Wait 32bit-word from another CPU via FIFO + + Arguments: id waiting id + + Returns: None + *---------------------------------------------------------------------------*/ +void PXI_WaitIDByFifo(PXIFifoTag tag, u32 id); + +/*---------------------------------------------------------------------------* + Name: PXI_SendDataByFifo + + Description: Send 32bit-word to another CPU via FIFO + + Arguments: + + Returns: None + *---------------------------------------------------------------------------*/ +void PXI_SendDataByFifo(PXIFifoTag tag, void* buf, int size); + +/*---------------------------------------------------------------------------* + Name: PXI_RecvDataByFifo + + Description: Recv 32bit-word to another CPU via FIFO + + Arguments: + + Returns: if error occured, returns minus value + *---------------------------------------------------------------------------*/ +PXIFifoStatus PXI_RecvDataByFifo(PXIFifoTag tag, void* buf, int max_size); + +/*---------------------------------------------------------------------------* + Name: PXI_IsSendFifoFull + + Description: Check if send fifo is full? + + Arguments: None. + + Returns: if send fifo is full + *---------------------------------------------------------------------------*/ +static inline BOOL PXI_IsSendFifoFull(void) +{ + return (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_SEND_FULL_MASK) >> REG_PXI_FIFO_CNT_SEND_FULL_SHIFT; +} + +/*---------------------------------------------------------------------------* + Name: PXI_IsRecvFifoEmpty + + Description: Check if receive fifo is empty? + + Arguments: None. + + Returns: if receive fifo is empty + *---------------------------------------------------------------------------*/ +static inline BOOL PXI_IsRecvFifoEmpty(void) +{ + return (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_RECV_EMP_MASK) >> REG_PXI_FIFO_CNT_RECV_EMP_SHIFT; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* FIRM_PXI_COMMON_MISC_H_ */ diff --git a/include/firm/pxi/common/pxi_firm.h b/include/firm/pxi/common/pxi_firm.h new file mode 100644 index 00000000..2abcda25 --- /dev/null +++ b/include/firm/pxi/common/pxi_firm.h @@ -0,0 +1,177 @@ +/*---------------------------------------------------------------------------* + Project: TwlFirm - -include - PXI + File: pxi_firm.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. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_PXI_COMMON_FIRM_H_ +#define FIRM_PXI_COMMON_FIRM_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// PXI sync ID for bootrom +typedef enum +{ + // from ARM7 + FIRM_PXI_ID_COLDBOOT = 1, // _start + FIRM_PXI_ID_WARMBOOT = 2, // _start + + FIRM_PXI_ID_INIT_ARM7 = 7, // PXI_InitFifoFIRM + + FIRM_PXI_ID_LOAD_HEADER = 6, // FATFS_LoadHeader + FIRM_PXI_ID_LOAD_STATIC = 5, // FATFS_LoadStatic + + FIRM_PXI_ID_LOAD_BUFFER_SEMAPHORE = 1, // *_LoadBuffer + + // from ARM9 + FIRM_PXI_ID_INIT_MMEM = 3, // _start + + FIRM_PXI_ID_INIT_ARM9 = 9, // PXI_InitFifoFIRM + + FIRM_PXI_ID_AUTH_HEADER = 10, // MI_LoadHeader + FIRM_PXI_ID_AUTH_STATIC = 11, // MI_LoadStatic + + FIRM_PXI_ID_SET_PATH = 4, // main (nandfirm) + FIRM_PXI_ID_DONE_HEADER = 5, // main (nandfirm) + FIRM_PXI_ID_DONE_STATIC = 6, // main (nandfirm) + + // from both of ARM9 and ARM7 + FIRM_PXI_ID_NULL = 0, + FIRM_PXI_ID_ERR = 0xF +} +FIRMPxiID; + + +/*---------------------------------------------------------------------------* + Name: PXI_InitFIRM + + Description: initialize PXI for firm + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_InitFIRM(void); + +/*---------------------------------------------------------------------------* + Name: PXI_SendStream + + Description: Send data stream + + Arguments: buf pointer to data buffer + size transfer size + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_SendStream( const void* buf, int size ); + +/*---------------------------------------------------------------------------* + Name: PXI_RecvStream + + Description: Receive data stream + + Arguments: buf pointer to data buffer + size transfer size + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_RecvStream( void* buf, int size ); + +/*---------------------------------------------------------------------------* + Name: PXI_NotifyID + + Description: Send ID + + Arguments: id id to send + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_NotifyID( FIRMPxiID id ); + +/*---------------------------------------------------------------------------* + Name: PXI_RecvID + + Description: Receive ID + + Arguments: None + + Returns: Received ID + *---------------------------------------------------------------------------*/ +FIRMPxiID PXI_RecvID( void ); + +/*---------------------------------------------------------------------------* + Name: PXI_ReleaseLoadBufferSemaphore + + Description: Release semaphore for *_LoadBuffer + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_ReleaseLoadBufferSemaphore( void ); + +/*---------------------------------------------------------------------------* + Name: PXI_AcquireLoadBufferSemaphore + + Description: Acquire semaphore for *_LoadBuffer + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void PXI_AcquireLoadBufferSemaphore( void ); + +/*---------------------------------------------------------------------------* + Name: PXIi_SendIDByIntf + + Description: send 4bit id to other processor + + Arguments: id notifying id + + Returns: None + *---------------------------------------------------------------------------*/ +void PXIi_SendIDByIntf( u32 id ); + +/*---------------------------------------------------------------------------* + Name: PXIi_RecvIDByIntf + + Description: receive 4bit id from the other processor + + Arguments: None + + Returns: received id + *---------------------------------------------------------------------------*/ +u32 PXIi_RecvIDByIntf( void ); + +/*---------------------------------------------------------------------------* + Name: PXIi_WaitIDByIntf + + Description: Wait 4bit id from the other processor + + Arguments: id waiting id + + Returns: None + *---------------------------------------------------------------------------*/ +void PXIi_WaitIDByIntf( u32 id ); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* FIRM_PXI_COMMON_FIRM_H_ */ diff --git a/include/firm/pxi/common/regname_ex.h b/include/firm/pxi/common/regname_ex.h new file mode 100644 index 00000000..5883d6cf --- /dev/null +++ b/include/firm/pxi/common/regname_ex.h @@ -0,0 +1,42 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - include - PXI + File: regname.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. + + $Log: $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_PXI_COMMON_REGNAME_EX_H_ +#define FIRM_PXI_COMMON_REGNAME_EX_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SDK_ARM9 + +#define REG_PXI_FIFO_CNT_SEND_FULL_SHIFT REG_PXI_SUBP_FIFO_CNT_SEND_FULL_SHIFT +#define REG_PXI_FIFO_CNT_RECV_EMP_SHIFT REG_PXI_SUBP_FIFO_CNT_RECV_EMP_SHIFT + +#else // SDK_ARM7 + +#define REG_PXI_FIFO_CNT_SEND_FULL_SHIFT REG_PXI_MAINP_FIFO_CNT_SEND_FULL_SHIFT +#define REG_PXI_FIFO_CNT_RECV_EMP_SHIFT REG_PXI_MAINP_FIFO_CNT_RECV_EMP_SHIFT + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif +/* FIRM_PXI_COMMON_REGNAME_EX_H_ */ +#endif diff --git a/include/firm/specfiles/ARM7-BB-FIRM.lcf.template b/include/firm/specfiles/ARM7-BB-FIRM.lcf.template new file mode 100644 index 00000000..a0176d4e --- /dev/null +++ b/include/firm/specfiles/ARM7-BB-FIRM.lcf.template @@ -0,0 +1,507 @@ +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makelcf +# File: ARM7-BB-FIRM.lcf.template +# +# 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$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 # > + + (RWX) : ORIGIN = , LENGTH = 0x0 > + +# binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 > + + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + arena.MAIN (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + check.WORKRAM (RWX) : ORIGIN = , LENGTH = 0x48000 > workram.check +} + +KEEP_SECTION +{ + .ctor +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); . = ALIGN(4); # Fit to cache line + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + crt0_firm.o (.text) + + + + + + + . = ALIGN(4); + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + EXCEPTION + SDK_STATIC_ETABLE_END =.; + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(4); + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(4); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + __exception_table_start__ = SDK_STATIC_ETABLE_START; # for exception table + __exception_table_end__ = SDK_STATIC_ETABLE_END; # for exception table + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.MAIN.START = 0x02380000; + SDK_AUTOLOAD.MAIN.END = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD.MAIN.BSS_END = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD.MAIN.SIZE = 0; + SDK_AUTOLOAD.MAIN.BSS_SIZE = 0; + SDK_AUTOLOAD.WRAM.START = 0x037f8000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_MAIN_START = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD_MAIN_END = SDK_AUTOLOAD.MAIN.END; + SDK_AUTOLOAD_MAIN_BSS_END = SDK_AUTOLOAD.MAIN.BSS_END; + SDK_AUTOLOAD_MAIN_SIZE = SDK_AUTOLOAD.MAIN.SIZE; + SDK_AUTOLOAD_MAIN_BSS_SIZE = SDK_AUTOLOAD.MAIN.BSS_SIZE; + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + SDK_AUTOLOAD_LIST = .; + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + SDK_AUTOLOAD_LIST_END = .; + } >> # > binary.AUTOLOAD_INFO + +# SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; +# SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(4); + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(4); + SDK_OVERLAY..DATA_END =.; + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + + ############################ ARENA ################################## + .arena.MAIN: + { + . = ALIGN(4); + SDK_SECTION_ARENA_START =.; + } > arena.MAIN + + + ############################ OVERLAYDEFS ############################ + .: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > + + + ############################ OVERLAYTABLE ########################### + .: + { + + # Overlay + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + + } > + + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_AUTOLOAD.MAIN.BSS_END; + SDK_WRAM_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + + # work ram size checker + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + .check.WORKRAM: + { + . = . + SDK_SECTION_ARENA_START - + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.WORKRAM +} diff --git a/include/firm/specfiles/ARM7-BB-FIRM.lsf b/include/firm/specfiles/ARM7-BB-FIRM.lsf new file mode 100644 index 00000000..42176502 --- /dev/null +++ b/include/firm/specfiles/ARM7-BB-FIRM.lsf @@ -0,0 +1,28 @@ +#---------------------------------------------------------------------------- +# Project: TwlFirm - include +# File: ARM7-BB-NORFIRM.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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$ +#---------------------------------------------------------------------------- +# +# TwlFirm LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x037f8000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) + Object * (.wram) + StackSize 1024 512 +} diff --git a/include/firm/specfiles/ARM7-BB-GCDFIRM.lcf.template b/include/firm/specfiles/ARM7-BB-GCDFIRM.lcf.template new file mode 100644 index 00000000..ebabab94 --- /dev/null +++ b/include/firm/specfiles/ARM7-BB-GCDFIRM.lcf.template @@ -0,0 +1,507 @@ +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makelcf +# File: ARM7-BB-NORFIRM.lcf.template +# +# 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:$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 # > + + (RWX) : ORIGIN = , LENGTH = 0x0 > + +# binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 > + + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + arena.MAIN (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + check.WORKRAM (RWX) : ORIGIN = , LENGTH = 0x48000 > workram.check +} + +KEEP_SECTION +{ + .ctor +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); . = ALIGN(4); # Fit to cache line + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + crt0.o (.text) + + + + + + + . = ALIGN(4); + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + EXCEPTION + SDK_STATIC_ETABLE_END =.; + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(4); + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(4); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + __exception_table_start__ = SDK_STATIC_ETABLE_START; # for exception table + __exception_table_end__ = SDK_STATIC_ETABLE_END; # for exception table + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.MAIN.START = 0x02380000; + SDK_AUTOLOAD.MAIN.END = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD.MAIN.BSS_END = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD.MAIN.SIZE = 0; + SDK_AUTOLOAD.MAIN.BSS_SIZE = 0; + SDK_AUTOLOAD.WRAM.START = 0x037f8000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_MAIN_START = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD_MAIN_END = SDK_AUTOLOAD.MAIN.END; + SDK_AUTOLOAD_MAIN_BSS_END = SDK_AUTOLOAD.MAIN.BSS_END; + SDK_AUTOLOAD_MAIN_SIZE = SDK_AUTOLOAD.MAIN.SIZE; + SDK_AUTOLOAD_MAIN_BSS_SIZE = SDK_AUTOLOAD.MAIN.BSS_SIZE; + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + SDK_AUTOLOAD_LIST = .; + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + SDK_AUTOLOAD_LIST_END = .; + } >> # > binary.AUTOLOAD_INFO + +# SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; +# SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(4); + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(4); + SDK_OVERLAY..DATA_END =.; + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + + ############################ ARENA ################################## + .arena.MAIN: + { + . = ALIGN(4); + SDK_SECTION_ARENA_START =.; + } > arena.MAIN + + + ############################ OVERLAYDEFS ############################ + .: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > + + + ############################ OVERLAYTABLE ########################### + .: + { + + # Overlay + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + + } > + + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_AUTOLOAD.MAIN.BSS_END; + SDK_WRAM_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + + # work ram size checker + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + .check.WORKRAM: + { + . = . + SDK_SECTION_ARENA_START - + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.WORKRAM +} diff --git a/include/firm/specfiles/ARM7-BB-GCDFIRM.lsf b/include/firm/specfiles/ARM7-BB-GCDFIRM.lsf new file mode 100644 index 00000000..42176502 --- /dev/null +++ b/include/firm/specfiles/ARM7-BB-GCDFIRM.lsf @@ -0,0 +1,28 @@ +#---------------------------------------------------------------------------- +# Project: TwlFirm - include +# File: ARM7-BB-NORFIRM.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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$ +#---------------------------------------------------------------------------- +# +# TwlFirm LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x037f8000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) + Object * (.wram) + StackSize 1024 512 +} diff --git a/include/firm/specfiles/ARM7-TS-FIRM.lcf.template b/include/firm/specfiles/ARM7-TS-FIRM.lcf.template new file mode 100644 index 00000000..7ef4c275 --- /dev/null +++ b/include/firm/specfiles/ARM7-TS-FIRM.lcf.template @@ -0,0 +1,406 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM7-TS-FIRM.lcf.template +# +# 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$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + arena.MAIN (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + check.WORKRAM_SHARED (RWX) : ORIGIN = 0x037b8000, LENGTH = 0x48000 > workram.check + # reached OSFromBrom7Buf before OS_BOOT_CODE_BUF + check.WORKRAM (RWX) : ORIGIN = 0x037b8000, LENGTH = 0x54000 > workram.check + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDMAIN (RWX) : ORIGIN = 0x02f88000, LENGTH = 0x74000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.WRAM.START = SDK_STATIC_BSS_END; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..SINIT_START; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + ############################ ARENA ################################## + .arena.MAIN: + { + . = ALIGN(4); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM_SHARED: + { + . = SDK_STATIC_END; + } > check.WORKRAM_SHARED + + .check.WORKRAM: + { + . = SDK_STATIC_BSS_END; + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = 0x02f88000; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02e80000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + .check.LTDMAIN: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.LTDMAIN + +} diff --git a/include/firm/specfiles/ARM7-TS-FIRM.lsf b/include/firm/specfiles/ARM7-TS-FIRM.lsf new file mode 100644 index 00000000..e6ad76e7 --- /dev/null +++ b/include/firm/specfiles/ARM7-TS-FIRM.lsf @@ -0,0 +1,42 @@ +#---------------------------------------------------------------------------- +# Project: TwlFirm - include +# File: ARM7-TS-FIRM.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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$ +#---------------------------------------------------------------------------- +# +# TwlFirm LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x037b8000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) + Object * (.etable) + Object * (.wram) + Object * (.ltdwram) + Object * (.ltdmain) + StackSize 1024 1024 +} + +#Autoload WRAM +#{ +# Address $(ADDRESS_LTDWRAM) +#} + +#Ltdautoload LTDMAIN +#{ +## Address 0x02f88000 +# Address 0x02380000 +#} diff --git a/include/firm/specfiles/ARM7-TS-GCDFIRM.lcf.template b/include/firm/specfiles/ARM7-TS-GCDFIRM.lcf.template new file mode 100644 index 00000000..c3244f8a --- /dev/null +++ b/include/firm/specfiles/ARM7-TS-GCDFIRM.lcf.template @@ -0,0 +1,507 @@ +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makelcf +# File: ARM7-TS-NORFIRM.lcf.template +# +# 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:$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 # > + + (RWX) : ORIGIN = , LENGTH = 0x0 > + +# binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 > + + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + arena.MAIN (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + check.WORKRAM (RWX) : ORIGIN = , LENGTH = 0x48000 > workram.check +} + +KEEP_SECTION +{ + .ctor +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); . = ALIGN(4); # Fit to cache line + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + crt0.o (.text) + + + + + + + . = ALIGN(4); + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + EXCEPTION + SDK_STATIC_ETABLE_END =.; + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(4); + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(4); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + __exception_table_start__ = SDK_STATIC_ETABLE_START; # for exception table + __exception_table_end__ = SDK_STATIC_ETABLE_END; # for exception table + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.MAIN.START = 0x02380000; + SDK_AUTOLOAD.MAIN.END = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD.MAIN.BSS_END = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD.MAIN.SIZE = 0; + SDK_AUTOLOAD.MAIN.BSS_SIZE = 0; + SDK_AUTOLOAD.WRAM.START = 0x037f8000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_MAIN_START = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD_MAIN_END = SDK_AUTOLOAD.MAIN.END; + SDK_AUTOLOAD_MAIN_BSS_END = SDK_AUTOLOAD.MAIN.BSS_END; + SDK_AUTOLOAD_MAIN_SIZE = SDK_AUTOLOAD.MAIN.SIZE; + SDK_AUTOLOAD_MAIN_BSS_SIZE = SDK_AUTOLOAD.MAIN.BSS_SIZE; + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + SDK_AUTOLOAD_LIST = .; + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + SDK_AUTOLOAD_LIST_END = .; + } >> # > binary.AUTOLOAD_INFO + +# SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; +# SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(4); + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(4); + SDK_OVERLAY..DATA_END =.; + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(4); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + + ############################ ARENA ################################## + .arena.MAIN: + { + . = ALIGN(4); + SDK_SECTION_ARENA_START =.; + } > arena.MAIN + + + ############################ OVERLAYDEFS ############################ + .: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > + + + ############################ OVERLAYTABLE ########################### + .: + { + + # Overlay + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + + } > + + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = SDK_AUTOLOAD.MAIN.BSS_END; + SDK_WRAM_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + + # work ram size checker + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + .check.WORKRAM: + { + . = . + SDK_SECTION_ARENA_START - + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.WORKRAM +} diff --git a/include/firm/specfiles/ARM7-TS-GCDFIRM.lsf b/include/firm/specfiles/ARM7-TS-GCDFIRM.lsf new file mode 100644 index 00000000..d4f5d88b --- /dev/null +++ b/include/firm/specfiles/ARM7-TS-GCDFIRM.lsf @@ -0,0 +1,28 @@ +#---------------------------------------------------------------------------- +# Project: TwlFirm - include +# File: ARM7-TS-NORFIRM.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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$ +#---------------------------------------------------------------------------- +# +# TwlFirm LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x037f8000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) + Object * (.wram) + StackSize 1024 512 +} diff --git a/include/firm/specfiles/ARM7-TS-PARTNER.lcf.template b/include/firm/specfiles/ARM7-TS-PARTNER.lcf.template new file mode 100644 index 00000000..5e9c4151 --- /dev/null +++ b/include/firm/specfiles/ARM7-TS-PARTNER.lcf.template @@ -0,0 +1,899 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM7-BB.lcf.template +# +# 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$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 #> + + + (RWX) : ORIGIN = , LENGTH = 0x0 #>> + +# binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + arena.MAIN (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + check.WORKRAM (RWX) : ORIGIN = 0x037f8000, LENGTH = 0x18000 > workram.check + check.MAINMEM (RWX) : ORIGIN = 0x02fe0000, LENGTH = 0x1c000 > mainmem.check + +# binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 #>> + +# binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + check.LTDWRAM (RWX) : ORIGIN = 0x03000000, LENGTH = 0x40000 > ltdwram.check + check.LTDMAIN (RWX) : ORIGIN = 0x02f88000, LENGTH = 0x58000 > ltdmain.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.MAIN.START = 0x02fe0000; + SDK_AUTOLOAD.MAIN.END = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD.MAIN.BSS_END = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD.MAIN.SIZE = 0; + SDK_AUTOLOAD.MAIN.BSS_SIZE = 0; + SDK_AUTOLOAD.WRAM.START = 0x037f8000; + SDK_AUTOLOAD.WRAM.END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.BSS_END = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD.WRAM.SIZE = 0; + SDK_AUTOLOAD.WRAM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_MAIN_START = SDK_AUTOLOAD.MAIN.START; + SDK_AUTOLOAD_MAIN_END = SDK_AUTOLOAD.MAIN.END; + SDK_AUTOLOAD_MAIN_BSS_END = SDK_AUTOLOAD.MAIN.BSS_END; + SDK_AUTOLOAD_MAIN_SIZE = SDK_AUTOLOAD.MAIN.SIZE; + SDK_AUTOLOAD_MAIN_BSS_SIZE = SDK_AUTOLOAD.MAIN.BSS_SIZE; + SDK_AUTOLOAD_WRAM_START = SDK_AUTOLOAD.WRAM.START; + SDK_AUTOLOAD_WRAM_END = SDK_AUTOLOAD.WRAM.END; + SDK_AUTOLOAD_WRAM_BSS_END = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_AUTOLOAD_WRAM_SIZE = SDK_AUTOLOAD.WRAM.SIZE; + SDK_AUTOLOAD_WRAM_BSS_SIZE = SDK_AUTOLOAD.WRAM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + SDK_AUTOLOAD_LIST = .; + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + SDK_AUTOLOAD_LIST_END = .; + } >> #> binary.AUTOLOAD_INFO + +# SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; +# SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ ARENA ################################## + .arena.MAIN: + { + . = ALIGN(4); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ OTHERS ################################# + SDK_WRAM_ARENA_LO = SDK_AUTOLOAD.WRAM.BSS_END; + SDK_SUBPRIV_ARENA_LO = SDK_AUTOLOAD.MAIN.BSS_END; + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = . + SDK_AUTOLOAD.WRAM.BSS_END - SDK_AUTOLOAD.WRAM.START + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM + + .check.MAINMEM: + { + . = SDK_SUBPRIV_ARENA_LO; + + } > check.MAINMEM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD.LTDWRAM.START = 0x03000000; + SDK_LTDAUTOLOAD.LTDWRAM.END = SDK_LTDAUTOLOAD.LTDWRAM.START; + SDK_LTDAUTOLOAD.LTDWRAM.BSS_END = SDK_LTDAUTOLOAD.LTDWRAM.START; + SDK_LTDAUTOLOAD.LTDWRAM.SIZE = 0; + SDK_LTDAUTOLOAD.LTDWRAM.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02e80000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0xdeadbeef; + + } >> #> binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + SDK_LTDAUTOLOAD_LTDWRAM_START = SDK_LTDAUTOLOAD.LTDWRAM.START; + SDK_LTDAUTOLOAD_LTDWRAM_END = SDK_LTDAUTOLOAD.LTDWRAM.END; + SDK_LTDAUTOLOAD_LTDWRAM_BSS_END = SDK_LTDAUTOLOAD.LTDWRAM.BSS_END; + SDK_LTDAUTOLOAD_LTDWRAM_SIZE = SDK_LTDAUTOLOAD.LTDWRAM.SIZE; + SDK_LTDAUTOLOAD_LTDWRAM_BSS_SIZE = SDK_LTDAUTOLOAD.LTDWRAM.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + SDK_LTDAUTOLOAD_LIST = .; + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + SDK_LTDAUTOLOAD_LIST_END = .; + } >> #> binary.LTDAUTOLOAD_INFO + +# SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; +# SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(4); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(4); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ OTHERS ################################# + .check.LTDWRAM: + { + . = SDK_LTDAUTOLOAD.LTDWRAM.BSS_END; + + } > check.LTDWRAM + + .check.LTDMAIN: + { +# . = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + + } > check.LTDMAIN + +} diff --git a/include/firm/specfiles/ARM9-BB-FIRM.lcf.template b/include/firm/specfiles/ARM9-BB-FIRM.lcf.template new file mode 100644 index 00000000..da10b754 --- /dev/null +++ b/include/firm/specfiles/ARM9-BB-FIRM.lcf.template @@ -0,0 +1,602 @@ +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makelcf +# File: ARM9-BB-FIRM.lcf.template +# +# 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$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 # > + + (RWX) : ORIGIN = , LENGTH = 0x0 # > + +# binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 > +# binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + dummy.MAIN_EX (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX (RW) : ORIGIN = AFTER(dummy.MAIN_EX,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + binary.MODULE_FILES (RW) : ORIGIN = 0x0, LENGTH = 0x0 > component.files + check.ITCM (RWX) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); . = ALIGN(32); # Fit to cache line + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + crt0_firm.o (.text) + libsyscall.a (.text) + crt0_firm.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + . = ALIGN(4); + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + EXCEPTION + SDK_STATIC_ETABLE_END =.; + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(32); + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + SDK_OVERLAY_DIGEST =.; + # NO DIGEST + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + __exception_table_start__ = SDK_STATIC_ETABLE_START; # for exception table + __exception_table_end__ = SDK_STATIC_ETABLE_END; # for exception table + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x027e0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(32); + SDK_AUTOLOAD..DATA_END =.; + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + SDK_AUTOLOAD_LIST = .; + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + SDK_AUTOLOAD_LIST_END = .; + } >> # > binary.AUTOLOAD_INFO + +# SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; +# SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + } >> # > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(32); + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(32); + SDK_OVERLAY..DATA_END =.; + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ MAIN EX ################################## + # MAIN EX Area + .dummy.MAIN_EX: + { + . = ALIGN(32); + } > dummy.MAIN_EX + + ############################ ARENA ################################## + .arena.MAIN: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + } > arena.MAIN + + .arena.MAIN_EX: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + } > arena.MAIN_EX + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + } > arena.DTCM + + ############################ OVERLAYDEFS ############################ + .: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > + + + ############################ OVERLAYTABLE ########################### + .: + { + + # Overlay + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + + } > + + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + } > binary.MODULE_FILES + + # ITCM/DTCM size checker => check AUTOLOAD_ITCM/DTCM + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + } > check.ITCM + + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + . = . + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + +} diff --git a/include/firm/specfiles/ARM9-BB-FIRM.lsf b/include/firm/specfiles/ARM9-BB-FIRM.lsf new file mode 100644 index 00000000..c7676d22 --- /dev/null +++ b/include/firm/specfiles/ARM9-BB-FIRM.lsf @@ -0,0 +1,42 @@ +#---------------------------------------------------------------------------- +# Project: TwlFirm - include +# File: ARM9-BB-NORFIRM.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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$ +#---------------------------------------------------------------------------- +# +# TwlFirm LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x03800000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) +} + +Autoload ITCM +{ + Address 0x01ff8000 + Object * (.itcm) + Object $(OBJS_AUTOLOAD) (.text) +} + +Autoload DTCM +{ + Address 0x027e0000 + Object * (.dtcm) + Object $(OBJS_AUTOLOAD) (.data) + Object $(OBJS_AUTOLOAD) (.bss) +} + diff --git a/include/firm/specfiles/ARM9-BB-GCDFIRM.lcf.template b/include/firm/specfiles/ARM9-BB-GCDFIRM.lcf.template new file mode 100644 index 00000000..4cace18e --- /dev/null +++ b/include/firm/specfiles/ARM9-BB-GCDFIRM.lcf.template @@ -0,0 +1,602 @@ +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makelcf +# File: ARM9-BB-NORFIRM.lcf.template +# +# 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:$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 # > + + (RWX) : ORIGIN = , LENGTH = 0x0 # > + +# binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 > +# binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + dummy.MAIN_EX (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX (RW) : ORIGIN = AFTER(dummy.MAIN_EX,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + binary.MODULE_FILES (RW) : ORIGIN = 0x0, LENGTH = 0x0 > component.files + check.ITCM (RWX) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); . = ALIGN(32); # Fit to cache line + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + crt0.o (.text) + libsyscall.a (.text) + crt0.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + . = ALIGN(4); + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + EXCEPTION + SDK_STATIC_ETABLE_END =.; + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(32); + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + SDK_OVERLAY_DIGEST =.; + # NO DIGEST + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + __exception_table_start__ = SDK_STATIC_ETABLE_START; # for exception table + __exception_table_end__ = SDK_STATIC_ETABLE_END; # for exception table + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x027e0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(32); + SDK_AUTOLOAD..DATA_END =.; + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + SDK_AUTOLOAD_LIST = .; + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + SDK_AUTOLOAD_LIST_END = .; + } >> # > binary.AUTOLOAD_INFO + +# SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; +# SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + } >> # > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(32); + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(32); + SDK_OVERLAY..DATA_END =.; + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ MAIN EX ################################## + # MAIN EX Area + .dummy.MAIN_EX: + { + . = ALIGN(32); + } > dummy.MAIN_EX + + ############################ ARENA ################################## + .arena.MAIN: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + } > arena.MAIN + + .arena.MAIN_EX: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + } > arena.MAIN_EX + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + } > arena.DTCM + + ############################ OVERLAYDEFS ############################ + .: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > + + + ############################ OVERLAYTABLE ########################### + .: + { + + # Overlay + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + + } > + + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + } > binary.MODULE_FILES + + # ITCM/DTCM size checker => check AUTOLOAD_ITCM/DTCM + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + } > check.ITCM + + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + . = . + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + +} diff --git a/include/firm/specfiles/ARM9-BB-GCDFIRM.lsf b/include/firm/specfiles/ARM9-BB-GCDFIRM.lsf new file mode 100644 index 00000000..c7676d22 --- /dev/null +++ b/include/firm/specfiles/ARM9-BB-GCDFIRM.lsf @@ -0,0 +1,42 @@ +#---------------------------------------------------------------------------- +# Project: TwlFirm - include +# File: ARM9-BB-NORFIRM.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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$ +#---------------------------------------------------------------------------- +# +# TwlFirm LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x03800000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) +} + +Autoload ITCM +{ + Address 0x01ff8000 + Object * (.itcm) + Object $(OBJS_AUTOLOAD) (.text) +} + +Autoload DTCM +{ + Address 0x027e0000 + Object * (.dtcm) + Object $(OBJS_AUTOLOAD) (.data) + Object $(OBJS_AUTOLOAD) (.bss) +} + diff --git a/include/firm/specfiles/ARM9-TS-FIRM.lcf.template b/include/firm/specfiles/ARM9-TS-FIRM.lcf.template new file mode 100644 index 00000000..7390057e --- /dev/null +++ b/include/firm/specfiles/ARM9-TS-FIRM.lcf.template @@ -0,0 +1,506 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-TS-FIRM.lcf.template +# +# 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$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.NITRO (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN.NITRO (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX.NITRO (RW) : ORIGIN = AFTER(dummy.MAIN_EX.NITRO,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + + check.ITCM (RW) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check + check.WORKRAM (RWX) : ORIGIN = 0x037c0000, LENGTH = 0x40000 > workram.check + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.TWL (RW) : ORIGIN = 0x0d000000, LENGTH = 0x0 + arena.WRAM.TWL (RW) : ORIGIN = AFTER(,,LTDMAIN,), LENGTH = 0x0 + arena.MAIN.TWL (RW) : ORIGIN = 0x02000400, LENGTH = 0x0 + arena.MAIN_EX.TWL (RW) : ORIGIN = AFTER(dummy.MAIN_EX.TWL,,,LTDMAIN,), LENGTH = 0x0 + + binary.MODULE_FILES (RW) : ORIGIN = 0, LENGTH = 0x0 > component.files +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + OBJECT(_start,*) + crt0_firm.o (.text) + crt0_firm.o (.rodata) + libsyscall.a (.text) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); # Fit to cache line + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY_DIGEST =.; + # NO DIGEST + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x02fe0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + + } > binary.AUTOLOAD_INFO + + SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ ARENA ################################## + .dummy.MAIN_EX.NITRO: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.NITRO + + .arena.MAIN.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN.NITRO + + .arena.MAIN_EX.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + + } > arena.MAIN_EX.NITRO + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + + } > arena.DTCM + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + + } > check.ITCM + + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + . = . + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + + .check.WORKRAM: + { + . = SDK_STATIC_BSS_END; + } > check.WORKRAM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02400000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ ARENA ################################## + .dummy.MAIN_EX.TWL: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.TWL + + .arena.WRAM.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_ARENA_LO =.; + + } > arena.WRAM.TWL + + .arena.MAIN_EX.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_EX_ARENA_LO =.; + + } > arena.MAIN_EX.TWL + + ############################ OTHERS ################################# + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + + } > binary.MODULE_FILES + +} diff --git a/include/firm/specfiles/ARM9-TS-FIRM.lsf b/include/firm/specfiles/ARM9-TS-FIRM.lsf new file mode 100644 index 00000000..c9fa3d5b --- /dev/null +++ b/include/firm/specfiles/ARM9-TS-FIRM.lsf @@ -0,0 +1,56 @@ +#---------------------------------------------------------------------------- +# Project: TwlFirm - include +# File: ARM9-TS-FIRM.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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$ +#---------------------------------------------------------------------------- +# +# TwlFirm LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x037c0000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) + Object * (.itcm) + Object $(OBJS_AUTOLOAD) (.text) + Object $(OBJS_AUTOLOAD) (.rodata) + Object $(OBJS_AUTOLOAD) (.init) + Object $(OBJS_AUTOLOAD) (.ctor) + Object $(OBJS_AUTOLOAD) (.sinit) + Object * (.ltdmain) + Object $(OBJS_LTDAUTOLOAD) + Library $(LLIBS_EX) $(GLIBS_EX) + Object * (.dtcm) + Object $(OBJS_AUTOLOAD) (.data) + Object $(OBJS_AUTOLOAD) (.sdata) + Object $(OBJS_AUTOLOAD) (.bss) + Object $(OBJS_AUTOLOAD) (.sbss) +} + +Autoload ITCM +{ + Address 0x01ff8000 +} + +Autoload DTCM +{ + Address $(ADDRESS_DTCM) +} + +Ltdautoload LTDMAIN +{ + # NITRO/TWL L̃I[o[C݂ꍇ́Aɂ̌ɔzuKv܂B + After $(TARGET_NAME) +} diff --git a/include/firm/specfiles/ARM9-TS-GCDFIRM.lcf.template b/include/firm/specfiles/ARM9-TS-GCDFIRM.lcf.template new file mode 100644 index 00000000..a5236b6f --- /dev/null +++ b/include/firm/specfiles/ARM9-TS-GCDFIRM.lcf.template @@ -0,0 +1,602 @@ +#--------------------------------------------------------------------------- +# Project: TwlFirm - tools - makelcf +# File: ARM9-TS-NORFIRM.lcf.template +# +# 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:$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 # > + + (RWX) : ORIGIN = , LENGTH = 0x0 # > + +# binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 > +# binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + (RW) : ORIGIN = AFTER(), LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + dummy.MAIN_EX (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX (RW) : ORIGIN = AFTER(dummy.MAIN_EX,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + binary.MODULE_FILES (RW) : ORIGIN = 0x0, LENGTH = 0x0 > component.files + check.ITCM (RWX) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); . = ALIGN(32); # Fit to cache line + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + crt0.o (.text) + libsyscall.a (.text) + crt0.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + . = ALIGN(4); + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + EXCEPTION + SDK_STATIC_ETABLE_END =.; + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(32); + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + SDK_OVERLAY_DIGEST =.; + # NO DIGEST + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + . = ALIGN(32); + SDK_STATIC_DATA_END =.; + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + __exception_table_start__ = SDK_STATIC_ETABLE_START; # for exception table + __exception_table_end__ = SDK_STATIC_ETABLE_END; # for exception table + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x027e0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(32); + SDK_AUTOLOAD..DATA_END =.; + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + SDK_AUTOLOAD_LIST = .; + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + SDK_AUTOLOAD_LIST_END = .; + } >> # > binary.AUTOLOAD_INFO + +# SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; +# SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + } >> # > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + + #:::::::::: text/rodata + . = ALIGN(32); + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: data + . = ALIGN(32); + SDK_OVERLAY..DATA_END =.; + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); . = ALIGN(32); + + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + . = ALIGN(4); + + + + + + + . = ALIGN(4); + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ MAIN EX ################################## + # MAIN EX Area + .dummy.MAIN_EX: + { + . = ALIGN(32); + } > dummy.MAIN_EX + + ############################ ARENA ################################## + .arena.MAIN: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + } > arena.MAIN + + .arena.MAIN_EX: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + } > arena.MAIN_EX + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + } > arena.DTCM + + ############################ OVERLAYDEFS ############################ + .: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > + + + ############################ OVERLAYTABLE ########################### + .: + { + + # Overlay + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + + } > + + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + + # Module filelist + .binary.MODULE_FILES: + { + WRITES (""); + WRITES (""); + WRITES (""); + } > binary.MODULE_FILES + + # ITCM/DTCM size checker => check AUTOLOAD_ITCM/DTCM + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + } > check.ITCM + + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + . = . + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + +} diff --git a/include/firm/specfiles/ARM9-TS-GCDFIRM.lsf b/include/firm/specfiles/ARM9-TS-GCDFIRM.lsf new file mode 100644 index 00000000..26780957 --- /dev/null +++ b/include/firm/specfiles/ARM9-TS-GCDFIRM.lsf @@ -0,0 +1,42 @@ +#---------------------------------------------------------------------------- +# Project: TwlFirm - include +# File: ARM9-TS-NORFIRM.lsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, 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$ +#---------------------------------------------------------------------------- +# +# TwlFirm LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x03800000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) +} + +Autoload ITCM +{ + Address 0x01ff8000 + Object * (.itcm) + Object $(OBJS_AUTOLOAD) (.text) +} + +Autoload DTCM +{ + Address 0x027e0000 + Object * (.dtcm) + Object $(OBJS_AUTOLOAD) (.data) + Object $(OBJS_AUTOLOAD) (.bss) +} + diff --git a/include/firm/specfiles/ARM9-TS-PARTNER.lcf.template b/include/firm/specfiles/ARM9-TS-PARTNER.lcf.template new file mode 100644 index 00000000..d4582b72 --- /dev/null +++ b/include/firm/specfiles/ARM9-TS-PARTNER.lcf.template @@ -0,0 +1,983 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM9-BB.lcf.template +# +# 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$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 #> + + + (RWX) : ORIGIN = , LENGTH = 0x0 #>> + +# binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> +# binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.NITRO (RW) : ORIGIN = 0x023e0000, LENGTH = 0x0 + arena.MAIN.NITRO (RW) : ORIGIN = AFTER(,), LENGTH = 0x0 + arena.MAIN_EX.NITRO (RW) : ORIGIN = AFTER(dummy.MAIN_EX.NITRO,), LENGTH = 0x0 + arena.ITCM (RW) : ORIGIN = AFTER(ITCM,), LENGTH = 0x0 + arena.DTCM (RW) : ORIGIN = AFTER(DTCM,), LENGTH = 0x0 + + check.ITCM (RW) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check + check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check + +# binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 #>> + +# binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWXO): ORIGIN = , LENGTH = 0x0 > + + + dummy.MAIN_EX.TWL (RW) : ORIGIN = 0x0d000000, LENGTH = 0x0 + arena.MAIN.TWL (RW) : ORIGIN = AFTER(,,LTDMAIN,), LENGTH = 0x0 + arena.MAIN_EX.TWL (RW) : ORIGIN = AFTER(dummy.MAIN_EX.TWL,,,LTDMAIN,), LENGTH = 0x0 + + binary.MODULE_FILES (RW) : ORIGIN = 0, LENGTH = 0x0 > component.files +} + +FORCE_ACTIVE +{ + SVC_SoftReset +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + SDK_STATIC_TEXT_START =.; + #:::::::::: text/rodata + libsyscall.a (.text) + OBJECT(_start,*) + crt0_firm.o (.text) + crt0_firm.o (.rodata) + # + # .version ZNVljĂ܂B + # ̃ZNVɊ܂܂̓bg`FbN̍ۂ + # KvƂȂ܂̂ŁAK̈ʒuɎc悤ɂĉB + # + * (.version) + OBJECT(TwlMain,*) + + + + + + + * (.exception) + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_STATIC_SINIT_END =.; + #:::::::::: text/rodata + SDK_STATIC_TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); # Fit to cache line + SDK_STATIC_DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY_DIGEST =.; + # NO DIGEST + SDK_OVERLAY_DIGEST_END =.; + #:::::::::: data + SDK_STATIC_DATA_END =.; + . = ALIGN(32); + SDK_STATIC_END =.; + + SDK_STATIC_TEXT_SIZE = SDK_STATIC_TEXT_END - SDK_STATIC_TEXT_START; + SDK_STATIC_DATA_SIZE = SDK_STATIC_DATA_END - SDK_STATIC_DATA_START; + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + + ############################ AUTOLOADS ############################## + SDK_AUTOLOAD.ITCM.START = 0x01ff8000; + SDK_AUTOLOAD.ITCM.END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.BSS_END = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD.ITCM.SIZE = 0; + SDK_AUTOLOAD.ITCM.BSS_SIZE = 0; + SDK_AUTOLOAD.DTCM.START = 0x02fe0000; + SDK_AUTOLOAD.DTCM.END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.BSS_END = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD.DTCM.SIZE = 0; + SDK_AUTOLOAD.DTCM.BSS_SIZE = 0; + SDK_AUTOLOAD_START = SDK_STATIC_END; + SDK_AUTOLOAD_SIZE = 0; + SDK_AUTOLOAD_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_AUTOLOAD__ID =; + SDK_AUTOLOAD..ID =; + SDK_AUTOLOAD..START =.; + SDK_AUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + #:::::::::: text/rodata + SDK_AUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(32); + SDK_AUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_AUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_AUTOLOAD..END =.; + + SDK_AUTOLOAD..TEXT_SIZE = SDK_AUTOLOAD..TEXT_END - SDK_AUTOLOAD..TEXT_START; + SDK_AUTOLOAD..DATA_SIZE = SDK_AUTOLOAD..DATA_END - SDK_AUTOLOAD..DATA_START; + SDK_AUTOLOAD..SIZE = SDK_AUTOLOAD..END - SDK_AUTOLOAD..START; + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SDK_AUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL + + + # + # BSS BLOCK + # + SDK_AUTOLOAD..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_AUTOLOAD..BSS_END = .; + + SDK_AUTOLOAD..BSS_SIZE = SDK_AUTOLOAD..BSS_END - SDK_AUTOLOAD..BSS_START; + + } >> + + + + SDK_AUTOLOAD_ITCM_START = SDK_AUTOLOAD.ITCM.START; + SDK_AUTOLOAD_ITCM_END = SDK_AUTOLOAD.ITCM.END; + SDK_AUTOLOAD_ITCM_BSS_END = SDK_AUTOLOAD.ITCM.BSS_END; + SDK_AUTOLOAD_ITCM_SIZE = SDK_AUTOLOAD.ITCM.SIZE; + SDK_AUTOLOAD_ITCM_BSS_SIZE = SDK_AUTOLOAD.ITCM.BSS_SIZE; + SDK_AUTOLOAD_DTCM_START = SDK_AUTOLOAD.DTCM.START; + SDK_AUTOLOAD_DTCM_END = SDK_AUTOLOAD.DTCM.END; + SDK_AUTOLOAD_DTCM_BSS_END = SDK_AUTOLOAD.DTCM.BSS_END; + SDK_AUTOLOAD_DTCM_SIZE = SDK_AUTOLOAD.DTCM.SIZE; + SDK_AUTOLOAD_DTCM_BSS_SIZE = SDK_AUTOLOAD.DTCM.BSS_SIZE; + + ############################ AUTOLOAD_INFO ########################## + .binary.AUTOLOAD_INFO: + { + SDK_AUTOLOAD_LIST = .; + + WRITEW ADDR(.); + WRITEW SDK_AUTOLOAD..SIZE; + WRITEW SDK_AUTOLOAD..BSS_SIZE; + + SDK_AUTOLOAD_LIST_END = .; + } >> #> binary.AUTOLOAD_INFO + +# SDK_AUTOLOAD_LIST = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE; +# SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO); + +# ############################ STATIC_FOOTER ########################## +# .binary.STATIC_FOOTER: +# { +# WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE +# WRITEW _start_ModuleParams - ADDR(.); +# WRITEW 0; # NO DIGEST +# } > binary.STATIC_FOOTER + + ############################ OVERLAYS ############################### + SDK_OVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_OVERLAY__ID =; ### SEGMENT OVERLAY ID + SDK_OVERLAY..ID =; + SDK_OVERLAY..START =.; + SDK_OVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_OVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_OVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_OVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_OVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_OVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_OVERLAY..END =.; + + SDK_OVERLAY..TEXT_SIZE = SDK_OVERLAY..TEXT_END - SDK_OVERLAY..TEXT_START; + SDK_OVERLAY..DATA_SIZE = SDK_OVERLAY..DATA_END - SDK_OVERLAY..DATA_START; + SDK_OVERLAY..SIZE = SDK_OVERLAY..END - SDK_OVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_OVERLAY..BSS_START = .; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_OVERLAY..BSS_END = .; + + SDK_OVERLAY..BSS_SIZE = SDK_OVERLAY..BSS_END - SDK_OVERLAY..BSS_START; + + } >> + + + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE + SDK_AUTOLOAD_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + ### overlay filename + + WRITES (""); # Overlay + + + } > F + + ############################ OVERLAYTABLE ########################### + .F: + { + + WRITEW ; # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_OVERLAY..SIZE; # size of module + WRITEW SDK_OVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_OVERLAY..SINIT_START; # start address of static init + WRITEW SDK_OVERLAY..SINIT_END; # end address of static init + WRITEW ; # ROM file ID + WRITEW 0; # Reserved + + + } > F + + ############################ ARENA ################################## + .dummy.MAIN_EX.NITRO: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.NITRO + + .arena.MAIN.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_START =.; + + } > arena.MAIN.NITRO + + .arena.MAIN_EX.NITRO: + { + . = ALIGN(32); + SDK_SECTION_ARENA_EX_START =.; + + } > arena.MAIN_EX.NITRO + + .arena.ITCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_ITCM_START =.; + + } > arena.ITCM + + .arena.DTCM: + { + . = ALIGN(32); + SDK_SECTION_ARENA_DTCM_START =.; + + } > arena.DTCM + + ############################ OTHERS ################################# + SDK_MAIN_ARENA_LO = SDK_SECTION_ARENA_START; + SDK_IRQ_STACKSIZE = ; # allocated in DTCM + SDK_SYS_STACKSIZE = ; # when 0 means all remains of DTCM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.ITCM: + { + . = . + SDK_AUTOLOAD_ITCM_SIZE + SDK_AUTOLOAD_ITCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + + } > check.ITCM + + .check.DTCM: + { + . = . + SDK_AUTOLOAD_DTCM_SIZE + SDK_AUTOLOAD_DTCM_BSS_SIZE; + + . = . + SDK_OVERLAY..SIZE + SDK_OVERLAY..BSS_SIZE; + + . = . + 0x080 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + } > check.DTCM + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD.LTDMAIN.START = SDK_STATIC_BSS_END; + SDK_LTDAUTOLOAD.LTDMAIN.END = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_EDN = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD.LTDMAIN.SIZE = 0; + SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE = 0; + SDK_LTDAUTOLOAD_TOP_START = 0x02400000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC ̈悪 4 bytes ̃_~[oCit@C̐擪ɓ # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_NUMBER = ; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } >> #> binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(32); # Fit to cache line + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDAUTOLOAD__ID =; + SDK_LTDAUTOLOAD..ID =; + SDK_LTDAUTOLOAD..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + #:::::::::: text/rodata + SDK_LTDAUTOLOAD..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDAUTOLOAD..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + + + + + + + #:::::::::: data + SDK_LTDAUTOLOAD..DATA_END =.; + . = ALIGN(32); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..TEXT_SIZE = SDK_LTDAUTOLOAD..TEXT_END - SDK_LTDAUTOLOAD..TEXT_START; + SDK_LTDAUTOLOAD..DATA_SIZE = SDK_LTDAUTOLOAD..DATA_END - SDK_LTDAUTOLOAD..DATA_START; + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDAUTOLOAD..BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + + SDK_LTDAUTOLOAD_LTDMAIN_START = SDK_LTDAUTOLOAD.LTDMAIN.START; + SDK_LTDAUTOLOAD_LTDMAIN_END = SDK_LTDAUTOLOAD.LTDMAIN.END; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_END = SDK_LTDAUTOLOAD.LTDMAIN.BSS_END; + SDK_LTDAUTOLOAD_LTDMAIN_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.SIZE; + SDK_LTDAUTOLOAD_LTDMAIN_BSS_SIZE = SDK_LTDAUTOLOAD.LTDMAIN.BSS_SIZE; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + SDK_LTDAUTOLOAD_LIST = .; + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + SDK_LTDAUTOLOAD_LIST_END = .; + } >> #> binary.LTDAUTOLOAD_INFO + +# SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; +# SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################### LTDOVERLAYS ############################# + SDK_LTDOVERLAY_NUMBER = ; + + + .: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + SDK_LTDOVERLAY__ID =; + SDK_LTDOVERLAY..ID =; + SDK_LTDOVERLAY..START =.; + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDOVERLAY..TEXT_START =.; + #:::::::::: text/rodata + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDOVERLAY..SINIT_START =.; + #:::::::::: ctor + + + + + + + + + + + + + WRITEW 0; + #:::::::::: ctor + SDK_LTDOVERLAY..SINIT_END =.; + #:::::::::: text/rodata + SDK_LTDOVERLAY..TEXT_END =.; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(32); + SDK_LTDOVERLAY..DATA_START =.; + #:::::::::: data + + + + + + + + + + + + + #:::::::::: data + SDK_LTDOVERLAY..DATA_END =.; + . = ALIGN(32); + SDK_LTDOVERLAY..END =.; + + SDK_LTDOVERLAY..TEXT_SIZE = SDK_LTDOVERLAY..TEXT_END - SDK_LTDOVERLAY..TEXT_START; + SDK_LTDOVERLAY..DATA_SIZE = SDK_LTDOVERLAY..DATA_END - SDK_LTDOVERLAY..DATA_START; + SDK_LTDOVERLAY..SIZE = SDK_LTDOVERLAY..END - SDK_LTDOVERLAY..START; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(32); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDOVERLAY..BSS_START =.; + #:::::::::: bss + + + + + + + + + + + + + #:::::::::: bss + . = ALIGN(32); + SDK_LTDOVERLAY..BSS_END =.; + + SDK_LTDOVERLAY..BSS_SIZE = SDK_LTDOVERLAY..BSS_END - SDK_LTDOVERLAY..BSS_START; + + } >> + + + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW 0; # padding + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + ### TWL limited overlay filename + + WRITES (""); + + + } > L + + ######################### LTDOVERLAYTABLE ########################### + .L: + { + + WRITES # overlay ID + WRITEW ADDR(.); # load address + WRITEW SDK_LTDOVERLAY..SIZE; # size of module + WRITEW SDK_LTDOVERLAY..BSS_SIZE; # size of bss + WRITEW SDK_LTDOVERLAY..SINIT_START; # start address of static init + WRITEW SDK_LTDOVERLAY..SINIT_END; # end address of static init + WRITEW # ROM file ID + WRITEW 0; # Reserved + + + } > L + + ############################ ARENA ################################## + .dummy.MAIN_EX.TWL: + { + . = ALIGN(32); + + } > dummy.MAIN_EX.TWL + + .arena.MAIN.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_ARENA_LO =.; + + } > arena.MAIN.TWL + + .arena.MAIN_EX.TWL: + { + . = ALIGN(32); + SDK_LTDMAIN_EX_ARENA_LO =.; + + } > arena.MAIN_EX.TWL + + ############################ OTHERS ################################# + # Module filelist + .binary.MODULE_FILES: + { +# WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + WRITES (""); + + } > binary.MODULE_FILES + +} diff --git a/include/firm/specfiles/ROM-TS-FIRM.rsf b/include/firm/specfiles/ROM-TS-FIRM.rsf new file mode 100644 index 00000000..fc1a8a6f --- /dev/null +++ b/include/firm/specfiles/ROM-TS-FIRM.rsf @@ -0,0 +1,179 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ROM-BB.rsf +# +# Copyright 2007 Nintendo. All rights reserved. +# +# These coded insructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- +# +# TWL ROM SPEC FILE +# + +Arm9 +{ + Static "$(MAKEROM_ARM9:r).TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.FLX.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.FLX.sbin$(COMPSUFFIX9)" + Elf "$(MAKEROM_ARM9:r).tef" +} + +Arm7 +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.FLX.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.FLX.sbin$(COMPSUFFIX7)" + Elf "$(MAKEROM_ARM7_BASE:r).tef" +} + +Arm9.Ltd +{ + Static "$(MAKEROM_ARM9:r).TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayDefs "$(MAKEROM_ARM9:r)_defs.TWL.LTD.sbin$(COMPSUFFIX9)" + OverlayTable "$(MAKEROM_ARM9:r)_table.TWL.LTD.sbin$(COMPSUFFIX9)" +} + +Arm7.Ltd +{ + Static "$(MAKEROM_ARM7_BASE:r).TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.TWL.LTD.sbin$(COMPSUFFIX7)" + OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.TWL.LTD.sbin$(COMPSUFFIX7)" +} + +Property +{ + ### + ### Settings for FinalROM + ### + #### BEGIN + # + # TITLE NAME: Your product name within 12bytes + # + TitleName "FIRM" + + # + # MAKER CODE: Your company ID# in 2 ascii words + # issued by NINTENDO + # + MakerCode "01" + + # + # REMASTER VERSION: Mastering version + # + #RomVersion 0 + + # + # ROM SPEED TYPE: [MROM/1TROM/UNDEFINED] + # + RomSpeedType $(MAKEROM_ROMSPEED) + + # + # ROM SIZE: in bit [64M/128M/256M/512M/1G/2G] + # + #RomSize 128M + #RomSize 256M + + # + # ROM PADDING: TRUE if finalrom + # + #RomFootPadding TRUE + + # + # ROM HEADER TEMPLATE: Provided to every product by NINTENDO + # + #RomHeaderTemplate ./etc/rom_header.template.sbin + + # + # BANNER FILE: generated from Banner Spec File + # + #BannerFile ./etc/myGameBanner.bnr + BannerFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + ### + ### Setting for TWL + ### + # + # BANNER FILE: + # + BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr + + # + # Digest parameters: + # + DigestParam 1024 32 + + # + # WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD] + # don't have to edit + # + #WramMapping $(MAKEROM_WRAM_MAPPING) + WramMappingDirect ../wram_regs/wram_regs.rbin + + # + # Codec mode: + # don't have to edit + # + CodecMode $(MAKEROM_CODEC_MODE) + + ### + #### END +} + +AppendProperty +{ + # + # Publisher : "Nintendo" + # don't have to edit + Publisher Nintendo + + # + # Application type : [USER/SYSTEM] + # don't have to edit + AppType System + + # + # launch title on the launcher : [TRUE/FALSE] + # don't have to edit + Launch TRUE + + # + # Boot allowed Media: [GameCard/NAND] + # + Media NAND + + # + # GameCode for TitleID : Your GameCode in 4 ascii words + # + #GameCode $(TITLEID_LO) + + # + # Public save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PublicSaveDataSize 32K + + # + # Private save data size: [16K/32K/64K/128K/256K/512K/1M/2M/4M/8M] + # + #PrivateSaveDataSize 16K + + # + # Enable SaveBannerFile + #SaveBannerFile TRUE +} + +RomSpec +{ + Offset 0x00000000 + Segment ALL + HostRoot $(MAKEROM_ROMROOT) + Root / + File $(MAKEROM_ROMFILES) +} diff --git a/include/sysmenu.h b/include/sysmenu.h new file mode 100644 index 00000000..087e5413 --- /dev/null +++ b/include/sysmenu.h @@ -0,0 +1,39 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: sysmenu.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 SYSMENU_H_ +#define SYSMENU_H_ + +// Compile switch---------------------- +#define DEBUG_USED_CARD_SLOT_B_ // fobOpŃJ[hXbgBgpꍇɗLɂB + +//------------------------------------- + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* SYSMENU_H_ */ +#endif diff --git a/include/sysmenu/acsign.h b/include/sysmenu/acsign.h new file mode 100644 index 00000000..9107b415 --- /dev/null +++ b/include/sysmenu/acsign.h @@ -0,0 +1,36 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - ACSIGN + File: acsign.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 SYSM_ACSIGN_H_ +#define SYSM_ACSIGN_H_ + +#ifdef SDK_ARM9 +#include +//#include +#endif // SDK_ARM9 + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* SYSM_ACSIGN_H_ */ +#endif diff --git a/include/sysmenu/acsign/ARM9/acsign.h b/include/sysmenu/acsign/ARM9/acsign.h new file mode 100644 index 00000000..17969eb2 --- /dev/null +++ b/include/sysmenu/acsign/ARM9/acsign.h @@ -0,0 +1,69 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: acsign.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 _ACSIGN_H_ +#define _ACSIGN_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined( RSA_ENC_DEC ) +#define ACSIGN_BUFFER ((160/8)*4) // o̓obt@ +#else +#define ACSIGN_BUFFER ((160/8)*1) // o̓obt@ +#endif + +// +int ACSign_Decrypto( + void* buffer, // o͗̈ + void* sgn_ptr, // f[^ւ̃|C^ + void* key_ptr // L[ւ̃|C^ + ); + +// +BOOL ACSign_Encrypto( + void *sign, // o̓obt@ւ̃|C^ + const void *key, // DERtH[}bg閧ւ̃|C^ + const void *data, // Ώۃf[^ւ̃|C^ + int length // Ώۃf[^ + ); + +// +int ACSign_Digest( + void* buffer, // o͗̈ + void* romh_ptr, // f[^ւ̃|C^ + void* mbin_ptr, // f[^ւ̃|C^ + int mbin_len, // f[^̒ + void* sbin_ptr, // f[^ւ̃|C^ + int sbin_len, // f[^̒ + u32 serial_num // VAio[ + ); + +// +int ACSign_Compare( + void* dercypto, // ACSign_Decryptȍo + void* digest // ACSign_Digest̏o + ); + +void ACSign_SetAllocFunc( void *(*pAlloc)( u32 ), void (*pFree)( void * ) ); + +#ifdef __cplusplus +} +#endif + +#endif //_ACSIGN_H_ diff --git a/include/sysmenu/acsign/ARM9/acsign_util.h b/include/sysmenu/acsign/ARM9/acsign_util.h new file mode 100644 index 00000000..dd09d6bf --- /dev/null +++ b/include/sysmenu/acsign/ARM9/acsign_util.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: acsign_util.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 _ACSIGN_UTIL_H_ +#define _ACSIGN_UTIL_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define AUTH_BUFFER_LEN 20 + +extern int ACSignDecrpto(void *output_buffer, MBDownloadFileInfo *download_file_info_buf); +extern int ACSignDigest(void *input_buffer, MBDownloadFileInfo *download_file_info_buf); + + +#ifdef __cplusplus +} +#endif + +#endif //_ACSIGN_UTIL_H_ diff --git a/include/sysmenu/banner.h b/include/sysmenu/banner.h new file mode 100644 index 00000000..7879d90a --- /dev/null +++ b/include/sysmenu/banner.h @@ -0,0 +1,34 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: banner.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$ + *---------------------------------------------------------------------------*/ + +#ifndef BANNER_H_ +#define BANNER_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* BANNER_H_ */ +#endif diff --git a/include/sysmenu/banner/common/NTRBanner.h b/include/sysmenu/banner/common/NTRBanner.h new file mode 100644 index 00000000..51af555d --- /dev/null +++ b/include/sysmenu/banner/common/NTRBanner.h @@ -0,0 +1,104 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: NTRBanner.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$ + *---------------------------------------------------------------------------*/ + +#ifndef NTR_BANNER_H_ +#define NTR_BANNER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifndef BANNER_ROM_OFFSET +#define BANNER_ROM_OFFSET ( HW_TWL_ROM_HEADER_BUF + 0x68 ) +#endif + +#define NTR_BNR_VER_MIN 0x01 +#define NTR_BNR_VER_MAX 0x03 +#define BNR_CHINESE_SUPPORT_VER 2 +#define BNR_HANGUL_SUPPORT_VER 3 + +#define BNR_LANG_MAX 16 +#define BNR_LANG_NUM_V1 6 +#define BNR_LANG_NUM_V2 1 +#define BNR_LANG_NUM_V3 1 + +#define BNR_HEADER_SIZE 32 +#define BNR_HEADER_RSV_SIZE 24 +#define BNR_IMAGE_SIZE ( 32 * 32 / (8/4) ) +#define BNR_PLTT_NUM 16 +#define BNR_PLTT_SIZE ( BNR_PLTT_NUM * 2 ) +#define BNR_LANG_LENGTH 128 +#define BNR_LANG_SIZE ( BNR_LANG_LENGTH * 2 ) + + +typedef enum NTRBannerLangCode { + NTR_BNR_JAPANESE = 0, + NTR_BNR_ENGLISH = 1, + NTR_BNR_FRENCH = 2, + NTR_BNR_GERMAN = 3, + NTR_BNR_ITALIAN = 4, + NTR_BNR_SPANISH = 5, + NTR_BNR_CHINESE = 6, + NTR_BNR_HANGUL = 7, + NTR_BNR_LANG_NUM +}NTRBannerLangCode; + + +typedef struct NTRBannerHeader { + u8 version; + u8 reserved_A; + u16 crc16_v1; + u16 crc16_v2; + u16 crc16_v3; + u8 reserved_B[ BNR_HEADER_RSV_SIZE ]; +}NTRBannerHeader; + + +typedef struct BannerFileV1 { + u8 image[ BNR_IMAGE_SIZE ]; + GXRgba pltt [ BNR_PLTT_NUM ]; + u16 comment[ BNR_LANG_NUM_V1 ][ BNR_LANG_LENGTH ]; +}BannerFileV1; + + +typedef struct BannerFileV2{ + u16 comment[ BNR_LANG_NUM_V2 ][ BNR_LANG_LENGTH ]; +}BannerFileV2; + + +typedef struct BannerFileV3{ + u16 comment[ BNR_LANG_NUM_V3 ][ BNR_LANG_LENGTH ]; +}BannerFileV3; + + +typedef struct NTRBannerFile { + NTRBannerHeader h; + BannerFileV1 v1; + BannerFileV2 v2; + BannerFileV3 v3; +}NTRBannerFile; + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* NTR_BANNER_H_ */ +#endif diff --git a/include/sysmenu/banner/common/TWLBanner.h b/include/sysmenu/banner/common/TWLBanner.h new file mode 100644 index 00000000..9302de6a --- /dev/null +++ b/include/sysmenu/banner/common/TWLBanner.h @@ -0,0 +1,82 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: TWLBanner.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$ + *---------------------------------------------------------------------------*/ + +#ifndef TWL_BANNER_H_ +#define TWL_BANNER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define TWL_BNR_VER_MIN 0x80 +#define TWL_BNR_VER_MAX 0x80 +#define TWL_BNR_ICON_NUM 8 +#define TWL_BNR_ICON_DISP_FRAME_MAX 60 +#define TWL_BNR_HEADER_RSV_SIZE ( BNR_HEADER_RSV_SIZE - sizeof(BannerAnimeCtrl) ) + + +typedef enum BannerAnimeLoopType { + BNR_ANIME_LOOP_NORMAL = 1, + BNR_ANIME_LOOP_BACK = 2 +}BannerAnimeLoopType; + + +typedef struct BannerAnimeCtrl { + BannerAnimeLoopType loopType; + u8 dispFrameCount[ TWL_BNR_ICON_NUM ]; +}BannerAnimeCtrl; + + +typedef struct TWLBannerHeader { + u8 version; + u8 reserved_A; + u16 crc16_v1; + u16 crc16_v2; + u16 crc16_v3; + u8 reserved_B[ TWL_BNR_HEADER_RSV_SIZE ]; + BannerAnimeCtrl anime; +}TWLBannerHeader; + + +typedef struct BannerIcon { + u8 image[ BNR_IMAGE_SIZE ]; + GXRgba pltt [ BNR_PLTT_NUM ]; +}BannerIcon; + +typedef struct BannerCommentRsv { + u16 comment[ BNR_LANG_MAX - NTR_BNR_LANG_NUM ][ BNR_LANG_LENGTH ]; +}BannerCommentRsv; + +typedef struct TWLBannerFile { + TWLBannerHeader h; + BannerFileV1 v1; + BannerFileV2 v2; + BannerFileV3 v3; + BannerCommentRsv rsv; + BannerIcon icon[ TWL_BNR_ICON_NUM - 1 ]; // 擪̂P‚BannerFileV1ɂB +}TWLBannerFile; + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* TWL_BANNER_H_ */ +#endif diff --git a/include/sysmenu/boot.h b/include/sysmenu/boot.h new file mode 100644 index 00000000..ced8a3b0 --- /dev/null +++ b/include/sysmenu/boot.h @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: boot.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 SYSM_BOOT_H_ +#define SYSM_BOOT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* SYSM_MACHINE_SETTINGS_H_ */ +#endif diff --git a/include/sysmenu/boot/common/boot_api.h b/include/sysmenu/boot/common/boot_api.h new file mode 100644 index 00000000..e36cf4bf --- /dev/null +++ b/include/sysmenu/boot/common/boot_api.h @@ -0,0 +1,83 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: boot_api.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-11-8#$ + $Rev: $ + $Author: yoshida_teruhisa $ + *---------------------------------------------------------------------------*/ + +#if !defined(_SYSMENU_BOOT_H_) +#define _SYSMENU_BOOT_API_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + Type definition + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + functions + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: BOOT_Core + + Description: u[g̃RA֐ + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void BOOT_Core( void ); + +/*---------------------------------------------------------------------------* + Name: BOOT_Init + + Description: u[ĝ߂̏ + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void BOOT_Init( void ); + +/*---------------------------------------------------------------------------* + Name: BOOT_WaitStart + + Description: X^[g҂(ARM7) + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +BOOL BOOT_WaitStart( void ); + +/*---------------------------------------------------------------------------* + Name: BOOT_WaitStart + + Description: u[gJnyARM7ւ̒ʒmyёҋ@(ARM9) + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void BOOT_Ready( void ); + +#ifdef __cplusplus +} +#endif + +#endif /* _SYSMENU_BOOT_API_H_ */ diff --git a/include/sysmenu/hotsw.h b/include/sysmenu/hotsw.h new file mode 100644 index 00000000..c3a14925 --- /dev/null +++ b/include/sysmenu/hotsw.h @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: hotsw.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 SYSM_HOTSW_H_ +#define SYSM_HOTSW_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* SYSM_HOTSW_H_ */ +#endif diff --git a/include/sysmenu/hotsw/common/hotsw.h b/include/sysmenu/hotsw/common/hotsw.h new file mode 100644 index 00000000..11441682 --- /dev/null +++ b/include/sysmenu/hotsw/common/hotsw.h @@ -0,0 +1,46 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK + File: Card.h + *---------------------------------------------------------------------------*/ +#ifndef __MY_CARD_H__ +#define __MY_CARD_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define SYSM_HOTSW_ENABLE_ROMEMU + +// Function prototype ------------------------------------------------------- +// }̏ +void HOTSW_Init(void); + +// J[hf[^[hBNormal[hSecure[hGame[hs +BOOL HOTSW_LoadCardData(void); + +// ARM7,9̏풓W[WJ֐ +void HOTSW_LoadStaticModule(void); + +// Boot Segment obt@̎w +void HOTSW_SetBootSegmentBuffer(void* buf, u32 size); + +// Secure Segment obt@̎w +void HOTSW_SetSecureSegmentBuffer(void* buf, u32 size); + +// RomG~[Vi[Ăobt@̃|C^Ԃ +#ifdef SDK_ARM7 +void* HOTSW_GetRomEmulationBuffer(void); +#else // SDK_ARM9 +SDK_INLINE void* HOTSW_GetRomEmulationBuffer(void) +{ + return (void*)HW_ISD_RESERVED; +} +#endif // SDK_ARM9 + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // __MY_CARD_H__ \ No newline at end of file diff --git a/include/sysmenu/hw/common/mmap.h b/include/sysmenu/hw/common/mmap.h new file mode 100644 index 00000000..aee88f83 --- /dev/null +++ b/include/sysmenu/hw/common/mmap.h @@ -0,0 +1,111 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: mmap.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$ + *---------------------------------------------------------------------------*/ + +#ifndef _SYSMENU_MMAP_H_ +#define _SYSMENU_MMAP_H_ + +#ifndef SDK_ASM +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +// define data ------------------------------------ + +// SystemMenug̃}bv` +#define SYSM_OWN_ARM9_MMEM_ADDR 0x02800000 +#ifdef DEBUG_USED_CARD_SLOT_B_ +#define SYSM_OWN_ARM9_MMEM_ADDR_END 0x02e73000 +#else +#define SYSM_OWN_ARM9_MMEM_ADDR_END 0x02e76000 +#endif +#define SYSM_OWN_ARM7_MMEM_ADDR 0x02280000 +#define SYSM_OWN_ARM7_MMEM_ADDR_END 0x02380000 +extern u32 SDK_AUTOLOAD_WRAM_START[]; +#ifndef SDK_ASM +#define SYSM_OWN_ARM7_WRAM_ADDR ((u32)SDK_AUTOLOAD_WRAM_START) +#else +#define SYSM_OWN_ARM7_WRAM_ADDR SDK_AUTOLOAD_WRAM_START +#endif +#define SYSM_OWN_ARM7_WRAM_ADDR_END 0x0380f000 + +#define SYSM_BOOTCODE_ARM9_ADDR 0x027ffc00 // ARM9ŏIu[gR[hAhX +#define SYSROM9_NINLOGO_ADR 0xffff0020 // ARM9VXeROM̔CVSi[AhX + +// J[hAvi[obt@ +#define SYSM_CARD_ROM_HEADER_SIZE 0x1000 + +#ifdef DEBUG_USED_CARD_SLOT_B_ +#define SYSM_CARD_BANNER_BUF ( SYSM_OWN_ARM9_MMEM_ADDR_END ) +#define SYSM_CARD_BANNER_BUF_END ( SYSM_CARD_BANNER_BUF + 0x3000 ) +#define SYSM_CARD_ROM_HEADER_BUF ( SYSM_CARD_BANNER_BUF_END ) +#else +#define SYSM_CARD_ROM_HEADER_BUF ( SYSM_OWN_ARM9_MMEM_ADDR_END ) +#endif +#define SYSM_CARD_ROM_HEADER_BUF_END ( SYSM_CARD_ROM_HEADER_BUF + SYSM_CARD_ROM_HEADER_SIZE ) +#define SYSM_CARD_ROM_HEADER_BAK ( SYSM_CARD_ROM_HEADER_BUF_END ) +#define SYSM_CARD_ROM_HEADER_BAK_END ( SYSM_CARD_ROM_HEADER_BAK + SYSM_CARD_ROM_HEADER_SIZE ) +#define SYSM_CARD_NTR_SECURE_BUF ( SYSM_CARD_ROM_HEADER_BAK_END ) +#define SYSM_CARD_NTR_SECURE_BUF_END ( SYSM_CARD_NTR_SECURE_BUF + SECURE_AREA_SIZE ) +#define SYSM_CARD_TWL_SECURE_BUF ( SYSM_CARD_NTR_SECURE_BUF_END ) +#define SYSM_CARD_TWL_SECURE_BUF_END ( SYSM_CARD_TWL_SECURE_BUF + SECURE_AREA_SIZE ) + +#define SYSM_NTR_ROM_HEADER_BUF 0x023ffe00 +#define SYSM_DBG_NTR_ROM_HEADER_BUF 0x027ffe00 +#define SYSM_DBG_NTR_SYSTEM_BUF 0x027ff000 + +// AvWRAMɒڔzuău[g悤ƂƁASystemMenũR[hƂԂ‚Ă낢₱ԂɂȂ̂ŁAKv + +// Av[h”\̈̃}bv` +#define SYSM_NTR_ARM9_LOAD_MMEM 0x02000000 // [h”\ARM9 static MMEM AhX +#define SYSM_NTR_ARM9_LOAD_MMEM_END 0x02280000 // [h”\ARM9 static MMEM ŏIAhX +#define SYSM_NTR_ARM7_LOAD_MMEM 0x02380000 // [h”\ARM7 static MMEM AhX +#define SYSM_NTR_ARM7_LOAD_MMEM_END 0x023c0000 // [h”\ARM7 static MMEM ŏIAhX +#define SYSM_NTR_ARM7_LOAD_WRAM 0x037f8000 // [h”\ARM7 static WRAM AhX +#define SYSM_NTR_ARM7_LOAD_WRAM_END 0x0380f000 // [h”\ARM7 static WRAM ŏIAhX + +#define SYSM_TWL_ARM9_LOAD_MMEM 0x02000400 // [h”\ARM9 static MMEM AhX +#define SYSM_TWL_ARM9_LOAD_MMEM_END SYSM_NTR_ARM9_LOAD_MMEM_END // [h”\ARM9 static MMEM ŏIAhX +#define SYSM_TWL_ARM7_LOAD_MMEM SYSM_NTR_ARM7_LOAD_MMEM // [h”\ARM7 static MMEM AhX +#define SYSM_TWL_ARM7_LOAD_MMEM_END SYSM_NTR_ARM7_LOAD_MMEM_END // [h”\ARM7 static MMEM ŏIAhX +#define SYSM_TWL_ARM7_LOAD_WRAM SYSM_NTR_ARM7_LOAD_WRAM // [h”\ARM7 static WRAM AhX +#define SYSM_TWL_ARM7_LOAD_WRAM_END SYSM_NTR_ARM7_LOAD_WRAM_END // [h”\ARM7 static WRAM ŏIAhX + +#define SYSM_TWL_ARM9_LTD_LOAD_MMEM 0x02400000 // [h”\ARM9 LTD static MMEM AhX +#define SYSM_TWL_ARM9_LTD_LOAD_MMEM_END 0x02800000 // [h”\ARM9 LTD static MMEM ŏIAhX +#define SYSM_TWL_ARM7_LTD_LOAD_MMEM 0x02e80000 // [h”\ARM7 LTD static MMEM AhX +#define SYSM_TWL_ARM7_LTD_LOAD_MMEM_END 0x02f88000 // [h”\ARM7 LTD static MMEM ŏIAhX +#define SYSM_TWL_ARM7_LTD_LOAD_WRAM 0x037c0000 // [h”\ARM7 LTD static WRAM AhX +#define SYSM_TWL_ARM7_LTD_LOAD_WRAM_END SYSM_NTR_ARM7_LOAD_WRAM_END // [h”\ARM7 LTD static WRAM ŏIAhX +#define SYSM_TWL_ARM7_LTD_HYB_LOAD_WRAM 0x037f8000 // [h”\ARM7 LTD static WRAM AhX +#define SYSM_TWL_ARM7_LTD_HYB_LOAD_WRAM_END SYSM_NTR_ARM7_LOAD_WRAM_END // [h”\ARM7 LTD static WRAM ŏIAhX + + +// NTR-IPL2̃KV[R[h@\ +#define SYSM_ARM9_LOAD_MMEM_LAST_ADDR 0x02280000 // [h”\ARM9 staticCŏIAhX +#define SYSM_ARM7_LOAD_MMEM_LAST_ADDR 0x023c0000 // [h”\ARM7 staticCŏIAhX +#define SYSM_ARM7_LOAD_WRAM_LAST_ADDR SYSM_OWN_ARM7_WRAM_ADDR_END // [h”\ARM7 staticCŏIAhX +#define SYSM_ARM9_MMEM_ENTRY_ADDR_LIMIT SYSM_ARM9_LOAD_MMEM_LAST_ADDR + +#ifdef __cplusplus +} +#endif + +#endif // _SYSMENU_MMAP_H_ + diff --git a/include/sysmenu/mb_loader.h b/include/sysmenu/mb_loader.h new file mode 100644 index 00000000..d5a1933b --- /dev/null +++ b/include/sysmenu/mb_loader.h @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - MB_LOADER + File: mb_loader.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 SYSM_MB_LOADER_H_ +#define SYSM_MB_LOADER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* SYSM_MB_LOADER_H_ */ +#endif diff --git a/include/sysmenu/mb_loader/common/mb_loader.h b/include/sysmenu/mb_loader/common/mb_loader.h new file mode 100644 index 00000000..9b853e62 --- /dev/null +++ b/include/sysmenu/mb_loader/common/mb_loader.h @@ -0,0 +1,86 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: mb_loader.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$ + *---------------------------------------------------------------------------*/ + +#if !defined(_LOADER_H_) +#define _LOADER_H_ + +#include +#include // twl/mb.hȂB + +#ifdef __cplusplus +extern "C" { +#endif + +#define PXI_FIFO_TAG_MB PXI_FIFO_TAG_USER_0 +/* + ̍ہAFIFO_TAGƂȂTAGԍɎw肵ĂB +*/ + +/*---------------------------------------------------------------------------* + Type definition + *---------------------------------------------------------------------------*/ + +typedef void (*MB_LoaderCallback)(void); + +/*---------------------------------------------------------------------------* + functions + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: LOADER_Init + + Description: [_[̏ + + Arguments: callback - u[g̏oƂɕԂR[obN + + Returns: None. + *---------------------------------------------------------------------------*/ + +void LOADER_Init(MB_LoaderCallback callback); + + +/*---------------------------------------------------------------------------* + Name: LOADER_Start + + Description: [_[̃X^[g + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ + +void LOADER_Start( void ); + + +/*---------------------------------------------------------------------------* + Name: MIm_CpuCopy32 + + Description: [_[pCpuCopy32֐ + + Arguments: + + Returns: TRUE - success FALSE - failed + *---------------------------------------------------------------------------*/ + +void MIm_CpuCopy32( register const void *srcp, register void *destp, register u32 size ); + + +#ifdef __cplusplus +} +#endif + +#endif /* _LOADER_H_ */ diff --git a/include/sysmenu/memorymap.h b/include/sysmenu/memorymap.h new file mode 100644 index 00000000..cfa4bf0e --- /dev/null +++ b/include/sysmenu/memorymap.h @@ -0,0 +1,34 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - memorymap + File: memorymap.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 SYSM_MEMORYMAP_H_ +#define SYSM_MEMORYMAP_H_ + + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* SYSM_MEMORYMAP_H_ */ +#endif diff --git a/include/sysmenu/reloc_info/common/reloc_info.h b/include/sysmenu/reloc_info/common/reloc_info.h new file mode 100644 index 00000000..2e8a17a5 --- /dev/null +++ b/include/sysmenu/reloc_info/common/reloc_info.h @@ -0,0 +1,49 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: reloc_info.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-12-12#$ + $Rev: 352 $ + $Author: yoshida_teruhisa $ + *---------------------------------------------------------------------------*/ + +#ifndef __SYSMENU_RELOC_INFO_H__ +#define __SYSMENU_RELOC_INFO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +//---------------------------------------------------------------------- +//@f[^^` +//---------------------------------------------------------------------- + +// ROMZOg +typedef enum RomSegmentName { + ARM9_STATIC = 0, + ARM7_STATIC = 1, + ARM9_LTD_STATIC = 2, + ARM7_LTD_STATIC = 3 +}RomSegmentName; + +//---------------------------------------------------------------------- +//@֐錾 +//---------------------------------------------------------------------- + +// [ḧ̃`FbNyэĔzu̐ +BOOL SYSM_CheckLoadRegionAndSetRelocateInfo( RomSegmentName seg, u32 *dest, u32 length, Relocate_Info *info, BOOL isTwlApp ); + +#ifdef __cplusplus +} +#endif + +#endif // __SYSMENU_RELOC_INFO_H__ + diff --git a/include/sysmenu/sysmenu_lib.h b/include/sysmenu/sysmenu_lib.h new file mode 100644 index 00000000..d0a2f675 --- /dev/null +++ b/include/sysmenu/sysmenu_lib.h @@ -0,0 +1,34 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - SYSMENU_LIB + File: sysmenu_lib.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 SYSM_SYSMENU_LIB_H_ +#define SYSM_SYSMENU_LIB_H_ + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* SYSM_SYSMENU_LIB_H_ */ +#endif diff --git a/include/sysmenu/sysmenu_lib/common/sysmenu_api.h b/include/sysmenu/sysmenu_lib/common/sysmenu_api.h new file mode 100644 index 00000000..71bb4937 --- /dev/null +++ b/include/sysmenu/sysmenu_lib/common/sysmenu_api.h @@ -0,0 +1,133 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: SYSM_lib.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 __SYSM_LIB_H__ +#define __SYSM_LIB_H__ + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// define data---------------------------------------------------------- + +#ifndef SDK_FINALROM +//#define SYSM_DEBUG_ // fobOR[hprhXCb` +//#define ENABLE_INITIAL_SETTINGS_ +#endif // SDK_FINALROM + +#define CARD_SLOT_NUM 1 // J[hXbg +#define LAUNCHER_TITLE_LIST_NUM 40 // `[̃^CgXg + +#define TITLE_ID_MACHINE_SETTINGS 0x000300055445534d // {̐ݒ̃^CgID + +#define PAD_PRODUCTION_SHORTCUT_CARD_BOOT ( PAD_BUTTON_A | PAD_BUTTON_B \ + | PAD_BUTTON_X | PAD_BUTTON_Y | PAD_BUTTON_R ) + // ʎYHŎgp鏉NݒLZăJ[hu[gV[gJbgL[ + +typedef enum PlatformCode { + PLATFORM_NTR = 0, + PLATFORM_TWL = 1 +}PlatformCode; + + +// ^Cg +typedef struct TitleProperty { // ̏́A`[ɂ͔FؒʂĂȂǁANɂ͔Fؒʂ̂őv낤B + NAMTitleId titleID; // ^CgIDiTitleID_HiŋNfBA͔łHj + LauncherBootFlags flags; // u[g̃`[tO + TWLBannerFile *pBanner; // oi[ւ̃|C^iŒ蒷tH[}bgȂUĂv낤B) +}TitleProperty; + +// AvF، +typedef enum AuthResult { + AUTH_RESULT_SUCCEEDED = 0, + AUTH_RESULT_PROCESSING = 1, + AUTH_RESULT_TITLE_LOAD_FAILED = 2, + AUTH_RESULT_TITLE_POINTER_ERROR = 3, + AUTH_RESULT_AUTHENTICATE_FAILED = 4, + AUTH_RESULT_ENTRY_ADDRESS_ERROR = 5, + AUTH_RESULT_TITLE_BOOTTYPE_ERROR = 6 +}AuthResult; + + +// global variable------------------------------------------------------ +#ifdef SDK_ARM9 +extern void *SYSM_Alloc( u32 size ); +extern void SYSM_Free( void *ptr ); +//extern void *(*SYSM_Alloc)( u32 size ); // Cugp +//extern void (*SYSM_Free)( void *ptr ); // +#endif + +// function------------------------------------------------------------- + +#ifdef SDK_ARM9 + +// +extern void SYSM_Init( void *(*pAlloc)(u32), void (*pFree)(void*) ); // B +extern void SYSM_SetArena( void ); // VXej[̃A[iBOS_IniťŌĂłB +extern void SYSM_SetAllocFunc( void *(*pAlloc)(u32), void (*pFree)(void*) ); // SYSM_initŐݒ肵ꍇ͕KvȂB +extern TitleProperty *SYSM_ReadParameters( void ); // {̐ݒf[^AZbgp[^Ȃǂ擾 + +// Av擾 +extern int SYSM_GetCardTitleList( TitleProperty *pTitleList_Card ); // J[hAv^CgXg̎擾 +extern int SYSM_GetNandTitleList( TitleProperty *pTitleList_Nand, int size ); // NAND Av^CgXg̎擾 + +// AvN +extern void SYSM_StartLoadTitle( TitleProperty *pBootTitle ); // w肵TitlePropertyʃXbhŃ[hJn +extern BOOL SYSM_IsLoadTitleFinished( TitleProperty *pBootTitle ); // SYSM_StartLoadTitleŋNXbhIǂmF +extern AuthResult SYSM_AuthenticateTitle( TitleProperty *pBootTitle ); // w肵TitlePropertyF؂ău[g + // ́Anever return. +// foCX +extern void SYSM_CaribrateTP( void ); // ^b`plLu[V +extern void SYSM_SetBackLightBrightness( u8 brightness ); // obNCg𐧌i{̐ݒf[^ւ̒lZ[usj + +// NintendoS +extern BOOL SYSM_CheckNintendoLogo( u16 *pLogoData ); // NintendoSf[^̃`FbN +extern void SYSM_LoadNintendoLogo2D( u16 *pLogoData, u16 *pDst, int paletteColorIndex ); // NintendoSf[^OBJ_2D`Ń[hipTempBufferɂ0x700bytesKv) +extern void SYSM_LoadNintendoLogo1D( u16 *pLogoData, u16 *pDst, int paletteColorIndex ); // NintendoSf[^OBJ_1D`Ń[hij + +// RTC +extern BOOL SYSM_CheckRTCDate( RTCDate *pDate ); // t킩`FbN +extern BOOL SYSM_CheckRTCTime( RTCTime *pTime ); // 킩`FbN +extern s64 SYSM_CalcRTCOffset( RTCDate *pNewDate, RTCTime *pNewTime ); // RTCItZbgvZRTCւ̓t`FbNs +extern u32 SYSM_GetDayNum( u32 year, u32 month ); // w肳ꂽNE̓擾 +extern BOOL SYSM_IsLeapYear100( u32 year ); // w肳ꂽN邤Nׂ + +#endif + +// ԃ`FbN +extern BOOL SYSM_IsExistCard( void ); // TWL/NTRJ[hĂ邩HiAv͖F؏ԁj +extern BOOL SYSM_IsInspectCard( void ); // J[hĂ邩H +extern BOOL SYSM_IsTPReadable( void ); // TP[h”\H +extern BOOL SYSM_IsLogoDemoSkip( void ); // Sf΂ԂH +extern void SYSM_SetLogoDemoSkip( BOOL skip ); // Sf΂ԃtOݒ肷B +extern BOOL SYSM_IsValidTSD( void ); // TWLݒf[^͗LH +extern void SYSM_SetValidTSD( BOOL valid ); // TWLݒf[^̗L^tOݒ肷B +extern const LauncherParamBody *SYSM_GetLauncherParamBody( void ); // Zbgp[^̎擾 + + +#ifdef __cplusplus +} +#endif + +#endif // __SYSM_LIB_H__ diff --git a/include/sysmenu/sysmenu_lib/common/sysmenu_work.h b/include/sysmenu/sysmenu_lib/common/sysmenu_work.h new file mode 100644 index 00000000..a66fdd83 --- /dev/null +++ b/include/sysmenu/sysmenu_lib/common/sysmenu_work.h @@ -0,0 +1,180 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL + File: sysmenu_work.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$ + *---------------------------------------------------------------------------*/ + +#ifndef __SYSMENU_WORK_H__ +#define __SYSMENU_WORK_H__ + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// define data ------------------------------------ +#define TITLE_ID_LAUNCHER ( 0x000300074c4e4352LLU ) +#define CLONE_BOOT_MODE 1 +#define OTHER_BOOT_MODE 2 + + +// NAMTitleIDHiLoɕăANZXꍇɎgp +typedef struct TitleID_HiLo { + u8 Lo[ 4 ]; + u32 Hi; +}TitleID_HiLo; + + +//---------------------------------------------------------------------- +//@PXIR}h +//---------------------------------------------------------------------- +#define SYSMENU_PXI_FIFO_TAG PXI_FIFO_TAG_USER_0 + +typedef enum SYSMPXICommand { + SYSM_PXI_COMM_DISABLE_HOTSW = 1 +}SYSMPXICommand; + +//---------------------------------------------------------------------- +//@ROMG~[V +//---------------------------------------------------------------------- +#define ISD_ROM_EMULATION_INFO_SIZE 0x20 // ROMG~[Vf[^TCY +#define ISD_ROM_EMULATION_INFO_MAGIC_CODE 0x444c5754 // "TWLD"̕ + +// ISfobKROMG~[V +typedef struct ISD_RomEmuInfo { + // }WbNR[hiISD_ROM_EMULATION_INFO_MAGIC_CODĚŒlj + u32 magic_code; + // tO + u32 isEnableSlot1 : 1; + u32 isEnableSlot2 : 1; + u32 bootSlotNo : 2; + u32 isEnableExMainMemory : 1; + u32 isBootMachineSettings : 1; + u32 isBootSpecifiedNANDApp : 1; + u32 isForceNTRMode : 1; + u32 isForceBannerViewMode : 1; + u32 rsv_flags : 23; + // isBootSpecifiedNANDAppŋNAvTitleID + u64 titleID; + // \ + u8 rsv[ 0x10 ]; +}ISD_RomEmuInfo; + + +//---------------------------------------------------------------------- +//@SYSM[N +//---------------------------------------------------------------------- +// SYSML[N\ +typedef struct SYSM_work { + Relocate_Info romRelocateInfo[RELOCATE_INFO_NUM]; // ROMĔzuiarm9,arm7ꂼltdflxōő4j + struct { + struct { + vu32 isFatalError :1; // FATALG[ + vu32 isARM9Start :1; // ARM9X^[gtO + vu32 isHotStart :1; // Hot/ColdX^[g + vu32 isValidLauncherParam :1; // Zbgp[^L + vu32 isValidTSD :1; // NITROݒf[^tO + vu32 isLogoSkip :1; // SfXLbv + vu32 isOnDebugger :1; // fobK삩H + vu32 isExistCard :1; // LNTR/TWLJ[h݂邩H + vu32 isCardStateChanged :1; // J[hԍXVtO + vu32 isLoadSucceeded :1; // Av[hH + vu32 isCardBoot :1; // J[hu[gH + vu32 isBrokenHWNormalInfo :1; // HWm[}񂪔jĂB + vu32 isBrokenHWSecureInfo :1; // HWZLA񂪔jĂB + vu32 isResetRTC :1; // RTCZbg + vu16 isEnableHotSW :1; // }LH + vu16 isBusyHotSW :1; // }H +#ifdef DEBUG_USED_CARD_SLOT_B_ + vu32 isValidCardBanner :1; + vu32 is1stCardChecked :1; + vu32 rsv :14; +#else + vu32 rsv :16; +#endif + }common; + struct { + vu16 reqChangeHotSW :1; + vu16 nextHotSWStatus :1; + vu16 rsv:15; + }arm9; + struct { + vu16 rsv:16; + }arm7; + }flags; + + u16 cardHeaderCrc16; // J[hoɎZoROMwb_CRC16iARM9ŃRs[Ďgp鑤j + u16 cardHeaderCrc16_bak; // J[hoɎZoROMwb_CRC16iARM7CuŃ_CNgɏ鑤j + OSLockWord lockCardRsc; // J[h\[Xrp + OSLockWord lockHotSW; // J[h\[Xrp + int cloneBootMode; + u32 nCardID; // J[hID + u32 gameCommondParam; // NTR̃Q[R}hp[^(NTRROMwb_̃Q[R}hp[^ɏ㏑) + + LauncherParam launcherParam; + ISD_RomEmuInfo romEmuInfo; + + // NTR-IPL2̃KV[@ŏIIɂ͏Ǝv + BOOL enableCardNormalOnly; + u8 rtcStatus; +}SYSM_work; + +// NTRɂdlpKv̂郏[N +typedef struct SDKBootCheckInfo{ + u32 nCardID; // NORMALJ[hID // SDKł͂Ăۂ@ŏIIɂ̓`[łɃJ[hIDZbg + u32 sCardID; // SECUREJ[hID + u16 cardHeaderCrc16; // J[hwb_CRC16 + u16 cardSecureCrc16; // J[hSECURËCRC16 + s16 cardHeaderError; // J[hwb_G[ + s16 disableEncryptedCardData; // J[hSECURËÍf[^ + + u16 sysromCrc16; // VXeROMCRC16 + s16 enableCardNormalOnly; // J[hNORMAL[ĥݗL + s16 isOnDebugger; // fobKœ쒆 + s8 rtcError; // RTCG[ + u8 rtcStatus1; // RTCXe[^X1 + +}SDKBootCheckInfo; + + +//---------------------------------------------------------------------- +//@SYSML[N̈̃AhXl +//---------------------------------------------------------------------- +// SYSMZbgp[^AhX̎擾iCuBARM9SYSM_GetLauncherParamgpĉBj +#define SYSMi_GetLauncherParamAddr() ( (LauncherParam *)HW_PARAM_LAUNCH_PARAM ) + +// SYSML[N̎擾 +#define SYSMi_GetWork() ( (SYSM_work *)HW_RED_RESERVED ) + +// SDKu[g`FbNiAvNɃJ[hIDZbgKvBj +#define SYSMi_GetSDKBootCheckInfo() ( (SDKBootCheckInfo *)HW_BOOT_CHECK_INFO_BUF ) +#define SYSMi_GetSDKBootCheckInfoForNTR() ( (SDKBootCheckInfo *)0x027ffc00 ) + +// NANDt@[[hĂĂ}CRt[WX^l̎擾 +#define SYSMi_GetMCUFreeRegisterValue() ( *(vu8 *)HW_RESET_PARAMETER_BUF ) + +// J[hROMwb_[N̎擾 +#define SYSM_GetCardRomHeader() ( (ROM_Header_Short *)SYSM_CARD_ROM_HEADER_BUF ) + +#ifdef __cplusplus +} +#endif + +#endif // __SYSMENU_WORK_H__ + diff --git a/keys/dummy/rsa/private9_0.der b/keys/dummy/rsa/private9_0.der new file mode 100644 index 00000000..97d98781 Binary files /dev/null and b/keys/dummy/rsa/private9_0.der differ diff --git a/keys/dummy/rsa/private9_0.pem b/keys/dummy/rsa/private9_0.pem new file mode 100644 index 00000000..f6c6617b --- /dev/null +++ b/keys/dummy/rsa/private9_0.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQC3BwxSGFBaRoOE1TQkMjRoDjhU9nmydzl6m3kubdy0ZzxMb/fd +NLMyRvtsMjxjmrEKYImhPfRBtXH6TE2RW5izpxtgQ5rYqE02omHZwhIafpg4lhNT +ZWROD0904XelD2nIcn9TpRzXncjsRCc8dpHbTziJj3K8VchQuSywNLKP0wIDAQAB +AoGBAJTgwc/hgTL9mqupNYGf6OsfbgkGeJWHz5SA9QCkUtvYAb93cJpZ7M2f2ZH4 +BxFKWmpDfpBPMellK3JbMNllNX7DIxjBgXElomcyysQUf5l/cVCRaKoBg/dFQ0U7 +9TyD4BdmlE14LGgXYjd+MjQVrIhrDK4rOyJ2URdDoV1PZawxAkEA73mByR0z+/gJ +og03JIL46tS2dsO5mjCYvCdvaneBXuWlUYRc3zrJJrwX9FOm8NmUWKFKYOwg7Ylx +lptHcY4BSwJBAMOoXLS7FsXajXnzeR0Y5EIAo9+ZYmn9ylLe0u9iaL/RXV8S9w8P +NdHrpZRoddLb+LCFhVeY9SwiSAkR9ZjnHpkCQC5oAXqTqis92cAJh5IPv2Tia6mA +LEtw92gezDx5hBx7rBmr6MNphOl4sburKkKqJ1E1kFBP8eGWLOjelm2u8xkCQQCf +jHFcp5ugZ+IqahJ/Wcb405DOS0Pnbp9ICJA1ySfmE5JybwKscxjOP7zcUnqSIfKf +76GWlxKGlMXtL4n4z68xAkBJJWrZvuGe0ha2wF0NVLURVWXctwFgEStNfWQqD+PM +DwVE6dHERFSO0ZPrfiZVUl/onk6H2ILEfdkSNzs75FSM +-----END RSA PRIVATE KEY----- diff --git a/keys/dummy/rsa/private_HWInfo.der b/keys/dummy/rsa/private_HWInfo.der new file mode 100644 index 00000000..a78da43e Binary files /dev/null and b/keys/dummy/rsa/private_HWInfo.der differ diff --git a/keys/dummy/rsa/private_HWInfo.pem b/keys/dummy/rsa/private_HWInfo.pem new file mode 100644 index 00000000..a55c5740 --- /dev/null +++ b/keys/dummy/rsa/private_HWInfo.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQDlcyzdiJ14or13KZTuxvMyZCCVuVLZndVNtd1zhhqX0BQQgEb0 +LM75BQbkwlhwQgdecdSc6xZwaxSWCoRpKB2CzT6UgpPIC0XTiZwFsriu/o1T3E8d +g4r+8QDNqcD6PxcxhBamOKtcO4GgZzUkU2bttyVzg9YI9KZLPJlKyhsitQIDAQAB +AoGBAIIVGRODl1tEUEwVi/UPX+NqtrqLtbfgboS/HYyYM81rz2RHhXJ7UOAHBJB+ +yirilFDsEhDgivkzDBnAXq9LaeaiXHZQwuUTszXyRSOdnaYzWoJAdPd3GH96a/xs +0VLWUTrzs1CH/5k8sxT4erk5l07ouBx5r/CPyJO/X5pIy8XhAkEA96DaxiFfdvEj +xXo1wkBmZbOsg+/wFMZhn+Bhm5Mxhblcrba60DmMyWhdJy6jb/gysAWY8OHLR21t +wMxAFccbvQJBAO00/fW8fA92BCb4Jh1s9uiXQAPpd+LdnxhXrm9+5y//wLLAUtii +awVmIycAuYlJSVzGSeQjAIP6MIefMp9lVlkCQHtDsAN2c13y1Vqk5gPHKPGxScv3 +cSv2QHxkJlJaKAmn5rF2R3IFY8aSU+SAO80t4JVsg+BMlXL9zudtBO2SSoUCQANe +pFjwU4bYs1hmYAw89wj41RT5JRXY9iCfZj/5OomJBZDEgKjJLeIGwGsWbIxRuTQT +MQuHn8NAM55JmauAAgkCQQC4bqOlgAPVGaoAK98Kf40EKufyY2XaMSiGmqpG3bnw +o13x8SWrOh6Stu5jgFnyGcItJone3lLWo2xN1b6SzN84 +-----END RSA PRIVATE KEY----- diff --git a/keys/dummy/rsa/private_gcd.der b/keys/dummy/rsa/private_gcd.der new file mode 100644 index 00000000..91e7fe42 Binary files /dev/null and b/keys/dummy/rsa/private_gcd.der differ diff --git a/keys/dummy/rsa/private_nand.der b/keys/dummy/rsa/private_nand.der new file mode 100644 index 00000000..771e3bf3 Binary files /dev/null and b/keys/dummy/rsa/private_nand.der differ diff --git a/keys/dummy/rsa/private_nor.der b/keys/dummy/rsa/private_nor.der new file mode 100644 index 00000000..2f3aba7b Binary files /dev/null and b/keys/dummy/rsa/private_nor.der differ diff --git a/keys/dummy/rsa/pubKey_HWInfo.der b/keys/dummy/rsa/pubKey_HWInfo.der new file mode 100644 index 00000000..756072c8 Binary files /dev/null and b/keys/dummy/rsa/pubKey_HWInfo.der differ diff --git a/keys/dummy/rsa/pubkey9_0.der b/keys/dummy/rsa/pubkey9_0.der new file mode 100644 index 00000000..156e3a2f Binary files /dev/null and b/keys/dummy/rsa/pubkey9_0.der differ diff --git a/keys/dummy/rsa/pubkey9_0.pem b/keys/dummy/rsa/pubkey9_0.pem new file mode 100644 index 00000000..da0c94dc --- /dev/null +++ b/keys/dummy/rsa/pubkey9_0.pem @@ -0,0 +1,6 @@ +-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3BwxSGFBaRoOE1TQkMjRoDjhU +9nmydzl6m3kubdy0ZzxMb/fdNLMyRvtsMjxjmrEKYImhPfRBtXH6TE2RW5izpxtg +Q5rYqE02omHZwhIafpg4lhNTZWROD0904XelD2nIcn9TpRzXncjsRCc8dpHbTziJ +j3K8VchQuSywNLKP0wIDAQAB +-----END PUBLIC KEY----- diff --git a/keys/dummy/rsa/pubkey_HWInfo.pem b/keys/dummy/rsa/pubkey_HWInfo.pem new file mode 100644 index 00000000..e5a13ec2 --- /dev/null +++ b/keys/dummy/rsa/pubkey_HWInfo.pem @@ -0,0 +1,6 @@ +-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlcyzdiJ14or13KZTuxvMyZCCV +uVLZndVNtd1zhhqX0BQQgEb0LM75BQbkwlhwQgdecdSc6xZwaxSWCoRpKB2CzT6U +gpPIC0XTiZwFsriu/o1T3E8dg4r+8QDNqcD6PxcxhBamOKtcO4GgZzUkU2bttyVz +g9YI9KZLPJlKyhsitQIDAQAB +-----END PUBLIC KEY----- diff --git a/keys/dummy/rsa/pubkey_gcd.der b/keys/dummy/rsa/pubkey_gcd.der new file mode 100644 index 00000000..b9cc07d1 Binary files /dev/null and b/keys/dummy/rsa/pubkey_gcd.der differ diff --git a/keys/dummy/rsa/pubkey_nand.der b/keys/dummy/rsa/pubkey_nand.der new file mode 100644 index 00000000..cbd2740d Binary files /dev/null and b/keys/dummy/rsa/pubkey_nand.der differ diff --git a/keys/dummy/rsa/pubkey_nor.der b/keys/dummy/rsa/pubkey_nor.der new file mode 100644 index 00000000..3c3999eb Binary files /dev/null and b/keys/dummy/rsa/pubkey_nor.der differ diff --git a/keys/makeHWInfo.pl b/keys/makeHWInfo.pl new file mode 100755 index 00000000..9b7337b6 --- /dev/null +++ b/keys/makeHWInfo.pl @@ -0,0 +1,105 @@ +#!/bin/perl + +use strict; + + +if( @ARGV != 8 ) { + die "usage: makeHWInfo.pl -r -s -k -o \n"; +} + +#`FbN +my $cmd = &analyze_argv; + +if( !exists($cmd->{"-r"}) or + !exists($cmd->{"-s"}) or + !exists($cmd->{"-k"}) or + !exists($cmd->{"-o"}) ) { + die "parameter error.\n"; +} + + +#[W +my @regionNameList = qw/ JAPAN AMERICA EUROPE AUSTRALIA CHINA KOREA /; +my $i = 0; +my $region = 0xff; +foreach ( @regionNameList ) { + if( $cmd->{"-r"} eq $_ ) { + $region = $i; + last; + } + $i++; +} +if( $region == 0xff ) { + die "region error.\n", $cmd->{"-r"}; +} + + +#VANo. +my $serialNo = $cmd->{"-s"}; +if( !( 11 == length($serialNo) or ( 12 == length($serialNo) ) ) ) { + die "serialNo length error. needs length \"11\" or \"12\"\n"; +} + + +#Bodyt@C +open(OUT, ">body.bin"); +binmode(OUT); +print OUT pack( "C", $region ); +print OUT pack( "A16", $serialNo ); +close(OUT); + + +#Headert@C +my $version = 1; +my $length = 17; +open(OUT, ">header.bin"); +binmode(OUT); +print OUT pack( "C", $version ); +print OUT pack( "CCC", 0, 0, 0 ); +print OUT pack( "L", $length ); +close(OUT); + +#R\[o +print "[Header]\n"; +printf " version : %d\n", $version; +printf " length : %d\n", $length; +print "[Body]\n"; +printf " region : %d (%s)\n", $region, $regionNameList[$region]; +printf " serialNo : %s (%d)\n", $serialNo, length($serialNo); + +#RSA +my $key = $cmd->{"-k"}; +my $outName = $cmd->{"-o"}; +system "openssl dgst -sha1 -binary -out tgt.dgst body.bin"; +system "openssl rsautl -sign -in tgt.dgst -inkey $key -out tgt.sgn"; +system "cat tgt.sgn header.bin body.bin >$outName"; +system "rm header.bin body.bin tgt.dgst tgt.sgn"; + +exit; + + +sub analyze_argv +{ + my $opt; + my %cmd = (); + + foreach my $token ( @ARGV ) + { + if( substr($token, 0, 1) eq "-" ) + { + $opt = $token; + } + elsif( $opt ) + { + $cmd{$opt} = $token; + $opt = ""; + } + else + { + push @{$cmd{""}}, $token; + } + } + + return \%cmd; +} + diff --git a/readme.txt b/readme.txt new file mode 100644 index 00000000..7bf4b433 --- /dev/null +++ b/readme.txt @@ -0,0 +1,15 @@ +1.rhɕKvȂ +@NORt@[ANANDt@[ + ENitroSDK4.0ȍ~ + ETwlSDK +@VXej[ +@@ETwlSDK +@@ENitroSystem 070314({c[add-insTwlSDKΉpb`𓖂Ắj + + +2.‹ϐ̐ݒ +@TWLIPL_ROOT + ex.) TWLIPL_ROOT=c:/TwlIPL + TWL_KEYSDIRiu[gROMN”\ȃt@[쐬ꍇAtwl_firmware|Wgj + ex.) TWL_KEYSDIR=c:/twl_firmware/bootrom/build/keys + diff --git a/setup b/setup new file mode 100644 index 00000000..579560c9 --- /dev/null +++ b/setup @@ -0,0 +1,8 @@ +#!/usr/bin/bash + +#---------------------------------------------------------------- +# This script is not for execute directly. +# Please use 'source ./setup'. +#---------------------------------------------------------------- + +export TWL_IPL_RED_ROOT=`cygpath -m $PWD` diff --git a/tools/bin/TXLib.dll b/tools/bin/TXLib.dll new file mode 100644 index 00000000..7e1dc0bd Binary files /dev/null and b/tools/bin/TXLib.dll differ diff --git a/tools/bin/makebanner.exe b/tools/bin/makebanner.exe new file mode 100644 index 00000000..fd580a2c Binary files /dev/null and b/tools/bin/makebanner.exe differ diff --git a/tools/openssl/openssl.exe b/tools/openssl/openssl.exe new file mode 100644 index 00000000..8967c316 Binary files /dev/null and b/tools/openssl/openssl.exe differ