Sign in

Not a member? | Forgot your Password?

Search motoroladsp

Search tips

Subscribe to motoroladsp

Search tips

Free PDF Downloads

A Quadrature Signals Tutorial: Complex, But Not Complicated

Understanding the 'Phasing Method' of Single Sideband Demodulation

Complex Digital Signal Processing in Telecommunications

Introduction to Sound Processing

C++ Tutorial

Introduction of C Programming for DSP Applications

Fixed-Point Arithmetic: An Introduction

Cascaded Integrator-Comb (CIC) Filter Introduction

Discussion Groups

IIR Filter Design Software

See Also

Embedded SystemsFPGA

Discussion Groups | Freescale DSPs | Sections (.bss) , (.rodata) and (.data) ... where and how to place them?

Technical discussions about Freescale (Motorola) DSPs (including the DSP56000, DSP56300, DSP56600, 56800 DSPs).

  

Post a new Thread



Is this thread worth a thumbs up?

0

Sections (.bss) , (.rodata) and (.data) ... where and how to place them? - Mariano Filippa - Jan 6 6:44:00 2004

I've been struggling with (.data), (.bss) and (.rodata) sections. At the end of this message, I have some issues I couldn't figure out. Any help will be greatly appreciated.

 

I did some testing and here are the results. Hope this information is helpful to anybody else.

 

 

Some ELF sections definitions (from targeting manual):

========================================================< /FONT>

 

 (.bss) => segment for uninitialized data. The stationery init code zeroes this area at startup.

 

 (.data) => segment for initialized data here by default.

 

 (.rodata) => segment for constant data, if the project has the write constant data to .rodata section checkbox enabled in target settings.

 

By default, zero-initialized data is put into the .bss section by the compiler (zeroed by INIT code). This behavior can be overriden by using the #pragma explicit_zero_data

 

Results compiling a C file, using Codewarrior 5.1:

========================================================< /FONT>

 

(comments indicate where the variable/constant was placed, taken from ELF symbol table)

 

// **** initialized stuff ****

 

const unsigned int VAR1[3]  = { 0x110A, 0x110B, 0x110C}; // .rodata

const          int VAR2[3]  = { 0x220A, 0x220B, 0x220C}; // .rodata

      unsigned int VAR3[3]  = { 0x330A, 0x330B, 0x330C}; // .data

            ;    int VAR4[3]  = { 0x440A, 0x440B, 0x440C}; // .data

 

const unsigned int VAR5     = 0x5555;   // .rodata

const          int VAR6     = 0x6666;   // .rodata

      unsigned int VAR7     = 0x7777;   // .data

            ;    int VAR8     = 0x8888;   // .data

 

// **** zero-initialized stuff ****

            ;   

const unsigned int VAR9[3]  = { 0x0000, 0x0000, 0x0000}; // .rodata

const          int VAR10[3] = { 0x0000, 0x0000, 0x0000}; // .rodata

      unsigned int VAR11[3] = { 0x0000, 0x0000, 0x0000}; // .bss

            ;    int VAR12[3] = { 0x0000, 0x0000, 0x0000}; // .bss

 

const unsigned int VAR13    = 0x0000;   // .rodata

const          int VAR14    = 0x0000;   // .rodata

      unsigned int VAR15    = 0x0000;   // .bss

            ;    int VAR16    = 0x0000;   // .bss

 

// **** uninitialized stuff ****

            ;   

      unsigned int VAR17[3] ;   // .bss

            ;    int VAR18[3] ;   // .bss

 

      unsigned int VAR19    ;   // .bss

            ;    int VAR20    ;   // .bss 

 

Observations:

========================================================< /FONT>

 

Constants: as expected, all of them are placed into (.rodata), even zero-initialized. These are to be loaded with application.

 

Variables: as expected, initialized stuff goes to (.data) and will be loaded to DSP with application. Zero-initialized stuff goes to (.bss) and will not be loaded with application. Instead, they'll be zeroed by DSP initialize code. Uninitialized variables also go to (.bss).

 

Stuff that I couldn't figure out:

========================================================< /FONT>

 

Where and how to place these sections in memory?

 

For (.rodata) sections, I would place them in (.x_flash_ROM). They are supposed to be constants, they should be downloaded with application and remain there when power goes off. Right?

 

For (.bss) sections, I would place them in (.x_RAM). They are supposed to be R/W and will be initialized after /RESET. Therefore, uninitialized data and zero-initialized data should go here. Right?

 

For (.data)... I read a thousand times "ROM to RAM Copying" in targeting. Still can't figure out. Here's my thinking: (.data) holds initialized variables. I would want them to be downloaded to ROM (to save them when power goes off) and copied to RAM when using them (to be able to R/W).

 

Questions:

 

a) Why "ROM to RAM Copying" specifies to move (.data) to .p_ROM and not .x_ROM ? Why not copying from .xROM to .xRAM ?

 

b) "Targeting" specifies this LCF:

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

MEMORY {

  .text (RWX) : ORIGIN = 0x8000, LENGTH = 0x0    # code (P)

  .data (RW)  : ORIGIN = 0x3000, LENGTH = 0x0    # data (X)-> RAM

}

 

SECTIONS{

 

F__ROM_Address = 0x1000;        # ROM Starting Address

 

  .main_application :

  {

    # .text sections

    *(.text)

  } > .text

 

  .data : AT( F__ROM_Address )  # Start data at 0x1000 -> ROM

  {

    # .data sections

    F_Begin_Data = .;           # Get start location for RAM

    *(.data)      &nb sp;              ;# Write data to the section (ROM)

    F_End_Data = .;              # Get end location for RAM

 

    # .bss sections

    * (.bss)

 

  } > .data

}

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

 

b.1) "F__ROM_Address = 0x1000" does not specify if it is .xROM, .xRAM, etc. What does "AT( F__ROM_Address )" mean ? Shouldn't it be like "F_ROM_Address = .;" inside a (.text) section?

 

b.2) I assume that AT means "put the following sections in F__ROM_Address, but declare them as .data in .xRAM. Is this so?

 

b.3) In my C file, I should do a :

   memcpy( (unsigned long *)&__Begin_Data,

           (cons t unsigned long *)&__ROMAddress,

           dataLen );

But how to tell the compiler that one address corresponds to .pROM and the other to .xRAM? is it embedded in __Begin_Data and __ROMAddress ?

 

 

I apologize for the extended size of this post. Any help on this will be greatly appreciated. It's 1:30am and I should be sleeping by now, but CodeWarrior has been keeping me awake till late with this mess... I hope I can solve this soon and get my life back to normal :)

 

Regards,

Mariano Filippa








Re: Sections (.bss) , (.rodata) and (.data) ... where and how to place them? - Mariano Filippa - Jan 6 20:53:00 2004

Thanks for the prompt reply. This is very helpful. I regret this is not fully explained in the targeting manual... :(
 
I assume that when you define F__ROM_Address , its address points to data (x) memory if its included in a data (x) section . Same goes if it is used within a program (p) section. Please, correct me if I'm wrong:
 
****** if initialized variables are to be placed in data (x) ROM:
 

.app_data : AT( F__x_ROM_Address ) # place them in .x_FLASH, say 0x1000

{

    F_Begin_Data = .;                

    *(.data)     &nb sp;           

    F_End_Data = .;                  

} > .x_RAM        & nbsp;            # declare them to be in .x_RAM, say 0x0000

 

****** if initialized variables are to be placed in program (p) ROM:
 

.app_data : AT ( F__p_ROM_Address) # place them in .p_FLASH, say 0x1000

{

  F_Begin_Data = .;            
  * (.data)            & nbsp;       
  F_End_Data = .;             
} > .p_xRAM_mirror      # Declare them to be in program (p) memory

          ;             & nbsp; #  at the intended data (x) address (mirror).

          ;             & nbsp; # The compiler will access data memory anyway,

          ;             & nbsp; #  no matter if they were declared in program memory

 

However, here's my question: As you said, "...codewarrior doesn't make difference between x-mem and p-mem pointers ...". So, for the second case, I cannot use C to copy variables from pROM to xRAM (the memcpy function). I should use assembly. Is this right? Targeting does not specify how to do it...

 

And last, does Motorola or Metrowerks have another ELF language manual? I'm really confused with:

a) global variables: prepend F or use double underscore? I see them mixed everywhere...

b) I had no idea that >> means "append" to section

Where can I get a good description of the sintax? Targeting isn't doing a good job....

 

Thank you very much for your help. This is starting to work really fine. I must confess that I was going to get a TI dsp. But now, I really want to stick to Motorola MCUs and DSPs. Keep up the good work ! :)

 

Mariano Filippa

m...@umd.umich.edu

 

 
----- Original Message -----
From: Dobsik Lubomir-RC085C
To: Mariano Filippa
Sent: Tuesday, January 06, 2004 9:33 AM
Subject: RE: [motoroladsp] Sections (.bss) , (.rodata) and (.data) ... where and how to place them?

well generally, you can choose whether you want your data to be stored in xflash or pflash, it's up to the initialization, startup, routine to do the proper data move...
 
in the code, the variables will be referenced by the address of the data section they are placed in (plus offset), but physically, they can be stored at any address (this is what the 'AT' command is good for).. so, for example, you want to have the initialized data stored in the xflash

 

.app_data : AT( F__ROM_Address )  # Start data at 0x1000 -> ROM

{

    # .data sections

    F_Begin_Data = .;           # Get start location for RAM

    *(.data)      &nb sp;              ;# Write data to the section (ROM)

    F_End_Data = .;              # Get end location for RAM

} > .data

 

.app_bss :

{

    # .bss sections

    * (.bss)

 

} >> .data          ;    #append to the .data memory segment

 

 

 

in the startup code, you must move the (F_End_Data - F_Begin_Data) words from the address "F__ROM_Address" to "F_Begin_Data" so the variables get initialized.

 

the second case, when the init values are stored in the pflash is rather more involved. you must declare another memory segment in the p-memory, spanning the same addresses as the data memory segment there the variables should reside (an image memory segment), you will take advantage of the fact that codewarrior doesn't make difference between x-mem and p-mem pointers.

 

.app_data : AT (__data_ROM_addr) # address of the data in p-flash
{

  F_Begin_Data = .;
  * (.data)
  F_End_Data = .;
} > .p_internal_RAM_image        # spans the same addresses as the .data memory segment

.app_bss :
{
 . = . + F_End_Data - F_Begin_Data;   # skip the init-ed variables

  # .bss sections

  * (.bss)

....

} > .data

 

 

if something was still unclear, don't heasitate to ask me,

 

Lubomir

-----Original Message-----
From: Mariano Filippa [mailto:m...@fibertel.com.ar]
Sent: 6. ledna 2004 7:44
To: m...@yahoogroups.com
Subject: [motoroladsp] Sections (.bss) , (.rodata) and (.data) ... where and how to place them?

I've been struggling with (.data), (.bss) and (.rodata) sections. At the end of this message, I have some issues I couldn't figure out. Any help will be greatly appreciated.

 

I did some testing and here are the results. Hope this information is helpful to anybody else.

 

 

Some ELF sections definitions (from targeting manual):

========================================================< /FONT>

 

 (.bss) => segment for uninitialized data. The stationery init code zeroes this area at startup.

 

 (.data) => segment for initialized data here by default.

 

 (.rodata) => segment for constant data, if the project has the write constant data to .rodata section checkbox enabled in target settings.

 

By default, zero-initialized data is put into the .bss section by the compiler (zeroed by INIT code). This behavior can be overriden by using the #pragma explicit_zero_data

 

Results compiling a C file, using Codewarrior 5.1:

========================================================< /FONT>

 

(comments indicate where the variable/constant was placed, taken from ELF symbol table)

 

// **** initialized stuff ****

 

const unsigned int VAR1[3]  = { 0x110A, 0x110B, 0x110C}; // .rodata

const          int VAR2[3]  = { 0x220A, 0x220B, 0x220C}; // .rodata

      unsigned int VAR3[3]  = { 0x330A, 0x330B, 0x330C}; // .data

            ;    int VAR4[3]  = { 0x440A, 0x440B, 0x440C}; // .data

 

const unsigned int VAR5     = 0x5555;   // .rodata

const          int VAR6     = 0x6666;   // .rodata

      unsigned int VAR7     = 0x7777;   // .data

            ;    int VAR8     = 0x8888;   // .data

 

// **** zero-initialized stuff ****

            ;   

const unsigned int VAR9[3]  = { 0x0000, 0x0000, 0x0000}; // .rodata

const          int VAR10[3] = { 0x0000, 0x0000, 0x0000}; // .rodata

      unsigned int VAR11[3] = { 0x0000, 0x0000, 0x0000}; // .bss

            ;    int VAR12[3] = { 0x0000, 0x0000, 0x0000}; // .bss

 

const unsigned int VAR13    = 0x0000;   // .rodata

const          int VAR14    = 0x0000;   // .rodata

      unsigned int VAR15    = 0x0000;   // .bss

            ;    int VAR16    = 0x0000;   // .bss

 

// **** uninitialized stuff ****

            ;   

      unsigned int VAR17[3] ;   // .bss

            ;    int VAR18[3] ;   // .bss

 

      unsigned int VAR19    ;   // .bss

            ;    int VAR20    ;   // .bss 

 

Observations:

========================================================< /FONT>

 

Constants: as expected, all of them are placed into (.rodata), even zero-initialized. These are to be loaded with application.

 

Variables: as expected, initialized stuff goes to (.data) and will be loaded to DSP with application. Zero-initialized stuff goes to (.bss) and will not be loaded with application. Instead, they'll be zeroed by DSP initialize code. Uninitialized variables also go to (.bss).

 

Stuff that I couldn't figure out:

========================================================< /FONT>

 

Where and how to place these sections in memory?

 

For (.rodata) sections, I would place them in (.x_flash_ROM). They are supposed to be constants, they should be downloaded with application and remain there when power goes off. Right?

 

For (.bss) sections, I would place them in (.x_RAM). They are supposed to be R/W and will be initialized after /RESET. Therefore, uninitialized data and zero-initialized data should go here. Right?

 

For (.data)... I read a thousand times "ROM to RAM Copying" in targeting. Still can't figure out. Here's my thinking: (.data) holds initialized variables. I would want them to be downloaded to ROM (to save them when power goes off) and copied to RAM when using them (to be able to R/W).

 

Questions:

 

a) Why "ROM to RAM Copying" specifies to move (.data) to .p_ROM and not .x_ROM ? Why not copying from .xROM to .xRAM ?

 

b) "Targeting" specifies this LCF:

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

MEMORY {

  .text (RWX) : ORIGIN = 0x8000, LENGTH = 0x0    # code (P)

  .data (RW)  : ORIGIN = 0x3000, LENGTH = 0x0    # data (X)-> RAM

}

 

SECTIONS{

 

F__ROM_Address = 0x1000;        # ROM Starting Address

 

  .main_application :

  {

    # .text sections

    *(.text)

  } > .text

 

  .data : AT( F__ROM_Address )  # Start data at 0x1000 -> ROM

  {

    # .data sections

    F_Begin_Data = .;           # Get start location for RAM

    *(.data)      &nb sp;              ;# Write data to the section (ROM)

    F_End_Data = .;              # Get end location for RAM

 

    # .bss sections

    * (.bss)

 

  } > .data

}

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

 

b.1) "F__ROM_Address = 0x1000" does not specify if it is .xROM, .xRAM, etc. What does "AT( F__ROM_Address )" mean ? Shouldn't it be like "F_ROM_Address = .;" inside a (.text) section?

 

b.2) I assume that AT means "put the following sections in F__ROM_Address, but declare them as .data in .xRAM. Is this so?

 

b.3) In my C file, I should do a :

   memcpy( (unsigned long *)&__Begin_Data,

           (cons t unsigned long *)&__ROMAddress,

           dataLen );

But how to tell the compiler that one address corresponds to .pROM and the other to .xRAM? is it embedded in __Begin_Data and __ROMAddress ?

 

 

I apologize for the extended size of this post. Any help on this will be greatly appreciated. It's 1:30am and I should be sleeping by now, but CodeWarrior has been keeping me awake till late with this mess... I hope I can solve this soon and get my life back to normal :)

 

Regards,

Mariano Filippa



_____________________________________
/groups.php3

Yahoo! Groups Links
  • To







Re: Sections (.bss) , (.rodata) and (.data) ... where and how to place them? - Mariano Filippa - Jan 7 18:11:00 2004

Thank you for the code !! It is really helpful.

You initialization is pretty much like mine. You are copying from xROM to
xRAM with C. That works excellent.

I also noticed that you got rid of MSL C library. I tried to get rid of it
but when I use a #pragma interrupt, the compiler calls a couple of functions
to save registers. I noticed that you used pure assembly in your ISR. Is
this the reason why you used asm?

I was thinking of writing my ISR in C without the #pragma. Then, I will have
something like:

#define ExitISR asm( rti )

void MyISR(void){
SaveRegisters();
// code goes here
ExitISR;
}

And I will have the following too:

asm void SaveRegisters(void){
// code in assemble for saving registers in stack
// can be copied from MSL C library or make your own
}

When compiled, I will have a RTI followed by an RTS, but it doesn't harm to
have the RTS.
By the way, pretty neat coding. Well done!

Regards,
Mariano ----- Original Message -----
From: "Thomas Kracke" <>
To: <>
Sent: Tuesday, January 06, 2004 7:28 PM
Subject: [motoroladsp] Sections (.bss) , (.rodata) and (.data) ... where and
how to place them? > Hallo Mariano,
>
> I had the same problems with CW a few weeks ago.
> The bad thing is: CW has differences between the
> versions for different controllers. I solved the
> problem with the MPC555 two years ago, but the CW for
> DSP56803 has some differences.
> I attached a complete project, which I run with CW
> Version . Please have a look on file DSP56803.c line
> 284 ff. and the file linker.cmd.
>
> I hope this help you.
>
> =====
>
> mit freundlichen Grueßen,
>
> Thomas Kracke
>
> __________________________________