Sanitize arm9 build system... however link script overflows itcm

This commit is contained in:
TuxSH 2018-05-23 15:02:57 +02:00
parent 52cd950ca6
commit d6d440a47e
5 changed files with 164 additions and 129 deletions

View File

@ -1,149 +1,177 @@
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2)) #---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),) ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif endif
ifneq ($(strip $(shell firmtool -v 2>&1 | grep usage)),) TOPDIR ?= $(CURDIR)
$(error "Please install firmtool v1.1 or greater") include $(DEVKITARM)/base_rules
export REVISION := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
export VERSION_MAJOR := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f1 -d.)
export VERSION_MINOR := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f2 -d.)
export VERSION_BUILD := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f3 -d.)
export COMMIT := $(shell git rev-parse --short=8 HEAD)
export IS_RELEASE := 0
ifeq ($(strip $(REVISION)),)
export REVISION := v0.0.0-0
export VERSION_MAJOR := 0
export VERSION_MINOR := 0
export VERSION_BUILD := 0
endif endif
include $(DEVKITARM)/base_tools ifeq ($(strip $(COMMIT)),)
export COMMIT := 0
name := Luma3DS
revision := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
version_major := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f1 -d.)
version_minor := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f2 -d.)
version_build := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f3 -d.)
commit := $(shell git rev-parse --short=8 HEAD)
is_release := 0
ifeq ($(strip $(revision)),)
revision := v0.0.0-0
version_major := 0
version_minor := 0
version_build := 0
endif endif
ifeq ($(strip $(commit)),) ifeq ($(strip $(VERSION_BUILD)),)
commit := 0 export VERSION_BUILD := 0
endif
ifeq ($(strip $(version_build)),)
version_build := 0
endif endif
ifeq ($(strip $(shell git describe --tags --match v[0-9]* | grep -)),) ifeq ($(strip $(shell git describe --tags --match v[0-9]* | grep -)),)
is_release := 1 export IS_RELEASE := 1
endif endif
dir_source := source #---------------------------------------------------------------------------------
dir_arm11 := arm11 # TARGET is the name of the output
dir_k11_extension := k11_extension # BUILD is the directory where object files & intermediate files will be placed
dir_sysmodules := sysmodules # SOURCES is a list of directories containing source code
dir_loader := $(dir_sysmodules)/loader # DATA is a list of directories containing data files
dir_rosalina := $(dir_sysmodules)/rosalina # INCLUDES is a list of directories containing header files
dir_sm := $(dir_sysmodules)/sm #---------------------------------------------------------------------------------
dir_pxi := $(dir_sysmodules)/pxi TARGET := $(notdir $(CURDIR))
dir_build := build BUILD := build
dir_out := out SOURCES := source source/fatfs source/fatfs/sdmmc
DATA := data
INCLUDES := include
ASFLAGS := -mcpu=arm946e-s #---------------------------------------------------------------------------------
CFLAGS := -Wall -Wextra $(ASFLAGS) -fno-builtin -std=c11 -Wno-main -O2 -ffast-math # options for code generation
LDFLAGS := -nostartfiles -Wl,--nmagic #---------------------------------------------------------------------------------
ARCH := -marm -march=armv5te -mtune=arm946e-s
DEFINES := -DARM9 -D_3DS
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ CFLAGS := -g -std=gnu11 -Wall -Wextra -O2 -mword-relocations \
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \ -fomit-frame-pointer -ffunction-sections -fdata-sections \
$(call rwildcard, $(dir_source), *.s *.c))) -Wno-main -fno-builtin $(ARCH) $(DEFINES)
modules = $(dir_build)/loader.cxi $(dir_build)/rosalina.cxi $(dir_build)/sm.cxi $(dir_build)/pxi.cxi CFLAGS += $(INCLUDE)
define bin2o CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
bin2s $< | $(AS) -o $(@)
endef
.PHONY: all ASFLAGS := -g $(ARCH)
all: firm LDFLAGS = -specs=$(TOPDIR)/linker.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
.PHONY: release LIBS :=
release: $(dir_out)/$(name)$(revision).7z
.PHONY: firm #---------------------------------------------------------------------------------
firm: $(dir_out)/boot.firm # list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=
.PHONY: clean
#---------------------------------------------------------------------------------
# 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 := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
ifeq ($(strip $(APP_TITLE)),)
APP_TITLE := $(notdir $(OUTPUT))
endif
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean: clean:
@$(MAKE) -C $(dir_arm11) clean @echo clean ...
@$(MAKE) -C $(dir_k11_extension) clean @rm -fr $(BUILD) $(TARGET).bin $(TARGET).elf
@$(MAKE) -C $(dir_loader) clean
@$(MAKE) -C $(dir_rosalina) clean
@$(MAKE) -C $(dir_sm) clean
@$(MAKE) -C $(dir_pxi) clean
@rm -rf $(dir_out) $(dir_build)
.PRECIOUS: $(dir_build)/%.bin
.PHONY: $(dir_arm11)
.PHONY: $(dir_k11_extension)
.PHONY: $(dir_loader)
.PHONY: $(dir_rosalina)
.PHONY: $(dir_sm)
.PHONY: $(dir_pxi)
$(dir_out)/$(name)$(revision).7z: all #---------------------------------------------------------------------------------
@mkdir -p "$(@D)" else
@[ -f "$@" ] || 7z a -mx $@ ./$(@D)/* ./exception_dump_parser -xr!.DS_Store .PHONY: all
$(dir_out)/boot.firm: $(dir_build)/modules.bin $(dir_build)/arm11.elf $(dir_build)/main.elf $(dir_build)/k11_extension.bin DEPENDS := $(OFILES:.o=.d)
@mkdir -p "$(@D)"
@firmtool build $@ -D $^ -A 0x18180000 0x18000000 -C XDMA XDMA NDMA XDMA
$(dir_build)/modules.bin: $(modules) #---------------------------------------------------------------------------------
@mkdir -p "$(@D)" # main targets
cat $^ > $@ #---------------------------------------------------------------------------------
all : $(OUTPUT).elf
$(dir_build)/arm11.elf: $(dir_arm11) $(OUTPUT).elf : $(OFILES)
@mkdir -p "$(@D)"
@$(MAKE) -C $<
$(dir_build)/main.elf: $(objects) %.elf: $(OFILES)
$(LINK.o) -T linker.ld $(OUTPUT_OPTION) $^ @echo linking $(notdir $@)
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
@$(NM) -CSn $@ > $(notdir $*.lst)
$(dir_build)/k11_extension.bin: $(dir_k11_extension) $(OFILES_SRC) : $(HFILES_BIN)
@mkdir -p "$(@D)"
@$(MAKE) -C $<
$(dir_build)/loader.cxi: $(dir_loader) memory.o strings.o: CFLAGS += -O3
@mkdir -p "$(@D)" config.o: CFLAGS += -DCONFIG_TITLE="\"$(APP_TITLE) $(REVISION) configuration\""
@$(MAKE) -C $< patches.o: CFLAGS += -DVERSION_MAJOR="$(VERSION_MAJOR)" -DVERSION_MINOR="$(VERSION_MINOR)"\
-DVERSION_BUILD="$(VERSION_BUILD)" -DISRELEASE="$(IS_RELEASE)" -DCOMMIT_HASH="0x$(COMMIT)"
$(dir_build)/rosalina.cxi: $(dir_rosalina) #---------------------------------------------------------------------------------
@mkdir -p "$(@D)" # you need a rule like this for each extension you use as binary data
@$(MAKE) -C $< #---------------------------------------------------------------------------------
%.bin.o : %.bin
$(dir_build)/sm.cxi: $(dir_sm) #---------------------------------------------------------------------------------
@mkdir -p "$(@D)" @echo $(notdir $<)
@$(MAKE) -C $<
$(dir_build)/pxi.cxi: $(dir_pxi)
@mkdir -p "$(@D)"
@$(MAKE) -C $<
$(dir_build)/%.bin.o: $(dir_build)/%.bin
@$(bin2o) @$(bin2o)
$(dir_build)/memory.o $(dir_build)/strings.o: CFLAGS += -O3 -include $(DEPENDS)
$(dir_build)/config.o: CFLAGS += -DCONFIG_TITLE="\"$(name) $(revision) configuration\""
$(dir_build)/patches.o: CFLAGS += -DVERSION_MAJOR="$(version_major)" -DVERSION_MINOR="$(version_minor)"\
-DVERSION_BUILD="$(version_build)" -DISRELEASE="$(is_release)" -DCOMMIT_HASH="0x$(commit)"
$(dir_build)/firm.o: $(dir_build)/modules.bin
$(dir_build)/firm.o: CFLAGS += -DLUMA_SECTION0_SIZE="$(shell wc -c $(dir_build)/modules.bin | tr -d [:space:][:alpha:][:punct:])"
$(dir_build)/%.o: $(dir_source)/%.c #---------------------------------------------------------------------------------------
@mkdir -p "$(@D)" endif
$(COMPILE.c) $(OUTPUT_OPTION) $< #---------------------------------------------------------------------------------------
$(dir_build)/%.o: $(dir_source)/%.s
@mkdir -p "$(@D)"
$(COMPILE.s) $(OUTPUT_OPTION) $<

View File

@ -7,7 +7,7 @@ MEMORY
{ {
NULL : ORIGIN = 0x00000000, LENGTH = 0x1000 NULL : ORIGIN = 0x00000000, LENGTH = 0x1000
main : ORIGIN = 0x08006000, LENGTH = 0x080F0000 - 0x08006000 main : ORIGIN = 0x08006000, LENGTH = 0x080F0000 - 0x08006000
itcm : ORIGIN = 0x01FF8000, LENGTH = 0x01FFB800 - 0x01FF8000 /* Unused ITCM slice. */ itcm : ORIGIN = 0x01FF8000, LENGTH = 1M
} }
SECTIONS SECTIONS
@ -39,13 +39,13 @@ SECTIONS
KEEP(*(.arm9_exception_handlers.text)) KEEP(*(.arm9_exception_handlers.text))
*(.arm9_exception_handlers.text*) *(.arm9_exception_handlers.text*)
KEEP(*(.chainloader.text.start)) KEEP(*(.chainloader.text.start))
build/chainloader.o build/i2c.o build/arm9_exception_handlers.o(.text*) chainloader.o i2c.o arm9_exception_handlers.o(.text*)
*(.arm9_exception_handlers.rodata*) *(.arm9_exception_handlers.rodata*)
build/chainloader.o build/i2c.o build/arm9_exception_handlers.o(.rodata*) chainloader.o i2c.o arm9_exception_handlers.o(.rodata*)
*(.arm9_exception_handlers.data*) *(.arm9_exception_handlers.data*)
build/chainloader.o build/i2c.o build/arm9_exception_handlers.o(.data*) chainloader.o i2c.o arm9_exception_handlers.o(.data*)
. = ALIGN(8); . = ALIGN(8);
} >itcm AT>main } >itcm AT>main
@ -55,7 +55,7 @@ SECTIONS
. = ALIGN(8); . = ALIGN(8);
PROVIDE (__itcm_bss_start__ = ABSOLUTE(.)); PROVIDE (__itcm_bss_start__ = ABSOLUTE(.));
*(.arm9_exception_handlers.bss*) *(.arm9_exception_handlers.bss*)
build/chainloader.o build/i2c.o build/arm9_exception_handlers.o(.bss* COMMON) chainloader.o i2c.o arm9_exception_handlers.o(.bss* COMMON)
. = ALIGN(8); . = ALIGN(8);
PROVIDE (__itcm_end__ = ABSOLUTE(.)); PROVIDE (__itcm_end__ = ABSOLUTE(.));
} >itcm AT>main } >itcm AT>main

7
arm9/linker.specs Normal file
View File

@ -0,0 +1,7 @@
%rename link old_link
*link:
%(old_link) -T %:getenv(TOPDIR /linker.ld) --nmagic --gc-sections
*startfile:
crti%O%s crtbegin%O%s

View File

@ -282,7 +282,7 @@ static inline void mergeSection0(FirmwareType firmType, u32 firmVersion, bool lo
if(firmType == NATIVE_FIRM && (ISN3DS || firmVersion >= 0x1D)) if(firmType == NATIVE_FIRM && (ISN3DS || firmVersion >= 0x1D))
{ {
//2) Merge that info with our own modules' //2) Merge that info with our own modules'
for(u8 *src = (u8 *)0x18180000; src < (u8 *)(0x18180000 + LUMA_SECTION0_SIZE); src += srcModuleSize) for(u8 *src = (u8 *)0x18180000; src < (u8 *)(0x18180000 + /*LUMA_SECTION0_SIZE*/0); src += srcModuleSize)
{ {
const char *name = ((Cxi *)src)->exHeader.systemControlInfo.appTitle; const char *name = ((Cxi *)src)->exHeader.systemControlInfo.appTitle;

View File

@ -70,16 +70,16 @@ emunandPatchSize:
.arm .arm
.align 4 .align 4
.set copy_launch_stub_stack_top, 0x01FFB800 #define copy_launch_stub_stack_top 0x01FFB800
.set copy_launch_stub_stack_bottom, 0x01FFA800 #define copy_launch_stub_stack_bottom 0x01FFA800
.set copy_launch_stub_addr, 0x01FF9000 #define copy_launch_stub_addr 0x01FF9000
.set argv_addr, (copy_launch_stub_stack_bottom - 0x100) #define argv_addr (copy_launch_stub_stack_bottom - 0x100)
.set fname_addr, (copy_launch_stub_stack_bottom - 0x200) #define fname_addr (copy_launch_stub_stack_bottom - 0x200)
.set low_tid_addr, (copy_launch_stub_stack_bottom - 0x300) #define low_tid_addr (copy_launch_stub_stack_bottom - 0x300)
.set firm_addr, 0x20001000 #define firm_addr 0x20001000
.set firm_maxsize, 0x07FFF000 #define firm_maxsize 0x07FFF000
.global rebootPatch .global rebootPatch
rebootPatch: rebootPatch: