"Make" now checks EWRAM, IWRAM and ROM space

This commit is contained in:
resetes12
2024-02-18 10:14:42 +01:00
parent ccdc259502
commit 7798724b8d
6 changed files with 1902 additions and 8 deletions

1
.gitignore vendored
View File

@@ -21,7 +21,6 @@ sound/**/*.bin
sound/songs/midi/*.s
tools/agbcc
*.map
*.ld
*.bat
*.dump
*.sa*

View File

@@ -119,8 +119,6 @@ ifneq ($(MODERN),1)
CPPFLAGS += -I tools/agbcc/include -I tools/agbcc -nostdinc -undef
endif
LDFLAGS = -Map ../../$(MAP)
SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c
GFX := tools/gbagfx/gbagfx$(EXE)
AIF := tools/aif2pcm/aif2pcm$(EXE)
@@ -412,19 +410,20 @@ $(OBJ_DIR)/sym_ewram.ld: sym_ewram.txt
$(RAMSCRGEN) ewram_data $< ENGLISH > $@
ifeq ($(MODERN),0)
LD_SCRIPT := ld_script.txt
LD_SCRIPT := ld_script.ld
LD_SCRIPT_DEPS := $(OBJ_DIR)/sym_bss.ld $(OBJ_DIR)/sym_common.ld $(OBJ_DIR)/sym_ewram.ld
else
LD_SCRIPT := ld_script_modern.txt
LD_SCRIPT := ld_script_modern.ld
LD_SCRIPT_DEPS :=
endif
$(OBJ_DIR)/ld_script.ld: $(LD_SCRIPT) $(LD_SCRIPT_DEPS)
cd $(OBJ_DIR) && sed "s#tools/#../../tools/#g" ../../$(LD_SCRIPT) > ld_script.ld
LDFLAGS = -Map ../../$(MAP)
$(ELF): $(OBJ_DIR)/ld_script.ld $(OBJS) libagbsyscall
@echo "cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ <objects> <lib>"
@cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ $(OBJS_REL) $(LIB)
@cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld --print-memory-usage -o ../../$@ $(OBJS_REL) $(LIB) | cat
$(FIX) $@ -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent
$(ROM): $(ELF)

View File

@@ -1,8 +1,11 @@
#include "global.h"
#include "malloc.h"
static void *sHeapStart;
static u32 sHeapSize;
__attribute__((section("__EWRAM_HEAP"))) u8 gHeap[HEAP_SIZE] = {0};
#define MALLOC_SYSTEM_ID 0xA3A3
struct MemBlock {

View File

@@ -1,8 +1,6 @@
#ifndef GUARD_ALLOC_H
#define GUARD_ALLOC_H
#define HEAP_SIZE 0x1C000
#define FREE_AND_SET_NULL(ptr) \
{ \
Free(ptr); \
@@ -11,6 +9,8 @@
#define TRY_FREE_AND_SET_NULL(ptr) if (ptr != NULL) FREE_AND_SET_NULL(ptr)
// 122 KB. Max size of the heap without running into other data
#define HEAP_SIZE 0x1C000
extern u8 gHeap[];
void *Alloc(u32 size);

1726
ld_script.ld Executable file

File diff suppressed because it is too large Load Diff

167
ld_script_modern.ld Executable file
View File

@@ -0,0 +1,167 @@
ENTRY(Start)
gNumMusicPlayers = 4;
gMaxLines = 0;
/* Memory Spaces */
MEMORY
{
EWRAM (rwx) : ORIGIN = 0x2000000, LENGTH = 256K
IWRAM (rwx) : ORIGIN = 0x3000000, LENGTH = 32K
ROM (rx) : ORIGIN = 0x8000000, LENGTH = 32M
}
SECTIONS {
ewram 0x2000000 (NOLOAD) :
ALIGN(4)
{
*(__EWRAM_HEAP);
src/*.o(ewram_data); /**/
gflib/*.o(ewram_data); /**/
} > EWRAM
iwram 0x3000000 (NOLOAD) :
ALIGN(4)
{
src/*.o(.bss);
gflib/*.o(.bss);
data/*.o(.bss);
*libc.a:*.o(.bss*);
*libnosys.a:*.o(.bss*);
/* .bss.code starts at 0x3001AA8 */
src/m4a.o(.bss.code);
/* COMMON starts at 0x30022A8 */
src/*.o(COMMON); /**/
gflib/*.o(COMMON); /**/
*libc.a:*.o(COMMON);
*libnosys.a:*.o(COMMON);
} > IWRAM
/* BEGIN ROM DATA */
. = 0x8000000;
.text :
ALIGN(4)
{
src/rom_header.o(.text*);
src/rom_header_gf.o(.text.*);
src/crt0.o(.text);
src/main.o(.text);
gflib/*.o(.text*);
src/*.o(.text*);
asm/*.o(.text*);
} > ROM =0
script_data :
ALIGN(4)
{
data/*.o(script_data);
} > ROM =0
lib_text :
ALIGN(4)
{
src/libgcnmultiboot.o(.text);
src/m4a_1.o(.text);
src/m4a.o(.text);
src/agb_flash.o(.text);
src/agb_flash_1m.o(.text);
src/agb_flash_mx.o(.text);
src/siirtc.o(.text);
src/librfu_stwi.o(.text);
src/librfu_intr.o(.text);
src/librfu_rfu.o(.text);
src/librfu_sio32id.o(.text);
*libagbsyscall.a:*.o(.text*);
*libgcc.a:*.o(.text*);
*libc.a:*.o(.text*);
*libnosys.a:*.o(.text*);
src/libisagbprn.o(.text);
} > ROM =0
.rodata :
ALIGN(4)
{
src/*.o(.rodata*);
gflib/*.o(.rodata*);
data/*.o(.rodata*);
} > ROM =0
song_data :
ALIGN(4)
{
sound/songs/*.o(.rodata);
} > ROM =0
lib_rodata :
SUBALIGN(4)
{
src/m4a.o(.rodata);
src/agb_flash.o(.rodata);
src/agb_flash_1m.o(.rodata);
src/agb_flash_mx.o(.rodata);
src/agb_flash_le.o(.rodata);
src/siirtc.o(.rodata);
src/librfu_rfu.o(.rodata);
src/librfu_sio32id.o(.rodata);
*libgcc.a:*.o(.rodata*);
*libc.a:*.o(.rodata*);
*libc.a:*.o(.data*);
src/libisagbprn.o(.rodata);
} > ROM =0
multiboot_data :
ALIGN(4)
{
data/multiboot_ereader.o(.rodata);
data/multiboot_berry_glitch_fix.o(.rodata);
data/multiboot_pokemon_colosseum.o(.rodata);
} > ROM =0
anim_mon_front_pic_data :
ALIGN(4)
{
src/anim_mon_front_pics.o(.rodata);
} > ROM =0
gfx_data :
ALIGN(4)
{
src/graphics.o(.rodata);
} > ROM =0
/* 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 .gnu.linkonce.wi.*) }
.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) }
/* Discard everything not specifically mentioned above. */
/DISCARD/ :
{
*(*);
}
}