Skip to content

monitoria-ti-ceub/Labubuntu

Repository files navigation

LABUBUNTU - Micro Kernel x86_64

Um kernel didático completo em Rust, com componentes em x86_64 Assembly e C. Projeto educacional para aprender arquitetura de kernels modernos.

Características

Arquitetura: x86_64 64-bit Linguagem Principal: Rust Bootloader: Multiboot2 compliant Gerenciamento: Memória, Processos, Interrupts Drivers: Timer (PIT), Interrupt Controller (PIC) Sistema de Arquivos: RAMDisk simples Syscalls: Interface base

Estrutura do Projeto

labubuntu/
├── src/
│   ├── main.rs           # Entry point do kernel
│   ├── lib.rs            # Lib do kernel
│   ├── serial.rs         # Driver UART serial
│   ├── panic.rs          # Panic handler
│   ├── arch/             # Arquitetura x86_64
│   │   ├── gdt.rs        # Global Descriptor Table
│   │   ├── interrupts.rs # Interrupt handlers
│   │   └── x86_64/
│   ├── mm/               # Memory Management
│   │   ├── allocator.rs  # Memory allocator
│   │   ├── paging.rs     # Virtual memory
│   │   └── heap.rs       # Kernel heap
│   ├── process/          # Process management
│   │   ├── process.rs    # Process structure
│   │   ├── scheduler.rs  # Process scheduler
│   │   └── task.rs       # Task/thread manager
│   ├── drivers/          # Hardware drivers
│   │   ├── pit.rs        # Programmable Interval Timer
│   │   └── pic.rs        # Programmable Interrupt Controller
│   ├── fs/               # File system
│   │   ├── ramdisk.rs    # RAM-based filesystem
│   │   └── inode.rs      # Inode structure
│   └── syscall/          # System calls
│       ├── mod.rs        # Syscall infrastructure
│       ├── call_numbers.rs # x86_64 syscall numbers
│       └── dispatch.rs   # Syscall dispatcher
├── bootloader/
│   ├── boot.asm          # X86_64 bootloader
│   └── kernel.ld         # Linker script
├── userland/             # User-mode programs
├── Cargo.toml            # Cargo dependencies
├── Makefile              # Build system
└── README.md             # This file

Dependências

Sistema

  • Rust 1.70+ (nightly)
  • QEMU (para emular)
  • GCC/Clang (para compilar C/Assembly)
  • GNU Make

Rust crates

x86_64 = "0.15"
uart_16550 = "0.3"
volatile = "0.5"
spin = "0.9"
xmas-elf = "0.9"

Construção e Execução

Build

# Compilar kernel
make build

# Ou com cargo direto
cargo build --release --target x86_64-unknown-none

Executar

# Rodar em QEMU
make run

# Debug com GDB
make debug
# Em outro terminal:
gdb -ex 'target remote :1234' target/x86_64-unknown-none/release/kernel

Criar ISO bootável

make iso
# Resultado: labubuntu.iso

Componentes Implementados

1. Boot & Initialization

  • Multiboot2 bootloader
  • Long mode (64-bit) setup
  • GDT (Global Descriptor Table)
  • IDT (Interrupt Descriptor Table)
  • Basic exception handlers

2. Memory Management

  • Kernel heap (256KB)
  • Virtual memory paging (basic)
  • Bump allocator
  • Page frame allocator

3. Process Management

  • Process table (256 processes max)
  • Process states (Ready, Running, Blocked, Terminated)
  • Process context switching
  • Round-Robin scheduler (basic)

4. Interrupt Handling

  • Exception handlers (Breakpoint, GPF, Page Fault)
  • Interrupt controller setup
  • Timer interrupt (PIT)
  • Keyboard interrupt (basic)

5. Device Drivers

  • Serial UART (16550 compatible)
  • Programmable Interval Timer (PIT 8254)
  • Programmable Interrupt Controller (PIC 8259)

6. System Calls

  • Syscall dispatcher
  • Basic syscalls: write, exit, getpid
  • x86_64 AMD64 ABI compliant

7. File System

  • Simple RAM disk filesystem
  • Inode structures
  • Basic file operations (create, read, write)

Exemplos de Uso

Hello World (C user program)

#include <syscall.h>

void main() {
    syscall_write(1, "Hello from LABUBUNTU!\n", 23);
    syscall_exit(0);
}

Compilar programa de usuário

# User program (from userland/)
gcc -nostdlib -o hello hello.c
# Vai rodar no kernel

Desenvolvimento

Code style

  • Rust style via cargo fmt
  • Linting with cargo clippy

Comandos úteis

make fmt       # Format code
make clippy    # Lint code
make check     # Type check
make docs      # Generate docs

Roadmap

Phase 1 (Done)

  • Basic bootloader
  • GDT/IDT setup
  • Memory management basics
  • serial console
  • Simple process manager

Phase 2 (In Progress)

  • Full paging implementation
  • User mode execution
  • More syscalls
  • Keyboard driver

Phase 3 (Planned)

  • Shell (basic command interpreter)
  • File system (ext2-like)
  • Network stack (basic)
  • Multi-core support
  • Shared memory

Debugging

QEMU Tips

# Start with monitor
qemu-system-x86_64 -kernel kernel -monitor stdio

# Useful QEMU monitor commands:
# info registers
# info mem
# xp /10i $rip  (examine 10 instructions at RIP)

GDB Commands

gdb target/x86_64-unknown-none/release/kernel

# GDB commands:
# b main           - Break at main
# c                - Continue
# si               - Step instruction
# p $rax           - Print register
# x/10i $rip       - Examine 10 instructions
# bt               - Backtrace

Contribuindo

Ideias para contribuição:

  1. Implementar mais drivers (e.g., AHCI, XHCI)
  2. Expandir filesystem (journaling, ext2)
  3. Adicionar networking básico
  4. Implementar mutex/semaphores robustos
  5. Criar shell de usuário
  6. Portar programas userland

Referências

Licença

MIT License - Veja LICENSE para detalhes

Autor

LABUBUNTU Kernel Team

  • Educacional
  • Open Source
  • Learning Resource

**Building the future of open-source kernels! **

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors