
西北工業大學,“全國大學生計算機系統能力大賽- 操作系統設計賽(全國)- OS內核實現賽道龍芯LA2K1000分賽道” 一等獎(無特等獎)參賽作品。
隊名來源:具有影響力的NPUcore,三個感嘆號代表三個成員。
被帶飛的隊長:[內核設計與適配/文檔] Yixu Feng ([email protected])
超級隊員:[Debug高手] Yifei Zhang ([email protected]), [硬件大神] Hanchen Zhang ([email protected]), [場外支持] Huan Guo (個人博客)
致後面參加OS比賽龍芯賽道的西工大或者是其它學校的同學們:如果你們看到了這個倉庫,說明你們找對了位置,這是我們NPUcore-IMPACT最原始的倉庫,是基於NPUcore+LA的plus版(我們後續又重構了新的版本,但在這個倉庫是找不到的)。這個倉庫的NPUcore-FF分支是我們初賽滿分( fat32文件系統)的分支,而ext4分支則是我們在決賽的時候對ext4文件系統進行適配的實驗分支,但請注意ext4分支是無法跑通的,因為它不是我們debug的最終版!
我們決賽最終階段(線上賽+第二階段)的代碼決定不完全對外公佈,原因是我們在決賽前的十五天內做了非常非常多的調整,比如:成功適配ext4 ,增加了很多新的syscall ...。但是代價是,時間緊迫,我們的代碼就是一大坨,我們真的不想把拉出來的低質量代碼給大家看。因此我們僅把這個原始倉庫公開給大家參考。下面是我推薦的參考鏈接:
如果你想使用rust版本基於LA的arch crate ,請參考:NPUcore-LA2K1000-Arch
如果你想了解我們初賽的Debug過程,請參考:LA初賽測例修復
如果你想知道我們在決賽第一階段做了什麼,請參考:決賽第一階段文檔
如果你想知道我們的最終版NPUcore-IMPACT和別人不一樣的地方,請參考:決賽答辯
如果你想知道我們現場賽做了什麼,請參考:現場賽
如果你想知道我們最後是怎麼答辯的,請參考:決賽稿
如果你想使用並修改我們的logo (需要學會使用AE),請參考:LOGO
如果你在Debug的時候遇到了我們沒提到的困難,請參考:2024二等獎:NPUcore-重生之我是菜狗、2022一等獎:RISCV原版NPUcore、2023二等獎-NPUcore+LA
如果你想學習NPUcore的搭建過程,請參考:NPUcore-Book
如果你想使用我們的代碼作為baseline ,我們推薦使用(我們修改的NPUcore-重生之我是菜狗隊伍代碼,包含部分ext4 ):NPUcore-lwext4
如果你想參考我們Latex的文檔格式與模板,請參考:NPUcore-IMPACT-doc
我們整理的龍芯參考文檔:百度網盤:密碼1145
我們的比賽測例:testcases源碼,testcases二進製文件
我們的QEMU環境:QEMU
QEMU上跑通不是真正的跑通。 ( QEMU和板子的區別主要是地址映射,出現問題請往這個方向查找)uboot源碼,別研究黑盒。NPUcore ,而不是用我們這個老版,我希望這個版本僅作為你們的一個參考。NPUcore ,而是先做一下這個實驗:xv6-loongarchNPUcore-IMPACT作為你的baseline,以及它的耦合度非常非常高,我們廢了半天勁才解耦FAT32版本的NPUcore-IMPACT作為你們的baseline,那請參考我們的所有文檔,並先實現vfs ,把fs和fat32完全解耦,再考慮增加新的文件系統(如果明年仍然是EXT4為主流)和系統調用。NPUcore-IMPACT在功能性上仍有很多不足,如果明年仍然需要跑ltp測例,那一定要多加系統調用(據說明年要拿好名次,可能需要200個syscall )。NPUcore2022主要做了cache上的優化,但是它也導致了很多功能上的問題,如果後面出了很多新的bug,請務必考慮這裡,必要時可以拋棄曾經的亮點。NPUcore-IMPACT ,請把功能優先於性能考慮,雖然性能上仍有很多優化空間,但是功能上的不完善會導致一分都得不到。sudo apt-get install make
sudo apt-get install cmake安裝rust對LoongArch的編譯鏈
安裝rustup(rust的安裝器+版本管理器)
rustup install nightly-2024-02-03安裝Rust工具鏈由於LoongArch架構的交叉編譯Rust工具鏈已經合併到上游, 目前不需要我們手動安裝。
在Makefile中有自動的檢測腳本, 只需要後續的make命令即可。
安裝交叉編譯工具。本項目使用的為在x86_64下編譯產生loongarch64的編譯工具。 Loong Arch GCC 13: https://github.com/LoongsonLab/oscomp-toolchains-for-oskernel
wget https://github.com/LoongsonLab/oscomp-toolchains-for-oskernel/releases/download/gcc-13.2.0-loongarch64/gcc-13.2.0-loongarch64-linux-gnu.tgz
tar zxf gcc-13.2.0-loongarch64-linux-gnu.tgz
# 在.bashrc中增加交叉编译器路径。假设当前路径为:/opt/gcc-13.2.0-loongarch64-linux-gnu
export PATH=${PATH}:/opt/gcc-13.2.0-loongarch64-linux-gnu/bin
# 如果配置正确,输入如下命令
loongarch64-linux-gnu-gcc -v
#会显示如下:
Using built-in specs.
COLLECT_GCC=loongarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/home/airxs/local/gcc-13.2.0-loongarch64-linux-gnu/bin/../libexec/gcc/loongarch64-linux-gnu/13.2.0/lto-wrapper
Target: loongarch64-linux-gnu
Configured with: ../configure --prefix=/home/airxs/user/gnu/cross-tools --build=x86_64-cross-linux-gnu --host=x86_64-cross-linux-gnu --target=loongarch64-linux-gnu --with-sysroot=/home/airxs/user/gnu/cross-tools/sysroot --with-mpfr=/home/airxs/user/gnu/cross-tools --with-gmp=/home/airxs/user/gnu/cross-tools --with-mpc=/home/airxs/user/gnu/cross-tools --enable-__cxa_atexit --enable-threads=posix --with-system-zlib --enable-libstdcxx-time --enable-checking=release --enable-default-pie --enable-languages=c,c++,fortran,objc,obj-c++,lto
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.2.0 (GCC)
缺少部分庫文件和編譯rust代碼出現錯誤的問題建議嘗試make clean後, 刪除對應文件夾的Cargo.lock, 嘗試在Cargo.toml中刪除版本限制再重新編譯。
直接在根目錄命令行make即可。 第一次運行推薦先執行一遍從而方便環境的安裝和熟悉。
ram=0x1f17f00
length=852992 must be 16777216 bytes,run command:
trucate -s 16777216 file
to resize file
oobsize = 64
_ __ __ _ _ ___ ___ __ _ _ / ___ __
| | | | | | | | __ [__ | | | | | | __ | |
| ___ | __ | | __ | | | | __] ___] | __ | | | | __] | __/ /
Trying to boot from SPI
U-Boot 2022.04 (Jan 26 2024 - 15:42:00 +0800)
CPU: LA264
Speed: Cpu @ 900 MHz/ Mem @ 400 MHz/ Bus @ 125 MHz
Model: loongson-2k1000
Board: LS2K1000-DP
DRAM: 1 GiB
Core: 74 devices, 20 uclasses, devicetree: board
cam_disable:1, vpu_disable:1, pcie0_enable:0, pcie1_enable:1
Loading Environment from SPIFlash... SF: Detected gd25q128 with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment
Cannot get ddc bus
In: serial
Out: serial
Err: serial vidconsole
eth0: using random MAC address - f2:ef:a7:28:76:cd
eth1: using random MAC address - 82:98:7e:f2:f8:e4
Net: Could not get PHY for mdio@0: addr 0
Could not get PHY for mdio@1: addr 0
3No ethernet found.
************************** Notice **************************
Press c to enter u-boot console, m to enter boot menu
************************************************************
Bus otg@40000000: dwc2_usb otg@40000000: Core Release: 0.000
dwc2_usb otg@40000000: SNPSID invalid (not DWC2 OTG device): 00000000
Port not available.
Bus ehci@40060000: USB EHCI 1.00
Bus ohci@40070000: USB OHCI 1.0
scanning bus ehci@40060000 for devices... 3 USB Device(s) found
scanning bus ohci@40070000 for devices... 1 USB Device(s) found
init ls_trigger_boot and set it default value
init ls_trigger_u_kernel and set it default value
init ls_trigger_u_rootfs and set it default value
init ls_trigger_u_uboot and set it default value
Saving Environment to SPIFlash... Erasing SPI flash...Writing to SPI flash...done
OK
Autoboot in 0 seconds
SF: Detected gd25q128 with page size 256 Bytes, erase size 4 KiB, total 16 MiB
device 0 offset 0xf0000, size 0x10000
SF: 65536 bytes @ 0xf0000 Read: OK
Reset SCSI
scanning bus for devices...
Target spinup took 0 ms.
Target spinup took 0 ms.
Target spinup took 0 ms.
SATA link 3 timeout.
SATA link 4 timeout.
SATA link 5 timeout.
AHCI 0001.0000 32 slots 6 ports 1.5 Gbps 0x3f impl SATA mode
flags: 64bit ncq only
Device 0: (0:0) Vendor: ATA Prod.: QEMU HARDDISK Rev: 2.5+
Type: Hard Disk
Capacity: 100.0 MB = 0.0 GB (204800 x 512)
Device 1: (1:0) Vendor: ATA Prod.: QEMU HARDDISK Rev: 2.5+
Type: Hard Disk
Capacity: 1024.0 MB = 1.0 GB (2097152 x 512)
Device 2: (2:0) Vendor: ATA Prod.: QEMU HARDDISK Rev: 2.5+
Type: Hard Disk
Capacity: 1024.0 MB = 1.0 GB (2097152 x 512)
** No partition table - scsi 0 **
Couldn ' t find partition scsi 0:1
Can ' t set block device
Wrong Image Format for bootm command
ERROR: can ' t get kernel image!
Bootcmd="setenv bootargs ${bootargs} root=/dev/sda${syspart} mtdparts=${mtdparts} video=${video}; sf probe;sf read ${fdt_addr} dtb;scsi reset;ext4load scsi 0:${syspart} ${loadaddr} /boot/uImage;bootm "
Boot Kernel failed. Kernel not found or bad.
=>
=>
=>
=> fatload scsi 0 ${loadaddr} /kernel.bin;go ${loadaddr};
47739944 bytes read in 761 ms (59.8 MiB/s)
## Starting application at 0x9000000090000000 ...
[kernel] NPUcore-IMAPCT!!! ENTER!
[kernel] UART address: 0x1fe20000
[bootstrap_init] PRCfg1 { SAVE reg. number: 8, Timer bits: 48, max vector entry spacing: 7 }
[kernel] Console initialized.
last 37479 Physical Frames.
.text [0x90000000, 0x90069000)
.rodata [0x90069000, 0x90075000)
.data [0x90081000, 0x92d88000)
.bss [0x92d88000, 0x96d99000)
mapping .text section
mapping .rodata section
mapping .data section
mapping .bss section
mapping physical memory
mapping memory-mapped registers
[get_timer_freq_first_time] clk freq: 100000000(from CPUCFG)
[CPUCFG 0x0] 1351680
[CPUCFG 0x1] 66253566
[CPUCFG 0x2] 6341127
[CPUCFG 0x3] 3327
[CPUCFG 0x4] 100000000
[CPUCFG 0x5] 65537
[CPUCFG 0x6] 0
[CPUCFG 0x10] 11325
[CPUCFG 0x11] 0
[CPUCFG 0x12] 0
[CPUCFG 0x13] 0
[CPUCFG 0x14] 0
Misc { 32-bit addr plv(1,2,3):: false,false,false, rdtime allowed for plv(1,2,3):: false,false,false, Disable dirty bit check for plv(0,1,2):: false,false,false, Misalignment check for plv(0,1,2,4):: false,false,false,false }
RVACfg { rbits: 0 }
[machine_init] MMAP_BASE: 0xffffff8000000000
[kernel] Hello, world!
Testing execve :
========== START test_execve ==========
I am test_echo.
execve success.
========== END main ==========
Testing brk :
========== START test_brk ==========
Before alloc,heap pos: 12288
After alloc,heap pos: 12352
Alloc again,heap pos: 12416
========== END test_brk ==========
Testing chdir :
========== START test_chdir ==========
chdir ret: 0
current working dir : /test_chdir
========== END test_chdir ==========
Testing clone :
========== START test_clone ==========
Child says successfully!
clone process successfully.
pid:3
========== END test_clone ==========
Testing close :
========== START test_close ==========
close 3 success.
========== END test_close ==========
Testing dup2 :
========== START test_dup2 ==========
from fd 100
========== END test_dup2 ==========
Testing dup :
========== START test_dup ==========
new fd is 3.
========== END test_dup ==========
Testing exit :
========== START test_exit ==========
exit OK.
========== END test_exit ==========
Testing fork :
========== START test_fork ==========
child process.
parent process. wstatus:0
========== END test_fork ==========
Testing fstat :
========== START test_fstat ==========
fstat ret: 0
fstat: dev: 2048, inode: 5784, mode: 33279, nlink: 1, size: 52, atime: 0, mtime: 0, ctime: 0
========== END test_fstat ==========
Testing getcwd :
========== START test_getcwd ==========
getcwd: / successfully!
========== END test_getcwd ==========
Testing getdents :
========== START test_getdents ==========
open fd:3
getdents fd:456
getdents success.
lib
========== END test_getdents ==========
Testing getpid :
========== START test_getpid ==========
getpid success.
pid = 2
========== END test_getpid ==========
Testing getppid :
========== START test_getppid ==========
getppid success. ppid : 1
========== END test_getppid ==========
Testing gettimeofday :
========== START test_gettimeofday ==========
gettimeofday success.
start:12098, end:12163
interval: 65
========== END test_gettimeofday ==========
Testing mkdir_ :
========== START test_mkdir ==========
mkdir ret: -17
mkdir success.
========== END test_mkdir ==========
Testing mmap :
========== START test_mmap ==========
file len: 27
mmap content: Hello, mmap successfully!
========== END test_mmap ==========
Testing mount :
========== START test_mount ==========
Mounting dev:/dev/vdb to ./mnt
mount return: 0
mount successfully
umount return: 0
========== END test_mount ==========
Testing munmap :
========== START test_munmap ==========
file len: 27
munmap return: 0
munmap successfully!
========== END test_munmap ==========
Testing open :
========== START test_open ==========
Hi, this is a text file.
syscalls testing success!
========== END test_open ==========
Testing openat :
========== START test_openat ==========
open dir fd: 3
openat fd: 4
openat success.
========== END test_openat ==========
Testing pipe :
========== START test_pipe ==========
cpid: 3
cpid: 0
Write to pipe successfully.
========== END test_pipe ==========
Testing read :
========== START test_read ==========
Hi, this is a text file.
syscalls testing success!
========== END test_read ==========
Testing sleep :
========== START test_sleep ==========
sleep success.
========== END test_sleep ==========
Testing times :
========== START test_times ==========
mytimes success
{tms_utime:274200, tms_stime:0, tms_cutime:0, tms_cstime:0}
========== END test_times ==========
Testing umount :
========== START test_umount ==========
Mounting dev:/dev/vda2 to ./mnt
mount return: 0
umount success.
return: 0
========== END test_umount ==========
Testing uname :
========== START test_uname ==========
Uname: Linux debian 5.10.0-7-riscv64 #1 SMP Debian 5.10.40-1 (2021-05-28) riscv64
========== END test_uname ==========
Testing unlink :
========== START test_unlink ==========
unlink success!
========== END test_unlink ==========
Testing wait :
========== START test_wait ==========
This is child process
wait child success.
wstatus: 0
========== END test_wait ==========
Testing waitpid :
========== START test_waitpid ==========
This is child process
waitpid successfully.
wstatus: 3
========== END test_waitpid ==========
Testing write :
========== START test_write ==========
Hello operating system contest.
========== END test_write ==========
Testing yield :
========== START test_yield ==========
I am child process: 3. iteration 0.
I am child process: 4. iteration 1.
I am child process: 3. iteration 0.
I am child process: 4. iteration 1.
I am child process: 5. iteration 2.
I am child process: 3. iteration 0.
I am child process: 4. iteration 1.
I am child process: 5. iteration 2.
I am child process: 3. iteration 0.
I am child process: 4. iteration 1.
I am child process: 5. iteration 2.
I am child process: 3. iteration 0.
I am child process: 4. iteration 1.
I am child process: 5. iteration 2.
I am child process: 5. iteration 2.
========== END test_yield ==========
[initproc] test finish在打印了大量的測試結果後退出執行。
注意,在命令後加入LOG=trace可以開啟trace及以上的所有log, log從低到高等級分為trace, debug, info, warning, error
make run : 編譯系統,且執行虛擬機測試make gdb : 執行開啟debug模式(需要配合gdb使用), 啟動虛擬機但不運行
make clean已經編譯的項目(包括用戶程序, 系統和FAT鏡像)