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.
I'm writing an application in which I want to obtain the code of a particular function during runtime. Obtaining the code of a function is not a problem, as I just used function pointer to obtain the start address of the function. However, I'm not able to determine the end of the function. I can solve this if I can obtain the size of the function and store it at a known memory location.
Is it possible to accomplish the above using:
1. ASSEMBLY: Use labels in assembly code to find the size of the function. 2. LINKER SCRIPT/SCATTER FILES: Use linker scripts or scatter files to find the size of the function.
Any help in this regard is highly appreciated.
I'd use assembler, least then you have some handle on the call tree too. Watch the function size, and those of any literals used, and where the literal pool is placed.
You could parse the .MAP files, or .HTM? The object files would also contain useful data.
You could use scatter files and sections to park specific functions in a specific region.
I'm writing an application in which I want to obtain the code of a particular function during runtime.
And why would you want to do that? "Function size" may not be such a straightforward concept due to a number of reasons. It is not very useful in itself. Why don't you descride the problem you are actually trying to solve?
Likely copying some code to RAM, programming a FLASH memory.
Often it makes sense to express the problem that really needs solving, rather than focus on a specific solution path that may/may not be the most appropriate.
Thank you for replying.
Basically I overwrite the code of one function with the code of another.
Thanks, I'll look into .MAP file. Can you give some more details on how to do it in assembly?
This doesn't sound like a good idea. I hope you understand all the problems this might create.
Allocate a block of RAM. Fill with code. Call through function pointer. Ignore size of ant function in your flash.
Sorry for not being clear earlier.
I want to copy code from one processor to another. Both the processors are the same and will have the same RTOS libraries installed. One processor will have all the code on it and other will just have memory space reserved (No code).
From my design point, I want to first overwrite the code of one function (a dummy function with no code, but only space reserved) with the code of another on the local processor. WITH THIS WORKING I can then move on to copying between two processors (Since this introduces extra complexities).
For this to work, I should obtain the code of that function. If that is possible then I can use IAP commands to overwrite the flash.
Duplicating code from one processor to the other doesn't require you to know any function size.
I do not want to duplicate the entire code. I just want to migrate a portion of the code, (in chunks of functions) from one processor to another.
And what about all references that function does to other functions and variables at very specific addresses?
I can overlook that fact for now. I am still working on a protocol to program such a system. For now I just want to copy the code correctly.
It is almost like a run time firmware upgrade.
I just want to migrate a portion of the code, (in chunks of functions) from one processor to another.
I don't think you understand what you are trying to do. You might be able to make it work with a simple function, but that won't mean it will work with any function. You would be able to do it if the functions were coded in assembly.