grub load time crash

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.
supagu
Member
Member
Posts: 46
Joined: Sat Apr 07, 2007 1:24 am

grub load time crash

Post 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.
Aali
Member
Member
Posts: 58
Joined: Sat Apr 14, 2007 12:13 pm

Post by Aali »

you can't load anything under 1MB with grub
supagu
Member
Member
Posts: 46
Joined: Sat Apr 07, 2007 1:24 am

Post 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.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post 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.
supagu
Member
Member
Posts: 46
Joined: Sat Apr 07, 2007 1:24 am

Post 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
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post 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?
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
supagu
Member
Member
Posts: 46
Joined: Sat Apr 07, 2007 1:24 am

Post 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
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

we want to see the contents of link.ld
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 »

also a header listing from objdump would be helpful (ctors+dtors sections)
"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 ]
supagu
Member
Member
Posts: 46
Joined: Sat Apr 07, 2007 1:24 am

Post 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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
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 »

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?
"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 ]
urxae
Member
Member
Posts: 149
Joined: Sun Jul 30, 2006 8:16 am
Location: The Netherlands

Post 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.
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 »

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.
"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