Skip to content

refactor(x86_64): cleanup dependencies and initialization code#26

Open
AsakuraMizu wants to merge 2 commits intomainfrom
pr/x86_64-cleanup
Open

refactor(x86_64): cleanup dependencies and initialization code#26
AsakuraMizu wants to merge 2 commits intomainfrom
pr/x86_64-cleanup

Conversation

@AsakuraMizu
Copy link
Copy Markdown
Contributor

@AsakuraMizu AsakuraMizu commented Mar 15, 2026

Tracking issue: #25

Description

All changes are related to x86_64:

  1. Remove static_assertions
  2. Remove init_percpu (due to feat: add percpu axplat_crates#42 and Add custom per-CPU area support, clarify init process, fix initialization percpu#22, this function is useless now)
  3. Replace lazyinit with spin
  4. Simplify initialization code (GDT, IDT)
  5. Remove PROTECTION_VIOLATION from page fault reserved error code
  6. Fix in trap.s that exceptions #CP(21)/#VC(29)/#SX(30) should have error code pushed on stack

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the x86_64 CPU initialization and trap-handling plumbing by replacing custom GDT/IDT wrappers with x86_64 crate primitives, updating segment selector usage across user entry/syscall paths, and adjusting low-level trap metadata (error-code vectors and #PF flag parsing). Also updates dependencies to align with the new implementation choices.

Changes:

  • Replace custom GDT/IDT structs and lazyinit usage with x86_64::{GlobalDescriptorTable, InterruptDescriptorTable} plus spin::Lazy.
  • Update user-space context setup and syscall MSR configuration to use new gdt::* selector constants.
  • Fix trap handling details (additional error-code vectors; allow PROTECTION_VIOLATION bit in #PF error code parsing) and adjust crate dependencies accordingly.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/x86_64/uspace.rs Switch user CS/SS selectors to gdt::* constants.
src/x86_64/syscall.rs Use gdt::* selectors when configuring STAR.
src/x86_64/trap.S Treat additional exception vectors as having CPU-pushed error codes.
src/x86_64/trap.rs Update reserved-bit filtering for page-fault error codes.
src/x86_64/gdt.rs Replace custom GDT with GlobalDescriptorTable and define selector constants.
src/x86_64/idt.rs Replace custom IDT with InterruptDescriptorTable initialized via spin::Lazy.
src/x86_64/init.rs Simplify trap init flow; remove helper exports/functions.
src/x86_64/mod.rs Stop re-exporting removed/now-internal x86_64 structs/types.
src/x86_64/context.rs Replace static_assertions size check with a const assert!.
Cargo.toml Update x86_64-target deps (percpu/spin) and adjust x86_64 features; remove static_assertions/lazyinit.
Cargo.lock Reflect dependency upgrades/removals (percpu/spin; remove lazyinit/static_assertions).
Comments suppressed due to low confidence (1)

src/x86_64/mod.rs:18

  • The module no longer re-exports GdtStruct, IdtStruct, and TaskStateSegment. Since these were public exports, removing them is a breaking API change for external users that may have depended on axcpu::x86_64::{GdtStruct, IdtStruct, TaskStateSegment}. If the intent is to make these internal-only, consider providing a migration path (re-export replacements like gdt::{KCODE64,...}), or bumping the crate version to reflect the breaking change.
pub mod uspace;

pub use self::context::{ExtendedState, FxsaveArea, TaskContext, TrapFrame};


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@equation314
Copy link
Copy Markdown
Member

I think we should merge #16 and release v0.3.0 first, and then consider this PR.

@AsakuraMizu
Copy link
Copy Markdown
Contributor Author

I think we should merge #16 and release v0.3.0 first, and then consider this PR.

OK, so shall we set #25 as the "milestone" of 0.4.0?

@AsakuraMizu AsakuraMizu changed the title feat(x86_64): upgrade dependencies, simplify initialization refactor(x86_64): cleanup dependencies and initialization code Apr 7, 2026
@AsakuraMizu AsakuraMizu requested a review from Copilot April 7, 2026 10:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the x86_64 backend initialization and dependencies by simplifying GDT/IDT setup, updating trap/exception handling details, and removing now-unneeded helper APIs/crates.

Changes:

  • Replaced lazyinit/custom IDT wrapper with spin::Lazy and direct InterruptDescriptorTable initialization.
  • Reworked GDT initialization to use x86_64::GlobalDescriptorTable and new selector constants (gdt::{KCODE64,KDATA,UCODE64,UDATA}).
  • Fixed trap/exception stack layout for #CP/#VC/#SX and adjusted page-fault error-code validation to treat PROTECTION_VIOLATION as non-reserved.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/x86_64/uspace.rs Switches user CS/SS setup to new gdt::* selectors.
src/x86_64/trap.S Ensures vectors 21/29/30 follow “CPU-pushed error code” convention.
src/x86_64/trap.rs Updates #PF error-code reserved-bit filtering.
src/x86_64/syscall.rs Uses new gdt::* selectors for STAR MSR configuration.
src/x86_64/mod.rs Removes public re-exports related to GDT/IDT/TSS.
src/x86_64/init.rs Simplifies trap init path and drops init_percpu helper.
src/x86_64/idt.rs Rebuilds IDT initialization with spin::Lazy and handler address table.
src/x86_64/gdt.rs Replaces custom GDT struct with GlobalDescriptorTable + per-CPU TSS/GDT init.
src/x86_64/context.rs Replaces static_assertions with a const-size assertion.
Cargo.toml Removes lazyinit/static_assertions, adds spin, adjusts x86_64 dependency features.
Cargo.lock Updates lockfile to reflect dependency changes.
Comments suppressed due to low confidence (1)

src/x86_64/mod.rs:18

  • This module previously re-exported GdtStruct, IdtStruct, and TaskStateSegment, but those public exports were removed. Since src/lib.rs re-exports x86_64::* on x86_64 targets, this is a public API breaking change for downstream users that imported these symbols from axcpu. If the break is intended, consider documenting it in the changelog / bumping the crate version accordingly, or providing a compatibility re-export (possibly deprecated) to ease migration.
pub mod uspace;

pub use self::context::{ExtendedState, FxsaveArea, TaskContext, TrapFrame};


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants