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

wirehaze git hosting

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