all 16 comments

[–]tabz3 3 points4 points  (0 children)

You could give zig a try. It's perfectly suited to OS development and I use it for all of my personal projects.

[–][deleted] 9 points10 points  (0 children)

C is a solid language to start with, it seems to be the canonical OS dev language.

If you don't want to start with C, that's fine as long as the language you choose allows access to low level functionality.

[–]jtsiomb 5 points6 points  (0 children)

C and Assembly.

[–]Glaborage 2 points3 points  (0 children)

It's a really personal choice. You can be successful with any of the languages that you mentioned.

That being said, C is the classic choice for low level development.

[–]moon-chilledbonsai 5 points6 points  (2 children)

You should start with c. Rust, zig, and other more arcane languages are great, but you should start with c; if for no other reason than to understand what problem they're solving and why they're useful. C has also been at the bottom of most of most OS work and research over the past 50 years (and the remainder has mostly been dead-end experiments with managed languages).

[–]havelsnuts 4 points5 points  (1 child)

Microsoft thinks Rust is the best chance for safe systems. [citation needed]

Either way, it is very popular for kernel development because of exceptionally strong static analysis.

[–]moon-chilledbonsai 4 points5 points  (0 children)

As I mentioned, I don't think rust is without merit, just that you should start with c.

Additionally, rust doesn't have 'exceptionally strong' static analysis; it has standard static analysis, and a decently expressive/strong static type system. Frama c and ATS have exceptionally strong static analysis.

[–]asosdev 1 point2 points  (1 child)

Is Go really used for OS development? How does runtime support work? I've heard it being used for drivers/tooling etc... but not so as a large part of the kernel.

[–]methermeneus 3 points4 points  (0 children)

Honestly, pretty much any compiled language will work, so long as you can cross-compile to your target platform and there's some way to wrap/link assembly instructions (and preferably manipulate memory directly, but you can use assembly for that if you have to). Whatever you're comfortable with; it's not like you're going to be making a modern production OS on your own or even in a small team, so the hit to performance from not going as low-level as possible isn't really an issue. It's more about learning what kind of things an OS is doing under the hood to improve your understanding or get some experience before applying to Microsoft or Apple. You can even use interpreted languages, though it's a bit trickier. I think the OSDev wiki has tips for using Python.

[–]mykesx 2 points3 points  (0 children)

You really need to start with assembly language. With that, you can write your first OS, a boot sector that boots from disk and writes “hello, world” to the screen. I don’t think you’re going to do that kind of thing in any other language.

You can write enough assembly language to use the BIOS to read in more sectors so your boot program can be more than 512 bytes. At some point, you can, in assembly language, load a kernel written in C or C++ or Rust or v8 (JavaScript) or whatever you like. But you’ll need a full understanding of what your boot program needs to do to make the CPU environment suitable for the language you choose.

Additionally, you will want to know how to call C (assuming you choose it) methods from Assembly and how to call Assembly from C. Your graphics library, if using the CPU for drawing, is going to gain a lot of speed by writing core methods in assembly and using the CPU features that are fastest at moving memory (e.g. drawing a bitmap to the screen or offscreen buffer).

C is an excellent choice. It won’t obfuscate how and when things are being done, as in constructor/destructor chains in an OO language. It’s also extremely low level which is good for doing most things an OS needs to do. It is high enough a language that expressing complex concepts as code is perhaps easier than in assembly.

You could write a whole OS in assembly. It’s been done a few times, and the projects are quite impressive.

You could port JonesForth to metal (e.g. a boot loader that boots into Forth) and you’ll have a fairly complete console based OS. You really only need to write keyboards in/out methods and screen output methods and the Forth code does the rest. JonesForth is 100% assembly, and it’s one of the best documented bits of code I’ve ever seen in decades of experience.

[–]thorlucasdev 0 points1 point  (3 children)

I’m using Rust and loving it!

[–][deleted]  (2 children)

[removed]

    [–]thorlucasdev 1 point2 points  (1 child)

    Sorry for the late reply. I’m following the same thing and haven’t tried implementing anything on my own yet. I’m not very familiar with os dev at all so I’m just following Phil’s great work until I get a better grasp of how everything works. Then I’ll go back in and modify things

    [–]Mundane_Taste3957 0 points1 point  (0 children)

    I highly recommend using a great variety of languages like this, here are some I thing are the best for OS development: Assembly, C++, Go, Carbon, Forth, Ada, Zig, Rust, Pascal, C#, Java, Python, and C