Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 0 additions & 4 deletions .dir-locals.el

This file was deleted.

22 changes: 0 additions & 22 deletions .editorconfig

This file was deleted.

6 changes: 0 additions & 6 deletions .gdbinit.tmpl-riscv

This file was deleted.

18 changes: 0 additions & 18 deletions .gitignore

This file was deleted.

File renamed without changes.
198 changes: 198 additions & 0 deletions G12_Project1_xv6CustomizeSystemCalls/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
K=kernel
U=user

OBJS = \
$K/entry.o \
$K/start.o \
$K/console.o \
$K/printf.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/exec.o \
$K/sysfile.o \
$K/kernelvec.o \
$K/plic.o \
$K/virtio_disk.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-elf-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \
then echo 'riscv64-elf-'; \
elif riscv64-none-elf-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \
then echo 'riscv64-none-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
MIN_QEMU_VERSION = 7.2

CC = $(TOOLPREFIX)gcc
AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump

CFLAGS = -Wall -Werror -Wno-unknown-attributes -O -fno-omit-frame-pointer -ggdb -gdwarf-2
CFLAGS += -march=rv64gc
CFLAGS += -MD
CFLAGS += -mcmodel=medany
CFLAGS += -ffreestanding
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.
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) $K/kernel.ld
$(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

$K/%.o: $K/%.S
$(CC) -march=rv64gc -g -c -o $@ $<

tags: $(OBJS)
etags kernel/*.S kernel/*.c

ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/umalloc.o

_%: %.o $(ULIB) $U/user.ld
$(LD) $(LDFLAGS) -T $U/user.ld -o $@ $< $(ULIB)
$(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

mkfs/mkfs: mkfs/mkfs.c $K/fs.h $K/param.h
gcc -Wno-unknown-attributes -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
# details:
# http://www.gnu.org/software/make/manual/html_node/Chained-Rules.html
.PRECIOUS: %.o

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/_grind\
$U/_wc\
$U/_zombie\
$U/_logstress\
$U/_forphan\
$U/_dorphan\
$U/_test_procs\
$U/_test_getppid\
$U/_test_sleep2

fs.img: mkfs/mkfs README $(UPROGS)
mkfs/mkfs fs.img README $(UPROGS)

-include kernel/*.d user/*.d

clean:
rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
*/*.o */*.d */*.asm */*.sym \
$K/kernel fs.img \
mkfs/mkfs .gdbinit \
$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

qemu: check-qemu-version $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)

print-gdbport:
@echo $(GDBPORT)

QEMU_VERSION := $(shell $(QEMU) --version | head -n 1 | sed -E 's/^QEMU emulator version ([0-9]+\.[0-9]+)\..*/\1/')
check-qemu-version:
@if [ "$(shell echo "$(QEMU_VERSION) >= $(MIN_QEMU_VERSION)" | bc)" -eq 0 ]; then \
echo "ERROR: Need qemu version >= $(MIN_QEMU_VERSION)"; \
exit 1; \
fi
File renamed without changes.
Binary file added G12_Project1_xv6CustomizeSystemCalls/fs.img
Binary file not shown.
File renamed without changes.
3 changes: 3 additions & 0 deletions G12_Project1_xv6CustomizeSystemCalls/kernel/bio.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kernel/bio.o: kernel/bio.c kernel/types.h kernel/param.h \
kernel/spinlock.h kernel/sleeplock.h kernel/riscv.h kernel/defs.h \
kernel/fs.h kernel/buf.h
Binary file added G12_Project1_xv6CustomizeSystemCalls/kernel/bio.o
Binary file not shown.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions G12_Project1_xv6CustomizeSystemCalls/kernel/console.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kernel/console.o: kernel/console.c \
/usr/lib/gcc-cross/riscv64-linux-gnu/13/include/stdarg.h kernel/types.h \
kernel/param.h kernel/spinlock.h kernel/sleeplock.h kernel/fs.h \
kernel/file.h kernel/memlayout.h kernel/riscv.h kernel/defs.h \
kernel/proc.h
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
3 changes: 3 additions & 0 deletions G12_Project1_xv6CustomizeSystemCalls/kernel/exec.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kernel/exec.o: kernel/exec.c kernel/types.h kernel/param.h \
kernel/memlayout.h kernel/riscv.h kernel/spinlock.h kernel/proc.h \
kernel/defs.h kernel/elf.h
Binary file not shown.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions G12_Project1_xv6CustomizeSystemCalls/kernel/file.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kernel/file.o: kernel/file.c kernel/types.h kernel/riscv.h kernel/defs.h \
kernel/param.h kernel/fs.h kernel/spinlock.h kernel/sleeplock.h \
kernel/file.h kernel/stat.h kernel/proc.h
File renamed without changes.
Binary file not shown.
File renamed without changes.
3 changes: 3 additions & 0 deletions G12_Project1_xv6CustomizeSystemCalls/kernel/fs.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kernel/fs.o: kernel/fs.c kernel/types.h kernel/riscv.h kernel/defs.h \
kernel/param.h kernel/stat.h kernel/spinlock.h kernel/proc.h \
kernel/sleeplock.h kernel/fs.h kernel/buf.h kernel/file.h
File renamed without changes.
Binary file added G12_Project1_xv6CustomizeSystemCalls/kernel/fs.o
Binary file not shown.
File renamed without changes.
2 changes: 2 additions & 0 deletions G12_Project1_xv6CustomizeSystemCalls/kernel/kalloc.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kernel/kalloc.o: kernel/kalloc.c kernel/types.h kernel/param.h \
kernel/memlayout.h kernel/spinlock.h kernel/riscv.h kernel/defs.h
Binary file not shown.
Binary file not shown.
Loading