The Language:
The programming languages used to create an operating system are primarily ASM and C. ASM is used to code the bootloader as this can’t be done using C. Don’t worry though, if you don’t want anything to do with ASM you can always borrow someone else’s code (see links at bottom). The rest of the OS can be done using C. Or if you want to be particularly 1337, you can do the whole thing in ASM [insert shudder here].
The Tools:
To code an OS you will need a text editor, assembler and a C compiler. My personal favorites are notepad, NASM and DJGPP. Links for these tools and others can be found at the bottom of the page.
The Terminology:
[Bootloader] - All operating systems have to be loaded (unless they don’t work). This task is completed by a bootloader. Drives (floppy and hard) are split into lots of sections, all 512 bytes long. These are called sectors. The first sector is what the computer looks for when it boots. It is called the bootsector (I bet that surprised you). A bootloader is a small raw binary program that sits in the bootsector of a disk (floppy or hard, it’s your choice).When a computer boots, it checks for a bootloader in the bootsector of the disk. If a bootloader is present, the computer will execute it. A bootloader isn't very complicated, all it has to do is load the kernel (see next) into the RAM so the computer can run it. I won’t be explaining the code behind the bootloader in this tutorial but I probably will in part #2.
[Kernel] – This is the main executable of the operating system.
[CPU Modes] – The CPU can run in several different modes (not just on and off). These modes decide how the operating system can access memory and resources. The first of these modes is ‘Real Mode’. If the kernel is running in real mode, it has almost unlimited access to the RAM up to 1 megabyte. Woohoo... or not. When the CPU starts it does so in real mode. This is probably sufficient if all you want to make is a simple ‘hello world’ kernel, but if you do want to challenge Microsoft, you’ll have to make the CPU enter ‘Protected Mode’. When the CPU is in protected mode, access to memory is limited, so it can’t be altered by you or other programs. Running in protected mode will make the OS more stable. In protected mode, you can also access up to 4 GB of RAM (that’s another dream for you). The bootloader is the section of code that sets this mode.
[Interrupts] - There are 2 different types of interrupts.
(1) Software Interrupt: Kind of like a ''function'' that dwells in the BIOS. These are used often to complete tasks like set video modes, or requesting data from the BIOS
(2) Hardware interrupts: These are a bit different. A hardware interrupt is something that ''calls a function'' in your code when something happens (when a key is pressed, etc...).
Interrupts are a great way of communicating with the computer''s hardware, but they can only be used in real mode. If you try to call an interrupt in protected mode, you will crash your OS. There are some ways to get around this problem though, but more on them later.
The Future:
In the next article I will take an in-depth look at the source code for an example bootloader. After that I might look at the kernel and perhaps drive partitions and the like.
Oh well, till next
time…
-DeMoNiCoN-
[Master of Logical Warfare]
MSN: logical_warfare@msn.com
ICQ: 177070929
THE LINKS:
[Tools]
All the tools that you *should* need
Home of DJGPP, click on the zip picker to find your required files
NASM development page
[Tutorials/Other Help]
OS development heaven
tutorial on graphics
http://groups.google.ca/groups?q=alt.os.development
http://www.mega-tokyo.com/forum
http://www.execpc.com/~geezer
http://www.osdev.org
http://www.osfaq.com
http://www.acm.uiuc.edu/sigops/
[Existing OS’s/Others]
http://www.freedos.org
http://www.menuetos.org/
http://www.anywherebb.com/hactar.html
IRC:
#osdev on irc.openprojects.org
#asm on irc.openprojects.org
#asm on EFnet
This article was originally written by DeMoNiCoN |