OS Development In Linux (GCC And LD Problems)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

OS Development In Linux (GCC And LD Problems)

Post by Lprogster »

...

Thanks,
Lster
Last edited by Lprogster on Tue Oct 23, 2007 11:23 am, edited 2 times in total.
User avatar
AndrewAPrice
Member
Member
Posts: 2309
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

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

Post 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 "...........".
My OS is Perception.
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Post by Lprogster »

Thank you; it now accepts my kernel, but when I run it Qemu just hangs. Any other ideas...?

Thanks,
Lster
grimpy
Posts: 11
Joined: Thu May 03, 2007 11:27 am

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Try bochs, preferrably with debugging enabled ;)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Post 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
Last edited by Lprogster on Tue May 08, 2007 8:34 am, edited 1 time in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Post by Lprogster »

Woohooooooooo! Thank you loads Combuster!

Lster
Post Reply