udp support
[nestedvm.git] / Makefile
index baabb85..530aa03 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,7 @@ flags = -march=mips1
 MIPS_CC = mips-unknown-elf-gcc
 MIPS_CXX = mips-unknown-elf-g++
 MIPS_G77 = mips-unknown-elf-g77
+MIPS_PC = mips-unknown-elf-gpc
 
 # Be VERY careful about changing any of these as they can break binary 
 # compatibility and create hard to find bugs
@@ -35,6 +36,8 @@ mips_optflags = -O3 -g \
        -freduce-all-givs
 
 MIPS_CFLAGS = $(mips_optflags) $(flags) -I. -Wall -Wno-unused -Werror
+MIPS_CXXFLAGS = $(MIPS_CFLAGS)
+MIPS_PCFLAGS = $(MIPS_CFLAGS) --big-endian
 MIPS_LD = mips-unknown-elf-gcc
 MIPS_LDFLAGS= $(flags) --static -Wl,--gc-sections
 MIPS_STRIP = mips-unknown-elf-strip
@@ -48,8 +51,13 @@ else
        JAVAC_NODEBUG_FLAGS = -g:none
 endif
 
-bcel_jar = upstream/build/bcel-5.1/bcel-5.1.jar
-classpath = build:$(bcel_jar)
+CYGWIN = $(findstring CYGWIN,$(shell uname))
+CLASSGEN_PATH = upstream/build/classgen/build
+ifneq ($(CYGWIN),)
+       classpath = $(shell cygpath -wp build:$(CLASSGEN_PATH))
+else
+       classpath = build:$(CLASSGEN_PATH)
+endif
 
 GCJ = gcj
 EXE_EXT = 
@@ -57,7 +65,9 @@ EXE_EXT =
 #####
 
 java_classes = $(java_sources:src/%.java=build/%.class)
-mips_objects = $(mips_sources:%.c=build/org/ibex/nestedvm/%.o) $(mips_asm_sources:%.s=build/org/ibex/nestedvm/%.o)
+mips_c_objects = $(mips_sources:%.c=build/org/ibex/nestedvm/%.o)
+mips_asm_objects = $(mips_asm_sources:%.s=build/org/ibex/nestedvm/%.o)
+mips_objects = $(mips_asm_objects) $(mips_c_objects)
 
 usr = $(mips2java_root)/upstream/install
 PATH := $(usr)/bin:$(PATH)
@@ -71,9 +81,15 @@ ifdef NATIVE_MIPS2JAVA_COMPILER
 all: build/mips2java$(EXE_EXT) $(mips_objects)
 endif
 
-$(tasks)/%:
-       $(MAKE) -C upstream tasks/$* usr="$(usr)" MIPS_LDFLAGS="$(MIPS_LDFLAGS)" MIPS_CFLAGS="$(flags) $(mips_optflags)"
+# HACK: Ensure libc is kept up to date when our mips_objects change
+$(tasks)/build_libc: $(mips_objects) upstream/misc/extraheaders.sh
 
+$(tasks)/%:
+       $(MAKE) -C upstream tasks/$* usr="$(usr)" \
+               MIPS_CFLAGS="$(filter-out -Werror,$(MIPS_CFLAGS))" \
+               MIPS_PCFLAGS="$(filter-out -Werror,$(MIPS_PCFLAGS))" \
+               MIPS_LDFLAGS="$(MIPS_LDFLAGS)"
+               
 upstream_clean_%:
        $(MAKE) -C upstream clean_$* usr="$(usr)"
 
@@ -89,11 +105,8 @@ build/org/ibex/nestedvm/util/.Dummy.class:
 $(java_classes): build/org/ibex/nestedvm/util/.Dummy.class
 endif
 
-$(java_classes): $(java_sources) $(bcel_jar)
-       $(JAVAC) -classpath $(classpath) -d build $(java_sources)
-
-$(bcel_jar): upstream/tasks/extract_bcel
-       @true
+$(java_classes): $(java_sources) $(tasks)/build_darcs_classgen
+       $(JAVAC) -classpath "$(classpath)" -d build $(java_sources)
 
 # GCJ Stuff
 # FIXME: We're cramming more than we need into the binary here
@@ -104,7 +117,14 @@ build/mips2java$(EXE_EXT): $(java_sources) $(java_gen_sources)
 #
 # MIPS Binary compilation
 #
-build/%.o: src/%.c $(tasks)/build_gcc
+
+# The nestedvm support library is special, it doesn't a full libc
+$(mips_c_objects): build/%.o: src/%.c $(tasks)/build_gcc $(tasks)/build_newlib $(tasks)/build_extraheaders
+       @mkdir -p `dirname $@`
+       $(MIPS_CC) $(MIPS_CFLAGS) -c -o $@ $<
+
+# Everything else needs a full libc
+build/%.o: src/%.c $(tasks)/build_gcc $(tasks)/build_libc
        @mkdir -p `dirname $@`
        $(MIPS_CC) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) -c -o $@ $<
 
@@ -112,17 +132,22 @@ build/%.o: src/%.s $(tasks)/build_gcc
        @mkdir -p `dirname $@`
        $(MIPS_CC) -x assembler-with-cpp -c -o $@ $<
 
-%.s: %.c $(tasks)/full_toolchain
+tmp/%.s: %.c $(tasks)/build_gcc
+       @mkdir -p `dirname $@`
        $(MIPS_CC) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) -c -S -o $@ $<
 
-build/%.mips: build/%.o $(mips_objects)
+build/%.mips: build/%.o $(tasks)/build_gcc $(tasks)/build_libc
        $(MIPS_LD) -o $@ $< $(MIPS_LDFLAGS) $($(notdir $*)_LDFLAGS)
 
-build/%.mips: src/%.cc $(tasks)/full_toolchain $(mips_objects)
+build/%.mips: src/%.cc $(tasks)/build_gcc_step2 $(tasks)/build_libc
        @mkdir -p `dirname $@`
-       $(MIPS_CXX) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) $(MIPS_LDFLAGS) $($(notdir $*)_LDFLAGS) -o $@ $<
+       $(MIPS_CXX) $(MIPS_CXXFLAGS) $($(notdir $*)_CXXFLAGS) $(MIPS_LDFLAGS) $($(notdir $*)_LDFLAGS) -o $@ $<
 
-build/%.mips.stripped: build/%.mips
+build/%.mips: src/%.pas $(tasks)/build_gpc
+       @mkdir -p `dirname $@`
+       $(MIPS_PC) $(MIPS_PCFLAGS) $($(notdir $*)_PCFLAGS) $(MIPS_LDFLAGS) $($(notdir $*)_LDFLAGS) -o $@ $<
+
+build/%.mips.stripped: build/%.mips $(tasks)/build_linker
        cp $< $@
        $(MIPS_STRIP) -s $@
 
@@ -130,14 +155,14 @@ build/%.mips.stripped: build/%.mips
 ifdef DO_JAVASOURCE
 
 build/%.java: build/%.mips build/org/ibex/nestedvm/JavaSourceCompiler.class 
-       $(JAVA) -cp $(classpath) org.ibex.nestedvm.Compiler -outformat javasource $(compiler_flags) $($(notdir $*)_COMPILERFLAGS) $(subst /,.,$*) $< > build/$*.java
+       $(JAVA) -cp "$(classpath)" org.ibex.nestedvm.Compiler -outformat javasource $(compiler_flags) $($(notdir $*)_COMPILERFLAGS) $(subst /,.,$*) $< > build/$*.java
 
 build/%.class: build/%.java build/org/ibex/nestedvm/Runtime.class
        $(JAVAC) $(JAVAC_NODEBUG_FLAGS) -classpath build -d build $<
 else
 
 build/%.class: build/%.mips build/org/ibex/nestedvm/ClassFileCompiler.class
-       $(JAVA) -cp $(classpath) org.ibex.nestedvm.Compiler -outformat class -outfile $@ $(compiler_flags) $($(notdir $*)_COMPILERFLAGS) $(subst /,.,$*) $<
+       $(JAVA) -cp "$(classpath)" org.ibex.nestedvm.Compiler -outformat class -d build $(compiler_flags) $($(notdir $*)_COMPILERFLAGS) $(subst /,.,$*) $<
 
 
 endif
@@ -152,7 +177,7 @@ clean:
 #
 # env.sh
 #
-env.sh: Makefile $(tasks)/full_toolchain build/org/ibex/nestedvm/Compiler.class
+env.sh: Makefile $(tasks)/build_gcc $(tasks)/build_libc build/org/ibex/nestedvm/Compiler.class
        @rm -f "$@~"
        @echo 'PATH="$(mips2java_root)/build:$(usr)/bin:$$PATH"; export PATH' >> $@~
        @echo 'CC=mips-unknown-elf-gcc; export CC' >> $@~
@@ -164,7 +189,7 @@ env.sh: Makefile $(tasks)/full_toolchain build/org/ibex/nestedvm/Compiler.class
        @echo 'CFLAGS="$(mips_optflags)"; export CFLAGS' >> $@~
        @echo 'CXXFLAGS="$(mips_optflags)"; export CXXFLAGS' >> $@~
        @echo 'LDFLAGS="$(MIPS_LDFLAGS)"; export LDFLAGS' >> $@~
-       @echo 'CLASSPATH=$(mips2java_root)/build:$(mips2java_root)/$(bcel_jar):.; export CLASSPATH' >> $@~
+       @echo 'CLASSPATH=$(mips2java_root)/build:$(mips2java_root)/upstream/build/classgen/build:.; export CLASSPATH' >> $@~
        @mv "$@~" "$@"
        @echo "$@ created successfully"
 
@@ -174,14 +199,13 @@ env.sh: Makefile $(tasks)/full_toolchain build/org/ibex/nestedvm/Compiler.class
 
 runtime_classes = Runtime Registers UsermodeConstants util/Seekable
 
-tex.jar: $(mips_objects) $(runtime_classes:%=build/org/ibex/nestedvm/%.class) upstream/tasks/build_tex
-       echo -e "Manifest-Version: 1.0\nMain-Class: TeX\n" > .manifest
+tex.jar: $(mips_objects) $(runtime_classes:%=build/org/ibex/nestedvm/%.class) build/tests/TeX.class
+       echo -e "Manifest-Version: 1.0\nMain-Class: Tex\n" > .manifest
        cp upstream/build/tex/TeX.class build
        cd build && jar cfm ../$@ ../.manifest \
-               TeX.class \
                $(runtime_classes:%=org/ibex/nestedvm/%.class) \
-               org/ibex/nestedvm/*.class \
-               org/ibex/nestedvm/util/*.class
+               org/ibex/nestedvm/Runtime\$$*.class \
+               org/ibex/nestedvm/util/Seekable\$$*.class
 
 runtime.jar: $(runtime_classes:%=build/org/ibex/nestedvm/%.class)
        cd build && jar cf ../$@ \
@@ -190,28 +214,41 @@ runtime.jar: $(runtime_classes:%=build/org/ibex/nestedvm/%.class)
                org/ibex/nestedvm/util/Seekable\$$*.class
 
 .manifest:
-       echo -ne "Manifest-Version: 1.0\nMain-Class: org.ibex.nestedvm.RuntimeCompiler\n" > $@
+       printf "Manifest-Version: 1.0\nMain-Class: org.ibex.nestedvm.RuntimeCompiler\n" > $@
 
 nestedvm.jar: $(java_classes) .manifest
        cd build && jar cfm ../$@ ../.manifest $(java_classes:build/%.class=%*.class)
+       cd $(CLASSGEN_PATH) && jar uf $(mips2java_root)/$@ .
 
-compact_runtime_compiler.jar: $(java_classes) .manifest $(tasks)/build_gcclass
+compact_runtime_compiler.jar: $(java_classes) .manifest $(tasks)/build_darcs_gcclass
        mkdir -p tmp/pruned
-       java -cp upstream/build/gcclass/build:$(bcel_jar) com.brian_web.gcclass.GCClass \
-               build tmp/pruned \
+       rm -rf tmp/pruned/*
+       java -cp \
+               upstream/build/gcclass/build:upstream/build/gcclass/upstream/bcel-5.1/bcel-5.1.jar \
+       com.brian_web.gcclass.GCClass \
+               "$(classpath)" tmp/pruned \
                org.ibex.nestedvm.RuntimeCompiler.main 'org.ibex.nestedvm.Runtime.decodeData' \
                'org.ibex.nestedvm.UnixRuntime.<init>' 'org.ibex.nestedvm.Runtime.initPages' \
                'org.ibex.nestedvm.Runtime.clearPages' 'org.ibex.nestedvm.Runtime.syscall' \
-               'org.ibex.nestedvm.Runtime$$CPUState.dup'
+               'org.ibex.nestedvm.Runtime$$CPUState.dup' \
+               org.ibex.nestedvm.util.Platform\$$Jdk{11,12,13,14}.'<init>'
        cd tmp/pruned && jar cfm ../../$@ ../../.manifest .
 
+sizecheck: compact_runtime_compiler.jar
+       @for c in `find tmp/pruned -name '*.class'|fgrep -v '$$'`; do \
+               for f in `echo $$c|sed 's,\.class$$,,;'`*.class; do gzip -c $$f; done | wc -c | tr -d '\n'; \
+               echo -e "\t`echo $$c | sed 's,tmp/pruned/org/ibex,,;s,\.class$$,,;s,/,.,g;'`"; \
+       done | sort -rn | awk '{ sum += $$1; print }  END { print sum,"Total"; }'
+
+
 # This is only for Brian to use... don't mess with it
-rebuild-constants: $(tasks)/build_newlib
+rebuild-constants: $(tasks)/build_libc
        @mkdir -p `dirname $@`
        ( \
                cat \
                        src/org/ibex/nestedvm/syscalls.h \
-                       $(usr)/mips-unknown-elf/include/sys/{errno.h,unistd.h,syslimits.h}; \
+                       $(usr)/mips-unknown-elf/include/nestedvm/socket.h \
+                       $(usr)/mips-unknown-elf/include/sys/{errno.h,unistd.h,syslimits.h,sysctl.h}; \
                $(MIPS_CC) -E -dM $(usr)/mips-unknown-elf/include/sys/fcntl.h | awk '$$2 ~ /^[OF]_/ { print; }'; \
        ) | ( \
                echo "// THIS FILE IS AUTOGENERATED! DO NOT EDIT!"; \
@@ -252,6 +289,9 @@ build/tests/FDTest.class: build/tests/Test.class
 fdtest: build/tests/FDTest.class
        $(JAVA) -cp build tests.FDTest
 
+# Pascal Test
+pascaltest: build/tests/PascalHello.class
+       $(JAVA) -cp build tests.PascalHello
 
 # Simple
 Simple_LDFLAGS = -nostdlib
@@ -263,7 +303,15 @@ Paranoia_CFLAGS = "-Wno-error"
 Paranoia_LDFLAGS = -lm
 paranoiatest: build/tests/Paranoia.class
        $(JAVA) -cp build tests.Paranoia
-       
+
+# Linpack
+build/tests/Linpack.mips: $(tasks)/download_linpack $(tasks)/build_gcc_step2
+       mkdir -p `dirname "$@"`
+       $(MIPS_G77) $(MIPS_CFLAGS) $(Linpack_CFLAGS) $(MIPS_LDFLAGS) -o $@ upstream/download/linpack_bench.f -lc
+
+linpacktest: build/tests/Linpack.class
+       $(JAVA) -cp build tests.Linpack
+
 #
 # Freetype Stuff
 #
@@ -272,7 +320,7 @@ FreeType_LDFLAGS =  -Lupstream/build/freetype/objs -lfreetype
 
 FreeTypeDemoHelper_CFLAGS = $(FreeType_CFLAGS)
 FreeTypeDemoHelper_LDFLAGS = $(FreeType_LDFLAGS)
-build/tests/FreeTypeDemoHelper.o: $(mips_objects) $(tasks)/build_freetype
+build/tests/FreeTypeDemoHelper.o: $(tasks)/build_freetype
 build/tests/FreeTypeDemoHelper.mips: 
 build/tests/FreeTypeDemo.class: build/tests/FreeTypeDemoHelper.class
 
@@ -285,7 +333,7 @@ build/tests/FTBench.o: $(tasks)/build_freetype
 #
 MSPackHelper_CFLAGS = -Iupstream/build/libmspack/mspack
 MSPackHelper_LDFLAGS = -Lupstream/build/libmspack/mspack -lmspack
-build/tests/MSPackHelper.o: $(mips_objects) $(tasks)/build_libmspack
+build/tests/MSPackHelper.o: $(tasks)/build_libmspack
 build/tests/MSPack.class: build/tests/MSPackHelper.class
 
 MSPackBench_CFLAGS = -Iupstream/build/libmspack/mspack
@@ -301,7 +349,7 @@ build/tests/Echo.class: build/tests/EchoHelper.class
 # Libjpeg
 #
 DJpeg_COMPILERFLAGS = -o onepage,pagesize=8m
-build/tests/DJpeg.mips: $(mips_objects) $(tasks)/build_libjpeg
+build/tests/DJpeg.mips: $(tasks)/build_libjpeg
        @mkdir -p `dirname $@`
        cp upstream/build/libjpeg/djpeg $@
 
@@ -309,17 +357,17 @@ build/tests/DJpeg.mips: $(mips_objects) $(tasks)/build_libjpeg
 # Busybox
 #
 BusyBox_COMPILERFLAGS = -o unixruntime
-build/tests/BusyBox.mips: $(mips_objects) $(tasks)/build_busybox
+build/tests/BusyBox.mips: $(tasks)/build_busybox
        @mkdir -p `dirname $@`
        cp upstream/build/busybox/busybox $@
 
 busyboxtest: build/tests/BusyBox.class
-       $(JAVA) -cp $(classpath) tests.BusyBox ash
+       $(JAVA) -Dnestedvm.busyboxhack=true -cp "$(classpath)" tests.BusyBox ash
 
 #
 # Boehm GC
 #
-build/tests/GCTest.mips: $(mips_objects) $(tasks)/build_boehmgc
+build/tests/GCTest.mips: $(tasks)/build_boehmgc
        @mkdir -p `dirname $@`
        cp upstream/build/boehmgc/gctest $@
 
@@ -327,6 +375,20 @@ boehmgctest: build/tests/Env.class build/tests/GCTest.class
        $(JAVA) -cp build tests.Env GC_PRINT_STATS=1  tests.GCTest
 
 
+# TeX
+
+Tangle_COMPILERFLAGS = -o unixruntime
+
+build/tests/Tangle.mips: $(tasks)/build_tex_tangle
+       @mkdir -p `dirname $@`
+       cp upstream/build/tex/tangle.mips $@
+
+
+TeX_COMPILERFLAGS = -o unixruntime
+build/tests/TeX.mips: $(tasks)/build_tex
+       @mkdir -p `dirname $@`
+       cp upstream/build/tex/tex.mips $@
+       
 #
 # Speed tests
 #
@@ -384,6 +446,23 @@ compiletests: $(patsubst %,build/tests/%.class,FTBench MSPackBench DJpeg Test Fr
        @true
 
 
+#
+# Darcs stuff
+#
+
+commit:
+       @if [ -d _darcs ]; then darcs push; \
+       else echo "You need darcs to commit"; false; \
+       fi
+
+update:
+       @if [ -d _darcs ]; then darcs pull; \
+       else wget -nH -rl 16 -N -X _darcs http://nestedvm.darcs.brianweb.net; \
+       fi
+
+#
+# Paper stuff
+#
 charts := $(shell find doc/charts -name \*.dat)
 
 # IVME Paper
@@ -392,15 +471,15 @@ doc/charts/%.pdf: doc/charts/%.dat doc/charts/%.gnuplot
        cd doc/charts; chmod +x boxfill.pl; ./boxfill.pl -g -o unfilled.eps $*.eps
        cd doc/charts; ps2pdf $*.eps
 
-tex := java -cp $(usr)/../../build:.. TeX
-
-#tex := java -cp $(usr)/../../build:.. org.ibex.nestedvm.Interpreter ../tex.mips
-doc/ivme04.pdf: doc/ivme04.tex doc/acmconf.cls $(charts:%.dat=%.pdf) tex.jar upstream/tasks/extract_texinputs
+doc/ivme04.pdf: doc/ivme04.tex doc/acmconf.cls $(charts:%.dat=%.pdf) build/tests/TeX.class
        cp upstream/build/tex/tex.pool upstream/build/tex/texinputs/tex.pool
-       cd upstream/build/tex/texinputs; echo '\latex.ltx' | $(tex)
-       cd upstream/build/tex/texinputs; ln -fs ../../../../doc/* .; rm -f ivme04.aux; touch ivme04.aux; touch ivme04.bbl
-       cd upstream/build/tex/texinputs; echo '\&latex \input ivme04.tex' | $(tex)
-       cd upstream/build/tex/texinputs; dvipdf ivme04.dvi
+       cd upstream/build/tex/texinputs && echo '\latex.ltx' | java -cp $(mips2java_root)/build:$(mips2java_root)/$(CLASSGEN_PATH) tests.TeX
+       cd upstream/build/tex/texinputs && ln -fs ../../../../doc/* .; rm -f ivme04.aux; touch ivme04.aux; touch ivme04.bbl
+       cd upstream/build/tex/texinputs && echo '\&latex \input ivme04.tex' | java -cp $(mips2java_root)/build:$(mips2java_root)/$(CLASSGEN_PATH) tests.TeX
+       cd upstream/build/tex/texinputs && bibtex ivme04
+       cd upstream/build/tex/texinputs && echo '\&latex \input ivme04.tex' | java -cp $(mips2java_root)/build:$(mips2java_root)/$(CLASSGEN_PATH) tests.TeX
+       cd upstream/build/tex/texinputs && dvipdf ivme04.dvi
+       #cp upstream/build/tex/texinputs/ivme04.pdf $@
 
 pdf: doc/ivme04.pdf
        open doc/ivme04.pdf