Instruction address in IAR

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Instruction address in IAR

1,712 Views
Shruthi_C
Contributor II

HI, 

I want to get address of present instruction running, so I used this in my IAR(GCC Compiler)

 

void *addr = (void *) __builtin_extract_return_addr (__builtin_return_address (0));

but its giving me error 

Error[Pe144]: a value of type "int" cannot be used to initialize an entity of type "void *"

 

Please support

Thanks

 

0 Kudos
Reply
8 Replies

1,645 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi @Shruthi_C 

I tried that in S32 Design Studio and it works as expected. Not sure what's wrong in IAR.

Or you can use something like this:

#define __ASM __asm
#define __INLINE inline
#define __STATIC_INLINE static inline

__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_LR(void)
{
register uint32_t result;

__ASM volatile ("MOV %0, LR\n" : "=r" (result) );
return(result);
}

And then:

uint32_t lr;

lr = __get_LR();

This also works on my side.

Regards,

Lukas

 

 

0 Kudos
Reply

1,607 Views
Shruthi_C
Contributor II

HI Lukas,

 

I tried the above content, but I am getting these warnings,

 

Warning[Pe172]: external/internal linkage conflict with previous declaration Hat line 85 of "internal preinclude.h"

Warning[Pe550]: variable "lr" was set but never used 

 

0 Kudos
Reply

1,576 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi @Shruthi_C 

what can you see on the line 85 in that file? I can't see such file in S32DS.

And the lr was obviously optimized out. I can see no problem with this.

Regards,

Lukas

0 Kudos
Reply

1,573 Views
Shruthi_C
Contributor II

Hi Lukas,

It shows like, That file does not exists  in S32K146

Shruthi_C_0-1695278843140.png

 

 

Thanks,

Shruthi

0 Kudos
Reply

1,565 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Ok, what will happen if you try to use the same code without defines like this?

 

__attribute__( ( always_inline ) ) static inline uint32_t __get_LR(void)
{
register uint32_t result;

__asm volatile ("MOV %0, LR\n" : "=r" (result) );
return(result);
}

0 Kudos
Reply

1,561 Views
Shruthi_C
Contributor II

Hi Lukas,

 

If I dont use #defines same behavior as before, warning

 

Shruthi_C_0-1695286264159.png

 

0 Kudos
Reply

1,525 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

It looks like the syntax is different in IAR. Please ask IAR for help, it seems I can't help with this.

Regards,

Lukas

0 Kudos
Reply

1,425 Views
Shruthi_C
Contributor II

HI Lukas, 

Thanks for your support

Regards 

Shruthi

0 Kudos
Reply