]> wirehaze git hosting - BOS.git/blob - kernel/int/idt.asm

wirehaze git hosting

fat12 structures, constants and general framework done
[BOS.git] / kernel / int / idt.asm
1 ;----------------------------------------------------------;
2 ; BOS kernel Christoffer Bubach, 2003-2015. ;
3 ;----------------------------------------------------------;
4 ; ;
5 ; Set/modify IDT entries ;
6 ; ;
7 ;----------------------------------------------------------;
8
9 ;-----------------------------------------------------;
10 ; ;
11 ; IDT entry structure ;
12 ; ;
13 ; 16bit - entry offset bits 0..15 ;
14 ; 16bit - code segment selector in GDT or LDT ;
15 ; 8bit - unused, set to 0 ;
16 ; 8bit - type and attributes ;
17 ; - 0xE = 32bit intterrupt ;
18 ; - 0x8 = Present bit = 1 ;
19 ; 16bit - entry offset bits 16..31 ;
20 ; ;
21 ; middle section for code segment 08 = 0x8E000008 ;
22 ;-----------------------------------------------------;
23
24
25 ;--------------------------------------------------;
26 ; set up IDT ;
27 ; in: esi = pointer to "unhandled int"-function. ;
28 ;--------------------------------------------------;
29 init_idt:
30 push eax
31 push ecx
32 push edi
33
34 xor edi, edi
35 xor ecx, ecx
36 add edi, [idtr.address]
37 .l1: ; loop full IDT table
38 mov eax, esi
39 mov word [edi], ax ; set handler lower offset
40 add edi, 2
41
42 mov dword [edi], 0x8E000008 ; set IDT segment and attributes
43 add edi, 4
44
45 mov eax, esi
46 shr eax, 16
47 mov word [edi], ax ; set handler high offset
48 add edi, 2
49
50 add cx, 8 ; 8byte *
51 cmp cx, word [idtr.size] ; 256 ints
52 jb .l1 ; = done?
53
54 pop edi
55 pop ecx
56 pop eax
57 ret
58
59
60
61 ;--------------------------------------;
62 ; modify IDT, set any int ;
63 ; in: cl = int number ;
64 ; edi = int function pointer ;
65 ;--------------------------------------;
66 set_int:
67 push eax
68 push ecx
69
70 mov al, 8 ; 8 bytes for each int
71 mul cl ; cl * al = ax
72 movzx ecx, ax ; ecx = IDT offset
73 shr ecx, 1 ; 1/2 for dword list
74 mov dword [(idt_list+ecx)], edi ; add to dword int list
75 movzx ecx, ax ; ecx = IDT offset
76
77 mov eax, edi
78 mov [(0x6c00+ecx)], ax
79 add ecx, 2
80
81 mov dword [(0x6c00+ecx)], 0x8E000008
82 add ecx, 4
83
84 mov eax, edi
85 shr eax, 16
86 mov [(0x6c00+ecx)], ax
87
88 pop ecx
89 pop eax
90 ret
91
92
93
94 ;------------------------------------------------;
95 ; get int address ;
96 ; in: cl = int number ;
97 ; out: esi = address or 0 if none present ;
98 ;------------------------------------------------;
99 get_int:
100 push eax
101
102 mov eax, 4 ; 4 bytes for each address
103 mul cl ; cl * al = ax
104 mov esi, idt_list
105 add esi, eax
106
107 pop eax
108 ret
109
110
111
112
113 ;----------------------------------------;
114 ; sets ints from list ;
115 ; in: esi = pointer to int list ;
116 ;----------------------------------------;
117 set_idt_list:
118 push eax
119 push edi
120
121 xor ecx, ecx
122 .l1:
123 lodsd
124 or eax, eax
125 jz .next
126 mov edi, eax
127 call set_int
128 .next:
129 inc ecx
130 cmp ecx, 0x100
131 jb .l1
132
133 pop edi
134 pop eax
135 ret
136
137
138
139 ;------------------------------;
140 ; list of idt entries. ;
141 ; 0 = not handled ;
142 ;------------------------------;
143 idt_list: dd isr00
144 dd isr01
145 dd isr02
146 dd isr03
147 dd isr04
148 dd isr05
149 dd isr06
150 dd isr07
151 dd isr08
152 dd isr09
153 dd isr0A
154 dd isr0B
155 dd isr0C
156 dd isr0D
157 dd isr0E
158 dd 0
159 dd isr10
160 dd isr11
161 dd isr12
162 dd isr13
163 times 12 dd 0 ; 12 unused ints
164 dd isr20
165 dd isr21
166 times 16 dd 0 ; 16 unused ints
167 dd isr32 ; First free and BOS system interrupt.
168 times 205 dd 0 ; 205 unused ints