Which variable can be used to access start of .text segment and size of .text segment?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Which variable can be used to access start of .text segment and size of .text segment?

ソリューションへジャンプ
4,193件の閲覧回数
jamit
Contributor I

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

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
3,280件の閲覧回数
CrasyCat
Specialist III

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

元の投稿で解決策を見る

0 件の賞賛
返信
10 返答(返信)
3,281件の閲覧回数
CrasyCat
Specialist III

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

0 件の賞賛
返信
3,280件の閲覧回数
jamit
Contributor I

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

0 件の賞賛
返信
3,280件の閲覧回数
CrasyCat
Specialist III

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

0 件の賞賛
返信
3,280件の閲覧回数
jamit
Contributor I

Thank you so much for your help.

 

Regards

Amit

0 件の賞賛
返信
3,280件の閲覧回数
jamit
Contributor I

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:-

 

 

[LNK,2,6999,-1]: Error: "_M2_Text_Size" is unresolved, referenced from:
 file.eln
[LNK,2,6999,-1]: Error: "_M2_Text_Size" is unresolved, referenced from:
 file.eln
[LNK,2,6999,-1]: Error: "_M2_Text_Size" is unresolved, referenced from:
 file.eln
I assume it is coming from 3 cores but I am not able to resolve it.
Pls let me know how to resolve the issue.
Regards
Amit

 

0 件の賞賛
返信
3,280件の閲覧回数
CrasyCat
Specialist III

Hello

 

How does the definition look like in the .lcf file?

 

CrasyCat

0 件の賞賛
返信
3,280件の閲覧回数
jamit
Contributor I

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

0 件の賞賛
返信
3,280件の閲覧回数
CrasyCat
Specialist III

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

0 件の賞賛
返信
3,280件の閲覧回数
jamit
Contributor I

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 

 

.unit c1, "core1"
.import "c0'shared_m2"
.set _M2_Text_Start, @segaddr(.m2_text)
.set _M2_Text_Size, @segsize(.m2_text)
But then i get the following error:-
[LNK,2,6003,37,msc8122.lcf]: Error: segment ".m2_text" does not exist
My assumption was by exporting and importing c0'shared_m2 all the cores have access to .m2_text and the associated symbols. I am not sure how to do this.
Further, is it possible that in my C code I restrict the _M2_Text_Start and _M2_Text_Size to core0 only using some pragmas e.g #pragma pgm_seg_name 
Thanks
Amit

 

0 件の賞賛
返信
3,280件の閲覧回数
CrasyCat
Specialist III

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

0 件の賞賛
返信