- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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. JanLink Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- 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'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't any other flags which solved it. Symbol table doesn't provide expected information. (x51 asembler has this info in "symbol table list " ) Is there another configuration or preprocesor settings? Thanks. Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 '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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
An automatic variable doesn'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's probably more what you want. Regards, --Scott- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- originally posted by smcnutt@Dec 15 2004, 09:00 AM an automatic variable doesn'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'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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page