Quick Links
RW/ZI initialization code
#1
Posted 12 June 2012 - 03:49 PM
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!
#2
Posted 15 June 2012 - 09:13 PM
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














