Skip to content

Commit 9be3ccd

Browse files
committed
Add base code for idt gestion
1 parent a3a6a86 commit 9be3ccd

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

Chapter-7/README.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
An interrupt is a signal to the processor emitted by hardware or software indicating an event that needs immediate attention.
44

5-
There are 3 types of interruptions:
5+
There are 3 types of interrupts:
66

77
- **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.
88
- **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
7070
| 12 | PS2 Mouse |
7171
| 13 | FPU / Coprocessor / Inter-processor |
7272
| 14 | Primary ATA Hard Disk |
73-
| 15 | Secondary ATA Hard Disk |
73+
| 15 | Secondary ATA Hard Disk |
7474

75+
#### How to initialize the interrupts?
7576

76-
<table><tr><td><a href="../Chapter-6/README.md" >&larr; Previous</a></td><td>Next &rarr;</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" >&larr; Previous</a></td><td>Next &rarr;</td></tr></table>

0 commit comments

Comments
 (0)