Ver Fonte

Merge branch 'master' into feat-dynamic-link

longjin há 4 dias atrás
pai
commit
89b19ffd01
100 ficheiros alterados com 5524 adições e 782 exclusões
  1. 35 40
      .github/workflows/makefile.yml
  2. 22 0
      .github/workflows/sync-to-cnb.yml
  3. 1 1
      .gitignore
  4. 3 140
      .vscode/settings.json
  5. 7 0
      Makefile
  6. 504 0
      build-scripts/Cargo.lock
  7. 1 3
      build-scripts/Cargo.toml
  8. 3 2
      build-scripts/Makefile
  9. 6 0
      build-scripts/gen_kallsyms/Cargo.toml
  10. 122 0
      build-scripts/gen_kallsyms/src/main.rs
  11. 10 0
      build-scripts/kernel_build/src/bindgen/arch/loongarch64.rs
  12. 0 20
      build-scripts/kernel_build/src/bindgen/arch/mod.rs
  13. 0 10
      build-scripts/kernel_build/src/bindgen/arch/riscv64.rs
  14. 0 11
      build-scripts/kernel_build/src/bindgen/arch/x86_64.rs
  15. 0 50
      build-scripts/kernel_build/src/bindgen/mod.rs
  16. 29 0
      build-scripts/kernel_build/src/cfiles/arch/loongarch64.rs
  17. 3 3
      build-scripts/kernel_build/src/cfiles/arch/mod.rs
  18. 1 18
      build-scripts/kernel_build/src/cfiles/arch/riscv64.rs
  19. 3 23
      build-scripts/kernel_build/src/cfiles/arch/x86_64.rs
  20. 1 14
      build-scripts/kernel_build/src/cfiles/common.rs
  21. 3 3
      build-scripts/kernel_build/src/cfiles/mod.rs
  22. 3 0
      build-scripts/kernel_build/src/constant.rs
  23. 0 2
      build-scripts/kernel_build/src/lib.rs
  24. 2 0
      build-scripts/kernel_build/src/utils/cargo_handler.rs
  25. 2 0
      build-scripts/kernel_build/src/utils/mod.rs
  26. 1 1
      dadk-manifest.toml
  27. 1 7
      docs/community/contact/index.rst
  28. 3 0
      docs/introduction/build_system.md
  29. 0 80
      docs/kernel/core_api/kernel_api.md
  30. 2 0
      docs/kernel/debug/debug-kernel-with-gdb.md
  31. 1 0
      docs/kernel/process_management/kthread.md
  32. 1 0
      docs/kernel/sched/cfs.md
  33. 2 1
      env.mk
  34. 0 1
      kernel/.gitignore
  35. 2404 0
      kernel/Cargo.lock
  36. 38 20
      kernel/Cargo.toml
  37. 6 2
      kernel/Makefile
  38. 5 1
      kernel/crates/bitmap/src/alloc_bitmap.rs
  39. 21 15
      kernel/crates/bitmap/src/bitmap_core.rs
  40. 2 0
      kernel/crates/bitmap/src/lib.rs
  41. 2 2
      kernel/crates/intertrait/src/lib.rs
  42. 2 0
      kernel/crates/kprobe/src/arch/loongarch64/mod.rs
  43. 3 3
      kernel/crates/rbpf/src/interpreter.rs
  44. 6 6
      kernel/crates/rbpf/src/stack.rs
  45. 13 2
      kernel/crates/rust-slabmalloc/src/lib.rs
  46. 12 46
      kernel/crates/rust-slabmalloc/src/pages.rs
  47. 9 11
      kernel/crates/rust-slabmalloc/src/sc.rs
  48. 582 0
      kernel/crates/rust-slabmalloc/src/tests.rs
  49. 15 1
      kernel/crates/rust-slabmalloc/src/zone.rs
  50. 1 1
      kernel/crates/system_error/Cargo.toml
  51. 32 12
      kernel/crates/system_error/src/lib.rs
  52. 7 1
      kernel/env.mk
  53. 42 9
      kernel/src/Makefile
  54. 0 20
      kernel/src/arch/arch.h
  55. 14 0
      kernel/src/arch/loongarch64/asm/bitops.rs
  56. 98 0
      kernel/src/arch/loongarch64/asm/boot.rs
  57. 2 0
      kernel/src/arch/loongarch64/asm/mod.rs
  58. 15 0
      kernel/src/arch/loongarch64/cpu.rs
  59. 10 0
      kernel/src/arch/loongarch64/elf.rs
  60. 1 0
      kernel/src/arch/loongarch64/include/asm/asm.h
  61. 54 0
      kernel/src/arch/loongarch64/init/boot.rs
  62. 24 0
      kernel/src/arch/loongarch64/init/mod.rs
  63. 6 0
      kernel/src/arch/loongarch64/interrupt/ipi.rs
  64. 123 0
      kernel/src/arch/loongarch64/interrupt/mod.rs
  65. 1 0
      kernel/src/arch/loongarch64/ipc/mod.rs
  66. 64 0
      kernel/src/arch/loongarch64/ipc/signal.rs
  67. 19 0
      kernel/src/arch/loongarch64/kprobe.rs
  68. 114 0
      kernel/src/arch/loongarch64/link.ld
  69. 21 0
      kernel/src/arch/loongarch64/loongarch64-unknown-none.json
  70. 7 0
      kernel/src/arch/loongarch64/mm/bump.rs
  71. 207 0
      kernel/src/arch/loongarch64/mm/mod.rs
  72. 30 0
      kernel/src/arch/loongarch64/mod.rs
  73. 24 0
      kernel/src/arch/loongarch64/msi.rs
  74. 20 0
      kernel/src/arch/loongarch64/pci/mod.rs
  75. 35 0
      kernel/src/arch/loongarch64/pio.rs
  76. 31 0
      kernel/src/arch/loongarch64/process/idle.rs
  77. 27 0
      kernel/src/arch/loongarch64/process/kthread.rs
  78. 90 0
      kernel/src/arch/loongarch64/process/mod.rs
  79. 28 0
      kernel/src/arch/loongarch64/process/syscall.rs
  80. 5 0
      kernel/src/arch/loongarch64/rand.rs
  81. 17 0
      kernel/src/arch/loongarch64/sched.rs
  82. 29 0
      kernel/src/arch/loongarch64/smp/mod.rs
  83. 8 0
      kernel/src/arch/loongarch64/syscall/mod.rs
  84. 307 0
      kernel/src/arch/loongarch64/syscall/nr.rs
  85. 24 0
      kernel/src/arch/loongarch64/time.rs
  86. 5 0
      kernel/src/arch/mod.rs
  87. 25 1
      kernel/src/arch/riscv64/asm/head.S
  88. 0 20
      kernel/src/arch/riscv64/asm/irqflags.h
  89. 0 35
      kernel/src/arch/riscv64/asm/spinlock.c
  90. 0 63
      kernel/src/arch/riscv64/include/asm/asm.h
  91. 0 26
      kernel/src/arch/riscv64/include/asm/csr.h
  92. 0 14
      kernel/src/arch/riscv64/include/asm/irqflags.h
  93. 23 8
      kernel/src/arch/riscv64/interrupt/handle.rs
  94. 18 4
      kernel/src/arch/riscv64/ipc/signal.rs
  95. 10 0
      kernel/src/arch/riscv64/link.ld
  96. 9 0
      kernel/src/arch/riscv64/mod.rs
  97. 3 11
      kernel/src/arch/riscv64/rand.rs
  98. 2 10
      kernel/src/arch/riscv64/syscall/mod.rs
  99. 0 1
      kernel/src/arch/x86_64/asm/apu_boot.S
  100. 0 7
      kernel/src/arch/x86_64/asm/cmpxchg.c

+ 35 - 40
.github/workflows/makefile.yml

@@ -11,14 +11,14 @@ jobs:
     name: Format check ${{ matrix.arch }}
     runs-on: ubuntu-latest
     continue-on-error: true
-    container: dragonos/dragonos-dev:v1.7
+    container: dragonos/dragonos-dev:v1.11
 
     strategy:
       matrix:
-        arch: [x86_64, riscv64]
+        arch: [x86_64, riscv64, loongarch64]
 
     steps:
-      - run: echo "Running in dragonos/dragonos-dev:v1.7"
+      - run: echo "Running in dragonos/dragonos-dev:v1.11"
       - uses: actions/checkout@v3
 
       - name: Format check
@@ -35,14 +35,14 @@ jobs:
     name: Kernel static test ${{ matrix.arch }}
     runs-on: ubuntu-latest
     continue-on-error: true
-    container: dragonos/dragonos-dev:v1.7
+    container: dragonos/dragonos-dev:v1.11
 
     strategy:
       matrix:
-        arch: [x86_64, riscv64]
+        arch: [x86_64, riscv64, loongarch64]
 
     steps:
-      - run: echo "Running in dragonos/dragonos-dev:v1.7"
+      - run: echo "Running in dragonos/dragonos-dev:v1.11"
 
       - uses: actions/checkout@v3
 
@@ -53,46 +53,41 @@ jobs:
           HOME: /root
         run: bash -c "source /root/.cargo/env && cd kernel && make test && make test-rbpf"
 
-  build-x86_64:
+  build:
+    name: Build ${{ matrix.arch }}
     runs-on: ubuntu-latest
-    container: dragonos/dragonos-dev:v1.7
-
-    steps:
-      - run: echo "Running in dragonos/dragonos-dev:v1.7"
-
-      - uses: actions/checkout@v3
-      - name: build the DragonOS
-        env:
-          ARCH: x86_64
-          HOME: /root
-        shell: bash -ileo pipefail {0}
-
-        run: |
-          source ~/.bashrc
-          source ~/.cargo/env
-          export DragonOS_GCC=$HOME/opt/dragonos-gcc/gcc-x86_64-unknown-none/bin
-          sed -i 's/arch = ".*"/arch = "${{ env.ARCH }}"/' dadk-manifest.toml
-
-          make all -j $(nproc)
-
-  build-riscv64:
-    runs-on: ubuntu-latest
-    container: dragonos/dragonos-dev:v1.7
+    container: dragonos/dragonos-dev:v1.11
+    continue-on-error: true
+    strategy:
+      matrix:
+        include:
+          - arch: x86_64
+            make_target: all
+            checkout_params: {}
+          - arch: riscv64
+            make_target: all
+            checkout_params:
+              submodules: "recursive"
+          - arch: loongarch64
+            make_target: all
+            checkout_params: {}
 
     steps:
-      - run: echo "Running in dragonos/dragonos-dev:v1.7"
-
+      - run: echo "Running in dragonos/dragonos-dev:v1.11"
+      
       - uses: actions/checkout@v3
-        with:
-          submodules: "recursive"
+        with: ${{ matrix.checkout_params }}
 
-      - name: build the DragonOS
-        shell: bash -ileo pipefail {0}
+      - name: Build the DragonOS
         env:
-          ARCH: riscv64
+          ARCH: ${{ matrix.arch }}
           HOME: /root
-
+        shell: bash -ileo pipefail {0}
         run: |
-          source ~/.bashrc && source ~/.cargo/env
+          source $HOME/.bashrc
+          source $HOME/.cargo/env
+          if [[ "$ARCH" == "x86_64" ]]; then
+            export DragonOS_GCC=$HOME/opt/dragonos-gcc/gcc-x86_64-unknown-none/bin
+          fi
           sed -i 's/arch = ".*"/arch = "${{ env.ARCH }}"/' dadk-manifest.toml
-          make kernel -j $(nproc)
+          make ${{ matrix.make_target }} -j $(nproc)

+ 22 - 0
.github/workflows/sync-to-cnb.yml

@@ -0,0 +1,22 @@
+name: Sync to CNB.cool
+on: [push]
+
+jobs:
+  sync:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+        with:
+          fetch-depth: 0
+      
+      - name: Sync to CNB Repository
+        run: |
+          docker run --rm \
+            -v ${{ github.workspace }}:${{ github.workspace }} \
+            -w ${{ github.workspace }} \
+            -e PLUGIN_TARGET_URL="https://cnb.cool/DragonOS-Community/DragonOS.git" \
+            -e PLUGIN_AUTH_TYPE="https" \
+            -e PLUGIN_USERNAME="cnb" \
+            -e PLUGIN_PASSWORD=${{ secrets.CNB_GIT_PASSWORD }} \
+            -e PLUGIN_FORCE="true" \
+            tencentcom/git-sync

+ 1 - 1
.gitignore

@@ -16,7 +16,7 @@ docs/_build
 draft
 cppcheck.xml
 /target/
-Cargo.lock
 .cache
 compile_commands.json
 /logs/
+*.log

+ 3 - 140
.vscode/settings.json

@@ -1,157 +1,20 @@
 {
     "files.associations": {
-        "stdbool.h": "c",
-        "printk.h": "c",
-        "stdarg.h": "c",
-        "process.h": "c",
-        "cpu.h": "c",
-        "mm.h": "c",
-        "glib.h": "c",
         "asm.h": "c",
-        "memory.h": "c",
-        "kprint.h": "c",
-        "ptrace.h": "c",
-        "mouse.h": "c",
-        "algorithm": "c",
-        "array": "c",
-        "atomic": "c",
-        "*.tcc": "c",
-        "bitset": "c",
-        "cassert": "c",
-        "cctype": "c",
-        "cerrno": "c",
-        "chrono": "c",
-        "climits": "c",
-        "clocale": "c",
-        "cmath": "c",
-        "codecvt": "c",
-        "condition_variable": "c",
-        "cstdarg": "c",
-        "cstddef": "c",
-        "cstdint": "c",
-        "cstdio": "c",
-        "cstdlib": "c",
-        "cstring": "c",
-        "ctime": "c",
-        "cwchar": "c",
-        "cwctype": "c",
-        "deque": "c",
-        "exception": "c",
-        "forward_list": "c",
-        "functional": "c",
-        "iterator": "c",
-        "list": "c",
-        "map": "c",
-        "memory": "c",
-        "memory_resource": "c",
-        "numeric": "c",
-        "optional": "c",
-        "random": "c",
-        "ratio": "c",
-        "set": "c",
-        "string": "c",
-        "string_view": "c",
-        "system_error": "c",
-        "tuple": "c",
-        "type_traits": "c",
-        "unordered_map": "c",
-        "utility": "c",
-        "vector": "c",
-        "fstream": "c",
-        "initializer_list": "c",
-        "ios": "c",
-        "iosfwd": "c",
-        "istream": "c",
-        "limits": "c",
-        "locale": "c",
-        "mutex": "c",
-        "new": "c",
-        "ostream": "c",
-        "queue": "c",
-        "sstream": "c",
-        "stdexcept": "c",
-        "streambuf": "c",
-        "thread": "c",
-        "cinttypes": "c",
-        "cstdbool": "c",
-        "typeinfo": "c",
-        "unistd.h": "c",
-        "stdint.h": "c",
-        "syscall.h": "c",
-        "fcntl.h": "c",
-        "types.h": "c",
-        "string.h": "c",
-        "math.h": "c",
-        "arch.h": "c",
-        "stdio.h": "c",
-        "wait_queue.h": "c",
-        "stddef.h": "c",
-        "spinlock.h": "c",
-        "stat.h": "c",
-        "video.h": "c",
-        "ahci.h": "c",
-        "slab.h": "c",
-        "boot_info.h": "c",
-        "pci.h": "c",
-        "time.h": "c",
-        "errno.h": "c",
-        "bug.h": "c",
-        "sched.h": "c",
-        "preempt.h": "c",
-        "textui.h": "c",
-        "atomic.h": "c",
-        "semaphore.h": "c",
-        "mm-types.h": "c",
-        "current.h": "c",
-        "traceback.h": "c",
-        "bitcount.h": "c",
-        "limits.h": "c",
-        "mutex.h": "c",
-        "mount.h": "c",
-        "internal.h": "c",
-        "compiler_attributes.h": "c",
-        "timer.h": "c",
-        "hid.h": "c",
-        "compiler.h": "c",
-        "err.h": "c",
-        "list.h": "c",
-        "irqflags.h": "c",
-        "dirent.h": "c",
-        "cmd_help.h": "c",
-        "wait.h": "c",
-        "ctype.h": "c",
-        "stdint-gcc.h": "c",
-        "acpi.h": "c",
-        "assert.h": "c",
-        "sys_version.h": "c",
-        "cmd.h": "c",
-        "net.h": "c",
-        "cmd_test.h": "c",
-        "cmpxchg.h": "c",
-        "mman.h": "c",
-        "clocksource.h": "c",
-        "ata.h": "c",
-        "barrier": "c",
-        "charconv": "c",
-        "printf.h": "c",
-        "klog.h": "c",
-        "malloc.h": "c",
-        "*.o": "c",
-        "k_log.h": "c"
     },
     "C_Cpp.errorSquiggles": "enabled",
     "esbonio.sphinx.confDir": "",
     "rust-analyzer.checkOnSave.allTargets": false,
     "rust-analyzer.linkedProjects": [
         "./kernel/Cargo.toml",
-        "./tools/Cargo.toml",
-    
+        //"./tools/Cargo.toml",
     ],
+    // "rust-analyzer.cargo.target": "loongarch64-unknown-none",
     // "rust-analyzer.cargo.target": "riscv64gc-unknown-none-elf",
     "rust-analyzer.cargo.target": "x86_64-unknown-none",
     "rust-analyzer.check.overrideCommand": [
         "make",
         "check",
-        
     ],
+    "makefile.configureOnOpen": false,
 }

+ 7 - 0
Makefile

@@ -74,6 +74,8 @@ clean-docs:
 gdb:
 ifeq ($(ARCH), x86_64)
 	rust-gdb -n -x tools/.gdbinit
+else ifeq ($(ARCH), loongarch64)
+	loongarch64-unknown-linux-gnu-gdb -n -x tools/.gdbinit
 else
 	gdb-multiarch -n -x tools/.gdbinit
 endif
@@ -139,6 +141,11 @@ run-vnc: check_arch
 	$(MAKE) write_diskimage || exit 1
 	$(MAKE) qemu-vnc
 
+run-nographic: check_arch
+	$(MAKE) all -j $(NPROCS)
+	$(MAKE) write_diskimage || exit 1
+	$(MAKE) qemu-nographic
+
 # 在docker中编译,并启动QEMU
 run-docker: check_arch
 	@echo "使用docker构建并运行"

+ 504 - 0
build-scripts/Cargo.lock

@@ -0,0 +1,504 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "aho-corasick"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "bindgen"
+version = "0.61.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a022e58a142a46fea340d68012b9201c094e93ec3d033a944a24f8fd4a4f09a"
+dependencies = [
+ "bitflags 1.3.2",
+ "cexpr",
+ "clang-sys",
+ "lazy_static",
+ "lazycell",
+ "log",
+ "peeking_take_while",
+ "proc-macro2",
+ "quote",
+ "regex",
+ "rustc-hash",
+ "shlex",
+ "syn 1.0.109",
+ "which",
+]
+
+[[package]]
+name = "bitflags"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+
+[[package]]
+name = "bitflags"
+version = "2.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
+
+[[package]]
+name = "cc"
+version = "1.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292"
+dependencies = [
+ "jobserver",
+ "libc",
+]
+
+[[package]]
+name = "cexpr"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
+dependencies = [
+ "nom",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "clang-sys"
+version = "1.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
+dependencies = [
+ "glob",
+ "libc",
+ "libloading",
+]
+
+[[package]]
+name = "either"
+version = "1.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
+
+[[package]]
+name = "equivalent"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
+
+[[package]]
+name = "errno"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8"
+dependencies = [
+ "libc",
+ "windows-sys",
+]
+
+[[package]]
+name = "gen_kallsyms"
+version = "0.1.0"
+
+[[package]]
+name = "glob"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
+
+[[package]]
+name = "hashbrown"
+version = "0.14.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
+
+[[package]]
+name = "home"
+version = "0.5.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb"
+dependencies = [
+ "windows-sys",
+]
+
+[[package]]
+name = "indexmap"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5"
+dependencies = [
+ "equivalent",
+ "hashbrown",
+]
+
+[[package]]
+name = "jobserver"
+version = "0.1.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "kernel_build"
+version = "0.1.0"
+dependencies = [
+ "bindgen",
+ "cc",
+ "lazy_static",
+ "toml",
+]
+
+[[package]]
+name = "lazy_static"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+
+[[package]]
+name = "lazycell"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
+
+[[package]]
+name = "libc"
+version = "0.2.150"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
+
+[[package]]
+name = "libloading"
+version = "0.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
+dependencies = [
+ "cfg-if",
+ "winapi",
+]
+
+[[package]]
+name = "linux-raw-sys"
+version = "0.4.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829"
+
+[[package]]
+name = "log"
+version = "0.4.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
+
+[[package]]
+name = "memchr"
+version = "2.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
+
+[[package]]
+name = "minimal-lexical"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
+
+[[package]]
+name = "nom"
+version = "7.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
+dependencies = [
+ "memchr",
+ "minimal-lexical",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.18.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
+
+[[package]]
+name = "peeking_take_while"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "regex"
+version = "1.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-automata",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-automata"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
+
+[[package]]
+name = "rustc-hash"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
+
+[[package]]
+name = "rustix"
+version = "0.38.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ad981d6c340a49cdc40a1028d9c6084ec7e9fa33fcb839cab656a267071e234"
+dependencies = [
+ "bitflags 2.4.1",
+ "errno",
+ "libc",
+ "linux-raw-sys",
+ "windows-sys",
+]
+
+[[package]]
+name = "serde"
+version = "1.0.193"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.193"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.43",
+]
+
+[[package]]
+name = "serde_spanned"
+version = "0.6.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "shlex"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
+
+[[package]]
+name = "syn"
+version = "1.0.109"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.43"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "toml"
+version = "0.8.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e"
+dependencies = [
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_edit",
+]
+
+[[package]]
+name = "toml_datetime"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "toml_edit"
+version = "0.22.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d"
+dependencies = [
+ "indexmap",
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "winnow",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
+
+[[package]]
+name = "which"
+version = "4.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
+dependencies = [
+ "either",
+ "home",
+ "once_cell",
+ "rustix",
+]
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
+[[package]]
+name = "windows-sys"
+version = "0.48.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
+dependencies = [
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
+]
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
+
+[[package]]
+name = "winnow"
+version = "0.6.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f"
+dependencies = [
+ "memchr",
+]

+ 1 - 3
build-scripts/Cargo.toml

@@ -1,5 +1,3 @@
 [workspace]
-members = [
-    "kernel_build",
-]
+members = ["gen_kallsyms", "kernel_build"]
 resolver = "2"

+ 3 - 2
build-scripts/Makefile

@@ -1,8 +1,9 @@
-.PHONY: fmt
+all:
+	@cargo +nightly-2024-11-05 build --release -p gen_kallsyms
 fmt:
 	cargo fmt --all $(FMT_CHECK)
-
 clean:
 	@cargo clean
 check:
 	@cargo +nightly-2024-11-05 check --workspace $(CARGO_ZBUILD) --message-format=json
+.PHONY: fmt

+ 6 - 0
build-scripts/gen_kallsyms/Cargo.toml

@@ -0,0 +1,6 @@
+[package]
+name = "gen_kallsyms"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]

+ 122 - 0
build-scripts/gen_kallsyms/src/main.rs

@@ -0,0 +1,122 @@
+use std::str;
+
+#[derive(Debug, Clone)]
+struct KernelSymbolEntry {
+    vaddr: u64,
+    #[allow(dead_code)]
+    symbol_type: char,
+    symbol: String,
+    symbol_length: usize,
+}
+
+fn symbol_to_write(vaddr: u64, text_vaddr: u64, etext_vaddr: u64) -> bool {
+    vaddr >= text_vaddr && vaddr <= etext_vaddr
+}
+fn read_symbol(line: &str) -> Option<KernelSymbolEntry> {
+    if line.len() > 512 {
+        return None;
+    } // skip line with length >= 512
+    let mut parts = line.split_whitespace();
+    let vaddr = u64::from_str_radix(parts.next()?, 16).ok()?;
+    let symbol_type = parts.next()?.chars().next()?;
+    let symbol = parts.collect::<Vec<_>>().join(" ");
+    if symbol_type != 'T' && symbol_type != 't' {
+        return None;
+    } // local symbol or global symbol in text section
+    if symbol == "$x" {
+        return None;
+    } // skip $x symbol
+    let symbol_length = symbol.len() + 1; // +1 for null terminator
+    Some(KernelSymbolEntry {
+        vaddr,
+        symbol_type,
+        symbol,
+        symbol_length,
+    })
+}
+
+fn read_map() -> (Vec<KernelSymbolEntry>, u64, u64) {
+    let mut symbol_table = Vec::new();
+    let mut text_vaddr = 0;
+    let mut etext_vaddr = 0;
+    let mut line = String::new();
+    loop {
+        let size = std::io::stdin().read_line(&mut line).unwrap();
+        if size == 0 {
+            break;
+        }
+        line = line.trim().to_string();
+        if let Some(entry) = read_symbol(&line) {
+            if entry.symbol.starts_with("_text") {
+                text_vaddr = entry.vaddr;
+            } else if entry.symbol.starts_with("_etext") {
+                etext_vaddr = entry.vaddr;
+            }
+            symbol_table.push(entry);
+        }
+        line.clear();
+    }
+    (symbol_table, text_vaddr, etext_vaddr)
+}
+
+fn generate_result(symbol_table: &[KernelSymbolEntry], text_vaddr: u64, etext_vaddr: u64) {
+    println!(".section .rodata\n");
+    println!(".global kallsyms_address");
+    println!(".align 8\n");
+    println!("kallsyms_address:");
+
+    let mut last_vaddr = 0;
+    let mut total_syms_to_write = 0;
+
+    for entry in symbol_table {
+        if !symbol_to_write(entry.vaddr, text_vaddr, etext_vaddr) || entry.vaddr == last_vaddr {
+            continue;
+        }
+
+        println!("\t.quad\t{:#x}", entry.vaddr);
+        total_syms_to_write += 1;
+        last_vaddr = entry.vaddr;
+    }
+
+    println!("\n.global kallsyms_num");
+    println!(".align 8");
+    println!("kallsyms_num:");
+    println!("\t.quad\t{}", total_syms_to_write);
+
+    println!("\n.global kallsyms_names_index");
+    println!(".align 8");
+    println!("kallsyms_names_index:");
+
+    let mut position = 0;
+    last_vaddr = 0;
+
+    for entry in symbol_table {
+        if !symbol_to_write(entry.vaddr, text_vaddr, etext_vaddr) || entry.vaddr == last_vaddr {
+            continue;
+        }
+
+        println!("\t.quad\t{}", position);
+        position += entry.symbol_length;
+        last_vaddr = entry.vaddr;
+    }
+
+    println!("\n.global kallsyms_names");
+    println!(".align 8");
+    println!("kallsyms_names:");
+
+    last_vaddr = 0;
+
+    for entry in symbol_table {
+        if !symbol_to_write(entry.vaddr, text_vaddr, etext_vaddr) || entry.vaddr == last_vaddr {
+            continue;
+        }
+
+        println!("\t.asciz\t\"{}\"", entry.symbol);
+        last_vaddr = entry.vaddr;
+    }
+}
+
+fn main() {
+    let (symbol_table, text_vaddr, etext_vaddr) = read_map();
+    generate_result(&symbol_table, text_vaddr, etext_vaddr);
+}

+ 10 - 0
build-scripts/kernel_build/src/bindgen/arch/loongarch64.rs

@@ -0,0 +1,10 @@
+use super::BindgenArch;
+
+pub struct LoongArch64BindgenArch;
+impl BindgenArch for LoongArch64BindgenArch {
+    fn generate_bindings(&self, builder: bindgen::Builder) -> bindgen::Builder {
+        builder
+            .clang_arg("-I./src/arch/loongarch64/include")
+            .clang_arg("--target=x86_64-none-none") // 由于clang不支持loongarch64,所以使用x86_64作为目标,按理来说问题不大
+    }
+}

+ 0 - 20
build-scripts/kernel_build/src/bindgen/arch/mod.rs

@@ -1,20 +0,0 @@
-use crate::utils::cargo_handler::{CargoHandler, TargetArch};
-
-use self::x86_64::X86_64BindgenArch;
-
-pub mod riscv64;
-pub mod x86_64;
-
-pub(super) trait BindgenArch {
-    fn generate_bindings(&self, builder: bindgen::Builder) -> bindgen::Builder;
-}
-
-/// 获取当前的bindgen架构;
-pub(super) fn current_bindgenarch() -> &'static dyn BindgenArch {
-    let arch = CargoHandler::target_arch();
-    match arch {
-        TargetArch::X86_64 => &X86_64BindgenArch,
-        TargetArch::Riscv64 => &riscv64::RiscV64BindgenArch,
-        _ => panic!("Unsupported arch: {:?}", arch),
-    }
-}

+ 0 - 10
build-scripts/kernel_build/src/bindgen/arch/riscv64.rs

@@ -1,10 +0,0 @@
-use super::BindgenArch;
-
-pub struct RiscV64BindgenArch;
-impl BindgenArch for RiscV64BindgenArch {
-    fn generate_bindings(&self, builder: bindgen::Builder) -> bindgen::Builder {
-        builder
-            .clang_arg("-I./src/arch/riscv64/include")
-            .clang_arg("--target=riscv64-none-none-elf")
-    }
-}

+ 0 - 11
build-scripts/kernel_build/src/bindgen/arch/x86_64.rs

@@ -1,11 +0,0 @@
-use super::BindgenArch;
-
-pub struct X86_64BindgenArch;
-
-impl BindgenArch for X86_64BindgenArch {
-    fn generate_bindings(&self, builder: bindgen::Builder) -> bindgen::Builder {
-        builder
-            .clang_arg("-I./src/arch/x86_64/include")
-            .clang_arg("--target=x86_64-none-none")
-    }
-}

+ 0 - 50
build-scripts/kernel_build/src/bindgen/mod.rs

@@ -1,50 +0,0 @@
-use std::{path::PathBuf, str::FromStr};
-
-use crate::{bindgen::arch::current_bindgenarch, utils::cargo_handler::CargoHandler};
-
-mod arch;
-
-/// 生成 C->Rust bindings
-pub fn generate_bindings() {
-    let wrapper_h = PathBuf::from_str("src/include/bindings/wrapper.h")
-        .expect("Failed to parse 'wrapper.h' path");
-    CargoHandler::emit_rerun_if_files_changed(&[wrapper_h.clone()]);
-
-    let out_path = PathBuf::from(String::from("src/include/bindings/"));
-
-    // The bindgen::Builder is the main entry point
-    // to bindgen, and lets you build up options for
-    // the resulting bindings.
-
-    let builder = bindgen::Builder::default()
-        .clang_arg("-I./src")
-        .clang_arg("-I./src/include")
-        // The input header we would like to generate
-        // bindings for.
-        .header(wrapper_h.to_str().unwrap())
-        .blocklist_file("src/include/bindings/bindings.h")
-        .clang_arg("-v")
-        // 使用core,并将c语言的类型改为core::ffi,而不是使用std库。
-        .use_core()
-        .ctypes_prefix("::core::ffi")
-        .generate_inline_functions(true)
-        .raw_line("#![allow(dead_code)]")
-        .raw_line("#![allow(non_upper_case_globals)]")
-        .raw_line("#![allow(non_camel_case_types)]")
-        // Tell cargo to invalidate the built crate whenever any of the
-        // included header files changed.
-        .parse_callbacks(Box::new(bindgen::CargoCallbacks));
-
-    // 处理架构相关的绑定
-    let builder = current_bindgenarch().generate_bindings(builder);
-
-    // Finish the builder and generate the bindings.
-    let bindings = builder
-        .generate()
-        // Unwrap the Result and panic on failure.
-        .expect("Unable to generate bindings");
-
-    bindings
-        .write_to_file(out_path.join("bindings.rs"))
-        .expect("Couldn't write bindings!");
-}

+ 29 - 0
build-scripts/kernel_build/src/cfiles/arch/loongarch64.rs

@@ -0,0 +1,29 @@
+use std::{collections::HashSet, path::PathBuf};
+
+use crate::constant::ARCH_DIR_LOONGARCH64;
+
+use super::CFilesArch;
+
+pub(super) struct LoongArch64CFilesArch;
+
+impl CFilesArch for LoongArch64CFilesArch {
+    fn setup_defines(&self, c: &mut cc::Build) {
+        c.define("__loongarch64__", None);
+        c.define("__loongarch", None);
+    }
+
+    fn setup_files(&self, _c: &mut cc::Build, _files: &mut HashSet<PathBuf>) {}
+
+    fn setup_global_flags(&self, c: &mut cc::Build) {
+        // 在这里设置编译器,不然的话vscode的rust-analyzer会报错
+        c.compiler("loongarch64-unknown-linux-gnu-gcc");
+        c.flag("-mcmodel=normal");
+
+        c.flag("-march=loongarch64");
+    }
+}
+
+#[allow(dead_code)]
+fn arch_path(relative_path: &str) -> PathBuf {
+    PathBuf::from(format!("{}/{}", ARCH_DIR_LOONGARCH64, relative_path))
+}

+ 3 - 3
build-scripts/kernel_build/src/cfiles/arch/mod.rs

@@ -6,17 +6,15 @@ use crate::utils::cargo_handler::{CargoHandler, TargetArch};
 
 use self::x86_64::X86_64CFilesArch;
 
+pub mod loongarch64;
 pub mod riscv64;
 pub mod x86_64;
 
 pub(super) trait CFilesArch {
     /// 设置架构相关的宏定义
     fn setup_defines(&self, c: &mut Build);
-    /// 设置架构相关的全局包含目录
-    fn setup_global_include_dir(&self, c: &mut HashSet<PathBuf>);
     /// 设置需要编译的架构相关的文件
     fn setup_files(&self, c: &mut Build, files: &mut HashSet<PathBuf>);
-
     /// 设置架构相关的全局编译标志
     fn setup_global_flags(&self, c: &mut Build);
 }
@@ -27,6 +25,8 @@ pub(super) fn current_cfiles_arch() -> &'static dyn CFilesArch {
     match arch {
         TargetArch::X86_64 => &X86_64CFilesArch,
         TargetArch::Riscv64 => &riscv64::RiscV64CFilesArch,
+        TargetArch::LoongArch64 => &loongarch64::LoongArch64CFilesArch,
+
         _ => panic!("Unsupported arch: {:?}", arch),
     }
 }

+ 1 - 18
build-scripts/kernel_build/src/cfiles/arch/riscv64.rs

@@ -1,8 +1,5 @@
-use std::{collections::HashSet, path::PathBuf};
-
-use crate::{constant::ARCH_DIR_RISCV64, utils::FileUtils};
-
 use super::CFilesArch;
+use std::{collections::HashSet, path::PathBuf};
 
 pub(super) struct RiscV64CFilesArch;
 
@@ -12,18 +9,8 @@ impl CFilesArch for RiscV64CFilesArch {
         c.define("__riscv", None);
     }
 
-    fn setup_global_include_dir(&self, include_dirs: &mut HashSet<PathBuf>) {
-        include_dirs.insert("src/arch/riscv64/include".into());
-    }
-
     fn setup_files(&self, _c: &mut cc::Build, files: &mut HashSet<PathBuf>) {
         files.insert(PathBuf::from("src/arch/riscv64/asm/head.S"));
-
-        FileUtils::list_all_files(&arch_path("asm"), Some("c"), true)
-            .into_iter()
-            .for_each(|f| {
-                files.insert(f);
-            });
     }
 
     fn setup_global_flags(&self, c: &mut cc::Build) {
@@ -37,7 +24,3 @@ impl CFilesArch for RiscV64CFilesArch {
         c.flag("-march=rv64gc");
     }
 }
-
-fn arch_path(relative_path: &str) -> PathBuf {
-    PathBuf::from(format!("{}/{}", ARCH_DIR_RISCV64, relative_path))
-}

+ 3 - 23
build-scripts/kernel_build/src/cfiles/arch/x86_64.rs

@@ -1,10 +1,6 @@
-use std::{collections::HashSet, path::PathBuf};
-
-use cc::Build;
-
-use crate::{constant::ARCH_DIR_X86_64, utils::FileUtils};
-
 use super::CFilesArch;
+use cc::Build;
+use std::{collections::HashSet, path::PathBuf};
 
 pub(super) struct X86_64CFilesArch;
 
@@ -13,24 +9,12 @@ impl CFilesArch for X86_64CFilesArch {
         c.define("__x86_64__", None);
     }
 
-    fn setup_global_include_dir(&self, include_dirs: &mut HashSet<PathBuf>) {
-        include_dirs.insert("src/arch/x86_64/include".into());
-    }
-
     fn setup_files(&self, _c: &mut Build, files: &mut HashSet<PathBuf>) {
-        const DIRS: [&str; 4] = ["driver/apic", "init", "asm", "interrupt"];
-        DIRS.iter().for_each(|dir| {
-            FileUtils::list_all_files(&arch_path(dir), Some("c"), true)
-                .into_iter()
-                .for_each(|f| {
-                    files.insert(f);
-                });
-        });
-
         // setup asm files
         files.insert(PathBuf::from("src/arch/x86_64/asm/head.S"));
         files.insert(PathBuf::from("src/arch/x86_64/asm/entry.S"));
         files.insert(PathBuf::from("src/arch/x86_64/asm/apu_boot.S"));
+        files.insert(PathBuf::from("src/arch/x86_64/vm/vmx/vmenter.S"));
     }
 
     fn setup_global_flags(&self, c: &mut Build) {
@@ -38,7 +22,3 @@ impl CFilesArch for X86_64CFilesArch {
         c.flag("-mcmodel=large").flag("-m64");
     }
 }
-
-fn arch_path(relative_path: &str) -> PathBuf {
-    PathBuf::from(format!("{}/{}", ARCH_DIR_X86_64, relative_path))
-}

+ 1 - 14
build-scripts/kernel_build/src/cfiles/common.rs

@@ -1,20 +1,7 @@
 use std::{collections::HashSet, path::PathBuf};
 
-use crate::utils::FileUtils;
-
-pub(super) fn setup_common_files(files: &mut HashSet<PathBuf>) {
-    const DIRS: [&str; 3] = ["src/common", "src/debug/traceback", "src/libs"];
-    DIRS.iter().for_each(|dir| {
-        FileUtils::list_all_files(&dir.into(), Some("c"), true)
-            .into_iter()
-            .for_each(|f| {
-                files.insert(f);
-            });
-    });
-}
-
 pub(super) fn setup_common_include_dir(include_dirs: &mut HashSet<PathBuf>) {
-    const DIRS: [&str; 3] = ["src/include", "src/common", "src"];
+    const DIRS: [&str; 2] = ["src/common", "src"];
     DIRS.iter().for_each(|dir| {
         include_dirs.insert(dir.into());
     });

+ 3 - 3
build-scripts/kernel_build/src/cfiles/mod.rs

@@ -20,6 +20,9 @@ impl CFilesBuilder {
         Self::setup_defines(&mut c);
         Self::setup_global_include_dir(&mut c);
         Self::setup_files(&mut c);
+        if c.get_files().count() == 0 {
+            return;
+        }
         c.compile("dragonos_kernel_cfiles");
     }
 
@@ -53,8 +56,6 @@ impl CFilesBuilder {
 
         common::setup_common_include_dir(&mut include_dirs);
 
-        current_cfiles_arch().setup_global_include_dir(&mut include_dirs);
-
         let include_dirs: Vec<PathBuf> = include_dirs.into_iter().collect();
         Self::set_rerun_if_files_changed(&include_dirs);
 
@@ -67,7 +68,6 @@ impl CFilesBuilder {
     fn setup_files(c: &mut Build) {
         let mut files: HashSet<PathBuf> = HashSet::new();
         current_cfiles_arch().setup_files(c, &mut files);
-        common::setup_common_files(&mut files);
         // 去重
         let files: Vec<PathBuf> = files.into_iter().collect();
         Self::set_rerun_if_files_changed(&files);

+ 3 - 0
build-scripts/kernel_build/src/constant/mod.rs → build-scripts/kernel_build/src/constant.rs

@@ -1,2 +1,5 @@
+#[allow(dead_code)]
 pub const ARCH_DIR_X86_64: &str = "src/arch/x86_64";
+#[allow(dead_code)]
 pub const ARCH_DIR_RISCV64: &str = "src/arch/riscv64";
+pub const ARCH_DIR_LOONGARCH64: &str = "src/arch/loongarch64";

+ 0 - 2
build-scripts/kernel_build/src/lib.rs

@@ -2,7 +2,6 @@
 extern crate lazy_static;
 extern crate cc;
 
-mod bindgen;
 mod cfiles;
 mod constant;
 mod kconfig;
@@ -12,7 +11,6 @@ mod utils;
 pub fn run() {
     println!("cargo:rustc-link-search=src");
 
-    crate::bindgen::generate_bindings();
     crate::cfiles::CFilesBuilder::build();
     crate::kconfig::KConfigBuilder::build();
 }

+ 2 - 0
build-scripts/kernel_build/src/utils/cargo_handler.rs

@@ -68,6 +68,7 @@ pub enum TargetArch {
     Riscv64,
     Mips64,
     Powerpc64,
+    LoongArch64,
     S390x,
     Sparc64,
     Unknown,
@@ -85,6 +86,7 @@ impl TargetArch {
             "riscv64" => TargetArch::Riscv64,
             "mips64" => TargetArch::Mips64,
             "powerpc64" => TargetArch::Powerpc64,
+            "loongarch64" => TargetArch::LoongArch64,
             "s390x" => TargetArch::S390x,
             "sparc64" => TargetArch::Sparc64,
             _ => TargetArch::Unknown,

+ 2 - 0
build-scripts/kernel_build/src/utils/mod.rs

@@ -2,8 +2,10 @@ use std::path::PathBuf;
 
 pub mod cargo_handler;
 
+#[allow(dead_code)]
 pub struct FileUtils;
 
+#[allow(dead_code)]
 impl FileUtils {
     /// 列出指定目录下的所有文件
     ///

+ 1 - 1
dadk-manifest.toml

@@ -1,7 +1,7 @@
 # DADK 总控文件
 
 [metadata]
-# Target architecture. Options: x86_64, riscv64
+# Target architecture. Options: x86_64, riscv64, loongarch64
 arch = "x86_64"
 
 # Hypervisor config path

+ 1 - 7
docs/community/contact/index.rst

@@ -30,10 +30,4 @@ DragonOS是一个开源项目,我们欢迎任何形式的赞助和捐赠,您
 财务及捐赠信息公开
 -------------------------
 
-DragonOS社区的捐赠信息将按年进行公开。赞助商、赞助者信息将在收到赞助后,15天内进行公开。
-
-社区管理、财务及法务主体
--------------------------
-
-灵高是DragonOS社区为满足相关监管合规要求,成立的 **非营利性质** 的单位。详情请见:https://ringotek.com.cn
-
+DragonOS社区的捐赠信息将按年进行公开。赞助商、赞助者信息将在收到赞助后,15天内进行公开。

+ 3 - 0
docs/introduction/build_system.md

@@ -215,6 +215,7 @@ make run-docker
 ### 5.1 创建磁盘镜像
 
 &emsp;&emsp;首先,您需要使用**普通用户**权限运行`tools/create_hdd_image.sh`,为DragonOS创建一块磁盘镜像文件。该脚本会自动完成创建磁盘镜像的工作,并将其移动到`bin/`目录下。
+
 &emsp;&emsp;请注意,由于权限问题,请务必使用**普通用户**权限运行此脚本。(运行后,需要提升权限时,系统可能会要求您输入密码)
 
 
@@ -239,6 +240,8 @@ make run-docker
 - 本地编译,不运行: `make all -j 您的CPU核心数`
 - 本地编译,并写入磁盘镜像,不运行: `make build`
 - 本地编译,写入磁盘镜像,并在QEMU中运行: `make run`
+- 本地编译,写入磁盘镜像,以无图形模式运行: 
+`make run-nographic`
 - Docker编译,并写入磁盘镜像,: `make docker`
 - Docker编译,写入磁盘镜像,并在QEMU中运行: `make run-docker`
 - 不编译,直接从已有的磁盘镜像启动: `make qemu`

+ 0 - 80
docs/kernel/core_api/kernel_api.md

@@ -572,86 +572,6 @@
 
 &emsp;&emsp;第二个字符串
 
-#### `printk(const char* fmt, ...)`
-
-##### 描述
-
-&emsp;&emsp;该宏能够在控制台上以黑底白字格式化输出字符串.
-
-##### 参数
-
-**fmt**
-
-&emsp;&emsp;源格式字符串
-
-**...**
-
-&emsp;&emsp;可变参数
-
-#### `printk_color(unsigned int FRcolor, unsigned int BKcolor, const char* fmt, ...)`
-
-##### 描述
-
-&emsp;&emsp;在控制台上以指定前景色和背景色格式化输出字符串.
-
-##### 参数
-
-**FRcolor**
-
-&emsp;&emsp;前景色
-
-**BKcolor**
-
-&emsp;&emsp;背景色
-
-**fmt**
-
-&emsp;&emsp;源格式字符串
-
-**...**
-
-&emsp;&emsp;可变参数
-
-#### `int vsprintf(char *buf, const char *fmt, va_list args)`
-
-##### 描述
-
-&emsp;&emsp;按照fmt格式化字符串,并将结果输出到buf中,返回写入buf的字符数量。
-
-##### 参数
-
-**buf**
-
-&emsp;&emsp;输出缓冲区
-
-**fmt**
-
-&emsp;&emsp;源格式字符串
-
-**args**
-
-&emsp;&emsp;可变参数列表
-
-#### `int sprintk(char *buf, const char *fmt, ...)`
-
-##### 描述
-
-&emsp;&emsp;按照fmt格式化字符串,并将结果输出到buf中,返回写入buf的字符数量。
-
-##### 参数
-
-**buf**
-
-&emsp;&emsp;输出缓冲区
-
-**fmt**
-
-&emsp;&emsp;源格式字符串
-
-**...**
-
-&emsp;&emsp;可变参数
-
 ### 内存操作
 
 #### `void *memcpy(void *dst, const void *src, uint64_t size)`

+ 2 - 0
docs/kernel/debug/debug-kernel-with-gdb.md

@@ -3,6 +3,7 @@
 
 ## 前言
 &emsp;&emsp;GDB是一个功能强大的开源调试工具,能够帮助您更好的诊断和修复程序中的错误。
+
 &emsp;&emsp;它提供了一套丰富的功能,使您能够检查程序的执行状态、跟踪代码的执行流程、查看和修改变量的值、分析内存状态等。它可以与编译器配合使用,以便您在调试过程中访问程序的调试信息。
 
 &emsp;&emsp;此教程将告诉您如何在DragonOS中使用`rust-gdb`来调试内核,包括如何开始调试以及相应的调试命令。
@@ -29,6 +30,7 @@ debug = true
 ### 1.2 运行DragonOS
 
 &emsp;&emsp;准备工作完成后,您就可以编译、运行DragonOS来开展后续的调试工作了。
+
 &emsp;&emsp;在DragonOS根目录中开启终端,使用`make run`即可开始编译运行DragonOS,如需更多编译命令方面的帮助,详见
 > [构建DragonOS](https://docs.dragonos.org/zh_CN/latest/introduction/build_system.html)。
 

+ 1 - 0
docs/kernel/process_management/kthread.md

@@ -9,6 +9,7 @@
 &emsp;&emsp;内核线程的创建是通过调用`KernelThreadMechanism::create()`或者`KernelThreadMechanism::create_and_run()`函数,向`kthreadd`守护线程发送创建任务来实现的。也就是说,内核线程的创建,最终是由`kthread_daemon`来完成。
 
 &emsp;&emsp;当内核线程被创建后,默认处于睡眠状态,要使用`ProcessManager::wakeup`函数将其唤醒。
+
 &emsp;&emsp;当内核其他模块想要停止一个内核线程的时候,可以调用`KernelThreadMechanism::stop()`函数,等待内核线程的退出,然后获得返回值并清理内核线程的pcb。
 
 &emsp;&emsp;内核线程应当经常检查`KernelThreadMechanism::should_stop()`的结果,以确定其是否要退出。当检测到需要退出时,内核线程返回一个返回码,即可退出。(注意资源的清理)

+ 1 - 0
docs/kernel/sched/cfs.md

@@ -16,6 +16,7 @@
 &emsp;&emsp;``FairSchedEntity``是完全公平调度器中最重要的结构体,他代表一个实体单位,它不止表示一个进程,它还可以是一个组或者一个用户,但是它在cfs队列中所表示的就单单是一个调度实体。这样的设计可以为上层提供更多的思路,比如上层可以把不同的进程归纳到一个调度实体从而实现组调度等功能而不需要改变调度算法。
 
 &emsp;&emsp;在cfs中,整体的结构是**一棵树**,每一个调度实体作为``cfs_rq``中的一个节点,若该调度实体不是单个进程(它可能是一个进程组),则在该调度实体中还需要维护一个自己的``cfs_rq``,这样的嵌套展开后,每一个叶子节点就是一个单独的进程。需要理解这样一棵树,**在后续文档中会以这棵树为核心讲解**。
+
 &emsp;&emsp;该结构体具体的字段意义请查阅源代码。这里提及几个重要的字段:
 
 

+ 2 - 1
env.mk

@@ -1,6 +1,7 @@
 
 ifeq ($(ARCH), )
-# !!!!在这里设置ARCH,可选 x86_64 和 riscv64
+# !!!!在这里设置ARCH,可选:
+# x86_64, riscv64, loongarch64
 # !!!!!!!如果不同时调整这里以及vscode的settings.json,那么自动补全和检查将会失效
 export ARCH?=x86_64
 endif

+ 0 - 1
kernel/.gitignore

@@ -1,6 +1,5 @@
 target/
 src/kernel
-Cargo.lock
 D.config
 
 # 将自动生成的C-Rust FFI加到gitignore

+ 2404 - 0
kernel/Cargo.lock

@@ -0,0 +1,2404 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "acpi"
+version = "5.0.0"
+source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/acpi-rs.git?rev=282df2af7b#282df2af7b9edee629af391005c2a6b89e73f88c"
+dependencies = [
+ "bit_field",
+ "bitflags 2.9.0",
+ "log",
+]
+
+[[package]]
+name = "ahash"
+version = "0.8.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
+dependencies = [
+ "cfg-if",
+ "once_cell",
+ "version_check",
+ "zerocopy 0.7.35",
+]
+
+[[package]]
+name = "aho-corasick"
+version = "1.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "allocator-api2"
+version = "0.2.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
+
+[[package]]
+name = "anyhow"
+version = "1.0.97"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
+
+[[package]]
+name = "arbitrary"
+version = "1.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223"
+
+[[package]]
+name = "asm_macros"
+version = "0.1.0"
+
+[[package]]
+name = "atomic_enum"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6227a8d6fdb862bcb100c4314d0d9579e5cd73fa6df31a2e6f6e1acd3c5f1207"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi",
+]
+
+[[package]]
+name = "autocfg"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
+
+[[package]]
+name = "base-x"
+version = "0.2.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270"
+
+[[package]]
+name = "bindgen"
+version = "0.61.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a022e58a142a46fea340d68012b9201c094e93ec3d033a944a24f8fd4a4f09a"
+dependencies = [
+ "bitflags 1.3.2",
+ "cexpr",
+ "clang-sys",
+ "lazy_static",
+ "lazycell",
+ "log",
+ "peeking_take_while",
+ "proc-macro2",
+ "quote",
+ "regex",
+ "rustc-hash",
+ "shlex",
+ "syn 1.0.109",
+ "which",
+]
+
+[[package]]
+name = "bit_field"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
+
+[[package]]
+name = "bitfield-struct"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a176f34515e3ff0b2ddb47cdbe48ccf21772381fe364d1ad68ed04b9c5fb63a8"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "bitflags"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+
+[[package]]
+name = "bitflags"
+version = "2.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
+
+[[package]]
+name = "bitmap"
+version = "0.1.0"
+
+[[package]]
+name = "bumpalo"
+version = "3.17.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
+
+[[package]]
+name = "byteorder"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
+
+[[package]]
+name = "byteorder"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
+
+[[package]]
+name = "bytes"
+version = "1.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
+
+[[package]]
+name = "cc"
+version = "1.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a"
+dependencies = [
+ "jobserver",
+ "libc",
+ "shlex",
+]
+
+[[package]]
+name = "cexpr"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
+dependencies = [
+ "nom",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "clang-sys"
+version = "1.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
+dependencies = [
+ "glob",
+ "libc",
+ "libloading",
+]
+
+[[package]]
+name = "clear-cache"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fe05a1a3c09033e9e87f7ba13af35cf2508148d3a97fb6b16475df84207993fa"
+dependencies = [
+ "libc",
+ "windows 0.58.0",
+]
+
+[[package]]
+name = "combine"
+version = "4.6.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd"
+dependencies = [
+ "bytes",
+ "memchr",
+]
+
+[[package]]
+name = "const_fn"
+version = "0.4.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2f8a2ca5ac02d09563609681103aada9e1777d54fc57a5acd7a41404f9c93b6e"
+
+[[package]]
+name = "cranelift-bforest"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a91a1ccf6fb772808742db2f51e2179f25b1ec559cbe39ea080c72ff61caf8f"
+dependencies = [
+ "cranelift-entity",
+]
+
+[[package]]
+name = "cranelift-codegen"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "169db1a457791bff4fd1fc585bb5cc515609647e0420a7d5c98d7700c59c2d00"
+dependencies = [
+ "bumpalo",
+ "cranelift-bforest",
+ "cranelift-codegen-meta",
+ "cranelift-codegen-shared",
+ "cranelift-control",
+ "cranelift-entity",
+ "cranelift-isle",
+ "gimli 0.27.3",
+ "hashbrown 0.13.2",
+ "log",
+ "regalloc2",
+ "smallvec",
+ "target-lexicon",
+]
+
+[[package]]
+name = "cranelift-codegen-meta"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3486b93751ef19e6d6eef66d2c0e83ed3d2ba01da1919ed2747f2f7bd8ba3419"
+dependencies = [
+ "cranelift-codegen-shared",
+]
+
+[[package]]
+name = "cranelift-codegen-shared"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "86a1205ab18e7cd25dc4eca5246e56b506ced3feb8d95a8d776195e48d2cd4ef"
+
+[[package]]
+name = "cranelift-control"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b108cae0f724ddfdec1871a0dc193a607e0c2d960f083cfefaae8ccf655eff2"
+dependencies = [
+ "arbitrary",
+]
+
+[[package]]
+name = "cranelift-entity"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "720444006240622798665bfc6aa8178e2eed556da342fda62f659c5267c3c659"
+
+[[package]]
+name = "cranelift-frontend"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7a94c4c5508b7407e125af9d5320694b7423322e59a4ac0d07919ae254347ca"
+dependencies = [
+ "cranelift-codegen",
+ "log",
+ "smallvec",
+ "target-lexicon",
+]
+
+[[package]]
+name = "cranelift-isle"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef1f888d0845dcd6be4d625b91d9d8308f3d95bed5c5d4072ce38e1917faa505"
+
+[[package]]
+name = "cranelift-jit"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "547845cd12d15167e5458556ee67513bfaff2e05e72eb489edfbabc9f21d9ea2"
+dependencies = [
+ "anyhow",
+ "cranelift-codegen",
+ "cranelift-control",
+ "cranelift-entity",
+ "cranelift-module",
+ "cranelift-native",
+ "libc",
+ "log",
+ "region",
+ "target-lexicon",
+ "wasmtime-jit-icache-coherence",
+ "windows-sys 0.48.0",
+]
+
+[[package]]
+name = "cranelift-module"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3c104ed6a4c56c15e1858cc466482373e3c13d022bc1391485769ba384d9b079"
+dependencies = [
+ "anyhow",
+ "cranelift-codegen",
+ "cranelift-control",
+]
+
+[[package]]
+name = "cranelift-native"
+version = "0.99.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ad5966da08f1e96a3ae63be49966a85c9b249fa465f8cf1b66469a82b1004a0"
+dependencies = [
+ "cranelift-codegen",
+ "libc",
+ "target-lexicon",
+]
+
+[[package]]
+name = "crc"
+version = "0.1.0"
+
+[[package]]
+name = "critical-section"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
+
+[[package]]
+name = "defer"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "930c7171c8df9fb1782bdf9b918ed9ed2d33d1d22300abb754f9085bc48bf8e8"
+
+[[package]]
+name = "defmt"
+version = "0.3.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "86f6162c53f659f65d00619fe31f14556a6e9f8752ccc4a41bd177ffcf3d6130"
+dependencies = [
+ "bitflags 1.3.2",
+ "defmt-macros",
+]
+
+[[package]]
+name = "defmt-macros"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9d135dd939bad62d7490b0002602d35b358dce5fd9233a709d3c1ef467d4bde6"
+dependencies = [
+ "defmt-parser",
+ "proc-macro-error2",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "defmt-parser"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3983b127f13995e68c1e29071e5d115cd96f215ccb5e6812e3728cd6f92653b3"
+dependencies = [
+ "thiserror",
+]
+
+[[package]]
+name = "derive_more"
+version = "0.99.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3da29a38df43d6f156149c9b43ded5e018ddff2a855cf2cfd62e8cd7d079c69f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "discard"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
+
+[[package]]
+name = "doc-comment"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
+
+[[package]]
+name = "dragonos_kernel"
+version = "0.1.10"
+dependencies = [
+ "acpi",
+ "asm_macros",
+ "atomic_enum",
+ "bit_field",
+ "bitfield-struct",
+ "bitflags 1.3.2",
+ "bitmap",
+ "cfg-if",
+ "defer",
+ "driver_base_macros",
+ "elf 0.7.2",
+ "fdt",
+ "hashbrown 0.13.2",
+ "ida",
+ "intertrait",
+ "kcmdline_macros",
+ "kdepends",
+ "kernel_build",
+ "klog_types",
+ "kprobe",
+ "lazy_static",
+ "linkme",
+ "log",
+ "loongArch64",
+ "lru",
+ "multiboot2",
+ "num",
+ "num-derive",
+ "num-traits 0.2.15",
+ "paste",
+ "printf-compat",
+ "raw-cpuid 11.5.0",
+ "rbpf",
+ "riscv",
+ "sbi-rt",
+ "slabmalloc",
+ "smoltcp",
+ "static-keys",
+ "system_error",
+ "uefi",
+ "uefi-raw",
+ "unified-init",
+ "unwinding",
+ "virtio-drivers",
+ "wait_queue_macros",
+ "x86",
+ "x86_64",
+]
+
+[[package]]
+name = "driver_base_macros"
+version = "0.1.0"
+
+[[package]]
+name = "either"
+version = "1.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
+
+[[package]]
+name = "elf"
+version = "0.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4841de15dbe0e49b9b62a417589299e3be0d557e0900d36acb87e6dae47197f5"
+dependencies = [
+ "byteorder 0.5.3",
+]
+
+[[package]]
+name = "elf"
+version = "0.7.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2b183d6ce6ca4cf30e3db37abf5b52568b5f9015c97d9fbdd7026aa5dcdd758"
+
+[[package]]
+name = "embedded-hal"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
+
+[[package]]
+name = "env_logger"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"
+dependencies = [
+ "atty",
+ "humantime",
+ "log",
+ "regex",
+ "termcolor",
+]
+
+[[package]]
+name = "equivalent"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
+
+[[package]]
+name = "errno"
+version = "0.3.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
+dependencies = [
+ "libc",
+ "windows-sys 0.59.0",
+]
+
+[[package]]
+name = "fallible-iterator"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
+
+[[package]]
+name = "fdt"
+version = "0.2.0-alpha1"
+source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/fdt?rev=9862813020#98628130200086c2e55dae0d997ac4daeb590e90"
+
+[[package]]
+name = "foldhash"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
+
+[[package]]
+name = "getrandom"
+version = "0.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi",
+]
+
+[[package]]
+name = "gimli"
+version = "0.27.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"
+dependencies = [
+ "fallible-iterator",
+ "indexmap 1.9.3",
+ "stable_deref_trait",
+]
+
+[[package]]
+name = "gimli"
+version = "0.31.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
+
+[[package]]
+name = "glob"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
+
+[[package]]
+name = "hash32"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"
+dependencies = [
+ "byteorder 1.5.0",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.12.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
+
+[[package]]
+name = "hashbrown"
+version = "0.13.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
+dependencies = [
+ "ahash",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.15.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
+dependencies = [
+ "allocator-api2",
+ "equivalent",
+ "foldhash",
+]
+
+[[package]]
+name = "heapless"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
+dependencies = [
+ "hash32",
+ "stable_deref_trait",
+]
+
+[[package]]
+name = "hermit-abi"
+version = "0.1.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "hex"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
+
+[[package]]
+name = "home"
+version = "0.5.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf"
+dependencies = [
+ "windows-sys 0.59.0",
+]
+
+[[package]]
+name = "humantime"
+version = "2.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f"
+
+[[package]]
+name = "ida"
+version = "0.1.0"
+dependencies = [
+ "kdepends",
+]
+
+[[package]]
+name = "indexmap"
+version = "1.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
+dependencies = [
+ "autocfg",
+ "hashbrown 0.12.3",
+]
+
+[[package]]
+name = "indexmap"
+version = "2.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058"
+dependencies = [
+ "equivalent",
+ "hashbrown 0.15.2",
+]
+
+[[package]]
+name = "intertrait"
+version = "0.2.2"
+dependencies = [
+ "doc-comment",
+ "hashbrown 0.13.2",
+ "intertrait-macros",
+ "linkme",
+ "once_cell",
+ "trybuild",
+]
+
+[[package]]
+name = "intertrait-macros"
+version = "0.2.2"
+dependencies = [
+ "hashbrown 0.13.2",
+ "intertrait",
+ "linkme",
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+ "uuid",
+]
+
+[[package]]
+name = "itertools"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
+dependencies = [
+ "either",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
+
+[[package]]
+name = "jobserver"
+version = "0.1.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "json"
+version = "0.11.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "92c245af8786f6ac35f95ca14feca9119e71339aaab41e878e7cdd655c97e9e5"
+
+[[package]]
+name = "kcmdline_macros"
+version = "0.1.0"
+
+[[package]]
+name = "kdepends"
+version = "0.1.0"
+dependencies = [
+ "crc",
+ "memoffset",
+ "ringbuffer",
+ "thingbuf",
+ "xarray",
+]
+
+[[package]]
+name = "kernel_build"
+version = "0.1.0"
+dependencies = [
+ "bindgen",
+ "cc",
+ "lazy_static",
+ "toml",
+]
+
+[[package]]
+name = "klog_types"
+version = "0.1.0"
+dependencies = [
+ "kdepends",
+]
+
+[[package]]
+name = "kprobe"
+version = "0.1.0"
+dependencies = [
+ "log",
+ "yaxpeax-arch",
+ "yaxpeax-x86",
+]
+
+[[package]]
+name = "lazy_static"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+dependencies = [
+ "spin 0.5.2",
+]
+
+[[package]]
+name = "lazycell"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
+
+[[package]]
+name = "libc"
+version = "0.2.171"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
+
+[[package]]
+name = "libloading"
+version = "0.8.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
+dependencies = [
+ "cfg-if",
+ "windows-targets 0.52.6",
+]
+
+[[package]]
+name = "linkme"
+version = "0.3.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ccb76662d78edc9f9bf56360d6919bdacc8b7761227727e5082f128eeb90bbf5"
+dependencies = [
+ "linkme-impl",
+]
+
+[[package]]
+name = "linkme-impl"
+version = "0.3.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8dccda732e04fa3baf2e17cf835bfe2601c7c2edafd64417c627dabae3a8cda"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "linux-raw-sys"
+version = "0.4.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
+
+[[package]]
+name = "lock_api"
+version = "0.4.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
+dependencies = [
+ "autocfg",
+ "scopeguard",
+]
+
+[[package]]
+name = "log"
+version = "0.4.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
+
+[[package]]
+name = "loongArch64"
+version = "0.2.4"
+source = "git+https://github.com/fslongjin/loongArch64?rev=7af150e#7af150e01e7ce3139f519578751c95bbdaf4fb4d"
+dependencies = [
+ "bit_field",
+ "bitflags 1.3.2",
+]
+
+[[package]]
+name = "lru"
+version = "0.12.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38"
+dependencies = [
+ "hashbrown 0.15.2",
+]
+
+[[package]]
+name = "mach"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "mach2"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "managed"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d"
+
+[[package]]
+name = "memchr"
+version = "2.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
+
+[[package]]
+name = "memoffset"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "minimal-lexical"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
+
+[[package]]
+name = "multiboot2"
+version = "0.22.2"
+source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/multiboot2?rev=05739aab40#05739aab40916370146a078ed5297ed113781aed"
+dependencies = [
+ "bitflags 2.9.0",
+ "derive_more",
+ "log",
+ "multiboot2-common",
+ "ptr_meta",
+ "uefi-raw",
+]
+
+[[package]]
+name = "multiboot2-common"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "891220b5305e3e8fe8eb192147e43ba6541148a9b4cfa8e36b28afa04736c8f1"
+dependencies = [
+ "derive_more",
+ "ptr_meta",
+]
+
+[[package]]
+name = "nom"
+version = "7.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
+dependencies = [
+ "memchr",
+ "minimal-lexical",
+]
+
+[[package]]
+name = "num"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606"
+dependencies = [
+ "num-complex",
+ "num-integer",
+ "num-iter",
+ "num-rational",
+ "num-traits 0.2.19",
+]
+
+[[package]]
+name = "num-complex"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
+dependencies = [
+ "num-traits 0.2.19",
+]
+
+[[package]]
+name = "num-derive"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "num-integer"
+version = "0.1.46"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
+dependencies = [
+ "num-traits 0.2.19",
+]
+
+[[package]]
+name = "num-iter"
+version = "0.1.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
+dependencies = [
+ "autocfg",
+ "num-integer",
+ "num-traits 0.2.19",
+]
+
+[[package]]
+name = "num-rational"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
+dependencies = [
+ "num-integer",
+ "num-traits 0.2.19",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.15"
+source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/num-traits.git?rev=1597c1c#1597c1c4d1b3e33548e4661c519b7246a5fc1c28"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.21.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc"
+
+[[package]]
+name = "paste"
+version = "1.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
+
+[[package]]
+name = "peeking_take_while"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
+
+[[package]]
+name = "pin-project"
+version = "1.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a"
+dependencies = [
+ "pin-project-internal",
+]
+
+[[package]]
+name = "pin-project-internal"
+version = "1.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "ppv-lite86"
+version = "0.2.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
+dependencies = [
+ "zerocopy 0.8.24",
+]
+
+[[package]]
+name = "printf-compat"
+version = "0.1.1"
+source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/printf-compat?rev=5f5c9cc363#5f5c9cc363f047411a0dccb37e0efb452ffb61d9"
+dependencies = [
+ "bitflags 1.3.2",
+ "itertools",
+]
+
+[[package]]
+name = "proc-macro-error-attr2"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5"
+dependencies = [
+ "proc-macro2",
+ "quote",
+]
+
+[[package]]
+name = "proc-macro-error2"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802"
+dependencies = [
+ "proc-macro-error-attr2",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "proc-macro-hack"
+version = "0.5.20+deprecated"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.94"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "ptr_meta"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bcada80daa06c42ed5f48c9a043865edea5dc44cbf9ac009fda3b89526e28607"
+dependencies = [
+ "ptr_meta_derive",
+]
+
+[[package]]
+name = "ptr_meta_derive"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bca9224df2e20e7c5548aeb5f110a0f3b77ef05f8585139b7148b59056168ed2"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.40"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "rand"
+version = "0.8.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
+dependencies = [
+ "libc",
+ "rand_chacha",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_chacha"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
+dependencies = [
+ "ppv-lite86",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
+dependencies = [
+ "getrandom",
+]
+
+[[package]]
+name = "raw-cpuid"
+version = "10.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332"
+dependencies = [
+ "bitflags 1.3.2",
+]
+
+[[package]]
+name = "raw-cpuid"
+version = "11.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c6df7ab838ed27997ba19a4664507e6f82b41fe6e20be42929332156e5e85146"
+dependencies = [
+ "bitflags 2.9.0",
+]
+
+[[package]]
+name = "rbpf"
+version = "0.2.0"
+dependencies = [
+ "byteorder 1.5.0",
+ "combine",
+ "cranelift-codegen",
+ "cranelift-frontend",
+ "cranelift-jit",
+ "cranelift-module",
+ "cranelift-native",
+ "elf 0.0.10",
+ "hex",
+ "json",
+ "libc",
+ "log",
+ "time",
+]
+
+[[package]]
+name = "regalloc2"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ad156d539c879b7a24a363a2016d77961786e71f48f2e2fc8302a92abd2429a6"
+dependencies = [
+ "hashbrown 0.13.2",
+ "log",
+ "rustc-hash",
+ "slice-group-by",
+ "smallvec",
+]
+
+[[package]]
+name = "regex"
+version = "1.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-automata",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-automata"
+version = "0.4.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.8.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
+
+[[package]]
+name = "region"
+version = "2.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0"
+dependencies = [
+ "bitflags 1.3.2",
+ "libc",
+ "mach",
+ "winapi",
+]
+
+[[package]]
+name = "ringbuffer"
+version = "0.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3df6368f71f205ff9c33c076d170dd56ebf68e8161c733c0caa07a7a5509ed53"
+
+[[package]]
+name = "riscv"
+version = "0.11.1"
+source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/riscv.git?rev=4241a97#4241a976271b24b1263efc0065d1fe3e333b5ac4"
+dependencies = [
+ "critical-section",
+ "embedded-hal",
+]
+
+[[package]]
+name = "rustc-hash"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
+
+[[package]]
+name = "rustc_version"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
+dependencies = [
+ "semver",
+]
+
+[[package]]
+name = "rustix"
+version = "0.38.44"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154"
+dependencies = [
+ "bitflags 2.9.0",
+ "errno",
+ "libc",
+ "linux-raw-sys",
+ "windows-sys 0.59.0",
+]
+
+[[package]]
+name = "rustversion"
+version = "1.0.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
+
+[[package]]
+name = "ryu"
+version = "1.0.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
+
+[[package]]
+name = "sbi-rt"
+version = "0.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7fbaa69be1eedc61c426e6d489b2260482e928b465360576900d52d496a58bd0"
+dependencies = [
+ "sbi-spec",
+]
+
+[[package]]
+name = "sbi-spec"
+version = "0.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6e36312fb5ddc10d08ecdc65187402baba4ac34585cb9d1b78522ae2358d890"
+
+[[package]]
+name = "scopeguard"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
+
+[[package]]
+name = "semver"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
+dependencies = [
+ "semver-parser",
+]
+
+[[package]]
+name = "semver-parser"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
+
+[[package]]
+name = "serde"
+version = "1.0.219"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.219"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "serde_json"
+version = "1.0.140"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
+dependencies = [
+ "itoa",
+ "memchr",
+ "ryu",
+ "serde",
+]
+
+[[package]]
+name = "serde_spanned"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "sha1"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770"
+dependencies = [
+ "sha1_smol",
+]
+
+[[package]]
+name = "sha1_smol"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d"
+
+[[package]]
+name = "shlex"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
+
+[[package]]
+name = "slabmalloc"
+version = "0.11.0"
+dependencies = [
+ "env_logger",
+ "log",
+ "rand",
+ "spin 0.9.8",
+]
+
+[[package]]
+name = "slice-group-by"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7"
+
+[[package]]
+name = "smallvec"
+version = "1.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd"
+
+[[package]]
+name = "smoltcp"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a1a996951e50b5971a2c8c0fa05a381480d70a933064245c4a223ddc87ccc97"
+dependencies = [
+ "bitflags 1.3.2",
+ "byteorder 1.5.0",
+ "cfg-if",
+ "defmt",
+ "heapless",
+ "log",
+ "managed",
+]
+
+[[package]]
+name = "spin"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
+
+[[package]]
+name = "spin"
+version = "0.9.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
+dependencies = [
+ "lock_api",
+]
+
+[[package]]
+name = "stable_deref_trait"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
+
+[[package]]
+name = "standback"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff"
+dependencies = [
+ "version_check",
+]
+
+[[package]]
+name = "static-keys"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa784228d57f9f47a0f5837289ba92296239c2273f146d97b35bbd8538806777"
+dependencies = [
+ "clear-cache",
+ "libc",
+ "mach2",
+ "windows 0.59.0",
+]
+
+[[package]]
+name = "stdweb"
+version = "0.4.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5"
+dependencies = [
+ "discard",
+ "rustc_version",
+ "stdweb-derive",
+ "stdweb-internal-macros",
+ "stdweb-internal-runtime",
+ "wasm-bindgen",
+]
+
+[[package]]
+name = "stdweb-derive"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "serde",
+ "serde_derive",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "stdweb-internal-macros"
+version = "0.2.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
+dependencies = [
+ "base-x",
+ "proc-macro2",
+ "quote",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "sha1",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "stdweb-internal-runtime"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
+
+[[package]]
+name = "syn"
+version = "1.0.109"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.100"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "system_error"
+version = "0.1.0"
+dependencies = [
+ "num-derive",
+ "num-traits 0.2.15",
+]
+
+[[package]]
+name = "target-lexicon"
+version = "0.12.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
+
+[[package]]
+name = "target-triple"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1ac9aa371f599d22256307c24a9d748c041e548cbf599f35d890f9d365361790"
+
+[[package]]
+name = "termcolor"
+version = "1.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
+name = "thingbuf"
+version = "0.1.4"
+source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/thingbuf.git?rev=2dded730c3#2dded730c354c1ff14d35ba8f86f5748d39d4136"
+dependencies = [
+ "memoffset",
+ "pin-project",
+]
+
+[[package]]
+name = "thiserror"
+version = "2.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "2.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "time"
+version = "0.2.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242"
+dependencies = [
+ "const_fn",
+ "libc",
+ "standback",
+ "stdweb",
+ "time-macros",
+ "version_check",
+ "winapi",
+]
+
+[[package]]
+name = "time-macros"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1"
+dependencies = [
+ "proc-macro-hack",
+ "time-macros-impl",
+]
+
+[[package]]
+name = "time-macros-impl"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f"
+dependencies = [
+ "proc-macro-hack",
+ "proc-macro2",
+ "quote",
+ "standback",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "toml"
+version = "0.8.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148"
+dependencies = [
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_edit",
+]
+
+[[package]]
+name = "toml_datetime"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "toml_edit"
+version = "0.22.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474"
+dependencies = [
+ "indexmap 2.8.0",
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "winnow",
+]
+
+[[package]]
+name = "trybuild"
+version = "1.0.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6ae08be68c056db96f0e6c6dd820727cca756ced9e1f4cc7fdd20e2a55e23898"
+dependencies = [
+ "glob",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "target-triple",
+ "termcolor",
+ "toml",
+]
+
+[[package]]
+name = "ucs2"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df79298e11f316400c57ec268f3c2c29ac3c4d4777687955cd3d4f3a35ce7eba"
+dependencies = [
+ "bit_field",
+]
+
+[[package]]
+name = "uefi"
+version = "0.26.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "07ead9f748a4646479b850add36b527113a80e80a7e0f44d7b0334291850dcc5"
+dependencies = [
+ "bitflags 2.9.0",
+ "log",
+ "ptr_meta",
+ "ucs2",
+ "uefi-macros",
+ "uefi-raw",
+ "uguid",
+]
+
+[[package]]
+name = "uefi-macros"
+version = "0.13.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "26a7b1c2c808c3db854a54d5215e3f7e7aaf5dcfbce095598cba6af29895695d"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "uefi-raw"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "864ac69eadd877bfb34e7814be1928122ed0057d9f975169a56ee496aa7bdfd7"
+dependencies = [
+ "bitflags 2.9.0",
+ "ptr_meta",
+ "uguid",
+]
+
+[[package]]
+name = "uguid"
+version = "2.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ab14ea9660d240e7865ce9d54ecdbd1cd9fa5802ae6f4512f093c7907e921533"
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
+
+[[package]]
+name = "unified-init"
+version = "0.1.0"
+dependencies = [
+ "linkme",
+ "system_error",
+ "unified-init-macros",
+]
+
+[[package]]
+name = "unified-init-macros"
+version = "0.1.0"
+dependencies = [
+ "linkme",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+ "system_error",
+ "unified-init",
+ "uuid",
+]
+
+[[package]]
+name = "unwinding"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "637d511437df708cee34bdec7ba2f1548d256b7acf3ff20e0a1c559f9bf3a987"
+dependencies = [
+ "gimli 0.31.1",
+]
+
+[[package]]
+name = "uuid"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
+dependencies = [
+ "getrandom",
+]
+
+[[package]]
+name = "version_check"
+version = "0.9.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
+
+[[package]]
+name = "virtio-drivers"
+version = "0.7.2"
+source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/virtio-drivers?rev=415ab38ff9#415ab38ff99f3c8e150269c04f65d684ba9d1365"
+dependencies = [
+ "bitflags 2.9.0",
+ "log",
+ "zerocopy 0.7.35",
+]
+
+[[package]]
+name = "volatile"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793"
+
+[[package]]
+name = "wait_queue_macros"
+version = "0.1.0"
+
+[[package]]
+name = "wasi"
+version = "0.11.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
+
+[[package]]
+name = "wasm-bindgen"
+version = "0.2.100"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
+dependencies = [
+ "cfg-if",
+ "once_cell",
+ "rustversion",
+ "wasm-bindgen-macro",
+]
+
+[[package]]
+name = "wasm-bindgen-backend"
+version = "0.2.100"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
+dependencies = [
+ "bumpalo",
+ "log",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.100"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.100"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+ "wasm-bindgen-backend",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.100"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "wasmtime-jit-icache-coherence"
+version = "12.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b59f94b0409221873565419168e20b5aedf18c4bd64de5c38acf8f0634efeee3"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "windows-sys 0.48.0",
+]
+
+[[package]]
+name = "which"
+version = "4.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
+dependencies = [
+ "either",
+ "home",
+ "once_cell",
+ "rustix",
+]
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-util"
+version = "0.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
+dependencies = [
+ "windows-sys 0.59.0",
+]
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
+[[package]]
+name = "windows"
+version = "0.58.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6"
+dependencies = [
+ "windows-core 0.58.0",
+ "windows-targets 0.52.6",
+]
+
+[[package]]
+name = "windows"
+version = "0.59.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f919aee0a93304be7f62e8e5027811bbba96bcb1de84d6618be56e43f8a32a1"
+dependencies = [
+ "windows-core 0.59.0",
+ "windows-targets 0.53.0",
+]
+
+[[package]]
+name = "windows-core"
+version = "0.58.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99"
+dependencies = [
+ "windows-implement 0.58.0",
+ "windows-interface 0.58.0",
+ "windows-result 0.2.0",
+ "windows-strings 0.1.0",
+ "windows-targets 0.52.6",
+]
+
+[[package]]
+name = "windows-core"
+version = "0.59.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "810ce18ed2112484b0d4e15d022e5f598113e220c53e373fb31e67e21670c1ce"
+dependencies = [
+ "windows-implement 0.59.0",
+ "windows-interface 0.59.1",
+ "windows-result 0.3.2",
+ "windows-strings 0.3.1",
+ "windows-targets 0.53.0",
+]
+
+[[package]]
+name = "windows-implement"
+version = "0.58.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "windows-implement"
+version = "0.59.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "83577b051e2f49a058c308f17f273b570a6a758386fc291b5f6a934dd84e48c1"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "windows-interface"
+version = "0.58.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "windows-interface"
+version = "0.59.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "windows-link"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
+
+[[package]]
+name = "windows-result"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e"
+dependencies = [
+ "windows-targets 0.52.6",
+]
+
+[[package]]
+name = "windows-result"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252"
+dependencies = [
+ "windows-link",
+]
+
+[[package]]
+name = "windows-strings"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10"
+dependencies = [
+ "windows-result 0.2.0",
+ "windows-targets 0.52.6",
+]
+
+[[package]]
+name = "windows-strings"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319"
+dependencies = [
+ "windows-link",
+]
+
+[[package]]
+name = "windows-sys"
+version = "0.48.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
+dependencies = [
+ "windows-targets 0.48.5",
+]
+
+[[package]]
+name = "windows-sys"
+version = "0.59.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
+dependencies = [
+ "windows-targets 0.52.6",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
+dependencies = [
+ "windows_aarch64_gnullvm 0.48.5",
+ "windows_aarch64_msvc 0.48.5",
+ "windows_i686_gnu 0.48.5",
+ "windows_i686_msvc 0.48.5",
+ "windows_x86_64_gnu 0.48.5",
+ "windows_x86_64_gnullvm 0.48.5",
+ "windows_x86_64_msvc 0.48.5",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
+dependencies = [
+ "windows_aarch64_gnullvm 0.52.6",
+ "windows_aarch64_msvc 0.52.6",
+ "windows_i686_gnu 0.52.6",
+ "windows_i686_gnullvm 0.52.6",
+ "windows_i686_msvc 0.52.6",
+ "windows_x86_64_gnu 0.52.6",
+ "windows_x86_64_gnullvm 0.52.6",
+ "windows_x86_64_msvc 0.52.6",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.53.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b"
+dependencies = [
+ "windows_aarch64_gnullvm 0.53.0",
+ "windows_aarch64_msvc 0.53.0",
+ "windows_i686_gnu 0.53.0",
+ "windows_i686_gnullvm 0.53.0",
+ "windows_i686_msvc 0.53.0",
+ "windows_x86_64_gnu 0.53.0",
+ "windows_x86_64_gnullvm 0.53.0",
+ "windows_x86_64_msvc 0.53.0",
+]
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.53.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.53.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.53.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
+
+[[package]]
+name = "windows_i686_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
+
+[[package]]
+name = "windows_i686_gnullvm"
+version = "0.53.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.53.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.53.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.53.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.53.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
+
+[[package]]
+name = "winnow"
+version = "0.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "x86"
+version = "0.52.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2781db97787217ad2a2845c396a5efe286f87467a5810836db6d74926e94a385"
+dependencies = [
+ "bit_field",
+ "bitflags 1.3.2",
+ "raw-cpuid 10.7.0",
+]
+
+[[package]]
+name = "x86_64"
+version = "0.14.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "100555a863c0092238c2e0e814c1096c1e5cf066a309c696a87e907b5f8c5d69"
+dependencies = [
+ "bit_field",
+ "bitflags 1.3.2",
+ "rustversion",
+ "volatile",
+]
+
+[[package]]
+name = "xarray"
+version = "0.1.0"
+source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/xarray?rev=de93b57c34#de93b57c34011899d79758b3bfa767b04316b107"
+dependencies = [
+ "smallvec",
+]
+
+[[package]]
+name = "yaxpeax-arch"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "36274fcc5403da2a7636ffda4d02eca12a1b2b8267b9d2e04447bd2ccfc72082"
+dependencies = [
+ "num-traits 0.2.19",
+]
+
+[[package]]
+name = "yaxpeax-x86"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a9a30b7dd533c7b1a73eaf7c4ea162a7a632a2bb29b9fff47d8f2cc8513a883"
+dependencies = [
+ "cfg-if",
+ "num-traits 0.2.19",
+ "yaxpeax-arch",
+]
+
+[[package]]
+name = "zerocopy"
+version = "0.7.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
+dependencies = [
+ "byteorder 1.5.0",
+ "zerocopy-derive 0.7.35",
+]
+
+[[package]]
+name = "zerocopy"
+version = "0.8.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
+dependencies = [
+ "zerocopy-derive 0.8.24",
+]
+
+[[package]]
+name = "zerocopy-derive"
+version = "0.7.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]
+
+[[package]]
+name = "zerocopy-derive"
+version = "0.8.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.100",
+]

+ 38 - 20
kernel/Cargo.toml

@@ -10,14 +10,10 @@ edition = "2021"
 crate-type = ["staticlib"]
 
 [workspace]
-members = [
-    "crates/*",
-]
+members = ["crates/*"]
 
 [features]
-default = ["backtrace", "kvm", "fatfs", "fatfs-secure", "static_keys_test"]
-# 内核栈回溯
-backtrace = ["dep:unwinding"]
+default = ["fatfs", "kvm", "fatfs-secure", "static_keys_test"]
 # kvm
 kvm = []
 
@@ -51,31 +47,39 @@ klog_types = { path = "crates/klog_types" }
 linkme = "=0.3.27"
 num = { version = "=0.4.0", default-features = false }
 num-derive = "=0.3"
-num-traits = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/num-traits.git", rev="1597c1c", default-features = false }
-smoltcp = { version = "=0.11.0", default-features = false, features = ["log", "alloc",  "socket-raw", "socket-udp", "socket-tcp", "socket-icmp", "socket-dhcpv4", "socket-dns", "proto-ipv4", "proto-ipv6"]}
+num-traits = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/num-traits.git", rev = "1597c1c", default-features = false }
+smoltcp = { version = "=0.11.0", default-features = false, features = [
+    "log",
+    "alloc",
+    "socket-raw",
+    "socket-udp",
+    "socket-tcp",
+    "socket-icmp",
+    "socket-dhcpv4",
+    "socket-dns",
+    "proto-ipv4",
+    "proto-ipv6",
+] }
 system_error = { path = "crates/system_error" }
 uefi = { version = "=0.26.0", features = ["alloc"] }
 uefi-raw = "=0.5.0"
 unified-init = { path = "crates/unified-init" }
-virtio-drivers = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/virtio-drivers", rev = "f91c807965" }
+virtio-drivers = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/virtio-drivers", rev = "415ab38ff9" }
 wait_queue_macros = { path = "crates/wait_queue_macros" }
 paste = "=1.0.14"
 slabmalloc = { path = "crates/rust-slabmalloc" }
 log = "0.4.21"
 kprobe = { path = "crates/kprobe" }
-xarray = "0.1.0"
 lru = "0.12.3"
 
 rbpf = { path = "crates/rbpf" }
-printf-compat = { version = "0.1.1", default-features = false }
+printf-compat = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/printf-compat", rev = "5f5c9cc363", default-features = false }
+
+static-keys = { version = "=0.7" }
+
+defer = "0.2.1"
+cfg-if = { version = "1.0.0" }
 
-static-keys = "=0.6.1"
-unwinding = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/unwinding", rev = "4eb845da62", default-features = false,  optional = true, features = [
-    "unwinder",
-    "fde-gnu-eh-frame-hdr",
-    "panic",
-    "personality"
-]}
 
 # target为x86_64时,使用下面的依赖
 [target.'cfg(target_arch = "x86_64")'.dependencies]
@@ -86,9 +90,23 @@ x86_64 = "=0.14.10"
 
 # target为riscv64时,使用下面的依赖
 [target.'cfg(target_arch = "riscv64")'.dependencies]
-riscv = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/riscv.git", rev = "4241a97", features = [ "s-mode" ] }
+riscv = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/riscv.git", rev = "4241a97", features = [
+    "s-mode",
+] }
 sbi-rt = { version = "=0.0.3", features = ["legacy"] }
 
+# target为loongarch64时,使用下面的依赖
+[target.'cfg(target_arch = "loongarch64")'.dependencies]
+loongArch64 = { git = "https://github.com/fslongjin/loongArch64", rev = "7af150e" }
+
+# 由于unwinding库不支持loongarch64架构,因此需要排除该依赖项
+[target.'cfg(not(target_arch = "loongarch64"))'.dependencies]
+unwinding = { version = "=0.2.3", default-features = false, features = [
+    "unwinder",
+    "fde-gnu-eh-frame-hdr",
+    "panic",
+    "personality",
+] }
 
 # 构建时依赖项
 [build-dependencies]
@@ -102,7 +120,7 @@ features = ["spin_no_std"]
 # The development profile, used for `cargo build`
 [profile.dev]
 # opt-level = 0  # Controls the --opt-level the compiler builds with
-debug = true   # Controls whether the compiler passes `-g`
+debug = true # Controls whether the compiler passes `-g`
 
 # The release profile, used for `cargo build --release`
 [profile.release]

+ 6 - 2
kernel/Makefile

@@ -7,6 +7,10 @@ ifeq ($(ARCH), x86_64)
 	export TARGET_JSON=arch/x86_64/x86_64-unknown-none.json
 else ifeq ($(ARCH), riscv64)
 	export TARGET_JSON=arch/riscv64/riscv64gc-unknown-none-elf.json
+else ifeq ($(ARCH), loongarch64)
+	export TARGET_JSON=arch/loongarch64/loongarch64-unknown-none.json
+else
+	$(error "Unsupported ARCH: $(ARCH)")
 endif
 
 export CARGO_ZBUILD=-Z build-std=core,alloc,compiler_builtins -Z build-std-features=compiler-builtins-mem
@@ -16,18 +20,18 @@ ECHO:
 	@echo "$@"
 
 all: 
+	$(MAKE) -C ../build-scripts all
 	$(MAKE) -C src all ARCH=$(ARCH) || (sh -c "echo 内核编译失败" && exit 1)
 	
 
 clean:
-	rm -f Cargo.lock
 	$(MAKE) -C src clean ARCH=$(ARCH)
 
 .PHONY: fmt
 fmt:
 	RUSTFLAGS="$(RUSTFLAGS)" cargo fmt --all $(FMT_CHECK)
 ifeq ($(ARCH), x86_64)
-	RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-11-05 clippy --all-features
+	RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-11-05 clippy --all-features --target x86_64-unknown-none
 endif
 
 

+ 5 - 1
kernel/crates/bitmap/src/alloc_bitmap.rs

@@ -4,7 +4,7 @@ use alloc::vec::Vec;
 
 use crate::{bitmap_core::BitMapCore, traits::BitMapOps};
 
-#[derive(Clone)]
+#[derive(Debug, Clone)]
 pub struct AllocBitmap {
     elements: usize,
     data: Vec<usize>,
@@ -26,6 +26,10 @@ impl AllocBitmap {
             self.data[i] &= rhs.data[i];
         }
     }
+
+    pub fn data(&self) -> &[usize] {
+        &self.data
+    }
 }
 
 impl BitMapOps<usize> for AllocBitmap {

+ 21 - 15
kernel/crates/bitmap/src/bitmap_core.rs

@@ -3,10 +3,16 @@ use core::{intrinsics::unlikely, marker::PhantomData};
 use crate::traits::BitOps;
 
 #[derive(Debug, Clone)]
-pub(crate) struct BitMapCore<T: BitOps> {
+pub struct BitMapCore<T: BitOps> {
     phantom: PhantomData<T>,
 }
 
+impl<T: BitOps> Default for BitMapCore<T> {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl<T: BitOps> BitMapCore<T> {
     pub const fn new() -> Self {
         Self {
@@ -15,7 +21,7 @@ impl<T: BitOps> BitMapCore<T> {
     }
 
     /// 获取位图中的某一位
-    pub(crate) fn get(&self, n: usize, data: &[T], index: usize) -> Option<bool> {
+    pub fn get(&self, n: usize, data: &[T], index: usize) -> Option<bool> {
         if unlikely(index >= n) {
             return None;
         }
@@ -30,7 +36,7 @@ impl<T: BitOps> BitMapCore<T> {
     }
 
     /// 设置位图中的某一位
-    pub(crate) fn set(&self, n: usize, data: &mut [T], index: usize, value: bool) -> Option<bool> {
+    pub fn set(&self, n: usize, data: &mut [T], index: usize, value: bool) -> Option<bool> {
         if unlikely(index >= n) {
             return None;
         }
@@ -43,7 +49,7 @@ impl<T: BitOps> BitMapCore<T> {
         Some(bit)
     }
 
-    pub(crate) fn set_all(&self, n: usize, data: &mut [T], value: bool) {
+    pub fn set_all(&self, n: usize, data: &mut [T], value: bool) {
         let val = if value { T::max() } else { T::zero() };
         for element in data.iter_mut() {
             *element = val;
@@ -58,7 +64,7 @@ impl<T: BitOps> BitMapCore<T> {
     }
 
     /// 获取位图中第一个为1的位
-    pub(crate) fn first_index(&self, data: &[T]) -> Option<usize> {
+    pub fn first_index(&self, data: &[T]) -> Option<usize> {
         for (i, element) in data.iter().enumerate() {
             let bit = <T as BitOps>::first_index(element);
             if let Some(b) = bit {
@@ -70,7 +76,7 @@ impl<T: BitOps> BitMapCore<T> {
     }
 
     /// 获取位图中第一个为0的位
-    pub(crate) fn first_false_index(&self, n: usize, data: &[T]) -> Option<usize> {
+    pub fn first_false_index(&self, n: usize, data: &[T]) -> Option<usize> {
         for (i, element) in data.iter().enumerate() {
             if let Some(bit) = <T as BitOps>::first_false_index(element) {
                 return self.make_index(n, i * T::bit_size() + bit);
@@ -81,7 +87,7 @@ impl<T: BitOps> BitMapCore<T> {
     }
 
     /// 获取位图中最后一个为1的位
-    pub(crate) fn last_index(&self, n: usize, data: &[T]) -> Option<usize> {
+    pub fn last_index(&self, n: usize, data: &[T]) -> Option<usize> {
         for (i, element) in data.iter().enumerate().rev() {
             if let Some(bit) = <T as BitOps>::last_index(element) {
                 return self.make_index(n, i * T::bit_size() + bit);
@@ -97,7 +103,7 @@ impl<T: BitOps> BitMapCore<T> {
     ///
     /// - `data`:位图数据
     /// - `n`:位图有效位数
-    pub(crate) fn last_false_index(&self, n: usize, data: &[T]) -> Option<usize> {
+    pub fn last_false_index(&self, n: usize, data: &[T]) -> Option<usize> {
         let mut iter = data.iter().rev();
         let mut last_element = *iter.next()?;
 
@@ -123,7 +129,7 @@ impl<T: BitOps> BitMapCore<T> {
     }
 
     /// 获取位图中下一个为1的位
-    pub(crate) fn next_index(&self, n: usize, data: &[T], index: usize) -> Option<usize> {
+    pub fn next_index(&self, n: usize, data: &[T], index: usize) -> Option<usize> {
         if unlikely(index >= n) {
             return None;
         }
@@ -146,7 +152,7 @@ impl<T: BitOps> BitMapCore<T> {
     }
 
     /// 获取位图中下一个为0的位
-    pub(crate) fn next_false_index(&self, n: usize, data: &[T], index: usize) -> Option<usize> {
+    pub fn next_false_index(&self, n: usize, data: &[T], index: usize) -> Option<usize> {
         if unlikely(index >= n) {
             return None;
         }
@@ -169,7 +175,7 @@ impl<T: BitOps> BitMapCore<T> {
     }
 
     /// 获取位图中上一个为1的位
-    pub(crate) fn prev_index(&self, n: usize, data: &[T], index: usize) -> Option<usize> {
+    pub fn prev_index(&self, n: usize, data: &[T], index: usize) -> Option<usize> {
         if unlikely(index >= n) {
             return None;
         }
@@ -190,7 +196,7 @@ impl<T: BitOps> BitMapCore<T> {
         None
     }
 
-    pub(crate) fn prev_false_index(&self, n: usize, data: &[T], index: usize) -> Option<usize> {
+    pub fn prev_false_index(&self, n: usize, data: &[T], index: usize) -> Option<usize> {
         let element_index = index / T::bit_size();
         let bit_index = index % T::bit_size();
 
@@ -208,7 +214,7 @@ impl<T: BitOps> BitMapCore<T> {
         None
     }
 
-    pub(crate) fn invert(&self, n: usize, data: &mut [T]) {
+    pub fn invert(&self, n: usize, data: &mut [T]) {
         for element in data.iter_mut() {
             <T as BitOps>::invert(element);
         }
@@ -222,7 +228,7 @@ impl<T: BitOps> BitMapCore<T> {
         }
     }
 
-    pub(crate) fn is_full(&self, n: usize, data: &[T]) -> bool {
+    pub fn is_full(&self, n: usize, data: &[T]) -> bool {
         let mut iter = data.iter().peekable();
         while let Some(element) = iter.next() {
             if iter.peek().is_none() {
@@ -245,7 +251,7 @@ impl<T: BitOps> BitMapCore<T> {
         return false;
     }
 
-    pub(crate) fn is_empty(&self, data: &[T]) -> bool {
+    pub fn is_empty(&self, data: &[T]) -> bool {
         for element in data.iter() {
             if element != &T::zero() {
                 return false;

+ 2 - 0
kernel/crates/bitmap/src/lib.rs

@@ -2,6 +2,7 @@
 #![feature(core_intrinsics)]
 #![allow(incomplete_features)] // for const generics
 #![feature(generic_const_exprs)]
+#![deny(clippy::all)]
 #![allow(internal_features)]
 #![allow(clippy::needless_return)]
 
@@ -13,4 +14,5 @@ mod bitmap_core;
 mod static_bitmap;
 pub mod traits;
 pub use alloc_bitmap::AllocBitmap;
+pub use bitmap_core::BitMapCore;
 pub use static_bitmap::StaticBitmap;

+ 2 - 2
kernel/crates/intertrait/src/lib.rs

@@ -124,11 +124,11 @@ static mut CASTER_MAP: Option<HashMap<(TypeId, TypeId), BoxedCaster, BuildFastHa
 #[cfg(target_os = "none")]
 #[allow(static_mut_refs)]
 pub fn caster_map() -> &'static HashMap<(TypeId, TypeId), BoxedCaster, BuildFastHasher> {
-    return unsafe {
+    unsafe {
         CASTER_MAP.as_ref().unwrap_or_else(|| {
             panic!("intertrait_caster_map() must be called after CASTER_MAP is initialized")
         })
-    };
+    }
 }
 
 /// Initializes the global [`CASTER_MAP`] with [`CASTERS`].

+ 2 - 0
kernel/crates/kprobe/src/arch/loongarch64/mod.rs

@@ -77,6 +77,7 @@ impl KprobeBuilder {
         };
         let inst_tmp_ptr = point.inst_tmp.as_ptr() as usize;
         let inst_32 = unsafe { core::ptr::read(address as *const u32) };
+
         unsafe {
             core::ptr::write(address as *mut u32, EBREAK_INST);
             // inst_32 :0-32
@@ -90,6 +91,7 @@ impl KprobeBuilder {
             self.symbol,
             inst_32
         );
+        Arc::new(point)
     }
 }
 

+ 3 - 3
kernel/crates/rbpf/src/interpreter.rs

@@ -660,9 +660,9 @@ pub fn execute_program(
                             // Save the callee saved registers
                             pre_stack.save_registers(&reg[6..=9]);
                             // Save the return address
-                            pre_stack.save_return_address(insn_ptr as u16);
+                            pre_stack.save_return_address(insn_ptr as u64);
                             // save the stack pointer
-                            pre_stack.save_sp(reg[10] as u16);
+                            pre_stack.save_sp(reg[10]);
                             let mut stack = StackFrame::new();
                             log::trace!("BPF TO BPF CALL: new pc: {} + {} = {}",insn_ptr ,insn.imm,insn_ptr + insn.imm as usize);
                             reg[10] = stack.as_ptr() as u64 + stack.len() as u64;
@@ -695,7 +695,7 @@ pub fn execute_program(
                     // Restore the return address
                     insn_ptr = stack.get_return_address() as usize;
                     // Restore the stack pointer
-                    reg[10] = stack.get_sp() as u64;
+                    reg[10] = stack.get_sp();
                     log::trace!("EXIT: new pc: {}", insn_ptr);
                 }
             }

+ 6 - 6
kernel/crates/rbpf/src/stack.rs

@@ -1,9 +1,9 @@
 use crate::{ebpf::STACK_SIZE, vec, Vec};
 
 pub struct StackFrame {
-    return_address: u16,
+    return_address: u64,
     saved_registers: [u64; 4],
-    sp: u16,
+    sp: u64,
     frame: Vec<u8>,
 }
 
@@ -54,22 +54,22 @@ impl StackFrame {
     }
 
     /// Save the return address
-    pub fn save_return_address(&mut self, address: u16) {
+    pub fn save_return_address(&mut self, address: u64) {
         self.return_address = address;
     }
 
     /// Get the return address
-    pub fn get_return_address(&self) -> u16 {
+    pub fn get_return_address(&self) -> u64 {
         self.return_address
     }
 
     /// Save the stack pointer
-    pub fn save_sp(&mut self, sp: u16) {
+    pub fn save_sp(&mut self, sp: u64) {
         self.sp = sp;
     }
 
     /// Get the stack pointer
-    pub fn get_sp(&self) -> u16 {
+    pub fn get_sp(&self) -> u64 {
         self.sp
     }
 }

+ 13 - 2
kernel/crates/rust-slabmalloc/src/lib.rs

@@ -18,11 +18,13 @@
 //! # Implementing GlobalAlloc
 //! See the [global alloc](https://github.com/gz/rust-slabmalloc/tree/master/examples/global_alloc.rs) example.
 #![allow(unused_features)]
+#![cfg_attr(test, feature(test, c_void_variant))]
 #![no_std]
 #![crate_name = "slabmalloc"]
 #![crate_type = "lib"]
 #![feature(maybe_uninit_as_bytes)]
-
+#![deny(clippy::all)]
+#![allow(clippy::needless_return)]
 extern crate alloc;
 
 mod pages;
@@ -33,8 +35,18 @@ pub use pages::*;
 pub use sc::*;
 pub use zone::*;
 
+#[cfg(test)]
+#[macro_use]
+extern crate std;
+#[cfg(test)]
+extern crate test;
+
+#[cfg(test)]
+mod tests;
+
 use core::alloc::Layout;
 use core::fmt;
+use core::mem;
 use core::ptr::{self, NonNull};
 
 use log::trace;
@@ -71,7 +83,6 @@ pub unsafe trait Allocator<'a> {
         layout: Layout,
         slab_callback: &'static dyn CallBack,
     ) -> Result<(), AllocationError>;
-
     /// Refill the allocator with a [`ObjectPage`].
     ///
     /// # Safety

+ 12 - 46
kernel/crates/rust-slabmalloc/src/pages.rs

@@ -1,11 +1,6 @@
-use alloc::boxed::Box;
-
 use crate::*;
-use core::{
-    mem,
-    sync::atomic::{AtomicU64, Ordering},
-};
-
+use alloc::boxed::Box;
+use core::sync::atomic::{AtomicU64, Ordering};
 /// A trait defining bitfield operations we need for tracking allocated objects within a page.
 pub(crate) trait Bitfield {
     fn initialize(&mut self, for_size: usize, capacity: usize);
@@ -59,9 +54,6 @@ impl Bitfield for [AtomicU64] {
         layout: Layout,
         page_size: usize,
     ) -> Option<(usize, usize)> {
-        let start_offset = get_offset_for_align(layout);
-        let data_start = base_addr + start_offset;
-
         for (base_idx, b) in self.iter().enumerate() {
             let bitval = b.load(Ordering::Relaxed);
             if bitval == u64::MAX {
@@ -79,7 +71,7 @@ impl Bitfield for [AtomicU64] {
                     return None;
                 }
 
-                let addr: usize = data_start + offset;
+                let addr: usize = base_addr + offset;
                 let alignment_ok = addr % layout.align() == 0;
                 let block_is_free = bitval & (1 << first_free) == 0;
                 if alignment_ok && block_is_free {
@@ -157,32 +149,6 @@ impl Bitfield for [AtomicU64] {
     }
 }
 
-/// # get_offset_for_align - 根据布局大小获取page内对齐偏移量
-///
-/// 这个函数根据给定的`Layout`大小确定一个合适的对齐偏移量。
-///
-/// ## 参数
-///
-/// - layout: Layout,这是需要计算对齐偏移量的布局参数。
-///
-/// ## 返回值
-///
-/// - usize: 成功时返回一个usize类型的对齐偏移量。
-fn get_offset_for_align(layout: Layout) -> usize {
-    match layout.size() {
-        0..=8 => 80,
-        9..=16 => 80,
-        17..=32 => 96,
-        33..=64 => 128,
-        65..=128 => 128,
-        129..=256 => 256,
-        257..=512 => 512,
-        513..=1024 => 1024,
-        1025..=2048 => 2048,
-        _ => panic!(),
-    }
-}
-
 /// This trait is used to define a page from which objects are allocated
 /// in an `SCAllocator`.
 ///
@@ -242,8 +208,7 @@ pub trait AllocablePage {
             ptr,
             layout
         );
-        let align_offset = get_offset_for_align(layout);
-        let page_offset = ((ptr.as_ptr() as usize) - align_offset) & (Self::SIZE - 1);
+        let page_offset = (ptr.as_ptr() as usize) & (Self::SIZE - 1);
         assert!(page_offset % layout.size() == 0);
         let idx = page_offset / layout.size();
         assert!(
@@ -282,20 +247,20 @@ pub trait AllocablePage {
 /// It is marked `repr(C)` because we rely on a well defined order of struct
 /// members (e.g., dealloc does a cast to find the bitfield).
 #[repr(C)]
+#[repr(align(4096))]
 pub struct ObjectPage<'a> {
+    /// Holds memory objects.
     #[allow(dead_code)]
-    /// A bit-field to track free/allocated memory within `data`.
-    pub(crate) bitfield: [AtomicU64; 8],
+    data: [u8; OBJECT_PAGE_SIZE - OBJECT_PAGE_METADATA_OVERHEAD],
 
     /// Next element in list (used by `PageList`).
     next: Rawlink<ObjectPage<'a>>,
     /// Previous element in  list (used by `PageList`)
     prev: Rawlink<ObjectPage<'a>>,
 
-    /// Holds memory objects.
-    data: [u8; OBJECT_PAGE_SIZE - OBJECT_PAGE_METADATA_OVERHEAD],
+    /// A bit-field to track free/allocated memory within `data`.
+    pub(crate) bitfield: [AtomicU64; 8],
 }
-
 impl<'a> ObjectPage<'a> {
     pub fn new() -> Box<ObjectPage<'a>> {
         unsafe { Box::new_uninit().assume_init() }
@@ -424,7 +389,6 @@ impl<'a, T: AllocablePage> PageList<'a, T> {
     }
 
     /// Removes `slab_page` from the list.
-    #[allow(clippy::manual_inspect)]
     pub(crate) fn pop<'b>(&'b mut self) -> Option<&'a mut T> {
         match self.head {
             None => None,
@@ -437,6 +401,8 @@ impl<'a, T: AllocablePage> PageList<'a, T> {
                 });
 
                 self.elements -= 1;
+
+                #[allow(clippy::manual_inspect)]
                 new_head.map(|node| {
                     *node.prev() = Rawlink::none();
                     *node.next() = Rawlink::none();
@@ -468,9 +434,9 @@ impl<'a, P: AllocablePage + 'a> Iterator for ObjectPageIterMut<'a, P> {
     type Item = &'a mut P;
 
     #[inline]
-    #[allow(clippy::manual_inspect)]
     fn next(&mut self) -> Option<&'a mut P> {
         unsafe {
+            #[allow(clippy::manual_inspect)]
             self.head.resolve_mut().map(|next| {
                 self.head = match next.next().resolve_mut() {
                     None => Rawlink::none(),

+ 9 - 11
kernel/crates/rust-slabmalloc/src/sc.rs

@@ -1,7 +1,5 @@
 //! A SCAllocator that can allocate fixed size objects.
 
-use core::mem;
-
 use crate::*;
 
 /// A genius(?) const min()
@@ -235,6 +233,10 @@ impl<'a, P: AllocablePage> SCAllocator<'a, P> {
             }
         }
 
+        self.free_obj_count = self
+            .free_obj_count
+            .saturating_sub(reclaimed * self.obj_per_page);
+
         reclaimed
     }
 
@@ -247,7 +249,6 @@ impl<'a, P: AllocablePage> SCAllocator<'a, P> {
             .initialize(self.size, P::SIZE - OBJECT_PAGE_METADATA_OVERHEAD);
         *page.prev() = Rawlink::none();
         *page.next() = Rawlink::none();
-        trace!("adding page to SCAllocator {:p}", page);
         self.insert_empty(page);
         self.free_obj_count += self.obj_per_page;
     }
@@ -314,15 +315,13 @@ impl<'a, P: AllocablePage> SCAllocator<'a, P> {
     /// May return an error in case an invalid `layout` is provided.
     /// The function may also move internal slab pages between lists partial -> empty
     /// or full -> partial lists.
-    ///
     /// # Safety
     /// The caller must ensure that the `layout` is valid.
     pub unsafe fn deallocate(
         &mut self,
         ptr: NonNull<u8>,
         layout: Layout,
-        slab_callback: &'static dyn CallBack,
-    ) -> Result<(), AllocationError> {
+    ) -> Result<bool, AllocationError> {
         assert!(layout.size() <= self.size);
         assert!(self.size <= (P::SIZE - OBJECT_PAGE_METADATA_OVERHEAD));
         trace!(
@@ -342,17 +341,16 @@ impl<'a, P: AllocablePage> SCAllocator<'a, P> {
 
         let ret = slab_page.deallocate(ptr, new_layout);
         debug_assert!(ret.is_ok(), "Slab page deallocate won't fail at the moment");
+
         self.free_obj_count += 1;
         let is_empty_after_dealloc = slab_page.is_empty(self.obj_per_page);
 
+        let mut need_reclaim = false;
         // 如果slab_page是空白的,且空闲块数大于free_limit,将slab_page归还buddy
         if self.free_obj_count >= self.free_limit && is_empty_after_dealloc {
-            self.slabs.remove_from_list(slab_page);
-            // 将slab_page归还buddy
-            slab_callback.free_slab_page(slab_page as *const P as *mut u8, P::SIZE);
+            need_reclaim = true;
         }
-        self.check_page_assignments();
 
-        ret
+        ret.map(|_| need_reclaim)
     }
 }

+ 582 - 0
kernel/crates/rust-slabmalloc/src/tests.rs

@@ -0,0 +1,582 @@
+use env_logger;
+use rand;
+use std::alloc;
+use std::alloc::Layout;
+use std::collections::HashSet;
+use std::mem::{size_of, transmute};
+use std::prelude::v1::*;
+
+use crate::*;
+use test::Bencher;
+
+/// A simple page allocator based on GlobalAlloc (for testing purposes).
+struct Pager {
+    base_pages: HashSet<*mut u8>, // probably should be hash-tables
+}
+
+unsafe impl Send for Pager {}
+unsafe impl Sync for Pager {}
+
+impl Pager {
+    pub fn new() -> Pager {
+        Pager {
+            base_pages: HashSet::with_capacity(1024),
+        }
+    }
+}
+
+impl Pager {
+    pub fn currently_allocated(&self) -> usize {
+        self.base_pages.len()
+    }
+
+    fn alloc_page(&mut self, page_size: usize) -> Option<*mut u8> {
+        let r =
+            unsafe { std::alloc::alloc(Layout::from_size_align(page_size, page_size).unwrap()) };
+
+        if !r.is_null() {
+            match page_size {
+                OBJECT_PAGE_SIZE => self.base_pages.insert(r),
+                _ => unreachable!("invalid page-size supplied"),
+            };
+            Some(r)
+        } else {
+            None
+        }
+    }
+
+    fn dealloc_page(&mut self, ptr: *mut u8, page_size: usize) {
+        let layout = match page_size {
+            OBJECT_PAGE_SIZE => {
+                assert!(
+                    self.base_pages.contains(&ptr),
+                    "Trying to deallocate invalid base-page"
+                );
+                self.base_pages.remove(&ptr);
+                Layout::from_size_align(OBJECT_PAGE_SIZE, OBJECT_PAGE_SIZE).unwrap()
+            }
+
+            _ => unreachable!("invalid page-size supplied"),
+        };
+
+        unsafe { std::alloc::dealloc(ptr, layout) };
+    }
+}
+
+trait PageProvider<'a>: Send {
+    fn allocate_page(&mut self) -> Option<&'a mut ObjectPage<'a>>;
+    fn release_page(&mut self, page: &'a mut ObjectPage<'a>);
+}
+
+impl<'a> PageProvider<'a> for Pager {
+    /// Allocates a new ObjectPage from the system.
+    ///
+    /// Uses `mmap` to map a page and casts it to a ObjectPage.
+    fn allocate_page(&mut self) -> Option<&'a mut ObjectPage<'a>> {
+        self.alloc_page(OBJECT_PAGE_SIZE)
+            .map(|r| unsafe { transmute(r as usize) })
+    }
+
+    /// Release a ObjectPage back to the system.slab_page
+    ///
+    /// Uses `munmap` to release the page back to the OS.
+    fn release_page(&mut self, p: &'a mut ObjectPage<'a>) {
+        self.dealloc_page(p as *const ObjectPage as *mut u8, OBJECT_PAGE_SIZE);
+    }
+}
+
+#[test]
+fn check_size() {
+    assert_eq!(
+        OBJECT_PAGE_SIZE as usize,
+        size_of::<ObjectPage>(),
+        "ObjectPage should be exactly the size of a single page."
+    );
+}
+
+#[test]
+fn test_mmap_allocator() {
+    let mut mmap = Pager::new();
+
+    match mmap.allocate_page() {
+        Some(sp) => {
+            sp.bitfield.initialize(8, OBJECT_PAGE_SIZE - 80);
+            assert!(!sp.is_full(), "Got empty slab");
+            assert!(sp.is_empty(6 * 64), "Got empty slab");
+            mmap.release_page(sp)
+        }
+        None => panic!("failed to allocate ObjectPage"),
+    }
+}
+
+macro_rules! test_sc_allocation {
+    ($test:ident, $size:expr, $alignment:expr, $allocations:expr, $type:ty) => {
+        #[test]
+        fn $test() {
+            let _ = env_logger::try_init();
+            let mut mmap = Pager::new();
+            {
+                let mut sa: SCAllocator<$type> = SCAllocator::new($size);
+                let alignment = $alignment;
+
+                let mut objects: Vec<NonNull<u8>> = Vec::new();
+                let mut vec: Vec<(usize, &mut [usize; $size / 8])> = Vec::new();
+                let layout = Layout::from_size_align($size, alignment).unwrap();
+
+                for _ in 0..$allocations {
+                    loop {
+                        match sa.allocate(layout) {
+                            // Allocation was successful
+                            Ok(nptr) => {
+                                unsafe {
+                                    vec.push((rand::random::<usize>(), transmute(nptr.as_ptr())))
+                                };
+                                objects.push(nptr);
+                                break;
+                            }
+                            // Couldn't allocate need to refill first
+                            Err(AllocationError::OutOfMemory) => {
+                                let page = mmap.allocate_page().unwrap();
+                                unsafe {
+                                    sa.refill(page);
+                                }
+                            }
+                            // Unexpected errors
+                            Err(AllocationError::InvalidLayout) => unreachable!("Unexpected error"),
+                        }
+                    }
+                }
+
+                // Write the objects with a random pattern
+                for item in vec.iter_mut() {
+                    let (pattern, ref mut obj) = *item;
+                    assert!(obj.len() == $size / 8);
+                    for i in 0..obj.len() {
+                        obj[i] = pattern;
+                    }
+                }
+
+                for item in vec.iter() {
+                    let (pattern, ref obj) = *item;
+                    for i in 0..obj.len() {
+                        assert_eq!(
+                            obj[i], pattern,
+                            "No two allocations point to the same memory."
+                        );
+                    }
+                }
+
+                // Make sure we can correctly deallocate:
+                let pages_allocated = sa.slabs.elements;
+
+                // Deallocate all the objects
+                for item in objects.iter_mut() {
+                    unsafe {
+                        sa.deallocate(*item, layout).expect("Can't deallocate");
+                    }
+                }
+
+                objects.clear();
+                sa.check_page_assignments();
+
+                // then allocate everything again,
+                for _ in 0..$allocations {
+                    loop {
+                        match sa.allocate(layout) {
+                            // Allocation was successful
+                            Ok(nptr) => {
+                                unsafe {
+                                    vec.push((rand::random::<usize>(), transmute(nptr.as_ptr())))
+                                };
+                                objects.push(nptr);
+                                break;
+                            }
+                            // Couldn't allocate need to refill first
+                            Err(AllocationError::OutOfMemory) => {
+                                let page = mmap.allocate_page().unwrap();
+                                unsafe {
+                                    sa.refill(page);
+                                }
+                            }
+                            // Unexpected errors
+                            Err(AllocationError::InvalidLayout) => unreachable!("Unexpected error"),
+                        }
+                    }
+                }
+
+                // and make sure we do not request more pages than what we had previously
+                // println!("{} {}", pages_allocated, sa.slabs.elements);
+                assert_eq!(
+                    pages_allocated, sa.slabs.elements,
+                    "Did not use more memory for 2nd allocation run."
+                );
+
+                // Deallocate everything once more
+                for item in objects.iter_mut() {
+                    unsafe {
+                        sa.deallocate(*item, layout).expect("Can't deallocate");
+                    }
+                }
+
+                // Drain the slab-allocator and give unused pages back to the OS
+                sa.try_reclaim_pages(usize::MAX, &mut |p: *mut ObjectPage| unsafe {
+                    mmap.release_page(&mut *p)
+                });
+            }
+
+            // Check that we released everything to our page allocator:
+            assert_eq!(
+                mmap.currently_allocated(),
+                0,
+                "Released all pages to the underlying memory manager."
+            );
+        }
+    };
+}
+
+test_sc_allocation!(op_512_size8_alignment1, 8, 1, 512, ObjectPage);
+test_sc_allocation!(op_4096_size8_alignment8, 8, 8, 4096, ObjectPage);
+test_sc_allocation!(op_500_size8_alignment64, 8, 64, 500, ObjectPage);
+test_sc_allocation!(op_4096_size12_alignment1, 12, 1, 4096, ObjectPage);
+test_sc_allocation!(op_4096_size13_alignment1, 13, 1, 4096, ObjectPage);
+test_sc_allocation!(op_2000_size14_alignment1, 14, 1, 2000, ObjectPage);
+test_sc_allocation!(op_4096_size15_alignment1, 15, 1, 4096, ObjectPage);
+test_sc_allocation!(op_8000_size16_alignment1, 16, 1, 8000, ObjectPage);
+test_sc_allocation!(op_1024_size24_alignment1, 24, 1, 1024, ObjectPage);
+test_sc_allocation!(op_3090_size32_alignment1, 32, 1, 3090, ObjectPage);
+test_sc_allocation!(op_4096_size64_alignment1, 64, 1, 4096, ObjectPage);
+test_sc_allocation!(op_1000_size512_alignment1, 512, 1, 1000, ObjectPage);
+test_sc_allocation!(op_4096_size1024_alignment1, 1024, 1, 4096, ObjectPage);
+test_sc_allocation!(op_10_size2048_alignment1, 2048, 1, 10, ObjectPage);
+test_sc_allocation!(op_10000_size512_alignment1, 512, 1, 10000, ObjectPage);
+
+#[test]
+#[should_panic]
+fn invalid_alignment() {
+    let _layout = Layout::from_size_align(10, 3).unwrap();
+}
+
+#[test]
+fn test_readme() -> Result<(), AllocationError> {
+    let object_size = 12;
+    let alignment = 4;
+    let layout = Layout::from_size_align(object_size, alignment).unwrap();
+
+    // We need something that can provide backing memory
+    // (4 KiB and 2 MiB pages) to our ZoneAllocator
+    // (see tests.rs for a dummy implementation).
+    let mut pager = Pager::new();
+    let page = pager.allocate_page().expect("Can't allocate a page");
+
+    let mut zone: ZoneAllocator = Default::default();
+    // Prematurely fill the ZoneAllocator with memory.
+    // Alternatively, the allocate call would return an
+    // error which we can capture to refill on-demand.
+    unsafe { zone.refill(layout, page)? };
+
+    let allocated = zone.allocate(layout)?;
+    unsafe { zone.deallocate(allocated, layout, &SlabCallback) }?;
+
+    Ok(())
+}
+
+#[test]
+fn test_readme2() -> Result<(), AllocationError> {
+    let object_size = 10;
+    let alignment = 8;
+    let layout = Layout::from_size_align(object_size, alignment).unwrap();
+
+    // We need something that can provide backing memory
+    // (4 KiB and 2 MiB pages) to our ZoneAllocator
+    // (see tests.rs for a dummy implementation).
+    let mut pager = Pager::new();
+    let page = pager.allocate_page().expect("Can't allocate a page");
+
+    let mut sa: SCAllocator<ObjectPage> = SCAllocator::new(object_size);
+    // Prematurely fill the SCAllocator with memory.
+    // Alternatively, the allocate call would return an
+    // error which we can capture to refill on-demand.
+    unsafe { sa.refill(page) };
+
+    sa.allocate(layout)?;
+    Ok(())
+}
+
+#[test]
+fn test_bug1() -> Result<(), AllocationError> {
+    let _ = env_logger::try_init();
+
+    let mut mmap = Pager::new();
+    let page = mmap.allocate_page();
+
+    let mut sa: SCAllocator<ObjectPage> = SCAllocator::new(8);
+    unsafe {
+        sa.refill(page.unwrap());
+    }
+
+    let ptr1 = sa.allocate(Layout::from_size_align(1, 1).unwrap())?;
+    let ptr2 = sa.allocate(Layout::from_size_align(2, 1).unwrap())?;
+    unsafe { sa.deallocate(ptr1, Layout::from_size_align(1, 1).unwrap()) }?;
+    let _ptr3 = sa.allocate(Layout::from_size_align(4, 1).unwrap())?;
+    unsafe {
+        sa.deallocate(ptr2, Layout::from_size_align(2, 1).unwrap())
+            .map(|_| ())
+    }
+}
+
+#[bench]
+fn slabmalloc_allocate_deallocate(b: &mut Bencher) {
+    let _ = env_logger::try_init();
+
+    let mut mmap = Pager::new();
+    let mut sa: SCAllocator<ObjectPage> = SCAllocator::new(8);
+    let layout = Layout::from_size_align(8, 1).unwrap();
+
+    let page = mmap.allocate_page();
+    unsafe {
+        sa.refill(page.unwrap());
+    }
+
+    let ptr = sa.allocate(layout).expect("Can't allocate");
+    test::black_box(ptr);
+    b.iter(|| {
+        let ptr = sa.allocate(layout).expect("Can't allocate");
+        test::black_box(ptr);
+        unsafe { sa.deallocate(ptr, layout).expect("Can't deallocate") };
+    });
+}
+
+#[bench]
+fn slabmalloc_allocate_deallocate_big(b: &mut Bencher) {
+    let _ = env_logger::try_init();
+
+    let mut mmap = Pager::new();
+    let mut sa: SCAllocator<ObjectPage> = SCAllocator::new(512);
+
+    let page = mmap.allocate_page();
+    unsafe {
+        sa.refill(page.unwrap());
+    }
+
+    let layout = Layout::from_size_align(512, 1).unwrap();
+    let ptr = sa.allocate(layout).expect("Can't allocate");
+    test::black_box(ptr);
+
+    b.iter(|| {
+        let ptr = sa.allocate(layout).expect("Can't allocate");
+        test::black_box(ptr);
+        unsafe { sa.deallocate(ptr, layout).expect("Can't deallocate") };
+    });
+}
+
+#[bench]
+fn jemalloc_allocate_deallocate(b: &mut Bencher) {
+    let layout = Layout::from_size_align(8, 1).unwrap();
+    let ptr = unsafe { alloc::alloc(layout) };
+    test::black_box(ptr);
+
+    b.iter(|| unsafe {
+        let ptr = alloc::alloc(layout);
+        test::black_box(ptr);
+        alloc::dealloc(ptr, layout);
+    });
+}
+
+#[bench]
+fn jemalloc_allocate_deallocate_big(b: &mut Bencher) {
+    let layout = Layout::from_size_align(512, 1).unwrap();
+    let ptr = unsafe { alloc::alloc(layout) };
+    test::black_box(ptr);
+
+    b.iter(|| unsafe {
+        let ptr = alloc::alloc(layout);
+        test::black_box(ptr);
+        alloc::dealloc(ptr, layout);
+    });
+}
+
+#[test]
+pub fn check_first_fit() {
+    let op: ObjectPage = Default::default();
+    let layout = Layout::from_size_align(8, 8).unwrap();
+    println!("{:?}", op.first_fit(layout));
+}
+
+#[test]
+fn list_pop() {
+    let mut op1: ObjectPage = Default::default();
+    let op1_ptr = &op1 as *const ObjectPage<'_>;
+    let mut op2: ObjectPage = Default::default();
+    let op2_ptr = &op2 as *const ObjectPage<'_>;
+    let mut op3: ObjectPage = Default::default();
+    let op3_ptr = &op3 as *const ObjectPage<'_>;
+    let mut op4: ObjectPage = Default::default();
+    let op4_ptr = &op4 as *const ObjectPage<'_>;
+
+    let mut list: PageList<ObjectPage> = PageList::new();
+    list.insert_front(&mut op1);
+    list.insert_front(&mut op2);
+    list.insert_front(&mut op3);
+
+    assert!(list.contains(op1_ptr));
+    assert!(list.contains(op2_ptr));
+    assert!(list.contains(op3_ptr));
+    assert!(!list.contains(op4_ptr));
+
+    let popped = list.pop();
+    assert_eq!(popped.unwrap() as *const ObjectPage, op3_ptr);
+    assert!(!list.contains(op3_ptr));
+
+    let popped = list.pop();
+    assert_eq!(popped.unwrap() as *const ObjectPage, op2_ptr);
+    assert!(!list.contains(op2_ptr));
+
+    list.insert_front(&mut op4);
+    assert!(list.contains(op4_ptr));
+    let popped = list.pop();
+    assert_eq!(popped.unwrap() as *const ObjectPage, op4_ptr);
+    assert!(!list.contains(op4_ptr));
+
+    let popped = list.pop();
+    assert_eq!(popped.unwrap() as *const ObjectPage, op1_ptr);
+    assert!(!list.contains(op1_ptr));
+
+    let popped = list.pop();
+    assert!(popped.is_none());
+
+    assert!(!list.contains(op1_ptr));
+    assert!(!list.contains(op2_ptr));
+    assert!(!list.contains(op3_ptr));
+    assert!(!list.contains(op4_ptr));
+}
+
+#[test]
+pub fn iter_empty_list() {
+    let mut new_head1: ObjectPage = Default::default();
+    let mut l = PageList::new();
+    l.insert_front(&mut new_head1);
+    for _p in l.iter_mut() {}
+}
+
+#[test]
+pub fn check_is_full_8() {
+    let _r = env_logger::try_init();
+    let layout = Layout::from_size_align(8, 1).unwrap();
+
+    let mut page: ObjectPage = Default::default();
+    page.bitfield.initialize(8, OBJECT_PAGE_SIZE - 80);
+    let obj_per_page = core::cmp::min((OBJECT_PAGE_SIZE - 80) / 8, 8 * 64);
+
+    let mut allocs = 0;
+    loop {
+        if page.allocate(layout).is_null() {
+            break;
+        }
+        allocs += 1;
+
+        if allocs < obj_per_page {
+            assert!(
+                !page.is_full(),
+                "Page mistakenly considered full after {} allocs",
+                allocs
+            );
+            assert!(!page.is_empty(obj_per_page));
+        }
+    }
+
+    assert_eq!(allocs, obj_per_page, "Can use all bitmap space");
+    assert!(page.is_full());
+}
+
+// Test for bug that reports pages not as full when
+// the entire bitfield wasn't allocated.
+#[test]
+pub fn check_is_full_512() {
+    let _r = env_logger::try_init();
+    let mut page: ObjectPage = Default::default();
+    page.bitfield.initialize(512, OBJECT_PAGE_SIZE - 80);
+    let layout = Layout::from_size_align(512, 1).unwrap();
+    let obj_per_page = core::cmp::min((OBJECT_PAGE_SIZE - 80) / 512, 6 * 64);
+
+    let mut allocs = 0;
+    loop {
+        if page.allocate(layout).is_null() {
+            break;
+        }
+
+        allocs += 1;
+
+        if allocs < (OBJECT_PAGE_SIZE - 80) / 512 {
+            assert!(!page.is_full());
+            assert!(!page.is_empty(obj_per_page));
+        }
+    }
+    assert!(page.is_full());
+}
+
+#[test]
+pub fn issue_9() -> Result<(), AllocationError> {
+    let mut pager = Pager::new();
+    let mut zone: ZoneAllocator = Default::default();
+
+    // size: 256 align: 1 | my pager gets called
+    let l1 = Layout::from_size_align(256, 1).unwrap();
+    assert!(zone.allocate(l1).is_err(), "my pager gets called");
+    let page = pager.allocate_page().expect("Can't allocate a page");
+    unsafe { zone.refill(l1, page)? };
+    let p1 = zone.allocate(l1)?;
+
+    // size: 48 align: 8 | my pager gets called
+    let l2 = Layout::from_size_align(48, 8).unwrap();
+    assert!(zone.allocate(l2).is_err(), "my pager gets called");
+    let page = pager.allocate_page().expect("Can't allocate a page");
+    unsafe { zone.refill(l2, page)? };
+    let p2 = zone.allocate(l2)?;
+    assert_eq!(p2.as_ptr() as usize % l2.align(), 0);
+    assert_ne!(p2, p1);
+
+    // size: 6 align: 1 | my pager gets called and returns the properly aligned address X
+    let l3 = Layout::from_size_align(6, 1).unwrap();
+    assert!(
+        zone.allocate(l3).is_err(),
+        "my pager gets called and returns the properly aligned address X"
+    );
+    let page = pager.allocate_page().expect("Can't allocate a page");
+    unsafe { zone.refill(l3, page)? };
+    let p3 = zone.allocate(l3)?;
+    assert_eq!(p3.as_ptr() as usize % l3.align(), 0);
+    assert_ne!(p3, p2);
+    assert_ne!(p3, p1);
+
+    //size: 8 align: 1 | my pager doesn't get called
+    let l4 = Layout::from_size_align(8, 1).unwrap();
+    // my pager doesn't get called
+    let p4 = zone.allocate(l4)?;
+    assert_eq!(p4.as_ptr() as usize % l4.align(), 0);
+    assert_ne!(p4, p3);
+    assert_ne!(p4, p2);
+    assert_ne!(p4, p1);
+
+    // size: 16 align: 1 | my pager gets called
+    let l5 = Layout::from_size_align(16, 1).unwrap();
+    assert!(zone.allocate(l5).is_err(), "my pager gets called");
+    let page = pager.allocate_page().expect("Can't allocate a page");
+    unsafe { zone.refill(l5, page)? };
+    let p5 = zone.allocate(l5)?;
+    assert_eq!(p5.as_ptr() as usize % l5.align(), 0);
+    assert_ne!(p5, p1);
+    assert_ne!(p5, p2);
+    assert_ne!(p5, p3);
+    assert_ne!(p5, p4);
+
+    Ok(())
+}
+
+/// 归还slab_page给buddy的回调
+struct SlabCallback;
+impl CallBack for SlabCallback {
+    unsafe fn free_slab_page(&self, base_addr: *mut u8, size: usize) {
+        assert_eq!(base_addr as usize & (OBJECT_PAGE_SIZE - 1), 0); // 确认地址4k对齐
+        assert_eq!(size, OBJECT_PAGE_SIZE); // 确认释放的slab_page大小
+    }
+}

+ 15 - 1
kernel/crates/rust-slabmalloc/src/zone.rs

@@ -120,6 +120,7 @@ impl<'a> ZoneAllocator<'a> {
             // reclaim的page数
             let just_reclaimed = slab.try_reclaim_pages(to_reclaim, &mut dealloc);
             self.total -= (just_reclaimed * OBJECT_PAGE_SIZE) as u64;
+
             to_reclaim = to_reclaim.saturating_sub(just_reclaimed);
             if to_reclaim == 0 {
                 break;
@@ -177,7 +178,20 @@ unsafe impl<'a> crate::Allocator<'a> for ZoneAllocator<'a> {
         slab_callback: &'static dyn CallBack,
     ) -> Result<(), AllocationError> {
         match ZoneAllocator::get_slab(layout.size()) {
-            Slab::Base(idx) => self.small_slabs[idx].deallocate(ptr, layout, slab_callback),
+            Slab::Base(idx) => {
+                let r = self.small_slabs[idx].deallocate(ptr, layout);
+                if let Ok(true) = r {
+                    self.small_slabs[idx].try_reclaim_pages(
+                        1,
+                        &mut |slab_page: *mut ObjectPage| {
+                            // 将slab_page归还buddy
+                            slab_callback
+                                .free_slab_page(slab_page as *const _ as *mut u8, ObjectPage::SIZE);
+                        },
+                    );
+                }
+                r.map(|_| ())
+            }
             Slab::Unsupported => Err(AllocationError::InvalidLayout),
         }
     }

+ 1 - 1
kernel/crates/system_error/Cargo.toml

@@ -7,4 +7,4 @@ edition = "2021"
 
 [dependencies]
 num-traits = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/num-traits.git", rev="1597c1c", default-features = false }
-num-derive = "0.3"
+num-derive = "0.3"

+ 32 - 12
kernel/crates/system_error/src/lib.rs

@@ -277,31 +277,51 @@ pub enum SystemError {
 
     // === 以下错误码不应该被用户态程序使用 ===
     ERESTARTSYS = 512,
+    ERESTARTNOINTR = 513,
+    /// restart if no handler
+    ERESTARTNOHAND = 514,
+
+    /// 没有对应的ioctlcmd
+    ENOIOCTLCMD = 515,
+    /// restart by calling sys restart syscall
+    ERESTART_RESTARTBLOCK = 516,
+
+    // === TODO: 这几个KVM的错误码不要放在这里 ===
+
     // VMX on 虚拟化开启指令出错
-    EVMXONFailed = 513,
+    EVMXONFailed = 1513,
     // VMX off 虚拟化关闭指令出错
-    EVMXOFFFailed = 514,
+    EVMXOFFFailed = 1514,
     // VMX VMWRITE 写入虚拟化VMCS内存出错
-    EVMWRITEFailed = 515,
-    EVMREADFailed = 516,
-    EVMPRTLDFailed = 517,
-    EVMLAUNCHFailed = 518,
-    KVM_HVA_ERR_BAD = 519,
-    /// 没有对应的ioctlcmd
-    ENOIOCTLCMD = 520,
+    EVMWRITEFailed = 1515,
+    EVMREADFailed = 1516,
+    EVMPRTLDFailed = 1517,
+    EVMLAUNCHFailed = 1518,
+    KVM_HVA_ERR_BAD = 1519,
+
+    MAXERRNO = 4095,
 }
 
 impl SystemError {
-    /// @brief 把posix错误码转换为系统错误枚举类型。
+    /// 判断一个值是否是有效的posix错误码。
+    pub fn is_valid_posix_errno<T>(val: T) -> bool
+    where
+        T: PartialOrd + From<i32>,
+    {
+        let max_errno = T::from(-(Self::MAXERRNO as i32));
+        val < T::from(0) && val >= max_errno
+    }
+
+    /// 尝试把posix错误码转换为系统错误枚举类型。
     pub fn from_posix_errno(errno: i32) -> Option<SystemError> {
         // posix 错误码是小于0的
-        if errno >= 0 {
+        if !Self::is_valid_posix_errno(errno) {
             return None;
         }
         return <Self as num_traits::FromPrimitive>::from_i32(-errno);
     }
 
-    /// @brief 把系统错误枚举类型转换为负数posix错误码。
+    /// 把系统错误枚举类型转换为负数posix错误码。
     pub fn to_posix_errno(&self) -> i32 {
         return -<Self as num_traits::ToPrimitive>::to_i32(self).unwrap();
     }

+ 7 - 1
kernel/env.mk

@@ -5,6 +5,10 @@ ifeq ($(ARCH), x86_64)
 CCPREFIX=x86_64-linux-gnu-
 else ifeq ($(ARCH), riscv64)
 CCPREFIX=riscv64-linux-gnu-
+else ifeq ($(ARCH), loongarch64)
+CCPREFIX=loongarch64-unknown-linux-gnu-
+else
+$(error "Unsupported ARCH: $(ARCH)")
 endif
 
 export CC=$(CCPREFIX)gcc
@@ -24,6 +28,8 @@ ifeq ($(ARCH), x86_64)
 GLOBAL_CFLAGS += -mcmodel=large -m64
 else ifeq ($(ARCH), riscv64)
 GLOBAL_CFLAGS += -mcmodel=medany -march=rv64gc -mabi=lp64d
+else ifeq ($(ARCH), loongarch64)
+GLOBAL_CFLAGS += -mcmodel=large -march=loongarch64
 endif
 
 ifeq ($(DEBUG), DEBUG)
@@ -31,4 +37,4 @@ GLOBAL_CFLAGS += -g
 endif
 
 export RUSTFLAGS := -C link-args=-znostart-stop-gc
-export RUSTDOCFLAGS := -C link-args=-znostart-stop-gc
+export RUSTDOCFLAGS := -C link-args=-znostart-stop-gc

+ 42 - 9
kernel/src/Makefile

@@ -10,17 +10,20 @@ LIB_FILES := $(foreach DIR,$(DIR_LIB),$(addprefix $(DIR)/,$(lib_patterns)))
 
 # unwind/backtrace related
 UNWIND_ENABLE ?= yes
+
+ifeq ($(ARCH), loongarch64)
+	UNWIND_ENABLE = no
+endif
+
 CFLAGS_UNWIND =
 LDFLAGS_UNWIND =
 RUSTFLAGS_UNWIND =
 ifeq ($(UNWIND_ENABLE), yes)
 	CFLAGS_UNWIND = -funwind-tables
 	LDFLAGS_UNWIND = --eh-frame-hdr
-	RUSTFLAGS_UNWIND = -Cforce-unwind-tables -Clink-arg=-Wl,eh_frame.ld -Cpanic=unwind
+	RUSTFLAGS +=  -Cforce-unwind-tables -Clink-arg=-Wl,eh_frame.ld -Cpanic=unwind
 endif
 
-RUSTFLAGS += $(RUSTFLAGS_UNWIND)
-
 CFLAGS = $(GLOBAL_CFLAGS) -fno-pie $(CFLAGS_UNWIND) -I $(shell pwd) -I $(shell pwd)/include
 
 ifeq ($(ARCH), x86_64)
@@ -42,12 +45,16 @@ kernel_rust:
 
 
 all: kernel
-
+	rm -f ./debug/kallsyms.o
 # if x86_64
 ifeq ($(ARCH), x86_64)
 	$(MAKE) __link_x86_64_kernel
 else ifeq ($(ARCH), riscv64)
 	$(MAKE) __link_riscv64_kernel
+else ifeq ($(ARCH), loongarch64)
+	$(MAKE) __link_loongarch64_kernel
+else
+	$(error Unknown ARCH: $(ARCH))
 endif
 	
 	@echo "Kernel Build Done."
@@ -62,8 +69,8 @@ kernel: $(kernel_subdirs) kernel_rust
 
 __link_riscv64_kernel:
 	@echo "Linking kernel..."
-	$(LD) -b elf64-littleriscv -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/riscv64gc-unknown-none-elf/release/libdragonos_kernel.a -T arch/riscv64/link.ld --no-relax
-	# 生成kallsyms
+	$(LD) -b elf64-littleriscv -z muldefs $(LDFLAGS_UNWIND) -o kernel ../target/riscv64gc-unknown-none-elf/release/libdragonos_kernel.a -T arch/riscv64/link.ld --no-relax
+# 生成kallsyms
 	current_dir=$(pwd)
 
 	@dbg='debug';for x in $$dbg; do \
@@ -75,7 +82,7 @@ __link_riscv64_kernel:
 # 重新链接
 	@echo "Re-Linking kernel..."
 	@echo $(shell find . -name "*.o")
-	$(LD) -b elf64-littleriscv -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/riscv64gc-unknown-none-elf/release/libdragonos_kernel.a ./debug/kallsyms.o  -T arch/riscv64/link.ld --no-relax
+	$(LD) -b elf64-littleriscv -z muldefs $(LDFLAGS_UNWIND) -o kernel ../target/riscv64gc-unknown-none-elf/release/libdragonos_kernel.a ./debug/kallsyms.o  -T arch/riscv64/link.ld --no-relax
 	@echo "Generating kernel ELF file..."
 
 ifeq ($(UNWIND_ENABLE), yes)
@@ -90,7 +97,7 @@ endif
 
 __link_x86_64_kernel:
 	@echo "Linking kernel..."
-	$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T arch/x86_64/link.lds --no-relax
+	$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T arch/x86_64/link.lds --no-relax
 # 生成kallsyms
 	current_dir=$(pwd)
 	
@@ -103,7 +110,7 @@ __link_x86_64_kernel:
 # 重新链接
 	@echo "Re-Linking kernel..."
 	@echo $(shell find . -name "*.o")
-	$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o  -T arch/x86_64/link.lds --no-relax
+	$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o  -T arch/x86_64/link.lds --no-relax
 	@echo "Generating kernel ELF file..."
 # 生成内核文件
 ifeq ($(UNWIND_ENABLE), yes)
@@ -113,6 +120,32 @@ else
 endif
 	rm kernel
 
+
+__link_loongarch64_kernel:
+	@echo "Linking kernel..."
+	$(LD) -b elf64-loongarch -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/loongarch64-unknown-none/release/libdragonos_kernel.a -T arch/loongarch64/link.ld --no-relax
+# 生成kallsyms
+	current_dir=$(pwd)
+	
+	@dbg='debug';for x in $$dbg; do \
+		cd $$x;\
+		$(MAKE) generate_kallsyms kernel_root_path="$(shell pwd)"||exit 1;\
+		cd ..;\
+	done
+
+# 重新链接
+	@echo "Re-Linking kernel..."
+	@echo $(shell find . -name "*.o")
+	$(LD) -b elf64-loongarch -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/loongarch64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o  -T arch/loongarch64/link.ld --no-relax
+	@echo "Generating kernel ELF file..."
+# 生成内核文件
+ifeq ($(UNWIND_ENABLE), yes)
+	$(OBJCOPY) -I elf64-loongarch -O elf64-loongarch kernel ../../bin/kernel/kernel.elf
+else
+	$(OBJCOPY) -I elf64-loongarch -O elf64-loongarch -R ".eh_frame" kernel ../../bin/kernel/kernel.elf
+endif
+	rm kernel
+
 __dragon_stub:
 	@echo "Linking dragon_stub..."
 	@mkdir -p $(ROOT_PATH)/bin/sysroot

+ 0 - 20
kernel/src/arch/arch.h

@@ -1,20 +0,0 @@
-#pragma once
-
-#define ARCH(arch) (defined(AK_ARCH_##arch) && AK_ARCH_##arch)
-
-
-#ifdef __i386__
-#    define AK_ARCH_I386 1
-#endif
-
-#ifdef __x86_64__
-#    define AK_ARCH_X86_64 1
-#endif
-
-#ifdef __riscv
-#    define AK_ARCH_riscv 1
-#endif
-
-#ifdef __riscv64
-#    define AK_ARCH_riscv64 1
-#endif

+ 14 - 0
kernel/src/arch/loongarch64/asm/bitops.rs

@@ -0,0 +1,14 @@
+/// 寻找u64中的第一个0所在的位(从第0位开始寻找)
+///
+/// 注意:如果x中没有0,那么结果将是未定义的。请确保传入的x至少存在1个0
+///
+/// # 参数
+/// * `x` - 目标u64
+///
+/// # 返回值
+/// 第一个(最低有效位)0位的位号(0..63)
+#[inline]
+#[allow(dead_code)]
+pub fn ffz(x: u64) -> i32 {
+    (!x).trailing_zeros() as i32
+}

+ 98 - 0
kernel/src/arch/loongarch64/asm/boot.rs

@@ -0,0 +1,98 @@
+///
+/// The earliest entry point for the primary CPU.
+///
+/// 这些代码拷贝、修改自 polyhal (https://github.com/Byte-OS/polyhal.git)
+use crate::arch::{cpu::current_cpu_id, init::boot::kernel_main};
+
+const QEMU_DTB_PADDR: usize = 0x100000;
+
+/// The earliest entry point for the primary CPU.
+///
+/// We can't use bl to jump to higher address, so we use jirl to jump to higher address.
+#[naked]
+#[no_mangle]
+#[link_section = ".text.entry"]
+unsafe extern "C" fn _start() -> ! {
+    core::arch::naked_asm!("
+    
+        ori         $t0, $zero, 0x1     # CSR_DMW1_PLV0
+        lu52i.d     $t0, $t0, -2048     # UC, PLV0, 0x8000 xxxx xxxx xxxx
+        csrwr       $t0, 0x180          # LOONGARCH_CSR_DMWIN0
+        ori         $t0, $zero, 0x11    # CSR_DMW1_MAT | CSR_DMW1_PLV0
+        lu52i.d     $t0, $t0, -1792     # CA, PLV0, 0x9000 xxxx xxxx xxxx
+        csrwr       $t0, 0x181          # LOONGARCH_CSR_DMWIN1
+
+        # Goto 1 if hart is not 0
+        csrrd       $t1, 0x20       # read cpu from csr
+        bnez        $t1, 1f
+
+        # Enable PG 
+        li.w		$t0, 0xb0		# PLV=0, IE=0, PG=1
+        csrwr		$t0, 0x0        # LOONGARCH_CSR_CRMD
+        li.w		$t0, 0x00		# PLV=0, PIE=0, PWE=0
+        csrwr		$t0, 0x1        # LOONGARCH_CSR_PRMD
+        li.w		$t0, 0x00		# FPE=0, SXE=0, ASXE=0, BTE=0
+        csrwr		$t0, 0x2        # LOONGARCH_CSR_EUEN
+
+    
+        la.global   $sp, {boot_stack}
+        li.d        $t0, {boot_stack_size}
+        add.d       $sp, $sp, $t0       # setup boot stack
+        csrrd       $a0, 0x20           # cpuid
+        la.global   $t0, {entry}
+        jirl        $zero,$t0,0
+    1:
+        li.w        $s0, {MBUF0}
+        iocsrrd.d   $t0, $s0
+        la.global   $t1, {sec_entry}
+        bne         $t0, $t1, 1b
+        jirl        $zero, $t1, 0
+        ",
+        boot_stack_size = const size_of_val(&crate::arch::process::BSP_IDLE_STACK_SPACE),
+        boot_stack = sym crate::arch::process::BSP_IDLE_STACK_SPACE,
+        MBUF0 = const loongArch64::consts::LOONGARCH_CSR_MAIL_BUF0,
+        entry = sym rust_tmp_main,
+        sec_entry = sym _start_secondary,
+    )
+}
+
+/// The earliest entry point for the primary CPU.
+///
+/// We can't use bl to jump to higher address, so we use jirl to jump to higher address.
+#[naked]
+#[no_mangle]
+#[link_section = ".text.entry"]
+pub(crate) unsafe extern "C" fn _start_secondary() -> ! {
+    core::arch::naked_asm!(
+        "
+        ori          $t0, $zero, 0x1     # CSR_DMW1_PLV0
+        lu52i.d      $t0, $t0, -2048     # UC, PLV0, 0x8000 xxxx xxxx xxxx
+        csrwr        $t0, 0x180          # LOONGARCH_CSR_DMWIN0
+        ori          $t0, $zero, 0x11    # CSR_DMW1_MAT | CSR_DMW1_PLV0
+        lu52i.d      $t0, $t0, -1792     # CA, PLV0, 0x9000 xxxx xxxx xxxx
+        csrwr        $t0, 0x181          # LOONGARCH_CSR_DMWIN1
+
+        li.w         $t0, {MBUF1}
+        iocsrrd.d    $sp, $t0
+
+        csrrd        $a0, 0x20                  # cpuid
+        la.global    $t0, {entry}
+
+        jirl $zero,$t0,0
+        ",
+        MBUF1 = const loongArch64::consts::LOONGARCH_CSR_MAIL_BUF1,
+        entry = sym _rust_secondary_main,
+    )
+}
+
+/// Rust temporary entry point
+///
+/// This function will be called after assembly boot stage.
+fn rust_tmp_main(hart_id: usize) {
+    unsafe { kernel_main(hart_id, QEMU_DTB_PADDR) };
+}
+
+/// The entry point for the second core.
+pub(crate) extern "C" fn _rust_secondary_main() {
+    unsafe { kernel_main(current_cpu_id().data() as usize, QEMU_DTB_PADDR) }
+}

+ 2 - 0
kernel/src/arch/loongarch64/asm/mod.rs

@@ -0,0 +1,2 @@
+pub mod bitops;
+pub mod boot;

+ 15 - 0
kernel/src/arch/loongarch64/cpu.rs

@@ -0,0 +1,15 @@
+use crate::smp::cpu::ProcessorId;
+
+/// 重置cpu
+pub unsafe fn cpu_reset() -> ! {
+    log::warn!("cpu_reset on loongarch64 platform was not implemented!");
+    loop {
+        unsafe { loongArch64::asm::idle() };
+    }
+}
+
+/// 获取当前cpu的id
+#[inline]
+pub fn current_cpu_id() -> ProcessorId {
+    ProcessorId::new(loongArch64::register::cpuid::read().core_id() as u32)
+}

+ 10 - 0
kernel/src/arch/loongarch64/elf.rs

@@ -0,0 +1,10 @@
+use crate::{arch::MMArch, libs::elf::ElfArch, mm::MemoryManagementArch};
+
+#[derive(Debug, Clone, Copy, Hash)]
+pub struct LoongArch64ElfArch;
+
+impl ElfArch for LoongArch64ElfArch {
+    const ELF_ET_DYN_BASE: usize = MMArch::USER_END_VADDR.data() / 3 * 2;
+
+    const ELF_PAGE_SIZE: usize = MMArch::PAGE_SIZE;
+}

+ 1 - 0
kernel/src/arch/loongarch64/include/asm/asm.h

@@ -0,0 +1 @@
+#pragma once

+ 54 - 0
kernel/src/arch/loongarch64/init/boot.rs

@@ -0,0 +1,54 @@
+use loongArch64::register::{ecfg, eentry};
+
+use crate::{init::init::start_kernel, mm::PhysAddr};
+
+static mut BOOT_HARTID: u32 = 0;
+static mut BOOT_FDT_PADDR: PhysAddr = PhysAddr::new(0);
+
+#[no_mangle]
+pub unsafe extern "C" fn kernel_main(hartid: usize, fdt_paddr: usize) -> ! {
+    clear_bss();
+
+    let fdt_paddr = PhysAddr::new(fdt_paddr);
+
+    unsafe {
+        BOOT_HARTID = hartid as u32;
+        BOOT_FDT_PADDR = fdt_paddr;
+    }
+    setup_trap_vector();
+    start_kernel();
+}
+
+/// 设置中断、异常处理函数
+fn setup_trap_vector() {
+    // todo!();
+    // let ptr = handle_exception as *const () as usize;
+    // ecfg::set_vs(0);
+    // eentry::set_eentry(handle_exception as usize);
+}
+
+/// Clear the bss section
+fn clear_bss() {
+    extern "C" {
+        fn _bss();
+        fn _ebss();
+    }
+    unsafe {
+        let bss_start = _bss as *mut u8;
+        let bss_end = _ebss as *mut u8;
+        let bss_size = bss_end as usize - bss_start as usize;
+
+        // Clear in chunks of u128 for efficiency
+        let u128_count = bss_size / core::mem::size_of::<u128>();
+        let u128_slice = core::slice::from_raw_parts_mut(bss_start as *mut u128, u128_count);
+        u128_slice.fill(0);
+
+        // Clear any remaining bytes
+        let remaining_bytes = bss_size % core::mem::size_of::<u128>();
+        if remaining_bytes > 0 {
+            let remaining_start = bss_start.add(u128_count * core::mem::size_of::<u128>());
+            let remaining_slice = core::slice::from_raw_parts_mut(remaining_start, remaining_bytes);
+            remaining_slice.fill(0);
+        }
+    }
+}

+ 24 - 0
kernel/src/arch/loongarch64/init/mod.rs

@@ -0,0 +1,24 @@
+use system_error::SystemError;
+pub mod boot;
+
+#[derive(Debug)]
+pub struct ArchBootParams {}
+
+impl ArchBootParams {
+    pub const DEFAULT: Self = ArchBootParams {};
+}
+
+#[inline(never)]
+pub fn early_setup_arch() -> Result<(), SystemError> {
+    todo!("la64:early_setup_arch");
+}
+
+#[inline(never)]
+pub fn setup_arch() -> Result<(), SystemError> {
+    todo!("la64:setup_arch");
+}
+
+#[inline(never)]
+pub fn setup_arch_post() -> Result<(), SystemError> {
+    todo!("la64:setup_arch_post");
+}

+ 6 - 0
kernel/src/arch/loongarch64/interrupt/ipi.rs

@@ -0,0 +1,6 @@
+use crate::exception::ipi::{IpiKind, IpiTarget};
+
+#[inline(always)]
+pub fn send_ipi(kind: IpiKind, target: IpiTarget) {
+    todo!("la64: send_ipi")
+}

+ 123 - 0
kernel/src/arch/loongarch64/interrupt/mod.rs

@@ -0,0 +1,123 @@
+pub mod ipi;
+
+use core::any::Any;
+
+use kprobe::ProbeArgs;
+use loongArch64::register::CpuMode;
+
+use crate::exception::{InterruptArch, IrqFlags, IrqFlagsGuard, IrqNumber};
+
+pub struct LoongArch64InterruptArch;
+
+impl InterruptArch for LoongArch64InterruptArch {
+    unsafe fn arch_irq_init() -> Result<(), system_error::SystemError> {
+        todo!("arch_irq_init() not implemented for LoongArch64InterruptArch")
+    }
+
+    unsafe fn interrupt_enable() {
+        loongArch64::register::crmd::set_ie(true);
+    }
+
+    unsafe fn interrupt_disable() {
+        loongArch64::register::crmd::set_ie(false);
+    }
+
+    fn is_irq_enabled() -> bool {
+        loongArch64::register::crmd::read().ie()
+    }
+
+    unsafe fn save_and_disable_irq() -> IrqFlagsGuard {
+        let ie = loongArch64::register::crmd::read().ie();
+        loongArch64::register::crmd::set_ie(false);
+        IrqFlagsGuard::new(IrqFlags::new(if ie { 1 } else { 0 }))
+    }
+
+    unsafe fn restore_irq(flags: IrqFlags) {
+        loongArch64::register::crmd::set_ie(flags.flags() == 1);
+    }
+
+    fn probe_total_irq_num() -> u32 {
+        todo!("probe_total_irq_num() not implemented for LoongArch64InterruptArch")
+    }
+
+    fn ack_bad_irq(irq: IrqNumber) {
+        todo!("ack_bad_irq() not implemented for LoongArch64InterruptArch")
+    }
+}
+
+/// 中断栈帧结构体
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct TrapFrame {
+    pub r0: usize,  // 0*8
+    pub ra: usize,  // 1*8
+    pub tp: usize,  // 2*8
+    pub usp: usize, // 3*8 (user stack pointer)
+    pub a0: usize,  // 4*8
+    pub a1: usize,  // 5*8
+    pub a2: usize,  // 6*8
+    pub a3: usize,  // 7*8
+    pub a4: usize,  // 8*8
+    pub a5: usize,  // 9*8
+    pub a6: usize,  // 10*8
+    pub a7: usize,  // 11*8
+    pub t0: usize,  // 12*8
+    pub t1: usize,  // 13*8
+    pub t2: usize,  // 14*8
+    pub t3: usize,  // 15*8
+    pub t4: usize,  // 16*8
+    pub t5: usize,  // 17*8
+    pub t6: usize,  // 18*8
+    pub t7: usize,  // 19*8
+    pub t8: usize,  // 20*8
+    pub r21: usize, // 21*8
+    pub fp: usize,  // 22*8
+    pub s0: usize,  // 23*8
+    pub s1: usize,  // 24*8
+    pub s2: usize,  // 25*8
+    pub s3: usize,  // 26*8
+    pub s4: usize,  // 27*8
+    pub s5: usize,  // 28*8
+    pub s6: usize,  // 29*8
+    pub s7: usize,  // 30*8
+    pub s8: usize,  // 31*8
+    /// original syscall arg0
+    pub orig_a0: usize,
+
+    pub csr_era: usize,
+    pub csr_badvaddr: usize,
+    pub csr_crmd: usize,
+    pub csr_prmd: usize,
+    pub csr_euen: usize,
+    pub csr_ecfg: usize,
+    pub csr_estat: usize,
+}
+
+impl TrapFrame {
+    /// 中断栈帧结构体的大小
+    pub const SIZE: usize = core::mem::size_of::<TrapFrame>();
+
+    /// 判断当前中断是否来自用户模式
+    pub fn is_from_user(&self) -> bool {
+        loongArch64::register::crmd::Crmd::from(self.csr_crmd).plv() == CpuMode::Ring3
+    }
+
+    #[inline(never)]
+    pub const fn new() -> Self {
+        let x = core::mem::MaybeUninit::<Self>::zeroed();
+        unsafe { x.assume_init() }
+    }
+}
+
+impl ProbeArgs for TrapFrame {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+    fn break_address(&self) -> usize {
+        todo!("TrapFrame::break_address()")
+    }
+
+    fn debug_address(&self) -> usize {
+        todo!("TrapFrame::debug_address()")
+    }
+}

+ 1 - 0
kernel/src/arch/loongarch64/ipc/mod.rs

@@ -0,0 +1 @@
+pub mod signal;

+ 64 - 0
kernel/src/arch/loongarch64/ipc/signal.rs

@@ -0,0 +1,64 @@
+use crate::arch::interrupt::TrapFrame;
+pub use crate::ipc::generic_signal::AtomicGenericSignal as AtomicSignal;
+pub use crate::ipc::generic_signal::GenericSigChildCode as SigChildCode;
+pub use crate::ipc::generic_signal::GenericSigSet as SigSet;
+pub use crate::ipc::generic_signal::GenericSignal as Signal;
+pub use crate::ipc::generic_signal::GENERIC_MAX_SIG_NUM as MAX_SIG_NUM;
+pub use crate::ipc::generic_signal::GENERIC_STACK_ALIGN as STACK_ALIGN;
+
+pub use crate::ipc::generic_signal::GenericSigFlags as SigFlags;
+
+use crate::ipc::signal_types::SignalArch;
+
+pub struct LoongArch64SignalArch;
+
+impl SignalArch for LoongArch64SignalArch {
+    // TODO: 为LoongArch64实现信号处理
+    // 注意,la64现在在中断/系统调用返回用户态时,没有进入 irqentry_exit() 函数,
+    // 到时候实现信号处理时,需要修改中断/系统调用返回用户态的代码,进入 irqentry_exit() 函数
+    unsafe fn do_signal_or_restart(_frame: &mut TrapFrame) {
+        todo!("la64:do_signal_or_restart")
+    }
+
+    fn sys_rt_sigreturn(_trap_frame: &mut TrapFrame) -> u64 {
+        todo!("la64:sys_rt_sigreturn")
+    }
+}
+
+/// siginfo中的si_code的可选值
+/// 请注意,当这个值小于0时,表示siginfo来自用户态,否则来自内核态
+#[derive(Copy, Debug, Clone)]
+#[repr(i32)]
+pub enum SigCode {
+    /// sent by kill, sigsend, raise
+    User = 0,
+    /// sent by kernel from somewhere
+    Kernel = 0x80,
+    /// 通过sigqueue发送
+    Queue = -1,
+    /// 定时器过期时发送
+    Timer = -2,
+    /// 当实时消息队列的状态发生改变时发送
+    Mesgq = -3,
+    /// 当异步IO完成时发送
+    AsyncIO = -4,
+    /// sent by queued SIGIO
+    SigIO = -5,
+}
+
+impl SigCode {
+    /// 为SigCode这个枚举类型实现从i32转换到枚举类型的转换函数
+    #[allow(dead_code)]
+    pub fn from_i32(x: i32) -> SigCode {
+        match x {
+            0 => Self::User,
+            0x80 => Self::Kernel,
+            -1 => Self::Queue,
+            -2 => Self::Timer,
+            -3 => Self::Mesgq,
+            -4 => Self::AsyncIO,
+            -5 => Self::SigIO,
+            _ => panic!("signal code not valid"),
+        }
+    }
+}

+ 19 - 0
kernel/src/arch/loongarch64/kprobe.rs

@@ -0,0 +1,19 @@
+use crate::arch::interrupt::TrapFrame;
+
+pub fn setup_single_step(frame: &mut TrapFrame, step_addr: usize) {
+    todo!("la64: setup_single_step")
+}
+
+pub fn clear_single_step(frame: &mut TrapFrame, return_addr: usize) {
+    todo!("la64: clear_single_step")
+}
+
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct KProbeContext {}
+
+impl From<&TrapFrame> for KProbeContext {
+    fn from(trap_frame: &TrapFrame) -> Self {
+        todo!("from trap frame to kprobe context");
+    }
+}

+ 114 - 0
kernel/src/arch/loongarch64/link.ld

@@ -0,0 +1,114 @@
+OUTPUT_FORMAT(
+    "elf64-loongarch",
+    "elf64-loongarch",
+    "elf64-loongarch"
+)
+
+OUTPUT_ARCH(loongarch)
+ENTRY(_start)
+
+
+SECTIONS
+{
+	KERNEL_VMA = 0x9000000000200000;
+	. = KERNEL_VMA;
+	. = ALIGN(4096);
+	boot_text_start_pa = .;
+	.boot.text :
+	{
+		KEEP(*(.bootstrap))
+		*(.bootstrap)
+		*(.bootstrap.*)
+		. = ALIGN(4096);
+		*(.initial_pgtable_section)
+		. = ALIGN(4096);
+	}
+
+
+	. = ALIGN(4096);
+	text_start_pa = .;
+	__executable_start = .;
+	.text (text_start_pa): 
+	{
+		_text = .;
+
+		/* any files' .text */
+		*(.text)
+
+		/* any files' .text.*, for example: rust .text._ZN* */
+		*(.text.*)
+
+		_etext = .;
+		__etext = .;
+	}
+	. = ALIGN(32768);
+	data_start_pa = .;
+	.data (data_start_pa):
+	{
+		_data = .;
+		*(.data)
+		*(.data.*)
+		*(.got.plt)
+   		*(.got)
+		_edata = .;
+	}
+
+	. = ALIGN(32768);
+
+	rodata_start_pa = .;
+	.rodata (rodata_start_pa):
+	{
+		_rodata = .;	
+		*(.rodata)
+		*(.rodata.*)
+		*(.gcc_except_table .gcc_except_table.*)
+		_erodata = .;
+	}
+
+	. = ALIGN(32768);
+	
+	trace_point_start_pa = .;
+	.tracepoint (trace_point_start_pa): AT(trace_point_start_pa - KERNEL_VMA)
+    {
+        _tracepoint = .;
+        *(.tracepoint)
+        *(.tracepoint.*)
+        _etracepoint = .;
+    }
+    . = ALIGN(32768);
+
+	init_proc_union_start_pa = .;
+	.data.init_proc_union (init_proc_union_start_pa):
+	 { *(.data.init_proc_union) }
+
+	. = ALIGN(32768);
+	 bss_start_pa = .;
+	.bss (bss_start_pa):
+	{
+		_bss = .;
+		*(.bss)
+		*(.bss.*)
+		*(.sbss)
+		*(.sbss.*)
+		_ebss = .;
+	}
+
+	eh_frame = .;
+	.eh_frame (eh_frame):
+	{
+		__eh_frame_hdr_start = .;
+		*(.eh_frame_hdr)
+		__eh_frame_hdr_end = .;
+		__eh_frame_start = .;
+		*(.eh_frame)
+		*(.rela.eh_frame)
+		__eh_frame_end = .;
+	}
+
+	_end = .;
+
+	/DISCARD/ : {
+		/* *(.eh_frame) */
+		
+	}
+}

+ 21 - 0
kernel/src/arch/loongarch64/loongarch64-unknown-none.json

@@ -0,0 +1,21 @@
+{
+    "arch": "loongarch64",
+    "code-model": "medium",
+    "crt-objects-fallback": "false",
+    "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128",
+    "features": "+f,+d",
+    "linker": "rust-lld",
+    "linker-flavor": "gnu-lld",
+    "llvm-abiname": "lp64d",
+    "llvm-target": "loongarch64-unknown-none",
+    "max-atomic-width": 64,
+    "metadata": {
+        "description": "Freestanding/bare-metal LoongArch64",
+        "host_tools": false,
+        "std": false,
+        "tier": 2
+    },
+    "panic-strategy": "abort",
+    "relocation-model": "static",
+    "target-pointer-width": "64"
+}

+ 7 - 0
kernel/src/arch/loongarch64/mm/bump.rs

@@ -0,0 +1,7 @@
+use crate::mm::{allocator::bump::BumpAllocator, MemoryManagementArch, PhysMemoryArea};
+
+impl<MMA: MemoryManagementArch> BumpAllocator<MMA> {
+    pub unsafe fn arch_remain_areas(_ret_areas: &mut [PhysMemoryArea], res_count: usize) -> usize {
+        todo!("la64: arch_remain_areas")
+    }
+}

+ 207 - 0
kernel/src/arch/loongarch64/mm/mod.rs

@@ -0,0 +1,207 @@
+pub mod bump;
+
+use crate::mm::{
+    allocator::page_frame::{FrameAllocator, PageFrameCount, PageFrameUsage},
+    page::EntryFlags,
+    MemoryManagementArch, PhysAddr, VirtAddr, VmFlags,
+};
+
+use crate::arch::MMArch;
+
+pub type PageMapper = crate::mm::page::PageMapper<LoongArch64MMArch, LockedFrameAllocator>;
+
+/// LoongArch64的内存管理架构结构体
+#[derive(Debug, Clone, Copy, Hash)]
+pub struct LoongArch64MMArch;
+
+impl MemoryManagementArch for LoongArch64MMArch {
+    const PAGE_FAULT_ENABLED: bool = false;
+
+    const PAGE_SHIFT: usize = 0;
+
+    const PAGE_ENTRY_SHIFT: usize = 0;
+
+    const PAGE_LEVELS: usize = 0;
+
+    const ENTRY_ADDRESS_SHIFT: usize = 0;
+
+    const ENTRY_FLAG_DEFAULT_PAGE: usize = 0;
+
+    const ENTRY_FLAG_DEFAULT_TABLE: usize = 0;
+
+    const ENTRY_FLAG_PRESENT: usize = 0;
+
+    const ENTRY_FLAG_READONLY: usize = 0;
+
+    const ENTRY_FLAG_WRITEABLE: usize = 0;
+
+    const ENTRY_FLAG_READWRITE: usize = 0;
+
+    const ENTRY_FLAG_USER: usize = 0;
+
+    const ENTRY_FLAG_WRITE_THROUGH: usize = 0;
+
+    const ENTRY_FLAG_CACHE_DISABLE: usize = 0;
+
+    const ENTRY_FLAG_NO_EXEC: usize = 0;
+
+    const ENTRY_FLAG_EXEC: usize = 0;
+
+    const ENTRY_FLAG_DIRTY: usize = 0;
+
+    const ENTRY_FLAG_ACCESSED: usize = 0;
+
+    const ENTRY_FLAG_HUGE_PAGE: usize = 0;
+
+    const ENTRY_FLAG_GLOBAL: usize = 0;
+
+    const PHYS_OFFSET: usize = 0x9000_0000_0000_0000;
+
+    const KERNEL_LINK_OFFSET: usize = 0;
+
+    const USER_END_VADDR: crate::mm::VirtAddr = VirtAddr::new(0);
+
+    const USER_BRK_START: crate::mm::VirtAddr = VirtAddr::new(0);
+
+    const USER_STACK_START: crate::mm::VirtAddr = VirtAddr::new(0);
+
+    const FIXMAP_START_VADDR: crate::mm::VirtAddr = VirtAddr::new(0);
+
+    const FIXMAP_SIZE: usize = 0;
+
+    const MMIO_BASE: crate::mm::VirtAddr = VirtAddr::new(0);
+
+    const MMIO_SIZE: usize = 0;
+
+    const PAGE_NONE: usize = 0;
+
+    const PAGE_SHARED: usize = 0;
+
+    const PAGE_SHARED_EXEC: usize = 0;
+
+    const PAGE_COPY_NOEXEC: usize = 0;
+
+    const PAGE_COPY_EXEC: usize = 0;
+
+    const PAGE_COPY: usize = 0;
+
+    const PAGE_READONLY: usize = 0;
+
+    const PAGE_READONLY_EXEC: usize = 0;
+
+    const PAGE_READ: usize = 0;
+
+    const PAGE_READ_EXEC: usize = 0;
+
+    const PAGE_WRITE: usize = 0;
+
+    const PAGE_WRITE_EXEC: usize = 0;
+
+    const PAGE_EXEC: usize = 0;
+
+    const PROTECTION_MAP: [crate::mm::page::EntryFlags<Self>; 16] = protection_map();
+
+    unsafe fn init() {
+        todo!()
+    }
+
+    unsafe fn invalidate_page(address: crate::mm::VirtAddr) {
+        todo!()
+    }
+
+    unsafe fn invalidate_all() {
+        todo!()
+    }
+
+    unsafe fn table(table_kind: crate::mm::PageTableKind) -> crate::mm::PhysAddr {
+        todo!()
+    }
+
+    unsafe fn set_table(table_kind: crate::mm::PageTableKind, table: crate::mm::PhysAddr) {
+        todo!()
+    }
+
+    fn virt_is_valid(virt: crate::mm::VirtAddr) -> bool {
+        todo!()
+    }
+
+    fn initial_page_table() -> crate::mm::PhysAddr {
+        todo!()
+    }
+
+    fn setup_new_usermapper() -> Result<crate::mm::ucontext::UserMapper, system_error::SystemError>
+    {
+        todo!()
+    }
+
+    fn make_entry(paddr: crate::mm::PhysAddr, page_flags: usize) -> usize {
+        todo!()
+    }
+}
+
+/// 获取内核地址默认的页面标志
+pub unsafe fn kernel_page_flags<A: MemoryManagementArch>(_virt: VirtAddr) -> EntryFlags<A> {
+    EntryFlags::from_data(LoongArch64MMArch::ENTRY_FLAG_DEFAULT_PAGE)
+        .set_user(false)
+        .set_execute(true)
+}
+
+/// 全局的页帧分配器
+#[derive(Debug, Clone, Copy, Hash)]
+pub struct LockedFrameAllocator;
+
+impl FrameAllocator for LockedFrameAllocator {
+    unsafe fn allocate(&mut self, count: PageFrameCount) -> Option<(PhysAddr, PageFrameCount)> {
+        todo!("LockedFrameAllocator::allocate")
+    }
+
+    unsafe fn free(&mut self, address: PhysAddr, count: PageFrameCount) {
+        todo!("LockedFrameAllocator::free")
+    }
+
+    unsafe fn usage(&self) -> PageFrameUsage {
+        todo!("LockedFrameAllocator::usage")
+    }
+}
+
+/// 获取保护标志的映射表
+///
+///
+/// ## 返回值
+/// - `[usize; 16]`: 长度为16的映射表
+const fn protection_map() -> [EntryFlags<MMArch>; 16] {
+    let mut map = [unsafe { EntryFlags::from_data(0) }; 16];
+    unsafe {
+        map[VmFlags::VM_NONE.bits()] = EntryFlags::from_data(MMArch::PAGE_NONE);
+        map[VmFlags::VM_READ.bits()] = EntryFlags::from_data(MMArch::PAGE_READONLY);
+        map[VmFlags::VM_WRITE.bits()] = EntryFlags::from_data(MMArch::PAGE_COPY);
+        map[VmFlags::VM_WRITE.bits() | VmFlags::VM_READ.bits()] =
+            EntryFlags::from_data(MMArch::PAGE_COPY);
+        map[VmFlags::VM_EXEC.bits()] = EntryFlags::from_data(MMArch::PAGE_READONLY_EXEC);
+        map[VmFlags::VM_EXEC.bits() | VmFlags::VM_READ.bits()] =
+            EntryFlags::from_data(MMArch::PAGE_READONLY_EXEC);
+        map[VmFlags::VM_EXEC.bits() | VmFlags::VM_WRITE.bits()] =
+            EntryFlags::from_data(MMArch::PAGE_COPY_EXEC);
+        map[VmFlags::VM_EXEC.bits() | VmFlags::VM_WRITE.bits() | VmFlags::VM_READ.bits()] =
+            EntryFlags::from_data(MMArch::PAGE_COPY_EXEC);
+        map[VmFlags::VM_SHARED.bits()] = EntryFlags::from_data(MMArch::PAGE_NONE);
+        map[VmFlags::VM_SHARED.bits() | VmFlags::VM_READ.bits()] =
+            EntryFlags::from_data(MMArch::PAGE_READONLY);
+        map[VmFlags::VM_SHARED.bits() | VmFlags::VM_WRITE.bits()] =
+            EntryFlags::from_data(MMArch::PAGE_SHARED);
+        map[VmFlags::VM_SHARED.bits() | VmFlags::VM_WRITE.bits() | VmFlags::VM_READ.bits()] =
+            EntryFlags::from_data(MMArch::PAGE_SHARED);
+        map[VmFlags::VM_SHARED.bits() | VmFlags::VM_EXEC.bits()] =
+            EntryFlags::from_data(MMArch::PAGE_READONLY_EXEC);
+        map[VmFlags::VM_SHARED.bits() | VmFlags::VM_EXEC.bits() | VmFlags::VM_READ.bits()] =
+            EntryFlags::from_data(MMArch::PAGE_READONLY_EXEC);
+        map[VmFlags::VM_SHARED.bits() | VmFlags::VM_EXEC.bits() | VmFlags::VM_WRITE.bits()] =
+            EntryFlags::from_data(MMArch::PAGE_SHARED_EXEC);
+        map[VmFlags::VM_SHARED.bits()
+            | VmFlags::VM_EXEC.bits()
+            | VmFlags::VM_WRITE.bits()
+            | VmFlags::VM_READ.bits()] = EntryFlags::from_data(MMArch::PAGE_SHARED_EXEC);
+    }
+
+    map
+}

+ 30 - 0
kernel/src/arch/loongarch64/mod.rs

@@ -0,0 +1,30 @@
+pub mod asm;
+pub mod cpu;
+pub mod elf;
+pub mod init;
+pub mod interrupt;
+pub mod ipc;
+pub mod kprobe;
+pub mod mm;
+pub mod msi;
+pub mod pci;
+pub mod pio;
+pub mod process;
+pub mod rand;
+pub mod sched;
+pub mod smp;
+pub mod syscall;
+pub mod time;
+
+pub use self::elf::LoongArch64ElfArch as CurrentElfArch;
+pub use self::interrupt::LoongArch64InterruptArch as CurrentIrqArch;
+pub use self::ipc::signal::LoongArch64SignalArch as CurrentSignalArch;
+pub use self::mm::LoongArch64MMArch as MMArch;
+pub use self::pci::LoongArch64PciArch as PciArch;
+pub use self::pio::LoongArch64PortIOArch as CurrentPortIOArch;
+pub use self::sched::LoongArch64SchedArch as CurrentSchedArch;
+pub use self::smp::LoongArch64SMPArch as CurrentSMPArch;
+pub use self::time::LoongArch64TimeArch as CurrentTimeArch;
+
+pub fn panic_pre_work() {}
+pub fn panic_post_work() {}

+ 24 - 0
kernel/src/arch/loongarch64/msi.rs

@@ -0,0 +1,24 @@
+use crate::driver::pci::pci_irq::TriggerMode;
+
+/// 获得MSI Message Address
+///
+/// # 参数
+/// - `processor`: 目标CPU ID号
+///
+/// # 返回值
+/// MSI Message Address
+pub fn arch_msi_message_address(_processor: u16) -> u32 {
+    unimplemented!("loongarch64::arch_msi_message_address()")
+}
+/// 获得MSI Message Data
+///
+/// # 参数
+/// - `vector`: 分配的中断向量号
+/// - `processor`: 目标CPU ID号
+/// - `trigger`: 申请中断的触发模式,MSI默认为边沿触发
+///
+/// # 返回值
+/// MSI Message Address
+pub fn arch_msi_message_data(_vector: u16, _processor: u16, _trigger: TriggerMode) -> u32 {
+    unimplemented!("loongarch64::arch_msi_message_data()")
+}

+ 20 - 0
kernel/src/arch/loongarch64/pci/mod.rs

@@ -0,0 +1,20 @@
+use crate::{
+    arch::TraitPciArch,
+    driver::pci::pci::{BusDeviceFunction, PciAddr},
+    mm::PhysAddr,
+};
+
+pub struct LoongArch64PciArch;
+impl TraitPciArch for LoongArch64PciArch {
+    fn read_config(_bus_device_function: &BusDeviceFunction, _offset: u8) -> u32 {
+        unimplemented!("LoongArch64PciArch::read_config")
+    }
+
+    fn write_config(_bus_device_function: &BusDeviceFunction, _offset: u8, _data: u32) {
+        unimplemented!("LoongArch64PciArch pci_root_0().write_config")
+    }
+
+    fn address_pci_to_physical(pci_address: PciAddr) -> crate::mm::PhysAddr {
+        return PhysAddr::new(pci_address.data());
+    }
+}

+ 35 - 0
kernel/src/arch/loongarch64/pio.rs

@@ -0,0 +1,35 @@
+use crate::arch::io::PortIOArch;
+
+pub struct LoongArch64PortIOArch;
+
+impl PortIOArch for LoongArch64PortIOArch {
+    #[inline(always)]
+    unsafe fn in8(_port: u16) -> u8 {
+        unimplemented!("LoongArch64PortIOArch::in8")
+    }
+
+    #[inline(always)]
+    unsafe fn in16(_port: u16) -> u16 {
+        unimplemented!("LoongArch64PortIOArch::in16")
+    }
+
+    #[inline(always)]
+    unsafe fn in32(_port: u16) -> u32 {
+        unimplemented!("LoongArch64PortIOArch::in32")
+    }
+
+    #[inline(always)]
+    unsafe fn out8(_port: u16, _data: u8) {
+        unimplemented!("LoongArch64PortIOArch::out8")
+    }
+
+    #[inline(always)]
+    unsafe fn out16(_port: u16, _data: u16) {
+        unimplemented!("LoongArch64PortIOArch::out16")
+    }
+
+    #[inline(always)]
+    unsafe fn out32(_port: u16, _data: u32) {
+        unimplemented!("LoongArch64PortIOArch::out32")
+    }
+}

+ 31 - 0
kernel/src/arch/loongarch64/process/idle.rs

@@ -0,0 +1,31 @@
+use core::hint::spin_loop;
+
+use log::error;
+
+use crate::{
+    arch::CurrentIrqArch,
+    exception::InterruptArch,
+    process::{ProcessFlags, ProcessManager},
+    sched::{SchedMode, __schedule},
+};
+
+impl ProcessManager {
+    /// 每个核的idle进程
+    pub fn arch_idle_func() -> ! {
+        loop {
+            let pcb = ProcessManager::current_pcb();
+            if pcb.flags().contains(ProcessFlags::NEED_SCHEDULE) {
+                __schedule(SchedMode::SM_NONE);
+            }
+            if CurrentIrqArch::is_irq_enabled() {
+                todo!("la64: arch_idle_func");
+                // unsafe {
+                //     x86::halt();
+                // }
+            } else {
+                error!("Idle process should not be scheduled with IRQs disabled.");
+                spin_loop();
+            }
+        }
+    }
+}

+ 27 - 0
kernel/src/arch/loongarch64/process/kthread.rs

@@ -0,0 +1,27 @@
+use system_error::SystemError;
+
+use alloc::sync::Arc;
+
+use crate::process::{
+    fork::CloneFlags,
+    kthread::{KernelThreadCreateInfo, KernelThreadMechanism},
+    Pid,
+};
+
+impl KernelThreadMechanism {
+    /// 伪造trapframe,创建内核线程
+    ///
+    /// ## 返回值
+    ///
+    /// 返回创建的内核线程的pid
+    pub fn __inner_create(
+        info: &Arc<KernelThreadCreateInfo>,
+        clone_flags: CloneFlags,
+    ) -> Result<Pid, SystemError> {
+        // WARNING: If create failed, we must drop the info manually or it will cause memory leak. (refcount will not decrease when create failed)
+        let create_info: *const KernelThreadCreateInfo =
+            KernelThreadCreateInfo::generate_unsafe_arc_ptr(info.clone());
+
+        todo!("la64:__inner_create()")
+    }
+}

+ 90 - 0
kernel/src/arch/loongarch64/process/mod.rs

@@ -0,0 +1,90 @@
+use alloc::sync::Arc;
+use system_error::SystemError;
+
+use crate::{
+    arch::CurrentIrqArch,
+    exception::InterruptArch,
+    mm::VirtAddr,
+    process::{fork::KernelCloneArgs, KernelStack, ProcessControlBlock, ProcessManager},
+};
+
+use super::interrupt::TrapFrame;
+
+pub mod idle;
+pub mod kthread;
+pub mod syscall;
+
+#[repr(align(32768))]
+pub union InitProcUnion {
+    /// 用于存放idle进程的内核栈
+    idle_stack: [u8; 32768],
+}
+
+#[link_section = ".data.init_proc_union"]
+#[no_mangle]
+pub(super) static BSP_IDLE_STACK_SPACE: InitProcUnion = InitProcUnion {
+    idle_stack: [0; 32768],
+};
+
+pub unsafe fn arch_switch_to_user(trap_frame: TrapFrame) -> ! {
+    // 以下代码不能发生中断
+    CurrentIrqArch::interrupt_disable();
+
+    todo!("la64: arch_switch_to_user")
+}
+
+/// PCB中与架构相关的信息
+#[derive(Debug, Clone, Copy)]
+#[allow(dead_code)]
+#[repr(C)]
+pub struct ArchPCBInfo {}
+
+impl ArchPCBInfo {
+    /// 创建一个新的ArchPCBInfo
+    ///
+    /// ## 参数
+    ///
+    /// - `kstack`:内核栈的引用
+    ///
+    /// ## 返回值
+    ///
+    /// 返回一个新的ArchPCBInfo
+    pub fn new(kstack: &KernelStack) -> Self {
+        todo!("la64: ArchPCBInfo::new")
+    }
+}
+
+impl ProcessControlBlock {
+    /// 获取当前进程的pcb
+    pub fn arch_current_pcb() -> Arc<Self> {
+        todo!("la64: arch_current_pcb")
+    }
+}
+
+impl ProcessManager {
+    pub fn arch_init() {
+        // do nothing
+    }
+    /// fork的过程中复制线程
+    ///
+    /// 由于这个过程与具体的架构相关,所以放在这里
+    pub fn copy_thread(
+        current_pcb: &Arc<ProcessControlBlock>,
+        new_pcb: &Arc<ProcessControlBlock>,
+        clone_args: &KernelCloneArgs,
+        current_trapframe: &TrapFrame,
+    ) -> Result<(), SystemError> {
+        todo!("la64: copy_thread")
+    }
+
+    /// 切换进程
+    ///
+    /// ## 参数
+    ///
+    /// - `prev`:上一个进程的pcb
+    /// - `next`:下一个进程的pcb
+    pub unsafe fn switch_process(prev: Arc<ProcessControlBlock>, next: Arc<ProcessControlBlock>) {
+        assert!(!CurrentIrqArch::is_irq_enabled());
+        todo!("la64: switch_process");
+    }
+}

+ 28 - 0
kernel/src/arch/loongarch64/process/syscall.rs

@@ -0,0 +1,28 @@
+use system_error::SystemError;
+
+use crate::{
+    arch::interrupt::TrapFrame,
+    mm::VirtAddr,
+    process::{
+        exec::{BinaryLoaderResult, ExecParam},
+        ProcessManager,
+    },
+    syscall::Syscall,
+};
+
+impl Syscall {
+    pub fn arch_do_execve(
+        regs: &mut TrapFrame,
+        param: &ExecParam,
+        load_result: &BinaryLoaderResult,
+        user_sp: VirtAddr,
+        argv_ptr: VirtAddr,
+    ) -> Result<(), SystemError> {
+        todo!("la64:arch_do_execve not unimplemented");
+    }
+
+    /// ## 用于控制和查询与体系结构相关的进程特定选项
+    pub fn arch_prctl(option: usize, arg2: usize) -> Result<usize, SystemError> {
+        todo!("la64:arch_prctl")
+    }
+}

+ 5 - 0
kernel/src/arch/loongarch64/rand.rs

@@ -0,0 +1,5 @@
+use crate::libs::rand::soft_rand;
+
+pub fn rand() -> usize {
+    return soft_rand();
+}

+ 17 - 0
kernel/src/arch/loongarch64/sched.rs

@@ -0,0 +1,17 @@
+use crate::sched::SchedArch;
+
+pub struct LoongArch64SchedArch;
+
+impl SchedArch for LoongArch64SchedArch {
+    fn enable_sched_local() {
+        todo!("LoongArch64::enable_sched_local")
+    }
+
+    fn disable_sched_local() {
+        todo!("LoongArch64::disable_sched_local")
+    }
+
+    fn initial_setup_sched_local() {
+        todo!("LoongArch64::initial_setup_sched_local")
+    }
+}

+ 29 - 0
kernel/src/arch/loongarch64/smp/mod.rs

@@ -0,0 +1,29 @@
+use log::warn;
+use system_error::SystemError;
+
+use crate::smp::{
+    cpu::{CpuHpCpuState, ProcessorId, SmpCpuManager},
+    SMPArch,
+};
+
+pub struct LoongArch64SMPArch;
+
+impl SMPArch for LoongArch64SMPArch {
+    #[inline(never)]
+    fn prepare_cpus() -> Result<(), SystemError> {
+        warn!("LoongArch64SMPArch::prepare_cpus() is not implemented");
+        Ok(())
+    }
+
+    fn start_cpu(_cpu_id: ProcessorId, _hp_state: &CpuHpCpuState) -> Result<(), SystemError> {
+        warn!("LoongArch64SMPArch::start_cpu() is not implemented");
+        Ok(())
+    }
+}
+
+impl SmpCpuManager {
+    pub fn arch_init(_boot_cpu: ProcessorId) {
+        // todo: 读取所有可用的CPU
+        todo!("la64:SmpCpuManager::arch_init()")
+    }
+}

+ 8 - 0
kernel/src/arch/loongarch64/syscall/mod.rs

@@ -0,0 +1,8 @@
+use system_error::SystemError;
+
+pub mod nr;
+
+/// 系统调用初始化
+pub fn arch_syscall_init() -> Result<(), SystemError> {
+    todo!("la64:arch_syscall_init");
+}

+ 307 - 0
kernel/src/arch/loongarch64/syscall/nr.rs

@@ -0,0 +1,307 @@
+#![allow(dead_code)]
+
+pub const SYS_IO_SETUP: usize = 0;
+pub const SYS_IO_DESTROY: usize = 1;
+pub const SYS_IO_SUBMIT: usize = 2;
+pub const SYS_IO_CANCEL: usize = 3;
+pub const SYS_IO_GETEVENTS: usize = 4;
+pub const SYS_SETXATTR: usize = 5;
+pub const SYS_LSETXATTR: usize = 6;
+pub const SYS_FSETXATTR: usize = 7;
+pub const SYS_GETXATTR: usize = 8;
+pub const SYS_LGETXATTR: usize = 9;
+pub const SYS_FGETXATTR: usize = 10;
+pub const SYS_LISTXATTR: usize = 11;
+pub const SYS_LLISTXATTR: usize = 12;
+pub const SYS_FLISTXATTR: usize = 13;
+pub const SYS_REMOVEXATTR: usize = 14;
+pub const SYS_LREMOVEXATTR: usize = 15;
+pub const SYS_FREMOVEXATTR: usize = 16;
+pub const SYS_GETCWD: usize = 17;
+pub const SYS_LOOKUP_DCOOKIE: usize = 18;
+pub const SYS_EVENTFD2: usize = 19;
+pub const SYS_EPOLL_CREATE1: usize = 20;
+pub const SYS_EPOLL_CTL: usize = 21;
+pub const SYS_EPOLL_PWAIT: usize = 22;
+pub const SYS_DUP: usize = 23;
+pub const SYS_DUP3: usize = 24;
+pub const SYS_FCNTL: usize = 25;
+pub const SYS_INOTIFY_INIT1: usize = 26;
+pub const SYS_INOTIFY_ADD_WATCH: usize = 27;
+pub const SYS_INOTIFY_RM_WATCH: usize = 28;
+pub const SYS_IOCTL: usize = 29;
+pub const SYS_IOPRIO_SET: usize = 30;
+pub const SYS_IOPRIO_GET: usize = 31;
+pub const SYS_FLOCK: usize = 32;
+pub const SYS_MKNODAT: usize = 33;
+pub const SYS_MKDIRAT: usize = 34;
+pub const SYS_UNLINKAT: usize = 35;
+pub const SYS_SYMLINKAT: usize = 36;
+pub const SYS_LINKAT: usize = 37;
+pub const SYS_UMOUNT2: usize = 39;
+pub const SYS_MOUNT: usize = 40;
+pub const SYS_PIVOT_ROOT: usize = 41;
+pub const SYS_NFSSERVCTL: usize = 42;
+pub const SYS_STATFS: usize = 43;
+pub const SYS_FSTATFS: usize = 44;
+pub const SYS_TRUNCATE: usize = 45;
+pub const SYS_FTRUNCATE: usize = 46;
+pub const SYS_FALLOCATE: usize = 47;
+pub const SYS_FACCESSAT: usize = 48;
+pub const SYS_CHDIR: usize = 49;
+pub const SYS_FCHDIR: usize = 50;
+pub const SYS_CHROOT: usize = 51;
+pub const SYS_FCHMOD: usize = 52;
+pub const SYS_FCHMODAT: usize = 53;
+pub const SYS_FCHOWNAT: usize = 54;
+pub const SYS_FCHOWN: usize = 55;
+pub const SYS_OPENAT: usize = 56;
+pub const SYS_CLOSE: usize = 57;
+pub const SYS_VHANGUP: usize = 58;
+pub const SYS_PIPE2: usize = 59;
+pub const SYS_QUOTACTL: usize = 60;
+pub const SYS_GETDENTS64: usize = 61;
+pub const SYS_LSEEK: usize = 62;
+pub const SYS_READ: usize = 63;
+pub const SYS_WRITE: usize = 64;
+pub const SYS_READV: usize = 65;
+pub const SYS_WRITEV: usize = 66;
+pub const SYS_PREAD64: usize = 67;
+pub const SYS_PWRITE64: usize = 68;
+pub const SYS_PREADV: usize = 69;
+pub const SYS_PWRITEV: usize = 70;
+pub const SYS_SENDFILE: usize = 71;
+pub const SYS_PSELECT6: usize = 72;
+pub const SYS_PPOLL: usize = 73;
+pub const SYS_SIGNALFD4: usize = 74;
+pub const SYS_VMSPLICE: usize = 75;
+pub const SYS_SPLICE: usize = 76;
+pub const SYS_TEE: usize = 77;
+pub const SYS_READLINKAT: usize = 78;
+pub const SYS_SYNC: usize = 81;
+pub const SYS_FSYNC: usize = 82;
+pub const SYS_FDATASYNC: usize = 83;
+pub const SYS_SYNC_FILE_RANGE: usize = 84;
+pub const SYS_TIMERFD_CREATE: usize = 85;
+pub const SYS_TIMERFD_SETTIME: usize = 86;
+pub const SYS_TIMERFD_GETTIME: usize = 87;
+pub const SYS_UTIMENSAT: usize = 88;
+pub const SYS_ACCT: usize = 89;
+pub const SYS_CAPGET: usize = 90;
+pub const SYS_CAPSET: usize = 91;
+pub const SYS_PERSONALITY: usize = 92;
+pub const SYS_EXIT: usize = 93;
+pub const SYS_EXIT_GROUP: usize = 94;
+pub const SYS_WAITID: usize = 95;
+pub const SYS_SET_TID_ADDRESS: usize = 96;
+pub const SYS_UNSHARE: usize = 97;
+pub const SYS_FUTEX: usize = 98;
+pub const SYS_SET_ROBUST_LIST: usize = 99;
+pub const SYS_GET_ROBUST_LIST: usize = 100;
+pub const SYS_NANOSLEEP: usize = 101;
+pub const SYS_GETITIMER: usize = 102;
+pub const SYS_SETITIMER: usize = 103;
+pub const SYS_KEXEC_LOAD: usize = 104;
+pub const SYS_INIT_MODULE: usize = 105;
+pub const SYS_DELETE_MODULE: usize = 106;
+pub const SYS_TIMER_CREATE: usize = 107;
+pub const SYS_TIMER_GETTIME: usize = 108;
+pub const SYS_TIMER_GETOVERRUN: usize = 109;
+pub const SYS_TIMER_SETTIME: usize = 110;
+pub const SYS_TIMER_DELETE: usize = 111;
+pub const SYS_CLOCK_SETTIME: usize = 112;
+pub const SYS_CLOCK_GETTIME: usize = 113;
+pub const SYS_CLOCK_GETRES: usize = 114;
+pub const SYS_CLOCK_NANOSLEEP: usize = 115;
+pub const SYS_SYSLOG: usize = 116;
+pub const SYS_PTRACE: usize = 117;
+pub const SYS_SCHED_SETPARAM: usize = 118;
+pub const SYS_SCHED_SETSCHEDULER: usize = 119;
+pub const SYS_SCHED_GETSCHEDULER: usize = 120;
+pub const SYS_SCHED_GETPARAM: usize = 121;
+pub const SYS_SCHED_SETAFFINITY: usize = 122;
+pub const SYS_SCHED_GETAFFINITY: usize = 123;
+pub const SYS_SCHED_YIELD: usize = 124;
+pub const SYS_SCHED_GET_PRIORITY_MAX: usize = 125;
+pub const SYS_SCHED_GET_PRIORITY_MIN: usize = 126;
+pub const SYS_SCHED_RR_GET_INTERVAL: usize = 127;
+pub const SYS_RESTART_SYSCALL: usize = 128;
+pub const SYS_KILL: usize = 129;
+pub const SYS_TKILL: usize = 130;
+pub const SYS_TGKILL: usize = 131;
+pub const SYS_SIGALTSTACK: usize = 132;
+pub const SYS_RT_SIGSUSPEND: usize = 133;
+pub const SYS_RT_SIGACTION: usize = 134;
+pub const SYS_RT_SIGPROCMASK: usize = 135;
+pub const SYS_RT_SIGPENDING: usize = 136;
+pub const SYS_RT_SIGTIMEDWAIT: usize = 137;
+pub const SYS_RT_SIGQUEUEINFO: usize = 138;
+pub const SYS_RT_SIGRETURN: usize = 139;
+pub const SYS_SETPRIORITY: usize = 140;
+pub const SYS_GETPRIORITY: usize = 141;
+pub const SYS_REBOOT: usize = 142;
+pub const SYS_SETREGID: usize = 143;
+pub const SYS_SETGID: usize = 144;
+pub const SYS_SETREUID: usize = 145;
+pub const SYS_SETUID: usize = 146;
+pub const SYS_SETRESUID: usize = 147;
+pub const SYS_GETRESUID: usize = 148;
+pub const SYS_SETRESGID: usize = 149;
+pub const SYS_GETRESGID: usize = 150;
+pub const SYS_SETFSUID: usize = 151;
+pub const SYS_SETFSGID: usize = 152;
+pub const SYS_TIMES: usize = 153;
+pub const SYS_SETPGID: usize = 154;
+pub const SYS_GETPGID: usize = 155;
+pub const SYS_GETSID: usize = 156;
+pub const SYS_SETSID: usize = 157;
+pub const SYS_GETGROUPS: usize = 158;
+pub const SYS_SETGROUPS: usize = 159;
+pub const SYS_UNAME: usize = 160;
+pub const SYS_SETHOSTNAME: usize = 161;
+pub const SYS_SETDOMAINNAME: usize = 162;
+pub const SYS_GETRUSAGE: usize = 165;
+pub const SYS_UMASK: usize = 166;
+pub const SYS_PRCTL: usize = 167;
+pub const SYS_GETCPU: usize = 168;
+pub const SYS_GETTIMEOFDAY: usize = 169;
+pub const SYS_SETTIMEOFDAY: usize = 170;
+pub const SYS_ADJTIMEX: usize = 171;
+pub const SYS_GETPID: usize = 172;
+pub const SYS_GETPPID: usize = 173;
+pub const SYS_GETUID: usize = 174;
+pub const SYS_GETEUID: usize = 175;
+pub const SYS_GETGID: usize = 176;
+pub const SYS_GETEGID: usize = 177;
+pub const SYS_GETTID: usize = 178;
+pub const SYS_SYSINFO: usize = 179;
+pub const SYS_MQ_OPEN: usize = 180;
+pub const SYS_MQ_UNLINK: usize = 181;
+pub const SYS_MQ_TIMEDSEND: usize = 182;
+pub const SYS_MQ_TIMEDRECEIVE: usize = 183;
+pub const SYS_MQ_NOTIFY: usize = 184;
+pub const SYS_MQ_GETSETATTR: usize = 185;
+pub const SYS_MSGGET: usize = 186;
+pub const SYS_MSGCTL: usize = 187;
+pub const SYS_MSGRCV: usize = 188;
+pub const SYS_MSGSND: usize = 189;
+pub const SYS_SEMGET: usize = 190;
+pub const SYS_SEMCTL: usize = 191;
+pub const SYS_SEMTIMEDOP: usize = 192;
+pub const SYS_SEMOP: usize = 193;
+pub const SYS_SHMGET: usize = 194;
+pub const SYS_SHMCTL: usize = 195;
+pub const SYS_SHMAT: usize = 196;
+pub const SYS_SHMDT: usize = 197;
+pub const SYS_SOCKET: usize = 198;
+pub const SYS_SOCKETPAIR: usize = 199;
+pub const SYS_BIND: usize = 200;
+pub const SYS_LISTEN: usize = 201;
+pub const SYS_ACCEPT: usize = 202;
+pub const SYS_CONNECT: usize = 203;
+pub const SYS_GETSOCKNAME: usize = 204;
+pub const SYS_GETPEERNAME: usize = 205;
+pub const SYS_SENDTO: usize = 206;
+pub const SYS_RECVFROM: usize = 207;
+pub const SYS_SETSOCKOPT: usize = 208;
+pub const SYS_GETSOCKOPT: usize = 209;
+pub const SYS_SHUTDOWN: usize = 210;
+pub const SYS_SENDMSG: usize = 211;
+pub const SYS_RECVMSG: usize = 212;
+pub const SYS_READAHEAD: usize = 213;
+pub const SYS_BRK: usize = 214;
+pub const SYS_MUNMAP: usize = 215;
+pub const SYS_MREMAP: usize = 216;
+pub const SYS_ADD_KEY: usize = 217;
+pub const SYS_REQUEST_KEY: usize = 218;
+pub const SYS_KEYCTL: usize = 219;
+pub const SYS_CLONE: usize = 220;
+pub const SYS_EXECVE: usize = 221;
+pub const SYS_MMAP: usize = 222;
+pub const SYS_FADVISE64: usize = 223;
+pub const SYS_SWAPON: usize = 224;
+pub const SYS_SWAPOFF: usize = 225;
+pub const SYS_MPROTECT: usize = 226;
+pub const SYS_MSYNC: usize = 227;
+pub const SYS_MLOCK: usize = 228;
+pub const SYS_MUNLOCK: usize = 229;
+pub const SYS_MLOCKALL: usize = 230;
+pub const SYS_MUNLOCKALL: usize = 231;
+pub const SYS_MINCORE: usize = 232;
+pub const SYS_MADVISE: usize = 233;
+pub const SYS_REMAP_FILE_PAGES: usize = 234;
+pub const SYS_MBIND: usize = 235;
+pub const SYS_GET_MEMPOLICY: usize = 236;
+pub const SYS_SET_MEMPOLICY: usize = 237;
+pub const SYS_MIGRATE_PAGES: usize = 238;
+pub const SYS_MOVE_PAGES: usize = 239;
+pub const SYS_RT_TGSIGQUEUEINFO: usize = 240;
+pub const SYS_PERF_EVENT_OPEN: usize = 241;
+pub const SYS_ACCEPT4: usize = 242;
+pub const SYS_RECVMMSG: usize = 243;
+//pub const SYS_ARCH_SPECIFIC_SYSCALL: usize = 244;
+pub const SYS_WAIT4: usize = 260;
+pub const SYS_PRLIMIT64: usize = 261;
+pub const SYS_FANOTIFY_INIT: usize = 262;
+pub const SYS_FANOTIFY_MARK: usize = 263;
+pub const SYS_NAME_TO_HANDLE_AT: usize = 264;
+pub const SYS_OPEN_BY_HANDLE_AT: usize = 265;
+pub const SYS_CLOCK_ADJTIME: usize = 266;
+pub const SYS_SYNCFS: usize = 267;
+pub const SYS_SETNS: usize = 268;
+pub const SYS_SENDMMSG: usize = 269;
+pub const SYS_PROCESS_VM_READV: usize = 270;
+pub const SYS_PROCESS_VM_WRITEV: usize = 271;
+pub const SYS_KCMP: usize = 272;
+pub const SYS_FINIT_MODULE: usize = 273;
+pub const SYS_SCHED_SETATTR: usize = 274;
+pub const SYS_SCHED_GETATTR: usize = 275;
+pub const SYS_RENAMEAT2: usize = 276;
+pub const SYS_SECCOMP: usize = 277;
+pub const SYS_GETRANDOM: usize = 278;
+pub const SYS_MEMFD_CREATE: usize = 279;
+pub const SYS_BPF: usize = 280;
+pub const SYS_EXECVEAT: usize = 281;
+pub const SYS_USERFAULTFD: usize = 282;
+pub const SYS_MEMBARRIER: usize = 283;
+pub const SYS_MLOCK2: usize = 284;
+pub const SYS_COPY_FILE_RANGE: usize = 285;
+pub const SYS_PREADV2: usize = 286;
+pub const SYS_PWRITEV2: usize = 287;
+pub const SYS_PKEY_MPROTECT: usize = 288;
+pub const SYS_PKEY_ALLOC: usize = 289;
+pub const SYS_PKEY_FREE: usize = 290;
+pub const SYS_STATX: usize = 291;
+pub const SYS_IO_PGETEVENTS: usize = 292;
+pub const SYS_RSEQ: usize = 293;
+pub const SYS_KEXEC_FILE_LOAD: usize = 294;
+pub const SYS_PIDFD_SEND_SIGNAL: usize = 424;
+pub const SYS_IO_URING_SETUP: usize = 425;
+pub const SYS_IO_URING_ENTER: usize = 426;
+pub const SYS_IO_URING_REGISTER: usize = 427;
+pub const SYS_OPEN_TREE: usize = 428;
+pub const SYS_MOVE_MOUNT: usize = 429;
+pub const SYS_FSOPEN: usize = 430;
+pub const SYS_FSCONFIG: usize = 431;
+pub const SYS_FSMOUNT: usize = 432;
+pub const SYS_FSPICK: usize = 433;
+pub const SYS_PIDFD_OPEN: usize = 434;
+pub const SYS_CLONE3: usize = 435;
+pub const SYS_CLOSE_RANGE: usize = 436;
+pub const SYS_OPENAT2: usize = 437;
+pub const SYS_PIDFD_GETFD: usize = 438;
+pub const SYS_FACCESSAT2: usize = 439;
+pub const SYS_PROCESS_MADVISE: usize = 440;
+pub const SYS_EPOLL_PWAIT2: usize = 441;
+pub const SYS_MOUNT_SETATTR: usize = 442;
+pub const SYS_QUOTACTL_FD: usize = 443;
+pub const SYS_LANDLOCK_CREATE_RULESET: usize = 444;
+pub const SYS_LANDLOCK_ADD_RULE: usize = 445;
+pub const SYS_LANDLOCK_RESTRICT_SELF: usize = 446;
+pub const SYS_PROCESS_MRELEASE: usize = 448;
+pub const SYS_FUTEX_WAITV: usize = 449;
+pub const SYS_SET_MEMPOLICY_HOME_NODE: usize = 450;
+
+// ===以下是为了代码一致性,才定义的调用号===
+
+pub const SYS_GETDENTS: usize = SYS_GETDENTS64;

+ 24 - 0
kernel/src/arch/loongarch64/time.rs

@@ -0,0 +1,24 @@
+use crate::time::{clocksource::HZ, TimeArch};
+
+/// 这个是系统jiffies时钟源的固有频率(不是调频之后的)
+pub const CLOCK_TICK_RATE: u32 = HZ as u32 * 1000000;
+
+pub struct LoongArch64TimeArch;
+
+impl TimeArch for LoongArch64TimeArch {
+    fn get_cycles() -> usize {
+        todo!("LoongArch64TimeArch::get_cycles")
+    }
+
+    fn cal_expire_cycles(ns: usize) -> usize {
+        todo!("LoongArch64TimeArch::cal_expire_cycles")
+    }
+
+    fn cycles2ns(cycles: usize) -> usize {
+        todo!("LoongArch64TimeArch::cycles2ns")
+    }
+}
+
+pub fn time_init() {
+    todo!("la64:time_init");
+}

+ 5 - 0
kernel/src/arch/mod.rs

@@ -13,6 +13,11 @@ pub mod riscv64;
 #[cfg(target_arch = "riscv64")]
 pub use self::riscv64::*; // 公开riscv64架构下的函数,使外界接口统一
 
+#[cfg(target_arch = "loongarch64")]
+pub mod loongarch64;
+#[cfg(target_arch = "loongarch64")]
+pub use self::loongarch64::*; // 公开loongarch64架构下的函数,使外界接口统一
+
 pub mod io;
 
 /// TraitPciArch Pci架构相关函数,任何架构都应独立实现trait里的函数

+ 25 - 1
kernel/src/arch/riscv64/asm/head.S

@@ -1,5 +1,29 @@
 #include "common/asm.h"
-#include "asm/csr.h"
+
+#define CSR_SSTATUS 0x100
+#define CSR_SIE 0x104
+#define CSR_STVEC 0x105
+#define CSR_SIP 0x144
+#define CSR_SSCRATCH 0x140
+
+#define CSR_TVEC CSR_STVEC
+#define CSR_SCRATCH CSR_SSCRATCH
+
+#define CSR_STATUS CSR_SSTATUS
+#define CSR_IE CSR_SIE
+#define CSR_IP CSR_SIP
+
+#define SR_FS 0x00006000
+#define SR_VS 0x00000600
+#define SR_FS_VS (SR_FS | SR_VS) /* Vector and Floating-Point Unit */
+
+#define SATP_MODE_39 0x8000000000000000ULL
+#define SATP_MODE_48 0x9000000000000000ULL
+#define SATP_MODE_57 0xa000000000000000ULL
+
+#define PAGE_OFFSET 0xffffffc000000000
+#define KERNEL_LINK_OFFSET 0x1000000
+#define KERNEL_VIRT_START (PAGE_OFFSET + KERNEL_LINK_OFFSET)
 
 .section .bootstrap
 

+ 0 - 20
kernel/src/arch/riscv64/asm/irqflags.h

@@ -1,20 +0,0 @@
-#pragma once
-#include <asm/asm.h>
-// 保存当前rflags的值到变量x内并关闭中断
-#define local_irq_save(x) \
-    do                    \
-    {                     \
-    } while (1)
-// 恢复先前保存的rflags的值x
-#define local_irq_restore(x) \
-    do                       \
-    {                        \
-    } while (1)
-#define local_irq_disable() \
-    do                      \
-    {                       \
-    } while (1)
-#define local_irq_enable() \
-    do                     \
-    {                      \
-    } while (1)

+ 0 - 35
kernel/src/arch/riscv64/asm/spinlock.c

@@ -1,35 +0,0 @@
-#include <common/spinlock.h>
-#include <process/preempt.h>
-
-void __arch_spin_lock(spinlock_t *lock)
-{
-    while(1);
-    rs_preempt_disable();
-}
-
-void __arch_spin_unlock(spinlock_t *lock)
-{
-    while(1);
-    rs_preempt_enable();
-}
-
-void __arch_spin_lock_no_preempt(spinlock_t *lock)
-{
-    while(1);
-}
-
-void __arch_spin_unlock_no_preempt(spinlock_t *lock)
-{
-    while(1);
-}
-
-long __arch_spin_trylock(spinlock_t *lock)
-{
-    uint64_t tmp_val = 0;
-    rs_preempt_disable();
-    // 交换tmp_val和lock的值,若tmp_val==1则证明加锁成功
-    while(1);
-    if (!tmp_val)
-        rs_preempt_enable();
-    return tmp_val;
-}

+ 0 - 63
kernel/src/arch/riscv64/include/asm/asm.h

@@ -1,63 +0,0 @@
-#pragma once
-
-#include "DragonOS/stdint.h"
-#include <common/stddef.h>
-#include <stdbool.h>
-
-// RISC-V 没有直接的开启/关闭中断的指令,你需要通过修改CSR寄存器来实现
-// 你可能需要在你的中断处理程序中处理这些操作
-
-#define nop() __asm__ __volatile__("nop\n\t")
-
-// RISC-V 没有 hlt 指令,你可能需要使用 wfi 指令来等待中断
-#define hlt() __asm__ __volatile__("wfi\n\t")
-
-// RISC-V 没有 pause 指令,你可能需要使用其他方法来实现处理器等待
-
-// RISC-V 使用 fence 指令来实现内存屏障
-#define io_mfence() __asm__ __volatile__("fence rw,rw\n\t" ::: "memory")
-#define io_sfence() __asm__ __volatile__("fence w,w\n\t" ::: "memory")
-#define io_lfence() __asm__ __volatile__("fence r,r\n\t" ::: "memory")
-
-// 开启中断
-#define sti() __asm__ __volatile__("csrsi mstatus, 8\n\t" ::: "memory")
-
-// 关闭中断
-#define cli() __asm__ __volatile__("csrci mstatus, 8\n\t" ::: "memory")
-
-// 从io口读入8个bit
-unsigned char io_in8(unsigned short port) {
-  while (1)
-    ;
-}
-
-// 从io口读入32个bit
-unsigned int io_in32(unsigned short port) {
-  while (1)
-    ;
-}
-
-// 输出8个bit到输出端口
-void io_out8(unsigned short port, unsigned char value) {
-  while (1)
-    ;
-}
-
-// 输出32个bit到输出端口
-void io_out32(unsigned short port, unsigned int value) {
-  while (1)
-    ;
-}
-
-/**
- * @brief 验证地址空间是否为用户地址空间
- *
- * @param addr_start 地址起始值
- * @param length 地址长度
- * @return true
- * @return false
- */
-bool verify_area(uint64_t addr_start, uint64_t length) {
-  while (1)
-    ;
-}

+ 0 - 26
kernel/src/arch/riscv64/include/asm/csr.h

@@ -1,26 +0,0 @@
-#pragma once
-
-#define CSR_SSTATUS 0x100
-#define CSR_SIE 0x104
-#define CSR_STVEC 0x105
-#define CSR_SIP 0x144
-#define CSR_SSCRATCH 0x140
-
-#define CSR_TVEC CSR_STVEC
-#define CSR_SCRATCH CSR_SSCRATCH
-
-#define CSR_STATUS CSR_SSTATUS
-#define CSR_IE CSR_SIE
-#define CSR_IP CSR_SIP
-
-#define SR_FS 0x00006000
-#define SR_VS 0x00000600
-#define SR_FS_VS (SR_FS | SR_VS) /* Vector and Floating-Point Unit */
-
-#define SATP_MODE_39 0x8000000000000000ULL
-#define SATP_MODE_48 0x9000000000000000ULL
-#define SATP_MODE_57 0xa000000000000000ULL
-
-#define PAGE_OFFSET 0xffffffc000000000
-#define KERNEL_LINK_OFFSET 0x1000000
-#define KERNEL_VIRT_START (PAGE_OFFSET + KERNEL_LINK_OFFSET)

+ 0 - 14
kernel/src/arch/riscv64/include/asm/irqflags.h

@@ -1,14 +0,0 @@
-#pragma once
-
-// 保存当前rflags的值到变量x内并关闭中断
-#define local_irq_save(x) \
-    do                    \
-    {                     \
-    } while (1)
-// 恢复先前保存的rflags的值x
-#define local_irq_restore(x) \
-    do                       \
-    {                        \
-    } while (1)
-#define local_irq_disable() cli();
-#define local_irq_enable() sti();

+ 23 - 8
kernel/src/arch/riscv64/interrupt/handle.rs

@@ -151,10 +151,18 @@ fn do_trap_insn_page_fault(trap_frame: &mut TrapFrame) -> Result<(), SystemError
     let vaddr = trap_frame.badaddr;
     let cause = trap_frame.cause;
     let epc = trap_frame.epc;
-    error!(
-        "riscv64_do_irq: do_insn_page_fault vaddr: {:#x}, cause: {:?} epc: {:#x}",
-        vaddr, cause, epc
-    );
+    if trap_frame.is_from_user() {
+        error!(
+            "riscv64_do_irq: do_trap_insn_page_fault(user mode): epc: {epc:#x}, vaddr={:#x}, cause={:?}",
+            vaddr, cause
+        );
+    } else {
+        panic!(
+            "riscv64_do_irq: do_trap_insn_page_fault(kernel mode): epc: {epc:#x}, vaddr={:#x}, cause={:?}",
+            vaddr, cause
+        );
+    }
+
     loop {
         spin_loop();
     }
@@ -165,10 +173,17 @@ fn do_trap_load_page_fault(trap_frame: &mut TrapFrame) -> Result<(), SystemError
     let vaddr = trap_frame.badaddr;
     let cause = trap_frame.cause;
     let epc = trap_frame.epc;
-    error!(
-        "riscv64_do_irq: do_trap_load_page_fault: epc: {epc:#x}, vaddr={:#x}, cause={:?}",
-        vaddr, cause
-    );
+    if trap_frame.is_from_user() {
+        error!(
+            "riscv64_do_irq: do_trap_load_page_fault(user mode): epc: {epc:#x}, vaddr={:#x}, cause={:?}",
+            vaddr, cause
+        );
+    } else {
+        panic!(
+            "riscv64_do_irq: do_trap_load_page_fault(kernel mode): epc: {epc:#x}, vaddr={:#x}, cause={:?}",
+            vaddr, cause
+        );
+    }
 
     loop {
         spin_loop();

+ 18 - 4
kernel/src/arch/riscv64/ipc/signal.rs

@@ -1,8 +1,9 @@
 use log::error;
 
 use crate::{
-    arch::{sched::sched, CurrentIrqArch},
+    arch::{interrupt::TrapFrame, sched::sched, CurrentIrqArch},
     exception::InterruptArch,
+    ipc::signal_types::SignalArch,
     process::ProcessManager,
 };
 
@@ -94,9 +95,7 @@ impl From<i32> for Signal {
 
 impl Into<SigSet> for Signal {
     fn into(self) -> SigSet {
-        SigSet {
-            bits: (1 << (self as usize - 1) as u64),
-        }
+        self.into_sigset()
     }
 }
 impl Signal {
@@ -339,3 +338,18 @@ fn sig_continue(sig: Signal) {
 fn sig_ignore(_sig: Signal) {
     return;
 }
+
+pub struct RiscV64SignalArch;
+
+impl SignalArch for RiscV64SignalArch {
+    // TODO: 为RISCV64实现信号处理
+    // 注意,rv64现在在中断/系统调用返回用户态时,没有进入 irqentry_exit() 函数,
+    // 到时候实现信号处理时,需要修改中断/系统调用返回用户态的代码,进入 irqentry_exit() 函数
+    unsafe fn do_signal_or_restart(_frame: &mut TrapFrame) {
+        todo!()
+    }
+
+    fn sys_rt_sigreturn(_trap_frame: &mut TrapFrame) -> u64 {
+        todo!()
+    }
+}

+ 10 - 0
kernel/src/arch/riscv64/link.ld

@@ -68,6 +68,16 @@ SECTIONS
 
 	. = ALIGN(32768);
 
+	trace_point_start_pa = .;
+	.tracepoint (trace_point_start_pa): AT(trace_point_start_pa - KERNEL_VMA)
+    {
+        _tracepoint = .;
+        *(.tracepoint)
+        *(.tracepoint.*)
+        _etracepoint = .;
+    }
+    . = ALIGN(32768);
+
 	init_proc_union_start_pa = .;
 	.data.init_proc_union (init_proc_union_start_pa): AT(init_proc_union_start_pa - KERNEL_VMA)
 	 { *(.data.init_proc_union) }

+ 9 - 0
kernel/src/arch/riscv64/mod.rs

@@ -27,6 +27,15 @@ pub use self::time::RiscV64TimeArch as CurrentTimeArch;
 
 pub use self::elf::RiscV64ElfArch as CurrentElfArch;
 
+pub use self::ipc::signal::RiscV64SignalArch as CurrentSignalArch;
+
 pub use crate::arch::smp::RiscV64SMPArch as CurrentSMPArch;
 
 pub use crate::arch::sched::RiscV64SchedArch as CurrentSchedArch;
+
+pub fn panic_pre_work() {
+    unsafe { riscv::register::sstatus::set_fs(riscv::register::sstatus::FS::Initial) };
+}
+pub fn panic_post_work() {
+    unsafe { riscv::register::sstatus::set_fs(riscv::register::sstatus::FS::Off) };
+}

+ 3 - 11
kernel/src/arch/riscv64/rand.rs

@@ -1,13 +1,5 @@
+use crate::libs::rand::soft_rand;
+
 pub fn rand() -> usize {
-    static mut SEED: u64 = 0xdead_beef_cafe_babe;
-    let mut buf = [0u8; size_of::<usize>()];
-    for x in buf.iter_mut() {
-        unsafe {
-            // from musl
-            SEED = SEED.wrapping_mul(0x5851_f42d_4c95_7f2d);
-            *x = (SEED >> 33) as u8;
-        }
-    }
-    let x: usize = unsafe { core::mem::transmute(buf) };
-    return x;
+    return soft_rand();
 }

+ 2 - 10
kernel/src/arch/riscv64/syscall/mod.rs

@@ -36,16 +36,8 @@ pub(super) fn syscall_handler(syscall_num: usize, frame: &mut TrapFrame) -> () {
 
     let args = [frame.a0, frame.a1, frame.a2, frame.a3, frame.a4, frame.a5];
     let mut syscall_handle = || -> usize {
-        #[cfg(feature = "backtrace")]
-        {
-            Syscall::catch_handle(syscall_num, &args, frame)
-                .unwrap_or_else(|e| e.to_posix_errno() as usize)
-        }
-        #[cfg(not(feature = "backtrace"))]
-        {
-            Syscall::handle(syscall_num, &args, frame)
-                .unwrap_or_else(|e| e.to_posix_errno() as usize)
-        }
+        Syscall::catch_handle(syscall_num, &args, frame)
+            .unwrap_or_else(|e| e.to_posix_errno() as usize)
     };
     syscall_return!(syscall_handle(), frame, false);
 }

+ 0 - 1
kernel/src/arch/x86_64/asm/apu_boot.S

@@ -1,5 +1,4 @@
 #include "../common/asm.h"
-#include <asm/apu_boot.h>
 
 
 .align 0x1000  // 按照4k对齐

+ 0 - 7
kernel/src/arch/x86_64/asm/cmpxchg.c

@@ -1,7 +0,0 @@
-#include <arch/x86_64/include/asm/cmpxchg.h>
-
-bool __try_cmpxchg_q(uint64_t *ptr, uint64_t *old_ptr, uint64_t *new_ptr)
-{
-    bool success = __raw_try_cmpxchg(ptr, old_ptr, *new_ptr, 8);
-    return success;
-}

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff