You create your little bootloader, set up the file system, enter pmode and load a small kernel that displays a simple message on the screen. Now what? How many ways do I have to do all these things? How many file system types? How many ways of activating A-20? How much freedom to create my own original O.S. do I have at the beginning, or when I already have started creating drivers?
I am not an expert assembly/C/OS development programmer, but I dare to create a simple plan that may help beginners stay on the right path and always have the feeling that everything is well organized and if you feel lost, just have a look over the basic guide, to see where you are. It is not a recipe or something that you just follow and "Tada! There's an operating system". I personally am stuck at a very basic level and I believe the reason of it is not having a main basic plan to review from time to time and see where am I at that moment.
Now, this is not an article but a request for help in what I want to do. I will just plant a small young tree here, hoping that more experienced developers might water it, and at the end, if we achieve a good, well-explained, well-organized outline for the "ordinary OS developer" I will convert it to PDF so everyone can make use of it.
So, from what I know to the moment, when starting to create your experimental OS (from scratch), I should pass through all this:
- What kind of O.S. and how complex will it be
You can create a simple O.S. with a basic interface and allowing a small set of operations, or a more advanced one, like most of us dream to develop (GUI, compiler, etc.). That's because you might not need to read all these lines.
A list of different kind of known operating systems will be useful here. - The processor
Will it be a 16-bit or 32-bit? Also, each processor type has its own set of extra features, that can be exploited. - The memory (RAM)
How much memory (approximately) will we need? It also depends on the processor mode, right? - The storage device
This is important, too. Will it be a floppy, a hard disk, an optical disk or some USB stick? The bootloader depends on it, as I have understood. - Input/Output
Will the interface offer mouse/keyboard support? The display can show text only or a cool graphical user interface, with images, videos and sound. - Other peripherals and devices
A printer, a modem, etc. We must know how far we want to go, and of course, leave open the possiblity to support more devices. - The bootloader
At this level there are many standards so you don't have many options to do something. I don't know how different are all the existing bootloaders but I guess not too much. How much and how well can you put something in a 512 bytes space?- Depending on the storage device, your bootloader is different
Most of the bootloader tutorials are for floppy disk, where you have 510 bytes to do whatever you want. You can set up a file system, enter pmode and activate A-20 inside all this space, then load the kernel, or you can do some of this and load a second bunch of code for the rest. Or you can just load the second bootloader.
On a hard disk, as I know, you also need a partition table and you only have like 446 bytes only for your instructions.
Now, as I have read before, there's a traditional partition table you can create, allowing a maximum of 4 partitions. There's also a way to create more than 4 partitions, is that right? Is the partition table structure a standardized one? How much freedom do we have here? - Different ways of loading your O.S.
Like I said, even if we are in 16-bits real mode and we have all the power, the bootloader, as I see and think, must follow many rules that won't give us any freedom to make some never-before-seen piece of code. In first place, you only have 510 or 446 bytes, secondly you must use some of this space to read the second sector of the disk and load some other code. Now, you can also create a file system or even go pmode already. I don't know if we can do more than this at this stage. - A second bootloader
It's almost a rule, if you want to create a more advanced operating system. This one can have much more space (if we are still in real mode, not so much), enough to:- Specify a file system
I must admit I have not understood the file system completely. There are many file systems and you can even create your own. I know that on a storage device you have stored all the code and data, from the bootloader to the last resource file (like an icon file). They are referenced by their names and extensions and they have more properties and limitations, based on the file system type (like creation data, size, maximum name length). From this, I understand that the filesystem is a special space where all the files are listed, with all these properties and their place on the disk, but the file system also looks like a pattern to be used in order to find a file on the disk. I need some explanations here (I swear I read all the info on the Internet). - Checking
I saw that people use to make some checking before enabling protected mode, like checking the processor type.
Are there any other verifications we could make at this stage?
- Specify a file system
- Entering protected mode
If you want just a simple 16-bit system that doesn't need more than 1 Mb of memory, you can stop here. Make use of all the interrupts and have fun! Those who want more need to continue.- Load the Global Descriptor Table
This is an important step, that's all I know about the GDT. There's a special register where you must load a structure of bytes. Now, how does the processor use them, I don't know. The only thing I understand is that it "maps" the entire memory we have, so the processor know which is data, which is code, where is everything, in order to protect memory from overwriting or forbidden access. Also, I see you don't have many options to "customize" it. The definition from the wiki is funny. "It contains entries telling the CPU about memory segments". Like "Hi CPU! I am GDT! Did I tell you about memory segments?" - Local Descriptor Table
Not obligatory and similar to the GDT. I have no clue what is it useful for - Interrupt descriptor table
Someone with more knowledge than me could explain this, too - Enable private mode
By changing the bit 0 of the control register CR0 to 1 you change the entire behavior of the processor, in this case you enable the protected mode. - Open gate A20
In order to gain access to all 32 address bus lines we enable electronic gate A20.
[/color]There are many ways to do this. Somebody with knowledge about them could explain each one
- Load the Global Descriptor Table
- Load kernel
Now we have load the kernel into memory. Of course, the kernel is not just a simple file, but it has an entry point. Now, it depends on the file system how we load that file (if we have a file system specified.
- Depending on the storage device, your bootloader is different
- The OS Kernel
This one would contain a lot of subsections. As I understand it, the kernel is a very big loop that will end when the user wants to shoot down the system. Inside this loop we have drivers, files operations, software support, libraries, interface, etc.
Let us see who dares to organize a little bit all the layers, based on their ring level and importance.
Well, this is how it looks initially but there's a lot of information to add, and that's why this is not an article but a request for help. I might be wrong in a lot of things, there are many missing points to describe and I appreciate so much your contribution. Text in red is for missing information or things that I don't understand.
If you want to correct me on something, just specify the number of the section and what is right. Like
7.3
This is wrong. The right definition is ...
The same you can do in order to add a new section or remove an existing one. I will often review the replies and modify the list. Also, as I am not a native English speaker, this might contain some grammatical/lexical errors. I will gladly receive any spank.
Thanks for your help in advance and have a nice journey as an OS developer!
A smiley from me