
ノースウェスタンポリテクニカル大学、「ナショナルカレッジ学生コンピューターシステム能力コンペティション - オペレーティングシステム設計競争(ナショナル) - OSカーネル実現トラックLoongson LA2K1000ポイントトラック」の最優秀賞(特別賞なし)エントリ。
チーム名ソース:影響力のあるnpucore、3つの感嘆符は3人のメンバーを表します。
連れ去られたキャプテン:[カーネルのデザインと適応/文書] Yixu Feng([email protected])
スーパープレーヤー:[デバッグエキスパート] Yifei Zhang([email protected])、[ハードウェアマスター] Hanchen Zhang([email protected])、[オフフィールドサポート] Huan Guo(個人ブログ)
Loongson TrackのOSコンペティションに参加したXi'an工科大学または他の学校の生徒に:この倉庫を見ると、適切な場所を見つけたことを意味します。これは、Npucore-Impactの最もオリジナルの倉庫であり、 NPUcore+LAに基づいたプラスバージョンです(後で新しいバージョンを再構築しましたが、この倉庫では見つけることができません)。このリポジトリのNPUcore-FFブランチは、初めてのフルスコア( fat32ファイルシステム)のブランチであり、 ext4ブランチはファイナルのext4ファイルシステムに適応した実験ブランチですが、 ext4ブランチはデバッグの最終バージョンではないため実行できないことに注意してください。
ファイナル(オンラインマッチ +セカンドステージ)の最終段階のコード決定は、ファイナルext4 15日前に多くの調整syscall行ったため、一般に公開されません。したがって、私たちはあなたの参照のためにこの元の倉庫を公開するだけです。ここに私の推奨リファレンスリンクは次のとおりです。
LAベースのアーチcrateのrustバージョンを使用する場合は、NPUCORE-LA2K1000-ARCHを参照してください。
予備競争のデバッグプロセスについて知りたい場合は、次を参照してください:LA予備競争テスト修復
ファイナルの第1フェーズで私たちが何をしたかを知りたい場合は、ファイナルフェーズ1ドキュメントを参照してください
NPUcore-IMPACT最終バージョンと他の人との差別化を知りたい場合は、参照してください:最終防衛を参照してください
ライブコンペティションで私たちが何をしたかを知りたい場合は、参照してください:ライブコンペティション
私たちが最終的にどのように防御したかを知りたい場合は、次のことを参照してください:最終ドラフト
logoを使用して変更する場合(AEの使用方法を学ぶ必要があります)、ロゴを参照してください。
デバッグ中に言及しなかったことの困難に遭遇した場合は、2024年2番目の賞:NPUCORE-REBIRTH:I AM CAIGOU、2022 FING PRIVE:RISCV ORIGINAL NPUCORE、2023 SECOND PRIZE NPUCORE+LAを参照してください。
NPUcore建設プロセスを学びたい場合は、NPUCORE-BOOKを参照してください
コードをbaselineとして使用したい場合は、(パートext4を含むNPUcore-重生之我是菜狗):npucore-lwext4を使用することをお勧めします。
Latexドキュメント形式とテンプレートを参照する場合は、NPUCORE-IMPACT-DOCを参照してください。
Loongsonリファレンスドキュメントをコンパイルしました:Baidu Netdisk:パスワード1145
競合テストの例:テストケースソースコード、テストケースバイナリファイル
私たちのQEMU環境:QEMU
QEMUを駆け抜けることは、本当の実行ではありません。 ( QEMUとボードの主な違いはアドレスマッピングです。問題がある場合は、この方向をご覧ください)ubootソースコードを2回読むことをお勧めします。ブラックボックスを調査しないでください。NPUcoreゼロから書くことができることを願っています。このバージョンがあなたのための参照としてのみ使用されることを願っています。NPUcore直接学習しないことが最善ですが、この実験を最初に実行します:xv6-loongarchNPUcore-IMPACTベースラインとして盲目的に使用すべきではないことをお勧めします。そのカップリングの程度は非常に高いです。私たちはそれを切り離すのに長い間役に立たなかった。NPUcore-IMPACTのFAT32バージョンをベースラインとして選択する場合は、すべてのドキュメントを参照してvfs最初に実装し、 fsとfat32を完全に分離し、次に新しいファイルシステム( EXT4がまだ主流である場合)とシステムコールの追加を検討してください。NPUcore-IMPACTには、まだ多くの機能的な欠点があります。来年ltpテストを実行する必要がある場合は、さらにシステムコールを追加する必要があります(今年は良いsyscallを取得する必要があると言われています。NPUcore2022主にcacheを最適化しますが、多くの機能的な問題にもつながります。後で多くの新しいバグがある場合は、必ずこれを考慮してください。必要に応じて、以前のハイライトを放棄できます。NPUcore-IMPACTについては、パフォーマンスを優先してください。パフォーマンスの最適化の余地はまだたくさんありますが、機能の欠陥は単一のポイントを獲得しないことにつながります。sudo apt-get install make
sudo apt-get install cmakeRustのコンピレーションチェーンをLoongarch用にインストールします
Rustup(Rustのインストーラー +バージョンマネージャー)をインストールする
rustup install nightly-2024-02-03 Rust ToolchainのインストールLoongarch Architectureの相互コンパイルが上流に統合されているため、現時点では手動でインストールする必要はありません。
Makefileには自動検出スクリプトがあり、後続のMakeコマンドのみが必要です。
相互コンパイルツールをインストールします。このプロジェクトは、x86_64の下でloongarch64を生成するコンパイルツールを使用します。 loong arch gcc 13:https://github.com/loongsonlab/oscomp-toolchains-for-oscernel
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 Codeコンピレーションの欠落にエラーがある場合は、 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多数のテスト結果を印刷した後、実行を終了します。
コマンドの後にログ=トレースを追加すると、トレース以上のすべてのログを有効にすることができることに注意してください。ログは、トレース、デバッグ、情報、警告、低から高へのエラーに分割されます。
make run :システムをコンパイルし、仮想マシンテストを実行するmake gdb :デバッグモードを実行し(GDBで使用する必要があります)、仮想マシンを起動しますが、実行しません
make clean :コンパイルされたプロジェクトをクリーンアップ(ユーザープログラム、システム、脂肪画像を含む)