c - How can I associate a global register variable to %gs (or %fs)? -


on x86_64 i'm playing toy os won't support multithreading.

i tried associate 2 global register variables %gs , %fs, way:

register foo* foo asm("gs"); register bar* bar asm("fs"); 

but gcc complains "gs" , "fs" not valid register names.

i tried other registers (eg r12 , r15) , compiled. tried %gs , %fs , compilation errors persists.

is possible use these registers way?
i've read issues these registers in amd64, i'm unable understand problem pointed there: gcc bug or problem use of register variables in amd64?

an 80386 compatible cpu has 6 segment registers named cs, ds, ss, es, fs, , gs. these segment registers used feature called segmentation , act pointer segment descriptor table, pointees implicitly added in address computations.

these segment register cannot realistically used hold arbitrary data specific ways (les , friends) load value them results in exception when load invalid value. used following purpose:

  • the segment register cs used when fetching instructions, ds when fetching data, ss when fetching data stack (i.e. relative esp or ebp) , es used in conjunction instructions scasb. in every instruction memory operand, can override segment address resolved against.
  • changing cs used change between real mode, 16 bit protected mode, 32 bit protected mode , long mode operating system. on windows, can done application (but not recommended). changing cs done doing far jump or call.
  • openbsd implements execution-prevention scheme (w^x) setting length limit on cs, no data both writable , executable @ same time.
  • the fs , gs segments never used default , commonly employed implement thread-local storage. can set offset associated fs , gs using arch_prctl system call on linux, keep in mind doing breaks expectations libc offset stored in segment descriptor table these segment descriptors , may make basic facilities such errno unusable.
  • in long mode (64 bit mode), whole segmentation mechanism not available. fs , gs can used value not looked in segment descriptor table, instead there 2 special register in kernel deposits offset added whenever fs , gs used. other mechanisms unavailable.

 this simplified description, it's bit more complex.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -