summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile101
1 files changed, 41 insertions, 60 deletions
diff --git a/Makefile b/Makefile
index b199842..1424d7c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,20 @@
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
+
+XXXOBJS = \
bio.o\
console.o\
exec.o\
@@ -28,48 +44,23 @@ OBJS = \
vectors.o\
vm.o\
-# Cross-compiling (e.g., on Mac OS X)
-# TOOLPREFIX = i386-jos-elf
-
-# Using native tools (e.g., on X86 Linux)
+# 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 i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
- then echo 'i386-jos-elf-'; \
- elif objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \
- then echo ''; \
+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-'; \
else echo "***" 1>&2; \
- echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \
- echo "*** Is the directory with i386-jos-elf-gcc in your PATH?" 1>&2; \
- echo "*** If your i386-*-elf toolchain is installed with a command" 1>&2; \
- echo "*** prefix other than 'i386-jos-elf-', set your TOOLPREFIX" 1>&2; \
- echo "*** environment variable to that prefix and run 'make' again." 1>&2; \
+ echo "*** Error: Couldn't find an 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
-# If the makefile can't find QEMU, specify its path here
-QEMU = qemu-system-x86_64
-
-# Try to infer the correct QEMU
-ifndef QEMU
-QEMU = $(shell if which qemu > /dev/null; \
- then echo qemu; exit; \
- elif which qemu-system-i386 > /dev/null; \
- then echo qemu-system-i386; exit; \
- elif which qemu-system-x86_64 > /dev/null; \
- then echo qemu-system-x86_64; exit; \
- else \
- qemu=/Applications/Q.app/Contents/MacOS/i386-softmmu.app/Contents/MacOS/i386-softmmu; \
- if test -x $$qemu; then echo $$qemu; exit; fi; fi; \
- echo "***" 1>&2; \
- echo "*** Error: Couldn't find a working QEMU executable." 1>&2; \
- echo "*** Is the directory containing the qemu binary in your PATH" 1>&2; \
- echo "*** or have you tried setting the QEMU variable in Makefile?" 1>&2; \
- echo "***" 1>&2; exit 1)
-endif
+QEMU = qemu-system-riscv64
CC = $(TOOLPREFIX)gcc
AS = $(TOOLPREFIX)gas
@@ -77,15 +68,10 @@ LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump
-XFLAGS = -m64 -mcmodel=large -ggdb
-# CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -Werror -fno-omit-frame-pointer
-CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -Werror -fno-omit-frame-pointer
-CFLAGS += -ffreestanding -fno-common -nostdlib $(XFLAGS)
+CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -Werror -fno-omit-frame-pointer -O
+CFLAGS = -mcmodel=medany
+CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
-ASFLAGS = -gdwarf-2 -Wa,-divide $(XFLAGS)
-# FreeBSD ld wants ``elf_i386_fbsd''
-LDFLAGS += -m $(shell $(LD) -V | grep elf_x86_64 2>/dev/null | head -n 1)
-LDFLAGS += -z max-page-size=4096
# Disable PIE when possible (for Ubuntu 16.10 toolchain)
ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]no-pie'),)
@@ -95,21 +81,17 @@ ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]nopie'),)
CFLAGS += -fno-pie -nopie
endif
-kernel: $(OBJS) entry.o entryother initcode kernel.ld
- $(LD) $(LDFLAGS) -T kernel.ld -o kernel entry.o $(OBJS) -b binary initcode entryother
+LDFLAGS = -z max-page-size=4096
+
+kernel: $(OBJS) entry.o kernel.ld
+ $(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
-entryother: entryother.S
- $(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c entryother.S
- $(LD) $(LDFLAGS) -N -e start -Ttext 0x7000 -o bootblockother.o entryother.o
- $(OBJCOPY) -S -O binary -j .text bootblockother.o entryother
- $(OBJDUMP) -S bootblockother.o > entryother.asm
-
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
+ #$(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
tags: $(OBJS) entryother.S _init
@@ -186,19 +168,18 @@ QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
then echo "-gdb tcp::$(GDBPORT)"; \
else echo "-s -p $(GDBPORT)"; fi)
ifndef CPUS
-CPUS := 2
+CPUS := 1
endif
-QEMUOPTS = -kernel kernel -drive file=fs.img,index=1,media=disk,format=raw -smp $(CPUS) -m 512 $(QEMUEXTRA)
-qemu: fs.img
- $(QEMU) -serial mon:stdio $(QEMUOPTS)
+QEMUOPTS = -machine virt -kernel kernel -m 3G -smp $(CPUS) -nographic
+#QEMUOPTS += -initrd fs.img
-qemu-nox: fs.img kernel
- $(QEMU) -nographic $(QEMUOPTS)
+qemu: kernel
+ $(QEMU) $(QEMUOPTS)
-.gdbinit: .gdbinit.tmpl-x64
- sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
+.gdbinit: .gdbinit.tmpl-riscv
+ sed "s/:1234/:$(GDBPORT)/" < $^ > $@
-qemu-gdb: fs.img kernel .gdbinit
+qemu-gdb: kernel .gdbinit
@echo "*** Now run 'gdb'." 1>&2
$(QEMU) $(QEMUOPTS) -S $(QEMUGDB)