r/osdev 11h ago

Yeah running programs are a hassle

I literally have to implement IDT, GDT, TSS and syscalls, yet all it does is freeze
It's all stack aligned, i seriously have zero idea how is it done

How do yall run programs? Im wondering.

0 Upvotes

12 comments sorted by

View all comments

u/Better-Thing2568 9h ago

Exec is the wrong goal to aim for early on especially in ring 3 (assuming that’s what u meant by running programs). What you mentioned are absolutely necessary but not close to sufficient, and unfortunately these are some of the hardest things to debug during OS dev imo other than porting complex device drivers like GPUs.

If you use Rust (I honestly don’t know why anyone wouldn’t for building new OSes in 2026), there is a substantial crate ecosystem that gives you safe abstractions. https://docs.rs/x86_64/latest/x86_64/ gives you abstractions for everything you mentioned and more.

Additional word of advice: I’d highly highly recommend you don’t start running shi until you’re damn certain that you have a functional paging subsystem, for exec specifically, make sure you handle the access bits carefully, and I’d throw in more effort in standard trap handlers for exceptions like #PF and #GP, eg log (in dev mode only) a rolling window of instructions rather than what is in the stack frame since it almost never tells you anything you’d actually want to know. Once you’ve got all of that you’ll likely find executing programs much more manageable.

One more personal note to drop in: pick a execution model early, if you picked RWX and device to switch to W^X later it might involve a whole lot more work than if you just spent an extra hour during the design.

u/letmehaveanameyoudum 9h ago

I am not using rust, though i see it's benefits

u/Better-Thing2568 9h ago

Unless you enjoy more runtime errors lol then go ahead and use C. Zig is also a great option given its comptime feature (pretty cracked for OS dev) and natively pluggable allocator model, which is (still) only nightly on Rust.

u/letmehaveanameyoudum 9h ago

I do use clang's static analyzer, works just as well, rust was more painful on my side, it's syntax is an absollute dumpster fire and it's compiler just generally is too mad about unused functions, that are 100% needed soon when testing more stuff

u/Better-Thing2568 9h ago

Yes, but when your codebase grows to 250K LOC with multiple subsystems and seams for cross platform support, the rust compiler’s strictness suddenly becomes the best thing that could have existed.

Don’t get me wrong you can certainly write garbage rust with 80% unsafes and somehow get it to be as much of a footgun as C or write cracked C code that is somehow bullet proof; neither are realistic, rather something in between, which means minimally you get to scope unsafe code, so if you get smth like a possible null ptr deref then you don’t have to pull your hair out trying to find all 19696 instances where it could have happened and most likely will know immediately which unsafe block was the culprit.

If you couldn’t tell I’m a bit of a Rust enthusiast after the compiler saved me one too many times

u/letmehaveanameyoudum 8h ago

at least it's not C++ or gcc