How can I access the void pointer in C, using arm inline assembly. I want to get the address of the pointer. Something like this,
void* funcAddr;
__asm(
"LDR r0, =funcAddr"
);
Is there any way to do this?
Say I have
void (*FuncPointer) (void);
then further in the code
asm volatile ("adr x24, FuncPointer\n");
Then x24 holds the address the FuncPointer is. In this case it is in .bss section as FuncPointer is global and uninitialized at the creation. This is about getting the address of that pointer. If you want to get what this pointer points to you will have to execute the load of that to the register, eg.:
ldr x25, [x24];
x25 will have an address of the function the FuncPointer points to.
What if FuncPointer is local? Will this work then?
Local is being placed in the stack. As long as the stack frame lives yes but once you return from/unwind the frame no. See:
void Func(void) {
FuncPointer = FuncPointed;
(*FuncPointer) (); //run FuncPointed()
return;
}
then in assembly
bl Func
next instruction
And only in Func() you can refer to the symbol FuncPointer (eg. adr, ldr as above). Once you go out of the function (after "ret" in assembly) the FuncPointer doesn't exist, the stack frame got unwound.
That's general not assembly or inline assembly specific.