rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
-# Only cygwin is maybe working on windows.
-PATH := $(PATH):$(DEVKITARM)/bin
-
-CROSS_CC := arm-none-eabi-gcc
-CROSS_AS := arm-none-eabi-as
-CROSS_LD := arm-none-eabi-ld
-CROSS_OC := arm-none-eabi-objcopy
-
-CC ?= gcc
-AS ?= as
-LD ?= ld
-OC ?= objcopy
-
-fw_name ?= Corbenik
-
-# If unset, the primary folder is /corbenik.
-fw_folder ?= corbenik
-
-# Other valid options:
-# shadowhand
-# cruel
-root ?= clusterfuck
-
-ifeq "$(root)" "clusterfuck"
- PATHARGS := -DPATH_ROOT=\"\"
- PATHARGS += -DPATH_DATA=\"/$(fw_folder)\"
-else ifeq "$(root)" "cruel"
- PATHARGS := -DPATH_ROOT=\"/3ds/apps\"
- PATHARGS += -DPATH_DATA=\"/3ds/appdata/$(fw_folder)\"
-else ifeq "$(root)" "shadowhand"
- PATHARGS := -DPATH_ROOT=\"/homebrew/3ds\"
- PATHARGS += -DPATH_DATA=\"/homebrew/3ds/$(fw_folder)\"
-endif
-
-dir_source := source
-dir_data := data
-dir_build := build
-dir_out := out
-
-REVISION := $(shell git rev-parse HEAD | head -c10)+$(shell git rev-list --count HEAD)
-REL ?= master
-
-# Default to enabling chainloader.
-CHAINLOADER ?= 1
-
-CROSS_ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te
-CROSS_CFLAGS := -MMD -MP -Wall -Wextra -Werror -fomit-frame-pointer -I$(shell pwd)/external/libctr9/out/include -Os $(ASFLAGS) -fshort-wchar -fno-builtin -std=gnu11 -DVERSION=\"$(REVISION)\" -DREL=\"$(REL)\" -DCHAINLOADER=$(CHAINLOADER) -DPATH_CFW=\"/$(fw_folder)\" -DFW_NAME=\"$(fw_name)\" $(PATHARGS)
-CROSS_FLAGS := dir_out=$(abspath $(dir_out)) --no-print-directory
-CROSS_LDFLAGS := -nostdlib -Wl,-z,defs -lgcc -Wl,-Map,$(dir_build)/link.map -L$(shell pwd)/external/libctr9/out/lib -lctr9
-
-objects_cfw = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
- $(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
+include common.mk
+
+objects_cfw = $(patsubst %.s, %.o, \
+ $(patsubst %.c, %.o, \
$(call rwildcard, $(dir_source), *.s *.c)))
.PHONY: all
make -C patch dir_out=$(dir_out) fw_name=$(fw_name) fw_folder=$(fw_folder) root=$(root)
.PHONY: a9lh
-a9lh: $(dir_out)/arm9loaderhax.bin
+a9lh: $(dir_out)/main.bin
mkdir -p $(dir_out)/$(fw_folder)/bits
.PHONY: reformat
.PHONY: clean
clean:
- rm -f host/{font-emit,font.h,font_prop.h,termfont.bin}
+ rm -f $(objects_cfw)
cd external/libctr9 && git clean -fxd
make -C external dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) clean
make -C patch dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) clean
make -C host/bdfe dir_out=$(dir_out) fw_folder=$(fw_folder) root=$(root) clean
rm -rf $(dir_out) $(dir_build)
-.PHONY: $(dir_out)/arm9loaderhax.bin
-$(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin
- @mkdir -p "$(dir_out)"
- @cp -av $< $@
-
-$(dir_build)/main.bin: $(dir_build)/main.elf
- $(CROSS_OC) $(CROSS_OCFLAGS) -S -O binary $< $@
-
-$(dir_build)/main.elf: $(objects_cfw)
- $(CROSS_CC) -T linker.ld $(OUTPUT_OPTION) $^ $(CROSS_LDFLAGS)
-
-$(dir_build)/%.o: $(dir_source)/%.c
- @mkdir -p "$(@D)"
- $(CROSS_CC) $(CROSS_CFLAGS) -c $(OUTPUT_OPTION) $<
-
-$(dir_build)/%.o: $(dir_source)/%.s
- @mkdir -p "$(@D)"
- $(CROSS_AS) $(CROSS_ASFLAGS) -c $(OUTPUT_OPTION) $<
-
-$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.c
- @mkdir -p "$(@D)"
- $(CROSS_CC) $(CROSS_CFLAGS) -c -Wno-unused-function $(OUTPUT_OPTION) $<
-
-$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.s
- @mkdir -p "$(@D)"
- $(CROSS_AS) $(CROSS_ASFLAGS) -c $(OUTPUT_OPTION) $<
-
-$(dir_build)/std/%.o: $(dir_source)/std/%.c
- @mkdir -p "$(@D)"
- $(CROSS_CC) $(CROSS_CFLAGS) -c -Wno-unused-function $(OUTPUT_OPTION) $<
-
-$(dir_build)/std/%.o: $(dir_source)/std/%.s
- @mkdir -p "$(@D)"
- $(CROSS_AS) $(CROSS_ASFLAGS) -c $(OUTPUT_OPTION) $<
-
-$(dir_build)/firm/%.o: $(dir_source)/firm/%.c
- @mkdir -p "$(@D)"
- $(CROSS_CC) $(CROSS_CFLAGS) -c -Wno-unused-function $(OUTPUT_OPTION) $<
-
-$(dir_build)/firm/%.o: $(dir_source)/firm/%.s
- @mkdir -p "$(@D)"
- $(CROSS_AS) $(CROSS_ASFLAGS) -c $(OUTPUT_OPTION) $<
-
-$(dir_build)/patch/%.o: $(dir_source)/patch/%.c
- @mkdir -p "$(@D)"
- $(CROSS_CC) $(CROSS_CFLAGS) -c -Wno-unused-function $(OUTPUT_OPTION) $<
+out/main.bin: out/main.elf
+ $(OC) $(OCFLAGS) -S -O binary $< $@
-$(dir_build)/patch/%.o: $(dir_source)/patch/%.s
- @mkdir -p "$(@D)"
- $(CROSS_AS) $(CROSS_ASFLAGS) -c $(OUTPUT_OPTION) $<
+out/main.elf: $(objects_cfw)
+ $(CC) $(LDFLAGS) -T linker.ld -o $@ $<
-$(dir_build)/misc/%.o: $(dir_source)/misc/%.c
- @mkdir -p "$(@D)"
- $(CROSS_CC) $(CROSS_CFLAGS) -c -Wno-unused-function $(OUTPUT_OPTION) $<
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+%.o: %.s
+ $(AS) $(ASFLAGS) -c -o $@ $<
include $(call rwildcard, $(dir_build), *.d)
--- /dev/null
+include common.mk
+
+corbenik_SOURCES = aes.c ctr_nand_crypto_interface.c ctr_sd_interface.c sha.c \
+ ctr_io_interface.c ctr_nand_interface.c sdmmc/delay.s sdmmc/sdmmc.c i2c.c \
+ ctr_rtc.c fatfs/diskio.c fatfs/ff.c fatfs/option/unicode.c ctr_system.c \
+ ctr_fatfs_interface.c fatfs/ctr_fatfs_disk.c ctr_disks.c \
+ fatfs/ctr_fatfs_disk.c ctr_fatfs.c ctr_interrupt.c ctr_system_ARM.c \
+ ctr_interrupt_asm.s ctr_screen.c ctr_hid.c ctr_pxi.c gamecart/command_ctr.c\
+ gamecart/command_ntr.c gamecart/protocol.c gamecart/protocol_ctr.c \
+ gamecart/protocol_ntr.c ctr_cart_interface.c gamecart/delay.s ctr_headers.c \
+ ctr_timer.c ctr_irq.c ctr_system_clock.c
+
+
+includedirectory = include
+
+corbenik_HEADERS = $(includedirectory)/
--- /dev/null
+INCPATHS=-I$(top_srcdir)/include
+C9FLAGS=-mcpu=arm946e-s -march=armv5te -mlittle-endian -mword-relocations
+
+SIZE_OPTIMIZATION = -Wl,--gc-sections -ffunction-sections
+
+CFLAGS= -std=gnu11 -O2 -g -fomit-frame-pointer -ffast-math \
+ -Wpedantic -Wall -Wextra -Wcast-align -Wcast-qual \
+ -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op \
+ -Wmissing-declarations -Wmissing-include-dirs -Wredundant-decls \
+ -Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wswitch-default \
+ -Wundef -Wno-unused $(THUMBFLAGS) $(SIZE_OPTIMIZATION) $(INCPATHS) $(C9FLAGS) \
+ -I$(shell pwd)/external/libctr9/out/include -I$(shell pwd)/include -Os $(ASFLAGS) \
+ -fshort-wchar -fno-builtin -std=gnu11 -DVERSION=\"$(REVISION)\" -DREL=\"$(REL)\" \
+ -DCHAINLOADER=$(CHAINLOADER) -DPATH_CFW=\"/$(fw_folder)\" -DFW_NAME=\"$(fw_name)\" \
+ $(PATHARGS)
+
+
+LDFLAGS=-Wl,--use-blx,--pic-veneer,-q -nostdlib -Wl,-z,defs -lgcc \
+ -Wl,-Map,$(dir_out)/link.map -L$(shell pwd)/external/libctr9/out/lib -lctr9
+
+OCFLAGS=--set-section-flags .bss=alloc,load,contents
+
+# Only cygwin is maybe working on windows.
+PATH := $(PATH):$(DEVKITARM)/bin
+
+CC := arm-none-eabi-gcc
+AS := arm-none-eabi-as
+LD := arm-none-eabi-ld
+OC := arm-none-eabi-objcopy
+
+BUILD_CC ?= gcc
+BUILD_AS ?= as
+BUILD_LD ?= ld
+BUILD_OC ?= objcopy
+
+fw_name ?= Corbenik
+
+# If unset, the primary folder is /corbenik.
+fw_folder ?= corbenik
+
+# Other valid options:
+# shadowhand
+# cruel
+root ?= clusterfuck
+
+ifeq "$(root)" "clusterfuck"
+ PATHARGS := -DPATH_ROOT=\"\"
+ PATHARGS += -DPATH_DATA=\"/$(fw_folder)\"
+else ifeq "$(root)" "cruel"
+ PATHARGS := -DPATH_ROOT=\"/3ds/apps\"
+ PATHARGS += -DPATH_DATA=\"/3ds/appdata/$(fw_folder)\"
+else ifeq "$(root)" "shadowhand"
+ PATHARGS := -DPATH_ROOT=\"/homebrew/3ds\"
+ PATHARGS += -DPATH_DATA=\"/homebrew/3ds/$(fw_folder)\"
+endif
+
+dir_source := source
+dir_data := data
+dir_build := build
+dir_out := out
+
+REVISION := $(shell git rev-parse HEAD | head -c10)+$(shell git rev-list --count HEAD)
+REL ?= master
+
+# Default to enabling chainloader.
+CHAINLOADER ?= 1
+
--- /dev/null
+AC_INIT([libctr9], [0.0.1], [], [])
+AM_INIT_AUTOMAKE([foreign no-dist-gzip dist-xz subdir-objects])
+
+#Find AR and RANLIB for lto support before initializing libtool
+AC_CHECK_TOOL([AR],gcc-ar)
+AC_CHECK_TOOL([RANLIB],gcc-ranlib)
+LT_INIT
+
+AC_PROG_CC
+AM_PROG_AS
+AC_CHECK_TOOL([OBJCOPY],objcopy)
+
+AC_CONFIG_FILES([Makefile src/Makefile test/Makefile examples/Makefile])
+
+AC_OUTPUT
cp -r out/* $mnt/ || exit 0
cp -r input/* $mnt/ || exit 0
cp out/arm9loaderhax.bin $mnt/corbenik/chain/Corbenik || exit 0
+cp out/arm9loaderhax.bin $mnt/arm9loaderhax_si.bin || exit 0
+rm -f $mnt/arm9loaderhax.bin || exit 0
umount $mnt || exit 0
sync || exit 0
eject ${dev} || exit 0
--- /dev/null
+#ifndef __COMMON_H
+#define __COMMON_H
+
+#include "std/types.h"
+#include "std/draw.h"
+#include "std/fs.h"
+#include "std/memory.h"
+#include "std/abort.h"
+#include "std/unused.h"
+
+#include "firm/fcram.h"
+#include "firm/headers.h"
+
+#include "patch_format.h"
+#include "config.h"
+#include "input.h"
+#include "patcher.h"
+
+#endif
+
+#include
+<patch/emunand.h>
+#include
+<patch/patch_file.h>
+#include
+<std/memory.h>
+#include
+<std/draw.h>
+#include
+<std/abort.h>
+#include
+<std/types.h>
+#include
+<std/fs.h>
+#include
+<std/unused.h>
+#include
+<firm/decryptor.h>
+#include
+<firm/headers.h>
+#include
+<firm/firm.h>
+#include
+<firm/fcram.h>
+#include
+<screeninit.h>
+#include
+<interrupt.h>
+#include
+<config.h>
+#include
+<input.h>
+#include
+<interp.h>
+#include
+<patch_format.h>
+#include <common.h>
+#include <patcher.h>
#if defined(CHAINLOADER) && CHAINLOADER == 1
-#include "common.h"
-#include "screeninit.h"
-#include "firm/firm.h"
-#include "firm/headers.h"
+#include <common.h>
+#include <screeninit.h>
+#include <firm/firm.h>
+#include <firm/headers.h>
uint32_t current_chain_index = 0;
+++ /dev/null
-#ifndef __COMMON_H
-#define __COMMON_H
-
-#include "std/types.h"
-#include "std/draw.h"
-#include "std/fs.h"
-#include "std/memory.h"
-#include "std/abort.h"
-#include "std/unused.h"
-
-#include "firm/fcram.h"
-#include "firm/headers.h"
-
-#include "patch_format.h"
-#include "config.h"
-#include "input.h"
-#include "patcher.h"
-
-#endif
-#include "common.h"
+#include <common.h>
FILE *conf_handle;
-#include "common.h"
-#include "firm/firm.h"
-#include "firm/headers.h"
+#include <common.h>
void header(char *append);
This is all fairly minimal and based on @d0k3's decrypt9 code.
*/
-#include "../std/memory.h"
+#include <common.h>
#include <ctr9/aes.h>
#include <ctr9/sha.h>
-#include "firm.h"
-#include "decryptor.h"
-
void
ncch_getctr(const ncch_h *ncch, uint8_t *ctr, uint8_t type)
{
while (rbc) {
if (wbc && ((*REG_AESCNT & 0x1F) <= 0xC)) // There's space for at least 4 ints
{
- *REG_AESWRFIFO = *src32++;
- *REG_AESWRFIFO = *src32++;
- *REG_AESWRFIFO = *src32++;
- *REG_AESWRFIFO = *src32++;
+ for(int i=0; i < 4; i++)
+ *REG_AESWRFIFO = *src32++;
wbc--;
}
if (rbc && ((*REG_AESCNT & (0x1F << 0x5)) >= (0x4 << 0x5))) // At least 4 ints available for read
{
- *dst32++ = *REG_AESRDFIFO;
- *dst32++ = *REG_AESRDFIFO;
- *dst32++ = *REG_AESRDFIFO;
- *dst32++ = *REG_AESRDFIFO;
+ for(int i=0; i < 4; i++)
+ *dst32++ = *REG_AESRDFIFO;
rbc--;
}
}
-#include "fcram.h"
+#include <common.h>
void *fcram_temp = (void *)0x23000000;
-#include "firm.h"
-
#include <stdint.h>
#include <stddef.h>
#include <ctr9/io.h>
#include <ctr9/aes.h>
#include <ctr9/sha.h>
-
-#include "../common.h"
-#include <ctr9/io.h>
-
-#include "decryptor.h"
+#include <common.h>
firm_h *firm_loc = (firm_h *)FCRAM_FIRM_LOC;
uint32_t firm_size = FCRAM_SPACING;
-#include "firm.h"
-#include "../common.h"
+#include <common.h>
// We use the firm's section 0's hash to identify the version
struct firm_signature firm_signatures[] = {
#include <stdint.h>
-#include "std/unused.h"
-#include "std/draw.h"
-#include "input.h"
+#include <common.h>
extern void waitcycles(uint32_t cycles);
#include "std/unused.h"
#ifndef LOADER
- #include "std/memory.h"
- #include "firm/firm.h"
- #include "config.h"
- #include "common.h"
- #include "firm/fcram.h"
+ #include <common.h>
#else
#include <string.h>
#endif
-#include "common.h"
+#include <common.h>
#include <ctr9/ctr_interrupt.h>
+#include <ctr9/ctr_irq.h>
void dump_state_printf(uint32_t* regs) {
fprintf(stderr, " cpsr:%x sp:%x lr:%x\n"
abort("Cannot continue. Halting.\n");
}
-void irq_INT(_UNUSED uint32_t* regs) {
- fprintf(stderr, "IRQ called. Returning.\n");
-}
-
void fiq_INT(_UNUSED uint32_t* regs) {
fprintf(stderr, "FIQ called. Returning.\n");
}
void install_interrupts() {
ctr_interrupt_prepare();
+ ctr_irq_initialize();
ctr_interrupt_set(CTR_INTERRUPT_RESET, reset_INT);
ctr_interrupt_set(CTR_INTERRUPT_UNDEF, undef_INT);
ctr_interrupt_set(CTR_INTERRUPT_SWI, swi_INT);
ctr_interrupt_set(CTR_INTERRUPT_PREABRT, preabrt_INT);
ctr_interrupt_set(CTR_INTERRUPT_DATABRT, databrt_INT);
- ctr_interrupt_set(CTR_INTERRUPT_IRQ, irq_INT);
ctr_interrupt_set(CTR_INTERRUPT_FIQ, fiq_INT);
}
#include <ctr9/ctr_hid.h>
-#include "common.h"
-#include "firm/firm.h"
-#include "input.h"
-#include "config.h"
-#include "screeninit.h"
-#include "std/abort.h"
-#include "interrupt.h"
+#include <common.h>
int is_n3ds = 0;
int doing_autoboot = 0;
-#include "common.h"
-#include "firm/firm.h"
-#include "firm/headers.h"
-#include "std/unused.h"
-
+#include <common.h>
#include <ctr9/ctr_system.h>
#define MAX_PATCHES ((FCRAM_SPACING / 2) / sizeof(struct options_s))
* emunand.c
*/
-#include "emunand.h"
-#include "../std/memory.h"
-#include "../std/draw.h"
-#include "../std/fs.h"
-#include "../std/abort.h"
-#include "../firm/firm.h"
-#include "../firm/fcram.h"
#include <ctr9/io.h>
-#include "../firm/headers.h"
-#include "../patch_format.h"
-#include "../config.h"
+#include <common.h>
uint8_t *emunand_temp = (uint8_t *)FCRAM_JUNK_LOC;
-#include "patch_file.h"
+#include <common.h>
/* Not possible to be implemented as bytecode. Hey, can't win em all. */
-#include "emunand.h"
-#include "../std/memory.h"
-#include "../std/draw.h"
-#include "../std/fs.h"
-#include "../std/abort.h"
-#include "../firm/firm.h"
-#include "../firm/fcram.h"
+#include <common.h>
#include <ctr9/io.h>
-#include "../firm/headers.h"
-#include "../patch_format.h"
int wait();
-#include "patch_file.h"
+#include <common.h>
uint8_t *arm11Section1 = NULL;
uint32_t *svc_tab_open = NULL, *exceptionsPage = NULL, *svcTable = NULL;
+#include <common.h>
#include <stdint.h>
-#include "std/unused.h"
-#include "std/memory.h"
-#include "firm/firm.h"
-#include "config.h"
-#include "common.h"
-#include "interp.h"
-#include "patch/emunand.h"
// TODO - Basically all this needs to move to patcher programs.
+#include <common.h>
#include <ctr9/io.h>
#include <ctr9/ctr_screen.h>
#include <ctr9/i2c.h>
-#include "common.h"
-#include "std/fs.h"
-#include "patch_format.h"
#define PDN_GPU_CNT (*(volatile uint8_t *)0x10141200)
+++ /dev/null
-This is (sort of) an implementation of C99 std. It is pathetically uncompliant but may be of interest to people wishing to have a usable 16-color printf function.
#define __ABORT_H
#include <stdarg.h>
-#include "draw.h"
+#include <common.h>
void poweroff();
uint32_t wait_key(int sleep);
-#include "draw.h"
-
#include <stdint.h>
#include <assert.h>
#include <stdarg.h>
-#include "memory.h"
+#include <common.h>
#include <ctr9/io.h>
-#include "../firm/fcram.h"
-#include "fs.h"
-#include "unused.h"
-#include "../config.h"
-#include "../patch_format.h"
-#include "abort.h"
static unsigned int top_cursor_x = 0, top_cursor_y = 0;
static unsigned int bottom_cursor_x = 0, bottom_cursor_y = 0;
#include <stddef.h>
-#include "fs.h"
-#include "memory.h"
#include <ctr9/io.h>
-#include "draw.h"
-#include "memory.h"
-#include "../config.h"
+#include <common.h>
// ctr_nand_crypto_interface ctr_io;
// ctr_nand_crypto_interface twl_io;
-#include "memory.h"
+#include <common.h>
#include <stdint.h>
#include <stddef.h>