diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 150 | 
1 files changed, 76 insertions, 74 deletions
| @@ -1,29 +1,33 @@ +K=kernel +U=user +  OBJS = \ -  start.o \ -  console.o \ -  uart.o \ -  kalloc.o \ -  spinlock.o \ -  string.o \ -  main.o \ -  vm.o \ -  proc.o \ -  swtch.o \ -  trampoline.o \ -  trap.o \ -  syscall.o \ -  sysproc.o \ -  bio.o \ -  fs.o \ -  log.o \ -  sleeplock.o \ -  file.o \ -  pipe.o \ -  ramdisk.o \ -  exec.o \ -  sysfile.o \ -  kernelvec.o \ -  plic.o +  $K/entry.o \ +  $K/start.o \ +  $K/console.o \ +  $K/uart.o \ +  $K/kalloc.o \ +  $K/spinlock.o \ +  $K/string.o \ +  $K/main.o \ +  $K/vm.o \ +  $K/proc.o \ +  $K/swtch.o \ +  $K/trampoline.o \ +  $K/trap.o \ +  $K/syscall.o \ +  $K/sysproc.o \ +  $K/bio.o \ +  $K/fs.o \ +  $K/log.o \ +  $K/sleeplock.o \ +  $K/file.o \ +  $K/pipe.o \ +  $K/ramdisk.o \ +  $K/exec.o \ +  $K/sysfile.o \ +  $K/kernelvec.o \ +  $K/plic.o  # riscv64-unknown-elf- or riscv64-linux-gnu-  # perhaps in /opt/riscv/bin @@ -53,6 +57,7 @@ OBJDUMP = $(TOOLPREFIX)objdump  CFLAGS = -Wall -Werror -O -fno-omit-frame-pointer -ggdb  CFLAGS += -mcmodel=medany  CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax +CFLAGS += -I.  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) @@ -65,41 +70,41 @@ endif  LDFLAGS = -z max-page-size=4096 -kernel: $(OBJS) entry.o kernel.ld initcode -	$(LD) $(LDFLAGS) -T kernel.ld -o kernel entry.o $(OBJS)  -	$(OBJDUMP) -S kernel > kernel.asm -	$(OBJDUMP) -t kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym +$K/kernel: $(OBJS) $K/kernel.ld $U/initcode +	$(LD) $(LDFLAGS) -T $K/kernel.ld -o $K/kernel $(OBJS)  +	$(OBJDUMP) -S $K/kernel > $K/kernel.asm +	$(OBJDUMP) -t $K/kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $K/kernel.sym -initcode: initcode.S -	$(CC) $(CFLAGS) -nostdinc -I. -c initcode.S -	$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o initcode.out initcode.o -	$(OBJCOPY) -S -O binary initcode.out initcode -	$(OBJDUMP) -S initcode.o > initcode.asm +$U/initcode: $U/initcode.S +	$(CC) $(CFLAGS) -nostdinc -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) entryother.S _init +tags: $(OBJS) _init  	etags *.S *.c -vectors.S: vectors.pl -	./vectors.pl > vectors.S - -ULIB = ulib.o usys.o printf.o umalloc.o +ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/umalloc.o  _%: %.o $(ULIB)  	$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^  	$(OBJDUMP) -S $@ > $*.asm  	$(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym -usys.S : usys.pl -	perl ./usys.pl > usys.S +$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 -_forktest: forktest.o $(ULIB) +$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 _forktest forktest.o ulib.o usys.o -	$(OBJDUMP) -S _forktest > forktest.asm +	$(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 -mkfs: mkfs.c fs.h -	gcc -Werror -Wall -o mkfs mkfs.c +mkfs/mkfs: mkfs/mkfs.c $K/fs.h +	gcc -Werror -Wall -I. -o mkfs/mkfs mkfs/mkfs.c  # 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 @@ -108,32 +113,33 @@ mkfs: mkfs.c fs.h  .PRECIOUS: %.o  UPROGS=\ -	_cat\ -	_echo\ -	_forktest\ -	_grep\ -	_init\ -	_kill\ -	_ln\ -	_ls\ -	_mkdir\ -	_rm\ -	_sh\ -	_stressfs\ -	_usertests\ -	_wc\ -	_zombie\ - -fs.img: mkfs README $(UPROGS) -	./mkfs fs.img README $(UPROGS) +	$U/_cat\ +	$U/_echo\ +	$U/_forktest\ +	$U/_grep\ +	$U/_init\ +	$U/_kill\ +	$U/_ln\ +	$U/_ls\ +	$U/_mkdir\ +	$U/_rm\ +	$U/_sh\ +	$U/_stressfs\ +	$U/_usertests\ +	$U/_wc\ +	$U/_zombie\ + +fs.img: mkfs/mkfs README $(UPROGS) +	mkfs/mkfs fs.img README $(UPROGS)  -include *.d  clean:   	rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \ -	*.o *.d *.asm *.sym vectors.S bootblock entryother \ -	initcode initcode.out kernel fs.img kernelmemfs \ -	mkfs .gdbinit \ +	*/*.o */*.d */*.asm */*.sym \ +	$U/initcode $U/initcode.out $K/kernel fs.img \ +	mkfs/mkfs .gdbinit \ +        $U/usys.S \  	$(UPROGS)  # make a printout @@ -155,23 +161,19 @@ QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \  ifndef CPUS  CPUS := 3  endif -QEMUOPTS = -machine virt -kernel kernel -m 3G -smp $(CPUS) -nographic +QEMUOPTS = -machine virt -kernel $K/kernel -m 3G -smp $(CPUS) -nographic  QEMUOPTS += -initrd fs.img -qemu: kernel fs.img +qemu: $K/kernel fs.img  	$(QEMU) $(QEMUOPTS)  .gdbinit: .gdbinit.tmpl-riscv  	sed "s/:1234/:$(GDBPORT)/" < $^ > $@ -qemu-gdb: kernel .gdbinit fs.img +qemu-gdb: $K/kernel .gdbinit fs.img  	@echo "*** Now run 'gdb'." 1>&2  	$(QEMU) $(QEMUOPTS) -S $(QEMUGDB) -qemu-nox-gdb: fs.img kernel .gdbinit -	@echo "*** Now run 'gdb'." 1>&2 -	$(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB) -  # CUT HERE  # prepare dist for students  # after running make dist, probably want to | 
