;----------------------------------------------------------;\r
-; BOS kernel Christoffer Bubach, 2003-2005. ;\r
+; BOS kernel Christoffer Bubach, 2003-2015. ;\r
;----------------------------------------------------------;\r
; ;\r
-; set/modify IDT entries ;\r
+; Set/modify IDT entries ;\r
; ;\r
;----------------------------------------------------------;\r
\r
+;-----------------------------------------------------;\r
+; ;\r
+; IDT entry structure ;\r
+; ;\r
+; 16bit - entry offset bits 0..15 ;\r
+; 16bit - code segment selector in GDT or LDT ;\r
+; 8bit - unused, set to 0 ;\r
+; 8bit - type and attributes ;\r
+; - 0xE = 32bit intterrupt ;\r
+; - 0x8 = Present bit = 1 ;\r
+; 16bit - entry offset bits 16..31 ;\r
+; ;\r
+; middle section for code segment 08 = 0x8E000008 ;\r
+;-----------------------------------------------------;\r
\r
\r
;--------------------------------------------------;\r
init_idt:\r
push eax\r
push ecx\r
+ push edi\r
\r
+ xor edi, edi\r
xor ecx, ecx\r
- .l1:\r
- mov eax, esi ; loop full IDT and\r
- mov [(0x6c00+ecx)], ax ; set to one ISR\r
- add ecx, 2\r
+ add edi, [idtr.address]\r
+ .l1: ; loop full IDT table\r
+ mov eax, esi\r
+ mov word [edi], ax ; set handler lower offset\r
+ add edi, 2\r
\r
- mov dword [(0x6c00+ecx)], 0x8E000008 ; 0x6c00 is where\r
- add ecx, 4 ; we put the IDT\r
+ mov dword [edi], 0x8E000008 ; set IDT segment and attributes\r
+ add edi, 4\r
\r
mov eax, esi\r
shr eax, 16\r
- mov [(0x6c00+ecx)], ax\r
- add ecx, 2\r
+ mov word [edi], ax ; set handler high offset\r
+ add edi, 2\r
\r
- cmp ecx, 0x800 ; 256 ints\r
- jb .l1 ; * 8 bytes each\r
+ add cx, 8 ; 8byte *\r
+ cmp cx, word [idtr.size] ; 256 ints\r
+ jb .l1 ; = done?\r
\r
+ pop edi\r
pop ecx\r
pop eax\r
ret\r
; edi = int function pointer ;\r
;--------------------------------------;\r
set_int:\r
- push eax\r
- push ecx\r
+ push eax\r
+ push ecx\r
\r
- mov al, 8 ; 8 bytes for each int\r
- mul cl ; cl * al = ax\r
- movzx ecx, ax ; ecx = IDT offset\r
- shr ecx, 1 ; 1/2 for dword list\r
- mov dword [(idt_list+ecx)], edi ; add to dword int list\r
- movzx ecx, ax ; ecx = IDT offset\r
+ mov al, 8 ; 8 bytes for each int\r
+ mul cl ; cl * al = ax\r
+ movzx ecx, ax ; ecx = IDT offset\r
+ shr ecx, 1 ; 1/2 for dword list\r
+ mov dword [(idt_list+ecx)], edi ; add to dword int list\r
+ movzx ecx, ax ; ecx = IDT offset\r
\r
- mov eax, edi\r
- mov [(0x6c00+ecx)], ax\r
- add ecx, 2\r
+ mov eax, edi\r
+ mov [(0x6c00+ecx)], ax\r
+ add ecx, 2\r
\r
- mov dword [(0x6c00+ecx)], 0x8E000008\r
- add ecx, 4\r
+ mov dword [(0x6c00+ecx)], 0x8E000008\r
+ add ecx, 4\r
\r
- mov eax, edi\r
- shr eax, 16\r
- mov [(0x6c00+ecx)], ax\r
+ mov eax, edi\r
+ shr eax, 16\r
+ mov [(0x6c00+ecx)], ax\r
\r
- pop ecx\r
- pop eax\r
- ret\r
+ pop ecx\r
+ pop eax\r
+ ret\r
\r
\r
\r
; out: esi = address or 0 if none present ;\r
;------------------------------------------------;\r
get_int:\r
- push eax\r
+ push eax\r
\r
- mov eax, 4 ; 4 bytes for each address\r
- mul cl ; cl * al = ax\r
- mov esi, idt_list\r
- add esi, eax\r
+ mov eax, 4 ; 4 bytes for each address\r
+ mul cl ; cl * al = ax\r
+ mov esi, idt_list\r
+ add esi, eax\r
\r
- pop eax\r
- ret\r
+ pop eax\r
+ ret\r
\r
\r
\r
; in: esi = pointer to int list ;\r
;----------------------------------------;\r
set_idt_list:\r
- push eax\r
- push edi\r
-\r
- xor ecx, ecx\r
- .l1:\r
- lodsd\r
- or eax, eax\r
- jz .next\r
- mov edi, eax\r
- call set_int\r
- .next:\r
- inc ecx\r
- cmp ecx, 0x100\r
- jb .l1\r
-\r
- pop edi\r
- pop eax\r
- ret\r
+ push eax\r
+ push edi\r
+\r
+ xor ecx, ecx\r
+ .l1:\r
+ lodsd\r
+ or eax, eax\r
+ jz .next\r
+ mov edi, eax\r
+ call set_int\r
+ .next:\r
+ inc ecx\r
+ cmp ecx, 0x100\r
+ jb .l1\r
+\r
+ pop edi\r
+ pop eax\r
+ ret\r
\r
\r
\r