Bare Bones Compilation

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
turb1d
Posts: 2
Joined: Fri Oct 05, 2012 11:51 pm

Bare Bones Compilation

Post by turb1d »

Hello,

I'm following the http://wiki.osdev.org/Bare_bones tutorial, but I'm having some issues getting it to run in Virtualbox. Initially, my makefile was:

Code: Select all

make : compile
    dd if=/dev/zero of=pad bs=1 count=750
    cat boot/stage1 boot/stage2 pad kernel.bin > floppy.img

compile :
    nasm -f elf -o loader.o loader.s
    gcc -o kernel.o -c kernel.c -Wall -Wextra -Werror -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
    ld -T linker.ld -o kernel.bin loader.o kernel.o
"make" yielded:

Code: Select all

nasm -f elf -o loader.o loader.s
gcc -o kernel.o -c kernel.c -Wall -Wextra -Werror -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
ld -T linker.ld -o kernel.bin loader.o kernel.o
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
make: *** [compile] Error 1
I therefore changed the "compile" target to:

Code: Select all

compile :
    nasm -f elf64 -o loader.o loader.s
    gcc -m64 -o kernel.o -c kernel.c -Wall -Wextra -Werror -nostdlib -fno-builtin -nostartfiles -nodefaultlibs
    ld -m elf_x86_64 -T linker.ld -o kernel.bin loader.o kernel.o
This compiles fine, but trying to load "floppy.img" in Virtualbox gives a VERR_VD_RAW_INVALID_HEADER error. Any help getting this to load properly? For reference, "uname -a" gives "Linux XXXX 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:09:38 UTC 2010 x86_64 GNU/Linux"
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Bare Bones Compilation

Post by bluemoon »

The barebones are 32-bit examples, have you ever read the source code?

If your hosted toolchain complains, check the parameters or use a cross compiler. You can't simply ask it to emit 64-bit objects as the source is not intended for 64-bit without modifications.
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:

Re: Bare Bones Compilation

Post by Combuster »

And more obviously, you are not using the commands from the tutorial.
"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 ]
turb1d
Posts: 2
Joined: Fri Oct 05, 2012 11:51 pm

Re: Bare Bones Compilation

Post by turb1d »

bluemoon wrote:The barebones are 32-bit examples, have you ever read the source code?

If your hosted toolchain complains, check the parameters or use a cross compiler. You can't simply ask it to emit 64-bit objects as the source is not intended for 64-bit without modifications.
Even trying with 32 bit flags (which does compile and run in QEMU) does not work in Virtualbox. This makes me think there is a difference between what QEMU and Virtualbox expects.
Combuster wrote:And more obviously, you are not using the commands from the tutorial.
i586-elf-gcc isn't available on my system. Cross compiling to i586 doesn't fix anything either.
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:

Re: Bare Bones Compilation

Post by Combuster »

It only goes to show that a certain skill in reading is required before you can start OS development. There are instructions how to get i586-elf-gcc. There are also explicit instructions not to use the default gcc on a 64-bit linux.

Continue with the entry exam, please
"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 ]
Post Reply