]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
refactor: per-CPU current_process via GS segment (SMP Phase 1)
authorTulio A M Mendes <[email protected]>
Mon, 16 Feb 2026 18:17:26 +0000 (15:17 -0300)
committerTulio A M Mendes <[email protected]>
Mon, 16 Feb 2026 18:17:26 +0000 (15:17 -0300)
commit08a23456f01b52b345f6c7445621f3d7f9446ba2
tree31c8356a4d8ece5f0b60ab8aa91a5cf45e6becc8
parentc0e8f3d5be74802c0156e2b2e052ad46847ecaa7
refactor: per-CPU current_process via GS segment (SMP Phase 1)

Replace the global current_process variable with per-CPU access
through the GS-based percpu_data structure on x86:

- process.h: #define current_process percpu_current() on x86,
  keeps extern fallback for non-x86
- scheduler.c: write sites use percpu_set_current()
- interrupts.S: ISR entry now reloads percpu GS by reading LAPIC ID
  from MMIO (0xC0400020) and looking up the correct GS selector in
  _percpu_gs_lut[256] — solves the chicken-and-egg problem of
  needing GS to find the CPU but GS being clobbered by user TLS
- percpu.c: _percpu_gs_lut lookup table populated during percpu_init()
- hal_cpu_set_tls: no longer loads GS immediately (would clobber
  kernel percpu GS); user TLS GS is restored on ISR exit via pop

This is the foundation for running the scheduler on AP cores.

83/83 smoke tests pass (9s), cppcheck clean.
include/process.h
src/arch/x86/interrupts.S
src/arch/x86/percpu.c
src/hal/x86/cpu.c
src/kernel/scheduler.c