commit bbd0239f33d4311404a19a50bdc341360bd880b4 parent ad4a862a25648e29e4fe409a555878178b617360 Author: Roberto E. Vargas Caballero <k0ga@shike2.com> Date: Wed, 23 Oct 2024 17:37:01 +0200 build/scc-as: Migrate to a recursive Makefile This simplifies the management of dependencies. Diffstat:
28 files changed, 201 insertions(+), 172 deletions(-)
diff --git a/.gitignore b/.gitignore @@ -14,11 +14,12 @@ dirs /src/cmd/scc-ar /src/cmd/scc-nm /src/cmd/scc-ranlib +/src/cmd/scc-as/scc-as /src/cmd/scc-as/as-amd64 /src/cmd/scc-as/as-i286 /src/cmd/scc-as/as-i386 -/src/cmd/scc-as/as-powerpc -/src/cmd/scc-as/as-powerpc64 +/src/cmd/scc-as/as-ppc +/src/cmd/scc-as/as-ppc64 /src/cmd/scc-as/as-z80 /src/cmd/scc-cc/cc1/cc1 /src/cmd/scc-cc/cc1/cpp-bug.c diff --git a/src/cmd/scc-as/.gitignore b/src/cmd/scc-as/.gitignore @@ -1,2 +1 @@ lexh -as diff --git a/src/cmd/scc-as/Makefile b/src/cmd/scc-as/Makefile @@ -1,10 +1,13 @@ .POSIX: +DIRS =\ + ppc\ + x80\ + x86\ + PROJECTDIR = ../../.. include $(PROJECTDIR)/scripts/rules.mk -MORE_CFLAGS = -I$(INCDIR)/$(STD) - OBJS = \ expr.o\ ins.o\ @@ -13,22 +16,25 @@ OBJS = \ symbol.o\ TARGET =\ + scc-as\ as-amd64\ as-i286\ as-i386\ - as-powerpc\ - as-powerpc64\ - as-z80 \ + as-ppc\ + as-ppc64\ + as-z80\ MORE_LDLIBS = -lscc -lmach -all: $(TARGET) +all: + $(MAKE) $(DIRS) + $(MAKE) $(TARGET) + @cp as-* $(LIBEXEC)/scc + @cp scc-as $(BINDIR) +$(DIRS): lexh $(TARGET): $(LIBSCC) $(LIBMACH) -scc-as: as - cp as $(BINDIR) - genhash.o: ../../libscc/genhash.c $(HOSTCC) -c ../../libscc/genhash.c @@ -38,13 +44,23 @@ lexh.o: lexh.c lexh: lexh.o genhash.o $(HOSTCC) -o $@ lexh.o genhash.o +as-ppc: $(OBJS) ppc/ppc.o + $(CC) $(PROJ_LDFLAGS) $(OBJS) ppc/ppc.o $(PROJ_LDLIBS) -o $@ + +as-ppc64: $(OBJS) ppc/ppc64.o + $(CC) $(PROJ_LDFLAGS) $(OBJS) ppc/ppc64.o $(PROJ_LDLIBS) -o $@ + +as-z80: $(OBJS) x80/z80.o + $(CC) $(PROJ_LDFLAGS) $(OBJS) x80/z80.o $(PROJ_LDLIBS) -o $@ + +as-i286: $(OBJS) x86/i286.o + $(CC) $(PROJ_LDFLAGS) $(OBJS) x86/i286.o $(PROJ_LDLIBS) -o $@ + +as-i386: $(OBJS) x86/i386.o + $(CC) $(PROJ_LDFLAGS) $(OBJS) x86/i386.o $(PROJ_LDLIBS) -o $@ + +as-amd64: $(OBJS) x86/amd64.o + $(CC) $(PROJ_LDFLAGS) $(OBJS) x86/amd64.o $(PROJ_LDLIBS) -o $@ + clean: - rm -f */*.o */*tbl.c lexh - rm -f as - -include powerpc/powerpc64.mk -include powerpc/powerpc.mk -include x86/amd64.mk -include x86/i386.mk -include x86/i286.mk -include x80/z80.mk + rm -f lexh diff --git a/src/cmd/scc-as/mktbl b/src/cmd/scc-as/mktbl @@ -12,10 +12,6 @@ do cpu=$2 shift 2 ;; - -f) - family=$2 - shift 2 - ;; -*) echo mktbl: incorrect parameter:$i >&2 exit 1 @@ -23,12 +19,10 @@ do esac done -echo cpu=${cpu:=z80} family=${family:=x80} - rm -f $$.c $family/${cpu}tbl.c trap "rm -f $$.c" 0 2 3 -awk '!/^$/ {print $1,NR,$2,$3,$4,$5,$6}' $family/ops.dat | +awk '!/^$/ {print $1,NR,$2,$3,$4,$5,$6}' ops.dat | sort -k1 -k2n | -LC_ALL=C awk -v cpu=`echo $cpu | tr a-z A-Z` -v family=$family -f mktbl.awk > $$.c && -mv $$.c $family/${cpu}tbl.c +LC_ALL=C awk -v cpu=`echo $cpu | tr a-z A-Z` -f ../mktbl.awk > $$.c && +mv $$.c ${cpu}tbl.c diff --git a/src/cmd/scc-as/mktbl.awk b/src/cmd/scc-as/mktbl.awk @@ -4,9 +4,9 @@ BEGIN { printf "#include <scc/mach.h>\n"\ "#include <scc/scc.h>\n"\ "#include \"../as.h\"\n"\ - "#include \"../" family "/proc.h\"\n" + "#include \"proc.h\"\n" - rules = family "/opers.dat" + rules = "opers.dat" while (getline < rules > 0) { regex[++nregs] = $1 value[nregs] = $2 @@ -48,8 +48,8 @@ END { printf "};\n\n" for (i = 0; i < nop; i++) - print opnames[i] | "./lexh" - close("./lexh") + print opnames[i] | "../lexh" + close("../lexh") print "struct op optab[] = {" for (i = 0; i < nvar; i++) { diff --git a/src/cmd/scc-as/powerpc/.gitignore b/src/cmd/scc-as/powerpc/.gitignore @@ -1,2 +0,0 @@ -powerpc64tbl.c -powerpctbl.c diff --git a/src/cmd/scc-as/powerpc/ops.dat b/src/cmd/scc-as/powerpc/ops.dat @@ -1,62 +0,0 @@ -# Tab 18, tabs 18, :set ts=18 -# op args size bytes format cpu -.SECTION sym,string? 0 none section POWERPC,POWERPC64 -.TEXT none 0 none text POWERPC,POWERPC64 -.DATA none 0 none data POWERPC,POWERPC64 -.BSS none 0 none bss POWERPC,POWERPC64 -.DB imm8+ 0 none defb POWERPC,POWERPC64 -.DEFB imm8+ 0 none defb POWERPC,POWERPC64 -.BYTE imm8+ 0 none defb POWERPC,POWERPC64 -.DW imm16+ 0 none defw POWERPC,POWERPC64 -.DEFW imm16+ 0 none defw POWERPC,POWERPC64 -.SHORT imm16+ 0 none defw POWERPC,POWERPC64 -.WORD imm16+ 0 none defw POWERPC,POWERPC64 -.DD imm32+ 0 none defd POWERPC,POWERPC64 -.DEFD imm32+ 0 none defd POWERPC,POWERPC64 -.LONG imm32+ 0 none defd POWERPC,POWERPC64 -.INT imm16+ 0 none defd POWERPC,POWERPC64 -.DQ imm64+ 0 none defq POWERPC,POWERPC64 -.DEFQ imm64+ 0 none defq POWERPC,POWERPC64 -.EQU sym,imm16 0 none equ POWERPC,POWERPC64 -.EQU imm16 0 none equ POWERPC,POWERPC64 -= imm16 0 none equ POWERPC,POWERPC64 -.SIZE sym,imm16 0 none size POWERPC,POWERPC64 -.SIZE imm16 0 none size POWERPC,POWERPC64 -.COMM sym,imm16 0 none common POWERPC,POWERPC64 -.COMM imm16 0 none common POWERPC,POWERPC64 -.TYPE sym,imm16 0 none type POWERPC,POWERPC64 -.TYPE imm16 0 none type POWERPC,POWERPC64 -.GLOBL sym+ 0 none global POWERPC,POWERPC64 -.PUBLIC sym+ 0 none global POWERPC,POWERPC64 -.EXTERN sym+ 0 none extrn POWERPC,POWERPC64 -.EXTRN sym+ 0 none extrn POWERPC,POWERPC64 -.STRING string+ 0 none string POWERPC,POWERPC64 -.ASCII string+ 0 none ascii POWERPC,POWERPC64 -.ALIGN imm16+ 0 none align POWERPC,POWERPC64 -.END none 0 none end POWERPC,POWERPC64 -.INCLUDE string 0 none include POWERPC,POWERPC64 - -# Branch instructions -B imm32 4 18,0,0 i_form POWERPC -B imm64 4 18,0,0 i_form POWERPC64 -BA imm32 4 18,1,0 i_form POWERPC -BA imm64 4 18,1,0 i_form POWERPC64 -BL imm32 4 18,0,1 i_form POWERPC -BL imm64 4 18,0,1 i_form POWERPC64 -BLA imm32 4 18,1,1 i_form POWERPC -BLA imm64 4 18,1,1 i_form POWERPC64 - -BC imm5,imm5,imm32 4 16,0,0 b_form POWERPC -BC imm5,imm5,imm64 4 16,0,0 b_form POWERPC64 -BCA imm5,imm5,imm32 4 16,1,0 b_form POWERPC -BCA imm5,imm5,imm64 4 16,1,0 b_form POWERPC64 -BCL imm5,imm5,imm32 4 16,0,1 b_form POWERPC -BCL imm5,imm5,imm64 4 16,0,1 b_form POWERPC64 -BCLA imm5,imm5,imm32 4 16,1,1 b_form POWERPC -BCLA imm5,imm5,imm64 4 16,1,1 b_form POWERPC64 - -BCLR imm5,imm5,imm2 4 19,0,16,0 xl_form POWERPC,POWERPC64 -BCLRL imm5,imm5,imm2 4 19,0,16,1 xl_form POWERPC,POWERPC64 - -BCCTR imm5,imm5,imm2 4 19,2,16,0 xl_form POWERPC,POWERPC64 -BCCTRL imm5,imm5,imm2 4 19,2,16,1 xl_form POWERPC,POWERPC64 diff --git a/src/cmd/scc-as/powerpc/powerpc.mk b/src/cmd/scc-as/powerpc/powerpc.mk @@ -1,13 +0,0 @@ -POWERPC = powerpc -POWERPC_OBJ =\ - $(OBJS)\ - $(POWERPC)/powerpctbl.o\ - $(POWERPC)/powerpc.o\ - $(POWERPC)/ins.o\ - -$(POWERPC)/powerpctbl.c: $(POWERPC)/ops.dat $(POWERPC)/opers.dat lexh - ./mktbl -f powerpc -c powerpc - -as-powerpc: $(POWERPC_OBJ) - $(CC) $(PROJ_LDFLAGS) $(POWERPC_OBJ) $(PROJ_LDLIBS) -o $@ - cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/scc-as/powerpc/powerpc64.mk b/src/cmd/scc-as/powerpc/powerpc64.mk @@ -1,13 +0,0 @@ -POWERPC = powerpc -POWERPC64_OBJ =\ - $(OBJS)\ - $(POWERPC)/powerpc64tbl.o\ - $(POWERPC)/powerpc64.o\ - $(POWERPC)/ins.o\ - -$(POWERPC)/powerpc64tbl.c: $(POWERPC)/ops.dat $(POWERPC)/opers.dat lexh - ./mktbl -f powerpc -c powerpc64 - -as-powerpc64: $(POWERPC64_OBJ) - $(CC) $(PROJ_LDFLAGS) $(POWERPC64_OBJ) $(PROJ_LDLIBS) -o $@ - cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/scc-as/ppc/.gitignore b/src/cmd/scc-as/ppc/.gitignore @@ -0,0 +1,2 @@ +ppc64tbl.c +ppctbl.c diff --git a/src/cmd/scc-as/ppc/Makefile b/src/cmd/scc-as/ppc/Makefile @@ -0,0 +1,31 @@ +.POSIX: + +PROJECTDIR = ../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS32 =\ + ppctbl.o\ + arch_ppc.o\ + ins.o\ + +OBJS64 =\ + ppc64tbl.o\ + arch_ppc64.o\ + ins.o\ + +all: ppc.o ppc64.o + +ppc.o: $(OBJS32) + $(LD) -r -o $@ $(OBJS32) + +ppc64.o: $(OBJS64) + $(LD) -r -o $@ $(OBJS64) + +ppctbl.c: ops.dat opers.dat + ../mktbl -c ppc + +ppc64tbl.c: ops.dat opers.dat + ../mktbl -c ppc64 + +clean: + rm -f ppc64tbl.c ppctbl.c diff --git a/src/cmd/scc-as/powerpc/powerpc.c b/src/cmd/scc-as/ppc/arch_ppc.c diff --git a/src/cmd/scc-as/powerpc/powerpc64.c b/src/cmd/scc-as/ppc/arch_ppc64.c diff --git a/src/cmd/scc-as/powerpc/ins.c b/src/cmd/scc-as/ppc/ins.c diff --git a/src/cmd/scc-as/powerpc/opers.dat b/src/cmd/scc-as/ppc/opers.dat diff --git a/src/cmd/scc-as/ppc/ops.dat b/src/cmd/scc-as/ppc/ops.dat @@ -0,0 +1,62 @@ +# Tab 18, tabs 18, :set ts=18 +# op args size bytes format cpu +.SECTION sym,string? 0 none section PPC,PPC64 +.TEXT none 0 none text PPC,PPC64 +.DATA none 0 none data PPC,PPC64 +.BSS none 0 none bss PPC,PPC64 +.DB imm8+ 0 none defb PPC,PPC64 +.DEFB imm8+ 0 none defb PPC,PPC64 +.BYTE imm8+ 0 none defb PPC,PPC64 +.DW imm16+ 0 none defw PPC,PPC64 +.DEFW imm16+ 0 none defw PPC,PPC64 +.SHORT imm16+ 0 none defw PPC,PPC64 +.WORD imm16+ 0 none defw PPC,PPC64 +.DD imm32+ 0 none defd PPC,PPC64 +.DEFD imm32+ 0 none defd PPC,PPC64 +.LONG imm32+ 0 none defd PPC,PPC64 +.INT imm16+ 0 none defd PPC,PPC64 +.DQ imm64+ 0 none defq PPC,PPC64 +.DEFQ imm64+ 0 none defq PPC,PPC64 +.EQU sym,imm16 0 none equ PPC,PPC64 +.EQU imm16 0 none equ PPC,PPC64 += imm16 0 none equ PPC,PPC64 +.SIZE sym,imm16 0 none size PPC,PPC64 +.SIZE imm16 0 none size PPC,PPC64 +.COMM sym,imm16 0 none common PPC,PPC64 +.COMM imm16 0 none common PPC,PPC64 +.TYPE sym,imm16 0 none type PPC,PPC64 +.TYPE imm16 0 none type PPC,PPC64 +.GLOBL sym+ 0 none global PPC,PPC64 +.PUBLIC sym+ 0 none global PPC,PPC64 +.EXTERN sym+ 0 none extrn PPC,PPC64 +.EXTRN sym+ 0 none extrn PPC,PPC64 +.STRING string+ 0 none string PPC,PPC64 +.ASCII string+ 0 none ascii PPC,PPC64 +.ALIGN imm16+ 0 none align PPC,PPC64 +.END none 0 none end PPC,PPC64 +.INCLUDE string 0 none include PPC,PPC64 + +# Branch instructions +B imm32 4 18,0,0 i_form PPC +B imm64 4 18,0,0 i_form PPC64 +BA imm32 4 18,1,0 i_form PPC +BA imm64 4 18,1,0 i_form PPC64 +BL imm32 4 18,0,1 i_form PPC +BL imm64 4 18,0,1 i_form PPC64 +BLA imm32 4 18,1,1 i_form PPC +BLA imm64 4 18,1,1 i_form PPC64 + +BC imm5,imm5,imm32 4 16,0,0 b_form PPC +BC imm5,imm5,imm64 4 16,0,0 b_form PPC64 +BCA imm5,imm5,imm32 4 16,1,0 b_form PPC +BCA imm5,imm5,imm64 4 16,1,0 b_form PPC64 +BCL imm5,imm5,imm32 4 16,0,1 b_form PPC +BCL imm5,imm5,imm64 4 16,0,1 b_form PPC64 +BCLA imm5,imm5,imm32 4 16,1,1 b_form PPC +BCLA imm5,imm5,imm64 4 16,1,1 b_form PPC64 + +BCLR imm5,imm5,imm2 4 19,0,16,0 xl_form PPC,PPC64 +BCLRL imm5,imm5,imm2 4 19,0,16,1 xl_form PPC,PPC64 + +BCCTR imm5,imm5,imm2 4 19,2,16,0 xl_form PPC,PPC64 +BCCTRL imm5,imm5,imm2 4 19,2,16,1 xl_form PPC,PPC64 diff --git a/src/cmd/scc-as/powerpc/proc.h b/src/cmd/scc-as/ppc/proc.h diff --git a/src/cmd/scc-as/as.c b/src/cmd/scc-as/scc-as.c diff --git a/src/cmd/scc-as/x80/Makefile b/src/cmd/scc-as/x80/Makefile @@ -0,0 +1,20 @@ +.POSIX: + +PROJECTDIR = ../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS_Z80 =\ + z80tbl.o\ + arch_z80.o\ + ins.o\ + +all: z80.o + +z80.o: $(OBJS_Z80) + $(LD) -r -o $@ $(OBJS_Z80) + +z80tbl.c: ops.dat opers.dat + ../mktbl -c z80 + +clean: + rm -f z80tbl.c diff --git a/src/cmd/scc-as/x80/z80.c b/src/cmd/scc-as/x80/arch_z80.c diff --git a/src/cmd/scc-as/x80/z80.mk b/src/cmd/scc-as/x80/z80.mk @@ -1,12 +0,0 @@ -Z80_OBJ =\ - $(OBJS)\ - x80/z80tbl.o\ - x80/z80.o\ - x80/ins.o\ - -x80/z80tbl.c: x80/ops.dat x80/opers.dat lexh - ./mktbl -f x80 -c z80 - -as-z80: $(OBJ) $(Z80_OBJ) - $(CC) $(PROJ_LDFLAGS) $(Z80_OBJ) $(PROJ_LDLIBS) -o $@ - cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/scc-as/x86/Makefile b/src/cmd/scc-as/x86/Makefile @@ -0,0 +1,42 @@ +.POSIX: + +PROJECTDIR = ../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS_286 =\ + i286tbl.o\ + arch_i286.o\ + ins.o\ + +OBJS_386 =\ + i386tbl.o\ + arch_i386.o\ + ins.o\ + +OBJS_AMD64 =\ + amd64tbl.o\ + arch_amd64.o\ + ins.o\ + +all: i286.o i386.o amd64.o + +i286.o: $(OBJS_286) + $(LD) -r -o $@ $(OBJS_286) + +i386.o: $(OBJS_386) + $(LD) -r -o $@ $(OBJS_386) + +amd64.o: $(OBJS_AMD64) + $(LD) -r -o $@ $(OBJS_AMD64) + +i286tbl.c: ops.dat opers.dat + ../mktbl -c i286 + +i386tbl.c: ops.dat opers.dat + ../mktbl -c i386 + +amd64tbl.c: ops.dat opers.dat + ../mktbl -c amd64 + +clean: + rm -f amd64tbl.c i386tbl.c i286tbl.c diff --git a/src/cmd/scc-as/x86/amd64.mk b/src/cmd/scc-as/x86/amd64.mk @@ -1,12 +0,0 @@ -AMD64_OBJ =\ - $(OBJS)\ - x86/amd64tbl.o\ - x86/amd64.o\ - x86/ins.o\ - -x86/amd64tbl.c: x86/ops.dat x86/opers.dat lexh - ./mktbl -f x86 -c amd64 - -as-amd64: $(AMD64_OBJ) - $(CC) $(PROJ_LDFLAGS) $(AMD64_OBJ) $(PROJ_LDLIBS) -o $@ - cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/scc-as/x86/amd64.c b/src/cmd/scc-as/x86/arch_amd64.c diff --git a/src/cmd/scc-as/x86/i286.c b/src/cmd/scc-as/x86/arch_i286.c diff --git a/src/cmd/scc-as/x86/i386.c b/src/cmd/scc-as/x86/arch_i386.c diff --git a/src/cmd/scc-as/x86/i286.mk b/src/cmd/scc-as/x86/i286.mk @@ -1,12 +0,0 @@ -I286_OBJ =\ - $(OBJS)\ - x86/i286tbl.o\ - x86/i286.o\ - x86/ins.o\ - -x86/i286tbl.c: x86/ops.dat x86/opers.dat lexh - ./mktbl -f x86 -c i286 - -as-i286: $(I286_OBJ) - $(CC) $(PROJ_LDFLAGS) $(I286_OBJ) $(PROJ_LDLIBS) -o $@ - cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/scc-as/x86/i386.mk b/src/cmd/scc-as/x86/i386.mk @@ -1,12 +0,0 @@ -I386_OBJ =\ - $(OBJS)\ - x86/i386tbl.o\ - x86/i386.o\ - x86/ins.o\ - -x86/i386tbl.c: x86/ops.dat x86/opers.dat lexh - ./mktbl -f x86 -c i386 - -as-i386: $(I386_OBJ) - $(CC) $(PROJ_LDFLAGS) $(I386_OBJ) $(PROJ_LDLIBS) -o $@ - cp $@ $(LIBEXEC)/scc