We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi All,
I am trying to write functions at specific locations. I am using KEIL 4 IDE ... and LPC2478 Though I could find a keyword "FIXED" which says one can write function at specific locations, but don't know how to use it .
This is what I want to achieve ....
for eg :
void main(void){ function_1(); function_2();
}
void function_1(){
void function_2(){
I need "function_1()" to be placed at specific location ...say...address 0x2000.
and
I need "function_2()" to be placed at specific location ...say...address 0x4000.
Can this be achieved ....and if yes How can I do this ?
All suggestions are welcome.... (I could not understand how the keyword "FIXED" works )....
Thanks ... K.Ganesh
Have a look in the linker manual - section 5.2.2, page 5.12
Any reason why the functions should be stored at fixed locations?
If supporting partial updates of code, it is more common to have a pointer table and perform indirect calls. This allows the size of the different functions to change as long as an updateable set of functions still fits in the reserved flash sector(s).
why say section and page? where is my pages in chm help? give me a web link.
Per,
I'm using a system that has 3 or even 4 "independent" components (multiple binaries, in effect), and I find it rather handy to have some functions placed at predefined locations (in order to allow hardware drivers to post RTX signals, for example - because the drivers themselves are not linked with RTX). But maybe what you mentioned is a better arrangement so I'm curious: Were you referring to a situation where there are multiple binaries, or a situation where there is only one program from which a partial update can "steal" a symbol to link with?
Using a link table has been used for many years.
An example is when you have multiple binaries. For example a BIOS and a main application. You don't want the main application to known internal information about the BIOS so instead it gets a table with pointers to use.
Quite similar (even if OS loader hides much of it) when using dynamic link libraries. The loaded DLL has a table of exported symbols. The main application may either directly use the pointers or the loader may patch the main application to make calls to the target address stored in the lookup table.
You are way better off with a pointer table than to store functions at absolute addresses. Store the table first or last in the updateable memory region to make it easy to locate. Then let the linker decide where to place the individual functions within the memory block.
Looks like fundamental techniques are no longer taught. Doesn't bode well for future products and their safety.
Yes ... I have a reason to have these functions at fixed locations.
To update the the hex file which is residing in a external data flash.
with ref to my example :
Assume I have a image of function "main" and "function_1" in a external data flash. And then Function_2 may read the data from the external data flash and update "main" and then update "function_1".....
As on Today I have 2 files at different offsets ..
What I need is a single file and functions at specific locations.
Thanks...
Hi Tamgir, Can you please provide the weblink for the linker manual referred by you.
Thanks
Thanks. Using such a table is a more robust solution - I admit that I never thought of doing that. Placing the functions in an absolute location seemed like the "natural" thing to do, but retrospectively, not the best solution. Next time I need to start from scratch, I will implement this system.
Ganesh,
It is better to use the .pdf version from the ARM site. I could not find the exact clause in the online version:
http://www.keil.com/support/man/docs/armlink/armlink_cegbbcjj.htm
<quote> Placing the functions in an absolute location seemed like the "natural" thing to do, but retrospectively, not the best solution. </quote>
Using a jump table:
Microsoft did it back in the 6502 BASIC days to make calls to the MONITOR functions.
The BBC Micro did it to call functions in the OS.
Wheels. They only exist so they can be re-invented.
For the sake of completeness, implementing such a table also greatly simplifies scatter loading. But, doing it the "wrong" way did teach me something else: how to run the preprocessor on a scatter file...!
Kind attn: Mr Per , Mr Tamir,
Can you help us with a sample file ....I went through the link and tried using the scattered file ...
The example suggests different load and execution address ...which will be same in my case....but it does not tell anything about Function relocation...
All suggestions are welcome.
(And I am using KEIL 4 IDE and LPC 2478 ).