Declare "end of kernel" in linker script

Programming, for all ages and all languages.
Post Reply
mangaluve
Member
Member
Posts: 110
Joined: Mon Feb 23, 2009 6:53 am

Declare "end of kernel" in linker script

Post 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.
clange
Member
Member
Posts: 163
Joined: Sun Oct 05, 2008 5:00 am
Location: Copenhagen, Denmark
Contact:

Re: Declare "end of kernel" in linker script

Post 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.
Last edited by clange on Sat Mar 21, 2009 8:28 am, edited 1 time in total.
mangaluve
Member
Member
Posts: 110
Joined: Mon Feb 23, 2009 6:53 am

Re: Declare "end of kernel" in linker script

Post 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?
clange
Member
Member
Posts: 163
Joined: Sun Oct 05, 2008 5:00 am
Location: Copenhagen, Denmark
Contact:

Re: Declare "end of kernel" in linker script

Post 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
mangaluve
Member
Member
Posts: 110
Joined: Mon Feb 23, 2009 6:53 am

Re: Declare "end of kernel" in linker script

Post 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)
clange
Member
Member
Posts: 163
Joined: Sun Oct 05, 2008 5:00 am
Location: Copenhagen, Denmark
Contact:

Re: Declare "end of kernel" in linker script

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