Page 1 of 1

OS Development In Linux (GCC And LD Problems)

Posted: Fri May 04, 2007 3:37 am
by Lprogster
...

Thanks,
Lster

Re: OS Development In Linux (GCC And LD Problems)

Posted: Fri May 04, 2007 4:16 am
by AndrewAPrice
Lprogster wrote:Hi all

As well as developing my OS in Windows, I would like to start a new OS in Linux. As when starting my first OS, I decided to start with this one at http://osdever.net/bkerndev/Docs/whatsleft.htm . (Scroll down to the bit 'Get the whole tutorial...' for the OS archive)

However I am having problems compiling it. There is a batch script with it which is used to compile it. I create my own '.sh' script with the equivalent commands and run it. I then use 'cat' to join it to my boot sector and it produces a 1MB kernel that Qemu tells me is invalid.

Here is my script; please dont run it as it may be unsafe!

Code: Select all

cd /home/lster/Desktop/bkerndev/Sources

nasm -f aout -o start.o start.asm

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o scrn.o scrn.c

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o gdt.o gdt.c

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o idt.o idt.c

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o isrs.o isrs.c

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o irq.o irq.c

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o timer.o timer.c

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o kb.o kb.c

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

cat ./bootsect.bin ./kernel.bin > ./a.img
It should be noted my boot sector has already been made (in Windows) and does work. I am using the provided link script and source code.

Any ideas? (Tell me if you need more info.)

Thanks,
Lster
That kernel is only a few kilobytes. Because you're not using grub, you'll have to change the memory address of the kernel. It sounds like your GCC hasn't been built with required the executable formats (the tutorial loads the kernel at the 1MB mark, so GCC is probably getting confused and inserting 1MB of random junk before your code).

That happened to me once.. My old GCC didn't support ELF, and when I compiled my kernel, it outputted a text file as if GCC literally 'ran' the kernel. The text file contents were like:

Code: Select all

Kernel now starting.........
Init keyboard.. DONE
Init floppy.. DONE
Enabling ints.. DONE
Login:
Of course, I was sitting there all "...........".

Posted: Fri May 04, 2007 4:24 am
by Lprogster
Thank you; it now accepts my kernel, but when I run it Qemu just hangs. Any other ideas...?

Thanks,
Lster

Posted: Fri May 04, 2007 9:52 am
by grimpy
Lprogster wrote:Thank you; it now accepts my kernel, but when I run it Qemu just hangs. Any other ideas...?
When Qemu "just hangs" it's very likely a triple fault.

Posted: Sun May 06, 2007 3:42 am
by Combuster
Try bochs, preferrably with debugging enabled ;)

Posted: Mon May 07, 2007 11:45 am
by Lprogster
Hi again all

I decided it is best to find out if there is something wrong with my kernel.

...

When Qemu runs a.img it prints '1' in the top left corner, but doesn't print the '2' next to it. Qemu doesn't hang like it did with my last kernel, though.

Any ideas? 8)

Thank you,
Lster

Posted: Mon May 07, 2007 2:33 pm
by Combuster
If you have tried bochs, it spits out warnings: partial read returns 9/512. This is due to the floppy image being not a multiple of 512 bytes in size. In contrast, Qemu does not clean up after you and just loads whatever it seems fit.

Solution: pad your second file to a 512 byte boundary
Better solution: Make sure your floppy image is always the full 1.44M in size.

Posted: Tue May 08, 2007 8:33 am
by Lprogster
Woohooooooooo! Thank you loads Combuster!

Lster