multiboot structures

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.
Post Reply
northfuse

multiboot structures

Post by northfuse »

is there any way through the multiboot structures (I use grub) to find out the size of the kernel image? it would really help me in setting up a memory manager (so I don't write over the kernel image ;D) thanks
Guest

Re:multiboot structures

Post by Guest »

you could do that with the use of your linker script, which is a much better way to find the kernel size at runtime.
you will have to use variables in your linker script to do this. IIRC this has been discussed here in detail sometime previously. HTH
Nairou

Re:multiboot structures

Post by Nairou »

Can you give an example? A search isn't turning up much.
Neuromancer

Re:multiboot structures

Post by Neuromancer »

Imagine u have this linker script:

Code: Select all

ENTRY (_loader)

SECTIONS
{
    . = 0x00100000;

    _start = .;

    .text :
    {
        *(.text)
        *(.rodata)
    }

    .data ALIGN (0x1000) :
    {
        *(.data)
    }

    .bss :
    {
        _sbss = .;
        *(COMMON)
        *(.bss)
        _ebss = .;
    }

     _end = .;
}
In you code use can get the size of the kernel easily:

Code: Select all


extern void _start, _end;

unsigned int kernelGetSize(void) {
        return (unsigned int)&_end - (unsigned int)&_start;
}
Remember to add the 'extern' statement to say the compiler that _start and _end are located outside this source file.
Compile your kernel with the '-T <linker script>' flag.
Nairou

Re:multiboot structures

Post by Nairou »

So does that return the size of the kernel as it exists on file, or the size of the block of memory the kernel occupies once it has been fully loaded by the bootloader?
Neuromancer

Re:multiboot structures

Post by Neuromancer »

It gives you the effective RAM memory used by the kernel.
Post Reply