Skip to content

fix(loongarch): LoongArch 用户态 bringup + rootfs 工具链整理,并补齐 statx 修复 busybox ls#236

Merged
ZIYAN137 merged 15 commits into
mainfrom
fix/la-interrupt
Jan 14, 2026
Merged

fix(loongarch): LoongArch 用户态 bringup + rootfs 工具链整理,并补齐 statx 修复 busybox ls#236
ZIYAN137 merged 15 commits into
mainfrom
fix/la-interrupt

Conversation

@ZIYAN137

Copy link
Copy Markdown
Contributor

🐞 Bug Fix / 错误修复

🐛 描述 (Description)

本 PR 用于将当前分支(fix/la-interrupt)合并回 main,包含 LoongArch 用户态 bringup、rootfs/构建工具链整理,以及补齐 statx(2) 以修复 BusyBox ls 在 LoongArch 下报 ENOSYS 的问题。

其中与 Issue #234 直接相关的现象是:在 LoongArch 运行到用户态 BusyBox shell 后,执行 ls 会报:

/bin/sh: ls: Function not implemented

根因是用户态调用了 statx(2)(syscall id=291),内核返回 ENOSYS,BusyBox 将其表现为 “Function not implemented”。本 PR 补齐 statx 系统调用,并在 VFS/UAPI 层补齐必要的数据结构与转换,使 ls 等依赖 statx 的命令在 LoongArch 上可正常工作。

除此之外,本分支还包含 LoongArch 启动入口/异常处理/TLB refill/execve/TLS/挂载流程等对齐修复,以及 rootfs 目录结构整理与相关文档补齐。

📦 本分支相较 main 的改动概览 (Compared to main)

说明:本 PR 体量较大(涉及 rootfs 重整与 LoongArch bringup),以下按“commit 维度”列出当前分支相对 main 的全部提交,同时给出高层摘要便于 review。

  • eca86a9 loongarch: task switch and rootfs tooling
  • b150890 Merge remote-tracking branch 'upstream/main' into feat/interrupt-user
  • 12e08bc cargo fmt
  • 5ca161f fix
  • d8ed6fa fix:修复一些定义错误,使用错误
  • baa80b7 bug定位
  • 968ff94 fix(loongarch): 修复用户态启动并对齐启动流程
  • 9765dac chore(loongarch): 降级 bringup 调试输出
  • cd5669b Merge remote-tracking branch 'origin/main' into fix/la-interrupt
  • 2e13235 fix: 加入LoongArch的ELF解析
  • e41e864 fix: 移动lib
  • 2615014 refactor: 重整data/loongarch_musl/
  • 9fe527c fix(loongarch): 补齐 statx,修复 busybox ls “Function not implemented”

📊 Diff Stats

  • 865 files changed, 1993 insertions(+), 186 deletions(-)

✅ 修复内容 (What Changed)

(按模块归纳,覆盖本分支相对 main 的改动范围)

  • LoongArch bringup

    • boot/DTB:启动入口增加 DTB 指针探测(magic 检查)并写入全局保存区,提升设备树初始化稳定性
    • trap/TLB:完善 TLB refill 入口;修正 trap_entry/__restore 寄存器保存/恢复映射,降低用户态寄存器污染与 trap storm 风险
    • execve/TLS:用户栈与 TLS/TP 初始化对齐 musl/busybox 预期;启动早期使能基础 FPU(EUEN.FPE)
    • 任务/调度:对齐 init 任务语义(PID/TID=1 等),并补齐与 SMP/任务切换相关实现
    • 挂载/设备:LoongArch 与 RISC-V 启动流程对齐,/dev 等挂载点由用户态 rcS 处理,内核侧按需创建设备节点
  • syscall / Linux ABI

    • statx(2):增加 SYS_STATX = 291(loongarch/riscv),并在 syscall 分发中接入(按 syscall number 递增顺序排列)
    • sys_statx:内核实现 statx(dirfd, pathname, flags, mask, buf),返回 STATX_BASIC_STATS(目前忽略 mask 的细粒度筛选)
    • debug:LoongArch 未知 syscall id 限额日志,便于后续定位 ENOSYS
  • rootfs / tooling / docs

    • rootfs:整理 data/loongarch_musl 目录结构并补齐 BusyBox 用户态文件
    • build/QEMU:调整构建脚本与 QEMU 运行脚本以适配 LoongArch 运行路径
    • docs:补充 LoongArch 文档并更新 document/SUMMARY.md

🚨 重现步骤 (Steps to Reproduce)

  1. make build ARCH=loongarch
  2. make run ARCH=loongarch
  3. 进入 / # 交互 shell 后执行 ls
  4. 预期结果:正常列出目录项
  5. 实际结果(Bug 现象):/bin/sh: ls: Function not implemented

🔗 关联 Issue

Fixes #234

🧪 测试 (Testing)

  • cargo build --target loongarch64-unknown-none(可编译)
  • cargo build --target riscv64gc-unknown-none-elf(可编译)
  • LoongArch QEMU 启动到 / # 后执行 ls 可正常工作(不再报 “Function not implemented”)

a6d9a6m and others added 14 commits January 8, 2026 05:24
  - 启动入口:探测 DTB 指针并写入 DTP,提升设备树初始化稳定性
  - trap:修正 trap_entry/__restore 寄存器保存/恢复映射,避免用户态寄存器被污染
  - tlb refill:使用 lddir/ldpte/tlbfill 实现 refill 入口,仅用 TLBRSAVE 保存 t0,避免踩
    CSR
  - execve:启用 EUEN.FPE;用户栈顶预留 TLS 页并设置 tp,适配 musl/busybox
  - 任务/调度:init 固定 PID/TID=1;CPU0 补齐 idle_task 兜底,避免 runqueue 为空时 panic
  - 挂载流程:LoongArch 与 RISC-V 对齐,/dev 等由 rcS 挂载;sys_mount 对 /dev,/proc,/
    sys,/tmp 自动创建挂载点目录,/dev 挂载后 init_dev 创建设备节点
  - 文档:新增 LoongArch bringup 修复总结并加入 SUMMARY
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ZIYAN137, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此 PR 旨在将 fix/la-interrupt 分支合并回 main,核心工作是为 LoongArch 架构实现全面的用户态启动支持,解决 BusyBox ls 命令在 LoongArch 上因缺少 statx(2) 系统调用而无法正常运行的关键问题,并对 LoongArch 的根文件系统结构和构建工具链进行了整理与优化,以提升其稳定性和可用性。

Highlights

  • LoongArch 用户态启动: 全面完善 LoongArch 用户态启动流程,包括 DTB 指针探测、TLB refill 机制、trap_entry/__restore 寄存器映射修正、execve/TLS 初始化对齐 musl/busybox 预期、FPU 使能、init 任务语义对齐以及 SMP/任务切换相关实现。
  • statx(2) 系统调用修复: 解决了 LoongArch 上 BusyBox ls 命令因缺少 statx(2) 系统调用而报错 ENOSYS 的问题。通过增加 SYS_STATX = 291 并实现内核 sys_statx,确保 ls 等依赖 statx 的命令正常工作。
  • 根文件系统与工具链整理: 重整了 data/loongarch_musl 目录结构,补齐 BusyBox 用户态文件,并调整了构建脚本与 QEMU 运行脚本以适配 LoongArch 运行路径,同时更新了相关文档。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本 PR 是一项重大的贡献,为 LoongArch 架构带来了用户态支持,并修复了 busybox ls 的关键问题。改动范围广泛,涵盖了从启动流程、异常处理到系统调用实现和工具链调整的方方面面。bringup_userland.md 中详尽的文档尤其值得称赞,它清晰地解释了问题、解决方案和验证步骤。

我的审查主要基于所提供的文件。由于提供的差异信息有限,我的审查集中在 scripts/make_init_simple_fs.py 工具上。我发现了一些通过重构文件收集和过滤逻辑来提高其效率和可维护性的机会。建议的更改整合了逻辑,消除了冗余,并通过避免多次遍历文件系统来提高性能。

总体而言,这是一个高质量的 PR,它使操作系统更加健壮和可移植。

@ZIYAN137 ZIYAN137 merged commit 8279fd7 into main Jan 14, 2026
1 check passed
@ZIYAN137 ZIYAN137 deleted the fix/la-interrupt branch January 14, 2026 08:44
a6d9a6m added a commit to a6d9a6m/comix-fork that referenced this pull request Jan 17, 2026
fix(loongarch): LoongArch 用户态 bringup + rootfs 工具链整理,并补齐 statx 修复 busybox ls
a6d9a6m added a commit to a6d9a6m/comix-fork that referenced this pull request Jan 18, 2026
fix(loongarch): LoongArch 用户态 bringup + rootfs 工具链整理,并补齐 statx 修复 busybox ls
a6d9a6m added a commit to a6d9a6m/comix-fork that referenced this pull request Jan 18, 2026
fix(loongarch): LoongArch 用户态 bringup + rootfs 工具链整理,并补齐 statx 修复 busybox ls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] oongArch 运行时在切换到用户态后卡住,没有进入用户程序,也没有新的 trap/异常日志

2 participants