Page 1 of 2
grub load time crash
Posted: Sat May 05, 2007 5:44 am
by supagu
NOTE: im using c++ for my kernel
boots using grub
so i've got my file system module that handles the file system.
I have a file class (with no constructor). When I add a static File to my memory manager, i get a load time crash saying:
root (fd0)
filesystem is fat, using whole disk
kernel /kernel.bin
[multiboot-kludge, loadaddr=0x100000, text-and-data=0xb000
error 13: invalid or unsupported format
any ideas what this could be? i tried swapping it with an array of 1024 ints just to see if it was some size problem, but that worked fine.
Posted: Sat May 05, 2007 8:03 am
by Aali
you can't load anything under 1MB with grub
Posted: Sat May 05, 2007 8:12 am
by supagu
under?
you mean my kernal needs to be bigger than 1mb in size?
its about 41kb (on disc) and adding the static File should have only made it bigger.
Posted: Sat May 05, 2007 8:32 am
by frank
No, you can't load anything at an address lower than 1mb, somehow one of the sections wants to be loaded at 0xb000.
Posted: Sat May 05, 2007 9:10 am
by supagu
hrmm this is all that is in my File class:
class File
{
// some functions here
char name[256];
unsigned long handle; // handle to the file
unsigned long cursor;
unsigned long fileSize; // size of file
unsigned short flags;
};
then in my memory mgr, i have:
static FS::File sPageFile;
adding this static instance is causing the problem, but i fail to see why/how
Posted: Sat May 05, 2007 9:26 am
by frank
I don't think that it has anything to do with the size of the class. I think that it is a problem with where the class is located in the binary and where GRUB is trying to load it too. Can you post you linker script?
Posted: Sat May 05, 2007 9:26 am
by Brynet-Inc
Maybe you're missing a .rodata section in your linker script... We can't help you unless you give us more information.
Posted: Sat May 05, 2007 6:14 pm
by supagu
Code: Select all
export PATH=$PATH:/usr/cross/bin
del *.bin
nasm -f elf -o start.o start.asm
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o video.o video.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o gdt.o gdt.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o idt.o idt.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o isrs.o isrs.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o irq.o irq.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o harddrive.o harddrive.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o timer.o timer.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o kb.o kb.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o string.o string.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o memory.o memory.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o system.o system.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o command.o command.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o smbios.o smbios.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o pci.o pci.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o fat32.o fat32.cpp
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o svga.o svga.cpp
i586-elf-ld -T link.ld -o kernel.bin start.o main.o timer.o video.o gdt.o idt.o isrs.o irq.o kb.o string.o memory.o system.o harddrive.o command.o smbios.o pci.o fat32.o svga.o
del *.o
its a batch file which i compile under cygwin
Posted: Sun May 06, 2007 8:19 am
by frank
we want to see the contents of link.ld
Posted: Mon May 07, 2007 2:39 am
by Combuster
also a header listing from objdump would be helpful (ctors+dtors sections)
Posted: Wed May 09, 2007 4:49 am
by supagu
OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
objdump on kernel.bin says its un recognised format
Posted: Wed May 09, 2007 5:03 am
by AJ
If you are using C++, it looks like your .ctors and .dtors sections are missing from the link script. You will need to manually run the constructors and destructors for global and static objects. Try looking at
http://www.osdever.net/tutorials/pdf/cpp_kernel.pdf.
HTH
Adam
Posted: Wed May 09, 2007 5:20 am
by Combuster
supagu wrote:objdump on kernel.bin says its un recognised format
obviously you cant dump flat binary files, would you try it again on the
object files?
Posted: Wed May 09, 2007 6:20 am
by urxae
supagu wrote:Code: Select all
nasm -f elf -o start.o start.asm
g++ -b i586-elf -V 4.0.2 -Wall -O -fno-rtti -fno-exceptions -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.cpp
[snip]
i586-elf-ld -T link.ld -o kernel.bin start.o main.o timer.o video.o gdt.o idt.o isrs.o irq.o kb.o string.o memory.o system.o harddrive.o command.o smbios.o pci.o fat32.o svga.o
supagu wrote:OUTPUT_FORMAT("binary")
Let me get this straight...
- You use GRUB as your bootloader.
- You're using what looks like an ELF cross-compiler + ELF ld. You instruct NASM to produce ELF output.
- You use that toolchain link your kernel into raw binary format (with the multiboot "aout kludge").
Any particular reason for that last one? (GRUB should load ELF executables just fine, without needing the kludge)
Try changing the OUTPUT_FORMAT to an ELF variant (possibly most easily done by just omitting it, as it's probably the default for that toolchain) and disabling the "kludge" flag in the multiboot header. See if that fixes it.
Posted: Wed May 09, 2007 6:33 am
by Combuster
Any particular reason for that last one? (GRUB should load ELF executables just fine, without needing the kludge)
Try changing the OUTPUT_FORMAT to an ELF variant (possibly most easily done by just omitting it, as it's probably the default for that toolchain) and disabling the "kludge" flag in the multiboot header. See if that fixes it.
GRUB may support both ELF and Multiboot, but other loaders may not necessarily do so (and support only one, or even neither). Hence choosing multiboot is a perfectly valid decision. Besides, many tutorials target multiboot rather than elf. Changing targets now will only cause more problems rather than solving any.