SlugOS is my little hobby OS project that I have been working on for a bit now (about 7 - 8 months, almost a year), though SlugOS is its name, the kernel itself is called Mantle and is on its 10th rewrite (I am a perfectionist and sometimes stuff gets to complex, I am very deep into stuff I do not know, and have to rewrite to get an improved version and fix any issues that pop up), it uses limine, has a full PMM, VMM, and a heap allocation system, and even a very simple API (only printing strings and single characters), the plan is to at some point get a shell, and run actual apps from an initramfs (which it can do with flat binaries, but I want ELF64), and then a real filesystem, dev.to will act as my place to blog/talk about SlugOS/Mantle.
Mantle has some other features:
- SSE1/SSE2 support
- The legacy 8259 PIC (Programmable Interrupt Chip)
- The legacy Intel 8253/8254 PIT (Programmable Interrupt Timer)
- A full kprint (printf) implementation, minus some things, like floating point support, but works with most stuff.
- A disk driver (ATA PIO mode, not very good)
- FAT32 disk driver
An example program (in NASM assembly) that would print out a string, might look like this
BITS 64
section .text
global _start
_start:
mov rsi 1 ; Print string code
mov rdi string ; The 2nd arg
int 0x70 ; The system API
ret ; Return to the program calling this
section .data
string db "API test!", 0
Of course this will not work unless I get a working ELF loader which could mean a full libelf implementation, or at least a very basic ELF loader, and in theory a ring 3/userspace setup. I plan to get a FAT32 driver beforehand. The current setup for running apps is a flat binary and just doing a direct jump to them, due to not having any idea on where it goes, in the binary it must have hardcoded values instead of strings at a memory address, an app might look like this
BITS 64
; This is for the system API, this is compiled and put into the initramfs
; System call 0 (print char) - 'H'
mov rdi, 0
mov rsi, 0x48
int 0x70
; System call 0 (print char) - 'E'
mov rdi, 0
mov rsi, 0x45
int 0x70
; System call 0 (print char) - 'L'
mov rdi, 0
mov rsi, 0x4C
int 0x70
; System call 0 (print char) - 'L'
mov rdi, 0
mov rsi, 0x4C
int 0x70
; System call 0 (print char) - 'O'
mov rdi, 0
mov rsi, 0x4F
int 0x70
; System call 0 (print char) - ','
mov rdi, 0
mov rsi, 0x2C
int 0x70
; System call 0 (print char) - ' '
mov rdi, 0
mov rsi, 0x20
int 0x70
; System call 0 (print char) - 'A'
mov rdi, 0
mov rsi, 0x41
int 0x70
; System call 0 (print char) - 'P'
mov rdi, 0
mov rsi, 0x50
int 0x70
; System call 0 (print char) - 'I'
mov rdi, 0
mov rsi, 0x49
int 0x70
; System call 0 (print char) - ' '
mov rdi, 0
mov rsi, 0x20
int 0x70
; System call 0 (print char) - 'W'
mov rdi, 0
mov rsi, 0x57
int 0x70
; System call 0 (print char) - 'O'
mov rdi, 0
mov rsi, 0x4F
int 0x70
; System call 0 (print char) - 'R'
mov rdi, 0
mov rsi, 0x52
int 0x70
; System call 0 (print char) - 'L'
mov rdi, 0
mov rsi, 0x4C
int 0x70
; System call 0 (print char) - 'D'
mov rdi, 0
mov rsi, 0x44
int 0x70
; System call 0 (print char) - '!'
mov rdi, 0
mov rsi, 0x21
int 0x70
; System call 0 (print char) - Newline
mov rdi, 0
mov rsi, 0x0A
int 0x70
; Return
ret
Which, of course, is long, ugly, and not very readable or useful since it lacks basic features. Moving beyond these flat binaries to a proper ELF loader and a more robust API is a key next step for the Mantle kernel, and I'm excited to share that progress with you as SlugOS continues to evolve. Have a great day or night wherever you are.