Writing Small OS

Mar 17, 2010 at 3:32pm
Before anything, I'd like to throw a couple things out there. Firstly, by OS, I'm not talking a Windows/Linux/Mac sized OS. I'm talking about writing a boot loader and small OS that I can run C++ applications outside of a full sized OS on. For right not, I'm just looking to develop a small, portable OS that I can layer my C++ programs over top of.

As redundant as it seems, there's a reason why I'm taking this route rather than using an existing portable OS; experience. So, this project is to A) create a portable OS that I can layer C++ applications on, so they may be used outside of a full OS, and B) Give me experience in writing portable OSes for computing devices.

All that being said, here's what I know:

I need to create two general things: a boot loader, which will be out of assembler and C++ (I think, given that's possible), and a kernal of sorts, which will contain C++ and possibly assembler if needed.

Here's where I'm stuck:

Assembler is apparently just a generalized name for about 40 billion types of itself. They all look primarily the same, but they take different Assemblers and work for different processors and such.

Here's what I need:

Most of the people who will be testing my software and myself use Intel processors, and from what I've seen, all 32 bit. I can't imagine any of them asking for 64 bit technology (they aren't huge tech buffs) and usually stores sell you 32 bit unless you ask for 64. Anyway, there are a couple of people who want to test that have AMD processors. Once again, I believe they are 32 bit, for the same reason.

I doubt just one assembler would cover both cases (but it would be amazing if one did_, so I need some options. I prefer using IDE software over command line, but I can stand to learn something command line.

I realize that this is a C++ forum, but as soon as the assembler part is figured out, I an move my assembler questions to a forum devoted to whatever type I end up using. The problem is I don't know where else to ask this type of question, and I already saw a few people who might be able to help here, so I hope this doesn't violate any rules.

The project will include C++ and I'll be asking C++ questions here as well.

Anyway, any answers/help/tips/etc. would be much, much appreciated.
Mar 17, 2010 at 4:18pm
Just wanted to commend you on a well-worded post :). I'm not experienced enough to help you, unfortunately, but I too am curious about this area. I'll be checking back here to see how this thread progresses...

Nice to see someone driven by the desire for experience, rather than by the desire to milk answers for homework...

Good luck :)
Mar 17, 2010 at 4:31pm
So what's your question? xD I'd be more then obliged to help, I did the exact same thing a while back.
Mar 17, 2010 at 4:34pm
shadowayex wrote:
a boot loader, which will be out of assembler and C++


I've noticed too many people referring to Assembly as assembler... that's like saying I'm going to use the Visual C++ programming language.
Mar 17, 2010 at 4:42pm
assembler was machine code originally. It was input using analog punch out cards fed to a machine by hand. The name "assembler" for a particular piece of software used to compile assembly language code came later. Or so says my dad...a computer science major from the early 80s
Mar 17, 2010 at 4:56pm
closed account (z05DSL3A)
Buy Operating System Concepts by Abraham Silberschatz and start reading.
Mar 17, 2010 at 5:03pm
Return 0 Oh, sorry about the confusion of names.

So I want to use assembly language, not assembler. Assembler is the program that compiles assembly code. Correct me if I'm wrong.

Seraphimsan I've read on articles that there are different kinds of assembly like Z80 Assembly, x86 Assembly, 8086 Assembly, etc. I'm not sure what variant I need. I looked at a few different variants and they all look primarily the same, so I don't know if there is any difference between them, nor do I know what assembler program I should use for the assembly language I use.

The questions I have are, based on the information given above, what variants (as I'm sure there's not one that covers all my testers) should I look at, and what assembler I should use for it.

As I said, I prefer to use IDEs connected to compilers, as it makes product a little faster, but if I have to use command line, given there's a good reference/tutorial to help, I can stand to learn to use a command line assembler.
Mar 17, 2010 at 5:16pm
I bought Operating Systems: Design and Implementation by Tanenbaum and Woodhull recently. It focuses on MINIX 3 way too much but it is otherwise a very good book. You might consider buying it (it's a little expensive, though).

To be honest, I would say there wasn't much point writing a bootloader. Unless your kernel needs some specific setup, you may as well just use GRUB. GRUB is like a miniature OS in itself. If you write a multiboot compliant kernel then it will boot your kernel exactly how you tell it.

If you need help with something specific, this is a great resource: http://wiki.osdev.org/Expanded_Main_Page
Read this first: http://wiki.osdev.org/Beginner_Mistakes to make sure you know what you're getting in to. Personally, I'm not going to attempt it for at least another year. But you can still play around making very basic monotasking kernels I guess...

As for assemblers, I would recommend you to try nasm. nasm is an execllent assembler (that is, a program which assembles assembly code); it is fast and small and can create 16, 32 or 64 bit code. I would learn x86 assembly (Intel syntax, although if you get time, learning gas syntax will be useful too because you often find both on the Internet).
Last edited on Mar 17, 2010 at 5:18pm
Mar 17, 2010 at 5:23pm
chrisname Thank you for your input. I'll look in to both NASM and x86 Assembly. Also, I'll see if I can locate a copy of the book you suggested (and Grey Wolf's also) that I can look at before I go ahead and buy it. Your links are also helpful.

If anyone else has any other suggestions, please don't hesitate. Any and all information will help, even if I don't end up using it right away.
Mar 17, 2010 at 5:58pm
if you've never developed a kernel before and need something free to get you started

http://www.osdever.net/bkerndev/Docs/intro.htm

will help you. It's how I got started in Kernel Dev. Just bare in mind some of his work doesnt quite link right depending on what compiler kit you use
Mar 17, 2010 at 6:01pm
closed account (1yR4jE8b)
You could also look at the code for Berklee's small operating system name nachOS which they use to teach there course in Operating Systems. There are Java and C++ implementations and covers basically everything you need to know about a traditional operating system (Concurrency, System Calls, File System, Network, Multiprogramming, Memory Protection etc...). Even though I

There's a google code page for nachOS here, but it's for the Java implementation:
http://code.google.com/p/nets3604-fu/source/browse/trunk/src/nachos/?r=79#nachos/proj3

Personally, even though I much prefer C++ and this is a C++ forum afterall, I would still recommend reading the source in Java as it is much easier to understand because there is less C++ centric quirks involved, at least until you understand the concepts. THEN work on implementing them in C++.

Messing around with that source and the book that Grey Wolf mentionned is how I got my start in OS programming. I'm going to warn you though, that writing an operating system is the single most difficult thing in computer programming. The trick is to take your time, work on small, isolated parts at a time and try to just have fun with it. :D
Mar 17, 2010 at 6:05pm
Your OS will need to initialize the machine to the correct state. 80x86 systems start up in a very old, DOS-days mode. You'll need to have the code to activate the "protected mode", which is what Windows and other modern, x86 systems do.

Next, you will need to have an executable file format, an assembler (and maybe C/C++ compiler), and a linker. If you like you can borrow from the existing PE32 or ELF formats, which would make your life much easier.

Finally, your kernel will need to provide basic functions to load and run processes and provide I/O accesses to your programs (keyboard, tty and pixel display output, port accesses [printer, internet, etc], and disk I/O.

How advanced your OS gets from there is up to you. Basic concepts include privilege levels (to prevent user programs from having full access to the machine), preemptive multitasking (running more than one program at a time), etc.

Frankly, before you even get to the 'advanced' step you already have your hands full. Disk I/O, for example, is a very involved subject. You will have to choose which filesystem(s) your OS will recognise. Recommended ones are FAT32, NTFS, EXT2+, and ISO CD/DVD formats.

A good start would be to play around with one of the small linux distros I recommended to you here ( http://www.cplusplus.com/forum/general/20909/ ).

Another would be to wander around OSDev.org
http://wiki.osdev.org/

This is a huge undertaking! JSYK.

Good luck!
Mar 18, 2010 at 2:40pm
Thank all of you for all the information.

I'm starting with looking at the sources of those linux distros mentioned. I realized this was going to be huge but holy crap xD

I'm not going to give up though. Thanks again for the information and I'll surely be back for more =D
Topic archived. No new replies allowed.