M3 Operating System Development

A chronicle of the development of the M3 operating system

Success! I booted my C kernel!

leave a comment »

After several hours of missteps and travel down dead-end paths, I have just now managed to boot my simple C kernel using my bootloader. All it does right now is display the letter M in the top left corner of the screen, but that M represents a lot of sweat and nearly a few tears.

I ended up having to switch over my development environment to my EeePC running Linux. The development tools for OS X do not support the ELF executable format in any fashion. I could go through the process of building a cross-compiler and getting the missing tools on my Mac, but I don’t want to go through that hassle right now. I want to just work on my kernel.

The biggest problem I had was getting the kernel code built and linked properly. I knew from previous tests with my assembly kernel that the bootloader was working properly and handing over control to the code at address 0x1000. I dutifully cobbled together a linker script that I handed to ld, and it seemed to link without error. However, whenever I loaded my code into the emulator, it would just sit there. No little M in the top left corner. No clue as to why it wasn’t working. My assumption is that the linker wasn’t linking things exactly the way that I thought it was. I don’t know what code was sitting at 0x1000, but I do know that it wasn’t the right code.

After a lot of research into linker parameters and writing linker scripts, and about a zillion failed modify/build/run cycles, I saw the light. I realized that what I needed to do to get everything glued together properly was to write a tiny little assembly program that I would link to my C kernel. The assembly program does two very important things: it provides useful information to the linker, and it calls into the kernel’s main function.

So what happens now is that the boot loader does its thing and then calls the code at address 0x1000. My little glue assembly program sits at that address, and it calls into the kernel’s main function, which right now simply displays an M in the top left corner of the screen. Eureka! Voila! Joy!

In the next day or so I will write up another tutorial explaining this entire process, complete with source code. However, right now I’m thinking about doing a little happy dance. 🙂


Written by m3os

March 15, 2009 at 8:10 am

Posted in Status Update

Tagged with , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: