xv7c4 - ccc-sp/riscv2os GitHub Wiki
xv7: 加入一個小型的 c 語言編譯器 (c4)
C4 編譯器
執行結果
$ make qemu
gcc -Werror -Wall -I. -o mkfs/mkfs mkfs/mkfs.c
riscv64-unknown-elf-gcc -w -Wall -Werror -O -fno-omit-frame-pointer -ggdb -MD -mcmodel=medany -ffreestanding -fno-common -nostdlib -mno-relax -I. -fno-stack-protector -DNET_TESTS_PORT=27772 -fno-pie -no-pie -c -o user/c4.o user/c4.c
riscv64-unknown-elf-ld -z max-page-size=4096 -N -e _main -Ttext 0 -o user/_c4 user/c4.o lib/_main.o lib/ulib.o user/usys.o lib/printf.o lib/sscanf.o lib/umalloc.o
mkfs/mkfs fs.img doc/README doc/hello.c doc/sum.c doc/fib.c user/c4.c user/_cat user/_echo user/_grep user/_init user/_kill user/_ln user/_ls user/_mkdir user/_rm user/_sh user/_stressfs user/_wc user/_zombie user/_uthread user/_cp user/_c4 user/_editor user/_nettests user/_mmaptest user/_forktest user/_usertests user/_bigfile
nmeta 70 (boot, super, log blocks 30 inode blocks 13, bitmap blocks 25) blocks 199930 total 200000
balloc: first 961 blocks have been allocated
balloc: write bitmap block at sector 45
qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 -netdev user,id=net0,hostfwd=udp::29772-:2000 -object filter-dump,id=net0,netdev=net0,file=packets.pcap -device e1000,netdev=net0,bus=pcie.0
xv6 kernel is booting
virtio disk init 0
hart 2 starting
hart 1 starting
init: starting sh
$ c4 hello.c
hello, world
exit(0) cycle = 9
$ c4 sum.c
sum(10)=55
exit(0) cycle = 303
$ c4 fib.c
f(7)=13
exit(8) cycle = 920