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

wirehaze git hosting

new indentation style
[BOS.git] / kernel / int / idt.asm
index cafbc63fc5dd368645431a0a1f513147232b1ea1..c6b28417e5f84963be8440b0db960d04dbb04849 100644 (file)
 ;----------------------------------------------------------;\r
 ;----------------------------------------------------------;\r
-; BOS kernel               Christoffer Bubach, 2003-2005. ;\r
+; BOS kernel                Christoffer Bubach, 2003-2015. ;\r
 ;----------------------------------------------------------;\r
 ;----------------------------------------------------------;\r
-;                                                         ;\r
-;      set/modify IDT entries                             ;\r
-;                                                         ;\r
+;                                                          ;\r
+;   Set/modify IDT entries                                 ;\r
+;                                                          ;\r
 ;----------------------------------------------------------;\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
 \r
 \r
 ;--------------------------------------------------;\r
-;     set up IDT                                  ;\r
-; in:  edi = pointer to "unhandled int"-function.  ;\r
+;     set up IDT                                   ;\r
+; in:  esi = pointer to "unhandled int"-function.  ;\r
 ;--------------------------------------------------;\r
 init_idt:\r
 ;--------------------------------------------------;\r
 init_idt:\r
-         push    eax\r
-         push    ecx\r
+        push   eax\r
+        push   ecx\r
+        push   edi\r
 \r
 \r
-         mov     ecx, 0\r
-     .loop:                                          ; loop\r
-         mov     eax, edi                            ; and\r
-         mov     [(0x6c00+ecx)], ax                  ; set whole IDT\r
-         add     ecx, 2                              ; to one ISR\r
+        xor    edi, edi\r
+        xor    ecx, ecx\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
 \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
 \r
-         mov     eax, edi\r
-         shr     eax, 16\r
-         mov     [(0x6c00+ecx)], ax\r
-         add     ecx, 2\r
+        mov    eax, esi\r
+        shr    eax, 16\r
+        mov    word [edi], ax                         ; set handler high offset\r
+        add    edi, 2\r
 \r
 \r
-         cmp     ecx, 0x800                          ; 256 ints\r
-         jb      .loop                               ; * 8 bytes each\r
+        add    cx, 8                                  ; 8byte *\r
+        cmp    cx, word [idtr.size]                   ; 256 ints\r
+        jb     .l1                                    ; = done?\r
 \r
 \r
-         pop     ecx\r
-         pop     eax\r
-         ret\r
+        pop    edi\r
+        pop    ecx\r
+        pop    eax\r
+        ret\r
 \r
 \r
 \r
 ;--------------------------------------;\r
 \r
 \r
 \r
 ;--------------------------------------;\r
-;  modify IDT, set any int            ;\r
-;     in: cl  = int number            ;\r
-;        edi = int function pointer   ;\r
+;  modify IDT, set any int             ;\r
+;     in: cl  = int number             ;\r
+;      edi = int function pointer      ;\r
 ;--------------------------------------;\r
 set_int:\r
 ;--------------------------------------;\r
 set_int:\r
-         push    eax\r
-         push    ecx\r
+        push   eax\r
+        push   ecx\r
 \r
 \r
-         mov     al, 8                               ; 8 bytes for each int\r
-         mul     cl                                  ; cl * al = ax\r
-         movzx   ecx, ax                             ; ecx = offset in IDT (1/2 for dword list)\r
-         ;;mov   [(idt_list+ecx/2)], edi             ; add new int to idt entry list\r
-         mov     dword [(idt_list+ecx)], edi         ; add new int to idt entry list\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
 \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
 \r
-         mov     dword [(0x6c00+ecx)], 0x8E000008\r
-         add     ecx, 4\r
+        mov    dword [(0x6c00+ecx)], 0x8E000008\r
+        add    ecx, 4\r
 \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
 \r
-         pop     ecx\r
-         pop     eax\r
-         ret\r
+        pop    ecx\r
+        pop    eax\r
+        ret\r
 \r
 \r
 \r
 ;------------------------------------------------;\r
 \r
 \r
 \r
 ;------------------------------------------------;\r
-;   get int address                             ;\r
-;      in:  cl = int number                     ;\r
-;      out: esi = address or 0 if none present  ;\r
+;   get int address                              ;\r
+;      in:  cl    = int number                   ;\r
+;      out: esi = address or 0 if none present   ;\r
 ;------------------------------------------------;\r
 get_int:\r
 ;------------------------------------------------;\r
 get_int:\r
-         push    eax\r
+        push   eax\r
 \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
 \r
-         pop     eax\r
-         ret\r
+        pop    eax\r
+        ret\r
 \r
 \r
 \r
 \r
 ;----------------------------------------;\r
 \r
 \r
 \r
 \r
 ;----------------------------------------;\r
-;   sets ints from list                 ;\r
-;      in:  esi = pointer to int list   ;\r
+;   sets ints from list                  ;\r
+;      in:  esi = pointer to int list    ;\r
 ;----------------------------------------;\r
 set_idt_list:\r
 ;----------------------------------------;\r
 set_idt_list:\r
-         push    eax\r
-         push    edi\r
+        push   eax\r
+        push   edi\r
 \r
 \r
-         mov     ecx, 0\r
-     .loop:\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      .loop\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
 \r
-         pop     edi\r
-         pop     eax\r
-         ret\r
+        pop    edi\r
+        pop    eax\r
+        ret\r
 \r
 \r
 \r
 ;------------------------------;\r
 ;   list of idt entries.       ;\r
 \r
 \r
 \r
 ;------------------------------;\r
 ;   list of idt entries.       ;\r
-;          0 = not handled    ;\r
+;        0 = not handled       ;\r
 ;------------------------------;\r
 ;------------------------------;\r
-idt_list:           dd   isr00\r
-                    dd   isr01\r
-                    dd   isr02\r
-                    dd   isr03\r
-                    dd   isr04\r
-                    dd   isr05\r
-                    dd   isr06\r
-                    dd   isr07\r
-                    dd   isr08\r
-                    dd   isr09\r
-                    dd   isr0A\r
-                    dd   isr0B\r
-                    dd   isr0C\r
-                    dd   isr0D\r
-                    dd   isr0E\r
-                    dd   0\r
-                    dd   isr10\r
-                    dd   isr11\r
-                    dd   isr12\r
-                    dd   isr13\r
-           times 12 dd   0                           ; 12 unused ints\r
-                    dd   isr20\r
-                    dd   isr21\r
-           times 16 dd   0                           ; 16 unused ints\r
-                    dd   isr32                       ; First free and BOS system interrupt.\r
-          times 205 dd   0                           ; 205 unused ints
\ No newline at end of file
+idt_list:   dd   isr00\r
+            dd   isr01\r
+            dd   isr02\r
+            dd   isr03\r
+            dd   isr04\r
+            dd   isr05\r
+            dd   isr06\r
+            dd   isr07\r
+            dd   isr08\r
+            dd   isr09\r
+            dd   isr0A\r
+            dd   isr0B\r
+            dd   isr0C\r
+            dd   isr0D\r
+            dd   isr0E\r
+            dd   0\r
+            dd   isr10\r
+            dd   isr11\r
+            dd   isr12\r
+            dd   isr13\r
+   times 12 dd   0                                    ; 12 unused ints\r
+            dd   isr20\r
+            dd   isr21\r
+   times 16 dd   0                                    ; 16 unused ints\r
+            dd   isr32                                ; First free and BOS system interrupt.\r
+  times 205 dd   0                                    ; 205 unused ints
\ No newline at end of file