Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

variables location in memory

Altera_Forum
Honored Contributor II
1,432 Views

Hi all, 

 

how should I obtain variable address in memory after build? 

 

Are there any flags for compilator or linker?  

 

Is this information available? I need absolute address for all variables used in application.  

 

 

 

Thanks for you advice. 

 

Best regards. 

 

Jan
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
707 Views

Assuming that you are using the IDE to build a HAL based project, then you can get the information by selecting: Window->Preferences->Nios II and then ticking the "Generate objdump file" tick box. 

 

Next time you build your project, a file will appear in the Debug/Release directory with the extension .objdump. Amongst other things, this contains the absolute address of all available symbols. 

 

You can also run nios2-elf-objdump from the command line to extract symbol information from any elf file.
0 Kudos
Altera_Forum
Honored Contributor II
707 Views

 

--- Quote Start ---  

originally posted by monkeyboy@Dec 15 2004, 05:17 AM 

assuming that you are using the ide to build a hal based project, then you can get the information by selecting: window->preferences->nios ii and then ticking the "generate objdump file" tick box. 

 

next time you build your project, a file will appear in the debug/release directory with the extension .objdump. amongst other things, this contains the absolute address of all available symbols. 

 

you can also run nios2-elf-objdump from the command line to extract symbol information from any elf file. 

--- Quote End ---  

 

Hi,  

 

thanks, but it isn't what I need. I can't find variable location in *.objdump 

 

Simple example, hello from Nios... 

 

#include <stdio.h> int main() {  char hello_string={"Hello from Nios II!\n"};  int i_cnt;  for (i_cnt=1;;i_cnt++) {    printf("%d. %s",i_cnt , hello_string);  }  return 0; } 

 

I&#39;m looking for i_cnt location (absolut memory address).  

 

Which address of memory I have to read to acquire actual i_cnt value ? 

 

I looked at nios2-elf-objdump help, but the aren&#39;t any other flags which solved it. 

 

Symbol table doesn&#39;t provide expected information. (x51 asembler has this info in "symbol table list " ) 

Is there another configuration or preprocesor settings? 

 

 

Thanks. 

 

Jan
0 Kudos
Altera_Forum
Honored Contributor II
707 Views

Hi, 

 

Two problems : 

1. Probably in your example, the variable will be putted in a register. So there is actually no memory reference. 

2. In your example, the variable is a local variable to the main function, so it will be on the stack (if it is not case 1) 

 

Try to do &#39;volatile int i_cnt;" as a global variable instead. This forces the compiler to use a memory location and not optimise it away.  

 

#include <stdio.h> volatile int i_cnt; int main() { char hello_string={"Hello from Nios II!\n"}; for (i_cnt=1;;i_cnt++) {   printf("%d. %s",i_cnt , hello_string); } return 0; } 

 

I think because it is a globale now, the volatile is not ncry anymore. But if you want to be sure that every time in the loop where i_cnt is used or changed the value is read or written to the memory (or cache), use the volatile. Otherwise, the compiler will read only once, and stores it once after the loop (if it is furhter needed). 

 

For the f core : 

If you need to be absolutely sure it is written to the memory every time, you have to bypass the datacache as follows : 

 

1. change the ptf file and set always bypass dcache to 1. Then the dcache will never be used (for no data at all) 

2. do a trick with the address of i_cnt to put a 1 on the highest bit. Then only for this variabele the data cache is bypassed 

 

#include <stdio.h> volatile int i_cnt; int main() { char hello_string={"Hello from Nios II!\n"}; volatile int* pi_cnt = &i_cnt; pi_cnt = (volatile int*) ((int) pi_cnt | 0x80000000); for (*pi_cnt=1;; *pi_cnt++) {   printf("%d. %s",*pi_cnt , hello_string); } return 0; } 

 

Stefaan
0 Kudos
Altera_Forum
Honored Contributor II
707 Views

An automatic variable doesn&#39;t have a fixed address. Your count variable is 

automatic -- do as svhb says to force static allocation: either use the static 

keyword at function scope (in which case it will show up as i_cnt.0) or move 

it to file scope (where it will show up as simply "i_cnt"). 

 

Then try using nios2-elf-nm to get your address map -- it&#39;s probably 

more what you want. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
707 Views

 

--- Quote Start ---  

originally posted by smcnutt@Dec 15 2004, 09:00 AM 

an automatic variable doesn&#39;t have a fixed address. your count variable is 

automatic -- do as svhb says to force static allocation: either use the static 

keyword at function scope (in which case it will show up as i_cnt.0) or move 

it to file scope (where it will show up as simply "i_cnt"). 

 

then try using nios2-elf-nm to get your address map -- it&#39;s probably 

more what you want. 

 

regards, 

--scott 

--- Quote End ---  

 

Thank you for your messages. 

 

Utility nios2-elf-nm works fine, but have to be source file correct. 

 

Nice day 

 

Jan
0 Kudos
Reply