|
2 | 2 |
|
3 | 3 | An interrupt is a signal to the processor emitted by hardware or software indicating an event that needs immediate attention.
|
4 | 4 |
|
5 |
| -There are 3 types of interruptions: |
| 5 | +There are 3 types of interrupts: |
6 | 6 |
|
7 | 7 | - **Hardware interrupts:** are sent to the processor from an external device (keyboard, mouse, hard disk, ...). Hardware interrupts were introduced as a way to reduce wasting the processor's valuable time in polling loops, waiting for external events.
|
8 | 8 | - **Software interrupts:** are initiated voluntarily by the software. It's used to manage system calls.
|
@@ -70,7 +70,55 @@ Here is a table of common interrupts (Maskable hardware interrupt are called IRQ
|
70 | 70 | | 12 | PS2 Mouse |
|
71 | 71 | | 13 | FPU / Coprocessor / Inter-processor |
|
72 | 72 | | 14 | Primary ATA Hard Disk |
|
73 |
| -| 15 | Secondary ATA Hard Disk | |
| 73 | +| 15 | Secondary ATA Hard Disk | |
74 | 74 |
|
| 75 | +#### How to initialize the interrupts? |
75 | 76 |
|
76 |
| -<table><tr><td><a href="../Chapter-6/README.md" >← Previous</a></td><td>Next →</td></tr></table> |
| 77 | +This is a simple method to define an IDT segment |
| 78 | + |
| 79 | +```cpp |
| 80 | +void init_idt_desc(u16 select, u32 offset, u16 type, struct idtdesc *desc) |
| 81 | +{ |
| 82 | + desc->offset0_15 = (offset & 0xffff); |
| 83 | + desc->select = select; |
| 84 | + desc->type = type; |
| 85 | + desc->offset16_31 = (offset & 0xffff0000) >> 16; |
| 86 | + return; |
| 87 | +} |
| 88 | +``` |
| 89 | +
|
| 90 | +And we can now initialize the interupts: |
| 91 | +
|
| 92 | +```cpp |
| 93 | +void init_idt(void) |
| 94 | +{ |
| 95 | + /* Init irq */ |
| 96 | + int i; |
| 97 | + for (i = 0; i < IDTSIZE; i++) |
| 98 | + init_idt_desc(0x08, (u32)_asm_schedule, INTGATE, &kidt[i]); // |
| 99 | + |
| 100 | + /* Vectors 0 -> 31 are for exceptions */ |
| 101 | + init_idt_desc(0x08, (u32) _asm_exc_GP, INTGATE, &kidt[13]); /* #GP */ |
| 102 | + init_idt_desc(0x08, (u32) _asm_exc_PF, INTGATE, &kidt[14]); /* #PF */ |
| 103 | + |
| 104 | + init_idt_desc(0x08, (u32) _asm_schedule, INTGATE, &kidt[32]); |
| 105 | + init_idt_desc(0x08, (u32) _asm_int_1, INTGATE, &kidt[33]); |
| 106 | + |
| 107 | + init_idt_desc(0x08, (u32) _asm_syscalls, TRAPGATE, &kidt[48]); |
| 108 | + init_idt_desc(0x08, (u32) _asm_syscalls, TRAPGATE, &kidt[128]); //48 |
| 109 | + |
| 110 | + kidtr.limite = IDTSIZE * 8; |
| 111 | + kidtr.base = IDTBASE; |
| 112 | + |
| 113 | + |
| 114 | + /* Copy the IDT to the memory */ |
| 115 | + memcpy((char *) kidtr.base, (char *) kidt, kidtr.limite); |
| 116 | +
|
| 117 | + /* Load the IDTR registry */ |
| 118 | + asm("lidtl (kidtr)"); |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +After intialization our IDT |
| 123 | + |
| 124 | +<table><tr><td><a href="../Chapter-6/README.md" >← Previous</a></td><td>Next →</td></tr></table> |
0 commit comments