]> wirehaze git hosting - BOS.git/blob - kernel/krl_incs/idt.inc

wirehaze git hosting

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