/kerosene

A hobby x86 OS written in C

Primary LanguageCMIT LicenseMIT

Kerosene

A hobby x86 monolithic OS written in C
This is an attempt of me to learn about osdev

Features

  • PS/2 keyboard driver
  • ATA PIO mode
  • FAT32 filesystem support
  • basic VESA driver (i think)

Build and run

Prerequisite

  • A GCC cross compiler. although a preinstalled GCC on linux will compile it just fine, the osdev wiki said we should use a cross compiler to avoid any unexpected errors.
    • if you are lazy to install one, use make all NO_CROSS_COMPILER=1 to compile using linux GCC (please do not report any errors if you use this option)
    • if you use a cross compiler then please check and correct the CROSS_COMPILER_LOC in the second line of Makefile
  • nasm
  • dosfstools
  • grub (and xorriso to gen iso image)
  • qemu

Build and run

# build
chmod +x script/*.sh
make all
# run
./script/run.sh # or make run
# make iso
./script/geniso.sh
# editing the disk files
./script/mount-device.sh
cd mnt/
## do some stuffs here
./script/umount-device.sh # you also want to run this if you ever encountered errors like disk image is in use or whatever
# if you want to copy some files/dirs and dont want to run mount-device and then umount-device
./script/cpyfile.sh file/or/directory/in/somewhere ./mnt/some/DIRECTORY/in/the/disk

Files and directories in fsfiles/ will be automatically copied into the disk image after running make all.
Note that scripts in script/ will need sudo privilege to setup loopback device for the hard disk image.

Running on real hardware

You can either make an iso ./script/geniso.sh and burn it to an usb or use sudo dd if=disk.img of=/dev/sdX && sync to burn the disk to an usb to run the OS. Note that ISO 9660 FS and usb driver are not implemented so the OS will perform filesystem commands on whatever partitions with FAT32 fs it found so just dont perform fs command and you will be fine.

Note

I am not responsible for any damage caused to your machine by the OS. Try this with your own risk!

Progress

Baby first step

  • basic bootloader
  • load the kernel
  • 2-stage bootloader
  • print some text in the kernel
  • switch to GRUB

Kernel stuffs

  • load GDT in the kernel
  • load IDT in the kernel
  • handle exception interrupt
  • handle interrupts send by PIC
  • load kernel with ELF binary instead of flat binary
  • support multiboot
  • higher half kernel

Hardware drivers

  • PS/2 keyboard driver
    • get key scancode
    • translate scancode to keycode
    • LED indicating
  • PIT
    • generate ticks
    • PC speaker (beep beep boop boop)
  • memory manager
    • physical memory manager: bitmap allocator
    • virtual memory manager
    • the heap: first-fit allocator
  • ATA
    • PIO mode
  • CMOS and RTC: get datetime
  • APCI
  • APIC
  • HPET
  • PS/2 mouse driver
  • VESA
    • plot pixel
    • render psf fonts
  • USB
  • sound
  • im not gonna touch networking

Filesystem

  • MBR support
  • GPT support
  • FAT32 fs
    • detect
    • list
    • make dir
    • remove dir
    • touch files
    • read
    • write file
    • move
    • copy
  • ext2 fs
  • vfs

Userland

  • TSS setup
  • enter usermode
  • syscall
    • putchar
    • current time
    • read file
    • write file
  • process manager
  • multitasking
  • load and run ELF file

Known bugs

  • ATA PIO mode initialization some time failed (very rare): address mark not found
  • print_debug gives gliberrish result if put in many formats
  • processes not giving control back properly

Learning resources

Note that anything related to osdev are on the osdev wiki

Great tutorials

Documents