|ARM Technical Support Knowledge Articles|
Applies to: C51 C Compiler
Information in this article applies to:
I have three object files, foo1.obj, bar2.obj and baz3.obj. foo1.obj contains the main() function. How do I locate all the code segments in foo1.obj consecutively in memory starting at 1000h, all the code segments in bar2.obj consecutively in memory starting at 2000h and all the code segments in baz3.obj consecutively in memory starting at 3000h?
This is possible but the solution is fairly involved. It assumes that all code segments in foo1.obj, bar2.obj and baz3.obj are relocatable. The source file and object file names are arbitary.
The order of the source files (foo1.c, bar2.c and baz3.c) in compilation affects the order the segments of the resultant modules are placed in code memory. In order for bar2.obj to be placed after foo1.obj in memory, bar2.c must come directly below foo1.c in the Edit Project window in uVision.
Similarly in order for baz3.obj to be placed after bar2.obj in memory, baz3.c must come directly below bar2.c in the Edit Project window in uVision.
In uVision, choose Project — Components, Environment and Books, and select the Group that contains your source file. Ensure that the order of the source files from top to bottom is:
foo1.c bar2.c baz3.c
The order may be changed by selecting a source file and clicking on the 'Move Up' and 'Move Down' buttons.
Note: As foo1.c contains the main() function, it's position in the order is not relevant. The resultant object file foo1.obj will always be placed at lower memory locations than the other object files.
The foo1.obj (containing the main() function) can be located at 1000h by using the BL51 linker's CODE directive. For example:
The code segments for all the modules will then start at location 1000h.
At this point the project should be built and the map file opened (.m51). Check that the code segments for foo1.obj start at 1000h.
Look for the last code segment in memory for foo1.obj and add the length to the base address. This is the memory location where a gap needs to be inserted between the code segments for foo1.obj and bar2.obj.
For example if the last segment in memory in foo1.obj starts at 0034h and has a length of 0005h then the gap needs to start at:
0034h + 0005h = 0039h
The size of the gap in order to move the first segment of bar2.obj to 2000h is:
2000h - 0039h = 1FC7h
To insert the gap a global array must be created in bar2.c. The following line will do the trick:
code char gap[0x1fc7] _at_ 0x0039;
This will create an array of bytes, starting at location 0039h and 1FC7h in size.
If the project is now built and the map file checked then the first segment of bar2.obj will now be located at 2000h.
A similar procedure can be used to insert another gap between bar2.obj and baz3.obj. The array will have to be given a different name to the first array however.
Article last edited on: 2006-10-24 11:35:08
Did you find this article helpful? Yes No
How can we improve this article?