K=kernel U=user D=SDK CFLAGS_MANDATORY=-DPKG_MKDIR_SIMPLE include libc/include.mk OBJS = \ $K/entry.o \ $K/start.o \ $K/riscv.o \ $K/console.o \ $K/kprintf.o \ $K/uart.o \ $K/physpg.o \ $K/spinlock.o \ $K/string.o \ $K/main.o \ $K/vm.o \ $K/bitarray.o \ $K/proc.o \ $K/trampoline.o \ $K/trap.o \ $K/syscall.o \ $K/sysproc.o \ $K/drives.o \ $K/diskio.o \ $K/vmrd.o \ $K/fsinstance.o \ $K/sleeplock.o \ $K/file.o \ $K/pipe.o \ $K/exec.o \ $K/sysfile.o \ $K/kernelvec.o \ $K/plic.o \ $K/virtio_disk.o \ $K/sched.o \ $K/sysnew.o \ $K/fpu.o \ $K/asmnew.o \ $K/sync.o \ $K/schedasm.o AUTOGENOBJS = \ autogen/res_data.o # $K/rme_kernel.o \ # riscv64-unknown-elf- or riscv64-linux-gnu- # perhaps in /opt/riscv/bin #TOOLPREFIX = # Try to infer the correct TOOLPREFIX if not set ifndef TOOLPREFIX TOOLPREFIX := $(shell if riscv64-unknown-elf-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \ then echo 'riscv64-unknown-elf-'; \ elif riscv64-linux-gnu-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \ then echo 'riscv64-linux-gnu-'; \ elif riscv64-unknown-linux-gnu-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \ then echo 'riscv64-unknown-linux-gnu-'; \ else echo "***" 1>&2; \ echo "*** Error: Couldn't find a riscv64 version of GCC/binutils." 1>&2; \ echo "*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \ echo "***" 1>&2; exit 1; fi) endif QEMU = qemu-system-riscv64 #CC = $(TOOLPREFIX)gcc CC = SDK/compilec AS = $(TOOLPREFIX)gas LD = $(TOOLPREFIX)ld OBJCOPY = $(TOOLPREFIX)objcopy OBJDUMP = $(TOOLPREFIX)objdump #CFLAGS = -Wall -Werror -O -fno-omit-frame-pointer -ggdb -gdwarf-2 #CFLAGS += -MD #CFLAGS += -mcmodel=medany # CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax #CFLAGS += -fno-common -nostdlib #CFLAGS += -fno-builtin-strncpy -fno-builtin-strncmp -fno-builtin-strlen -fno-builtin-memset #CFLAGS += -fno-builtin-memmove -fno-builtin-memcmp -fno-builtin-log -fno-builtin-bzero #CFLAGS += -fno-builtin-strchr -fno-builtin-exit -fno-builtin-malloc -fno-builtin-putc #CFLAGS += -fno-builtin-free #CFLAGS += -fno-builtin-memcpy -Wno-main #CFLAGS += -fno-builtin-printf -fno-builtin-fprintf -fno-builtin-vprintf CFLAGS = -I. --dynamic $(CFLAGS_MANDATORY) #CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) # Disable PIE when possible (for Ubuntu 16.10 toolchain) #ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]no-pie'),) #CFLAGS += -fno-pie -no-pie #endif #ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]nopie'),) #CFLAGS += -fno-pie -nopie #endif LDFLAGS = -z max-page-size=4096 $K/kernel: $(OBJS) $(AUTOGENOBJS) $K/kernel.ld $U/initcode kernel-audit.txt $(LD) $(LDFLAGS) -T $K/kernel.ld -o $K/kernel $(OBJS) $(AUTOGENOBJS) $(OBJDUMP) -S $K/kernel > $K/kernel.asm $(OBJDUMP) -t $K/kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $K/kernel.sym $K/kernel.bin: $K/kernel $(OBJCOPY) -O binary $K/kernel $K/kernel.bin $U/initcode: $U/initcode.S $(CC) $(CFLAGS) -I. -Ikernel -c $U/initcode.S -o $U/initcode.o $(LD) $(LDFLAGS) -N -e start -Ttext 0 -o $U/initcode.out $U/initcode.o $(OBJCOPY) -S -O binary $U/initcode.out $U/initcode $(OBJDUMP) -S $U/initcode.o > $U/initcode.asm tags: $(OBJS) _init etags *.S *.c ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/umalloc.o _%: %.o $(ULIB) $(LD) $(LDFLAGS) -T $U/user.ld -o $@ $^ $(OBJDUMP) -S $@ > $*.asm $(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym $U/usys.S : $U/usys.pl perl $U/usys.pl > $U/usys.S $U/usys.o : $U/usys.S $(CC) $(CFLAGS) -c -o $U/usys.o $U/usys.S $U/_forktest: $U/forktest.o $(ULIB) # forktest has less library code linked in - needs to be small # in order to be able to max out the proc table. $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_forktest $U/forktest.o $U/ulib.o $U/usys.o $(OBJDUMP) -S $U/_forktest > $U/forktest.asm #TODO: test mkfs on new compiler mkfs/mkfs: mkfs/mkfs.c mkfs/mkfsv2.c $K/fs.h $K/param.h gcc -Werror -Wall -I. -o mkfs/mkfs mkfs/mkfs.c mkfs/mkfsv2: mkfs/main.c mkfs/mkfsv2.c $K/fs.h $K/param.h gcc -Werror -Wall -I. -o mkfs/mkfsv2 mkfs/main.c $D/assemble: $D/compilec $D/assemble.c $D/asmln.c $D/asmln.h $D/asmdata.c $D/asmdata.h $D/asmpp.c $D/asmpp.h $D/compilec -I$D/fakelibc -o $D/assemble $D/assemble.c #TODO: Better self-hosting build process $D/compilec: $D/compilec.c $D/brutal.c $D/ccb.h $D/ccbgeneric.h compilec -I$D/fakelibc -o $D/compilec $D/compilec.c $D/audit: $D/audit.c $D/compilec $D/compilec -I$D/fakelibc -o $D/audit $D/audit.c $D/res2c: $D/res2c.c $D/compilec $D/compilec -I$D/fakelibc -o $D/res2c $D/res2c.c $D/srve: $D/srve.c $D/srve.h $D/srve_core.h $D/srve_core_h.h $D/srve_core_c.h $D/compilec $D/compilec -I$D/fakelibc -o $D/srve $D/srve.c pkg/pkg: pkg/pkg.c $D/compilec $D/compilec -I$D/fakelibc -DPKG_MKDIR_LINUX -o pkg/pkg pkg/pkg.c pkg/dist/pkg: pkg/_libc_pkg cp $< $@ pkg/pkg.pkg: pkg/pkg pkg/pkg.pkb pkg/dist/pkg pkg/pkg build pkg/pkg.pkb kernel-audit.txt: $D/audit $(OBJS) libc/elf.h libc/string.c mkfs/fsformat.h $D/audit kernel/*.c kernel/*.h kernel/*.S libc/elf.h libc/string.c mkfs/fsformat.h > kernel-audit.txt # Prevent deletion of intermediate files, e.g. cat.o, after first build, so # that disk image changes after first build are persistent until clean. More # details: # http://www.gnu.org/software/make/manual/html_node/Chained-Rules.html .PRECIOUS: %.o UPROGS=\ $U/_cat\ $U/_echo\ $U/_forktest\ $U/_thrdtest\ $U/_grep\ $U/_init\ $U/_kill\ $U/_ln\ $U/_ls\ $U/_mkdir\ $U/_rm\ $U/_sh\ $U/_stressfs\ $U/_grind\ $U/_wc\ $U/_zombie\ $U/_libc_drives\ $U/_libc_st\ $D/_numbered\ $D/_libc_assemble\ $D/_libc_compilec\ $D/_libc_hello\ $D/_libc_audit\ $D/_libc_res2c\ AI/_libc_example1\ $U/_libc_scm\ pkg/_libc_pkg # $U/_usertests\ st.o: SDK/compilec user/st.c SDK/compilec -I SDK/fakelibc -c -ost.o user/st.c st: st.o gcc -ost st.o -lm fs.img: mkfs/mkfsv2 README $U/classic.st pkg/pkg.pkg $(UPROGS) mkfs/mkfsv2 -v1 --skip_underscores --output fs.img --blocksize 4096 --blocks 2000 README $U/classic.st pkg/pkg.pkg $(UPROGS) snapshot ramdisk0.img: mkfs/mkfsv2 README mkfs/mkfsv2 -v0 --blocksize 4096 --output ramdisk0.img --blocks 500 README ramdisk1.img: mkfs/mkfsv2 README mkfs/mkfsv2 -v1 --blocksize 4096 --output ramdisk1.img --blocks 800 README SDK/rv64.inc SDK/*.c SDK/*.h imgsums.txt: ramdisk0.img ramdisk1.img md5sum $^ > imgsums.txt autogen/res_data.c: $D/res2c ramdisk0.img ramdisk1.img $D/res2c --output autogen/res_data.c --type RAMDISK --filename RD0 ramdisk0.img --type RAMDISK --filename RD1 ramdisk1.img -include kernel/*.d user/*.d clean: rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \ */*.o */*.d */*.asm */*.sym \ $U/initcode $U/initcode.out $K/kernel fs.img \ mkfs/mkfs mkfs/mkfsv2 $D/assemble $D/compilec $D/audit $D/res2c .gdbinit \ ramdisk0.img ramdisk1.img imgsums.txt \ $U/usys.S \ $(UPROGS) # try to generate a unique GDB port GDBPORT = $(shell expr `id -u` % 5000 + 25000) # QEMU's gdb stub command line changed in 0.11 QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \ then echo "-gdb tcp::$(GDBPORT)"; \ else echo "-s -p $(GDBPORT)"; fi) ifndef CPUS CPUS := 3 endif QEMUOPTS = -machine virt -bios none -kernel $K/kernel -m 128M -smp $(CPUS) -nographic QEMUOPTS += -global virtio-mmio.force-legacy=false QEMUOPTS += -drive file=fs.img,if=none,format=raw,id=x0 QEMUOPTS += -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 -accel tcg # Some more options just for testing QEMUOPTS += -object memory-backend-file,id=shmem0,mem-path=foo,size=1M,share=on QEMUOPTS += -device ivshmem-plain,memdev=shmem0,bus=pcie.0,addr=0x2.0 qemu: imgsums.txt $K/kernel fs.img $(QEMU) $(QEMUOPTS) .gdbinit: .gdbinit.tmpl-riscv sed "s/:1234/:$(GDBPORT)/" < $^ > $@ qemu-gdb: $K/kernel .gdbinit fs.img @echo "*** Now run 'gdb' in another window." 1>&2 $(QEMU) $(QEMUOPTS) -S $(QEMUGDB)