Skip to content

About

just a learning project for x86_64 asembly

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

MicroKernel x86_64

A minimal, expandable micro-kernel written entirely in x86_64 assembly.

Features

  • Multi-boot support: BIOS, UEFI, UEFI Secure Boot, and GRUB Multiboot2
  • Pure assembly: No C dependencies, complete low-level control
  • Modular design: Easy to extend with new features
  • 64-bit: Native x86_64 long mode operation
  • POSIX Compatible: Unix-like system call interface for backwards compatibility
  • CPU feature discovery: CPUID-based vendor, brand, and feature reporting at boot
  • Modern CPU support hooks: NX, XSAVE, and FXSR/FXRSTOR awareness during initialization
  • Console subsystem: Serial + VGA dual console output for diagnostics and debugging
  • Keyboard input path: IRQ-driven scancode capture for future shell and command input
  • Timekeeping: Monotonic tick counter and uptime reporting

POSIX Compatibility

The kernel includes a POSIX compatibility layer that provides:

  • File Operations: open, close, read, write, lseek, stat, dup, pipe
  • Process Management: fork, exit, wait, getpid, getppid
  • Signal Handling: kill, sigaction, sigprocmask
  • Memory Management: mmap, munmap, brk
  • User/Group IDs: getuid, setuid, getgid, setgid
  • Time Functions: nanosleep, clock_gettime, times

Uses Linux x86_64 syscall ABI for direct binary compatibility.

See POSIX_COMPAT.md for full details.

Directory Structure

microkernel/
├── boot/
│   ├── bios/           # Legacy BIOS boot (MBR)
│   │   └── stage1.asm  # First stage bootloader
│   │   └── stage2.asm  # Second stage (loads kernel)
│   ├── uefi/           # UEFI boot
│   │   └── boot.asm    # UEFI application entry
│   │   └── secureboot.asm  # Secure boot support
│   └── multiboot2/     # GRUB Multiboot2 header
│       └── header.asm  # Multiboot2 compliant header
├── kernel/
│   ├── entry.asm       # Unified kernel entry point
│   ├── gdt.asm         # Global Descriptor Table
│   ├── idt.asm         # Interrupt Descriptor Table
│   ├── memory.asm      # Memory management
│   ├── scheduler.asm   # Basic task scheduler
│   ├── syscall.asm     # System call interface
│   ├── ipc.asm         # Inter-process communication
│   ├── drivers/        # Expandable driver framework
│   │   ├── serial.asm  # Serial port driver
│   │   └── vga.asm     # VGA text mode driver
│   └── posix/          # POSIX compatibility layer
│       ├── vfs.asm     # Virtual file system
│       ├── signal.asm  # Signal handling
│       ├── process.asm # Process management
│       └── posix_syscall.asm  # Linux ABI syscall dispatcher
├── include/
│   ├── macros.inc      # Common assembly macros
│   └── posix.inc       # POSIX constants and structures
├── docs/
│   ├── EXTENSION_GUIDE.md  # How to extend the kernel
│   └── POSIX_COMPAT.md     # POSIX compatibility details
├── scripts/
│   ├── build.sh        # Build script
│   └── generate_keys.sh # Secure Boot key generation
└── Makefile            # Main build file

Building

Prerequisites

  • NASM (Netwide Assembler)
  • GNU ld (linker)
  • QEMU (for testing)
  • mtools (for disk images)
  • gnu-efi (for UEFI builds)

Build Commands

# Build all boot targets
make all

# Build specific targets
make bios        # Legacy BIOS bootable image
make uefi        # UEFI bootable image
make multiboot2  # Multiboot2 ELF for GRUB

# Clean build artifacts
make clean

# Run in QEMU
make run-bios    # Test BIOS boot
make run-uefi    # Test UEFI boot

Architecture

Boot Flow

BIOS Boot:
  MBR → Stage1 → Stage2 → Protected Mode → Long Mode → Kernel

UEFI Boot:
  UEFI Firmware → Boot Application → Long Mode → Kernel

Multiboot2 Boot:
  GRUB → Multiboot2 Header → Protected Mode → Long Mode → Kernel

Memory Map (after boot)

0x0000_0000_0000_0000 - 0x0000_0000_0000_0FFF : Reserved (Real Mode IVT)
0x0000_0000_0000_1000 - 0x0000_0000_0000_7BFF : Free (low memory)
0x0000_0000_0000_7C00 - 0x0000_0000_0000_7DFF : BIOS Boot Sector
0x0000_0000_0001_0000 - 0x0000_0000_0009_FFFF : Kernel Code/Data
0x0000_0000_0010_0000 - 0x0000_0000_001F_FFFF : Kernel Heap
0x0000_0000_0020_0000 - ...                   : User Space

Expanding the Kernel

  1. Adding a new driver: Create a new .asm file in kernel/drivers/
  2. Adding a syscall: Register in kernel/syscall.asm
  3. Adding an interrupt handler: Register in kernel/idt.asm

Secure Boot Support

For UEFI Secure Boot, you need to sign the bootloader:

# Generate keys (one time)
./scripts/generate_keys.sh

# Sign the UEFI binary
sbsign --key MOK.key --cert MOK.crt --output bootx64-signed.efi bootx64.efi

License

MIT License - Feel free to use and modify.

About

just a learning project for x86_64 asembly

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages