views:

231

answers:

2

This is a hard question to ask because I'm positive I'm about to be bombarded with haters commenting on "if I can't write an operating system already, I won't ever to be able to write an operating system". Well I've read Modern OS by Tanembaum, Linux Kernel Development, Understanding the Linux kernel and others I still don't know if or not I can write an operating system and only by pushing forward to write one will I realise what I don't know. On top of that none of the books I read even bother to describe the boot sequence / compilation sequence.

Anyway I hate to be negative but I would just like to build the example code from the bkerndev tutorial below and have an absolutely minimum operating system:

http://www.osdever.net/bkerndev/index.php?the%5Fid=90

You can download the associated source code in a zip format from here:

http://www.osdever.net/bkerndev/bkerndev.zip

When you try and compile this kernel you run into all sorts of errors caused by the fact that some of the code is broken. Another user was seeking help for this here on stack overflow here:

http://stackoverflow.com/questions/1688844/compiling-my-own-kernel-not-from-linux-kernel-source

Although didn't get much help. I have addressed those errors by adding the gcc flag fleading-underscores and by changing some of the data types. You can see my code here:

http://github.com/PhillipTaylor/farmix

The code will compile sucessfully and leave me with a kernel.bin executable but when I boot into it from grub I get:

Error 13: Unrecognised or unsupported format (or something to that nature)

When I take the kernel.bin directly from the authors zip file and run it on my eeepc it boots absolutely fine so I think I have a problem with compiling the code correctly. The author is building it from a Windows machine, I believe, but I am trying to compile it using Fedora 10 i386 with GNU GCC 4.3 and I think this is what is causing the issue so I ask you, how do I build a valid executable kernel? Am I missing the correct target or the wrong binary format?

I would really appreciate someone helping me over this embarrassing "first step"

+2  A: 

My comment above wasn't very clear. What I meant is "What does the 'file' command report on your kernel.bin vs. theirs?". The output of the linker is a raw binary file. It should start with a few magic words that grub recognizes. They are defined in start.asm near "mboot". I suspect yours is different than theirs.

I don't have nasm handy so I can't build, but you might want to start by comparing the first few words of the .bin file.

Richard Pennington
when I run the file command against the authors (working) kernel and my kernel I get "data" for both of them so it isn't point to any issue but looking at the binary files in vim I can see mine starts with the word "Hello World" and the authors doesn't. The start.asm file provided does tell us that the file does need a certain byte pattern to be recognised by grub correctly so it looks like this is the issue. I'm not sure what I need to do to fix this issue however :-s
Philluminati
+1  A: 

It turns out that the line used to compile the app was explicitly set to compile to "aout" format which was what the guide said and what I assumed to be true. Only reading stuff in the "barebones" guide convinced me that I may have been confused. As soon as I changed that one line to "nasm -f elf" it all worked.

This is a tag in my repository that points to a basic WORKING version of bkerndev tutorial code (How to write your own Operating system) for future reference and people who were in my position..

It comes with a makefile for building it from a 32 bit Linux system.

http://github.com/PhillipTaylor/farmix/tree/bkerndev%5Ftutorial%5Fworking

Philluminati