Page 1 of 1

Declare "end of kernel" in linker script

Posted: Sat Mar 21, 2009 7:02 am
by mangaluve
The linker script that I use for my kernel is

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text 0x1000 :
    {     
        *(.text)
    }

    .data :
    {   
        *(.data)       
    }

    .bss :
    {    
        *(.bss)      
    }

    end = .; _end = .; __end = .;
}
Then I can use the address of the end-variable in my C-code to determine where the kernel ends. However, my kernel has a size of 0x1570 bytes. It's loaded into memory at address 0x1000. Hence, the end variable should have the address 0x2570, right? But it hasn't, the value of end, when I print it, is 0x31D8. Now I dont like when things don't add up, so what is the problem? If I put the end-variable before the .bss section instead, it seems correct, the address of end is 0x2570.

Re: Declare "end of kernel" in linker script

Posted: Sat Mar 21, 2009 7:18 am
by clange
Hi

BSS = blank static storage. This is just zeroes so there is no need to store that in the kernel binary file. This explains the difference in file size and loaded size. Remember to clear the BSS segment your self during kernel init.

clange

EDIT: bss is Block Started by Symbol not blank static storage.

Re: Declare "end of kernel" in linker script

Posted: Sat Mar 21, 2009 7:25 am
by mangaluve
THanks! Exactly what is the .bss segment, when it comes to C-code? Is it everything that isn't initialized or what? (I dont know how to create a "blank" static array for instance). So basically I should change my link-script to

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text 0x1000 :
    {     
        *(.text)
    }

    .data :
    {   
        *(.data)       
    }

    .bss :
    {   
         bss_start = .; _bss_start = .; __bss_start = .;
        *(.bss)     
    }

    end = .; _end = .; __end = .;
}
and then do something like

Code: Select all

memset((u8int*)&bss_start + 4, 0, &end - & bss_start - 4);
[code]
to fill the space between (not including) bss_start and end with zeroes?

Re: Declare "end of kernel" in linker script

Posted: Sat Mar 21, 2009 8:27 am
by clange
Hi

BSS is not blank static storage but Block Started by Symbol http://en.wikipedia.org/wiki/Block_Started_by_Symbol.

You don't need to add 4 to the address of bss_start.

clange

Re: Declare "end of kernel" in linker script

Posted: Sat Mar 21, 2009 8:28 am
by mangaluve
But what if I want to use the BBS for some reason later on? It will be overwritten in case I dont add 4, isn't that correct? (just precaution)

Re: Declare "end of kernel" in linker script

Posted: Sat Mar 21, 2009 9:44 am
by clange
You are already using the BSS and you should overwrite it with zeroes. The code expects it to be cleared by the loader.

I think you are confused about pointers. bss_start is a symbol that is defined to be positioned at the start of the BSS. When you take the address of bss_start this will be the address of the BSS.

clange