From ab2b953eb9f7da5adef42a845c57f5d1a00d6afc Mon Sep 17 00:00:00 2001 From: Adrian <127942625+Adrian8115@users.noreply.github.com> Date: Mon, 11 Sep 2023 19:02:30 +0200 Subject: [PATCH] Add files via upload --- Makefile | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ linker_bin.ld | 28 ++++++++++++++++++++ linker_hhk.ld | 5 ++++ 3 files changed, 106 insertions(+) create mode 100644 Makefile create mode 100644 linker_bin.ld create mode 100644 linker_hhk.ld diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f0ad8bc --- /dev/null +++ b/Makefile @@ -0,0 +1,73 @@ +# run `make all` to compile the .hhk and .bin file, use `make` to compile only the .bin file. +# The .hhk file is the original format, the bin file is a newer format. +APP_NAME:=3dRenderer + +ifndef SDK_DIR +$(error You need to define the SDK_DIR environment variable, and point it to the sdk/ folder) +endif + +AS:=sh4-elf-as +AS_FLAGS:= + +CC:=sh4-elf-gcc +CC_FLAGS:=-ffreestanding -fshort-wchar -Wall -Wextra -O2 -I $(SDK_DIR)/include/ -I $(SDK_DIR)/newlib/sh-elf/include/ -I /home/adrian/hollyhock-2/app_template/src/include/ + +CXX:=sh4-elf-g++ +CXX_FLAGS:=-ffreestanding -fno-exceptions -fno-rtti -fshort-wchar -Wall -Wextra -O2 -fpermissive -I $(SDK_DIR)/include/ -m4a-nofpu -I $(SDK_DIR)/newlib/sh-elf/include/ + +LD:=sh4-elf-gcc +LD_FLAGS:=-nostartfiles -m4-nofpu -Wno-undef -L$(SDK_DIR)/newlib/sh-elf/lib -lm + +READELF:=sh4-elf-readelf +OBJCOPY:=sh4-elf-objcopy + +AS_SOURCES:=$(wildcard *.s) +CC_SOURCES:=$(wildcard *.c) +CXX_SOURCES := $(wildcard src/*.cpp) +OBJECTS:=$(AS_SOURCES:.s=.o) $(CC_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o) + +APP_ELF:=$(APP_NAME).hhk +APP_BIN:=$(APP_NAME).bin + +bin: $(APP_BIN) Makefile + +hhk: $(APP_ELF) Makefile + +all: $(APP_ELF) $(APP_BIN) Makefile + +clean: + rm -f $(OBJECTS) $(APP_ELF) $(APP_BIN) + +$(APP_ELF): $(OBJECTS) $(SDK_DIR)/sdk.o linker_hhk.ld + $(LD) -T linker_hhk.ld -o $@ $(LD_FLAGS) $(OBJECTS) $(SDK_DIR)/sdk.o + $(OBJCOPY) --set-section-flags .hollyhock_name=contents,strings,readonly $(APP_ELF) $(APP_ELF) + $(OBJCOPY) --set-section-flags .hollyhock_description=contents,strings,readonly $(APP_ELF) $(APP_ELF) + $(OBJCOPY) --set-section-flags .hollyhock_author=contents,strings,readonly $(APP_ELF) $(APP_ELF) + $(OBJCOPY) --set-section-flags .hollyhock_version=contents,strings,readonly $(APP_ELF) $(APP_ELF) + +$(APP_BIN): $(OBJECTS) $(SDK_DIR)/sdk.o linker_bin.ld + $(LD) -Wl,--oformat=binary -T linker_bin.ld -o $@ $(LD_FLAGS) $(OBJECTS) $(SDK_DIR)/sdk.o + +# We're not actually building sdk.o, just telling the user they need to do it +# themselves. Just using the target to trigger an error when the file is +# required but does not exist. +$(SDK_DIR)/sdk.o: + $(error You need to build the SDK before using it. Run make in the SDK directory, and check the README.md in the SDK directory for more information) + +%.o: %.s + $(AS) $< -o $@ $(AS_FLAGS) + +%.o: %.c + $(CC) -c $< -o $@ $(CC_FLAGS) + +# Break the build if global constructors are present: +# Read the sections from the object file (with readelf -S) and look for any +# called .ctors - if they exist, give the user an error message, delete the +# object file (so that on subsequent runs of make the build will still fail) +# and exit with an error code to halt the build. +src/%.o: src/%.cpp + $(CXX) -c $< -o $@ $(CXX_FLAGS) + @$(READELF) $@ -S | grep ".ctors" > /dev/null && echo "ERROR: Global constructors aren't supported." && rm $@ && exit 1 || exit 0 + + +.PHONY: bin hhk all clean \ No newline at end of file diff --git a/linker_bin.ld b/linker_bin.ld new file mode 100644 index 0000000..ed8efa6 --- /dev/null +++ b/linker_bin.ld @@ -0,0 +1,28 @@ +ENTRY(_main); + +SECTIONS { + start_address = 0x8CFF0000; + .init start_address : AT(start_address) { + *(.init) + } + info_address = 0x8CFF0010; + . = info_address; + .hollyhock_name : { + *(.hollyhock_name) + } + .hollyhock_description : { + *(.hollyhock_description) + } + .hollyhock_author : { + *(.hollyhock_author) + } + .hollyhock_version : { + *(.hollyhock_version) + } + .text : { + *(.text) + } +} + + + diff --git a/linker_hhk.ld b/linker_hhk.ld new file mode 100644 index 0000000..7217949 --- /dev/null +++ b/linker_hhk.ld @@ -0,0 +1,5 @@ +ENTRY(_main); + +SECTIONS { + . = 0x8CFF0000; +}