From e31d2c55fd9ed2eae577461d3cfeb7580f796e4c Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Mon, 23 Jan 2023 20:34:27 -0800 Subject: [PATCH] library-ify move Makefile to common.mk and add a LIB variable that makes it easy to use this from a subdirectory. Also fix section alignment issues in .text --- Makefile => common.mk | 35 +++++++++++++++++++++-------------- sh2.h | 2 +- sh2.lds | 4 ++-- type.h | 2 ++ 4 files changed, 26 insertions(+), 17 deletions(-) rename Makefile => common.mk (76%) diff --git a/Makefile b/common.mk similarity index 76% rename from Makefile rename to common.mk index 690d11f..1e5f937 100644 --- a/Makefile +++ b/common.mk @@ -1,11 +1,16 @@ +LIB ?= . + AARCH = --isa=sh2 --big AFLAGS = -g -gdwarf-4 +CFLAGS = -I$(LIB) CFLAGS += -ffunction-sections -fshort-enums -ffreestanding -nostdlib CFLAGS += -Wall -Werror -Wfatal-errors -Wno-error=unused-variable -g -gdwarf-4 -Og +CXXFLAGS = -fno-exceptions -fno-rtti CARCH = -m2 -mb TARGET = sh2-none-elf- CC = $(TARGET)gcc +CXX = $(TARGET)g++ AS = $(TARGET)as LD = $(TARGET)ld OBJCOPY = $(TARGET)objcopy @@ -13,17 +18,17 @@ OBJDUMP = $(TARGET)objdump all: main.iso -sys_%.o: segasmp/lib/sys_%.o +$(LIB)/sys_%.o: $(LIB)/segasmp/lib/sys_%.o $(OBJCOPY) -I coff-sh -O elf32-sh -g \ --rename-section .text=.text.$* \ $< $@ -SYS_IP_OBJ += sys_id.o -SYS_IP_OBJ += sys_sec.o -SYS_IP_OBJ += sys_area.o sys_areb.o sys_aree.o sys_arej.o -SYS_IP_OBJ += sys_arek.o sys_arel.o sys_aret.o sys_areu.o -SYS_IP_OBJ += sys_init.o -SYS_IP_OBJ += smpsys.o +SYS_IP_OBJ += $(LIB)/sys_id.o +SYS_IP_OBJ += $(LIB)/sys_sec.o +SYS_IP_OBJ += $(LIB)/sys_area.o $(LIB)/sys_areb.o $(LIB)/sys_aree.o $(LIB)/sys_arej.o +SYS_IP_OBJ += $(LIB)/sys_arek.o $(LIB)/sys_arel.o $(LIB)/sys_aret.o $(LIB)/sys_areu.o +SYS_IP_OBJ += $(LIB)/sys_init.o +SYS_IP_OBJ += $(LIB)/smpsys.o %.o: %.s $(AS) $(AFLAGS) $(AARCH) $< -o $@ @@ -34,8 +39,11 @@ SYS_IP_OBJ += smpsys.o %.o: %.c $(CC) $(CFLAGS) $(CARCH) -c $< -o $@ +%.o: %.cpp + $(CXX) $(CFLAGS) $(CXXFLAGS) $(CARCH) -c $< -o $@ + %.elf: - $(LD) --print-memory-usage -T sys_ip.lds $^ -o $@ + $(LD) --print-memory-usage -T $(LIB)/sys_ip.lds $^ -o $@ %.bin: %.elf $(OBJCOPY) -O binary $< $@ @@ -48,10 +56,9 @@ SYS_IP_OBJ += smpsys.o sys_ip.elf: $(SYS_IP_OBJ) -MAIN_OBJ = main.o cd.o m68k/main.bin.o - main.elf: $(MAIN_OBJ) - $(LD) --print-memory-usage -T sh2.lds $^ -o $@ + $(LD) --print-memory-usage \ + -T $(LIB)/sh2.lds $^ -o $@ # mkisofs sorts file names alphabetically, it does not place the files in the # generated directory descriptors the order given on the command-line. @@ -86,9 +93,9 @@ main.iso: main.bin sys_ip.bin -o $@ \ -graft-points \ /0main.bin=./main.bin \ - /=./segasmp/smp_cpy.txt \ - /=./segasmp/smp_abs.txt \ - /=./segasmp/smp_bib.txt + /=$(LIB)/segasmp/smp_cpy.txt \ + /=$(LIB)/segasmp/smp_abs.txt \ + /=$(LIB)/segasmp/smp_bib.txt clean: rm -f *.iso *.o *.bin *.elf diff --git a/sh2.h b/sh2.h index 540d8bb..1041d10 100644 --- a/sh2.h +++ b/sh2.h @@ -105,7 +105,7 @@ struct sh2 { extern struct sh2 sh2 __asm("sh2"); -extern reg32 vec[0xff] __asm("vec"); +extern reg32 sh2_vec[0xff] __asm("sh2_vec"); enum tier_bits { TIER__ICIE = (1 << 7), diff --git a/sh2.lds b/sh2.lds index c6ae48f..46e68bc 100644 --- a/sh2.lds +++ b/sh2.lds @@ -9,7 +9,7 @@ SECTIONS { . = 0x06010000; - .text ALIGN(2) : SUBALIGN(2) + .text ALIGN(4) : SUBALIGN(4) { *(.text.start) *(.text*) @@ -40,5 +40,5 @@ scsp = 0x05A00000; vdp1 = 0x05C00000; vdp2 = 0x05E00000; scu = 0x05FE0000; -vec = 0x06000000; +sh2_vec = 0x06000000; sh2 = 0xfffffe00; diff --git a/type.h b/type.h index 7b889a0..9cf027c 100644 --- a/type.h +++ b/type.h @@ -1,4 +1,6 @@ +#ifndef __cplusplus #define static_assert _Static_assert +#endif #define offsetof __builtin_offsetof typedef volatile unsigned char reg8;