title: Detail about MSR_GS_BASE in linux x86 64
body: <p>I tried to figure out the details of MACRO current in Linux kernel.
  The final assembly code of current is:</p>
  
  <pre><code>movq %%gs:0xb000,%0
  </code></pre>
  
  <p>The code above can work! But when I print the %%gs, its value is 0, so the %%gs points to the first item of GDT NULL!!?? How it works?</p>
  
  <pre><code>mov %%gs, %0
  </code></pre>
  
  <p>Instead, the base of gs is in MSR_GS_BASE, and the current can be replaced like:</p>
  
  <pre><code>/*0xb000 is the offset of per_cpu__current_task*/
  cur_task = (unsigned long*)(x86_rdmsr64(MSR_GS_BASE) + 0xb000);
  println("cur_task:%p",*cur_task);
  </code></pre>
  
  <p>My questions is:</p>
  
  <p>%gs points to the first item of GDT NULL!!?? How it works as read from MSR_GS_BASE, is it a CPU feature？ I need some references about this.</p>