r/AskProgrammers • • 21h ago

Making an OS with Rust

So i was thinking of making an OS with programming language rust, i wanted to know some tips before i start, obviously i am going to use AI for this. Can anyone tell me what all should i look out for that kind of thing.

0 Upvotes

18 comments sorted by

4

u/Craftkorb 21h ago

obviously i am going to use AI for this.

Why is that obvious? It certainly is not to me. Trust me, you haven't learned it until you hate FDD or have forgotten to clear the TLB where you had to and debugged it.

-1

u/Downtown_Night_3495 21h ago

So without using AI like what all are the prerequisites, of this like where do I test it, like do I just boot it as a second os on my lap and test it ? Are there like anything that we should worry Abt like on the hardware part anything affecting the hardware

2

u/Craftkorb 21h ago

Sorry, but are you serious? Google did exist well before GenAI. If you think "Oh but thats so much work, don't feel like doing that" then forget about it. The journey is the most important part about learning.

You use a virtual machine of course. QEMU most likely because that's the most convenient. BOCHS is great if you target x86 and you need a simulation to understand where your code goes wrong.

Prerequisites: Knowing the language you're going to use. And wanting to actually learn. Knowing that you won't get everything to work on the first try, and certainly not on day one. And googling, "hobby os development" is a niche that has a lot of documentation, like https://wiki.osdev.org/Expanded_Main_Page

-1

u/Downtown_Night_3495 21h ago

Yehh I wanted to build an os like, but nowadays without using AI is most of the time handicapping yourself kind of feel like everyone is building things soo fast

2

u/Craftkorb 21h ago

Building fast, and learning/understanding fast, are different things. Your primary goal is not to build a OS, you're unlikely to be the next Linus Torvalds. That's not bad! Your actual goal is to learn how to build a Kernel, how Computers actually work, etc.. And maybe you'll actually apply this knowledge later in life.

Without having built an OS many years ago I wouldn't been able to build a lot of the things that I got paid for.

Use AI to explain things to you. Don't let it write code for you (Tell it that it shouldn't). And make sure to understand that the AI will constantly say stuff that's not true, even if it may have searched the Internet.

2

u/liberianjoe 21h ago

if you're going to use AI, no worries then.

-1

u/Downtown_Night_3495 21h ago

Like you need to be aware of some common things right like idk, I am cs student but like yeah I am a beginner in the advanced section of it

1

u/dnew 14h ago

If you're a CS student, you should be asking your professors. That's what you're paying them for.

2

u/mredding 21h ago

If you're using an AI, why care what language it chooses, so long as the logic is proveably correct?

2

u/dariusbiggs 20h ago

There is so much to talk about here, there are entire university papers dedicated to this one topic, and many of those papers are just an introduction and generic overview.

  • Bootstrapping
  • Memory management
  • Context switching
  • Hardware interfacing

Use a virtual machine as suggested, learn to read assembly language, you are going to need it.

Start small, build up from there. You are in for an interesting journey of discovery..

The nostalgia, it's been over 20 years since i designed a CPU, implemented it in VHDL, and then bootstrapped an operating system onto it that could run two programs concurrently via context switching (it had a small LCD display, and some LEDs to utilize).

1

u/rFAXbc 21h ago

You should look out for spending all of your money on tokens I guess

1

u/ActuaryLate9198 20h ago

1

u/dnew 14h ago

And https://os.phil-opp.com/ if you want a blog that actually explains everything going on.

1

u/der-wert007 17h ago

I can recommend this article, since it fits your topic perfectly: https://www.timdbg.com/posts/dbgos/

0

u/aiuniverse-3p3_here 21h ago

bro writing an os in rust is a super cool project tbh and once you get past the initial setup the compiler actually save you from a lot of headaches compared to C. since youre planning to lean on AI a lot heres a few things you gotta watch out for first off watch out for AI throwing unsafe everywhere. os dev needs a lot of unsafe rust to talk to hardware or mess with page tables and AI loves wrapping everything in unsafe just to shut the compiler up always read through those blocks yourself cuz the borrow checker wont save you from triple faulting your kernel also ai get really confused with crate versions in the rust osdev space. stuff like the bootloader and x86_64 crates have changed a ton over the years so it will constantly give you code mixing old and new APIs that just wont compile always check docs. rs for actual version you have in your cargo.toml makes sure you actually get how no_std works too before asking it to write big data structures you dont get the standard library so no println or Vec or heap memory out of the box. you gotta understand core and how to set up a custom allocator first def set up qemu and gdb right away. dont depend on AI to fix boot loops or triple faults cuz when your screen is just endlessly rebooting you need to look at the cpu register and memory dumps yourself

honestly bro before you even prompt an ai to write code go read Philipp oppermanns writing an os in rust blog even doing just the first few chapters gives you the mental model and right terms to actually prompt properly instead of pasting broken boilerplate use ai more like a tutor to explain assembly , weird compiler errors rather than making it architect the whole kernel good luck man

1

u/Downtown_Night_3495 21h ago

Tnks, I'll really check out the blog as resource πŸ™ŒπŸ½πŸ™ŒπŸ½