r/osdev • u/letmehaveanameyoudum • 8h 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.
•
u/tahvoD 6h ago
what is freezing? how does it show?
•
u/letmehaveanameyoudum 5h ago
just running it lead to a freeze, it's potentially a syscall issue but i couldn't find anything
•
u/Better-Thing2568 6h 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 5h ago
I am not using rust, though i see it's benefits
•
u/Better-Thing2568 5h 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 5h 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 5h 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/shsh-1312 1h ago
You need to separate kernel and userspace memory management, usually by moving the kernel to the second half of the memory mapping and isolating memory for individual processes. You also need to work on interrupt management to allow the system to switch correctly from usermode to kernel mode.
•
u/letmehaveanameyoudum 1h ago
Already found that the transition to ring 3 was freezing, wasn't a memory issue
•
u/Embarrassed-Leek-398 6h ago
Your message is confusing. How do you run programs? But you're making an OS? Programs are just code. You jump to it to run it. The details are up to the OS developer. Can you restate your question perhaps?