Erro 13: Invalid or unsupported executable format
Posted: Sun Aug 02, 2009 6:57 am
Hello,
I looked over loads of forum posts and I couldn't find a solution. I would really appreciate some help as I've been trying to run this for 3 full days. Thanks in advance.
I'm trying to follow the Bare Bones tutorial to right my first kernel. What I'm trying to do it to write a kernel that loops forever printing "Hello, World!".
I followed all the steps in the tutorial except for a few changes since it's written for x86 and I'm trying to create a x86_64 kernel. The changes I've done were the following:
change linker.ld lines from:
push eax
push ebx
to:
push rax
push rbx
After this change I can compile and link with:
nasm -f elf64 -o loader.o -s loader.s
x86_64-pc-linux-gcc -masm=intel -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs
Which gives me the following error:
kernel.c: In function 'kmain':
kernel.c:5: warning: unused variable 'boot_loader_name'
kernel.c:3: warning: unused parameter 'magic'
x86_64-pc-linux-ld -T linker.ld -o kernel.bin loader.o kernel.o
I then create the floppy image (tried with stage1 and stage2 from i386 and x86_64) , run qemu and when I type 'kernel 200+5' I get:
Erro 13: Invalid or unsupported executable format
I also trying with target elf64-little and tried using grub2's grub-mkrecovery. The last didn't give me the error but I'm still not sure if it was working.
Extra question: Just let me ask something that it's on my mind. As far as I know stage1 and stage2 are running in real mode. Does it still support the push rax/rbx from loader.s? Aren't them only allowed in long mode?
Here is the output of some commands and my code:
$file kernel.bin
kernel.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
$file kernel.o
kernel.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
$file loader.o
loader.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
$file floppy.img
floppy.img: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3
$objdump -h kernel.bin
kernel.bin: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 000000bb 0000000000100000 0000000000100000 00100000 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .rodata 00000002 0000000000101000 0000000000101000 00101000 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .eh_frame 00000058 0000000000101008 0000000000101008 00101008 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .bss 00004000 0000000000101060 0000000000101060 00101060 2**2
ALLOC
4 .comment 00000031 0000000000000000 0000000000000000 00101060 2**0
CONTENTS, READONLY
$objdump -h kernel.o
kernel.o: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000009b 0000000000000000 0000000000000000 00000040 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 0000000000000000 0000000000000000 000000dc 2**2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 0000000000000000 0000000000000000 000000dc 2**2
ALLOC
3 .rodata 00000002 0000000000000000 0000000000000000 000000dc 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .comment 00000012 0000000000000000 0000000000000000 000000de 2**0
CONTENTS, READONLY
5 .note.GNU-stack 00000000 0000000000000000 0000000000000000 000000f0 2**0
CONTENTS, READONLY
6 .eh_frame 00000050 0000000000000000 0000000000000000 000000f0 2**3
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
$objdump -h loader.o
loader.o: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000001f 0000000000000000 0000000000000000 00000240 2**4
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .bss 00004000 0000000000000000 0000000000000000 00000260 2**2
ALLOC
2 .comment 0000001f 0000000000000000 0000000000000000 00000260 2**0
CONTENTS, READONLY
$mbcheck loader.o
loader.o: The Multiboot header is found at the offset 576.
loader.o: Page alignment is turned on.
loader.o: Memory information is turned on.
loader.o: Address fields is turned off.
loader.o: All checks passed.
$mbcheck (for kernel.o and kernel.bin)
kernel.bin: No Multiboot header.
$mbcheck floppy.img
floppy.img: The Multiboot header is found at the offset 5367.
floppy.img: Bad checksum (0xffdff805).
kernel.c
#include "vga.h"
void kmain(void *mbd, unsigned int magic){
char *boot_loader_name = (char *) mbd + 64;
char str[] = "Hello, World!";
while(1==1) { vga_print(str, GREEN_BLACK); }
}
I looked over loads of forum posts and I couldn't find a solution. I would really appreciate some help as I've been trying to run this for 3 full days. Thanks in advance.
I'm trying to follow the Bare Bones tutorial to right my first kernel. What I'm trying to do it to write a kernel that loops forever printing "Hello, World!".
I followed all the steps in the tutorial except for a few changes since it's written for x86 and I'm trying to create a x86_64 kernel. The changes I've done were the following:
change linker.ld lines from:
push eax
push ebx
to:
push rax
push rbx
After this change I can compile and link with:
nasm -f elf64 -o loader.o -s loader.s
x86_64-pc-linux-gcc -masm=intel -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs
Which gives me the following error:
kernel.c: In function 'kmain':
kernel.c:5: warning: unused variable 'boot_loader_name'
kernel.c:3: warning: unused parameter 'magic'
x86_64-pc-linux-ld -T linker.ld -o kernel.bin loader.o kernel.o
I then create the floppy image (tried with stage1 and stage2 from i386 and x86_64) , run qemu and when I type 'kernel 200+5' I get:
Erro 13: Invalid or unsupported executable format
I also trying with target elf64-little and tried using grub2's grub-mkrecovery. The last didn't give me the error but I'm still not sure if it was working.
Extra question: Just let me ask something that it's on my mind. As far as I know stage1 and stage2 are running in real mode. Does it still support the push rax/rbx from loader.s? Aren't them only allowed in long mode?
Here is the output of some commands and my code:
$file kernel.bin
kernel.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
$file kernel.o
kernel.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
$file loader.o
loader.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
$file floppy.img
floppy.img: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3
$objdump -h kernel.bin
kernel.bin: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 000000bb 0000000000100000 0000000000100000 00100000 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .rodata 00000002 0000000000101000 0000000000101000 00101000 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .eh_frame 00000058 0000000000101008 0000000000101008 00101008 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .bss 00004000 0000000000101060 0000000000101060 00101060 2**2
ALLOC
4 .comment 00000031 0000000000000000 0000000000000000 00101060 2**0
CONTENTS, READONLY
$objdump -h kernel.o
kernel.o: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000009b 0000000000000000 0000000000000000 00000040 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 0000000000000000 0000000000000000 000000dc 2**2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 0000000000000000 0000000000000000 000000dc 2**2
ALLOC
3 .rodata 00000002 0000000000000000 0000000000000000 000000dc 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .comment 00000012 0000000000000000 0000000000000000 000000de 2**0
CONTENTS, READONLY
5 .note.GNU-stack 00000000 0000000000000000 0000000000000000 000000f0 2**0
CONTENTS, READONLY
6 .eh_frame 00000050 0000000000000000 0000000000000000 000000f0 2**3
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
$objdump -h loader.o
loader.o: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000001f 0000000000000000 0000000000000000 00000240 2**4
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .bss 00004000 0000000000000000 0000000000000000 00000260 2**2
ALLOC
2 .comment 0000001f 0000000000000000 0000000000000000 00000260 2**0
CONTENTS, READONLY
$mbcheck loader.o
loader.o: The Multiboot header is found at the offset 576.
loader.o: Page alignment is turned on.
loader.o: Memory information is turned on.
loader.o: Address fields is turned off.
loader.o: All checks passed.
$mbcheck (for kernel.o and kernel.bin)
kernel.bin: No Multiboot header.
$mbcheck floppy.img
floppy.img: The Multiboot header is found at the offset 5367.
floppy.img: Bad checksum (0xffdff805).
kernel.c
#include "vga.h"
void kmain(void *mbd, unsigned int magic){
char *boot_loader_name = (char *) mbd + 64;
char str[] = "Hello, World!";
while(1==1) { vga_print(str, GREEN_BLACK); }
}