void init_desc(void) { // IDT entries ISR_ENTRY(0); ISR_ENTRY(1); ISR_ENTRY(2); ISR_ENTRY(3); ISR_ENTRY(4); ISR_ENTRY(5); ISR_ENTRY(6); ISR_ENTRY(7); ISR_ENTRY(8); ISR_ENTRY(9); ISR_ENTRY(10); ISR_ENTRY(11); ISR_ENTRY(12); ISR_ENTRY(13); ISR_ENTRY(14); ISR_ENTRY(15); ISR_ENTRY(16); ISR_ENTRY(17); ISR_ENTRY(18); ISR_ENTRY(19); ISR_ENTRY(20); ISR_ENTRY(21); ISR_ENTRY(22); ISR_ENTRY(23); ISR_ENTRY(24); ISR_ENTRY(25); ISR_ENTRY(26); ISR_ENTRY(27); ISR_ENTRY(28); ISR_ENTRY(29); ISR_ENTRY(30); ISR_ENTRY(31); SYSG((u32)isr128, this_cpu.idt[0x80]);// SYStem Call goes here ISR_ENTRY(255); IRQ_ENTRY(0); IRQ_ENTRY(1); IRQ_ENTRY(2); IRQ_ENTRY(3); IRQ_ENTRY(4); IRQ_ENTRY(5); IRQ_ENTRY(6); IRQ_ENTRY(7); IRQ_ENTRY(8); IRQ_ENTRY(9); IRQ_ENTRY(10); IRQ_ENTRY(11); IRQ_ENTRY(12); IRQ_ENTRY(13); IRQ_ENTRY(14); IRQ_ENTRY(15); write_tss(&this_cpu.gdt[GDT_TSS_ENTRY], __KERNEL_DS, 0x0); this_cpu.idt_ptr.limit = IDT_ENTRY_NUM * sizeof(struct idt_desc_struct); this_cpu.idt_ptr.base = (u32)&(this_cpu.idt); gdt_flush((u32)&(this_cpu.gdt_ptr)); init_8259A(); irq_enable(2); memset((u8 *)&interrupt_handlers , 0, sizeof(interrupt_handlers)); idt_flush((u32)&(this_cpu.idt_ptr)); tss_flush(); }
void gdt_init(void) { /* that's kind of ugly (setting the null segment) */ memset(&gdt[SEG_NULL_IDX], 0x0, sizeof(struct gdt_entry)); /* 0x08 */ gdt_set_segment(SEG_KCODE_IDX, 0x0, 0xffffffff, GDTE_DPL_KERNEL | GDTE_X | GDTE_W | GDTE_NOT_TSS, GDTE_PAGE_GRAN | GDTE_32_BIT); /* 0x10 */ gdt_set_segment(SEG_KDATA_IDX, 0x0, 0xffffffff, GDTE_DPL_KERNEL | GDTE_R | GDTE_NOT_TSS, GDTE_PAGE_GRAN | GDTE_32_BIT); /* 0x18 */ gdt_set_segment(SEG_UCODE_IDX, 0x0, 0xffffffff, GDTE_DPL_USER | GDTE_X | GDTE_W | GDTE_NOT_TSS, GDTE_PAGE_GRAN | GDTE_32_BIT); /* 0x20 */ gdt_set_segment(SEG_UDATA_IDX, 0x0, 0xffffffff, GDTE_DPL_USER | GDTE_R | GDTE_NOT_TSS, GDTE_PAGE_GRAN | GDTE_32_BIT); /* task switching structure */ tss_init(SEG_KDATA, (uint32_t)&kernel_stack_top); gdt_install(); kprintf("[gdt] global descriptors were set up\n"); tss_flush(SEG_TSS); }
void init_gdt() { //Sets up the gdt pointer gdtp.limit = (sizeof(struct gdt_entry)*GDT_LEN)-1; gdtp.base = (unsigned int)&gdt_table; /*the first NULL entry*/ gdt_set_gate(0, 0,0,0,0); // 0x9A, 0x92, 0xFA, 0xF2 gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // Ok, add the tss set_tss(5, 0x10, 0x0); /*actually flushes gdt with lgdt code*/ gdt_flush((unsigned int)&gdtp); // now flush the TSS tss_flush(); }
void init_gdt() { gdt_ptr.size = (sizeof(gdt_entry_t) * 6) - 1; gdt_ptr.base = (u32int)&gdt_entries; gdt_set(0, 0, 0, 0, 0); // Null segment gdt_set(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment gdt_set(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment gdt_set(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // User mode code segment gdt_set(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // User mode data segment write_tss(5, 0x10, 0x0); gdt_flush((u32int)&gdt_ptr); tss_flush(); }
/* Should be called by main. This will setup the special GDT * pointer, set up the first 5 entries in our GDT, and then * finally call gdt_flush() in our assembler file in order * to tell the processor where the new GDT is and update the * new segment registers */ static void gdt_init() { /* Setup the GDT pointer and limit */ gdt_ptr.limit = (sizeof(gdt_entry_t) * 6) - 1; gdt_ptr.base = (uint32_t)&gdt_entries; gdt_set_gate(0, 0, 0, 0, 0); /* Null segment */ gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); /* Code segment */ gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); /* Data segment */ gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); /* User mode code segment */ gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); /* User mode data segment */ tss_write(5, 0x10, 0x0); /* Flush out the old GDT and install the new changes */ gdt_flush((uint32_t)&gdt_ptr); tss_flush(); }
void gdt_install(void) { gdtpointer.limit = (sizeof(struct gdt_entry) * NUM_OF_GDT) - 1; gdtpointer.base = (u32)&gdt; gdt_set_gate(0,0,0,0,0); gdt_set_gate(1,0,0xffffffff,0x9a, 0xcf); gdt_set_gate(2,0,0xffffffff,0x92, 0xcf); gdt_set_gate(3,0,0xffffffff,0xfa, 0xcf); /*usermode*/ gdt_set_gate(4,0,0xffffffff,0xf2, 0xcf); /*usermode*/ write_tss(5,0x10,0x0); gdt_flush(); tss_flush(); }
void gdt_init() { memset(&gdt_entries, 0, sizeof(gdt_entries)); gdt_set_gate(0, 0, 0, 0, 0); // 0x0 Null segment gdt_set_gate(1, 0, 0xFFFF, 0x98, 0x20); // 0x8 Kernel Code segment gdt_set_gate(2, 0, 0xFFFF, 0x90, 0x00); // 0x10 Kernel Data segment gdt_set_gate(3, 0, 0xFFFF, 0xF8, 0x20); // 0x18 User mode code segment gdt_set_gate(4, 0, 0xFFFF, 0xF0, 0x00); // 0x20 User mode data segment gdt_set_tss(); // 0x28 TSS64 gdt_ptr.limit = sizeof(gdt_entries) - 1; gdt_ptr.base = (u64)&gdt_entries; gdt_flush(&gdt_ptr); tss_flush(); }
/* * gdt_install * Install the kernel's GDTs */ void gdt_install(void) { /* GDT pointer and limits */ gp.limit = (sizeof(struct gdt_entry) * 6) - 1; gp.base = (unsigned int)&gdt; /* NULL */ gdt_set_gate(0, 0, 0, 0, 0); /* Code segment */ gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); /* Data segment */ gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); /* User code */ gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); /* User data */ gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); write_tss(5, 0x10, 0x0); /* Go go go */ gdt_flush(); tss_flush(); }
static void init_gdt() { gdt_ptr.limit = (sizeof(gdt_entry_t) * GDT_ENTRIES) - 1; gdt_ptr.base = (u32int)&gdt_entries; gdt_set_gate(0, 0, 0, 0, 0); // Null segment gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); // User mode code segment gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); // User mode data segment gdt_set_gate(5, 0, 0, 0xF2, 0xCF); // User mode tlb segment // u32 base = KERNEL_VIRTUAL_BASE - cpu::cPageSize; // u32 limit = cpu::cPageSize; // gdt_set_gate(5, base, limit, 0xF2, 0xCF); // User mode tlb segment write_tss(6, 0x10, 0x0); gdt_set_gate(7, 0, 0, 0x92, 0xCF); // Percpu segment gdt_flush((u32int)&gdt_ptr); tss_flush(); }
void init_gdt(uint32_t kstack_ptr) { // We have six entries in the GDT - two for kernel mode, // two for user mode, the NULL descriptor, // and one for the TSS (task state segment) // The limit is the last valid byte from the start of the GDT // - i.e. the size of the GDT - 1. gdt_ptr.limit = sizeof(gdt_entry_t) * 6 - 1; gdt_ptr.base = (uint32_t) &gdt_entries; gdt_set_gate(0, 0, 0, 0, 0); // null segment gdt_set_gate(1, 0, 0xFFFFF, 0x9A, 0xCF); // kernel code gdt_set_gate(2, 0, 0xFFFFF, 0x92, 0xCF); // kernel data gdt_set_gate(3, 0, 0xFFFFF, 0xFA, 0xCF); // user code gdt_set_gate(4, 0, 0xFFFFF, 0xF2, 0xCF); // user data // we pass gdt_entry index, kernel stack data segment offset // and kernel stack pointer write_tss(5, 0x10, kstack_ptr); gdt_flush((uint32_t) &gdt_ptr); tss_flush(); }
/* * gdt_install * Install the kernel's GDTs */ void gdt_install() { blog("Setting up Global Descriptor Tables..."); /* GDT pointer and limits */ gp.limit = (sizeof(struct gdt_entry) * 6) - 1; gp.base = (unsigned int)&gdt; /* NULL */ gdt_set_gate(0, 0, 0, 0, 0); /* Code segment */ gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); /* Data segment */ gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); /* User code */ gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); /* User data */ gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); write_tss(5, 0x10, 0x0); /* Go go go */ gdt_flush(); tss_flush(); bfinish(0); }
void create_gdt() { gdt_ptr.limit = sizeof(t_gdt_entry) * MAX_DESCRIPTORS - 1; gdt_ptr.base = (u32)&gdt; kmemset(gdt, 0, sizeof(gdt)); //Null Segment gdt_set_descriptor(0, 0, 0, 0, 0); //Code Segment gdt_set_descriptor(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); //Data Segment gdt_set_descriptor(2, 0, 0xFFFFFFFF, 0x92, 0xCF); //User mode Code Segment gdt_set_descriptor(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); //User mode Data Segment gdt_set_descriptor(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); //TSS load_default_tss(); gdt_flush((u32)&gdt_ptr); tss_flush(); }