static-link libagbsyscall similar to pokeemerald... Thx Pika

This commit is contained in:
Seth Barberee 2020-10-20 13:02:58 -05:00
parent 33b0b86f53
commit a0aac0e9d2
6 changed files with 609 additions and 104 deletions

3
.gitignore vendored
View File

@ -17,8 +17,6 @@
sound/**/*.bin
src/*.s
tools/agbcc
ld_script_ruby.txt
ld_script_sapphire.txt
*.map
*.id0
*.id1
@ -39,3 +37,4 @@ build/
.idea/
*.DS_Store
*.pl
*.a

View File

@ -53,7 +53,7 @@ SUBDIRS := $(sort $(dir $(ALL_OBJECTS)))
ifeq ($(OS),Windows_NT)
LIB := ../../tools/agbcc/lib/libc.a ../../tools/agbcc/lib/libgcc.a
else
LIB := -L ../../tools/agbcc/lib -lc -lgcc
LIB := -L ../../tools/agbcc/lib -lc -lgcc -L ../../libagbsyscall -lagbsyscall
endif
LD_SCRIPT := $(BUILD_DIR)/ld_script.ld
@ -78,7 +78,7 @@ endif
ALL_BUILDS := red
# Available targets
.PHONY: all clean tidy
.PHONY: all clean tidy libagbsyscall
MAKEFLAGS += --no-print-directory
# Secondary expansion is required for dependency variables in object rules.
@ -107,12 +107,13 @@ clean: tidy
tidy:
$(RM) $(ALL_BUILDS:%=pmd_%{.gba,.elf,.map})
$(RM) -r build
@$(MAKE) clean -C libagbsyscall
$(ROM): %.gba: %.elf
$(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0xA000000 $< $@
$(GBAFIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent
%.elf: $(LD_SCRIPT) $(ALL_OBJECTS) $(LIBC)
%.elf: $(LD_SCRIPT) $(ALL_OBJECTS) $(LIBC) libagbsyscall
cd $(BUILD_DIR) && $(LD) -T ld_script.ld -Map ../../$(MAP) -o ../../$@ $(LIB)
$(LD_SCRIPT): ld_script.txt $(BUILD_DIR)/sym_ewram.ld $(BUILD_DIR)/sym_ewram2.ld $(BUILD_DIR)/sym_iwram.ld
@ -131,3 +132,6 @@ $(BUILD_DIR)/data/%.o: data/%.s $$(ASM_DEP)
$(BUILD_DIR)/%.o: %.s $$(ASM_DEP)
$(AS) $(ASFLAGS) $< -o $@
libagbsyscall:
@$(MAKE) -C libagbsyscall TOOLCHAIN=$(TOOLCHAIN)

View File

@ -1,34 +0,0 @@
.include "asm/macros.inc"
.syntax unified
.text
thumb_func_start CpuSet
CpuSet:
swi 0xB
bx lr
thumb_func_end CpuSet
thumb_func_start SoundBiasReset
SoundBiasReset:
movs r0, 0
swi 0x19
bx lr
thumb_func_end SoundBiasReset
thumb_func_start SoundBiasSet
SoundBiasSet:
movs r0, 0x1
swi 0x19
bx lr
thumb_func_end SoundBiasSet
thumb_func_start VBlankIntrWait
VBlankIntrWait:
movs r2, 0
swi 0x5
bx lr
thumb_func_end VBlankIntrWait
.align 2, 0 @ Don't pad with nop.

View File

@ -12,14 +12,14 @@ SECTIONS {
ewram_start = .;
INCLUDE "sym_ewram.ld"
src/agb_flash.o(.bss);
tools/agbcc/lib/libgcc.a:fp-bit.o(.bss);
tools/agbcc/lib/libgcc.a:dp-bit.o(.bss);
tools/agbcc/lib/libc.a:syscalls.o(.bss);
*libgcc.a:fp-bit.o(.bss);
*libgcc.a:dp-bit.o(.bss);
*libc.a:syscalls.o(.bss);
. = ALIGN(16);
INCLUDE "sym_ewram2.ld"
tools/agbcc/lib/libc.a:impure.o(.data);
tools/agbcc/lib/libc.a:locale.o(.data);
tools/agbcc/lib/libc.a:mallocr.o(.data);
*libc.a:impure.o(.data);
*libc.a:locale.o(.data);
*libc.a:mallocr.o(.data);
gUnknown_203BC04 = .;
. = 0x40000;
}
@ -123,62 +123,65 @@ SECTIONS {
src/m4a_2.o(.text);
asm/m4a_3.o(.text);
src/m4a_4.o(.text);
asm/syscall.o(.text);
*libagbsyscall.a:CpuSet.o(.text);
*libagbsyscall.a:SoundBiasReset.o(.text);
*libagbsyscall.a:SoundBiasSet.o(.text);
*libagbsyscall.a:VBlankIntrWait.o(.text);
src/agb_flash.o(.text);
src/agb_flash_1m.o(.text);
src/agb_flash_mx.o(.text);
src/agb_flash_le.o(.text);
tools/agbcc/lib/libgcc.a:_call_via_rX.o(.text);
tools/agbcc/lib/libgcc.a:_divsi3.o(.text);
tools/agbcc/lib/libgcc.a:_dvmd_tls.o(.text);
tools/agbcc/lib/libgcc.a:_fixunssfsi.o(.text);
tools/agbcc/lib/libgcc.a:_modsi3.o(.text);
tools/agbcc/lib/libgcc.a:_umodsi3.o(.text);
tools/agbcc/lib/libgcc.a:fp-bit.o(.text);
tools/agbcc/lib/libgcc.a:_muldi3.o(.text);
tools/agbcc/lib/libgcc.a:dp-bit.o(.text);
tools/agbcc/lib/libgcc.a:_lshrdi3.o(.text);
tools/agbcc/lib/libgcc.a:_negdi2.o(.text);
tools/agbcc/lib/libc.a:memcpy.o(.text);
tools/agbcc/lib/libc.a:memset.o(.text);
tools/agbcc/lib/libc.a:sprintf.o(.text);
tools/agbcc/lib/libc.a:strcat.o(.text);
tools/agbcc/lib/libc.a:strcmp.o(.text);
tools/agbcc/lib/libc.a:strcpy.o(.text);
tools/agbcc/lib/libc.a:strlen.o(.text);
tools/agbcc/lib/libc.a:strncpy.o(.text);
tools/agbcc/lib/libc.a:vfprintf.o(.text);
tools/agbcc/lib/libc.a:vsprintf.o(.text);
tools/agbcc/lib/libc.a:wsetup.o(.text);
tools/agbcc/lib/libc.a:dtoa.o(.text);
tools/agbcc/lib/libc.a:fflush.o(.text);
tools/agbcc/lib/libc.a:findfp.o(.text);
tools/agbcc/lib/libc.a:freer.o(.text);
tools/agbcc/lib/libc.a:fvwrite.o(.text);
tools/agbcc/lib/libc.a:fwalk.o(.text);
tools/agbcc/lib/libc.a:locale.o(.text);
tools/agbcc/lib/libc.a:makebuf.o(.text);
tools/agbcc/lib/libc.a:mallocr.o(.text);
tools/agbcc/lib/libc.a:mbtowc_r.o(.text);
tools/agbcc/lib/libc.a:memchr.o(.text);
tools/agbcc/lib/libc.a:memmove.o(.text);
tools/agbcc/lib/libc.a:mlock.o(.text);
tools/agbcc/lib/libc.a:mprec.o(.text);
tools/agbcc/lib/libc.a:s_isinf.o(.text);
tools/agbcc/lib/libc.a:s_isnan.o(.text);
tools/agbcc/lib/libc.a:sbrkr.o(.text);
tools/agbcc/lib/libc.a:stdio.o(.text);
tools/agbcc/lib/libc.a:syscalls.o(.text);
tools/agbcc/lib/libc.a:writer.o(.text);
tools/agbcc/lib/libc.a:callocr.o(.text);
tools/agbcc/lib/libc.a:closer.o(.text);
tools/agbcc/lib/libc.a:errno.o(.text);
tools/agbcc/lib/libc.a:fstatr.o(.text);
tools/agbcc/lib/libc.a:abort.o(.text);
tools/agbcc/lib/libc.a:libcfunc.o(.text);
tools/agbcc/lib/libc.a:lseekr.o(.text);
tools/agbcc/lib/libc.a:readr.o(.text);
tools/agbcc/lib/libgcc.a:_udivsi3.o(.text);
*libgcc.a:_call_via_rX.o(.text);
*libgcc.a:_divsi3.o(.text);
*libgcc.a:_dvmd_tls.o(.text);
*libgcc.a:_fixunssfsi.o(.text);
*libgcc.a:_modsi3.o(.text);
*libgcc.a:_umodsi3.o(.text);
*libgcc.a:fp-bit.o(.text);
*libgcc.a:_muldi3.o(.text);
*libgcc.a:dp-bit.o(.text);
*libgcc.a:_lshrdi3.o(.text);
*libgcc.a:_negdi2.o(.text);
*libc.a:memcpy.o(.text);
*libc.a:memset.o(.text);
*libc.a:sprintf.o(.text);
*libc.a:strcat.o(.text);
*libc.a:strcmp.o(.text);
*libc.a:strcpy.o(.text);
*libc.a:strlen.o(.text);
*libc.a:strncpy.o(.text);
*libc.a:vfprintf.o(.text);
*libc.a:vsprintf.o(.text);
*libc.a:wsetup.o(.text);
*libc.a:dtoa.o(.text);
*libc.a:fflush.o(.text);
*libc.a:findfp.o(.text);
*libc.a:freer.o(.text);
*libc.a:fvwrite.o(.text);
*libc.a:fwalk.o(.text);
*libc.a:locale.o(.text);
*libc.a:makebuf.o(.text);
*libc.a:mallocr.o(.text);
*libc.a:mbtowc_r.o(.text);
*libc.a:memchr.o(.text);
*libc.a:memmove.o(.text);
*libc.a:mlock.o(.text);
*libc.a:mprec.o(.text);
*libc.a:s_isinf.o(.text);
*libc.a:s_isnan.o(.text);
*libc.a:sbrkr.o(.text);
*libc.a:stdio.o(.text);
*libc.a:syscalls.o(.text);
*libc.a:writer.o(.text);
*libc.a:callocr.o(.text);
*libc.a:closer.o(.text);
*libc.a:errno.o(.text);
*libc.a:fstatr.o(.text);
*libc.a:abort.o(.text);
*libc.a:libcfunc.o(.text);
*libc.a:lseekr.o(.text);
*libc.a:readr.o(.text);
*libgcc.a:_udivsi3.o(.text);
} =0
.rodata :
@ -195,13 +198,13 @@ SECTIONS {
src/agb_flash_1m.o(.rodata);
src/agb_flash_mx.o(.rodata);
src/agb_flash_le.o(.rodata);
tools/agbcc/lib/libc.a:sprintf.o(.rodata);
tools/agbcc/lib/libc.a:vfprintf.o(.rodata);
tools/agbcc/lib/libc.a:dtoa.o(.rodata);
tools/agbcc/lib/libc.a:impure.o(.rodata);
tools/agbcc/lib/libc.a:locale.o(.rodata);
tools/agbcc/lib/libc.a:mprec.o(.rodata);
tools/agbcc/lib/libc.a:syscalls.o(.rodata);
*libc.a:sprintf.o(.rodata);
*libc.a:vfprintf.o(.rodata);
*libc.a:dtoa.o(.rodata);
*libc.a:impure.o(.rodata);
*libc.a:locale.o(.rodata);
*libc.a:mprec.o(.rodata);
*libc.a:syscalls.o(.rodata);
. = ALIGN(4);
data/data_8270000.o(.rodata);
} =0

98
libagbsyscall/Makefile Normal file
View File

@ -0,0 +1,98 @@
TOOLCHAIN := $(DEVKITARM)
COMPARE ?= 0
ifeq ($(CC),)
HOSTCC := gcc
else
HOSTCC := $(CC)
endif
ifeq ($(CXX),)
HOSTCXX := g++
else
HOSTCXX := $(CXX)
endif
ifneq (,$(wildcard $(TOOLCHAIN)/base_tools))
include $(TOOLCHAIN)/base_tools
else
export PATH := $(TOOLCHAIN)/bin:$(PATH)
PREFIX := arm-none-eabi-
OBJCOPY := $(PREFIX)objcopy
export CC := $(PREFIX)gcc
export AS := $(PREFIX)as
endif
export CPP := $(PREFIX)cpp
export LD := $(PREFIX)ld
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
ASFLAGS := -mcpu=arm7tdmi
ARFLAGS := rc
SYSCALLS := IntrWait \
RegisterRamReset \
Sqrt \
MusicPlayerOpen \
SoundBiasReset \
SoundDriverVSyncOn \
Mod \
VBlankIntrWait \
MusicPlayerStart \
SoundDriverVSyncOff \
HuffUnComp \
SoftResetExram \
MusicPlayerFadeOut \
LZ77UnCompWram \
SoundDriverMain \
SoundBiasChange \
LZ77UnCompVram \
ArcTan2 \
MusicPlayerStop \
DivArm \
ModArm \
SoundDriverVSync \
SoundDriverInit \
BgAffineSet \
Diff8bitUnFilterWram \
MultiBoot \
MidiKey2Freq \
Div \
Diff8bitUnFilterVram \
ArcTan \
ObjAffineSet \
SoftResetRom \
SoundDriverMode \
RLUnCompWram \
BitUnPack \
SoundChannelClear \
CpuFastSet \
CpuSet \
Diff16bitUnFilter \
SoundBiasSet \
MusicPlayerContinue \
SoftReset \
RLUnCompVram
ASM_SRCS := libagbsyscall.s
ASM_OBJS := $(foreach syscall, $(SYSCALLS), $(syscall).o)
LIB := libagbsyscall.a
.PHONY: all clean
all: $(LIB)
@:
clean:
rm -f $(LIB) $(ASM_OBJS)
$(LIB): $(ASM_OBJS)
$(AR) $(ARFLAGS) $@ $^
$(ASM_OBJS): libagbsyscall.s
$(AS) $(ASFLAGS) --defsym L_$(*F)=1 -o $@ $<

View File

@ -0,0 +1,435 @@
.include "../constants/gba_constants.inc"
.include "../asm/macros/function.inc"
.syntax unified
.text
.set SOFT_RESET_DIRECT_BUF, 0x03007FFA
.set USER_STACK, 0x03007F00
.set RESET_EX_WRAM_FLAG, 0x1
.ifdef NO_GRANULAR_AGBSYSCALL
.set L_IntrWait, 1
.set L_RegisterRamReset, 1
.set L_Sqrt, 1
.set L_MusicPlayerOpen, 1
.set L_SoundBiasReset, 1
.set L_SoundDriverVSyncOn, 1
.set L_Mod, 1
.set L_VBlankIntrWait, 1
.set L_MusicPlayerStart, 1
.set L_SoundDriverVSyncOff, 1
.set L_HuffUnComp, 1
.set L_SoftResetExram, 1
.set L_MusicPlayerFadeOut, 1
.set L_LZ77UnCompWram, 1
.set L_SoundDriverMain, 1
.set L_SoundBiasChange, 1
.set L_LZ77UnCompVram, 1
.set L_ArcTan2, 1
.set L_MusicPlayerStop, 1
.set L_DivArm, 1
.set L_ModArm, 1
.set L_SoundDriverVSync, 1
.set L_SoundDriverInit, 1
.set L_BgAffineSet, 1
.set L_Diff8bitUnFilterWram, 1
.set L_MultiBoot, 1
.set L_MidiKey2Freq, 1
.set L_Div, 1
.set L_Diff8bitUnFilterVram, 1
.set L_ArcTan, 1
.set L_ObjAffineSet, 1
.set L_SoftResetRom, 1
.set L_SoundDriverMode, 1
.set L_RLUnCompWram, 1
.set L_BitUnPack, 1
.set L_SoundChannelClear, 1
.set L_CpuFastSet, 1
.set L_CpuSet, 1
.set L_Diff16bitUnFilter, 1
.set L_SoundBiasSet, 1
.set L_MusicPlayerContinue, 1
.set L_SoftReset, 1
.set L_RLUnCompVram, 1
.endif
.ifdef L_IntrWait
thumb_func_start IntrWait
IntrWait:
movs r2, #0
svc #4
bx lr
thumb_func_end IntrWait
.endif
.ifdef L_RegisterRamReset
thumb_func_start RegisterRamReset
RegisterRamReset:
svc #1
bx lr
thumb_func_end RegisterRamReset
.endif
.ifdef L_Sqrt
thumb_func_start Sqrt
Sqrt:
svc #8
bx lr
thumb_func_end Sqrt
.endif
.ifdef L_MusicPlayerOpen
thumb_func_start MusicPlayerOpen
MusicPlayerOpen:
svc #32
bx lr
thumb_func_end MusicPlayerOpen
.endif
.ifdef L_SoundBiasReset
thumb_func_start SoundBiasReset
SoundBiasReset:
movs r0, #0
svc #25
bx lr
thumb_func_end SoundBiasReset
.endif
.ifdef L_SoundDriverVSyncOn
thumb_func_start SoundDriverVSyncOn
SoundDriverVSyncOn:
svc #41
bx lr
thumb_func_end SoundDriverVSyncOn
.endif
.ifdef L_Mod
thumb_func_start Mod
Mod:
svc #6
adds r0, r1, #0
bx lr
thumb_func_end Mod
.endif
.ifdef L_VBlankIntrWait
thumb_func_start VBlankIntrWait
VBlankIntrWait:
movs r2, #0
svc #5
bx lr
thumb_func_end VBlankIntrWait
.endif
.ifdef L_MusicPlayerStart
thumb_func_start MusicPlayerStart
MusicPlayerStart:
svc #33
bx lr
thumb_func_end MusicPlayerStart
.endif
.ifdef L_SoundDriverVSyncOff
thumb_func_start SoundDriverVSyncOff
SoundDriverVSyncOff:
svc #40
bx lr
thumb_func_end SoundDriverVSyncOff
.endif
.ifdef L_HuffUnComp
thumb_func_start HuffUnComp
HuffUnComp:
svc #19
bx lr
thumb_func_end HuffUnComp
.endif
.ifdef L_SoftResetExram
thumb_func_start SoftResetExram
SoftResetExram:
ldr r3, =REG_IME
movs r2, #0
strb r2, [r3, #0]
ldr r3, =SOFT_RESET_DIRECT_BUF
movs r2, #1
strb r2, [r3, #0]
subs r3, #SOFT_RESET_DIRECT_BUF - USER_STACK
mov sp, r3
movs r2, #RESET_EX_WRAM_FLAG
bics r0, r2
svc #1
svc #0
.pool
thumb_func_end SoftResetExram
.endif
.ifdef L_MusicPlayerFadeOut
thumb_func_start MusicPlayerFadeOut
MusicPlayerFadeOut:
svc #36
bx lr
thumb_func_end MusicPlayerFadeOut
.endif
.ifdef L_LZ77UnCompWram
thumb_func_start LZ77UnCompWram
LZ77UnCompWram:
svc #17
bx lr
thumb_func_end LZ77UnCompWram
.endif
.ifdef L_SoundDriverMain
thumb_func_start SoundDriverMain
SoundDriverMain:
svc #28
bx lr
thumb_func_end SoundDriverMain
.endif
.ifdef L_SoundBiasChange
thumb_func_start SoundBiasChange
SoundBiasChange:
svc #25
bx lr
thumb_func_end SoundBiasChange
.endif
.ifdef L_LZ77UnCompVram
thumb_func_start LZ77UnCompVram
LZ77UnCompVram:
svc #18
bx lr
thumb_func_end LZ77UnCompVram
.endif
.ifdef L_ArcTan2
thumb_func_start ArcTan2
ArcTan2:
svc #10
bx lr
thumb_func_end ArcTan2
.endif
.ifdef L_MusicPlayerStop
thumb_func_start MusicPlayerStop
MusicPlayerStop:
svc #34
bx lr
thumb_func_end MusicPlayerStop
.endif
.ifdef L_DivArm
thumb_func_start DivArm
DivArm:
svc #7
bx lr
thumb_func_end DivArm
.endif
.ifdef L_ModArm
thumb_func_start ModArm
ModArm:
svc #7
adds r0, r1, #0
bx lr
thumb_func_end ModArm
.endif
.ifdef L_SoundDriverVSync
thumb_func_start SoundDriverVSync
SoundDriverVSync:
svc #29
bx lr
thumb_func_end SoundDriverVSync
.endif
.ifdef L_SoundDriverInit
thumb_func_start SoundDriverInit
SoundDriverInit:
svc #26
bx lr
thumb_func_end SoundDriverInit
.endif
.ifdef L_BgAffineSet
thumb_func_start BgAffineSet
BgAffineSet:
svc #14
bx lr
thumb_func_end BgAffineSet
.endif
.ifdef L_Diff8bitUnFilterWram
thumb_func_start Diff8bitUnFilterWram
Diff8bitUnFilterWram:
svc #22
bx lr
thumb_func_end Diff8bitUnFilterWram
.endif
.ifdef L_MultiBoot
thumb_func_start MultiBoot
MultiBoot:
movs r1, #1
svc #37
bx lr
thumb_func_end MultiBoot
.endif
.ifdef L_MidiKey2Freq
thumb_func_start MidiKey2Freq
MidiKey2Freq:
svc #31
bx lr
thumb_func_end MidiKey2Freq
.endif
.ifdef L_Div
thumb_func_start Div
Div:
svc #6
bx lr
thumb_func_end Div
.endif
.ifdef L_Diff8bitUnFilterVram
thumb_func_start Diff8bitUnFilterVram
Diff8bitUnFilterVram:
svc #23
bx lr
thumb_func_end Diff8bitUnFilterVram
.endif
.ifdef L_ArcTan
thumb_func_start ArcTan
ArcTan:
svc #9
bx lr
thumb_func_end ArcTan
.endif
.ifdef L_ObjAffineSet
thumb_func_start ObjAffineSet
ObjAffineSet:
svc #15
bx lr
thumb_func_end ObjAffineSet
.endif
.ifdef L_SoftResetRom
thumb_func_start SoftResetRom
SoftResetRom:
ldr r3, =REG_IME
movs r2, #0
strb r2, [r3, #0]
ldr r3, =SOFT_RESET_DIRECT_BUF
movs r2, #0
strb r2, [r3, #0]
subs r3, #SOFT_RESET_DIRECT_BUF - USER_STACK
mov sp, r3
svc #1
svc #0
.pool
thumb_func_end SoftResetRom
.endif
.ifdef L_SoundDriverMode
thumb_func_start SoundDriverMode
SoundDriverMode:
svc #27
bx lr
thumb_func_end SoundDriverMode
.endif
.ifdef L_RLUnCompWram
thumb_func_start RLUnCompWram
RLUnCompWram:
svc #20
bx lr
thumb_func_end RLUnCompWram
.endif
.ifdef L_BitUnPack
thumb_func_start BitUnPack
BitUnPack:
svc #16
bx lr
thumb_func_end BitUnPack
.endif
.ifdef L_SoundChannelClear
thumb_func_start SoundChannelClear
SoundChannelClear:
svc #30
bx lr
thumb_func_end SoundChannelClear
.endif
.ifdef L_CpuFastSet
thumb_func_start CpuFastSet
CpuFastSet:
svc #12
bx lr
thumb_func_end CpuFastSet
.endif
.ifdef L_CpuSet
thumb_func_start CpuSet
CpuSet:
svc #11
bx lr
thumb_func_end CpuSet
.endif
.ifdef L_Diff16bitUnFilter
thumb_func_start Diff16bitUnFilter
Diff16bitUnFilter:
svc #24
bx lr
thumb_func_end Diff16bitUnFilter
.endif
.ifdef L_SoundBiasSet
thumb_func_start SoundBiasSet
SoundBiasSet:
movs r0, #1
svc #25
bx lr
thumb_func_end SoundBiasSet
.endif
.ifdef L_MusicPlayerContinue
thumb_func_start MusicPlayerContinue
MusicPlayerContinue:
svc #35
bx lr
thumb_func_end MusicPlayerContinue
.endif
.ifdef L_SoftReset
thumb_func_start SoftReset
SoftReset:
ldr r3, =REG_IME
movs r2, #0
strb r2, [r3, #0]
ldr r1, =USER_STACK
mov sp, r1
svc #1
svc #0
.pool
thumb_func_end SoftReset
.endif
.ifdef L_RLUnCompVram
thumb_func_start RLUnCompVram
RLUnCompVram:
svc #21
bx lr
thumb_func_end RLUnCompVram
.endif
.align 2, 0 @ Don't pad with nop