/** * IDT flag overview * * flags = x xx 0x11x 000 ????? * | | | \ SS = Storage Segment (0 for interrupts) * | | \ D = Size of gate: 1 = 32 bits; 0 = 16 bits * | \ DPL = Num. higher PL from which it is accessible * \ P = Segment Present bit */ void setInterruptHandler(int vector, void (*handler)(), int maxAccessibleFromPL) { Word flags = (Word)(maxAccessibleFromPL << 13); flags |= 0x8E00; // P = 1, D = 1, Type = 1110 (Interrupt Gate) idt[vector].lowOffset = lowWord((DWord)handler); idt[vector].segmentSelector = __KERNEL_CS; idt[vector].flags = flags; idt[vector].highOffset = highWord((DWord)handler); }
void setTrapHandler(int vector, void (*handler)(), int maxAccessibleFromPL) { Word flags = (Word)(maxAccessibleFromPL << 13); // Changed to 0x8e00 to convert it to an 'interrupt gate' and so the system calls will be thread-safe. flags |= 0x8e00; // P = 1, D = 1, Type = 1110 (Interrupt Gate) //flags |= 0x8F00; // P = 1, D = 1, Type = 1111 (Trap Gate) idt[vector].lowOffset = lowWord((DWord)handler); idt[vector].segmentSelector = __KERNEL_CS; idt[vector].flags = flags; idt[vector].highOffset = highWord((DWord)handler); }
void setInterruptHandler(int vector, void (*handler)(), int maxAccessibleFromPL) { /***********************************************************************/ /* THE INTERRUPTION GATE FLAGS: R1: pg. 5-11 */ /* *************************** */ /* flags = x xx 0x110 000 ????? */ /* | | | */ /* | | \ D = Size of gate: 1 = 32 bits; 0 = 16 bits */ /* | \ DPL = Num. higher PL from which it is accessible */ /* \ P = Segment Present bit */ /***********************************************************************/ Word flags = (Word)(maxAccessibleFromPL << 13); flags |= 0x8E00; /* P = 1, D = 1, Type = 1110 (Interrupt Gate) */ idt[vector].lowOffset = lowWord((DWord)handler); idt[vector].segmentSelector = __KERNEL_CS; idt[vector].flags = flags; idt[vector].highOffset = highWord((DWord)handler); }
void setTrapHandler(int vector, void (*handler)(), int maxAccessibleFromPL) { /***********************************************************************/ /* THE TRAP GATE FLAGS: R1: pg. 5-11 */ /* ******************** */ /* flags = x xx 0x111 000 ????? */ /* | | | */ /* | | \ D = Size of gate: 1 = 32 bits; 0 = 16 bits */ /* | \ DPL = Num. higher PL from which it is accessible */ /* \ P = Segment Present bit */ /***********************************************************************/ Word flags = (Word)(maxAccessibleFromPL << 13); //flags |= 0x8F00; /* P = 1, D = 1, Type = 1111 (Trap Gate) */ /* Changed to 0x8e00 to convert it to an 'interrupt gate' and so the system calls will be thread-safe. */ flags |= 0x8E00; /* P = 1, D = 1, Type = 1110 (Interrupt Gate) */ idt[vector].lowOffset = lowWord((DWord)handler); idt[vector].segmentSelector = __KERNEL_CS; idt[vector].flags = flags; idt[vector].highOffset = highWord((DWord)handler); }
init_frames(); init_dir_pages(); for (i = 0; i < NR_TASKS; ++i){ vdir[i] = 0; } allocate_DIR(&task[0].task); set_cr3(get_DIR(&task[0].task)); set_pe_flag(); } /***********************************************/ /************** SEGMENTATION MANAGEMENT ********/ /***********************************************/ void setGdt() { /* Configure TSS base address, that wasn't initialized */ gdt[KERNEL_TSS>>3].lowBase = lowWord((DWord)&(tss)); gdt[KERNEL_TSS>>3].midBase = midByte((DWord)&(tss)); gdt[KERNEL_TSS>>3].highBase = highByte((DWord)&(tss)); gdtR.base = (DWord)gdt; gdtR.limit = 256 * sizeof(Descriptor); set_gdt_reg(&gdtR); } /***********************************************/ /************* TSS MANAGEMENT*******************/ /***********************************************/ void setTSS() { tss.PreviousTaskLink = NULL;