My Own OS!

Pages: 12
HAH! I've been following tutorial after tutorial in how to get an OS up and running. Up until now either they have left information out, have been machine specific, or otherwise I was inadequate.

Late last night I started reading the Bare-Bones tutorial at OS Dev, and just a few moments ago I booted to a hello world OS both from qemu and from a real usb device!

The entire OS is about 6Kb in size at the finish. I'm like buzzing right now.

http://wiki.osdev.org/Bare_Bones

[Edit: I misquoted the size of the OS. After using grub2-mkrescue to create a bootable image, the final iso file is actually 9Mb; the built-kernel being run inside that file is 6Kb. It looks like if I were to install and use the older version of grub the final iso size might drop to as little as 1.9Mb]
Last edited on
Link your OS?(Or make a video of it working)
It wouldn't be much of a video, all it does right now is show the grub multiboot screen which only has myos as an option. Hitting enter then leads to the words "Hello World; Kernel".
That's why I called it a "Hello World OS"... maybe I should have capitalized the whole phrase.

No hardware support, no text input, just those words at the top of a VGA-text-console. But the big deal is that it is an "OS" running my kernel!

I'm now following their "Meaty Skeleton" tutorial in which they begin to implement proper file-layout, functions for text entry, and general terminal stuff. At the end of it I still won't quite have a user-space set up (where the user can execute programs), that's several tut's away.
Eventually the tutorials also cover compiling a c++ compiler on my main machine that will run on my custom OS as well. At that point it can be self-replicating which would be really cool.

I'm a regular Linux user so the tutorials might be easier to go through from there vs straight from a Windows environment.
Last edited on
If you haven't already, setup a Virtual Machine. It makes testing and crashing so much easier to do. Also a bit better than figuring out what your hardware will do when your OS does something it probably shouldn't have.
Thanks, I'm currently using qemu just because that's the VM program that the tutorial uses.

I'm learning a lot of new stuff from these tutorials, like try compiling this with g++ or clang++;
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>

/* Following code copied direct from http://wiki.osdev.org/Calling_Global_Constructors */

__attribute__ ((constructor)) void foo(void)
{
        printf("foo is running and printf is available at this point\n");
}

int main(int argc, char* argv[])
{
        printf("%s: main is running with argc=%i\n", argv[0], argc);
}


I had no idea that I could execute code before main. (Technically this is a Gnu gcc extension and is compiler-specific. The tutorial said that clang is generally compatible with g++ so I ran the above through clang++ and it also worked.)
Last edited on
Is that even correct? Is it guaranteed that you can call printf that early?

(It would be correct if you were using std::cout, because of a special guarantee, i.e.,
http://eel.is/c++draft/iostream.objects#overview-3 )

I'm missing something.
Last edited on
@Mbozzi: Apparently it is for current gcc (and clang++ and whatever the gear at the top right corner of the code runs). I would not make any claims that printf loaded so soon for anything that I haven't tested it on... It's again all compiler specific. (The overviews I've read to this point say that the standards do not indicate a specific loading order, that is left to the discretion of the compiler. GCC has laid things out so that the user can indicate what order their global constructors run in, so that objects can be built off one another safely)

So I finished the "Meaty Skeleton" tutorial, and while the file layout and some of the libc functions are now set up there is still no user-space. I'm also a little uncertain about their use of void-pointer-returning functions used in some of their code.

I have several things I want to get done in the next three weeks;
1) Tutorial on setting up a full Standard C library
2) Tutorial on porting over a compiler
3) Set up the User Space
4) Hard drive file-system/driver
5) Pass my college classes...

So maybe this project is going to go to the back-burner for a while, no matter how far down the list I put my classes they still take precedence. I'll try for 1 tutorial a week so I can get through Calculus 3. It also looks like if I want to have any real success in writing drivers for hardware like the keyboard and usb ports I'll have to find myself a good book on assembly code.

Last edited on
After "Meaty Skeleton" the tutorials are not as ready to spoon feed the reader. They're still giving good advice suggesting good resources and the like, but there is a distinct lack of instructions for what a preferred next step might be for instance and the on-site source code appears to be drying up.

http://wiki.osdev.org/C_Library
I've gone through their instruction set about installing a standard C library. I haven't implemented anything yet, but I'm currently downloading gLibC from the official git repo (https://www.gnu.org/software/libc/sources.html). I was tempted to build my own implementation of a standard C library but that's going to be way down on my todo list. It might ultimately be worth it if I decide to focus on reducing size of the final OS file.

https://github.com/dryc/libc11 <- I've also downloaded "LibC11" which is a Creative Commons 0 (public Domain) project. It's incomplete but might be far enough along to implement the cross-compiled compiler. gLibC's download size compressed was 132Mb. LibC11's compressed download size was 174Kb.


EDIT: ...And that's a no-go. http://wiki.osdev.org/Porting_GCC_to_your_OS The tutorial on actually building and porting a compiler over to the OS is both marked "Master" in difficulty and the tutorial is a work in progress. I think I'm about ready to purchase Tanenbaum's book though.
Last edited on
Now you see why so many stop after the hello world example. The complexity of writing your own OS requires a lot of dedication. I dabbled with it at one point, but when book price tags are $100+ to get the required guidance...makes it that much steeper of a learning curve.
I didn't mean to sound so down on the project, that incomplete page hit me a bit sideways since it's what I really wanted to implement.

I'm having some issues in navigating to the "expected next steps", it does look like I skipped past a dozen or so other full beginner tutorials, some that do build up toward a portable gcc. Perhaps if I follow them the instructions that do exist in the work in progress page will be enough.

EDIT: I've found this guy's collection of code samples, unfortunately all of them look to be coded in assembly (which I feel generally confident in reading but I still have no experience coding in). Anyhow, I don't want to lose this link: http://wiki.osdev.org/JohnBurger:Demo/Overview
Last edited on
@newbieg
What is your inspiration for such an unbelievably huge project? Do you want your work to be recognized by all people in the world?

Do you think your OS can beat Linux, Mac, Windows, Android, etc? If you have belief in your OS, that is.

Great, keep it up. You can become a programmer scientist and conduct your project. It is a really challenging project but the ultimate thing you will gain is not so bad. If you want to earn a recognition from all people in the world.

You can at least post your OS on this forum for at least 10 years if you are enthusiastic enough. So do your best to change the world.
Last edited on
@Mantorr22

For the people that are eventually employed to work on OS's, how do you think they learn? Maybe the OP is not out to create something better than the main stream OS's out there, but if he wants to learn something by tinkering with a basic OS - then good on him IMO.

Who knows one day he might start with a Linux distro and customise it to make his own distro - lots of people might like it and it could be very popular.
@TheIdeasMan
In fact, what I wanted to say is it is not worth the time anymore. In the past, there were many competitions about who could make a better OS. Now there exist so many beautiful-looking OS, lone people can't compete with others anymore by writing their OS because the idea is now obsolete.

About Linux distro, there also exist so many variants of Linux, so the chance of recognition is really low even if you try your best. Unless you are a programmer scientist, only these people are capable of taking on the hardest programming problems in the world, and we can trust them.

@Mantorr22

The OP probably knows all that, my guess the motivation is education.
For the people that are eventually employed to work on OS's, how do you think they learn?

As someone who was employed to work on an OS, I have to say this kind of future career choice is a very reasonable justification for hobby OS work.
No, to answer what must have been a sarcastic question, I don't think I will gain world fame. There are plenty of what are called hobby-OS's out there. TheIdeasMan has the best explanation so far, the most I'll probably benefit from it is self-education.

I do want to share resources and experience if possible.
Last edited on
Currently I'm reading through Bartlett's "Programming from the Ground Up". Google "Bartlett assembly code" and you should get several pdf links to his book.

Before I get yelled at for pirating books;
-----------------------------------------------------
Programming from the Ground Up
by Jonathan Bartlett
Edited by Dominick Bruno, Jr.
Copyright © 2003 by Jonathan Bartlett
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free
Documentation License, Version 1.1 or any later version published by the Free Software Foundation;
with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. etc etc etc.
------------------------------------------------------

I will try to keep as much of my own OS in C and C++ as I can, but it looks like assembly is at least going to be needed to make a start on device drivers. I might get away with just one or two functions with inline assembly for many of them (I might be able to abstract them out for similar devices). I'll post my code on github as soon as I get a keyboard driver, at this time my code strictly follows the "Meaty Skeleton" tutorial from the original website above.
Last edited on
Cubbi, I'm curious how you got your start in OS development?

Did you go through a college course, get on the job training, or did you learn on your own? (Or is there a fourth option that I'm not considering?)


Next resource: Nick Blundell's "Writing a Simple Operating System From Scratch". By page 20 I have gotten clearer information about assembly than I got out of the first 80 pages of Bartlett's book. Also it has no focus as far as the parent OS, it uses the NASM assembler which should be available on all mainstream OS's (Actually so should Gnu-as http://stackoverflow.com/questions/13793609/nasm-vs-gas-practical-differences ). He gives a neat trick in using a teletype interface that the BIOS set up for us, and he starts expecting you to write working external functions by page 22 which is doable off of his instructions though a nice challenge for a first-timer in assembly.

I'm hoping the book will get into actually booting the program from a usb stick or HD. Right now the code I'm building only runs in qemu.

Edit: Surprise! Going into 32bit protected mode (general 32bit computing) means we no longer have access to BIOS provided interfaces. Bye bye predefined teletype.
Last edited on
Cubbi, I'm curious how you got your start in OS development?

got hired into a team that handled bug reports and released patches for LynxOS (http://lynx.com )
Did you go through a college course, get on the job training, or did you learn on your own? (Or is there a fourth option that I'm not considering?)

nothing specific for the job, they just needed understanding of everything low-level, and C programming, I don't remember how their recruiter found me, that was 17 years ago.
Last edited on
Wow, they do a good job of advertising on that web-page. Reading through the specs I had a little voice in the back of my head saying "It powers Airplanes!"

Very cool, thanks.
Pages: 12