#include "gdt.h" gdt_entry gdt[] = { gdt_entry_init(0, 0, 0), gdt_entry_init(0, 0xfffff, 0xc09a), // Code segment. gdt_entry_init(0, 0xfffff, 0xc092), // Data segment. gdt_entry_init(0, 0xfffff, 0xc0fa), // User mode code segment. gdt_entry_init(0, 0xfffff, 0xc0f2), // User mode data segment. }; gdt_ptr gdtr = { .base = gdt, .limit = sizeof(gdt) - 1 }; void gdt_init() { asm volatile( "lgdt (%0)\n" "mov %w1, %%ds\n" "mov %w1, %%es\n" "mov %w1, %%fs\n" "mov %w1, %%gs\n" "mov %w1, %%ss\n" "ljmp $0x08, $.flush\n" ".flush:\n" : : "r" (&gdtr), "r" (0x10) ); }