diff --git a/.travis.yml b/.travis.yml index bcfc0b0..e7df730 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,11 @@ install: - sudo perl devkitARMupdate.pl script: - - make + - make gateway + - mv output/Launcher.dat . + - make clean + - make bootstrap + - mv output/Decrypt9.bin . env: global: @@ -18,9 +22,19 @@ env: after_success: - > if [ "$TRAVIS_BRANCH" == "master" ]; then + GITDATE="`git show -s --date=short --format='%ad' | sed 's/-//g'`" + GITREV="`git show -s --format='%h'`" + REV_NAME_GW="decrypt9-${GITDATE}-${GITREV}-browser" + REV_NAME_BS="decrypt9-${GITDATE}-${GITREV}-bootstrap" + sudo apt-get -qq install lftp p7zip-full - ARCHIVE_NAME="`git show -s --format='%h-%f' | cut -c1-111`.7z" - 7z a archive README.md Launcher.dat scripts/*.py - mv archive.7z "$ARCHIVE_NAME" - lftp -c "open -u builds,$BUILD_PASSWORD sftp://archshift.com; put -O '/decrypt9/nightly/' '$ARCHIVE_NAME'" + mkdir "$REV_NAME_GW" "$REV_NAME_BS" + + cp -R README.md Launcher.dat scripts "$REV_NAME_GW" + cp -R README.md Decrypt9.bin scripts "$REV_NAME_BS" + 7z a "$REV_NAME_GW" "$REV_NAME_GW/*" + 7z a "$REV_NAME_BS" "$REV_NAME_BS/*" + + lftp -c "open -u builds,$BUILD_PASSWORD sftp://archshift.com; put -O '/decrypt9/nightly/browser' '${REV_NAME_GW}.7z'" + lftp -c "open -u builds,$BUILD_PASSWORD sftp://archshift.com; put -O '/decrypt9/nightly/bootstrap' '${REV_NAME_BS}.7z'" fi diff --git a/Makefile b/Makefile index 6c979a4..ddb2586 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ include $(DEVKITARM)/ds_rules #--------------------------------------------------------------------------------- export TARGET := $(shell basename $(CURDIR)) BUILD := build -SOURCES := source source/fatfs source/decryptor +SOURCES := source source/fatfs source/decryptor source/abstraction DATA := data INCLUDES := include source source/fatfs @@ -36,28 +36,34 @@ CFLAGS := -g -Wall -O2\ -ffast-math -std=c99\ $(ARCH) -CFLAGS += $(INCLUDE) -DARM9 +CFLAGS += $(INCLUDE) -DEXEC_$(EXEC_METHOD) -DARM9 CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -ASFLAGS := -g $(ARCH) -LDFLAGS = -nostartfiles -g --specs=../stub.specs $(ARCH) -Wl,-Map,$(TARGET).map +ASFLAGS := -g $(ARCH) -DEXEC_$(EXEC_METHOD) +LDFLAGS = -nostartfiles -g $(ARCH) -Wl,-Map,$(TARGET).map -LIBS := +ifeq ($(EXEC_METHOD),GATEWAY) + LDFLAGS += --specs=../gateway.specs +else ifeq ($(EXEC_METHOD),BOOTSTRAP) + LDFLAGS += --specs=../bootstrap.specs +endif + +LIBS := #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- LIBDIRS := - + #--------------------------------------------------------------------------------- # no real need to edit anything past this point unless you need to add additional # rules for different file extensions #--------------------------------------------------------------------------------- ifneq ($(BUILD),$(notdir $(CURDIR))) #--------------------------------------------------------------------------------- - + export OUTPUT_D := $(CURDIR)/output export OUTPUT := $(OUTPUT_D)/$(TARGET) @@ -94,31 +100,35 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) -.PHONY: $(BUILD) clean all - +.PHONY: $(BUILD) clean all gateway bootstrap + #--------------------------------------------------------------------------------- -all: $(OUTPUT_D) $(BUILD) +all: $(OUTPUT_D) gateway $(OUTPUT_D): @[ -d $@ ] || mkdir -p $@ -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile +gateway: $(OUTPUT_D) + @[ -d $(BUILD) ] || mkdir -p $(BUILD) + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile EXEC_METHOD=GATEWAY cp tools/LauncherTemplate.dat $(OUTPUT_D)/Launcher.dat python tools/insert.py $(OUTPUT_D)/Launcher.dat $(OUTPUT).bin 0x16D8D0 - + +bootstrap: $(OUTPUT_D) + @[ -d $(BUILD) ] || mkdir -p $(BUILD) + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile EXEC_METHOD=BOOTSTRAP + #--------------------------------------------------------------------------------- clean: @echo clean ... @rm -fr $(BUILD) $(OUTPUT_D) - - + + #--------------------------------------------------------------------------------- else - + DEPENDS := $(OFILES:.o=.d) - + #--------------------------------------------------------------------------------- # main targets #--------------------------------------------------------------------------------- @@ -130,11 +140,11 @@ $(OUTPUT).elf : $(OFILES) %.bin: %.elf @$(OBJCOPY) -O binary $< $@ @echo built ... $(notdir $@) - + -include $(DEPENDS) - + #--------------------------------------------------------------------------------------- endif #--------------------------------------------------------------------------------------- diff --git a/README.md b/README.md index 60736bf..7fce32e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ## Generating xorpads for encrypted files -First build by running `make` in the project root. +First build by running `make` in the project root. By default, it will build the browser version of Decrypt9. If you'd like to build for use with brahma or bootstrap, run `make bootstrap` instead. ### Decrypting gamecart dumps diff --git a/stub.ld b/bootstrap.ld similarity index 71% rename from stub.ld rename to bootstrap.ld index c10c050..21d6f08 100644 --- a/stub.ld +++ b/bootstrap.ld @@ -14,7 +14,7 @@ SECTIONS __text_start = . ; KEEP (*(.init)) . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >ram = 0xff + } >ram = 0xff .plt : { *(.plt) } >ram = 0xff .text : /* ALIGN (4): */ @@ -126,39 +126,5 @@ SECTIONS __end__ = ABSOLUTE(.); } >ram - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } .stack 0x80000 : { _stack = .; *(.stack) } - /* These must appear regardless of . */ -} \ No newline at end of file +} diff --git a/bootstrap.specs b/bootstrap.specs new file mode 100644 index 0000000..0a18b74 --- /dev/null +++ b/bootstrap.specs @@ -0,0 +1,5 @@ +%rename link old_link + +*link: +%(old_link) -T ../bootstrap.ld%s + diff --git a/gateway.ld b/gateway.ld new file mode 100644 index 0000000..aff0a18 --- /dev/null +++ b/gateway.ld @@ -0,0 +1,130 @@ +OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") +OUTPUT_ARCH(arm) +ENTRY(_start) + +MEMORY + { + ram : ORIGIN = 0x08000000, LENGTH = 128K + } + +SECTIONS +{ + .init : + { + __text_start = . ; + KEEP (*(.init)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ram = 0xff + .plt : { *(.plt) } >ram = 0xff + + .text : /* ALIGN (4): */ + { + *(.text .stub .text.* .gnu.linkonce.t.*) + KEEP (*(.text.*personality*)) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.glue_7t) *(.glue_7) *(.vfp11_veneer) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ram = 0xff + + .fini : + { + KEEP (*(.fini)) + } >ram =0xff + + __text_end = . ; + + .rodata : + { + *(.rodata) + *all.rodata*(*) + *(.roda) + *(.rodata.*) + *(.gnu.linkonce.r*) + SORT(CONSTRUCTORS) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ram = 0xff + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >ram + __exidx_start = .; + .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >ram + __exidx_end = .; + +/* Ensure the __preinit_array_start label is properly aligned. We + could instead move the label definition inside the section, but + the linker would then create the section even if it turns out to + be empty, which isn't pretty. */ + . = ALIGN(32 / 8); + PROVIDE (__preinit_array_start = .); + .preinit_array : { KEEP (*(.preinit_array)) } >ram = 0xff + PROVIDE (__preinit_array_end = .); + PROVIDE (__init_array_start = .); + .init_array : { KEEP (*(.init_array)) } >ram = 0xff + PROVIDE (__init_array_end = .); + PROVIDE (__fini_array_start = .); + .fini_array : { KEEP (*(.fini_array)) } >ram = 0xff + PROVIDE (__fini_array_end = .); + + .ctors : + { + /* gcc uses crtbegin.o to find the start of the constructors, so + we make sure it is first. Because this is a wildcard, it + doesn't matter if the user does not actually link against + crtbegin.o; the linker won't look for a file to match a + wildcard. The wildcard also means that it doesn't matter which + directory crtbegin.o is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ram = 0xff + + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ram = 0xff + + .eh_frame : + { + KEEP (*(.eh_frame)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ram = 0xff + + .gcc_except_table : + { + *(.gcc_except_table) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ram = 0xff + .jcr : { KEEP (*(.jcr)) } >ram = 0 + .got : { *(.got.plt) *(.got) } >ram = 0 + + .data ALIGN(4) : { + __data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d*) + CONSTRUCTORS + . = ALIGN(4); + __data_end = ABSOLUTE(.) ; + } >ram = 0xff + + .bss ALIGN(4) : + { + __bss_start = ABSOLUTE(.); + __bss_start__ = ABSOLUTE(.); + *(.dynbss) + *(.gnu.linkonce.b*) + *(.bss*) + *(COMMON) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + __bss_end__ = ABSOLUTE(.); + __end__ = ABSOLUTE(.); + } >ram + + .stack 0x80000 : { _stack = .; *(.stack) } +} diff --git a/stub.specs b/gateway.specs similarity index 59% rename from stub.specs rename to gateway.specs index b6c2098..ff32c30 100644 --- a/stub.specs +++ b/gateway.specs @@ -1,5 +1,5 @@ %rename link old_link *link: -%(old_link) -T ../stub.ld%s +%(old_link) -T ../gateway.ld%s diff --git a/source/start.s b/source/abstraction/bs-start.s similarity index 98% rename from source/start.s rename to source/abstraction/bs-start.s index cfbfba4..2cfb33e 100644 --- a/source/start.s +++ b/source/abstraction/bs-start.s @@ -1,3 +1,5 @@ +#ifdef EXEC_BOOTSTRAP + .section ".init" .global _start .extern main @@ -100,3 +102,5 @@ _init: @ return control to FIRM ldr pc, arm9ep_backup + +#endif // EXEC_BOOTSTRAP diff --git a/source/abstraction/gw-start.s b/source/abstraction/gw-start.s new file mode 100644 index 0000000..1bd04ae --- /dev/null +++ b/source/abstraction/gw-start.s @@ -0,0 +1,51 @@ +#ifdef EXEC_GATEWAY + +.section ".init" + +.global _start +.extern main + +.align 4 +.arm + +_vectors: + ldr pc, =InfiniteLoop + .pool + ldr pc, =InfiniteLoop + .pool + ldr pc, =InfiniteLoop + .pool + ldr pc, =InfiniteLoop + .pool + ldr pc, =InfiniteLoop + .pool + ldr pc, =InfiniteLoop + .pool + +_start: + ldr sp,=0x22140000 + + @@wait for the arm11 kernel threads to be ready + ldr r1, =0x10000 + waitLoop9: + sub r1, #1 + + cmp r1, #0 + bgt waitLoop9 + + ldr r1, =0x10000 + waitLoop92: + sub r1, #1 + + cmp r1, #0 + bgt waitLoop92 + + ldr sp,=0x22160000 + ldr r3, =main + blx r3 +.pool + +InfiniteLoop: + b InfiniteLoop + +#endif // EXEC_GATEWAY diff --git a/source/draw.h b/source/draw.h index cdef3cd..6cfdd1c 100644 --- a/source/draw.h +++ b/source/draw.h @@ -14,10 +14,19 @@ #define RGB(r,g,b) (r<<24|b<<16|g<<8|r) -#define TOP_SCREEN0 (u8*)(0x20000000) -#define TOP_SCREEN1 (u8*)(0x20046500) -#define BOT_SCREEN0 (u8*)(0x2008CA00) -#define BOT_SCREEN1 (u8*)(0x200C4E00) +#ifdef EXEC_GATEWAY + #define TOP_SCREEN0 (u8*)(*(u32*)((uint32_t)0x080FFFC0 + 4 * (*(u32*)0x080FFFD8 & 1))) + #define BOT_SCREEN0 (u8*)(*(u32*)0x080FFFD4) + #define TOP_SCREEN1 TOP_SCREEN0 + #define BOT_SCREEN1 BOT_SCREEN0 +#elif defined(EXEC_BOOTSTRAP) + #define TOP_SCREEN0 (u8*)(0x20000000) + #define TOP_SCREEN1 (u8*)(0x20046500) + #define BOT_SCREEN0 (u8*)(0x2008CA00) + #define BOT_SCREEN1 (u8*)(0x200C4E00) +#else + #error "Unknown execution method" +#endif void ClearScreen(unsigned char *screen, int color); void DrawCharacter(unsigned char *screen, int character, int x, int y, int color, int bgcolor); diff --git a/source/fs.c b/source/fs.c index d9ac134..aa0428f 100644 --- a/source/fs.c +++ b/source/fs.c @@ -7,8 +7,11 @@ static FIL file; bool InitFS() { +#ifndef EXEC_GATEWAY + // TODO: Magic? *(u32*)0x10000020 = 0; *(u32*)0x10000020 = 0x340; +#endif return f_mount(&fs, "0:", 0) == FR_OK; }