I have a X86_64 code that retrieves the pointer to the thread state:
uintptr_t addr;
arch_prctl(ARCH_GET_FS, &addr);
As I saw on the ABI, I guess this is what the r13
is for. I implemented the following code that I expect to behave the same as arch_prctl:
uintptr_t addr;
__asm__ ("\tmr %0, 13" : "=r" (addr));
Is it that simple? Is there a better way?
using debian 8.1 on a ppc64le machine
It isn't clear to me what you really want to do.
But if you want the thread pointer, r13 is the correct register on ppc64 and ppc64le, while r2 would be the correct one for ppc. You still have to be careful on how to access the fields in the Thread-Local storage, because they're ABI-specific.
Chapter 3.7.2 from the PPC64 ELF V2 ABI will give you more details on how to access some fields in the TLS. If you prefer to read some code, this file is where part of the magic really happens.