Login

Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.

ARM Community: RW/ZI initialization code - ARM Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

RW/ZI initialization code Rate Topic: ***** 1 Votes

#1 User is offline   menzoda 

  • Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 07-March 12

Posted 12 June 2012 - 03:49 PM

Hello everyone. I have a problem and I hope you'll help.

I am trying to create an application without runtime library. I read a lot of ARM documentation and in every book written that I must provide my own RW/ZI initialization code. But there is nothing about HOW to provide this code. I can't find examples. I don't know what information gives me a compiler so that I could write this code. The only thing I found is that the compiler can use different compression algorithms for the initialization data, and If I do not want to use rtlib... What do you think? ...Yes! I must provide my own RW/ZI initialization code. Perhaps I should create it with the help of God.

I'll be very grateful for any information! Thanks!
0

#2 User is offline   isogen74 

  • Super Contributor
  • PipPipPipPip
  • Group: Members
  • Posts: 1098
  • Joined: 20-March 07

Posted 15 June 2012 - 09:13 PM

Hi menzoda,

Welcome to the world of writing your own loader - this is not entirely trivial and what your code needs to do will vary depending on your platform and what you want to load.

Assuming you are running bare metal on an ARM core (and not trying to second guess the OS linker/loader - that's a whole different problem) you need to know a couple of things:

* Where you RW data is stored in ROM/Flash/whatever-storage-you-want-to-use
* What address your RW data needs to end up in RAM (and how much needs to be copied)
* What address your ZI data needs to end up in RAM (and how much needs to be zeroed).

How you get this data depends on the toolchain you are using, but assuming you are using the ARM tools there are some magic linker generated symbols which you can use in C or assembler code to get this data.

http://infocenter.ar...g/CHDFHJDJ.html

The basic premise is that before the C "main" function runs you will need to:

* Setup the stack pointer
* Copy the RW data from storage address to the right location in memory (for each RW region you linked)
* Zero the ZI data location in memory (for each ZI region you linked)
* Branch to the main function

It is important that you provide an appropriate scatter file to the linker to ensure that all of the regions you have are correctly located (you can usually get away with a single ZI, a single RW, and a single RO region, but that depends on the program and device).


If you cannot execute your code in place (e.g. it is stored in an SDCard or some other block storage device) then you may also need to copy the code. This can be "fun" because you have to copy the code while it is executing, and correctly ensure you "bounce" the PC to the new value without breaking anything (like having a link-register pointing to an old address). It's not too complex, but will require some assembler to modify the stack pointer. This also typically requires that the loader code is compiled and linked to be position-independent.

HTH,
Iso

This post has been edited by isogen74: 15 June 2012 - 09:20 PM

When optimizing software, consider that the quickest code to run is the bit you removed from the call path.
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic