
Thor – A minimalistic operating system in assembly and C++ - ingve
https://github.com/wichtounet/thor-os#thor-os
======
Jaruzel
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...](https://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-
dev.pdf)

~~~
gravypod
Check out the broken thorn tutorials on the subject. They are far more
complete.

~~~
Jaruzel
I will!

I'm guessing you mean these..?

[http://www.brokenthorn.com/Resources/OSDevIndex.html](http://www.brokenthorn.com/Resources/OSDevIndex.html)

~~~
wichtounet
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!

~~~
gravypod
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 about low level
development.

It at it's heart is organized as a reference, not a text book.

I wish that someone would go through and accumulate all the knowledge, put it
into a series based textbook with chapters, throw in some example code and VMs
for many architectures, and sell it to me because I'd pay. I'd also push for
those at my university to construct a class around the book as it would be one
of the most fascinating and knowledge packed classes I'd think you could take.
(Hint hint, nudge nudge writers and professors!)

But yes to date NOTHING beats osdev.

~~~
faviouz
What would be a good step-by-step tutorial in your opinion?

~~~
gravypod
If you'd like the links that really helped me, check out this:

[http://www.osdever.net/bkerndev/Docs/title.htm](http://www.osdever.net/bkerndev/Docs/title.htm)

[http://www.brokenthorn.com/Resources/OSDevIndex.html](http://www.brokenthorn.com/Resources/OSDevIndex.html)

[https://github.com/stephenfewer/NoNameOS](https://github.com/stephenfewer/NoNameOS)

[https://anastas.io/osdev/memory/2016/08/08/page-frame-
alloca...](https://anastas.io/osdev/memory/2016/08/08/page-frame-
allocator.html)

[https://github.com/kjiwa/x86-boot-
sector-c](https://github.com/kjiwa/x86-boot-sector-c)

These are all useful. If you're more of a book worm check out Minix as said in
other parts of this tree. Very very easy to read, interesting bits of history
about OS development, and source code included! Nothing's useful without
source code.

If you'd like to look up some general software books check out Programming the
IBM PC, or something to that effect. It's commonly called The Pink Shirt Book.
Has interesting stuff on IBM interrupts, coding standards, and bits on
filesystems!

------
_c_
+1 for being able to run on Bochs.

There's nothing minimalistic about Qemu. It's an enormous resource intensive
program to build. And it's not even easy to run in text mode (no x11). "Qemu-
lite" is sorely needed.

~~~
Sir_Cmpwn
It's actually quite easy to run in text mode, just add -nographic. It
automatically hooks the serial port up to your terminal, too.

~~~
_c_
What OS are you using?

Is it working for you in VGA text mode (no x11)?

Is this now working on other UNIX-like OS besides Linux?

I have had problems with -nographic in the past and I know others who have as
well, but maybe it works reliably now?

~~~
Sir_Cmpwn
You mean can I run it without having X11 running? Yes, of course, with
-nographic. How do you think most major VPS providers run qemu? They certainly
don't run their hosts with X11 going.

And yes, it runs on not-Linux, but obviously the main selling point of qemu is
the access it provides to KVM, which is an interface provided by the Linux
kernel. You can do software emulation of a number of architectures on a number
of operating systems with qemu.

~~~
_c_
Are you saying you yourself do this? You're using BSD, running in VGA
textmode, from which you run qemu with -nographic to load an image of another
OS? You yourself are doing this?

Most of "major VPS providers" I know use Linux, not BSD. (Yes, there are some
exceptions but the reliance on Linux is almost universal.)

I would love it if you were right and I am wrong, but I seriously doubt you
have _tested this_ recently. I will happily give Qemu another go if you have
tested this recently and it worked.

~~~
Sir_Cmpwn
Do your research, don't ask me to do it for you.

[https://wiki.freebsd.org/qemu](https://wiki.freebsd.org/qemu)

qemu runs on Linux, OSX, Windows, and various smaller Unicies.

~~~
_c_
So you are admitting you have not tested this and you are just going by what
you read.

When was the last time you used any "smaller Unices"?

Anyway, even if the problems with -nographic on x86 have been fixed on other
non-FreeBSD BSD's (and I have my doubts), my comment that compiling qemu has
become a substantial undertaking still stands. I suspect you've probably never
even tried compiling it yourself but that will not stop you from commenting.

I compile Bochs statically on low powered computers with no problems. Cannot
say the same for Qemu. Even you're not using x11 they expect you to have x11
libraries at compile time. As with most programs that grow so large, there are
more than a few dependencies one can do without.

------
joshmarinacci
The hobbyist OSes pop up a lot on Hackernews. Some are more full featured than
others. What would say is the minimum feature set to be called a real OS?

~~~
whorleater
At least for my operating systems class, the requirement was to be able to
boot and run a text editor, usually Vi. Didn't stop some people from building
one that could run Doom though.

~~~
joshmarinacci
Ah. I was thinking something more like process isolation and device drivers.

~~~
wichtounet
It's probably highly subjective to make a description of what needs an OS to
be an OS. For me, it would be to be able to boot on hardware, to be able to
execute applications and to give these applications an abstract layer to the
hardware.

------
mLuby
Should have called it ant-man.

------
revelation
And the latest commit message is "Prepare ICMP message type decoding"

It seems we have not learned from the mistakes of prior operating systems and
instead of a "Windows NT ping of death" we'll have a "Thor ping of death",
which is a curious image, Thor brought down by a puny ping.

~~~
wichtounet
That would be impossible, Thor cannot be brought down by any other than
Jörmungandr. More seriously, I'll try to avoid reproducing the ping of death
issue :)

------
insulanian
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?

~~~
dbcurtis
> 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).

~~~
steveklabnik
Funny you should mention the Cortex-M :) [https://github.com/helena-
project/tock/](https://github.com/helena-project/tock/) (written in Rust, just
linked to it down thread as well)

~~~
orcy
$ grep -r unsafe | wc -l

292

~~~
steveklabnik
Sure. Hardware is inherently not safe; the key is to build up safe
abstractions around it by using the type system.

------
jordigh
An OS in C++?

But Linus said...

[http://harmful.cat-v.org/software/c++/linus](http://harmful.cat-v.org/software/c++/linus)

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

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

~~~
pjmlp
BeOS, Symbian, L4, Genode, Mac OS X drivers, and big parts of Windows are all
examples of C++ use in OS development.

~~~
retro64
BeOS is the reason I learned C++. I don't recall exactly, but either I didn't
understand how or there was no other option but C++ if one wanted to hit the
BeOS API. Pity Be Inc. got shafted so bad by MS monopoly abuse.

They had zero vendors willing to put their OS on a box and resell it because
MS threatened the vendors with pulling their right to sell Windows if they
did. This wasn't particular to Be, but to any other OS.

~~~
pjmlp
Yeah, still have my Be CDs stored somewhere.

However regarding Microsoft, I actually think that vendors were as guilty as
Microsoft.

They could have chosen not to take Microsoft's discount and try to sell
alternative OSes, even if it meant having to face a few challenges.

The one that takes is as guilty as the one that gives.

~~~
retro64
I would have to really dig for the emails the company sent out (I should have
them archived someplace), but I _thought_ the issue wasn't discounts, but a
revoking of the license to sell Windows if the OEMs didn't comply.

I did a quick search and came up with Quora answer given here:
[https://www.quora.com/Why-was-the-BeOS-dropped](https://www.quora.com/Why-
was-the-BeOS-dropped)

but this doesn't jive with my memory. I will have to see if I can find an old
email or maybe dig further on the net. I certainly don’t want to be rewriting
history.

~~~
pjmlp
Even if it was revoking the license, vendors had an option, and they have
chosen the easy one out.

I remember quite a few small shops trying to put a fight selling other kinds
of computers, they might have lost in the end, but they tried to walk a
different path.

