This repository has been archived by the owner on Aug 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d07d6dd
Showing
37 changed files
with
7,579 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Cakes.dat | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2)) | ||
|
||
# This should be set externally | ||
name ?= Cakes.dat | ||
path ?= / | ||
dir_out ?= . | ||
|
||
CC := arm-none-eabi-gcc | ||
AS := arm-none-eabi-as | ||
LD := arm-none-eabi-ld | ||
OC := arm-none-eabi-objcopy | ||
|
||
PYTHON2 := python | ||
PYTHON_VER_MAJOR := $(word 2, $(subst ., , $(shell python --version 2>&1))) | ||
ifneq ($(PYTHON_VER_MAJOR), 2) | ||
PYTHON2 := python2 | ||
endif | ||
|
||
dir_source := source | ||
dir_build := build | ||
dir_tools := p3ds | ||
|
||
ARM9FLAGS := -mcpu=arm946e-s -march=armv5te | ||
ARM11FLAGS := -mcpu=mpcore | ||
ASFLAGS := -mlittle-endian | ||
CFLAGS := -marm $(ASFLAGS) -O2 -std=c11 -MMD -MP -fno-builtin -fshort-wchar -Wall -Wextra -Wno-main -DLAUNCHER_PATH='"$(path)$(name)"' | ||
|
||
get_objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ | ||
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, $1)) | ||
|
||
objects := $(call get_objects, $(wildcard $(dir_source)/*.s $(dir_source)/*.c)) | ||
|
||
objects_mset_4x := $(patsubst $(dir_build)/%, $(dir_build)/mset_4x/%, \ | ||
$(objects)) | ||
objects_mset_4x_dg := $(patsubst $(dir_build)/%, $(dir_build)/mset_4x_dg/%, \ | ||
$(objects)) | ||
objects_spider_4x := $(patsubst $(dir_build)/%, $(dir_build)/spider_4x/%, \ | ||
$(objects)) | ||
objects_spider_5x := $(patsubst $(dir_build)/%, $(dir_build)/spider_5x/%, \ | ||
$(objects)) | ||
objects_spider_9x := $(patsubst $(dir_build)/%, $(dir_build)/spider_9x/%, \ | ||
$(objects)) | ||
|
||
objects_payload := $(call get_objects, \ | ||
$(call rwildcard, $(dir_source)/payload, *.s *.c)) | ||
|
||
versions := mset_4x mset_4x_dg spider_4x spider_5x spider_9x | ||
|
||
rops := $(foreach ver, $(versions), $(dir_build)/$(ver)/rop.dat) | ||
|
||
.PHONY: all | ||
all: launcher | ||
|
||
.PHONY: launcher | ||
launcher: $(dir_out)/$(name) | ||
|
||
.PHONY: bigpayload | ||
bigpayload: $(dir_build)/bigpayload.built | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf $(dir_out)/$(name) $(dir_build) | ||
|
||
# Big payload | ||
$(dir_build)/bigpayload.built: $(dir_out)/$(name) $(dir_build)/payload/main.bin | ||
dd if=$(dir_build)/payload/main.bin of=$(dir_out)/$(name) bs=512 seek=256 | ||
@touch $@ | ||
|
||
# Throw everything together | ||
$(dir_out)/$(name): $(rops) | ||
touch $@ | ||
dd if=$(dir_build)/mset_4x/rop.dat of=$@ | ||
dd if=$(dir_build)/mset_4x_dg/rop.dat of=$@ bs=512 seek=80 | ||
dd if=$(dir_build)/spider_4x/rop.dat of=$@ bs=512 seek=144 | ||
dd if=$(dir_build)/spider_5x/rop.dat of=$@ bs=512 seek=176 | ||
dd if=$(dir_build)/spider_9x/rop.dat of=$@ bs=512 seek=208 | ||
|
||
$(dir_build)/mset_4x/rop.dat: $(dir_build)/mset_4x/main.bin | ||
$(PYTHON2) $(dir_tools)/build-rop.py MSET_4X $< $@ | ||
|
||
$(dir_build)/mset_4x_dg/rop.dat: $(dir_build)/mset_4x_dg/main.bin | ||
$(PYTHON2) $(dir_tools)/build-rop.py MSET_4X_DG $< $@ | ||
|
||
$(dir_build)/spider_4x/rop.dat: $(dir_build)/spider_4x/rop.dat.dec | ||
$(PYTHON2) $(dir_tools)/spider-encrypt.py $< $@ | ||
$(dir_build)/spider_4x/rop.dat.dec: $(dir_build)/spider_4x/main.bin | ||
$(PYTHON2) $(dir_tools)/build-rop.py SPIDER_4X $< $@ | ||
|
||
$(dir_build)/spider_5x/rop.dat: $(dir_build)/spider_5x/rop.dat.dec | ||
$(PYTHON2) $(dir_tools)/spider-encrypt.py $< $@ | ||
$(dir_build)/spider_5x/rop.dat.dec: $(dir_build)/spider_5x/main.bin | ||
$(PYTHON2) $(dir_tools)/build-rop.py SPIDER_5X $< $@ | ||
|
||
$(dir_build)/spider_9x/rop.dat: $(dir_build)/spider_9x/rop.dat.dec | ||
$(PYTHON2) $(dir_tools)/spider-encrypt.py $< $@ | ||
$(dir_build)/spider_9x/rop.dat.dec: $(dir_build)/spider_9x/main.bin | ||
$(PYTHON2) $(dir_tools)/build-rop.py SPIDER_9X $< $@ | ||
|
||
# Create bin from elf | ||
$(dir_build)/%/main.bin: $(dir_build)/%/main.elf | ||
$(OC) -S -O binary $< $@ | ||
|
||
# Different flags for different things | ||
$(dir_build)/payload/main.elf: ASFLAGS := $(ARM9FLAGS) $(ASFLAGS) | ||
$(dir_build)/payload/main.elf: CFLAGS := $(ARM9FLAGS) $(CFLAGS) | ||
$(dir_build)/payload/main.elf: $(objects_payload) | ||
# FatFs requires libgcc for __aeabi_uidiv | ||
$(CC) -nostartfiles $(LDFLAGS) -T linker_payload.ld $(OUTPUT_OPTION) $^ | ||
|
||
$(dir_build)/mset_4x/main.elf: ASFLAGS := $(ARM11FLAGS) $(ASFLAGS) | ||
$(dir_build)/mset_4x/main.elf: CFLAGS := -DENTRY_MSET -DENTRY_MSET_4x \ | ||
$(ARM11FLAGS) $(CFLAGS) | ||
$(dir_build)/mset_4x/main.elf: $(objects_mset_4x) | ||
$(LD) $(LDFLAGS) -T linker_mset.ld $(OUTPUT_OPTION) $^ | ||
|
||
$(dir_build)/mset_4x_dg/main.elf: ASFLAGS := $(ARM11FLAGS) $(ASFLAGS) | ||
$(dir_build)/mset_4x_dg/main.elf: CFLAGS := -DENTRY_MSET -DENTRY_MSET_4x_DG \ | ||
$(ARM11FLAGS) $(CFLAGS) | ||
$(dir_build)/mset_4x_dg/main.elf: $(objects_mset_4x_dg) | ||
$(LD) $(LDFLAGS) -T linker_mset.ld $(OUTPUT_OPTION) $^ | ||
|
||
$(dir_build)/spider_4x/main.elf: ASFLAGS := $(ARM11FLAGS) $(ASFLAGS) | ||
$(dir_build)/spider_4x/main.elf: CFLAGS := -DENTRY_SPIDER -DENTRY_SPIDER_4x \ | ||
$(ARM11FLAGS) $(CFLAGS) | ||
$(dir_build)/spider_4x/main.elf: $(objects_spider_4x) | ||
$(LD) $(LDFLAGS) -T linker_spider.ld $(OUTPUT_OPTION) $^ | ||
|
||
$(dir_build)/spider_5x/main.elf: ASFLAGS := $(ARM11FLAGS) $(ASFLAGS) | ||
$(dir_build)/spider_5x/main.elf: CFLAGS := -DENTRY_SPIDER -DENTRY_SPIDER_5x \ | ||
$(ARM11FLAGS) $(CFLAGS) | ||
$(dir_build)/spider_5x/main.elf: $(objects_spider_5x) | ||
$(LD) $(LDFLAGS) -T linker_spider.ld $(OUTPUT_OPTION) $^ | ||
|
||
$(dir_build)/spider_9x/main.elf: ASFLAGS := $(ARM11FLAGS) $(ASFLAGS) | ||
$(dir_build)/spider_9x/main.elf: CFLAGS := -DENTRY_SPIDER -DENTRY_SPIDER_9x \ | ||
$(ARM11FLAGS) $(CFLAGS) | ||
$(dir_build)/spider_9x/main.elf: $(objects_spider_9x) | ||
$(LD) $(LDFLAGS) -T linker_spider.ld $(OUTPUT_OPTION) $^ | ||
|
||
$(dir_build)/payload/%.o: $(dir_source)/payload/%.c | ||
@mkdir -p "$(@D)" | ||
$(COMPILE.c) $(OUTPUT_OPTION) $< | ||
|
||
$(dir_build)/payload/%.o: $(dir_source)/payload/%.s | ||
@mkdir -p "$(@D)" | ||
$(COMPILE.s) $(OUTPUT_OPTION) $< | ||
|
||
# Fatfs requires to be built in thumb | ||
$(dir_build)/payload/fatfs/%.o: $(dir_source)/payload/fatfs/%.c | ||
@mkdir -p "$(@D)" | ||
$(COMPILE.c) -mthumb -mthumb-interwork -Wno-unused-function $(OUTPUT_OPTION) $< | ||
|
||
$(dir_build)/payload/fatfs/%.o: $(dir_source)/payload/fatfs/%.s | ||
@mkdir -p "$(@D)" | ||
$(COMPILE.s) -mthumb -mthumb-interwork $(OUTPUT_OPTION) $< | ||
|
||
.SECONDEXPANSION: | ||
$(dir_build)/%.o: $(dir_source)/$$(notdir $$*).c | ||
@mkdir -p "$(@D)" | ||
$(COMPILE.c) $(OUTPUT_OPTION) $< | ||
|
||
.SECONDEXPANSION: | ||
$(dir_build)/%.o: $(dir_source)/$$(notdir $$*).s | ||
@mkdir -p "$(@D)" | ||
$(COMPILE.s) $(OUTPUT_OPTION) $< | ||
|
||
include $(call rwildcard, $(dir_build), *.d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ENTRY(_start) | ||
SECTIONS | ||
{ | ||
. = 0x00240000; | ||
.text.start : { *(.text.start) } | ||
.text : { *(.text) } | ||
.data : { *(.data) } | ||
.bss : { *(.bss COMMON) } | ||
.rodata : { *(.rodata) } | ||
. = ALIGN(4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ENTRY(_start) | ||
SECTIONS | ||
{ | ||
. = 0x23F00000; | ||
.text.start : { *(.text.start) } | ||
.text : { *(.text) } | ||
.data : { *(.data) } | ||
.bss : { *(.bss COMMON) } | ||
.rodata : { *(.rodata) } | ||
. = ALIGN(4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ENTRY(_start) | ||
SECTIONS | ||
{ | ||
. = 0x009D2000; | ||
.text.start : { *(.text.start) } | ||
.text : { *(.text) } | ||
.data : { *(.data) } | ||
.bss : { *(.bss COMMON) } | ||
.rodata : { *(.rodata) } | ||
. = ALIGN(4); | ||
} |
Submodule p3ds
added at
ad105a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "appcompat.h" | ||
|
||
void (*memcpy)(void *dest, void *src, uint32_t len) = (void *)FUNC_MEMCPY; | ||
int (*GSPGPU_FlushDataCache)(void *address, uint32_t length) = (void *)FUNC_GSPGPU_FLUSHDATACACHE; | ||
void (*nn__gxlow__CTR__CmdReqQueueTx__TryEnqueue)(void *arg1, void *arg2) = (void *)FUNC_NN__GXLOW__CTR__CMDREQQUEUETX__TRYENQUEUE; | ||
uint32_t (*svcControlMemory)(uint32_t *outaddr, uint32_t *addr0, uint32_t *addr1, uint32_t size, uint32_t operation, uint32_t permissions) = (void *)FUNC_SVCCONTROLMEMORY; | ||
int (*fopen)(uint32_t (*handle)[], short unsigned int *path, int flags) = (void *)FUNC_FOPEN; | ||
int (*fread)(uint32_t (*handle)[], uint32_t *read, void *buffer, uint32_t size) = (void *)FUNC_FREAD; | ||
int (*fwrite)(uint32_t (*handle)[], uint32_t *written, void *src, uint32_t size) = (void *)FUNC_FWRITE; | ||
|
||
#ifdef ENTRY_SPIDER | ||
int (*GX_SetTextureCopy)(void *input_buffer, void *output_buffer, uint32_t size, int in_x, int in_y, int out_x, int out_y, int flags) = (void *)FUNC_GX_SETTEXTURECOPY; | ||
int (*svcSleepThread)(unsigned long long nanoseconds) = (void *)FUNC_SVCSLEEPTHREAD; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#ifndef __appcompat_h__ | ||
#define __appcompat_h__ | ||
|
||
#include <stdint.h> | ||
#include "launcher_path.h" | ||
|
||
// Functions | ||
void (*memcpy)(void *dest, void *src, uint32_t len); | ||
int (*GSPGPU_FlushDataCache)(void *address, uint32_t length); | ||
void (*nn__gxlow__CTR__CmdReqQueueTx__TryEnqueue)(void *arg1, void *arg2); | ||
uint32_t (*svcControlMemory)(uint32_t *outaddr, uint32_t *addr0, uint32_t *addr1, uint32_t size, uint32_t operation, uint32_t permissions); | ||
int (*fopen)(uint32_t (*handle)[], short unsigned int *path, int flags); | ||
int (*fread)(uint32_t (*handle)[], uint32_t *read, void *buffer, uint32_t size); | ||
int (*fwrite)(uint32_t (*handle)[], uint32_t *written, void *src, uint32_t size); | ||
|
||
#ifdef ENTRY_SPIDER | ||
int (*GX_SetTextureCopy)(void *input_buffer, void *output_buffer, uint32_t size, int in_x, int in_y, int out_x, int out_y, int flags); | ||
int (*svcSleepThread)(unsigned long long nanoseconds); | ||
#endif | ||
|
||
|
||
#if defined(ENTRY_MSET) | ||
#define FUNC_MEMCPY 0x001BFA60 | ||
#define FUNC_GSPGPU_FLUSHDATACACHE 0x0013C5D4 | ||
#define FUNC_NN__GXLOW__CTR__CMDREQQUEUETX__TRYENQUEUE 0x001AC924 | ||
#define FUNC_SVCCONTROLMEMORY 0x001C3E24 | ||
#define FUNC_FOPEN 0x001B82A8 | ||
#define FUNC_FREAD 0x001B3954 | ||
#define FUNC_FWRITE 0x001B3B50 | ||
|
||
#define APP_GPUHANDLE (0x0027C580 + 0x58) | ||
|
||
#if defined(ENTRY_MSET_4x) | ||
// Default firm 4.x (0x1F) | ||
// MSET code offset in FCRAM | ||
#define APP_CODE_OFFSET 0x03E6D000 | ||
#elif defined(ENTRY_MSET_4x_DG) | ||
// Firm 9.0~9.2 (0x38) | ||
// MSET code offset in FCRAM | ||
#define APP_CODE_OFFSET 0x03F00000 | ||
#endif | ||
|
||
#elif defined(ENTRY_SPIDER_4x) | ||
#define FUNC_MEMCPY 0x0029BF60 | ||
#define FUNC_GSPGPU_FLUSHDATACACHE 0x00344B84 | ||
#define FUNC_NN__GXLOW__CTR__CMDREQQUEUETX__TRYENQUEUE 0x002CF3EC | ||
#define FUNC_SVCCONTROLMEMORY 0x002D6ADC | ||
#define FUNC_FOPEN 0x0025B0A4 | ||
#define FUNC_FREAD 0x002FC8E4 | ||
#define FUNC_FWRITE 0x00311D90 | ||
|
||
#define FUNC_GX_SETTEXTURECOPY 0x002C62E4 | ||
#define FUNC_SVCSLEEPTHREAD 0x002A513C | ||
|
||
#define APP_GPUHANDLE (0x003F54E8 + 0x58) | ||
|
||
#elif defined(ENTRY_SPIDER_5x) | ||
#define FUNC_MEMCPY 0x00240B58 | ||
#define FUNC_GSPGPU_FLUSHDATACACHE 0x001914FC | ||
#define FUNC_NN__GXLOW__CTR__CMDREQQUEUETX__TRYENQUEUE 0x0012BF4C | ||
#define FUNC_SVCCONTROLMEMORY 0x001431C0 | ||
#define FUNC_FOPEN 0x0022FE44 | ||
#define FUNC_FREAD 0x001686C0 | ||
#define FUNC_FWRITE 0x00168748 | ||
|
||
#define FUNC_GX_SETTEXTURECOPY 0x0011DD80 | ||
#define FUNC_SVCSLEEPTHREAD 0x0010420C | ||
|
||
#define APP_GPUHANDLE (0x003D7C40 + 0x58) | ||
|
||
#elif defined(ENTRY_SPIDER_9x) | ||
#define FUNC_MEMCPY 0x00240B50 | ||
#define FUNC_GSPGPU_FLUSHDATACACHE 0x00191504 | ||
#define FUNC_NN__GXLOW__CTR__CMDREQQUEUETX__TRYENQUEUE 0x0012BF04 | ||
#define FUNC_SVCCONTROLMEMORY 0x001431A0 | ||
#define FUNC_FOPEN 0x0022FE08 | ||
#define FUNC_FREAD 0x001686DC | ||
#define FUNC_FWRITE 0x00168764 | ||
|
||
#define FUNC_GX_SETTEXTURECOPY 0x0011DD48 | ||
#define FUNC_SVCSLEEPTHREAD 0x0023FFE8 | ||
|
||
#define APP_GPUHANDLE (0x003D7C40 + 0x58) | ||
#endif | ||
|
||
|
||
#if defined(ENTRY_MSET) | ||
// The usable area for this app | ||
#define APP_FCRAM_ADDR 0x14000000 | ||
|
||
#define APP_CFW_OFFSET 0x400000 | ||
#define APP_LAUNCHER_PATH (L"YS:/" LAUNCHER_PATH) | ||
|
||
#elif defined(ENTRY_SPIDER) | ||
// The usable area for this app | ||
#define APP_FCRAM_ADDR 0x18400000 | ||
|
||
#define APP_CFW_OFFSET 0x4410000 | ||
#define APP_LAUNCHER_PATH (L"dmc:/" LAUNCHER_PATH) | ||
#endif | ||
|
||
// Locations in fcram | ||
#define APP_CHECK_MEM (APP_FCRAM_ADDR + 0x1000) | ||
#define APP_ARM11_BUFFER (APP_FCRAM_ADDR + 0x2000) | ||
#define APP_MEM_HAX_MEM (APP_FCRAM_ADDR + 0x50000) | ||
#define APP_FIRM_COMPAT (APP_FCRAM_ADDR + 0x20000) | ||
|
||
#define ARM9_PAYLOAD_MAXSIZE 0x10000 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef __arm11_tools_h__ | ||
#define __arm11_tools_h__ | ||
|
||
#include <stdint.h> | ||
|
||
void invalidate_data_cache(); | ||
void invalidate_instruction_cache(); | ||
void asm_memcpy(void *dest, void *src, uint32_t length); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.global invalidate_data_cache | ||
invalidate_data_cache: | ||
mov r0, #0 | ||
mcr p15, 0, r0, c7, c14, 0 @ Clean and Invalidate Entire Data Cache | ||
mcr p15, 0, r0, c7, c10, 4 @ Data Synchronization Barrier | ||
bx lr | ||
|
||
.global invalidate_instruction_cache | ||
invalidate_instruction_cache: | ||
mov r0, #0 | ||
mcr p15, 0, r0, c7, c5, 0 | ||
mcr p15, 0, r0, c7, c5, 4 | ||
mcr p15, 0, r0, c7, c5, 6 | ||
mcr p15, 0, r0, c7, c10, 4 | ||
bx lr | ||
|
||
.global asm_memcpy | ||
asm_memcpy: | ||
add r2, r1 | ||
|
||
.memcpy_loop: | ||
ldmia r1!, {r3} | ||
stmia r0!, {r3} | ||
cmp r1, r2 | ||
bcc .memcpy_loop | ||
|
||
bx lr |
Oops, something went wrong.