#[1]Tobe Osakwe
[2]Tobe Osakwe
* [3]Home
* [4]About
* [5]Dart
* [6]Github
* [7]Resume
* [8]Contact
[9]Subscribe
16 February 2020 / [10]Programming
Writing Your Second Operating System
With any skill for which there exist Internet tutorials, there are
bound to be hundreds of tutorials covering the very basics. This is
especially true for computer programming. The problem, though, is that
once you get past the basics, the amount of resources available tends
to thin out dramatically. The world is full of "your first OS kernel"
articles, but what happens when you decide your first design was
novice-made garbage, and want to create a better system from the ground
up?
stallion-prototype-1 ([11]GitHub) is/was my second attempt (not
counting myriad mini-attempts along the way) at creating an operating
system kernel. Clearly, I didn't create the next Linux, and there are
no user space programs, but I still consider it a success in terms of
material learned. I don't intend to start an OS project for some time,
as I'm [12]working on other things right now, but these are the things
I'll be focusing on:
What Is My Plan, And What Order Will I Do Things In?
At least, in my (albeit limited) experience, it's pretty difficult to
decide on the order you'll add things to your system, because not only
are there several components required before you can add any meaningful
functionality to your kernel, but it's also very difficult for novices
to foresee what they'll need to add when they are probably unaware of
the existence of most of what they'll soon be interacting with. For
example, how would you know when to add ACPI code before you even know
what ACPI is?
For the next version of Stallion, though, I've identified basic groups
of functionality that should be accomplished at roughly at the same
time:
* Bootloader, higher-half kernel setup, GDT, IDT, mapping the kernel
into pages
* Setting up memory management - a kmalloc ported from liballoc
([13]
https://github.com/blanham/liballoc) will do fine
How Will I Boot My System?
OSDev intermediates have probably used GRUB before. However, I'm not
talking about the bootloader here (I'm using GRUB2). Above, I mentioned
that I'll be building a [14]higher-half kernel. This involves loading
the kernel into memory at offset 0xC1000000 (or higher). The most
common way to do this is load some "early" code that maps the kernel
into the necessary memory.
My approach will be to have GRUB boot this early code, providing the
kernel itself as an ELF module.
How Will I Test My System?
Unit testing is crucial for things that cannot (easily) be formally
verified. The more exhaustive, the better, for something like this.
Testing an operating system in an emulator is probably not the easiest
thing to do. But also, it's important to note that not every component
of the kernel directly needs to be run in an emulator. If you can
abstract away the underlying system, then you can possibly create a
simple test driver, and test the logical components using GoogleTest,
or another unit testing library.
How Will I Make My System Secure?
To be honest, I don't know. But some terms you want to familiarize
yourself with are capabilities and ASLR. My system will be
microkernel-based, so as long as I know what I'm doing, and at least
prevent Heartbleed/Spectre, hopefully things will be alright. My OS
will somewhat be like the "iOS of desktop," so programs will have
limited privileges to begin with.
How Will I Organize My Code?
Ultimately, I'll probably split up the higher-half loader and kernel,
and then split up the source code and actual user space items. More
important than just organizing the code is also writing
English-language documentation about each folder, including which
functionality the files in that directory provides.
How Can I Isolate Platform-Specific Code?
Conversely to how you might test the system by abstracting away the
underlying system, you can place all the platform-specific code into
the individual implementations of the interface. For example, if you
have a base InterruptHandler class, you can have an X86InterruptHandler
and ArmInterruptHandler.
How Can I Take Advantage Of An IDE?
Setting up a build system via CMake alone is painful, and a bad idea
because of all the shell stuff you have to do. Maybe I'll have a make
target that calls CMake? This way, I can use CLion to develop the
kernel. I've tried bear and ran into issues generating a
compile_commands.json, but since CMake can generate them, I can even
edit with language server support in Vim.
How Can I Make Sure My Code Is Readable And Maintainable?
Not only by using clang format, and a style guide, but also documenting
the organization of the project in English. If I don't take care to
follow good practices early, then the project will quickly become a
chore to work on.
How Can I Get To User-Space ASAP?
All the cool stuff exists in user space. The goals of my theoretical
operating system involve mostly having a slick UI, so I'd love to hack
on that ASAP.
However, having a user interface requires not only drivers, but also
all of the underlying infrastructure necessary to implement them. Maybe
I can possibly load test programs without existing drivers by providing
in-memory mock implementations?
How Can Other People Build My System?
Getting the toolchains necessary to build operating systems is a
project in itself. For example, it's very difficult, if not impossible,
to build Linux on Mac, let alone Windows.
CMake itself is cross-platform, but make isn't. Plus, the tools to
build ISO's, like GRUB, need to be built locally.
If other people can't feasibly build your system, it'll be impossible
for them to contribute, which means your project will likely never
reach the critical mass of users necessary to be important in any way.
When, And How, Am I Going To Build A GUI?
A GUI is my eventual goal. There's no shame in wanting to have windows
and nice things. After I have user-space (see above), I can start on
that. My first idea for a nice UI is to build the system UI using
embedded Chromium; this way, I could build applications using, maybe,
React.
An alternative is to embed something Flutter, or yet, write the system
UI manually in C/C++ (I would like to avoid this).
Why Would Someone Want To Use My System?
What unique does my system bring to the table? Do I execute on those
goals well? How am I marketing the project? Do I even expect it to be a
long term success? Am I treating the system as a project, or product?
Is it user-friendly? Or is it just a side project? Why would someone
bother using it?
Most Importantly - How Can I Measure Progress?
GitHub issues are a great idea. Combined with their "Projects" triage
feature, it's very possible to keep track of goals and milestones. The
triage boards, when made public, also effectively serve as a project
roadmap.
__________________________________________________________________
If we're being honest here, I'm probably never going to actually start
the project, let alone complete it. But maybe the reader will. Take the
experience you used from failing your first project, and take it to
finish your second.
Subscribe to Tobe Osakwe
Get the latest posts delivered right to your inbox
____________________
(BUTTON) Subscribe
Tobe Osakwe
[15]Tobe Osakwe
Hello, world! My name is Tobe, and I'm a third-year Comp. Sci. student
at Florida State University. My hobbies include programming, writing,
and music-making. Hiring? Check out my resume!
[16]Read More
[INS: :INS]
Please enable JavaScript to view the [17]comments powered by Disqus.
— Tobe Osakwe —
[18]Programming
* [19]What's New - January 27th, 2020
* [20]Things I Hate About Python
* [21]Contribute, Or Die: An Open Source Mantra
[22]See all 16 posts →
[23]What's New - January 27th, 2020
What's New
What's New - January 27th, 2020
As January winds down, I figured it would be a good time to continue my
"What's New" series. (I've actually posted one this month already, so
this will also cover early February.)What's
* Tobe Osakwe
[24]Tobe Osakwe
3 min read
[25]Tobe Osakwe icon Tobe Osakwe
—
Writing Your Second Operating System
Share this
[26]Tobe Osakwe © 2020
[27]Latest Posts [28]Twitter [29]Ghost
Tobe Osakwe
Subscribe to Tobe Osakwe
Stay up to date! Get all the latest & greatest posts delivered straight
to your inbox
____________________
(BUTTON) Subscribe
References
Visible links
1.
https://thosakwe.com/rss/
2.
https://thosakwe.com/
3.
https://thosakwe.com/blog/
4.
https://thosakwe.com/blog/about-me/
5.
https://thosakwe.com/blog/tag/dart/
6.
http://github.com/thosakwe
7.
https://docs.google.com/document/d/1owpoweSYiHpTybC6yNcO5MIbV6WcB4eD_ge7z_KBLCg/edit?usp=sharing
8.
https://thosakwe.com/blog/contact/
9.
https://thosakwe.com/writing-your-second-operating-system-kernel/#subscribe
10.
https://thosakwe.com/tag/programming/
11.
https://github.com/thosakwe/stallion-prototype-1
12.
https://thosakwe.com/reading-list-january-2020/
13.
https://github.com/blanham/liballoc
14.
https://wiki.osdev.org/Higher_Half_Kernel
15.
https://thosakwe.com/author/tobe/
16.
https://thosakwe.com/author/tobe/
17.
https://disqus.com/?ref_noscript
18.
https://thosakwe.com/tag/programming/
19.
https://thosakwe.com/reading-list-january-2020/
20.
https://thosakwe.com/things-i-hate-about-python/
21.
https://thosakwe.com/contribute-or-die/
22.
https://thosakwe.com/tag/programming/
23.
https://thosakwe.com/reading-list-january-2020/
24.
https://thosakwe.com/author/tobe/
25.
https://thosakwe.com/
26.
https://thosakwe.com/
27.
https://thosakwe.com/
28.
https://twitter.com/thosakwe
29.
https://ghost.org/
Hidden links:
31.
https://twitter.com/thosakwe
32.
https://thosakwe.com/reading-list-january-2020/
33.
https://twitter.com/share?text=Writing%20Your%20Second%20Operating%20System&url=
https://thosakwe.com/writing-your-second-operating-system-kernel/
34.
https://www.facebook.com/sharer/sharer.php?u=
https://thosakwe.com/writing-your-second-operating-system-kernel/
35.
https://thosakwe.com/writing-your-second-operating-system-kernel/