Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

inonitz/PrimOS

Repository files navigation

Contributors Forks Stargazers MIT


PrimOS

Operating System Bootloader & Kernel

About

This project was originally done for a program in the Davidson Institute Of Science Education
during my final year of High School (Grade 12)
My target platform is x86_64 as it is by far the most common ISA currently
Do note that, while the final goal was (obviously...) a little too ambitious, most of my aims were met:

  • Modern UEFI Bootloader, Using GNU-EFI & OVMF, written in C & inline assembly
  • A Simple OS kernel, featuring:
    • Simple Font & Text Rendering, enabled by UEFI-GraphicsOutputProtocol
    • IA-32e Virtual Memory Support at the Higher Half - Kernel resides in the last 512GiB of the Virtual Address Space
    • Basic Utility Libraries, including but not limited to prink
    • Global Descriptor Table (Kind of required but i'll mention it anyways ;)
    • An Interrupt Descriptor Table
      • I have an abstraction to dynamically manage interrupts, see router.h
    • Basic ACPI Support, specifically with the I/O APIC & the Local APIC
    • Kernel Timers using HPET & Local APIC Drivers
    • A Physical Memory Manager using a Page-Granular (4096 Byte) Buddy Allocator Array
    • A Virtual Memory Manager using AVL Trees (Honestly this part is untested, and needs further improvements during scheduling features)
    • Atomics mini-library using GCC & clang Specific compiler extensions
    • SMP support, Initialization of all available cores and Core-specific data structures, each cpu needs its own:
      • Task State Segment
      • Stack
      • Many more scheduling structures... (That I've yet to implement & test :) )

Currently the up-to-date branch is dev

  • the 'legacy' branch contains the unmodified code I wrote back in 2021

Considerations

The original motivation was genuine curiousity for lower-level mechanisms & abstractions during my first years of programming -
wanting to know how everything worked under the hood
I also found writing software to interact with hardware incredibly interesting

Project Structure

This project follows my premake5-workspace-template Template repository
Originally I only used a makefile, but I've graduated from that since then :)

  • [NOTE]: This project is a heavily modified version of the 'barebones' branch

Built With / Technologies Used





Getting Started

Prerequisites

  • Take extra caution when using prebuilt compilers, as they will automatically include system headers & libraries to the compilation commands, even on freestanding targets

  • On Linux:

    Just get the tools required, there should not be many/if any problems

  • On Windows:

    Personally I've had luck only with ELF-Cross-Tools & Msys2, specifically the following packages:

    • Msys2-Mingw64 Terminal (Only this Environment can supply mtools & clang for all I know)
    • mtools
    • clang
    • lld
    • lldb
    • clangd & friends
    • Do Note that ELF-Cross-Tools is used for the kernel, and msys2-mingw64-clang is used for the bootloader (I have not found a better setup yet...)

Installation without compiling

  • clone the dev branch
git clone -b dev https://github.com/inonitz/PrimOS.git
cd misc/working_example
./run.bat
./run.sh

Installation

git clone -b legacy https://github.com/inonitz/PrimOS.git
git clone -b dev https://github.com/inonitz/PrimOS.git
# Don't forget to add your own remote repo
git remote set-url origin your_github_username/your_fancy_os_kernel_name
git remote -v

Usage

call premake5 --help in the root of the repository

Common Commands:

 premake5 cleanproj --proj=kernel 
 premake5 cleanbuild
 premake5 cleancfg
 premake5 cleanclangd
 premake5 cleanall 
 premake5 export-compile-commands
 premake5 ecc (same as export-compile-commands)

The following commands build the whole project:

premake5 --cc=choose_specific_compiler ecc && premake5 --cc=choose_specific_compiler gmake
make config=Debug_amd64 -j 16 kernelimage

The following 3 targets are defined in the makefiles:

  • bootloader
  • kernel
  • kernelimage - Packages the kernel & bootloader together to an ISO image

There are 3 configurations available:

  • Debug_amd64
  • Release_amd64
  • RelWithDebInfo_amd64
  • You can add more Platforms/Configurations in the workspace.lua file (I only support AMD64)

Roadmap

  • Utilizing Profile-Guided Optimization
  • Automating setup with Docker
  • Bringing back SMP Support (Relocation Errors)
  • Syscalls
  • Context Switching And Per-process Control Blocks
  • Task Scheduling (MLFQ)
  • ext2 file system
  • USB 3.0 Support
    • Specifically USB Keyboard & Mouse Support is more relevant
  • PCIe Driver Support
  • Userspace (?)
  • Profit (????)

Contributing

I honestly Don't Care. open an issue if you're interested, I'll be sure to give it my attention

License

Distributed under the MIT License. See LICENSE file.

Acknowledgements

  • PonchoOS For a great initial youtube guide & base skeleton for my project
  • Jarod42 For the Improvements branch of export-compile-commands
  • Best-README

Resources / Bibilography

TODO Add Relevant Bookmarks for each sub-topic

AltStyle によって変換されたページ (->オリジナル) /