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
This commit is contained in:
Zack Buhman 2023-01-23 20:34:27 -08:00
parent 6640c37a1d
commit e31d2c55fd
4 changed files with 26 additions and 17 deletions

View File

@ -1,11 +1,16 @@
LIB ?= .
AARCH = --isa=sh2 --big AARCH = --isa=sh2 --big
AFLAGS = -g -gdwarf-4 AFLAGS = -g -gdwarf-4
CFLAGS = -I$(LIB)
CFLAGS += -ffunction-sections -fshort-enums -ffreestanding -nostdlib CFLAGS += -ffunction-sections -fshort-enums -ffreestanding -nostdlib
CFLAGS += -Wall -Werror -Wfatal-errors -Wno-error=unused-variable -g -gdwarf-4 -Og CFLAGS += -Wall -Werror -Wfatal-errors -Wno-error=unused-variable -g -gdwarf-4 -Og
CXXFLAGS = -fno-exceptions -fno-rtti
CARCH = -m2 -mb CARCH = -m2 -mb
TARGET = sh2-none-elf- TARGET = sh2-none-elf-
CC = $(TARGET)gcc CC = $(TARGET)gcc
CXX = $(TARGET)g++
AS = $(TARGET)as AS = $(TARGET)as
LD = $(TARGET)ld LD = $(TARGET)ld
OBJCOPY = $(TARGET)objcopy OBJCOPY = $(TARGET)objcopy
@ -13,17 +18,17 @@ OBJDUMP = $(TARGET)objdump
all: main.iso 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 \ $(OBJCOPY) -I coff-sh -O elf32-sh -g \
--rename-section .text=.text.$* \ --rename-section .text=.text.$* \
$< $@ $< $@
SYS_IP_OBJ += sys_id.o SYS_IP_OBJ += $(LIB)/sys_id.o
SYS_IP_OBJ += sys_sec.o SYS_IP_OBJ += $(LIB)/sys_sec.o
SYS_IP_OBJ += sys_area.o sys_areb.o sys_aree.o sys_arej.o SYS_IP_OBJ += $(LIB)/sys_area.o $(LIB)/sys_areb.o $(LIB)/sys_aree.o $(LIB)/sys_arej.o
SYS_IP_OBJ += sys_arek.o sys_arel.o sys_aret.o sys_areu.o SYS_IP_OBJ += $(LIB)/sys_arek.o $(LIB)/sys_arel.o $(LIB)/sys_aret.o $(LIB)/sys_areu.o
SYS_IP_OBJ += sys_init.o SYS_IP_OBJ += $(LIB)/sys_init.o
SYS_IP_OBJ += smpsys.o SYS_IP_OBJ += $(LIB)/smpsys.o
%.o: %.s %.o: %.s
$(AS) $(AFLAGS) $(AARCH) $< -o $@ $(AS) $(AFLAGS) $(AARCH) $< -o $@
@ -34,8 +39,11 @@ SYS_IP_OBJ += smpsys.o
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) $(CARCH) -c $< -o $@ $(CC) $(CFLAGS) $(CARCH) -c $< -o $@
%.o: %.cpp
$(CXX) $(CFLAGS) $(CXXFLAGS) $(CARCH) -c $< -o $@
%.elf: %.elf:
$(LD) --print-memory-usage -T sys_ip.lds $^ -o $@ $(LD) --print-memory-usage -T $(LIB)/sys_ip.lds $^ -o $@
%.bin: %.elf %.bin: %.elf
$(OBJCOPY) -O binary $< $@ $(OBJCOPY) -O binary $< $@
@ -48,10 +56,9 @@ SYS_IP_OBJ += smpsys.o
sys_ip.elf: $(SYS_IP_OBJ) sys_ip.elf: $(SYS_IP_OBJ)
MAIN_OBJ = main.o cd.o m68k/main.bin.o
main.elf: $(MAIN_OBJ) 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 # mkisofs sorts file names alphabetically, it does not place the files in the
# generated directory descriptors the order given on the command-line. # generated directory descriptors the order given on the command-line.
@ -86,9 +93,9 @@ main.iso: main.bin sys_ip.bin
-o $@ \ -o $@ \
-graft-points \ -graft-points \
/0main.bin=./main.bin \ /0main.bin=./main.bin \
/=./segasmp/smp_cpy.txt \ /=$(LIB)/segasmp/smp_cpy.txt \
/=./segasmp/smp_abs.txt \ /=$(LIB)/segasmp/smp_abs.txt \
/=./segasmp/smp_bib.txt /=$(LIB)/segasmp/smp_bib.txt
clean: clean:
rm -f *.iso *.o *.bin *.elf rm -f *.iso *.o *.bin *.elf

2
sh2.h
View File

@ -105,7 +105,7 @@ struct sh2 {
extern struct sh2 sh2 __asm("sh2"); extern struct sh2 sh2 __asm("sh2");
extern reg32 vec[0xff] __asm("vec"); extern reg32 sh2_vec[0xff] __asm("sh2_vec");
enum tier_bits { enum tier_bits {
TIER__ICIE = (1 << 7), TIER__ICIE = (1 << 7),

View File

@ -9,7 +9,7 @@ SECTIONS
{ {
. = 0x06010000; . = 0x06010000;
.text ALIGN(2) : SUBALIGN(2) .text ALIGN(4) : SUBALIGN(4)
{ {
*(.text.start) *(.text.start)
*(.text*) *(.text*)
@ -40,5 +40,5 @@ scsp = 0x05A00000;
vdp1 = 0x05C00000; vdp1 = 0x05C00000;
vdp2 = 0x05E00000; vdp2 = 0x05E00000;
scu = 0x05FE0000; scu = 0x05FE0000;
vec = 0x06000000; sh2_vec = 0x06000000;
sh2 = 0xfffffe00; sh2 = 0xfffffe00;

2
type.h
View File

@ -1,4 +1,6 @@
#ifndef __cplusplus
#define static_assert _Static_assert #define static_assert _Static_assert
#endif
#define offsetof __builtin_offsetof #define offsetof __builtin_offsetof
typedef volatile unsigned char reg8; typedef volatile unsigned char reg8;