EmbeddedRelated.com
Forums

Initializing static variables (GNU gcc tools for H8S/2633)

Started by Robert Bielik April 15, 2004
"Paul Carpenter" <paul$@pcserv.demon.co.uk> wrote in message
news:20040415.2307.298224snz@pcserv.demon.co.uk...
> I have never seen "Hitachi" compilers, just IAR from Hitachi/Renesas, with > more recognition of GCC.
IIRC, it was around the time that HEW came out ('99?) that the sales reps were offering us three toolchains (gcc, IAR, Hitachi), and the Hitachi one was being heavily promoted (as you'd expect). I do distinctly remember my rep telling me that the IAR compilers were being "de-emphasised" in favour of Hitachi versions, but I also remember wondering later if it was purely a badging exercise. More recently I've been working on the H8 again, with up-to-date tools provided by my customer's R&D dept. And the compilers again are overtly IAR. I think I missed the middle of the story (roughly '01 through late '03). Steve http://www.sfdesign.co.uk http://www.fivetrees.com
On 14 Apr 2004 23:11:47 -0700, robert.bielik@gyros.com (Robert Bielik)
wrote:

>Hi all, > >I have "inherited" a project with a H8S/2633F MPU (using the GNU gcc >toolchain). I need static variables. Problem is that there is no init >code for static variables in the bootloader code. I.e. the initial >static data is correctly placed in the FLASH ROM, but the data is >never transferred at startup to the RAM. I have searched everywhere >for a simple example showing how to do it but have come up empty so >far. > >Does anyone have a (asm) code snippet for this ?? I guess any MPU in >the 26xx series would do... > >If you do, please send a copy to my email address also. > >TIA >/Rob
Hi Rob, As you've already surmised you need to create a startup code section which takes the ROM-based .data section and copies it into the .bss section. The linker, LD, configuartion file is so organised to refer to an image of the .data section but offset into the .bss or RAM area. The GNU manual on LD provides you with information on how to setup the linker file. From that you can write the companion startup code. The startup code is initiated from the Power-on-reset. The start and end boundaries of the .data section can be defined in the linker configuration file -- this is required to mark out the start & range of the ROM code to copy. Of course there is the simple solution and that is to eliminate all use of initialised variables. Ken. +====================================+ I hate junk email. Please direct any genuine email to: kenlee at hotpop.com
Ken Lee wrote:
> As you've already surmised you need to create a startup code > section which takes the ROM-based .data section and copies it into the > .bss section.
A small nit here. The initialized data is copied to RAM, but not the bss. The bss is for global/static variables that are initialized by default to zero.
> The linker, LD, configuartion file is so organised to > refer to an image of the .data section but offset into the .bss or RAM > area. The GNU manual on LD provides you with information on how to > setup the linker file. From that you can write the companion startup > code. The startup code is initiated from the Power-on-reset. The start > and end boundaries of the .data section can be defined in the linker > configuration file -- this is required to mark out the start & range > of the ROM code to copy. > > Of course there is the simple solution and that is to > eliminate all use of initialised variables.
While this eliminates the need to copy initialized data into RAM, it does not do the other important setup of the C runtime, which is to zero the bss section. I assume that if your startup code is missing the data initialization it may also be missing the bss initialization. -- Michael N. Moran (h) 770 516 7918 5009 Old Field Ct. (c) 678 521 5460 Kennesaw, GA, USA 30144 http://mnmoran.org "... abstractions save us time working, but they don't save us time learning." Joel Spolsky, The Law of Leaky Abstractions The Beatles were wrong: 1 & 1 & 1 is 1
On 2004-04-16, Ken Lee <postmaster@noname.com> wrote:

> As you've already surmised you need to create a startup code > section which takes the ROM-based .data section and copies it > into the .bss section.
Nooo! The .bss section should be initialized to all zeros. The .data section should have two addresses: VMA (virtial memory address): the run-time address where the compiled code expects the variables to be. This will be in RAM. LMA (load memory address): the addresses to which the initialization data are stored by the linker. This will be in ROM. Startup code should copy from .data's LMA to .data's VMA.
> The linker, LD, configuartion file is so organised to refer to > an image of the .data section but offset into the .bss or RAM > area.
It sounds like you're doing a round-about, home-made implimenation of the VMA/LMA capabilities built into the linker?
>[...]
> Of course there is the simple solution and that is to > eliminate all use of initialised variables.
That's rarely simple. It takes 4-5 lines of code to copy all of the initializer values from .data LMA to the .data VMA. It takes at least one line of code per vairable to itialize them piecemeal in application code. Your "simpler" solution can take thousands of times more code. -- Grant Edwards grante Yow! I'm young... I'm at HEALTHY... I can HIKE visi.com THRU CAPT GROGAN'S LUMBAR REGIONS!