Page 1 of 1

Multiboot - strange behavior

Posted: Tue Jan 28, 2003 9:45 am
by Whatever5k
I'm currently working on my memory manager...
After initializing some paging structures (without enabling paging), and setting up the physical memory allocator, I want to test this allocator...
Now I have this some code like this here:

Code: Select all

void init_mm(void)
{
init_paging();
init_phys_alloc();

printk("test1\n");
printk("test2\n");
printk("test3\n");
printk("test4\n");
}
These printk() functions may seem strange, but they have a certain role: With this code, GRUB won't load my kernel with the error message "Error 13: Invalid or unsupported executable format".
mbchk also sais that it has no Multiboot header...if I remove the printk() functions, everything is fine again and GRUB loads my kernel (mbchk also sais it's ok)

What the heck is happening here? I'm linking to ELF and I *do* have a multiboot header...
Somebody can help?

Re:Multiboot - strange behavior

Posted: Tue Jan 28, 2003 11:20 am
by Therx
You need to make sure that the Multiboot header is in the first 8 kb of the kernel. The easiest way to do this is to put it as the first thing in the first linked file

Code: Select all

entry:
   jmp start

MULTIBOOT HEADER HERE

start:
   YOUR CODE

Re:Multiboot - strange behavior

Posted: Tue Jan 28, 2003 1:07 pm
by Whatever5k
That's not the problem, I'm doing that... . The strange thing is that the multiboot header fails if I add a couple of printk() calls, but when removing those, everything works as normal, GRUB can load my kernel...

Re:Multiboot - strange behavior

Posted: Tue Jan 28, 2003 3:52 pm
by Adrian
i once had a similiar problem - everytime i added a call to a local function, my code crashed immiedately after starting. after some time i figured out that it is too big, and some of the code was placed in a far sector on the floppy. my readcluster function loading the program was errononeus and couldn'tn read that sector.

so try adding some junk and see if your problem depends on the file size.

PS some time after i copied only 4500 bytes to a new location, so when i got a biggercode it also crashed. soon i've found the problem

Re:Multiboot - strange behavior

Posted: Tue Jan 28, 2003 3:55 pm
by Therx
Can I see your linker script as Adrian suggested maybe it can't cope with a larger file

Re:Multiboot - strange behavior

Posted: Wed Jan 29, 2003 9:50 am
by Whatever5k
Here it is:

Code: Select all

OUTPUT_FORMAT("elf32-i386")     /* we use ELF */
ENTRY(start)

physical_load_addr = 0x100000;  /* GRUB can't load below 1MB */
SECTIONS
{
    . = physical_load_addr;
    .text :
    {
        *(.text)
    }
    .rodata :
    {
        *(.rodata)
    }
    .data :
    {
        *(.data)
    }
    .bss :
    {
        bss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
    kernel_end = .;
}
I also think that it may depend on the file size...but I don't see any errors

Re:Multiboot - strange behavior

Posted: Wed Jan 29, 2003 11:15 am
by Whatever5k
Seems as I've found the bug...the Multiboot header was probably not put in the first 8KB of the kernel...I linked my kernel like this:

Code: Select all

ld -T linker.ld -o flick.img mm/paging.o mm/alloc.o kernel/main.o ... boot/start.o
Now the multiboot header is built in boot/start.o. But it is linked at last and therefore placed at the end of the kernel. If the sources that are placed before start.o get too big, the multiboot header isn't placed in the first 8KB anymore...so I changed it into this:

Code: Select all

ld -T linker.ld -o flick.img boot/start.o mm/paging.o ...
Now it seems to work. The multiboot header is always found at the same offset, no matter if I add some printk() calls...

Thanks for your help anyway