Hi,
I am using MetrowerksCodeWarrior v2.7.3 and MSC8122 for my project. I want to use the start address and the size of the .text section
during program execution. Is there any variable that stores the start and the size of .text section.
I couldn't get anything related to this in the manuals.
Regards
Amit
解決済! 解決策の投稿を見る。
Hello
Did you try to use the Expressions and Symbols described in SC100 linker reference.pdf, chapter Linker Command File section Linker Command File Syntax > Expressions and Symbols.
You can define a symbol in the .lcf file using this syntax and use that symbol in your C source file.
Be careful symbol must start with an _ in the .lcf file because of internal name mangling.
If your symbol is called _Start_of_text, it needs to be declared as Start_of_text in your C source file.
CrasyCat
Hello
Did you try to use the Expressions and Symbols described in SC100 linker reference.pdf, chapter Linker Command File section Linker Command File Syntax > Expressions and Symbols.
You can define a symbol in the .lcf file using this syntax and use that symbol in your C source file.
Be careful symbol must start with an _ in the .lcf file because of internal name mangling.
If your symbol is called _Start_of_text, it needs to be declared as Start_of_text in your C source file.
CrasyCat
Thanks for your help.
I have a further query.
How can I use the size of .text segment during program execution of C code? The Expressions and Symbols defines @segsize(text) as the size of the text segment. But how can I access this variable during program execution.
Regards
Amit
Hello
Just define the following symbols in your linker file:
.provide _TextStart, @secaddr(".text")
.provide _TextSize, @secsize(".text")
And you can refer to then as follows in your .c source file:
/* Defined in linker control file */
extern unsigned long TextStart[];
extern unsigned long TextSize[];
/* Global variables used to hold .text start address and size.*/
unsigned char *StartOfCode;
unsigned int SizeOfCode;
void foo(void)
{
StartOfCode = (unsigned char *)TextStart;
SizeOfCode = (unsigned int) TextSize;
}
CrasyCat
Thank you so much for your help.
Regards
Amit
Hi,
I am using MSC8122. The memory models is:- M1 memory contains core specific program code (isr etc.). Program code common to all the cores is placed in M2 memory. I use .lcf files for linking and common file is used to generate the .map file for all the 4 cores.
As discussed earlier, I did the following to access start of M2 .text segment and size.
extern unsigned long M2_Text_Start[];
extern unsigned long M2_Text_Size[];
extern unsigned char* g_M2_Start_Of_Code;
extern unsinged int g_M2_Size_Of_Code;
In the C file I do:-
g_M2_Size_Of_Code = (unsinged int)M2_Text_Size;
But I get the following error:-
Hello
How does the definition look like in the .lcf file?
CrasyCat
Hi,
Following is a snippet of the .lcf file.
.unit c0,""
.space shared_m2, M2_start, M2_end ".m2_text"
.export "shared_m2"
.org M2_start
.segment .m2_text, ".text",
.set _M2_Text_Start, @segaddr(.m2_text)
.set _M2_Text_Size, @segsize(.m2_text)
.unit c1, "core1"
.import "c0'shared_m2"
.unit c2, "core2"
.import "c0'shared_m2"
.unit c3, "core3"
.import "c0'shared_m2"
Regards
Amit
Hello
According to your lcf snippet, _M2_Text_Start and _M2_Text_Size are only defined for core 0.
They are undefined in core 1, 2 and 3.
This is the reason you are getting the message.
CrasyCat
Hi,
I understood your point and checked the .map files for all the 4 cores. I see the symbol _M2_Text_Start and _M2_Text_Size only in the memory map for core0 and not in the other three cores.
But my .lcf files defines M2 for core0 only and then exports the shared_m2. The other cores import the shared_m2. So won't this automatically mean the symbols _M2_Text_Start and _M2_Text_Size will be accessible to all the cores.
I tried to modify my .lcf file as
Hello
This does not seem to work.
What you can try is define the symbols StartOfCode and SizeOfCode into shared memory. Initialize them on core 0 only
and then access the symbols from any other core.
CrasyCat