M3 Operating System Development

A chronicle of the development of the M3 operating system

Booting a C kernel on OS X – a bit of a snag

leave a comment »

Things were cruising along smoothly for a little while with the boot loader, but now I’ve run into a bit of a snag. Right now, the M3 boot loader will load up my simple “kernel” stub written in assembly just fine, but the goal for the M3 kernel is to have the entire thing written in C. So the next logical step in my development process is to figure out how to get my boot loader to load and hand over control to a simple C “kernel”, which is really just a stub that will print a line of text on the screen or something equally simple.

For this purpose, I’ve borrowed a simple C “kernel” from this article about mixing C and assembly. I was able to compile the code just fine, but my problems started when it came time to link everything together. I was getting errors about invalid command line parameters and the like. Particularly, it didn’t like the -T option, which indicates to the linker where the text section of the code should be loaded in memory. On OS X, the ld command has no such option.

After digging a bit deeper, I learned that the OS X tools don’t support the same binary file types as those on Linux or Windows. Notably absent is the ELF binary type – OS X dev tools simply don’t support the creation of such files, because OS X doesn’t support that format. Instead, OS X uses what’s called the Mach-O binary format.

I found what I think to be the command line equivalent of -T for ld on OS X. The option is -segaddr. I got everything linked together, but when I tried to run my code on Q(emu) it just hung.

At this point, I have two choices. The first is that I could dig around through some OS X documentation and try to figure out how to output a flat binary file instead of Mach-O. The second is that I take out the Eee PC and move my development over to that box, since it’s Linux.

I’m not giving up on OS X just yet, so for now I’m going to do a bit of research into the OS X dev tools and try to figure out how to get the linker to do my bidding. If that proves to be a no-go, then I’ll move over to Linux. Gotta keep the momentum going.


Written by m3os

March 14, 2009 at 9:03 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: