Skip to content

Commit

Permalink
Revert ld_script
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Sep 17, 2024
1 parent e5edb9b commit 435a0cd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ld_script_sapphire.txt
*.id2
*.nam
*.til
*.ld
tags
types_*.taghl
*.swp
Expand Down
27 changes: 13 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ ifeq ($(MODERN),0)
CPPFLAGS += -I tools/agbcc/include -I tools/agbcc -nostdinc -undef
CC1 := tools/agbcc/bin/agbcc$(EXE)
override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -Wunused -O$(O_LEVEL) -fhex-asm -g
LIBPATH := -L ../../tools/agbcc/lib
LIBDIRS := ../../tools/agbcc/lib
else
# Note: The makefile must be set up to not call these if modern == 0
MODERNCC := $(PREFIX)gcc
PATH_MODERNCC := PATH="$(PATH)" $(MODERNCC)
CC1 = $(shell $(PATH_MODERNCC) --print-prog-name=cc1) -quiet
override CFLAGS += -mthumb -mthumb-interwork -O$(O_LEVEL) -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast -fno-aggressive-loop-optimizations -Wno-stringop-overflow
LIBPATH := -L $(shell dirname $(shell $(PATH_MODERNCC) --print-file-name=libgcc.a)) -L $(shell dirname $(shell $(MODERNCC) --print-file-name=libc.a))
LIBDIRS := -L $(shell dirname $(shell $(PATH_MODERNCC) --print-file-name=libgcc.a)) -L $(shell dirname $(shell $(MODERNCC) --print-file-name=libc.a))
endif
LIB := $(LIBPATH) -lgcc -lc
LDFLAGS := $(LIBDIRS:%=-L %) -lgcc -lc

# Enable debug info if set
ifeq ($(DINFO),1)
Expand Down Expand Up @@ -370,24 +370,23 @@ $(foreach src, $(C_ASM_SRCS), $(eval $(call ASM_DEP_PREPROC,$(src:%.s=$(OBJ_DIR)
$(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call ASM_DEP_PREPROC,$(src:%.s=$(OBJ_DIR)/%),$(src))))
endif

$(OBJ_DIR)/sym_%.ld: sym_%.txt
$(CPP) -P $(CPPFLAGS) $< | sed -e "s#tools/#../../tools/#g" > $@

# Linker script
ifeq ($(MODERN),0)
LD_SCRIPT := ld_script.ld
LD_SCRIPT_DEPS := $(OBJ_DIR)/sym_bss.ld $(OBJ_DIR)/sym_common.ld $(OBJ_DIR)/sym_ewram.ld
LD_SCRIPT := $(OBJ_DIR)/ld_script.ld
else
LD_SCRIPT := ld_script_modern.ld
LD_SCRIPT_DEPS :=
LD_SCRIPT := $(OBJ_DIR)/ld_script_modern.ld
endif

# Final rules
$(LD_SCRIPT): $(LD_SCRIPT:$(OBJ_DIR)/%.ld=%.txt) $(OBJ_DIR)/sym_common.ld $(OBJ_DIR)/sym_ewram.ld $(OBJ_DIR)/sym_bss.ld
sed -e "s#tools/#../../tools/#g" $< >$@
$(OBJ_DIR)/sym_%.ld: sym_%.txt
$(CPP) -P $(CPPFLAGS) $< | sed -e "s#tools/#../../tools/#g" > $@

# Elf from object files
$(ELF): $(LD_SCRIPT) $(LD_SCRIPT_DEPS) $(OBJS)
@cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ../../$< --print-memory-usage -o ../../$@ $(OBJS_REL) $(LIB) | cat
$(FIX) $@ -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(GAME_REVISION) --silent
$(ELF): $(LD_SCRIPT) $(OBJS)
@echo "cd $(OBJ_DIR) && $(LD) -T $(LD_SCRIPT:$(OBJ_DIR)/%=%) -Map ../../$(MAP) -o ../../$@ <objects> <lib>"
@cd $(OBJ_DIR) && $(LD) -T $(LD_SCRIPT:$(OBJ_DIR)/%=%) -Map ../../$(MAP) -o ../../$@ $(OBJS_REL) $(LDFLAGS)
$(FIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(GAME_REVISION) --silent

$(ROM): $(ELF)
$(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0x9000000 $< $@
Expand Down
51 changes: 20 additions & 31 deletions ld_script.ld → ld_script.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@ ENTRY(Start)
gNumMusicPlayers = 4;
gMaxLines = 60;

MEMORY
{
EWRAM (rwx) : ORIGIN = 0x2000000, LENGTH = 256K
IWRAM (rwx) : ORIGIN = 0x3000000, LENGTH = 32K
ROM (rx) : ORIGIN = 0x8000000, LENGTH = 32M
}

__gfx_load_address = 0x8d00000;

SECTIONS {
. = 0x2000000;

ewram 0x2000000 (NOLOAD) :
ewram (NOLOAD) :
ALIGN(4)
{
INCLUDE "sym_ewram.ld"
src/*.o(ewram_data);
} > EWRAM

iwram 0x3000000 (NOLOAD) :
. = 0x40000;
}

. = 0x3000000;

iwram (NOLOAD) :
ALIGN(4)
{
/* .bss starts at 0x3000000 */
Expand All @@ -37,7 +32,7 @@ SECTIONS {
*(COMMON);
end = .;
. = 0x8000;
} > IWRAM
}

. = 0x8000000;

Expand Down Expand Up @@ -384,7 +379,7 @@ SECTIONS {
src/debug/unknown_debug_menu.o(.text);
src/name_string_util.o(.text);
src/menu_cursor.o(.text);
} > ROM =0
} =0

script_data :
ALIGN(4)
Expand All @@ -397,7 +392,7 @@ SECTIONS {
data/battle_ai_scripts.o(script_data);
data/contest_ai_scripts.o(script_data);
data/mystery_event_script_cmd_table.o(script_data);
} > ROM =0
} =0

lib_text :
ALIGN(4)
Expand Down Expand Up @@ -468,7 +463,7 @@ SECTIONS {
*libc.a:*syscalls*.o(.text);
*libc.a:*errno*.o(.text);
src/libs/libisagbprn.o(.text);
} > ROM =0
} =0

.rodata :
ALIGN(4)
Expand Down Expand Up @@ -795,7 +790,7 @@ SECTIONS {
data/debug_mystery_event_scripts.o(.rodata);
src/libs/m4a_tables.o(.rodata);
data/sound_data.o(.rodata);
} > ROM =0
} =0

song_data :
ALIGN(4)
Expand Down Expand Up @@ -1217,7 +1212,7 @@ SECTIONS {
sound/songs/mus_vs_elite_four.o(.rodata);
sound/songs/mus_vs_aqua_magma_leader.o(.rodata);
sound/songs/mus_radio_tower_takeover.o(.rodata);
} > ROM =0
} =0

lib_rodata :
ALIGN(4)
Expand All @@ -1232,21 +1227,15 @@ SECTIONS {
*libc.a(.rodata);
*libc.a(.data);
src/libs/libisagbprn.o(.rodata);
} > ROM =0
} =0

gfx_data __gfx_load_address :
ALIGN(4)
{
src/data/graphics.o(.rodata);
} > ROM =0
. = 0x8D00000;

extra :
gfx_data :
ALIGN(4)
{
src/*.o(.text);
src/*.o(.rodata);
data/*.o(.rodata);
} > ROM =0
src/data/graphics.o(.rodata);
} =0

/* DWARF 2 sections */
.debug_aranges 0 : { *(.debug_aranges) }
Expand All @@ -1264,4 +1253,4 @@ SECTIONS {
{
*(*);
}
}
}
36 changes: 17 additions & 19 deletions ld_script_modern.ld → ld_script_modern.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ ENTRY(Start)
gNumMusicPlayers = 4;
gMaxLines = 60;

MEMORY
{
EWRAM (rwx) : ORIGIN = 0x2000000, LENGTH = 256K
IWRAM (rwx) : ORIGIN = 0x3000000, LENGTH = 32K
ROM (rx) : ORIGIN = 0x8000000, LENGTH = 32M
}

SECTIONS {
. = 0x2000000;

ewram 0x2000000 (NOLOAD) :
ewram (NOLOAD) :
ALIGN(4)
{
INCLUDE "sym_ewram.ld"
*(ewram_data);
} > EWRAM

iwram 0x3000000 (NOLOAD) :
. = 0x40000;
}

. = 0x3000000;

iwram (NOLOAD) :
ALIGN(4)
{
/* .bss starts at 0x3000000 */
Expand All @@ -32,7 +30,7 @@ SECTIONS {
*(COMMON);
end = .;
. = 0x8000;
} > IWRAM
}

. = 0x8000000;

Expand All @@ -43,25 +41,25 @@ SECTIONS {
src/rom_header_gf.o(.text.*);
src/crt0.o(.text);
*(.text*);
} > ROM =0
} =0

script_data :
ALIGN(4)
{
*(script_data);
} > ROM =0
*(script_data);
} =0

.data :
ALIGN(4)
{
*(.data*);
} > ROM =0
*(.data*);
} =0

.rodata :
ALIGN(4)
{
*(.rodata*);
} > ROM =0
*(.rodata*);
} =0

/* DWARF 2 sections */
.debug_aranges 0 : { *(.debug_aranges) }
Expand All @@ -79,4 +77,4 @@ SECTIONS {
{
*(*);
}
}
}

0 comments on commit 435a0cd

Please sign in to comment.