From f44463b1a2dfa9ad367ea4941cc5765690fecf3e Mon Sep 17 00:00:00 2001 From: William Jhun <36206676+wjhun@users.noreply.github.com> Date: Thu, 16 Jul 2020 19:04:10 -0400 Subject: [PATCH] build for multiple platforms; add mkfs command line option to specify kernel image; initial aarch64 definitions and 'virt' platform hello world; utilize aarch64 tag feature for userspace runtime use --- .circleci/config.yml | 4 +- .gdbinit | 2 +- .gitignore | 3 + Makefile | 137 ++------- README.md | 4 +- {stage3 => platform/pc}/.gdb | 0 {stage3 => platform/pc}/Makefile | 146 ++++++++- {boot => platform/pc/boot}/Makefile | 3 +- {boot => platform/pc/boot}/csum.inc | 0 {boot => platform/pc/boot}/def32.h | 0 {boot => platform/pc/boot}/linker_script | 0 {boot => platform/pc/boot}/service32.s | 0 {boot => platform/pc/boot}/stage1.s | 0 {boot => platform/pc/boot}/stage2.c | 0 {stage3 => platform/pc}/linker_script | 0 {stage3 => platform/pc}/stage3.c | 0 platform/virt/Makefile | 361 +++++++++++++++++++++++ platform/virt/hello.c | 24 ++ platform/virt/linker_script | 35 +++ rules.mk | 25 +- src/aarch64/crt0.s | 5 + src/aarch64/def64.h | 0 src/aarch64/machine.h | 177 +++++++++++ src/{runtime/uniboot.h => config.h} | 49 --- src/kernel/pagecache_internal.h | 2 +- src/{x86_64 => kernel}/region.h | 0 src/kernel/service.c | 3 - src/runtime/metadata.h | 6 +- src/runtime/runtime.h | 7 +- src/runtime/storage.h | 2 +- src/runtime/tuple.c | 2 + src/runtime/tuple.h | 10 + src/unix_process/unix_process_runtime.c | 75 ++++- src/x86_64/def64.h | 3 + src/x86_64/kernel_machine.h | 12 + src/x86_64/machine.h | 30 ++ test/Makefile | 2 +- test/e2e/Makefile | 5 + test/e2e/go/config.json | 4 +- test/e2e/nginx_1.15.6/config.json | 4 +- test/e2e/node_v11.5.0/config.json | 4 +- test/e2e/php_7.3.5/config.json | 4 +- test/e2e/python_3.6.7/config.json | 4 +- test/e2e/ruby_2.5.1/config.json | 4 +- test/e2e/rust/config.json | 4 +- test/go/Makefile | 5 + test/go/common.go | 4 +- test/go/node_test.go | 4 +- test/runtime/Makefile | 19 ++ test/runtime/aio.manifest | 6 - test/runtime/creat.manifest | 6 - test/runtime/dummy.manifest | 6 + test/runtime/dup.manifest | 6 - test/runtime/epoll.manifest | 6 - test/runtime/eventfd.manifest | 6 - test/runtime/fallocate.manifest | 6 - test/runtime/fcntl.manifest | 6 - test/runtime/fst.manifest | 6 - test/runtime/ftrace.manifest | 6 - test/runtime/getdents.manifest | 6 - test/runtime/getrandom.manifest | 6 - test/runtime/hw.manifest | 6 - test/runtime/hws.manifest | 6 - test/runtime/io_uring.manifest | 5 - test/runtime/mkdir.manifest | 6 - test/runtime/mmap.manifest | 6 - test/runtime/nullpage.manifest | 5 - test/runtime/paging.manifest | 5 - test/runtime/pipe.manifest | 6 - test/runtime/readv.manifest | 5 - test/runtime/rename.manifest | 6 - test/runtime/sendfile.manifest | 6 - test/runtime/signal.manifest | 6 - test/runtime/socketpair.manifest | 6 - test/runtime/symlink.manifest | 6 - test/runtime/thread_test.manifest | 5 - test/runtime/time.manifest | 6 - test/runtime/udploop.manifest | 6 - test/runtime/unixsocket.manifest | 6 - test/runtime/unlink.manifest | 6 - test/runtime/vsyscall.manifest | 6 - test/runtime/web.manifest | 5 - test/runtime/webg.manifest | 6 - test/runtime/webs-poll.manifest | 6 - test/runtime/webs-select.manifest | 6 - test/runtime/webs.manifest | 6 - test/runtime/write.manifest | 5 - test/runtime/writev.manifest | 5 - test/unit/Makefile | 1 + tools/Makefile | 9 +- tools/dump.c | 1 - tools/mkfs.c | 22 +- 92 files changed, 1001 insertions(+), 452 deletions(-) rename {stage3 => platform/pc}/.gdb (100%) rename {stage3 => platform/pc}/Makefile (61%) rename {boot => platform/pc/boot}/Makefile (96%) rename {boot => platform/pc/boot}/csum.inc (100%) rename {boot => platform/pc/boot}/def32.h (100%) rename {boot => platform/pc/boot}/linker_script (100%) rename {boot => platform/pc/boot}/service32.s (100%) rename {boot => platform/pc/boot}/stage1.s (100%) rename {boot => platform/pc/boot}/stage2.c (100%) rename {stage3 => platform/pc}/linker_script (100%) rename {stage3 => platform/pc}/stage3.c (100%) create mode 100644 platform/virt/Makefile create mode 100644 platform/virt/hello.c create mode 100644 platform/virt/linker_script create mode 100644 src/aarch64/crt0.s create mode 100644 src/aarch64/def64.h create mode 100644 src/aarch64/machine.h rename src/{runtime/uniboot.h => config.h} (53%) rename src/{x86_64 => kernel}/region.h (100%) create mode 100644 test/runtime/dummy.manifest diff --git a/.circleci/config.yml b/.circleci/config.yml index 12d9cb853..e16c8cec4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,7 +40,7 @@ jobs: - run: sudo gcloud config set project ${GOOGLE_PROJECT_ID} - run: gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE} - - run: mkdir temp && cp output/stage3/bin/stage3.img temp/ && cp output/boot/boot.img temp/ && cp output/tools/bin/mkfs temp/ + - run: mkdir temp && cp output/platform/pc/bin/kernel.img temp/ && cp output/platform/pc/boot/boot.img temp/ && cp output/tools/bin/mkfs temp/ - run: cd temp && tar cvzf nanos-nightly-linux.tar.gz * && gsutil cp nanos-nightly-linux.tar.gz gs://nanos/release/nightly - run: gsutil acl ch -u AllUsers:R gs://nanos/release/nightly/nanos-nightly-linux.tar.gz - run: rm -r temp @@ -92,7 +92,7 @@ jobs: - run: sudo gcloud config set project ${GOOGLE_PROJECT_ID} - run: gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE} - - run: mkdir temp && cp output/stage3/bin/stage3.img temp/ && cp output/boot/boot.img temp/ && cp output/tools/bin/mkfs temp/ + - run: mkdir temp && cp output/platform/pc/bin/kernel.img temp/ && cp output/platform/pc/boot/boot.img temp/ && cp output/tools/bin/mkfs temp/ - run: cd temp && tar cvzf nanos-nightly-darwin.tar.gz * && gsutil cp nanos-nightly-darwin.tar.gz gs://nanos/release/nightly - run: gsutil acl ch -u AllUsers:R gs://nanos/release/nightly/nanos-nightly-darwin.tar.gz - run: rm -r temp diff --git a/.gdbinit b/.gdbinit index b6c3353a3..065f65658 100644 --- a/.gdbinit +++ b/.gdbinit @@ -1,5 +1,5 @@ set architecture i386:x86-64 display/i $pc target remote :1234 -symbol-file ./output/stage3/bin/stage3.img +symbol-file ./output/platform/pc/bin/kernel.img diff --git a/.gitignore b/.gitignore index 072f538ab..5226d6e6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ Makefile.local /tags /TAGS +/GTAGS +/GPATH +/GRTAGS # test artifacts /test/go/go.sum diff --git a/Makefile b/Makefile index 434822e40..5f6526af0 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,10 @@ -SUBDIR= boot stage3 test tools +SUBDIR= $(PLATFORMDIR) test tools # runtime tests / ready-to-use targets TARGET= webg -ifneq ($(NANOS_TARGET_ROOT),) -TARGET_ROOT_OPT= -r $(NANOS_TARGET_ROOT) -endif - -MKFS= $(OUTDIR)/tools/bin/mkfs -BOOTIMG= $(OUTDIR)/boot/boot.img -STAGE3= $(OUTDIR)/stage3/bin/stage3.img - -IMAGE= $(OUTDIR)/image/disk.raw CLEANFILES+= $(IMAGE) -CLEANDIRS+= $(OUTDIR)/image +CLEANDIRS+= $(OUTDIR)/image $(OUTDIR)/platform/$(PLATFORM) $(OUTDIR)/platform LWIPDIR= $(VENDORDIR)/lwip GITFLAGS+= --depth 1 https://github.com/nanovms/lwip.git -b STABLE-2_1_2_RELEASE @@ -39,40 +30,12 @@ AWS_AMI_IMAGE= nanos-$(TARGET) all: image -include rules.mk - -.PHONY: image release contgen mkfs boot stage3 target stage distclean - -image: mkfs boot stage3 target - @ echo "MKFS $@" - @ $(MKDIR) $(dir $(IMAGE)) - $(Q) $(MKFS) $(TARGET_ROOT_OPT) -b $(BOOTIMG) $(IMAGE) >1)) - -run-bridge: image - $(QEMU) $(QEMU_COMMON) $(QEMU_NET) $(QEMU_ACCEL) || exit $$(($$?>>1)) - -run-noaccel: image - $(QEMU) $(QEMU_COMMON) $(QEMU_USERNET) $(QEMU_CPU) || exit $$(($$?>>1)) +run: + $(Q) $(MAKE) -C $(PLATFORMDIR) TARGET=$(TARGET) run +run-bridge: + $(Q) $(MAKE) -C $(PLATFORMDIR) TARGET=$(TARGET) run-bridge + +run-noaccel: + $(Q) $(MAKE) -C $(PLATFORMDIR) TARGET=$(TARGET) run-noaccel ############################################################################## # VMware @@ -238,13 +147,3 @@ create-ec2-snapshot: upload-ec2-image status_message=`$(ECHO) "$$json" | $(JQ) -r ".ImportSnapshotTasks[0].SnapshotTaskDetail.StatusMessage?"`; \ $(PRINTF) "$(CLEAR_LINE)Task $$import_task_id: $$status_message ($$progress%%)"; \ done - -ifeq ($(UNAME_s),Darwin) -REL_OS= darwin -QEMU_ACCEL= -accel $(ACCEL) -cpu host -ACCEL?= hvf -# ACCEL=? hax -else -REL_OS= linux -QEMU_ACCEL= -enable-kvm -cpu host -endif diff --git a/README.md b/README.md index f5032e333..19f5b9f8f 100644 --- a/README.md +++ b/README.md @@ -113,8 +113,8 @@ copy the 3 required files to an appropriate release: ``` cp output/tools/bin/mkfs ~/.ops/0.1.17/. -cp output/boot/boot.img ~/.ops/0.1.17/. -cp output/stage3/bin/stage3.img ~/.ops/0.1.17/. +cp output/platform/pc/boot/boot.img ~/.ops/0.1.17/. +cp output/platform/pc/bin/kernel.img ~/.ops/0.1.17/. ``` ### Contributing diff --git a/stage3/.gdb b/platform/pc/.gdb similarity index 100% rename from stage3/.gdb rename to platform/pc/.gdb diff --git a/stage3/Makefile b/platform/pc/Makefile similarity index 61% rename from stage3/Makefile rename to platform/pc/Makefile index 91055374d..6e172bfdb 100644 --- a/stage3/Makefile +++ b/platform/pc/Makefile @@ -1,6 +1,8 @@ +SUBDIR= boot LWIPDIR= $(VENDORDIR)/lwip -PROGRAMS= stage3.img -SRCS-stage3.img= \ +PROGRAMS= kernel.img + +SRCS-kernel.img= \ $(CURDIR)/stage3.c \ $(OBJDIR)/gitversion.c \ $(SRCDIR)/drivers/ata.c \ @@ -166,7 +168,7 @@ CFLAGS+=$(INCLUDES) # Enable tracing by specifying TRACE=ftrace on command line ifeq ($(TRACE),ftrace) CFLAGS+= -DCONFIG_FTRACE -pg -SRCS-stage3.img+= \ +SRCS-kernel.img+= \ $(SRCDIR)/unix/ftrace.c \ $(ARCHDIR)/ftrace.s endif @@ -180,14 +182,14 @@ VDSO_SRCDIR= $(SRCDIR)/kernel VDSO_OBJDIR= $(OBJDIR)/vdso VDSO_SRCS= $(VDSO_SRCDIR)/vdso.c $(VDSO_SRCDIR)/vdso-now.c VDSO_OBJS= $(patsubst $(VDSO_SRCDIR)/%.c,$(VDSO_OBJDIR)/%.o,$(VDSO_SRCS)) -VDSO_CFLAGS= -DKERNEL -DBUILD_VDSO -I$(INCLUDES) -I$(OBJDIR) -fPIC -c +VDSO_CFLAGS= -DKERNEL -DBUILD_VDSO -I$(INCLUDES) -I$(OBJDIR) -I$(SRCDIR) -fPIC -c VDSO_LDFLAGS= -nostdlib -fPIC -shared --build-id=none --hash-style=both --eh-frame-hdr -T$(ARCHDIR)/vdso.lds VDSO_DEPS= $(patsubst %.o,%.d,$(VDSO_OBJS)) OBJDUMPFLAGS= -d -S -M intel-mnemonic DEPFILES+= $(VDSO_DEPS) -CLEANFILES+= $(foreach f,gitversion.c frame.inc stage3.dis stage3.img src/unix/ftrace.* $(ARCHDIR)/ftrace.*,$(OBJDIR)/$f) $(VDSO_OBJDIR)/vdso.so $(VDSO_OBJDIR)/vdso-image.c $(VDSO_OBJS) $(VDSO_DEPS) -CLEANDIRS+= $(foreach d,output src src/hyperv vdso/src/$(ARCH) vdso/src vdso vendor vendor/lwip vendor/lwip/src,$(OBJDIR)/$d) +CLEANFILES+= $(foreach f,gitversion.c frame.inc kernel.dis kernel.img src/unix/ftrace.* $(ARCHDIR)/ftrace.*,$(OBJDIR)/$f) $(VDSO_OBJDIR)/vdso.so $(VDSO_OBJDIR)/vdso-image.c $(VDSO_OBJS) $(VDSO_DEPS) +CLEANDIRS+= $(foreach d,output/platform output src src/hyperv vdso/src/$(ARCH) vdso/src vdso vendor vendor/lwip vendor/lwip/src platform,$(OBJDIR)/$d) msg_vdsogen= VDSOGEN $@ cmd_vdsogen= $(VDSOGEN) $(VDSO_OBJDIR)/vdso.so $@ @@ -205,20 +207,65 @@ msg_sed= SED $@ cmd_sed= $(SED) -e 's/\#/%/' <$^ >$@ msg_version= VERSION $@ -cmd_version= $(ECHO) "const char *gitversion = \"$(shell $(GIT) rev-parse HEAD)\";" >$@ +cmd_version= $(MKDIR) $(dir $@); $(ECHO) "const char *gitversion = \"$(shell $(GIT) rev-parse HEAD)\";" >$@ + +include ../../rules.mk + +MKFS= $(TOOLDIR)/mkfs +BOOTIMG= $(OBJDIR)/boot/boot.img +KERNEL= $(OBJDIR)/bin/kernel.img + +ifneq ($(ARCH),x86_64) +$(error The pc platform only supports the x86_64 architecture.) +endif + +all: kernel.dis boot -all: stage3.dis +contgen: + $(Q) $(MAKE) -C $(ROOTDIR)/tools $@ -include ../rules.mk +mkfs vdsogen: contgen + $(Q) $(MAKE) -C $(ROOTDIR)/tools $@ -.PHONY: stage3.dis +boot: contgen + $(Q) $(MAKE) -C boot -stage3.dis: $(OBJDIR)/stage3.dis +kernel: contgen $(PROG-kernel.img) $(OBJDIR)/kernel.dis + +target: contgen +ifeq ($(TARGET),) + @echo TARGET variable not specified + @false +endif + $(Q) $(MAKE) -C $(ROOTDIR)/test/runtime $(TARGET) + +ifneq ($(NANOS_TARGET_ROOT),) +TARGET_ROOT_OPT= -r $(NANOS_TARGET_ROOT) +endif + +image: contgen mkfs boot kernel target +ifeq ($(IMAGE),) + @echo IMAGE variable not specified + @false +endif + @ echo "MKFS $@" + @ $(MKDIR) $(dir $(IMAGE)) + $(Q) cd $(ROOTDIR); $(MKFS) $(TARGET_ROOT_OPT) -b $(BOOTIMG) -k $(KERNEL) $(IMAGE) < $(ROOTDIR)/test/runtime/$(TARGET).manifest + +release: mkfs boot kernel + $(Q) $(RM) -r release + $(Q) $(MKDIR) release + $(CP) $(MKFS) release + $(CP) $(BOOTIMG) release + $(CP) $(KERNEL) release + cd release && $(TAR) -czvf nanos-release-$(REL_OS)-${version}.tar.gz * + +.PHONY: mkfs vdsogen boot kernel target image release $(VDSOGEN): @$(MAKE) -C $(ROOTDIR)/tools vdsogen -$(OBJDIR)/stage3.dis: $(PROG-stage3.img) +$(OBJDIR)/kernel.dis: $(PROG-kernel.img) $(call cmd,objdump) $(VDSO_OBJDIR)/%.o: $(VDSO_SRCDIR)/%.c @@ -228,10 +275,10 @@ $(VDSO_OBJDIR)/%.o: $(VDSO_SRCDIR)/%.c $(VDSO_OBJDIR)/vdso.so: $(VDSO_OBJS) $(call cmd,vdso_ld) -$(VDSO_OBJDIR)/vdso-image.c: $(VDSOGEN) $(VDSO_OBJDIR)/vdso.so +$(VDSO_OBJDIR)/vdso-image.c: contgen $(VDSOGEN) $(VDSO_OBJDIR)/vdso.so $(call cmd,vdsogen) -$(PROG-stage3.img): linker_script $(VDSO_OBJDIR)/vdso-image.c +$(PROG-kernel.img): linker_script $(VDSO_OBJDIR)/vdso-image.c $(OBJDIR)/gitversion.c: $(ROOTDIR)/.git/index $(ROOTDIR)/.git/HEAD $(call cmd,version) @@ -241,7 +288,6 @@ $(OBJDIR)/src/$(ARCH)/crt0.o: $(OBJDIR)/frame.inc $(OBJDIR)/frame.inc: $(ARCHDIR)/frame.h $(call cmd,sed) -# XXX fix up for arm ifeq ($(UNAME_s),Darwin) ELF_TARGET= -target x86_64-elf CFLAGS+= $(ELF_TARGET) @@ -249,7 +295,77 @@ VDSO_CFLAGS+= $(ELF_TARGET) VDSO_LDFLAGS+= -undefined dynamic_lookup LD= x86_64-elf-ld OBJDUMP= x86_64-elf-objdump +REL_OS= darwin +QEMU_ACCEL= -accel $(ACCEL) -cpu host +ACCEL?= hvf else # XXX already defined? LD= $(CROSS_COMPILE)ld +REL_OS= linux +QEMU_ACCEL= -enable-kvm -cpu host endif + +############################################################################## +# run + +.PHONY: run run-bridge run-nokvm + +QEMU= qemu-system-x86_64 +MACHINE_TYPE= q35 +QEMU_CPU= -cpu max +DISPLAY= none +STORAGE= virtio-scsi +STORAGE_BUS= ,bus=pci.2,addr=0x0 +NETWORK= virtio-net +NETWORK_BUS= ,bus=pci.3,addr=0x0 + +QEMU_MACHINE= -machine $(MACHINE_TYPE) +QEMU_MEMORY= -m 2G +QEMU_PCI= -device pcie-root-port,port=0x10,chassis=1,id=pci.1,bus=$(PCI_BUS),multifunction=on,addr=0x3 \ + -device pcie-root-port,port=0x11,chassis=2,id=pci.2,bus=$(PCI_BUS),addr=0x3.0x1 \ + -device pcie-root-port,port=0x12,chassis=3,id=pci.3,bus=$(PCI_BUS),addr=0x3.0x2 + +ifeq ($(DISPLAY),none) +QEMU_DISPLAY= -display none +else ifeq ($(DISPLAY),vga) +QEMU_DISPLAY= +else +$(error Unsupported DISPLAY=$(DISPLAY)) +endif +QEMU_SERIAL= -serial stdio +QEMU_STORAGE= -drive if=none,id=hd0,format=raw,file=$(IMAGE) +ifeq ($(STORAGE),virtio-scsi) +QEMU_STORAGE+= -device virtio-scsi-pci$(STORAGE_BUS),id=scsi0 -device scsi-hd,bus=scsi0.0,drive=hd0 +else ifeq ($(STORAGE),pvscsi) +QEMU_STORAGE+= -device pvscsi$(STORAGE_BUS),id=scsi0 -device scsi-hd,bus=scsi0.0,drive=hd0 +else ifeq ($(STORAGE),virtio-blk) +QEMU_STORAGE+= -device virtio-blk-pci$(STORAGE_BUS),drive=hd0 +else ifeq ($(STORAGE),ide) +MACHINE_TYPE= pc # no AHCI support yet +QEMU_STORAGE+= -device ide-hd,bus=ide.0,drive=hd0 +else +$(error Unsupported STORAGE=$(STORAGE)) +endif +ifeq ($(MACHINE_TYPE),q35) +PCI_BUS= pcie.0 +else +PCI_BUS= pci.0 +endif +QEMU_TAP= -netdev tap,id=n0,ifname=tap0,script=no,downscript=no +QEMU_NET= -device $(NETWORK)$(NETWORK_BUS),mac=7e:b8:7e:87:4a:ea,netdev=n0 $(QEMU_TAP) +QEMU_USERNET= -device $(NETWORK)$(NETWORK_BUS),netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080,hostfwd=tcp::9090-:9090,hostfwd=udp::5309-:5309 -object filter-dump,id=filter0,netdev=n0,file=/tmp/nanos.pcap +QEMU_FLAGS= +#QEMU_FLAGS+= -smp 4 +#QEMU_FLAGS+= -d int -D int.log +#QEMU_FLAGS+= -s -S + +QEMU_COMMON= $(QEMU_MACHINE) $(QEMU_MEMORY) $(QEMU_DISPLAY) $(QEMU_PCI) $(QEMU_SERIAL) $(QEMU_STORAGE) -device isa-debug-exit -no-reboot $(QEMU_FLAGS) + +run: image + $(QEMU) $(QEMU_COMMON) $(QEMU_USERNET) $(QEMU_ACCEL) || exit $$(($$?>>1)) + +run-bridge: image + $(QEMU) $(QEMU_COMMON) $(QEMU_NET) $(QEMU_ACCEL) || exit $$(($$?>>1)) + +run-noaccel: image + $(QEMU) $(QEMU_COMMON) $(QEMU_USERNET) $(QEMU_CPU) || exit $$(($$?>>1)) diff --git a/boot/Makefile b/platform/pc/boot/Makefile similarity index 96% rename from boot/Makefile rename to platform/pc/boot/Makefile index 148d0844e..84a793650 100644 --- a/boot/Makefile +++ b/platform/pc/boot/Makefile @@ -56,9 +56,10 @@ cmd_objcopy= $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ all: boot -include ../rules.mk +include ../../../rules.mk CLEANFILES+= $(foreach f,boot.img stage1 stage1.lst stage2.pad stage2.bin stage2.strip,$(OBJDIR)/$f) +CLEANDIRS+= $(OBJDIR)/platform/pc $(OBJDIR)/platform .PHONY: boot diff --git a/boot/csum.inc b/platform/pc/boot/csum.inc similarity index 100% rename from boot/csum.inc rename to platform/pc/boot/csum.inc diff --git a/boot/def32.h b/platform/pc/boot/def32.h similarity index 100% rename from boot/def32.h rename to platform/pc/boot/def32.h diff --git a/boot/linker_script b/platform/pc/boot/linker_script similarity index 100% rename from boot/linker_script rename to platform/pc/boot/linker_script diff --git a/boot/service32.s b/platform/pc/boot/service32.s similarity index 100% rename from boot/service32.s rename to platform/pc/boot/service32.s diff --git a/boot/stage1.s b/platform/pc/boot/stage1.s similarity index 100% rename from boot/stage1.s rename to platform/pc/boot/stage1.s diff --git a/boot/stage2.c b/platform/pc/boot/stage2.c similarity index 100% rename from boot/stage2.c rename to platform/pc/boot/stage2.c diff --git a/stage3/linker_script b/platform/pc/linker_script similarity index 100% rename from stage3/linker_script rename to platform/pc/linker_script diff --git a/stage3/stage3.c b/platform/pc/stage3.c similarity index 100% rename from stage3/stage3.c rename to platform/pc/stage3.c diff --git a/platform/virt/Makefile b/platform/virt/Makefile new file mode 100644 index 000000000..6828c0ba8 --- /dev/null +++ b/platform/virt/Makefile @@ -0,0 +1,361 @@ +LWIPDIR= $(VENDORDIR)/lwip +PROGRAMS= kernel.elf + +# XXX temp +WITHOUT_SSP= 1 + +SRCS-kernel.elf= \ + $(SRCDIR)/aarch64/crt0.s \ + $(CURDIR)/hello.c + +# SRCS-kernel.elf= \ +# $(CURDIR)/stage3.c \ +# $(OBJDIR)/gitversion.c \ +# $(SRCDIR)/drivers/ata.c \ +# $(SRCDIR)/drivers/ata-pci.c \ +# $(SRCDIR)/drivers/console.c \ +# $(SRCDIR)/drivers/storage.c \ +# $(SRCDIR)/drivers/vga.c \ +# $(SRCDIR)/gdb/gdbstub.c \ +# $(SRCDIR)/gdb/gdbtcp.c \ +# $(SRCDIR)/gdb/gdbutil.c \ +# $(SRCDIR)/http/http.c \ +# $(SRCDIR)/kernel/backed_heap.c \ +# $(SRCDIR)/kernel/elf.c \ +# $(SRCDIR)/kernel/kernel.c \ +# $(SRCDIR)/kernel/kvm_platform.c \ +# $(SRCDIR)/kernel/pagecache.c \ +# $(SRCDIR)/kernel/pci.c \ +# $(SRCDIR)/kernel/pvclock.c \ +# $(SRCDIR)/kernel/schedule.c \ +# $(SRCDIR)/kernel/service.c \ +# $(SRCDIR)/kernel/symtab.c \ +# $(SRCDIR)/kernel/vdso-now.c \ +# $(SRCDIR)/net/direct.c \ +# $(SRCDIR)/net/net.c \ +# $(SRCDIR)/net/netsyscall.c \ +# $(SRCDIR)/runtime/bitmap.c \ +# $(SRCDIR)/runtime/buffer.c \ +# $(SRCDIR)/runtime/extra_prints.c \ +# $(SRCDIR)/runtime/format.c \ +# $(SRCDIR)/runtime/heap/freelist.c \ +# $(SRCDIR)/runtime/heap/id.c \ +# $(SRCDIR)/runtime/heap/mcache.c \ +# $(SRCDIR)/runtime/heap/objcache.c \ +# $(SRCDIR)/runtime/memops.c \ +# $(SRCDIR)/runtime/merge.c \ +# $(SRCDIR)/runtime/pqueue.c \ +# $(SRCDIR)/runtime/queue.c \ +# $(SRCDIR)/runtime/random.c \ +# $(SRCDIR)/runtime/range.c \ +# $(SRCDIR)/runtime/rbtree.c \ +# $(SRCDIR)/runtime/runtime_init.c \ +# $(SRCDIR)/runtime/sg.c \ +# $(SRCDIR)/runtime/sha256.c \ +# $(SRCDIR)/runtime/symbol.c \ +# $(SRCDIR)/runtime/table.c \ +# $(SRCDIR)/runtime/timer.c \ +# $(SRCDIR)/runtime/tuple.c \ +# $(SRCDIR)/runtime/string.c \ +# $(SRCDIR)/runtime/crypto/chacha.c \ +# $(SRCDIR)/tfs/tfs.c \ +# $(SRCDIR)/tfs/tlog.c \ +# $(SRCDIR)/unix/aio.c \ +# $(SRCDIR)/unix/blockq.c \ +# $(SRCDIR)/unix/exec.c \ +# $(SRCDIR)/unix/eventfd.c \ +# $(SRCDIR)/unix/filesystem.c \ +# $(SRCDIR)/unix/futex.c \ +# $(SRCDIR)/unix/io_uring.c \ +# $(SRCDIR)/unix/mktime.c \ +# $(SRCDIR)/unix/mmap.c \ +# $(SRCDIR)/unix/notify.c \ +# $(SRCDIR)/unix/poll.c \ +# $(SRCDIR)/unix/signal.c \ +# $(SRCDIR)/unix/socket.c \ +# $(SRCDIR)/unix/special.c \ +# $(SRCDIR)/unix/syscall.c \ +# $(SRCDIR)/unix/thread.c \ +# $(SRCDIR)/unix/timer.c \ +# $(SRCDIR)/unix/unix_clock.c \ +# $(SRCDIR)/unix/unix.c \ +# $(SRCDIR)/unix/vdso.c \ +# $(SRCDIR)/unix/pipe.c \ +# $(SRCDIR)/virtio/virtio_net.c \ +# $(SRCDIR)/virtio/virtio_pci.c \ +# $(SRCDIR)/virtio/virtio_storage.c \ +# $(SRCDIR)/virtio/virtio_scsi.c \ +# $(SRCDIR)/virtio/virtqueue.c \ +# $(SRCDIR)/virtio/scsi.c \ +# $(SRCDIR)/vmware/vmxnet3_net.c \ +# $(SRCDIR)/vmware/vmxnet3_queue.c \ +# $(SRCDIR)/vmware/pvscsi.c \ +# $(SRCDIR)/xen/xen.c \ +# $(SRCDIR)/xen/xennet.c \ +# $(SRCDIR)/aarch64/ap.s \ +# $(SRCDIR)/aarch64/apic.c \ +# $(SRCDIR)/aarch64/breakpoint.c \ +# $(SRCDIR)/aarch64/clock.c \ +# $(SRCDIR)/aarch64/flush.c \ +# $(SRCDIR)/aarch64/hpet.c \ +# $(SRCDIR)/aarch64/interrupt.c \ +# $(SRCDIR)/aarch64/mp.c \ +# $(SRCDIR)/aarch64/page.c \ +# $(SRCDIR)/aarch64/rtc.c \ +# $(SRCDIR)/aarch64/serial.c \ +# $(SRCDIR)/aarch64/synth.c \ +# $(SRCDIR)/aarch64/x2apic.c \ +# $(SRCDIR)/aarch64/xapic.c \ +# $(VDSO_OBJDIR)/vdso-image.c \ +# $(SRCS-lwip) + +SRCS-lwip= \ + $(LWIPDIR)/src/core/def.c \ + $(LWIPDIR)/src/core/inet_chksum.c \ + $(LWIPDIR)/src/core/init.c \ + $(LWIPDIR)/src/core/ip.c \ + $(LWIPDIR)/src/core/ipv4/dhcp.c \ + $(LWIPDIR)/src/core/ipv4/etharp.c \ + $(LWIPDIR)/src/core/ipv4/icmp.c \ + $(LWIPDIR)/src/core/ipv4/ip4_addr.c \ + $(LWIPDIR)/src/core/ipv4/ip4_frag.c \ + $(LWIPDIR)/src/core/ipv4/ip4.c \ + $(LWIPDIR)/src/core/ipv6/icmp6.c \ + $(LWIPDIR)/src/core/ipv6/ip6.c \ + $(LWIPDIR)/src/core/ipv6/ip6_addr.c \ + $(LWIPDIR)/src/core/ipv6/ip6_frag.c \ + $(LWIPDIR)/src/core/ipv6/mld6.c \ + $(LWIPDIR)/src/core/ipv6/nd6.c \ + $(LWIPDIR)/src/core/mem.c \ + $(LWIPDIR)/src/core/memp.c \ + $(LWIPDIR)/src/core/netif.c \ + $(LWIPDIR)/src/core/pbuf.c \ + $(LWIPDIR)/src/core/stats.c \ + $(LWIPDIR)/src/core/tcp_in.c \ + $(LWIPDIR)/src/core/tcp_out.c \ + $(LWIPDIR)/src/core/tcp.c \ + $(LWIPDIR)/src/core/timeouts.c \ + $(LWIPDIR)/src/core/udp.c \ + $(LWIPDIR)/src/api/err.c \ + $(LWIPDIR)/src/netif/ethernet.c + +INCLUDES=\ + -I$(SRCDIR) \ + -I$(ARCHDIR) \ + -I$(SRCDIR)/gdb \ + -I$(SRCDIR)/http \ + -I$(SRCDIR)/kernel \ + -I$(SRCDIR)/net \ + -I$(SRCDIR)/runtime \ + -I$(SRCDIR)/tfs \ + -I$(SRCDIR)/unix \ + -I$(SRCDIR)/unix_process \ + -I$(SRCDIR)/xen/public \ + -I$(LWIPDIR)/src/include + +AFLAGS+=-I$(ARCHDIR) + +CFLAGS+=$(KERNCFLAGS) -DKERNEL -mcpu=cortex-a57 +CFLAGS+=-Wno-address # lwIP build sadness +CFLAGS+=$(INCLUDES) + +# Enable tracing by specifying TRACE=ftrace on command line +ifeq ($(TRACE),ftrace) +CFLAGS+= -DCONFIG_FTRACE -pg +SRCS-kernel.elf+= \ + $(SRCDIR)/unix/ftrace.c \ + $(ARCHDIR)/ftrace.s +endif + +#CFLAGS+= -DLWIPDIR_DEBUG -DEPOLL_DEBUG -DNETSYSCALL_DEBUG -DKERNEL_DEBUG +AFLAGS+= -I$(OBJDIR)/ +LDFLAGS+= $(KERNLDFLAGS) -T linker_script + +VDSOGEN= $(TOOLDIR)/vdsogen +VDSO_SRCDIR= $(SRCDIR)/kernel +VDSO_OBJDIR= $(OBJDIR)/vdso +VDSO_SRCS= $(VDSO_SRCDIR)/vdso.c $(VDSO_SRCDIR)/vdso-now.c +VDSO_OBJS= $(patsubst $(VDSO_SRCDIR)/%.c,$(VDSO_OBJDIR)/%.o,$(VDSO_SRCS)) +VDSO_CFLAGS= -DKERNEL -DBUILD_VDSO -I$(INCLUDES) -I$(OBJDIR) -I$(SRCDIR) -fPIC -c +VDSO_LDFLAGS= -nostdlib -fPIC -shared --build-id=none --hash-style=both --eh-frame-hdr -T$(ARCHDIR)/vdso.lds +VDSO_DEPS= $(patsubst %.o,%.d,$(VDSO_OBJS)) +OBJDUMPFLAGS= -d -S + +DEPFILES+= $(VDSO_DEPS) +CLEANFILES+= $(foreach f,gitversion.c frame.inc kernel.dis kernel.elf bin/kernel.img src/unix/ftrace.* $(ARCHDIR)/ftrace.*,$(OBJDIR)/$f) $(VDSO_OBJDIR)/vdso.so $(VDSO_OBJDIR)/vdso-image.c $(VDSO_OBJS) $(VDSO_DEPS) +CLEANDIRS+= $(foreach d,output/platform output src vdso/src/$(ARCH) vdso/src vdso vendor vendor/lwip vendor/lwip/src platform,$(OBJDIR)/$d) + +OBJCOPYFLAGS = -S -O binary + +msg_vdsogen= VDSOGEN $@ +cmd_vdsogen= $(VDSOGEN) $(VDSO_OBJDIR)/vdso.so $@ + +msg_vdso_cc= CC $@ +cmd_vdso_cc= $(CC) $(DEPFLAGS) $(VDSO_CFLAGS) -c $< -o $@ + +msg_vdso_ld= LD $@ +cmd_vdso_ld= $(LD) $(VDSO_LDFLAGS) $(VDSO_OBJS) -o $@ + +msg_objdump= OBJDUMP $@ +cmd_objdump= $(OBJDUMP) $(OBJDUMPFLAGS) $(OBJDUMPFLAGS_$(@F)) $< $< >$@ + +msg_objcopy= OBJCOPY $@ +cmd_objcopy= $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ + +msg_sed= SED $@ +cmd_sed= $(SED) -e 's/\#/%/' <$^ >$@ + +msg_version= VERSION $@ +cmd_version= $(MKDIR) $(dir $@); $(ECHO) "const char *gitversion = \"$(shell $(GIT) rev-parse HEAD)\";" >$@ + +include ../../rules.mk + +MKFS= $(TOOLDIR)/mkfs +KERNEL= $(OBJDIR)/bin/kernel.img + +ifneq ($(ARCH),aarch64) +$(error The virt platform only supports the aarch64 architecture.) +endif + +all: $(KERNEL) kernel.dis + +contgen: + $(Q) $(MAKE) -C $(ROOTDIR)/tools $@ + +mkfs vdsogen: contgen + $(Q) $(MAKE) -C $(ROOTDIR)/tools $@ + +kernel: contgen $(PROG-kernel.elf) $(OBJDIR)/kernel.dis $(KERNEL) + +target: contgen +ifeq ($(TARGET),) + @echo TARGET variable not specified + @false +endif + $(Q) $(MAKE) -C $(ROOTDIR)/test/runtime $(TARGET) + +ifneq ($(NANOS_TARGET_ROOT),) +TARGET_ROOT_OPT= -r $(NANOS_TARGET_ROOT) +endif + +image: contgen mkfs kernel target +ifeq ($(IMAGE),) + @echo IMAGE variable not specified + @false +endif + @ echo "MKFS $@" + @ $(MKDIR) $(dir $(IMAGE)) + $(Q) cd $(ROOTDIR); $(MKFS) $(TARGET_ROOT_OPT) -k $(KERNEL) $(IMAGE) < $(ROOTDIR)/test/runtime/$(TARGET).manifest + +release: mkfs kernel + $(Q) $(RM) -r release + $(Q) $(MKDIR) release + $(CP) $(MKFS) release + $(CP) $(KERNEL) release + cd release && $(TAR) -czvf nanos-release-$(REL_OS)-${version}.tar.gz * + +.PHONY: mkfs vdsogen kernel target image release + +$(VDSOGEN): + @$(MAKE) -C $(ROOTDIR)/tools vdsogen + +$(OBJDIR)/kernel.dis: $(PROG-kernel.elf) + $(call cmd,objdump) + +$(VDSO_OBJDIR)/%.o: $(VDSO_SRCDIR)/%.c + @$(MKDIR) $(dir $@) + $(call cmd,vdso_cc) + +$(VDSO_OBJDIR)/vdso.so: $(VDSO_OBJS) + $(call cmd,vdso_ld) + +$(VDSO_OBJDIR)/vdso-image.c: contgen $(VDSOGEN) $(VDSO_OBJDIR)/vdso.so + $(call cmd,vdsogen) + +$(PROG-kernel.elf): linker_script # $(VDSO_OBJDIR)/vdso-image.c + +$(KERNEL): $(PROG-kernel.elf) + $(call cmd,objcopy) + +$(OBJDIR)/gitversion.c: $(ROOTDIR)/.git/index $(ROOTDIR)/.git/HEAD + $(call cmd,version) + +# $(OBJDIR)/src/$(ARCH)/crt0.o: $(OBJDIR)/frame.inc + +$(OBJDIR)/frame.inc: $(ARCHDIR)/frame.h + $(call cmd,sed) + +#ifeq ($(UNAME_s),Darwin) +#ELF_TARGET= -target aarch64-littleelf +#CFLAGS+= $(ELF_TARGET) +#VDSO_CFLAGS+= $(ELF_TARGET) +#VDSO_LDFLAGS+= -undefined dynamic_lookup +#LD= aarch64-elf-ld +#OBJDUMP= aarch64-elf-objdump +#REL_OS= darwin +#QEMU_ACCEL= -accel $(ACCEL) -cpu host +#ACCEL?= hvf +#else +# XXX already defined? +LD= $(CROSS_COMPILE)ld +REL_OS= linux +QEMU_ACCEL= -enable-kvm -cpu host +#endif + +############################################################################## +# run + +.PHONY: run run-bridge run-nokvm + +QEMU= qemu-system-aarch64 +MACHINE_TYPE= virt +QEMU_CPU= -cpu max +DISPLAY= none +STORAGE= virtio-scsi +#STORAGE_BUS= ,bus=pci.2,addr=0x0 +NETWORK= virtio-net +#NETWORK_BUS= ,bus=pci.3,addr=0x0 + +QEMU_MACHINE= -machine $(MACHINE_TYPE) +QEMU_MEMORY= -m 1G +#QEMU_PCI= -device pcie-root-port,port=0x10,chassis=1,id=pci.1,bus=$(PCI_BUS),multifunction=on,addr=0x3 \ +# -device pcie-root-port,port=0x11,chassis=2,id=pci.2,bus=$(PCI_BUS),addr=0x3.0x1 \ +# -device pcie-root-port,port=0x12,chassis=3,id=pci.3,bus=$(PCI_BUS),addr=0x3.0x2 +#QEMU_KERNEL= -kernel $(KERNEL) +QEMU_KERNEL= -kernel $(PROG-kernel.elf) + +QEMU_DISPLAY= -display none +#QEMU_DISPLAY= -nographic +QEMU_SERIAL= -serial stdio +QEMU_STORAGE= -drive if=none,id=hd0,format=raw,file=$(IMAGE) +ifeq ($(STORAGE),virtio-scsi) +QEMU_STORAGE+= -device virtio-scsi-device,id=scsi0 -device scsi-hd,bus=scsi0.0,drive=hd0 +else ifeq ($(STORAGE),pvscsi) +QEMU_STORAGE+= -device pvscsi$(STORAGE_BUS),id=scsi0 -device scsi-hd,bus=scsi0.0,drive=hd0 +else ifeq ($(STORAGE),virtio-blk) +QEMU_STORAGE+= -device virtio-blk-pci$(STORAGE_BUS),drive=hd0 +else ifeq ($(STORAGE),ide) +MACHINE_TYPE= pc # no AHCI support yet +QEMU_STORAGE+= -device ide-hd,bus=ide.0,drive=hd0 +else +$(error Unsupported STORAGE=$(STORAGE)) +endif +QEMU_TAP= -netdev tap,id=n0,ifname=tap0,script=no,downscript=no +QEMU_NET= -device $(NETWORK)$(NETWORK_BUS),mac=7e:b8:7e:87:4a:ea,netdev=n0 $(QEMU_TAP) +QEMU_USERNET= -device $(NETWORK)$(NETWORK_BUS),netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080,hostfwd=tcp::9090-:9090,hostfwd=udp::5309-:5309 -object filter-dump,id=filter0,netdev=n0,file=/tmp/nanos.pcap +QEMU_FLAGS= -d in_asm -D $(ROOTDIR)/asm.out +#QEMU_FLAGS+= -smp 4 +#QEMU_FLAGS+= -d int -D int.log +#QEMU_FLAGS+= -s -S + +QEMU_COMMON= $(QEMU_MACHINE) $(QEMU_MEMORY) $(QEMU_KERNEL) $(QEMU_DISPLAY) $(QEMU_SERIAL) -no-reboot $(QEMU_FLAGS) + +run: image + $(QEMU) $(QEMU_COMMON) $(QEMU_USERNET) $(QEMU_ACCEL) || exit $$(($$?>>1)) + +run-bridge: image + $(QEMU) $(QEMU_COMMON) $(QEMU_NET) $(QEMU_ACCEL) || exit $$(($$?>>1)) + +# $(QEMU) $(QEMU_COMMON) $(QEMU_USERNET) $(QEMU_CPU) || exit $$(($$?>>1)) +run-noaccel: image + $(QEMU) $(QEMU_COMMON) $(QEMU_CPU) || exit $$(($$?>>1)) diff --git a/platform/virt/hello.c b/platform/virt/hello.c new file mode 100644 index 000000000..2a1ff7917 --- /dev/null +++ b/platform/virt/hello.c @@ -0,0 +1,24 @@ +/* just a test */ + +volatile unsigned int *UART0DR = (unsigned int *)0x09000000; /* data register */ +volatile unsigned int *UART0FR = (unsigned int *)0x09000018; /* flag register */ + +#define UART_FR_TXFF (1 << 5) /* TX FIFO full */ + +void putc(char c) +{ + while ((*UART0FR) & UART_FR_TXFF); + *UART0DR = c; +} + +void puts(char *s) +{ + while (*s != '\0') + putc(*s++); +} + +int main(void) +{ + puts("unibooty\n"); + return 0; +} diff --git a/platform/virt/linker_script b/platform/virt/linker_script new file mode 100644 index 000000000..a4e773bd1 --- /dev/null +++ b/platform/virt/linker_script @@ -0,0 +1,35 @@ +OUTPUT_FORMAT("elf64-littleaarch64") + +ENTRY(_start) + +SECTIONS +{ + . = 0x40000000; + __start = .; + + text_start = .; + .text : ALIGN(4096) + { + *(.text) + *(.text.*) + } + text_end = .; + + .data : ALIGN(4096) + { + *(.data) + *(.data.*) + } + + PROVIDE(bss_start = .); + .bss : ALIGN(32) + { + *(.bss) + *(.bss.*) + *(COMMON) + } + PROVIDE(bss_end = .); + + . = 0x41000000; /* XXX temp stack, for test */ + stack_top = .; +} diff --git a/rules.mk b/rules.mk index e26afcf0b..40a6f2afe 100644 --- a/rules.mk +++ b/rules.mk @@ -10,19 +10,24 @@ TOOLDIR= $(OUTDIR)/tools/bin UNAME_s= $(shell uname -s) ARCH?= $(shell uname -m) ARCHDIR= $(SRCDIR)/$(ARCH) +PLATFORM?= pc +PLATFORMDIR= $(ROOTDIR)/platform/$(PLATFORM) +PLATFORMOBJDIR= $(subst $(ROOTDIR),$(OUTDIR),$(PLATFORMDIR)) +IMAGE= $(OUTDIR)/image/disk.raw # To reveal verbose build messages, override Q= in command line. Q= @ ECHO= echo CAT= cat -CC= $(CROSS_COMPILE)gcc +# XXX llvm for darwin CP= cp DD= dd ifeq ($(UNAME_s),Darwin) GNUTAR= gnutar else GNUTAR= tar +NATIVE_CC= gcc endif GIT= git GO= go @@ -32,6 +37,17 @@ AS= nasm else AS= $(CROSS_COMPILE)as endif + +ifneq ($(CROSS_COMPILE),) +CC= $(CROSS_COMPILE)gcc +else +ifeq ($(UNAME_s),Darwin) +CC= cc +else +CC= gcc +endif +endif + LD= $(CC) LN= ln SED= sed @@ -55,10 +71,13 @@ DEPFLAGS= -MD -MP -MT $@ KERNCFLAGS= -nostdinc \ -fno-builtin \ - -mno-sse \ - -mno-sse2 \ -fdata-sections \ -ffunction-sections + +ifeq ($(ARCH),x86_64) +KERNCFLAGS+= -mno-sse \ + -mno-sse2 +endif KERNCFLAGS+= -fno-omit-frame-pointer KERNLDFLAGS= --gc-sections -n diff --git a/src/aarch64/crt0.s b/src/aarch64/crt0.s new file mode 100644 index 000000000..31b449542 --- /dev/null +++ b/src/aarch64/crt0.s @@ -0,0 +1,5 @@ + .globl _start +_start: + adrp x0, stack_top + mov sp, x0 + bl main diff --git a/src/aarch64/def64.h b/src/aarch64/def64.h new file mode 100644 index 000000000..e69de29bb diff --git a/src/aarch64/machine.h b/src/aarch64/machine.h new file mode 100644 index 000000000..d16c86ff3 --- /dev/null +++ b/src/aarch64/machine.h @@ -0,0 +1,177 @@ +typedef unsigned char u8; +typedef char s8; +typedef unsigned short u16; +typedef short s16; +typedef unsigned int u32; +typedef int s32; +typedef unsigned long long u64; +typedef long long s64; +typedef __uint128_t u128; + +typedef u64 word; +typedef u64 bytes; + +#define U32_MAX (~0u) +#define S32_MAX ((s32)(U32_MAX >> 1)) +#define S32_MIN (-S32_MAX - 1) + +#define U64_MAX (~0ull) +#define S64_MAX ((s64)(U64_MAX >> 1)) +#define S64_MIN (-S64_MAX - 1) + +#define USER_VA_TAG_OFFSET 56 +#define USER_VA_TAG_WIDTH 8 + +#define pointer_from_u64(__a) ((void *)(__a)) +#define u64_from_pointer(__a) ((u64)(__a)) +#define field_from_u64(u, f) (((u) >> f ## _SHIFT) & MASK(f ## _BITS)) + +#define DIV(__x, __by, __q, __r) \ + do { asm("udiv %0, %2, %3; msub %1, %0, %3, %2" : \ + "=&r"(__q), "=r"(__r) : "r"(__x), "r"(__by)); } while(0) + +#if 0 +#define ROL(__x, __b)\ + ({\ + __asm__("rolq %1, %0": "=g"(__x): "i" (__b));\ + __x;\ + }) +#endif + +/* These are defined as functions to avoid multiple evaluation of x. */ +static inline u16 +__bswap16(u16 _x) +{ + return (u16)(_x << 8 | _x >> 8); +} + +static inline u32 +__bswap32(u32 _x) +{ + return ((u32)__bswap16(_x & 0xffff) << 16) | __bswap16(_x >> 16); +} + +static inline u64 +__bswap64(u64 _x) +{ + return ((u64)__bswap32(_x & 0xffffffff) << 32) | __bswap32(_x >> 32); +} + +#ifndef htobe16 +#define htobe16(x) __bswap16(x) +#endif +#ifndef be16toh +#define be16toh(x) __bswap16(x) +#endif +#ifndef htole16 +#define htole16(x) (x) +#endif +#ifndef le16toh +#define le16toh(x) (x) +#endif + +#ifndef htobe32 +#define htobe32(x) __bswap32(x) +#endif +#ifndef be32toh +#define be32toh(x) __bswap32(x) +#endif +#ifndef htole32 +#define htole32(x) (x) +#endif +#ifndef le32toh +#define le32toh(x) (x) +#endif + +#ifndef htobe64 +#define htobe64(x) __bswap64(x) +#endif +#ifndef be64toh +#define be64toh(x) __bswap64(x) +#endif +#ifndef htole64 +#define htole64(x) (x) +#endif +#ifndef le64toh +#define le64toh(x) (x) +#endif + +#ifdef KERNEL +#define VA_TAG_BASE KMEM_BASE +#define VA_TAG_OFFSET 39 +#define VA_TAG_WIDTH 8 +#else +#define VA_TAG_BASE 0 +#define VA_TAG_OFFSET USER_VA_TAG_OFFSET +#define VA_TAG_WIDTH USER_VA_TAG_WIDTH +#endif + +static inline void *tag(void* v, u64 tval) { + return pointer_from_u64(VA_TAG_BASE | (tval << VA_TAG_OFFSET) | u64_from_pointer(v)); +} + +static inline u16 tagof(void* v) { + return (u64_from_pointer(v) >> VA_TAG_OFFSET) & ((1ull << VA_TAG_WIDTH) - 1); +} + +#define valueof(__x) (__x) +/* returns -1 if x == 0, caller must check */ +static inline u64 msb(u64 x) +{ + return x ? 63 - __builtin_clzll(x) : -1ull; +} + +static inline u64 lsb(u64 x) +{ + return ((s64)__builtin_ffsll(x)) - 1; +} + + +static inline void compiler_barrier(void) +{ +} + +static inline void write_barrier(void) +{ +} + +static inline void read_barrier(void) +{ +} + +static inline void memory_barrier(void) +{ +} + +#if 0 +static inline word fetch_and_add(word *variable, word value) +{ + asm volatile("lock; xadd %0, %1" : "+r" (value), "+m" (*variable) :: "memory", "cc"); + return value; +} + +static inline void atomic_set_bit(u64 *target, u64 bit) +{ + asm volatile("lock btsq %1, %0": "+m"(*target): "r"(bit) : "memory"); +} + +static inline void atomic_clear_bit(u64 *target, u64 bit) +{ + asm volatile("lock btrq %1, %0": "+m"(*target):"r"(bit) : "memory"); +} +#endif + +static inline word fetch_and_add(word *target, word num) +{ + return __sync_fetch_and_add(target, num); +} + +static inline u64 fetch_and_add_64(u64 *target, u64 num) +{ + return __sync_fetch_and_add(target, num); +} + +static inline void kern_pause(void) +{ + // XXX +} diff --git a/src/runtime/uniboot.h b/src/config.h similarity index 53% rename from src/runtime/uniboot.h rename to src/config.h index d30c486cd..df3890c9e 100644 --- a/src/runtime/uniboot.h +++ b/src/config.h @@ -1,52 +1,3 @@ -#include - -#define BOOTFS_SIZE (8 * MB) - -#define KMEM_BASE 0xffff800000000000ull -#define KERNEL_BASE 0xffffffff80000000ull -#define KMEM_LIMIT 0xffffffff00000000ull -#define PAGES_BASE 0xffffffffc0000000ull -#define USER_LIMIT 0x0000800000000000ull - -/* Physical address where kernel ELF is loaded in case of direct stage3 load */ -#define KERNEL_BASE_PHYS 0x00200000ul - -#ifdef BOOT - -#include - -#else /* BOOT */ - -#include -#define USER_VA_TAG_OFFSET 44 -#ifdef STAGE3 -#define VA_TAG_BASE KMEM_BASE -#define VA_TAG_OFFSET 39 -#define VA_TAG_WIDTH 8 -#else -#define VA_TAG_BASE 0 -#define VA_TAG_OFFSET USER_VA_TAG_OFFSET -#define VA_TAG_WIDTH 3 -#endif - -static inline void *tag(void* v, u64 tval) { - return pointer_from_u64(VA_TAG_BASE | (tval << VA_TAG_OFFSET) | u64_from_pointer(v)); -} - -static inline u16 tagof(void* v) { - return (u64_from_pointer(v) >> VA_TAG_OFFSET) & ((1ull << VA_TAG_WIDTH) - 1); -} - -#define valueof(__x) (__x) - -#endif /* BOOT */ - -extern void * AP_BOOT_PAGE; - -/* AP boot page */ -#define AP_BOOT_START u64_from_pointer(&AP_BOOT_PAGE) -#define AP_BOOT_END (AP_BOOT_START + PAGESIZE) - /* identity-mapped space for initial page tables */ #define INITIAL_PAGES_SIZE (64 * KB) diff --git a/src/kernel/pagecache_internal.h b/src/kernel/pagecache_internal.h index 74b4e74a4..d5bd015c3 100644 --- a/src/kernel/pagecache_internal.h +++ b/src/kernel/pagecache_internal.h @@ -16,7 +16,7 @@ typedef struct pagecache { void *zero_page; /* for zero-fill dma */ /* state_lock covers list access, page state changes and - alterations to page completion vecs */# + alterations to page completion vecs */ #ifdef KERNEL struct spinlock state_lock; #endif diff --git a/src/x86_64/region.h b/src/kernel/region.h similarity index 100% rename from src/x86_64/region.h rename to src/kernel/region.h diff --git a/src/kernel/service.c b/src/kernel/service.c index 1a35a3623..5047ee847 100644 --- a/src/kernel/service.c +++ b/src/kernel/service.c @@ -355,9 +355,6 @@ static void new_cpu() u64 xsave_features(); u64 xsave_frame_size(); -/* XXX machine dep */ -#define MBR_ADDRESS 0x7c00 - static void __attribute__((noinline)) init_service_new_stack() { kernel_heaps kh = &heaps; diff --git a/src/runtime/metadata.h b/src/runtime/metadata.h index 68efb4567..105a6b644 100644 --- a/src/runtime/metadata.h +++ b/src/runtime/metadata.h @@ -40,9 +40,11 @@ static inline tuple resolve_path(tuple n, vector v) if (buffer_length(i) == 0) continue; tuple c = table_find(n, sym(children)); - assert(c); + if (!c) + return c; n = table_find(c, intern(i)); - assert(n); + if (!n) + return n; } return n; } diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index cdc8dc665..152a2b9bd 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -1,9 +1,10 @@ -#include +#include +#include +#include +#include #if !defined(BOOT) && !defined(STAGE3) #include #endif -#include -#include typedef u8 boolean; typedef u32 character; diff --git a/src/runtime/storage.h b/src/runtime/storage.h index d29de9b2d..353af6f47 100644 --- a/src/runtime/storage.h +++ b/src/runtime/storage.h @@ -14,7 +14,7 @@ enum partition { #define SECTOR_OFFSET 9ULL #define SECTOR_SIZE (1ULL << SECTOR_OFFSET) - +#define BOOTFS_SIZE (8 * MB) #define SEC_PER_TRACK 63 #define HEADS 255 #define MAX_CYL 1023 diff --git a/src/runtime/tuple.c b/src/runtime/tuple.c index 2f6b1130b..ccdb9e254 100644 --- a/src/runtime/tuple.c +++ b/src/runtime/tuple.c @@ -219,6 +219,7 @@ void encode_eav(buffer dest, table dictionary, tuple e, symbol a, value v) void encode_tuple(buffer dest, table dictionary, tuple t) { + tuple_debug("%s: dest %p, dictionary %p, tuple %p\n", __func__, dest, dictionary, t); u64 d = u64_from_pointer(table_find(dictionary, t)); if (d) { push_header(dest, reference, type_tuple, t->count); @@ -228,6 +229,7 @@ void encode_tuple(buffer dest, table dictionary, tuple t) srecord(dictionary, t); } table_foreach (t, n, v) { + tuple_debug(" tfe n %p, v %p, tag %d\n", n, v, tagof(v)); encode_symbol(dest, dictionary, n); encode_value(dest, dictionary, v); } diff --git a/src/runtime/tuple.h b/src/runtime/tuple.h index 76b7b5b0d..4cfe5278d 100644 --- a/src/runtime/tuple.h +++ b/src/runtime/tuple.h @@ -40,4 +40,14 @@ static inline value value_from_u64(heap h, u64 v) return result; } +static inline tuple find_or_allocate_tuple(tuple t, symbol s) +{ + assert(tagof(t) == tag_tuple); + value v = table_find(t, s); + if (!v) + return allocate_tuple(); + assert(tagof(v) == tag_tuple); + return (tuple)v; +} + value null_value(void); diff --git a/src/unix_process/unix_process_runtime.c b/src/unix_process/unix_process_runtime.c index 38eec23b4..4776e5238 100644 --- a/src/unix_process/unix_process_runtime.c +++ b/src/unix_process/unix_process_runtime.c @@ -1,10 +1,22 @@ #include #include +#include +#include #include +#include #include #include -#include -#include + +#ifdef __aarch64__ +#include +#endif + +//#define TAG_HEAP_DEBUG +#ifdef TAG_HEAP_DEBUG +#define tag_debug(x, ...) do {rprintf("%s: " x, __func__, ##__VA_ARGS__);} while(0) +#else +#define tag_debug(x, ...) +#endif /* Helper functions to ignore unused result (eliminate CC warning) */ static inline void igr(int x) {} @@ -46,7 +58,8 @@ static void malloc_free(heap h, u64 z, bytes length) static u64 malloc_alloc(heap h, bytes s) { bytes_allocated += s; - return (u64)malloc(s); + void *p = malloc(s); + return p ? (u64)p : INVALID_PHYSICAL; } heap malloc_allocator() @@ -72,6 +85,7 @@ void halt(char *format, ...) exit(2); } +#ifndef __aarch64__ static heap allocate_tagged_region(heap h, u64 tag) { u64 size = 256 * MB; @@ -79,6 +93,61 @@ static heap allocate_tagged_region(heap h, u64 tag) size, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); return (heap)create_id_heap(h, h, u64_from_pointer(region), size, 1); } +#else +struct tagheap { + struct heap h; + heap mh; + u64 vtag; +}; + +static void tag_dealloc(heap h, u64 a, bytes s) +{ + struct tagheap *th = (struct tagheap *)h; + tag_debug("%s: tag %d, a 0x%lx, s 0x%lx\n", __func__, th->vtag >> VA_TAG_OFFSET, a, s); + deallocate_u64(th->mh, a & MASK(48), s); +} + +static u64 tag_alloc(heap h, bytes s) +{ + struct tagheap *th = (struct tagheap *)h; + void *p = allocate(th->mh, s); + if (p == INVALID_ADDRESS) + return INVALID_PHYSICAL; + u64 a = u64_from_pointer(p); + assert((a >> VA_TAG_OFFSET) == 0); + a |= th->vtag; + tag_debug("%s: tag %d, s 0x%lx, a 0x%lx\n", __func__, th->vtag >> VA_TAG_OFFSET, s, a); + return a; +} + +#define PR_SET_TAGGED_ADDR_CTRL 55 +#define PR_TAGGED_ADDR_ENABLE (1UL << 0) + +static heap allocate_tagged_region(heap h, u64 tag) +{ + static boolean abi_init = false; + if (!abi_init) { + abi_init = true; + int rv = prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0); + if (rv < 0) + halt("prctl failed on PR_SET_TAGGED_ADDR_CTRL %d (%s)\n", errno, strerror(errno)); + } + struct tagheap *th = allocate(h, sizeof(struct tagheap)); + if (th == INVALID_ADDRESS) + return INVALID_ADDRESS; + assert(tag < 256); + th->mh = h; + th->vtag = tag << VA_TAG_OFFSET; + th->h.alloc = tag_alloc; + th->h.dealloc = tag_dealloc; + th->h.destroy = 0; + th->h.pagesize = 32; // XXX + th->h.allocated = 0; + th->h.total = 0; + tag_debug("%s: tag %d, bits 0x%lx, heap %p\n", __func__, tag, th->vtag, th); + return &th->h; +} +#endif extern void init_extra_prints(); diff --git a/src/x86_64/def64.h b/src/x86_64/def64.h index 4888bab35..408b53fec 100644 --- a/src/x86_64/def64.h +++ b/src/x86_64/def64.h @@ -23,6 +23,9 @@ typedef u64 bytes; #define S64_MAX ((s64)(U64_MAX >> 1)) #define S64_MIN (-S64_MAX - 1) +#define USER_VA_TAG_OFFSET 44 +#define USER_VA_TAG_WIDTH 3 + #define pointer_from_u64(__a) ((void *)(__a)) #define u64_from_pointer(__a) ((u64)(__a)) // a super sad hack to allow us to write to the bss in elf.c as diff --git a/src/x86_64/kernel_machine.h b/src/x86_64/kernel_machine.h index d1386375d..7180abec6 100644 --- a/src/x86_64/kernel_machine.h +++ b/src/x86_64/kernel_machine.h @@ -2,6 +2,13 @@ #error must be in kernel or bootloader build #endif +#define MBR_ADDRESS 0x7c00 + +#define KERNEL_BASE 0xffffffff80000000ull +#define KMEM_LIMIT 0xffffffff00000000ull +#define PAGES_BASE 0xffffffffc0000000ull + +#define KERNEL_BASE_PHYS 0x00200000ul #define STACK_ALIGNMENT 16 #define VIRTUAL_ADDRESS_BITS 48 @@ -41,6 +48,11 @@ #define TSS_SIZE 0x68 +/* AP boot page */ +extern void * AP_BOOT_PAGE; +#define AP_BOOT_START u64_from_pointer(&AP_BOOT_PAGE) +#define AP_BOOT_END (AP_BOOT_START + PAGESIZE) + static inline void cpuid(u32 fn, u32 ecx, u32 * v) { asm volatile("cpuid" : "=a" (v[0]), "=b" (v[1]), "=c" (v[2]), "=d" (v[3]) : "0" (fn), "2" (ecx)); diff --git a/src/x86_64/machine.h b/src/x86_64/machine.h index 65f59ce50..0e2484cd8 100644 --- a/src/x86_64/machine.h +++ b/src/x86_64/machine.h @@ -1,3 +1,33 @@ +#ifdef BOOT +#include +#else +/* kernel or userland */ +#include + +#define KMEM_BASE 0xffff800000000000ull +#define USER_LIMIT 0x0000800000000000ull + +#ifdef KERNEL +#define VA_TAG_BASE KMEM_BASE +#define VA_TAG_OFFSET 39 +#define VA_TAG_WIDTH 8 +#else +#define VA_TAG_BASE 0 +#define VA_TAG_OFFSET USER_VA_TAG_OFFSET +#define VA_TAG_WIDTH USER_VA_TAG_WIDTH +#endif + +static inline void *tag(void* v, u64 tval) { + return pointer_from_u64(VA_TAG_BASE | (tval << VA_TAG_OFFSET) | u64_from_pointer(v)); +} + +static inline u16 tagof(void* v) { + return (u64_from_pointer(v) >> VA_TAG_OFFSET) & ((1ull << VA_TAG_WIDTH) - 1); +} + +#define valueof(__x) (__x) +#endif /* !BOOT */ + static inline void compiler_barrier(void) { asm volatile("" ::: "memory"); diff --git a/test/Makefile b/test/Makefile index df61368fd..631856ece 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,7 +4,7 @@ SUBDIR= unit runtime go e2e SUBDIR_SKIP-test= runtime all test: - $(foreach d,$(filter-out $(SUBDIR_SKIP-$@),$(SUBDIR)),$(call execute_command,$(Q) $(MAKE) -C $d $@)) + $(foreach d,$(filter-out $(SUBDIR_SKIP-$@),$(SUBDIR)),$(call execute_command,$(Q) $(MAKE) -C $d $@ PLATFORM=$(PLATFORM))) test: all diff --git a/test/e2e/Makefile b/test/e2e/Makefile index bc34eae9a..05a8ef90c 100644 --- a/test/e2e/Makefile +++ b/test/e2e/Makefile @@ -6,8 +6,13 @@ GOGET= $(GO) get BINARY_NAME= ops test: + $(Q) $(MKDIR) $(OBJDIR) + $(Q) $(LN) -sf $(PLATFORMOBJDIR)/bin/kernel.img $(OBJDIR)/kernel.img + $(Q) $(LN) -sf $(PLATFORMOBJDIR)/boot/boot.img $(OBJDIR)/boot.img $(GOTEST) -v +CLEANFILES+= $(OBJDIR)/kernel.img $(OBJDIR)/boot.img + .PHONY: test include ../../rules.mk diff --git a/test/e2e/go/config.json b/test/e2e/go/config.json index 20c63576c..eb60ba198 100644 --- a/test/e2e/go/config.json +++ b/test/e2e/go/config.json @@ -3,7 +3,7 @@ "RunConfig": { "Ports": [8080] }, - "Boot": "../../../output/boot/boot.img", - "Kernel": "../../../output/stage3/bin/stage3.img", + "Boot": "../../../output/test/e2e/boot.img", + "Kernel": "../../../output/test/e2e/kernel.img", "Mkfs": "../../../output/tools/bin/mkfs" } diff --git a/test/e2e/nginx_1.15.6/config.json b/test/e2e/nginx_1.15.6/config.json index 86ef2359f..190ae37e0 100644 --- a/test/e2e/nginx_1.15.6/config.json +++ b/test/e2e/nginx_1.15.6/config.json @@ -4,7 +4,7 @@ "RunConfig": { "Ports": [8084] }, - "Boot": "../../../output/boot/boot.img", - "Kernel": "../../../output/stage3/bin/stage3.img", + "Boot": "../../../output/test/e2e/boot.img", + "Kernel": "../../../output/test/e2e/kernel.img", "Mkfs": "../../../output/tools/bin/mkfs" } diff --git a/test/e2e/node_v11.5.0/config.json b/test/e2e/node_v11.5.0/config.json index 25f499791..f33d5d67b 100644 --- a/test/e2e/node_v11.5.0/config.json +++ b/test/e2e/node_v11.5.0/config.json @@ -3,7 +3,7 @@ "RunConfig": { "Ports": [8083] }, - "Boot": "../../../output/boot/boot.img", - "Kernel": "../../../output/stage3/bin/stage3.img", + "Boot": "../../../output/test/e2e/boot.img", + "Kernel": "../../../output/test/e2e/kernel.img", "Mkfs": "../../../output/tools/bin/mkfs" } diff --git a/test/e2e/php_7.3.5/config.json b/test/e2e/php_7.3.5/config.json index fc87cb37a..e0ae42721 100644 --- a/test/e2e/php_7.3.5/config.json +++ b/test/e2e/php_7.3.5/config.json @@ -3,7 +3,7 @@ "RunConfig": { "Ports": [9501] }, - "Boot": "../../../output/boot/boot.img", - "Kernel": "../../../output/stage3/bin/stage3.img", + "Boot": "../../../output/test/e2e/boot.img", + "Kernel": "../../../output/test/e2e/kernel.img", "Mkfs": "../../../output/tools/bin/mkfs" } diff --git a/test/e2e/python_3.6.7/config.json b/test/e2e/python_3.6.7/config.json index 2a8df7deb..4d20096eb 100644 --- a/test/e2e/python_3.6.7/config.json +++ b/test/e2e/python_3.6.7/config.json @@ -3,7 +3,7 @@ "RunConfig": { "Ports": [8000] }, - "Boot": "../../../output/boot/boot.img", - "Kernel": "../../../output/stage3/bin/stage3.img", + "Boot": "../../../output/test/e2e/boot.img", + "Kernel": "../../../output/test/e2e/kernel.img", "Mkfs": "../../../output/tools/bin/mkfs" } diff --git a/test/e2e/ruby_2.5.1/config.json b/test/e2e/ruby_2.5.1/config.json index 47d2a11d8..1acabeab4 100644 --- a/test/e2e/ruby_2.5.1/config.json +++ b/test/e2e/ruby_2.5.1/config.json @@ -7,7 +7,7 @@ "RunConfig": { "Ports": [4567] }, - "Boot": "../../../output/boot/boot.img", - "Kernel": "../../../output/stage3/bin/stage3.img", + "Boot": "../../../output/test/e2e/boot.img", + "Kernel": "../../../output/test/e2e/kernel.img", "Mkfs": "../../../output/tools/bin/mkfs" } diff --git a/test/e2e/rust/config.json b/test/e2e/rust/config.json index 20c63576c..eb60ba198 100644 --- a/test/e2e/rust/config.json +++ b/test/e2e/rust/config.json @@ -3,7 +3,7 @@ "RunConfig": { "Ports": [8080] }, - "Boot": "../../../output/boot/boot.img", - "Kernel": "../../../output/stage3/bin/stage3.img", + "Boot": "../../../output/test/e2e/boot.img", + "Kernel": "../../../output/test/e2e/kernel.img", "Mkfs": "../../../output/tools/bin/mkfs" } diff --git a/test/go/Makefile b/test/go/Makefile index b6c716565..9b4715d62 100644 --- a/test/go/Makefile +++ b/test/go/Makefile @@ -11,8 +11,13 @@ build: deps $(GOBUILD) test: build + $(Q) $(MKDIR) $(OBJDIR) + $(Q) $(LN) -sf $(PLATFORMOBJDIR)/bin/kernel.img $(OBJDIR)/kernel.img + $(Q) $(LN) -sf $(PLATFORMOBJDIR)/boot/boot.img $(OBJDIR)/boot.img $(GOTEST) -v +CLEANFILES+= $(OBJDIR)/kernel.img $(OBJDIR)/boot.img + post-clean: $(Q) $(GOCLEAN) $(Q) $(RM) -rf .staging diff --git a/test/go/common.go b/test/go/common.go index a80927472..91749a6f3 100644 --- a/test/go/common.go +++ b/test/go/common.go @@ -16,8 +16,8 @@ import ( func defaultConfig() lepton.Config { var c lepton.Config - c.Boot = "../../output/boot/boot.img" - c.Kernel = "../../output/stage3/bin/stage3.img" + c.Boot = "../../output/test/go/boot.img" + c.Kernel = "../../output/test/go/kernel.img" c.Mkfs = "../../output/tools/bin/mkfs" c.NameServer = "8.8.8.8" diff --git a/test/go/node_test.go b/test/go/node_test.go index 60957a681..d1c96b8a7 100644 --- a/test/go/node_test.go +++ b/test/go/node_test.go @@ -56,8 +56,8 @@ func TestNodeHelloWorld(t *testing.T) { c.Args = append(c.Args, "js/hello.js") c.RunConfig.Imagename = "image" c.RunConfig.Memory = "2G" - c.Boot = "../../output/boot/boot.img" - c.Kernel = "../../output/stage3/bin/stage3.img" + c.Boot = "../../output/test/go/boot.img" + c.Kernel = "../../output/test/go/kernel.img" c.Mkfs = "../../output/tools/bin/mkfs" c.Env = make(map[string]string) c.RunConfig.Imagename = "image" diff --git a/test/runtime/Makefile b/test/runtime/Makefile index 299a9e510..091b5418b 100644 --- a/test/runtime/Makefile +++ b/test/runtime/Makefile @@ -341,6 +341,7 @@ LDFLAGS-readv= -static CFLAGS+= -DENABLE_MSG_DEBUG CFLAGS+= -I$(ARCHDIR) \ + -I$(SRCDIR) \ -I$(SRCDIR)/http \ -I$(SRCDIR)/kernel \ -I$(SRCDIR)/runtime \ @@ -351,8 +352,16 @@ CLEANDIRS+= $(OBJDIR)/test all: $(PROGRAMS) +dummy: + +.PHONY: dummy + include ../../rules.mk +ifneq ($(CROSS_COMPILE),) +CFLAGS+= --sysroot $(TARGET_ROOT) -I$(TARGET_ROOT)/usr/include +LDFLAGS+= --sysroot=$(TARGET_ROOT) -L$(TARGET_ROOT)/usr/lib/$(ARCH)-linux-gnu +else ifeq ($(UNAME_s),Darwin) CFLAGS+= -target x86_64-elf --sysroot $(TARGET_ROOT) -I $(TARGET_ROOT)/usr/include LD= x86_64-elf-ld @@ -367,3 +376,13 @@ $(PROG-hw): OBJS_END=$(OBJS_CRTEND_D) $(PROG-web): OBJS_BEGIN=$(OBJS_CRTBEGIN_D) $(PROG-web): OBJS_END=$(OBJS_CRTEND_D) endif +endif + +ifneq ($(CROSS_COMPILE),) +GO_ENV= GOOS=linux +ifeq ($(ARCH),aarch64) +GO_ENV+= GOARCH=arm64 +else +GO_ENV+= GOARCH=$(ARCH) +endif +endif diff --git a/test/runtime/aio.manifest b/test/runtime/aio.manifest index 709e3e6a9..a340673c3 100644 --- a/test/runtime/aio.manifest +++ b/test/runtime/aio.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program aio:(contents:(host:output/test/runtime/bin/aio)) diff --git a/test/runtime/creat.manifest b/test/runtime/creat.manifest index ef5588672..78d67406f 100644 --- a/test/runtime/creat.manifest +++ b/test/runtime/creat.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program creat:(contents:(host:output/test/runtime/bin/creat)) diff --git a/test/runtime/dummy.manifest b/test/runtime/dummy.manifest new file mode 100644 index 000000000..90f292cd9 --- /dev/null +++ b/test/runtime/dummy.manifest @@ -0,0 +1,6 @@ +( + program:/dummy + fault:t + arguments:[webg poppy] + environment:(USER:bobby PWD:/) +) diff --git a/test/runtime/dup.manifest b/test/runtime/dup.manifest index 7639b7ffc..08d4829de 100644 --- a/test/runtime/dup.manifest +++ b/test/runtime/dup.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program dup:(contents:(host:output/test/runtime/bin/dup)) diff --git a/test/runtime/epoll.manifest b/test/runtime/epoll.manifest index beeead3ba..070092317 100644 --- a/test/runtime/epoll.manifest +++ b/test/runtime/epoll.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program epoll:(contents:(host:output/test/runtime/bin/epoll)) diff --git a/test/runtime/eventfd.manifest b/test/runtime/eventfd.manifest index f5c4d600e..4d92ff5a8 100644 --- a/test/runtime/eventfd.manifest +++ b/test/runtime/eventfd.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program eventfd:(contents:(host:output/test/runtime/bin/eventfd)) diff --git a/test/runtime/fallocate.manifest b/test/runtime/fallocate.manifest index 4d933c2c6..715c7e5f7 100644 --- a/test/runtime/fallocate.manifest +++ b/test/runtime/fallocate.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program fallocate:(contents:(host:output/test/runtime/bin/fallocate)) diff --git a/test/runtime/fcntl.manifest b/test/runtime/fcntl.manifest index 8afa317cb..ef837834e 100644 --- a/test/runtime/fcntl.manifest +++ b/test/runtime/fcntl.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program fcntl:(contents:(host:output/test/runtime/bin/fcntl)) diff --git a/test/runtime/fst.manifest b/test/runtime/fst.manifest index b2f4d1135..42708494e 100644 --- a/test/runtime/fst.manifest +++ b/test/runtime/fst.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program fst:(contents:(host:output/test/runtime/bin/fst)) diff --git a/test/runtime/ftrace.manifest b/test/runtime/ftrace.manifest index 2e8296437..a16097f77 100644 --- a/test/runtime/ftrace.manifest +++ b/test/runtime/ftrace.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( ftrace:(contents:(host:output/test/runtime/bin/ftrace)) infile:(contents:(host:test/runtime/read_contents/hello)) diff --git a/test/runtime/getdents.manifest b/test/runtime/getdents.manifest index 151c77cae..87c10dc12 100644 --- a/test/runtime/getdents.manifest +++ b/test/runtime/getdents.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program getdents:(contents:(host:output/test/runtime/bin/getdents)) diff --git a/test/runtime/getrandom.manifest b/test/runtime/getrandom.manifest index 3fefdd330..2cac00221 100644 --- a/test/runtime/getrandom.manifest +++ b/test/runtime/getrandom.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program getrandom:(contents:(host:output/test/runtime/bin/getrandom)) diff --git a/test/runtime/hw.manifest b/test/runtime/hw.manifest index b71a81a5c..04476b51e 100644 --- a/test/runtime/hw.manifest +++ b/test/runtime/hw.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program hw:(contents:(host:output/test/runtime/bin/hw)) diff --git a/test/runtime/hws.manifest b/test/runtime/hws.manifest index 40500ccad..4d383d308 100644 --- a/test/runtime/hws.manifest +++ b/test/runtime/hws.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program hws:(contents:(host:output/test/runtime/bin/hws))) diff --git a/test/runtime/io_uring.manifest b/test/runtime/io_uring.manifest index 75df6fdd8..a9b63254a 100644 --- a/test/runtime/io_uring.manifest +++ b/test/runtime/io_uring.manifest @@ -1,9 +1,4 @@ ( - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( io_uring:(contents:(host:output/test/runtime/bin/io_uring)) etc:(children:(ld.so.cache:(contents:(host:/etc/ld.so.cache)) passwd:(contents:(host:/etc/passwd)) group:(contents:(host:/etc/group)))) diff --git a/test/runtime/mkdir.manifest b/test/runtime/mkdir.manifest index decb0ae41..9e57550f9 100644 --- a/test/runtime/mkdir.manifest +++ b/test/runtime/mkdir.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program mkdir:(contents:(host:output/test/runtime/bin/mkdir)) diff --git a/test/runtime/mmap.manifest b/test/runtime/mmap.manifest index c2dfb8f4a..0b2ee9ed2 100644 --- a/test/runtime/mmap.manifest +++ b/test/runtime/mmap.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( mmap:(contents:(host:output/test/runtime/bin/mmap)) infile:(contents:(host:test/runtime/read_contents/hello)) diff --git a/test/runtime/nullpage.manifest b/test/runtime/nullpage.manifest index de29f9acf..e2152c9dc 100644 --- a/test/runtime/nullpage.manifest +++ b/test/runtime/nullpage.manifest @@ -1,9 +1,4 @@ ( - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( nullpage:(contents:(host:output/test/runtime/bin/nullpage)) ) diff --git a/test/runtime/paging.manifest b/test/runtime/paging.manifest index 4775c670a..5fbebc9e4 100644 --- a/test/runtime/paging.manifest +++ b/test/runtime/paging.manifest @@ -1,9 +1,4 @@ ( - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( paging:(contents:(host:output/test/runtime/bin/paging)) ) diff --git a/test/runtime/pipe.manifest b/test/runtime/pipe.manifest index 5619f44eb..e2b8e54a3 100644 --- a/test/runtime/pipe.manifest +++ b/test/runtime/pipe.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program pipe:(contents:(host:output/test/runtime/bin/pipe)) diff --git a/test/runtime/readv.manifest b/test/runtime/readv.manifest index 3047835e5..011df891d 100644 --- a/test/runtime/readv.manifest +++ b/test/runtime/readv.manifest @@ -1,9 +1,4 @@ ( - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( readv:(contents:(host:output/test/runtime/bin/readv)) hello:(contents:(host:test/runtime/read_contents/hello)) diff --git a/test/runtime/rename.manifest b/test/runtime/rename.manifest index 895d6f6a9..9cd937ac3 100644 --- a/test/runtime/rename.manifest +++ b/test/runtime/rename.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program rename:(contents:(host:output/test/runtime/bin/rename)) diff --git a/test/runtime/sendfile.manifest b/test/runtime/sendfile.manifest index 99d53c29a..ec09ab798 100644 --- a/test/runtime/sendfile.manifest +++ b/test/runtime/sendfile.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( # files infile:(contents:(host:test/runtime/write_contents/infile)) diff --git a/test/runtime/signal.manifest b/test/runtime/signal.manifest index 2609d90e4..8f4ffdfe2 100644 --- a/test/runtime/signal.manifest +++ b/test/runtime/signal.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program signal:(contents:(host:output/test/runtime/bin/signal)) diff --git a/test/runtime/socketpair.manifest b/test/runtime/socketpair.manifest index 9fb25b059..ef555dad6 100644 --- a/test/runtime/socketpair.manifest +++ b/test/runtime/socketpair.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program socketpair:(contents:(host:output/test/runtime/bin/socketpair)) diff --git a/test/runtime/symlink.manifest b/test/runtime/symlink.manifest index f288fe074..3b029ae76 100644 --- a/test/runtime/symlink.manifest +++ b/test/runtime/symlink.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program symlink:(contents:(host:output/test/runtime/bin/symlink)) diff --git a/test/runtime/thread_test.manifest b/test/runtime/thread_test.manifest index 115935cf9..a8fa4ff80 100644 --- a/test/runtime/thread_test.manifest +++ b/test/runtime/thread_test.manifest @@ -1,9 +1,4 @@ ( - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( tt:(contents:(host:output/test/runtime/bin/thread_test))) program:/tt diff --git a/test/runtime/time.manifest b/test/runtime/time.manifest index 5946073f3..2a3802ffb 100644 --- a/test/runtime/time.manifest +++ b/test/runtime/time.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program time:(contents:(host:output/test/runtime/bin/time)) diff --git a/test/runtime/udploop.manifest b/test/runtime/udploop.manifest index 881db74f0..d22e01345 100644 --- a/test/runtime/udploop.manifest +++ b/test/runtime/udploop.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program udploop:(contents:(host:output/test/runtime/bin/udploop))) diff --git a/test/runtime/unixsocket.manifest b/test/runtime/unixsocket.manifest index e5e65a03b..762c2ef8d 100644 --- a/test/runtime/unixsocket.manifest +++ b/test/runtime/unixsocket.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program unixsocket:(contents:(host:output/test/runtime/bin/unixsocket)) diff --git a/test/runtime/unlink.manifest b/test/runtime/unlink.manifest index ccd5a868a..c9303e387 100644 --- a/test/runtime/unlink.manifest +++ b/test/runtime/unlink.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program unlink:(contents:(host:output/test/runtime/bin/unlink)) diff --git a/test/runtime/vsyscall.manifest b/test/runtime/vsyscall.manifest index 34014e6aa..fe8e85f96 100644 --- a/test/runtime/vsyscall.manifest +++ b/test/runtime/vsyscall.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program vsyscall:(contents:(host:output/test/runtime/bin/vsyscall)) diff --git a/test/runtime/web.manifest b/test/runtime/web.manifest index 0b4b358be..fda0a8ccb 100644 --- a/test/runtime/web.manifest +++ b/test/runtime/web.manifest @@ -1,9 +1,4 @@ ( - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( web:(contents:(host:output/test/runtime/bin/web)) etc:(children:( diff --git a/test/runtime/webg.manifest b/test/runtime/webg.manifest index eb0239577..6758242df 100644 --- a/test/runtime/webg.manifest +++ b/test/runtime/webg.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program webg:(contents:(host:output/test/runtime/bin/webg)) diff --git a/test/runtime/webs-poll.manifest b/test/runtime/webs-poll.manifest index 21c6ea9a3..c9862cc9a 100644 --- a/test/runtime/webs-poll.manifest +++ b/test/runtime/webs-poll.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program webs:(contents:(host:output/test/runtime/bin/webs))) diff --git a/test/runtime/webs-select.manifest b/test/runtime/webs-select.manifest index c0c65b1aa..7bded9690 100644 --- a/test/runtime/webs-select.manifest +++ b/test/runtime/webs-select.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program webs:(contents:(host:output/test/runtime/bin/webs))) diff --git a/test/runtime/webs.manifest b/test/runtime/webs.manifest index 3686e8d18..bcee3824f 100644 --- a/test/runtime/webs.manifest +++ b/test/runtime/webs.manifest @@ -1,10 +1,4 @@ ( - #64 bit elf to boot from host - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( #user program webs:(contents:(host:output/test/runtime/bin/webs))) diff --git a/test/runtime/write.manifest b/test/runtime/write.manifest index ea06baf7f..6d2277ebf 100644 --- a/test/runtime/write.manifest +++ b/test/runtime/write.manifest @@ -1,9 +1,4 @@ ( - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( write:(contents:(host:output/test/runtime/bin/write)) hello:(contents:(host:test/runtime/write_contents/hello)) diff --git a/test/runtime/writev.manifest b/test/runtime/writev.manifest index 356e8d2cb..fb1a1a81f 100644 --- a/test/runtime/writev.manifest +++ b/test/runtime/writev.manifest @@ -1,9 +1,4 @@ ( - boot:( - children:( - kernel:(contents:(host:output/stage3/bin/stage3.img)) - ) - ) children:( writev:(contents:(host:output/test/runtime/bin/writev)) hello:(contents:(host:test/runtime/write_contents/hello)) diff --git a/test/unit/Makefile b/test/unit/Makefile index 136b5fbc8..12700b71a 100644 --- a/test/unit/Makefile +++ b/test/unit/Makefile @@ -134,6 +134,7 @@ SRCS-vector_test= \ CFLAGS+= -I$(ARCHDIR) \ + -I$(SRCDIR) \ -I$(SRCDIR)/http \ -I$(SRCDIR)/kernel \ -I$(SRCDIR)/runtime \ diff --git a/tools/Makefile b/tools/Makefile index 192565b5c..e7afe5843 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,6 +1,6 @@ -ARCH=$(shell uname -m) +override ARCH=$(shell uname -m) +override CROSS_COMPILE= CONTGEN=$(OBJDIR)/bin/contgen -CROSS_COMPILE= PROGRAMS=dump mkfs vdsogen SRCS-dump= \ @@ -61,6 +61,7 @@ SRCS-mkfs= \ SRCS-vdsogen= $(CURDIR)/vdsogen.c CFLAGS+=-I$(ARCHDIR) \ + -I$(SRCDIR) \ -I$(SRCDIR)/kernel \ -I$(SRCDIR)/runtime \ -I$(SRCDIR)/tfs \ @@ -74,6 +75,6 @@ contgen: $(CONTGEN) $(CONTGEN): $(CURDIR)/contgen.c @$(MKDIR) $(dir $@) - $(CC) $(CFLAGS) $< -o $@ + $(CC) $(DEPFLAGS) -std=gnu11 -O3 $< -o $@ -CLEANFILES+= $(CONTGEN) +CLEANFILES+= $(CONTGEN) $(TOOLDIR)/contgen.d diff --git a/tools/dump.c b/tools/dump.c index cb2b2927d..b1771ce99 100644 --- a/tools/dump.c +++ b/tools/dump.c @@ -1,5 +1,4 @@ #include -#include #include #include diff --git a/tools/mkfs.c b/tools/mkfs.c index 6d95b6aa2..d049e683f 100644 --- a/tools/mkfs.c +++ b/tools/mkfs.c @@ -298,6 +298,7 @@ static void usage(const char *program_name) "image-file < manifest-file\n" "\n" "-b - specify boot image to prepend\n" + "-k - specify kernel image\n" "-r - specify target root\n" "-s - specify minimum image file size; can be expressed in bytes, " "KB (with k or K suffix), MB (with m or M suffix), and GB (with g or" @@ -338,14 +339,18 @@ int main(int argc, char **argv) { int c; const char *bootimg_path = NULL; + const char *kernelimg_path = NULL; const char *target_root = NULL; long long img_size = 0; - while ((c = getopt(argc, argv, "hb:r:s:")) != EOF) { + while ((c = getopt(argc, argv, "hb:k:r:s:")) != EOF) { switch (c) { case 'b': bootimg_path = optarg; break; + case 'k': + kernelimg_path = optarg; + break; case 'r': target_root = optarg; break; @@ -423,7 +428,18 @@ int main(int argc, char **argv) } tuple boot = table_find(root, sym(boot)); - if (!boot) { + if (kernelimg_path != NULL) { + if (!boot) + boot = allocate_tuple(); + tuple children = find_or_allocate_tuple(boot, sym(children)); + tuple kernel = find_or_allocate_tuple(children, sym(kernel)); + tuple contents = find_or_allocate_tuple(kernel, sym(contents)); + buffer b = alloca_wrap_buffer(kernelimg_path, runtime_strlen(kernelimg_path)); + table_set(contents, sym(host), b); + table_set(kernel, sym(contents), contents); + table_set(children, sym(kernel), kernel); + table_set(boot, sym(children), children); + } else if (!boot) { /* Look for kernel file in root filesystem, for backward * compatibility. */ tuple c = children(root); @@ -437,7 +453,7 @@ int main(int argc, char **argv) } } if (!boot) - halt("boot FS not found\n"); + halt("kernel or boot FS not specified\n"); pagecache pc = allocate_pagecache(h, h, 0, PAGESIZE); assert(pc != INVALID_ADDRESS); create_filesystem(h, SECTOR_SIZE, BOOTFS_SIZE, 0,