On 03/24/2012 11:52 PM, Pranay Kumar Srivastava wrote:
>
> ________________________________________
> From: kernelnewbies-bounces+pranay.shrivastava=hcl....@kernelnewbies.org 
> [kernelnewbies-bounces+pranay.shrivastava=hcl....@kernelnewbies.org] On 
> Behalf Of [email protected] 
> [[email protected]]
> Sent: Saturday, March 24, 2012 9:30 PM
> To: [email protected]
> Subject: Kernelnewbies Digest, Vol 16, Issue 29
>
> Send Kernelnewbies mailing list submissions to
>          [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>          http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> or, via email, send a message with subject or body 'help' to
>          [email protected]
>
> You can reach the person managing the list at
>          [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Kernelnewbies digest..."
>
>
> Today's Topics:
>
>     1. Query on linker scripts (Vaibhav Jain)
>     2. Re: Query on linker scripts (Carlo Caione)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 23 Mar 2012 21:43:40 -0700
> From: Vaibhav Jain<[email protected]>
> Subject: Query on linker scripts
> To: [email protected]
> Message-ID:
>          <CAKuUYSw=_zzykpwetbjsgeyppsrowk+whm0o5l_pncmanvc...@mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> Recently I have started reading tutorials for writing a small kernel. All
> such tutorials mention use of linker scripts. I have
> read few articles on linker scritps but I am stuck on one thing. I am
> unable to understand the use of defining new symbols in linker scripts.
> Using a linker script to arrange different sections in the object file is
> understandable but defining symbols which are not referenced anywhere in
> the script
> is confusing. An example is the use of symbols sbss and ebss in the bss
> section as show in the script below
>
>
> ENTRY (loader)
> SECTIONS
> {
>      . = 0x00100000;
>      .text ALIGN (0x1000) :
>      {
>          *(.text)
>      }
>      .rodata ALIGN (0x1000) :
>      {
>          *(.rodata*)
>      }
>      .data ALIGN (0x1000) :
>      {
>          *(.data)
>      }
>      .bss :
>      {
>          sbss = .;
>          *(COMMON)
>          *(.bss)
>          ebss = .;
>      }
> }
>
> Please explain how defining such symbols is useful.
>
> Thanks
> Vaibhav Jain
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: 
> http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120323/6e1741da/attachment-0001.html
>
> ------------------------------
>
> Message: 2
> Date: Sat, 24 Mar 2012 16:26:38 +0100
> From: Carlo Caione<[email protected]>
> Subject: Re: Query on linker scripts
> To: Vaibhav Jain<[email protected]>
> Cc: [email protected]
> Message-ID:<[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 24/03/2012 05:43, Vaibhav Jain wrote:
>> Hi,
> [cut]
>> is confusing. An example is the use of symbols sbss and ebss in the bss
>> section as show in the script below
>> ENTRY (loader)
>> SECTIONS
>> {
>>       . = 0x00100000;
>>       .text ALIGN (0x1000) :
>>       {
>>           *(.text)
>>       }
>>       .rodata ALIGN (0x1000) :
>>       {
>>           *(.rodata*)
>>       }
>>       .data ALIGN (0x1000) :
>>       {
>>           *(.data)
>>       }
>>       .bss :
>>       {
>>           sbss = .;
The sbss will tell you the start of the section bss.
>>           *(COMMON)
>>           *(.bss)
>>           ebss = .;

The ebss will tell you the end of the section bss. The use of these symbols is 
since you'd like to have the kernel's section be safe from every other process.

This way you can know where your kernel code starts and ends. So you can set up 
the pages( ptes and pgds as well) in a sensible manner for your kernel.

So in the above case you'd have like two variables in your C code like extern 
long sbss,ebss and then to get the location where the bss begins you'd do &sbss 
while to get its ending address you'd do &ebss. So when you subtract these two 
that should give you the size of your bss section.

However you should do ebss=. after your .bss section and make it ALIGN(0x1000) 
like others so you get page aligned section values cuz it makes easier to 
arrange for the pte and pgd for kernel. Also you should set the GDT values for 
kernel only code separately accordingly from the values you get after an 
initial temporary GDT has been setup earlier by GRUB or by you.

More appropriate would be to get the size of text and data sections as well 
since you wouldn't want to accidentally bump into kernel code.



>>       }
>> }
>
> I'm not sure if you are OT, anyway...
>
> i.e. they are useful if you want to clear the bss section before execution.
>
> [snippet for ARM proc]
> ...
>          ldr     r2, =_sbss
>          b       LoopFillZerobss
> /* Zero fill the bss segment. */
> FillZerobss:
>          movs    r3, #0
>          str     r3, [r2], #4
>
> LoopFillZerobss:
>          ldr     r3, = _ebss
>          cmp     r2, r3
>          bcc     FillZerobss
> ...
>
> --
> Carlo Caione
>
>
>
> ------------------------------
>
> _______________________________________________
> Kernelnewbies mailing list
> [email protected]
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
> End of Kernelnewbies Digest, Vol 16, Issue 29
> *********************************************

::DISCLAIMER::
-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended 
for the named recipient(s) only.
It shall not attach any liability on the originator or HCL or its affiliates. 
Any views or opinions presented in
this email are solely those of the author and may not necessarily reflect the 
opinions of HCL or its affiliates.
Any form of reproduction, dissemination, copying, disclosure, modification, 
distribution and / or publication of
this message without the prior written consent of the author of this e-mail is 
strictly prohibited. If you have
received this email in error please delete it and notify the sender 
immediately. Before opening any mail and
attachments please check them for viruses and defect.

-----------------------------------------------------------------------------------------------------------------------

_______________________________________________
Kernelnewbies mailing list
[email protected]
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Reply via email to