void dummy_int_handler(); void dummy_err_handler(); void thread_int_handler(); void start(); void cont(); struct INTERRUPT { unsigned short offsetLow; unsigned short segmentSelector; unsigned reserved : 5; unsigned signature : 8; unsigned dpl : 2; unsigned present : 1; unsigned short offsetHigh; }; struct INTERRUPT idt[256]; void* stack; void* stack2; void func() { while (1) { *(char*)(0xB8000) = 'S'; } } void kmain() { short idtr[3] = { 256 * 8, (int) idt & 0xffff, (int) idt >> 16 }; struct INTERRUPT thread = { (int) thread_int_handler & 0xffff, 1 << 3, 0, 0x70, 0, 1, (int) thread_int_handler >> 16 }; struct INTERRUPT dummy = { (int) dummy_int_handler & 0xffff, 1 << 3, 0, 0x70, 0, 1, (int) dummy_int_handler >> 16 }; struct INTERRUPT err = { (int) dummy_err_handler & 0xffff, 1 << 3, 0, 0x70, 0, 1, (int) dummy_err_handler >> 16 }; idt[0] = dummy; idt[1] = dummy; idt[2] = dummy; idt[3] = dummy; idt[4] = dummy; idt[5] = dummy; idt[6] = dummy; idt[7] = dummy; idt[8] = thread; idt[9] = dummy; idt[10] = err; idt[11] = err; idt[12] = err; idt[13] = err; idt[14] = err; idt[15] = dummy; idt[16] = dummy; idt[17] = err; int i; for (i = 18; i < 256; i++) idt[i] = dummy; asm("lidt (%0)" : : "a" (idtr)); asm("outb %b0, %w1" : : "a" (0xFE), "Nd" (21)); stack2 = 0x200000; start(); while (1) { *(char*)(0xB8000) = 'T'; cont(); } }