Live data from Hacker News

Thor – A minimalistic operating system in assembly and C++

github.com

61–70 of 152 posts

Re: Thor – A minimalistic operating system in assembly and C++

#62
post #2

Last week I read the very good 'How to build an operating system from scratch' [1], and I'm glad I did. It meant that I could burrow into the files on this github project and understand exactly what was going on. One day, when I finally have some free time, I am totally going to do this myself. --- [1] https://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures...

That looks awesome! I did a little side project on rolling my own Unix kernel, highly recommend the guide! https://web.archive.org/web/20160301082842/http://www.jamesm...

Re: Thor – A minimalistic operating system in assembly and C++

#63

Can an operating system be developed from scratch using a safe language such as Rust? If yes, why people still even think about doing it with unsafe languages?

> If yes, why people still even think about doing it with unsafe languages?

What you need for OS or embedded development is a language that doesn't get in your way. C doesn't get in your way. C is the first language that both stayed out of your way and also provided reasonable productivity features (over BCPL, B, and assembly).

It was only recently that people have figured out how to come close to a "safe" language that doesn't get in your way.

Here is a test case: grab an ARM Cortex-Mx processor. Boot, configure the I/O matrix, and set up, oh say, the counter/timer peripherals for PWM motor control and quadrature decode. If you can do that without a trip to an "unsafe" language, that is a worthy accomplishment for your safe language.

Another test case might be doing page swapping and page-table updates on a virtual memory subsystem on a multi-core CPU without a trip to an unsafe language.

I guess a more direct answer to your question is that when you get down to the hardware, you have to deal with weirdo bit fields, volatile hardware registers, strange read/write ordering requirements, interlocks, and even some totally non-interlockable volatile stuff. C can do it (although I admit it uses language features not everyone sees every day).

Re: Thor – A minimalistic operating system in assembly and C++

#64

Earlier quoted context omitted.

Totally agreed with your comment until that: > as long as you have a disciplined team and sane coding guidelines Is it not possible at all anymore to just hire people actually understanding what they are doing? Or cargo cult is here to stay? I am sorry - please don't take that as a personal attack, but explaining people that C++ can actually be used in OS development by mindlessly sticking to some rules doesn't seem…

It's more that certain features can be way more expensive than they look. e.g. say you're working on an embedded system, and you want a string, so you do: std::string s = "fnord"; At first it seems to work fine --- but you firmware image's RAM requirements have just gone up by 32kB, and a week later there's a crisis when adding another feature causes the system to stop linking because the RAM address space is full. W…

[deleted]

Re: Thor – A minimalistic operating system in assembly and C++

#65

Earlier quoted context omitted.

I'm pretty sure it is! ( I'm also pretty sure that for a subset of the HN crowd, you may have just proven Linus's point :-P )

I think even HN readers must accept that the Windows kernel is rock solid. Maybe even better than Linux - Windows even gracefully handles graphics drivers crashing and can restart them virtually seamlessly. Linux just panics.

Graphics (speaking of modern 3D graphics) on Linux sucks, because NVidia and Co do not really care about it. It has gotten better (e.g. the deep learning crowd is mostly on Linux using cuda), but is still a far-cry from the stability of other sub-systems.

So I would say it is mostly gaming. There are not many games on Linux (again, getting better, but it takes time), so gfx vendors do not allocate big resources to support it, so the developer-experience is suboptimal, the classic chicken-egg problem.

Re: Thor – A minimalistic operating system in assembly and C++

#66
post #58

Earlier quoted context omitted.

> > Can an operating system be developed from scratch using a safe language such as Rust? > We don't know. Sure we do. Redox[0] boots into a desktop environment with a filesystem, etc etc. What we don't really know is how performant/portable/etc you could make it if you put the same amount of manpower into it as went into .

We do know some prototype can boot. We don't know about operating system being in use in any environment for any purpose. Damn, we don't know could the browser engine written in Rust work or not, despite the fact writing a browser engine was the goal of Rust from the day one. By the way, network card driver can be written in LuaJIT (and perform well) too[1]. Shall we do it? [1] http://lukego.github.io/blog/2013/01/03…

> Damn, we don't know could the browser engine written in Rust work or not, despite the fact writing a browser engine was the goal of Rust from the day one.

We kind of do at this point. It renders reasonably well, faster on some workloads than existing browsers. The majority of work still to do involves chasing down rendering bugs, and building a shell around it. That's a lot of work, but it's the sort of work that isn't breaking new ground like the work with integrating JS and the DOM and a GC into Rust, it's regular boring work. (There's some exciting things going on - see WebRender - but they're mostly theoretically optional and the browser would work perfectly fine and performant if it had much of the same infrastructure as it has today.)

> By the way, network card driver can be written in LuaJIT (and perform well) too[1]. Shall we do it?

Lua's already used for some embedded development. Using LuaJIT as a network driver in some cases seems reasonable to me - especially if you were running it as a userspace process under a microkernel.

Re: Thor – A minimalistic operating system in assembly and C++

#67

Earlier quoted context omitted.

They are pretty good indeed to begin with. However, the best resource there is is clearly osdev.org, both the forums and the wiki are full of information!

The OSDev wiki is the best think to hit the internet since sliced bread (with cats faces pushed through them?) but it's far from a tutorial. It's a wiki. While it is one of the best repositories of knowledge on the subject of low level development, it's not a step by step guide. In the same way I don't recommend that people read Wikipedia to learn about human history I'd also not recommend reading osdev to learn abou…

I don't know but the Tanenbaum books."Operating Systems Design and Implementation" is old, but the appendix is the full C source code to Minix 3.0 if you buy the 3rd Edition. I had the 1st Edition with around 12K lines of C in the appendix. Great book, and I had Minix 1.5 running on my old Amiga around 1990. Minix was more portable than Linux, which came out around 4 year after Minix. I had my money on Minix when Linux came along, since Minix was a microkernel, and I thought it sounded like the better direction to take. Well, Linux won out, and funny enough microkernels came back in style anyway with MachTen, MkLinux, and QNX. QNX was very successful in the realtime OS world. I used it on two jobs. The newer Tanenbaum book: "Modern Operating Systems" I have not read, but if it is like the first one, I'd imagine it would be very educational too.

Re: Thor – A minimalistic operating system in assembly and C++

#68
post #6
post #4

Earlier quoted context omitted.

That's Linus's opinion, yes. Not everyone has to share it.

It's a really annoying widespread opinion. I've been looking for people who really do write OSes in modern C++.

I'm the maintainer of a proprietary C++14 RTOS for work. What do you want to know?

Re: Thor – A minimalistic operating system in assembly and C++

#69

Earlier quoted context omitted.

Ha. You posted this while I was writing my answer, and I see you (very nearly) used the exact same pair of examples that I did. This is possibly a hint as to where the pain points are... (Your post is better than mine, though.)

Haha, I was just about to reply to your comment with nearly the same thing! I think one day I may need to do a book on C++ for embedded folks. Chapter 1 will be "Please don't use std::string!".

or iostreams. BTW I sure would lap the book up.
Post reply on HN