Main Page | Modules | File List | File Members

isr.asm

00001 ; ndk - [ isr.asm ]
00002 ;
00003 ; These are the definitions of all the general
00004 ; purpose exceptions, as well as some of the
00005 ; irqs.
00006 ;
00007 ; Please see:
00008 ;   /src/idt.{c,h}
00009 ;
00010 ; (c)2002 dcipher / neuraldk
00011 ;           www.neuraldk.org
00012 
00013 ; make sure all our wrappers are visible to gcc
00014 global int00h_wrapper, int10h_wrapper
00015 global int01h_wrapper, int11h_wrapper
00016 global int02h_wrapper, int12h_wrapper
00017 global int03h_wrapper, int13h_wrapper
00018 global int04h_wrapper, int14h_wrapper
00019 global int05h_wrapper, int15h_wrapper
00020 global int06h_wrapper, int16h_wrapper
00021 global int07h_wrapper, int17h_wrapper
00022 global int08h_wrapper, int18h_wrapper
00023 global int09h_wrapper, int19h_wrapper
00024 global int0Ah_wrapper, int1Ah_wrapper
00025 global int0Bh_wrapper, int1Bh_wrapper
00026 global int0Ch_wrapper, int1Ch_wrapper
00027 global int0Dh_wrapper, int1Dh_wrapper
00028 global int0Eh_wrapper, int1Eh_wrapper
00029 global int0Fh_wrapper, int1Fh_wrapper
00030 
00031 ; custom handlers for the timer and keyboard
00032 global int20h_wrapper
00033 global int21h_wrapper
00034 
00035 ; a byte array defining which exceptions
00036 ; send an error code
00037 global exceptionHasErrorCode
00038 
00039 ; defined in the C source
00040 extern timerHandler
00041 extern kbdHandler
00042 extern stdHandler
00043 
00044 section .text
00045 bits 32
00046 
00047 ; A macro used to create the general purpose
00048 ; wrappers
00049 %macro NEW_ISR 2
00050 %1:
00051         push    eax             ; save original eax
00052         mov     eax, %2         ; which exception?
00053         jmp     commonHandler   ; jump to the common code
00054 %endmacro
00055 
00056 commonHandler:
00057         push    ebp
00058         mov     ebp, esp
00059 
00060         ; push all registers (to be printed upon an exception)
00061         ; NOTE: should I push flags!?
00062         push ds
00063         push es
00064         push fs
00065         push gs
00066         push ss
00067         pushad
00068 
00069         ; NOTE: new... eflags!
00070         pushfd
00071 
00072         ; correct eax to value before "exceptionNum" overwrote it
00073         ; back in the NEW_ISR wrapper
00074         add     esp, 32         ; goto location of eax on stack
00075         push dword [ss:ebp+4]   ; overwrite it
00076         sub     esp, 28         ; return back to previous poisition on stack
00077 
00078         ; store task register
00079         str     bx
00080         push    bx
00081         push word 0
00082 
00083         ; make sure ds and es have valid selectors
00084         mov     bx, 08h
00085         mov     ds, bx
00086         mov     es, bx
00087 
00088         ; check if this exception provides an error code
00089         mov     ebx, eax
00090         cmp     byte [exceptionHasErrorCode + ebx], 0
00091         je      .1
00092 
00093         ; if so, push it onto the stack along with cs:ip
00094         push    word 0
00095         push    word  [ss:ebp+8]         ; error code
00096         push    dword [ss:ebp+12]         ; ip
00097         push    word 0
00098         push    word  [ss:ebp+16]         ; cs
00099         jmp     .2
00100 
00101 .1:
00102         ; if not, push "0" as error code, and cs:ip
00103         push    dword 0                  ; error code
00104         push    dword [ss:ebp+8]        ; ip
00105         push    dword [ss:ebp+12]        ; cs
00106 .2:
00107         push    word 0
00108         push    ax                      ; exception no
00109 
00110         ; call the standard error handler (C portion),
00111         ; which will examine the stack (which contains all
00112         ; the registers) and print them out
00113         call    stdHandler
00114 
00115         ; get rid of the error code, cs:ip stuff
00116         add     esp, 10
00117         ; and restore all the regs back to their previous settings
00118         popfd
00119         popad
00120         pop     ss
00121         pop     gs
00122         pop     fs
00123         pop     es
00124         pop     ds
00125         pop    ebp
00126         pop    eax
00127         iretd
00128 
00129 int20h_wrapper:
00130         push    ds
00131         push    es                      ; saving segment registers and
00132         pushad                          ; other regs because it's an ISR
00133         mov     bx, 08h
00134         mov     ds, bx
00135         mov     es, bx                  ; load ds and es with valid selector
00136         call    timerHandler            ; call actual ISR code
00137         popad                           ; restoring the regs
00138         pop     es
00139         pop     ds
00140         iretd
00141 
00142 int21h_wrapper:
00143         push    ds
00144         push    es                      ; saving segment registers and
00145         pushad                          ; other regs because it's an ISR
00146         mov     bx, 08h
00147         mov     ds, bx
00148         mov     es, bx                  ; load ds and es with valid selector
00149         ;call    kbdhandler              ; call actual ISR code
00150         popad                           ; restoring the regs
00151         pop     es
00152         pop     ds
00153         iretd
00154 
00155 NEW_ISR int00h_wrapper, 00h
00156 NEW_ISR int01h_wrapper, 01h
00157 NEW_ISR int02h_wrapper, 02h
00158 NEW_ISR int03h_wrapper, 03h
00159 NEW_ISR int04h_wrapper, 04h
00160 NEW_ISR int05h_wrapper, 05h
00161 NEW_ISR int06h_wrapper, 06h
00162 NEW_ISR int07h_wrapper, 07h
00163 NEW_ISR int08h_wrapper, 08h
00164 NEW_ISR int09h_wrapper, 09h
00165 NEW_ISR int0Ah_wrapper, 0Ah
00166 NEW_ISR int0Bh_wrapper, 0Bh
00167 NEW_ISR int0Ch_wrapper, 0Ch
00168 NEW_ISR int0Dh_wrapper, 0Dh
00169 NEW_ISR int0Eh_wrapper, 0Eh
00170 NEW_ISR int0Fh_wrapper, 0Fh
00171 NEW_ISR int10h_wrapper, 10h
00172 NEW_ISR int11h_wrapper, 11h
00173 NEW_ISR int12h_wrapper, 12h
00174 NEW_ISR int13h_wrapper, 13h
00175 NEW_ISR int14h_wrapper, 14h
00176 NEW_ISR int15h_wrapper, 15h
00177 NEW_ISR int16h_wrapper, 16h
00178 NEW_ISR int17h_wrapper, 17h
00179 NEW_ISR int18h_wrapper, 18h
00180 NEW_ISR int19h_wrapper, 19h
00181 NEW_ISR int1Ah_wrapper, 1Ah
00182 NEW_ISR int1Bh_wrapper, 1Bh
00183 NEW_ISR int1Ch_wrapper, 1Ch
00184 NEW_ISR int1Dh_wrapper, 1Dh
00185 NEW_ISR int1Eh_wrapper, 1Eh
00186 NEW_ISR int1Fh_wrapper, 1Fh
00187 
00188 section .data
00189 
00190 exceptionHasErrorCode db 0,0,0,0,0,0,0,0, 1,0,1,1,1,1,1,0
00191                       db 0,1,0,0,0,0,0,0, 0,0,0,0,0,0,0,0

Generated on Sun Nov 21 18:26:11 2004 for ndk by doxygen 1.3.2