-
Notifications
You must be signed in to change notification settings - Fork 0
/
idt.c
106 lines (90 loc) · 3.17 KB
/
idt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* ** por compatibilidad se omiten tildes **
================================================================================
TRABAJO PRACTICO 3 - System Programming - ORGANIZACION DE COMPUTADOR II - FCEN
================================================================================
definicion de las rutinas de atencion de interrupciones
*/
#include "defines.h"
#include "idt.h"
#include "isr.h"
#include "screen.h"
#include "tss.h"
idt_entry idt[255] = {
};
idt_descriptor IDT_DESC = {
sizeof(idt) - 1,
(unsigned int) &idt
};
/*
La siguiente es una macro de EJEMPLO para ayudar a armar entradas de
interrupciones. Para usar, descomentar y completar CORRECTAMENTE los
atributos y el registro de segmento. Invocarla desde idt_inicializar() de
la siguiene manera:
void idt_inicializar() {
IDT_ENTRY(0);
...
IDT_ENTRY(19);
...
}
*/
char *errors[] = {
"Error 0: Division por cero",
"Error 1",
"Error 2: Interrupcion NMI",
"Error 3: Breakpoint",
"Error 4: Overflow",
"Error 5: Bound range exceeded",
"Error 6: Invalid Opcode",
"Error 7: Device Not Available",
"Error 8: Double Fault",
"Error 9: Coprocessor Segment Overrun",
"Error 10: Invalid TSS",
"Error 11: Segment Not Present",
"Error 12: Stack-Segment Fault",
"Error 13: General Protection",
"Error 14: Page Fault",
"Error 15",
"Error 16: FPU Error",
"Error 17: Alignment Check",
"Error 18: Machine Check",
"Error 19: SIMD Floating-Point Exception",
};
#define IDT_ENTRY(numero) \
idt[numero].offset_0_15 = (unsigned short) ((unsigned int)(&_isr ## numero) & (unsigned int) 0xFFFF); \
idt[numero].segsel = (unsigned short) 0x0040; \
idt[numero].attr = (unsigned short) 0x8E00; \
idt[numero].offset_16_31 = (unsigned short) ((unsigned int)(&_isr ## numero) >> 16 & (unsigned int) 0xFFFF);
#define IDT_ENTRY2(numero) \
idt[numero].offset_0_15 = (unsigned short) ((unsigned int)(&_isr ## numero) & (unsigned int) 0xFFFF); \
idt[numero].segsel = (unsigned short) 0x0040; \
idt[numero].attr = (unsigned short) 0xEE00; /*dpl 3*/ \
idt[numero].offset_16_31 = (unsigned short) ((unsigned int)(&_isr ## numero) >> 16 & (unsigned int) 0xFFFF);
void print_error(int a) {
print(errors[a], 23, 4, 10);
}
void idt_inicializar() {
// Excepciones
IDT_ENTRY(0);
IDT_ENTRY(1);
IDT_ENTRY(2);
IDT_ENTRY(3);
IDT_ENTRY(4);
IDT_ENTRY(5);
IDT_ENTRY(6);
IDT_ENTRY(7);
IDT_ENTRY(8);
IDT_ENTRY(9);
IDT_ENTRY(10);
IDT_ENTRY(11);
IDT_ENTRY(12);
IDT_ENTRY(13);
IDT_ENTRY(14);
IDT_ENTRY(15);
IDT_ENTRY(16);
IDT_ENTRY(17);
IDT_ENTRY(18);
IDT_ENTRY(19);
IDT_ENTRY(32);
IDT_ENTRY(33);
IDT_ENTRY2(70); // 0x46 DPL = 11
}