Page 1 of 1

Bare Bones Compilation

Posted: Sat Oct 06, 2012 12:00 am
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"

Re: Bare Bones Compilation

Posted: Sat Oct 06, 2012 12:13 am
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.

Re: Bare Bones Compilation

Posted: Sat Oct 06, 2012 3:22 am
by Combuster
And more obviously, you are not using the commands from the tutorial.

Re: Bare Bones Compilation

Posted: Sat Oct 06, 2012 10:20 am
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.

Re: Bare Bones Compilation

Posted: Sun Oct 07, 2012 5:12 am
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