Page 1 of 1

Bran's Kernel - Compiles but doesn't work

Posted: Tue Mar 04, 2008 1:58 pm
by Mark Vickers
Hello,

I'm just starting to look at OS development and came across the Bran tutorial and found I understood most of it. So I thought I'd set it up on my Slackware linux box and compile it so I could tinker.
I had a few problems with leading underscores and compiler warnings but these are now all fixed and the kernel compiles and links without any warning or errors. I am suspicious though as my version is 23k whereas Bran's original is 12K.

To test the kernel I found info on using GRUBs stage2_eltorito code to make a bootable CD. I put both my version of the kernel and Bran's original onto a CD image and booted it on Bochs. Bran's works as advertised but in Bochs all I get is a blank screen. So I burned the iso image onto a CDRW and booted it on a real system. Again Bran's worked as advertised but my version prints garbage on the screen.

Can anyone give me any clues as how to proceed?

I am using Slackware 11. GCC 3.4.6. NASM 0.98.39 and LD 2.15.92.0.2. My build script is included below..
#!/bin/bash
echo "cleaning old files..."
rm *.o
rm kernel.bin
echo "assembling start..."
nasm -f aout -o start.o start.asm
echo "compiling c files..."
COMPILE_FLAGS="-Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin"
COMPILE_FLAGS2="-fleading-underscore"
gcc $COMPILE_FLAGS $COMPILE_FLAGS2 -I./include -c -o main.o main.c
gcc $COMPILE_FLAGS $COMPILE_FLAGS2 -I./include -c -o scrn.o scrn.c
gcc $COMPILE_FLAGS $COMPILE_FLAGS2 -I./include -c -o gdt.o gdt.c
gcc $COMPILE_FLAGS $COMPILE_FLAGS2 -I./include -c -o idt.o idt.c
gcc $COMPILE_FLAGS $COMPILE_FLAGS2 -I./include -c -o isrs.o isrs.c
gcc $COMPILE_FLAGS $COMPILE_FLAGS2 -I./include -c -o irq.o irq.c
gcc $COMPILE_FLAGS $COMPILE_FLAGS2 -I./include -c -o timer.o timer.c
gcc $COMPILE_FLAGS $COMPILE_FLAGS2 -I./include -c -o kb.o kb.c
echo "linking..."
ld -T link.ld -o kernel.bin start.o main.o scrn.o gdt.o idt.o isrs.o irq.o timer.o kb.o
echo "copying to iso structure..."
cp kernel.bin grubiso/iso/boot/
echo "done"

I've made minor changes to the original C files to get rid of compiler warnings. This just involved making main into an int and casting some assigns. Otherwise its as downloaded.

Thanks
Mark

Progress of sorts

Posted: Wed Mar 05, 2008 3:28 am
by Mark Vickers
OK. I've got a little further. I've proved that the majority of the code is working (at least the video stuff). I can change the cls routine to fill the screen with any character. Also I have proved that moving the cursor and the putch routine work as I can make things appear on screen. It looks as if the puts routine is not working.

"Aha!" I thought. "This is a problem with strings!" and I remember reading about that on the Wiki. However when I check my link.ld it does indeed have the *(.rodata) in the text section.

So I'm guessing my gcc is putting the strings somewhere else. Any ideas anyone?

Thanks
Mark

Posted: Wed Mar 05, 2008 8:38 am
by JamesM
Have you tried hexdumping the resulting binary and checking if the strings are present?

Posted: Wed Mar 05, 2008 9:18 am
by zaleschiemilgabriel
That's what you get for copying someone else's work. :roll:
I don't think James was expecting all these compiler-related questions when he posted those tutorials and I would be really ashamed to ask for this kind of help knowing how much he already did... but that's just me.
I've been using James' tutorials for a while now, and I found nothing wrong or at least nothing that I couldn't get to compile by myself... :D

I never had to say this, so I'll say it here: thanks for the tutorials, James.

Cheers!

Posted: Wed Mar 05, 2008 9:22 am
by JamesM
He's using Bran's, not mine. Although mine are based off Bran's.

EDIT: Thank you! :oops: :oops: *blushes*

Posted: Wed Mar 05, 2008 9:24 am
by zaleschiemilgabriel
I mostly use yours, so thanks... :P

Posted: Wed Mar 05, 2008 10:26 am
by Mark Vickers
Hello JamesM,

I'm at work at the moment but logged into my home PC and did a hexdump. The strings are there all lumped together at the end of the kernel. I notice that in Bran's kernel they seem to be embedded throughout the kernel image.
I'm thinking that I might dump out the address of one of the strings and then dump out what's there to see if that gives me any clues as to what is happening. Will try that tonight.

By the way I've just scanned through your tutorial and it looks like a better place for me to start than Bran's. Will probably work through yours soon and see if I have better luck.

Thanks
Mark

Solved

Posted: Wed Mar 05, 2008 4:33 pm
by Mark Vickers
Well I've found out what the problem is!

After much expermentation I removed the line...
OUTPUT_FORMAT("binary")
from the link.ld script. Immediately the size of the kernel dropped by 4K and when I try it for real in a bootable CD image it works! :D

So now I'll be tinkering and learning from this kernel but I'll also be looking at your tutorial JamesM as it looks to go much further than Bran's.

Thanks go to JamesM and Bran for these nuggets, I've started on the long road to my own hobby kernel.

Thanks
Mark