title: Doing a indirect far jump/call in protected mode
body: <p>How do I perform an indirect far jump/call in protected mode? First I was thinking that doing this is allowable:</p>
  
  <pre><code>jmp 0x10:eax;
  </code></pre>
  
  <p>(Don't worry about the segment selector..the 2nd entry of my GDT is a valid code segment)</p>
  
  <p>But when nasm assembled it, it was a syntax error. Looking at the Book 2a of the Intel (instruction set reference) manual, it can only be done using <code>jmp ptr16:32</code>, where the <code>ptr16:32</code> is an immediate value, or using <code>jmp m16:32</code>, where the <code>m16:32</code> is a memory location containing the 48-bit jump address (the 16:32).</p>
  
  <p>Now I tried to encode it this way:</p>
  
  <pre><code>mov dword[ds:jumpaddress_offset],eax
  ; or just dword[jumpaddress_offset],eax
  mov word[ds:jumpaddress_sel],0x10;
  ; or just mov word[ds:jumpaddress_sel],0x10;
  jmp dword far [dword ds:jumpaddress];
  ...
  jumpaddress:
  jumpaddress_sel dw 0
  jumpaddress_offset dd 0
  </code></pre>
  
  <p>It assembled successfully, but when I tried to run it the processor gets a general protection fault and restarts. I don't know what happened.</p>
  
  <p>I assumed the encoding is like this:</p>
  
  <p>(for example I want to jump to 0x10:0x8010 using indirect jump)</p>
  
  <pre><code>dw 0x10
  dd 0x8010
  </code></pre>
  
  <p>What could be the wrong with this?
  Is it that the 48-bit memory value should be coded in little endian?
  And should it be coded like this?</p>
  
  <pre><code>;0010 0000 8010
  dd 0x10,0x80,0,0,0x10,0
  </code></pre>
  
  <p>I haven't tried doing the last one.</p>