M3 Operating System Development

A chronicle of the development of the M3 operating system

Rough plan of action for the near future

leave a comment »

This might be completely off, and is completely subject to change by the minute, but here’s my current thinking about what to work on in the near future. I’d like to keep development rolling, while I read up and do some research into some of the major pieces of the kernel such as memory management, process management, etc.

  • Interrupts – set up an Interrupt Descriptor Table (IDT) and write some Interrupt Service Routines (ISRs) so that the kernel can be responsive to certain important interrupts, such as clock ticks, page faults, etc.
  • Write a driver that handles the keyboard.
  • Write some test routines. I’d like to build as many tests as possible along the way, so that I know that everything is working exactly how I think it is.

I think that a two-pronged approach to this project will keep the momentum going. When I feel like coding, I will. When I don’t feel up to coding, I’ll be reading and researching and planning.

Advertisements

Written by m3os

March 28, 2009 at 8:50 am

Posted in Status Update

What’s in a Name – M3

leave a comment »

I thought I’d take a bit of time to explain where the name M3 comes from, just in case anyone is curious.

I first became interested in OS design and development about twelve years ago, in 1997. Being a recent graduate of college, a newlywed, and just plain young, I got the idea that I could write my own OS. Call it youthful optimism, call it hubris, call it insanity if you want, but that was my thinking at the time.

Of course, one of the most important things that one must do when writing an OS is to come up with a good name. A good name is way more important than, say, actual code. One trend at the time was to incorporate the suffix “ix” or “ux” to the name of your OS, if it in any way resembled or derived from Unix. Another trend was to work the letters “os” into the name, such as BeOS, or FreeDOS. I wanted to cut my own path, and stay away from such trends. I was a rebel, a renegade, a trailblazer.

In 1997, the new millennium was starting to come into view. Seeing as I was setting off to build an operating system that would serve as a platform for the new millenium, nay, the platform for the new millenium, I wanted to capture that idea in the name. After kicking around names like MilleniOS and Milleniux, I settled on the simple yet solid M3.

M3 – the operating system for the third millenium.

Well, M3 didn’t really get too far down the path to development back in 1997, but when I decided to restart my efforts in 2009, I kept the name. Seeing as we’re not too far into the 3rd millennium, it’s still applicable. Besides, I can’t think of anything better.

Plus, there’s all sorts of clever things that I could do to play off the name, if I were a clever marketer. M3 could be three things that start with M, such as Modular Modern Microkernel, or Multitasking Modular Microkernel, or well, you get the idea. But before I get clever with the marketing, I’d like to have a working product. Otherwise, M3 will just be another word for vaporware.

Written by m3os

March 23, 2009 at 12:44 pm

Posted in Personal

Useful Linux Commands for Operating System Development

leave a comment »

As I was attempting to figure out what was going on with my C kernel and my “missing” strings. I happened upon some rather useful linux commands for examining and debugging object files, so I thought I would share them here.

nm – print names from object file

strings – dump ASCII strings from object file. It’s interesting to run this command on other binaries to see what they contain. This command gives you an excellent reason as to why you shouldn’t embed sensitive information in your application as plaintext. Seeing such text is a simple command away for anyone that might have malicious intent with your code.

xxd – dumps contents of a binary file – gives you a hexdump – shows you what address information can be found at within your binary.

objdump – displays information about object file.

All of these commands have many command-line options, which you can see if you click on the command names above. For me, these have already proved useful, because they allowed me to determine whether my “missing” strings were actually in my kernel binary or not. I can see them providing similar help in the future, as kernel development progresses.

Written by m3os

March 21, 2009 at 10:34 am

Posted in Random

Linker woes and missing strings

leave a comment »

Boy – getting my print function to work took some doing. I wrote the initial version of this function last night, and ran it to no avail. My clearscreen function was clearing the screen, and that’s it. My strings were not getting printed to the screen by my print function.

Poking around on OSDev.org led me to believe that there was a problem with my rodata section (for read-only data, I suppose), which is the section where string constants reside. I was declaring the following string constant in my code:

char *welcome = "Welcome to M3\nLine 2 here\n";

Which should put the string between the quotes into the rodata section (along with a terminating null char).

The first place that I checked was my linker script. I noticed that I was aligning everything to start at 0x1000. I’m not sure why I did this – probably had something to do with the fact that controlling the linker is completely new to me. My guess is that this had the effect of putting all the sections on top of each other.

I changed the linker script to put rodata right after the text section, and aligned the data section to start on the next page boundary, so it’s well out of the way. After linking the file with this modified script, I could see that things were no longer being dumped on top of each other. The -M switch to the ld command was helpful here, as was the trace switch (-t). Here’s the command I was using:

ld -T link.ld -M -t -o kernel.o start.o main.o

Executing this binary yielded something at the top of the screen – several seemingly miscellaneous characters on the first line, and couple of miscellaneous characters on the second line. This was definitely better, but not the desired goal.

Then I looked at my C code, and yeah, I’m definitely rusty. I guess it was kind of late when I wrote the first version of this code, because it was just plain wrong. I wasn’t iterating through my string properly – for some reason I was jumping two characters at a time. Bah. I’ll just chalk it up to the late hour.

After de-stupiding my C code, I rebuilt and re-ran, and voila! I saw my two-line string printed nicely at the top of my blank screen. Excellent.

Baby steps…

Written by m3os

March 21, 2009 at 10:27 am

Posted in Uncategorized

Plan for the kernel – baby steps

leave a comment »

Now that I have successfully booted into my very rudimentary C kernel, I can start working to expand that into something that is truly functional.

I’m not just going to jump right into the heavy stuff yet though. Instead, I will ease myself into the shallow waters, and once I’m comfortable I’ll wade into greater depths. It’s been many years since I wrote C code, and even back then I didn’t really get into anything too difficult. Therefore, the first order of business is to refamiliarize myself with programming in C. 

I’ve spent the last couple of days reading up, and I’m ready to start writing some code.

I’ll start exercising my C muscles by coding up some routines that will be immediately useful as I start to build out the rest of the kernel. First up is a clearscreen routine, which will clear the entire screen. Next up will be a print routine, a function that will print a null-terminated string to the screen at the current cursor position. That means it will also need to track the current cursor position. I’ll also need to add cursor handling into the clearscreen function, which will reset the screen position to line 0, position 0.

From there, I plan to write several functions that will assist in debugging, by dumping the contents of the registers to the screen, or the contents of a certain section of memory, etc. Whatever I think will be useful for debugging purposes as I start to tread into the gnarly areas of paging, memory management, etc.

Written by m3os

March 20, 2009 at 7:18 pm

Posted in Status Update

Tagged with , ,

Tutorial: Setting up an OS development environment on the EeePC (running Xandros)

leave a comment »

As I said in a previous post, I abandoned my OS X development environment for the time being, since the dev tools that come with OS X only support Mach-O binaries, and don’t have utilities such as objcopy. I know that there is a darwintools package for binutils, which I believe has a cross-compiler that will target the ELF format, but for now I decided to take the quick route and switch to developing under Linux on my EeePC. 

The EecPC runs the Xandros flavor of Linux, and by default it comes with some development tools, but not everything that we are going to need. For one thing, make is missing. Ya gotta have make – it simplifies the entire tedious compile/link/disk image creation process.

To set up the EeePC with all the dev goodies, we’ll follow this howto for installing development tools.

Before you can use apt-get, make sure that you have already added the apt-get repository that we added in our previous tutorial about getting our boot sector to run on the EeePC.

Once you’ve got that repository in your list, open a terminal window (by pressing ctrl-alt-T) and type the following commands:

sudo su
apt-get update
apt-get install build-essential

The first command, sudo su will put you into superuser mode. You may be prompted to enter the superuser password at this point. The second command, apt-get update will query the known repositories and update the known package lists. The final command, apt-get install will download and install the build-essential package, which has make and other necessary development utilities.

To test things out, type make at the command prompt. You should see an error message about no targets being specified, and no Makefile found. Congrats – if you see that error then all is good, and you are ready to go.

The last development tool that we’ll need is a very important one – subversion. Subversion is an excellent version control system. I’d advise anyone serious about software development to learn about subversion or some other version control system. Not having your code in a version control system is like walking a fraying tightrope without a net. For any new project, get your code under version control early.

Subversion is part of the same repository that we’ve been using, so we merely need to type:

 

sudo apt-get install subversion

 

and let apt-get work its magic.

My subversion repository is actually hosted by Google Code. They’ve got free project hosting, which is really swell.

Written by m3os

March 17, 2009 at 9:44 am