SimpleOS is a basic operating system designed as a learning project to understand low-level programming concepts such as bootloaders, kernel development, and system architecture.
- GRUB (Grand Unified Bootloader) has been successfully implemented as the bootloader for SimpleOS.
- GRUB loads the kernel from the ISO file and transfers control to the kernel's entry point.
- The
menu.lstconfiguration file provides instructions for GRUB to locate and load the kernel (kernel.elf).
- A basic kernel entry function has been implemented.
- The kernel entry function is defined in
loader.s(written in assembly) and hands over control tokmain, a C function.
-
A Global Descriptor Table (GDT) has been implemented to enable memory segmentation in protected mode.
-
The GDT defines the following segments:
Segment Name Selector Base Address Limit Type Privilege Level Null Segment 0x000x000000000x00000000Reserved N/A Kernel Code Segment 0x080x000000000xFFFFFFFFRead/Execute 0(Kernel Mode)Kernel Data Segment 0x100x000000000xFFFFFFFFRead/Write 0(Kernel Mode)User Code Segment 0x180x000000000xFFFFFFFFRead/Execute 3(User Mode)User Data Segment 0x200x000000000xFFFFFFFFRead/Write 3(User Mode) -
This segmentation setup ensures the separation of kernel code and data, providing a foundation for memory protection and management.
- A Programmable Interrupt Controller (PIC) is used to manage hardware interrupts, remapping them to avoid conflicts with CPU exceptions.
- A Interrupt Descriptor Table (IDT) has been implemented to define and manage interrupt vectors.
- Support for both hardware interrupts (e.g., keyboard, timer) and CPU exceptions has been added:
- Keyboard Interrupt (IRQ1): Converts scancodes into ASCII characters and prints them to the screen.
- Timer Interrupt (IRQ0): Currently acknowledges the interrupt but serves as a foundation for future scheduling and multitasking functionality.
- The interrupt handling system preserves CPU state, processes the interrupt, and restores state before returning.
- Framebuffer driver:
- Enables interaction with the video memory to write text directly to the screen.
- Provides functions for clearing the screen and writing strings or characters at specific positions.
- Implemented in
framebuffer.candframebuffer.hunder thedriversdirectory.
- I/O Ports driver:
- Implements low-level input and output operations for hardware communication via I/O ports.
- Provides helper functions like
outbandinbfor sending and receiving data to/from specific ports. - Implemented in
io.sandio.hunder thedriversdirectory.
- Serial Port driver (COM1):
- Enables communication through the COM1 serial port.
- Provides functions to initialize the serial port, send data, and receive data.
- Useful for debugging and inter-process communication.
- Implemented in
serial.candserial.hunder thedriversdirectory. - Results of a serial_write() are printed in the com1_log.txt file
- Keyboard driver:
- Simple keyboard driver that converts scancode into ascii
- Ring 3 Transition: Successfully implemented the transition from Kernel Mode (Ring 0) to User Mode (Ring 3).
- GDT Updates: Extended the Global Descriptor Table to include User Code and User Data segments with specific DPL (Descriptor Privilege Level) set to 3.
- Task State Segment (TSS):
- Implemented and loaded the TSS to manage stack switching during interrupts.
- Ensures the CPU can safely switch back to the Kernel Stack (
ESP0) when an interrupt occurs while in User Mode.
- Paging for User Mode: Updated page tables to allow User Mode access (
Userbit set) to necessary memory regions (code and stack).
- Virtual File System (VFS):
- Implemented a VFS abstraction layer to manage file nodes (
fs_node_t) and standard operations (ls,write,cat,rm) uniformly, independent of the underlying storage device.
- Implemented a VFS abstraction layer to manage file nodes (
- Storage Mechanism:
- Utilizes a RAMDisk approach where a standard
.tararchive is loaded into physical memory by GRUB as a Multiboot Module. - The file system is non-persistent (changes are lost on reboot), serving as an initial RamDisk (InitRD).
- Utilizes a RAMDisk approach where a standard
- TAR Driver:
- Implemented a parser for the USTAR (TAR) file format in
kernel/tar.c. - Scans the memory region provided by GRUB to identify file headers, convert octal sizes, and map content offsets.
- Dynamically creates VFS nodes for files found within the archive.
- Implemented a parser for the USTAR (TAR) file format in
- Overview: SimpleOS implements basic multithreading support via kernel threads and a preemptive round-robin scheduler driven by the PIT timer.
- Ready Queue: The scheduler uses a circular linked list as the ready queue; each
process_tnode stores the thread'sesp, PID and name. - Scheduler: A simple round-robin scheduler is implemented;
- Limitations & Future Work:
- No priorities — scheduling is strictly round-robin.
- Focus is on kernel threads; a full user-mode process loader and finer isolation are future improvements.
- Additional synchronization primitives (semaphores, condition variables) would improve multi-threaded programs.
- loader.s: Implements the Multiboot header and transfers control to the kernel entry function.
- kernel/kmain.c: Contains the kernel's entry point.
- link.ld: Linker script to organize sections of the kernel binary and ensure compatibility with the Multiboot protocol.
- drivers: Contains all the drivers implemented for the kernel
- com1_log.txt: Contains the results of the serial port communication on com1 (Used for debug information), you can comunicate on that port with serial_write()
- NASM: Assembler for
loader.s. - GCC: Compiler for
kmain.c. - genisoimage: For generating the bootable ISO.
- Bochs: Emulator to test the OS.
- Compile the kernel source files:
make- Generate the bootable ISO:
make run- Run the OS in the Bochs emulator by choosing the configuration file in the repo (bochsrc.txt)
To remove all generated files:
make clean- Expand kernel functionality
- Enrich shell for user interaction.
This project is open to contributions. Feel free to fork the repository and submit a pull request with your changes or improvements.