On Tue, Mar 27, 2012 at 8:34 PM, H.J. Lu <hjl.to...@gmail.com> wrote:
> %fs and %gs are special in 64bit mode. For a memory operand > "%fs:address", its effective address is base address of %fs + address. > The base address of %fs and %fs are hidden. "mov %fs, %eax" > will only access the visible part of %fs, which is the 16bit segment > selector. In 64bit mode, UNSPEC_TP is the base address of %fs. > To access the base address of %fs, we can use system call: > > int arch_prctl(int code, unsigned long addr); > int arch_prctl(int code, unsigned long *addr); > > ARCH_SET_FS > Set the 64-bit base for the FS register to addr. > > ARCH_GET_FS > Return the 64-bit base value for the FS register of the > current thread in the unsigned long pointed to by addr. > > BTW, 4 new instructions are added to read/write base address of > %fs/%gs directly. For now, we have to use the system call to > update base address of %fs, To read the base address of %fs, > OS arranges that the base address of %fs points to a struct: > > typedef struct > { > void *tcb; /* Pointer to the TCB. Not necessarily the > thread descriptor used by libpthread. */ > ... > } > > and sets up tcb == the base address of %fs. Then we can use > > "mov{l}\t{%%fs:0, %k0|%k0, DWORD PTR fs:0}" > > to move the base address of %fs into %r32 and %r64 directly. > I hope this answers your questions. Let me say this way: please propose the patch that implements your suggestions. I will leave the approval of the patch to someone else. Uros.