
Northwestern Polytechnical University, the first prize (no special prize) entry for "National College Student Computer System Ability Competition - Operating System Design Competition (National) - OS kernel realization track Loongson LA2K1000 points track".
Team name source: Influential NPUcore, three exclamation marks represent three members.
The captain who was taken away: [Kernel design and adaptation/document] Yixu Feng ([email protected])
Super players: [Debug expert] Yifei Zhang ([email protected]), [Hardware master] Hanchen Zhang ([email protected]), [Off-field support] Huan Guo (personal blog)
To the students from Xi'an University of Technology or other schools who participated in the OS competition in Loongson Track: If you see this warehouse, it means you have found the right location. This is the most original warehouse of our NPUcore-IMPACT, which is a plus version based on NPUcore+LA (we later reconstructed a new version, but it cannot be found in this warehouse). NPUcore-FF branch of this repository is the branch of our first-time full score ( fat32 file system), and the ext4 branch is the experimental branch that we adapted to the ext4 file system in the finals, but please note that ext4 branch cannot run because it is not the final version of our debug !
The code decision for the final stage of our final (online match + second stage) is not fully announced to the public because we made a lot of adjustments within the fifteen days before the final, such as: successfully adapting ext4 and adding a lot of new syscall ... But the price is that time is tight, our code is just a big lump, and we really don’t want to show everyone the low-quality code we pulled out. Therefore, we only publicly disclose this original warehouse for your reference. Here are my recommended reference links:
If you want to use the rust version of LA-based arch crate , please refer to: NPUcore-LA2K1000-Arch
If you want to know about the Debug process of our preliminary competition, please refer to: LA preliminary competition test repair
If you want to know what we did in the first phase of the final, please refer to: Finals Phase 1 Documentation
If you want to know what differentiates our final version NPUcore-IMPACT from others, please refer to: Final Defence
If you want to know what we did on the live competition, please refer to: Live competition
If you want to know how we finally defended, please refer to: Draft of the final
If you want to use and modify our logo (need to learn how to use AE), please refer to: LOGO
If you encounter difficulties that we did not mention during Debug, please refer to: 2024 Second Prize: NPUcore-Rebirth: I am a Caigou, 2022 First Prize: RISCV original NPUcore, 2023 Second Prize-NPUcore+LA
If you want to learn the NPUcore construction process, please refer to: NPUcore-Book
If you want to use our code as baseline , we recommend using (our modified NPUcore-重生之我是菜狗team code, including part ext4 ): NPUcore-lwext4
If you want to refer to our Latex document format and template, please refer to: NPUcore-IMPACT-doc
We compiled Loongson reference document: Baidu Netdisk: Password 1145
Our competition test examples: testcases source code, testcases binary file
Our QEMU environment: QEMU
QEMU is not a real run through. (The main difference between QEMU and board is address mapping. If there is any problem, please look in this direction)uboot source code twice, and do not study the black box.NPUcore from scratch instead of using our old version. I hope this version is only used as a reference for you.NPUcore during the learning stage, but do this experiment first: xv6-loongarchNPUcore-IMPACT as your baseline, and its coupling degree is very, very high. We have been useless for a long time to decouple it.FAT32 version of NPUcore-IMPACT as your baseline, please refer to all our documentation and implement vfs first, completely decouple fs and fat32 , and then consider adding a new file system (if EXT4 is still mainstream next year) and system calls.NPUcore-IMPACT still has many functional shortcomings. If you still need to run the ltp test next year, you must add more system calls (it is said that you need to get a good ranking this year, and you may need 200 syscall ).NPUcore2022 mainly optimizes cache , but it also leads to many functional problems. If there are many new bugs later, please be sure to consider this. If necessary, you can abandon the previous highlights.NPUcore-IMPACT , please give priority to performance. Although there is still a lot of room for optimization in performance, imperfections in function will lead to not getting a single point.sudo apt-get install make
sudo apt-get install cmakeInstall rust's compilation chain for LoongArch
Install rustup (rust's installer + version manager)
rustup install nightly-2024-02-03 Installing the Rust toolchain Since the cross-compilation of the LoongArch architecture has been merged into the upstream, we do not need to install it manually at present.
There is an automatic detection script in Makefile , only the subsequent make command is needed.
Install the cross-compilation tool. This project uses a compilation tool that generates loongarch64 under x86_64. 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)
If there is an error in missing some library files and rust code compilation, it is recommended to try to make clean , delete the Cargo.lock in the corresponding folder, try to delete the version limit in Cargo.toml and then recompile.
Just make it directly in the root directory command line. It is recommended to execute it first to facilitate the installation and familiarity of the environment.
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 finishExit execution after printing a large number of test results.
Note that adding LOG=trace after the command can enable all logs of trace and above. The logs are divided into trace, debug, info, warning, error from low to high.
make run : compile the system and perform virtual machine tests
make gdb : Execute debug mode (need to be used with gdb), start the virtual machine but not run
make clean : Clean up compiled projects (including user programs, systems and FAT images)