-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Goal
Migrate the remaining NASM assembly files (.s extension) to GAS (GNU Assembler) format (.S extension), enabling full integration with the GCC toolchain and C preprocessor.
Context
Currently, MeniOS uses both NASM and GAS for assembly code:
- NASM files (
.s): Legacy stand-alone stubs with no C preprocessor usage - GAS files (
.S): Modern assembly that integrates with GCC, using CPP and sharing headers/macros with C code
We lean on GAS for the .S sources because they depend on the C preprocessor and share headers/macros with the C toolchain; letting GCC drive GAS keeps those files in the same compilation flow as the rest of the kernel and avoids re-implementing the macro plumbing in NASM.
The few stand-alone .s files that NASM still handles (referenced in Makefile:733-735) are legacy stubs with no CPP usage, so it's been simpler to leave them there until we either convert them to .S or drop NASM entirely.
Current NASM Files
Three files remain in NASM format:
src/kernel/lgdt.s- Load GDT (Global Descriptor Table)src/kernel/lidt.s- Load IDT (Interrupt Descriptor Table)src/kernel/pit.s- Programmable Interval Timer
These are compiled explicitly in the Makefile:
$(NASM) -f elf64 ./src/kernel/lgdt.s
$(NASM) -f elf64 ./src/kernel/pit.s
$(NASM) -f elf64 ./src/kernel/lidt.sBenefits of Migration
- Unified toolchain: Use GCC/GAS exclusively, eliminating NASM dependency
- C preprocessor integration: Access to
#include,#define, and shared kernel macros - Consistent syntax: All assembly in GAS AT&T syntax
- Simplified build: Single compilation flow through GCC
- Better maintainability: Assembly code follows same conventions as other
.Sfiles
Implementation Plan
1. Convert lgdt.s to lgdt.S
- Translate NASM Intel syntax → GAS AT&T syntax
- Update instruction syntax (e.g.,
lgdt [rdi]→lgdt (%rdi)) - Add
.intel_syntax noprefixdirective if needed to minimize changes - Update Makefile to compile with GCC
2. Convert lidt.s to lidt.S
- Similar translation to lgdt.s
- Verify IDT loading still works correctly
3. Convert pit.s to pit.S
- Translate PIT setup code
- Ensure timer interrupts still fire correctly
4. Update Build System
- Remove NASM-specific rules from Makefile (lines 733-735)
- Remove
ARCH_NASM_OBJECTSvariable (line 141) - Update
KERNEL_OBJ_FILESto use standard compilation - Remove NASM from
BUILD_REQUIRED_TOOLScheck (line 726)
5. Update Documentation
- Remove NASM from toolchain requirements
- Document GAS as the standard assembler
Testing & Validation
- Kernel boots successfully
- GDT loads correctly (check segmentation)
- IDT loads correctly (test interrupts)
- PIT timer fires at correct frequency
- All existing tests pass
Related Issues
- Refactor code structure to make it more organized #23 - Code structure refactoring (Phase 7 includes build system cleanup)
Notes
- GAS supports both AT&T syntax (default) and Intel syntax via
.intel_syntaxdirective - Most existing
.Sfiles use AT&T syntax for consistency with GCC conventions - Consider whether to use AT&T or Intel syntax for new
.Sfiles (recommend AT&T for consistency)
Definition of Done
- All three
.sfiles converted to.Sformat - NASM removed from build dependencies
- Makefile cleaned up (NASM rules removed)
- Kernel builds and boots successfully
- All interrupts and timers working correctly
- Documentation updated
Priority
HIGH - Critical for GCC/self-hosting milestone
Justification
This issue is essential for the Road to GCC milestone:
- Unified Toolchain: Eliminates NASM dependency, standardizing on GCC/GAS
- Build System Simplification: Enables Refactor monolithic Makefile into modular domain-focused structure #352 (Makefile refactoring)
- Self-Hosting Requirement: GCC compilation requires consistent toolchain
- Maintainability: All assembly follows same conventions
Impact
- Blocks Refactor monolithic Makefile into modular domain-focused structure #352 (Makefile modularization)
- Required for GCC native compilation
- Simplifies build dependencies
- Improves code consistency
Estimated Effort: 2-3 weeks part-time
Related Issues:
- Refactor code structure to make it more organized #23 (Code structure refactoring) ✅ COMPLETE
- Refactor monolithic Makefile into modular domain-focused structure #352 (Makefile modularization) - blocked by this issue