[WIP] Migrate x86_64-qemu-virt platform to kbootloader#47
Draft
[WIP] Migrate x86_64-qemu-virt platform to kbootloader#47
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.
Original prompt
Background
The aarch64-qemu-virt platform has been migrated to use the unified kbootloader crate for boot entry. x86_64-qemu-virt is still using platform-private boot.rs/multiboot.S and manual entry functions; the goal is to migrate this platform to the new system, with all entry code unified in kbootloader.
Tasks for this PR (x86_64-qemu-virt only)
__primary_switched(magic, mbi)and__secondary_switched(magic); validates the Multiboot magic, gets current cpu_id using raw_cpuid, calls INIT_PERCPU, INIT_TRAP, then call_kernel_entry.[target.'cfg(target_arch = "x86_64")'.dependencies] raw_cpuid = "11"extern crate kbootloader;, notmod boot;in lib.rs.Design/compatibility notes
Next PRs
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: j 从kbootloader设计来看 我希望他尽可能少依赖外部库 不过没有办法的花,用 target dependency 引入也行 k: 这个校验逻辑是保留在 kbootloader 中 l) 统一 multiboot.S 的方案 可以用一份 只要你确认功能不会互相影响 m: INIT_PERCPU 的签名应该是 fn(usize) n) 我们可以在 kbootloader 中提供一个可选的 PLATFORM_PRE_MMU 回调 让platform决定是否有额外操作 去决定是否实现 o) 可以用 boot_device_mm[(start, end), (start ,end)] 和 BOOT_NORMAL_MM((start, end), (start ,end)) 配置 然后动态计算映射页表 p 可以
Assistant:
好的,所有技术细节已经确认清楚。让我整理一下完整的实现方案,然后开始创建 PR。
最终实现方案总结
1.
kbootloader新增 x86_64 架构支持src/arch/x86_64/模块:包含mod.rs、entry.rs、multiboot.S{cbit_mask}参数(非 SEV 时为 0),保留_start32+_start(64-bit 跳板)兼容两种入口__primary_switched:校验 multiboot magic →call_init_percpu!(cpu_id)→call_init_trap!()→call_kernel_entry!(PRIMARY_KERNEL_ENTRY, cpu_id, mbi)__secondary_switched:call_init_percpu!(cpu_id)→call_init_trap!()→call_kernel_entry!(SECOND_KERNEL_ENTRY, cpu_id)current_cpu_id():通过 target dependency 引入raw_cpuid2. 新增 distributed_slice
INIT_PERCPU: [fn(usize)]— 签名fn(cpu_id: usize)call_init_percpu!宏init_percpu→init_trap→kernel_entry3. aarch64 新增
PLATFORM_PRE_MMU回调PLATFORM_PRE_MMU: [fn()]— 可选,platform 决定是否注册create_boot_page_tables()之前调用kvm_guard_granule_init+do_xmap_granules4. aarch64 页表映射可配置化
kbuild_config新增BOOT_DEVICE_MM和BOOT_NORMAL_MM配置create_boot_page_tables()根据配置动态创建映射5. 三个平台迁移
x86_64-qemu-virt:删除boot.rs,lib.rs中extern crate kbootloader,init.rs移除init_trap调用x86-csv:同上,额外处理cbit_maskaarch64-crosvm-virt:删除boot.rs,统一使用 kbootloader 的_start(带 MZ header,注释说明 crosvm 待测试),init.rs移除init_trap,power.rs引用改为kbootloader::arch::_start_secondary让我现在创建 PR。
Assistant: I've submitted the pull request to the coding agent. It will create a PR on the
dyn_bootloaderbranch ofguoweikang/x-kernelthat migrates all three remaining platforms (x86_64-qemu-virt,x86-csv,aarch64-crosvm-virt) to use the unifiedkbootloadercrate.Here's a summary of the migration plan the agent will implement:
kbootloader Enhancements
INIT_PERCPUdistributed_slice —fn(usize)for x86_64's percpu init beforeinit_trapPLATFORM_PRE_MMUdistributed_slice —fn()for crosvm's KVM guard granule ops before MMU enableBOOT_DEVICE_MM/BOOT_NORMAL_MMkconfig arraysmultiboot.S(withcbit_maskparam), Rust entry points, multiboot magic validationINIT_PERCPUcalls added to existing aarch64 entr...This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.