Skip to content

refactor(x86_64): replace lazy_static GDT boilerplate with const GlobalDescriptorTable - #14

Merged
imtsuki merged 3 commits into
masterfrom
refactor/clean-gdt
Nov 13, 2026
Merged

imtsuki merged 3 commits into
masterfrom
refactor/clean-gdt

Conversation

@imtsuki

@imtsuki imtsuki commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Cleans up GDT & TSS initialization using x86_64 0.15's const GlobalDescriptorTable / Descriptor APIs without lazy_static!, magic selector indices, or aliasing UB:

  • const fn base_gdt() & pub const SELECTORS: Derives both the base GlobalDescriptorTable and Selectors (kernel_code, kernel_data, user_data, user_code) from a single const source of truthβ€”zero hardcoded GDT indices, zero manual set_rpl / PrivilegeLevel, zero assert!s.
  • Unified Per-CPU CpuGdt & Sound Raw-Pointer TSS: Packs (GlobalDescriptorTable, TaskStateSegment, IstStack) into a single CpuGdt (with a 16-byte-aligned 16 KiB #DF IST stack) and uses Descriptor::tss_segment_unchecked(&raw const (*cpu).tss) + load_unsafe() instead of creating an invalid &'static TaskStateSegment over a mutable TSS.
  • Uniform Null Data Selectors: Clears DS, ES, FS, and GS to SegmentSelector::NULL on boot (matching hardware iretq -> syscall steady state and clearing UEFI's stale FS).
  • Drop #PF IST (PAGE_FAULT_IST_INDEX): Keeps IST exclusively for #DF (DOUBLE_FAULT_IST_INDEX) so #PF remains reentrant for future CoW / lazy paging while kernel stack overflows are caught by KernelStack guard pages escalating to #DF.
  • Slimmer PerCpu & syscall_entry: Removes user_cs and user_ss from PerCpu (shrinking it to 16 bytes) and pushes const gdt::SELECTORS.user_* immediates directly in syscall_entry.

Verification

  • make build (dev & release) + cargo check with frame-allocator-buddy
  • Booted in QEMU (debug & release) and verified Ring 3 /init shell execution, syscall/iretq transitions, and hardware interrupts

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: βœ… Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
πŸ“ Code Review βœ… Completed 2026-11-13T23:16:09.420087Z 107a8ca New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with πŸ‘€ while any review is running, comments if it has suggestions, and reacts with πŸ‘ once all reviews finish with no findings.

@imtsuki imtsuki changed the title refactor(x86_64): replace x86_64/lazy_static GDT & TSS with static [u64; 7] table refactor(x86_64): replace lazy_static GDT boilerplate with const GlobalDescriptorTable Nov 13, 2026
@imtsuki
imtsuki merged commit 1f0a197 into master Nov 13, 2026
2 checks passed
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.

1 participant