From ff61889138ba72be29a9cae795e1940c2a29249a Mon Sep 17 00:00:00 2001 From: bLueriVerLHR Date: Fri, 21 Jul 2023 14:26:41 +0800 Subject: [PATCH 1/3] [Modified] change toolchain to la32r --- .gitmodules | 3 ++ la32r-toolchains | 1 + lasoft/xv6-la/Makefile | 97 +++++++++++------------------------- lasoft/xv6-la/kernel/la32r.h | 0 lasoft/xv6-la/kernel/start.c | 2 +- loongarch64-linux-gnu | 1 - 6 files changed, 33 insertions(+), 71 deletions(-) create mode 160000 la32r-toolchains create mode 100644 lasoft/xv6-la/kernel/la32r.h delete mode 160000 loongarch64-linux-gnu diff --git a/.gitmodules b/.gitmodules index f0ca3ed..10ce7ab 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "lasoft/la32r-nemu"] path = lasoft/la32r-nemu url = https://gitee.com/wwt_panache/la32r-nemu +[submodule "la32r-toolchains"] + path = la32r-toolchains + url = https://gitee.com/loongson-edu/la32r-toolchains diff --git a/la32r-toolchains b/la32r-toolchains new file mode 160000 index 0000000..c6d7b1f --- /dev/null +++ b/la32r-toolchains @@ -0,0 +1 @@ +Subproject commit c6d7b1ffac6fa75b4e4e08df6496850e84984137 diff --git a/lasoft/xv6-la/Makefile b/lasoft/xv6-la/Makefile index d5e8f5d..4180100 100644 --- a/lasoft/xv6-la/Makefile +++ b/lasoft/xv6-la/Makefile @@ -2,53 +2,37 @@ 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 + $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-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 +TOOLPREFIX ?= CC = $(TOOLPREFIX)gcc AS = $(TOOLPREFIX)gas @@ -146,30 +130,5 @@ clean: $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 - build: $K/kernel fs.img -qemu: $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) - diff --git a/lasoft/xv6-la/kernel/la32r.h b/lasoft/xv6-la/kernel/la32r.h new file mode 100644 index 0000000..e69de29 diff --git a/lasoft/xv6-la/kernel/start.c b/lasoft/xv6-la/kernel/start.c index e16f18a..5356339 100644 --- a/lasoft/xv6-la/kernel/start.c +++ b/lasoft/xv6-la/kernel/start.c @@ -51,7 +51,7 @@ start() w_tp(id); // switch to supervisor mode and jump to main(). - asm volatile("mret"); + asm volatile("ertn"); } // arrange to receive timer interrupts. diff --git a/loongarch64-linux-gnu b/loongarch64-linux-gnu deleted file mode 160000 index f535a6f..0000000 --- a/loongarch64-linux-gnu +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f535a6f47e8837dc3a5fea74a1d49a9aa1bad393 From 82f8712de1401423b84b3ce4f84d22194d64b2f5 Mon Sep 17 00:00:00 2001 From: bLueriVerLHR Date: Sat, 22 Jul 2023 01:28:32 +0800 Subject: [PATCH 2/3] [Modified] rm la32r toolchain fxk it --- .gitmodules | 6 ------ la32r-toolchains | 1 - 2 files changed, 7 deletions(-) delete mode 160000 la32r-toolchains diff --git a/.gitmodules b/.gitmodules index 10ce7ab..c1aa3f9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,6 @@ -[submodule "loongarch64-linux-gnu"] - path = loongarch64-linux-gnu - url = https://gitee.com/loongarch_community/loongarch64-linux-gnu [submodule "nscscc-team-la32r"] path = nscscc-team-la32r url = https://gitee.com/loongson-edu/nscscc-team-la32r [submodule "lasoft/la32r-nemu"] path = lasoft/la32r-nemu url = https://gitee.com/wwt_panache/la32r-nemu -[submodule "la32r-toolchains"] - path = la32r-toolchains - url = https://gitee.com/loongson-edu/la32r-toolchains diff --git a/la32r-toolchains b/la32r-toolchains deleted file mode 160000 index c6d7b1f..0000000 --- a/la32r-toolchains +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c6d7b1ffac6fa75b4e4e08df6496850e84984137 From 1811d54f49e0eb472f28030f9fbe9b854d144f66 Mon Sep 17 00:00:00 2001 From: bLueriVerLHR Date: Sat, 22 Jul 2023 02:02:10 +0800 Subject: [PATCH 3/3] [Modified] update makefile --- Makefile | 31 +++++++++++++++---------------- lasoft/xv6-la/Makefile | 11 +++++------ lasoft/xv6-la/kernel/entry.S | 1 + 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 1c4aa2f..8ab6ab8 100644 --- a/Makefile +++ b/Makefile @@ -7,30 +7,29 @@ submodue-update-init: # prepare loongarch toolchain -TOOLCHAIN_PK := loongarch64-linux-gnu/toolchain-loongarch64-linux-gnu-gcc8-host-x86_64-2022-07-18.tar.xz +TOOLCHAIN_URL := https://gitee.com/loongson-edu/la32r-toolchains/releases/download/v0.0.2/loongarch32r-linux-gnusf-2022-05-20-x86.tar.gz +LA_GDB_URL := https://gitee.com/loongson-edu/la32r-toolchains/releases/download/v0.0.2/loongarch32r-linux-gnusf-gdb-x86 -LA_PATH := ext/toolchain-loongarch64-linux-gnu-gcc8-host-x86_64-2022-07-18/bin -LA_ARCH := loongarch64-linux-gnu- -LA := $(LA_PATH)/$(LA_ARCH) +TOOLCHAIN_TAR := $(notdir $(TOOLCHAIN_URL)) +LA_GDB_TAR := $(notdir $(LA_GDB_URL)) -GCC := $(LA)gcc -OD := $(LA)objdump -OC := $(LA)objcopy -RE := $(LA)readelf +ext/$(TOOLCHAIN_TAR): + wget $(TOOLCHAIN_URL) + tar -zxvf $(notdir $@) + mv loongarch32r-linux-gnusf-* ext -LA_TOOLS := $(GCC) $(OD) $(OC) $(RE) +lagcc: ext/$(TOOLCHAIN_TAR) -unpk-gcc: submodue-update-init - mkdir -p ext - tar -xvf $(TOOLCHAIN_PK) -C ext - -$(LA_TOOLS): unpk-gcc +LA_ARCH := loongarch32r-linux-gnusf- # prepare loongarch source code -xv6: - TOOLPREFIX=$(CURDIR)/$(LA) $(MAKE) -C lasoft/xv6-la build +xv6: lagcc + TOOLPREFIX=$(CURDIR)/$(shell find ext -type d -name '$(LA_ARCH)*')/bin/$(LA_ARCH) \ + $(MAKE) -C lasoft/xv6-la build xv6-clean: $(MAKE) -C lasoft/xv6-la clean +clean-latc: + rm -r ext/* diff --git a/lasoft/xv6-la/Makefile b/lasoft/xv6-la/Makefile index 4180100..db73e2e 100644 --- a/lasoft/xv6-la/Makefile +++ b/lasoft/xv6-la/Makefile @@ -30,8 +30,6 @@ OBJS = \ $K/plic.o \ $K/virtio_disk.o -# riscv64-unknown-elf- or riscv64-linux-gnu- -# perhaps in /opt/riscv/bin TOOLPREFIX ?= CC = $(TOOLPREFIX)gcc @@ -42,9 +40,10 @@ 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 += -mcmodel=normal +CFLAGS += -ffreestanding -fno-common -nostdlib -mstrict-align CFLAGS += -I. +CFLAGS += -mfpu=none -mabi=ilp32s -march=loongarch32r 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) @@ -58,12 +57,12 @@ endif LDFLAGS = -z max-page-size=4096 $K/kernel: $(OBJS) $K/kernel.ld $U/initcode - $(LD) $(LDFLAGS) -T $K/kernel.ld -o $K/kernel $(OBJS) + $(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 $U/initcode: $U/initcode.S - $(CC) $(CFLAGS) -march=rv64g -nostdinc -I. -Ikernel -c $U/initcode.S -o $U/initcode.o + $(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 diff --git a/lasoft/xv6-la/kernel/entry.S b/lasoft/xv6-la/kernel/entry.S index a8433b8..107d410 100644 --- a/lasoft/xv6-la/kernel/entry.S +++ b/lasoft/xv6-la/kernel/entry.S @@ -1,3 +1,4 @@ +#include "csr.h" # qemu -kernel loads the kernel at 0x80000000 # and causes each hart (i.e. CPU) to jump there. # kernel.ld causes the following code to