#ProtOS!

1 messages · Page 1 of 1 (latest)

hot pagoda
#

So i've always wanted to make my own solo little kernel.... I went the wrong way and tried to vibecode it from A to Z with... horrible results of course
-# what was I thinking TwT

So i started over, disabled all AI tools and started making ProtOS for the sole purpose of further learning low-level kernel programming to prepare myself for a much bigger and serious project (nijiOS, wink-wink to my friend mono)! I hope it will be a rlly fun and educative journey!

I plan on making this alone but i still like chatting abt it and recieve help when I'm stuck because i'm a big idiot when it comes to low-level :P

Now onto the technical stuff

Architecture: x86_64
Bootloader: limine Limine (UEFI)
Language: C
Toolchain: CMake

Yea i went with the good o'l basics... Still don't know what will set this apart from other cool little OSes :P

-# for y'all wondering, ProtOS comes from protogenOS but also a derivative from Proton :3

hot pagoda
#

Now

I’m kinda lost on what to implement first thonk

I might go with GDT (whatever it is plz help me ;w;), interrupts then PIT then system panic handling and finally the absolutely scary scary paging of doom

distant stump
mild timber
#

and i did a basic kassert and panic almost at the beginning
to be fair, panic is basically
somehow lock scheduler
asm volatile("cli");
printf(random error message);
asm volatile("1:\nhlt; jmp 1b;")

hot pagoda
mild timber
#

GDT is a legacy way to do protection (long mode doesn't have it anymore basically)
idea was that you could break up the linear address space into segments
so for example instead of accessing the heap via idk 0x52876980 + offset
you could've had the ds register point to a gdt entry starting at 0x52876980, and the access to the heap would've been %ds + offset (and anyway, accessing data via memory references uses the %ds by default)
at the same time, you could've set maximum sizes (limits) of these segments as to cause GP# when the program tried to access somewhere beyond the segment
in le modern days™, most OSes skip this and make something Intel calls the "Flat segmented memory model", where each segment essentially starts at 0 and ends at 0xFFFFFFFF, making segments a noop
the only segments you might want to actually set up is the %gs (on IA-32), or %fs (on AMD64), which according to the System V ABI hold the userspace thread control block, which you need for thread local storage
for SMP kernels, you usually use one or the other for the cpu core info
AMD64 has dedicated wrfsbase and wrgsbase instructions, so you don't have to mess with the GDT at all
a little more recent AMD64 cpus even have swapgs which allows you to have a kernel gs segment and user gs segment, so the userspace is free to use it

#

this is where physical, linear, and logical addresses come into play
physical are... well physical
linear are physical after they've been put through paging
logical are offsets from the segments

so assuming the example i stated, heap being at 0x52876980 with %ds being set to that as well
heap address 0x1000 would have logical address of 0x1000, virtual of 0x52877980, and physical 0x0010F980

#

hope that helped :3

hot pagoda
mild timber
#

:3

hot pagoda
mild timber
#

well on IA-32 you need to have at least the flat model otherwise you'll get a GP# on every single memory reference (including addresses in instructions like MOV)

#

considering you're making a 64 bit os, you'll need one for the duration of you not being in long mode

#

so (idk if limine goes into long mode for you, in that case you don't need to) from limine until switching to long mode

#

and anyway
GDT itself isn't that difficult
it's enough for you to have 2 segments (for the kernel code and data), and set cs to the code, and set ds, es, fs, gs to data

#

huh i guess you need to make a gdt even in long mode
or at least there are definitions for 64 bit segments
so i guess make (hardcoding is enough) 2 segments for 32 bit mode
and 5 segments for 64 bit (ring 0 code, ring 0 data, ring 3 code, ring 3 data, TSS for interrupts from ring 3 to ring 0)

hot pagoda
#

Ok cool :3

#

Tysm twin

mild timber
#

ok did some research

#

so

#

limine does ig throw you into long mode
so in that case you need a gdt with:
the NULL descriptor
64 bit kernel code
64 bit kernel data
64 bit user code
64 bit user data
64 bit TSS

and in the TSS, assuming you don't do alternate stacks for interrupts,
set RSP0 to a per-thread kernel stack
and either create a io port bitmap, or set IOPB to the size of the 64 bit tss

#

i guess test it out
there's a nonzero chance stuff will just work without the gdt if you don't plan to jump to IA-32e mode
i never did 64 bit stuff so i'm not 100% sure
but setting valid GDT values definitely won't hurt

hot pagoda
#

Alr

mild timber
#

do tell how it's goin later
kinda interested now

hot pagoda
#

I have two math exams today so i could work on this later…

mild timber
#

fair enough
had math final exam yesterday lol

#

was pretty hard ngl but i think i have around 70 - 80% correct

mild timber
distant stump
#

I have spotted a JetBrains user

mild timber
#

jetbrains clion is peak

distant stump
hot pagoda
hot pagoda
#

I COOKED

distant stump
mild timber
hot pagoda
#

FUCK GDTTTTT

distant stump
hot pagoda
#

HECK YEAAAA IT WORKSSS

hot pagoda
#

got interrupts and GDT working!
also i cooked up a lil system panic lol

hot pagoda
hot pagoda
#

Been a while :3

#

Still doing the project I’m just having tons of homework lately lol

#

Anyways I’m almost done with the PMM so that’s good

hot pagoda
#

woah it's been a while

#

so many things happenned in the meantime like paging, heap, and now i'm working on a vfs!

#

the current state of the OS

hot pagoda
#

Sheesh tarfs somewhat works :3

formal stump
mild timber
#

nice necro post🙏

#

other than those i do vga, and uart first

#

also
a bootloader hands you a functional gdt
idt should probably be sooner, but i'd rather have proper paging so that everything is where i expect it to be

foggy turtle
#

Protogen :3

sweet cedar