title: Operating System Kernel assembly meaning?
body: <p><strong>Question 1.</strong><br>
  Whats the meaning of</p>
  
  <p>asm volatile ("ljmp %0, $1f\n 1:\n" :: "i" (KERNEL_CS));</p>
  
  <p>My guess is setting %cs as KERNEL_CS,but what about the immediate number $1f?</p>
  
  <p><strong>Question 2.</strong></p>
  
  <p>If we can use <code>jmp label</code> to jump to some label,why do we bother writing <code>jmp label f</code> or <code>jmp label b</code>?</p>
  
  <p><strong>Question 3.</strong></p>
  
  <p>Can my kernel program use <code>asm volatile ("ljmp %0, $1f\n 1:\n" :: "i" (USER_CS));</code> to change the privilege level to ring 3 at ring 0?I did this in my ISR,and I got General Protection Error.But I think my %cs and %ip are in valid exeutable and readeble memory segment after jmp,because my GDT is something like this</p>
  
  <pre><code>static struct segdesc gdt[] = {
  SEG_NULL,
  [SEG_KTEXT] = SEG(STA_X | STA_R, 0x0, 0xFFFFFFFF, DPL_KERNEL),
  [SEG_KDATA] = SEG(STA_W, 0x0, 0xFFFFFFFF, DPL_KERNEL),
  [SEG_UTEXT] = SEG(STA_X | STA_R, 0x0, 0xFFFFFFFF, DPL_USER),
  [SEG_UDATA] = SEG(STA_W, 0x0, 0xFFFFFFFF, DPL_USER),
  [SEG_TSS]    = SEG_NULL,
  </code></pre>
  
  <p>};</p>
  
  <p>Both KERNEL TEXT ,DATA and USER TEXT ,DATA segment are strating from the same address and have the same size.</p>