diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2020-06-06 15:29:42 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2020-06-06 15:29:42 -0400 |
commit | 5f236d558aa37918f0286383ba9489a550283d7f (patch) | |
tree | e0b772d6526594a8c737949cae2d5e636fdba876 | |
parent | 760a22318663896b2ebd76d8d3213dcc9e9bcfe5 (diff) |
libsyscall.a source
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | Makefile | 17 | ||||
-rw-r--r-- | arm9/Makefile | 18 | ||||
-rw-r--r-- | arm9/arm9.lcf | 3 | ||||
-rw-r--r-- | arm9/lib/Makefile | 89 | ||||
-rw-r--r-- | arm9/lib/syscall/_svc_mw.s | 121 | ||||
-rw-r--r-- | arm9/modules/01/src/module_01.cpp | 14 | ||||
-rw-r--r-- | include/nitro/types.h | 2 | ||||
-rw-r--r-- | include/sinit.h | 10 |
9 files changed, 252 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index aac9651e..abf430db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,8 @@ set(CMAKE_CXX_STANDARD 11) enable_language(ASM) +add_compile_options(-fms-extensions) + file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "*.c" "*.cpp") add_executable(PokeDiamond ${SOURCES}) @@ -204,6 +204,7 @@ TOOLS = $(foreach tool,$(TOOLBASE),$(TOOLS_DIR)/$(tool)/$(tool)$(EXE)) export LM_LICENSE_FILE := $(TOOLS_DIR)/mwccarm/license.dat export MWCIncludes := arm9/lib/include +export MWLibraries := arm9/lib ######################### Targets ########################### @@ -220,7 +221,7 @@ endif .SECONDARY: .DELETE_ON_ERROR: .SECONDEXPANSION: -.PHONY: all clean mostlyclean tidy tools $(TOOLDIRS) patch_mwasmarm arm9 arm7 +.PHONY: all libs clean mostlyclean tidy tools $(TOOLDIRS) patch_mwasmarm arm9 arm7 MAKEFLAGS += --no-print-directory @@ -230,18 +231,18 @@ ifeq ($(COMPARE),1) endif clean: mostlyclean - make -C arm9 clean - make -C arm7 clean - make -C tools/mwasmarm_patcher clean + $(MAKE) -C arm9 clean + $(MAKE) -C arm7 clean + $(MAKE) -C tools/mwasmarm_patcher clean mostlyclean: tidy - make -C arm9 mostlyclean - make -C arm7 mostlyclean + $(MAKE) -C arm9 mostlyclean + $(MAKE) -C arm7 mostlyclean find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' \) -exec $(RM) {} + tidy: - make -C arm9 tidy - make -C arm7 tidy + $(MAKE) -C arm9 tidy + $(MAKE) -C arm7 tidy $(RM) -r $(BUILD_DIR) tools: $(TOOLDIRS) diff --git a/arm9/Makefile b/arm9/Makefile index df04770c..0b880bd3 100644 --- a/arm9/Makefile +++ b/arm9/Makefile @@ -186,7 +186,8 @@ OBJCOPY := $(CROSS)objcopy ASFLAGS = -proc arm5te -i .. CFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -i ../include -ir ../include-mw -ir lib/include -interworking -DFS_IMPLEMENT -enum int -W all -D$(GAME_VERSION) -D$(GAME_LANGUAGE) CXXFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -i ../include -ir ../include-mw -ir lib/include -interworking -DFS_IMPLEMENT -enum int -W all -D$(GAME_VERSION) -D$(GAME_LANGUAGE) -LDFLAGS = -map -nodead -w off -proc v5te -interworking -map -symtab -m _start +LDFLAGS = -nodead -w off -proc v5te -interworking -map closure,unused -symtab sort -m _start +# LIBS := -Llib -lsyscall ####################### Other Tools ######################### @@ -202,7 +203,8 @@ TOOLBASE = $(TOOLDIRS:$(TOOLS_DIR)/%=%) TOOLS = $(foreach tool,$(TOOLBASE),$(TOOLS_DIR)/$(tool)/$(tool)$(EXE)) export LM_LICENSE_FILE := $(TOOLS_DIR)/mwccarm/license.dat -export MWCIncludes := lib/include +export MWCIncludes := $(CURDIR)/lib/include +export MWLibraries := $(CURDIR)/lib ######################### Targets ########################### @@ -217,24 +219,28 @@ NODEP := 1 endif .PRECIOUS: $(ROM) -.PHONY: all clean mostlyclean tidy tools $(TOOLDIRS) patch_mwasmarm +.PHONY: all libs clean mostlyclean tidy tools $(TOOLDIRS) patch_mwasmarm MAKEFLAGS += --no-print-directory -all: $(ROM) +all: libs $(ROM) ifeq ($(COMPARE),1) @$(SHA1SUM) -c $(TARGET).sha1 @echo $(ROM): OK endif +libs: + $(MAKE) -C lib + clean: mostlyclean - make -C $(TOOLS_DIR)/mwasmarm_patcher clean + $(MAKE) -C $(TOOLS_DIR)/mwasmarm_patcher clean mostlyclean: tidy find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' \) -exec $(RM) {} + tidy: $(RM) -r $(BUILD_DIR) + $(MAKE) clean -C lib tools: $(TOOLDIRS) @@ -277,7 +283,7 @@ $(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT) $(CPP) $(VERSION_CFLAGS) -MMD -MP -MT $@ -MF $@.d -I include/ -I . -DBUILD_DIR=$(BUILD_DIR) -o $@ $< $(ROM): $(O_FILES) $(BUILD_DIR)/$(LD_SCRIPT) $(BIN_FILES) - $(LD) $(LDFLAGS) $(BUILD_DIR)/$(LD_SCRIPT) -o $(ELF) $(O_FILES) $(BIN_FILES) + $(LD) $(LDFLAGS) $(LIBS) $(BUILD_DIR)/$(LD_SCRIPT) -o $(ELF) $(O_FILES) $(BIN_FILES) $(OBJCOPY) --update-section arm9=$@ -j arm9 $(foreach ov,$(OVERLAYS),--update-section $(ov)=$(BUILD_DIR)/$(ov).sbin -j $(ov)) $(ELF) 2>/dev/null # Make sure build directory exists before compiling anything diff --git a/arm9/arm9.lcf b/arm9/arm9.lcf index fced9d86..9fb4de49 100644 --- a/arm9/arm9.lcf +++ b/arm9/arm9.lcf @@ -117,7 +117,8 @@ SECTIONS { ALIGNALL(4); . = ALIGN(32); SDK_STATIC_START = .; SDK_STATIC_TEXT_START = .; - secure.o (.text) + /* libsyscall.a (.text) */ + secure.o (.text) /* is actually libsyscall with nitro encryption */ crt0.o (.text) crt0.o (.rodata) * (.version) diff --git a/arm9/lib/Makefile b/arm9/lib/Makefile new file mode 100644 index 00000000..c0e95ade --- /dev/null +++ b/arm9/lib/Makefile @@ -0,0 +1,89 @@ + + +# Try to include devkitarm if installed +TOOLCHAIN := $(DEVKITARM) + +ifneq (,$(wildcard $(TOOLCHAIN)/base_tools)) +include $(TOOLCHAIN)/base_tools +endif + +### Default target ### + +default: all + +# If you are using WSL, it is recommended you build with NOWINE=1. +WSLENV ?= no +ifeq ($(WSLENV),) +NOWINE = 1 +else +NOWINE = 0 +endif + +ifeq ($(OS),Windows_NT) +EXE := .exe +WINE := +else +EXE := +WINE := wine +endif + +ifeq ($(NOWINE),1) +WINE := +endif + +# Compare result of arm9, arm7, and ROM to sha1 hash(s) +COMPARE ?= 1 + +##################### Compiler Options ####################### + +MWCCVERSION = 1.2/sp2p3 + +CROSS := arm-none-eabi- + +MWCCARM = ../../tools/mwccarm/$(MWCCVERSION)/mwccarm.exe +# Argh... due to EABI version shenanigans, we can't use GNU LD to link together +# MWCC built objects and GNU built ones. mwldarm, however, doesn't care, so we +# have to use mwldarm for now. +# TODO: Is there a hack workaround to let us go back to GNU LD? Ideally, the +# only dependency should be MWCCARM. +MWLDARM = ../../tools/mwccarm/$(MWCCVERSION)/mwldarm.exe +MWASMARM = ../../tools/mwccarm/$(MWCCVERSION)/mwasmarm.exe +NARCCOMP = ../../tools/narccomp/narccomp$(EXE) +SCANINC = ../../tools/scaninc/scaninc$(EXE) + +AS = $(WINE) $(MWASMARM) +CC = $(WINE) $(MWCCARM) +CPP := cpp -P +LD = $(WINE) $(MWLDARM) +AR := $(CROSS)ar +OBJDUMP := $(CROSS)objdump +OBJCOPY := $(CROSS)objcopy + +# ./tools/mwccarm/2.0/base/mwasmarm.exe -proc arm5te asm/arm9_thumb.s -o arm9.o +ASFLAGS = -proc arm5te -ir ../.. +CFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -i include -ir include-mw -ir arm9/lib/include -W all +LDFLAGS = -library -nodead -w off -proc v5te -interworking -pic +ARFLAGS = rcS + +export MWCIncludes := include + +################ Targets ################# + +LIBS := libsyscall.a +.PHONY: all clean + +all: $(LIBS) + +clean: + $(RM) $(LIBS) $(LIBS:%.a=%/*.o) + +libsyscall.a: syscall/_svc_mw.o + +%.a: + $(AR) $(ARFLAGS) -o $@ $^ + +%.o: %.c + $(CC) $(CFLAGS) -o $@ $< + +%.o: %.s + $(AS) $(ASFLAGS) -o $@ $< diff --git a/arm9/lib/syscall/_svc_mw.s b/arm9/lib/syscall/_svc_mw.s new file mode 100644 index 00000000..c1e36b4b --- /dev/null +++ b/arm9/lib/syscall/_svc_mw.s @@ -0,0 +1,121 @@ + .include "asm/macros.inc" + + .text + ; NITRO SYSCALL LIBRARY + ; VERSION 3.2 + + ; Secure area + .space 0x800 + + non_word_aligned_thumb_func_start SVC_SoftReset +SVC_SoftReset: + swi 0 + bx lr + thumb_func_end SVC_SoftReset + + non_word_aligned_thumb_func_start SVC_WaitByLoop +SVC_WaitByLoop: + swi 3 + bx lr + thumb_func_end SVC_WaitByLoop + + non_word_aligned_thumb_func_start SVC_WaitIntr +SVC_WaitIntr: + mov r2, #0 + swi 4 + bx lr + thumb_func_end SVC_WaitIntr + + non_word_aligned_thumb_func_start SVC_WaitVBlankIntr +SVC_WaitVBlankIntr: + mov r2, #0 + swi 5 + bx lr + thumb_func_end SVC_WaitVBlankIntr + + non_word_aligned_thumb_func_start SVC_Halt +SVC_Halt: + swi 6 + bx lr + thumb_func_end SVC_Halt + + non_word_aligned_thumb_func_start SVC_Div +SVC_Div: + swi 9 + bx lr + thumb_func_end SVC_Div + + non_word_aligned_thumb_func_start SVC_DimRem +SVC_DivRem: + swi 9 + add r0, r1, #0 + bx lr + thumb_func_end SVC_DivRem + + non_word_aligned_thumb_func_start SVC_CpuSet +SVC_CpuSet: + swi 11 + bx lr + thumb_func_end SVC_CpuSet + + non_word_aligned_thumb_func_start SVC_CpuFastSet +SVC_CpuFastSet: + swi 12 + bx lr + thumb_func_end SVC_CpuFastSet + + non_word_aligned_thumb_func_start SVC_Sqrt +SVC_Sqrt: + swi 13 + bx lr + thumb_func_end SVC_Sqrt + + non_word_aligned_thumb_func_start SVC_GetCRC16 +SVC_GetCRC16: + swi 14 + bx lr + thumb_func_end SVC_GetCRC16 + + non_word_aligned_thumb_func_start IsMemExpanded +IsMemExpanded: + swi 15 + bx lr + thumb_func_end IsMemExpanded + + non_word_aligned_thumb_func_start SVC_UnpackBits +SVC_UnpackBits: + swi 16 + bx lr + thumb_func_end SVC_UnpackBits + + non_word_aligned_thumb_func_start SVC_UncompressLZ8 +SVC_UncompressLZ8: + swi 17 + bx lr + thumb_func_end SVC_UncompressLZ8 + + non_word_aligned_thumb_func_start SVC_UncompressLZ16FromDevice +SVC_UncompressLZ16FromDevice: + swi 18 + bx lr + thumb_func_end SVC_UncompressLZ16FromDevice + + non_word_aligned_thumb_func_start SVC_UncompressHuffmanFromDevice +SVC_UncompressHuffmanFromDevice: + swi 19 + bx lr + thumb_func_end SVC_UncompressHuffmanFromDevice + + non_word_aligned_thumb_func_start SVC_UncompressRL8 +SVC_UncompressRL8: + swi 20 + bx lr + thumb_func_end SVC_UncompressRL8 + + non_word_aligned_thumb_func_start SVC_UncompressRL16FromDevice +SVC_UncompressRL16FromDevice: + swi 21 + bx lr + thumb_func_end SVC_UncompressRL16FromDevice + + .balign 4, 0 ; Don't pad with nop diff --git a/arm9/modules/01/src/module_01.cpp b/arm9/modules/01/src/module_01.cpp index 9da5f8d5..1f9f0edc 100644 --- a/arm9/modules/01/src/module_01.cpp +++ b/arm9/modules/01/src/module_01.cpp @@ -1,11 +1,7 @@ #include "global.h" -#include "FS_overlay.h" +#include "sinit.h" -class Unk021D7500 { - u32 unk0; - u32 unk4; -public: - THUMB_FUNC Unk021D7500() { unk4++; } -}; - -static Unk021D7500 UNK_021D7500; +THUMB_FUNC static void NitroStaticInit(void) { + static u32 var[2]; + var[1]++; +} diff --git a/include/nitro/types.h b/include/nitro/types.h index 190d9eae..dfa5ba87 100644 --- a/include/nitro/types.h +++ b/include/nitro/types.h @@ -54,4 +54,6 @@ typedef int BOOL; #endif // __cplusplus #endif +#define SDK_FORCE_EXPORT __declspec(force_export) + #endif //POKEDIAMOND_TYPES_H diff --git a/include/sinit.h b/include/sinit.h new file mode 100644 index 00000000..47fe4438 --- /dev/null +++ b/include/sinit.h @@ -0,0 +1,10 @@ +#ifndef GUARD_SINIT_H +#define GUARD_SINIT_H + +static void NitroStaticInit(void); +#pragma define_section SINIT ".sinit" abs32 RWX +#pragma section SINIT begin +SDK_FORCE_EXPORT static void (*NitroStaticInit_[])(void) = { NitroStaticInit }; +#pragma section SINIT end + +#endif //GUARD_SINIT_H |