title: Triple fault in home grown kernel
body: <p>I am trying to write a kernel, mostly for entertainment purposes, and I am running into a problem were I believe it is triple faulting.  Everything worked before I attempted to enable paging.  The code that is breaking is this: </p>
  
  <pre><code>void switch_page_directory(page_directory_t *dir){
  
   current_directory = dir;
   asm volatile("mov %0, %%cr3":: "r"(&amp;dir-&gt;tablesPhysical));
  
   u32int cr0;
   asm volatile("mov %%cr0, %0": "=r"(cr0));
  
   cr0 |= 0x80000000;//enable paging
   asm volatile("mov %0, %%cr0":: "r"(cr0)); //this line breaks
  
  
  }//switch page directory
  </code></pre>
  
  <p>I have been following a variety of tutorials / documents for this but the one I am using to paging is thus <a href="http://www.jamesmolloy.co.uk/tutorial_html/6.-Paging.html" rel="noreferrer">http://www.jamesmolloy.co.uk/tutorial_html/6.-Paging.html</a> .  I am not sure what other code will be useful in figuring this out but if there is more I should provide I will be more than happy to do so.</p>
  
  <p>Edit=====</p>
  
  <p>I believe the CS,DS and SS are selecting correct entries here's the code used to set them</p>
  
  <pre><code>global gdt_flush     
  extern gp            
  gdt_flush:
  
      lgdt [gp]        ; Load the GDT with our 'gp' which is a special pointer
      mov ax, 0x10      ; 0x10 is the offset in the GDT to our data segment
  
      mov ds, ax
      mov es, ax
      mov fs, ax
      mov gs, ax
      mov ss, ax
  
      jmp 0x08:flush2   ; 0x08 is the offset to our code segment: Far jump!
  
  flush2:
      ret               ; Returns back to the C code!
  </code></pre>
  
  <p>and here's the gdt struct itself</p>
  
  <pre><code>struct gdt_entry{
      unsigned short limit_low;
      unsigned short base_low;
      unsigned char base_middle;
      unsigned char access;
      unsigned char granularity;
      unsigned char base_high;
  } __attribute__((packed));
  
  struct gdt_ptr{
      unsigned short limit;
      unsigned int base;
  } __attribute__((packed));
  
  struct gdt_entry gdt[5];
  struct gdt_ptr gp;
  </code></pre>
  
  <p>The IDT is very similar to this.</p>